Skip to content

Commit

Permalink
Merge pull request #6 from ohreteam/pk1
Browse files Browse the repository at this point in the history
update literal array and trycatch
  • Loading branch information
Penkace authored Dec 29, 2024
2 parents 73b35e1 + 2bb3ecc commit 377d020
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
44 changes: 43 additions & 1 deletion ohre/abcre/dis/AsmLiteral.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,52 @@ def __init__(self, lines: List[str]):
self.module_request_array: Dict = None
self.module_tags: List[Dict] = None
if (len(lines) == 1):
print(f"AsmLiteral todo: single line, processer is todo") # TODO: normal situation
self._process_normal_literal(lines)
else:
self._process_module_request_array(lines)

def _process_normal_literal(self, lines: List[str]):
literal_content = ' '.join(lines)
s_idx = literal_content.find("{")+1
e_idx = literal_content.find("[")
element_amount_str = literal_content[s_idx:e_idx].strip()
assert element_amount_str.isdigit(), f"Expected a digit for element amount, got {element_amount_str}"
element_amount = int(element_amount_str)

s_idx = literal_content.find("[")+1
e_idx = literal_content.find("]")
element_content = literal_content[s_idx:e_idx]
array_split_list = [x.strip() for x in element_content.strip().split(',') if len(x) > 0]

method_dict = {}
if 'method' in element_content and 'method_affiliate' in element_content:
cnt = 0
while cnt < len(array_split_list):
if 'string' in array_split_list[cnt]:
method_string = array_split_list[cnt].split(':')[1].strip()[1:-1]
method_name = array_split_list[cnt+1].split(':')[1].strip()
method_aff = array_split_list[cnt+2].split(':')[1].strip()
method_dict[method_string] = {'method': method_name, 'method_affiliate': method_aff}
cnt += 3
else:
cnt += 1
method_amount = array_split_list[-1].split(':')[1]
method_dict["method_amount"] = method_amount
else:
cnt = 0
while cnt < len(array_split_list):
variable_string = array_split_list[cnt].split(':')[1].strip()[1:-1]
variable_value = array_split_list[cnt+1]
if 'null_value' in variable_value:
variable_value = 'null_value'
else:
variable_value = variable_value.split(":")[1].strip()
if '"' in variable_value:
variable_value = variable_value.replace('"', '')
cnt += 2
method_dict[variable_string] = variable_value
self.module_tags = [method_dict]

def _process_module_request_array(self, lines: List[str]):
s_idx = lines[0].find("{")
e_idx = lines[0].find("[")
Expand Down
3 changes: 3 additions & 0 deletions ohre/abcre/dis/NAC.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def __init__(self, op_args: List[str]):
self.type = NACTYPE.get_NAC_type(self.op)
if (self.type == NACTYPE.LABEL and self.op.endswith(":")):
self.op = self.op[:-1]
if (self.type == NACTYPE.TRYCATCH and self.op.endswith("catchall")):
# fetch catchall sutition, then need to get try_begin_label_0 and try_end_label_0
self.op = self.op[1:]
self.args: list = list()
for i in range(1, len(op_args)):
self.args.append(op_args[i])
Expand Down
4 changes: 3 additions & 1 deletion ohre/abcre/dis/NACTYPE.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self):
RETURN = 6 # 1 arg
IMPORT = 11
LABEL = 12
TRYCATCH = 13
NOP = 20
# >= 30: need more analysis
CMP_INST = 30 # comparation instructions
Expand All @@ -49,7 +50,8 @@ def get_NAC_type(cls, op: str) -> int:
op = op.strip()
if (op.endswith(":")):
return NACTYPE.LABEL

if (op.endswith("catchall")):
return NACTYPE.TRYCATCH
info_d = cls.isa.get_opstr_info_dict(op)
assert info_d is not None and "title" in info_d.keys()
if (_value_in_key_of_dict(info_d, "properties", "return")):
Expand Down

0 comments on commit 377d020

Please sign in to comment.