Nguyen Anh Quynh | 6f9b113 | 2014-05-19 17:06:44 +0800 | [diff] [blame] | 1 | This documentation explains how to compile Capstone on Windows using |
| 2 | Microsoft Visual Studio version 2010 or newer. |
Nguyen Anh Quynh | 61882e5 | 2014-05-18 00:39:49 +0800 | [diff] [blame] | 3 | |
Nguyen Anh Quynh | f1c3acb | 2014-05-28 22:39:23 +0800 | [diff] [blame] | 4 | To compile Capstone on *nix, see COMPILE.TXT |
| 5 | |
| 6 | To compile Capstone with CMake, see COMPILE_CMAKE.TXT |
| 7 | |
Axel 0vercl0k Souchet | 27e9cc4 | 2014-05-10 14:41:45 +0100 | [diff] [blame] | 8 | *-*-*-*-*-* |
| 9 | |
tandasat | 45e5eab | 2016-05-11 21:48:32 -0700 | [diff] [blame] | 10 | Capstone requires no prerequisite packages with default configurations, so it is |
| 11 | easy to compile & install. Open the Visual Studio solution "msvc/capstone.sln" |
| 12 | and follow the instructions below. |
Nguyen Anh Quynh | 61882e5 | 2014-05-18 00:39:49 +0800 | [diff] [blame] | 13 | |
| 14 | NOTE: This requires Visual Studio 2010 or newer versions. |
Axel 0vercl0k Souchet | 27e9cc4 | 2014-05-10 14:41:45 +0100 | [diff] [blame] | 15 | |
tandasat | 45e5eab | 2016-05-11 21:48:32 -0700 | [diff] [blame] | 16 | If you wish to embed Capstone in a kernel driver, Visual Studio 2013 or newer |
| 17 | versions, and Windows Driver Kit 8.1 Update 1 or newer versions are required. |
| 18 | |
Axel 0vercl0k Souchet | 27e9cc4 | 2014-05-10 14:41:45 +0100 | [diff] [blame] | 19 | |
| 20 | (0) Tailor Capstone to your need. |
| 21 | |
Nguyen Anh Quynh | 74a114e | 2015-10-05 16:14:19 +0800 | [diff] [blame] | 22 | Out of 9 archtitectures supported by Capstone (Arm, Arm64, M68K, Mips, PPC, |
| 23 | Sparc, SystemZ, X86 & XCore), if you just need several selected archs, choose |
| 24 | the ones you want to compile in by opening Visual Studio solution "msvc\capstone.sln", |
Nguyen Anh Quynh | c80d840 | 2014-05-26 23:02:48 +0800 | [diff] [blame] | 25 | then directly editing the projects "capstone_static" & "capstone_dll" for static |
Nguyen Anh Quynh | 01f4839 | 2014-05-15 11:06:43 +0800 | [diff] [blame] | 26 | and dynamic libraries, respectively. This must be done before going to the |
| 27 | next steps. |
Axel 0vercl0k Souchet | 27e9cc4 | 2014-05-10 14:41:45 +0100 | [diff] [blame] | 28 | |
Nguyen Anh Quynh | ba37f33 | 2014-05-14 07:48:50 +0800 | [diff] [blame] | 29 | In VisualStudio interface, modify the preprocessor definitions via |
Satoshi Tanda | 565b6c3 | 2016-09-27 07:39:51 -0700 | [diff] [blame] | 30 | "Project Properties" -> "Configuration Properties" -> "C/C++" -> "Preprocessor" |
Nguyen Anh Quynh | ba37f33 | 2014-05-14 07:48:50 +0800 | [diff] [blame] | 31 | to customize Capstone library, as followings. |
Axel 0vercl0k Souchet | 27e9cc4 | 2014-05-10 14:41:45 +0100 | [diff] [blame] | 32 | |
Nguyen Anh Quynh | ba37f33 | 2014-05-14 07:48:50 +0800 | [diff] [blame] | 33 | - CAPSTONE_HAS_ARM: support ARM. Delete this to remove ARM support. |
Nguyen Anh Quynh | 01f4839 | 2014-05-15 11:06:43 +0800 | [diff] [blame] | 34 | - CAPSTONE_HAS_ARM64: support ARM64. Delete this to remove ARM64 support. |
Nguyen Anh Quynh | 74a114e | 2015-10-05 16:14:19 +0800 | [diff] [blame] | 35 | - CAPSTONE_HAS_M68K: support M68K. Delete this to remove M68K support. |
Nguyen Anh Quynh | 01f4839 | 2014-05-15 11:06:43 +0800 | [diff] [blame] | 36 | - CAPSTONE_HAS_MIPS: support Mips. Delete this to remove Mips support. |
| 37 | - CAPSTONE_HAS_PPC: support PPC. Delete this to remove PPC support. |
Nguyen Anh Quynh | ba37f33 | 2014-05-14 07:48:50 +0800 | [diff] [blame] | 38 | - CAPSTONE_HAS_SPARC: support Sparc. Delete this to remove Sparc support. |
| 39 | - CAPSTONE_HAS_SYSZ: support SystemZ. Delete this to remove SystemZ support. |
| 40 | - CAPSTONE_HAS_X86: support X86. Delete this to remove X86 support. |
Nguyen Anh Quynh | c80d840 | 2014-05-26 23:02:48 +0800 | [diff] [blame] | 41 | - CAPSTONE_HAS_XCORE: support XCore. Delete this to remove XCore support. |
Axel 0vercl0k Souchet | 27e9cc4 | 2014-05-10 14:41:45 +0100 | [diff] [blame] | 42 | |
Nguyen Anh Quynh | 74a114e | 2015-10-05 16:14:19 +0800 | [diff] [blame] | 43 | By default, all 9 architectures are compiled in. |
Nguyen Anh Quynh | ba37f33 | 2014-05-14 07:48:50 +0800 | [diff] [blame] | 44 | |
| 45 | |
| 46 | Besides, Capstone also allows some more customization via following macros. |
| 47 | |
| 48 | - CAPSTONE_USE_SYS_DYN_MEM: delete this to use your own dynamic memory management. |
Nguyen Anh Quynh | 01f4839 | 2014-05-15 11:06:43 +0800 | [diff] [blame] | 49 | - CAPSTONE_DIET_NO: rename this to "CAPSTONE_DIET" to make the binaries more compact. |
| 50 | - CAPSTONE_X86_REDUCE_NO: rename this to "CAPSTONE_X86_REDUCE" to make X86 binary smaller. |
obs | cb8e40c | 2014-08-17 21:07:13 +0200 | [diff] [blame] | 51 | - CAPSTONE_X86_ATT_DISABLE_NO: rename this to "CAPSTONE_X86_ATT_DISABLE" to disable |
| 52 | AT&T syntax on x86. |
Nguyen Anh Quynh | ba37f33 | 2014-05-14 07:48:50 +0800 | [diff] [blame] | 53 | |
Nguyen Anh Quynh | 01f4839 | 2014-05-15 11:06:43 +0800 | [diff] [blame] | 54 | By default, Capstone use system dynamic memory management, and both DIET and X86_REDUCE |
| 55 | modes are disable. |
Nguyen Anh Quynh | ba37f33 | 2014-05-14 07:48:50 +0800 | [diff] [blame] | 56 | |
Axel 0vercl0k Souchet | 27e9cc4 | 2014-05-10 14:41:45 +0100 | [diff] [blame] | 57 | |
| 58 | For each option, refer to docs/README for more details. |
| 59 | |
Nguyen Anh Quynh | 9c02b27 | 2014-05-14 08:00:22 +0800 | [diff] [blame] | 60 | |
| 61 | |
Axel 0vercl0k Souchet | 27e9cc4 | 2014-05-10 14:41:45 +0100 | [diff] [blame] | 62 | (1) Compile from source on Windows with Visual Studio |
| 63 | |
Nguyen Anh Quynh | 9c02b27 | 2014-05-14 08:00:22 +0800 | [diff] [blame] | 64 | - Choose the configuration and the platform you want: Release/Debug & Win32/Win64. |
| 65 | - Build only the libraries, or the libraries along with all the tests. |
tandasat | 45e5eab | 2016-05-11 21:48:32 -0700 | [diff] [blame] | 66 | - "capstone_static_winkernel" is for compiling Capstone for a driver and |
| 67 | "test_winkernel" is a test for a driver, and those are excluded from build by |
| 68 | default. To compile them, open the Configuration Manager through the [Build] |
| 69 | menu and check "Build" check boxes for those project. |
Nguyen Anh Quynh | 9c02b27 | 2014-05-14 08:00:22 +0800 | [diff] [blame] | 70 | |
| 71 | |
Axel 0vercl0k Souchet | 27e9cc4 | 2014-05-10 14:41:45 +0100 | [diff] [blame] | 72 | |
Nguyen Anh Quynh | 726f99c | 2014-05-10 23:22:59 +0800 | [diff] [blame] | 73 | (2) You can make sure the prior steps successfully worked by launching one of the |
Nguyen Anh Quynh | 9c02b27 | 2014-05-14 08:00:22 +0800 | [diff] [blame] | 74 | testing binary (test*.exe). |
tandasat | 45e5eab | 2016-05-11 21:48:32 -0700 | [diff] [blame] | 75 | |
| 76 | The testing binary for a driver "test_winkernel.sys" is made up of all tests for |
| 77 | supported architectures configured with the step (0) along side its own tests. |
| 78 | Below explains a procedure to run the test driver and check test results. |
| 79 | |
| 80 | On the x64 platform, the test signing mode has to be enabled to install the test |
| 81 | driver. To do it, open the command prompt with the administrator privileges and |
| 82 | type the following command, and then restart the system to activate the change: |
| 83 | |
| 84 | >bcdedit /set testsigning on |
| 85 | |
| 86 | Test results from the test driver is sent to kernel debug buffer. In order to |
| 87 | see those results, download DebugView and run it with the administrator |
| 88 | privileges, then check [Capture Kernel] through the [Capture] menu. |
| 89 | |
| 90 | DebugView: https://technet.microsoft.com/en-us/sysinternals/debugview.aspx |
| 91 | |
| 92 | To install and uninstall the driver, use the 'sc' command. For installing and |
| 93 | executing test_winkernel.sys, execute the following commands with the |
| 94 | administrator privileges: |
| 95 | |
| 96 | >sc create test_winkernel type= kernel binPath= <full path to test_winkernel.sys> |
| 97 | [SC] CreateService SUCCESS |
| 98 | |
| 99 | >sc start test_winkernel |
| 100 | [SC] StartService FAILED 995: |
| 101 | |
| 102 | The I/O operation has been aborted because of either a thread exit or an application request. |
| 103 | |
| 104 | To uninstall the driver, execute the following commands with the administrator |
| 105 | privileges: |
| 106 | |
| 107 | >sc delete test_winkernel |
| 108 | >bcdedit /deletevalue testsigning |