def extract_insn_bytes_features(f, bb, insn): """ parse byte sequence features from the given instruction. example: # push offset iid_004118d4_IShellLinkA ; riid """ if insn.mnem == "call": return for oper in insn.opers: if isinstance(oper, envi.archs.i386.disasm.i386ImmOper): v = oper.getOperValue(oper) elif isinstance(oper, envi.archs.i386.disasm.i386RegMemOper): # handle case like: # movzx ecx, ds:byte_423258[eax] v = oper.disp elif isinstance(oper, envi.archs.i386.disasm.i386SibOper): # like 0x401000 in `mov eax, 0x401000[2 * ebx]` v = oper.imm elif isinstance(oper, envi.archs.amd64.disasm.Amd64RipRelOper): # see: Lab21-01.exe_:0x1400010D3 v = oper.getOperAddr(insn) else: continue for v in derefs(f.vw, v): try: buf = read_bytes(f.vw, v) except envi.exc.SegmentationViolation: continue if capa.features.extractors.helpers.all_zeros(buf): continue yield Bytes(buf), insn.va
def extract_insn_bytes_features(f, bb, insn): """ parse byte sequence features from the given instruction. example: # push offset iid_004118d4_IShellLinkA ; riid """ for data_ref in insn.getDataRefs(): for v in derefs(f.smda_report, data_ref): bytes_read = read_bytes(f.smda_report, v) if bytes_read is None: continue if capa.features.extractors.helpers.all_zeros(bytes_read): continue yield Bytes(bytes_read), insn.offset
def extract_insn_bytes_features(f, bb, insn): """parse referenced byte sequences args: f (IDA func_t) bb (IDA BasicBlock) insn (IDA insn_t) example: push offset iid_004118d4_IShellLinkA ; riid """ if idaapi.is_call_insn(insn): return ref = capa.features.extractors.ida.helpers.find_data_reference_from_insn(insn) if ref != insn.ea: extracted_bytes = capa.features.extractors.ida.helpers.read_bytes_at(ref, MAX_BYTES_FEATURE_SIZE) if extracted_bytes and not capa.features.extractors.helpers.all_zeros(extracted_bytes): yield Bytes(extracted_bytes), insn.ea