wargio / r2dec-js

radare2 plugin - converts asm to pseudo-C code.
514 stars 50 forks source link

Compiling under windows #177

Closed q8ing closed 5 years ago

q8ing commented 5 years ago

Hello,

When I tried to compile it under windows, I got the following error:

C:>cd r2dec-js

C:\r2dec-js>make -C p The system cannot find the path specified. The system cannot find the path specified. The system cannot find the path specified. The system cannot find the path specified. The system cannot find the path specified. The system cannot find the path specified. make: Entering directory C:/r2dec-js/p' 'rm' is not recognized as an internal or external command, operable program or batch file. 'sleep' is not recognized as an internal or external command, operable program or batch file. make: *** [clean] Error 1 make: Leaving directoryC:/r2dec-js/p'

Any solution, please?

wargio commented 5 years ago

oh, please use meson under windows or a unix shell like cygwin or msys2 to build.

Maijin commented 5 years ago

Maybe update this @wargio - https://github.com/wargio/r2dec-js#windows-users-only

wargio commented 5 years ago

yes, you are right. i'd like to have a confirmation from @q8ing

q8ing commented 5 years ago

Thank you for your replay. At the beginning I thought I could compile It using make on windows OS, because the instructions didn't mention anything about meson. I tried meson, but I got the following error:

C:\cmd\radare2>meson C:\cmd\r2dec-js\p The Meson build system Version: 0.51.999 Source dir: C:\cmd\r2dec-js\p Build dir: C:\cmd\radare2 Build type: native build Project name: r2dec Project version: undefined C compiler for the build machine: gcc (gcc 8.2.0 "gcc (MinGW.org GCC-8.2.0-3) 8.2.0") C compiler for the host machine: gcc (gcc 8.2.0 "gcc (MinGW.org GCC-8.2.0-3) 8.2.0") Build machine cpu family: x86 Build machine cpu: x86 Program radare2 found: YES (C:\cmd\radare2\bin\radare2.EXE) Library r_core found: YES Library r_util found: YES Library r_cons found: YES Library r_config found: YES Library r_io found: YES Library m found: YES

meson.build:42:0: ERROR: Include dir C:/cmd/radare2/bin/./include does not exist.

A full log can be found at C:\cmd\radare2\meson-logs\meson-log.txt

C:\cmd\radare2>


I don't know how to modify include path, because windows doesn't allow me to create a directory with (. ) as a name.

wargio commented 5 years ago

the . directory is the same directory.

xarkes commented 5 years ago

I think there's a mistake with the include directory. I don't know where/how it's introduced, but you could try to copy it in your bin folder.

q8ing commented 5 years ago

Yeah, I copied it to the directory and It solved the problem, But I got another problem, I think it is related to the compiler. I am using the latest version of mingw32 gcc compiler. Any help is appreciated.

C:\cmd\r2dec-js>ninja
[1/3] Compiling C object core_pdd@sha/duktape_duk_console.c.obj.
FAILED: core_pdd@sha/duktape_duk_console.c.obj
gcc @core_pdd@sha/duktape_duk_console.c.obj.rsp
In file included from c:\cmd\radare2\bin\include\r_cons.h:19,
                 from p/duktape/duk_console.c:13:
c:\cmd\radare2\bin\include\r_util\r_sys.h:100:10: fatal error: intrin.h: No such file or directory
 #include <intrin.h>
          ^~~~~~~~~~
compilation terminated.
[2/3] Compiling C object core_pdd@sha/core_pdd.c.obj.
FAILED: core_pdd@sha/core_pdd.c.obj
gcc @core_pdd@sha/core_pdd.c.obj.rsp
In file included from c:\cmd\radare2\bin\include\r_util.h:13,
                 from c:\cmd\radare2\bin\include\r_cmd.h:5,
                 from p/core_pdd.c:12:
c:\cmd\radare2\bin\include\r_th.h:13:21: error: unknown type name 'CONDITION_VARIABLE'
 #define R_TH_COND_T CONDITION_VARIABLE
                     ^~~~~~~~~~~~~~~~~~
c:\cmd\radare2\bin\include\r_th.h:55:2: note: in expansion of macro 'R_TH_COND_T'
  R_TH_COND_T cond;
  ^~~~~~~~~~~
In file included from c:\cmd\radare2\bin\include\r_util.h:64,
                 from c:\cmd\radare2\bin\include\r_cmd.h:5,
                 from p/core_pdd.c:12:
c:\cmd\radare2\bin\include\r_util/r_sys.h:100:10: fatal error: intrin.h: No such file or directory
 #include <intrin.h>
          ^~~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.

C:\cmd\r2dec-js>
q8ing commented 5 years ago

I used the 64 bit version of Mingw and I have compiled it successfully. I tried pdd? But it is not decompiling the file.

