wargio / r2dec-js

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

Remove duktape and use QuickJS #295

Closed wargio closed 10 months ago

wargio commented 1 year ago

@trufae this adds support to r2dec to use quickjs unfortunately i couldn't use the code you implemented because i wanted to also support the ci. i had to remove the Makefile version.

trufae commented 1 year ago

Cool! happy to see the relative paths. But i can't get it to compile:

With make

0$ make -C p
/Applications/Xcode.app/Contents/Developer/usr/bin/make build
make[1]: *** No rule to make target `duktape/duktape.o', needed by `core_pdd.dylib'.  Stop.
make: *** [all] Error 2
2$

and i assume you will deprecate the makefile :? and abandon the p directory where the duktape code was, so this is a leftover i guess.

With meson/ninja

0$ ninja -C b
ninja: Entering directory `b'
[13/18] Generating js/bytecode.h with a custom command
FAILED: js/bytecode.h
/Users/pancake/prg/r2js/b/subprojects/libquickjs/qjsc ../js/r2dec-plugin.js -m -N main_bytecode -c -o js/bytecode.h
Could not load '-m'
ninja: build stopped: subcommand failed.
1$

the fix is this:

0$ git diff
diff --git a/js/meson.build b/js/meson.build
index 364905c..c993154 100644
--- a/js/meson.build
+++ b/js/meson.build
@@ -9,14 +9,14 @@ if get_option('standalone')
       'bytecode.h',
       output : 'bytecode.h',
       input : r2dec_testsuite,
-      command : [qjsc, '@INPUT@', '-m', '-N', 'main_bytecode', '-c', '-o', '@OUTPUT@'],
+      command : [qjsc, '-m', '-N', 'main_bytecode', '-c', '-o', '@OUTPUT@', '@INPUT@'],
   )
 else
   bytecode_h = custom_target(
       'bytecode.h',
       output : 'bytecode.h',
       input : r2dec_plugin,
-      command : [qjsc, '@INPUT@', '-m', '-N', 'main_bytecode', '-c', '-o', '@OUTPUT@'],
+      command : [qjsc, '-m', '-N', 'main_bytecode', '-c', '-o', '@OUTPUT@', '@INPUT@'],
   )
 endif

@@ -25,4 +25,4 @@ bytecode_mod_h = custom_target(
     output : 'bytecode_mod.h',
     input : bytecode_h,
     command : [modjs_gen, '@INPUT@', '@OUTPUT@'],
-)
\ No newline at end of file
+)
0$

after this i managed to get it working, at least with small functions. otherwise i get an error (which maybe affects master, didnt tried) a.zip <-

another thing i noticed is this CC error:

[0x100003a84]> pddi
ERROR: Missing space after CC
Do you want to print 1 lines? (y/N)
[0x100003a84]>

Do you have some numbers about the performance? hope the whole codebase gets some es6 improvements after merging this

wargio commented 1 year ago

i haven't tested time differences.

trufae commented 10 months ago

So it is ready for testing then? i can make up some numbers

wargio commented 10 months ago

looks like there are some issues on windows (tests) but for me can be tested

wargio commented 10 months ago

i need to still apply your changes

wargio commented 10 months ago

I have fixed windows build and the issue you had. i cannot tho fix the debian package or the macos one

trufae commented 10 months ago

I did some tests: r2 -q -c af -c '?t pdd' /bin/ls

building with meson b --buildtype=release

is there a way to install the plugin in the home? because ninja -C b install is putting things in the system path always

wargio commented 10 months ago

is there a way to install the plugin in the home? because ninja -C b install is putting things in the system path always

just do --prefix=whatever

trufae commented 10 months ago

yeah thing is that home directory doesnt follow system structure, but thats not really a blocker for me, so im good to get this merged. i have a bunch of other improvements but i would prefer to get this merged before moving forward.

Good work!