Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
matrix-sample
Overview
Overview
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
mall
arch
matrix-sample
Commits
a97f2d37
Commit
a97f2d37
authored
Sep 02, 2019
by
QIANGLU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add
parent
5d0da1c2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
0 deletions
+84
-0
AgentStartup.java
spring-boot-agent/src/main/java/com/qianglu/agent/AgentStartup.java
+17
-0
DumpClassesService.java
spring-boot-agent/src/main/java/com/qianglu/agent/service/DumpClassesService.java
+67
-0
No files found.
spring-boot-agent/src/main/java/com/qianglu/agent/AgentStartup.java
0 → 100755
View file @
a97f2d37
package
com
.
qianglu
.
agent
;
import
com.qianglu.agent.service.DumpClassesService
;
import
java.lang.instrument.Instrumentation
;
/**
* @author qianglu
*/
public
class
AgentStartup
{
public
static
void
premain
(
String
arg
,
Instrumentation
instrumentation
)
{
System
.
err
.
println
(
"agent startup , args is "
+
arg
);
// 注册我们的文件下载函数
instrumentation
.
addTransformer
(
new
DumpClassesService
());
}
}
spring-boot-agent/src/main/java/com/qianglu/agent/service/DumpClassesService.java
0 → 100644
View file @
a97f2d37
package
com
.
qianglu
.
agent
.
service
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.lang.instrument.ClassFileTransformer
;
import
java.lang.instrument.IllegalClassFormatException
;
import
java.security.ProtectionDomain
;
import
java.util.Arrays
;
import
java.util.List
;
/**
* 测试下载
*
* @author QIANGLU on 2019-08-15
*/
public
class
DumpClassesService
implements
ClassFileTransformer
{
private
static
final
List
<
String
>
SYSTEM_CLASS_PREFIX
=
Arrays
.
asList
(
"java"
,
"sum"
,
"jdk"
);
@Override
public
byte
[]
transform
(
ClassLoader
loader
,
String
className
,
Class
<?>
classBeingRedefined
,
ProtectionDomain
protectionDomain
,
byte
[]
classfileBuffer
)
throws
IllegalClassFormatException
{
if
(!
isSystemClass
(
className
))
{
System
.
out
.
println
(
"load class "
+
className
);
FileOutputStream
fos
=
null
;
try
{
// 将类名统一命名为classNamedump.class格式
fos
=
new
FileOutputStream
(
className
+
"dump.class"
);
fos
.
write
(
classfileBuffer
);
fos
.
flush
();
}
catch
(
IOException
ioe
)
{
ioe
.
printStackTrace
();
}
finally
{
// 关闭文件输出流
if
(
null
!=
fos
)
{
try
{
fos
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
return
classfileBuffer
;
}
/**
* 判断一个类是否为系统类
*
* @param className 类名
* @return System Class then return true,else return false
*/
private
boolean
isSystemClass
(
String
className
)
{
// 假设系统类的类名不为NULL而且不为空
if
(
null
==
className
||
className
.
isEmpty
())
{
return
false
;
}
for
(
String
prefix
:
SYSTEM_CLASS_PREFIX
)
{
if
(
className
.
startsWith
(
prefix
))
{
return
true
;
}
}
return
false
;
}
}
\ No newline at end of file
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