Skip to content

Commit

Permalink
Merge pull request capstone-engine#779 from tandasat/original
Browse files Browse the repository at this point in the history
Fix typo, style, suppress MSVC PREfast warnings, ignore residual files on project upgrade
  • Loading branch information
aquynh authored Sep 28, 2016
2 parents f9474e1 + f177f92 commit 97e3838
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ _*
packages/freebsd/ports/devel/capstone/distinfo

# VisualStudio
ProjectUpgradeLog.log
Debug/
Release/
ipch/
*.sdf
*.opensdf
*.suo
*.user
*.backup
*.VC.db
*.VC.opendb

Expand Down
2 changes: 1 addition & 1 deletion COMPILE_MSVC.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ versions, and Windows Driver Kit 8.1 Update 1 or newer versions are required.
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.
Expand Down
2 changes: 1 addition & 1 deletion HACK.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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.
3 changes: 2 additions & 1 deletion arch/AArch64/AArch64BaseInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions arch/Sparc/SparcInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
13 changes: 5 additions & 8 deletions arch/XCore/XCoreInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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, ' ');
Expand Down
4 changes: 2 additions & 2 deletions contrib/cs_driver/cs_driver/cs_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion cs.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* Capstone Disassembly Engine */
/* By Nguyen Anh Quynh <[email protected]>, 2013-2014 */
#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>
Expand Down
2 changes: 1 addition & 1 deletion docs/README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Documention of Capstone disassembly framework.
Documentation of Capstone disassembly framework.

* Switching to 2.1 engine.

Expand Down
8 changes: 4 additions & 4 deletions include/x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,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
Expand All @@ -235,7 +235,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;
Expand Down
5 changes: 3 additions & 2 deletions tests/test_winkernel.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* Capstone Disassembly Engine */
/* By Satoshi Tanda <[email protected]>, 2016 */

#include <ntddk.h>
#include <capstone.h>

Expand All @@ -19,7 +20,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.
Expand Down Expand Up @@ -93,7 +94,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)) {
Expand Down
17 changes: 10 additions & 7 deletions windows/winkernel_mm.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* Capstone Disassembly Engine */
/* By Satoshi Tanda <[email protected]>, 2016 */

#include "winkernel_mm.h"
#include <ntddk.h>

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions windows/winkernel_mm.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* Capstone Disassembly Engine */
/* By Satoshi Tanda <[email protected]>, 2016 */

#ifndef CS_WINDOWS_WINKERNEL_MM_H
#define CS_WINDOWS_WINKERNEL_MM_H

Expand Down

0 comments on commit 97e3838

Please sign in to comment.