Git Product home page Git Product logo

r2ghidra's Introduction

We have a new website! If you want to contribute, have a look at the repository!

old website link

How to build documentation html pages

1. Install sphinx

sudo pip install sphinx

2. Build documentation

cd radareorg
sphinx-build source build

Open index.html located in build directory to start reading the documentation.

r2ghidra's People

Contributors

aemmitt-ns avatar anthraxx avatar brainstorm avatar condret avatar dogtopus avatar fmaerkl-sw avatar fxti avatar gordboy avatar itayc0hen avatar kamou avatar karliss avatar lironzua avatar lowlyw avatar maximevince avatar milahu avatar nirmalmanoj avatar pelijah avatar prodrigestivill avatar qinzhiben11 avatar radare avatar ret2libc avatar sab24 avatar sordidlist avatar thejeon avatar thestr4ng3r avatar trufae avatar unixfreaxjp avatar vysnet avatar yossizap avatar zutle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

r2ghidra's Issues

unable to build with -Werror=format-security

The build errors out with -Werror=format-security which means I can't release the distro package upgrade:

In file included from ../src/anal_ghidra.cpp:4:
/usr/include/libr/r_anal.h:66:48: error: format not a string literal and no format arguments [-Werror=format-sec
urity]
   66 | #define esilprintf(op, fmt, ...) r_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__)
      |                                  ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/anal_ghidra.cpp:1350:9: note: in expansion of macro ‘esilprintf’
 1350 |         esilprintf (anal_op, ss.str()[0] == ','? ss.str().c_str() + 1: ss.str().c_str());
      |         ^~~~~~~~~~
../src/anal_ghidra.cpp: In function ‘int sleigh_op(RAnal*, RAnalOp*, uint64_t, const uint8_t*, int, RAnalOpMask)
’:
../src/anal_ghidra.cpp:1408:46: warning: zero-length gnu_printf format string [-Wformat-zero-length]
 1408 |                         esilprintf (anal_op, "");
      |                                              ^~
/usr/include/libr/r_anal.h:66:60: note: in definition of macro ‘esilprintf’
   66 | #define esilprintf(op, fmt, ...) r_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__)
      |                                                            ^~~

r2ghidra 5.7.6 r_asm_t->config compile error against radare 5.7.6

latest r2ghidra 5.7.6 seems to have an API incompatibility to radare 5.7.6 😿

../src/R2LoadImage.cpp: In lambda function:
../src/R2LoadImage.cpp:67:64: error: ‘RAsm’ {aka ‘struct r_asm_t’} has no member named ‘config’
   67 |                                         int inc = (core->rasm->config->bits == 64)? 8: 4;
      |                                                                ^~~~~~

pdgo not working

no offsets are propagated from ghidra. maybe a missing patch? this is a regression, so it will be good to determine which commit broke that and add tests accordingly after fixing this

error: ‘r_codemeta_add_item’ was not declared

Describe the issue
When I try to install r2ghidra via r2pm I get the following Error:

/home/greatgodoffire/r2ghidra/src/CodeXMLParse.cpp:300:3: error: ‘r_codemeta_add_item’ was not declared in this scope; did you mean ‘r_codemeta_at’?
  300 |   r_codemeta_add_item (code, &annotation);
      |   ^~~~~~~~~~~~~~~~~~~
      |   r_codemeta_at

I have encountered the same issue when building it via CMake.

How to reproduce?
Run r2pm -ci r2ghidra or clone this repository and build it with CMake.

Expected behavior
A successful installation.

Additional context
Screenfetch:

greatgodoffire@lolcat
OS: Manjaro 21.0.3 Ornara
Kernel: x86_64 Linux 5.10.32-1-MANJARO
Uptime: 11h 32m
Packages: 1858
Shell: zsh 5.8
Resolution: 3200x1080
WM: i3
 GTK Theme: Matcha-dark-sea [GTK2/3]
 Icon Theme: Papirus-Dark-Maia
Font: Sans 10
 Disk: 851G / 5,5T (17%)
 CPU: Intel Core i5-3320M @ 4x 3.3GHz [63.0°C]
GPU: Mesa DRI Intel(R) HD Graphics 4000 (IVB GT2)
RAM: 3013MiB / 7819MiB

radare2 version:

$ r2 -v
radare2 5.2.0 0 @ linux-x86-64 git.5.2.0

8051 sleigh

It will be cool to have working 8051 sleigh in r2ghidra

Build the sleigh files with meson

Right now it is only possible to do that using the following commands:

make -C ghidra sleigh-build
export R2_LIBR_PLUGINS=$(r2 -H R2_LIBR_PLUGINS)
DESTDIR="${pkgdir}" make -C ghidra install

reference thread: #93 (comment)

RISC-V on windows

i tried r2 with option -a riscv -c"pdg"
got a message: "Ghidra Decompiler Error: Could not match asm.arch riscv to sleigh arch."

R2 version is 5.5.0-w64. works perfectly with 8051.
what's the recipe for riscv?

[BUG] Windows Build Errors

[BUG] Windows Build Errors

Issue Description:

The batch scripts provided to configure and make the plugin seem to have errors. Also the plugin sources have errors, which is causing ninja to teminate abruptly, but the CI continues without detecting. Windows builds have the following errors that i have spotted till now.

Issue Causes and Solutions (if any spotted):

Firstly the preconfigure scripts have 2 errors.

  • The ARCH variable is declared but later left unused L18.

    First Solution:
    I fixed this little bug by replacing %VSARCH% with %ARCH%
    bash~ ~sed -i 's|%VSARCH%|%ARCH%|g' preconfigure.bat~ ~

    Fixed in commit fd5366d

  • Secondly the url provided for ghidra-native is broken L6.
    Second Solution:
    To fix this I replaced the url with tag url

    - python -m wget https://github.com/radareorg/ghidra-native/releases/download/0.1.8/ghidra-native-0.1.8.zip
    + python -m wget https://github.com/radareorg/ghidra-native/archive/refs/tags/0.1.8.zip -o ghidra-native-0.1.8.zip
  • Errors in src\CodeXMLParse.cpp cause plugin dll build to fail. [Logs Here].

  • Errors in src\ArchMap.cpp cause plugin sleigh build to fail. [Logs Here].

Related Issues

None spotted till now.

error: 'RAnal'

im trying to install r2ghidra so i can be able to 'pdg' in radare2 ,i tried to install it with r2pm -ci r2ghidra
i had error with r_core ,after long research ,i found out installing libxxhash-dev can solve this issue and it did.
now im stuck with another error ,i have no clue how to pass this ,please help.

image

Problem compiling r2ghidra on Windows, with Visual Studio 2019

