Skip to content

Instantly share code, notes, and snippets.

@NyaMisty
Last active January 1, 2024 15:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NyaMisty/693db2ce2e75c230f36b628fd7610852 to your computer and use it in GitHub Desktop.
Save NyaMisty/693db2ce2e75c230f36b628fd7610852 to your computer and use it in GitHub Desktop.
Resync IDA Local Types

Resync Local Types in IDA

Sometimes there's some inconsistency between local types and structs view.

Typically, you can see the type in the "Structures" view are zero-lengthed, which should normally be the same size as local type's one.

When this happens, you'll not be able to rename the structure fields in HexRay Decompiler's view, and both hotkey N and right-clicking the item won't show the rename popup.

After reverse engineering the hexx64.dll, I found that IDA tries to do the following things:

if (vd->item->get_memptr()) { /* Add the rename handler */ }

and in get_memptr(), it's doing:

const char *name = expr->x->type.get_type_name()
struc_t *struc = get_struc(get_struc_id(name))
member_t *member  = get_member(struc, expr->m)

After debugging, it seems that name and struc can be retrieved, but member are not. Replaying the operations in IDAPython also fails.

I thought it's because that IDA didn't import the type correctly last time, so I wrote the script above to fix it.

def is_autosync(name, tif):
return idaapi.get_ordinal_from_idb_type(name, tif.get_decltype().to_bytes(1, 'little')) != -1
for ord in range(1, idaapi.get_ordinal_qty(None)):
t = idaapi.tinfo_t()
t.get_numbered_type(None, ord)
typename = t.get_type_name()
#print('Processing struct %d: %s' % (ord, typename))
if typename.startswith('#'):
continue
autosync = is_autosync(typename, t)
print('Processing struct %d: %s%s' % (ord, typename, ' (autosync) ' if autosync else ''))
idaapi.import_type(None, -1, typename, idaapi.IMPTYPE_OVERRIDE)
if autosync:
continue
struc = idaapi.get_struc(idaapi.get_struc_id(typename))
if not struc:
continue
struc.ordinal = -1
idaapi.save_struc(struc, False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment