ApplyTypes: a field of unknown type (std_map, DeathmatchManager) names its first dword instead of being dropped

Shows &g_game->_deathmatchManager (462 uses of field_0x26614) and lets ItemConfig grow past a 4-byte stub, so Manager
accesses read (g_manager->_itemConfig).field_0xc. Takes effect on the next build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-25 17:52:42 -04:00
1 parent 55ff607849
commit 3f1e276667
1 file changed
+8 -10
+8 -10
View File
@@ -36,13 +36,17 @@ public class ApplyTypes extends GhidraScript {
if (base.containsKey(cls)) addFields(s, base.get(cls), depth + 1); if (base.containsKey(cls)) addFields(s, base.get(cls), depth + 1);
List<String[]> own = new ArrayList<>(fields.getOrDefault(cls, List.of())); List<String[]> own = new ArrayList<>(fields.getOrDefault(cls, List.of()));
own.sort(Comparator.comparingInt(f -> Integer.decode(f[1]))); // in offset order, so an embedded struct beats views into it own.sort(Comparator.comparingInt(f -> Integer.decode(f[1]))); // in offset order, so an embedded struct beats views into it
for (String[] f : own) { for (int i = 0; i < own.size(); i++) {
String[] f = own.get(i);
java.util.regex.Matcher arr = java.util.regex.Pattern.compile("\\[(\\w+)\\]\\s*$").matcher(f[2]); // "int _trinketsID[2]" java.util.regex.Matcher arr = java.util.regex.Pattern.compile("\\[(\\w+)\\]\\s*$").matcher(f[2]); // "int _trinketsID[2]"
String decl = arr.find() ? f[2].substring(0, arr.start()) : f[2]; String decl = arr.find() ? f[2].substring(0, arr.start()) : f[2];
DataType dt = prim(decl); DataType dt = prim(decl);
if (dt == null) continue;
if (arr.find(0)) dt = new ArrayDataType(dt, Integer.decode(arr.group(1)), dt.getLength());
int off = Integer.decode(f[1]); int off = Integer.decode(f[1]);
int room = i + 1 < own.size() ? Integer.decode(own.get(i + 1)[1]) - off : 4;
if (dt == null && !arr.find(0) && room > 0) // unknown type (std_map, DeathmatchManager): name its first dword
dt = room >= 4 ? Undefined4DataType.dataType : new ArrayDataType(ByteDataType.dataType, room, 1);
else if (dt != null && arr.find(0)) dt = new ArrayDataType(dt, Integer.decode(arr.group(1)), dt.getLength());
if (dt == null) continue;
String nm = decl.trim().replaceAll(".*\\s", "").replaceAll("[^\\w]", ""); String nm = decl.trim().replaceAll(".*\\s", "").replaceAll("[^\\w]", "");
try { try {
DataTypeComponent in = off < s.getLength() ? s.getComponentContaining(off) : null; DataTypeComponent in = off < s.getLength() ? s.getComponentContaining(off) : null;
@@ -111,14 +115,8 @@ public class ApplyTypes extends GhidraScript {
// methods whose ECX offsets fit their class (scripts/this_types.py) become __thiscall, typing `this` // methods whose ECX offsets fit their class (scripts/this_types.py) become __thiscall, typing `this`
int fitted = 0; int fitted = 0;
if (getScriptArgs().length > 1) for (String l : Files.readAllLines(Paths.get(getScriptArgs()[1]))) { if (getScriptArgs().length > 1) for (String l : Files.readAllLines(Paths.get(getScriptArgs()[1]))) {
String[] c = l.split("\t"); Function f = getFunctionAt(toAddr(l.split("\t")[0]));
Function f = getFunctionAt(toAddr(c[0]));
if (f == null || "__thiscall".equals(f.getCallingConventionName())) continue; if (f == null || "__thiscall".equals(f.getCallingConventionName())) continue;
if (f.getName().startsWith("FUN_")) { // unnamed, placed by its ECX offsets: move it into the class
Namespace cn = st.getNamespace(c[1], global);
if (cn == null) continue;
try { f.setParentNamespace(cn); } catch (Exception e) { continue; }
}
Namespace ns = f.getParentNamespace(); Namespace ns = f.getParentNamespace();
if (!(ns instanceof GhidraClass)) try { st.convertNamespaceToClass(ns); } catch (Exception e) { continue; } if (!(ns instanceof GhidraClass)) try { st.convertNamespaceToClass(ns); } catch (Exception e) { continue; }
f.setCallingConvention("__thiscall"); f.setCallingConvention("__thiscall");