Skip to content

Commit c374a5f

Browse files
committed
Let mem is_mapped use is_available impl
1 parent d5d697c commit c374a5f

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

qiling/os/memory.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -343,38 +343,29 @@ def unmap_all(self):
343343
self.unmap(begin, end - begin + 1)
344344

345345
def is_available(self, addr: int, size: int) -> bool:
346-
'''Query whether the memory range starting at `addr` and is of length of `size` bytes
346+
"""Query whether the memory range starting at `addr` and is of length of `size` bytes
347347
can be allocated.
348348
349349
Returns: True if it can be allocated, False otherwise
350-
'''
350+
"""
351351

352352
assert size > 0, 'expected a positive size value'
353353

354354
begin = addr
355355
end = addr + size
356356

357-
# make sure neither begin nor end are enclosed within a mapped range
358-
return not any((lbound <= begin < ubound) or (lbound < end <= ubound) for lbound, ubound, _, _ in self.map_info)
357+
# make sure neither begin nor end are enclosed within a mapped range, or entirely enclosing one
358+
return not any((lbound <= begin < ubound) or (lbound < end <= ubound) or (begin <= lbound < ubound <= end) for lbound, ubound, _, _ in self.map_info)
359+
360+
def is_mapped(self, addr: int, size: int) -> bool:
361+
"""Query whether the memory range starting at `addr` and is of length of `size` bytes
362+
is mapped, either partially or entirely.
363+
364+
Returns: True if any part of the specified memory range is taken, False otherwise
365+
"""
366+
367+
return not self.is_available(addr, size)
359368

360-
def is_mapped(self, address, size):
361-
'''
362-
The main function of is_mmaped is to determine
363-
whether the memory starting with addr and size has been mapped.
364-
Returns true if it has already been allocated.
365-
If unassigned, returns False.
366-
'''
367-
368-
for region in list(self.ql.uc.mem_regions()):
369-
if ((address >= region[0] and address < region[1]) or
370-
((address + size - 1) >= region[0] and (address + size - 1) < region[1]) or
371-
(address <= region[0] and (address + size - 1) > region[1])):
372-
self.ql.log.info("%x - %x is taken" % (address, address + size - 1))
373-
return True
374-
375-
return False
376-
377-
378369
def is_free(self, address, size):
379370
'''
380371
The main function of is_free first must fufull is_mapped condition.

0 commit comments

Comments
 (0)