Commit efb8f4c6 authored by swift_gan's avatar swift_gan Committed by swift_gan

remove useless code

parent 56125250
//
// Created by 甘尧 on 2019/1/12.
//
#include "../includes/ICast.h"
#include "art/art_6_0.h"
namespace SandHook {
class CastDexCacheResolvedMethods : public IMember<art::mirror::ArtMethod, void*> {
protected:
Size calOffset(JNIEnv *jniEnv, art::mirror::ArtMethod p) override {
if (SDK_INT >= ANDROID_P)
return getParentSize() + 1;
int offset = 0;
Size addr = getAddressFromJava(jniEnv, "com/swift/sandhook/SandHookMethodResolver", "resolvedMethodsAddress");
if (addr != 0) {
offset = findOffset(&p, getParentSize(), 2, reinterpret_cast<void *>(addr));
if (offset >= 0) {
return static_cast<Size>(offset);
}
}
return getParentSize() + 1;
}
};
class CastEntryPointFormInterpreter : public IMember<art::mirror::ArtMethod, void*> {
protected:
Size calOffset(JNIEnv *jniEnv, art::mirror::ArtMethod p) override {
if (SDK_INT <= ANDROID_M)
return getParentSize() - 3 * BYTE_POINT;
else
return getParentSize() + 1;
}
};
class CastEntryPointQuickCompiled : public IMember<art::mirror::ArtMethod, void*> {
protected:
Size calOffset(JNIEnv *jniEnv, art::mirror::ArtMethod p) override {
if (SDK_INT >= ANDROID_L2) {
return getParentSize() - BYTE_POINT;
} else {
return getParentSize() - 8 * 2 - 4 * 4;
}
}
};
class CastEntryPointFromJni : public IMember<art::mirror::ArtMethod, void*> {
protected:
Size calOffset(JNIEnv *jniEnv, art::mirror::ArtMethod p) override {
if (SDK_INT >= ANDROID_L2 && SDK_INT <= ANDROID_N) {
return getParentSize() - 2 * BYTE_POINT;
} else {
return getParentSize() - 8 * 2 - 4 * 4;
}
}
};
class CastAccessFlag : public IMember<art::mirror::ArtMethod, uint32_t> {
protected:
Size calOffset(JNIEnv *jniEnv, art::mirror::ArtMethod p) override {
int offset = findOffset(&p, getParentSize(), sizeof(uint32_t), 524313);
if (offset < 0)
throw getParentSize() + 1;
else
return static_cast<size_t>(offset);
}
};
class CastDexMethodIndex : public IMember<art::mirror::ArtMethod, uint32_t> {
protected:
Size calOffset(JNIEnv *jniEnv, art::mirror::ArtMethod p) override {
if (SDK_INT >= ANDROID_P)
return getParentSize() + 1;
int offset = 0;
jint index = getIntFromJava(jniEnv, "com/swift/sandhook/SandHookMethodResolver", "dexMethodIndex");
if (index != 0) {
offset = findOffset(&p, getParentSize(), 2, static_cast<uint32_t>(index));
if (offset >= 0) {
return static_cast<Size>(offset);
}
}
return getParentSize() + 1;
}
};
class CastArtMethod {
public:
static Size size;
static IMember<art::mirror::ArtMethod, void*>* entryPointQuickCompiled;
static IMember<art::mirror::ArtMethod, void*>* entryPointFormInterpreter;
static IMember<art::mirror::ArtMethod, void*>* dexCacheResolvedMethods;
static IMember<art::mirror::ArtMethod, uint32_t>* dexMethodIndex;
static IMember<art::mirror::ArtMethod, uint32_t>* accessFlag;
static void init(JNIEnv *env) {
//init ArtMethodSize
jclass sizeTestClass = env->FindClass("com/swift/sandhook/ArtMethodSizeTest");
Size artMethod1 = (Size) env->GetStaticMethodID(sizeTestClass, "method1", "()V");
Size artMethod2 = (Size) env->GetStaticMethodID(sizeTestClass, "method2", "()V");
size = artMethod2 - artMethod1;
art::mirror::ArtMethod m1 = *reinterpret_cast<art::mirror::ArtMethod *>(artMethod1);
art::mirror::ArtMethod m2 = *reinterpret_cast<art::mirror::ArtMethod *>(artMethod2);
//init Members
entryPointQuickCompiled = new CastEntryPointQuickCompiled();
entryPointQuickCompiled->init(env, m1, size);
accessFlag = new CastAccessFlag();
accessFlag->init(env, m1, size);
entryPointFormInterpreter = new CastEntryPointFormInterpreter();
entryPointFormInterpreter->init(env, m1, size);
dexCacheResolvedMethods = new CastDexCacheResolvedMethods();
dexCacheResolvedMethods->init(env, m1, size);
dexMethodIndex = new CastDexMethodIndex();
dexMethodIndex->init(env, m1, size);
// //test
// art::mirror::ArtMethod** mArray = reinterpret_cast<art::mirror::ArtMethod**>(m1.dex_cache_resolved_methods_);
//
// art::mirror::ArtMethod m1B = *mArray[m1.dex_method_index_];
// art::mirror::ArtMethod m1C = *mArray[m2.dex_method_index_];
}
static void copy(art::mirror::ArtMethod* from, art::mirror::ArtMethod* to) {
memcpy(to, from, size);
}
};
Size CastArtMethod::size = 0;
IMember<art::mirror::ArtMethod, void*>* CastArtMethod::entryPointQuickCompiled = nullptr;
IMember<art::mirror::ArtMethod, void*>* CastArtMethod::entryPointFormInterpreter = nullptr;
IMember<art::mirror::ArtMethod, void*>* CastArtMethod::dexCacheResolvedMethods = nullptr;
IMember<art::mirror::ArtMethod, uint32_t>* CastArtMethod::dexMethodIndex = nullptr;
IMember<art::mirror::ArtMethod, uint32_t>* CastArtMethod::accessFlag = nullptr;
}
//
// Created by 甘尧 on 2019/1/12.
//
#include <stdint.h>
#include <string.h>
#include "arch.h"
#include "utils.h"
#define ANDROID_L 21
#define ANDROID_L2 22
#define ANDROID_M 23
#define ANDROID_N 24
#define ANDROID_N2 25
#define ANDROID_O 26
#define ANDROID_O2 27
#define ANDROID_P 28
#ifndef SANDHOOK_ICAST_H
#define SANDHOOK_ICAST_H
namespace SandHook {
static int SDK_INT = 0;
template <typename T>
class ICast {
public:
ICast(T t) {
this->origin = t;
};
virtual Size getSize() { return sizeof(T); };
private:
T origin;
};
template <typename PType, typename MType>
class IMember {
public:
virtual void init(JNIEnv *jniEnv, PType p, Size size) {
this->parentSize = size;
offset = calOffset(jniEnv, p);
}
virtual Size getOffset() {
return offset;
}
virtual Size getParentSize() {
return parentSize;
}
virtual MType get(PType p) {
if (offset > parentSize)
return NULL;
return *reinterpret_cast<MType*>(&p + getOffset());
};
virtual void set(PType p, MType t) {
if (offset > parentSize)
return;
memcpy(&p + getOffset(), &t, sizeof(MType));
};
private:
Size offset = 0;
protected:
Size parentSize = 0;
virtual Size calOffset(JNIEnv *jniEnv, PType p) = 0;
};
}
#endif //SANDHOOK_ICAST_H
\ No newline at end of file
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