capstone-engine / capstone

Capstone disassembly/disassembler framework for ARM, ARM64 (ARMv8), Alpha, BPF, Ethereum VM, HPPA, LoongArch, M68K, M680X, Mips, MOS65XX, PPC, RISC-V(rv32G/rv64G), SH, Sparc, SystemZ, TMS320C64X, TriCore, Webassembly, XCore and X86.
http://www.capstone-engine.org
7.53k stars 1.55k forks source link

mnemonic and op_str empty PPC #1494

Closed kamiyaa closed 5 years ago

kamiyaa commented 5 years ago

After building capstone on a powerpc machine and running a demo program, I was able to decode instructions properly. But when implementing it into a larger program, I ran into this weird behaviour where cs_ins->mnemonic and cs_ins->op_str are empty:

// for ld instruction
csInst:
id: 599
address: 256
size: 4
strlen(cs_ins->mnemonic): 0
strlen(cs_ins->op_str): 0

// for lwz instruction
csInst:
id: 651
address: 256
size: 4
strlen(cs_ins->mnemonic): 0
strlen(cs_ins->op_str): 0

and this is the case for all instructions. I have these declared as global variables:

csh csHandle;
cs_insn *csInst = NULL;    // we only need to disassemble one instruction at any given time
cs_arch csArch = CS_ARCH_PPC;
cs_mode csMode = CS_MODE_64 | CS_MODE_BIG_ENDIAN;

This occurs on next branch f9ebfae858fa8a3b14efe838249a94cd99a4797d

aquynh commented 5 years ago

Can you provide the input (in hexcode), and paste the output with "cstool" here?

Make sure you are building the latest code from the "next" branch, with: "make clean; ./make.sh; sudo ./make.sh install".

aquynh commented 5 years ago

Sounds like your program has a bug? Can you minimize your code, and post it here?

kamiyaa commented 5 years ago

sorry, it seems I had an older version of capstone headers when statically linking with the library. Thanks.