Rizin
unix-like reverse engineering framework and cli tools
vbCapstone.cpp
Go to the documentation of this file.
1 /*
2  Capstone Disassembly Engine bindings for VB6
3  Contributed by FireEye FLARE Team
4  Author: David Zimmer <david.zimmer@fireeye.com>, <dzzie@yahoo.com>
5  License: Apache
6  Copyright: FireEye 2017
7 
8  This dll is a small stdcall shim so VB6 can access the capstone API
9 */
10 
11 #include <stdio.h>
12 #include <conio.h>
13 #include <string.h>
14 
15 #include <capstone.h>
16 #pragma comment(lib, "capstone.lib")
17 
18 #define EXPORT comment(linker, "/EXPORT:"__FUNCTION__"="__FUNCDNAME__)
19 
20 unsigned int __stdcall bs_version(int *major, int *minor){
21 #pragma EXPORT
22  return cs_version(major,minor);
23 }
24 
25 bool __stdcall bs_support(int query){
26 #pragma EXPORT
27  return cs_support(query);
28 }
29 
30 cs_err __stdcall bs_open(cs_arch arch, cs_mode mode, csh *handle){
31 #pragma EXPORT
32  return cs_open(arch, mode, handle);
33 }
34 
35 cs_err __stdcall bs_close(csh *handle){
36 #pragma EXPORT
37  return cs_close(handle);
38 }
39 
40 cs_err __stdcall bs_option(csh handle, cs_opt_type type, size_t value){
41 #pragma EXPORT
42  return cs_option(handle, type, value);
43 }
44 
45 cs_err __stdcall bs_errno(csh handle){
46 #pragma EXPORT
47  return cs_errno(handle);
48 }
49 
50 const char* __stdcall bs_strerror(cs_err code){
51 #pragma EXPORT
52  return cs_strerror(code);
53 }
54 
55 size_t __stdcall bs_disasm(csh handle, const uint8_t *code, size_t code_size, uint64_t address, size_t count, cs_insn **insn){
56 #pragma EXPORT
57  return cs_disasm(handle, code, code_size, address, count, insn);
58 }
59 
60 void __stdcall getInstruction(cs_insn *insn, uint32_t index, void* curInst, uint32_t bufSize){
61 #pragma EXPORT
62  memcpy(curInst, (void*)&insn[index], bufSize); //size lets us get a partial version of whatever we have implemented in the vbstruct...
63 }
64 
65 const char* __stdcall bs_reg_name(csh handle, unsigned int reg_id){
66 #pragma EXPORT
67  return cs_reg_name(handle, reg_id);
68 }
69 
70 void __stdcall bs_free(cs_insn *insn, size_t count){
71 #pragma EXPORT
72  return cs_free(insn, count);
73 }
74 
75 cs_insn* __stdcall bs_malloc(csh handle){
76 #pragma EXPORT
77  return cs_malloc(handle);
78 }
79 
80 
81 int __stdcall bs_op_index(csh handle, const cs_insn *insn, unsigned int op_type, unsigned int position){
82 #pragma EXPORT
83  return cs_op_index(handle,insn,op_type,position);
84 }
85 
86 int __stdcall bs_op_count(csh handle, const cs_insn *insn, unsigned int op_type){
87 #pragma EXPORT
88  return cs_op_count(handle,insn,op_type);
89 }
90 
91 bool __stdcall bs_reg_write(csh handle, const cs_insn *insn, unsigned int reg_id){
92 #pragma EXPORT
93  return cs_reg_write(handle,insn,reg_id);
94 }
95 
96 bool __stdcall bs_reg_read(csh handle, const cs_insn *insn, unsigned int reg_id){
97 #pragma EXPORT
98  return cs_reg_read(handle,insn,reg_id);
99 }
100 
101 bool __stdcall bs_insn_group(csh handle, const cs_insn *insn, unsigned int group_id){
102 #pragma EXPORT
103  return cs_insn_group(handle,insn,group_id);
104 }
105 
106 const char* __stdcall bcs_group_name(csh handle, unsigned int group_id){
107 #pragma EXPORT
108  return cs_group_name(handle,group_id);
109 }
110 
111 const char* __stdcall bs_insn_name(csh handle, unsigned int insn_id){
112 #pragma EXPORT
113  return cs_insn_name(handle,insn_id);
114 }
115 
116 bool __stdcall bs_disasm_iter(csh handle, const uint8_t **code, size_t *size, uint64_t *address, cs_insn *insn){
117 #pragma EXPORT
118  return cs_disasm_iter(handle, code, size, address, insn);
119 }
static mcore_handle handle
Definition: asm_mcore.c:8
cs_arch
Architecture type.
Definition: capstone.h:74
cs_mode
Mode type.
Definition: capstone.h:102
cs_opt_type
Runtime option for the disassembled engine.
Definition: capstone.h:168
size_t csh
Definition: capstone.h:71
static int value
Definition: cmd_api.c:93
CAPSTONE_EXPORT unsigned int CAPSTONE_API cs_version(int *major, int *minor)
Definition: cs.c:357
CAPSTONE_EXPORT bool CAPSTONE_API cs_support(int query)
Definition: cs.c:368
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_errno(csh handle)
Definition: cs.c:402
CAPSTONE_EXPORT size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64_t offset, size_t count, cs_insn **insn)
Definition: cs.c:798
CAPSTONE_EXPORT const char *CAPSTONE_API cs_group_name(csh ud, unsigned int group)
Definition: cs.c:1178
CAPSTONE_EXPORT bool CAPSTONE_API cs_reg_read(csh ud, const cs_insn *insn, unsigned int reg_id)
Definition: cs.c:1217
CAPSTONE_EXPORT const char *CAPSTONE_API cs_strerror(cs_err code)
Definition: cs.c:414
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_open(cs_arch arch, cs_mode mode, csh *handle)
Definition: cs.c:453
CAPSTONE_EXPORT bool CAPSTONE_API cs_insn_group(csh ud, const cs_insn *insn, unsigned int group_id)
Definition: cs.c:1190
CAPSTONE_EXPORT int CAPSTONE_API cs_op_count(csh ud, const cs_insn *insn, unsigned int op_type)
Definition: cs.c:1271
CAPSTONE_EXPORT const char *CAPSTONE_API cs_insn_name(csh ud, unsigned int insn)
Definition: cs.c:1166
CAPSTONE_EXPORT void CAPSTONE_API cs_free(cs_insn *insn, size_t count)
Definition: cs.c:1017
CAPSTONE_EXPORT const char *CAPSTONE_API cs_reg_name(csh ud, unsigned int reg)
Definition: cs.c:1154
CAPSTONE_EXPORT bool CAPSTONE_API cs_reg_write(csh ud, const cs_insn *insn, unsigned int reg_id)
Definition: cs.c:1244
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_close(csh *handle)
Definition: cs.c:501
CAPSTONE_EXPORT int CAPSTONE_API cs_op_index(csh ud, const cs_insn *insn, unsigned int op_type, unsigned int post)
Definition: cs.c:1369
CAPSTONE_EXPORT cs_insn *CAPSTONE_API cs_malloc(csh ud)
Definition: cs.c:1030
CAPSTONE_EXPORT bool CAPSTONE_API cs_disasm_iter(csh ud, const uint8_t **code, size_t *size, uint64_t *address, cs_insn *insn)
Definition: cs.c:1058
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_option(csh ud, cs_opt_type type, size_t value)
Definition: cs.c:646
cs_arch arch
Definition: cstool.c:13
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
#define minor(dev)
Definition: fsmagic.c:57
#define major(dev)
Definition: fsmagic.c:56
voidpf void uLong size
Definition: ioapi.h:138
const char int mode
Definition: ioapi.h:137
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
int type
Definition: mipsasm.c:17
unsigned int uint32_t
Definition: sftypes.h:29
unsigned long uint64_t
Definition: sftypes.h:28
unsigned char uint8_t
Definition: sftypes.h:31
Definition: inftree9.h:24
const char *__stdcall bs_strerror(cs_err code)
Definition: vbCapstone.cpp:50
bool __stdcall bs_reg_write(csh handle, const cs_insn *insn, unsigned int reg_id)
Definition: vbCapstone.cpp:91
bool __stdcall bs_insn_group(csh handle, const cs_insn *insn, unsigned int group_id)
Definition: vbCapstone.cpp:101
const char *__stdcall bcs_group_name(csh handle, unsigned int group_id)
Definition: vbCapstone.cpp:106
cs_insn *__stdcall bs_malloc(csh handle)
Definition: vbCapstone.cpp:75
bool __stdcall bs_support(int query)
Definition: vbCapstone.cpp:25
const char *__stdcall bs_insn_name(csh handle, unsigned int insn_id)
Definition: vbCapstone.cpp:111
const char *__stdcall bs_reg_name(csh handle, unsigned int reg_id)
Definition: vbCapstone.cpp:65
int __stdcall bs_op_index(csh handle, const cs_insn *insn, unsigned int op_type, unsigned int position)
Definition: vbCapstone.cpp:81
unsigned int __stdcall bs_version(int *major, int *minor)
Definition: vbCapstone.cpp:20
cs_err __stdcall bs_close(csh *handle)
Definition: vbCapstone.cpp:35
cs_err __stdcall bs_option(csh handle, cs_opt_type type, size_t value)
Definition: vbCapstone.cpp:40
void __stdcall bs_free(cs_insn *insn, size_t count)
Definition: vbCapstone.cpp:70
size_t __stdcall bs_disasm(csh handle, const uint8_t *code, size_t code_size, uint64_t address, size_t count, cs_insn **insn)
Definition: vbCapstone.cpp:55
void __stdcall getInstruction(cs_insn *insn, uint32_t index, void *curInst, uint32_t bufSize)
Definition: vbCapstone.cpp:60
int __stdcall bs_op_count(csh handle, const cs_insn *insn, unsigned int op_type)
Definition: vbCapstone.cpp:86
bool __stdcall bs_disasm_iter(csh handle, const uint8_t **code, size_t *size, uint64_t *address, cs_insn *insn)
Definition: vbCapstone.cpp:116
bool __stdcall bs_reg_read(csh handle, const cs_insn *insn, unsigned int reg_id)
Definition: vbCapstone.cpp:96
cs_err __stdcall bs_errno(csh handle)
Definition: vbCapstone.cpp:45
cs_err __stdcall bs_open(cs_arch arch, cs_mode mode, csh *handle)
Definition: vbCapstone.cpp:30