Java injector by qmaks

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

💉 Inject JavaAgent into any running JVM (with DisableAttachMechanism)

fan87/Java-Injector

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Читайте также:  Spider среда разработки python

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

readme.md

Inject to JNI Enabled JVMs on Linux & Windows, even with DisableAttachMechanism enabled.

The repository is not product ready, as there may be bugs, but I’m already using it for products as I can fix bugs really quick.

It currently supports x86 64bits Linux & Windows JVM, you may build the native-agent-native & injection-target- yourself to make it work on 32bit machines, or potentially ARM machines.

It also supports Java 8 and above, although the compiler may not be happy about the use of ClassTransformer in some projects on Java version 9 or above.

To use it as library, please get it from Jitpack

You may have to initialize the NativeInstrumentation in your Java-agent:

public class AgentMain < public static void test() < System.out.println("Test Method Called"); > public static void main(String[] args) throws Exception < agentmain("Test Args", new NativeInstrumentation()); > public static void agentmain(String agentArgs, Instrumentation instrumentation) throws Exception < assert agentArgs.equals("Test Args"); System.out.println("Hello, World! " + agentArgs); NativeInstrumentation.init(); NativeInstrumentation.invokeStaticMethodS(AgentMain.class, "test", "()V"); final int[] times = 0>; final byte[][] data = new byte[1][1]; instrumentation.addTransformer(new ClassFileTransformer() < @Override public byte[] transform(ClassLoader classLoader, String s, Class aClass, ProtectionDomain protectionDomain, byte[] bytes) throws IllegalClassFormatException < if (s.equals("TestClass")) < times[0]++; if (times[0] > 2) < return null; > ClassNode node = new ClassNode(); ClassReader reader = new ClassReader(bytes); reader.accept(node, 0); for (MethodNode method : node.methods) < for (AbstractInsnNode instruction : method.instructions) < if (instruction instanceof LdcInsnNode) < if (aClass == null) < ((LdcInsnNode) instruction).cst = "Replaced Text!"; > else < ((LdcInsnNode) instruction).cst = "Replaced Text! 2"; > > > > ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES); node.accept(writer); data[0] = writer.toByteArray(); return writer.toByteArray(); > return null; > >, true); TestClass.test(); instrumentation.retransformClasses(TestClass.class); TestClass.test(); ClassNode node = new ClassNode(); ClassReader reader = new ClassReader(data[0]); reader.accept(node, 0); for (MethodNode method : node.methods) < for (AbstractInsnNode instruction : method.instructions) < if (instruction instanceof LdcInsnNode) < ((LdcInsnNode) instruction).cst = "Replaced Text! 3"; > > > ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES); node.accept(writer); instrumentation.redefineClasses(new ClassDefinition(TestClass.class, writer.toByteArray())); TestClass.test(); > >

Hook into Java methods in runtime

It’s possible (And I’m also doing it) to transform Java classes in JVM runtime without injecting/attaching to itself using NativeInstrumentation .

