Commit 0d3eb16a authored by swift_gan's avatar swift_gan

start reconsitution

parent 6a6129fe
......@@ -6,6 +6,7 @@ import com.swift.sandhook.MainActivity;
import com.swift.sandhook.annotation.HookClass;
import com.swift.sandhook.annotation.HookMethod;
import com.swift.sandhook.annotation.HookMethodBackup;
import com.swift.sandhook.annotation.HookMode;
import com.swift.sandhook.annotation.MethodParams;
import java.lang.reflect.Method;
......@@ -19,6 +20,7 @@ public class CustmizeHooker {
@HookMethod("methodBeHooked")
@MethodParams({int.class, int.class})
@HookMode(HookMode.REPLACE)
public static int staticMethodHooked(int a, int b) {
Log.e("CustmizeHooker", "methodBeHooked be hooked");
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:
class ArtMethod {
public:
// uint32_t declaring_class_;
//
// // Access flags; low 16 bits are defined by spec.
// // Getting and setting this flag needs to be atomic when concurrency is
// // possible, e.g. after this method's class is linked. Such as when setting
// // verifier flags and single-implementation flag.
// uint32_t access_flags_;
//
// /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
//
// // Offset to the CodeItem.
// uint32_t dex_code_item_offset_;
//
// // Index into method_ids of the dex file associated with this method.
// uint32_t dex_method_index_;
//
// /* End of dex file fields. */
//
// // Entry within a dispatch table for this method. For static/direct methods the index is into
// // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
// // ifTable.
// uint16_t method_index_;
//
// // The hotness we measure for this method. Managed by the interpreter. Not atomic, as we allow
// // missing increments: if the method is hot, we will see it eventually.
// uint16_t hotness_count_;
//
// // 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;
void* codeEntry;
bool isAbstract();
bool isNative();
bool isCompiled();
void setAccessFlags(uint32_t flags);
void disableCompilable();
void tryDisableInline();
void disableInterpreterForO();
void setPrivate();
void setStatic();
void setQuickCodeEntry(void* entry);
void setJniCodeEntry(void* entry);
void setInterpreterCodeEntry(void* entry);
void setDexCacheResolveItem(ArtMethod* method, uint32_t index);
void* getQuickCodeEntry();
void* getInterpreterCodeEntry();
uint32_t getAccessFlags();
uint32_t getDexMethodIndex();
bool compile();
void flushCache();
void backup(ArtMethod* backup);
};
}
......
......@@ -18,6 +18,15 @@ namespace SandHook {
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) {
if (size > EXE_BLOCK_SIZE)
return 0;
......@@ -78,8 +87,7 @@ namespace SandHook {
HookTrampoline* TrampolineManager::installInlineTrampoline(mirror::ArtMethod *originMethod,
mirror::ArtMethod *hookMethod,
mirror::ArtMethod *backupMethod,
bool isNative) {
mirror::ArtMethod *backupMethod) {
AutoLock autoLock(installLock);
......@@ -93,12 +101,6 @@ namespace SandHook {
Code callOriginTrampolineSpace;
Code originEntry;
if (!isNative) {
uint32_t originCodeSize = sizeOfEntryCode(originMethod);
if (originCodeSize < SIZE_DIRECT_JUMP_TRAMPOLINE)
goto label_error;
}
//生成二段跳板
inlineHookTrampoline = new InlineHookTrampoline();
checkThumbCode(inlineHookTrampoline, getEntryCode(originMethod));
......
......@@ -48,6 +48,8 @@ namespace SandHook {
HookTrampoline* installInlineTrampoline(mirror::ArtMethod* originMethod, mirror::ArtMethod* hookMethod, mirror::ArtMethod* backupMethod,
bool isNative);
bool canSafeInline(mirror::ArtMethod* method, char* msg);
uint32_t sizeOfEntryCode(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