Examples | Selecting random structure attributes with tags - arizvisa/ida-minsc GitHub Wiki

Selecting only structures that are marked as listed

Every structure has a name, so in this case the tag only exists if the structure is listed.

for st, tags in struc.select('__name__'):
    print(st, st.name, tags)

Selecting only structures that you've created

Every structure has (is) a type, so in this case the "typeinfo" attribute is used to distinguish whether it's a type you've created or modified with the structure interface.

for st, tags in struc.select('__typeinfo__'):
    print(st, st.name, tags)

Likewise, if you want to find structures/unions that have been imported or come exclusively from the type library you can just iterate through them and check the tag yourself.

for st in struc.iterate():
    if '__typeinfo__' not in st.tag():
        print('not-from-me', st, st.name, st.tag())
    else:
        print('this-one-is-mine', st, st.name)
    continue

This logic "seems" inverted because it lets you easily select the structures in a database that are unique to it (allowing you to serialize them and import them elsewhere).

mystrucs = [st for st, tags in struc.select('__typeinfo__')]
saved = pickle.dumps(mystruc)

Creating a single union for multiple structures

Say you've created multiple structures referencing the same field not realizing that they should've been a union.

# first manually select each of them, commenting^Wtagging them with "[thisone] 1"
newstruc = struc.new('vobject', 'suffix', union=True)
index = 0
for st, tags in struc.select('thisone'):
    if tags['thisone'] == 1:
        newstruc.add(('member', index), st.typeinfo)
    continue

Being a dick?

Say you have no idea what kind of pointer you want...

lol = struc.new('megapointer', union=True)
for st, _ in struc.select():
    lol.add(('field', len(lol.members)), db.types.pointer(st))
print(lol.members)