MCPcopy Create free account
hub / github.com/capstone-engine/capstone / cs_disasm_iter

Function cs_disasm_iter

cs.c:1114–1210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1112// iterator for instruction "single-stepping"
1113CAPSTONE_EXPORT
1114bool CAPSTONE_API cs_disasm_iter(csh ud, const uint8_t **code, size_t *size,
1115 uint64_t *address, cs_insn *insn)
1116{
1117 if (*size == 0)
1118 return false;
1119
1120 struct cs_struct *handle;
1121 uint16_t insn_size;
1122 MCInst mci;
1123 bool r;
1124
1125 handle = (struct cs_struct *)(uintptr_t)ud;
1126 if (!handle) {
1127 return false;
1128 }
1129
1130 handle->errnum = CS_ERR_OK;
1131
1132 MCInst_Init(&mci);
1133 mci.csh = handle;
1134
1135 // relative branches need to know the address & size of current insn
1136 mci.address = *address;
1137
1138 // save all the information for non-detailed mode
1139 mci.flat_insn = insn;
1140 mci.flat_insn->address = *address;
1141#ifdef CAPSTONE_DIET
1142 // zero out mnemonic & op_str
1143 mci.flat_insn->mnemonic[0] = '\0';
1144 mci.flat_insn->op_str[0] = '\0';
1145#endif
1146
1147 r = handle->disasm(ud, *code, *size, &mci, &insn_size, *address, handle->getinsn_info);
1148 if (r) {
1149 SStream ss;
1150 SStream_Init(&ss);
1151
1152 mci.flat_insn->size = insn_size;
1153
1154 // map internal instruction opcode to public insn ID
1155 handle->insn_id(handle, insn, mci.Opcode);
1156
1157 handle->printer(&mci, &ss, handle->printer_info);
1158
1159 fill_insn(handle, insn, ss.buffer, &mci, handle->post_printer, *code);
1160
1161 // adjust for pseudo opcode (X86)
1162 if (handle->arch == CS_ARCH_X86)
1163 insn->id += mci.popcode_adjust;
1164
1165 *code += insn_size;
1166 *size -= insn_size;
1167 *address += insn_size;
1168 } else { // encounter a broken instruction
1169 size_t skipdata_bytes;
1170
1171 // if there is no request to skip data, or remaining data is too small,

Callers 5

mainFunction · 0.85
testFunction · 0.85
LLVMFuzzerTestOneInputFunction · 0.85
bs_disasm_iterFunction · 0.85
test_iter.cFile · 0.85

Calls 5

MCInst_InitFunction · 0.85
SStream_InitFunction · 0.85
fill_insnFunction · 0.85
skipdata_opstrFunction · 0.85
disasmMethod · 0.45

Tested by 2

mainFunction · 0.68
testFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…