mirror of
https://github.com/radareorg/radare2-r2papi.git
synced 2026-11-12 16:15:06 -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.
57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
from r2papi.base import R2Base
|
|
|
|
|
|
class ConfigType(R2Base):
|
|
def __init__(self, r2, var_type):
|
|
super().__init__(r2)
|
|
|
|
valid_vars = []
|
|
for v in self._exec(f"e??j {var_type}", json=True):
|
|
valid_vars.append(v["name"].split(".")[1])
|
|
|
|
# Update directly from __dict__ to avoid __setattr__ and __getattr__
|
|
self.__dict__["valid_vars"] = valid_vars
|
|
self.__dict__["var_type"] = var_type
|
|
|
|
def __getattr__(self, attr):
|
|
if attr in self.valid_vars:
|
|
ret = self._exec(f"e {self.var_type}.{attr}")
|
|
if ret.isdigit():
|
|
ret = int(ret)
|
|
elif ret == "true":
|
|
ret = True
|
|
elif ret == "false":
|
|
ret = False
|
|
return ret
|
|
raise AttributeError()
|
|
|
|
def __setattr__(self, attr, val):
|
|
# Dirty way to avoid infinite recursion
|
|
if attr in ("r2", "_tmp_off"):
|
|
self.__dict__[attr] = val
|
|
elif attr in self.valid_vars:
|
|
if val is True:
|
|
val = "true"
|
|
elif val is False:
|
|
val = "false"
|
|
self._exec(f"e {self.var_type}.{attr}={val}")
|
|
else:
|
|
raise AttributeError()
|
|
|
|
|
|
class Config(R2Base):
|
|
def __init__(self, r2):
|
|
super().__init__(r2)
|
|
|
|
# anal, scr, asm, io...
|
|
self.vars_types = []
|
|
v = self._exec("e??j", json=True)
|
|
for var in v:
|
|
var_type = var["name"].split(".")[0]
|
|
if var_type not in self.vars_types:
|
|
self.vars_types.append(var_type)
|
|
|
|
def __getattr__(self, attr):
|
|
if attr in self.vars_types:
|
|
return ConfigType(self.r2, attr)
|