Closed miksh closed 2 years ago
I feel this is either caused by recent changes in angr’s memory data analysis or by the disassembler engine (capstone). I’ll debug it today and see what is going on.
Can you run test cases here and make sure they run in your environment?
Somehow I have a feeling that you are using GCC to assemble Intel syntax assembly files that reassembler generates… Give nasm a try?
It seems that these issues are caused by newer versions of GCC (?) changing the names of init
and fini
sections. Tiny changes that are causing troubles in reassembler's GCC library function removal logic. https://github.com/angr/angr/pull/3099 should solve this problem.
Also do not try the Python 2 version of angr. It is no longer maintained.
By the way, here is a better test.py that I use (so that you can get AT&T syntax that GCC likes):
import argparse
import subprocess
import angr
from patcherex.backends.reassembler_backend import ReassemblerBackend
if __name__=='__main__':
parser = argparse.ArgumentParser();
parser.add_argument("input")
parser.add_argument("output")
args= parser.parse_args()
p = angr.Project(args.input, auto_load_libs=False)
r = p.analyses.Reassembler(syntax="at&t")
r.symbolize()
r.remove_unnecessary_stuff()
assembly = r.assembly(comments=True, symbolized=True)
with open(args.output + ".s", "w") as f:
f.write(assembly)
subprocess.check_call(["gcc", "-no-pie", args.output + ".s", "-o", args.output],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
Thank you for your prompt response. I can solve Error#2 because of your help. I didn't know 'at&t' option, thanks. I hope another issue will be resolved soon.
Also, I have another question. Dose Ramblr officially support x86/x86-64 PIE binaries? I have another issue when I test a toy program which was compiled with PIE option.
The PR is merged. Error 1 and 2 should have both been solved.
Dose Ramblr officially support x86/x86-64 PIE binaries?
Nope. In theory it's extremely easy to do since you no longer need to heuristically symbolize pointers on PIE binaries. I am not interested in implementing the support for angr's reassembler. You can do it by yourself (and send us a PR) if you want to :)
By the way, an example solution that leverages explicit pointers (or relocation information) in PIE binaries is RetroWrite. I bet you know that paper.
I appreciate your effort. Fortunately, all the above errors seems to be resolved. :)
I got another error when I reassembled x86 binaries.
To be specific, ramblr emits reassembly files but I failed to recompile all of them.
And I found that Ramblr emits duplicated symbols as follows.
# data @ 0x806b394
.label_1:
.section .tm_clone_table
.align 4
# data @ 0x806b394
.label_1:
.section .bss
I think ramblr mis-handles some sections. I added relevant section info.
readily -S ls_x86 | grep '\.data' -A1
[24] .data PROGBITS 0806b1e0 0221e0 0001b4 00 WA 0 0 32
[25] .tm_clone_table PROGBITS 0806b394 022394 000000 00 WA 0 0 4
I’ve never seen .tm_clone_table. Can you share the binary?
@ltfish Have you checked my binary file? I hope that it is not a big deal.
Sorry for the late reply. I'm taking a sick leave and will take a look at the binary when situation permits.
I'm sorry to hear that. I wish you get well soon.
@miksh Did you notice that your ls_x86.run
has GCC-specific PIE code, specifically getpc calls (0x8049cc0)? Your binary is not full PIE, but partial PIE. I feel it's because your GCC is too new (which probably always links against PIE libraries regardless of your compilation settings), or the build process has some issues.
Reassembler does not officially support PIE binaries. I'm working on a quick fix, but I am not interested in testing it on a large corpus of PIE binaries.
https://github.com/angr/angr/pull/3171 works on your ls_x86.run
.
Two other issues that I fixed in this PR: Reassembler did not support xword ptr
. It also did not support empty sections (like tm_clone_table
).
Thank you for your kind cooperation. I have just checked that ramblr properly reassembles the sample binary. 👍
@miksh Did you notice that your
ls_x86.run
has GCC-specific PIE code, specifically getpc calls (0x8049cc0)? Your binary is not full PIE, but partial PIE. I feel it's because your GCC is too new (which probably always links against PIE libraries regardless of your compilation settings), or the build process has some issues.Reassembler does not officially support PIE binaries. I'm working on a quick fix, but I am not interested in testing it on a large corpus of PIE binaries.
I compiled the sample binary with gcc v7.5.0. I found that some intrinsic functions use getpc call even if I use no-pie options.
I found that some intrinsic functions use getpc call even if I use no-pie options.
I believe it's because some libraries on your system that GCC statically linked to has getpc
calls inside.
I'm closing this issue. Feel free to reopen or open a new one if you have more questions about reassembler!
I am trying to use ramblr for my research but I found some errors when I ran it.
I created a simple patch(re-compile) program as follows. (I did not add any instrumentations for test)
Also, I use a lastest angr versions as follows.
However, I met several errors even when I ran it
Error #1
I created a toy program (hello.c) as follows.
Then I ran it, but my program got syntax error.
After debugging, I found that there is a mistake as follows.
I fixed it as follows.
After fixing an aformentioned error, I also got error (error #1) as follows.
We examined assembly file that ramblr emited, and found that the errors are related to missing symbols.
Error #2
Next, I test(recompile) 'ls' binary, and I found a different error as follows. First, I ran python3 version.
I think ramblr could not properly handle following instruction.
Error #3
Also, python2 version emits different error as follows. I think the error reason is similar to that of error #1