from idautils import *
from idaapi import *
from os.path import *
from idc import *
f = open("DBCMeta.txt", "w+")
# Do not use default set up, we'll call setup().
s = Strings()
field_type_map = {
0: "i",
1: "l",
2: "s",
3: "f",
}
field_size_map = {
0: 4,
1: 8,
2: 4,
3: 4
}
for i, v in enumerate(s):
sv = str(v)
fnf = sv.rpartition('\\')[2]
fn = fnf.rpartition('.')[0]
if fn == "Item-sparse":
fn = "ItemSparse"
xpc2 = sv.endswith("2")
if sv.startswith("DBFilesClient"):
vx = XrefsTo(v.ea, 0)
delta = 0x00 if not xpc2 else 0x04
for vxx in vx:
f.write("struct %sMeta {\n" % fn)
f.write(" constexpr %sMeta() { }\n\n" % fn)
field_count = idc.Dword(vxx.frm + 0x04 + delta)
record_size = idc.Dword(vxx.frm + 0x08 + delta)
index_column = idc.Dword(vxx.frm + 0x10 + delta)
field_offsets_ptr = idc.Dword(vxx.frm + 0x14 + delta * 2)
field_sizes_ptr = idc.Dword(vxx.frm + 0x18 + delta * 2)
field_types_ptr = idc.Dword(vxx.frm + 0x1C + delta * 2)
streamed_str = idc.Dword(vxx.frm + 0x0C + delta * 2) == 0
f.write(" constexpr static const std::uint32_t indexColumn = %d;\n" % index_column)
f.write(" constexpr static const std::uint32_t recordSize = %d; // 0x%X\n" % (record_size, record_size));
f.write(" constexpr static const std::uint32_t fieldOffsets[] = {\n ");
for i in range(field_count):
fmt_str = " %d" if i + 1 == field_count else " %d,"
f.write(fmt_str % idc.Dword(field_offsets_ptr + i * 4))
f.write("\n };\n")
any_str = False
f.write(" constexpr static const char fieldTypes[] = { \"")
for i in range(field_count):
f_type = idc.Dword(field_types_ptr + i * 4)
f_type_str = field_type_map.get(f_type, "{}".format(f_type))
if i == index_column:
f_type_str = "n"
if f_type_str == "s":
any_str = True
f.write("%s" % f_type_str)
f.write("\" };\n")
f.write(" constexpr static const std::uint32_t arraySizes[] = {\n ");
for i in range(field_count):
fmt_str = " %d" if i + 1 == field_count else " %d,"
i_type = idc.Dword(field_types_ptr + i * 4)
f.write(fmt_str % (idc.Dword(field_sizes_ptr + i * 4) / int(field_size_map.get(i_type, 4))))
f.write("\n };\n")
f.write(" constexpr static const bool sparse_storage = %s;\n\n" % ("true" if streamed_str and any_str else "false"))
f.write(" static const char* name() { return \"%s\"; }\n" % fnf);
f.write("\n");
f.write(" static DBMeta<%sMeta> instance() {\n" % fn)
f.write(" static DBMeta _instance { name(), indexColumn, fieldOffsets, fieldTypes, arraySizes };\n")
f.write(" return _instance;\n")
f.write(" };\n")
f.write("}\n\n")
print "Dumped %s" % str(v)
print "Saved to %s" % os.path.realpath(f.name)
f.close()
Bon, des fois #Vélib c'est pas complètement au point hein #debug pic.twitter.com/qt2efmquXP
— Samuel Tardieu (@rfc1149) August 11, 2018
Non seulement le déploiement est une catastrophe mais en plus, l'application est mal codée. #velibgate #velib pic.twitter.com/pHjEzLlWUt
— Mathieu Bonnier ? (@Mat__bon) May 16, 2018