enhance del_mapinfo/change_mapinfo#1401
Conversation
Signed-off-by: HyperSine <hypersine.git@outlook.com>
|
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 qlyou 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.pycould 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_rangesindel_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: