Nguyen Anh Quynh | 864595c | 2019-02-02 07:39:07 +0800 | [diff] [blame] | 1 | Code structure |
| 2 | -------------- |
Nguyen Anh Quynh | 1ae38db | 2013-11-27 14:33:13 +0800 | [diff] [blame] | 3 | |
Nguyen Anh Quynh | 864595c | 2019-02-02 07:39:07 +0800 | [diff] [blame] | 4 | Capstone source is organized as followings. |
Nguyen Anh Quynh | 7f36d26 | 2013-12-05 10:25:51 +0800 | [diff] [blame] | 5 | |
Nguyen Anh Quynh | 8282dc6 | 2014-01-15 21:20:47 +0800 | [diff] [blame] | 6 | . <- core engine + README + COMPILE.TXT etc |
Nguyen Anh Quynh | bdbde1f | 2013-11-27 17:00:06 +0800 | [diff] [blame] | 7 | ├── arch <- code handling disasm engine for each arch |
Nguyen Anh Quynh | 7f36d26 | 2013-12-05 10:25:51 +0800 | [diff] [blame] | 8 | │ ├── AArch64 <- ARM64 (aka ARMv8) engine |
| 9 | │ ├── ARM <- ARM engine |
Nguyen Anh Quynh | 7732f3a | 2018-12-12 16:30:45 +0700 | [diff] [blame] | 10 | │ ├── EVM <- Ethereum engine |
Wolfgang Schwotzer | 22b4d0e | 2017-10-21 15:44:36 +0200 | [diff] [blame] | 11 | │ ├── M680X <- M680X engine |
Nguyen Anh Quynh | 74a114e | 2015-10-05 16:14:19 +0800 | [diff] [blame] | 12 | │ ├── M68K <- M68K engine |
Nguyen Anh Quynh | 7f36d26 | 2013-12-05 10:25:51 +0800 | [diff] [blame] | 13 | │ ├── Mips <- Mips engine |
Sebastian Macke | 7436f54 | 2018-12-04 19:09:38 +0100 | [diff] [blame] | 14 | │ ├── MOS65XX <- MOS65XX engine |
Nguyen Anh Quynh | ab26cd9 | 2014-01-07 11:46:21 +0800 | [diff] [blame] | 15 | │ ├── PowerPC <- PowerPC engine |
Nguyen Anh Quynh | 636f506 | 2014-03-23 22:24:28 +0800 | [diff] [blame] | 16 | │ ├── Sparc <- Sparc engine |
| 17 | │ ├── SystemZ <- SystemZ engine |
Nguyen Anh Quynh | 921dbb2 | 2018-12-16 21:53:56 +0800 | [diff] [blame] | 18 | │ ├── TMS320C64x <- TMS320C64x engine |
Nguyen Anh Quynh | c80d840 | 2014-05-26 23:02:48 +0800 | [diff] [blame] | 19 | │ ├── X86 <- X86 engine |
| 20 | │ └── XCore <- XCore engine |
Nguyen Anh Quynh | 18ebd80 | 2013-11-27 21:29:12 +0800 | [diff] [blame] | 21 | ├── bindings <- all bindings are under this dir |
Nguyen Anh Quynh | bdbde1f | 2013-11-27 17:00:06 +0800 | [diff] [blame] | 22 | │ ├── java <- Java bindings + test code |
| 23 | │ ├── ocaml <- Ocaml bindings + test code |
pancake | 5ea5037 | 2014-11-01 22:14:13 +0100 | [diff] [blame] | 24 | │ └── python <- Python bindings + test code |
Nguyen Anh Quynh | ea980bd | 2014-11-02 00:34:14 +0800 | [diff] [blame] | 25 | ├── contrib <- Code contributed by community to help Capstone integration |
Nguyen Anh Quynh | fcd1b44 | 2016-10-11 00:20:58 +0800 | [diff] [blame] | 26 | ├── cstool <- Cstool |
Nguyen Anh Quynh | ea980bd | 2014-11-02 00:34:14 +0800 | [diff] [blame] | 27 | ├── docs <- Documentation |
Nguyen Anh Quynh | 7f36d26 | 2013-12-05 10:25:51 +0800 | [diff] [blame] | 28 | ├── include <- API headers in C language (*.h) |
Nguyen Anh Quynh | ea980bd | 2014-11-02 00:34:14 +0800 | [diff] [blame] | 29 | ├── msvc <- Microsoft Visual Studio support (for Windows compile) |
| 30 | ├── packages <- Packages for Linux/OSX/BSD. |
tandasat | 45e5eab | 2016-05-11 21:48:32 -0700 | [diff] [blame] | 31 | ├── windows <- Windows support (for Windows kernel driver compile) |
Nguyen Anh Quynh | 6adc5c1 | 2014-01-07 11:34:05 +0800 | [diff] [blame] | 32 | ├── suite <- Development test tools - for Capstone developers only |
Nguyen Anh Quynh | 7f36d26 | 2013-12-05 10:25:51 +0800 | [diff] [blame] | 33 | ├── tests <- Test code (in C language) |
pancake | 5ea5037 | 2014-11-01 22:14:13 +0100 | [diff] [blame] | 34 | └── xcode <- Xcode support (for MacOSX compile) |
Nguyen Anh Quynh | 1ae38db | 2013-11-27 14:33:13 +0800 | [diff] [blame] | 35 | |
| 36 | |
Nguyen Anh Quynh | ea980bd | 2014-11-02 00:34:14 +0800 | [diff] [blame] | 37 | Follow instructions in COMPILE.TXT for how to compile and run test code. |
Nguyen Anh Quynh | 18ebd80 | 2013-11-27 21:29:12 +0800 | [diff] [blame] | 38 | |
Nguyen Anh Quynh | 7f36d26 | 2013-12-05 10:25:51 +0800 | [diff] [blame] | 39 | Note: if you find some strange bugs, it is recommended to firstly clean |
| 40 | the code and try to recompile/reinstall again. This can be done with: |
Nguyen Anh Quynh | 1ae38db | 2013-11-27 14:33:13 +0800 | [diff] [blame] | 41 | |
Nguyen Anh Quynh | 06aef6b | 2014-05-07 16:00:33 +0800 | [diff] [blame] | 42 | $ ./make.sh |
| 43 | $ sudo ./make.sh install |
Nguyen Anh Quynh | 1ae38db | 2013-11-27 14:33:13 +0800 | [diff] [blame] | 44 | |
Nguyen Anh Quynh | fcd1b44 | 2016-10-11 00:20:58 +0800 | [diff] [blame] | 45 | Then test Capstone with cstool, for example: |
| 46 | |
| 47 | $ cstool x32 "90 91" |
| 48 | |
Nguyen Anh Quynh | ea980bd | 2014-11-02 00:34:14 +0800 | [diff] [blame] | 49 | At the same time, for Java/Ocaml/Python bindings, be sure to always use |
Satoshi Tanda | 565b6c3 | 2016-09-27 07:39:51 -0700 | [diff] [blame] | 50 | the bindings coming with the core to avoid potential incompatibility issue |
Nguyen Anh Quynh | ea980bd | 2014-11-02 00:34:14 +0800 | [diff] [blame] | 51 | with older versions. |
| 52 | See bindings/<language>/README for detail instructions on how to compile & |
| 53 | install the bindings. |
Catena cyber | 4baab44 | 2019-01-30 13:33:35 +0100 | [diff] [blame] | 54 | |
| 55 | |
Nguyen Anh Quynh | 864595c | 2019-02-02 07:39:07 +0800 | [diff] [blame] | 56 | Coding style |
| 57 | ------------ |
| 58 | - C code follows Linux kernel coding style, using tabs for indentation. |
| 59 | - Python code uses 4 spaces for indentation. |
| 60 | |
| 61 | |
| 62 | Adding an architecture |
| 63 | ---------------------- |
Catena cyber | 4baab44 | 2019-01-30 13:33:35 +0100 | [diff] [blame] | 64 | |
| 65 | Obviously, you first need to write all the logic and put it in a new directory arch/newarch |
| 66 | Then, 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 Quynh | 864595c | 2019-02-02 07:39:07 +0800 | [diff] [blame] | 69 | Integrate: |
Catena cyber | 4baab44 | 2019-01-30 13:33:35 +0100 | [diff] [blame] | 70 | - cs.c |
| 71 | - cstool/cstool.c |
Nguyen Anh Quynh | 864595c | 2019-02-02 07:39:07 +0800 | [diff] [blame] | 72 | - cstool/cstool_newarch.c: print the architecture specific details |
Catena cyber | 4baab44 | 2019-01-30 13:33:35 +0100 | [diff] [blame] | 73 | - include/capstone/capstone.h |
Nguyen Anh Quynh | 864595c | 2019-02-02 07:39:07 +0800 | [diff] [blame] | 74 | - include/capstone/newarch.h: create this file to export all specifics about the new architecture |
Catena cyber | 4baab44 | 2019-01-30 13:33:35 +0100 | [diff] [blame] | 75 | |
Nguyen Anh Quynh | 864595c | 2019-02-02 07:39:07 +0800 | [diff] [blame] | 76 | Compile: |
Catena cyber | 4baab44 | 2019-01-30 13:33:35 +0100 | [diff] [blame] | 77 | - CMakeLists.txt |
| 78 | - Makefile |
| 79 | - config.mk |
| 80 | |
Nguyen Anh Quynh | 864595c | 2019-02-02 07:39:07 +0800 | [diff] [blame] | 81 | Tests: |
Catena cyber | 4baab44 | 2019-01-30 13:33:35 +0100 | [diff] [blame] | 82 | - tests/Makefile |
| 83 | - tests/test_basic.c |
| 84 | - tests/test_detail.c |
| 85 | - tests/test_iter.c |
| 86 | - tests/test_newarch.c |
Nguyen Anh Quynh | 864595c | 2019-02-02 07:39:07 +0800 | [diff] [blame] | 87 | - suite/fuzz/fuzz_disasm.c: add the architecture and its modes to the list of fuzzed platforms |
Catena cyber | 4baab44 | 2019-01-30 13:33:35 +0100 | [diff] [blame] | 88 | |
Nguyen Anh Quynh | 864595c | 2019-02-02 07:39:07 +0800 | [diff] [blame] | 89 | Bindings: |
Catena cyber | 4baab44 | 2019-01-30 13:33:35 +0100 | [diff] [blame] | 90 | - bindings/Makefile |
Nguyen Anh Quynh | 864595c | 2019-02-02 07:39:07 +0800 | [diff] [blame] | 91 | - bindings/const_generator.py: add the header file and the architecture |
Catena cyber | 4baab44 | 2019-01-30 13:33:35 +0100 | [diff] [blame] | 92 | - bindings/python/Makefile |
| 93 | - bindings/python/capstone/__init__.py |
Nguyen Anh Quynh | 864595c | 2019-02-02 07:39:07 +0800 | [diff] [blame] | 94 | - 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 cyber | 4baab44 | 2019-01-30 13:33:35 +0100 | [diff] [blame] | 97 | - bindings/python/test_all.py |
| 98 | |
Nguyen Anh Quynh | 864595c | 2019-02-02 07:39:07 +0800 | [diff] [blame] | 99 | Docs: |
Catena cyber | 4baab44 | 2019-01-30 13:33:35 +0100 | [diff] [blame] | 100 | - README.md |
| 101 | - HACK.txt |
Nguyen Anh Quynh | 864595c | 2019-02-02 07:39:07 +0800 | [diff] [blame] | 102 | - CREDITS.txt: add your name |