HexHive / retrowrite

RetroWrite -- Retrofitting compiler passes through binary rewriting
Other
655 stars 78 forks source link

Cannot recompile assembled code[BUG] #31

Open ha2san opened 2 years ago

ha2san commented 2 years ago

When I try to compile the assembled code I get this error

(retro) bash-5.1$ file binary/quich
binary/quich: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV),
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2,
BuildID[sha1]=f78f9f350f2b849566bbc2062e349729a5493eba, for GNU/Linux 4.4.0,
with debug_info, not stripped

(retro) bash-5.1$ retrowrite binary/quich asm/quich_reassembled.s
.init_array frame_dummy pointer removed.
[*] Relocations for a section that's not loaded: .rela.dyn
[*] Relocations for a section that's not loaded: .rela.plt
[x] Couldn't find valid section ade0
[x] Couldn't find valid section afd8
[x] Couldn't find valid section afe0
[x] Couldn't find valid section afe8
[x] Couldn't find valid section aff0
[x] Couldn't find valid section aff8

(retro) bash-5.1$ gcc asm/quich_reassembled.s -lm -o binary/quich_reassembled
asm/quich_reassembled.s: Assembler messages:
asm/quich_reassembled.s:4898: Error: unrecognized symbol type "GLIBC_2.2.5_b220"
asm/quich_reassembled.s:4898: Error: junk at end of line, first unrecognized character is `,'
asm/quich_reassembled.s:4899: Error: junk at end of line, first unrecognized character is `@'
asm/quich_reassembled.s:4900: Error: invalid character '@' in mnemonic
asm/quich_reassembled.s:4936: Error: unrecognized symbol type "GLIBC_2.2.5_b230"
asm/quich_reassembled.s:4936: Error: junk at end of line, first unrecognized character is `,'
asm/quich_reassembled.s:4937: Error: junk at end of line, first unrecognized character is `@'
asm/quich_reassembled.s:4938: Error: invalid character '@' in mnemonic
asm/quich_reassembled.s:4974: Error: unrecognized symbol type "GLIBC_2.2.5_b240"
asm/quich_reassembled.s:4974: Error: junk at end of line, first unrecognized character is `,'
asm/quich_reassembled.s:4975: Error: junk at end of line, first unrecognized character is `@'
asm/quich_reassembled.s:4976: Error: invalid character '@' in mnemonic

Steps To Reproduce:

Source code can be found at https://github.com/Usbac/quich, I added -pie to the CFLAGS to make sure that the binary is compiled as position independent code (PIE). Adding or removing the -g flags does not change anything.

Environment:

OS: 5.14.21-2-MANJARO x86_64 GNU/Linux GCC: gcc (GCC) 11.2.0 retrowrite at commit: 117dad525114bca695317e14affffd4e3de13cce

ha2san commented 2 years ago

one of the errors seems for example to come from this line:

.type   stdout@GLIBC_2.2.5_b220,@object
Akira-u commented 2 years ago

Hi ha2san! I have met the same problem as you on aarch64 and gcc 9.4.0. I solved the problem with delete all the @GLIBC_*** in the .s files. Here's the command: sed -i 's/@GLIBC_2.17//g' $AS_FILE.s. Hope this helps :)