blob: a928621bd65e691a8a74d129f8e9439b9cc72b6b [file] [log] [blame]
Nguyen Anh Quynh864595c2019-02-02 07:39:07 +08001Code structure
2--------------
Nguyen Anh Quynh1ae38db2013-11-27 14:33:13 +08003
Nguyen Anh Quynh864595c2019-02-02 07:39:07 +08004Capstone source is organized as followings.
Nguyen Anh Quynh7f36d262013-12-05 10:25:51 +08005
Nguyen Anh Quynh8282dc62014-01-15 21:20:47 +08006. <- core engine + README + COMPILE.TXT etc
Nguyen Anh Quynhbdbde1f2013-11-27 17:00:06 +08007├── arch <- code handling disasm engine for each arch
Nguyen Anh Quynh7f36d262013-12-05 10:25:51 +08008│   ├── AArch64 <- ARM64 (aka ARMv8) engine
9│   ├── ARM <- ARM engine
Nguyen Anh Quynh7732f3a2018-12-12 16:30:45 +070010│   ├── EVM <- Ethereum engine
Wolfgang Schwotzer22b4d0e2017-10-21 15:44:36 +020011│   ├── M680X <- M680X engine
Nguyen Anh Quynh74a114e2015-10-05 16:14:19 +080012│   ├── M68K <- M68K engine
Nguyen Anh Quynh7f36d262013-12-05 10:25:51 +080013│   ├── Mips <- Mips engine
Sebastian Macke7436f542018-12-04 19:09:38 +010014│   ├── MOS65XX <- MOS65XX engine
Nguyen Anh Quynhab26cd92014-01-07 11:46:21 +080015│   ├── PowerPC <- PowerPC engine
Nguyen Anh Quynh636f5062014-03-23 22:24:28 +080016│   ├── Sparc <- Sparc engine
17│   ├── SystemZ <- SystemZ engine
Nguyen Anh Quynh921dbb22018-12-16 21:53:56 +080018│   ├── TMS320C64x <- TMS320C64x engine
Nguyen Anh Quynhc80d8402014-05-26 23:02:48 +080019│   ├── X86 <- X86 engine
20│   └── XCore <- XCore engine
Nguyen Anh Quynh18ebd802013-11-27 21:29:12 +080021├── bindings <- all bindings are under this dir
Nguyen Anh Quynhbdbde1f2013-11-27 17:00:06 +080022│   ├── java <- Java bindings + test code
23│   ├── ocaml <- Ocaml bindings + test code
pancake5ea50372014-11-01 22:14:13 +010024│   └── python <- Python bindings + test code
Nguyen Anh Quynhea980bd2014-11-02 00:34:14 +080025├── contrib <- Code contributed by community to help Capstone integration
Nguyen Anh Quynhfcd1b442016-10-11 00:20:58 +080026├── cstool <- Cstool
Nguyen Anh Quynhea980bd2014-11-02 00:34:14 +080027├── docs <- Documentation
Nguyen Anh Quynh7f36d262013-12-05 10:25:51 +080028├── include <- API headers in C language (*.h)
Nguyen Anh Quynhea980bd2014-11-02 00:34:14 +080029├── msvc <- Microsoft Visual Studio support (for Windows compile)
30├── packages <- Packages for Linux/OSX/BSD.
tandasat45e5eab2016-05-11 21:48:32 -070031├── windows <- Windows support (for Windows kernel driver compile)
Nguyen Anh Quynh6adc5c12014-01-07 11:34:05 +080032├── suite <- Development test tools - for Capstone developers only
Nguyen Anh Quynh7f36d262013-12-05 10:25:51 +080033├── tests <- Test code (in C language)
pancake5ea50372014-11-01 22:14:13 +010034└── xcode <- Xcode support (for MacOSX compile)
Nguyen Anh Quynh1ae38db2013-11-27 14:33:13 +080035
36
Nguyen Anh Quynhea980bd2014-11-02 00:34:14 +080037Follow instructions in COMPILE.TXT for how to compile and run test code.
Nguyen Anh Quynh18ebd802013-11-27 21:29:12 +080038
Nguyen Anh Quynh7f36d262013-12-05 10:25:51 +080039Note: if you find some strange bugs, it is recommended to firstly clean
40the code and try to recompile/reinstall again. This can be done with:
Nguyen Anh Quynh1ae38db2013-11-27 14:33:13 +080041
Nguyen Anh Quynh06aef6b2014-05-07 16:00:33 +080042 $ ./make.sh
43 $ sudo ./make.sh install
Nguyen Anh Quynh1ae38db2013-11-27 14:33:13 +080044
Nguyen Anh Quynhfcd1b442016-10-11 00:20:58 +080045Then test Capstone with cstool, for example:
46
47 $ cstool x32 "90 91"
48
Nguyen Anh Quynhea980bd2014-11-02 00:34:14 +080049At the same time, for Java/Ocaml/Python bindings, be sure to always use
Satoshi Tanda565b6c32016-09-27 07:39:51 -070050the bindings coming with the core to avoid potential incompatibility issue
Nguyen Anh Quynhea980bd2014-11-02 00:34:14 +080051with older versions.
52See bindings/<language>/README for detail instructions on how to compile &
53install the bindings.
Catena cyber4baab442019-01-30 13:33:35 +010054
55
Nguyen Anh Quynh864595c2019-02-02 07:39:07 +080056Coding style
57------------
58- C code follows Linux kernel coding style, using tabs for indentation.
59- Python code uses 4 spaces for indentation.
60
61
62Adding an architecture
63----------------------
Catena cyber4baab442019-01-30 13:33:35 +010064
65Obviously, you first need to write all the logic and put it in a new directory arch/newarch
66Then, you have to modify other files.
67(You can look for one architecture such as EVM in these files to get what you need to do)
68
Nguyen Anh Quynh864595c2019-02-02 07:39:07 +080069Integrate:
Catena cyber4baab442019-01-30 13:33:35 +010070- cs.c
71- cstool/cstool.c
Nguyen Anh Quynh864595c2019-02-02 07:39:07 +080072- cstool/cstool_newarch.c: print the architecture specific details
Catena cyber4baab442019-01-30 13:33:35 +010073- include/capstone/capstone.h
Nguyen Anh Quynh864595c2019-02-02 07:39:07 +080074- include/capstone/newarch.h: create this file to export all specifics about the new architecture
Catena cyber4baab442019-01-30 13:33:35 +010075
Nguyen Anh Quynh864595c2019-02-02 07:39:07 +080076Compile:
Catena cyber4baab442019-01-30 13:33:35 +010077- CMakeLists.txt
78- Makefile
79- config.mk
80
Nguyen Anh Quynh864595c2019-02-02 07:39:07 +080081Tests:
Catena cyber4baab442019-01-30 13:33:35 +010082- tests/Makefile
83- tests/test_basic.c
84- tests/test_detail.c
85- tests/test_iter.c
86- tests/test_newarch.c
Nguyen Anh Quynh864595c2019-02-02 07:39:07 +080087- suite/fuzz/fuzz_disasm.c: add the architecture and its modes to the list of fuzzed platforms
Catena cyber4baab442019-01-30 13:33:35 +010088
Nguyen Anh Quynh864595c2019-02-02 07:39:07 +080089Bindings:
Catena cyber4baab442019-01-30 13:33:35 +010090- bindings/Makefile
Nguyen Anh Quynh864595c2019-02-02 07:39:07 +080091- bindings/const_generator.py: add the header file and the architecture
Catena cyber4baab442019-01-30 13:33:35 +010092- bindings/python/Makefile
93- bindings/python/capstone/__init__.py
Nguyen Anh Quynh864595c2019-02-02 07:39:07 +080094- bindings/python/capstone/newarch.py: define the python structures
95- bindings/python/capstone/newarch_const.py: generate this file
96- bindings/python/test_newarch.py: create a basic decoding test
Catena cyber4baab442019-01-30 13:33:35 +010097- bindings/python/test_all.py
98
Nguyen Anh Quynh864595c2019-02-02 07:39:07 +080099Docs:
Catena cyber4baab442019-01-30 13:33:35 +0100100- README.md
101- HACK.txt
Nguyen Anh Quynh864595c2019-02-02 07:39:07 +0800102- CREDITS.txt: add your name