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
0d3eb16a
Commit
0d3eb16a
authored
Feb 02, 2019
by
swift_gan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
start reconsitution
parent
6a6129fe
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
52 deletions
+83
-52
CustmizeHooker.java
...n/java/com/swift/sandhook/testHookers/CustmizeHooker.java
+2
-0
art.cpp
hooklib/src/main/cpp/casts/art/art.cpp
+42
-0
art.h
hooklib/src/main/cpp/casts/art/art.h
+27
-44
trampoline_manager.cpp
hooklib/src/main/cpp/trampoline/trampoline_manager.cpp
+10
-8
trampoline_manager.h
hooklib/src/main/cpp/trampoline/trampoline_manager.h
+2
-0
No files found.
app/src/main/java/com/swift/sandhook/testHookers/CustmizeHooker.java
View file @
0d3eb16a
...
@@ -6,6 +6,7 @@ import com.swift.sandhook.MainActivity;
...
@@ -6,6 +6,7 @@ import com.swift.sandhook.MainActivity;
import
com.swift.sandhook.annotation.HookClass
;
import
com.swift.sandhook.annotation.HookClass
;
import
com.swift.sandhook.annotation.HookMethod
;
import
com.swift.sandhook.annotation.HookMethod
;
import
com.swift.sandhook.annotation.HookMethodBackup
;
import
com.swift.sandhook.annotation.HookMethodBackup
;
import
com.swift.sandhook.annotation.HookMode
;
import
com.swift.sandhook.annotation.MethodParams
;
import
com.swift.sandhook.annotation.MethodParams
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
...
@@ -19,6 +20,7 @@ public class CustmizeHooker {
...
@@ -19,6 +20,7 @@ public class CustmizeHooker {
@HookMethod
(
"methodBeHooked"
)
@HookMethod
(
"methodBeHooked"
)
@MethodParams
({
int
.
class
,
int
.
class
})
@MethodParams
({
int
.
class
,
int
.
class
})
@HookMode
(
HookMode
.
REPLACE
)
public
static
int
staticMethodHooked
(
int
a
,
int
b
)
{
public
static
int
staticMethodHooked
(
int
a
,
int
b
)
{
Log
.
e
(
"CustmizeHooker"
,
"methodBeHooked be hooked"
);
Log
.
e
(
"CustmizeHooker"
,
"methodBeHooked be hooked"
);
try
{
try
{
...
...
hooklib/src/main/cpp/casts/art/art.cpp
0 → 100644
View file @
0d3eb16a
//
// 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
hooklib/src/main/cpp/casts/art/art.h
View file @
0d3eb16a
...
@@ -41,50 +41,33 @@ public:
...
@@ -41,50 +41,33 @@ public:
class
ArtMethod
{
class
ArtMethod
{
public
:
public
:
// uint32_t declaring_class_;
void
*
codeEntry
;
//
// // Access flags; low 16 bits are defined by spec.
bool
isAbstract
();
// // Getting and setting this flag needs to be atomic when concurrency is
bool
isNative
();
// // possible, e.g. after this method's class is linked. Such as when setting
bool
isCompiled
();
// // verifier flags and single-implementation flag.
// uint32_t access_flags_;
void
setAccessFlags
(
uint32_t
flags
);
//
void
disableCompilable
();
// /* Dex file fields. The defining dex file is available via declaring_class_->dex_cache_ */
void
tryDisableInline
();
//
void
disableInterpreterForO
();
// // Offset to the CodeItem.
void
setPrivate
();
// uint32_t dex_code_item_offset_;
void
setStatic
();
//
// // Index into method_ids of the dex file associated with this method.
void
setQuickCodeEntry
(
void
*
entry
);
// uint32_t dex_method_index_;
void
setJniCodeEntry
(
void
*
entry
);
//
void
setInterpreterCodeEntry
(
void
*
entry
);
// /* End of dex file fields. */
void
setDexCacheResolveItem
(
ArtMethod
*
method
,
uint32_t
index
);
//
// // Entry within a dispatch table for this method. For static/direct methods the index is into
void
*
getQuickCodeEntry
();
// // the declaringClass.directMethods, for virtual methods the vtable and for interface methods the
void
*
getInterpreterCodeEntry
();
// // ifTable.
uint32_t
getAccessFlags
();
// uint16_t method_index_;
uint32_t
getDexMethodIndex
();
//
// // The hotness we measure for this method. Managed by the interpreter. Not atomic, as we allow
bool
compile
();
// // missing increments: if the method is hot, we will see it eventually.
void
flushCache
();
// uint16_t hotness_count_;
void
backup
(
ArtMethod
*
backup
);
//
// // 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
;
};
};
}
}
...
...
hooklib/src/main/cpp/trampoline/trampoline_manager.cpp
View file @
0d3eb16a
...
@@ -18,6 +18,15 @@ namespace SandHook {
...
@@ -18,6 +18,15 @@ namespace SandHook {
return
size
;
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
)
{
Code
TrampolineManager
::
allocExecuteSpace
(
Size
size
)
{
if
(
size
>
EXE_BLOCK_SIZE
)
if
(
size
>
EXE_BLOCK_SIZE
)
return
0
;
return
0
;
...
@@ -78,8 +87,7 @@ namespace SandHook {
...
@@ -78,8 +87,7 @@ namespace SandHook {
HookTrampoline
*
TrampolineManager
::
installInlineTrampoline
(
mirror
::
ArtMethod
*
originMethod
,
HookTrampoline
*
TrampolineManager
::
installInlineTrampoline
(
mirror
::
ArtMethod
*
originMethod
,
mirror
::
ArtMethod
*
hookMethod
,
mirror
::
ArtMethod
*
hookMethod
,
mirror
::
ArtMethod
*
backupMethod
,
mirror
::
ArtMethod
*
backupMethod
)
{
bool
isNative
)
{
AutoLock
autoLock
(
installLock
);
AutoLock
autoLock
(
installLock
);
...
@@ -93,12 +101,6 @@ namespace SandHook {
...
@@ -93,12 +101,6 @@ namespace SandHook {
Code
callOriginTrampolineSpace
;
Code
callOriginTrampolineSpace
;
Code
originEntry
;
Code
originEntry
;
if
(
!
isNative
)
{
uint32_t
originCodeSize
=
sizeOfEntryCode
(
originMethod
);
if
(
originCodeSize
<
SIZE_DIRECT_JUMP_TRAMPOLINE
)
goto
label_error
;
}
//生成二段跳板
//生成二段跳板
inlineHookTrampoline
=
new
InlineHookTrampoline
();
inlineHookTrampoline
=
new
InlineHookTrampoline
();
checkThumbCode
(
inlineHookTrampoline
,
getEntryCode
(
originMethod
));
checkThumbCode
(
inlineHookTrampoline
,
getEntryCode
(
originMethod
));
...
...
hooklib/src/main/cpp/trampoline/trampoline_manager.h
View file @
0d3eb16a
...
@@ -48,6 +48,8 @@ namespace SandHook {
...
@@ -48,6 +48,8 @@ namespace SandHook {
HookTrampoline
*
installInlineTrampoline
(
mirror
::
ArtMethod
*
originMethod
,
mirror
::
ArtMethod
*
hookMethod
,
mirror
::
ArtMethod
*
backupMethod
,
HookTrampoline
*
installInlineTrampoline
(
mirror
::
ArtMethod
*
originMethod
,
mirror
::
ArtMethod
*
hookMethod
,
mirror
::
ArtMethod
*
backupMethod
,
bool
isNative
);
bool
isNative
);
bool
canSafeInline
(
mirror
::
ArtMethod
*
method
,
char
*
msg
);
uint32_t
sizeOfEntryCode
(
mirror
::
ArtMethod
*
method
);
uint32_t
sizeOfEntryCode
(
mirror
::
ArtMethod
*
method
);
HookTrampoline
*
getHookTrampoline
(
mirror
::
ArtMethod
*
method
)
{
HookTrampoline
*
getHookTrampoline
(
mirror
::
ArtMethod
*
method
)
{
...
...
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