Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r2dec seems broken as of 9646f560d169ab684ff67f2fbf6f8b3c61588bb4 #296

Open
dguerri opened this issue Nov 23, 2023 · 14 comments
Open

r2dec seems broken as of 9646f560d169ab684ff67f2fbf6f8b3c61588bb4 #296

dguerri opened this issue Nov 23, 2023 · 14 comments

Comments

@dguerri
Copy link

dguerri commented Nov 23, 2023

with r2pm:

❯ r2pm -ci r2dec
INFO: Cleaning r2dec
INFO: Using r2-5.8.9 and r2pm-5.8.9
INFO: Cleaning r2dec
INFO: git clone --depth=10 --recursive https://github.com/wargio/r2dec-js /root/.local/share/radare2/r2pm/git//r2dec
Cloning into '/root/.local/share/radare2/r2pm/git//r2dec'...
remote: Enumerating objects: 258, done.
remote: Counting objects: 100% (258/258), done.
remote: Compressing objects: 100% (197/197), done.
remote: Total 258 (delta 87), reused 170 (delta 52), pack-reused 0
Receiving objects: 100% (258/258), 1.50 MiB | 6.85 MiB/s, done.
Resolving deltas: 100% (87/87), done.
INFO: Starting install for r2dec
INFO: R2PM_NEEDS: Found python3 in PATH
INFO: R2PM_NEEDS: Found gcc in PATH
INFO: R2PM_NEEDS: Found make in PATH
INFO: SCRIPT=<<EOF
INFO: 	export CFLAGS='-DR2DEC_HOME="${R2PM_GITDIR}/r2dec"'
	${MAKE} -C p USE_JSC=1 V= || exit 1
	if [ "${GLOBAL}" = 1 ]; then
		${MAKE} -C p uninstall
		${MAKE} -C p install V= USE_JSC=1 || exit 1
	else
		${MAKE} -C p user-uninstall
		${MAKE} -C p user-install V= USE_JSC=1 || exit 1
	fi
INFO: EOF
make: Entering directory '/root/.local/share/radare2/r2pm/git/r2dec/p'
make: *** No rule to make target 'r2dec_jsc.c.in', needed by 'r2dec_jsc.c'.  Stop.
make: Leaving directory '/root/.local/share/radare2/r2pm/git/r2dec/p'

Manually:

cd /root/.local/share/radare2/r2pm/git/r2dec/
❯ export CFLAGS='-DR2DEC_HOME="/root/.local/share/radare2/r2pm/git/r2dec/"'
❯ make  -C p USE_JSC=1 V=
make: Entering directory '/root/.local/share/radare2/r2pm/git/r2dec/p'
make: *** No rule to make target 'r2dec_jsc.c.in', needed by 'r2dec_jsc.c'.  Stop.
make: Leaving directory '/root/.local/share/radare2/r2pm/git/r2dec/p'
❯ make  -C p USE_JSC=0 V=
make: Entering directory '/root/.local/share/radare2/r2pm/git/r2dec/p'
make build
make[1]: Entering directory '/root/.local/share/radare2/r2pm/git/r2dec/p'
make[1]: *** No rule to make target 'duktape/duktape.o', needed by 'core_pdd.so'.  Stop.
make[1]: Leaving directory '/root/.local/share/radare2/r2pm/git/r2dec/p'
make: *** [Makefile:39: all] Error 2
make: Leaving directory '/root/.local/share/radare2/r2pm/git/r2dec/p'
@dguerri
Copy link
Author

dguerri commented Nov 23, 2023

commit 6ba7ae5 works:

