Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
SandHook
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
SandHook
Commits
5bc325a2
Commit
5bc325a2
authored
Feb 03, 2019
by
swift_gan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[reconsit]done
parent
5bd6ce01
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
106 additions
and
131 deletions
+106
-131
art_method.cpp
hooklib/src/main/cpp/art/art_method.cpp
+18
-10
art_method.h
hooklib/src/main/cpp/includes/art_method.h
+7
-2
hide_api.h
hooklib/src/main/cpp/includes/hide_api.h
+2
-2
utils.h
hooklib/src/main/cpp/includes/utils.h
+7
-4
sandhook.cpp
hooklib/src/main/cpp/sandhook.cpp
+58
-113
utils.cpp
hooklib/src/main/cpp/utils/utils.cpp
+14
-0
No files found.
hooklib/src/main/cpp/art/art_method.cpp
View file @
5bc325a2
...
@@ -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
hooklib/src/main/cpp/includes/art_method.h
View file @
5bc325a2
...
@@ -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
();
};
};
}
}
...
...
hooklib/src/main/cpp/includes/hide_api.h
View file @
5bc325a2
...
@@ -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
);
}
}
...
...
hooklib/src/main/cpp/includes/utils.h
View file @
5bc325a2
...
@@ -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
*
metho
dName
);
jint
getIntFromJava
(
JNIEnv
*
env
,
const
char
*
className
,
const
char
*
fiel
dName
);
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
);
}
}
...
...
hooklib/src/main/cpp/sandhook.cpp
View file @
5bc325a2
This diff is collapsed.
Click to expand it.
hooklib/src/main/cpp/utils/utils.cpp
View file @
5bc325a2
...
@@ -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
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment