MCPcopy Create free account
hub / github.com/qilingframework/qiling / align

Method align

qiling/os/memory.py:264–284  ·  view source on GitHub ↗

Align a value down to the specified alignment boundary. If `value` is already aligned, the same value is returned. Commonly used to determine the base address of the enclosing page. Args: value: a value to align alignment: alignment boundary; must be

(self, value: int, alignment: Optional[int] = None)

Source from the content-addressed store, hash-verified

262 return next((lbound for lbound, info in stripped if os.path.basename(info) == filename), None)
263
264 def align(self, value: int, alignment: Optional[int] = None) -> int:
265 """Align a value down to the specified alignment boundary. If `value` is already
266 aligned, the same value is returned. Commonly used to determine the base address
267 of the enclosing page.
268
269 Args:
270 value: a value to align
271 alignment: alignment boundary; must be a power of 2. if not specified value
272 will be aligned to page size
273
274 Returns: value aligned down to boundary
275 """
276
277 if alignment is None:
278 alignment = self.pagesize
279
280 # make sure alignment is a power of 2
281 assert alignment & (alignment - 1) == 0
282
283 # round down to nearest alignment
284 return value & ~(alignment - 1)
285
286 def align_up(self, value: int, alignment: Optional[int] = None) -> int:
287 """Align a value up to the specified alignment boundary. If `value` is already

Callers 12

protectMethod · 0.95
disassemblerMethod · 0.80
init_linux_trapsFunction · 0.80
ql_syscall_munmapFunction · 0.80
syscall_mmap_implFunction · 0.80
ql_syscall_shmatFunction · 0.80
load_elf_segmentsMethod · 0.80
__push_bytesMethod · 0.80
load_with_ldMethod · 0.80
load_driverMethod · 0.80
_skip_unmapped_rwMethod · 0.80
mem_crashFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected