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