Skip to content

Commit

Permalink
Add additional patch on capstone 4.0.2 for PPC Signed 16 bit immediates
Browse files Browse the repository at this point in the history
Capstone version 4.0.2 has a bug when disassembling a powerpc instruction
with a signed 16-bit immediate.
See capstone-engine/capstone#1746 and
capstone-engine/capstone#1746 (comment).

This change adds to the capstone patch to fix this problem.
  • Loading branch information
richardlford authored and PeterMatula committed Dec 1, 2022
1 parent f2d557f commit ad34524
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions deps/capstone/patch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ string(REPLACE
"${content}"
)

if("${new_content}" STREQUAL "${content}")
string(REPLACE
"static void printS16ImmOperand(MCInst *MI, unsigned OpNo, SStream *O)\n{\n\tif (MCOperand_isImm(MCInst_getOperand(MI, OpNo))) {\n\t\tunsigned short Imm = (unsigned short)MCOperand_getImm(MCInst_getOperand(MI, OpNo));\n if (Imm > HEX_THRESHOLD)\n SStream_concat(O, \"0x%x\", Imm);\n else\n SStream_concat(O, \"%u\", Imm);\n"
"static void printS16ImmOperand(MCInst *MI, unsigned OpNo, SStream *O)\n{\n\tif (MCOperand_isImm(MCInst_getOperand(MI, OpNo))) {\n// RetDec fix\n\t\tshort Imm = (short)MCOperand_getImm(MCInst_getOperand(MI, OpNo));\n\t\tSStream_concat(O, \"%d\", Imm);\n"
new_content2
"${new_content}"
)

if("${new_content2}" STREQUAL "${content}")
message(STATUS "-- Patching: ${full_path} skipped")
else()
message(STATUS "-- Patching: ${full_path} patched")
file(WRITE "${full_path}" "${new_content}")
file(WRITE "${full_path}" "${new_content2}")
endif()

0 comments on commit ad34524

Please sign in to comment.