❯ git checkout 6ba7ae5
Note: switching to '6ba7ae5'.

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 6ba7ae5 Add missing "b.le" on arm
❯ make  -C p USE_JSC=1 V=
make: Entering directory '/root/.local/share/radare2/r2pm/git/r2dec/p'
awk '{if(/@JSC_SOURCES@/)exit;print}' < r2dec_jsc.c.in > r2dec_jsc.c
python make_jsc.py .. >> r2dec_jsc.c
awk 'BEGIN{A=0}{if(A==1){print}if(/@JSC_SOURCES@/)A=1}' < r2dec_jsc.c.in >> r2dec_jsc.c
make build
make[1]: Entering directory '/root/.local/share/radare2/r2pm/git/r2dec/p'
echo "[CC] duktape/duktape.o"
[CC] duktape/duktape.o
cc -DR2DEC_HOME="/root/.local/share/radare2/r2pm/git/r2dec/" -g -O3 -std=c99 -Wall -fPIC -I./duktape -DUSE_JSC=1 -g -O3 -std=c99 -Wall -fPIC -I./duktape -DUSE_JSC=1 -I/usr/local/include/libr -c duktape/duktape.c -o duktape/duktape.o
echo "[CC] duktape/duk_console.o"
[CC] duktape/duk_console.o
cc -DR2DEC_HOME="/root/.local/share/radare2/r2pm/git/r2dec/" -g -O3 -std=c99 -Wall -fPIC -I./duktape -DUSE_JSC=1 -g -O3 -std=c99 -Wall -fPIC -I./duktape -DUSE_JSC=1 -I/usr/local/include/libr -c duktape/duk_console.c -o duktape/duk_console.o
echo "[CC] core_pdd.o"
[CC] core_pdd.o
cc -DR2DEC_HOME="/root/.local/share/radare2/r2pm/git/r2dec/" -g -O3 -std=c99 -Wall -fPIC -I./duktape -DUSE_JSC=1 -g -O3 -std=c99 -Wall -fPIC -I./duktape -DUSE_JSC=1 -I/usr/local/include/libr -c core_pdd.c -o core_pdd.o
echo "[CC] core_pdd.so"
[CC] core_pdd.so
cc -lm -L/usr/local/lib -lr_core -lr_config -ldl -lr_debug -ldl -lr_bin -ldl -lr_lang -ldl -lr_anal -ldl -lr_bp -ldl -lr_egg -ldl -lr_asm -ldl -lr_flag -ldl -lr_search -ldl -lr_syscall -ldl -lr_fs -ldl -lr_io -ldl -lr_socket -ldl -lr_cons -ldl -lr_magic -ldl -lr_crypto -ldl -lr_arch -ldl -lr_esil -ldl -lr_reg -ldl -lr_util -ldl -shared duktape/duktape.o duktape/duk_console.o core_pdd.o -o core_pdd.so
make[1]: Leaving directory '/root/.local/share/radare2/r2pm/git/r2dec/p'
make: Leaving directory '/root/.local/share/radare2/r2pm/git/r2dec/p'

Radare2 version 5.8.9 (although, looking at the latest r2dec commits, I don't think it matters)

❯ radare2 -v
radare2 5.8.9 31530 @ linux-x86-64
birth: git.5.8.8-888-g4ceb8ebba3 2023-11-23__19:36:13
commit: 4ceb8ebba36c9aefa6803f70e88248469b486f87
options: gpl -O? cs:5 cl:2 make

@wargio
Copy link
Owner

wargio commented Nov 24, 2023

yes ofc. @trufae you should use tags not master as is, unless you update it to use meson and the new folder structure.

@trufae
Copy link
Contributor

trufae commented Nov 24, 2023

I updated the package and it should work. Did you updated the database?

@wargio
Copy link
Owner

wargio commented Nov 24, 2023

@dguerri please confirm this is fixed and close the issue :)

@trufae
Copy link
Contributor

trufae commented Nov 24, 2023

r2pm -Uci r2dec

-U updates the database
There’s also r2dec-duk which picks then last commit that used duktape. The default pkg uses master

@dguerri
Copy link
Author

dguerri commented Nov 24, 2023

It seems to be failing silently as b doesn't contain a valid build tree:

❯ r2pm -Uci r2dec
INFO: Nothing to upgrade
INFO: Cleaning r2dec
INFO: Using r2-5.8.9 and r2pm-5.8.9
INFO: Cleaning r2dec
INFO: git clone --depth=10 --recursive https://github.com/wargio/r2dec-js /root/.local/share/radare2/r2pm/git//r2dec
Cloning into '/root/.local/share/radare2/r2pm/git//r2dec'...
remote: Enumerating objects: 258, done.
remote: Counting objects: 100% (258/258), done.
remote: Compressing objects: 100% (197/197), done.
remote: Total 258 (delta 87), reused 170 (delta 52), pack-reused 0
Receiving objects: 100% (258/258), 1.50 MiB | 7.04 MiB/s, done.
Resolving deltas: 100% (87/87), done.
INFO: Starting install for r2dec
INFO: R2PM_NEEDS: Found gcc in PATH
INFO: R2PM_NEEDS: Found make in PATH
INFO: R2PM_NEEDS: Found ninja in PATH
INFO: SCRIPT=<<EOF
INFO: 	meson b --reconfigure || exit 1
	( cd b && ninja ) || exit 1
	if [ "${GLOBAL}" = 1 ]; then
		${R2PM_SUDO} ninja uninstall
		${R2PM_SUDO} ninja install V= USE_JSC=1 || exit 1
	else
		mkdir -p ${R2PM_PLUGDIR}
		cp -f b/libcore_pdd.${R2_LIBEXT} ${R2PM_PLUGDIR}
		echo "${R2PM_PLUGDIR}/libcore_pdd.${R2_LIBEXT}"
	fi
