Skip to content

Commit 8b8e94a

Browse files
committed
Fixed TEQ crash
1 parent 9a00b37 commit 8b8e94a

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ROM_OFFSET = 8331264
2020
SRC_FILES = $(patsubst %, $(SRC_DIR)/%.c, $(CPP_FILES))
2121
OBJ_FILES = $(patsubst %, $(OBJ_DIR)/%.o, $(CPP_FILES))
2222

23+
PAYLOAD_RAW = $(OBJ_DIR)/payload-raw
2324
PAYLOAD = $(OBJ_DIR)/payload
2425
PAYLOAD_HEADER = $(TOOL_DIR)/payload_header
2526
PAYLOAD_DATA = $(TOOL_DIR)/payload_data
@@ -34,9 +35,12 @@ all: $(OBJ_DIR) $(ROM) $(PAYLOAD_HEADER) $(PAYLOAD_DATA)
3435
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
3536
$(CC) $(CFLAGS) $< -c -o $@
3637

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

41+
$(PAYLOAD): $(PAYLOAD_RAW)
42+
python remove_teq.py $(PAYLOAD_HEADER_SIZE) $(PAYLOAD_RAW) $(PAYLOAD)
43+
4044
$(ROM): $(PAYLOAD)
4145
dd bs=1 seek=$(ROM_OFFSET) if=$^ of=$@ conv=notrunc
4246

remove_teq.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import sys
2+
3+
header_size = int(sys.argv[1])
4+
path_from = sys.argv[2]
5+
path_to = sys.argv[3]
6+
7+
passthru = False
8+
amount_of_zeros = 0
9+
offset = 0
10+
11+
with open(path_from, "rb") as f_from, open(path_to, "wb") as f_to:
12+
while buf := f_from.read(4):
13+
val = int.from_bytes(buf, byteorder='big')
14+
if header_size:
15+
header_size -= 4
16+
elif not passthru:
17+
if val == 0:
18+
amount_of_zeros += 1
19+
else:
20+
amount_of_zeros = 0
21+
22+
if amount_of_zeros > 4:
23+
print(f'0x{offset:X}: passthrough enabled')
24+
passthru = True
25+
26+
mask = 0b11111100000000000000000000111111
27+
teq = 0b00000000000000000000000000110100
28+
if val & mask == teq:
29+
print(f'0x{offset:X}: teq {val:08X} patched')
30+
val = 0
31+
32+
offset += 4
33+
f_to.write(val.to_bytes(4, byteorder='big'))

src/xversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
HACKTICE_VERSION(1, 4, 0)
1+
HACKTICE_VERSION(1, 4, 1)

0 commit comments

Comments
 (0)