diff --git a/.gitignore b/.gitignore index eab9097ac3..b7abb383c7 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,4 @@ test_iter_benchmark *.s +.DS_Store diff --git a/CMakeLists.txt b/CMakeLists.txt index c2b1c111c3..239ba5ea1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,7 +60,6 @@ set(HEADERS_ENGINE MCInstrDesc.h SStream.h cs_priv.h - myinttypes.h include/platform.h ) diff --git a/SStream.c b/SStream.c index 3f648ccb7c..2228e99a8a 100644 --- a/SStream.c +++ b/SStream.c @@ -12,7 +12,8 @@ #endif #include -#include "myinttypes.h" +#include + #include "SStream.h" #include "cs_priv.h" #include "utils.h" diff --git a/arch/AArch64/AArch64InstPrinter.c b/arch/AArch64/AArch64InstPrinter.c index 65825c2766..19c46598c4 100644 --- a/arch/AArch64/AArch64InstPrinter.c +++ b/arch/AArch64/AArch64InstPrinter.c @@ -16,7 +16,7 @@ #ifdef CAPSTONE_HAS_ARM64 -#include "../../myinttypes.h" +#include #include #include diff --git a/arch/ARM/ARMDisassembler.c b/arch/ARM/ARMDisassembler.c index b4dbb43d95..e7dd7a7ed7 100644 --- a/arch/ARM/ARMDisassembler.c +++ b/arch/ARM/ARMDisassembler.c @@ -15,7 +15,7 @@ #include #include #include -#include "../../myinttypes.h" +#include #include "ARMAddressingModes.h" #include "ARMBaseInfo.h" diff --git a/arch/ARM/ARMInstPrinter.c b/arch/ARM/ARMInstPrinter.c index c73a713503..bdca3e7e1b 100644 --- a/arch/ARM/ARMInstPrinter.c +++ b/arch/ARM/ARMInstPrinter.c @@ -19,7 +19,7 @@ #include // DEBUG #include #include -#include "../../myinttypes.h" +#include #include "ARMInstPrinter.h" #include "ARMAddressingModes.h" diff --git a/arch/Mips/MipsDisassembler.c b/arch/Mips/MipsDisassembler.c index 818a1deb28..4e837db19f 100644 --- a/arch/Mips/MipsDisassembler.c +++ b/arch/Mips/MipsDisassembler.c @@ -19,7 +19,7 @@ #include #include -#include "../../myinttypes.h" +#include #include "../../utils.h" diff --git a/arch/Mips/MipsInstPrinter.c b/arch/Mips/MipsInstPrinter.c index accce44046..6dbbac2cee 100644 --- a/arch/Mips/MipsInstPrinter.c +++ b/arch/Mips/MipsInstPrinter.c @@ -16,7 +16,7 @@ #ifdef CAPSTONE_HAS_MIPS -#include "../../myinttypes.h" +#include #include #include // debug #include diff --git a/arch/PowerPC/PPCGenAsmWriter.inc b/arch/PowerPC/PPCGenAsmWriter.inc index 7d9ad73836..689216cba2 100644 --- a/arch/PowerPC/PPCGenAsmWriter.inc +++ b/arch/PowerPC/PPCGenAsmWriter.inc @@ -10,7 +10,7 @@ /* By Nguyen Anh Quynh , 2013-2014 */ #include // debug -#include "../../myinttypes.h" +#include /// printInstruction - This method is automatically generated by tablegen /// from the instruction set description. diff --git a/arch/Sparc/SparcGenAsmWriter.inc b/arch/Sparc/SparcGenAsmWriter.inc index 239f62051d..b8f34959d7 100644 --- a/arch/Sparc/SparcGenAsmWriter.inc +++ b/arch/Sparc/SparcGenAsmWriter.inc @@ -10,7 +10,7 @@ /* By Nguyen Anh Quynh , 2013-2014 */ #include // debug -#include "../../myinttypes.h" +#include /// printInstruction - This method is automatically generated by tablegen diff --git a/arch/SystemZ/SystemZGenAsmWriter.inc b/arch/SystemZ/SystemZGenAsmWriter.inc index f864137427..8ffc29d611 100644 --- a/arch/SystemZ/SystemZGenAsmWriter.inc +++ b/arch/SystemZ/SystemZGenAsmWriter.inc @@ -10,7 +10,7 @@ /* By Nguyen Anh Quynh , 2013-2014 */ #include // debug -#include "../../myinttypes.h" +#include /// printInstruction - This method is automatically generated by tablegen diff --git a/arch/SystemZ/SystemZInstPrinter.c b/arch/SystemZ/SystemZInstPrinter.c index 10adf135d4..2b9cbff007 100644 --- a/arch/SystemZ/SystemZInstPrinter.c +++ b/arch/SystemZ/SystemZInstPrinter.c @@ -19,7 +19,7 @@ #include #include #include -#include "../../myinttypes.h" +#include #include "SystemZInstPrinter.h" #include "../../MCInst.h" diff --git a/arch/X86/X86ATTInstPrinter.c b/arch/X86/X86ATTInstPrinter.c index 7f53cf86c0..78fad0c730 100644 --- a/arch/X86/X86ATTInstPrinter.c +++ b/arch/X86/X86ATTInstPrinter.c @@ -21,7 +21,7 @@ #if !defined(CAPSTONE_HAS_OSXKERNEL) #include #endif -#include "../../myinttypes.h" +#include #if defined(CAPSTONE_HAS_OSXKERNEL) #include #else diff --git a/arch/X86/X86Disassembler.c b/arch/X86/X86Disassembler.c index 1814c44731..dccb30821d 100644 --- a/arch/X86/X86Disassembler.c +++ b/arch/X86/X86Disassembler.c @@ -19,7 +19,6 @@ #ifdef CAPSTONE_HAS_X86 -#include "../../myinttypes.h" // debug #include #include "../../cs_priv.h" diff --git a/arch/X86/X86IntelInstPrinter.c b/arch/X86/X86IntelInstPrinter.c index 001feb9cfb..9bd94cb44d 100644 --- a/arch/X86/X86IntelInstPrinter.c +++ b/arch/X86/X86IntelInstPrinter.c @@ -20,7 +20,7 @@ #if !defined(CAPSTONE_HAS_OSXKERNEL) #include #endif -#include "../../myinttypes.h" +#include #if defined(CAPSTONE_HAS_OSXKERNEL) #include #else diff --git a/arch/XCore/XCoreGenAsmWriter.inc b/arch/XCore/XCoreGenAsmWriter.inc index d179930d6f..72ca2f8cf2 100644 --- a/arch/XCore/XCoreGenAsmWriter.inc +++ b/arch/XCore/XCoreGenAsmWriter.inc @@ -10,7 +10,7 @@ /* By Nguyen Anh Quynh , 2013-2014 */ #include // debug -#include "../../myinttypes.h" +#include /// printInstruction - This method is automatically generated by tablegen diff --git a/arch/XCore/XCoreInstPrinter.c b/arch/XCore/XCoreInstPrinter.c index bafe5ba096..e23fa4c7df 100644 --- a/arch/XCore/XCoreInstPrinter.c +++ b/arch/XCore/XCoreInstPrinter.c @@ -19,7 +19,7 @@ #include #include #include -#include "../../myinttypes.h" +#include #include "XCoreInstPrinter.h" #include "../../MCInst.h" diff --git a/cs.c b/cs.c index 6854c7dc0c..2e4be02a55 100644 --- a/cs.c +++ b/cs.c @@ -476,6 +476,10 @@ size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64 handle->errnum = CS_ERR_OK; + // reset IT block of ARM structure + if (handle->arch == CS_ARCH_ARM) + handle->ITBlock.size = 0; + #ifdef CAPSTONE_USE_SYS_DYN_MEM if (count > 0 && count <= INSN_CACHE_SIZE) cache_size = (unsigned int) count; diff --git a/include/capstone.h b/include/capstone.h index 867ed9027c..354e499fc7 100644 --- a/include/capstone.h +++ b/include/capstone.h @@ -124,7 +124,7 @@ typedef struct cs_opt_mem { // Runtime option for the disassembled engine typedef enum cs_opt_type { - CS_OPT_INVALID = 0, // No opetion specified + CS_OPT_INVALID = 0, // No option specified CS_OPT_SYNTAX, // Assembly output syntax CS_OPT_DETAIL, // Break down instruction structure into details CS_OPT_MODE, // Change engine's mode at run-time @@ -512,7 +512,7 @@ cs_insn * CAPSTONE_API cs_malloc(csh handle); @handle: handle returned by cs_open() @code: buffer containing raw binary code to be disassembled - @code_size: size of above code + @size: size of above code @address: address of the first insn in given raw code buffer @insn: pointer to instruction to be filled in by this API. diff --git a/myinttypes.h b/myinttypes.h deleted file mode 100644 index 0356467403..0000000000 --- a/myinttypes.h +++ /dev/null @@ -1,10 +0,0 @@ -/* Capstone Disassembly Engine */ -/* By Axel Souchet, 2014 */ - -#ifndef CS_MYINTTYPES_H -#define CS_MYINTTYPES_H - -// The contents of myinttype.h are moved to platform.h -#include - -#endif diff --git a/suite/arm/test_arm_regression.c b/suite/arm/test_arm_regression.c index f5bddfb8b0..8b87f164b0 100644 --- a/suite/arm/test_arm_regression.c +++ b/suite/arm/test_arm_regression.c @@ -9,8 +9,8 @@ #include #include #include -#include "../../myinttypes.h" +#include #include static csh handle; diff --git a/suite/benchmark/test_iter_benchmark.c b/suite/benchmark/test_iter_benchmark.c index 0c04b8f0bc..39cd39d644 100644 --- a/suite/benchmark/test_iter_benchmark.c +++ b/suite/benchmark/test_iter_benchmark.c @@ -4,8 +4,8 @@ #include #include #include -#include "../myinttypes.h" +#include #include static void test() diff --git a/tests/test.c b/tests/test.c index 0ab6f4ef81..afff7a980f 100644 --- a/tests/test.c +++ b/tests/test.c @@ -3,8 +3,8 @@ #include #include -#include "../myinttypes.h" +#include #include struct platform { diff --git a/tests/test_arm.c b/tests/test_arm.c index bd31d31403..1af84be715 100644 --- a/tests/test_arm.c +++ b/tests/test_arm.c @@ -3,8 +3,8 @@ #include #include -#include "../myinttypes.h" +#include #include static csh handle; diff --git a/tests/test_arm64.c b/tests/test_arm64.c index ea35da6c68..6a9f8daebb 100644 --- a/tests/test_arm64.c +++ b/tests/test_arm64.c @@ -3,8 +3,8 @@ #include #include -#include "../myinttypes.h" +#include #include static csh handle; diff --git a/tests/test_detail.c b/tests/test_detail.c index 75853f7ea6..2d205f2092 100644 --- a/tests/test_detail.c +++ b/tests/test_detail.c @@ -3,8 +3,8 @@ #include #include -#include "../myinttypes.h" +#include #include struct platform { diff --git a/tests/test_iter.c b/tests/test_iter.c index c393254b90..623889d681 100644 --- a/tests/test_iter.c +++ b/tests/test_iter.c @@ -4,8 +4,8 @@ // This sample code demonstrates the APIs cs_malloc() & cs_disasm_iter(). #include #include -#include "../myinttypes.h" +#include #include struct platform { diff --git a/tests/test_mips.c b/tests/test_mips.c index feafd289c9..f5795b871c 100644 --- a/tests/test_mips.c +++ b/tests/test_mips.c @@ -3,8 +3,8 @@ #include #include -#include "../myinttypes.h" +#include #include struct platform { diff --git a/tests/test_ppc.c b/tests/test_ppc.c index 3fe229256d..36a8b2d320 100644 --- a/tests/test_ppc.c +++ b/tests/test_ppc.c @@ -2,8 +2,8 @@ /* By Nguyen Anh Quynh , 2013> */ #include -#include "../myinttypes.h" +#include #include struct platform { diff --git a/tests/test_skipdata.c b/tests/test_skipdata.c index 7fb78e04a9..8e4a21cbdf 100644 --- a/tests/test_skipdata.c +++ b/tests/test_skipdata.c @@ -3,8 +3,8 @@ #include #include -#include "../myinttypes.h" +#include #include struct platform { diff --git a/tests/test_sparc.c b/tests/test_sparc.c index 522d823916..60f9487ab6 100644 --- a/tests/test_sparc.c +++ b/tests/test_sparc.c @@ -2,8 +2,8 @@ /* By Nguyen Anh Quynh , 2013-2014 */ #include -#include "../myinttypes.h" +#include #include struct platform { diff --git a/tests/test_systemz.c b/tests/test_systemz.c index abbc73469c..209a7bf16e 100644 --- a/tests/test_systemz.c +++ b/tests/test_systemz.c @@ -2,8 +2,8 @@ /* By Nguyen Anh Quynh , 2013-2014 */ #include -#include "../myinttypes.h" +#include #include struct platform { diff --git a/tests/test_winkernel.cpp b/tests/test_winkernel.cpp index 42abf40bbc..dce077cc7c 100644 --- a/tests/test_winkernel.cpp +++ b/tests/test_winkernel.cpp @@ -73,77 +73,80 @@ namespace xcore { #pragma warning(pop) // Exercises all existing regression tests -static void test() { - KFLOATING_SAVE float_save; - NTSTATUS status; - - // Any of Capstone APIs cannot be called at IRQL higher than DISPATCH_LEVEL - // since our malloc implementation using ExAllocatePoolWithTag() is able to - // allocate memory only up to the DISPATCH_LEVEL level. - NT_ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL); - - // 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 - // Point or MMX in a WDM Driver" on MSDN for more details. - status = KeSaveFloatingPointState(&float_save); - if (!NT_SUCCESS(status)) { - printf("ERROR: Failed to save floating point state!\n"); - return; - } - - unnamed::test(); - arm::test(); - arm64::test(); - detail::test(); - iter::test(); - mips::test(); - ppc::test(); - skipdata::test(); - sparc::test(); - systemz::test(); - x86::test(); - xcore::test(); - - // Restores the nonvolatile floating-point context. - KeRestoreFloatingPointState(&float_save); +static void test() +{ + KFLOATING_SAVE float_save; + NTSTATUS status; + + // Any of Capstone APIs cannot be called at IRQL higher than DISPATCH_LEVEL + // since our malloc implementation using ExAllocatePoolWithTag() is able to + // allocate memory only up to the DISPATCH_LEVEL level. + NT_ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL); + + // 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 + // Point or MMX in a WDM Driver" on MSDN for more details. + status = KeSaveFloatingPointState(&float_save); + if (!NT_SUCCESS(status)) { + printf("ERROR: Failed to save floating point state!\n"); + return; + } + + unnamed::test(); + arm::test(); + arm64::test(); + detail::test(); + iter::test(); + mips::test(); + ppc::test(); + skipdata::test(); + sparc::test(); + systemz::test(); + x86::test(); + xcore::test(); + + // Restores the nonvolatile floating-point context. + KeRestoreFloatingPointState(&float_save); } // Functional test for cs_winkernel_vsnprintf() static void cs_winkernel_vsnprintf_test() { - char buf[10]; - bool ok = true; - ok = (ok && cs_snprintf(buf, sizeof(buf), "%s", "") == 0 && strcmp(buf, "") == 0); - ok = (ok && cs_snprintf(buf, sizeof(buf), "%s", "0") == 1 && strcmp(buf, "0") == 0); - ok = (ok && cs_snprintf(buf, sizeof(buf), "%s", "012345678") == 9 && strcmp(buf, "012345678") == 0); - ok = (ok && cs_snprintf(buf, sizeof(buf), "%s", "0123456789") == 10 && strcmp(buf, "012345678") == 0); - ok = (ok && cs_snprintf(buf, sizeof(buf), "%s", "01234567890") == 11 && strcmp(buf, "012345678") == 0); - ok = (ok && cs_snprintf(buf, sizeof(buf), "%s", "0123456789001234567890") == 22 && strcmp(buf, "012345678") == 0); - if (!ok) { - printf("ERROR: cs_winkernel_vsnprintf_test() did not produce expected results!\n"); - } + char buf[10]; + bool ok = true; + ok = (ok && cs_snprintf(buf, sizeof(buf), "%s", "") == 0 && strcmp(buf, "") == 0); + ok = (ok && cs_snprintf(buf, sizeof(buf), "%s", "0") == 1 && strcmp(buf, "0") == 0); + ok = (ok && cs_snprintf(buf, sizeof(buf), "%s", "012345678") == 9 && strcmp(buf, "012345678") == 0); + ok = (ok && cs_snprintf(buf, sizeof(buf), "%s", "0123456789") == 10 && strcmp(buf, "012345678") == 0); + ok = (ok && cs_snprintf(buf, sizeof(buf), "%s", "01234567890") == 11 && strcmp(buf, "012345678") == 0); + ok = (ok && cs_snprintf(buf, sizeof(buf), "%s", "0123456789001234567890") == 22 && strcmp(buf, "012345678") == 0); + if (!ok) { + printf("ERROR: cs_winkernel_vsnprintf_test() did not produce expected results!\n"); + } } // Driver entry point EXTERN_C NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, - PUNICODE_STRING RegistryPath) { - UNREFERENCED_PARAMETER(DriverObject); - UNREFERENCED_PARAMETER(RegistryPath); - cs_winkernel_vsnprintf_test(); - test(); - return STATUS_CANCELLED; + PUNICODE_STRING RegistryPath) +{ + UNREFERENCED_PARAMETER(DriverObject); + UNREFERENCED_PARAMETER(RegistryPath); + cs_winkernel_vsnprintf_test(); + test(); + return STATUS_CANCELLED; } // This functions mimics printf() but does not return the same value as printf() // would do. printf() is required to exercise regression tests. -int __cdecl printf(const char * format, ...) { - NTSTATUS status; - va_list args; - - va_start(args, format); - status = vDbgPrintEx(DPFLTR_DEFAULT_ID, DPFLTR_ERROR_LEVEL, format, args); - va_end(args); - return NT_SUCCESS(status); +int __cdecl printf(const char * format, ...) +{ + NTSTATUS status; + va_list args; + + va_start(args, format); + status = vDbgPrintEx(DPFLTR_DEFAULT_ID, DPFLTR_ERROR_LEVEL, format, args); + va_end(args); + return NT_SUCCESS(status); } diff --git a/tests/test_x86.c b/tests/test_x86.c index 880d03a680..5edad24ec7 100644 --- a/tests/test_x86.c +++ b/tests/test_x86.c @@ -3,8 +3,8 @@ #include #include -#include "../myinttypes.h" +#include #include static csh handle; @@ -104,9 +104,6 @@ static void print_insn_detail(csh ud, cs_mode mode, cs_insn *ins) case X86_OP_IMM: printf("\t\toperands[%u].type: IMM = 0x%" PRIx64 "\n", i, op->imm); break; - case X86_OP_FP: - printf("\t\toperands[%u].type: FP = %f\n", i, op->fp); - break; case X86_OP_MEM: printf("\t\toperands[%u].type: MEM\n", i); if (op->mem.segment != X86_REG_INVALID) diff --git a/tests/test_xcore.c b/tests/test_xcore.c index 32a9ec0cc0..958565531a 100644 --- a/tests/test_xcore.c +++ b/tests/test_xcore.c @@ -2,8 +2,8 @@ /* By Nguyen Anh Quynh , 2013-2014 */ #include -#include "../myinttypes.h" +#include #include struct platform { diff --git a/windows/winkernel_mm.c b/windows/winkernel_mm.c index 3ccb40d527..08ca9945fa 100644 --- a/windows/winkernel_mm.c +++ b/windows/winkernel_mm.c @@ -8,10 +8,9 @@ static const ULONG CS_WINKERNEL_POOL_TAG = 'kwsC'; // A structure to implement realloc() -typedef struct _CS_WINKERNEL_MEMBLOCK -{ - size_t size; // A number of bytes allocated - char data[1]; // An address returned to a caller +typedef struct _CS_WINKERNEL_MEMBLOCK { + size_t size; // A number of bytes allocated + char data[1]; // An address returned to a caller } CS_WINKERNEL_MEMBLOCK; C_ASSERT(sizeof(CS_WINKERNEL_MEMBLOCK) == sizeof(void *) * 2); @@ -19,66 +18,63 @@ C_ASSERT(sizeof(CS_WINKERNEL_MEMBLOCK) == sizeof(void *) * 2); // free() void CAPSTONE_API cs_winkernel_free(void *ptr) { - if (ptr) - { - ExFreePoolWithTag(CONTAINING_RECORD(ptr, CS_WINKERNEL_MEMBLOCK, data), CS_WINKERNEL_POOL_TAG); - } + if (ptr) { + ExFreePoolWithTag(CONTAINING_RECORD(ptr, CS_WINKERNEL_MEMBLOCK, data), CS_WINKERNEL_POOL_TAG); + } } // malloc() void * CAPSTONE_API cs_winkernel_malloc(size_t size) { - // Disallow zero length allocation because they waste pool header space and, - // in many cases, indicate a potential validation issue in the calling code. - NT_ASSERT(size); - - CS_WINKERNEL_MEMBLOCK *block = (CS_WINKERNEL_MEMBLOCK *)ExAllocatePoolWithTag( - NonPagedPoolNx, size + sizeof(CS_WINKERNEL_MEMBLOCK), CS_WINKERNEL_POOL_TAG); - if (!block) - { - return NULL; - } - block->size = size; - return block->data; + // Disallow zero length allocation because they waste pool header space and, + // in many cases, indicate a potential validation issue in the calling code. + NT_ASSERT(size); + + CS_WINKERNEL_MEMBLOCK *block = (CS_WINKERNEL_MEMBLOCK *)ExAllocatePoolWithTag( + NonPagedPoolNx, size + sizeof(CS_WINKERNEL_MEMBLOCK), CS_WINKERNEL_POOL_TAG); + if (!block) { + return NULL; + } + block->size = size; + + return block->data; } // calloc() void * CAPSTONE_API cs_winkernel_calloc(size_t n, size_t size) { - size_t total = n * size; + size_t total = n * size; - void *new_ptr = cs_winkernel_malloc(total); - if (!new_ptr) - { - return NULL; - } + void *new_ptr = cs_winkernel_malloc(total); + if (!new_ptr) { + return NULL; + } - return RtlFillMemory(new_ptr, total, 0); + return RtlFillMemory(new_ptr, total, 0); } // realloc() void * CAPSTONE_API cs_winkernel_realloc(void *ptr, size_t size) { - void *new_ptr = NULL; - size_t current_size = 0; - size_t smaller_size = 0; - - if (!ptr) - { - return cs_winkernel_malloc(size); - } - - new_ptr = cs_winkernel_malloc(size); - if (!new_ptr) - { - return NULL; - } - - current_size = CONTAINING_RECORD(ptr, CS_WINKERNEL_MEMBLOCK, data)->size; - smaller_size = (current_size < size) ? current_size : size; - RtlCopyMemory(new_ptr, ptr, smaller_size); - cs_winkernel_free(ptr); - return new_ptr; + void *new_ptr = NULL; + size_t current_size = 0; + size_t smaller_size = 0; + + if (!ptr) { + return cs_winkernel_malloc(size); + } + + new_ptr = cs_winkernel_malloc(size); + if (!new_ptr) { + return NULL; + } + + current_size = CONTAINING_RECORD(ptr, CS_WINKERNEL_MEMBLOCK, data)->size; + smaller_size = (current_size < size) ? current_size : size; + RtlCopyMemory(new_ptr, ptr, smaller_size); + cs_winkernel_free(ptr); + + return new_ptr; } // vsnprintf(). _vsnprintf() is avaialable for drivers, but it differs from @@ -86,35 +82,35 @@ void * CAPSTONE_API cs_winkernel_realloc(void *ptr, size_t size) // 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. +// API as listed in dontuse.h for security +// purposes. 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. - 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 - // 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. - char* tmp = cs_winkernel_malloc(0x1000); - if (!tmp) { - return result; - } - result = _vsnprintf(tmp, 0x1000, format, argptr); - NT_ASSERT(result != -1); - cs_winkernel_free(tmp); - } - - return result; + 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. + 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 + // 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. + char* tmp = cs_winkernel_malloc(0x1000); + if (!tmp) { + return result; + } + + result = _vsnprintf(tmp, 0x1000, format, argptr); + NT_ASSERT(result != -1); + cs_winkernel_free(tmp); + } + + return result; } #pragma warning(pop) diff --git a/windows/winkernel_mm.h b/windows/winkernel_mm.h index f2090398e3..f9ab6a2a0b 100644 --- a/windows/winkernel_mm.h +++ b/windows/winkernel_mm.h @@ -1,7 +1,7 @@ /* Capstone Disassembly Engine */ /* By Satoshi Tanda , 2016 */ -#ifndef CS_WINDOWS_WINKERNEL_MM_H_ -#define CS_WINDOWS_WINKERNEL_MM_H_ +#ifndef CS_WINDOWS_WINKERNEL_MM_H +#define CS_WINDOWS_WINKERNEL_MM_H #ifdef __cplusplus extern "C" { @@ -19,4 +19,4 @@ int CAPSTONE_API cs_winkernel_vsnprintf(char *buffer, size_t count, const char * } #endif -#endif // CS_WINDOWS_WINKERNEL_MM_H_ +#endif // CS_WINDOWS_WINKERNEL_MM_H diff --git a/xcode/Capstone.xcodeproj/project.pbxproj b/xcode/Capstone.xcodeproj/project.pbxproj index bcce829c5d..5bd6c68890 100644 --- a/xcode/Capstone.xcodeproj/project.pbxproj +++ b/xcode/Capstone.xcodeproj/project.pbxproj @@ -308,7 +308,6 @@ DC474F6B19DE6F3B00BCA449 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; DC5BFF4019EE544E008CA585 /* test_iter */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = test_iter; sourceTree = BUILT_PRODUCTS_DIR; }; DC5BFF4819EE54BE008CA585 /* test_iter.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = test_iter.c; path = ../tests/test_iter.c; sourceTree = ""; }; - DC696C5E1AD4600200A56306 /* myinttypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = myinttypes.h; path = ../myinttypes.h; sourceTree = ""; }; DCFE23BD19DDCC2D00EF8EA9 /* libcapstone.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libcapstone.a; sourceTree = BUILT_PRODUCTS_DIR; }; DCFE23CD19DDCC9500EF8EA9 /* libcapstone.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libcapstone.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; DCFE23DD19DDCD8700EF8EA9 /* AArch64AddressingModes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AArch64AddressingModes.h; sourceTree = ""; }; @@ -617,7 +616,6 @@ DCFE24B719DDCE1E00EF8EA9 /* MCInstrDesc.h */, DCFE24A019DDCDEE00EF8EA9 /* MCRegisterInfo.c */, DCFE24B819DDCE1E00EF8EA9 /* MCRegisterInfo.h */, - DC696C5E1AD4600200A56306 /* myinttypes.h */, DCFE24A119DDCDEE00EF8EA9 /* SStream.c */, DCFE24B919DDCE1E00EF8EA9 /* SStream.h */, DCFE24A219DDCDEE00EF8EA9 /* utils.c */,