mirror of https://github.com/pwndbg/pwndbg.git
chore(ghidra): use memoize feature to cache r2pipe handle
We need to cache and reset the r2pipe handle based on memoize conditions as the PIE base could potentially change.pull/901/head
parent
44770fd71f
commit
707fe12e3d
@ -1,17 +1,32 @@
|
|||||||
|
import gdb
|
||||||
|
|
||||||
import pwndbg.elf
|
import pwndbg.elf
|
||||||
|
import pwndbg.memoize
|
||||||
|
|
||||||
|
|
||||||
|
@pwndbg.memoize.reset_on_new_base_address
|
||||||
|
def r2pipe():
|
||||||
|
"""
|
||||||
|
Spawn and return a r2pipe handle for the current process file.
|
||||||
|
|
||||||
|
This function requires a radare2 installation plus the r2pipe python
|
||||||
|
library. The base address is automatically set for PIE when loading the
|
||||||
|
binary.
|
||||||
|
After opening the handle, the binary is automatically analyzed.
|
||||||
|
|
||||||
radare2 = {}
|
Raises ImportError if r2pipe python library is not available.
|
||||||
|
Raises Exception if anything goes fatally wrong.
|
||||||
|
|
||||||
|
Returns a r2pipe.open handle.
|
||||||
|
"""
|
||||||
|
filename = gdb.current_progspace().filename
|
||||||
|
if not filename:
|
||||||
|
raise Exception('Could not find objfile to create a r2pipe for')
|
||||||
|
|
||||||
def r2pipe(filename):
|
|
||||||
r2 = radare2.get(filename)
|
|
||||||
if r2:
|
|
||||||
return r2
|
|
||||||
import r2pipe
|
import r2pipe
|
||||||
flags = ['-e', 'io.cache=true']
|
flags = ['-e', 'io.cache=true']
|
||||||
if pwndbg.elf.get_elf_info(filename).is_pie and pwndbg.elf.exe():
|
if pwndbg.elf.get_elf_info(filename).is_pie and pwndbg.elf.exe():
|
||||||
flags.extend(['-B', hex(pwndbg.elf.exe().address)])
|
flags.extend(['-B', hex(pwndbg.elf.exe().address)])
|
||||||
r2 = r2pipe.open(filename, flags=flags)
|
r2 = r2pipe.open(filename, flags=flags)
|
||||||
radare2[filename] = r2
|
|
||||||
r2.cmd("aaaa")
|
r2.cmd("aaaa")
|
||||||
return r2
|
return r2
|
||||||
|
|||||||
Loading…
Reference in new issue