Merge pull request #781 from tandasat/next

PR #779 plus more warning suppression and compile error fix
This commit is contained in:
Nguyen Anh Quynh 2016-09-29 08:49:03 +08:00 committed by GitHub
commit c6e7a9e0eb
15 changed files with 46 additions and 29 deletions

2
.gitignore vendored
View File

@ -77,6 +77,7 @@ _*
packages/freebsd/ports/devel/capstone/distinfo
# VisualStudio
ProjectUpgradeLog.log
Debug/
Release/
ipch/
@ -84,6 +85,7 @@ ipch/
*.opensdf
*.suo
*.user
*.backup
*.VC.db
*.VC.opendb

View File

@ -27,7 +27,7 @@ versions, and Windows Driver Kit 8.1 Update 1 or newer versions are required.
next steps.
In VisualStudio interface, modify the preprocessor definitions via
"Project Properties" -> "Configuration Propertis" -> "C/C++" -> "Preprocessor"
"Project Properties" -> "Configuration Properties" -> "C/C++" -> "Preprocessor"
to customize Capstone library, as followings.
- CAPSTONE_HAS_ARM: support ARM. Delete this to remove ARM support.

View File

@ -36,7 +36,7 @@ the code and try to recompile/reinstall again. This can be done with:
$ sudo ./make.sh install
At the same time, for Java/Ocaml/Python bindings, be sure to always use
the bindings coming with the core to avoid potential incompatility issue
the bindings coming with the core to avoid potential incompatibility issue
with older versions.
See bindings/<language>/README for detail instructions on how to compile &
install the bindings.

View File

@ -17,7 +17,8 @@
#ifdef CAPSTONE_HAS_ARM64
#if defined (WIN32) || defined (WIN64) || defined (_WIN32) || defined (_WIN64)
#pragma warning(disable:4996)
#pragma warning(disable:4996) // disable MSVC's warning on strcpy()
#pragma warning(disable:28719) // disable MSVC's warning on strcpy()
#endif
#include "../../utils.h"

View File

@ -6,6 +6,10 @@
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
//Banned API Usage : strcat / sprintf is a Banned API as listed in dontuse.h for
//security purposes.
#pragma warning(disable:28719)
#endif
#include <stdio.h> // DEBUG

View File

