Skip to content

Commit d635f2d

Browse files
committed
rewrite _parse_parameter & add _get_string_by_address in rzapkinfo.py
1 parent de11358 commit d635f2d

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
@@ -697,27 +697,45 @@ def _get_method_by_address(self, address: int) -> MethodObject:
697697
else:
698698
return None
699699

700+
def _get_string_by_address(self, address: str) -> str:
701+
"""
702+
Find the content of string via the specified string address.
703+
704+
:param address: an address used to find the corresponding method
705+
:return: the content in the given address
706+
"""
707+
dexindex = 0
708+
709+
rz = self._get_rz(dexindex)
710+
content = rz.cmd(f"pr @ {int(address, 16)}")
711+
return content
712+
700713
@staticmethod
701-
def _parse_parameter(mnemonic: str, parameter: str) -> Any:
714+
def _parse_parameter(parameter: str, p_type: str = "int") -> Any:
702715
"""Parse the value of the parameter based on the mnemonic.
703716
704717
:param mnemonic: the mnemonic of a bytecode
705718
:param parameter: the parameter of a bytecode
706719
:return: the value of the parameter
707720
"""
708-
if mnemonic.startswith("invoke"):
709-
return re.sub(r"\.", "->", parameter, count=1)
710-
elif mnemonic == "const-wide":
711-
return float(parameter)
712-
elif mnemonic.startswith("const") and "string" not in mnemonic:
713-
return int(parameter, 16)
714-
elif '/lit' in mnemonic:
715-
return int(parameter, 16)
721+
if p_type == "int":
722+
try:
723+
parameter = int(parameter, 16)
724+
except (TypeError, ValueError):
725+
return RizinImp._parse_parameter(parameter, "float")
726+
727+
elif p_type == "float":
728+
try:
729+
parameter = float(parameter)
730+
except (TypeError, ValueError):
731+
return RizinImp._parse_parameter(parameter, "str")
732+
733+
elif p_type == "str":
734+
parameter = re.sub(r"\.", "->", parameter, count=1)
716735

717736
return parameter
718737

719-
@staticmethod
720-
def _parse_smali(smali: str) -> BytecodeObject:
738+
def _parse_smali(self, smali: str) -> BytecodeObject:
721739
"""
722740
Convert a Smali code provided by the Rizin command `pdfj` into a
723741
BytecodeObject.
@@ -740,10 +758,13 @@ def _parse_smali(smali: str) -> BytecodeObject:
740758

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

761+
if mnemonic == "const-string" and args[-1][:2] == "0x":
762+
args[-1] = self._get_string_by_address(args[-1])
763+
743764
parameter = None
744765
# Remove the parameter at the last
745766
if args and not args[-1].startswith("v"):
746-
parameter = RizinImp._parse_parameter(mnemonic, args[-1])
767+
parameter = RizinImp._parse_parameter(args[-1])
747768
args = args[:-1]
748769

749770
register_list = []

0 commit comments

Comments
 (0)