Commit 5bc325a2 authored by swift_gan's avatar swift_gan

[reconsit]done

parent 5bd6ce01
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
#include "../includes/art_method.h" #include "../includes/art_method.h"
#include "../includes/cast_art_method.h" #include "../includes/cast_art_method.h"
#include "../includes/hide_api.h" #include "../includes/hide_api.h"
#include "../includes/utils.h"
using namespace art::mirror; using namespace art::mirror;
using namespace SandHook; using namespace SandHook;
void ArtMethod::tryDisableInline() { void ArtMethod::tryDisableInline() {
if (SDK_INT < ANDROID_O) if (SDK_INT < ANDROID_O)
return; return;
...@@ -47,7 +47,7 @@ bool ArtMethod::isNative() { ...@@ -47,7 +47,7 @@ bool ArtMethod::isNative() {
} }
bool ArtMethod::isCompiled() { bool ArtMethod::isCompiled() {
return getQuickCodeEntry() == SandHook::CastArtMethod::quickToInterpreterBridge; return getQuickCodeEntry() != SandHook::CastArtMethod::quickToInterpreterBridge;
} }
void ArtMethod::setAccessFlags(uint32_t flags) { void ArtMethod::setAccessFlags(uint32_t flags) {
...@@ -94,23 +94,31 @@ void ArtMethod::setInterpreterCodeEntry(void *entry) { ...@@ -94,23 +94,31 @@ void ArtMethod::setInterpreterCodeEntry(void *entry) {
CastArtMethod::entryPointFormInterpreter->set(this, entry); CastArtMethod::entryPointFormInterpreter->set(this, entry);
} }
void ArtMethod::setDexCacheResolveList(void *list) {
CastArtMethod::dexCacheResolvedMethods->set(this, list);
}
void ArtMethod::setDexCacheResolveItem(uint32_t index, void* item) { void ArtMethod::setDexCacheResolveItem(uint32_t index, void* item) {
CastArtMethod::dexCacheResolvedMethods->setElement(this, index, item); CastArtMethod::dexCacheResolvedMethods->setElement(this, index, item);
} }
bool ArtMethod::compile() { bool ArtMethod::compile(JNIEnv* env) {
// if (isCompiled()) if (isCompiled())
// return true; return true;
// Size threadId = getAddressFromJavaByCallMethod(env, "com/swift/sandhook/SandHook", "getThreadId"); Size threadId = getAddressFromJavaByCallMethod(env, "com/swift/sandhook/SandHook", "getThreadId");
// if (threadId == 0) if (threadId == 0)
// return false; return false;
// return compileMethod(this, ) && isCompiled(); return compileMethod(this, reinterpret_cast<void *>(threadId)) && isCompiled();
} }
void ArtMethod::flushCache() { void ArtMethod::flushCache() {
flushCacheExt(reinterpret_cast<Size>(this), size());
} }
void ArtMethod::backup(ArtMethod *backup) { void ArtMethod::backup(ArtMethod *backup) {
memcpy(backup, this, size());
}
Size ArtMethod::size() {
return CastArtMethod::size;
} }
\ No newline at end of file
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
#ifndef ART_H #ifndef ART_H
#define ART_H #define ART_H
#include <jni.h>
#include "arch.h"
namespace art { namespace art {
namespace mirror { namespace mirror {
class Object { class Object {
...@@ -41,7 +44,6 @@ public: ...@@ -41,7 +44,6 @@ public:
class ArtMethod { class ArtMethod {
public: public:
void* codeEntry;
bool isAbstract(); bool isAbstract();
bool isNative(); bool isNative();
...@@ -57,6 +59,7 @@ public: ...@@ -57,6 +59,7 @@ public:
void setQuickCodeEntry(void* entry); void setQuickCodeEntry(void* entry);
void setJniCodeEntry(void* entry); void setJniCodeEntry(void* entry);
void setInterpreterCodeEntry(void* entry); void setInterpreterCodeEntry(void* entry);
void setDexCacheResolveList(void* list);
void setDexCacheResolveItem(uint32_t index, void* item); void setDexCacheResolveItem(uint32_t index, void* item);
void* getQuickCodeEntry(); void* getQuickCodeEntry();
...@@ -64,10 +67,12 @@ public: ...@@ -64,10 +67,12 @@ public:
uint32_t getAccessFlags(); uint32_t getAccessFlags();
uint32_t getDexMethodIndex(); uint32_t getDexMethodIndex();
bool compile(); bool compile(JNIEnv* env);
void flushCache(); void flushCache();
void backup(ArtMethod* backup); void backup(ArtMethod* backup);
static Size size();
}; };
} }
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
extern "C" { extern "C" {
void initHideApi(JNIEnv *env, int SDK_VERSION); void initHideApi(JNIEnv *env, int SDK_VERSION);
bool compileMethod(void *artMethod, void *thread); bool compileMethod(void *artMethod, void *thread);
} }
......
...@@ -10,16 +10,19 @@ ...@@ -10,16 +10,19 @@
#include "jni.h" #include "jni.h"
#include "../includes/arch.h" #include "../includes/arch.h"
#include <unistd.h> #include <unistd.h>
#include <sys/mman.h>
extern "C" { extern "C" {
Size getAddressFromJava(JNIEnv *env, const char *className, const char *fieldName); Size getAddressFromJava(JNIEnv *env, const char *className, const char *fieldName);
Size getAddressFromJavaByCallMethod(JNIEnv *env, const char *className, const char *methodName);
Size getAddressFromJavaByCallMethod(JNIEnv *env, const char *className, const char *methodName); jint getIntFromJava(JNIEnv *env, const char *className, const char *fieldName);
jint getIntFromJava(JNIEnv *env, const char *className, const char *fieldName); bool munprotect(size_t addr, size_t len);
bool munprotect(size_t addr, size_t len); bool flushCacheExt(Size addr, Size len);
} }
......
This diff is collapsed.
...@@ -59,5 +59,19 @@ extern "C" { ...@@ -59,5 +59,19 @@ extern "C" {
return true; return true;
} }
bool flushCacheExt(Size addr, Size len) {
#if defined(__arm__)
int i = cacheflush(addr, addr + len, 0);
if (i == -1) {
return false;
}
return true;
#elif defined(__aarch64__)
char *begin = reinterpret_cast<char *>(addr);
__builtin___clear_cache(begin, begin + len);
#endif
return true;
}
} }
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