Source code for angr.storage.memory_mixins.paged_memory.privileged_mixin
from.paged_memory_mixinimportPagedMemoryMixin
[docs]classPrivilegedPagingMixin(PagedMemoryMixin):""" A mixin for paged memory models which will raise SimSegfaultExceptions if STRICT_PAGE_ACCESS is enabled and a segfault condition is detected. Segfault conditions include: - getting a page for reading which is non-readable - getting a page for writing which is non-writable - creating a page The latter condition means that this should be inserted under any mixins which provide other implementations of ``_initialize_page``. """def_get_page(self,pageno:int,writing:bool,priv:bool=False,**kwargs):page=super()._get_page(pageno,writing,**kwargs)ifself.category=="mem"andnotprivando.STRICT_PAGE_ACCESSinself.state.options:ifwritingandnotself.state.solver.is_true(page.perm_write):raiseSimSegfaultException(pageno*self.page_size,"non-writable")ifnotwritingandnotself.state.solver.is_true(page.perm_read):raiseSimSegfaultException(pageno*self.page_size,"non-readable")returnpagedef_initialize_page(self,pageno:int,priv:bool=False,**kwargs):ifself.category=="mem"andnotprivando.STRICT_PAGE_ACCESSinself.state.options:raiseSimSegfaultException(pageno*self.page_size,"unmapped")returnsuper()._initialize_page(pageno,**kwargs)