mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Arithmetic overflow checks
This commit is contained in:
parent
1f0d2dcc82
commit
eb375362a1
29 changed files with 503 additions and 87 deletions
|
@ -985,7 +985,7 @@ String X64CPU::InstructionToString(X64Instr* inst, uint64 addr)
|
|||
return result;
|
||||
}
|
||||
|
||||
bool X64CPU::IsObjectAccessBreak(uint64 address, DbgModuleMemoryCache* memoryCache, int64* regs, int64* outObjectPtr)
|
||||
DbgBreakKind X64CPU::GetDbgBreakKind(uint64 address, DbgModuleMemoryCache* memoryCache, int64* regs, int64* outObjectPtr)
|
||||
{
|
||||
// We've looking for a CMP BYTE PTR [<reg>], -0x80
|
||||
// if <reg> is R12 then encoding takes an extra 2 bytes
|
||||
|
@ -1005,6 +1005,19 @@ bool X64CPU::IsObjectAccessBreak(uint64 address, DbgModuleMemoryCache* memoryCac
|
|||
continue;
|
||||
|
||||
auto immediateType = (instDesc.TSFlags & llvm::X86II::ImmMask);
|
||||
if ((immediateType == llvm::X86II::Imm8) && (inst.mMCInst.getNumOperands() == 2))
|
||||
{
|
||||
// We're checking for a TEST [<reg>], 1
|
||||
if (inst.mMCInst.getOpcode() != llvm::X86::TEST8ri)
|
||||
continue;
|
||||
auto immOp = inst.mMCInst.getOperand(1);
|
||||
if (!immOp.isImm())
|
||||
continue;
|
||||
if (immOp.getImm() != 1)
|
||||
continue;
|
||||
return DbgBreakKind_ArithmeticOverflow;
|
||||
}
|
||||
|
||||
if ((immediateType == 0) || (inst.mMCInst.getNumOperands() < 6))
|
||||
continue;
|
||||
|
||||
|
@ -1027,10 +1040,35 @@ bool X64CPU::IsObjectAccessBreak(uint64 address, DbgModuleMemoryCache* memoryCac
|
|||
|
||||
*outObjectPtr = (uint64)regs[regNum];
|
||||
|
||||
return true;
|
||||
return DbgBreakKind_ObjectAccess;
|
||||
}
|
||||
|
||||
return false;
|
||||
// check jno/jnb
|
||||
for (int offset = 3; offset <= 3; offset++)
|
||||
{
|
||||
if (!Decode(address - offset, memoryCache, &inst))
|
||||
continue;
|
||||
|
||||
if (inst.GetLength() != 2)
|
||||
continue;
|
||||
|
||||
const MCInstrDesc &instDesc = mInstrInfo->get(inst.mMCInst.getOpcode());
|
||||
if (!instDesc.isBranch())
|
||||
continue;
|
||||
|
||||
auto immediateType = (instDesc.TSFlags & llvm::X86II::ImmMask);
|
||||
if ((immediateType == llvm::X86II::Imm8PCRel) && (inst.mMCInst.getNumOperands() == 2))
|
||||
{
|
||||
auto immOp = inst.mMCInst.getOperand(1);
|
||||
if (!immOp.isImm())
|
||||
continue;
|
||||
if ((immOp.getImm() != 1) && (immOp.getImm() != 3))
|
||||
continue;
|
||||
return DbgBreakKind_ArithmeticOverflow;
|
||||
}
|
||||
}
|
||||
|
||||
return DbgBreakKind_None;
|
||||
}
|
||||
|
||||
int X64CPU::GetOpcodesForMnemonic(const StringImpl& mnemonic, Array<int>& outOpcodes)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue