Use align and align_up where appropriate

This commit is contained in:
elicn
2021-12-28 20:48:22 +02:00
parent 37024acf95
commit 978e1df95a
3 changed files with 14 additions and 13 deletions
+2 -2
View File
@@ -11,8 +11,8 @@ from qiling.const import QL_VERBOSE
def mem_crash(ql: Qiling, access: int, address: int, size: int, value: int):
print(f'got crash')
PAGE_SIZE = 0x1000
aligned = address & ~(PAGE_SIZE - 1)
PAGE_SIZE = ql.mem.pagesize
aligned = ql.mem.align(address)
# map the entire page containing the invalid address and fill it with 'Q's
ql.mem.map(aligned, PAGE_SIZE)
+8 -8
View File
@@ -42,7 +42,7 @@ from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import (QPushButton, QHBoxLayout)
# Qiling
from qiling import *
from qiling import Qiling
from qiling.const import *
from qiling.arch.x86_const import reg_map_32 as x86_reg_map_32
from qiling.arch.x86_const import reg_map_64 as x86_reg_map_64
@@ -1568,16 +1568,16 @@ class QlEmuPlugin(plugin_t, UI_Hooks):
self.paths[start_bb_id].append(cur_bb.id)
ql.emu_stop()
def _skip_unmapped_rw(self, ql, type, addr, size, value):
alignment = 0x1000
# Round down
map_addr = addr & (~(alignment - 1))
# Round up
map_size = ((size + (alignment - 1)) & (~(alignment - 1)))
def _skip_unmapped_rw(self, ql: Qiling, type, addr, size, value):
map_addr = ql.mem.align(addr)
map_size = ql.mem.align_up(size)
if not ql.mem.is_mapped(map_addr, map_size):
logging.warning(f"Invalid memory R/W, trying to map {hex(map_size)} at {hex(map_addr)}")
ql.mem.map(map_addr, map_size)
ql.mem.write(map_addr, b'\x00'*map_size)
ql.mem.write(map_addr, b'\x00' * map_size)
return True
def _find_branch_in_real_block(self, bb):
+4 -3
View File
@@ -84,11 +84,12 @@ def syscall_mmap_impl(ql: Qiling, addr: int, mlen: int, prot: int, flags: int, f
need_mmap = True
mmap_base = addr
mmap_size = (mlen - (addr & (pagesize - 1)) + pagesize - 1) & ~(pagesize - 1)
mmap_size = ql.mem.align_up(mlen - ql.mem.align(addr))
if ql.ostype != QL_OS.QNX:
mmap_base &= ~(pagesize - 1)
if (flags & MAP_FIXED) > 0 and mmap_base != addr:
mmap_base = ql.mem.align(mmap_base)
if (flags & MAP_FIXED) and mmap_base != addr:
return MAP_FAILED
# initial ql.loader.mmap_address