diff --git a/reverse-sandbox/operation_node.py b/reverse-sandbox/operation_node.py index bb59317..2d85634 100644 --- a/reverse-sandbox/operation_node.py +++ b/reverse-sandbox/operation_node.py @@ -426,7 +426,7 @@ def __eq__(self, other): return self.raw == other.raw def __hash__(self): - return struct.unpack('I', - ''.join([chr(x) for x in re[i:i+4]]))[0] + b''.join([bytes([x]) for x in re[i:i+4]]))[0] node_transition = struct.unpack('>I', - ''.join([chr(x) for x in re[i+4:i+8]]))[0] + b''.join([bytes([x]) for x in re[i+4:i+8]]))[0] node_arg = struct.unpack('>I', - ''.join([chr(x) for x in re[i+8:i+12]]))[0] + b''.join([bytes([x]) for x in re[i+8:i+12]]))[0] i += 12 logger.debug('node idx:{:#010x} type: {:#02x} arg: {:#010x}' \ @@ -136,10 +136,10 @@ def transform(x): return c class_size = struct.unpack('>I', - ''.join([chr(x) for x in re[i:i+4]]))[0] + b''.join([bytes([x]) for x in re[i:i+4]]))[0] i += 0x4 content = struct.unpack('>{}I'.format(class_size), - ''.join([chr(x) for x in re[i:i+4*class_size]])) + b''.join([bytes([x]) for x in re[i:i+4*class_size]])) i += 0x4 * class_size assert(class_size % 2 == 0) @@ -162,23 +162,23 @@ class RegexParser(object): @staticmethod def parse(re, i, regex_list): node_count = struct.unpack('>I', - ''.join([chr(x) for x in re[i:i+0x4]]))[0] + b''.join([bytes([x]) for x in re[i:i+0x4]]))[0] logger.debug('node count = {:#x}'.format(node_count)) start_node = struct.unpack('>I', - ''.join([chr(x) for x in re[i+0x4:i+0x8]]))[0] + b''.join([bytes([x]) for x in re[i+0x4:i+0x8]]))[0] logger.debug('start node = {:#x}'.format(start_node)) end_node = struct.unpack('>I', - ''.join([chr(x) for x in re[i+0x8:i+0xC]]))[0] + b''.join([bytes([x]) for x in re[i+0x8:i+0xC]]))[0] logger.debug('end node = {:#x}'.format(end_node)) cclass_count = struct.unpack('>I', - ''.join([chr(x) for x in re[i+0xC:i+0x10]]))[0] + b''.join([bytes([x]) for x in re[i+0xC:i+0x10]]))[0] logger.debug('character class count = {:#x}'.format(cclass_count)) submatch_count = struct.unpack('>I', - ''.join([chr(x) for x in re[i+0x10:i+0x14]]))[0] + b''.join([bytes([x]) for x in re[i+0x10:i+0x14]]))[0] i += 0x14 logger.debug('submatch count = {:#x}'.format(submatch_count)) diff --git a/reverse-sandbox/regex_parser_v2.py b/reverse-sandbox/regex_parser_v2.py index cd8c1ed..dffbb9b 100644 --- a/reverse-sandbox/regex_parser_v2.py +++ b/reverse-sandbox/regex_parser_v2.py @@ -112,13 +112,13 @@ def parse_parantheses_close(node_type, node_arg, node_transition, node_idx): def node_parse(re, i, regex_list, node_idx): node_type = struct.unpack('= 12: f.seek(8) re_table_count = struct.unpack("= 13: @@ -328,7 +333,7 @@ def main(): else: f.seek(offset * 8) re_length = struct.unpack("= 0x10 and b < 0x3f: - rss.token = "${" + global_vars[b-0x10] + "}" + rss.token = b"${" + global_vars[b-0x10] + b"}" b = rss.get_next_byte() rss.update_state(b) elif rss.state == rss.STATE_CONCAT_BYTE_READ: @@ -335,7 +342,7 @@ def parse_byte_string(self, s, global_vars): logger.warn("last state is not STATE_END_BYTE_READ ({:d})".format(rss.state)) logger.warn("previous state ({:d})".format(rss.state_stack[len(rss.state_stack)-1])) - logger.info("initial string: " + " ".join("0x{:02x}".format(ord(c)) for c in s)) + logger.info("initial string: " + " ".join("0x{:02x}".format(c) for c in s)) logger.info("output_strings (num: {:d}): {:s}".format(len(rss.output_strings), ",".join('"{:s}"'.format(s) for s in rss.output_strings))) return rss.output_strings diff --git a/reverse-sandbox/sandbox_filter.py b/reverse-sandbox/sandbox_filter.py index 1df0f12..e5d7cb2 100644 --- a/reverse-sandbox/sandbox_filter.py +++ b/reverse-sandbox/sandbox_filter.py @@ -37,7 +37,7 @@ def get_filter_arg_string_by_offset(f, offset): if ios_major_version >= 10: f.seek(offset * 8) s = f.read(4+len) - logger.info("binary string is " + s.encode("hex")) + logger.info("binary string is " + s.hex()) ss = reverse_string.SandboxString() myss = ss.parse_byte_string(s[4:], global_vars) actual_string = "" @@ -72,7 +72,7 @@ def get_filter_arg_string_by_offset_with_type(f, offset): if ios_major_version >= 10: f.seek(base_addr + offset * 8) s = f.read(4+len) - logger.info("binary string is " + s.encode("hex")) + logger.info("binary string is " + s.hex()) ss = reverse_string.SandboxString() myss = ss.parse_byte_string(s[4:], global_vars) append = "literal" diff --git a/reverse-sandbox/sandbox_regex.py b/reverse-sandbox/sandbox_regex.py index 9a3f14a..effbab6 100644 --- a/reverse-sandbox/sandbox_regex.py +++ b/reverse-sandbox/sandbox_regex.py @@ -456,7 +456,7 @@ def create_regex_list(re): regex_list = [] - version = struct.unpack('>I', ''.join([chr(x) for x in re[:4]]))[0] + version = struct.unpack('>I', b''.join([bytes(chr(x), 'utf-8') for x in re[:4]]))[0] logger.debug("re.version: 0x%x", version) i = 4