Skip to content
joelpx edited this page Feb 3, 2016 · 1 revision

Source code structure

  • lib/_init_.py : definition of two important classes : GlobalContext and AddrContext. The first one contains all preferences and it's in charge to load the binary. In all files, the instance is named gctx. The second class is a context for a dump or a decompilation. It contains the start address, the flow graph, ... It's named as ctx.
  • lib/fileformat :
    • elf.py, pe.py, raw.py : loaders for the appropriate file type.
    • pefile2.py : is a wrapper to pefile with a better support of symbols.
    • binary.py : the Binary class is a wrapper to all loaders. It runs c++filt to demangle symbols. There is also a SectionAbs which is an abstraction of all sections.
  • lib/database.py : all information are serialized with msgpack then compressed with zlib. Contains symbols, defined functions, ...
  • lib/disassembler.py : loads the binary class, manages the database (renaming, jumptables, ...), generates flow graphs, dump disassembly, ... Named in the code as dis.
  • lib/memory.py : The Memory class contains a dictionnary address -> [size, type, priv_value]. For FUNCTION and CODE, priv_value is the function id.
  • lib/analyzer.py : analyze the flow graph, operands, check if the function returns or not, ... It fills the Memory class.
  • lib/output.py : main abstract class to print disassembly.

Architecture dependant :

  • lib/arch/NAME/utils.py : specifies which instruction is a jump (condtional or not), a call, ... Set a symbol for some instructions (example, for MIPS the beq instruction must be printed as ==).
  • lib/arch/NAME/output.py : defines how to print instructions and operands. The class inherits of lib/output.py.
  • lib/arch/NAME/process_ast.py : assign colors, replace instructions in li for MIPS, ...
  • lib/arch/NAME/_init_.py : list of functions defined in process_ast.py.

Pseudo-decompiler algorithm :

  • lib/ast.py : define multiple classes to create the ast and to print it.
  • lib/graph.py : contains the graph definition. The loop detection algorithm is here.
  • lib/generate_ast.py : with the graph and detected loops, it creates the ast.

User-interface :

  • lib/ui/console.py : this is the shell.
  • lib/ui/readline.py : key press manager for the console.
  • lib/ui/window.py : abstract class to display an Output class.
  • lib/ui/visual.py : ncurses interface, inherits from window.py.
  • lib/ui/inlineed.py : inline editor. It inherits from window.py.
  • lib/ui/vim.py : exports output for Vim.

Others :

  • lib/custom_colors.py : here you can set your own colors.
  • lib/colors.py : print strings in color.
  • lib/utils.py
  • lib/exceptions.py
Clone this wiki locally