bughoho 2015-09-28 15:08:25 +08:00
parent e72de39fb6
commit ec31ea84ee
3 changed files with 81 additions and 5 deletions

View File

@ -791,6 +791,17 @@ bool X86_getInstruction(csh ud, const uint8_t *code, size_t code_len,
info.offset = address;
memset(&insn, 0, offsetof(InternalInstruction, reader));
//initialize some the necessary values
insn.prefixPresent[0x26] = 0;
insn.prefixPresent[0x2e] = 0;
insn.prefixPresent[0x36] = 0;
insn.prefixPresent[0x3e] = 0;
insn.prefixPresent[0x64] = 0;
insn.prefixPresent[0x65] = 0;
insn.prefixPresent[0x66] = 0;
insn.prefixPresent[0xf0] = 0;
insn.prefixPresent[0xf2] = 0;
insn.prefixPresent[0xf3] = 0;
if (instr->flat_insn->detail) {
instr->flat_insn->detail->x86.op_count = 0;

View File

@ -553,8 +553,6 @@ struct InstructionSpecifier {
typedef struct InternalInstruction {
// from here, all members must be initialized to ZERO to work properly
uint8_t operandSize;
/* 1 if the prefix byte corresponding to the entry is present; 0 if not */
uint8_t prefixPresent[0x100];
uint8_t prefix0, prefix1, prefix2, prefix3;
/* The value of the REX prefix, if present */
uint8_t rexPrefix;
@ -580,9 +578,6 @@ typedef struct InternalInstruction {
/* 1 if the prefix byte, 0xf2 or 0xf3 is xacquire or xrelease */
bool xAcquireRelease;
/* contains the location (for use with the reader) of the prefix byte */
uint64_t prefixLocations[0x100];
/* The value of the vector extension prefix(EVEX/VEX/XOP), if present */
uint8_t vectorExtensionPrefix[4];
@ -590,6 +585,11 @@ typedef struct InternalInstruction {
/* Reader interface (C) */
byteReader_t reader;
/* 1 if the prefix byte corresponding to the entry is present; 0 if not */
uint8_t prefixPresent[0x100];
/* contains the location (for use with the reader) of the prefix byte */
uint64_t prefixLocations[0x100];
/* Opaque value passed to the reader */
const void* readerArg;
/* The address of the next byte to read via the reader */

View File

@ -0,0 +1,65 @@
/* Capstone Disassembler Engine */
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013> */
// This sample code demonstrates the APIs cs_malloc() & cs_disasm_iter().
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "../myinttypes.h"
#include <capstone.h>
static void test()
{
#define X86_CODE32 "\x8d\x4c\x32\x08\x01\xd8\x81\xc6\x34\x12\x00\x00"
/* origin version output: time used:2.683000
* modified version output: time used:2.358000
* if don't output format text string,like this:
//handle->printer(&mci, &ss, handle->printer_info); <-----cs.c line 700
output:time used:1.138000
*/
csh handle;
uint64_t address;
cs_insn *insn;
int i;
cs_err err;
const uint8_t *code;
size_t size;
err = cs_open(CS_ARCH_X86, CS_MODE_32, &handle);
if (err) {
printf("Failed on cs_open() with error returned: %u\n", err);
return;
}
cs_option(handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_INTEL);
cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);
clock_t start, end;
double timeUsed;
start = clock();
int maxcount = 3400000;
insn = cs_malloc(handle);
for (i = 0; i < maxcount;) {
code = X86_CODE32;
address = 0x1000;
size = sizeof(X86_CODE32) - 1;
while(cs_disasm_iter(handle, &code, &size, &address, insn)) {
i++;
}
}
cs_free(insn, 1);
cs_close(&handle);
end = clock();
timeUsed = (double)(end - start) / CLOCKS_PER_SEC;
printf("time used:%f\n", timeUsed);
getchar();
}
int main()
{
test();
return 0;
}