|
BinNavi database format
In the latest version of BinNavi we moved to SQL for storage of the disassembly information. We spent a fair amount of time thinking about how to best store the disassembly information in a way that would be as little architecture-dependent as possible and allow for fast querying while, at the same time, trying to not make it too hard to use directly through SQL. We also wanted to be able to have a central repository of all disassembly data, doing away with the need of keeping local databases that easily get out of sync. A central repository has other advantages like allowing for different users to look at the same project. The disassembly data is currently exported from IDA into the database via a exporter , ida2sql, written in Python and requiring IDAPython. This exporter is included with BinNavi and also made available separately. If you want to play with it just drops us a line at Sabre. One can already perform interesting analysis by just using SQL queries directly, although we provide a lot of the functionality in a more convenient form through BinNavis integrated Python interface. The core set of tables looks like this: ![]() The basic table layout is:
For each of the following the module id will be appended to the table name.
Currently only MySQL has been thoroughly tested. Some of the advantages the schema brings are:
Some query examplesListing the modules in the database: SELECT * FROM modules Counting the number of functions: SELECT count(address) FROM functions Counting the number of basic blocks (blocks shared by functions will be counted multiple times): SELECT count(address) FROM basic_blocks and without counting the shared ones: SELECT count(DISTINCT(address)) FROM basic_blocks; How about a histogram showing the of mnemonic distribution? SELECT mnemonic, COUNT(mnemonic) as mnem_count FROM instructions GROUP BY mnemonic ORDER BY mnem_count; . . or, 275 inc, 361 movzx, 377 leave, 392 sub, 403 stos, 429 . . or something a bit more elaborate like getting all addresses in a disassembly where a specific register is used: SELECT HEX(instructions.address), mnemonic FROM instructions JOIN (operand_tuples, operand_expressions, expression_tree) ON instructions.address = operand_tuples.address AND operand_tuples.operand_id = operand_expressions.operand_id AND expression_tree.id = operand_expressions.expr_id WHERE symbol=ebp; . . 71CF14D3, mov 71CF14D6, mov 71CF14E9, pop 71CF15E1, push 71CF15E2, mov 71CF15E6, mov 71CF1617, pop . . for queries like the last one or more complex ones its usually a good idea to move to the embedded Python interpreter in BinNavi before getting lost in SQL... Comments
| ||||||