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 }
getInstruction
void __stdcall getInstruction(cs_insn *insn, uint32_t index, void *curInst, uint32_t bufSize)
Definition: vbCapstone.cpp:60
cs_op_index
CAPSTONE_EXPORT int CAPSTONE_API cs_op_index(csh ud, const cs_insn *insn, unsigned int op_type, unsigned int post)
Definition: cs.c:1396
cs_close
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_close(csh *handle)
Definition: cs.c:522
cs_opt_type
cs_opt_type
Runtime option for the disassembled engine.
Definition: capstone.h:169
bs_support
bool __stdcall bs_support(int query)
Definition: vbCapstone.cpp:25
position
intern position
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/array.c:487
cs_disasm
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:822
string.h
bs_errno
cs_err __stdcall bs_errno(csh handle)
Definition: vbCapstone.cpp:45
cs_open
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_open(cs_arch arch, cs_mode mode, csh *handle)
Definition: cs.c:474
bs_insn_name
const char *__stdcall bs_insn_name(csh handle, unsigned int insn_id)
Definition: vbCapstone.cpp:111
cs_arch
cs_arch
Architecture type.
Definition: capstone.h:74
bs_disasm_iter
bool __stdcall bs_disasm_iter(csh handle, const uint8_t **code, size_t *size, uint64_t *address, cs_insn *insn)
Definition: vbCapstone.cpp:116
mode
const char int mode
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:135
cs_reg_write
CAPSTONE_EXPORT bool CAPSTONE_API cs_reg_write(csh ud, const cs_insn *insn, unsigned int reg_id)
Definition: cs.c:1266
bs_free
void __stdcall bs_free(cs_insn *insn, size_t count)
Definition: vbCapstone.cpp:70
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
cs_option
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_option(csh ud, cs_opt_type type, size_t value)
Definition: cs.c:670
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
cs_mode
cs_mode
Mode type.
Definition: capstone.h:103
cs_op_count
CAPSTONE_EXPORT int CAPSTONE_API cs_op_count(csh ud, const cs_insn *insn, unsigned int op_type)
Definition: cs.c:1293
capstone.h
query
Definition: ares_private.h:198
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
cs_insn_name
const CAPSTONE_EXPORT char *CAPSTONE_API cs_insn_name(csh ud, unsigned int insn)
Definition: cs.c:1188
bs_disasm
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
cs_reg_name
const CAPSTONE_EXPORT char *CAPSTONE_API cs_reg_name(csh ud, unsigned int reg)
Definition: cs.c:1176
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
cs_support
CAPSTONE_EXPORT bool CAPSTONE_API cs_support(int query)
Definition: cs.c:388
bs_strerror
const char *__stdcall bs_strerror(cs_err code)
Definition: vbCapstone.cpp:50
bs_reg_write
bool __stdcall bs_reg_write(csh handle, const cs_insn *insn, unsigned int reg_id)
Definition: vbCapstone.cpp:91
arch
cs_arch arch
Definition: cstool.c:13
bs_op_index
int __stdcall bs_op_index(csh handle, const cs_insn *insn, unsigned int op_type, unsigned int position)
Definition: vbCapstone.cpp:81
value
const char * value
Definition: hpack_parser_table.cc:165
csh
size_t csh
Definition: capstone.h:71
bs_reg_name
const char *__stdcall bs_reg_name(csh handle, unsigned int reg_id)
Definition: vbCapstone.cpp:65
bcs_group_name
const char *__stdcall bcs_group_name(csh handle, unsigned int group_id)
Definition: vbCapstone.cpp:106
cs_disasm_iter
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:1080
bs_option
cs_err __stdcall bs_option(csh handle, cs_opt_type type, size_t value)
Definition: vbCapstone.cpp:40
count
int * count
Definition: bloaty/third_party/googletest/googlemock/test/gmock_stress_test.cc:96
cs_strerror
const CAPSTONE_EXPORT char *CAPSTONE_API cs_strerror(cs_err code)
Definition: cs.c:435
bs_reg_read
bool __stdcall bs_reg_read(csh handle, const cs_insn *insn, unsigned int reg_id)
Definition: vbCapstone.cpp:96
bs_close
cs_err __stdcall bs_close(csh *handle)
Definition: vbCapstone.cpp:35
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
cs_group_name
const CAPSTONE_EXPORT char *CAPSTONE_API cs_group_name(csh ud, unsigned int group)
Definition: cs.c:1200
bs_insn_group
bool __stdcall bs_insn_group(csh handle, const cs_insn *insn, unsigned int group_id)
Definition: vbCapstone.cpp:101
cs_malloc
CAPSTONE_EXPORT cs_insn *CAPSTONE_API cs_malloc(csh ud)
Definition: cs.c:1052
bs_open
cs_err __stdcall bs_open(cs_arch arch, cs_mode mode, csh *handle)
Definition: vbCapstone.cpp:30
cs_free
CAPSTONE_EXPORT void CAPSTONE_API cs_free(cs_insn *insn, size_t count)
Definition: cs.c:1039
bs_op_count
int __stdcall bs_op_count(csh handle, const cs_insn *insn, unsigned int op_type)
Definition: vbCapstone.cpp:86
handle
static csh handle
Definition: test_arm_regression.c:16
bs_malloc
cs_insn *__stdcall bs_malloc(csh handle)
Definition: vbCapstone.cpp:75
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
code
Definition: bloaty/third_party/zlib/contrib/infback9/inftree9.h:24
cs_insn_group
CAPSTONE_EXPORT bool CAPSTONE_API cs_insn_group(csh ud, const cs_insn *insn, unsigned int group_id)
Definition: cs.c:1212
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
bs_version
unsigned int __stdcall bs_version(int *major, int *minor)
Definition: vbCapstone.cpp:20
cs_version
CAPSTONE_EXPORT unsigned int CAPSTONE_API cs_version(int *major, int *minor)
Definition: cs.c:377
cs_reg_read
CAPSTONE_EXPORT bool CAPSTONE_API cs_reg_read(csh ud, const cs_insn *insn, unsigned int reg_id)
Definition: cs.c:1239
cs_errno
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_errno(csh handle)
Definition: cs.c:423


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:50