| 1 |
Code structure |
| 2 |
-------------- |
| 3 |
|
| 4 |
Capstone source is organized as followings. |
| 5 |
|
| 6 |
. <- core engine + README + COMPILE.TXT etc |
| 7 |
├── arch <- code handling disasm engine for each arch |
| 8 |
│ ├── AArch64 <- ARM64 (aka ARMv8) engine |
| 9 |
│ ├── ARM <- ARM engine |
| 10 |
│ ├── BPF <- Berkeley Packet Filter engine |
| 11 |
│ ├── EVM <- Ethereum engine |
| 12 |
│ ├── M680X <- M680X engine |
| 13 |
│ ├── M68K <- M68K engine |
| 14 |
│ ├── Mips <- Mips engine |
| 15 |
│ ├── MOS65XX <- MOS65XX engine |
| 16 |
│ ├── PowerPC <- PowerPC engine |
| 17 |
│ ├── RISCV <- RISCV engine |
| 18 |
│ ├── SH <- SH engine |
| 19 |
│ ├── Sparc <- Sparc engine |
| 20 |
│ ├── SystemZ <- SystemZ engine |
| 21 |
│ ├── TMS320C64x <- TMS320C64x engine |
| 22 |
│ ├── TriCore <- TriCore engine |
| 23 |
│ └── WASM <- WASM engine |
| 24 |
├── bindings <- all bindings are under this dir |
| 25 |
│ ├── java <- Java bindings + test code |
| 26 |
│ ├── ocaml <- Ocaml bindings + test code |
| 27 |
│ └── python <- Python bindings + test code |
| 28 |
├── contrib <- Code contributed by community to help Capstone integration |
| 29 |
├── cstool <- Cstool |
| 30 |
├── docs <- Documentation |
| 31 |
├── include <- API headers in C language (*.h) |
| 32 |
├── msvc <- Microsoft Visual Studio support (for Windows compile) |
| 33 |
├── packages <- Packages for Linux/OSX/BSD. |
| 34 |
├── windows <- Windows support (for Windows kernel driver compile) |
| 35 |
├── suite <- Development test tools - for Capstone developers only |
| 36 |
├── tests <- Test code (in C language) |
| 37 |
└── xcode <- Xcode support (for MacOSX compile) |
| 38 |
|
| 39 |
|
| 40 |
Follow instructions in COMPILE.TXT for how to compile and run test code. |
| 41 |
|
| 42 |
Note: if you find some strange bugs, it is recommended to firstly clean |
| 43 |
the code and try to recompile/reinstall again. This can be done with: |
| 44 |
|
| 45 |
$ ./make.sh |
| 46 |
$ sudo ./make.sh install |
| 47 |
|
| 48 |
Then test Capstone with cstool, for example: |
| 49 |
|
| 50 |
$ cstool x32 "90 91" |
| 51 |
|
| 52 |
At the same time, for Java/Ocaml/Python bindings, be sure to always use |
| 53 |
the bindings coming with the core to avoid potential incompatibility issue |
| 54 |
with older versions. |
| 55 |
See bindings/<language>/README for detail instructions on how to compile & |
| 56 |
install the bindings. |
| 57 |
|
| 58 |
|
| 59 |
Coding style |
| 60 |
------------ |
| 61 |
- C code follows Linux kernel coding style, using tabs for indentation. |
| 62 |
- Python code uses 4 spaces for indentation. |
| 63 |
|
| 64 |
|
| 65 |
Adding an architecture |
| 66 |
---------------------- |
| 67 |
|
| 68 |
Obviously, you first need to write all the logic and put it in a new directory arch/newarch |
| 69 |
Then, you have to modify other files. |
| 70 |
(You can look for one architecture such as EVM in these files to get what you need to do) |
| 71 |
|
| 72 |
Integrate: |
| 73 |
- cs.c |
| 74 |
- cstool/cstool.c |
| 75 |
- cstool/cstool_newarch.c: print the architecture specific details |
| 76 |
- include/capstone/capstone.h |
| 77 |
- include/capstone/newarch.h: create this file to export all specifics about the new architecture |
| 78 |
|
| 79 |
Compile: |
| 80 |
- CMakeLists.txt |
| 81 |
- Makefile |
| 82 |
- config.mk |
| 83 |
|
| 84 |
Tests: |
| 85 |
- tests/Makefile |
| 86 |
- tests/test_basic.c |
| 87 |
- tests/test_detail.c |
| 88 |
- tests/test_iter.c |
| 89 |
- tests/test_newarch.c |
| 90 |
- suite/fuzz/platform.c: add the architecture and its modes to the list of fuzzed platforms |
| 91 |
- suite/capstone_get_setup.c |
| 92 |
- suite/MC/newarch/mode.mc: samples |
| 93 |
- suite/test_corpus.py: correspondence between architecture and mode as text and architecture number for fuzzing |
| 94 |
|
| 95 |
Bindings: |
| 96 |
- bindings/Makefile |
| 97 |
- bindings/const_generator.py: add the header file and the architecture |
| 98 |
- bindings/python/Makefile |
| 99 |
- bindings/python/capstone/__init__.py |
| 100 |
- bindings/python/capstone/newarch.py: define the python structures |
| 101 |
- bindings/python/capstone/newarch_const.py: generate this file |
| 102 |
- bindings/python/test_newarch.py: create a basic decoding test |
| 103 |
- bindings/python/test_all.py |
| 104 |
|
| 105 |
Docs: |
| 106 |
- README.md |
| 107 |
- HACK.txt |
| 108 |
- CREDITS.txt: add your name |