INFO: EOF
Directory does not contain a valid build tree:
/root/.local/share/radare2/r2pm/git/r2dec/b
❯ echo $?
0

@dguerri
Copy link
Author

dguerri commented Nov 24, 2023

This worked:

cd /root/.local/share/radare2/r2pm/git/r2dec
meson . b
ninja install

@dguerri
Copy link
Author

dguerri commented Nov 24, 2023

I think it's somehow trying to use the old build "system" with meson and ninja instead of make

@trufae
Copy link
Contributor

trufae commented Nov 24, 2023

works fine here

0$ r2pm -ci r2dec
INFO: Cleaning r2dec
INFO: Using r2-5.8.9 and r2pm-5.8.9
INFO: Cleaning r2dec
INFO: git clone --depth=10 --recursive https://github.com/wargio/r2dec-js /Users/pancake/.local/share/radare2/r2pm/git//r2dec
Cloning into '/Users/pancake/.local/share/radare2/r2pm/git//r2dec'...
remote: Enumerating objects: 258, done.
remote: Counting objects: 100% (258/258), done.
remote: Compressing objects: 100% (197/197), done.
remote: Total 258 (delta 87), reused 170 (delta 52), pack-reused 0
Receiving objects: 100% (258/258), 1.50 MiB | 5.97 MiB/s, done.
Resolving deltas: 100% (87/87), done.
INFO: Starting install for r2dec
INFO: R2PM_NEEDS: Found gcc in PATH
INFO: R2PM_NEEDS: Found make in PATH
INFO: R2PM_NEEDS: Found ninja in PATH
INFO: SCRIPT=<<EOF
INFO: 	meson b --reconfigure || exit 1
	( cd b && ninja ) || exit 1
	if [ "${GLOBAL}" = 1 ]; then
		${R2PM_SUDO} ninja uninstall
		${R2PM_SUDO} ninja install V= USE_JSC=1 || exit 1
	else
		mkdir -p ${R2PM_PLUGDIR}
		cp -f b/libcore_pdd.${R2_LIBEXT} ${R2PM_PLUGDIR}
		echo "${R2PM_PLUGDIR}/libcore_pdd.${R2_LIBEXT}"
	fi
INFO: EOF
The Meson build system
Version: 1.2.3
Source dir: /Users/pancake/.local/share/radare2/r2pm/git/r2dec
Build dir: /Users/pancake/.local/share/radare2/r2pm/git/r2dec/b
Build type: native build
Project name: r2dec
Project version: undefined
C compiler for the host machine: cc (clang 15.0.0 "Apple clang version 15.0.0 (clang-1500.0.40.1)")
C linker for the host machine: cc ld64 1015.7
Host machine cpu family: aarch64
Host machine cpu: aarch64
Cloning into 'libquickjs'...
remote: Enumerating objects: 544, done.
remote: Counting objects: 100% (349/349), done.
remote: Compressing objects: 100% (96/96), done.
remote: Total 544 (delta 289), reused 253 (delta 253), pack-reused 195
Receiving objects: 100% (544/544), 1.85 MiB | 3.75 MiB/s, done.
Resolving deltas: 100% (389/389), done.
HEAD is now at c81f05c Fix unclean double<>int64 comparisons (#6)

Executing subproject libquickjs

libquickjs| Project name: quickjs
libquickjs| Project version: 2021-03-27-frida
libquickjs| C compiler for the host machine: cc (clang 15.0.0 "Apple clang version 15.0.0 (clang-1500.0.40.1)")
libquickjs| C linker for the host machine: cc ld64 1015.7
libquickjs| Run-time dependency threads found: YES
libquickjs| Library dl found: YES
libquickjs| Library m found: YES
libquickjs| Has header "unistd.h" : YES
libquickjs| Checking for function "malloc_usable_size" : NO
libquickjs| Configuring config.h using configuration
libquickjs| Build targets in project: 2
libquickjs| Subproject libquickjs finished.

Program radare2 found: YES (/usr/local/bin/radare2)
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
Message: radare2 include dir: /usr/local/include/libr
Message: radare2 library dir: /usr/local/lib
Message: radare2 plugin dir:  /usr/local/lib/radare2/5.8.9
Build targets in project: 6

r2dec undefined

  Subprojects
    libquickjs: YES

Found ninja-1.11.1 at /opt/homebrew/bin/ninja
WARNING: Running the setup command as `meson [options]` instead of `meson setup [options]` is ambiguous and deprecated.
[6/18] Linking target modjs_gen
ld: warning: -undefined error is deprecated
[12/18] Linking target subprojects/libquickjs/qjsc
ld: warning: -undefined error is deprecated
[18/18] Linking target libcore_pdd.dylib
ld: warning: -undefined error is deprecated
/Users/pancake/.local/share/radare2/plugins/libcore_pdd.dylib
0$

@trufae
Copy link
Contributor

trufae commented Nov 24, 2023

i added an rm -rf b at the begining to force meson rebuild the directory. it should work well for you too. thanks for reporting

@dguerri
Copy link
Author

dguerri commented Nov 24, 2023

Weird! Could it be the meson version?

I will look into it as soon I am back home.

@dguerri
Copy link
Author

dguerri commented Nov 24, 2023

I am still seeing the above issue on a vanilla Ubuntu 22.04.3. Meson version 0.61.2

❯ r2pm -Uic r2dec
INFO: Nothing to upgrade
INFO: Cleaning r2dec
INFO: Using r2-5.8.9 and r2pm-5.8.9
INFO: Cleaning r2dec
INFO: git clone --depth=10 --recursive https://github.com/wargio/r2dec-js /root/.local/share/radare2/r2pm/git//r2dec
Cloning into '/root/.local/share/radare2/r2pm/git//r2dec'...
remote: Enumerating objects: 258, done.
remote: Counting objects: 100% (258/258), done.
remote: Compressing objects: 100% (197/197), done.
remote: Total 258 (delta 87), reused 170 (delta 52), pack-reused 0
Receiving objects: 100% (258/258), 1.50 MiB | 6.85 MiB/s, done.
Resolving deltas: 100% (87/87), done.
INFO: Starting install for r2dec
INFO: R2PM_NEEDS: Found gcc in PATH
INFO: R2PM_NEEDS: Found make in PATH
INFO: R2PM_NEEDS: Found ninja in PATH
INFO: R2PM_NEEDS: Found meson in PATH
INFO: SCRIPT=<<EOF
INFO: 	rm -rf b
	meson b --reconfigure || exit 1
	ninja -C b || exit 1
	if [ "${GLOBAL}" = 1 ]; then
		${R2PM_SUDO} ninja uninstall
		${R2PM_SUDO} ninja install || exit 1
	else
		mkdir -p ${R2PM_PLUGDIR}
		cp -f b/libcore_pdd.${R2_LIBEXT} ${R2PM_PLUGDIR}
		echo "${R2PM_PLUGDIR}/libcore_pdd.${R2_LIBEXT}"
	fi
INFO: EOF
Directory does not contain a valid build tree:
/root/.local/share/radare2/r2pm/git/r2dec/b
❯ meson -v
0.61.2
❯ cat /etc/issue.net
Ubuntu 22.04.3 LTS

meson b --reconfigure seems to work only on a previously "primed" b directory.
What works for me is:

pwd
/root/.local/share/radare2/r2pm/git/r2dec
❯ rm -rf b
❯ meson . b
The Meson build system
Version: 0.61.2
Source dir: /root/.local/share/radare2/r2pm/git/r2dec
Build dir: /root/.local/share/radare2/r2pm/git/r2dec/b
Build type: native build
Project name: r2dec
Project version: undefined
C compiler for the host machine: cc (gcc 11.4.0 "cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0")
C linker for the host machine: cc ld.bfd 2.38
Host machine cpu family: x86_64
Host machine cpu: x86_64

Executing subproject libquickjs

libquickjs| Project name: quickjs
libquickjs| Project version: 2021-03-27-frida
libquickjs| C compiler for the host machine: cc (gcc 11.4.0 "cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0")
libquickjs| C linker for the host machine: cc ld.bfd 2.38
libquickjs| Run-time dependency threads found: YES
libquickjs| Library dl found: YES
libquickjs| Library m found: YES
libquickjs| Has header "unistd.h" : YES
libquickjs| Checking for function "malloc_usable_size" : YES
libquickjs| Configuring config.h using configuration
libquickjs| Build targets in project: 2
libquickjs| Subproject libquickjs finished.

Program radare2 found: YES (/usr/local/bin/radare2)
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
Message: radare2 include dir: /usr/local/include/libr
Message: radare2 library dir: /usr/local/lib
Message: radare2 plugin dir:  /usr/local/lib/radare2/5.8.9
Build targets in project: 6

r2dec undefined

  Subprojects
    libquickjs: YES

Found ninja-1.10.1 at /usr/bin/ninja
❯ ninja -C b
ninja: Entering directory `b'
[18/18] Linking target libcore_pdd.so

@dguerri
Copy link
Author

dguerri commented Nov 24, 2023

I see you are using MacOS, and the version of meson shipped with homebrew is 1.3.0:

❯ brew info meson
==> meson: stable 1.3.0 (bottled), HEAD

Maybe a safe option could be to wipe b and then use

meson . b

Instead of

meson b --reconfigure

@trufae
Copy link
Contributor

trufae commented Nov 25, 2023

try again, i removed the --reconfigure flag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants