Nguyen Anh Quynh | 61882e5 | 2014-05-18 00:39:49 +0800 | [diff] [blame] | 1 | This documentation explains how to compile, install & run Capstone on MacOSX, |
| 2 | Linux, *BSD & Solaris. We also show steps to cross-compile for Microsoft Windows. |
| 3 | |
| 4 | To natively compile for Windows using Microsoft Visual Studio, see COMPILE_MSVC.TXT. |
| 5 | |
Nguyen Anh Quynh | f1c3acb | 2014-05-28 22:39:23 +0800 | [diff] [blame] | 6 | To compile using CMake, see COMPILE_CMAKE.TXT. |
| 7 | |
Nguyen Anh Quynh | cc35100 | 2014-10-06 22:19:10 +0800 | [diff] [blame] | 8 | To compile using XCode on MacOSX, see xcode/README.md. |
| 9 | |
Koutheir Attouchi | 08d419e | 2016-04-12 09:26:47 +0200 | [diff] [blame] | 10 | To compile for Windows CE (a.k.a, Windows Embedded Compact), see windowsce/COMPILE.md. |
| 11 | |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 12 | *-*-*-*-*-* |
| 13 | |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 14 | Capstone requires no prerequisite packages, so it is easy to compile & install. |
| 15 | |
| 16 | |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 17 | |
Nguyen Anh Quynh | a6a1153 | 2013-12-24 17:03:45 +0800 | [diff] [blame] | 18 | (0) Tailor Capstone to your need. |
| 19 | |
Nguyen Anh Quynh | ed1246d | 2018-03-31 17:29:22 +0800 | [diff] [blame] | 20 | Out of 12 archtitectures supported by Capstone (Arm, Arm64, M68K, Mips, PPC, |
| 21 | Sparc, SystemZ, XCore, X86, M680X, TMS320C64x & EVM), if you just need several |
| 22 | selected archs, choose the ones you want to compile in by editing "config.mk" |
| 23 | before going to next steps. |
Nguyen Anh Quynh | a6a1153 | 2013-12-24 17:03:45 +0800 | [diff] [blame] | 24 | |
Nguyen Anh Quynh | ed1246d | 2018-03-31 17:29:22 +0800 | [diff] [blame] | 25 | By default, all 12 architectures are compiled. |
Nguyen Anh Quynh | a6a1153 | 2013-12-24 17:03:45 +0800 | [diff] [blame] | 26 | |
Nguyen Anh Quynh | 18759b3 | 2014-04-29 14:00:16 +0800 | [diff] [blame] | 27 | The other way of customize Capstone without having to edit config.mk is to |
| 28 | pass the desired options on the commandline to ./make.sh. Currently, |
baguette | 86e8450 | 2014-08-17 20:59:05 +0200 | [diff] [blame] | 29 | Capstone supports 5 options, as followings. |
Nguyen Anh Quynh | 18759b3 | 2014-04-29 14:00:16 +0800 | [diff] [blame] | 30 | |
| 31 | - CAPSTONE_ARCHS: specify list of architectures to compiled in. |
Nguyen Anh Quynh | e31327d | 2014-04-29 14:25:15 +0800 | [diff] [blame] | 32 | - CAPSTONE_USE_SYS_DYN_MEM: change this if you have your own dynamic memory management. |
Nguyen Anh Quynh | 18759b3 | 2014-04-29 14:00:16 +0800 | [diff] [blame] | 33 | - CAPSTONE_DIET: use this to make the output binaries more compact. |
| 34 | - CAPSTONE_X86_REDUCE: another option to make X86 binary smaller. |
Nguyen Anh Quynh | 6638294 | 2014-08-20 14:02:14 +0800 | [diff] [blame] | 35 | - CAPSTONE_X86_ATT_DISABLE: disables AT&T syntax on x86. |
Nguyen Anh Quynh | f85f981 | 2014-11-13 14:58:45 +0800 | [diff] [blame] | 36 | - CAPSTONE_STATIC: build static library. |
| 37 | - CAPSTONE_SHARED: build dynamic (shared) library. |
Nguyen Anh Quynh | 18759b3 | 2014-04-29 14:00:16 +0800 | [diff] [blame] | 38 | |
Nguyen Anh Quynh | f85f981 | 2014-11-13 14:58:45 +0800 | [diff] [blame] | 39 | By default, Capstone uses system dynamic memory management, both DIET and X86_REDUCE |
| 40 | modes are disable, and builds all the static & shared libraries. |
Nguyen Anh Quynh | 01f4839 | 2014-05-15 11:06:43 +0800 | [diff] [blame] | 41 | |
Nguyen Anh Quynh | f85f981 | 2014-11-13 14:58:45 +0800 | [diff] [blame] | 42 | To avoid editing config.mk for these customization, we can pass their values to |
Nguyen Anh Quynh | 18759b3 | 2014-04-29 14:00:16 +0800 | [diff] [blame] | 43 | make.sh, as followings. |
| 44 | |
Nguyen Anh Quynh | e31327d | 2014-04-29 14:25:15 +0800 | [diff] [blame] | 45 | $ CAPSTONE_ARCHS="arm aarch64 x86" CAPSTONE_USE_SYS_DYN_MEM=no CAPSTONE_DIET=yes CAPSTONE_X86_REDUCE=yes ./make.sh |
Nguyen Anh Quynh | 18759b3 | 2014-04-29 14:00:16 +0800 | [diff] [blame] | 46 | |
| 47 | NOTE: on commandline, put these values in front of ./make.sh, not after it. |
| 48 | |
Nguyen Anh Quynh | 18759b3 | 2014-04-29 14:00:16 +0800 | [diff] [blame] | 49 | For each option, refer to docs/README for more details. |
Nguyen Anh Quynh | a6a1153 | 2013-12-24 17:03:45 +0800 | [diff] [blame] | 50 | |
| 51 | |
Nguyen Anh Quynh | f08ed97 | 2014-04-07 22:13:56 +0800 | [diff] [blame] | 52 | |
Nguyen Anh Quynh | a6a1153 | 2013-12-24 17:03:45 +0800 | [diff] [blame] | 53 | (1) Compile from source |
| 54 | |
Nguyen Anh Quynh | dba00f8 | 2014-01-17 14:20:54 +0800 | [diff] [blame] | 55 | On *nix (such as MacOSX, Linux, *BSD, Solaris): |
Nguyen Anh Quynh | a6a1153 | 2013-12-24 17:03:45 +0800 | [diff] [blame] | 56 | |
Nguyen Anh Quynh | fe5e7f3 | 2014-01-17 14:56:03 +0800 | [diff] [blame] | 57 | - To compile for current platform, run: |
Nguyen Anh Quynh | a6a1153 | 2013-12-24 17:03:45 +0800 | [diff] [blame] | 58 | |
Nguyen Anh Quynh | dba00f8 | 2014-01-17 14:20:54 +0800 | [diff] [blame] | 59 | $ ./make.sh |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 60 | |
Nguyen Anh Quynh | de6dd29 | 2014-04-14 14:40:25 +0800 | [diff] [blame] | 61 | - On 64-bit OS, run the command below to cross-compile Capstone for 32-bit binary: |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 62 | |
Nguyen Anh Quynh | de6dd29 | 2014-04-14 14:40:25 +0800 | [diff] [blame] | 63 | $ ./make.sh nix32 |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 64 | |
| 65 | |
| 66 | |
Nguyen Anh Quynh | a6a1153 | 2013-12-24 17:03:45 +0800 | [diff] [blame] | 67 | (2) Install Capstone on *nix |
| 68 | |
| 69 | To install Capstone, run: |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 70 | |
Nguyen Anh Quynh | dba00f8 | 2014-01-17 14:20:54 +0800 | [diff] [blame] | 71 | $ sudo ./make.sh install |
Nguyen Anh Quynh | de6dd29 | 2014-04-14 14:40:25 +0800 | [diff] [blame] | 72 | |
Nguyen Anh Quynh | dba00f8 | 2014-01-17 14:20:54 +0800 | [diff] [blame] | 73 | For FreeBSD/OpenBSD, where sudo is unavailable, run: |
Nguyen Anh Quynh | f74bebf | 2013-12-09 13:53:11 +0800 | [diff] [blame] | 74 | |
Nguyen Anh Quynh | de6dd29 | 2014-04-14 14:40:25 +0800 | [diff] [blame] | 75 | $ su; ./make.sh install |
Nguyen Anh Quynh | f74bebf | 2013-12-09 13:53:11 +0800 | [diff] [blame] | 76 | |
Nguyen Anh Quynh | a6a1153 | 2013-12-24 17:03:45 +0800 | [diff] [blame] | 77 | Users are then required to enter root password to copy Capstone into machine |
| 78 | system directories. |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 79 | |
Nguyen Anh Quynh | 9919e3b | 2014-01-22 10:17:17 +0800 | [diff] [blame] | 80 | Afterwards, run ./tests/test* to see the tests disassembling sample code. |
Nguyen Anh Quynh | dba00f8 | 2014-01-17 14:20:54 +0800 | [diff] [blame] | 81 | |
| 82 | |
Nguyen Anh Quynh | fe5e7f3 | 2014-01-17 14:56:03 +0800 | [diff] [blame] | 83 | NOTE: The core framework installed by "./make.sh install" consist of |
| 84 | following files: |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 85 | |
Patroklos Argyroudis | a6503fe | 2013-11-27 14:25:34 +0200 | [diff] [blame] | 86 | /usr/include/capstone/capstone.h |
| 87 | /usr/include/capstone/x86.h |
| 88 | /usr/include/capstone/arm.h |
| 89 | /usr/include/capstone/arm64.h |
Nguyen Anh Quynh | ed1246d | 2018-03-31 17:29:22 +0800 | [diff] [blame] | 90 | /usr/include/capstone/evm.h |
Nguyen Anh Quynh | 74a114e | 2015-10-05 16:14:19 +0800 | [diff] [blame] | 91 | /usr/include/capstone/m68k.h |
Nguyen Anh Quynh | ed1246d | 2018-03-31 17:29:22 +0800 | [diff] [blame] | 92 | /usr/include/capstone/m680x.h |
Patroklos Argyroudis | a6503fe | 2013-11-27 14:25:34 +0200 | [diff] [blame] | 93 | /usr/include/capstone/mips.h |
Nguyen Anh Quynh | dba00f8 | 2014-01-17 14:20:54 +0800 | [diff] [blame] | 94 | /usr/include/capstone/ppc.h |
Nguyen Anh Quynh | 05e2713 | 2014-03-10 11:58:57 +0800 | [diff] [blame] | 95 | /usr/include/capstone/sparc.h |
Nguyen Anh Quynh | 48a14ca | 2014-03-23 08:35:45 +0800 | [diff] [blame] | 96 | /usr/include/capstone/systemz.h |
Nguyen Anh Quynh | ed1246d | 2018-03-31 17:29:22 +0800 | [diff] [blame] | 97 | /usr/include/capstone/tms320c64x.h |
Nguyen Anh Quynh | 4bd4a2f | 2015-02-11 10:30:03 +0800 | [diff] [blame] | 98 | /usr/include/capstone/xcore.h |
| 99 | /usr/include/capstone/platform.h |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 100 | /usr/lib/libcapstone.so (for Linux/*nix), or /usr/lib/libcapstone.dylib (OSX) |
Nguyen Anh Quynh | 0427122 | 2013-12-09 11:12:47 +0800 | [diff] [blame] | 101 | /usr/lib/libcapstone.a |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 102 | |
| 103 | |
| 104 | |
Nguyen Anh Quynh | f08ed97 | 2014-04-07 22:13:56 +0800 | [diff] [blame] | 105 | (3) Cross-compile for Windows from *nix |
Nguyen Anh Quynh | a6a1153 | 2013-12-24 17:03:45 +0800 | [diff] [blame] | 106 | |
| 107 | To cross-compile for Windows, Linux & gcc-mingw-w64-i686 (and also gcc-mingw-w64-x86-64 |
| 108 | for 64-bit binaries) are required. |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 109 | |
Nguyen Anh Quynh | fe5e7f3 | 2014-01-17 14:56:03 +0800 | [diff] [blame] | 110 | - To cross-compile Windows 32-bit binary, simply run: |
Nguyen Anh Quynh | de6dd29 | 2014-04-14 14:40:25 +0800 | [diff] [blame] | 111 | |
Nguyen Anh Quynh | dba00f8 | 2014-01-17 14:20:54 +0800 | [diff] [blame] | 112 | $ ./make.sh cross-win32 |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 113 | |
Nguyen Anh Quynh | fe5e7f3 | 2014-01-17 14:56:03 +0800 | [diff] [blame] | 114 | - To cross-compile Windows 64-bit binary, run: |
Nguyen Anh Quynh | de6dd29 | 2014-04-14 14:40:25 +0800 | [diff] [blame] | 115 | |
Nguyen Anh Quynh | dba00f8 | 2014-01-17 14:20:54 +0800 | [diff] [blame] | 116 | $ ./make.sh cross-win64 |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 117 | |
Nguyen Anh Quynh | 9919e3b | 2014-01-22 10:17:17 +0800 | [diff] [blame] | 118 | Resulted files libcapstone.dll, libcapstone.dll.a & tests/test*.exe can then |
| 119 | be used on Windows machine. |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 120 | |
| 121 | |
| 122 | |
Nguyen Anh Quynh | f08ed97 | 2014-04-07 22:13:56 +0800 | [diff] [blame] | 123 | (4) Cross-compile for iOS from Mac OSX. |
Nguyen Anh Quynh | 2eecc6c | 2014-04-01 10:22:54 +0800 | [diff] [blame] | 124 | |
| 125 | To cross-compile for iOS (iPhone/iPad/iPod), Mac OSX with XCode installed is required. |
| 126 | |
| 127 | - To cross-compile for ArmV7 (iPod 4, iPad 1/2/3, iPhone4, iPhone4S), run: |
| 128 | $ ./make.sh ios_armv7 |
| 129 | |
| 130 | - To cross-compile for ArmV7s (iPad 4, iPhone 5C, iPad mini), run: |
| 131 | $ ./make.sh ios_armv7s |
| 132 | |
| 133 | - To cross-compile for Arm64 (iPhone 5S, iPad mini Retina, iPad Air), run: |
| 134 | $ ./make.sh ios_arm64 |
| 135 | |
| 136 | - To cross-compile for all iDevices (armv7 + armv7s + arm64), run: |
| 137 | $ ./make.sh ios |
| 138 | |
| 139 | Resulted files libcapstone.dylib, libcapstone.a & tests/test* can then |
| 140 | be used on iOS devices. |
| 141 | |
| 142 | |
| 143 | |
Nguyen Anh Quynh | f08ed97 | 2014-04-07 22:13:56 +0800 | [diff] [blame] | 144 | (5) Cross-compile for Android |
| 145 | |
| 146 | To cross-compile for Android (smartphone/tablet), Android NDK is required. |
Nguyen Anh Quynh | a5540d8 | 2015-06-22 15:52:45 +0800 | [diff] [blame] | 147 | NOTE: Only ARM and ARM64 are currently supported. |
Nguyen Anh Quynh | f08ed97 | 2014-04-07 22:13:56 +0800 | [diff] [blame] | 148 | |
Nguyen Anh Quynh | a5540d8 | 2015-06-22 15:52:45 +0800 | [diff] [blame] | 149 | $ NDK=/android/android-ndk-r10e ./make.sh cross-android arm |
| 150 | or |
| 151 | $ NDK=/android/android-ndk-r10e ./make.sh cross-android arm64 |
Nguyen Anh Quynh | f08ed97 | 2014-04-07 22:13:56 +0800 | [diff] [blame] | 152 | |
| 153 | Resulted files libcapstone.so, libcapstone.a & tests/test* can then |
| 154 | be used on Android devices. |
| 155 | |
| 156 | |
| 157 | |
| 158 | (6) Compile on Windows with Cygwin |
Nguyen Anh Quynh | a6a1153 | 2013-12-24 17:03:45 +0800 | [diff] [blame] | 159 | |
| 160 | To compile under Cygwin gcc-mingw-w64-i686 or x86_64-w64-mingw32 run: |
Daniel Godas-Lopez | cf05e11 | 2013-11-28 18:23:39 +0000 | [diff] [blame] | 161 | |
Nguyen Anh Quynh | de6dd29 | 2014-04-14 14:40:25 +0800 | [diff] [blame] | 162 | - To compile Windows 32-bit binary under Cygwin, run: |
| 163 | |
Nguyen Anh Quynh | dba00f8 | 2014-01-17 14:20:54 +0800 | [diff] [blame] | 164 | $ ./make.sh cygwin-mingw32 |
Daniel Godas-Lopez | cf05e11 | 2013-11-28 18:23:39 +0000 | [diff] [blame] | 165 | |
Nguyen Anh Quynh | de6dd29 | 2014-04-14 14:40:25 +0800 | [diff] [blame] | 166 | - To compile Windows 64-bit binary under Cygwin, run: |
| 167 | |
Nguyen Anh Quynh | dba00f8 | 2014-01-17 14:20:54 +0800 | [diff] [blame] | 168 | $ ./make.sh cygwin-mingw64 |
Daniel Godas-Lopez | cf05e11 | 2013-11-28 18:23:39 +0000 | [diff] [blame] | 169 | |
Nguyen Anh Quynh | 9919e3b | 2014-01-22 10:17:17 +0800 | [diff] [blame] | 170 | Resulted files libcapstone.dll, libcapstone.dll.a & tests/test*.exe can then |
| 171 | be used on Windows machine. |
Daniel Godas-Lopez | cf05e11 | 2013-11-28 18:23:39 +0000 | [diff] [blame] | 172 | |
Nguyen Anh Quynh | fe5e7f3 | 2014-01-17 14:56:03 +0800 | [diff] [blame] | 173 | |
Nguyen Anh Quynh | f08ed97 | 2014-04-07 22:13:56 +0800 | [diff] [blame] | 174 | |
| 175 | (7) By default, "cc" (default C compiler on the system) is used as compiler. |
Nguyen Anh Quynh | a6a1153 | 2013-12-24 17:03:45 +0800 | [diff] [blame] | 176 | |
Nguyen Anh Quynh | de6dd29 | 2014-04-14 14:40:25 +0800 | [diff] [blame] | 177 | - To use "clang" compiler instead, run the command below: |
Nguyen Anh Quynh | a6a1153 | 2013-12-24 17:03:45 +0800 | [diff] [blame] | 178 | |
Nguyen Anh Quynh | dba00f8 | 2014-01-17 14:20:54 +0800 | [diff] [blame] | 179 | $ ./make.sh clang |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 180 | |
Nguyen Anh Quynh | fe5e7f3 | 2014-01-17 14:56:03 +0800 | [diff] [blame] | 181 | - To use "gcc" compiler instead, run: |
Oliver Pinter | 6e2c075 | 2014-01-16 12:16:21 +0100 | [diff] [blame] | 182 | |
Nguyen Anh Quynh | dba00f8 | 2014-01-17 14:20:54 +0800 | [diff] [blame] | 183 | $ ./make.sh gcc |
Oliver Pinter | 6e2c075 | 2014-01-16 12:16:21 +0100 | [diff] [blame] | 184 | |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 185 | |
| 186 | |
Nguyen Anh Quynh | de6dd29 | 2014-04-14 14:40:25 +0800 | [diff] [blame] | 187 | (8) To uninstall Capstone, run the command below: |
Nguyen Anh Quynh | 919875b | 2014-04-14 14:00:12 +0800 | [diff] [blame] | 188 | |
| 189 | $ sudo ./make.sh uninstall |
| 190 | |
| 191 | |
| 192 | |
| 193 | (9) Language bindings |
Nguyen Anh Quynh | a6a1153 | 2013-12-24 17:03:45 +0800 | [diff] [blame] | 194 | |
Nguyen Anh Quynh | 9919e3b | 2014-01-22 10:17:17 +0800 | [diff] [blame] | 195 | So far, Python, Ocaml & Java are supported by bindings in the main code. |
| 196 | Look for the bindings under directory bindings/, and refer to README file |
| 197 | of corresponding languages. |
| 198 | |
Nguyen Anh Quynh | 736762d | 2014-11-14 15:22:05 +0800 | [diff] [blame] | 199 | Community also provide bindings for C#, Go, Ruby, NodeJS, C++ & Vala. Links to |
| 200 | these can be found at address http://capstone-engine.org/download.html |