Commit 60422367 authored by swift_gan's avatar swift_gan

fix thumb32 check

parent 8eed3a00
...@@ -92,8 +92,8 @@ namespace SandHook { ...@@ -92,8 +92,8 @@ namespace SandHook {
return (codeAddr & 0x1) == 0x1; return (codeAddr & 0x1) == 0x1;
} }
bool isThumb32(uint32_t code) { bool isThumb32(uint16_t code) {
return code >> 16 != 0; return ((code & 0xF000) == 0xF000) || ((code & 0xF800) == 0xE800);
} }
void InstDecode::decode(void *codeStart, Size codeLen, InstVisitor *visitor) { void InstDecode::decode(void *codeStart, Size codeLen, InstVisitor *visitor) {
...@@ -103,13 +103,14 @@ namespace SandHook { ...@@ -103,13 +103,14 @@ namespace SandHook {
codeStart = Trampoline::getThumbCodeAddress(static_cast<Code>(codeStart)); codeStart = Trampoline::getThumbCodeAddress(static_cast<Code>(codeStart));
Size codeAddr = reinterpret_cast<Size>(codeStart); Size codeAddr = reinterpret_cast<Size>(codeStart);
while (offset <= codeLen) { while (offset <= codeLen) {
uint16_t ram16 = *reinterpret_cast<uint16_t*>(codeAddr + offset);
uint32_t ram32 = *reinterpret_cast<uint32_t*>(codeAddr + offset); uint32_t ram32 = *reinterpret_cast<uint32_t*>(codeAddr + offset);
if (isThumb32(ram32)) { if (isThumb32(ram16)) {
//thumb32 //thumb32
inst = new InstThumb32(ram32); inst = new InstThumb32(ram32);
} else { } else {
//thumb16 //thumb16
inst = new InstThumb16(static_cast<uint16_t>(ram32)); inst = new InstThumb16(ram16);
} }
if (!visitor->visit(inst, offset, codeLen)) { if (!visitor->visit(inst, offset, codeLen)) {
delete inst; delete inst;
......
...@@ -25,12 +25,23 @@ namespace SandHook { ...@@ -25,12 +25,23 @@ namespace SandHook {
public: public:
bool pcRelated = false; bool pcRelated = false;
bool instWillBeDestroy = false;
int instSize = 0;
bool visit(Inst *inst, Size offset, Size length) override { bool visit(Inst *inst, Size offset, Size length) override {
instSize += inst->instLen();
if (inst->pcRelated()) { if (inst->pcRelated()) {
pcRelated = true; pcRelated = true;
return false; return false;
} }
if (instSize > SIZE_DIRECT_JUMP_TRAMPOLINE) {
instWillBeDestroy = true;
}
return true; return true;
} }
}; };
...@@ -49,7 +60,7 @@ namespace SandHook { ...@@ -49,7 +60,7 @@ namespace SandHook {
InstDecode::decode(method->getQuickCodeEntry(), SIZE_DIRECT_JUMP_TRAMPOLINE, &visitor); InstDecode::decode(method->getQuickCodeEntry(), SIZE_DIRECT_JUMP_TRAMPOLINE, &visitor);
return !visitor.pcRelated; return (!visitor.pcRelated) && (!visitor.instWillBeDestroy);
} }
Code TrampolineManager::allocExecuteSpace(Size size) { Code TrampolineManager::allocExecuteSpace(Size size) {
......
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