def get_flag_and_id(size, type): flag = 0x00000000 typeid = -1 if size == 1: flag = 0x00000000 # byte elif size == 2: flag = 0x10000000 # word elif size == 4: flag = 0x20000000 # dword elif size == 8: flag = 0x30000000 # qword try: typeTable = type.get("table") except AttributeError: return {"flag": flag, "typeid": typeid} if typeTable == "PDOMCStructure" or typeTable == "PDOMCPPClassType": flag = 0x60000000 typeid = idaapi.get_struc_id(str(type.get("name"))) return {"flag": flag, "typeid": typeid} elif typeTable == "PDOMCEnumeration" or typeTable == "PDOMCPPEnumeration": typeid = idaapi.get_enum_size( idaapi.get_enum(str(type.get("name")))) elif typeTable == "PDOMCTypedef" or typeTable == "PDOMCPPTypedef": return IDAtools.get_flag_and_id(size, type.get("type")) return {"flag": flag, "typeid": typeid}
def get_size(name, type, line): if type == "BasicType": try: return idc.SizeOf(idc.parse_decl(str(name), 0)[1]) except: try: idc.SizeOf( idc.parse_decl(str(line.get("type").get("name")), 0)[1]) except: return 1 elif type == "ArrayType": subType = line.get("type") if not subType: return line.get("size") typeSize = IDAtools.get_size(str(subType.get("name")), subType.get("table"), subType) try: return (typeSize * int(line.get("size"))) except TypeError: return 1 elif type == "PointerType" or type == "ReferenceType" or type == "QualifierType": return 4 elif type == "CFunctionType" or type == "CPPFunctionType": return 4 elif type == "PDOMCEnumeration" or type == "PDOMCPPEnumeration": return idaapi.get_enum_size(idaapi.get_enum(str(name))) elif type == "PDOMCStructure" or type == "PDOMCPPClassType": return idaapi.get_struc_size(idaapi.get_struc_id(str(name))) elif type == "PDOMCTypedef" or type == "PDOMCPPTypedef": subType = line.get("type") if not subType: return 1 return IDAtools.get_size(subType.get("name"), subType.get("table"), subType) else: raise Exception("Missing case", type)
def __len__(self): """Number of members in the enum""" return idaapi.get_enum_size(self._eid)