【问题标题】:How to allocate (malloc) memory in an angr simulation state?如何在 angr 模拟状态下分配(malloc)内存?
【发布时间】:2020-03-27 06:56:13
【问题描述】:

我成功地弄清楚了如何使用 angr 运行程序,从核心转储定义的状态开始(请参阅How to run program using angr after loading with the elfcore backend?)但现在我想知道这个:

如何在程序的 SimulationState 中分配内存?

我运行程序的起始状态是一个函数的开始,它接受一个指针和一个长度。我希望能够以任意长度重新分配内存,并将这个指针(和适当的长度)传递给函数。

我发现有一个我认为是插件类,angr.state_plugins.heap.heap_libc.SimHeapLibc (documentation),它有一个malloc 方法,但是我如何使用这个插件,它实际上是我需要的吗?

【问题讨论】:

    标签: python-3.x x86-64 reverse-engineering elf angr


    【解决方案1】:

    好吧,想通了。

    首先,你想要的插件类是angr.state_plugins.heap.heap_ptmalloc.SimHeapPTMalloc。原来angr.state_plugins.heap.heap_libc.SimHeapLibc 只是基类。

    然后用例变成:

    simstate = angr.factory.AngrObjectFactory(proj).blank_state()
    
    # IMPORTANT NOTE: you need to register the plugin with the name heap or it will break
    simstate.register_plugin("heap", angr.state_plugins.heap.heap_ptmalloc.SimHeapPTMalloc())
    
    # Voila, malloc and use arbitrary amounts of memory in the simulation space.
    ptr = self.simstate.heap.malloc(data_len)
    simstate.memory.store(ptr, simstate.solver.BVV(data_bytes, data_len*8))
    

    【讨论】:

      猜你喜欢
      • 2022-11-10
      • 2020-11-23
      • 2016-07-15
      • 2012-12-26
      • 2013-11-20
      • 2018-10-16
      • 1970-01-01
      • 2013-02-23
      • 2010-09-11
      相关资源
      最近更新 更多