mirror of
https://github.com/radareorg/radare2-r2papi.git
synced 2026-11-09 17:48:11 -10:00
- Search: string/wide/case-insensitive/Rabin-Karp/JSON searches now use _cmd_arg so patterns with spaces/special chars are safe.
- Flags: removed leftover manual _tmp_off = "" cleanups (now automatic).
- Debugger: added _tmp_addr() helper, removed manual _tmp_off cleanup.
- Esil: ESIL expressions use _cmd_arg; EsilCPU.registers() returns {} on failure; emulateInstr resolves symbol names to numeric
addresses because aesp doesn't accept symbols.
- Config: cleaned up old-style super() and % formatting; config set now uses key=value.
- File: minor __getattr__ cleanup.
- IOMap: setName uses _cmd_arg for arbitrary map names.
- R2Api / Function: af, afn, afn., p8, aoj, axtj now rely on automatic _tmp_off handling; removed duplicated open/files definitions.
75 lines
1.9 KiB
Python
75 lines
1.9 KiB
Python
from r2papi.base import R2Base
|
|
from r2papi.iomap import IOMap
|
|
|
|
|
|
class File(R2Base):
|
|
def __init__(self, r2, fd):
|
|
super(File, self).__init__(r2)
|
|
|
|
self.fd = fd
|
|
|
|
if not self.fd:
|
|
raise OSError("File not found")
|
|
|
|
def _getCurrObject(self):
|
|
files = self._exec("oj", json=True)
|
|
for f in files:
|
|
if f["fd"] == self.fd:
|
|
return f
|
|
|
|
return None
|
|
|
|
@property
|
|
def writable(self):
|
|
obj = self._getCurrObject()
|
|
return obj["writable"] if obj else None
|
|
|
|
@writable.setter
|
|
def writable(self, value):
|
|
if isinstance(value, bool):
|
|
if value:
|
|
# TODO: this reopens in rw-, so if the file was loaded with
|
|
# r-x we lose the x
|
|
self._exec(f"oo+ {self.fd}")
|
|
else:
|
|
# TODO: How to set -w ?
|
|
pass
|
|
|
|
def getFilename(self):
|
|
obj = self._getCurrObject()
|
|
return obj["uri"] if obj else None
|
|
|
|
def getSize(self):
|
|
obj = self._getCurrObject()
|
|
return obj["size"] if obj else None
|
|
|
|
def getIOMaps(self):
|
|
maps = self._exec("omj", json=True)
|
|
ret_maps = []
|
|
curr_fd = self.fd
|
|
for m in maps:
|
|
if m["fd"] == curr_fd:
|
|
ret_maps.append(IOMap(self.r2, m["map"]))
|
|
|
|
return ret_maps
|
|
|
|
def getFrom(self):
|
|
obj = self._getCurrObject()
|
|
return obj["from"] if obj else None
|
|
|
|
def __getattr__(self, attr):
|
|
if attr in ("uri", "filename"):
|
|
return self.getFilename()
|
|
if attr == "size":
|
|
return self.getSize()
|
|
# Offset instead of from because from is a reserved word
|
|
if attr == "offset":
|
|
return self.getFrom()
|
|
if attr in ("iomaps", "IOmaps"):
|
|
return self.getIOMaps()
|
|
return None
|
|
|
|
def close(self):
|
|
self._exec(f"o-{self.fd}")
|
|
self.fd = None
|