From 1dd929aad5eed2b48bdd155938f654a956ff19a0 Mon Sep 17 00:00:00 2001 From: Horst Schirmeier Date: Sat, 23 May 2020 22:23:44 +0200 Subject: [PATCH] capstone: only use insn.detail if it's not NULL Capstone NULLs the detail field when it encounters a bad/invalid opcode. Change-Id: I421386903756e03049e950f09b8a500b54fe4a73 --- src/core/util/capstonedisassembler/CapstoneDisassembler.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/util/capstonedisassembler/CapstoneDisassembler.cpp b/src/core/util/capstonedisassembler/CapstoneDisassembler.cpp index 5f490efa..1b79b781 100644 --- a/src/core/util/capstonedisassembler/CapstoneDisassembler.cpp +++ b/src/core/util/capstonedisassembler/CapstoneDisassembler.cpp @@ -135,8 +135,10 @@ int CapstoneDisassembler::disassemble_section(Elf_Data *data, Elf32_Shdr *shdr32 for (j = 0; j < count; j++) { unsigned int opcode = 0; if (m_elf->m_machine == EM_386 || m_elf->m_machine == EM_X86_64) { - opcode = (insn[j].detail->x86.opcode[3] << 24) | (insn[j].detail->x86.opcode[2] << 16) | - (insn[j].detail->x86.opcode[1] << 8) | insn[j].detail->x86.opcode[0]; + if (insn[j].detail) { // NULL if insn is broken + opcode = (insn[j].detail->x86.opcode[3] << 24) | (insn[j].detail->x86.opcode[2] << 16) | + (insn[j].detail->x86.opcode[1] << 8) | insn[j].detail->x86.opcode[0]; + } } else if (m_elf->m_machine == EM_ARM) { // placeholder opcode = 0;