From 3f888496363d1be6aae5986d8d90d37d3c92ba5d Mon Sep 17 00:00:00 2001 From: shweet Date: Sat, 24 Oct 2026 21:59:11 -0400 Subject: [PATCH] ApplyTypes: classes with __thiscall methods keep a typed this even with no confirmed field Co-Authored-By: Claude Opus 5.5 --- scripts/ApplyTypes.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/ApplyTypes.java b/scripts/ApplyTypes.java index 8864f9c..a8ec3d4 100644 --- a/scripts/ApplyTypes.java +++ b/scripts/ApplyTypes.java @@ -64,12 +64,19 @@ public class ApplyTypes extends GhidraScript { Namespace global = currentProgram.getGlobalNamespace(); Set classes = new TreeSet<>(fields.keySet()); classes.addAll(base.keySet()); + // classes with ZHL __thiscall methods get a struct even with no confirmed field, so `this` is still typed + Set methodClasses = new HashSet<>(); + for (Function f : currentProgram.getListing().getFunctions(true)) { + String cm = f.getComment(); + if (cm != null && cm.contains("__thiscall") && !f.getParentNamespace().isGlobal()) methodClasses.add(f.getParentNamespace().getName()); + } + classes.addAll(methodClasses); int typed = 0; for (int pass = 0; pass < 3; pass++) // later passes embed structs (Entity._sprite is an ANM2) built by earlier ones for (String cls : classes) { StructureDataType s = new StructureDataType(cls, 4); addFields(s, cls, 0); - if (s.getLength() < 0x20) continue; // skip trivial structs + if (s.getLength() < 0x20 && !methodClasses.contains(cls)) continue; // skip trivial structs DataType dt = dtm.addDataType(s, DataTypeConflictHandler.REPLACE_HANDLER); Namespace ns = st.getNamespace(cls, global); if (ns == null) ns = st.createClass(global, cls, SourceType.USER_DEFINED);