import me.fan87.javainjector.NativeInstrumentation import org.objectweb.asm.ClassReader import org.objectweb.asm.ClassWriter import org.objectweb.asm.Opcodes import org.objectweb.asm.Type import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.analysis.Analyzer import org.objectweb.asm.tree.analysis.AnalyzerException import org.objectweb.asm.tree.analysis.SimpleVerifier import org.objectweb.asm.util.CheckClassAdapter import java.io.PrintWriter import java.lang.instrument.ClassDefinition import java.lang.instrument.ClassFileTransformer object TransformManager < val classesCache = HashMapClass*>, ClassNode>() val instrumentation = NativeInstrumentation() init < try < NativeInstrumentation.loadNativeLib() > catch (e: Throwable) < e.printStackTrace() >try < NativeInstrumentation.init() > catch (e: Throwable) < e.printStackTrace() >> fun transformClass(classTransformer: ClassTransformer) < if (classTransformer.targetClass in classesCache) < val classNode = classesCache[classTransformer.targetClass]!! classTransformer.transform(classNode) var result: ByteArray try < val classWriter = ClassWriter(ClassWriter.COMPUTE_FRAMES) classNode.accept(classWriter) result = classWriter.toByteArray() > catch (e: Exception) < e.printStackTrace() val classWriter = ClassWriter(ClassWriter.COMPUTE_MAXS) classNode.accept(classWriter) result = classWriter.toByteArray() > CheckClassAdapter.verify(ClassReader(result), TransformManager::class.java.classLoader, false, PrintWriter(System.err, true)); instrumentation.redefineClasses(ClassDefinition(classTransformer.targetClass, result)) > else < val transformer = ClassFileTransformer < loader, className, classBeingRedefined, protectionDomain, classfileBuffer -> try < if (classBeingRedefined == classTransformer.targetClass) < val classNode = ClassNode() val classReader = ClassReader(classfileBuffer) classReader.accept(classNode, ClassReader.EXPAND_FRAMES) classTransformer.transform(classNode) var result: ByteArray try < val classWriter = ClassWriter(ClassWriter.COMPUTE_FRAMES) classNode.accept(classWriter) result = classWriter.toByteArray() > catch (e: Exception) < e.printStackTrace() val classWriter = ClassWriter(ClassWriter.COMPUTE_MAXS) classNode.accept(classWriter) result = classWriter.toByteArray() > CheckClassAdapter.verify(ClassReader(result), TransformManager::class.java.classLoader, false, PrintWriter(System.err, true)); classesCache[classBeingRedefined] = classNode result > else < classfileBuffer >> catch (e: Throwable) < e.printStackTrace() classfileBuffer >> instrumentation.addTransformer(transformer, true) instrumentation.retransformClasses(classTransformer.targetClass) instrumentation.removeTransformer(transformer) > > fun verify(classNode: ClassNode, loader: ClassLoader, printWriter: PrintWriter) < var syperType = if (classNode.superName == null) null else Type.getObjectType(classNode.superName) var methods = classNode.methods var interfaces: MutableListType> = ArrayList() for ( interfaceName:kotlin.String? in classNode.interfaces) < interfaces.add(Type.getObjectType(interfaceName)) > for ( method:org.objectweb.asm.tree.MethodNode? in methods) < val verifier = SimpleVerifier( Type.getObjectType(classNode.name), syperType, interfaces, classNode.access and Opcodes.ACC_INTERFACE != 0 ) val analyzer = Analyzer(verifier) if (loader != null) < verifier.setClassLoader(loader) >try < analyzer.analyze(classNode.name, method) >catch (e: AnalyzerException) < e.printStackTrace(printWriter) >> printWriter.flush() > >

About

💉 Inject JavaAgent into any running JVM (with DisableAttachMechanism)

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Way to inject jar files into java process through a dll.

TheQmaks/JavaInjector

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

This tool inject your jar file and allocates object of class, which name must be written in zip comment. Entry point of your main-class will be constructor. After building you classes, you should put them into archive using WinRAR of other archivator which can change archive comment. You should write main class in comment as single line. Example: Put class with name «Main» inside package «test», constructor will be your entry-point, e.g «public Main() < Your awesome code >«, so you should set comment in your archive with classes to «test.Main» without quotes.

About

Way to inject jar files into java process through a dll.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Inject any JAR file into a running JVM

License

birthdates/java-injector

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Inject any JAR file into a running JVM.

NOTE: This program will most likely trigger your anti-virus

  1. Download the latest release or build it yourself (if you build it yourself, create a libs folder and move runner/Run.java into it)
  2. Move all files into one folder
  3. Compile your JAR and move it into the same folder but rename it to run.jar
  4. Launch your Java application ( javaw.exe application)
  5. Run injector.exe and the JAR file should be injected into the JVM (if not, steps were not followed correctly)

You will need to build the program yourself. Head into shared.h and uncomment the line that looks like #define VERBOSE . After this, rebuild the project.

When creating the JAR, include a resource run.txt with one line: the location of your main class.

This class must have a empty void function main (this is the function that will first be called)

package com.example; public class ExampleRun < public static void main() < System.out.println("Example injected."); > >

NOTE: The example JAR provided in the releases will just close the application it injects into.

  1. My Java code does not execute! — There is likely an error within your code, run the program in verbose mode.
  2. Nothing injects (not even console) — There is likely another javaw.exe running.
  3. ClassNotFoundException — The JVM you injected into does not have this class!
  4. My prints aren’t showing even in verbose mode! — Prints from other threads will not show up in verbose mode.

About

Inject any JAR file into a running JVM

Источник

Оцените статью