I am trying to build on windows. CMAKE is telling me paths are missing:

Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19042.
searching for file: r_core
Library set to Radare2_LIBRARY_core-NOTFOUND
searching for file: r_config
Library set to Radare2_LIBRARY_config-NOTFOUND
searching for file: r_cons
Library set to Radare2_LIBRARY_cons-NOTFOUND
searching for file: r_io
Library set to Radare2_LIBRARY_io-NOTFOUND
searching for file: r_util
Library set to Radare2_LIBRARY_util-NOTFOUND
searching for file: r_flag
Library set to Radare2_LIBRARY_flag-NOTFOUND
searching for file: r_asm
Library set to Radare2_LIBRARY_asm-NOTFOUND
searching for file: r_debug
Library set to Radare2_LIBRARY_debug-NOTFOUND
searching for file: r_hash
Library set to Radare2_LIBRARY_hash-NOTFOUND
searching for file: r_bin
Library set to Radare2_LIBRARY_bin-NOTFOUND
searching for file: r_lang
Library set to Radare2_LIBRARY_lang-NOTFOUND
searching for file: r_io
Library set to Radare2_LIBRARY_io-NOTFOUND
searching for file: r_anal
Library set to Radare2_LIBRARY_anal-NOTFOUND
searching for file: r_parse
Library set to Radare2_LIBRARY_parse-NOTFOUND
searching for file: r_bp
Library set to Radare2_LIBRARY_bp-NOTFOUND
searching for file: r_egg
Library set to Radare2_LIBRARY_egg-NOTFOUND
searching for file: r_reg
Library set to Radare2_LIBRARY_reg-NOTFOUND
searching for file: r_search
Library set to Radare2_LIBRARY_search-NOTFOUND
searching for file: r_syscall
Library set to Radare2_LIBRARY_syscall-NOTFOUND
searching for file: r_socket
Library set to Radare2_LIBRARY_socket-NOTFOUND
searching for file: r_fs
Library set to Radare2_LIBRARY_fs-NOTFOUND
searching for file: r_magic
Library set to Radare2_LIBRARY_magic-NOTFOUND
searching for file: r_crypto
Library set to Radare2_LIBRARY_crypto-NOTFOUND
CMake Error at C:/Program Files/CMake/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Radare2 (missing: Radare2_LIBRARIES Radare2_INCLUDE_DIRS)
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
cmake/FindRadare2.cmake:119 (find_package_handle_standard_args)
CMakeLists.txt:85 (find_package)

Configuring incomplete, errors occurred!

See also "D:/Users/feder/Files/Code/Development/r2ghidra-master/build/CMakeFiles/CMakeOutput.log".

I have manually installed and unzipped Radare2 binaries and created manually Radare2_LIBRARIES and Radare2_INCLUDE_DIRS, pointing them to radare2-5.4.2-w64\lib and radare2-5.4.2-w64\include respectively.

I appreciate any hint on how to proceed with succesful compilation.
Thanks

meson build system does not install any files for distro packaging

It seems that the meson build system is lacking some instructions. Its not installing a single file:

Expected files:

  • all the /usr/lib/radare2/$version/r2ghidra_sleigh sleigh as well as the .so
