Skip to content

Commit

Permalink
Fixed TEQ crash
Browse files Browse the repository at this point in the history
  • Loading branch information
aglab2 committed Mar 11, 2023
1 parent 9a00b37 commit 8b8e94a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ROM_OFFSET = 8331264
SRC_FILES = $(patsubst %, $(SRC_DIR)/%.c, $(CPP_FILES))
OBJ_FILES = $(patsubst %, $(OBJ_DIR)/%.o, $(CPP_FILES))

PAYLOAD_RAW = $(OBJ_DIR)/payload-raw
PAYLOAD = $(OBJ_DIR)/payload
PAYLOAD_HEADER = $(TOOL_DIR)/payload_header
PAYLOAD_DATA = $(TOOL_DIR)/payload_data
Expand All @@ -34,9 +35,12 @@ all: $(OBJ_DIR) $(ROM) $(PAYLOAD_HEADER) $(PAYLOAD_DATA)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) $< -c -o $@

$(PAYLOAD): $(OBJ_FILES)
$(PAYLOAD_RAW): $(OBJ_FILES)
$(LD) -o $@ -L. -L $(LIBRARY_PATH) --oformat binary -T ldscript -M $^

$(PAYLOAD): $(PAYLOAD_RAW)
python remove_teq.py $(PAYLOAD_HEADER_SIZE) $(PAYLOAD_RAW) $(PAYLOAD)

$(ROM): $(PAYLOAD)
dd bs=1 seek=$(ROM_OFFSET) if=$^ of=$@ conv=notrunc

Expand Down
33 changes: 33 additions & 0 deletions remove_teq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import sys

header_size = int(sys.argv[1])
path_from = sys.argv[2]
path_to = sys.argv[3]

passthru = False
amount_of_zeros = 0
offset = 0

with open(path_from, "rb") as f_from, open(path_to, "wb") as f_to:
while buf := f_from.read(4):
val = int.from_bytes(buf, byteorder='big')
if header_size:
header_size -= 4
elif not passthru:
if val == 0:
amount_of_zeros += 1
else:
amount_of_zeros = 0

if amount_of_zeros > 4:
print(f'0x{offset:X}: passthrough enabled')
passthru = True

mask = 0b11111100000000000000000000111111
teq = 0b00000000000000000000000000110100
if val & mask == teq:
print(f'0x{offset:X}: teq {val:08X} patched')
val = 0

offset += 4
f_to.write(val.to_bytes(4, byteorder='big'))
2 changes: 1 addition & 1 deletion src/xversion.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
HACKTICE_VERSION(1, 4, 0)
HACKTICE_VERSION(1, 4, 1)

0 comments on commit 8b8e94a

Please sign in to comment.