How to use the qiling.os.windows.memory.Chunk function in qiling

To help you get started, we’ve selected a few qiling examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github qilingframework / qiling / qiling / os / windows / memory.py View on Github external
# Find the heap chunks that best matches size 
        self.chunks.sort(key=Chunk.compare)
        for chunk in self.chunks:
            if chunk.inuse is False and chunk.size > size:
                chunk.inuse = True
                return chunk.address

        chunk = None
        # If we need mem_map new memory
        if self.current_use + size > self.current_alloc:
            real_size = align(size, self.page_size)
            # If the heap is not enough
            if self.start_address + self.current_use + real_size > self.end_address:
                return 0
            self.ql.uc.mem_map(self.start_address + self.current_alloc, real_size)
            chunk = Chunk(self.start_address + self.current_use, size)
            self.current_alloc += real_size
            self.current_use += size
            self.chunks.append(chunk)
        else:
            chunk = Chunk(self.start_address + self.current_use, size)
            self.current_use += size
            self.chunks.append(chunk)

        chunk.inuse = True
        # print("heap.mem_alloc addresss: " + hex(chunk.address))
        return chunk.address
github qilingframework / qiling / qiling / os / windows / memory.py View on Github external
def mem_alloc(self, size):
        if self.ql.arch == QL_X86:
            size = align(size, 4)
        elif self.ql.arch == QL_X8664:
            size = align(size, 8)
        else:
            raise QlErrorArch("unknown ql.arch")

        # Find the heap chunks that best matches size 
        self.chunks.sort(key=Chunk.compare)
        for chunk in self.chunks:
            if chunk.inuse is False and chunk.size > size:
                chunk.inuse = True
                return chunk.address

        chunk = None
        # If we need mem_map new memory
        if self.current_use + size > self.current_alloc:
            real_size = align(size, self.page_size)
            # If the heap is not enough
            if self.start_address + self.current_use + real_size > self.end_address:
                return 0
            self.ql.uc.mem_map(self.start_address + self.current_alloc, real_size)
            chunk = Chunk(self.start_address + self.current_use, size)
            self.current_alloc += real_size
            self.current_use += size
github qilingframework / qiling / qiling / os / windows / memory.py View on Github external
return chunk.address

        chunk = None
        # If we need mem_map new memory
        if self.current_use + size > self.current_alloc:
            real_size = align(size, self.page_size)
            # If the heap is not enough
            if self.start_address + self.current_use + real_size > self.end_address:
                return 0
            self.ql.uc.mem_map(self.start_address + self.current_alloc, real_size)
            chunk = Chunk(self.start_address + self.current_use, size)
            self.current_alloc += real_size
            self.current_use += size
            self.chunks.append(chunk)
        else:
            chunk = Chunk(self.start_address + self.current_use, size)
            self.current_use += size
            self.chunks.append(chunk)

        chunk.inuse = True
        # print("heap.mem_alloc addresss: " + hex(chunk.address))
        return chunk.address