Skip to content

Commit

Permalink
Instrumentation...
Browse files Browse the repository at this point in the history
  • Loading branch information
melontini committed Jun 28, 2023
1 parent ffe6123 commit 0707465
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ run/
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
##Don't ignore the agent
!dark-matter-danger/src/main/resources/jar/instrumentation_agent.jar
!dark-matter-danger/src/main/resources/jar/dark_matter_instrumentation_agent.jar
2 changes: 1 addition & 1 deletion dark-matter-danger/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jar {
manifest {
attributes(
"Manifest-Version": "1.0",
"Agent-Class": "me.melontini.dark_matter.danger.InstrumentationAgent",
"Agent-Class": "me.melontini.dark_matter.danger.instrumentation.InstrumentationAgent",
"Can-Retransform-Classes": "true",
"Can-Redefine-Classes": "true"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ public static void bootstrap(boolean bootstrap) {

try {
final String name = ManagementFactory.getRuntimeMXBean().getName();
final Path jarPath = Paths.get(GAME_DIR, AGENT_DIR, "instrumentation_agent.jar");
final Path jarPath = Paths.get(GAME_DIR, AGENT_DIR, "dark_matter_instrumentation_agent.jar");
final File jar = jarPath.toFile();

DarkMatterLog.info("Attaching instrumentation agent to VM.");

if (!Files.exists(jarPath)) {
createAgentJar(jarPath, jar);
} else {
try (InputStream stream = InstrumentationAccess.class.getClassLoader().getResourceAsStream("jar/instrumentation_agent.jar")) {
try (InputStream stream = InstrumentationAccess.class.getResourceAsStream("jar/dark_matter_instrumentation_agent.jar")) {
if (stream != null) {
byte[] bytes = stream.readAllBytes();
if (!Arrays.equals(Files.readAllBytes(jarPath), bytes)) {
Expand All @@ -181,7 +181,7 @@ public static void bootstrap(boolean bootstrap) {
createAgentJar(jarPath, jar);
}
} else {
throw new NullPointerException("Couldn't find included \"jar/instrumentation_agent.jar\"!");
throw new NullPointerException("Couldn't find included \"jar/dark_matter_instrumentation_agent.jar\"!");
}
}
}
Expand All @@ -202,13 +202,13 @@ public static void bootstrap(boolean bootstrap) {

private static void createAgentJar(Path jarPath, File jar) throws IOException {
Files.createDirectories(jarPath.getParent());
try (InputStream stream = InstrumentationAccess.class.getClassLoader().getResourceAsStream("jar/instrumentation_agent.jar")) {
try (InputStream stream = InstrumentationAccess.class.getClassLoader().getResourceAsStream("jar/dark_matter_instrumentation_agent.jar")) {
if (stream != null) {
try (FileOutputStream outputStream = new FileOutputStream(jar)) {
outputStream.write(stream.readAllBytes());
}
} else {
throw new NullPointerException("Couldn't find included \"jar/instrumentation_agent.jar\"!");
throw new NullPointerException("Couldn't find included \"jar/dark_matter_instrumentation_agent.jar\"!");
}
}
}
Expand Down

0 comments on commit 0707465

Please sign in to comment.