C:\cmd>radare2 crackme0x05.exe -- THIS IS NOT FUNNY [0x00401260]> pdd? ;-- entry0: ;-- _mainCRTStartup: ;-- eip: 0x00401260 55 push ebp 0x00401261 89e5 mov ebp, esp 0x00401263 83ec08 sub esp, 8 0x00401266 c70424010000. mov dword [esp], 1 0x0040126d ff1508614000 call dword [sym.imp.msvcrt.dll_set_apptype] ; 0x406108 ; "Lb" 0x00401273 e8c8feffff call sym.mingw_CRTStartup 0x00401278 90 nop 0x00401279 8db426000000. lea esi, [esi] ;-- _WinMainCRTStartup: 0x00401280 55 push ebp 0x00401281 89e5 mov ebp, esp 0x00401283 83ec08 sub esp, 8 0x00401286 c70424020000. mov dword [esp], 2 0x0040128d ff1508614000 call dword [sym.imp.msvcrt.dll_set_apptype] ; 0x406108 ; "Lb" 0x00401293 e8a8feffff call sym.mingw_CRTStartup 0x00401298 90 nop 0x00401299 8db426000000. lea esi, [esi] ;-- _atexit: 0x004012a0 55 push ebp 0x004012a1 8b0d24614000 mov ecx, dword sym.imp.msvcrt.dll_atexit ; [0x406124:4]=0x62a0 reloc.msvcrt.dll_atexit 0x004012a7 89e5 mov ebp, esp 0x004012a9 5d pop ebp 0x004012aa ffe1 jmp ecx 0x004012ac 8d742600 lea esi, [esi]


Any help is appreciated.

xarkes commented 5 years ago

You have to move the pdd .dll file inside your radare2 plugins folder.

pelijah commented 5 years ago

And set R2DEC_HOME env variable or copy whole r2dec-js dir to %R2_RDATAHOME%\r2pm\git\ where %R2_RDATAHOME% is path returned by radare2.exe -H R2_RDATAHOME.

q8ing commented 5 years ago

Thank you guys for helping me. I did everything you told me. I used "radare2 -H" to get plugins directory path and after I moved .dll and .lib files to plugins directory, I got this error when i ran radare2

1

I have no idea how to solve it.

pelijah commented 5 years ago

You can upload an image right here.

xarkes commented 5 years ago

I think you should not copy the lib, only the dll.

q8ing commented 5 years ago

I think you should not copy the lib, only the dll.

I had already done that before and radare2 crashed when I used "pdd" plugin. Here is an image to show you what I mean:

1

and

2

Maijin commented 5 years ago

@q8ing Can you paste the output of radare2 -v and radare2 -V ?

q8ing commented 5 years ago

@q8ing Can you paste the output of radare2 -v and radare2 -V ?

C:\cmd>radare2 -v radare2 3.6.0 1 @ windows-x86-64 git.3.6.0 commit: ff3bb6e3b2e6a519b4c975d05758c171a5186389 build: Mon 06/24/2019__15:10:34.53

C:\cmd>radare2 -V 3.6.0 r2 3.6.0 r_anal 3.6.0 r_lib 3.6.0 r_egg 3.6.0 r_asm 3.6.0 r_bin 3.6.0 r_cons 3.6.0 r_flag 3.6.0 r_core 3.6.0 r_crypto 3.6.0 r_bp 3.6.0 r_debug 3.6.0 r_main 3.6.0 r_hash 3.6.0 r_fs 3.6.0 r_io 3.6.0 r_magic 3.6.0 r_parse 3.6.0 r_reg 3.6.0 r_sign 3.6.0 r_search 3.6.0 r_syscall 3.6.0 r_util

pelijah commented 5 years ago

So do you want to use 32-bit dll with 64-bit app?

q8ing commented 5 years ago

So do you want to use 32-bit dll with 64-bit app?

How can I build r2dec-js for 64 bit version? could you help me, please?

pelijah commented 5 years ago

Maybe MinGW64? You can also get core_pdd.dll from a Cutter dist https://github.com/radareorg/cutter/releases (goto radare2\lib\plugins\ subdir).

q8ing commented 5 years ago

Maybe MinGW64? You can also get core_pdd.dll from a Cutter dist https://github.com/radareorg/cutter/releases (goto radare2\lib\plugins\ subdir).

I had already compiled it using Mingw64 version. I tried "core_pdd.dll" from Cutter and it worked without any problems.

[0x00401260]> aaaa [x] Analyze all flags starting with sym. and entry0 (aa) [x] Analyze function calls (aac) [x] Analyze len bytes of instructions for references (aar) [x] Check for objc references [x] Check for vtables [x] Type matching analysis for all functions (aaft) [x] Use -AA or aaaa to perform additional experimental analysis. [x] Finding function preludes [x] Enable constraint types analysis for variables [0x00401260]> pdd / r2dec pseudo code output / / crackme0x05.exe @ 0x401260 /

include

void entry0 (void) { _set_app_type (1); _mingw_CRTStartup (); _set_app_type (2); _mingw_CRTStartup (); } [0x00401260]>

I have no idea why the compiled version is not working!!!

Thank you for your help.

pelijah commented 5 years ago

Well, sorry, I didn't notice your comments about MinGW64 and working pdd? command. In fine, r2 loads and initializes r2dec plugin, but plugin crashes when you call pdd. So you can try to debug it.

q8ing commented 5 years ago

I'll close this issue and I wish the developers will solve the problem related to .dll. Also, It would be better If the instructions for compiling under Windows are updated.

Thank you very much guys.

wargio commented 5 years ago

fixed instructions on how to build it on windows. thanks for the issue :)

q8ing commented 5 years ago

You are always welcome my friend :)))