==> Starting package()...
ninja: Entering directory `build'
[0/1] /usr/bin/meson install --no-rebuild
Nothing to install.

its called like this:

meson setup   --prefix        /usr \
  --libexecdir    lib \
  --sbindir       bin \
  --buildtype     plain \
  --auto-features enabled \
  --wrap-mode     nodownload \
  -D              b_lto=true \
  -D              b_pie=true \
  build
ninja -C build --verbose
DESTDIR="${pkgdir}" ninja --verbose -C build install

Expected installed files:

${pkgdir}/usr/
${pkgdir}/usr/lib/
${pkgdir}/usr/lib/radare2/
${pkgdir}/usr/lib/radare2/5.6.6/
${pkgdir}/usr/lib/radare2/5.6.6/anal_ghidra.so
${pkgdir}/usr/lib/radare2/5.6.6/asm_ghidra.so
${pkgdir}/usr/lib/radare2/5.6.6/core_ghidra.so
${pkgdir}/usr/lib/radare2/5.6.6/r2ghidra_sleigh/
${pkgdir}/usr/lib/radare2/5.6.6/r2ghidra_sleigh/6502.cspec
${pkgdir}/usr/lib/radare2/5.6.6/r2ghidra_sleigh/6502.ldefs
${pkgdir}/usr/lib/radare2/5.6.6/r2ghidra_sleigh/6502.pspec
${pkgdir}/usr/lib/radare2/5.6.6/r2ghidra_sleigh/6502.sla
${pkgdir}/usr/lib/radare2/5.6.6/r2ghidra_sleigh/...

r2ghidra doesn't work with radare 5.0.0

sudo dpkg -i radare2*5.0.0*.deb
r2pm -i r2ghidra
r2 -A baby_reverse

[0x00001200]> s main
[0x000012e9]> pdg
Ghidra Decompiler Error: No print languages registered

Cannot build r2ghidra for Windows.

Cannot build r2ghidra for Windows. I had to replace Enterprise with Community in the path to the vcvarsall.bat file in preconfigure.bat for this to work on my system. But at startup configure.bat I get such output:

C:\Users\User.local\share\radare2\r2pm\git\r2ghidra>configure.bat
"Configuring the build directory with cmake"
-- The C compiler identification is GNU 10.2.0
-- The CXX compiler identification is GNU 10.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/bin/cc.exe
-- Check for working C compiler: /usr/bin/cc.exe - broken
CMake Error at /usr/share/cmake-3.21.3/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler

"/usr/bin/cc.exe"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: /c/Users/User/.local/share/radare2/r2pm/git/r2ghidra/build/CMakeFiles/CMakeTmp

Run Build Command(s):/c/Python39/Scripts/ninja.exe cmTC_2f3ac && ninja: error: '/c/Users/User/.local/share/radare2/r2pm/git/r2ghidra/build/CMakeFiles/CMakeTmp/testCCompiler.c', needed by 'CMakeFiles/cmTC_2f3ac.dir/testCCompiler.c.o', missing and no known rule to make it

CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:4 (project)

-- Configuring incomplete, errors occurred!
See also "/c/Users/User/.local/share/radare2/r2pm/git/r2ghidra/build/CMakeFiles/CMakeOutput.log".
See also "/c/Users/User/.local/share/radare2/r2pm/git/r2ghidra/build/CMakeFiles/CMakeError.log".

"$ r2pm -ci r2ghidra" failing on Arch Linux 5.13.7

Installation proceeds smoothly until:

CMake Error at ghidra/CMakeLists.txt:221 (add_executable):
  Cannot find source file:

    ghidra/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
  .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc


CMake Error at ghidra/CMakeLists.txt:204 (add_library):
  Cannot find source file:

    ghidra/Ghidra/Features/Decompiler/src/decompile/cpp/sleigh_arch.cc

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
  .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc


CMake Error at ghidra/CMakeLists.txt:201 (add_library):
  Cannot find source file:

    ghidra/Ghidra/Features/Decompiler/src/decompile/cpp/libdecomp.cc

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
  .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc


CMake Error at ghidra/CMakeLists.txt:197 (add_library):
  Cannot find source file:

    ghidra/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
  .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc


CMake Error at ghidra/CMakeLists.txt:221 (add_executable):
  No SOURCES given to target: sleighc


CMake Error at ghidra/CMakeLists.txt:204 (add_library):
  No SOURCES given to target: ghidra_decompiler_sleigh


CMake Error at ghidra/CMakeLists.txt:201 (add_library):
  No SOURCES given to target: ghidra_libdecomp


CMake Error at ghidra/CMakeLists.txt:197 (add_library):
  No SOURCES given to target: ghidra_decompiler_base


CMake Generate step failed.  Build files cannot be regenerated correctly.

r2pm -ci r2ghidra fails on /usr/bin/cc on linux mint 20.1

I have installed r2 from deb release 5.2.1 no problems

sudo apt install cmake

r2pm -ci r2ghidra

Cleaning r2ghidra...
clean Done For r2ghidra
/home/mint/.local/share/radare2/r2pm/db/r2ghidra TGZ=
Cleaning up /home/mint/.local/share/radare2/r2pm/git/r2ghidra...
Cloning into 'r2ghidra'...
remote: Enumerating objects: 103, done.
remote: Counting objects: 100% (103/103), done.
remote: Compressing objects: 100% (99/99), done.
remote: Total 103 (delta 1), reused 49 (delta 1), pack-reused 0
Receiving objects: 100% (103/103), 265.45 KiB | 2.19 MiB/s, done.
Resolving deltas: 100% (1/1), done.
Submodule 'ghidra/ghidra' (https://github.com/radareorg/ghidra.git) registered for path 'ghidra/ghidra'
Submodule 'third-party/pugixml' (https://github.com/zeux/pugixml.git) registered for path 'third-party/pugixml'
Cloning into '/home/mint/.local/share/radare2/r2pm/git/r2ghidra/ghidra/ghidra'...
remote: Enumerating objects: 98154, done.
remote: Total 98154 (delta 0), reused 0 (delta 0), pack-reused 98154
Receiving objects: 100% (98154/98154), 120.51 MiB | 7.50 MiB/s, done.
Resolving deltas: 100% (60152/60152), done.
Cloning into '/home/mint/.local/share/radare2/r2pm/git/r2ghidra/third-party/pugixml'...
remote: Enumerating objects: 8880, done.
remote: Counting objects: 100% (47/47), done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 8880 (delta 24), reused 26 (delta 13), pack-reused 8833
Receiving objects: 100% (8880/8880), 6.31 MiB | 4.57 MiB/s, done.
Resolving deltas: 100% (6121/6121), done.
Submodule path 'ghidra/ghidra': checked out '5560ac1711a07705e8fdb232726593f957d6dd5a'
Submodule path 'third-party/pugixml': checked out '0e3f1699ffab5f820060fe99c61f0f9495c0c5b6'
error: pathspec 'r2-5.2.1' did not match any file(s) known to git
Already up to date.
Install Done For r2ghidra
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is unknown
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- broken
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler

"/usr/bin/cc"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: /home/mint/.local/share/radare2/r2pm/git/r2ghidra/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_66298/fast && make -f CMakeFiles/cmTC_66298.dir/build.make CMakeFiles/cmTC_66298.dir/build
make[1]: Entering directory '/home/mint/.local/share/radare2/r2pm/git/r2ghidra/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_66298.dir/testCCompiler.c.o
/usr/bin/cc -I/home/mint/.local/share/radare2/prefix/include -o CMakeFiles/cmTC_66298.dir/testCCompiler.c.o -c /home/mint/.local/share/radare2/r2pm/git/r2ghidra/build/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_66298
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_66298.dir/link.txt --verbose=1
/usr/bin/cc -I/home/mint/.local/share/radare2/prefix/include -L/home/mint/.local/share/radare2/prefix/lib -rdynamic CMakeFiles/cmTC_66298.dir/testCCompiler.c.o -o cmTC_66298
/usr/bin/ld: cannot find Scrt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_66298.dir/build.make:87: cmTC_66298] Error 1
make[1]: Leaving directory '/home/mint/.local/share/radare2/r2pm/git/r2ghidra/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_66298/fast] Error 2

CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:4 (project)

compiling under windows

hello,

I tried to compile it for windows, but I faced an error:

1

My cmake version is:

C:\Users\root\Desktop\r2ghidra\build>cmake -version
cmake version 3.19.4

CMake suite maintained and supported by Kitware (kitware.com/cmake).


I am using the latest radare2 version and It works perfectly.


C:\Users\root\Desktop\r2ghidra\build>radare2 -v
radare2 5.1.0 25703 @ windows-x86-64 git.5.1.0-28-g89ff9aaf6
commit: 89ff9aaf6e668dfd2a17bf4cd9a1bdd7e176f4bd build: Wed 02/03/2021__ 7:29:32.24


C:\Users\root\Desktop\r2ghidra\build>radare2 -H
R2_VERSION=5.1.0
R2_PREFIX=.
R2_MAGICPATH=C:\Users\root\AppData\Local\Programs\radare2\dist\share\magic
R2_INCDIR=C:\Users\root\AppData\Local\Programs\radare2\dist\include\libr
R2_LIBDIR=C:\Users\root\AppData\Local\Programs\radare2\dist\lib
R2_LIBEXT=dll
R2_RCONFIGHOME=C:\Users\root.config\radare2
R2_RDATAHOME=C:\Users\root.local\share\radare2
R2_RCACHEHOME=C:\Users\root.cache\radare2
R2_LIBR_PLUGINS=C:\Users\root\AppData\Local\Programs\radare2\dist\lib\plugins
R2_USER_PLUGINS=C:\Users\root.local\share\radare2\plugins
R2_USER_ZIGNS=C:\Users\root.local\share\radare2\zigns

Any help is appreciated.

r2ghidra "No languages available..."

With radare2 fresh compile from git source on Ubuntu 20.04.2 LTS and installing r2ghidra the recommended way... ($ r2pm -ci r2ghidra):

using pdg returns "Ghidra Decompiler Error: No print languages registered"

and running pdgs returns "No languages available, make sure r2ghidra.sleighhome is set correctly!"

Now I have not done much research on Ghidra yet, but although the README specifically says that this is standalone, something tells me that I am missing files from Ghidra. Have I misunderstood the README for r2ghidra and expected to already have Ghidra set up?

Thanks.

How to install the r2ghidra plugin on Windows

Hi, first of all, thanks for this build. you are doing great. but I am running with an issue regarding the installation of ghindra plugin.
I installed radare2 latest version from windows installer and for plugin as per instruction i unzip it in radare directory but when i try to decode a function, i came up with following error

[0x000008a0]> afl
0x000008a0    1 12           entry0
0x00000dac    8 236          sym.Java_sg_vantagepoint_uncrackable2_CodeCheck_bar
0x00000d8c    1 32           sym.Java_sg_vantagepoint_uncrackable2_MainActivity_init
0x00000918   10 220          fcn.00000918
0x000007f0    1 16           sym.imp.pthread_create
0x00000800    1 16           sym.imp.__cxa_finalize
0x00000810    1 16           sym.imp.ptrace
0x00000820    1 16           sym.imp.strncmp
0x00000830    1 16           sym.imp._exit
0x00000840    1 16           sym.imp.__stack_chk_fail
0x00000850    1 16           sym.imp.fork
0x00000860    1 16           sym.imp.getppid
0x00000870    1 16           sym.imp.waitpid
0x00000880    1 16           sym.imp.pthread_exit
0x00000890    1 16           sym.imp.__cxa_atexit
0x000008b0    2 8            entry.fini0
0x000007d0    1 20           fcn.000007d0
[0x000008a0]> s 0x00000dac
[0x00000dac]> pdg
Error: r2pm -ci r2ghidra

r2ghidra-dec R2PM redirects to rz

INFO    10 unnecessary extensions/truncations were converted to copies
Use -u switch to list each individually
[ 99%] Generating sleigh/tricore.sla
[ 99%] Generating sleigh/x86-64.sla
[100%] Generating sleigh/x86.sla
INFO    17 NOP constructors found
Use -n switch to list each individually
INFO    24 unnecessary extensions/truncations were converted to copies
Use -u switch to list each individually
INFO    221 NOP constructors found
Use -n switch to list each individually
INFO    8 unnecessary extensions/truncations were converted to copies
Use -u switch to list each individually
INFO    252 NOP constructors found
Use -n switch to list each individually
INFO    10 operations wrote to temporaries that were not read
Use -t switch to list each individually
INFO    8 unnecessary extensions/truncations were converted to copies
Use -u switch to list each individually
INFO    13 operations wrote to temporaries that were not read
Use -t switch to list each individually
[100%] Built target sla
[  6%] Built target ghidra_decompiler_sleigh
[  7%] Built target pugixml
[  8%] Built target ghidra_libdecomp
[ 37%] Built target ghidra_decompiler_base
[ 42%] Built target core_ghidra
[ 44%] Built target asm_ghidra
[ 46%] Built target analysis_ghidra
[ 48%] Built target sleighc
[100%] Built target sla
Install the project...
-- Install configuration: ""
CMake Error at cmake_install.cmake:47 (file):
  file cannot create directory: /usr/local/share/rizin/plugins.  Maybe need
  administrative privileges.


Makefile:85: recipe for target 'install' failed
make: *** [install] Error 1

.fidb File Support

Description

At the moment, the output of decompiling has the types "wrong". (E.g. uint64_t instead of FILETIME).
Ghidra has support for .fidb files with more information. Could this be integrated into r2ghidra?

Here a side-to-side comparison:

r2ghidra:

void fcn.140006654(void)

{
    uint32_t uVar1;
    uint64_t var_10h;
    uint64_t lpSystemTimeAsFileTime;
    uint64_t lpPerformanceCount;
    
    lpSystemTimeAsFileTime = 0;
    if (*(uint64_t *)0x14001b000 == 0x2b992ddfa232) {
        (*_sym.imp.KERNEL32.dll_GetSystemTimeAsFileTime)(&lpSystemTimeAsFileTime);
        var_10h = lpSystemTimeAsFileTime;
        uVar1 = (*_sym.imp.KERNEL32.dll_GetCurrentThreadId)();
        var_10h = var_10h ^ uVar1;
        uVar1 = (*_sym.imp.KERNEL32.dll_GetCurrentProcessId)();
        var_10h = var_10h ^ uVar1;
        (*_sym.imp.KERNEL32.dll_QueryPerformanceCounter)(&lpPerformanceCount);
        *(uint64_t *)0x14001b000 =
             (lpPerformanceCount << 0x20 ^ lpPerformanceCount ^ var_10h ^ (uint64_t)&var_10h) & 0xffffffffffff;
        if (*(uint64_t *)0x14001b000 == 0x2b992ddfa232) {
            *(uint64_t *)0x14001b000 = 0x2b992ddfa233;
        }
    }
    *(uint64_t *)0x14001b008 = ~*(uint64_t *)0x14001b000;
    return;
}

ghidra:


void FUN_140006654(void)

{
  DWORD DVar1;
  _FILETIME local_res8;
  _FILETIME local_res10;
  uint local_res18;
  undefined4 uStackX28;
  
  local_res10 = (_FILETIME)0x0;
  if (DAT_14001b000 == 0x2b992ddfa232) {
    GetSystemTimeAsFileTime((LPFILETIME)&local_res10);
    local_res8 = local_res10;
    DVar1 = GetCurrentThreadId();
    local_res8 = (_FILETIME)((ulonglong)local_res8 ^ (ulonglong)DVar1);
    DVar1 = GetCurrentProcessId();
    local_res8 = (_FILETIME)((ulonglong)local_res8 ^ (ulonglong)DVar1);
    QueryPerformanceCounter((LARGE_INTEGER *)&local_res18);
    DAT_14001b000 =
         ((ulonglong)local_res18 << 0x20 ^ CONCAT44(uStackX28,local_res18) ^ (ulonglong)local_res8 ^
         (ulonglong)&local_res8) & 0xffffffffffff;
    if (DAT_14001b000 == 0x2b992ddfa232) {
      DAT_14001b000 = 0x2b992ddfa233;
    }
  }
  DAT_14001b008 = ~DAT_14001b000;
  return;
}

As you can see, the output of ghidra has more information.

For more information/fidb files see here:
https://github.com/NationalSecurityAgency/ghidra/tree/master/Ghidra/Features/FunctionID/data and https://github.com/NationalSecurityAgency/ghidra-data/tree/master/FunctionID

Build errors

I tried to install via r2pm -ci r2ghidra

Build error:

In file included from SleighAnalValue.h:6,
                 from SleighAnalValue.cpp:3:
SleighAsm.h:222:25: error: ‘RAsmOp’ has not been declared
  222 |         int disassemble(RAsmOp *op, unsigned long long offset);
      |                         ^~~~~~
In file included from SleighAsm.cpp:3:
SleighAsm.h:222:25: error: ‘RAsmOp’ has not been declared
  222 |         int disassemble(RAsmOp *op, unsigned long long offset);
      |                         ^~~~~~
SleighAsm.cpp:424:5: error: ‘int SleighAsm::disassemble’ is not a static data member of ‘class SleighAsm’
  424 | int SleighAsm::disassemble(RAsmOp *op, unsigned long long offset) {
      |     ^~~~~~~~~
SleighAsm.cpp:424:28: error: ‘RAsmOp’ was not declared in this scope; did you mean ‘RAsm’?
  424 | int SleighAsm::disassemble(RAsmOp *op, unsigned long long offset) {
      |                            ^~~~~~
      |                            RAsm
SleighAsm.cpp:424:36: error: ‘op’ was not declared in this scope
  424 | int SleighAsm::disassemble(RAsmOp *op, unsigned long long offset) {
      |                                    ^~
SleighAsm.cpp:424:40: error: expected primary-expression before ‘unsigned’
  424 | int SleighAsm::disassemble(RAsmOp *op, unsigned long long offset) {
      |                                        ^~~~~~~~
SleighAsm.cpp:424:65: error: expression list treated as compound expression in initializer [-fpermissive]
  424 | int SleighAsm::disassemble(RAsmOp *op, unsigned long long offset) {
      |                                                                 ^

More info:

> $ r2 -V                                                                                                                                                  
5.7.8-704-g984a8ade53  r2
5.7.8-704-g984a8ade53  r_anal
5.7.8-704-g984a8ade53  r_lib
5.7.8-704-g984a8ade53  r_egg
5.7.8-704-g984a8ade53  r_asm
5.7.8-704-g984a8ade53  r_bin
5.7.8-704-g984a8ade53  r_cons
5.7.8-704-g984a8ade53  r_flag
5.7.8-704-g984a8ade53  r_core
5.7.8-704-g984a8ade53  r_crypto
5.7.8-704-g984a8ade53  r_bp
5.7.8-704-g984a8ade53  r_debug
5.7.8-704-g984a8ade53  r_main
5.7.8-704-g984a8ade53  r_fs
5.7.8-704-g984a8ade53  r_io
5.7.8-704-g984a8ade53  r_magic
5.7.8-704-g984a8ade53  r_parse
5.7.8-704-g984a8ade53  r_reg
5.7.8-704-g984a8ade53  r_sign
5.7.8-704-g984a8ade53  r_search
5.7.8-704-g984a8ade53  r_syscall
5.7.8-704-g984a8ade53  r_util

> $ uname -r                                                                                                                                               
6.0.0-kali5-amd64

BUG: Ghidra Decompiler Error: No print languages registered

I recently cleaned out and fresh installed radare2, and now get this error:

[0x00001060]> s main
[0x00001159]> pdg
Ghidra Decompiler Error: No print languages registered

I tried with multiple binaries. r2 installed from git:

$ r2pm -l
r2book
r2frida
r2ghidra
r2ghidra-sleigh

$ r2 -V
5.5.4  r2
5.5.4  r_anal
5.5.4  r_lib
5.5.4  r_egg
5.5.4  r_asm
5.5.4  r_bin
5.5.4  r_cons
5.5.4  r_flag
5.5.4  r_core
5.5.4  r_crypto
5.5.4  r_bp
5.5.4  r_debug
5.5.4  r_main
5.5.4  r_hash
5.5.4  r_fs
5.5.4  r_io
5.5.4  r_magic
5.5.4  r_parse
5.5.4  r_reg
5.5.4  r_sign
5.5.4  r_search
5.5.4  r_syscall
5.5.4  r_util

~/tmp/radare2$ git log | head
commit 6231e6058513be306f34fb29132441d8235e7114
Author: pancake <[email protected]>
Date:   Tue Feb 1 20:03:26 2022 +0100

    Fix #18621 - Specify ABI version to be X.Y instead of X.Y.Z ##build
    
    * Installation creates some more symlinks now

Linux build errors v5.7.8

Description

Building r2ghidra v.5.7.8

During build there are multiple errors on Linux x86_64

../r2ghidra-5.7.8/src/ArchMap.cpp: In function ‘std::string       SleighIdFromCore(RCore*)’:
    ../r2ghidra-5.7.8/src/ArchMap.cpp:204:45: error: ‘static          void SleighArchitecture::collectSpecFiles(std::ostream&)’ is      protected within this context
      204 |  R2Architecture::collectSpecFiles (std::cerr);
          |                                             ^
    In file included from ../r2ghidra-5.7.8/src/ArchMap.h:6,
                     from ../r2ghidra-5.7.8/src/ArchMap.cpp:3:
    ../r2ghidra-5.7.8/ghidra-native/src/decompiler/sleigh_arch.       hh:100:15: note: declared protected here
      100 |   static void collectSpecFiles(ostream &errs);  ///<      Gather specification files in normal locations
          |               ^~~~~~~~~~~~~~~~
    ../r2ghidra-5.7.8/src/ArchMap.cpp:205:31: error:                  ‘getLanguageDescriptions’ is not a member of ‘R2Architecture’
      205 |  auto langs = R2Architecture::                            getLanguageDescriptions ();
1453       |                               ^~~~~~~~~~~~~~~~~~~~~~~

../r2ghidra-5.7.8/src/SleighInstruction.cpp: In member            function ‘void SleighParserContext::                              setPrototype(SleighInstructionPrototype*)’:
1506 ../r2ghidra-5.7.8/src/SleighInstruction.cpp:35:4: error:          ‘getBaseState’ was not declared in this scope; did you mean       ‘getParserState’?
       35 |   *getBaseState() = &prototype->rootState;
          |    ^~~~~~~~~~~~
          |    getParserState
../r2ghidra-5.7.8/src/SleighInstruction.cpp: In member            function ‘SleighParserContext* R2Sleigh::                         newSleighParserContext(Address&, SleighInstructionPrototype*      )’:
    ../r2ghidra-5.7.8/src/SleighInstruction.cpp:79:53: error:         ‘getContextCache’ was not declared in this scope; did you         mean ‘ContextCache’?
       79 |  SleighParserContext *pos = new                           SleighParserContext(getContextCache());
          |                                                           ^~~~~~~~~~~~~~~
          |                                                           ContextCache

I can upload the whole build log, but don't know where to attach it.

Topic: types for variables, flags, and function signatures

Types are more useful in the decompiler than in disassembly because the decompiler attempts to recover code as higher level as possible, that means that the result of the decompiler usually needs to be cleaned manually; In the case of ghidra, the process is to rename variables (there is also splitting a variable into two separate variables which is something specific to ghidra decompiler), to change variable types, change calling conventions, and change function signatures (ghidra supports automatically applying functions signatures from signature databases or type database), ghidra also has type deduction, an untyped variable automatically picks a type if assigned a value of a known type, this can be a function return value, or if a variable is passed as an argument in a call to a function with known parameter types.

radare does have a type system, but I would describe it as incomplete and incorrect, for instance, it doesn't do alignment, also it doesn't handle properly configuration specific sizes such as the size of a pointer. But is radare really pressed about types? Is the type feature in radare really used by people? I am thinking that ghidra plugin should have its own full featured type system because it makes a significant difference in ghidra while not that much in radare. I have experimented locally with the type system of radare, as well as exporting the variables that ghidra finds back to radare and I came to the conclusion of making ghidra plugin independent, especially that for the latter I found that ghidra has a special kind of variables that are neither a register variable nor a stack variable, they only exist in the intermediate representation so they can't be exported to radare, though ghidra does give them a type and a name. I concluded that mapping features of ghidra to radare one to one may not be feasible nor interesting. Also if ghidra specific code is in the plugin, it wouldn't be deleted from radare because it is "dead code that is not used in radare".

Debian build issues

Description

Debian build has unstripped libs and exes and has random user:group ownership. It is also unusually large.

Fix for now

Unpack .deb file, strip stuff, fix ownerships, recalculate md5sums, amend DEBIAN/control with new install size then repack. This is not trivial for the n00b.

File sizes before and after repack

-rw-r--r-- 1 gordboy gordboy 50613548 Dec 23 10:43 r2ghidra_5.8.0_amd64.deb
-rw-r--r-- 1 gordboy gordboy 9422720 Dec 23 11:31 r2ghidra_5.8.0_amd64.deb

Suggested partial fixes

Strip things

In dist/debian/build.sh

add section to strip things, similar to the way it is done in

https://github.com/radareorg/radare2/blob/master/sys/debian.sh

for radare2

Change zip format for tar

In dist/debian/deb.mk

change to xz zip format by using

tar cJvf and cpJvf

instead of

tar czvf and tar cpzvf

similar to the way it is done in

https://github.com/radareorg/radare2/blob/master/dist/debian/deb_hand.mak

for radare2

Another debian packaging improvement

So moving to fakeroot in the CI is all good.

One more change would make the final debian package substantially smaller. In

https://github.com/radareorg/r2ghidra/blob/master/dist/debian/deb.mk

at line 94, changing

cd ${PACKAGE_DIR}/control && tar czvf $@/control.tar.gz *

to

cd ${PACKAGE_DIR}/control && tar cJvf $@/control.tar.gz *

and at line 98, changing

tar cpzvf $@/data.tar.gz *

to

tar cpJvf $@/data.tar.gz *

would change the compression type from gzip to xz and make the final package much smaller.

We do the same thing in the parent radare2 in

https://github.com/radareorg/radare2/blob/master/dist/debian/deb_hand.mak

and this would sync things up nicely.

Issued a PR for this at

#108

Ghidra Decompiler Error: parameter list floating-point entries must come first

I am attempting to decompile a .NET native x86_64 Windows DLL on Linux using Radare2 5.6.8 and the latest version of r2ghidra.

When I try to decompile any function, I am greeted with "Ghidra Decompiler Error: parameter list floating-point entries must come first," with no other information.

I am able to decompile Linux x86_64 binaries without issue, as well as use pdd from r2dec to decompile the same DLL's functions.

option to do pdg with <timeout>

Adding a timeout for pdg instruction (Decompile current function with Ghidra decompiler).

I fixed this issue locally for my linux os environment Adding pdgt command that decompile function until timeout.

And changing _cmd function in core_ghidra.cpp as follows:

static int e_child_pid = 0;
static void timer_handler(int pid)
{
kill(e_child_pid, SIGKILL);
}

static void _cmd(RCore *core, const char input)
{
switch(input)
{
case 'd': // "pdgd"
DecompileCmd(core, DecompileMode::DEBUG_XML);
break;
case '\0': // "pdg"
DecompileCmd(core, DecompileMode::DEFAULT);
break;
case 't': // "pdgt"
{
ut64 timeout = (ut64)strtoull(input + 2, nullptr, 0);
signal(SIGALRM, timer_handler);
pid_t pid = fork();
e_child_pid = pid;
if (pid < 0) {
eprintf("Fork failed!\n");
}
if (pid == 0) {
DecompileCmd(core, DecompileMode::DEFAULT);
} else {
alarm(timeout);
int state;
waitpid(pid, &state, 0);
}
break;
}
case 'x': // "pdgx"
DecompileCmd(core, DecompileMode::XML);
break;
case 'j': // "pdgj"
DecompileCmd(core, DecompileMode::JSON);
break;
case 'o': // "pdgo"
DecompileCmd(core, DecompileMode::OFFSET);
break;
case '
': // "pdg
"
DecompileCmd(core, DecompileMode::STATEMENTS);
break;
case 's': // "pdgs"
switch(input[1])
{
case 's': // "pdgss"
PrintAutoSleighLang(core);
break;
case 'd': // "pdgsd"
Disassemble(core, (ut64)strtoull(input + 2, nullptr, 0));
break;
default:
ListSleighLangs();
break;
}
break;
case 'a': // "pdga"
EnablePlugin(core);
break;
default:
PrintUsage(core);
break;
}
}

w32 binaries

I will appreciate for r2ghidra-x.x.0-w32.zip release

Build fails Linux / Ubuntu - ‘RCodeMeta’ does not name a type

I download and build using

./preconfigure
./configure
make

I got a bunch of erros of like:

CodeXMLParse.cpp:297:7: error: ‘RCodeMeta’ does not name a type; did you mean ‘RCorePuts’?
 R_API RCodeMeta *ParseCodeXML(Funcdata *func, const char *xml) {

image

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
r2 -v
radare2 5.2.0-git 27528 @ linux-x86-64 git.5.6.0
commit: 8d678888a97d9aed4049d1a7467132c41ad6ffa7 build: 2022-02-08__21:17:09

Release binary?

@trufae , hi, thank you for your hard work on radare2.
I want to use pdg on windows, but it seems building r2ghidra need a higher version of visual studio which support at least c++14 I think, but I only have vs2013, so I can't compile it at all (got many errors relate to c++ stuff).
So there has any plan to release binary?

No sleigh specification for PowerPC:BE:32:default

OS: Android-Termux

i installed r2ghidra using those commands
r2pm update
r2pm -i r2ghidra
it then downloaded, compiled and installed everything, but when a try and actually use it it says this Ghidra Decompiler Error: No sleigh specification for PowerPC:BE:32:default
what can i do to fix this
thxs

r2pm -ci r2ghidra fails upon a CMake error on Ubuntu 16.04

$ r2 -v
radare2 5.3.1 1 @ linux-x86-64 git.
commit: d894f967e857a1cfa84144eb4bc0bdc87c540eee build: 2021-06-15__10:10:18
$ r2pm -ci r2ghidra
Cleaning r2ghidra...
clean Done For r2ghidra

...

-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:37 (if):
  if given arguments:

    "MSVC_VERSION" "GREATER_EQUAL" "1900"

  Unknown arguments specified


-- Configuring incomplete, errors occurred!

r2pm -ci

Hello, r2pm -ci r2ghidra command, isn't actually working as it seems, it'll falsely install and not allow me to properly use r2ghidra, is there any way I can fix this?

add the boolean check kwarg to the run_command call

add check:false to run_command

r2ghidra/meson.build

Lines 35 to 41 in 0799403

res = run_command(['r2','-HR2_LIBR_PLUGINS'], capture:true)
if res.returncode() == 0
r2_plugdir = res.stdout().strip()
else
prefix = get_option('prefix')
r2_plugdir = prefix + '/lib/radare2/plugins'
endif

WARNING: You should add the boolean check kwarg to the run_command call.
It currently defaults to false,
but it will default to true in future releases of meson.
See also: mesonbuild/meson#9300

r2pm -ci r2ghidra fails with strange error

I am running Kali Linux in WSL, and for some reason I can’t install r2ghidra. It compiles fine, but then the installation fails with this message:

: Leaving directory '/home/kali/.local/share/radare2/r2pm/git/r2ghidra/src' gmake: Entering directory '/home/kali/.local/share/radare2/r2pm/git/r2ghidra/src' mkdir -p mkdir: missing operand Try 'mkdir --help' for more information. gmake: *** [Makefile:86: install] Error 1 gmake: Leaving directory '/home/kali/.local/share/radare2/r2pm/git/r2ghidra/src'

I think this might be because line 83 in src/Makefile, PLUGDIR?=$(R2_LIBR_PLUGINS) doesn’t work for some reason, it looked like PLUGDIR is set to nothing.

Any ideas?

install error with r2pm

Describe the issue

trying to install with r2pm fails for me.

image

How to reproduce?

Idk install it via r2pm

Expected behavior

a successful install

Additional context
image

[Install error] cannot stat 'sleighc': No such file or directory

I'm trying to install this plugin via r2pm but I'm this error (as in below screenshot)

image

Commands used to install:-

r2pm -U
r2pm -ci r2ghidra

I'm on 6.0.6-arch1-1 with radare2 installed via github (not by package manager).

5.7.8-551-gf05b4e2eba  r2
5.7.8-551-gf05b4e2eba  r_anal
5.7.8-551-gf05b4e2eba  r_lib
5.7.8-551-gf05b4e2eba  r_egg
5.7.8-551-gf05b4e2eba  r_asm
5.7.8-551-gf05b4e2eba  r_bin
5.7.8-551-gf05b4e2eba  r_cons
5.7.8-551-gf05b4e2eba  r_flag
5.7.8-551-gf05b4e2eba  r_core
5.7.8-551-gf05b4e2eba  r_crypto
5.7.8-551-gf05b4e2eba  r_bp
5.7.8-551-gf05b4e2eba  r_debug
5.7.8-551-gf05b4e2eba  r_main
5.7.8-551-gf05b4e2eba  r_fs
5.7.8-551-gf05b4e2eba  r_io
5.7.8-551-gf05b4e2eba  r_magic
5.7.8-551-gf05b4e2eba  r_parse
5.7.8-551-gf05b4e2eba  r_reg
5.7.8-551-gf05b4e2eba  r_sign
5.7.8-551-gf05b4e2eba  r_search
5.7.8-551-gf05b4e2eba  r_syscall
5.7.8-551-gf05b4e2eba  r_util

pdg gives not c-style format

Description

Please describe what are you missing or wanting to be improved

Hello. I am using r2ghidra after I installed r2 from source and r2ghidra from r2pm -ci r2ghidra.
When I type pdg in r2, it shows us not c-style source code rather similar to xml or something.
I have searched it but I could not find how to change the output format.

Provide images, ascii-art, test files and anything that may help us understand your request

<function>
<funcproto><return_type>void</return_type> main(void)</funcproto>

{
    <vardecl symref="0x400001000000001d">uint uVar1</vardecl>;
    <vardecl symref="0x400001000000001e">code cVar2</vardecl>;
    <vardecl symref="0x400001000000001f">int32_t iVar3</vardecl>;

// ...

Allow using system pugixml for build

I ended up patching meson.build by myself:

From 971fdf012c6c48e43e00d91727698ace4b0c67a6 Mon Sep 17 00:00:00 2001
From: Maxim Karasev <[email protected]>
Date: Fri, 23 Dec 2022 22:27:24 +0300
Subject: [PATCH] Use system pugixml

---
 meson.build | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/meson.build b/meson.build
index e35d4f7..a5788c9 100644
--- a/meson.build
+++ b/meson.build
@@ -7,10 +7,6 @@ version : '5.8.0',
 default_options : ['c_std=c11', 'cpp_std=c++11']
 )
 
-pugixml_sources = [
-  'third-party/pugixml/src/pugixml.cpp'
-]
-
 r2ghidra_sources = [
   'src/ArchMap.cpp',
   'src/CodeXMLParse.cpp',
@@ -28,7 +24,6 @@ r2ghidra_sources = [
 
 incdirs = [
   'src',
-  'third-party/pugixml/src/',
   'ghidra-native/src/decompiler/',
 ]
 
@@ -178,7 +173,6 @@ ghidra_decompiler_sources = [
 
 r2ghidra_core_sources = [
   r2ghidra_sources,
-  pugixml_sources,
   ghidra_decompiler_sources,
   'src/anal_ghidra_plugin.c',
   'src/anal_ghidra.cpp',
@@ -188,16 +182,17 @@ r2ghidra_core_sources = [
 
 sleighc_sources = [
   r2ghidra_sources,
-  pugixml_sources,
   'ghidra-native/src/decompiler/slgh_compile.cc',
   'ghidra-native/src/decompiler/slghparse.cc',
   'ghidra-native/src/decompiler/slghscan.cc',
   ghidra_decompiler_sources,
 ]
 
+pugixml = dependency('pugixml')
+
 r2ghidra_core_plugin = library('core_r2ghidra',
   r2ghidra_core_sources,
-  dependencies: [r_core],
+  dependencies: [r_core, pugixml],
   override_options : ['c_std=c11', 'cpp_std=c++11'],
   include_directories: r2ghidra_incdirs,
   install: true,
@@ -207,6 +202,6 @@ r2ghidra_core_plugin = library('core_r2ghidra',
 sleighc_exe = executable('sleighc', sleighc_sources,
   include_directories: r2ghidra_incdirs,
   override_options : ['c_std=c11', 'cpp_std=c++11'],
-  dependencies: [r_core],
+  dependencies: [r_core, pugixml],
   install: true
 )
-- 
2.39.0

Would be nice to have such ability as an option in upstream.

XML error parsing SLEIGH file for riscv

Describe the issue

unable to emulate riscv

How to reproduce?

  1. install plugin r2pm -ci r2ghidra
  2. check support for emulation rasm2 -L (shows _dAe ... r2ghidra)
  3. compile a c file using
    riscv64-linux-gnu-gcc hello-world.c -o hello-world
    or even
    clang --target=riscv64 -march=rv64gc -c hello-world.c (linking appears to have issues on clang)

try to emulate

r2 -a r2ghidra -e asm.cpu=riscv hello-world

goto asm page

see error
image

Expected behavior

radare2 opens file and can step through assembly via ESIL

Building r2ghidra on Termux fails due to lack of sudo

Hello, after running:

r2pm init
r2pm update
r2pm -ci r2ghidra

I have the following error:

[ 99%] Linking CXX shared library asm_ghidra.so   
[ 99%] Built target asm_ghidra                    
17 warnings generated.                            
[100%] Linking CXX shared library anal_ghidra.so  [100%] Built target anal_ghidra                   
/data/data/com.termux/files/usr/bin/r2pm: 18: sudo: not found

r2ghidra was able to install with previous versions, but from doing a bit of research, termux does not have sudo out of the box. Any help would be greatly appreciated and I would be happy to provide some assistance with this bug.
Thank you.

Build failure when compiling x86-64.slaspec

Build Log:

...
Compiling (2 of 2) ../ghidra-native/src/Processors/x86/data/languages/x86-64.slaspec
WARN  247 NOP constructors found
WARN  Use -n switch to list each individually
WARN  201 unnecessary extensions/truncations were converted to copies
WARN  Use -u switch to list each individually
WARN  13 operations wrote to temporaries that were not read
WARN  Use -t switch to list each individually
Unrecoverable error: Child has as many Patterns as parent
make[1]: *** [deps.mk:121: sleigh-build] Error 2
make[1]: Leaving directory '/usr/src/r2ghidra-5.5.2/ghidra'
make: *** [Makefile:9: all] Error 2

x86 - missing strings in decompilation

cat hello.c

#include <unistd.h>
#include <stdio.h>

void  main() {
	unsigned int t = 1;

	while (1) {
		printf("Hi r2con: %d\n", 2019);
		sleep(t);
	}
}

Decompilation

[0x00001130]> pdg

void main(void)

{
    int32_t var_14h;
    int32_t var_10h;
    int32_t var_ch;
    int32_t s;
    
    do {
        sym.imp.printf(0x2000, 0x7e3);
        sym.imp.sleep(1);
    } while( true );
}

Sample

hello_avd_x86.zip

Configure error when trying to install r2ghidra

Here's the output:

$ r2pm -ci r2ghidra
Cleaning r2ghidra...
DEPENDS: r2ghidra-sleigh
Sat Jul  9 11:18:22 PM +03 2022
clean Done For r2ghidra
/home/mathway/.local/share/radare2/r2pm/db/r2ghidra TGZ=
Cleaning up /home/mathway/.local/share/radare2/r2pm/git/r2ghidra...
HEAD is now at 086ec3e Add r2premium package to r2pm (#141)
Updating 086ec3e..2c70f2c
Fast-forward
 db/r2ghidra-sleigh |  2 +-
 db/v               | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 db/v
[r2pm] Updating package database /home/mathway/.local/share/radare2/r2pm/db ...
Already up to date.
error: pathspec 'r2-5.5.0' did not match any file(s) known to git
Already up to date.
DEPENDS: r2ghidra-sleigh
Sat Jul  9 11:18:22 PM +03 2022
Install Done For r2ghidra
git clone https://github.com/radareorg/ghidra-native
Cloning into 'ghidra-native'...
cd ghidra-native && git checkout 0.2.0
Note: switching to '0.2.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 2444a81 Update version number
gmake -C ghidra-native patch
gmake[1]: Entering directory '/home/mathway/.local/share/radare2/r2pm/git/r2ghidra/ghidra-native'
for a in patches/0001-space-after-comma.patch patches/0002-make-sleigharch-public.patch patches/0004-public-fields.patch patches/00067-readonly-warning.patch patches/0020-Fix-double-free-crash-when-deinitializing-multiple-X.patch patches/0022-Show-noreturn-information-in-function-signature-2.patch patches/0023-Undef-LoadImage-for-windows.patch patches/0024-ignore-symbol-beyond-space.patch patches/0044-bad-unicode-codepoint.patch patches/0055-datatype-clone.patch patches/0056-nullderef-workaround.patch patches/0090-nocasts-warnings.patch ; do echo "patch -p1 < $a" ; patch -p1 < $a ; done
patch -p1 < patches/0001-space-after-comma.patch
patching file src/decompiler/printc.cc
Hunk #2 succeeded at 1907 (offset 46 lines).
Hunk #3 succeeded at 2006 (offset 46 lines).
Hunk #4 succeeded at 2025 (offset 46 lines).
Hunk #5 succeeded at 2478 (offset 46 lines).
patch -p1 < patches/0002-make-sleigharch-public.patch
patching file src/decompiler/sleigh_arch.hh
patch -p1 < patches/0004-public-fields.patch
patching file src/decompiler/context.hh
patching file src/decompiler/sleigh.hh
Hunk #1 succeeded at 167 (offset 1 line).
patch -p1 < patches/00067-readonly-warning.patch
patching file src/decompiler/funcdata_varnode.cc
patch -p1 < patches/0020-Fix-double-free-crash-when-deinitializing-multiple-X.patch
patching file src/decompiler/xml.cc
patching file src/decompiler/xml.hh
patch -p1 < patches/0022-Show-noreturn-information-in-function-signature-2.patch
patching file src/decompiler/prettyprint.cc
patching file src/decompiler/prettyprint.hh
patching file src/decompiler/printc.cc
Hunk #1 succeeded at 2358 (offset 46 lines).
patch -p1 < patches/0023-Undef-LoadImage-for-windows.patch
patching file src/decompiler/loadimage.hh
patch -p1 < patches/0024-ignore-symbol-beyond-space.patch
patching file src/decompiler/database.cc
patch -p1 < patches/0044-bad-unicode-codepoint.patch
patching file src/decompiler/stringmanage.cc
patch -p1 < patches/0055-datatype-clone.patch
patching file src/decompiler/type.hh
patch -p1 < patches/0056-nullderef-workaround.patch
patching file src/decompiler/merge.hh
patch -p1 < patches/0090-nocasts-warnings.patch
patching file src/decompiler/printc.cc
Hunk #1 succeeded at 3097 (offset 2 lines).
Hunk #2 succeeded at 3106 (offset 2 lines).
touch patch.done
gmake[1]: Leaving directory '/home/mathway/.local/share/radare2/r2pm/git/r2ghidra/ghidra-native'
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for working directories... current
using prefix '/usr'
checking for c++ compiler... c++
checking for cpp... cpp
checking for git... /usr/bin/git
checking for pkg-config... /usr/bin/pkg-config
Using PKGCONFIG: /usr/bin/pkg-config
checking pkg-config flags for r_core... no
This package is required
ERROR: configure

I am using up-to-date Kali linux distro.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.