Skip to content

Instantly share code, notes, and snippets.

@ryankennedy
Last active January 4, 2017 13:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ryankennedy/5691324 to your computer and use it in GitHub Desktop.
Save ryankennedy/5691324 to your computer and use it in GitHub Desktop.
Quickly creating a command line utility to run ASMifier (http://asm.ow2.org/asm40/javadoc/user/org/objectweb/asm/util/ASMifier.html).
#include <stdio.h>
#include <errno.h>
int main(int argc, char* argv[]) {
int i;
char* argv2[argc+3];
argv2[0] = "java";
argv2[1] = "-cp";
argv2[2] = argv[0];
argv2[3] = "org.objectweb.asm.util.ASMifier";
for (i = 1;i < argc; i ++) {
argv2[i+3] = argv[i];
}
argv2[argc+3] = 0;
execvp("java", argv2);
printf("Cannot execute '");
for (i = 0;i < argc+2; i ++) { printf("%s ", argv2[i]); }
printf("', caused by error: %d\n", errno);
}
Stealing from Sam Pullara's idea for creating standalone executables from Java JAR files:
http://www.javarants.com/2004/01/07/standalone-java-programs-on-unix-systems-now-with-c-code/
I've modified it slightly to handle a JAR file that doesn't have a Main-Class entry in the manifest.
In my case, I'm feeding it the ASM "all" JAR so I can have a command line utility for running the
org.objectweb.asm.util.ASMifier utility.
gcc asmifier.c
cat > asmifier a.out ~/.m2/repository/org/ow2/asm/asm-all/4.1/asm-all-4.1.jar
chmod +x asmifier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment