Legend:
Library
Module
Module type
Parameter
Class
Class type
Disassembled program.
Project contains data that we were able to reconstruct during the disassembly, semantic analysis, and other arbitrary amount of analyses.
Actually, project allows to associate arbitrary data with memory regions, program terms, and even attach them globally to itself. So it can be seen as a knowledge base of deeply interconnected facts.
Other than delivering information, from the bap to a passes, it can be also used as a communication media between different passes, (see Working with project).
from_file filename creates a project from the provided input source.
The input code regions are speculatively disassembled and the set of basic blocks is determined, using the algorithm described in Disasm.Driver. After that the concrete whole program control-flow graph (CFG) is built, which can be accessed with the Project.disasm function. The whole program CFG is then partitioned into a set of subroutines using the dominators analsysis, see Disasm.Subroutines for details. Based on this partition a symbol table, which is a set of a subroutines control-flow graphs, is built. The symbol table, which can be accessed with Project.symbols, also contains information about the interprocedural control flow. Finally, the symbol table is translated into the intermediate representation, which can be accessed using the Project.program function. The whole process is pictured below.
---------------------
( Disassembling )
---------------------
|
+---------------------+
| |
| All instructions |
| and basic blocks |
| |
+---------------------+
|
---------------------
( CFG reconstruction )
---------------------
|
+---------------------+
| |
| The whole program |
| control-flow graph |
| |
+---------------------+
|
---------------------
( Partitioning )
---------------------
|
+---------------------+
| |
| The quotient set of |
| basic blocks |
| |
+---------------------+
|
---------------------
( Constructing Symtab )
---------------------
|
+---------------------+
| |
| The symbol table |
| and the callgraph |
| |
+---------------------+
|
---------------------
( IR Reconstruction )
---------------------
|
+---------------------+
| |
| The IR of the |
| binary program |
| |
+---------------------+
The disassembling process is fully integrated with the knowledge base. If the input source provides information about symbols and their location, then this information will be automatically reflected to the knowledge base.
The brancher, symbolizer, and rooter parameters are ignored since 2.0.0 and their information could be reflected to the knowledge base using, correspondingly, Brancher.provide, Symbolizer.provide, and Rooter.provide functions.
parameterstate
if specified then the provided state will be used as the initial state
parameterpackage
if specified, then all symbols during the disassembly will be created (interned) in the specified package.
since 2.0.0 the state parameter is added
since 2.0.0 the parameter [disassembler] is unused
since 2.0.0 the parameter [brancher] is unused
since 2.0.0 the parameter [symbolizer] is unused
since 2.0.0 the parameter [rooter] is unused
since 2.0.0 the parameter [reconstructor] is unused
map_program t ~f maps the IR representation of the program with function f.
Note: since the program is computed lazily this function should be preferred to program composed with_program for passes that transform the program representation so that they are not run if the program is never ever used.
tag_memory project region tag value tags a given region of memory in project with a given tag and value. Example: Project.tag_memory project tained color red
substitute p region tag value is like tag_memory, but it will also apply substitutions in the provided string value, as per OCaml standard library's Buffer.add_substitute function.
Example:
Project.substitute project comment "$symbol starts at $symbol_addr"
The following substitutions are supported:
$section{_name,_addr,_min_addr,_max_addr} - name of region of file to which it belongs. For example, in ELF this name will correspond to the section name
$symbol{_name,_addr,_min_addr,_max_addr} - name or address of the symbol to which this memory belongs
$asm - assembler listing of the memory region
$bil - BIL code of the tagged memory region
$block{_name,_addr,_min_addr,_max_addr} - name or address of a basic block to which this region belongs
$min_addr, $addr - starting address of a memory region
$max_addr - address of the last byte of a memory region.
has project field checks whether field exists or not. Useful for fields of type unit, that actually isomorphic to bool fields, e.g., if Project.has project mark
To add new pass one of the following register_* functions should be called.
type pass
val register_pass :
?autorun:bool ->?runonce:bool ->?deps:string list->?name:string ->(t->t)->
unit
register_pass ?autorun ?runonce ?deps ?name pass registers a pass over a project.
If autorun is true, then the host program will run this pass automatically. If runonce is true, then for a given project the pass will be run only once. Each repeating attempts to run the pass will be ignored. The runonce parameter defaults to false when autorun is false, and to true otherwise.
Parameter deps is list of dependencies. Each dependency is a name of a pass, that should be run before the pass. The dependencies will be run in a specified order every time the pass is run.
To get access to command line arguments use Plugin.argv
val register_pass' :
?autorun:bool ->?runonce:bool ->?deps:string list->?name:string ->(t-> unit)->
unit
register_pass' pass registers pass that doesn't modify the project effect and is run only for side effect. (See register_pass)