forked from glankk/gz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenhooks
More file actions
executable file
·48 lines (42 loc) · 1.72 KB
/
genhooks
File metadata and controls
executable file
·48 lines (42 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env sh
if [ -z "$AS" ]; then AS="mips64-gcc"; fi
if [ -z "$CC" ]; then CC="mips64-gcc"; fi
if [ -z "$NM" ]; then NM="mips64-nm"; fi
if [ -z "$READELF" ]; then READELF="mips64-readelf"; fi
elf="$1"
if [ -z "$elf" ]; then
echo usage: \`genhooks \<elf-file\>\`
exit
fi
z64def()
{
printf "#include \"src/gz/z64.h\"\n$1" | $CC -E - $CPPFLAGS | tail -n 1 -
}
gzsym()
{
echo "0x`$NM "$elf" | grep " $1\$" | sed -e "s/[0-9A-Fa-f]\{8\}\?\([0-9A-Fa-f]\{8\}\).*/\1/"`"
}
asmgsc()
{
addr="$(printf "%d" "$1")"
addr="$(expr "$addr" % 536870912 + 2164260864)" # addr = addr & 0x1FFFFFFF | 0x81000000
tmpfile="$(mktemp)"
echo ".set noreorder; .set noat; $2" | $AS -x assembler -c - -o "$tmpfile"
$READELF -x .text "$tmpfile" | grep "0x[0-9A-Fa-f]\{8\}" | grep -o " [0-9A-Fa-f]\{8\}" |
while read -r line; do
printf "%08X %04X\n" "$addr" "0x`echo "$line" | sed -s "s/\(....\)..../\1/"`"
addr="$(expr "$addr" + 2)"
printf "%08X %04X\n" "$addr" "0x`echo "$line" | sed -s "s/....\(....\)/\1/"`"
addr="$(expr "$addr" + 2)"
done
rm -f "$tmpfile"
}
asmgsc "$(z64def z64_main_hook_addr)" "jal $(gzsym _start);"
asmgsc "$(z64def z64_entrance_offset_hook_addr)" "jal $(gzsym entrance_offset_hook); nop;"
asmgsc "$(z64def z64_frame_update_call_addr)" "jal $(gzsym update_hook); nop;"
asmgsc "$(z64def z64_frame_input_call_addr)" "jal $(gzsym input_hook); nop;"
disp_hook="$(gzsym disp_hook)"
asmgsc "$(z64def z64_disp_swap_1_addr)" "jal $disp_hook;"
asmgsc "$(z64def z64_disp_swap_2_addr)" "jal $disp_hook;"
asmgsc "$(z64def z64_disp_swap_3_addr)" "jal $disp_hook;"
asmgsc "$(z64def z64_disp_swap_4_addr)" "jal $disp_hook;"