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
a19895ec
Commit
a19895ec
authored
Feb 22, 2019
by
swift_gan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix hook wrapper switch logic
parent
8966cd99
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
6 deletions
+22
-6
SkipParamCheck.java
...in/java/com/swift/sandhook/annotation/SkipParamCheck.java
+11
-0
HookWrapper.java
...src/main/java/com/swift/sandhook/wrapper/HookWrapper.java
+11
-6
No files found.
annotation/src/main/java/com/swift/sandhook/annotation/SkipParamCheck.java
0 → 100644
View file @
a19895ec
package
com
.
swift
.
sandhook
.
annotation
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
@Target
({
ElementType
.
METHOD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
SkipParamCheck
{
}
hooklib/src/main/java/com/swift/sandhook/wrapper/HookWrapper.java
View file @
a19895ec
...
...
@@ -10,6 +10,7 @@ import com.swift.sandhook.annotation.HookReflectClass;
import
com.swift.sandhook.annotation.MethodParams
;
import
com.swift.sandhook.annotation.MethodReflectParams
;
import
com.swift.sandhook.annotation.Param
;
import
com.swift.sandhook.annotation.SkipParamCheck
;
import
com.swift.sandhook.annotation.ThisObject
;
import
java.lang.annotation.Annotation
;
...
...
@@ -99,7 +100,9 @@ public class HookWrapper {
}
catch
(
NoSuchMethodException
e
)
{
throw
new
HookErrorException
(
"can not find target method: "
+
methodName
,
e
);
}
checkSignature
(
foundMethod
,
method
,
pars
);
if
(!
method
.
isAnnotationPresent
(
SkipParamCheck
.
class
))
{
checkSignature
(
foundMethod
,
method
,
pars
);
}
HookEntity
entity
=
hookEntityMap
.
get
(
foundMethod
);
if
(
entity
==
null
)
{
entity
=
new
HookEntity
(
foundMethod
);
...
...
@@ -119,7 +122,9 @@ public class HookWrapper {
}
catch
(
NoSuchMethodException
e
)
{
throw
new
HookErrorException
(
"can not find target method: "
+
methodName
,
e
);
}
checkSignature
(
foundMethod
,
method
,
pars
);
if
(!
method
.
isAnnotationPresent
(
SkipParamCheck
.
class
))
{
checkSignature
(
foundMethod
,
method
,
pars
);
}
HookEntity
entity
=
hookEntityMap
.
get
(
foundMethod
);
if
(
entity
==
null
)
{
entity
=
new
HookEntity
(
foundMethod
);
...
...
@@ -153,7 +158,7 @@ public class HookWrapper {
return
pars
;
}
else
if
(
getParsCount
(
method
)
>
0
)
{
if
(
getParsCount
(
method
)
==
1
)
{
if
(
hasThisObject
(
method
))
{
if
(
hasThisObject
(
method
)
||
Modifier
.
isStatic
(
method
.
getModifiers
())
)
{
return
parseMethodParsNew
(
classLoader
,
method
);
}
else
{
return
null
;
...
...
@@ -209,7 +214,7 @@ public class HookWrapper {
}
}
try
{
realPars
[
parIndex
]
=
getRealParType
(
classLoader
,
hookPar
,
methodAnnos
);
realPars
[
parIndex
]
=
getRealParType
(
classLoader
,
hookPar
,
methodAnnos
,
method
.
isAnnotationPresent
(
SkipParamCheck
.
class
)
);
}
catch
(
Exception
e
)
{
throw
new
HookErrorException
(
"hook method <"
+
method
.
getName
()
+
"> parser pars error"
,
e
);
}
...
...
@@ -218,7 +223,7 @@ public class HookWrapper {
return
realPars
;
}
private
static
Class
getRealParType
(
ClassLoader
classLoader
,
Class
hookPar
,
Annotation
[]
annotations
)
throws
Exception
{
private
static
Class
getRealParType
(
ClassLoader
classLoader
,
Class
hookPar
,
Annotation
[]
annotations
,
boolean
skipCheck
)
throws
Exception
{
if
(
annotations
==
null
||
annotations
.
length
==
0
)
return
hookPar
;
for
(
Annotation
annotation:
annotations
)
{
...
...
@@ -227,7 +232,7 @@ public class HookWrapper {
if
(
TextUtils
.
isEmpty
(
param
.
value
()))
return
hookPar
;
Class
realPar
=
classNameToClass
(
param
.
value
(),
classLoader
);
if
(
realPar
.
equals
(
hookPar
)
||
hookPar
.
isAssignableFrom
(
realPar
))
{
if
(
skipCheck
||
realPar
.
equals
(
hookPar
)
||
hookPar
.
isAssignableFrom
(
realPar
))
{
return
realPar
;
}
else
{
throw
new
ClassCastException
(
"hook method par cast error!"
);
...
...
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