Skip to content

Commit f3b5cbe

Browse files
committed
Refresh mem map_anywhere impl and doc
1 parent 914fc33 commit f3b5cbe

File tree

1 file changed

+16
-37
lines changed

1 file changed

+16
-37
lines changed

qiling/os/memory.py

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -427,46 +427,25 @@ def find_free_space(self, size: int, minaddr: int = None, maxaddr: int = None, a
427427

428428
raise QlOutOfMemory('Out Of Memory')
429429

430-
def map_anywhere(
431-
self,
432-
size,
433-
#name = "",
434-
#kind = "",
435-
min_addr = 0,
436-
alignment = 0x1000,
437-
#prot: int = ProtType.RWX,
438-
) -> int:
439-
"""
440-
Maps a region of memory with requested size, within the
441-
addresses specified. The size and start address will respect the
442-
alignment.
430+
def map_anywhere(self, size: int, minaddr: int = None, maxaddr: int = None, align=0x1000, perms: int = UC_PROT_ALL, info: str = None) -> int:
431+
"""Map a region anywhere in memory.
443432
444433
Args:
445-
size: # of bytes to map. This will be rounded up to match
446-
the alignment.
447-
name: String used to identify mapped region. Used for
448-
debugging.
449-
kind: String used to identify the purpose of the mapped
450-
region. Used for debugging.
451-
min_addr: The lowest address that could be mapped.
452-
max_addr: The highest address that could be mapped.
453-
alignment: Ensures the size and start address are multiples
454-
of this. Must be a multiple of 0x1000. Default 0x1000.
455-
prot: RWX permissions of the mapped region. Defaults to
456-
granting all permissions.
457-
Returns:
458-
Start address of mapped region.
459-
"""
460-
max_mem_addr = self.max_mem_addr
461-
address = self.find_free_space(
462-
size, min_addr=min_addr, max_addr=max_mem_addr, alignment=alignment
463-
)
464-
"""
465-
we need a better mem_map as defined in the issue
434+
size: desired range size (in bytes)
435+
minaddr: lowest base address to consider (or None for minimal address possible)
436+
maxaddr: highest end address to allow (or None for maximal address possible)
437+
align: base address alignment, must be a power of 2
438+
perms: requested permissions mask
439+
info: range label string
440+
441+
Returns: mapped address
466442
"""
467-
#self.map(address, util.align(size), name, kind)
468-
self.map(address, self.align(size))
469-
return address
443+
444+
addr = self.find_free_space(size, minaddr, maxaddr, align)
445+
446+
self.map(addr, self.align(size), perms, info)
447+
448+
return addr
470449

471450
def protect(self, addr, size, perms):
472451
aligned_address = (addr >> 12) << 12

0 commit comments

Comments
 (0)