pbiernat / ripr

Package Binary Code as a Python class using Binary Ninja and Unicorn Engine
MIT License
396 stars 29 forks source link

Invalid memory mapping (UC_ERR_MAP) #10

Open F-hertz opened 6 years ago

F-hertz commented 6 years ago

Hello,

From an so library : ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, stripped

I got unicorn.unicorn.UcError: Invalid memory mapping (UC_ERR_MAP) self.mu = Uc(UC_ARCH_X86, UC_MODE_32)

   self.mu.mem_map(0x12000,0x4000)
   self.mu.mem_map(0x18000,0x4000)
   self.mu.mem_map(0x1000 * 1, 0x1000)

is there some hints ?

pbiernat commented 6 years ago

I don't get any errors from unicorn, at least just from those lines.

Happy to take a look in the next day or so if you want to post the full output and target binary.

v-p-b commented 6 years ago

I get a very similar error when I compile the RC4 sample to 32-bit (gcc -m32):

Traceback (most recent call last):
  File "test.py", line 58, in <module>
    prga=PRGA()
  File "test.py", line 14, in __init__
    self.mu.mem_map(0x804a000L,0x4000)
  File "/usr/local/lib/python2.7/dist-packages/unicorn/unicorn.py", line 407, in mem_map
    raise UcError(status)
unicorn.unicorn.UcError: Invalid memory mapping (UC_ERR_MAP)

Here's the relevant part of the code:

        self.mu.mem_map(0x8048000L,0x4000)
        self.mu.mem_map(0x804a000L,0x4000)
        self.mu.mem_map(0x7ffff000,0x200000)

        self.mu.mem_write(0x804a020L, self.data_0)
        self.mu.mem_write(0x80484cbL, self.code_0)
        self.mu.mem_write(0x80485b1L, self.code_1)

It seems that the mappings overlap: If I change the size of the first mapping to 0x1000 (still plenty to hold the data) the issue goes away.

psifertex commented 1 year ago

I ran into this error on stream recently. One underlying issue is that if you want to emulate arguments, ripr needs to make sure that region doesn't overlap with existing sections. I'll probably whip up a PR to make that change in a little bit. In the meantime, an easy hack is to just rebase the entire binary to a different offset.