rename API cs_disasm_dyn() to cs_disasm_ex(), and intentionally breaks compatibility with 1.0
This commit is contained in:
parent
b8f2af6317
commit
04c19beefe
2
cs.c
2
cs.c
|
@ -181,7 +181,7 @@ cs_err cs_option(csh ud, cs_opt_type type, size_t value)
|
|||
|
||||
// dynamicly allocate memory to contain disasm insn
|
||||
// NOTE: caller must free() the allocated memory itself to avoid memory leaking
|
||||
size_t cs_disasm_dyn(csh ud, const uint8_t *buffer, size_t size, uint64_t offset, size_t count, cs_insn **insn)
|
||||
size_t cs_disasm_ex(csh ud, const uint8_t *buffer, size_t size, uint64_t offset, size_t count, cs_insn **insn)
|
||||
{
|
||||
cs_struct *handle = (cs_struct *)(uintptr_t)ud;
|
||||
MCInst mci;
|
||||
|
|
|
@ -132,7 +132,7 @@ typedef struct cs_insn {
|
|||
// These are values returned by cs_errno()
|
||||
typedef enum cs_err {
|
||||
CS_ERR_OK = 0, // No error: everything was fine
|
||||
CS_ERR_MEM, // Out-Of-Memory error: cs_open(), cs_disasm_dyn()
|
||||
CS_ERR_MEM, // Out-Of-Memory error: cs_open(), cs_disasm_ex()
|
||||
CS_ERR_ARCH, // Unsupported architecture: cs_open()
|
||||
CS_ERR_HANDLE, // Invalid handle: cs_op_count(), cs_op_index()
|
||||
CS_ERR_CSH, // Invalid csh argument: cs_close(), cs_errno(), cs_option()
|
||||
|
@ -223,31 +223,6 @@ cs_err cs_option(csh handle, cs_opt_type type, size_t value);
|
|||
*/
|
||||
cs_err cs_errno(csh handle);
|
||||
|
||||
/*
|
||||
Disasm the binary code in @buffer.
|
||||
Disassembled instructions will be put into @insn
|
||||
NOTE: this API requires the pre-allocated buffer in @insn
|
||||
|
||||
@handle: handle returned by cs_open()
|
||||
@code: buffer containing raw binary code to be disassembled
|
||||
@code_size: size of above code
|
||||
@address: address of the first insn in given raw code buffer
|
||||
@insn: array of insn filled in by this function
|
||||
NOTE: @insn size must be at least @count to avoid buffer overflow
|
||||
@count: number of instrutions to be disassembled, or 0 to get all of them
|
||||
@return: the number of succesfully disassembled instructions,
|
||||
or 0 if this function failed to disassemble the given code
|
||||
|
||||
NOTE: this API does not provide detail information, meaning @detail = NULL
|
||||
|
||||
On failure, call cs_errno() for error code.
|
||||
*/
|
||||
size_t cs_disasm(csh handle,
|
||||
const uint8_t *code, size_t code_size,
|
||||
uint64_t address,
|
||||
size_t count,
|
||||
cs_insn *insn);
|
||||
|
||||
/*
|
||||
Dynamicly allocate memory to contain disasm insn
|
||||
Disassembled instructions will be put into @*insn
|
||||
|
@ -269,17 +244,17 @@ size_t cs_disasm(csh handle,
|
|||
|
||||
On failure, call cs_errno() for error code.
|
||||
*/
|
||||
size_t cs_disasm_dyn(csh handle,
|
||||
size_t cs_disasm_ex(csh handle,
|
||||
const uint8_t *code, size_t code_size,
|
||||
uint64_t address,
|
||||
size_t count,
|
||||
cs_insn **insn);
|
||||
|
||||
/*
|
||||
Free memory allocated in @insn by cs_disasm_dyn()
|
||||
Free memory allocated in @insn by cs_disasm_ex()
|
||||
|
||||
@insn: pointer returned by @insn argument in cs_disasm_dyn()
|
||||
@count: number of cs_insn structures returned by cs_disasm_dyn()
|
||||
@insn: pointer returned by @insn argument in cs_disasm_ex()
|
||||
@count: number of cs_insn structures returned by cs_disasm_ex()
|
||||
*/
|
||||
void cs_free(cs_insn *insn, size_t count);
|
||||
|
||||
|
@ -310,7 +285,7 @@ const char *cs_insn_name(csh handle, unsigned int insn_id);
|
|||
Internally, this simply verifies if @group_id matches any member of insn->groups array.
|
||||
|
||||
@handle: handle returned by cs_open()
|
||||
@insn: disassembled instruction structure received from cs_disasm() or cs_disasm_dyn()
|
||||
@insn: disassembled instruction structure received from cs_disasm() or cs_disasm_ex()
|
||||
@group_id: group that you want to check if this instruction belong to.
|
||||
|
||||
@return: true if this instruction indeed belongs to aboved group, or false otherwise.
|
||||
|
@ -322,7 +297,7 @@ bool cs_insn_group(csh handle, cs_insn *insn, unsigned int group_id);
|
|||
Find the register id from header file of corresponding architecture (arm.h for ARM, x86.h for X86, ...)
|
||||
Internally, this simply verifies if @reg_id matches any member of insn->regs_read array.
|
||||
|
||||
@insn: disassembled instruction structure received from cs_disasm() or cs_disasm_dyn()
|
||||
@insn: disassembled instruction structure received from cs_disasm() or cs_disasm_ex()
|
||||
@reg_id: register that you want to check if this instruction used it.
|
||||
|
||||
@return: true if this instruction indeed implicitly used aboved register, or false otherwise.
|
||||
|
@ -334,7 +309,7 @@ bool cs_reg_read(csh handle, cs_insn *insn, unsigned int reg_id);
|
|||
Find the register id from header file of corresponding architecture (arm.h for ARM, x86.h for X86, ...)
|
||||
Internally, this simply verifies if @reg_id matches any member of insn->regs_write array.
|
||||
|
||||
@insn: disassembled instruction structure received from cs_disasm() or cs_disasm_dyn()
|
||||
@insn: disassembled instruction structure received from cs_disasm() or cs_disasm_ex()
|
||||
@reg_id: register that you want to check if this instruction modified it.
|
||||
|
||||
@return: true if this instruction indeed implicitly modified aboved register, or false otherwise.
|
||||
|
@ -346,7 +321,7 @@ bool cs_reg_write(csh handle, cs_insn *insn, unsigned int reg_id);
|
|||
Find the operand type in header file of corresponding architecture (arm.h for ARM, x86.h for X86, ...)
|
||||
|
||||
@handle: handle returned by cs_open()
|
||||
@insn: disassembled instruction structure received from cs_disasm() or cs_disasm_dyn()
|
||||
@insn: disassembled instruction structure received from cs_disasm() or cs_disasm_ex()
|
||||
@op_type: Operand type to be found.
|
||||
|
||||
@return: number of operands of given type @op_type in instruction @insn,
|
||||
|
@ -360,7 +335,7 @@ int cs_op_count(csh handle, cs_insn *insn, unsigned int op_type);
|
|||
Find the operand type in header file of corresponding architecture (arm.h for ARM, x86.h for X86, ...)
|
||||
|
||||
@handle: handle returned by cs_open()
|
||||
@insn: disassembled instruction structure received from cs_disasm() or cs_disasm_dyn()
|
||||
@insn: disassembled instruction structure received from cs_disasm() or cs_disasm_ex()
|
||||
@op_type: Operand type to be found.
|
||||
@position: position of the operand to be found. This must be in the range
|
||||
[1, cs_op_count(handle, insn, op_type)]
|
||||
|
|
|
@ -131,7 +131,6 @@ static void test()
|
|||
|
||||
csh handle;
|
||||
uint64_t address = 0x1000;
|
||||
//cs_insn insn[16];
|
||||
cs_insn *insn;
|
||||
int i;
|
||||
|
||||
|
@ -147,8 +146,7 @@ static void test()
|
|||
|
||||
//cs_option(handle, CS_OPT_DETAIL, CS_OPT_OFF);
|
||||
|
||||
//size_t count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, insn);
|
||||
size_t count = cs_disasm_dyn(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
|
||||
size_t count = cs_disasm_ex(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
|
||||
if (count) {
|
||||
printf("****************\n");
|
||||
printf("Platform: %s\n", platforms[i].comment);
|
||||
|
@ -165,7 +163,7 @@ static void test()
|
|||
// print out the next offset, after the last insn
|
||||
printf("0x%"PRIx64":\n", insn[j-1].address + insn[j-1].size);
|
||||
|
||||
// free memory allocated by cs_disasm_dyn()
|
||||
// free memory allocated by cs_disasm_ex()
|
||||
cs_free(insn, count);
|
||||
} else {
|
||||
printf("****************\n");
|
||||
|
|
|
@ -196,7 +196,7 @@ static void test()
|
|||
if (cs_open(platforms[i].arch, platforms[i].mode, &handle))
|
||||
return;
|
||||
|
||||
size_t count = cs_disasm_dyn(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
|
||||
size_t count = cs_disasm_ex(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
|
||||
if (count) {
|
||||
printf("****************\n");
|
||||
printf("Platform: %s\n", platforms[i].comment);
|
||||
|
@ -210,7 +210,7 @@ static void test()
|
|||
}
|
||||
printf("0x%"PRIx64":\n", insn[j-1].address + insn[j-1].size);
|
||||
|
||||
// free memory allocated by cs_disasm_dyn()
|
||||
// free memory allocated by cs_disasm_ex()
|
||||
cs_free(insn, count);
|
||||
} else {
|
||||
printf("****************\n");
|
||||
|
|
|
@ -147,7 +147,6 @@ static void test()
|
|||
};
|
||||
|
||||
uint64_t address = 0x2c;
|
||||
//cs_insn insn[16];
|
||||
cs_insn *insn;
|
||||
int i;
|
||||
|
||||
|
@ -155,8 +154,7 @@ static void test()
|
|||
if (cs_open(platforms[i].arch, platforms[i].mode, &handle))
|
||||
return;
|
||||
|
||||
//size_t count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, insn);
|
||||
size_t count = cs_disasm_dyn(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
|
||||
size_t count = cs_disasm_ex(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
|
||||
if (count) {
|
||||
printf("****************\n");
|
||||
printf("Platform: %s\n", platforms[i].comment);
|
||||
|
@ -170,7 +168,7 @@ static void test()
|
|||
}
|
||||
printf("0x%"PRIx64":\n", insn[j-1].address + insn[j-1].size);
|
||||
|
||||
// free memory allocated by cs_disasm_dyn()
|
||||
// free memory allocated by cs_disasm_ex()
|
||||
cs_free(insn, count);
|
||||
} else {
|
||||
printf("****************\n");
|
||||
|
|
|
@ -137,7 +137,6 @@ static void test()
|
|||
|
||||
csh handle;
|
||||
uint64_t address = 0x1000;
|
||||
//cs_insn all_insn[16];
|
||||
cs_insn *all_insn;
|
||||
int i;
|
||||
|
||||
|
@ -150,8 +149,7 @@ static void test()
|
|||
|
||||
//cs_option(handle, CS_OPT_DETAIL, CS_OPT_OFF);
|
||||
|
||||
//size_t count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, all_insn);
|
||||
size_t count = cs_disasm_dyn(handle, platforms[i].code, platforms[i].size, address, 0, &all_insn);
|
||||
size_t count = cs_disasm_ex(handle, platforms[i].code, platforms[i].size, address, 0, &all_insn);
|
||||
if (count) {
|
||||
printf("****************\n");
|
||||
printf("Platform: %s\n", platforms[i].comment);
|
||||
|
@ -197,7 +195,7 @@ static void test()
|
|||
// print out the next offset, after the last insn
|
||||
printf("0x%"PRIx64":\n", all_insn[j-1].address + all_insn[j-1].size);
|
||||
|
||||
// free memory allocated by cs_disasm_dyn()
|
||||
// free memory allocated by cs_disasm_ex()
|
||||
cs_free(all_insn, count);
|
||||
} else {
|
||||
printf("****************\n");
|
||||
|
|
|
@ -101,7 +101,7 @@ static void test()
|
|||
if (cs_open(platforms[i].arch, platforms[i].mode, &handle))
|
||||
return;
|
||||
|
||||
size_t count = cs_disasm_dyn(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
|
||||
size_t count = cs_disasm_ex(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
|
||||
if (count) {
|
||||
printf("****************\n");
|
||||
printf("Platform: %s\n", platforms[i].comment);
|
||||
|
@ -115,7 +115,7 @@ static void test()
|
|||
}
|
||||
printf("0x%"PRIx64":\n", insn[j-1].address + insn[j-1].size);
|
||||
|
||||
// free memory allocated by cs_disasm_dyn()
|
||||
// free memory allocated by cs_disasm_ex()
|
||||
cs_free(insn, count);
|
||||
} else {
|
||||
printf("****************\n");
|
||||
|
|
|
@ -161,7 +161,6 @@ static void test()
|
|||
};
|
||||
|
||||
uint64_t address = 0x1000;
|
||||
//cs_insn insn[16];
|
||||
cs_insn *insn;
|
||||
int i;
|
||||
|
||||
|
@ -172,8 +171,7 @@ static void test()
|
|||
if (platforms[i].opt_type)
|
||||
cs_option(handle, platforms[i].opt_type, platforms[i].opt_value);
|
||||
|
||||
//size_t count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, insn);
|
||||
size_t count = cs_disasm_dyn(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
|
||||
size_t count = cs_disasm_ex(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
|
||||
if (count) {
|
||||
printf("****************\n");
|
||||
printf("Platform: %s\n", platforms[i].comment);
|
||||
|
@ -187,7 +185,7 @@ static void test()
|
|||
}
|
||||
printf("0x%"PRIx64":\n", insn[j-1].address + insn[j-1].size);
|
||||
|
||||
// free memory allocated by cs_disasm_dyn()
|
||||
// free memory allocated by cs_disasm_ex()
|
||||
cs_free(insn, count);
|
||||
} else {
|
||||
printf("****************\n");
|
||||
|
|
Loading…
Reference in New Issue