From e41ab93b2f88ee5beefd43c755dba52aeb55758c Mon Sep 17 00:00:00 2001 From: David Bors Date: Wed, 30 Nov 2022 20:34:55 +0200 Subject: [PATCH] feat: Update reverse operations to Python3 Up until now all reverse operations needed `Python2` to run. This lead to a user needing to have 2 different versions of Python installed on their system. Now, only `Python3` is required to run all `Sandblaster` operations. Signed-off-by: David Bors --- reverse-sandbox/operation_node.py | 2 +- reverse-sandbox/regex_parser_v1.py | 20 ++++++++++---------- reverse-sandbox/regex_parser_v2.py | 24 ++++++++++++------------ reverse-sandbox/regex_parser_v3.py | 2 +- reverse-sandbox/reverse_sandbox.py | 22 ++++++++++++++-------- reverse-sandbox/sandbox_regex.py | 2 +- 6 files changed, 39 insertions(+), 33 deletions(-) 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("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