diff --git a/ohre/abcre/dis/AsmLiteral.py b/ohre/abcre/dis/AsmLiteral.py index fb9489f..2af429a 100644 --- a/ohre/abcre/dis/AsmLiteral.py +++ b/ohre/abcre/dis/AsmLiteral.py @@ -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("[") diff --git a/ohre/abcre/dis/NAC.py b/ohre/abcre/dis/NAC.py index 9d9486b..a8c4b0f 100644 --- a/ohre/abcre/dis/NAC.py +++ b/ohre/abcre/dis/NAC.py @@ -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]) diff --git a/ohre/abcre/dis/NACTYPE.py b/ohre/abcre/dis/NACTYPE.py index 27b0d11..933238c 100644 --- a/ohre/abcre/dis/NACTYPE.py +++ b/ohre/abcre/dis/NACTYPE.py @@ -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 @@ -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")):