Merge branch 'next' of https://github.com/aquynh/capstone into next

This commit is contained in:
Nguyen Anh Quynh
2017-05-25 23:10:26 +08:00
7 changed files with 42 additions and 2 deletions

View File

@ -20484,6 +20484,8 @@ static char *getRegisterName(unsigned RegNo)
#ifdef PRINT_ALIAS_INSTR
#undef PRINT_ALIAS_INSTR
#ifndef CAPSTONE_DIET
static void printCustomAliasOperand(MCInst *MI, unsigned OpIdx,
unsigned PrintMethodIdx, SStream *OS)
{
@ -20573,4 +20575,6 @@ static char *printAliasInstr(MCInst *MI, SStream *OS, void *info)
return tmp;
}
#endif
#endif // PRINT_ALIAS_INSTR

View File

@ -4575,6 +4575,8 @@ static char *getRegisterName(unsigned RegNo)
#ifdef PRINT_ALIAS_INSTR
#undef PRINT_ALIAS_INSTR
#ifndef CAPSTONE_DIET
static void printCustomAliasOperand(MCInst *MI, unsigned OpIdx,
unsigned PrintMethodIdx, SStream *OS)
{
@ -4646,4 +4648,6 @@ static char *printAliasInstr(MCInst *MI, SStream *OS, void *info)
return tmp;
}
#endif
#endif // PRINT_ALIAS_INSTR

View File

@ -720,11 +720,16 @@ static void printMemOffs64(MCInst *MI, unsigned OpNo, SStream *O)
printMemOffset(MI, OpNo, O);
}
#ifndef CAPSTONE_DIET
static char *printAliasInstr(MCInst *MI, SStream *OS, void *info);
#endif
static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI);
void X86_Intel_printInst(MCInst *MI, SStream *O, void *Info)
{
#ifndef CAPSTONE_DIET
char *mnem;
#endif
x86_reg reg, reg2;
enum cs_ac_type access1, access2;
@ -734,11 +739,13 @@ void X86_Intel_printInst(MCInst *MI, SStream *O, void *Info)
return;
}
#ifndef CAPSTONE_DIET
// Try to print any aliases first.
mnem = printAliasInstr(MI, O, Info);
if (mnem)
cs_mem_free(mnem);
else
#endif
printInstruction(MI, O, Info);
reg = X86_insn_reg_intel(MCInst_getOpcode(MI), &access1);

View File

@ -4,7 +4,9 @@
#ifdef CAPSTONE_HAS_X86
#include <string.h>
#ifndef CAPSTONE_HAS_OSXKERNEL
#include <stdlib.h>
#endif
#include "X86Mapping.h"
#include "X86DisassemblerDecoder.h"
@ -3128,6 +3130,7 @@ static bool valid_repne(cs_struct *h, unsigned int opcode)
// given MCInst's id, find out if this insn is valid for BND prefix
// BND prefix is valid for CALL/JMP/RET
#ifndef CAPSTONE_DIET
static bool valid_bnd(cs_struct *h, unsigned int opcode)
{
unsigned int id;
@ -3170,6 +3173,7 @@ static bool valid_bnd(cs_struct *h, unsigned int opcode)
// not found
return false;
}
#endif
// given MCInst's id, find out if this insn is valid for REP prefix
static bool valid_rep(cs_struct *h, unsigned int opcode)

16
cs.c
View File

@ -45,7 +45,11 @@
#endif
// default SKIPDATA mnemonic
#ifndef CAPSTONE_DIET
#define SKIPDATA_MNEM ".byte"
#else // No printing is available in diet mode
#define SKIPDATA_MNEM NULL
#endif
cs_err (*arch_init[MAX_ARCH])(cs_struct *) = { NULL };
cs_err (*arch_option[MAX_ARCH]) (cs_struct *, cs_opt_type, size_t value) = { NULL };
@ -552,6 +556,7 @@ cs_err CAPSTONE_API cs_option(csh ud, cs_opt_type type, size_t value)
}
// generate @op_str for data instruction of SKIPDATA
#ifndef CAPSTONE_DIET
static void skipdata_opstr(char *opstr, const uint8_t *buffer, size_t size)
{
char *p = opstr;
@ -580,6 +585,7 @@ static void skipdata_opstr(char *opstr, const uint8_t *buffer, size_t size)
available -= len;
}
}
#endif
// dynamicly allocate memory to contain disasm insn
// NOTE: caller must free() the allocated memory itself to avoid memory leaking
@ -708,9 +714,14 @@ size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64
insn_cache->address = offset;
insn_cache->size = (uint16_t)skipdata_bytes;
memcpy(insn_cache->bytes, buffer, skipdata_bytes);
#ifdef CAPSTONE_DIET
insn_cache->mnemonic[0] = '\0';
insn_cache->op_str[0] = '\0';
#else
strncpy(insn_cache->mnemonic, handle->skipdata_setup.mnemonic,
sizeof(insn_cache->mnemonic) - 1);
skipdata_opstr(insn_cache->op_str, buffer, skipdata_bytes);
#endif
insn_cache->detail = NULL;
next_offset = skipdata_bytes;
@ -912,10 +923,15 @@ bool CAPSTONE_API cs_disasm_iter(csh ud, const uint8_t **code, size_t *size,
insn->id = 0; // invalid ID for this "data" instruction
insn->address = *address;
insn->size = (uint16_t)skipdata_bytes;
#ifdef CAPSTONE_DIET
insn->mnemonic[0] = '\0';
insn->op_str[0] = '\0';
#else
memcpy(insn->bytes, *code, skipdata_bytes);
strncpy(insn->mnemonic, handle->skipdata_setup.mnemonic,
sizeof(insn->mnemonic) - 1);
skipdata_opstr(insn->op_str, *code, skipdata_bytes);
#endif
*code += skipdata_bytes;
*size -= skipdata_bytes;

View File

@ -30,9 +30,9 @@ extern "C" {
#endif
#else
#define CAPSTONE_API
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(CAPSTONE_STATIC)
#define CAPSTONE_EXPORT __attribute__((visibility("default")))
#else
#else // defined(CAPSTONE_STATIC)
#define CAPSTONE_EXPORT
#endif
#endif

View File

@ -62,6 +62,11 @@ typedef unsigned long long uint64_t;
#define UINT64_MAX 0xffffffffffffffffui64
#endif // defined(_MSC_VER) && (_MSC_VER <= 1700 || defined(_KERNEL_MODE))
#ifdef CAPSTONE_HAS_OSXKERNEL
// this system has stdint.h
#include <stdint.h>
#endif
#define __PRI_8_LENGTH_MODIFIER__ "hh"
#define __PRI_64_LENGTH_MODIFIER__ "ll"