Skip to content

Commit c9f6e5b

Browse files
committed
rewrite _parse_parameter & add _get_string_by_address in rzapkinfo.py
1 parent 9774a4c commit c9f6e5b

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

quark/core/rzapkinfo.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -709,27 +709,45 @@ def _get_method_by_address(self, address: int) -> MethodObject:
709709
else:
710710
return None
711711

712+
def _get_string_by_address(self, address: str) -> str:
713+
"""
714+
Find the content of string via the specified string address.
715+
716+
:param address: an address used to find the corresponding method
717+
:return: the content in the given address
718+
"""
719+
dexindex = 0
720+
721+
rz = self._get_rz(dexindex)
722+
content = rz.cmd(f"pr @ {int(address, 16)}")
723+
return content
724+
712725
@staticmethod
713-
def _parse_parameter(mnemonic: str, parameter: str) -> Any:
726+
def _parse_parameter(parameter: str, p_type: str = "int") -> Any:
714727
"""Parse the value of the parameter based on the mnemonic.
715728
716729
:param mnemonic: the mnemonic of a bytecode
717730
:param parameter: the parameter of a bytecode
718731
:return: the value of the parameter
719732
"""
720-
if mnemonic.startswith("invoke"):
721-
return re.sub(r"\.", "->", parameter, count=1)
722-
elif mnemonic == "const-wide":
723-
return float(parameter)
724-
elif mnemonic.startswith("const") and "string" not in mnemonic:
725-
return int(parameter, 16)
726-
elif '/lit' in mnemonic:
727-
return int(parameter, 16)
733+
if p_type == "int":
734+
try:
735+
parameter = int(parameter, 16)
736+
except (TypeError, ValueError):
737+
return RizinImp._parse_parameter(parameter, "float")
738+
739+
elif p_type == "float":
740+
try:
741+
parameter = float(parameter)
742+
except (TypeError, ValueError):
743+
return RizinImp._parse_parameter(parameter, "str")
744+
745+
elif p_type == "str":
746+
parameter = re.sub(r"\.", "->", parameter, count=1)
728747

729748
return parameter
730749

731-
@staticmethod
732-
def _parse_smali(smali: str) -> BytecodeObject:
750+
def _parse_smali(self, smali: str) -> BytecodeObject:
733751
"""
734752
Convert a Smali code provided by the Rizin command `pdfj` into a
735753
BytecodeObject.
@@ -752,10 +770,13 @@ def _parse_smali(smali: str) -> BytecodeObject:
752770

753771
args = [arg.strip() for arg in re.split("[{},]+", args) if arg]
754772

773+
if mnemonic == "const-string" and args[-1][:2] == "0x":
774+
args[-1] = self._get_string_by_address(args[-1])
775+
755776
parameter = None
756777
# Remove the parameter at the last
757778
if args and not args[-1].startswith("v"):
758-
parameter = RizinImp._parse_parameter(mnemonic, args[-1])
779+
parameter = RizinImp._parse_parameter(args[-1])
759780
args = args[:-1]
760781

761782
register_list = []

0 commit comments

Comments
 (0)