Skip to content

Commit

Permalink
(Binary Analysis) Fixed problems with PPC instruction decoding
Browse files Browse the repository at this point in the history
* Create "unknown" instructions instead of throwing an exception when
  decoding an invalid PPC machine instruction.

* Fixed the MULLDO instruction so it works for both 32- and 64-bit
  instruction sets.

Issue #215
  • Loading branch information
matzke1 authored and rosecompiler committed Aug 1, 2024
1 parent 538523a commit a69e1a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/Rose/BinaryAnalysis/Disassembler/Powerpc.C
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,15 @@ Powerpc::disassembleOne(const MemoryMap::Ptr &map, rose_addr_t start_va, Address
c = ByteOrder::swapBytes(c);

// Disassemble the instruction
State state;
startInstruction(state, start_va, c);
SgAsmPowerpcInstruction *insn = disassemble(state); // throws an exception on error
ASSERT_not_null(insn);
SgAsmPowerpcInstruction *insn = nullptr;
try {
State state;
startInstruction(state, start_va, c);
insn = disassemble(state); // throws an exception on error, but we want to return an unknown insn
ASSERT_not_null(insn);
} catch (const ExceptionPowerpc &e) {
return makeUnknownInstruction(e);
}

// Note successors if necessary
if (successors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1349,10 +1349,10 @@ struct IP_mulldo: P {
explicit IP_mulldo(UpdateCr::Flag updateCr): updateCr(updateCr) {}
void p(D d, Ops ops, I insn, A args) {
assert_args(insn, args, 3);
BaseSemantics::SValue::Ptr a = d->read(args[1], 32);
BaseSemantics::SValue::Ptr b = d->read(args[2], 32);
BaseSemantics::SValue::Ptr a = d->read(args[1]);
BaseSemantics::SValue::Ptr b = d->read(args[2]);
BaseSemantics::SValue::Ptr product = ops->signedMultiply(a, b);
BaseSemantics::SValue::Ptr result = ops->extract(product, 0, 32);
BaseSemantics::SValue::Ptr result = ops->extract(product, 0, args[0]->get_type()->get_nBits());
d->write(args[0], result);
d->setXerOverflow(ops->invert(ops->equalToZero(ops->extract(result, 32, 64))));
if (UpdateCr::YES == updateCr)
Expand Down

0 comments on commit a69e1a9

Please sign in to comment.