Commit a294625b authored by swift_gan's avatar swift_gan Committed by swift_gan

[Reconstitution]typo

parent 8eac60f2
......@@ -10,24 +10,24 @@ using namespace SandHook::RegistersA32;
using namespace SandHook::AsmA32;
AssemblerA32::AssemblerA32(CodeBuffer* codeBuffer) {
code_container.setCodeBuffer(codeBuffer);
code_container.SetCodeBuffer(codeBuffer);
}
void *AssemblerA32::GetPC() {
return reinterpret_cast<void *>(code_container.curPc);
return reinterpret_cast<void *>(code_container.cur_pc);
}
void *AssemblerA32::GetStartPC() {
return reinterpret_cast<void *>(code_container.startPc);
return reinterpret_cast<void *>(code_container.start_pc);
}
void AssemblerA32::AllocBufferFirst(U32 size) {
code_container.allocBufferFirst(size);
code_container.AllocBufferFirst(size);
}
void *AssemblerA32::Finish() {
code_container.commit();
return reinterpret_cast<void *>(code_container.startPc);
code_container.Commit();
return reinterpret_cast<void *>(code_container.start_pc);
}
void AssemblerA32::Emit(U32 data32) {
......@@ -39,7 +39,7 @@ void AssemblerA32::Emit(U16 data16) {
}
void AssemblerA32::Emit(BaseUnit *unit) {
code_container.append(unit);
code_container.Append(unit);
}
void AssemblerA32::Mov(RegisterA32 &rd, U16 imm16) {
......
......@@ -31,7 +31,7 @@ namespace SandHook {
void Emit(U32 data32);
void Emit(U16 data16);
void Emit(Unit<Base>* unit);
void Emit(BaseUnit* unit);
void Mov(RegisterA32 &rd, U16 imm16);
......
......@@ -22,8 +22,8 @@ goto label_matched; \
Arm32Decoder* Arm32Decoder::instant = new Arm32Decoder();
void Arm32Decoder::Disassembler(void *codeStart, Addr codeLen, InstVisitor &visitor,
bool onlyPcRelInst) {
void Arm32Decoder::Disassemble(void *codeStart, Addr codeLen, InstVisitor &visitor,
bool onlyPcRelInst) {
bool thumb = IsThumbCode(reinterpret_cast<Addr>(codeStart));
if (thumb) {
codeStart = GetThumbCodeAddress(codeStart);
......
......@@ -12,8 +12,8 @@ namespace SandHook {
class Arm32Decoder : public InstDecoder {
public:
void Disassembler(void *codeStart, Addr codeLen, InstVisitor &visitor,
bool onlyPcRelInst) override;
void Disassemble(void *codeStart, Addr codeLen, InstVisitor &visitor,
bool onlyPcRelInst) override;
public:
static Arm32Decoder* instant;
};
......
......@@ -28,7 +28,7 @@ void *InlineHookArm32Android::Hook(void *origin, void *replace) {
return nullptr;
}
bool changeMode = IsThumbCode((Addr) origin) != IsThumbCode((Addr) replace);
bool change_mode = IsThumbCode((Addr) origin) != IsThumbCode((Addr) replace);
void* backup = nullptr;
AssemblerA32 assembler_backup(backup_buffer);
......@@ -39,7 +39,7 @@ void *InlineHookArm32Android::Hook(void *origin, void *replace) {
//build inline trampoline
#define __ assembler_inline.
if (!changeMode) {
if (!change_mode) {
Label *target_addr_label = new Label();
ALIGN_FOR_LDR
__ Ldr(PC, target_addr_label);
......@@ -54,7 +54,7 @@ void *InlineHookArm32Android::Hook(void *origin, void *replace) {
//build backup method
CodeRelocateA32 relocate = CodeRelocateA32(assembler_backup);
backup = relocate.Relocate(origin, code_container_inline->size(), nullptr);
backup = relocate.Relocate(origin, code_container_inline->Size(), nullptr);
#define __ assembler_backup.
Label* origin_addr_label = new Label();
ALIGN_FOR_LDR
......@@ -107,7 +107,7 @@ bool InlineHookArm32Android::BreakPoint(void *origin, void (*callback)(REG *)) {
//build trampoline
origin_addr_s = (Addr) GetThumbPC(backup);
callback_addr_s = (Addr) callback;
void* trampoline = backup_buffer->copy((void*)BP_SHELLCODE, SHELLCODE_LEN(BP_SHELLCODE));
void* trampoline = backup_buffer->Copy((void*)BP_SHELLCODE, SHELLCODE_LEN(BP_SHELLCODE));
//build inline trampoline
#define __ assembler_inline.
......
......@@ -44,7 +44,7 @@ void* CodeRelocateA32::Relocate(void *startPc, Addr len, void *toPc = nullptr) t
__ AllocBufferFirst(static_cast<U32>(len * 8));
void* curPc = __ GetPC();
if (toPc == nullptr) {
Disassembler::Get()->Disassembler(startPc, len, *this, true);
Disassembler::Get()->Disassemble(startPc, len, *this, true);
} else {
//TODO
}
......@@ -52,7 +52,7 @@ void* CodeRelocateA32::Relocate(void *startPc, Addr len, void *toPc = nullptr) t
}
void* CodeRelocateA32::Relocate(BaseInst *instruction, void *toPc) throw(ErrorCodeException) {
void* curPc = __ GetPC();
void* cur_pc = __ GetPC();
//insert later AddBind labels
__ Emit(GetLaterBindLabel(cur_offset));
......@@ -60,7 +60,7 @@ void* CodeRelocateA32::Relocate(BaseInst *instruction, void *toPc) throw(ErrorCo
if (!instruction->PcRelate()) {
__ Emit(instruction);
instruction->Ref();
return curPc;
return cur_pc;
}
if (instruction->InstType() == thumb32) {
......@@ -88,7 +88,7 @@ void* CodeRelocateA32::Relocate(BaseInst *instruction, void *toPc) throw(ErrorCo
__ Emit(instruction);
instruction->Ref();
}
return curPc;
return cur_pc;
}
......@@ -99,14 +99,14 @@ IMPL_RELOCATE(T16, B_COND) {
return;
}
Addr targetAddr = inst->GetImmPCOffsetTarget();
Addr target_addr = inst->GetImmPCOffsetTarget();
if (inst->condition == al) {
Label* target_label = new Label;
ALIGN_FOR_LDR
__ Ldr(PC, target_label);
__ Emit(target_label);
__ Emit(targetAddr);
__ Emit(target_addr);
} else {
Label* true_label = new Label();
Label* false_label = new Label();
......@@ -117,7 +117,7 @@ IMPL_RELOCATE(T16, B_COND) {
ALIGN_FOR_LDR
__ Ldr(PC, target_label);
__ Emit(target_label);
__ Emit(targetAddr);
__ Emit(target_addr);
__ Emit(false_label);
}
......@@ -130,13 +130,13 @@ IMPL_RELOCATE(T16, B) {
return;
}
Addr targetAddr = inst->GetImmPCOffsetTarget();
Addr target_addr = inst->GetImmPCOffsetTarget();
Label* target_label = new Label();
ALIGN_FOR_LDR
__ Ldr(PC, target_label);
__ Emit(target_label);
__ Emit((Addr) GetThumbPC(reinterpret_cast<void *>(targetAddr)));
__ Emit((Addr) GetThumbPC(reinterpret_cast<void *>(target_addr)));
}
......@@ -155,7 +155,7 @@ IMPL_RELOCATE(T16, CBZ_CBNZ) {
return;
}
Addr targetAddr = inst->GetImmPCOffsetTarget();
Addr target_addr = inst->GetImmPCOffsetTarget();
Label* true_label = new Label;
Label* false_label = new Label;
......@@ -168,7 +168,7 @@ IMPL_RELOCATE(T16, CBZ_CBNZ) {
ALIGN_FOR_LDR
__ Ldr(PC, target_label);
__ Emit(target_label);
__ Emit((Addr) GetThumbPC(reinterpret_cast<void *>(targetAddr)));
__ Emit((Addr) GetThumbPC(reinterpret_cast<void *>(target_addr)));
__ Emit(false_label);
}
......@@ -182,9 +182,9 @@ IMPL_RELOCATE(T16, LDR_LIT) {
return;
}
Addr targetAddr = inst->GetImmPCOffsetTarget();
Addr target_addr = inst->GetImmPCOffsetTarget();
__ Mov(*inst->rt, targetAddr);
__ Mov(*inst->rt, target_addr);
__ Ldr(*inst->rt, MemOperand(inst->rt, 0));
}
......@@ -197,9 +197,9 @@ IMPL_RELOCATE(T16, ADR) {
return;
}
Addr targetAddr = inst->GetImmPCOffsetTarget();
Addr target_addr = inst->GetImmPCOffsetTarget();
__ Mov(*inst->rd, targetAddr);
__ Mov(*inst->rd, target_addr);
}
......@@ -229,14 +229,14 @@ IMPL_RELOCATE(T32, B32) {
return;
}
Addr targetAddr = inst->GetImmPCOffsetTarget();
Addr target_addr = inst->GetImmPCOffsetTarget();
if (inst->x == T32_B32::thumb) {
//Thumb mode
targetAddr = reinterpret_cast<Addr>(GetThumbPC(reinterpret_cast<void *>(targetAddr)));
target_addr = reinterpret_cast<Addr>(GetThumbPC(reinterpret_cast<void *>(target_addr)));
}
__ Mov(IP, targetAddr);
__ Mov(IP, target_addr);
if (inst->op == T32_B32::BL) {
__ Blx(IP);
} else {
......@@ -254,9 +254,9 @@ IMPL_RELOCATE(T32, LDR_LIT) {
return;
}
Addr targetAddr = inst->GetImmPCOffsetTarget();
Addr target_addr = inst->GetImmPCOffsetTarget();
__ Mov(*inst->rt, targetAddr);
__ Mov(*inst->rt, target_addr);
switch (inst->op) {
case T32_LDR_LIT::LDR:
__ Ldr(*inst->rt, MemOperand(inst->rt, 0));
......
......@@ -9,24 +9,24 @@ using namespace SandHook::RegistersA64;
using namespace SandHook::AsmA64;
AssemblerA64::AssemblerA64(CodeBuffer* codeBuffer) {
code_container.setCodeBuffer(codeBuffer);
code_container.SetCodeBuffer(codeBuffer);
}
void *AssemblerA64::GetPC() {
return reinterpret_cast<void *>(code_container.curPc);
return reinterpret_cast<void *>(code_container.cur_pc);
}
void *AssemblerA64::GetStartPC() {
return reinterpret_cast<void *>(code_container.startPc);
return reinterpret_cast<void *>(code_container.start_pc);
}
void AssemblerA64::AllocBufferFirst(U32 size) {
code_container.allocBufferFirst(size);
code_container.AllocBufferFirst(size);
}
void *AssemblerA64::Finish() {
code_container.commit();
return reinterpret_cast<void *>(code_container.startPc);
code_container.Commit();
return reinterpret_cast<void *>(code_container.start_pc);
}
......@@ -39,7 +39,7 @@ void AssemblerA64::Emit(U32 data32) {
}
void AssemblerA64::Emit(BaseUnit *unit) {
code_container.append(unit);
code_container.Append(unit);
}
void AssemblerA64::MoveWide(RegisterA64 &rd, INST_A64(MOV_WIDE)::OP op, U64 imme,
......
......@@ -25,7 +25,7 @@ namespace SandHook {
void Emit(U32 data32);
void Emit(U64 data64);
void Emit(Unit<Base>* unit);
void Emit(BaseUnit* unit);
void MoveWide(RegisterA64& rd, INST_A64(MOV_WIDE)::OP op, U64 imme, INST_A64(MOV_WIDE)::Shift shift);
......
......@@ -16,8 +16,8 @@ goto label_matched; \
Arm64Decoder* Arm64Decoder::instant = new Arm64Decoder();
void Arm64Decoder::Disassembler(void *codeStart, Addr codeLen, InstVisitor &visitor,
bool onlyPcRelInst) {
void Arm64Decoder::Disassemble(void *codeStart, Addr codeLen, InstVisitor &visitor,
bool onlyPcRelInst) {
InstA64 *pc = reinterpret_cast<InstA64 *>(codeStart);
Addr end_addr = (Addr) codeStart + codeLen;
BaseUnit* unit = nullptr;
......
......@@ -11,8 +11,8 @@ namespace SandHook {
class Arm64Decoder : public InstDecoder {
public:
void Disassembler(void *codeStart, Addr codeLen, InstVisitor &visitor,
bool onlyPcRelInst) override;
void Disassemble(void *codeStart, Addr codeLen, InstVisitor &visitor,
bool onlyPcRelInst) override;
public:
static Arm64Decoder* instant;
};
......
......@@ -36,13 +36,13 @@ void *InlineHookArm64Android::Hook(void *origin, void *replace) {
//build backup method
CodeRelocateA64 relocate = CodeRelocateA64(assembler_backup);
backup = relocate.Relocate(origin, code_container_inline->size(), nullptr);
backup = relocate.Relocate(origin, code_container_inline->Size(), nullptr);
#define __ assembler_backup.
Label* origin_addr_label = new Label();
__ Ldr(IP1, origin_addr_label);
__ Br(IP1);
__ Emit(origin_addr_label);
__ Emit((Addr) origin + code_container_inline->size());
__ Emit((Addr) origin + code_container_inline->Size());
__ Finish();
#undef __
......
......@@ -24,7 +24,7 @@ CodeRelocateA64::CodeRelocateA64(AssemblerA64 &assembler) : CodeRelocate(assembl
assemblerA64 = &assembler;
}
bool CodeRelocateA64::Visit(Unit<Base> *unit, void *pc) {
bool CodeRelocateA64::Visit(BaseUnit *unit, void *pc) {
Relocate(reinterpret_cast<BaseInst *>(unit), __ GetPC());
cur_offset += unit->Size();
if (unit->RefCount() == 0) {
......@@ -39,17 +39,17 @@ void* CodeRelocateA64::Relocate(void *startPc, Addr len, void *toPc = nullptr) t
length = len;
cur_offset = 0;
__ AllocBufferFirst(static_cast<U32>(len * 8));
void* curPc = __ GetPC();
void* cur_pc = __ GetPC();
if (toPc == nullptr) {
Disassembler::Get()->Disassembler(startPc, len, *this, true);
Disassembler::Get()->Disassemble(startPc, len, *this, true);
} else {
//TODO
}
return curPc;
return cur_pc;
}
void* CodeRelocateA64::Relocate(BaseInst *instruction, void *toPc) throw(ErrorCodeException) {
void* curPc = __ GetPC();
void* cur_pc = __ GetPC();
//insert later AddBind labels
__ Emit(GetLaterBindLabel(cur_offset));
......@@ -57,7 +57,7 @@ void* CodeRelocateA64::Relocate(BaseInst *instruction, void *toPc) throw(ErrorCo
if (!instruction->PcRelate()) {
__ Emit(instruction);
instruction->Ref();
return curPc;
return cur_pc;
}
switch (instruction->InstCode()) {
CASE(B_BL)
......@@ -70,7 +70,7 @@ void* CodeRelocateA64::Relocate(BaseInst *instruction, void *toPc) throw(ErrorCo
__ Emit(instruction);
instruction->Ref();
}
return curPc;
return cur_pc;
}
IMPL_RELOCATE(B_BL) {
......@@ -82,7 +82,7 @@ IMPL_RELOCATE(B_BL) {
return;
}
Addr targetAddr = inst->GetImmPCOffsetTarget();
Addr target_addr = inst->GetImmPCOffsetTarget();
if (inst->op == inst->BL) {
Addr lr = reinterpret_cast<Addr>(toPc);
......@@ -91,7 +91,7 @@ IMPL_RELOCATE(B_BL) {
lr += 4; // Br
__ Mov(LR, lr);
}
__ Mov(IP1, targetAddr);
__ Mov(IP1, target_addr);
__ Br(IP1);
}
......@@ -104,7 +104,7 @@ IMPL_RELOCATE(B_COND) {
return;
}
Addr targetAddr = inst->GetImmPCOffsetTarget();
Addr target_addr = inst->GetImmPCOffsetTarget();
Label *true_label = new Label();
Label *false_label = new Label();
......@@ -113,7 +113,7 @@ IMPL_RELOCATE(B_COND) {
__ B(false_label);
__ Emit(true_label);
__ Mov(IP1, targetAddr);
__ Mov(IP1, target_addr);
__ Br(IP1);
__ Emit(false_label);
......@@ -128,7 +128,7 @@ IMPL_RELOCATE(TBZ_TBNZ) {
return;
}
Addr targetAddr = inst->GetImmPCOffsetTarget();
Addr target_addr = inst->GetImmPCOffsetTarget();
Label *true_label = new Label();
Label *false_label = new Label();
......@@ -141,7 +141,7 @@ IMPL_RELOCATE(TBZ_TBNZ) {
__ B(false_label);
__ Emit(true_label);
__ Mov(IP1, targetAddr);
__ Mov(IP1, target_addr);
__ Br(IP1);
__ Emit(false_label);
......@@ -156,7 +156,7 @@ IMPL_RELOCATE(CBZ_CBNZ) {
return;
}
Addr targetAddr = inst->GetImmPCOffsetTarget();
Addr target_addr = inst->GetImmPCOffsetTarget();
Label *true_label = new Label();
Label *false_label = new Label();
......@@ -170,14 +170,14 @@ IMPL_RELOCATE(CBZ_CBNZ) {
__ B(false_label);
__ Emit(true_label);
__ Mov(IP1, targetAddr);
__ Mov(IP1, target_addr);
__ Br(IP1);
__ Emit(false_label);
}
IMPL_RELOCATE(LDR_LIT) {
Addr targetAddr = inst->GetImmPCOffsetTarget();
Addr target_addr = inst->GetImmPCOffsetTarget();
XRegister* rtX = XReg(inst->rt->Code());
WRegister* rtW = WReg(inst->rt->Code());
......@@ -190,20 +190,20 @@ IMPL_RELOCATE(LDR_LIT) {
switch (inst->op) {
case INST_A64(LDR_LIT)::LDR_X:
__ Mov(*rtX, targetAddr);
__ Mov(*rtX, target_addr);
__ Ldr(*rtX, MemOperand(rtX, 0, Offset));
break;
case INST_A64(LDR_LIT)::LDR_W:
__ Mov(*rtX, targetAddr);
__ Mov(*rtX, target_addr);
__ Ldr(*rtW, MemOperand(rtX, 0, Offset));
break;
case INST_A64(LDR_LIT)::LDR_SW:
__ Mov(*rtX, targetAddr);
__ Mov(*rtX, target_addr);
__ Ldrsw(*rtX, MemOperand(rtX, 0, Offset));
break;
case INST_A64(LDR_LIT)::LDR_PRFM:
__ Push(X0);
__ Mov(X0, targetAddr);
__ Mov(X0, target_addr);
__ Ldrsw(X0, MemOperand(rtX, 0, Offset));
__ Pop(X0);
break;
......
......@@ -26,7 +26,7 @@ namespace SandHook {
void* Relocate(void *startPc, Addr len, void *toPc) throw(ErrorCodeException) override;
bool Visit(Unit<Base> *unit, void *pc) override;
bool Visit(BaseUnit *unit, void *pc) override;
DEFINE_RELOCATE(B_BL)
......
......@@ -99,7 +99,7 @@ namespace SandHook {
S backup_;
};
class Void : public Unit<Base> {
class Void : public BaseUnit {
public:
Void(U32 size) : size_(size) {}
......
......@@ -20,7 +20,7 @@ namespace SandHook {
Label() {}
Label(void *pc) : Unit<Base>(pc) {}
Label(void *pc) : BaseUnit(pc) {}
enum UnitTypeDef UnitType() override {
return UnitTypeDef::UnitLabel;
......
......@@ -8,32 +8,32 @@
using namespace SandHook::Assembler;
using namespace SandHook::Asm;
CodeContainer::CodeContainer(CodeBuffer *codeBuffer) : codeBuffer(codeBuffer) {}
CodeContainer::CodeContainer(CodeBuffer *codeBuffer) : code_buffer(codeBuffer) {}
void CodeContainer::setCodeBuffer(CodeBuffer *codeBuffer) {
this->codeBuffer = codeBuffer;
void CodeContainer::SetCodeBuffer(CodeBuffer *codeBuffer) {
this->code_buffer = codeBuffer;
}
void CodeContainer::append(Unit<Base> *unit) {
void CodeContainer::Append(BaseUnit *unit) {
units.push_back(unit);
unit->SetVPC(curPc);
unit->SetVPC(cur_pc);
switch (unit->UnitType()) {
case UnitLabel:
labels.push_back((Label*)unit);
break;
default:
curPc += unit->Size();
cur_pc += unit->Size();
}
}
void CodeContainer::commit() {
U32 bufferSize = static_cast<U32>(curPc - startPc);
void CodeContainer::Commit() {
U32 bufferSize = static_cast<U32>(cur_pc - start_pc);
void* bufferStart;
if (startPc > 0) {
bufferStart = reinterpret_cast<void *>(startPc);
codeBuffer->ResetLastBufferSize(bufferSize);
if (start_pc > 0) {
bufferStart = reinterpret_cast<void *>(start_pc);
code_buffer->ResetLastBufferSize(bufferSize);
} else {
bufferStart = codeBuffer->GetBuffer(bufferSize);
bufferStart = code_buffer->GetBuffer(bufferSize);
}
Addr pcNow = reinterpret_cast<Addr>(bufferStart);
......@@ -61,23 +61,23 @@ void CodeContainer::commit() {
FlushCache(reinterpret_cast<Addr>(bufferStart), pcNow - reinterpret_cast<Addr>(bufferStart));
//Set pc
startPc = reinterpret_cast<Addr>(bufferStart);
curPc = pcNow;
start_pc = reinterpret_cast<Addr>(bufferStart);
cur_pc = pcNow;
}
void CodeContainer::allocBufferFirst(U32 size) {
startPc = reinterpret_cast<Addr>(codeBuffer->GetBuffer(size));
curPc = startPc;
void CodeContainer::AllocBufferFirst(U32 size) {
start_pc = reinterpret_cast<Addr>(code_buffer->GetBuffer(size));
cur_pc = start_pc;
}
CodeContainer::~CodeContainer() {
std::list<Unit<Base>*>::iterator unit;
std::list<BaseUnit*>::iterator unit;
for(unit = units.begin();unit != units.end(); ++unit) {
delete (*unit);
}
}
Addr CodeContainer::size() {
return curPc - startPc;
Addr CodeContainer::Size() {
return cur_pc - start_pc;
}
......@@ -11,13 +11,13 @@
using namespace SandHook::Decoder;
bool DefaultVisitor::Visit(Unit<Base> *unit, void *pc) {
bool DefaultVisitor::Visit(BaseUnit *unit, void *pc) {
bool res = visitor(unit, pc);
delete unit;
return res;
}
DefaultVisitor::DefaultVisitor(bool (*visitor)(Unit<Base> *, void *)) : visitor(visitor) {}
DefaultVisitor::DefaultVisitor(bool (*visitor)(BaseUnit *, void *)) : visitor(visitor) {}
//do not support now
InstDecoder* Disassembler::Get(Arch arch) {
......
......@@ -23,7 +23,7 @@ namespace SandHook {
public:
virtual void* GetBuffer(U32 size) = 0;
virtual void ResetLastBufferSize(U32 size){};
virtual void* copy(void* start, U32 size) {
virtual void* Copy(void* start, U32 size) {
void* bufferStart = GetBuffer(size);
if (bufferStart == nullptr)
return nullptr;
......@@ -38,26 +38,26 @@ namespace SandHook {
CodeContainer(CodeBuffer *codeBuffer);
void setCodeBuffer(CodeBuffer *codeBuffer);
void SetCodeBuffer(CodeBuffer *codeBuffer);
//allow code Relocate to Get new pc first
void allocBufferFirst(U32 size);
void append(Unit<Base>* unit);
void commit();
void AllocBufferFirst(U32 size);
void Append(BaseUnit *unit);
void Commit();
Addr size();
Addr Size();
virtual ~CodeContainer();
public:
//before commit is virtual address so = 0, after commit is real address
Addr startPc = 0;
Addr curPc = 0;
Addr start_pc = 0;
Addr cur_pc = 0;
private:
Addr maxSize = 0;
std::list<Unit<Base>*> units = std::list<Unit<Base>*>();
Addr max_size = 0;
std::list<BaseUnit*> units = std::list<BaseUnit*>();
std::list<Label*> labels = std::list<Label*>();
CodeBuffer* codeBuffer = nullptr;
CodeBuffer* code_buffer = nullptr;
};
......
......@@ -15,7 +15,7 @@ namespace SandHook {
class InstVisitor {
public:
//need free unit
virtual bool Visit(Unit<Base> *unit, void *pc) {
virtual bool Visit(BaseUnit *unit, void *pc) {
delete unit;
return false;
};
......@@ -32,11 +32,12 @@ namespace SandHook {
class InstDecoder {
public:
virtual void Disassembler(void *code_start, Addr code_len, InstVisitor &visitor,
bool only_pc_rel = false) = 0;
inline void Disassembler(void* codeStart, Addr codeLen, bool (*visitor)(Unit<Base>*, void*), bool only_pc_rel = false) {
virtual void Disassemble(void *code_start, Addr code_len, InstVisitor &visitor,
bool only_pc_rel = false) = 0;
inline void Disassemble(void *codeStart, Addr codeLen,
bool (*visitor)(BaseUnit *, void *), bool only_pc_rel = false) {
InstVisitor vis = DefaultVisitor(visitor);
Disassembler(codeStart, codeLen, vis, only_pc_rel);
Disassemble(codeStart, codeLen, vis, only_pc_rel);
};
};
......
......@@ -3,8 +3,6 @@
//
#include <jni.h>
#include <sys/mman.h>
#include <log.h>
#include "sandhook_native.h"
#include "hook.h"
#include "elf.h"
......@@ -12,138 +10,6 @@
using namespace SandHook::Hook;
using namespace SandHook::Elf;
int m1 = 5;
int m3 = 1036;
int m2 = 1035;
int m4 = 5;
void (*dosth3Backup)(int, int) = nullptr;
void (*dosth4Backup)() = nullptr;
void (*dosth4Backup2)() = nullptr;
void (*innerSuspendVM)() = nullptr;
static void (*heapPreForkBackup)(void *) = nullptr;
static void myHeapPreFork(void *heap) {
heapPreForkBackup(heap);
}
void SuspendVMReplace() {
LOGE("VM Suspend!");
innerSuspendVM();
}
void do2() {
int a = 1 + 1;
int b = 1 + 1;
int c = 1 + 1;
int d = 1 + 1;
}
void do3(int x, int y) {
do2();
int a = 1 + 1;
int b = 1 + 1;
int c = 1 + 1;
int d = a + b + c;
LOGE("do3 = %d", y);
}
void do5() {
LOGE("x = %d", 5);
}
void do4() {
int a = 1 + 1;
int b = a + 1;
int d = a + 1;
int e = a + 1;
LOGE("x = %d", 7);
}
void do4replace() {
int a = 1 + 1;
int b = 1 + 1;
int c = 1 + 1;
int d = 1 + 1;
dosth4Backup();
}
void do4replace2() {
int a = 1 + 1;
int c = 1 + 1;
int d = 1 + 1;
dosth4Backup2();
}
void do3replace(int x, int y) {
int a = 1 + 1;
int b = 1 + 1;
int c = 1 + 1;
int d = 1 + 1;
dosth3Backup(x, y);
}
void do1() {
do2();
}
void breakCallback(REG regs[]) {
LOGE("breakCallback = %d SP = %d", regs[0], regs);
}
class Visitor : public InstVisitor {
bool Visit(Unit<Base> *unit, void *pc) override {
BaseInst* instruction = reinterpret_cast<BaseInst *>(unit);
instruction->Assemble();
return true;
}
};
extern "C"
JNIEXPORT void JNICALL
Java_com_swift_sandhook_nativehook_NativeHook_test(JNIEnv *env, jclass jclass1) {
dosth4Backup = reinterpret_cast<void (*)()>(InlineHook::instance->Hook(
reinterpret_cast<void *>(do4),
reinterpret_cast<void *>(do4replace)));
dosth4Backup2 = reinterpret_cast<void (*)()>(InlineHook::instance->Hook(
reinterpret_cast<void *>(do4),
reinterpret_cast<void *>(do4replace2)));
do4();
if (sizeof(void*) == 8) {
heapPreForkBackup = reinterpret_cast<void (*)(void *)>(SandInlineHookSym("/system/lib64/libart.so", "_ZN3art2gc4Heap13PreZygoteForkEv",
reinterpret_cast<void *>(myHeapPreFork)));
innerSuspendVM = reinterpret_cast<void (*)()>(SandInlineHookSym("/system/lib64/libart.so", "_ZN3art3Dbg9SuspendVMEv",
reinterpret_cast<void *>(SuspendVMReplace)));
} else {
heapPreForkBackup = reinterpret_cast<void (*)(void *)>(SandInlineHookSym("/system/lib/libart.so", "_ZN3art2gc4Heap13PreZygoteForkEv",
reinterpret_cast<void *>(myHeapPreFork)));
innerSuspendVM = reinterpret_cast<void (*)()>(SandInlineHookSym("/system/lib/libart.so", "_ZN3art3Dbg9SuspendVMEv",
reinterpret_cast<void *>(SuspendVMReplace)));
}
void* do3P = reinterpret_cast<void *>(do3);
InlineHook::instance->BreakPoint(reinterpret_cast<void *>((Addr)do3), breakCallback);
LOGE("ok");
do3(100, 2);
}
extern "C"
EXPORT void* SandGetSym(const char* so, const char* symb) {
......
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