(self, uc, access, address, size, value, user_data)
return True
This callback is called when unicorn needs to access data that's not yet present in memory.
This callback is called when unicorn needs to access data that's not yet present in memory.
This callback is called when unicorn needs to access data that s not yet present in memory .
def _hook_mem_unmapped(self, uc, access, address, size, value, user_data): #pylint:disable=unused-argument
        """
        This callback is called when unicorn needs to access data that's not yet present in memory.
        """
        if user_data == 1:
            self._skip_next_callback = True
        elif self._skip_next_callback:
            self._skip_next_callback = False
            return True

        start = address & ~0xfff
        needed_pages = 2 if address - start + size > 0x1000 else 1

        attempt_pages = 10
        for pageno in range(attempt_pages):
            page_addr = (start + pageno * 0x1000) & ((1 << self.state.arch.bits) - 1)
            if page_addr == 0:
                if pageno >= needed_pages:
                    break
                if options.UNICORN_ZEROPAGE_GUARD in self.state.options:
                    self.error = 'accessing zero page (%#x)' % access
                    l.warning(self.error)

                    _UC_NATIVE.stop(self._uc_state, STOP.STOP_ZEROPAGE)
                    return False

            l.info('mmap [%#x, %#x] because %d', page_addr, page_addr + 0xfff, access)
            try:
                self._map_one_page(uc, page_addr)
            except SegfaultError:
                # this is the unicorn segfault error. idk why this would show up
                _UC_NATIVE.stop(self._uc_state, STOP.STOP_SEGFAULT)
                return False
            except SimSegfaultError:
                _UC_NATIVE.stop(self._uc_state, STOP.STOP_SEGFAULT)
                return False
            except unicorn.UcError as e:
                if e.errno != 11:
                    self.error = str(e)
                    _UC_NATIVE.stop(self._uc_state, STOP.STOP_ERROR)
                    return False
                l.info("...already mapped :)")
                break
            except SimMemoryError as e:
                if pageno >= needed_pages:
                    l.info("...never mind")
                    break
                else:
                    self.error = str(e)
                    _UC_NATIVE.stop(self._uc_state, STOP.STOP_ERROR)
                    return False

        return True
def _hook_mem_unmapped ( self , uc , access , address , size , value , user_data ) : #pylint:disable=unused-argument if user_data == 1 : self . _skip_next_callback = True elif self . _skip_next_callback : self . _skip_next_callback = False return True start = address & ~ 0xfff needed_pages = 2 if address - start + size > 0x1000 else 1 attempt_pages = 10 for pageno in range ( attempt_pages ) : page_addr = ( start + pageno * 0x1000 ) & ( ( 1 << self . state . arch . bits ) - 1 ) if page_addr == 0 : if pageno >= needed_pages : break if options . UNICORN_ZEROPAGE_GUARD in self . state . options : self . error = 'accessing zero page (%#x)' % access l . warning ( self . error ) _UC_NATIVE . stop ( self . _uc_state , STOP . STOP_ZEROPAGE ) return False l . info ( 'mmap [%#x, %#x] because %d' , page_addr , page_addr + 0xfff , access ) try : self . _map_one_page ( uc , page_addr ) except SegfaultError : # this is the unicorn segfault error. idk why this would show up _UC_NATIVE . stop ( self . _uc_state , STOP . STOP_SEGFAULT ) return False except SimSegfaultError : _UC_NATIVE . stop ( self . _uc_state , STOP . STOP_SEGFAULT ) return False except unicorn . UcError as e : if e . errno != 11 : self . error = str ( e ) _UC_NATIVE . stop ( self . _uc_state , STOP . STOP_ERROR ) return False l . info ( "...already mapped :)" ) break except SimMemoryError as e : if pageno >= needed_pages : l . info ( "...never mind" ) break else : self . error = str ( e ) _UC_NATIVE . stop ( self . _uc_state , STOP . STOP_ERROR ) return False return True