4 ScratchABit is an interactive incremental disassembler with data/control
5 flow analysis capabilities. ScratchABit is dedicated to the efforts of
6 the OpenSource reverse engineering community (reverse engineering to
7 produce OpenSource drivers/firmware for hardware not properly supported
8 by vendors, for hardware and software interoperability, for security
11 ScratchABit supports well-known in the community IDAPython API to write
12 disassembly/extension modules.
14 ScratchABit is a work in progress, features are added on as needed basis,
15 contributions are welcome.
17 ScratchABit is released under the terms of GNU General Public License v3
21 Requirements/manifesto
22 ----------------------
24 1. Should not be written in an obfuscated language. These include languages
25 which are too low-level, which allow to access non-initialized variables,
26 which don't differentiate between variables and functions/procedures, which
27 start array indexes from arbitrary numbers, etc., etc. ScratchABit is
28 written in Python (modern version, Python3) for your pleasure and sanity.
30 2. User interface framework should allow user interaction of the needed
31 level, not add dependencies, bloat, issues, and incompatibilities between
32 framework's versions. ScratchABit currently uses simple full-screen text
33 user interface, using ANSI/VT100 terminal escape sequences (yes, even
34 curses library was deemed too bloat a dependency to force upon users).
36 3. Should leverage easy to use text formats to store "database", to
37 facilitate easy reuse and tool writing, and storage in version control
44 To use ScratchABit, you need Python3 installed and VT100 (minimum) or
45 XTerm (recommended) terminal or terminal emulator (any Unix system
46 should be compliant, like Linux/BSD/etc., see FAQ below for more).
50 git clone --recursive https://github.com/pfalcon/ScratchABit
52 If you cloned code without `--recursive`, run `git submodule update --init`
53 in the ScratchABit directory.
55 ScratchABit now ships with [Capstone Engine](http://www.capstone-engine.org/)
56 based CPU plugin(s), which allow access to a number of CPU architectures.
57 To use it, recent Python bindings module for Capstone should be installed
58 (in the preference to packages shipped by OS distributions, which are often
59 outdated). The easiest way to install it is into the Python user packages
62 pip3 install --no-cache-dir --user capstone
64 An alternative is to install it to a Python
65 [virtual environment](https://docs.python.org/3/library/venv.html) within
66 the ScratchABit directory:
69 source .venv/bin/activate
70 pip3 install --no-cache-dir capstone
72 Whenever you open a new terminal session to work with ScratchABit,
73 run `source .venv/bin/activate` command again to activate the virtual
76 If nothing of the above works, you can try to install the capstone
77 package system-wide (not recommended):
79 sudo pip3 install --system capstone
85 If you want to disassemble a file in self-describing executable format
86 (like ELF), just pass it as an argument to `ScratchABit.py`. The repository
87 includes a number of `example-*.elf` files for various architectures for
88 a quick start. For example, to try x86 32bit version:
90 python3 ScratchABit.py example-x86_32.elf
92 Alternatively, if you want to disassemble a raw binary file, you need
93 to create a .def (definition) file, to specify what memory areas are
94 defined for the code, at which address to load binary file, etc. (Note:
95 a .def file may be useful for .elf and similar files too.) The repository
96 includes a simple x86_64 raw binary code, and the corresponding
97 [example-x86_64.def](example-x86_64.def) file (look inside for
98 description of available options):
100 python3 ScratchABit.py example-x86_64.def
102 Press F9 to access menus (mouse works too in XTerm-compatible terminals).
103 Press F1 to get help about key bindings (most actions are also accessible
104 via menu). The workflow of ScratchABit is similar to other interactive
105 dissamblers (some previous experience or background reading may be helpful).
110 IDAPython processor plugins can be loaded from anywhere on the Python
111 module path. Alternatively, you can symlink/copy the plugin `.py` file(s)
112 into the [`plugins/cpu/`](plugins/cpu/) subdirectory.
114 After the plugin is made available, create a new definition file based
115 on [`example-x86_64.def`](example-x86_64.def#L4) that sets the plugin module
116 name (without `.py` extenstion) in the `cpu xxx` line.
118 For a very simple example that uses an external plugin, see this
119 [esp8266.def file](https://gist.github.com/projectgus/f898d5798e3e44240796)
120 that works with the xtensa.py plugin from the
121 [ida-xtensa2 repository](https://github.com/pfalcon/ida-xtensa2).
123 TODO/Things to decide
124 ---------------------
126 * ~~Currently uses multiple files for "database", each storing particular
127 type of information. Switch to a single YAML file instead?~~
128 * ~~Add color (low priority, (unbloated!) patches welcome).~~
129 * ~~Few important UI commands to implement yet for comfortable work.~~ (
130 All the most important commands should be there, other functionality is
131 expected to be implemented using plugins).
132 * ~~Offer to save DB on quit if modified.~~
133 * Git integration for DB saving.
134 * ~~Improve robustness (add exception handler at the main loop level, don't
135 abort the application, show to user/log and continue).~~
136 * Try to deal with code flow inconsistencies (e.g. within an instruction -
137 low priority for intended usage) and data access inconsistencies (e.g.
138 accessing individual bytes of previosly detected word - higher priority).
140 * See how to support other types of IDAPython plugins besides just processor
142 * Parse and use debugging information (e.g. DWARF) present in ELF (etc.)
149 > Q: What processors/architectures are supported?
151 A: ScratchABit doesn't support any processor architectures on its own,
152 it is fully retargettable using IDAPython API plugins. Many plugins are
153 available, writing a new plugin is easy. To let users test-drive
154 ScratchABit, a simple x86 processor plugin is included in the
155 distribution, using [Pymsasid](https://github.com/pfalcon/pymsasid3)
156 disassembler under the hood.
158 From version 2.0, [Capstone](http://www.capstone-engine.org/) plugin
159 is also included, allowing access to a number of architectures,
160 including x86, ARM, MIPS, PowerPC, SPARC, etc. (architecture support
161 is enabled gradually based on user testing).
163 You can read about the plugins shipped together with ScratchABit in
164 the [README for `plugins/cpu/` dir](plugins/cpu/).
168 A: ScratchABit is dedicated to static analysis and easy support for
169 new CPU architectures (just code up an new CPU plugin in Python - you
170 can get initial results in few hours). Dynamic analysis wasn't conceived
171 to be a core feature and there're no immediate plans to implement it.
172 Patches are welcome though.
176 A: There is a related project, called
177 [ScratchABlock](https://github.com/pfalcon/ScratchABlock) for deep
178 program analysis, transformation and decompilation. It's expected
179 that as ScratchABlock matures, some of its functionality will be
180 available within ScratchABit (perhaps via plugins).
182 > Q: I'm not on Linux, how can I run ScratchABit?
184 A: Install Linux in an emulator/VM on your system and rejoice.
186 > Q: Mandatory screenshot?
190 ![screenshot](https://raw.githubusercontent.com/pfalcon/ScratchABit/master/docs/scratchabit.png)