@ -20,6 +20,10 @@
#define _CRT_SECURE_NO_WARNINGS
#endif
#if defined (WIN32) || defined (WIN64) || defined (_WIN32) || defined (_WIN64)
#pragma warning(disable:28719) // disable MSVC's warning on strncpy()
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -2923,7 +2923,10 @@ static struct insn_reg2 insn_regs_intel2[] = {
static struct insn_reg insn_regs_intel_sorted [ARR_SIZE(insn_regs_intel)];
static int regs_cmp(const void *a, const void *b)
// Explicitly specified calling convention with CAPSTONE_API so that it is always
// compiled as __cdecl on MSVC and does not cause a compile error even when
// default calling convention is __stdcall (eg. capstone_static_winkernel project)
static int CAPSTONE_API regs_cmp(const void *a, const void *b)
{
uint16_t l = ((struct insn_reg *)a)->insn;
uint16_t r = ((struct insn_reg *)b)->insn;

View File

@ -16,6 +16,11 @@
#ifdef CAPSTONE_HAS_XCORE
#if defined (WIN32) || defined (WIN64) || defined (_WIN32) || defined (_WIN64)
#pragma warning(disable : 4996) // disable MSVC's warning on strcpy()
#pragma warning(disable : 28719) // disable MSVC's warning on strcpy()
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -46,15 +51,7 @@ void XCore_insn_extract(MCInst *MI, const char *code)
char *p, *p2;
char tmp[128];
// make MSVC shut up on strcpy()
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996)
#endif
strcpy(tmp, code); // safe because code is way shorter than 128 bytes
#ifdef _MSC_VER
#pragma warning(pop)
#endif
// find the first space
p = strchr(tmp, ' ');

View File

@ -56,14 +56,14 @@ static NTSTATUS cs_driver_hello() {
// On a 32bit driver, KeSaveFloatingPointState() is required before using any
// Capstone function because Capstone can access to the MMX/x87 registers and
// 32bit Windows requires drivers to use KeSaveFloatingPointState() before and
// KeRestoreFloatingPointState() after accesing to them. See "Using Floating
// KeRestoreFloatingPointState() after accessing them. See "Using Floating
// Point or MMX in a WDM Driver" on MSDN for more details.
status = KeSaveFloatingPointState(&float_save);
if (!NT_SUCCESS(status)) {
return status;
}
// Do stuff just like user-mode. All functionalites are supported.
// Do stuff just like user-mode. All functionalities are supported.
if (cs_open(CS_ARCH_X86, (sizeof(void *) == 4) ? CS_MODE_32 : CS_MODE_64,
&handle) != CS_ERR_OK) {
goto exit;

3
cs.c
View File

@ -1,7 +1,8 @@
/* Capstone Disassembly Engine */
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2015 */
#if defined (WIN32) || defined (WIN64) || defined (_WIN32) || defined (_WIN64)
#pragma warning(disable:4996)
#pragma warning(disable:4996) // disable MSVC's warning on strcpy()
#pragma warning(disable:28719) // disable MSVC's warning on strcpy()
#endif
#if defined(CAPSTONE_HAS_OSXKERNEL)
#include <libkern/libkern.h>

View File

@ -1,4 +1,4 @@
Documention of Capstone disassembly framework.
Documentation of Capstone disassembly framework.
* Switching to 2.1 engine.

View File

@ -269,15 +269,15 @@ typedef struct cs_x86 {
// prefix[3] indicates address-size override (X86_PREFIX_ADDRSIZE)
uint8_t prefix[4];
// Instruction opcode, wich can be from 1 to 4 bytes in size.
// Instruction opcode, which can be from 1 to 4 bytes in size.
// This contains VEX opcode as well.
// An trailing opcode byte gets value 0 when irrelevant.
uint8_t opcode[4];
// REX prefix: only a non-zero value is relavant for x86_64
// REX prefix: only a non-zero value is relevant for x86_64
uint8_t rex;
// Address size, which can be overrided with above prefix[5].
// Address size, which can be overridden with above prefix[5].
uint8_t addr_size;
// ModR/M byte
@ -292,7 +292,7 @@ typedef struct cs_x86 {
/* SIB state */
// SIB index register, or X86_REG_INVALID when irrelevant.
x86_reg sib_index;
// SIB scale. only applicable if sib_index is relavant.
// SIB scale. only applicable if sib_index is relevant.
int8_t sib_scale;
// SIB base register, or X86_REG_INVALID when irrelevant.
x86_reg sib_base;

View File

@ -1,5 +1,6 @@
/* Capstone Disassembly Engine */
/* By Satoshi Tanda <tanda.sat@gmail.com>, 2016 */
#include <ntddk.h>
#include <capstone/platform.h>
@ -21,7 +22,7 @@ EXTERN_C DRIVER_INITIALIZE DriverEntry;
#pragma warning(disable : 4005) // 'identifier' : macro redefinition
#pragma warning(disable : 4007) // 'main': must be '__cdecl'
// Drivers must protect floating point hardware state. See use of float simm:
// Drivers must protect floating point hardware state. See use of float.
// Use KeSaveFloatingPointState/KeRestoreFloatingPointState around floating
// point operations. Display Drivers should use the corresponding Eng... routines.
#pragma warning(disable : 28110) // Suppress this, as it is false positive.
@ -103,7 +104,7 @@ static void test()
// On a 32bit driver, KeSaveFloatingPointState() is required before using any
// Capstone function because Capstone can access to the MMX/x87 registers and
// 32bit Windows requires drivers to use KeSaveFloatingPointState() before and
// KeRestoreFloatingPointState() after accesing to them. See "Using Floating
// KeRestoreFloatingPointState() after accessing them. See "Using Floating
// Point or MMX in a WDM Driver" on MSDN for more details.
status = KeSaveFloatingPointState(&float_save);
if (!NT_SUCCESS(status)) {

View File

@ -1,5 +1,6 @@
/* Capstone Disassembly Engine */
/* By Satoshi Tanda <tanda.sat@gmail.com>, 2016 */
#include "winkernel_mm.h"
#include <ntddk.h>
@ -30,6 +31,8 @@ void * CAPSTONE_API cs_winkernel_malloc(size_t size)
// in many cases, indicate a potential validation issue in the calling code.
NT_ASSERT(size);
// FP; a use of NonPagedPool is required for Windows 7 support
#pragma prefast(suppress : 30030) // Allocating executable POOL_TYPE memory
CS_WINKERNEL_MEMBLOCK *block = (CS_WINKERNEL_MEMBLOCK *)ExAllocatePoolWithTag(
NonPagedPool, size + sizeof(CS_WINKERNEL_MEMBLOCK), CS_WINKERNEL_POOL_TAG);
if (!block) {
@ -77,27 +80,27 @@ void * CAPSTONE_API cs_winkernel_realloc(void *ptr, size_t size)
return new_ptr;
}
// vsnprintf(). _vsnprintf() is avaialable for drivers, but it differs from
// vsnprintf() in a return value and when a null-terminater is set.
// vsnprintf(). _vsnprintf() is available for drivers, but it differs from
// vsnprintf() in a return value and when a null-terminator is set.
// cs_winkernel_vsnprintf() takes care of those differences.
#pragma warning(push)
#pragma warning(disable : 28719) // Banned API Usage : _vsnprintf is a Banned
// API as listed in dontuse.h for security
// purposes.
// Banned API Usage : _vsnprintf is a Banned API as listed in dontuse.h for
// security purposes.
#pragma warning(disable : 28719)
int CAPSTONE_API cs_winkernel_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr)
{
int result = _vsnprintf(buffer, count, format, argptr);
// _vsnprintf() returns -1 when a string is truncated, and returns "count"
// when an entire string is stored but without '\0' at the end of "buffer".
// In both cases, null-terminater needs to be added manually.
// In both cases, null-terminator needs to be added manually.
if (result == -1 || (size_t)result == count) {
buffer[count - 1] = '\0';
}
if (result == -1) {
// In case when -1 is returned, the function has to get and return a number
// of characters that would have been written. This attempts so by re-tring
// of characters that would have been written. This attempts so by retrying
// the same conversion with temp buffer that is most likely big enough to
// complete formatting and get a number of characters that would have been
// written.

View File

@ -1,5 +1,6 @@
/* Capstone Disassembly Engine */
/* By Satoshi Tanda <tanda.sat@gmail.com>, 2016 */
#ifndef CS_WINDOWS_WINKERNEL_MM_H
#define CS_WINDOWS_WINKERNEL_MM_H