Commit 0d3eb16a authored by swift_gan's avatar swift_gan

start reconsitution

parent 6a6129fe
...@@ -6,6 +6,7 @@ import com.swift.sandhook.MainActivity; ...@@ -6,6 +6,7 @@ import com.swift.sandhook.MainActivity;
import com.swift.sandhook.annotation.HookClass; import com.swift.sandhook.annotation.HookClass;
import com.swift.sandhook.annotation.HookMethod; import com.swift.sandhook.annotation.HookMethod;
import com.swift.sandhook.annotation.HookMethodBackup; import com.swift.sandhook.annotation.HookMethodBackup;
import com.swift.sandhook.annotation.HookMode;
import com.swift.sandhook.annotation.MethodParams; import com.swift.sandhook.annotation.MethodParams;
import java.lang.reflect.Method; import java.lang.reflect.Method;
...@@ -19,6 +20,7 @@ public class CustmizeHooker { ...@@ -19,6 +20,7 @@ public class CustmizeHooker {
@HookMethod("methodBeHooked") @HookMethod("methodBeHooked")
@MethodParams({int.class, int.class}) @MethodParams({int.class, int.class})
@HookMode(HookMode.REPLACE)
public static int staticMethodHooked(int a, int b) { public static int staticMethodHooked(int a, int b) {
Log.e("CustmizeHooker", "methodBeHooked be hooked"); Log.e("CustmizeHooker", "methodBeHooked be hooked");
try { try {
......
//
// Created by swift on 2019/2/3.
//
#include <cstdint>
#include "art.h"
#include <../cast_art_method.h>
namespace art::mirror {
void ArtMethod::setStatic() {
};
void ArtMethod::tryDisableInline() {
}
void ArtMethod::disableInterpreterForO() {
}
void ArtMethod::disableCompilable() {
}
bool ArtMethod::isAbstract() {
}
bool ArtMethod::isNative() {
}
void ArtMethod::setAccessFlags(uint32_t flags) {
}
void ArtMethod::setPrivate() {
}
}
\ No newline at end of file
...@@ -41,50 +41,33 @@ public: ...@@ -41,50 +41,33 @@ public:
class ArtMethod { class ArtMethod {
public: public:
// uint32_t declaring_class_; void* codeEntry;
//
// // Access flags; low 16 bits are defined by spec. bool isAbstract();
// // Getting and setting this flag needs to be atomic when concurrency is bool isNative();
// // possible, e.g. after this method's class is linked. Such as when setting bool isCompiled();
// // verifier flags and single-implementation flag.
// uint32_t access_flags_; void setAccessFlags(uint32_t flags);
// void disableCompilable();
// /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */ void tryDisableInline();
// void disableInterpreterForO();
// // Offset to the CodeItem. void setPrivate();
// uint32_t dex_code_item_offset_; void setStatic();
//
// // Index into method_ids of the dex file associated with this method. void setQuickCodeEntry(void* entry);
// uint32_t dex_method_index_; void setJniCodeEntry(void* entry);
// void setInterpreterCodeEntry(void* entry);
// /* End of dex file fields. */ void setDexCacheResolveItem(ArtMethod* method, uint32_t index);
//
// // Entry within a dispatch table for this method. For static/direct methods the index is into void* getQuickCodeEntry();
// // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the void* getInterpreterCodeEntry();
// // ifTable. uint32_t getAccessFlags();
// uint16_t method_index_; uint32_t getDexMethodIndex();
//
// // The hotness we measure for this method. Managed by the interpreter. Not atomic, as we allow bool compile();
// // missing increments: if the method is hot, we will see it eventually. void flushCache();
// uint16_t hotness_count_; void backup(ArtMethod* backup);
//
// // Fake padding field gets inserted here.
//
// // Must be the last fields in the method.
// struct PtrSizedFields {
// // Short cuts to declaring_class_->dex_cache_ member for fast compiled code access.
// void* dex_cache_resolved_methods_;
//
// // Pointer to JNI function registered to this method, or a function to resolve the JNI function,
// // or the profiling data for non-native methods, or an ImtConflictTable, or the
// // single-implementation of an abstract/interface method.
// void* data_;
//
// // Method dispatch from quick compiled code invokes this pointer which may cause bridging into
// // the interpreter.
// void* entry_point_from_quick_compiled_code_;
// } ptr_sized_fields_;
void * placeHolder;
}; };
} }
......
...@@ -18,6 +18,15 @@ namespace SandHook { ...@@ -18,6 +18,15 @@ namespace SandHook {
return size; return size;
} }
bool TrampolineManager::canSafeInline(mirror::ArtMethod *method, char *msg) {
//check size
if (!isNative) {
uint32_t originCodeSize = sizeOfEntryCode(originMethod);
if (originCodeSize < SIZE_DIRECT_JUMP_TRAMPOLINE)
goto label_error;
}
}
Code TrampolineManager::allocExecuteSpace(Size size) { Code TrampolineManager::allocExecuteSpace(Size size) {
if (size > EXE_BLOCK_SIZE) if (size > EXE_BLOCK_SIZE)
return 0; return 0;
...@@ -78,8 +87,7 @@ namespace SandHook { ...@@ -78,8 +87,7 @@ namespace SandHook {
HookTrampoline* TrampolineManager::installInlineTrampoline(mirror::ArtMethod *originMethod, HookTrampoline* TrampolineManager::installInlineTrampoline(mirror::ArtMethod *originMethod,
mirror::ArtMethod *hookMethod, mirror::ArtMethod *hookMethod,
mirror::ArtMethod *backupMethod, mirror::ArtMethod *backupMethod) {
bool isNative) {
AutoLock autoLock(installLock); AutoLock autoLock(installLock);
...@@ -93,12 +101,6 @@ namespace SandHook { ...@@ -93,12 +101,6 @@ namespace SandHook {
Code callOriginTrampolineSpace; Code callOriginTrampolineSpace;
Code originEntry; Code originEntry;
if (!isNative) {
uint32_t originCodeSize = sizeOfEntryCode(originMethod);
if (originCodeSize < SIZE_DIRECT_JUMP_TRAMPOLINE)
goto label_error;
}
//生成二段跳板 //生成二段跳板
inlineHookTrampoline = new InlineHookTrampoline(); inlineHookTrampoline = new InlineHookTrampoline();
checkThumbCode(inlineHookTrampoline, getEntryCode(originMethod)); checkThumbCode(inlineHookTrampoline, getEntryCode(originMethod));
......
...@@ -48,6 +48,8 @@ namespace SandHook { ...@@ -48,6 +48,8 @@ namespace SandHook {
HookTrampoline* installInlineTrampoline(mirror::ArtMethod* originMethod, mirror::ArtMethod* hookMethod, mirror::ArtMethod* backupMethod, HookTrampoline* installInlineTrampoline(mirror::ArtMethod* originMethod, mirror::ArtMethod* hookMethod, mirror::ArtMethod* backupMethod,
bool isNative); bool isNative);
bool canSafeInline(mirror::ArtMethod* method, char* msg);
uint32_t sizeOfEntryCode(mirror::ArtMethod* method); uint32_t sizeOfEntryCode(mirror::ArtMethod* method);
HookTrampoline* getHookTrampoline(mirror::ArtMethod* method) { HookTrampoline* getHookTrampoline(mirror::ArtMethod* method) {
......
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