Commit 032ebf96 authored by swift_gan's avatar swift_gan

cal accessFlag offset

parent 1347ca13
......@@ -15,10 +15,25 @@ namespace SandHook {
};
class CastAccessFlag : public IMember<art::mirror::ArtMethod, uint32_t> {
protected:
Size calOffset(art::mirror::ArtMethod p) override {
int offset = findOffset(&p, getParentSize(), sizeof(uint32_t), 524313);
if (offset < 0)
throw 0;
else
return static_cast<size_t>(offset);
}
};
class CastArtMethod {
public:
static Size size;
static IMember<art::mirror::ArtMethod, void*>* entryPointQuickCompiled;
static IMember<art::mirror::ArtMethod, uint32_t>* accessFlag;
static void init(JNIEnv *env) {
//init ArtMethodSize
......@@ -33,11 +48,15 @@ namespace SandHook {
entryPointQuickCompiled = new CastEntryPointQuickCompiled();
entryPointQuickCompiled->init(m, size);
accessFlag = new CastAccessFlag();
accessFlag->init(m, size);
}
};
Size CastArtMethod::size = 0;
IMember<art::mirror::ArtMethod, void*>* CastArtMethod::entryPointQuickCompiled = nullptr;
IMember<art::mirror::ArtMethod, uint32_t>* CastArtMethod::accessFlag = nullptr;
}
......
......@@ -5,13 +5,11 @@
#include <stdint.h>
#include <string.h>
#include "arch.h"
#include "utils.h"
#ifndef SANDHOOK_ICAST_H
#define SANDHOOK_ICAST_H
#endif //SANDHOOK_ICAST_H
namespace SandHook {
template <typename T>
......@@ -60,4 +58,6 @@ namespace SandHook {
};
}
\ No newline at end of file
}
#endif //SANDHOOK_ICAST_H
\ No newline at end of file
//
// Created by 甘尧 on 2019/1/13.
//
#ifndef SANDHOOK_UTILS_H
#define SANDHOOK_UTILS_H
#include <cwchar>
template<typename T>
int findOffset(void *start, size_t len,size_t step,T value) {
if (NULL == start) {
return -1;
}
for (int i = 0; i <= len; i += step) {
T current_value = *reinterpret_cast<T*>((size_t)start + i);
if (value == current_value) {
return i;
}
}
return -1;
}
#endif //SANDHOOK_UTILS_H
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