@@ -7597,14 +7597,18 @@ namespace Detours {
7597
7597
}
7598
7598
7599
7599
pInsn = pInstruction.get();
7600
- g_CachedInstructions.insert (it, std::make_pair(pExceptionAddress, std::move(pInstruction)));
7600
+ g_CachedInstructions.emplace_hint (it, std::make_pair(pExceptionAddress, std::move(pInstruction)));
7601
7601
}
7602
7602
}
7603
7603
7604
+ if (!pInsn) {
7605
+ return;
7606
+ }
7607
+
7604
7608
switch (unOperation) {
7605
7609
case MEMORY_HOOK_OPERATION::MEMORY_READ: {
7606
7610
if (pInsn->OperandsCount) {
7607
- auto& ReadOperand = pInsn->Operands[pInsn->OperandsCount - 1];
7611
+ auto ReadOperand = pInsn->Operands[pInsn->OperandsCount - 1];
7608
7612
if (!ReadOperand.Access.Read) {
7609
7613
return;
7610
7614
}
@@ -7644,18 +7648,16 @@ namespace Detours {
7644
7648
if (unBase) {
7645
7649
const size_t unOffset = reinterpret_cast<size_t>(pAddress) - unBase;
7646
7650
SetRegisterValue(pCTX, ReadOperand.Info.Memory.Base, ReadOperand.Info.Memory.BaseSize, reinterpret_cast<size_t>(pNewAddress) - unOffset);
7647
- auto OperandCopy = ReadOperand;
7648
- OperandCopy.Info.Memory.HasIndex = false;
7649
- g_CachedOperations.emplace_back(const_cast<void*>(pExceptionAddress), unOperation, const_cast<void*>(pAddress), OperandCopy, static_cast<char*>(pNewAddress) - unOffset);
7651
+ ReadOperand.Info.Memory.HasIndex = false;
7652
+ g_CachedOperations.emplace_back(const_cast<void*>(pExceptionAddress), unOperation, const_cast<void*>(pAddress), ReadOperand, static_cast<char*>(pNewAddress) - unOffset);
7650
7653
return;
7651
7654
}
7652
7655
7653
7656
if (unIndex) {
7654
7657
const size_t unOffset = reinterpret_cast<size_t>(pAddress) - unIndex;
7655
7658
SetRegisterValue(pCTX, ReadOperand.Info.Memory.Index, ReadOperand.Info.Memory.IndexSize, reinterpret_cast<size_t>(pNewAddress) - unOffset);
7656
- auto OperandCopy = ReadOperand;
7657
- OperandCopy.Info.Memory.HasBase = false;
7658
- g_CachedOperations.emplace_back(const_cast<void*>(pExceptionAddress), unOperation, const_cast<void*>(pAddress), OperandCopy, static_cast<char*>(pNewAddress) - unOffset);
7659
+ ReadOperand.Info.Memory.HasBase = false;
7660
+ g_CachedOperations.emplace_back(const_cast<void*>(pExceptionAddress), unOperation, const_cast<void*>(pAddress), ReadOperand, static_cast<char*>(pNewAddress) - unOffset);
7659
7661
return;
7660
7662
}
7661
7663
}
@@ -7675,7 +7677,7 @@ namespace Detours {
7675
7677
7676
7678
case MEMORY_HOOK_OPERATION::MEMORY_WRITE: {
7677
7679
if (pInsn->OperandsCount) {
7678
- auto& WriteOperand = pInsn->Operands[pInsn->OperandsCount - 1];
7680
+ auto WriteOperand = pInsn->Operands[pInsn->OperandsCount - 1];
7679
7681
if (!WriteOperand.Access.Write) {
7680
7682
if (pInsn->OperandsCount > 1) {
7681
7683
WriteOperand = pInsn->Operands[pInsn->OperandsCount - 2];
@@ -7721,17 +7723,15 @@ namespace Detours {
7721
7723
if (unBase) {
7722
7724
const size_t unOffset = reinterpret_cast<size_t>(pAddress) - unBase;
7723
7725
SetRegisterValue(pCTX, WriteOperand.Info.Memory.Base, WriteOperand.Info.Memory.BaseSize, reinterpret_cast<size_t>(pNewAddress) - unOffset);
7724
- auto OperandCopy = WriteOperand;
7725
- OperandCopy.Info.Memory.HasIndex = false;
7726
+ WriteOperand.Info.Memory.HasIndex = false;
7726
7727
g_CachedOperations.emplace_back(const_cast<void*>(pExceptionAddress), unOperation, const_cast<void*>(pAddress), OperandCopy, static_cast<char*>(pNewAddress) - unOffset);
7727
7728
return;
7728
7729
}
7729
7730
7730
7731
if (unIndex) {
7731
7732
const size_t unOffset = reinterpret_cast<size_t>(pAddress) - unIndex;
7732
7733
SetRegisterValue(pCTX, WriteOperand.Info.Memory.Index, WriteOperand.Info.Memory.IndexSize, reinterpret_cast<size_t>(pNewAddress) - unOffset);
7733
- auto OperandCopy = WriteOperand;
7734
- OperandCopy.Info.Memory.HasBase = false;
7734
+ WriteOperand.Info.Memory.HasBase = false;
7735
7735
g_CachedOperations.emplace_back(const_cast<void*>(pExceptionAddress), unOperation, const_cast<void*>(pAddress), OperandCopy, static_cast<char*>(pNewAddress) - unOffset);
7736
7736
return;
7737
7737
}
0 commit comments