mirror of
https://github.com/radareorg/r2ghidra.git
synced 2026-11-07 06:25:57 -10:00
ccode mode called setNoCastPrinting(true) after applying r2ghidra.casts, so
`e r2ghidra.casts=true` was silently overridden and semantically necessary
truncations disappeared. For
long cast_test(long x) { return (long)(int)x + 0x100000000L; }
the output was `arg1 + 0x100000000`, which evaluates to 0xffffffff at
0xffffffff instead of the 0x1ffffffff the binary produces.
Let r2ghidra.casts decide: ccode keeps only the identifier cleanup and the
hidden implied ZEXT/SEXT extensions and no-convention prototype style. With
ccode=true,casts=true the printer now emits
`(int64_t)(int)arg1 + 0x100000000`; with casts=false it stays cast-free as the
option documents, and ccode=false output is unchanged.
Regression in test/db/extras/r2ghidra_ccode with the compiled fixture.
56 lines
1.1 KiB
Plaintext
56 lines
1.1 KiB
Plaintext
# ConsoleApplication1.exe is radare2-testbins/pe/ConsoleApplication1.exe; the ELF
|
|
# fixtures are built by test/bins/Makefile.
|
|
NAME=ccode strips the Windows API-set DLL prefix from import names
|
|
FILE=bins/pe/ConsoleApplication1.exe
|
|
CMDS=<<EOF
|
|
aaaa
|
|
s sub.api_ms_win_crt_stdio_l1_1_0.dll__set_fmode
|
|
e r2ghidra.ccode=true
|
|
pdg~_set_fmode
|
|
EOF
|
|
EXPECT=<<EOF
|
|
void _set_fmode(void)
|
|
_set_fmode();
|
|
EOF
|
|
RUN
|
|
|
|
NAME=ccode preserves the whole ELF import name
|
|
FILE=bins/elf/x86_64-pthread-lock.so
|
|
CMDS=<<EOF
|
|
aa
|
|
s entry0
|
|
e r2ghidra.ccode=true
|
|
pdg~pthread_mutex_lock
|
|
EOF
|
|
EXPECT=<<EOF
|
|
pthread_mutex_lock(arg1);
|
|
EOF
|
|
RUN
|
|
|
|
NAME=ccode keeps leading underscores of sym.imp names
|
|
FILE=bins/hello-arm
|
|
CMDS=<<EOF
|
|
aa
|
|
s sym._start_main
|
|
e r2ghidra.ccode=true
|
|
pdg~__libc_init
|
|
EOF
|
|
EXPECT=<<EOF
|
|
__libc_init(param_1,0,*(iRam00000424 + 0x418),&stack0xffffffec);
|
|
EOF
|
|
RUN
|
|
|
|
NAME=ccode honors r2ghidra.casts and keeps necessary truncations
|
|
FILE=bins/elf/x86_64-cast-test.o
|
|
CMDS=<<EOF
|
|
aa
|
|
s sym.cast_test
|
|
e r2ghidra.ccode=true
|
|
e r2ghidra.casts=true
|
|
pdg~return
|
|
EOF
|
|
EXPECT=<<EOF
|
|
return (int64_t)(int)arg1 + 0x100000000;
|
|
EOF
|
|
RUN
|