Skip to content

Commit 978e1df

Browse files
committed
Use align and align_up where appropriate
1 parent 37024ac commit 978e1df

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

examples/mem_invalid_access.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
def mem_crash(ql: Qiling, access: int, address: int, size: int, value: int):
1212
print(f'got crash')
1313

14-
PAGE_SIZE = 0x1000
15-
aligned = address & ~(PAGE_SIZE - 1)
14+
PAGE_SIZE = ql.mem.pagesize
15+
aligned = ql.mem.align(address)
1616

1717
# map the entire page containing the invalid address and fill it with 'Q's
1818
ql.mem.map(aligned, PAGE_SIZE)

qiling/extensions/idaplugin/qilingida.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from PyQt5.QtWidgets import (QPushButton, QHBoxLayout)
4343

4444
# Qiling
45-
from qiling import *
45+
from qiling import Qiling
4646
from qiling.const import *
4747
from qiling.arch.x86_const import reg_map_32 as x86_reg_map_32
4848
from qiling.arch.x86_const import reg_map_64 as x86_reg_map_64
@@ -1568,16 +1568,16 @@ def _guide_hook(self, ql, addr, size):
15681568
self.paths[start_bb_id].append(cur_bb.id)
15691569
ql.emu_stop()
15701570

1571-
def _skip_unmapped_rw(self, ql, type, addr, size, value):
1572-
alignment = 0x1000
1573-
# Round down
1574-
map_addr = addr & (~(alignment - 1))
1575-
# Round up
1576-
map_size = ((size + (alignment - 1)) & (~(alignment - 1)))
1571+
def _skip_unmapped_rw(self, ql: Qiling, type, addr, size, value):
1572+
map_addr = ql.mem.align(addr)
1573+
map_size = ql.mem.align_up(size)
1574+
15771575
if not ql.mem.is_mapped(map_addr, map_size):
15781576
logging.warning(f"Invalid memory R/W, trying to map {hex(map_size)} at {hex(map_addr)}")
1577+
15791578
ql.mem.map(map_addr, map_size)
1580-
ql.mem.write(map_addr, b'\x00'*map_size)
1579+
ql.mem.write(map_addr, b'\x00' * map_size)
1580+
15811581
return True
15821582

15831583
def _find_branch_in_real_block(self, bb):

qiling/os/posix/syscall/mman.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ def syscall_mmap_impl(ql: Qiling, addr: int, mlen: int, prot: int, flags: int, f
8484

8585
need_mmap = True
8686
mmap_base = addr
87-
mmap_size = (mlen - (addr & (pagesize - 1)) + pagesize - 1) & ~(pagesize - 1)
87+
mmap_size = ql.mem.align_up(mlen - ql.mem.align(addr))
8888

8989
if ql.ostype != QL_OS.QNX:
90-
mmap_base &= ~(pagesize - 1)
91-
if (flags & MAP_FIXED) > 0 and mmap_base != addr:
90+
mmap_base = ql.mem.align(mmap_base)
91+
92+
if (flags & MAP_FIXED) and mmap_base != addr:
9293
return MAP_FAILED
9394

9495
# initial ql.loader.mmap_address

0 commit comments

Comments
 (0)