|
|
@ -1,4 +1,4 @@ |
|
|
|
/* Tang Yuhang <1648200150@qq.com> 2016 */ |
|
|
|
/* Tang Yuhang <tyh000011112222@gmail.com> 2016 */ |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdio.h> |
|
|
|
#include <inttypes.h> |
|
|
|
#include <inttypes.h> |
|
|
|
#include <string.h> |
|
|
|
#include <string.h> |
|
|
@ -7,7 +7,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include <capstone.h> |
|
|
|
#include <capstone.h> |
|
|
|
|
|
|
|
|
|
|
|
#define VERSION "1.0" |
|
|
|
#define VERSION "2.0" |
|
|
|
|
|
|
|
|
|
|
|
void print_insn_detail_x86(csh ud, cs_mode mode, cs_insn *ins); |
|
|
|
void print_insn_detail_x86(csh ud, cs_mode mode, cs_insn *ins); |
|
|
|
void print_insn_detail_arm(csh handle, cs_insn *ins); |
|
|
|
void print_insn_detail_arm(csh handle, cs_insn *ins); |
|
|
@ -22,7 +22,7 @@ void print_insn_detail_xcore(csh handle, cs_insn *ins); |
|
|
|
static uint8_t char_to_hexnum(char c) |
|
|
|
static uint8_t char_to_hexnum(char c) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (c >= '0' && c <= '9') { |
|
|
|
if (c >= '0' && c <= '9') { |
|
|
|
return (uint8_t)(c - '0'); |
|
|
|
return (uint8_t)(c - '0'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (c >= 'a' && c <= 'f') { |
|
|
|
if (c >= 'a' && c <= 'f') { |
|
|
@ -37,7 +37,7 @@ static uint8_t char_to_hexnum(char c) |
|
|
|
// valid hexadecimal, and return actual length of uint8_t[] in @size.
|
|
|
|
// valid hexadecimal, and return actual length of uint8_t[] in @size.
|
|
|
|
static uint8_t *preprocess(char *code, size_t *size) |
|
|
|
static uint8_t *preprocess(char *code, size_t *size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
size_t i = 0, j = 0; |
|
|
|
size_t i = 0, j = 0; |
|
|
|
uint8_t high, low; |
|
|
|
uint8_t high, low; |
|
|
|
uint8_t *result; |
|
|
|
uint8_t *result; |
|
|
|
|
|
|
|
|
|
|
@ -174,17 +174,17 @@ int main(int argc, char **argv) |
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(mode, "arm")) { |
|
|
|
if (!strcmp(mode, "arm")) { |
|
|
|
arch = "arm"; |
|
|
|
arch = "arm"; |
|
|
|
err = cs_open(CS_ARCH_ARM, CS_MODE_ARM, &handle); |
|
|
|
err = cs_open(CS_ARCH_ARM, CS_MODE_ARM, &handle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(mode, "armb")) { |
|
|
|
if (!strcmp(mode, "armb")) { |
|
|
|
arch = "arm"; |
|
|
|
arch = "arm"; |
|
|
|
err = cs_open(CS_ARCH_ARM, CS_MODE_ARM + CS_MODE_BIG_ENDIAN, &handle); |
|
|
|
err = cs_open(CS_ARCH_ARM, CS_MODE_ARM + CS_MODE_BIG_ENDIAN, &handle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(mode, "arml")) { |
|
|
|
if (!strcmp(mode, "arml")) { |
|
|
|
arch = "arm"; |
|
|
|
arch = "arm"; |
|
|
|
err = cs_open(CS_ARCH_ARM, CS_MODE_ARM + CS_MODE_LITTLE_ENDIAN, &handle); |
|
|
|
err = cs_open(CS_ARCH_ARM, CS_MODE_ARM + CS_MODE_LITTLE_ENDIAN, &handle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(mode, "thumb")) { |
|
|
|
if (!strcmp(mode, "thumb")) { |
|
|
@ -194,49 +194,49 @@ int main(int argc, char **argv) |
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(mode, "thumbbe")) { |
|
|
|
if (!strcmp(mode, "thumbbe")) { |
|
|
|
arch = "arm"; |
|
|
|
arch = "arm"; |
|
|
|
err = cs_open(CS_ARCH_ARM, CS_MODE_THUMB + CS_MODE_BIG_ENDIAN, &handle); |
|
|
|
err = cs_open(CS_ARCH_ARM, CS_MODE_THUMB + CS_MODE_BIG_ENDIAN, &handle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(mode, "thumble")) { |
|
|
|
if (!strcmp(mode, "thumble")) { |
|
|
|
arch = "arm"; |
|
|
|
arch = "arm"; |
|
|
|
err = cs_open(CS_ARCH_ARM, CS_MODE_ARM + CS_MODE_LITTLE_ENDIAN, &handle); |
|
|
|
err = cs_open(CS_ARCH_ARM, CS_MODE_ARM + CS_MODE_LITTLE_ENDIAN, &handle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(mode, "arm64")) { |
|
|
|
if (!strcmp(mode, "arm64")) { |
|
|
|
arch = "arm64"; |
|
|
|
arch = "arm64"; |
|
|
|
err = cs_open(CS_ARCH_ARM64, CS_MODE_LITTLE_ENDIAN, &handle); |
|
|
|
err = cs_open(CS_ARCH_ARM64, CS_MODE_LITTLE_ENDIAN, &handle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(mode, "mips")) { |
|
|
|
if (!strcmp(mode, "mips")) { |
|
|
|
arch = "mips"; |
|
|
|
arch = "mips"; |
|
|
|
err = cs_open(CS_ARCH_MIPS, CS_MODE_MIPS32 + CS_MODE_LITTLE_ENDIAN, &handle); |
|
|
|
err = cs_open(CS_ARCH_MIPS, CS_MODE_MIPS32 + CS_MODE_LITTLE_ENDIAN, &handle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(mode, "mipsbe")) { |
|
|
|
if (!strcmp(mode, "mipsbe")) { |
|
|
|
arch = "mips"; |
|
|
|
arch = "mips"; |
|
|
|
err = cs_open(CS_ARCH_MIPS, CS_MODE_MIPS32 + CS_MODE_BIG_ENDIAN, &handle); |
|
|
|
err = cs_open(CS_ARCH_MIPS, CS_MODE_MIPS32 + CS_MODE_BIG_ENDIAN, &handle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(mode, "mips64")) { |
|
|
|
if (!strcmp(mode, "mips64")) { |
|
|
|
arch = "mips"; |
|
|
|
arch = "mips"; |
|
|
|
err = cs_open(CS_ARCH_MIPS, CS_MODE_MIPS64 + CS_MODE_BIG_ENDIAN, &handle); |
|
|
|
err = cs_open(CS_ARCH_MIPS, CS_MODE_MIPS64 + CS_MODE_BIG_ENDIAN, &handle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(mode, "mips64be")) { |
|
|
|
if (!strcmp(mode, "mips64be")) { |
|
|
|
arch = "mips"; |
|
|
|
arch = "mips"; |
|
|
|
err = cs_open(CS_ARCH_MIPS, CS_MODE_MIPS64 + CS_MODE_BIG_ENDIAN, &handle); |
|
|
|
err = cs_open(CS_ARCH_MIPS, CS_MODE_MIPS64 + CS_MODE_BIG_ENDIAN, &handle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(mode, "x16")) { |
|
|
|
if (!strcmp(mode, "x16")) { |
|
|
|
md = CS_MODE_64; |
|
|
|
md = CS_MODE_16; |
|
|
|
arch = "x86"; |
|
|
|
arch = "x86"; |
|
|
|
err = cs_open(CS_ARCH_X86, CS_MODE_16, &handle); |
|
|
|
err = cs_open(CS_ARCH_X86, CS_MODE_16, &handle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(mode, "x32")) { |
|
|
|
if (!strcmp(mode, "x32")) { |
|
|
|
md = CS_MODE_32; |
|
|
|
md = CS_MODE_32; |
|
|
|
arch = "x86"; |
|
|
|
arch = "x86"; |
|
|
|
err = cs_open(CS_ARCH_X86, CS_MODE_32, &handle); |
|
|
|
err = cs_open(CS_ARCH_X86, CS_MODE_32, &handle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(mode, "x64")) { |
|
|
|
if (!strcmp(mode, "x64")) { |
|
|
@ -248,9 +248,9 @@ int main(int argc, char **argv) |
|
|
|
if (!strcmp(mode, "x16att")) { |
|
|
|
if (!strcmp(mode, "x16att")) { |
|
|
|
md = CS_MODE_16; |
|
|
|
md = CS_MODE_16; |
|
|
|
arch = "x86"; |
|
|
|
arch = "x86"; |
|
|
|
err = cs_open(CS_ARCH_X86, CS_MODE_16, &handle); |
|
|
|
err = cs_open(CS_ARCH_X86, CS_MODE_16, &handle); |
|
|
|
if (!err) { |
|
|
|
if (!err) { |
|
|
|
cs_option(handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_ATT); |
|
|
|
cs_option(handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_ATT); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -278,8 +278,8 @@ int main(int argc, char **argv) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(mode,"ppc64be")) { |
|
|
|
if (!strcmp(mode,"ppc64be")) { |
|
|
|
arch = "ppc"; |
|
|
|
arch = "ppc"; |
|
|
|
err = cs_open(CS_ARCH_PPC,CS_MODE_64+CS_MODE_BIG_ENDIAN, &handle); |
|
|
|
err = cs_open(CS_ARCH_PPC,CS_MODE_64+CS_MODE_BIG_ENDIAN, &handle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(mode,"sparc")) { |
|
|
|
if (!strcmp(mode,"sparc")) { |
|
|
|