-
Notifications
You must be signed in to change notification settings - Fork 750
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
enhance del_mapinfo/change_mapinfo #1401
Conversation
Signed-off-by: HyperSine <[email protected]>
Cool, that make sense. |
Hi, The code seems to break the test. I need to revert it. Will you be able to make another PR ? |
Can you tell me which test is broken? |
https://github.com/qilingframework/qiling/actions/runs/7208092719/job/19636291311
|
I think the problem is not from my code. It is due to the bug from upstream: unicorn-engine/unicorn#1877. In
If you modify the test code # from line 13
def test_qdb_mips32el_hello(self):
rootfs = "../examples/rootfs/mips32el_linux"
path = rootfs + "/bin/mips32el_hello"
ql = Qiling([path], rootfs)
ql.loader.mmap_address = 0x20000000 # <-- add just this line
ql.debugger = "qdb::rr:qdb_scripts/mips32el.qdb"
ql.run()
del ql you will find my PR passes the test. |
Checklist
Which kind of PR do you create?
Coding convention?
Extra tests?
Changelog?
Target branch?
One last thing
I was trying to emulate a ELF packed by virbox protector recently. I found there were some error logs when handling syscall_mprotect. Because I cannot post the ELF file on github, here's the minimum code to reproduce:
Output:
After some investigation, I found that the function
change_mapinfo()
inqiling/os/memory.py
could only change only one MapInfoEntry at a time and that MapInfoEntry must be fully contained by memory range [mem_s, mem_e). If multiple MapInfoEntry just overlap but all of them are not fully contained by the memory range, such error would appear. So I did some enhancement to change_mapinfo and other functions. Here is what this PR contains:find_mapinfo()
as it would be used in bothdel_mapinfo()
andchange_mapinfo()
.find_mapinfo()
to calculateoverlap_ranges
indel_mapinfo()
. It has less iterations so we can have better performance.del_mapinfo()
. The new entries to be added are all parts of entries removed before. So just insert new entries at index fromi0
, no need to callbisect.insort
.change_mapinfo()
. Now it could change multiple overlapping entries' permissions/label at a time.mem_unmap()
anddel_mapinfo()
inunmap()
function for better exception safety.After applying this PR, the code above wound have correct output: