From c9fd6086840c416418f8b27cd6df83e2a1bd9ee5 Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Tue, 7 Jun 2016 12:03:19 -0400 Subject: [PATCH] Fix up some stuff. Again. A lot is going wrong here. --- host/bytecode_asm.py | 38 ++++++++++++++++++++------------------ patch/memexec.pco | 8 +++----- source/interp.c | 25 ++++++++++++------------- source/menu.c | 3 --- 4 files changed, 35 insertions(+), 39 deletions(-) diff --git a/host/bytecode_asm.py b/host/bytecode_asm.py index e5e2c38..27d1c35 100755 --- a/host/bytecode_asm.py +++ b/host/bytecode_asm.py @@ -149,7 +149,9 @@ def parse_op(token_list, instr_offs): else: tok = bytearray.fromhex(token_list[1]) num = struct.unpack(">H", tok)[0] - return bytearray.fromhex("07") + struct.pack(">H", instr_offs[num]) + val = bytearray(struct.pack(">H", instr_offs[num])) + val.reverse() + return bytearray.fromhex("07") + val elif token_list[0] == "rewind": return bytearray.fromhex("08") elif token_list[0] == "and": @@ -186,7 +188,9 @@ def parse_op(token_list, instr_offs): if s != 2: syn_err("invalid number of arguments") - return bytearray.fromhex("0F") + bytearray.fromhex(token_list[1]) + val = bytearray.fromhex(token_list[1]) + val.reverse() + return bytearray.fromhex("0F") + val elif token_list[0] == "jmpeq": if s != 2: syn_err("invalid number of arguments") @@ -196,7 +200,8 @@ def parse_op(token_list, instr_offs): else: tok = bytearray.fromhex(token_list[1]) num = struct.unpack(">H", tok)[0] - return bytearray.fromhex("17") + struct.pack(">H", instr_offs[num]) + val = bytearray(struct.pack(">H", instr_offs[num])) + return bytearray.fromhex("17") + val elif token_list[0] == "jmpne": if s != 2: syn_err("invalid number of arguments") @@ -206,7 +211,8 @@ def parse_op(token_list, instr_offs): else: tok = bytearray.fromhex(token_list[1]) num = struct.unpack(">H", tok)[0] - return bytearray.fromhex("27") + struct.pack(">H", instr_offs[num]) + val = bytearray(struct.pack(">H", instr_offs[num])) + return bytearray.fromhex("27") + val elif token_list[0] == "jmplt": if s != 2: syn_err("invalid number of arguments") @@ -216,7 +222,8 @@ def parse_op(token_list, instr_offs): else: tok = bytearray.fromhex(token_list[1]) num = struct.unpack(">H", tok)[0] - return bytearray.fromhex("37") + struct.pack(">H", instr_offs[num]) + val = bytearray(struct.pack(">H", instr_offs[num])) + return bytearray.fromhex("37") + val elif token_list[0] == "jmpgt": if s != 2: syn_err("invalid number of arguments") @@ -226,7 +233,8 @@ def parse_op(token_list, instr_offs): else: tok = bytearray.fromhex(token_list[1]) num = struct.unpack(">H", tok)[0] - return bytearray.fromhex("47") + struct.pack(">H", instr_offs[num]) + val = bytearray(struct.pack(">H", instr_offs[num])) + return bytearray.fromhex("47") + val elif token_list[0] == "jmple": if s != 2: syn_err("invalid number of arguments") @@ -236,7 +244,8 @@ def parse_op(token_list, instr_offs): else: tok = bytearray.fromhex(token_list[1]) num = struct.unpack(">H", tok)[0] - return bytearray.fromhex("57") + struct.pack(">H", instr_offs[num]) + val = bytearray(struct.pack(">H", instr_offs[num])) + return bytearray.fromhex("57") + val elif token_list[0] == "jmpge": if s != 2: syn_err("invalid number of arguments") @@ -246,7 +255,8 @@ def parse_op(token_list, instr_offs): else: tok = bytearray.fromhex(token_list[1]) num = struct.unpack(">H", tok)[0] - return bytearray.fromhex("67") + struct.pack(">H", instr_offs[num]) + val = bytearray(struct.pack(">H", instr_offs[num])) + return bytearray.fromhex("67") + val def pad_zero_r(x, c): while len(x) < c: @@ -295,11 +305,7 @@ with open(in_file, "r") as ins: for line in ins: lines += 1 tokens = re.split("\s+", line.strip("\n")) # Split by whitespace. - try: - bytes = parse_op(tokens, None) # Parse. - except: - print("Error on line " + str(lines)) - exit(1) + bytes = parse_op(tokens, None) # Parse. if bytes: offsets += [size] size += len(bytes) @@ -312,11 +318,7 @@ with open(in_file, "r") as ins: for line in ins: lines += 1 tokens = re.split("\s+", line.strip("\n")) # Split by whitespace. - try: - bytes = parse_op(tokens, offsets) # Parse. - except: - print("Error on line " + str(lines)) - exit(1) + bytes = parse_op(tokens, offsets) # Parse. if bytes: bytecode += bytes diff --git a/patch/memexec.pco b/patch/memexec.pco index a61e1ab..37ceca3 100644 --- a/patch/memexec.pco +++ b/patch/memexec.pco @@ -4,16 +4,14 @@ # $uuid 06 # $flags devmode -# Status: needs assembler to be fixed - -# Relative to NATIVE_FIRM, section index [1] +# 0: Relative to NATIVE_FIRM, section index [1] rel native_s1 -# Find this byte string. +# 1: Find this byte string. find 9705000015E40000 # Move backwards until we find what we want. -# LOOP: +# LOOP (2): back 04 test 16640100 jmpne 0002 diff --git a/source/interp.c b/source/interp.c index 0eb06da..24926c9 100644 --- a/source/interp.c +++ b/source/interp.c @@ -209,14 +209,14 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug) if (debug) log("jmp\n"); code++; - code = bytecode + code[1] + (code[0] << 8); + code = bytecode + (code[0] + (code[1] << 8)); break; case OP_JMPEQ: // Jump to offset if equal if (debug) log("jmpeq\n"); code++; if (eq) - code = bytecode + code[1] + (code[0] << 8); + code = bytecode + (code[0] + (code[1] << 8)); else code += 2; break; @@ -225,7 +225,7 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug) log("jmpne\n"); code++; if (!eq) - code = bytecode + code[1] + (code[0] << 8); + code = bytecode + (code[0] + (code[1] << 8)); else code += 2; break; @@ -234,7 +234,7 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug) log("jmplt\n"); code++; if (lt) - code = bytecode + code[1] + (code[0] << 8); + code = bytecode + (code[0] + (code[1] << 8)); else code += 2; break; @@ -243,7 +243,7 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug) log("jmpgt\n"); code++; if (gt) - code = bytecode + code[1] + (code[0] << 8); + code = bytecode + (code[0] + (code[1] << 8)); else code += 2; break; @@ -252,7 +252,7 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug) log("jmple\n"); code++; if (lt || eq) - code = bytecode + code[1] + (code[0] << 8); + code = bytecode + (code[0] + (code[1] << 8)); else code += 2; break; @@ -261,7 +261,7 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug) log("jmpge\n"); code++; if (gt || eq) - code = bytecode + code[1] + (code[0] << 8); + code = bytecode + (code[0] + (code[1] << 8)); else code += 2; break; @@ -332,16 +332,15 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug) if (debug) log("seek\n"); code++; - offset = ( code[3] + (code[2] << 8) + (code[1] << 16) + (code[0] << 24)); - if (offset > current_mode->size) { + offset = code[0] + (code[1] << 8) + (code[2] << 16) + (code[3] << 24); + if (offset > current_mode->size) { // Went out of bounds. Error. #ifndef LOADER fprintf(stderr, "%x", offset); #endif - // Went out of bounds. Error. abort("seeked out of bounds\n"); - } - else - code += 4; + } + + code += 4; break; case OP_NEXT: if (debug) diff --git a/source/menu.c b/source/menu.c index 04b0eee..488cabd 100644 --- a/source/menu.c +++ b/source/menu.c @@ -56,9 +56,6 @@ static struct options_s options[] = { { OPTION_OVERLY_VERBOSE, "Verbose", "Output more debug information than the average user needs.", boolean_val, 0, 0 }, { OPTION_SAVE_LOGS, "Logging", "Save logs to the corbenik folder. Slows operation a bit.", boolean_val, 0, 0 }, - { OPTION_RECONFIGURED, "Reconfigured (DO NOT UNCHECK)", "If patches were reconfigured, this will be set. Do not untick this if ticked.", boolean_val, 0, - 0 }, - // { OPTION_ARM9THREAD, "ARM9 Thread", boolean_val, 0, 0 }, // { IGNORE_PATCH_DEPS, "Ignore dependencies", boolean_val, 0, 0 }, // { IGNORE_BROKEN_SHIT, "Allow unsafe options", boolean_val, 0, 0 }, -- 2.39.5