qiling icon indicating copy to clipboard operation
qiling copied to clipboard

Heap Memory Allocator for Linux

Open mustakimur opened this issue 2 years ago • 1 comments

It seems like every platform except Linux implements the QlMemoryHeap class that lets users manipulate the heap memory. Unfortunately, for Linux binaries, we could not find equivalent functions as ql.os.heap.alloc(size).

Can anyone point out why it is like that/ how we could manipulate heap memory for Linux binaries?

Thanks.

mustakimur avatar Dec 02 '22 20:12 mustakimur

This code is suitable for my scenario, I'm not sure if it's universal.

class Qlkit(qiling.Qiling):
    def __init__(self, *args, **kw):
         qiling.Qiling.__init__(self, *args, **kw)
         self.heap = self.heap_init()

    def heap_init(self):
        qlkit_heap_address = None

        # search mem space
        heap_base = 0x0060000000
        heap = None
        for i in range(0, 0x10):
            hbase = heap_base + (i * 0x100000)
            if(not self.mem.is_mapped(hbase, 4)):
                qlkit_heap_address = hbase

        # map the heap
        if(qlkit_heap_address != None):
            heap = QlMemoryHeap(self,
                qlkit_heap_address, qlkit_heap_address+0x10000
            )
        else:
            print("Didn't find memory space for qlkit_heap")
        return heap

rootkiter avatar Dec 27 '23 10:12 rootkiter