#!/bin/bash # Usage: find.sh MODE ARG # name REGEX functions whose qualified name matches (addr name size) # str REGEX strings matching, with the functions using them (addr "string" users) # strs X strings a function uses (anm2 animations/events, sounds, paths) # code REGEX functions whose decompiled C contains REGEX (addr name hits) # callers X who calls X (address or exact name) # callees X what X calls # npc TYPE NPC AI function(s) for an entities2.xml type id (see README) # item ID code lines testing collectible/trinket ID (HasCollectible(0x34,..), HasTrinket, ...) # active ID [N] the case(s) for active item ID in Entity_Player::UseActiveItem (N lines each, default 60) # player ID code comparing the player type to ID (heuristic: compare within 4 lines of a player-type read) # enum REGEX game enums (entity types, collectibles, trinkets, cards, players...) from REPENTOGON # lua REGEX Lua API bindings (class, member, target function or field+offset) # val ADDR constant at DAT_ADDR as int/float/double/string (decompiler leaves floats as DAT_) # field REGEX known struct field offsets (REPENTOGON zhl struct defs) # vtable CLASS vtable slots of an RTTI class, read from the exe (e.g. Weapon_Knife, Entity_Player) D="$(cd "$(dirname "$0")" && pwd)"; T="$D/dump" MODE="$1"; ARG="$2" [ -z "$ARG" ] && { sed -n '2,17p' "$0"; exit 1; } addr_of() { # address or name -> 8-digit address if [[ "$1" =~ ^(0x)?[0-9a-fA-F]{6,8}$ ]]; then printf '%08x\n' $((16#${1#0x})) else awk -F'\t' -v n="$1" '$2 == n "" {print $1}' "$T/functions.tsv"; fi } name_of() { awk -F'\t' 'NR==FNR {n[$1]=$2; next} {print $0 "\t" n[$1]}' "$T/functions.tsv" -; } case "$MODE" in name) grep -E -- "$ARG" <(cut -f1-3 "$T/functions.tsv") ;; str) awk -F'\t' -v r="$ARG" '$2 ~ r' "$T/strings.tsv" ;; code) awk -v r="$ARG" '/^\/\/@@ / {h=$2" "$3; next} $0 ~ r {c[h]++} END {for (k in c) print k, c[k]}' "$T/all.c" | sort ;; strs) for a in $(addr_of "$ARG"); do awk -F'\t' -v a="$a:" 'index($3, a) {print $2}' "$T/strings.tsv"; "$D/decompile.sh" "$a" | grep -o '"[^"]*"' | tr -d '"'; done | sort -u ;; callers) for a in $(addr_of "$ARG"); do awk -F'\t' -v a="$a" '$2 == a "" {print $1}' "$T/calls.tsv"; done | sort -u | name_of ;; callees) for a in $(addr_of "$ARG"); do awk -F'\t' -v a="$a" '$1 == a "" {print $2}' "$T/calls.tsv"; done | sort -u | name_of ;; npc) grep -P "^$ARG\t" "$T/npc_ai.tsv" ;; item) H=$(printf '0x%x' "$ARG") awk -v r="(Collectible|Trinket)[A-Za-z]*[(]([^,()]*,)?($H|$ARG)[,)]" '/^\/\/@@ / {h=$2" "$3; next} $0 ~ r {gsub(/^ +/, ""); print h "\t" $0}' "$T/all.c" ;; active) H=$(printf '%x' "$ARG") "$D/decompile.sh" Entity_Player::UseActiveItem | awk -v r="case ([(][^)]*[)])?(0x$H|$ARG):|caseD_$H:" -v n="${3:-60}" '$0 ~ r {w=n; print "---- line " NR} w-- > 0' ;; player) H=$(printf '0x%x' "$ARG") # player-type read, then a compare/case with ID within 4 lines awk -v r="([!=]= |case )($H|$ARG)([^0-9a-fx]|$)" '/^\/\/@@ / {h=$2" "$3; next} /_playerType|0x13c0|GetPlayerType/ {w=5} w-- > 0 && $0 ~ r {gsub(/^ +/, ""); print h "\t" $0}' "$T/all.c" ;; enum) grep -P -- "$ARG" "$D/repentogon/libzhl/functions/Global.zhl" | sed 's/^ *//' ;; lua) grep -P -- "$ARG" "$T/lua_bindings.tsv" ;; val) python3 -I "$D/scripts/read_value.py" "$D/bin/isaac-ng.exe" "${ARG#DAT_}" ;; field) grep -P -- "$ARG" "$T/zhl_fields.tsv" ;; vtable) python3 -I "$D/scripts/vtable.py" "$D/bin/isaac-ng.exe" "$T/functions.tsv" "$ARG" "${3:-40}" ;; *) sed -n '2,17p' "$0"; exit 1 ;; esac