ApplyTypes: place fields in offset order and keep an embedded struct over views into it
Entity._sprite (ANM2, now its full 0x114) was being overwritten by _spriteOffset/_spriteScale/_isFlipX, which are sprite members; every sprite access had fallen back to field_0x48/0x78/0x7c/0x8c. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
67c8120d40
commit
540cc49d34
1 file changed
+5
-1
@@ -34,7 +34,9 @@ public class ApplyTypes extends GhidraScript {
|
|||||||
void addFields(StructureDataType s, String cls, int depth) {
|
void addFields(StructureDataType s, String cls, int depth) {
|
||||||
if (depth > 8) return;
|
if (depth > 8) return;
|
||||||
if (base.containsKey(cls)) addFields(s, base.get(cls), depth + 1);
|
if (base.containsKey(cls)) addFields(s, base.get(cls), depth + 1);
|
||||||
for (String[] f : 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
|
||||||
|
for (String[] f : own) {
|
||||||
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);
|
||||||
@@ -43,6 +45,8 @@ public class ApplyTypes extends GhidraScript {
|
|||||||
int off = Integer.decode(f[1]);
|
int off = Integer.decode(f[1]);
|
||||||
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;
|
||||||
|
if (in != null && in.getOffset() != off && in.getDataType() != DataType.DEFAULT) continue; // inside a placed member (Entity 0xdc is _sprite._offset): keep the member
|
||||||
if (off + dt.getLength() > s.getLength()) s.growStructure(off + dt.getLength() - s.getLength());
|
if (off + dt.getLength() > s.getLength()) s.growStructure(off + dt.getLength() - s.getLength());
|
||||||
s.replaceAtOffset(off, dt, dt.getLength(), nm, null);
|
s.replaceAtOffset(off, dt, dt.getLength(), nm, null);
|
||||||
} catch (Exception e) { /* overlapping/odd field: skip */ }
|
} catch (Exception e) { /* overlapping/odd field: skip */ }
|
||||||
|
|||||||
Reference in new issue
Block a user