Commit 22ec6bcb authored by swift_gan's avatar swift_gan

fix tweak opcode imm

parent ef518c65
...@@ -64,15 +64,9 @@ namespace SandHook { ...@@ -64,15 +64,9 @@ namespace SandHook {
codeCopy(reinterpret_cast<Code>(&offSet), OFFSET_INLINE_OFFSET_ENTRY_CODE, BYTE_POINT); codeCopy(reinterpret_cast<Code>(&offSet), OFFSET_INLINE_OFFSET_ENTRY_CODE, BYTE_POINT);
#if defined(__arm__) #if defined(__arm__)
Code32Bit offset32; Code32Bit offset32;
Code32Bit code32Bit;
offset32.code = offSet; offset32.code = offSet;
unsigned char offsetOP = isBigEnd() ? offset32.op.op4 : offset32.op.op1; unsigned char offsetOP = isBigEnd() ? offset32.op.op4 : offset32.op.op1;
code32Bit.code = *reinterpret_cast<uint32_t*>(((Size)getCode() + OFFSET_INLINE_OP_OFFSET_CODE)); tweakOpImm(OFFSET_INLINE_OP_OFFSET_CODE, offsetOP);
if (isBigEnd()) {
code32Bit.op.op4 = offsetOP;
} else {
code32Bit.op.op1 = offsetOP;
}
#endif #endif
} }
......
...@@ -85,6 +85,17 @@ extern "C" void CALL_ORIGIN_TRAMPOLINE(); ...@@ -85,6 +85,17 @@ extern "C" void CALL_ORIGIN_TRAMPOLINE();
namespace SandHook { namespace SandHook {
//deal with little or big edn
union Code32Bit {
uint32_t code;
struct {
unsigned char op1;
unsigned char op2;
unsigned char op3;
unsigned char op4;
} op;
};
class Trampoline { class Trampoline {
public: public:
...@@ -136,6 +147,18 @@ namespace SandHook { ...@@ -136,6 +147,18 @@ namespace SandHook {
return *pointer == 0; return *pointer == 0;
} }
//tweak imm of a 32bit asm code
void tweakOpImm(Size codeOffset, unsigned char imm) {
Code32Bit code32Bit;
code32Bit.code = *reinterpret_cast<uint32_t*>(((Size)getCode() + codeOffset));
if (isBigEnd()) {
code32Bit.op.op4 = imm;
} else {
code32Bit.op.op1 = imm;
}
codeCopy(reinterpret_cast<Code>(&code32Bit.code), codeOffset, 4);
}
protected: protected:
virtual Size codeLength() = 0; virtual Size codeLength() = 0;
virtual Code templateCode() = 0; virtual Code templateCode() = 0;
...@@ -145,17 +168,6 @@ namespace SandHook { ...@@ -145,17 +168,6 @@ namespace SandHook {
Size codeLen; Size codeLen;
}; };
union Code32Bit {
uint32_t code;
struct {
unsigned char op1;
unsigned char op2;
unsigned char op3;
unsigned char op4;
} op;
};
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment