Commit 21256c16 authored by swift_gan's avatar swift_gan Committed by swift_gan

[Reconstitution]init

parent 1306c792
...@@ -27,7 +27,7 @@ dependencies { ...@@ -27,7 +27,7 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':hooklib') implementation project(':hooklib')
//implementation project(':nativehook') implementation project(':nativehook')
implementation project(':xposedcompat') implementation project(':xposedcompat')
//implementation project(':xposedcompat_new') //implementation project(':xposedcompat_new')
} }
...@@ -5,6 +5,7 @@ import android.app.Application; ...@@ -5,6 +5,7 @@ import android.app.Application;
import android.os.Build; import android.os.Build;
import android.util.Log; import android.util.Log;
import com.swift.sandhook.nativehook.NativeHook;
import com.swift.sandhook.test.TestClass; import com.swift.sandhook.test.TestClass;
import com.swift.sandhook.testHookers.ActivityHooker; import com.swift.sandhook.testHookers.ActivityHooker;
import com.swift.sandhook.testHookers.CtrHook; import com.swift.sandhook.testHookers.CtrHook;
...@@ -22,7 +23,7 @@ import de.robv.android.xposed.XposedHelpers; ...@@ -22,7 +23,7 @@ import de.robv.android.xposed.XposedHelpers;
public class MyApp extends Application { public class MyApp extends Application {
//if you want test Android Q, please set true, because SDK_INT of Android Q is still 28 //if you want test Android Q, please Set true, because SDK_INT of Android Q is still 28
public final static boolean testAndroidQ = false; public final static boolean testAndroidQ = false;
@Override @Override
...@@ -36,6 +37,8 @@ public class MyApp extends Application { ...@@ -36,6 +37,8 @@ public class MyApp extends Application {
SandHookConfig.SDK_INT = 29; SandHookConfig.SDK_INT = 29;
} }
NativeHook.test();
SandHook.disableVMInline(); SandHook.disableVMInline();
SandHook.tryDisableProfile(getPackageName()); SandHook.tryDisableProfile(getPackageName());
SandHook.disableDex2oatInline(false); SandHook.disableDex2oatInline(false);
......
...@@ -71,6 +71,7 @@ include_directories( ...@@ -71,6 +71,7 @@ include_directories(
src/main/cpp/archs/arm/arm32/decoder src/main/cpp/archs/arm/arm32/decoder
src/main/cpp/archs/arm/arm32/hook src/main/cpp/archs/arm/arm32/hook
src/main/cpp/archs/arm/arm32/relocate src/main/cpp/archs/arm/arm32/relocate
src/main/cpp/antihook
) )
# Searches for a specified prebuilt library and stores the path as a # Searches for a specified prebuilt library and stores the path as a
......
...@@ -17,7 +17,7 @@ android { ...@@ -17,7 +17,7 @@ android {
cmake { cmake {
arguments '-DBUILD_TESTING=OFF' arguments '-DBUILD_TESTING=OFF'
cppFlags "-frtti -fexceptions -Wpointer-arith" cppFlags "-frtti -fexceptions -Wpointer-arith"
abiFilters 'armeabi-v7a', 'arm64-v8a' abiFilters 'arm64-v8a'
} }
} }
} }
......
...@@ -146,7 +146,7 @@ void AssemblerA32::Add(RegisterA32 &rd, RegisterA32 &rn, RegisterA32 &rm) { ...@@ -146,7 +146,7 @@ void AssemblerA32::Add(RegisterA32 &rd, RegisterA32 &rn, RegisterA32 &rm) {
} }
void AssemblerA32::Cmp(RegisterA32 &rd, RegisterA32 &rn) { void AssemblerA32::Cmp(RegisterA32 &rd, RegisterA32 &rn) {
if (rd.getCode() < 8 && rn.getCode() < 8) { if (rd.Code() < 8 && rn.Code() < 8) {
Emit(reinterpret_cast<Unit<Base>*>(new INST_T16(CMP_REG)(rd, rn))); Emit(reinterpret_cast<Unit<Base>*>(new INST_T16(CMP_REG)(rd, rn)));
} else { } else {
Emit(reinterpret_cast<Unit<Base>*>(new INST_T16(CMP_REG_EXT)(rd, rn))); Emit(reinterpret_cast<Unit<Base>*>(new INST_T16(CMP_REG_EXT)(rd, rn)));
...@@ -154,7 +154,7 @@ void AssemblerA32::Cmp(RegisterA32 &rd, RegisterA32 &rn) { ...@@ -154,7 +154,7 @@ void AssemblerA32::Cmp(RegisterA32 &rd, RegisterA32 &rn) {
} }
void AssemblerA32::Pop(RegisterA32 &rt) { void AssemblerA32::Pop(RegisterA32 &rt) {
if (rt.getCode() < 8 || rt == PC) { if (rt.Code() < 8 || rt == PC) {
Emit(reinterpret_cast<Unit<Base>*>(new INST_T16(POP)(RegisterList(rt)))); Emit(reinterpret_cast<Unit<Base>*>(new INST_T16(POP)(RegisterList(rt))));
} else { } else {
throw ErrorCodeException("error pop inst"); throw ErrorCodeException("error pop inst");
...@@ -162,7 +162,7 @@ void AssemblerA32::Pop(RegisterA32 &rt) { ...@@ -162,7 +162,7 @@ void AssemblerA32::Pop(RegisterA32 &rt) {
} }
void AssemblerA32::Push(RegisterA32 &rt) { void AssemblerA32::Push(RegisterA32 &rt) {
if (rt.getCode() < 8 || rt == PC) { if (rt.Code() < 8 || rt == PC) {
Emit(reinterpret_cast<Unit<Base>*>(new INST_T16(PUSH)(RegisterList(rt)))); Emit(reinterpret_cast<Unit<Base>*>(new INST_T16(PUSH)(RegisterList(rt))));
} else { } else {
throw ErrorCodeException("error pop inst"); throw ErrorCodeException("error pop inst");
......
...@@ -23,7 +23,8 @@ goto label_matched; \ ...@@ -23,7 +23,8 @@ goto label_matched; \
Arm32Decoder* Arm32Decoder::instant = new Arm32Decoder(); Arm32Decoder* Arm32Decoder::instant = new Arm32Decoder();
void Arm32Decoder::decode(void *codeStart, Addr codeLen, InstVisitor &visitor, bool onlyPcRelInst) { void Arm32Decoder::Disassembler(void *codeStart, Addr codeLen, InstVisitor &visitor,
bool onlyPcRelInst) {
bool thumb = isThumbCode(reinterpret_cast<Addr>(codeStart)); bool thumb = isThumbCode(reinterpret_cast<Addr>(codeStart));
if (thumb) { if (thumb) {
codeStart = getThumbCodeAddress(codeStart); codeStart = getThumbCodeAddress(codeStart);
...@@ -74,7 +75,7 @@ void Arm32Decoder::decode(void *codeStart, Addr codeLen, InstVisitor &visitor, b ...@@ -74,7 +75,7 @@ void Arm32Decoder::decode(void *codeStart, Addr codeLen, InstVisitor &visitor, b
if (!visitor.visit(unit, pc)) { if (!visitor.visit(unit, pc)) {
break; break;
} }
pc = reinterpret_cast<InstA64 *>((Addr)pc + unit->size()); pc = reinterpret_cast<InstA64 *>((Addr)pc + unit->Size());
unit = nullptr; unit = nullptr;
} }
} }
......
...@@ -12,7 +12,8 @@ namespace SandHook { ...@@ -12,7 +12,8 @@ namespace SandHook {
class Arm32Decoder : public InstDecoder { class Arm32Decoder : public InstDecoder {
public: public:
void decode(void *codeStart, Addr codeLen, InstVisitor &visitor, bool onlyPcRelInst) override; void Disassembler(void *codeStart, Addr codeLen, InstVisitor &visitor,
bool onlyPcRelInst) override;
public: public:
static Arm32Decoder* instant; static Arm32Decoder* instant;
}; };
......
...@@ -17,7 +17,7 @@ using namespace SandHook::Utils; ...@@ -17,7 +17,7 @@ using namespace SandHook::Utils;
#include "assembler_arm32.h" #include "assembler_arm32.h"
using namespace SandHook::RegistersA32; using namespace SandHook::RegistersA32;
void *InlineHookArm32Android::inlineHook(void *origin, void *replace) { void *InlineHookArm32Android::InlineHook(void *origin, void *replace) {
AutoLock lock(hookLock); AutoLock lock(hookLock);
void* originCode; void* originCode;
...@@ -73,7 +73,7 @@ void *InlineHookArm32Android::inlineHook(void *origin, void *replace) { ...@@ -73,7 +73,7 @@ void *InlineHookArm32Android::inlineHook(void *origin, void *replace) {
IMPORT_SHELLCODE(BP_SHELLCODE) IMPORT_SHELLCODE(BP_SHELLCODE)
IMPORT_LABEL(callback_addr_s, Addr) IMPORT_LABEL(callback_addr_s, Addr)
IMPORT_LABEL(origin_addr_s, Addr) IMPORT_LABEL(origin_addr_s, Addr)
bool InlineHookArm32Android::breakPoint(void *origin, void (*callback)(REG *)) { bool InlineHookArm32Android::BreakPoint(void *origin, void (*callback)(REG *)) {
AutoLock lock(hookLock); AutoLock lock(hookLock);
void* originCode; void* originCode;
......
...@@ -18,9 +18,9 @@ namespace SandHook { ...@@ -18,9 +18,9 @@ namespace SandHook {
inline ~InlineHookArm32Android() { inline ~InlineHookArm32Android() {
delete hookLock; delete hookLock;
} }
void *inlineHook(void *origin, void *replace) override; void *InlineHook(void *origin, void *replace) override;
bool breakPoint(void *point, void (*callback)(REG *)) override; bool BreakPoint(void *point, void (*callback)(REG *)) override;
protected: protected:
std::mutex* hookLock; std::mutex* hookLock;
......
...@@ -2,16 +2,15 @@ ...@@ -2,16 +2,15 @@
// Created by swift on 2019/5/16. // Created by swift on 2019/5/16.
// //
#ifndef SANDHOOK_ARM32_BASE_H #pragma once
#define SANDHOOK_ARM32_BASE_H
#include <ostream> #include <ostream>
#include "arm_base.h" #include "arm_base.h"
#include "register_list_arm32.h" #include "register_list_arm32.h"
#include "instruction.h" #include "instruction.h"
#define DECODE_OFFSET(bits, ext) signExtend32(bits + ext, COMBINE(get()->imm##bits, 0, ext)) #define DECODE_OFFSET(bits, ext) SignExtend32(bits + ext, COMBINE(Get()->imm##bits, 0, ext))
#define ENCODE_OFFSET(bits, ext) get()->imm##bits = TruncateToUint##bits(offset >> ext) #define ENCODE_OFFSET(bits, ext) Get()->imm##bits = TruncateToUint##bits(offset >> ext)
#define CODE_OFFSET(I) I->offset + (I->instType() == A32 ? 2 * 4 : 2 * 2) #define CODE_OFFSET(I) I->offset + (I->instType() == A32 ? 2 * 4 : 2 * 2)
...@@ -47,8 +46,8 @@ namespace SandHook { ...@@ -47,8 +46,8 @@ namespace SandHook {
bool IsPostIndex() const { return addr_mode == PostIndex; } bool IsPostIndex() const { return addr_mode == PostIndex; }
public: public:
RegisterA32* rn; // base RegisterA32* rn; // base_
RegisterA32* rm; // register offset RegisterA32* rm; // register offset_
S32 offset; // valid if rm_ == no_reg S32 offset; // valid if rm_ == no_reg
Shift shift; Shift shift;
Sign sign; Sign sign;
...@@ -126,10 +125,10 @@ namespace SandHook { ...@@ -126,10 +125,10 @@ namespace SandHook {
private: private:
static U16 RegisterToList(RegisterA32& reg) { static U16 RegisterToList(RegisterA32& reg) {
if (reg.getCode() == UnknowRegiser.getCode()) { if (reg.Code() == UnknowRegiser.Code()) {
return 0; return 0;
} else { } else {
return static_cast<U16>(UINT16_C(1) << reg.getCode()); return static_cast<U16>(UINT16_C(1) << reg.Code());
} }
} }
...@@ -165,6 +164,4 @@ namespace SandHook { ...@@ -165,6 +164,4 @@ namespace SandHook {
std::ostream& operator<<(std::ostream& os, RegisterList registers); std::ostream& operator<<(std::ostream& os, RegisterList registers);
} }
} }
\ No newline at end of file
#endif //SANDHOOK_ARM32_BASE_H
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
//A64_STR_IMM::A64_STR_IMM() {} //A64_STR_IMM::A64_STR_IMM() {}
// //
//A64_STR_IMM::A64_STR_IMM(STRUCT_A64(STR_IMM) *inst) : InstructionA64(inst) { //A64_STR_IMM::A64_STR_IMM(STRUCT_A64(STR_IMM) *inst) : InstructionA64(inst) {
// decode(inst); // DisAssembler(inst);
//} //}
// //
//A64_STR_IMM::A64_STR_IMM(RegisterA64 &rt, const MemOperand &operand) : rt(&rt), operand(operand) {} //A64_STR_IMM::A64_STR_IMM(RegisterA64 &rt, const MemOperand &operand) : rt(&rt), operand(operand) {}
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
// : condition(condition), rt(&rt), operand(operand) {} // : condition(condition), rt(&rt), operand(operand) {}
// //
//AddrMode A64_STR_IMM::decodeAddrMode() { //AddrMode A64_STR_IMM::decodeAddrMode() {
// if (get()->P == 1 && get()->W == 0) { // if (Get()->P == 1 && Get()->W == 0) {
// return Offset; // return Offset;
// } else if (get()->P == 0 && get()->W == 0) { // } else if (Get()->P == 0 && Get()->W == 0) {
// return PostIndex; // return PostIndex;
// } else if (get()->P == 1 && get()->W == 1) { // } else if (Get()->P == 1 && Get()->W == 1) {
// return PreIndex; // return PreIndex;
// } else { // } else {
// valid = false; // valid = false;
...@@ -29,20 +29,20 @@ ...@@ -29,20 +29,20 @@
// } // }
//} //}
// //
//void A64_STR_IMM::decode(STRUCT_A64(STR_IMM) *inst) { //void A64_STR_IMM::DisAssembler(STRUCT_A64(STR_IMM) *inst) {
// imm32 = zeroExtend32(12, inst->imm12); // imm32 = zeroExtend32(12, inst->imm12);
// condition = Condition(inst->cond); // condition = Condition(inst->cond);
// operand.addr_mode = decodeAddrMode(); // operand.addr_mode_ = decodeAddrMode();
// index = inst->P == 1; // index = inst->P == 1;
// wback = inst->P == 1 || inst->W == 0; // wback = inst->P == 1 || inst->W == 0;
// add = inst->U == 0; // add = inst->U == 0;
// rt = XReg(static_cast<U8>(inst->rt)); // rt = XReg(static_cast<U8>(inst->rt));
// operand.base = XReg(static_cast<U8>(inst->rn)); // operand.base_ = XReg(static_cast<U8>(inst->rn));
// operand.offset = add ? imm32 : -imm32; // operand.offset_ = add ? imm32 : -imm32;
//} //}
// //
// //
//void A64_STR_IMM::assembler() { //void A64_STR_IMM::Assembler() {
// INST_DCHECK(condition, Condition::nv) // INST_DCHECK(condition, Condition::nv)
// //
//} //}
\ No newline at end of file
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
// Created by swift on 2019/5/12. // Created by swift on 2019/5/12.
// //
#ifndef SANDHOOK_NH_INST_ARM32_H #pragma once
#define SANDHOOK_NH_INST_ARM32_H
namespace SandHook { namespace SandHook {
...@@ -20,16 +19,16 @@ namespace SandHook { ...@@ -20,16 +19,16 @@ namespace SandHook {
// //
// DEFINE_IS_EXT(STR_IMM, TEST_INST_FIELD(opcode, OPCODE_A64(STR_IMM)) && TEST_INST_FIELD(unkown1_0, 0) && TEST_INST_FIELD(unkown2_0, 0)) // DEFINE_IS_EXT(STR_IMM, TEST_INST_FIELD(opcode, OPCODE_A64(STR_IMM)) && TEST_INST_FIELD(unkown1_0, 0) && TEST_INST_FIELD(unkown2_0, 0))
// //
// inline U32 instCode() override { // inline U32 InstCode() override {
// return STR_x; // return STR_x;
// } // }
// //
// void decode(STRUCT_A64(STR_IMM) *inst) override; // void DisAssembler(STRUCT_A64(STR_IMM) *inst) override;
// //
// void assembler() override; // void Assembler() override;
// //
// AddrMode getAddrMode() { // AddrMode getAddrMode() {
// return operand.addr_mode; // return operand.addr_mode_;
// } // }
// //
// private: // private:
...@@ -46,6 +45,4 @@ namespace SandHook { ...@@ -46,6 +45,4 @@ namespace SandHook {
// bool index; // bool index;
//}; //};
} }
} }
\ No newline at end of file
#endif //SANDHOOK_NH_INST_ARM32_H
...@@ -2,14 +2,13 @@ ...@@ -2,14 +2,13 @@
// Created by swift on 2019/5/16. // Created by swift on 2019/5/16.
// //
#ifndef SANDHOOK_INST_CODE_ARM32_H #pragma once
#define SANDHOOK_INST_CODE_ARM32_H
enum class InstCodeA32 { enum class InstCodeA32 : InstCode {
}; };
enum class InstCodeT16 { enum class InstCodeT16 : InstCode {
UNKNOW, UNKNOW,
BASE_SASMC, BASE_SASMC,
DATA_PROC, DATA_PROC,
...@@ -33,7 +32,7 @@ enum class InstCodeT16 { ...@@ -33,7 +32,7 @@ enum class InstCodeT16 {
ADD_REG_RDN ADD_REG_RDN
}; };
enum class InstCodeT32 { enum class InstCodeT32 : InstCode {
UNKNOW, UNKNOW,
B32, B32,
LDR_LIT, LDR_LIT,
...@@ -41,6 +40,4 @@ enum class InstCodeT32 { ...@@ -41,6 +40,4 @@ enum class InstCodeT32 {
LDR_UIMM, LDR_UIMM,
MOV_MOVT_IMM, MOV_MOVT_IMM,
SUB_IMM, SUB_IMM,
}; };
\ No newline at end of file
#endif //SANDHOOK_INST_CODE_ARM32_H
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
// Created by swift on 2019/5/12. // Created by swift on 2019/5/12.
// //
#ifndef SANDHOOK_NH_INST_STRUCT_ARM32_H #pragma once
#define SANDHOOK_NH_INST_STRUCT_ARM32_H
#include "instruction.h" #include "instruction.h"
...@@ -26,7 +25,4 @@ DEFINE_STRUCT_A32(STR_IMM) { ...@@ -26,7 +25,4 @@ DEFINE_STRUCT_A32(STR_IMM) {
InstA64 P:1; InstA64 P:1;
InstA64 opcode:3; InstA64 opcode:3;
InstA64 cond:4; InstA64 cond:4;
}; };
\ No newline at end of file
#endif //SANDHOOK_NH_INST_STRCUT_ARM32_H
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
// Created by swift on 2019/5/12. // Created by swift on 2019/5/12.
// //
#ifndef SANDHOOK_NH_INST_STRUCT_T16_H #pragma once
#define SANDHOOK_NH_INST_STRUCT_T16_H
#include "instruction.h" #include "instruction.h"
#include "inst_code_arm32.h" #include "inst_code_arm32.h"
...@@ -19,7 +17,7 @@ ...@@ -19,7 +17,7 @@
InstT16 opcode_base:w_base; InstT16 opcode_base:w_base;
//Shift (immediate), add, subtract, move, and compare //Shift (immediate_), add, subtract, Move, and compare
//opcode_base == 0b00 //opcode_base == 0b00
DEFINE_OPCODE_T16(BASE_SASMC, 0b00) DEFINE_OPCODE_T16(BASE_SASMC, 0b00)
//Data-processing //Data-processing
...@@ -34,7 +32,7 @@ DEFINE_OPCODE_T16(MISC, 0b1011) ...@@ -34,7 +32,7 @@ DEFINE_OPCODE_T16(MISC, 0b1011)
#define T16_REG_WIDE 3 #define T16_REG_WIDE 3
//unknow inst //Unknow inst
DEFINE_STRUCT_T16(UNKNOW) { DEFINE_STRUCT_T16(UNKNOW) {
InstT16 raw; InstT16 raw;
}; };
...@@ -156,7 +154,4 @@ DEFINE_STRUCT_T16(PUSH) { ...@@ -156,7 +154,4 @@ DEFINE_STRUCT_T16(PUSH) {
InstT16 regs:8; InstT16 regs:8;
InstT16 M:1; InstT16 M:1;
InstT16 opcode:7; InstT16 opcode:7;
}; };
\ No newline at end of file
#endif //SANDHOOK_NH_INST_STRUCT_T16_H
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
// Created by swift on 2019/5/12. // Created by swift on 2019/5/12.
// //
#ifndef SANDHOOK_NH_INST_STRUCT_T32_H #pragma once
#define SANDHOOK_NH_INST_STRUCT_T32_H
#include "instruction.h" #include "instruction.h"
...@@ -16,7 +15,7 @@ ...@@ -16,7 +15,7 @@
#define T32_REG_WIDE 4 #define T32_REG_WIDE 4
//unknow inst //Unknow inst
DEFINE_STRUCT_T32(UNKNOW) { DEFINE_STRUCT_T32(UNKNOW) {
InstT32 raw; InstT32 raw;
}; };
...@@ -96,5 +95,3 @@ DEFINE_STRUCT_T32(SUB_IMM) { ...@@ -96,5 +95,3 @@ DEFINE_STRUCT_T32(SUB_IMM) {
InstT32 imm3:3; InstT32 imm3:3;
InstT32 opcode2:1; InstT32 opcode2:1;
}; };
#endif //SANDHOOK_NH_INST_STRUCT_T32_H
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
// Created by swift on 2019/5/16. // Created by swift on 2019/5/16.
// //
#ifndef SANDHOOK_INST_T16_H #pragma once
#define SANDHOOK_INST_T16_H
#include "arm_base.h" #include "arm_base.h"
#include "register_list_arm32.h" #include "register_list_arm32.h"
...@@ -13,10 +12,10 @@ ...@@ -13,10 +12,10 @@
#define INST_T16(X) T16_##X #define INST_T16(X) T16_##X
#define IS_OPCODE_T16(RAW, OP) INST_T16(OP)::is(RAW) #define IS_OPCODE_T16(RAW, OP) INST_T16(OP)::Is(RAW)
#define DEFINE_IS_EXT(X, COND) \ #define DEFINE_IS_EXT(X, COND) \
inline static bool is(InstT16& inst) { \ inline static bool Is(InstT16& inst) { \
union { \ union { \
InstT16 raw; \ InstT16 raw; \
STRUCT_T16(X) inst; \ STRUCT_T16(X) inst; \
...@@ -44,62 +43,52 @@ namespace SandHook { ...@@ -44,62 +43,52 @@ namespace SandHook {
namespace AsmA32 { namespace AsmA32 {
template<typename Inst> template<typename S, U32 C>
class InstructionT16 : public Instruction<Inst> { class InstructionT16 : public Instruction<S,C> {
public: public:
InstructionT16() {} InstructionT16() {}
InstructionT16(Inst *inst) : Instruction<Inst>(inst) {} InstructionT16(void *inst) : Instruction<S,C>(inst) {}
Inst mask(Inst raw) { INLINE U32 Size() override {
return raw & *(this->get());
}
U32 size() override {
return 2; return 2;
} }
void *getPC() override { INLINE void *GetPC() override {
return reinterpret_cast<void *>((Addr) Instruction<Inst>::getPC() + 2 * 2); return reinterpret_cast<void *>((Addr) Instruction<S,C>::GetPC() + 2 * 2);
}
Addr getVPC() override {
return Instruction<Inst>::getVPC() + 2 * 2;
} }
static inline S32 signExtend32(unsigned int bits, U32 value) { INLINE Addr GetVPC() override {
return ExtractSignedBitfield32(bits - 1, 0, value); return Instruction<S,C>::GetVPC() + 2 * 2;
} }
InstType instType() override { INLINE InstType InstType() override {
return thumb16; return thumb16;
} }
Arch arch() override { INLINE Arch Arch() override {
return arm32; return arm32;
} }
}; };
template<typename Inst> template<typename S,U32 C>
class T16_INST_PC_REL : public InstructionT16<Inst> { class T16_INST_PC_REL : public InstructionT16<S,C> {
public: public:
T16_INST_PC_REL() {}; T16_INST_PC_REL(void *inst) : InstructionT16<S,C>(inst) {};
T16_INST_PC_REL(Inst *inst) : InstructionT16<Inst>(inst) {}; INLINE virtual Off GetImmPCOffset() {
virtual Off getImmPCOffset() {
return 0; return 0;
}; };
virtual Addr getImmPCOffsetTarget() { INLINE virtual Addr GetImmPCOffsetTarget() {
return (Addr) this->getPC() + getImmPCOffset(); return (Addr) this->GetPC() + GetImmPCOffset();
}; };
inline bool pcRelate() override { INLINE bool PcRelate() override {
return true; return true;
}; };
...@@ -111,15 +100,13 @@ namespace SandHook { ...@@ -111,15 +100,13 @@ namespace SandHook {
T16_UNKNOW(STRUCT_T16(UNKNOW) &inst); T16_UNKNOW(STRUCT_T16(UNKNOW) &inst);
DEFINE_INST_CODE(UNKNOW)
inline bool unknow() override { inline bool unknow() override {
return true; return true;
} }
void decode(T16_STRUCT_UNKNOW *inst) override; void Disassembler(T16_STRUCT_UNKNOW *inst) override;
void assembler() override; void Assembler() override;
private: private:
STRUCT_T16(UNKNOW) inst_backup; STRUCT_T16(UNKNOW) inst_backup;
...@@ -140,13 +127,13 @@ namespace SandHook { ...@@ -140,13 +127,13 @@ namespace SandHook {
DEFINE_INST_CODE(B) DEFINE_INST_CODE(B)
void onOffsetApply(Off offset) override; void OnOffsetApply(Off offset) override;
Off getImmPCOffset() override; Off GetImmPCOffset() override;
void decode(STRUCT_T16(B) *inst) override; void Disassembler(STRUCT_T16(B) *inst) override;
void assembler() override; void Assembler() override;
public: public:
Off offset; Off offset;
...@@ -167,13 +154,13 @@ namespace SandHook { ...@@ -167,13 +154,13 @@ namespace SandHook {
DEFINE_INST_CODE(B_COND) DEFINE_INST_CODE(B_COND)
Off getImmPCOffset() override; Off GetImmPCOffset() override;
void onOffsetApply(Off offset) override; void OnOffsetApply(Off offset) override;
void decode(STRUCT_T16(B_COND) *inst) override; void Disassembler(STRUCT_T16(B_COND) *inst) override;
void assembler() override; void Assembler() override;
public: public:
Condition condition; Condition condition;
...@@ -197,9 +184,9 @@ namespace SandHook { ...@@ -197,9 +184,9 @@ namespace SandHook {
DEFINE_INST_CODE(BX_BLX) DEFINE_INST_CODE(BX_BLX)
void decode(T16_STRUCT_BX_BLX *inst) override; void Disassembler(T16_STRUCT_BX_BLX *inst) override;
void assembler() override; void Assembler() override;
public: public:
OP op; OP op;
...@@ -226,13 +213,13 @@ namespace SandHook { ...@@ -226,13 +213,13 @@ namespace SandHook {
DEFINE_INST_CODE(CBZ_CBNZ) DEFINE_INST_CODE(CBZ_CBNZ)
void onOffsetApply(Off offset) override; void OnOffsetApply(Off offset) override;
Off getImmPCOffset() override; Off GetImmPCOffset() override;
void decode(T16_STRUCT_CBZ_CBNZ *inst) override; void Disassembler(T16_STRUCT_CBZ_CBNZ *inst) override;
void assembler() override; void Assembler() override;
public: public:
OP op; OP op;
...@@ -251,15 +238,15 @@ namespace SandHook { ...@@ -251,15 +238,15 @@ namespace SandHook {
DEFINE_INST_CODE(LDR_LIT) DEFINE_INST_CODE(LDR_LIT)
Addr getImmPCOffsetTarget() override; Addr GetImmPCOffsetTarget() override;
Off getImmPCOffset() override; Off GetImmPCOffset() override;
void onOffsetApply(Off offset) override; void OnOffsetApply(Off offset) override;
void decode(T16_STRUCT_LDR_LIT *inst) override; void Disassembler(T16_STRUCT_LDR_LIT *inst) override;
void assembler() override; void Assembler() override;
public: public:
Off offset; Off offset;
...@@ -277,9 +264,9 @@ namespace SandHook { ...@@ -277,9 +264,9 @@ namespace SandHook {
DEFINE_INST_CODE(ADD_IMM_RDN) DEFINE_INST_CODE(ADD_IMM_RDN)
void decode(T16_STRUCT_ADD_IMM_RDN *inst) override; void Disassembler(T16_STRUCT_ADD_IMM_RDN *inst) override;
void assembler() override; void Assembler() override;
public: public:
RegisterA32 *rdn; RegisterA32 *rdn;
...@@ -299,15 +286,15 @@ namespace SandHook { ...@@ -299,15 +286,15 @@ namespace SandHook {
DEFINE_INST_CODE(ADR) DEFINE_INST_CODE(ADR)
Off getImmPCOffset() override; Off GetImmPCOffset() override;
Addr getImmPCOffsetTarget() override; Addr GetImmPCOffsetTarget() override;
void onOffsetApply(Off offset) override; void OnOffsetApply(Off offset) override;
void decode(T16_STRUCT_ADR *inst) override; void Disassembler(T16_STRUCT_ADR *inst) override;
void assembler() override; void Assembler() override;
public: public:
RegisterA32 *rd; RegisterA32 *rd;
...@@ -328,9 +315,9 @@ namespace SandHook { ...@@ -328,9 +315,9 @@ namespace SandHook {
DEFINE_IS_EXT(CMP_REG, TEST_INST_FIELD(opcode_base, OPCODE_T16(DATA_PROC)) && DEFINE_IS_EXT(CMP_REG, TEST_INST_FIELD(opcode_base, OPCODE_T16(DATA_PROC)) &&
TEST_INST_FIELD(opcode, OPCODE_T16(CMP_REG))) TEST_INST_FIELD(opcode, OPCODE_T16(CMP_REG)))
void decode(T16_STRUCT_CMP_REG *inst) override; void Disassembler(T16_STRUCT_CMP_REG *inst) override;
void assembler() override; void Assembler() override;
public: public:
RegisterA32 *rm; RegisterA32 *rm;
...@@ -350,9 +337,9 @@ namespace SandHook { ...@@ -350,9 +337,9 @@ namespace SandHook {
DEFINE_IS_EXT(MOV_REG, TEST_INST_FIELD(opcode_base, OPCODE_T16(DATA_PROC)) && DEFINE_IS_EXT(MOV_REG, TEST_INST_FIELD(opcode_base, OPCODE_T16(DATA_PROC)) &&
TEST_INST_FIELD(opcode, OPCODE_T16(MOV_REG))) TEST_INST_FIELD(opcode, OPCODE_T16(MOV_REG)))
void decode(T16_STRUCT_MOV_REG *inst) override; void Disassembler(T16_STRUCT_MOV_REG *inst) override;
void assembler() override; void Assembler() override;
bool pcRelate() override; bool pcRelate() override;
...@@ -374,9 +361,9 @@ namespace SandHook { ...@@ -374,9 +361,9 @@ namespace SandHook {
DEFINE_INST_CODE(ADD_REG) DEFINE_INST_CODE(ADD_REG)
void decode(T16_STRUCT_ADD_REG *inst) override; void Disassembler(T16_STRUCT_ADD_REG *inst) override;
void assembler() override; void Assembler() override;
public: public:
RegisterA32 *rd; RegisterA32 *rd;
...@@ -396,9 +383,9 @@ namespace SandHook { ...@@ -396,9 +383,9 @@ namespace SandHook {
DEFINE_INST_CODE(CMP_REG_EXT) DEFINE_INST_CODE(CMP_REG_EXT)
void decode(T16_STRUCT_CMP_REG_EXT *inst) override; void Disassembler(T16_STRUCT_CMP_REG_EXT *inst) override;
void assembler() override; void Assembler() override;
public: public:
...@@ -417,9 +404,9 @@ namespace SandHook { ...@@ -417,9 +404,9 @@ namespace SandHook {
DEFINE_INST_CODE(POP) DEFINE_INST_CODE(POP)
void decode(T16_STRUCT_POP *inst) override; void Disassembler(T16_STRUCT_POP *inst) override;
void assembler() override; void Assembler() override;
public: public:
RegisterList registerList; RegisterList registerList;
...@@ -436,9 +423,9 @@ namespace SandHook { ...@@ -436,9 +423,9 @@ namespace SandHook {
DEFINE_INST_CODE(PUSH) DEFINE_INST_CODE(PUSH)
void decode(T16_STRUCT_PUSH *inst) override; void Disassembler(T16_STRUCT_PUSH *inst) override;
void assembler() override; void Assembler() override;
public: public:
RegisterList registerList; RegisterList registerList;
...@@ -459,9 +446,9 @@ namespace SandHook { ...@@ -459,9 +446,9 @@ namespace SandHook {
bool pcRelate() override; bool pcRelate() override;
void decode(T16_STRUCT_ADD_REG_RDN *inst) override; void Disassembler(T16_STRUCT_ADD_REG_RDN *inst) override;
void assembler() override; void Assembler() override;
public: public:
RegisterA32* rdn; RegisterA32* rdn;
...@@ -475,6 +462,4 @@ namespace SandHook { ...@@ -475,6 +462,4 @@ namespace SandHook {
#undef DEFINE_IS #undef DEFINE_IS
#undef TEST_INST_FIELD #undef TEST_INST_FIELD
#undef TEST_INST_OPCODE #undef TEST_INST_OPCODE
#undef DEFINE_INST_CODE #undef DEFINE_INST_CODE
\ No newline at end of file
#endif //SANDHOOK_INST_T16_H
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
#include "inst_struct_t32.h" #include "inst_struct_t32.h"
#define SET_BASE_OPCODE(X) get()->opcode_base = OPCODE_T32(X) #define SET_BASE_OPCODE(X) Get()->opcode_base = OPCODE_T32(X)
#define SET_OPCODE(X) get()->opcode = OPCODE_T32(X) #define SET_OPCODE(X) Get()->opcode = OPCODE_T32(X)
#define SET_OPCODE_MULTI(X, INDEX) get()->opcode##INDEX = OPCODE_T32(X##_##INDEX) #define SET_OPCODE_MULTI(X, INDEX) Get()->opcode##INDEX = OPCODE_T32(X##_##INDEX)
using namespace SandHook::Asm; using namespace SandHook::Asm;
using namespace SandHook::AsmA32; using namespace SandHook::AsmA32;
...@@ -19,78 +19,78 @@ using namespace SandHook::AsmA32; ...@@ -19,78 +19,78 @@ using namespace SandHook::AsmA32;
//Unknow //Unknow
T32_UNKNOW::T32_UNKNOW(STRUCT_T32(UNKNOW) &inst) : InstructionT32(&inst) { T32_UNKNOW::T32_UNKNOW(STRUCT_T32(UNKNOW) &inst) : InstructionT32(&inst) {
decode(&inst); Disassembler(&inst);
} }
void T32_UNKNOW::decode(T32_STRUCT_UNKNOW *inst) { void T32_UNKNOW::Disassembler(T32_STRUCT_UNKNOW *inst) {
inst_backup = *inst; inst_backup = *inst;
} }
void T32_UNKNOW::assembler() { void T32_UNKNOW::Assembler() {
set(inst_backup); Set(inst_backup);
} }
T32_B32::T32_B32(T32_STRUCT_B32 *inst) : T32_INST_PC_REL(inst) { T32_B32::T32_B32(T32_STRUCT_B32 *inst) : T32_INST_PC_REL(inst) {
decode(inst); Disassembler(inst);
} }
T32_B32::T32_B32(T32_B32::OP op, T32_B32::X x, Off offset) : op(op), x(x), offset(offset) {} T32_B32::T32_B32(T32_B32::OP op, T32_B32::X x, Off offset) : op(op), x(x), offset(offset) {}
T32_B32::T32_B32(T32_B32::OP op, T32_B32::X x, Label &label) : op(op), x(x) { T32_B32::T32_B32(T32_B32::OP op, T32_B32::X x, Label &label) : op(op), x(x) {
bindLabel(label); BindLabel(label);
} }
Off T32_B32::getImmPCOffset() { Off T32_B32::GetImmPCOffset() {
U32 S = get()->S; U32 S = Get()->S;
U32 imm21 = COMBINE(get()->imm10, get()->imm11, 11); U32 imm21 = COMBINE(Get()->imm10, Get()->imm11, 11);
if (get()->X == 0 && op == BL) { if (Get()->X == 0 && op == BL) {
imm21 &= ~(1 << 0); imm21 &= ~(1 << 0);
} }
U32 i1 = !(get()->J1 ^ S); U32 i1 = !(Get()->J1 ^ S);
U32 i2 = !(get()->J2 ^ S); U32 i2 = !(Get()->J2 ^ S);
U32 i1i2 = COMBINE(i1, i2, 1); U32 i1i2 = COMBINE(i1, i2, 1);
U32 Si1i2 = COMBINE(-S, i1i2, 2); U32 Si1i2 = COMBINE(-S, i1i2, 2);
return signExtend32(25, COMBINE(Si1i2, imm21, 21) << 1); return SignExtend32(25, COMBINE(Si1i2, imm21, 21) << 1);
} }
void T32_B32::decode(T32_STRUCT_B32 *inst) { void T32_B32::Disassembler(T32_STRUCT_B32 *inst) {
DECODE_OP; DECODE_OP;
x = X(inst->X); x = X(inst->X);
offset = getImmPCOffset(); offset = GetImmPCOffset();
} }
void T32_B32::assembler() { void T32_B32::Assembler() {
SET_OPCODE(B32); SET_OPCODE(B32);
ENCODE_OP; ENCODE_OP;
get()->X = x; Get()->X = x;
U32 imm24 = TruncateToUint25(offset) >> 1; U32 imm24 = TruncateToUint25(offset) >> 1;
get()->imm11 = BITS(imm24, 0, 10); Get()->imm11 = BITS(imm24, 0, 10);
get()->imm10 = BITS(imm24, 11, 20); Get()->imm10 = BITS(imm24, 11, 20);
if (get()->X == 0) { if (Get()->X == 0) {
get()->imm11 |= (1 << 0); Get()->imm11 |= (1 << 0);
} }
get()->S = BIT(imm24, 23); Get()->S = BIT(imm24, 23);
U32 i1 = BIT(imm24, 22); U32 i1 = BIT(imm24, 22);
U32 i2 = BIT(imm24, 21); U32 i2 = BIT(imm24, 21);
if (i1 == 1) { if (i1 == 1) {
get()->J1 = get()->S; Get()->J1 = Get()->S;
} else { } else {
get()->J1 = !get()->S; Get()->J1 = !Get()->S;
} }
if (i2 == 1) { if (i2 == 1) {
get()->J2 = get()->S; Get()->J2 = Get()->S;
} else { } else {
get()->J2 = !get()->S; Get()->J2 = !Get()->S;
} }
} }
Addr T32_B32::getImmPCOffsetTarget() { Addr T32_B32::GetImmPCOffsetTarget() {
if (x == arm && op == BL) { if (x == arm && op == BL) {
void* base = reinterpret_cast<void *>(ALIGN((Addr) getPC(), 4)); void* base = reinterpret_cast<void *>(ALIGN((Addr) getPC(), 4));
return offset + reinterpret_cast<Addr>(base); return offset + reinterpret_cast<Addr>(base);
} else { } else {
return T32_INST_PC_REL::getImmPCOffsetTarget(); return T32_INST_PC_REL::GetImmPCOffsetTarget();
} }
} }
...@@ -100,67 +100,67 @@ T32_LDR_UIMM::T32_LDR_UIMM(T32_STRUCT_LDR_UIMM *inst) : InstructionT32(inst) {} ...@@ -100,67 +100,67 @@ T32_LDR_UIMM::T32_LDR_UIMM(T32_STRUCT_LDR_UIMM *inst) : InstructionT32(inst) {}
T32_LDR_UIMM::T32_LDR_UIMM(RegisterA32 &rt, RegisterA32 &rn, U32 offset) : rt(&rt), rn(&rn), T32_LDR_UIMM::T32_LDR_UIMM(RegisterA32 &rt, RegisterA32 &rn, U32 offset) : rt(&rt), rn(&rn),
offset(offset) {} offset(offset) {}
void T32_LDR_UIMM::decode(T32_STRUCT_LDR_UIMM *inst) { void T32_LDR_UIMM::Disassembler(T32_STRUCT_LDR_UIMM *inst) {
DECODE_RN(Reg); DECODE_RN(Reg);
DECODE_RT(Reg); DECODE_RT(Reg);
INST_ASSERT(rn == &PC); INST_ASSERT(rn == &PC);
offset = inst->imm12; offset = inst->imm12;
} }
void T32_LDR_UIMM::assembler() { void T32_LDR_UIMM::Assembler() {
SET_OPCODE(LDR_UIMM); SET_OPCODE(LDR_UIMM);
ENCODE_RN; ENCODE_RN;
ENCODE_RT; ENCODE_RT;
INST_ASSERT(rn == &PC); INST_ASSERT(rn == &PC);
get()->imm12 = offset; Get()->imm12 = offset;
} }
T32_LDR_LIT::T32_LDR_LIT() {} T32_LDR_LIT::T32_LDR_LIT() {}
T32_LDR_LIT::T32_LDR_LIT(T32_STRUCT_LDR_LIT *inst) : T32_INST_PC_REL(inst) { T32_LDR_LIT::T32_LDR_LIT(T32_STRUCT_LDR_LIT *inst) : T32_INST_PC_REL(inst) {
decode(inst); Disassembler(inst);
} }
T32_LDR_LIT::T32_LDR_LIT(OP op, S s, RegisterA32 &rt, Off offset) : op(op), s(s), rt(&rt), offset(offset) {} T32_LDR_LIT::T32_LDR_LIT(OP op, S s, RegisterA32 &rt, Off offset) : op(op), s(s), rt(&rt), offset(offset) {}
T32_LDR_LIT::T32_LDR_LIT(OP op, S s, RegisterA32 &rt, Label& label) : op(op), s(s), rt(&rt) { T32_LDR_LIT::T32_LDR_LIT(OP op, S s, RegisterA32 &rt, Label& label) : op(op), s(s), rt(&rt) {
bindLabel(label); BindLabel(label);
} }
Off T32_LDR_LIT::getImmPCOffset() { Off T32_LDR_LIT::GetImmPCOffset() {
return get()->U == add ? get()->imm12 : -get()->imm12; return Get()->U == add ? Get()->imm12 : -Get()->imm12;
} }
void T32_LDR_LIT::onOffsetApply(Off offset) { void T32_LDR_LIT::OnOffsetApply(Off offset) {
this->offset = offset; this->offset = offset;
if (offset >= 0) { if (offset >= 0) {
get()->U = add; Get()->U = add;
get()->imm12 = static_cast<InstT32>(offset); Get()->imm12 = static_cast<InstT32>(offset);
} else { } else {
get()->U = cmp; Get()->U = cmp;
get()->imm12 = static_cast<InstT32>(-offset); Get()->imm12 = static_cast<InstT32>(-offset);
} }
} }
void T32_LDR_LIT::decode(T32_STRUCT_LDR_LIT *inst) { void T32_LDR_LIT::Disassembler(T32_STRUCT_LDR_LIT *inst) {
DECODE_OP; DECODE_OP;
DECODE_RT(Reg); DECODE_RT(Reg);
s = S(inst->S); s = S(inst->S);
offset = getImmPCOffset(); offset = GetImmPCOffset();
} }
void T32_LDR_LIT::assembler() { void T32_LDR_LIT::Assembler() {
SET_OPCODE(LDR_LIT); SET_OPCODE(LDR_LIT);
ENCODE_OP; ENCODE_OP;
ENCODE_RT; ENCODE_RT;
get()->S = s; Get()->S = s;
if (offset >= 0) { if (offset >= 0) {
get()->U = add; Get()->U = add;
get()->imm12 = static_cast<InstT32>(offset); Get()->imm12 = static_cast<InstT32>(offset);
} else { } else {
get()->U = cmp; Get()->U = cmp;
get()->imm12 = static_cast<InstT32>(-offset); Get()->imm12 = static_cast<InstT32>(-offset);
} }
} }
...@@ -168,14 +168,14 @@ void T32_LDR_LIT::assembler() { ...@@ -168,14 +168,14 @@ void T32_LDR_LIT::assembler() {
T32_MOV_MOVT_IMM::T32_MOV_MOVT_IMM() {} T32_MOV_MOVT_IMM::T32_MOV_MOVT_IMM() {}
T32_MOV_MOVT_IMM::T32_MOV_MOVT_IMM(T32_STRUCT_MOV_MOVT_IMM *inst) : InstructionT32(inst) { T32_MOV_MOVT_IMM::T32_MOV_MOVT_IMM(T32_STRUCT_MOV_MOVT_IMM *inst) : InstructionT32(inst) {
decode(inst); Disassembler(inst);
} }
T32_MOV_MOVT_IMM::T32_MOV_MOVT_IMM(T32_MOV_MOVT_IMM::OP op, RegisterA32 &rd, U16 imm16) : op(op), T32_MOV_MOVT_IMM::T32_MOV_MOVT_IMM(T32_MOV_MOVT_IMM::OP op, RegisterA32 &rd, U16 imm16) : op(op),
rd(&rd), rd(&rd),
imm16(imm16) {} imm16(imm16) {}
void T32_MOV_MOVT_IMM::decode(T32_STRUCT_MOV_MOVT_IMM *inst) { void T32_MOV_MOVT_IMM::Disassembler(T32_STRUCT_MOV_MOVT_IMM *inst) {
DECODE_OP; DECODE_OP;
DECODE_RD(Reg); DECODE_RD(Reg);
U16 imm4i = COMBINE(inst->imm4, inst->i, 1); U16 imm4i = COMBINE(inst->imm4, inst->i, 1);
...@@ -183,27 +183,27 @@ void T32_MOV_MOVT_IMM::decode(T32_STRUCT_MOV_MOVT_IMM *inst) { ...@@ -183,27 +183,27 @@ void T32_MOV_MOVT_IMM::decode(T32_STRUCT_MOV_MOVT_IMM *inst) {
imm16 = COMBINE(imm4i, imm38, 11); imm16 = COMBINE(imm4i, imm38, 11);
} }
void T32_MOV_MOVT_IMM::assembler() { void T32_MOV_MOVT_IMM::Assembler() {
SET_OPCODE_MULTI(MOV_MOVT_IMM, 1); SET_OPCODE_MULTI(MOV_MOVT_IMM, 1);
SET_OPCODE_MULTI(MOV_MOVT_IMM, 2); SET_OPCODE_MULTI(MOV_MOVT_IMM, 2);
ENCODE_OP; ENCODE_OP;
ENCODE_RD; ENCODE_RD;
get()->imm8 = BITS(imm16, 0, 7); Get()->imm8 = BITS(imm16, 0, 7);
get()->imm3 = BITS(imm16, 8 ,10); Get()->imm3 = BITS(imm16, 8 ,10);
get()->i = BIT(imm16, 11); Get()->i = BIT(imm16, 11);
get()->imm4 = BITS(imm16, 12, 15); Get()->imm4 = BITS(imm16, 12, 15);
} }
T32_LDR_IMM::T32_LDR_IMM(T32_STRUCT_LDR_IMM *inst) : InstructionT32(inst) { T32_LDR_IMM::T32_LDR_IMM(T32_STRUCT_LDR_IMM *inst) : InstructionT32(inst) {
decode(inst); Disassembler(inst);
} }
T32_LDR_IMM::T32_LDR_IMM(T32_LDR_IMM::OP op, RegisterA32 &rt, const MemOperand &operand) : op(op), T32_LDR_IMM::T32_LDR_IMM(T32_LDR_IMM::OP op, RegisterA32 &rt, const MemOperand &operand) : op(op),
rt(&rt), rt(&rt),
operand(operand) {} operand(operand) {}
void T32_LDR_IMM::decode(T32_STRUCT_LDR_IMM *inst) { void T32_LDR_IMM::Disassembler(T32_STRUCT_LDR_IMM *inst) {
DECODE_OP; DECODE_OP;
DECODE_RT(Reg); DECODE_RT(Reg);
operand.rn = Reg(static_cast<U8>(inst->rn)); operand.rn = Reg(static_cast<U8>(inst->rn));
...@@ -219,31 +219,31 @@ void T32_LDR_IMM::decode(T32_STRUCT_LDR_IMM *inst) { ...@@ -219,31 +219,31 @@ void T32_LDR_IMM::decode(T32_STRUCT_LDR_IMM *inst) {
operand.offset = inst->U == 0 ? -inst->imm8 : inst->imm8; operand.offset = inst->U == 0 ? -inst->imm8 : inst->imm8;
} }
void T32_LDR_IMM::assembler() { void T32_LDR_IMM::Assembler() {
SET_OPCODE_MULTI(LDR_IMM, 1); SET_OPCODE_MULTI(LDR_IMM, 1);
SET_OPCODE_MULTI(LDR_IMM, 2); SET_OPCODE_MULTI(LDR_IMM, 2);
ENCODE_OP; ENCODE_OP;
get()->rn = operand.rn->getCode(); Get()->rn = operand.rn->Code();
if (operand.offset < 0) { if (operand.offset < 0) {
get()->imm8 = static_cast<InstT32>(-operand.offset); Get()->imm8 = static_cast<InstT32>(-operand.offset);
get()->U = 0; Get()->U = 0;
} else { } else {
get()->imm8 = static_cast<InstT32>(operand.offset); Get()->imm8 = static_cast<InstT32>(operand.offset);
get()->U = 1; Get()->U = 1;
} }
switch (operand.addr_mode) { switch (operand.addr_mode) {
case Offset: case Offset:
get()->P = 1; Get()->P = 1;
get()->U = 0; Get()->U = 0;
get()->W = 0; Get()->W = 0;
break; break;
case PostIndex: case PostIndex:
get()->P = 0; Get()->P = 0;
get()->W = 1; Get()->W = 1;
break; break;
case PreIndex: case PreIndex:
get()->P = 1; Get()->P = 1;
get()->W = 1; Get()->W = 1;
break; break;
default: default:
valid = false; valid = false;
...@@ -253,5 +253,5 @@ void T32_LDR_IMM::assembler() { ...@@ -253,5 +253,5 @@ void T32_LDR_IMM::assembler() {
T32_SUB_IMM::T32_SUB_IMM(T32_STRUCT_SUB_IMM *inst) : InstructionT32(inst) { T32_SUB_IMM::T32_SUB_IMM(T32_STRUCT_SUB_IMM *inst) : InstructionT32(inst) {
decode(inst); DisAssembler(inst);
} }
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Created by swift on 2019/5/16. // Created by swift on 2019/5/16.
// //
#ifndef SANDHOOK_INST_T32_H #pragma once
#define SANDHOOK_INST_T32_H
#include "arm_base.h" #include "arm_base.h"
#include "arm32_base.h" #include "arm32_base.h"
...@@ -54,7 +54,7 @@ namespace SandHook { ...@@ -54,7 +54,7 @@ namespace SandHook {
InstructionT32(Inst *inst) : Instruction<Inst>(inst) {} InstructionT32(Inst *inst) : Instruction<Inst>(inst) {}
Inst mask(Inst raw) { Inst mask(Inst raw) {
return raw & *(this->get()); return raw & *(this->Get());
} }
U32 size() override { U32 size() override {
...@@ -62,14 +62,14 @@ namespace SandHook { ...@@ -62,14 +62,14 @@ namespace SandHook {
} }
void *getPC() override { void *getPC() override {
return reinterpret_cast<void *>((Addr) Instruction<Inst>::getPC() + 2 * 2); return reinterpret_cast<void *>((Addr) Instruction<Inst>::GetPC() + 2 * 2);
} }
Addr getVPC() override { Addr getVPC() override {
return Instruction<Inst>::getVPC() + 2 * 2; return Instruction<Inst>::GetVPC() + 2 * 2;
} }
static inline S32 signExtend32(unsigned int bits, U32 value) { static inline S32 SignExtend32(unsigned int bits, U32 value) {
return ExtractSignedBitfield32(bits - 1, 0, value); return ExtractSignedBitfield32(bits - 1, 0, value);
} }
...@@ -92,12 +92,12 @@ namespace SandHook { ...@@ -92,12 +92,12 @@ namespace SandHook {
T32_INST_PC_REL(Inst *inst) : InstructionT32<Inst>(inst) {}; T32_INST_PC_REL(Inst *inst) : InstructionT32<Inst>(inst) {};
virtual Off getImmPCOffset() { virtual Off GetImmPCOffset() {
return 0; return 0;
}; };
virtual Addr getImmPCOffsetTarget() { virtual Addr GetImmPCOffsetTarget() {
return (Addr) this->getPC() + getImmPCOffset(); return (Addr) this->GetPC() + GetImmPCOffset();
}; };
inline bool pcRelate() override { inline bool pcRelate() override {
...@@ -118,9 +118,9 @@ namespace SandHook { ...@@ -118,9 +118,9 @@ namespace SandHook {
return true; return true;
} }
void decode(T32_STRUCT_UNKNOW *inst) override; void Disassembler(T32_STRUCT_UNKNOW *inst) override;
void assembler() override; void Assembler() override;
private: private:
STRUCT_T32(UNKNOW) inst_backup; STRUCT_T32(UNKNOW) inst_backup;
...@@ -150,13 +150,13 @@ namespace SandHook { ...@@ -150,13 +150,13 @@ namespace SandHook {
DEFINE_IS_EXT(B32, TEST_INST_FIELD(opcode, OPCODE_T32(B32)) && (TEST_INST_FIELD(op, B) || TEST_INST_FIELD(op, BL))) DEFINE_IS_EXT(B32, TEST_INST_FIELD(opcode, OPCODE_T32(B32)) && (TEST_INST_FIELD(op, B) || TEST_INST_FIELD(op, BL)))
Addr getImmPCOffsetTarget() override; Addr GetImmPCOffsetTarget() override;
Off getImmPCOffset() override; Off GetImmPCOffset() override;
void decode(T32_STRUCT_B32 *inst) override; void Disassembler(T32_STRUCT_B32 *inst) override;
void assembler() override; void Assembler() override;
public: public:
OP op; OP op;
...@@ -174,9 +174,9 @@ namespace SandHook { ...@@ -174,9 +174,9 @@ namespace SandHook {
DEFINE_IS(LDR_UIMM) DEFINE_IS(LDR_UIMM)
void decode(T32_STRUCT_LDR_UIMM *inst) override; void Disassembler(T32_STRUCT_LDR_UIMM *inst) override;
void assembler() override; void Assembler() override;
public: public:
RegisterA32* rt; RegisterA32* rt;
...@@ -216,13 +216,13 @@ namespace SandHook { ...@@ -216,13 +216,13 @@ namespace SandHook {
DEFINE_INST_CODE(LDR_LIT) DEFINE_INST_CODE(LDR_LIT)
Off getImmPCOffset() override; Off GetImmPCOffset() override;
void onOffsetApply(Off offset) override; void OnOffsetApply(Off offset) override;
void decode(T32_STRUCT_LDR_LIT *inst) override; void Disassembler(T32_STRUCT_LDR_LIT *inst) override;
void assembler() override; void Assembler() override;
public: public:
OP op; OP op;
...@@ -250,9 +250,9 @@ namespace SandHook { ...@@ -250,9 +250,9 @@ namespace SandHook {
DEFINE_INST_CODE(MOV_MOVT_IMM) DEFINE_INST_CODE(MOV_MOVT_IMM)
void decode(T32_STRUCT_MOV_MOVT_IMM *inst) override; void Disassembler(T32_STRUCT_MOV_MOVT_IMM *inst) override;
void assembler() override; void Assembler() override;
public: public:
OP op; OP op;
...@@ -280,9 +280,9 @@ namespace SandHook { ...@@ -280,9 +280,9 @@ namespace SandHook {
DEFINE_INST_CODE(LDR_IMM) DEFINE_INST_CODE(LDR_IMM)
void decode(T32_STRUCT_LDR_IMM *inst) override; void Disassembler(T32_STRUCT_LDR_IMM *inst) override;
void assembler() override; void Assembler() override;
public: public:
OP op; OP op;
...@@ -315,5 +315,3 @@ namespace SandHook { ...@@ -315,5 +315,3 @@ namespace SandHook {
#undef TEST_INST_FIELD #undef TEST_INST_FIELD
#undef TEST_INST_OPCODE #undef TEST_INST_OPCODE
#undef DEFINE_INST_CODE #undef DEFINE_INST_CODE
#endif //SANDHOOK_INST_T32_H
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
// Created by swift on 2019/5/12. // Created by swift on 2019/5/12.
// //
#ifndef SANDHOOK_NH_REGISTER_A32_H #pragma once
#define SANDHOOK_NH_REGISTER_A32_H
#include "base.h" #include "base.h"
#include "register.h" #include "register.h"
...@@ -36,7 +35,7 @@ namespace SandHook { ...@@ -36,7 +35,7 @@ namespace SandHook {
U8 getWide() override; U8 getWide() override;
virtual bool isUnkonw () { virtual bool isUnkonw () {
return getCode() == 38; return Code() == 38;
} }
static RegisterA32* get(U8 code) { static RegisterA32* get(U8 code) {
...@@ -47,6 +46,4 @@ namespace SandHook { ...@@ -47,6 +46,4 @@ namespace SandHook {
static RegisterA32* registers[]; static RegisterA32* registers[];
}; };
} }
} }
\ No newline at end of file
#endif //SANDHOOK_NH_REGISTER_A32_H
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
// Created by swift on 2019/5/8. // Created by swift on 2019/5/8.
// //
#ifndef SANDHOOK_NH_REGISTER_LIST_A32_H #pragma once
#define SANDHOOK_NH_REGISTER_LIST_A32_H
#include "register_arm32.h" #include "register_arm32.h"
...@@ -30,6 +29,4 @@ namespace RegistersA32 { ...@@ -30,6 +29,4 @@ namespace RegistersA32 {
extern RegisterA32 PC; extern RegisterA32 PC;
extern RegisterA32 UnknowRegiser; extern RegisterA32 UnknowRegiser;
}} }}
#define Reg(N) RegisterA32::get(N) #define Reg(N) RegisterA32::get(N)
\ No newline at end of file
#endif //SANDHOOK_NH_REGISTER_LIST_A32_H
...@@ -26,8 +26,8 @@ CodeRelocateA32::CodeRelocateA32(AssemblerA32 &assembler) : CodeRelocate(assembl ...@@ -26,8 +26,8 @@ CodeRelocateA32::CodeRelocateA32(AssemblerA32 &assembler) : CodeRelocate(assembl
bool CodeRelocateA32::visit(Unit<Base> *unit, void *pc) { bool CodeRelocateA32::visit(Unit<Base> *unit, void *pc) {
relocate(reinterpret_cast<Instruction<Base> *>(unit), __ getPC()); relocate(reinterpret_cast<Instruction<Base> *>(unit), __ getPC());
curOffset += unit->size(); curOffset += unit->Size();
if (unit->refcount() == 0) { if (unit->RefCount() == 0) {
delete unit; delete unit;
} }
return true; return true;
...@@ -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()->decode(startPc, len, *this, true); Disassembler::Get()->Disassembler(startPc, len, *this, true);
} else { } else {
//TODO //TODO
} }
...@@ -54,25 +54,25 @@ void* CodeRelocateA32::relocate(void *startPc, Addr len, void *toPc = nullptr) t ...@@ -54,25 +54,25 @@ void* CodeRelocateA32::relocate(void *startPc, Addr len, void *toPc = nullptr) t
void* CodeRelocateA32::relocate(Instruction<Base> *instruction, void *toPc) throw(ErrorCodeException) { void* CodeRelocateA32::relocate(Instruction<Base> *instruction, void *toPc) throw(ErrorCodeException) {
void* curPc = __ getPC(); void* curPc = __ getPC();
//insert later bind labels //insert later AddBind labels
__ Emit(getLaterBindLabel(curOffset)); __ Emit(getLaterBindLabel(curOffset));
if (!instruction->pcRelate()) { if (!instruction->pcRelate()) {
__ Emit(instruction); __ Emit(instruction);
instruction->ref(); instruction->Ref();
return curPc; return curPc;
} }
if (instruction->instType() == thumb32) { if (instruction->InstType() == thumb32) {
switch (instruction->instCode()) { switch (instruction->InstCode()) {
CASE(T32, B32) CASE(T32, B32)
CASE(T32, LDR_LIT) CASE(T32, LDR_LIT)
default: default:
__ Emit(instruction); __ Emit(instruction);
instruction->ref(); instruction->Ref();
} }
} else if (instruction->instType() == thumb16) { } else if (instruction->InstType() == thumb16) {
switch (instruction->instCode()) { switch (instruction->InstCode()) {
CASE(T16, B) CASE(T16, B)
CASE(T16, B_COND) CASE(T16, B_COND)
CASE(T16, BX_BLX) CASE(T16, BX_BLX)
...@@ -82,11 +82,11 @@ void* CodeRelocateA32::relocate(Instruction<Base> *instruction, void *toPc) thro ...@@ -82,11 +82,11 @@ void* CodeRelocateA32::relocate(Instruction<Base> *instruction, void *toPc) thro
CASE(T16, ADD_REG_RDN) CASE(T16, ADD_REG_RDN)
default: default:
__ Emit(instruction); __ Emit(instruction);
instruction->ref(); instruction->Ref();
} }
} else { } else {
__ Emit(instruction); __ Emit(instruction);
instruction->ref(); instruction->Ref();
} }
return curPc; return curPc;
} }
...@@ -99,7 +99,7 @@ IMPL_RELOCATE(T16, B_COND) { ...@@ -99,7 +99,7 @@ IMPL_RELOCATE(T16, B_COND) {
return; return;
} }
Addr targetAddr = inst->getImmPCOffsetTarget(); Addr targetAddr = inst->GetImmPCOffsetTarget();
if (inst->condition == al) { if (inst->condition == al) {
Label* target_label = new Label; Label* target_label = new Label;
...@@ -130,7 +130,7 @@ IMPL_RELOCATE(T16, B) { ...@@ -130,7 +130,7 @@ IMPL_RELOCATE(T16, B) {
return; return;
} }
Addr targetAddr = inst->getImmPCOffsetTarget(); Addr targetAddr = inst->GetImmPCOffsetTarget();
Label* target_label = new Label(); Label* target_label = new Label();
ALIGN_FOR_LDR ALIGN_FOR_LDR
...@@ -142,26 +142,26 @@ IMPL_RELOCATE(T16, B) { ...@@ -142,26 +142,26 @@ IMPL_RELOCATE(T16, B) {
IMPL_RELOCATE(T16, BX_BLX) { IMPL_RELOCATE(T16, BX_BLX) {
__ Emit(reinterpret_cast<Instruction<Base>*>(inst)); __ Emit(reinterpret_cast<Instruction<Base>*>(inst));
inst->ref(); inst->Ref();
} }
IMPL_RELOCATE(T16, CBZ_CBNZ) { IMPL_RELOCATE(T16, CBZ_CBNZ) {
inst->ref(); inst->Ref();
if (inRelocateRange(CODE_OFFSET(inst), sizeof(InstT16))) { if (inRelocateRange(CODE_OFFSET(inst), sizeof(InstT16))) {
inst->bindLabel(*getLaterBindLabel(CODE_OFFSET(inst) + curOffset)); inst->BindLabel(*getLaterBindLabel(CODE_OFFSET(inst) + curOffset));
__ Emit(reinterpret_cast<Instruction<Base>*>(inst)); __ Emit(reinterpret_cast<Instruction<Base>*>(inst));
return; return;
} }
Addr targetAddr = inst->getImmPCOffsetTarget(); Addr targetAddr = inst->GetImmPCOffsetTarget();
Label* true_label = new Label; Label* true_label = new Label;
Label* false_label = new Label; Label* false_label = new Label;
Label* target_label = new Label(); Label* target_label = new Label();
inst->bindLabel(*true_label); inst->BindLabel(*true_label);
__ Emit(reinterpret_cast<Instruction<Base>*>(inst)); __ Emit(reinterpret_cast<Instruction<Base>*>(inst));
__ B(false_label); __ B(false_label);
__ Emit(true_label); __ Emit(true_label);
...@@ -176,13 +176,13 @@ IMPL_RELOCATE(T16, CBZ_CBNZ) { ...@@ -176,13 +176,13 @@ IMPL_RELOCATE(T16, CBZ_CBNZ) {
IMPL_RELOCATE(T16, LDR_LIT) { IMPL_RELOCATE(T16, LDR_LIT) {
if (inRelocateRange(CODE_OFFSET(inst), inst->rt->getWide())) { if (inRelocateRange(CODE_OFFSET(inst), inst->rt->getWide())) {
inst->ref(); inst->Ref();
inst->bindLabel(*getLaterBindLabel(CODE_OFFSET(inst) + curOffset)); inst->BindLabel(*getLaterBindLabel(CODE_OFFSET(inst) + curOffset));
__ Emit(reinterpret_cast<Instruction<Base>*>(inst)); __ Emit(reinterpret_cast<Instruction<Base>*>(inst));
return; return;
} }
Addr targetAddr = inst->getImmPCOffsetTarget(); Addr targetAddr = inst->GetImmPCOffsetTarget();
__ Mov(*inst->rt, targetAddr); __ Mov(*inst->rt, targetAddr);
__ Ldr(*inst->rt, MemOperand(inst->rt, 0)); __ Ldr(*inst->rt, MemOperand(inst->rt, 0));
...@@ -191,13 +191,13 @@ IMPL_RELOCATE(T16, LDR_LIT) { ...@@ -191,13 +191,13 @@ IMPL_RELOCATE(T16, LDR_LIT) {
IMPL_RELOCATE(T16, ADR) { IMPL_RELOCATE(T16, ADR) {
if (inRelocateRange(CODE_OFFSET(inst), inst->rd->getWide())) { if (inRelocateRange(CODE_OFFSET(inst), inst->rd->getWide())) {
inst->ref(); inst->Ref();
inst->bindLabel(*getLaterBindLabel(CODE_OFFSET(inst) + curOffset)); inst->BindLabel(*getLaterBindLabel(CODE_OFFSET(inst) + curOffset));
__ Emit(reinterpret_cast<Instruction<Base>*>(inst)); __ Emit(reinterpret_cast<Instruction<Base>*>(inst));
return; return;
} }
Addr targetAddr = inst->getImmPCOffsetTarget(); Addr targetAddr = inst->GetImmPCOffsetTarget();
__ Mov(*inst->rd, targetAddr); __ Mov(*inst->rd, targetAddr);
...@@ -206,7 +206,7 @@ IMPL_RELOCATE(T16, ADR) { ...@@ -206,7 +206,7 @@ IMPL_RELOCATE(T16, ADR) {
IMPL_RELOCATE(T16, ADD_REG_RDN) { IMPL_RELOCATE(T16, ADD_REG_RDN) {
if (*inst->rm != PC) { if (*inst->rm != PC) {
inst->ref(); inst->Ref();
__ Emit(reinterpret_cast<Instruction<Base>*>(inst)); __ Emit(reinterpret_cast<Instruction<Base>*>(inst));
return; return;
} }
...@@ -223,13 +223,13 @@ IMPL_RELOCATE(T16, ADD_REG_RDN) { ...@@ -223,13 +223,13 @@ IMPL_RELOCATE(T16, ADD_REG_RDN) {
IMPL_RELOCATE(T32, B32) { IMPL_RELOCATE(T32, B32) {
if (inRelocateRange(CODE_OFFSET(inst), sizeof(InstT16))) { if (inRelocateRange(CODE_OFFSET(inst), sizeof(InstT16))) {
inst->ref(); inst->Ref();
inst->bindLabel(*getLaterBindLabel(CODE_OFFSET(inst) + curOffset)); inst->BindLabel(*getLaterBindLabel(CODE_OFFSET(inst) + curOffset));
__ Emit(reinterpret_cast<Instruction<Base> *>(inst)); __ Emit(reinterpret_cast<Instruction<Base> *>(inst));
return; return;
} }
Addr targetAddr = inst->getImmPCOffsetTarget(); Addr targetAddr = inst->GetImmPCOffsetTarget();
if (inst->x == T32_B32::thumb) { if (inst->x == T32_B32::thumb) {
...@@ -248,13 +248,13 @@ IMPL_RELOCATE(T32, B32) { ...@@ -248,13 +248,13 @@ IMPL_RELOCATE(T32, B32) {
IMPL_RELOCATE(T32, LDR_LIT) { IMPL_RELOCATE(T32, LDR_LIT) {
if (inRelocateRange(CODE_OFFSET(inst), sizeof(Addr))) { if (inRelocateRange(CODE_OFFSET(inst), sizeof(Addr))) {
inst->ref(); inst->Ref();
inst->bindLabel(*getLaterBindLabel(CODE_OFFSET(inst) + curOffset)); inst->BindLabel(*getLaterBindLabel(CODE_OFFSET(inst) + curOffset));
__ Emit(reinterpret_cast<Instruction<Base>*>(inst)); __ Emit(reinterpret_cast<Instruction<Base>*>(inst));
return; return;
} }
Addr targetAddr = inst->getImmPCOffsetTarget(); Addr targetAddr = inst->GetImmPCOffsetTarget();
__ Mov(*inst->rt, targetAddr); __ Mov(*inst->rt, targetAddr);
switch (inst->op) { switch (inst->op) {
...@@ -276,7 +276,7 @@ IMPL_RELOCATE(T32, LDR_LIT) { ...@@ -276,7 +276,7 @@ IMPL_RELOCATE(T32, LDR_LIT) {
} }
break; break;
default: default:
inst->ref(); inst->Ref();
__ Emit(reinterpret_cast<Instruction<Base>*>(inst)); __ Emit(reinterpret_cast<Instruction<Base>*>(inst));
} }
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
// Created by swift on 2019/5/23. // Created by swift on 2019/5/23.
// //
#ifndef SANDHOOK_CODE_RELOCATE_ARM32_H #pragma once
#define SANDHOOK_CODE_RELOCATE_ARM32_H
#include <mutex> #include <mutex>
#include <map> #include <map>
...@@ -55,6 +54,4 @@ namespace SandHook { ...@@ -55,6 +54,4 @@ namespace SandHook {
} }
} }
#undef DEFINE_RELOCATE #undef DEFINE_RELOCATE
\ No newline at end of file
#endif //SANDHOOK_CODE_RELOCATE_ARM32_H
...@@ -12,19 +12,19 @@ AssemblerA64::AssemblerA64(CodeBuffer* codeBuffer) { ...@@ -12,19 +12,19 @@ AssemblerA64::AssemblerA64(CodeBuffer* codeBuffer) {
codeContainer.setCodeBuffer(codeBuffer); codeContainer.setCodeBuffer(codeBuffer);
} }
void *AssemblerA64::getPC() { void *AssemblerA64::GetPC() {
return reinterpret_cast<void *>(codeContainer.curPc); return reinterpret_cast<void *>(codeContainer.curPc);
} }
void *AssemblerA64::getStartPC() { void *AssemblerA64::GetStartPC() {
return reinterpret_cast<void *>(codeContainer.startPc); return reinterpret_cast<void *>(codeContainer.startPc);
} }
void AssemblerA64::allocBufferFirst(U32 size) { void AssemblerA64::AllocBufferFirst(U32 size) {
codeContainer.allocBufferFirst(size); codeContainer.allocBufferFirst(size);
} }
void *AssemblerA64::finish() { void *AssemblerA64::Finish() {
codeContainer.commit(); codeContainer.commit();
return reinterpret_cast<void *>(codeContainer.startPc); return reinterpret_cast<void *>(codeContainer.startPc);
} }
...@@ -95,7 +95,7 @@ void AssemblerA64::B(Off offset) { ...@@ -95,7 +95,7 @@ void AssemblerA64::B(Off offset) {
} }
void AssemblerA64::B(Label *label) { void AssemblerA64::B(Label *label) {
Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(B_BL)(INST_A64(B_BL)::B, *label))); Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(B_BL)(INST_A64(B_BL)::B, label)));
} }
void AssemblerA64::Bl(Off offset) { void AssemblerA64::Bl(Off offset) {
...@@ -103,7 +103,7 @@ void AssemblerA64::Bl(Off offset) { ...@@ -103,7 +103,7 @@ void AssemblerA64::Bl(Off offset) {
} }
void AssemblerA64::Bl(Label *label) { void AssemblerA64::Bl(Label *label) {
Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(B_BL)(INST_A64(B_BL)::BL, *label))); Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(B_BL)(INST_A64(B_BL)::BL, label)));
} }
void AssemblerA64::B(Condition condition, Off offset) { void AssemblerA64::B(Condition condition, Off offset) {
...@@ -111,11 +111,11 @@ void AssemblerA64::B(Condition condition, Off offset) { ...@@ -111,11 +111,11 @@ void AssemblerA64::B(Condition condition, Off offset) {
} }
void AssemblerA64::B(Condition condition, Label *label) { void AssemblerA64::B(Condition condition, Label *label) {
Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(B_COND)(condition, *label))); Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(B_COND)(condition, label)));
} }
void AssemblerA64::Tbz(RegisterA64 &rt, U32 bit, Label *label) { void AssemblerA64::Tbz(RegisterA64 &rt, U32 bit, Label *label) {
Emit((reinterpret_cast<Unit<Base> *>(new INST_A64(TBZ_TBNZ)(INST_A64(TBZ_TBNZ)::TBZ, rt, bit, *label)))); Emit((reinterpret_cast<Unit<Base> *>(new INST_A64(TBZ_TBNZ)(INST_A64(TBZ_TBNZ)::TBZ, rt, bit, label))));
} }
void AssemblerA64::Tbz(RegisterA64 &rt, U32 bit, Off offset) { void AssemblerA64::Tbz(RegisterA64 &rt, U32 bit, Off offset) {
...@@ -127,7 +127,7 @@ void AssemblerA64::Tbnz(RegisterA64 &rt, U32 bit, Off offset) { ...@@ -127,7 +127,7 @@ void AssemblerA64::Tbnz(RegisterA64 &rt, U32 bit, Off offset) {
} }
void AssemblerA64::Tbnz(RegisterA64 &rt, U32 bit, Label *label) { void AssemblerA64::Tbnz(RegisterA64 &rt, U32 bit, Label *label) {
Emit((reinterpret_cast<Unit<Base> *>(new INST_A64(TBZ_TBNZ)(INST_A64(TBZ_TBNZ)::TBNZ, rt, bit, *label)))); Emit((reinterpret_cast<Unit<Base> *>(new INST_A64(TBZ_TBNZ)(INST_A64(TBZ_TBNZ)::TBNZ, rt, bit, label))));
} }
...@@ -136,7 +136,7 @@ void AssemblerA64::Cbz(RegisterA64 &rt, Off offset) { ...@@ -136,7 +136,7 @@ void AssemblerA64::Cbz(RegisterA64 &rt, Off offset) {
} }
void AssemblerA64::Cbz(RegisterA64 &rt, Label *label) { void AssemblerA64::Cbz(RegisterA64 &rt, Label *label) {
Emit((reinterpret_cast<Unit<Base> *>(new INST_A64(CBZ_CBNZ)(INST_A64(CBZ_CBNZ)::CBZ, *label, rt)))); Emit((reinterpret_cast<Unit<Base> *>(new INST_A64(CBZ_CBNZ)(INST_A64(CBZ_CBNZ)::CBZ, label, rt))));
} }
...@@ -146,11 +146,11 @@ void AssemblerA64::Cbnz(RegisterA64 &rt, Off offset) { ...@@ -146,11 +146,11 @@ void AssemblerA64::Cbnz(RegisterA64 &rt, Off offset) {
} }
void AssemblerA64::Cbnz(RegisterA64 &rt, Label *label) { void AssemblerA64::Cbnz(RegisterA64 &rt, Label *label) {
Emit((reinterpret_cast<Unit<Base> *>(new INST_A64(CBZ_CBNZ)(INST_A64(CBZ_CBNZ)::CBNZ, *label, rt)))); Emit((reinterpret_cast<Unit<Base> *>(new INST_A64(CBZ_CBNZ)(INST_A64(CBZ_CBNZ)::CBNZ, label, rt))));
} }
void AssemblerA64::Str(RegisterA64 &rt, const MemOperand& memOperand) { void AssemblerA64::Str(RegisterA64 &rt, const MemOperand& memOperand) {
if (memOperand.addr_mode == Offset) { if (memOperand.addr_mode_ == Offset) {
Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(STR_UIMM)(rt, memOperand))); Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(STR_UIMM)(rt, memOperand)));
} else { } else {
Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(STR_IMM)(rt, memOperand))); Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(STR_IMM)(rt, memOperand)));
...@@ -158,7 +158,7 @@ void AssemblerA64::Str(RegisterA64 &rt, const MemOperand& memOperand) { ...@@ -158,7 +158,7 @@ void AssemblerA64::Str(RegisterA64 &rt, const MemOperand& memOperand) {
} }
void AssemblerA64::Ldr(RegisterA64 &rt, const MemOperand &memOperand) { void AssemblerA64::Ldr(RegisterA64 &rt, const MemOperand &memOperand) {
if (memOperand.addr_mode == Offset && memOperand.offset >= 0) { if (memOperand.addr_mode_ == Offset && memOperand.offset_ >= 0) {
Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(LDR_UIMM)(rt, memOperand))); Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(LDR_UIMM)(rt, memOperand)));
} else { } else {
Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(LDR_IMM)(rt, memOperand))); Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(LDR_IMM)(rt, memOperand)));
...@@ -166,15 +166,15 @@ void AssemblerA64::Ldr(RegisterA64 &rt, const MemOperand &memOperand) { ...@@ -166,15 +166,15 @@ void AssemblerA64::Ldr(RegisterA64 &rt, const MemOperand &memOperand) {
} }
void AssemblerA64::Ldr(RegisterA64 &rt, Label* label) { void AssemblerA64::Ldr(RegisterA64 &rt, Label* label) {
Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(LDR_LIT)(rt.isX() ? INST_A64(LDR_LIT)::LDR_X : INST_A64(LDR_LIT)::LDR_W, rt, *label))); Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(LDR_LIT)(rt.isX() ? INST_A64(LDR_LIT)::LDR_X : INST_A64(LDR_LIT)::LDR_W, rt, label)));
} }
void AssemblerA64::Ldrsw(RegisterA64 &rt, Label* label) { void AssemblerA64::Ldrsw(RegisterA64 &rt, Label* label) {
Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(LDR_LIT)(INST_A64(LDR_LIT)::LDR_SW, rt, *label))); Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(LDR_LIT)(INST_A64(LDR_LIT)::LDR_SW, rt, label)));
} }
void AssemblerA64::Ldrsw(XRegister &rt, const MemOperand& memOperand) { void AssemblerA64::Ldrsw(XRegister &rt, const MemOperand& memOperand) {
if (memOperand.addr_mode == Offset) { if (memOperand.addr_mode_ == Offset) {
Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(LDRSW_UIMM)(rt, memOperand))); Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(LDRSW_UIMM)(rt, memOperand)));
} else { } else {
Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(LDRSW_IMM)(rt, memOperand))); Emit(reinterpret_cast<Unit<Base> *>(new INST_A64(LDRSW_IMM)(rt, memOperand)));
...@@ -182,7 +182,7 @@ void AssemblerA64::Ldrsw(XRegister &rt, const MemOperand& memOperand) { ...@@ -182,7 +182,7 @@ void AssemblerA64::Ldrsw(XRegister &rt, const MemOperand& memOperand) {
} }
// If the current stack pointer is sp, then it must be aligned to 16 bytes // If the current stack pointer is sp, then it must be aligned to 16 bytes
// on entry and the total size of the specified registers must also be a // on entry and the total Size of the specified registers must also be a
// multiple of 16 bytes. // multiple of 16 bytes.
void AssemblerA64::Pop(RegisterA64 &rd) { void AssemblerA64::Pop(RegisterA64 &rd) {
if (rd.isX()) { if (rd.isX()) {
...@@ -193,7 +193,7 @@ void AssemblerA64::Pop(RegisterA64 &rd) { ...@@ -193,7 +193,7 @@ void AssemblerA64::Pop(RegisterA64 &rd) {
} }
// If the current stack pointer is sp, then it must be aligned to 16 bytes // If the current stack pointer is sp, then it must be aligned to 16 bytes
// on entry and the total size of the specified registers must also be a // on entry and the total Size of the specified registers must also be a
// multiple of 16 bytes. // multiple of 16 bytes.
void AssemblerA64::Push(RegisterA64 &rt) { void AssemblerA64::Push(RegisterA64 &rt) {
if (rt.isX()) { if (rt.isX()) {
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
// Created by swift on 2019/5/11. // Created by swift on 2019/5/11.
// //
#ifndef SANDHOOK_NH_ASSEMBLER_A64_H #pragma once
#define SANDHOOK_NH_ASSEMBLER_A64_H
#include "assembler.h" #include "assembler.h"
#include "register_arm64.h" #include "register_arm64.h"
...@@ -19,10 +18,10 @@ namespace SandHook { ...@@ -19,10 +18,10 @@ namespace SandHook {
public: public:
AssemblerA64(CodeBuffer* codeBuffer); AssemblerA64(CodeBuffer* codeBuffer);
void allocBufferFirst(U32 size); void AllocBufferFirst(U32 size);
void* getStartPC(); void* GetStartPC();
void* getPC(); void* GetPC();
void* finish(); void* Finish();
void Emit(U32 data32); void Emit(U32 data32);
void Emit(U64 data64); void Emit(U64 data64);
...@@ -99,6 +98,4 @@ namespace SandHook { ...@@ -99,6 +98,4 @@ namespace SandHook {
}; };
} }
} }
\ No newline at end of file
#endif //SANDHOOK_NH_ASSEMBLER_A64_H
...@@ -10,14 +10,14 @@ using namespace SandHook::AsmA64; ...@@ -10,14 +10,14 @@ using namespace SandHook::AsmA64;
#define CASE(X) \ #define CASE(X) \
if (IS_OPCODE_A64(*pc, X)) { \ if (IS_OPCODE_A64(*pc, X)) { \
STRUCT_A64(X) *s = reinterpret_cast<STRUCT_A64(X) *>(pc); \ unit = reinterpret_cast<BaseUnit*>(new INST_A64(X)(pc)); \
unit = reinterpret_cast<Unit<Base> *>(new INST_A64(X)(*s)); \
goto label_matched; \ goto label_matched; \
} }
Arm64Decoder* Arm64Decoder::instant = new Arm64Decoder(); Arm64Decoder* Arm64Decoder::instant = new Arm64Decoder();
void Arm64Decoder::decode(void *codeStart, Addr codeLen, InstVisitor &visitor, bool onlyPcRelInst) { void Arm64Decoder::Disassembler(void *codeStart, Addr codeLen, InstVisitor &visitor,
bool onlyPcRelInst) {
InstA64 *pc = reinterpret_cast<InstA64 *>(codeStart); InstA64 *pc = reinterpret_cast<InstA64 *>(codeStart);
Addr endAddr = (Addr) codeStart + codeLen; Addr endAddr = (Addr) codeStart + codeLen;
Unit<Base>* unit = nullptr; Unit<Base>* unit = nullptr;
...@@ -48,12 +48,13 @@ void Arm64Decoder::decode(void *codeStart, Addr codeLen, InstVisitor &visitor, b ...@@ -48,12 +48,13 @@ void Arm64Decoder::decode(void *codeStart, Addr codeLen, InstVisitor &visitor, b
label_matched: label_matched:
if (unit == nullptr) { if (unit == nullptr) {
unit = reinterpret_cast<Unit<Base> *>(new INST_A64(UNKNOW)(*reinterpret_cast<STRUCT_A64(UNKNOW) *>(pc))); unit = reinterpret_cast<BaseUnit*>(new INST_A64(UNKNOW)(pc));
} }
if (!visitor.visit(unit, pc)) { reinterpret_cast<BaseInst*>(unit)->Disassembler();
if (!visitor.Visit(unit, pc)) {
break; break;
} }
pc = reinterpret_cast<InstA64 *>((Addr)pc + unit->size()); pc = reinterpret_cast<InstA64 *>((Addr)pc + unit->Size());
unit = nullptr; unit = nullptr;
} }
} }
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
// Created by swift on 2019/5/6. // Created by swift on 2019/5/6.
// //
#ifndef SANDHOOK_NH_DECODER_ARM64_H #pragma once
#define SANDHOOK_NH_DECODER_ARM64_H
#include "decoder.h" #include "decoder.h"
...@@ -12,12 +11,11 @@ namespace SandHook { ...@@ -12,12 +11,11 @@ namespace SandHook {
class Arm64Decoder : public InstDecoder { class Arm64Decoder : public InstDecoder {
public: public:
void decode(void *codeStart, Addr codeLen, InstVisitor &visitor, bool onlyPcRelInst) override; void Disassembler(void *codeStart, Addr codeLen, InstVisitor &visitor,
bool onlyPcRelInst) override;
public: public:
static Arm64Decoder* instant; static Arm64Decoder* instant;
}; };
} }
} }
\ No newline at end of file
#endif //SANDHOOK_NH_DECODER_ARM64_H
...@@ -15,7 +15,7 @@ using namespace SandHook::Utils; ...@@ -15,7 +15,7 @@ using namespace SandHook::Utils;
#include "assembler_arm64.h" #include "assembler_arm64.h"
#include "code_relocate_arm64.h" #include "code_relocate_arm64.h"
using namespace SandHook::RegistersA64; using namespace SandHook::RegistersA64;
void *InlineHookArm64Android::inlineHook(void *origin, void *replace) { void *InlineHookArm64Android::Hook(void *origin, void *replace) {
AutoLock lock(hookLock); AutoLock lock(hookLock);
void* backup = nullptr; void* backup = nullptr;
...@@ -43,15 +43,15 @@ void *InlineHookArm64Android::inlineHook(void *origin, void *replace) { ...@@ -43,15 +43,15 @@ void *InlineHookArm64Android::inlineHook(void *origin, void *replace) {
__ Br(IP1); __ Br(IP1);
__ Emit(origin_addr_label); __ Emit(origin_addr_label);
__ Emit((Addr) origin + codeContainerInline->size()); __ Emit((Addr) origin + codeContainerInline->size());
__ finish(); __ Finish();
#undef __ #undef __
//commit inline trampoline //commit inline trampoline
assemblerInline.finish(); assemblerInline.Finish();
return backup; return backup;
} }
bool InlineHookArm64Android::breakPoint(void *point, void (*callback)(REG regs[])) { bool InlineHookArm64Android::BreakPoint(void *point, void (*callback)(REG regs[])) {
AutoLock lock(hookLock); AutoLock lock(hookLock);
void* backup = nullptr; void* backup = nullptr;
...@@ -71,7 +71,7 @@ bool InlineHookArm64Android::breakPoint(void *point, void (*callback)(REG regs[] ...@@ -71,7 +71,7 @@ bool InlineHookArm64Android::breakPoint(void *point, void (*callback)(REG regs[]
__ Br(IP1); __ Br(IP1);
__ Emit(origin_addr_label); __ Emit(origin_addr_label);
__ Emit((Addr) point + 4 * 4); __ Emit((Addr) point + 4 * 4);
__ finish(); __ Finish();
#undef __ #undef __
...@@ -114,11 +114,11 @@ bool InlineHookArm64Android::breakPoint(void *point, void (*callback)(REG regs[] ...@@ -114,11 +114,11 @@ bool InlineHookArm64Android::breakPoint(void *point, void (*callback)(REG regs[]
__ Mov(IP1, (Addr) backup); __ Mov(IP1, (Addr) backup);
__ Br(IP1); __ Br(IP1);
__ finish(); __ Finish();
#undef __ #undef __
void* secondTrampoline = assemblerTrampoline.getStartPC(); void* secondTrampoline = assemblerTrampoline.GetStartPC();
//build inline trampoline //build inline trampoline
#define __ assemblerInline. #define __ assemblerInline.
Label* target_addr_label = new Label(); Label* target_addr_label = new Label();
...@@ -126,7 +126,7 @@ bool InlineHookArm64Android::breakPoint(void *point, void (*callback)(REG regs[] ...@@ -126,7 +126,7 @@ bool InlineHookArm64Android::breakPoint(void *point, void (*callback)(REG regs[]
__ Br(IP1); __ Br(IP1);
__ Emit(target_addr_label); __ Emit(target_addr_label);
__ Emit((Addr) secondTrampoline); __ Emit((Addr) secondTrampoline);
__ finish(); __ Finish();
#undef __ #undef __
return true; return true;
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
// Created by swift on 2019/5/23. // Created by swift on 2019/5/23.
// //
#ifndef SANDHOOK_HOOK_ARM64_H #pragma once
#define SANDHOOK_HOOK_ARM64_H
#include "hook.h" #include "hook.h"
...@@ -11,20 +10,8 @@ namespace SandHook { ...@@ -11,20 +10,8 @@ namespace SandHook {
namespace Hook { namespace Hook {
class InlineHookArm64Android : public InlineHook { class InlineHookArm64Android : public InlineHook {
public: public:
inline InlineHookArm64Android() { void *Hook(void *origin, void *replace) override;
hookLock = new std::mutex(); bool BreakPoint(void *point, void (*callback)(REG[])) override;
};
inline ~InlineHookArm64Android() {
delete hookLock;
}
void *inlineHook(void *origin, void *replace) override;
bool breakPoint(void *point, void (*callback)(REG[])) override;
protected:
std::mutex* hookLock;
}; };
} }
} }
#endif //SANDHOOK_HOOK_ARM64_H
...@@ -2,12 +2,11 @@ ...@@ -2,12 +2,11 @@
// Created by swift on 2019/5/8. // Created by swift on 2019/5/8.
// //
#ifndef SANDHOOK_NH_INST_CODE_ARM64_H #pragma once
#define SANDHOOK_NH_INST_CODE_ARM64_H
#include "inst_struct_aarch64.h" #include "inst_struct_aarch64.h"
enum class InstCodeA64 { enum class InstCodeA64 : InstCode {
UNKNOW, UNKNOW,
MOV_WIDE, MOV_WIDE,
MOV_REG, MOV_REG,
...@@ -30,6 +29,4 @@ enum class InstCodeA64 { ...@@ -30,6 +29,4 @@ enum class InstCodeA64 {
STP_LDP, STP_LDP,
ADD_SUB_IMM, ADD_SUB_IMM,
MSR_MRS MSR_MRS
}; };
\ No newline at end of file
#endif //SANDHOOK_NH_INST_CODE_ARM64_H
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
// Created by swift on 2019/5/5. // Created by swift on 2019/5/5.
// //
#ifndef SANDHOOK_NH_INST_AARCH64_H #pragma once
#define SANDHOOK_NH_INST_AARCH64_H
#include "instruction.h" #include "instruction.h"
...@@ -39,7 +38,7 @@ enum FieldWide { ...@@ -39,7 +38,7 @@ enum FieldWide {
WideReg = 5, WideReg = 5,
}; };
//unknow inst //Unknow inst
DEFINE_STRUCT_A64(UNKNOW) { DEFINE_STRUCT_A64(UNKNOW) {
InstA64 raw; InstA64 raw;
}; };
...@@ -233,6 +232,4 @@ DEFINE_STRUCT_A64(MSR_MRS) { ...@@ -233,6 +232,4 @@ DEFINE_STRUCT_A64(MSR_MRS) {
InstA64 sysreg:16; InstA64 sysreg:16;
InstA64 op:1; InstA64 op:1;
InstA64 opcode:10; InstA64 opcode:10;
}; };
\ No newline at end of file
#endif //SANDHOOK_NH_INST_AARCH64_H
...@@ -26,7 +26,7 @@ XRegister::XRegister(U8 code) : RegisterA64(code) {} ...@@ -26,7 +26,7 @@ XRegister::XRegister(U8 code) : RegisterA64(code) {}
XRegister::XRegister() {} XRegister::XRegister() {}
U8 XRegister::getWide() { U8 XRegister::Wide() {
return Reg64Bit; return Reg64Bit;
} }
...@@ -43,6 +43,6 @@ WRegister::WRegister(U8 code) : RegisterA64(code) {} ...@@ -43,6 +43,6 @@ WRegister::WRegister(U8 code) : RegisterA64(code) {}
WRegister::WRegister() {} WRegister::WRegister() {}
U8 WRegister::getWide() { U8 WRegister::Wide() {
return Reg32Bit; return Reg32Bit;
} }
// //
// Created by swift on 2019/5/8. // Created by swift on 2019/5/8.
// //
#pragma once
#ifndef SANDHOOK_NH_REGISTER_A64_H
#define SANDHOOK_NH_REGISTER_A64_H
#include "register.h" #include "register.h"
...@@ -62,7 +60,7 @@ namespace SandHook { ...@@ -62,7 +60,7 @@ namespace SandHook {
XRegister(); XRegister();
XRegister(U8 code); XRegister(U8 code);
U8 getWide() override; U8 Wide() override;
static XRegister* get(U8 code) { static XRegister* get(U8 code) {
return registers[code]; return registers[code];
...@@ -75,9 +73,10 @@ namespace SandHook { ...@@ -75,9 +73,10 @@ namespace SandHook {
class WRegister : public RegisterA64 { class WRegister : public RegisterA64 {
public: public:
WRegister(); WRegister();
WRegister(U8 code); WRegister(U8 code);
U8 getWide() override; U8 Wide() override;
static WRegister* get(U8 code) { static WRegister* get(U8 code) {
return registers[code]; return registers[code];
...@@ -87,6 +86,8 @@ namespace SandHook { ...@@ -87,6 +86,8 @@ namespace SandHook {
static WRegister* registers[]; static WRegister* registers[];
}; };
class SystemRegister { class SystemRegister {
public: public:
...@@ -98,34 +99,31 @@ namespace SandHook { ...@@ -98,34 +99,31 @@ namespace SandHook {
U16 op0:2; U16 op0:2;
}; };
SystemRegister(U16 value) : value(value) {}
SystemRegister(U16 op0, U16 op1, U16 crn, U16 crm, U16 op2) { SystemRegister(U16 op0, U16 op1, U16 crn, U16 crm, U16 op2) {
reg.op0 = op0; reg.op0 = op0;
reg.op1 = op1; reg.op1 = op1;
reg.CRn = crn; reg.CRn = crn;
reg.CRm = crm; reg.CRm = crm;
reg.op2 = op2; reg.op2 = op2;
value = ForceCast<U16>(reg);
} }
U16 value() { bool operator==(const SystemRegister &rhs) const {
return value == rhs.value;
union { }
U16 raw;
SystemReg reg;
} ret;
ret.reg = reg;
return ret.raw; bool operator!=(const SystemRegister &rhs) const {
return !(rhs == *this);
} }
public: public:
U16 value;
SystemReg reg; SystemReg reg;
}; };
} }
} }
\ No newline at end of file
#endif //SANDHOOK_NH_REGISTER_A64_H
...@@ -18,7 +18,7 @@ namespace SandHook { ...@@ -18,7 +18,7 @@ namespace SandHook {
XRegister IP0 = X16; XRegister IP0 = X16;
XRegister IP1 = X17; XRegister IP1 = X17;
XRegister LR = X30; XRegister LR = X30;
//zero reg //zero reg_
XRegister XZR = X31; XRegister XZR = X31;
WRegister WZR = W31; WRegister WZR = W31;
RegisterA64 UnknowRegiser = RegisterA64(38); RegisterA64 UnknowRegiser = RegisterA64(38);
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
// Created by swift on 2019/5/8. // Created by swift on 2019/5/8.
// //
#ifndef SANDHOOK_NH_REGISTER_LIST_A64_H #pragma once
#define SANDHOOK_NH_REGISTER_LIST_A64_H
#include "register_arm64.h" #include "register_arm64.h"
#include "base.h" #include "base.h"
...@@ -34,7 +33,7 @@ namespace SandHook { ...@@ -34,7 +33,7 @@ namespace SandHook {
extern XRegister IP0; extern XRegister IP0;
extern XRegister IP1; extern XRegister IP1;
extern XRegister LR; extern XRegister LR;
//zero reg //zero reg_
extern XRegister XZR; extern XRegister XZR;
extern WRegister WZR; extern WRegister WZR;
extern RegisterA64 UnknowRegiser; extern RegisterA64 UnknowRegiser;
...@@ -58,6 +57,4 @@ namespace SandHook { ...@@ -58,6 +57,4 @@ namespace SandHook {
} }
#define XReg(N) XRegister::get(N) #define XReg(N) XRegister::get(N)
#define WReg(N) WRegister::get(N) #define WReg(N) WRegister::get(N)
\ No newline at end of file
#endif //SANDHOOK_NH_REGISTER_LIST_A64_H
...@@ -24,10 +24,10 @@ CodeRelocateA64::CodeRelocateA64(AssemblerA64 &assembler) : CodeRelocate(assembl ...@@ -24,10 +24,10 @@ CodeRelocateA64::CodeRelocateA64(AssemblerA64 &assembler) : CodeRelocate(assembl
assemblerA64 = &assembler; assemblerA64 = &assembler;
} }
bool CodeRelocateA64::visit(Unit<Base> *unit, void *pc) { bool CodeRelocateA64::Visit(Unit<Base> *unit, void *pc) {
relocate(reinterpret_cast<Instruction<Base> *>(unit), __ getPC()); relocate(reinterpret_cast<BaseInst *>(unit), __ GetPC());
curOffset += unit->size(); curOffset += unit->Size();
if (unit->refcount() == 0) { if (unit->RefCount() == 0) {
delete unit; delete unit;
} }
return true; return true;
...@@ -38,28 +38,28 @@ void* CodeRelocateA64::relocate(void *startPc, Addr len, void *toPc = nullptr) t ...@@ -38,28 +38,28 @@ void* CodeRelocateA64::relocate(void *startPc, Addr len, void *toPc = nullptr) t
startAddr = reinterpret_cast<Addr>(startPc); startAddr = reinterpret_cast<Addr>(startPc);
length = len; length = len;
curOffset = 0; curOffset = 0;
__ 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()->decode(startPc, len, *this, true); Disassembler::get()->Disassembler(startPc, len, *this, true);
} else { } else {
//TODO //TODO
} }
return curPc; return curPc;
} }
void* CodeRelocateA64::relocate(Instruction<Base> *instruction, void *toPc) throw(ErrorCodeException) { void* CodeRelocateA64::relocate(BaseInst *instruction, void *toPc) throw(ErrorCodeException) {
void* curPc = __ getPC(); void* curPc = __ GetPC();
//insert later bind labels //insert later AddBind labels
__ Emit(getLaterBindLabel(curOffset)); __ Emit(getLaterBindLabel(curOffset));
if (!instruction->pcRelate()) { if (!instruction->PcRelate()) {
__ Emit(instruction); __ Emit(instruction);
instruction->ref(); instruction->Ref();
return curPc; return curPc;
} }
switch (instruction->instCode()) { switch (instruction->InstCode()) {
CASE(B_BL) CASE(B_BL)
CASE(B_COND) CASE(B_COND)
CASE(TBZ_TBNZ) CASE(TBZ_TBNZ)
...@@ -68,7 +68,7 @@ void* CodeRelocateA64::relocate(Instruction<Base> *instruction, void *toPc) thro ...@@ -68,7 +68,7 @@ void* CodeRelocateA64::relocate(Instruction<Base> *instruction, void *toPc) thro
CASE(ADR_ADRP) CASE(ADR_ADRP)
default: default:
__ Emit(instruction); __ Emit(instruction);
instruction->ref(); instruction->Ref();
} }
return curPc; return curPc;
} }
...@@ -76,13 +76,13 @@ void* CodeRelocateA64::relocate(Instruction<Base> *instruction, void *toPc) thro ...@@ -76,13 +76,13 @@ void* CodeRelocateA64::relocate(Instruction<Base> *instruction, void *toPc) thro
IMPL_RELOCATE(B_BL) { IMPL_RELOCATE(B_BL) {
if (inRelocateRange(inst->offset, sizeof(InstA64))) { if (inRelocateRange(inst->offset, sizeof(InstA64))) {
inst->ref(); inst->Ref();
inst->bindLabel(*getLaterBindLabel(inst->offset + curOffset)); inst->BindLabel(getLaterBindLabel(inst->offset + curOffset));
__ Emit(reinterpret_cast<Instruction<Base>*>(inst)); __ Emit(reinterpret_cast<BaseInst*>(inst));
return; return;
} }
Addr targetAddr = inst->getImmPCOffsetTarget(); Addr targetAddr = inst->GetImmPCOffsetTarget();
if (inst->op == inst->BL) { if (inst->op == inst->BL) {
Addr lr = reinterpret_cast<Addr>(toPc); Addr lr = reinterpret_cast<Addr>(toPc);
...@@ -98,13 +98,13 @@ IMPL_RELOCATE(B_BL) { ...@@ -98,13 +98,13 @@ IMPL_RELOCATE(B_BL) {
IMPL_RELOCATE(B_COND) { IMPL_RELOCATE(B_COND) {
if (inRelocateRange(inst->offset, sizeof(InstA64))) { if (inRelocateRange(inst->offset, sizeof(InstA64))) {
inst->ref(); inst->Ref();
inst->bindLabel(*getLaterBindLabel(inst->offset + curOffset)); inst->BindLabel(getLaterBindLabel(inst->offset + curOffset));
__ Emit(reinterpret_cast<Instruction<Base>*>(inst)); __ Emit(reinterpret_cast<BaseInst*>(inst));
return; return;
} }
Addr targetAddr = inst->getImmPCOffsetTarget(); Addr targetAddr = inst->GetImmPCOffsetTarget();
Label *true_label = new Label(); Label *true_label = new Label();
Label *false_label = new Label(); Label *false_label = new Label();
...@@ -122,13 +122,13 @@ IMPL_RELOCATE(B_COND) { ...@@ -122,13 +122,13 @@ IMPL_RELOCATE(B_COND) {
IMPL_RELOCATE(TBZ_TBNZ) { IMPL_RELOCATE(TBZ_TBNZ) {
if (inRelocateRange(inst->offset, sizeof(InstA64))) { if (inRelocateRange(inst->offset, sizeof(InstA64))) {
inst->ref(); inst->Ref();
inst->bindLabel(*getLaterBindLabel(inst->offset + curOffset)); inst->BindLabel(getLaterBindLabel(inst->offset + curOffset));
__ Emit(reinterpret_cast<Instruction<Base>*>(inst)); __ Emit(reinterpret_cast<BaseInst*>(inst));
return; return;
} }
Addr targetAddr = inst->getImmPCOffsetTarget(); Addr targetAddr = inst->GetImmPCOffsetTarget();
Label *true_label = new Label(); Label *true_label = new Label();
Label *false_label = new Label(); Label *false_label = new Label();
...@@ -150,13 +150,13 @@ IMPL_RELOCATE(TBZ_TBNZ) { ...@@ -150,13 +150,13 @@ IMPL_RELOCATE(TBZ_TBNZ) {
IMPL_RELOCATE(CBZ_CBNZ) { IMPL_RELOCATE(CBZ_CBNZ) {
if (inRelocateRange(inst->offset, sizeof(InstA64))) { if (inRelocateRange(inst->offset, sizeof(InstA64))) {
inst->ref(); inst->Ref();
inst->bindLabel(*getLaterBindLabel(inst->offset + curOffset)); inst->BindLabel(getLaterBindLabel(inst->offset + curOffset));
__ Emit(reinterpret_cast<Instruction<Base>*>(inst)); __ Emit(reinterpret_cast<BaseInst*>(inst));
return; return;
} }
Addr targetAddr = inst->getImmPCOffsetTarget(); Addr targetAddr = inst->GetImmPCOffsetTarget();
Label *true_label = new Label(); Label *true_label = new Label();
Label *false_label = new Label(); Label *false_label = new Label();
...@@ -177,14 +177,14 @@ IMPL_RELOCATE(CBZ_CBNZ) { ...@@ -177,14 +177,14 @@ IMPL_RELOCATE(CBZ_CBNZ) {
} }
IMPL_RELOCATE(LDR_LIT) { IMPL_RELOCATE(LDR_LIT) {
Addr targetAddr = inst->getImmPCOffsetTarget(); Addr targetAddr = inst->GetImmPCOffsetTarget();
XRegister* rtX = XReg(inst->rt->getCode()); XRegister* rtX = XReg(inst->rt->Code());
WRegister* rtW = WReg(inst->rt->getCode()); WRegister* rtW = WReg(inst->rt->Code());
if (inRelocateRange(inst->offset, sizeof(Addr))) { if (inRelocateRange(inst->offset, sizeof(Addr))) {
inst->ref(); inst->Ref();
inst->bindLabel(*getLaterBindLabel(inst->offset + curOffset)); inst->BindLabel(getLaterBindLabel(inst->offset + curOffset));
__ Emit(reinterpret_cast<Instruction<Base>*>(inst)); __ Emit(reinterpret_cast<BaseInst*>(inst));
return; return;
} }
...@@ -211,5 +211,5 @@ IMPL_RELOCATE(LDR_LIT) { ...@@ -211,5 +211,5 @@ IMPL_RELOCATE(LDR_LIT) {
} }
IMPL_RELOCATE(ADR_ADRP) { IMPL_RELOCATE(ADR_ADRP) {
__ Mov(*inst->rd, inst->getImmPCOffsetTarget()); __ Mov(*inst->rd, inst->GetImmPCOffsetTarget());
} }
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
// Created by swift on 2019/5/12. // Created by swift on 2019/5/12.
// //
#ifndef SANDHOOK_NH_CODE_RELOCATE_A64_H #pragma once
#define SANDHOOK_NH_CODE_RELOCATE_A64_H
#include <mutex> #include <mutex>
#include <map> #include <map>
...@@ -23,11 +22,11 @@ namespace SandHook { ...@@ -23,11 +22,11 @@ namespace SandHook {
public: public:
CodeRelocateA64(AssemblerA64 &assembler); CodeRelocateA64(AssemblerA64 &assembler);
void* relocate(Instruction<Base> *instruction, void *toPc) throw(ErrorCodeException) override; void* relocate(BaseInst *instruction, void *toPc) throw(ErrorCodeException) override;
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(Unit<Base> *unit, void *pc) override;
DEFINE_RELOCATE(B_BL) DEFINE_RELOCATE(B_BL)
...@@ -49,6 +48,4 @@ namespace SandHook { ...@@ -49,6 +48,4 @@ namespace SandHook {
} }
} }
#undef DEFINE_RELOCATE #undef DEFINE_RELOCATE
\ No newline at end of file
#endif //SANDHOOK_NH_CODE_RELOCATE_A64_H
...@@ -2,30 +2,29 @@ ...@@ -2,30 +2,29 @@
// Created by swift on 2019/5/16. // Created by swift on 2019/5/16.
// //
#ifndef SANDHOOK_ARM_BASE_H #pragma once
#define SANDHOOK_ARM_BASE_H
// Condition codes. // Condition codes.
enum Condition { enum Condition {
eq = 0, // Z set Equal. eq = 0, // Z Set Equal.
ne = 1, // Z clear Not equal. ne = 1, // Z clear Not equal.
cs = 2, // C set Carry set. cs = 2, // C Set Carry Set.
cc = 3, // C clear Carry clear. cc = 3, // C clear Carry clear.
mi = 4, // N set Negative. mi = 4, // N Set Negative.
pl = 5, // N clear Positive or zero. pl = 5, // N clear Positive or zero.
vs = 6, // V set Overflow. vs = 6, // V Set Overflow.
vc = 7, // V clear No overflow. vc = 7, // V clear No overflow.
hi = 8, // C set, Z clear Unsigned higher. hi = 8, // C Set, Z clear Unsigned higher.
ls = 9, // C clear or Z set Unsigned lower or same. ls = 9, // C clear or Z Set Unsigned lower or same.
ge = 10, // N == V Greater or equal. ge = 10, // N == V Greater or equal.
lt = 11, // N != V Less than. lt = 11, // N != V Less than.
gt = 12, // Z clear, N == V Greater than. gt = 12, // Z clear, N == V Greater than.
le = 13, // Z set or N != V Less then or equal le = 13, // Z Set or N != V Less then or equal
al = 14, // Always. al = 14, // Always.
nv = 15, // Behaves as always/al. nv = 15, // Behaves as always/al.
// Aliases. // Aliases.
hs = cs, // C set Unsigned higher or same. hs = cs, // C Set Unsigned higher or same.
lo = cc // C clear Unsigned lower. lo = cc // C clear Unsigned lower.
}; };
...@@ -42,31 +41,29 @@ enum Shift { ...@@ -42,31 +41,29 @@ enum Shift {
enum AddrMode { Offset, PreIndex, PostIndex, NonAddrMode}; enum AddrMode { Offset, PreIndex, PostIndex, NonAddrMode};
//decode field & encode field //Disassembler field & encode field
//condition //condition
#define DECODE_COND condition = Condition(inst->cond) #define DECODE_COND condition = Condition(Get()->cond)
#define ENCODE_COND get()->cond = condition #define ENCODE_COND Get()->cond = condition
//reg //reg_
#define DECODE_RD(Type) rd = Type(static_cast<U8>(get()->rd)) #define DECODE_RD(Type) rd = Type(static_cast<U8>(Get()->rd))
#define ENCODE_RD get()->rd = rd->getCode() #define ENCODE_RD Get()->rd = rd->Code()
#define DECODE_RT(Type) rt = Type(static_cast<U8>(get()->rt)) #define DECODE_RT(Type) rt = Type(static_cast<U8>(Get()->rt))
#define ENCODE_RT get()->rt = rt->getCode() #define ENCODE_RT Get()->rt = rt->Code()
#define DECODE_RM(Type) rm = Type(static_cast<U8>(get()->rm)) #define DECODE_RM(Type) rm = Type(static_cast<U8>(Get()->rm))
#define ENCODE_RM get()->rm = rm->getCode() #define ENCODE_RM Get()->rm = rm->Code()
#define DECODE_RN(Type) rn = Type(static_cast<U8>(get()->rn)) #define DECODE_RN(Type) rn = Type(static_cast<U8>(Get()->rn))
#define ENCODE_RN get()->rn = rn->getCode() #define ENCODE_RN Get()->rn = rn->Code()
//op //op
#define DECODE_OP op = OP(inst->op) #define DECODE_OP op = OP(Get()->op)
#define ENCODE_OP get()->op = op #define ENCODE_OP Get()->op = op
#define DECODE_SHIFT operand.shift = Shift(inst->shift) #define DECODE_SHIFT operand.shift_ = Shift(Get()->shift)
#define ENCODE_SHIFT get()->shift = operand.shift #define ENCODE_SHIFT Get()->shift = operand.shift_
\ No newline at end of file
#endif //SANDHOOK_ARM_BASE_H
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
// Created by swift on 2019/6/1. // Created by swift on 2019/6/1.
// //
#ifndef SANDHOOK_SHELL_CODE_ARM_H #pragma once
#define SANDHOOK_SHELL_CODE_ARM_H
//for shell code //for shell code
#define FUNCTION_START(x) \ #define FUNCTION_START(x) \
...@@ -29,6 +28,4 @@ extern "C" void x##_END(); ...@@ -29,6 +28,4 @@ extern "C" void x##_END();
#define IMPORT_LABEL(X,T) extern T X; #define IMPORT_LABEL(X,T) extern T X;
#define SHELLCODE_LEN(x) (Addr)x##_END - (Addr)x #define SHELLCODE_LEN(x) (Addr)x##_END - (Addr)x
\ No newline at end of file
#endif //SANDHOOK_SHELL_CODE_ARM_H
// //
// Created by swift on 2019/5/16. // Created by swift on 2019/5/16.
// //
#pragma once
#ifndef SANDHOOK_PLACE_HOLDER_H
#define SANDHOOK_PLACE_HOLDER_H
#endif //SANDHOOK_PLACE_HOLDER_H
// //
// Created by SwiftGan on 2019/4/15. // Created by SwiftGan on 2019/4/15.
// //
#pragma once
#ifndef SANDHOOK_CPU_H
#define SANDHOOK_CPU_H
#include "register.h" #include "register.h"
...@@ -17,4 +15,3 @@ namespace SandHook { ...@@ -17,4 +15,3 @@ namespace SandHook {
} }
} }
#endif //SANDHOOK_CPU_H
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
// Created by swift on 2019/5/10. // Created by swift on 2019/5/10.
// //
#ifndef SANDHOOK_NH_DATA_H #pragma once
#define SANDHOOK_NH_DATA_H
#include "unit.h" #include "unit.h"
...@@ -21,15 +20,22 @@ public: \ ...@@ -21,15 +20,22 @@ public: \
namespace SandHook { namespace SandHook {
namespace Asm { namespace Asm {
template <typename DType> template <typename D>
class Data : public Unit<DType> { class Data : public Unit<D> {
public: public:
Data(DType raw) : Unit<DType>() {
this->set(raw); Data(D raw) : backup_(raw) {}
}
inline UnitType unitType() override { INLINE UnitTypeDef UnitType() override {
return UnitType::UnitData; return UnitTypeDef::UnitData;
}; };
void Move(D *dest) override {
*dest = backup_;
}
private:
D backup_;
}; };
...@@ -52,6 +58,4 @@ namespace SandHook { ...@@ -52,6 +58,4 @@ namespace SandHook {
}; };
} }
} }
\ No newline at end of file
#endif //SANDHOOK_NH_DATA_H
//
// Created by SwiftGan on 2019/4/15.
//
#ifndef SANDHOOK_IMME_H
#define SANDHOOK_IMME_H
#include "../includes/base.h"
namespace SandHook {
namespace Asm {
template <typename ImmeType>
class Imme {
public:
virtual ImmeType get() = 0;
virtual void set(ImmeType imme) = 0;
U8 size() {
return immeSize;
};
private:
//byte
U8 immeSize;
ImmeType value;
Arch arch;
InstType instType;
};
}
}
#endif //SANDHOOK_IMME_H
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
// Created by SwiftGan on 2019/4/15. // Created by SwiftGan on 2019/4/15.
// //
#ifndef SANDHOOK_INSTRUCTION_H #pragma once
#define SANDHOOK_INSTRUCTION_H
#include <memory>
#include "unit.h" #include "unit.h"
#include "label.h" #include "label.h"
...@@ -23,84 +23,87 @@ typedef U32 InstRaw; ...@@ -23,84 +23,87 @@ typedef U32 InstRaw;
#define INST_CHECK(X,V) \ #define INST_CHECK(X,V) \
CHECK(X,V, valid = false;) CHECK(X,V, valid_ = false;)
#define INST_DCHECK(X,V) \ #define INST_DCHECK(X,V) \
DCHECK(X,V, valid = false;) DCHECK(X,V, valid_ = false;)
#define INST_ASSERT(COND) \ #define INST_ASSERT(COND) \
if (COND) { \ if (COND) { \
valid = false; \ valid_ = false; \
} }
namespace SandHook { namespace SandHook {
namespace Asm { namespace Asm {
template <typename Inst> template <typename S, U32 C>
class Instruction : public Unit<Inst>, public LabelBinder { class Instruction : public Unit<S>, public LabelBinder {
public: public:
Instruction() {} Instruction() {}
Instruction(Inst *inst) : Unit<Inst>(inst) {} Instruction(void *inst) : Unit<S>(inst) {}
Instruction(S *inst) : Unit<S>(inst) {}
UnitType unitType() override { UnitTypeDef UnitType() override {
return UnitType::UnitInst; return UnitTypeDef::UnitInst;
}; };
virtual InstType instType() { virtual InstType InstType() {
return unknowInst; return unknowInst;
} }
virtual Arch arch() { virtual Arch Arch() {
return unknowArch; return unknowArch;
} }
virtual U32 instCode() { virtual U32 InstCode() {
return 0; return C;
}; };
virtual bool pcRelate() { virtual bool PcRelate() {
return false; return false;
} }
virtual bool unknow() { virtual bool Unknow() {
return false; return false;
} }
inline bool isValid() const { inline bool Valid() const {
return valid; return valid_;
} }
virtual void onOffsetApply(Off offset) {} virtual void OnOffsetApply(Off offset) {}
void onLabelApply(Addr pc) override { void OnLabelApply(Addr pc) override {
onOffsetApply(pc - this->getVPC()); OnOffsetApply(pc - this->GetVPC());
} }
inline void bindLabel(Label &l) { INLINE void BindLabel(Label *label) {
label = &l; label_ = label;
l.addBinder(this); label->AddBind(this);
} }
virtual void decode(Inst* inst) { virtual void Disassembler() {
inst_backup = *inst; backup_ = *this->pc_;
} }
virtual void assembler() { virtual void Assembler() {
this->set(inst_backup); *this->pc_ = backup_;
} }
protected: protected:
bool valid = true; bool valid_ = true;
Label* label = nullptr; Label* label_ = nullptr;
Inst inst_backup; S backup_;
}; };
class Void : public Unit<Base> { class Void : public Unit<Base> {
public: public:
Void(U32 size) : size_(size) {} Void(U32 size) : size_(size) {}
U32 size() override { U32 Size() override {
return size_; return size_;
} }
...@@ -108,7 +111,8 @@ namespace SandHook { ...@@ -108,7 +111,8 @@ namespace SandHook {
U32 size_; U32 size_;
}; };
using BaseInst = Instruction<Base,0>;
using BaseInstRef = std::shared_ptr<BaseInst>;
} }
} }
#endif //SANDHOOK_INSTRUCTION_H
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
// Created by swift on 2019/5/10. // Created by swift on 2019/5/10.
// //
#ifndef SANDHOOK_NH_LABEL_H #pragma once
#define SANDHOOK_NH_LABEL_H
#include "unit.h" #include "unit.h"
#include <list> #include <list>
...@@ -13,53 +12,42 @@ namespace SandHook { ...@@ -13,53 +12,42 @@ namespace SandHook {
class LabelBinder { class LabelBinder {
public: public:
virtual void onLabelApply(Addr pc) = 0; virtual void OnLabelApply(Addr pc) = 0;
}; };
class Label : public Unit<Base> { class Label : public BaseUnit {
public: public:
Label() {} Label() {}
Label(void *pc) : pc(pc) {} Label(void *pc) : Unit<Base>(pc) {}
inline UnitType unitType() override { enum UnitTypeDef UnitType() override {
return UnitType::UnitLabel; return UnitTypeDef::UnitLabel;
} }
inline U32 size() override { INLINE U32 Size() override {
return 0; return 0;
} }
inline void setPC(void* pc) { INLINE void AddBind(LabelBinder *binder) {
this->pc = pc;
}
inline void *getPC() override {
return pc;
}
inline void addBinder(LabelBinder* binder) {
binders.push_back(binder); binders.push_back(binder);
} }
inline void removeBinder(LabelBinder* binder) { INLINE void RemoveBind(LabelBinder *binder) {
binders.push_back(binder); binders.push_back(binder);
} }
inline void bindLabel() { INLINE void BindLabel() {
std::list<LabelBinder*>::iterator binder; std::list<LabelBinder*>::iterator binder;
for(binder = binders.begin();binder != binders.end(); ++binder) { for(binder = binders.begin();binder != binders.end(); ++binder) {
(*binder)->onLabelApply(getVPC()); (*binder)->OnLabelApply(GetVPC());
} }
} }
private: private:
void* pc;
std::list<LabelBinder*> binders = std::list<LabelBinder*>(); std::list<LabelBinder*> binders = std::list<LabelBinder*>();
}; };
} }
} }
\ No newline at end of file
#endif //SANDHOOK_NH_LABEL_H
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
include ':app', ':hooklib', ':hookers', ':annotation', ':xposedcompat', ':nativehook', ':xposedcompat_new' include ':app', ':hooklib', ':hookers', ':annotation', ':xposedcompat', ':nativehook'
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