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
bd2a9f9a
Commit
bd2a9f9a
authored
Jan 23, 2019
by
swift_gan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
half fix for thumb hook
parent
e75ab9c9
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
121 additions
and
17 deletions
+121
-17
misc.xml
.idea/misc.xml
+75
-0
arm32.S
app/src/main/cpp/trampoline/arch/arm32.S
+18
-0
trampoline.cpp
app/src/main/cpp/trampoline/trampoline.cpp
+3
-3
trampoline.h
app/src/main/cpp/trampoline/trampoline.h
+15
-4
trampoline_manager.cpp
app/src/main/cpp/trampoline/trampoline_manager.cpp
+8
-8
ActivityHooker.java
app/src/main/java/com/swift/sandhook/ActivityHooker.java
+1
-1
MyApp.java
app/src/main/java/com/swift/sandhook/MyApp.java
+1
-1
No files found.
.idea/misc.xml
View file @
bd2a9f9a
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"MarkdownProjectSettings"
wasCopied=
"true"
>
<PreviewSettings
splitEditorLayout=
"SPLIT"
splitEditorPreview=
"PREVIEW"
useGrayscaleRendering=
"false"
zoomFactor=
"1.0"
maxImageWidth=
"0"
showGitHubPageIfSynced=
"false"
allowBrowsingInPreview=
"false"
synchronizePreviewPosition=
"true"
highlightPreviewType=
"NONE"
highlightFadeOut=
"5"
highlightOnTyping=
"true"
synchronizeSourcePosition=
"true"
verticallyAlignSourceAndPreviewSyncPosition=
"true"
showSearchHighlightsInPreview=
"false"
showSelectionInPreview=
"true"
openRemoteLinks=
"true"
replaceUnicodeEmoji=
"false"
lastLayoutSetsDefault=
"false"
>
<PanelProvider>
<provider
providerId=
"com.vladsch.idea.multimarkdown.editor.swing.html.panel"
providerName=
"Default - Swing"
/>
</PanelProvider>
</PreviewSettings>
<ParserSettings
gitHubSyntaxChange=
"false"
emojiShortcuts=
"1"
emojiImages=
"0"
>
<PegdownExtensions>
<option
name=
"ABBREVIATIONS"
value=
"false"
/>
<option
name=
"ANCHORLINKS"
value=
"true"
/>
<option
name=
"ASIDE"
value=
"false"
/>
<option
name=
"ATXHEADERSPACE"
value=
"true"
/>
<option
name=
"AUTOLINKS"
value=
"true"
/>
<option
name=
"DEFINITIONS"
value=
"false"
/>
<option
name=
"DEFINITION_BREAK_DOUBLE_BLANK_LINE"
value=
"false"
/>
<option
name=
"FENCED_CODE_BLOCKS"
value=
"true"
/>
<option
name=
"FOOTNOTES"
value=
"false"
/>
<option
name=
"HARDWRAPS"
value=
"false"
/>
<option
name=
"HTML_DEEP_PARSER"
value=
"false"
/>
<option
name=
"INSERTED"
value=
"false"
/>
<option
name=
"QUOTES"
value=
"false"
/>
<option
name=
"RELAXEDHRULES"
value=
"true"
/>
<option
name=
"SMARTS"
value=
"false"
/>
<option
name=
"STRIKETHROUGH"
value=
"true"
/>
<option
name=
"SUBSCRIPT"
value=
"false"
/>
<option
name=
"SUPERSCRIPT"
value=
"false"
/>
<option
name=
"SUPPRESS_HTML_BLOCKS"
value=
"false"
/>
<option
name=
"SUPPRESS_INLINE_HTML"
value=
"false"
/>
<option
name=
"TABLES"
value=
"true"
/>
<option
name=
"TASKLISTITEMS"
value=
"true"
/>
<option
name=
"TOC"
value=
"false"
/>
<option
name=
"WIKILINKS"
value=
"true"
/>
</PegdownExtensions>
<ParserOptions>
<option
name=
"ADMONITION_EXT"
value=
"false"
/>
<option
name=
"ATTRIBUTES_EXT"
value=
"false"
/>
<option
name=
"COMMONMARK_LISTS"
value=
"true"
/>
<option
name=
"DUMMY"
value=
"false"
/>
<option
name=
"EMOJI_SHORTCUTS"
value=
"true"
/>
<option
name=
"ENUMERATED_REFERENCES_EXT"
value=
"false"
/>
<option
name=
"FLEXMARK_FRONT_MATTER"
value=
"false"
/>
<option
name=
"GFM_LOOSE_BLANK_LINE_AFTER_ITEM_PARA"
value=
"false"
/>
<option
name=
"GFM_TABLE_RENDERING"
value=
"true"
/>
<option
name=
"GITBOOK_URL_ENCODING"
value=
"false"
/>
<option
name=
"GITHUB_LISTS"
value=
"false"
/>
<option
name=
"GITHUB_WIKI_LINKS"
value=
"true"
/>
<option
name=
"HEADER_ID_NO_DUPED_DASHES"
value=
"false"
/>
<option
name=
"JEKYLL_FRONT_MATTER"
value=
"false"
/>
<option
name=
"NO_TEXT_ATTRIBUTES"
value=
"false"
/>
<option
name=
"PARSE_HTML_ANCHOR_ID"
value=
"false"
/>
<option
name=
"SIM_TOC_BLANK_LINE_SPACER"
value=
"true"
/>
</ParserOptions>
</ParserSettings>
<HtmlSettings
headerTopEnabled=
"false"
headerBottomEnabled=
"false"
bodyTopEnabled=
"false"
bodyBottomEnabled=
"false"
embedUrlContent=
"false"
addPageHeader=
"true"
embedImages=
"false"
embedHttpImages=
"false"
imageUriSerials=
"false"
>
<GeneratorProvider>
<provider
providerId=
"com.vladsch.idea.multimarkdown.editor.swing.html.generator"
providerName=
"Default Swing HTML Generator"
/>
</GeneratorProvider>
<headerTop
/>
<headerBottom
/>
<bodyTop
/>
<bodyBottom
/>
</HtmlSettings>
<CssSettings
previewScheme=
"UI_SCHEME"
cssUri=
""
isCssUriEnabled=
"false"
isCssUriSerial=
"true"
isCssTextEnabled=
"false"
isDynamicPageWidth=
"true"
>
<StylesheetProvider>
<provider
providerId=
"com.vladsch.idea.multimarkdown.editor.swing.html.css"
providerName=
"Default Swing Stylesheet"
/>
</StylesheetProvider>
<ScriptProviders
/>
<cssText
/>
<cssUriHistory
/>
</CssSettings>
<HtmlExportSettings
updateOnSave=
"false"
parentDir=
""
targetDir=
""
cssDir=
""
scriptDir=
""
plainHtml=
"false"
imageDir=
""
copyLinkedImages=
"false"
imageUniquifyType=
"0"
targetExt=
""
useTargetExt=
"false"
noCssNoScripts=
"false"
linkToExportedHtml=
"true"
exportOnSettingsChange=
"true"
regenerateOnProjectOpen=
"false"
linkFormatType=
"HTTP_ABSOLUTE"
/>
<LinkMapSettings>
<textMaps
/>
</LinkMapSettings>
</component>
<component
name=
"NullableNotNullManager"
>
<option
name=
"myDefaultNullable"
value=
"android.support.annotation.Nullable"
/>
<option
name=
"myDefaultNotNull"
value=
"android.support.annotation.NonNull"
/>
...
...
app/src/main/cpp/trampoline/arch/arm32.S
View file @
bd2a9f9a
...
...
@@ -71,21 +71,39 @@ FUNCTION_END(DIRECT_JUMP_TRAMPOLINE_T)
FUNCTION_START_T(INLINE_HOOK_TRAMPOLINE_T)
//4 byte
ldr RegT, addr_origin_art_method_t
//2 byte
cmp RegMethod, RegT
nop
//2 byte
bne origin_code_t
nop
//4 byte
ldr RegMethod, addr_hook_art_method_t
//4 byte
ldr RegT, offset_entry_code2_t
//2 byte
add RegT, RegMethod, RegT
nop
//4 byte
ldr pc, [RegT]
origin_code_t:
//4 byte
.long 0
//4 byte
.long 0
//4 byte
ldr RegT, addr_origin_art_method_t
//4 byte
add RegT, RegT, #8
//4 byte
ldr RegT, [RegT]
//4 byte
add RegT, RegT, SIZE_JUMP
//2 byte
mov pc, RegT
nop
addr_origin_art_method_t:
.long 0
offset_entry_code2_t:
...
...
app/src/main/cpp/trampoline/trampoline.cpp
View file @
bd2a9f9a
...
...
@@ -26,7 +26,7 @@ namespace SandHook {
Code
templateCode
()
override
{
#if defined(__arm__)
if
(
isThumCode
())
{
return
reinterpret_cast
<
Code
>
(
DIRECT_JUMP_TRAMPOLINE_T
);
return
getThumbCodeAddress
(
reinterpret_cast
<
Code
>
(
DIRECT_JUMP_TRAMPOLINE_T
)
);
}
else
{
return
reinterpret_cast
<
Code
>
(
DIRECT_JUMP_TRAMPOLINE
);
}
...
...
@@ -94,7 +94,7 @@ namespace SandHook {
Code
templateCode
()
override
{
#if defined(__arm__)
if
(
isThumCode
())
{
return
reinterpret_cast
<
Code
>
(
INLINE_HOOK_TRAMPOLINE_T
);
return
getThumbCodeAddress
(
reinterpret_cast
<
Code
>
(
INLINE_HOOK_TRAMPOLINE_T
)
);
}
else
{
return
reinterpret_cast
<
Code
>
(
INLINE_HOOK_TRAMPOLINE
);
}
...
...
@@ -123,7 +123,7 @@ namespace SandHook {
Code
templateCode
()
override
{
#if defined(__arm__)
if
(
isThumCode
())
{
return
reinterpret_cast
<
Code
>
(
CALL_ORIGIN_TRAMPOLINE_T
);
return
getThumbCodeAddress
(
reinterpret_cast
<
Code
>
(
CALL_ORIGIN_TRAMPOLINE_T
)
);
}
else
{
return
reinterpret_cast
<
Code
>
(
CALL_ORIGIN_TRAMPOLINE
);
}
...
...
app/src/main/cpp/trampoline/trampoline.h
View file @
bd2a9f9a
...
...
@@ -48,12 +48,12 @@
#define SIZE_DIRECT_JUMP_TRAMPOLINE 4 * 2
#define OFFSET_JUMP_ADDR_TARGET 4 * 1
#define SIZE_INLINE_HOOK_TRAMPOLINE 4 * 16
#define OFFSET_INLINE_ADDR_ORIGIN_METHOD 4 * 13
#define SIZE_INLINE_HOOK_TRAMPOLINE 4 * 17
#define OFFSET_INLINE_ORIGIN_CODE 4 * 7
#define OFFSET_INLINE_OFFSET_ENTRY_CODE 4 * 14
#define OFFSET_INLINE_ADDR_HOOK_METHOD 4 * 15
#define OFFSET_INLINE_OP_OFFSET_CODE 4 * 10
#define OFFSET_INLINE_ADDR_ORIGIN_METHOD 4 * 14
#define OFFSET_INLINE_OFFSET_ENTRY_CODE 4 * 15
#define OFFSET_INLINE_ADDR_HOOK_METHOD 4 * 16
#define SIZE_CALL_ORIGIN_TRAMPOLINE 4 * 4
#define OFFSET_CALL_ORIGIN_ART_METHOD 4 * 2
...
...
@@ -177,6 +177,17 @@ namespace SandHook {
codeCopy
(
reinterpret_cast
<
Code
>
(
&
code32Bit
.
code
),
codeOffset
,
4
);
}
//work for thumb
Code
getThumbCodeAddress
(
Code
code
)
{
Size
addr
=
reinterpret_cast
<
Size
>
(
code
)
&
(
~
0x00000001
);
return
reinterpret_cast
<
Code
>
(
addr
);
}
Code
getThumbCodePcAddress
(
Code
code
)
{
Size
addr
=
reinterpret_cast
<
Size
>
(
code
)
&
(
~
0x00000001
);
return
reinterpret_cast
<
Code
>
(
addr
+
1
);
}
protected
:
virtual
Size
codeLength
()
=
0
;
virtual
Code
templateCode
()
=
0
;
...
...
app/src/main/cpp/trampoline/trampoline_manager.cpp
View file @
bd2a9f9a
...
...
@@ -81,9 +81,7 @@ namespace SandHook {
//生成二段跳板
inlineHookTrampoline
=
new
InlineHookTrampoline
();
#if defined(__arm__)
checkThumbCode
(
inlineHookTrampoline
,
getEntryCode
(
originMethod
));
#endif
inlineHookTrampoline
->
init
();
inlineHookTrampolineSpace
=
allocExecuteSpace
(
inlineHookTrampoline
->
getCodeLen
());
if
(
inlineHookTrampolineSpace
==
0
)
...
...
@@ -97,24 +95,26 @@ namespace SandHook {
//注入 EntryCode
directJumpTrampoline
=
new
DirectJumpTrampoline
();
#if defined(__arm__)
checkThumbCode
(
directJumpTrampoline
,
getEntryCode
(
originMethod
));
#endif
directJumpTrampoline
->
init
();
originEntry
=
getEntryCode
(
originMethod
);
if
(
!
memUnprotect
(
reinterpret_cast
<
Size
>
(
originEntry
),
directJumpTrampoline
->
getCodeLen
()))
{
goto
label_error
;
}
directJumpTrampoline
->
setExecuteSpace
(
originEntry
);
directJumpTrampoline
->
setJumpTarget
(
inlineHookTrampoline
->
getCode
());
if
(
directJumpTrampoline
->
isThumCode
())
{
directJumpTrampoline
->
setExecuteSpace
(
directJumpTrampoline
->
getThumbCodeAddress
(
originEntry
));
directJumpTrampoline
->
setJumpTarget
(
directJumpTrampoline
->
getThumbCodePcAddress
(
inlineHookTrampoline
->
getCode
()));
}
else
{
directJumpTrampoline
->
setExecuteSpace
(
originEntry
);
directJumpTrampoline
->
setJumpTarget
(
inlineHookTrampoline
->
getCode
());
}
hookTrampoline
->
inlineJump
=
directJumpTrampoline
;
//备份原始方法
if
(
backupMethod
!=
nullptr
)
{
callOriginTrampoline
=
new
CallOriginTrampoline
();
#if defined(__arm__)
checkThumbCode
(
callOriginTrampoline
,
getEntryCode
(
originMethod
));
#endif
callOriginTrampoline
->
init
();
callOriginTrampolineSpace
=
allocExecuteSpace
(
callOriginTrampoline
->
getCodeLen
());
if
(
callOriginTrampolineSpace
==
0
)
...
...
app/src/main/java/com/swift/sandhook/ActivityHooker.java
View file @
bd2a9f9a
...
...
@@ -16,7 +16,7 @@ public class ActivityHooker {
@MethodParams
(
Bundle
.
class
)
public
static
void
onCreate
(
Activity
thiz
,
Bundle
bundle
)
{
Log
.
e
(
"ActivityHooker"
,
"hooked success "
+
thiz
);
onCreateBackup
(
thiz
,
bundle
);
//
onCreateBackup(thiz, bundle);
}
@HookMethodBackup
(
"onCreate"
)
...
...
app/src/main/java/com/swift/sandhook/MyApp.java
View file @
bd2a9f9a
...
...
@@ -9,7 +9,7 @@ public class MyApp extends Application {
public
void
onCreate
()
{
super
.
onCreate
();
try
{
SandHook
.
addHookClass
(
LogHooker
.
class
,
ActivityHooker
.
class
,
Object
Hooker
.
class
);
SandHook
.
addHookClass
(
Activity
Hooker
.
class
);
}
catch
(
HookErrorException
e
)
{
e
.
printStackTrace
();
}
...
...
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