Permalink
Browse files

files

  • Loading branch information...
1 parent 71f4948 commit 53d30ce4ed59894f04455853a7c9ddb5d8ca0919 @gtrak committed Mar 30, 2013
View
@@ -0,0 +1,3 @@
+# Introduction to nodisassemble
+
+TODO: write [great documentation](http://jacobian.org/writing/great-documentation/what-to-write/)
@@ -0,0 +1,61 @@
+package no.disassemble;
+
+import java.lang.instrument.Instrumentation;
+import java.lang.instrument.ClassFileTransformer;
+import java.lang.instrument.IllegalClassFormatException;
+import java.security.ProtectionDomain;
+
+import java.util.Set;
+import java.util.HashSet;
+
+public class NoDisassemble {
+
+ public static java.util.Map<String,byte[]> classes = new java.util.concurrent.ConcurrentHashMap<String,byte[]>();
+ public static Instrumentation inst = null;
+
+ private static void println(Object arg){
+ System.out.println(arg);
+ }
+ {
+ println("Initializing NoDisassemble");
+ }
+ public static class ClojureTransformer implements ClassFileTransformer {
+ {println("Initializing transformer");}
+ public byte[] transform(ClassLoader loader, String className,
+ Class<?> classBeingRedefined, ProtectionDomain protectionDomain,
+ byte[] classBytes) throws IllegalClassFormatException {
+ // println("Registering " + className);
+ classes.put(className, classBytes);
+ return classBytes;
+ }
+
+ }
+
+ /**
+ * Entry point method, called when the JVM initializes this package as an instrumentation agent.
+ * @param args The arguments for this agent. Currently unused.
+ * @param inst The instrumentation object to register with.
+ */
+ public static void premain(String args, Instrumentation _inst) {
+ println("Adding ClojureTransformer");
+ inst = _inst;
+ inst.addTransformer(new ClojureTransformer(), true);
+
+ }
+
+
+ /**
+ * Provides help text if run.
+ * @param args Ignored.
+ */
+ public static void main(String[] args) {
+ System.out.println();
+ System.out.println("Presuming the profile.jar and auditor.jar are in the dist directory then use with:");
+ System.out.println(" java -javaagent:dist/profile.jar -classpath ${CLASSPATH}:dist/auditor.jar <main.program.class>");
+ System.out.println();
+ System.out.println("If wanting to instrument the java.* classes, then use:");
+ System.out.println(" java -javaagent:dist/profile.jar=logsys -Xbootclasspath/a:dist/auditor.jar -classpath ${CLASSPATH}:dist/auditor.jar <main.program.class>");
+ System.out.println();
+ }
+
+}
@@ -0,0 +1,12 @@
+/target
+/lib
+/classes
+/checkouts
+pom.xml
+pom.xml.asc
+*.jar
+*.class
+.lein-deps-sum
+.lein-failures
+.lein-plugins
+.lein-repl-history
@@ -0,0 +1,25 @@
+# lein-nodisassemble
+
+A Leiningen plugin to do many wonderful things.
+
+## Usage
+
+FIXME: Use this for user-level plugins:
+
+Put `[lein-nodisassemble "0.1.0-SNAPSHOT"]` into the `:plugins` vector of your
+`:user` profile, or if you are on Leiningen 1.x do `lein plugin install
+lein-nodisassemble 0.1.0-SNAPSHOT`.
+
+FIXME: Use this for project-level plugins:
+
+Put `[lein-nodisassemble "0.1.0-SNAPSHOT"]` into the `:plugins` vector of your project.clj.
+
+FIXME: and add an example usage that actually makes sense:
+
+ $ lein nodisassemble
+
+## License
+
+Copyright © 2013 FIXME
+
+Distributed under the Eclipse Public License, the same as Clojure.
@@ -0,0 +1,8 @@
+(defproject lein-nodisassemble "0.1.0-SNAPSHOT"
+ :description "FIXME: write description"
+ :url "http://example.com/FIXME"
+ :license {:name "Eclipse Public License"
+ :url "http://www.eclipse.org/legal/epl-v10.html"}
+ :eval-in-leiningen true
+
+ )
@@ -0,0 +1,11 @@
+(ns leiningen.nodisassemble)
+
+(defn middleware [project]
+ (update-in
+ project [:jvm-opts]
+ pr-str ""))
+
+(defn nodisassemble
+ "I don't do a lot."
+ [project & args]
+ (println "Hi!"))
View
@@ -0,0 +1,14 @@
+(defproject nodisassemble "0.1.0-SNAPSHOT"
+ :description "FIXME: write description"
+ :url "http://example.com/FIXME"
+ :license {:name "Eclipse Public License"
+ :url "http://www.eclipse.org/legal/epl-v10.html"}
+ :dependencies [[org.eclipse.jdt/core "3.3.0-v_771"]
+ [org.clojure/clojure "1.4.0"]]
+
+ :java-source-paths ["java"]
+ :manifest {"Premain-Class" "no.disassemble.NoDisassemble"
+ "Main-Class" "no.disassemble.NoDisassemble"
+ "Can-Redefine-Classes" true
+ "Can-Retransform-Classes" true}
+ )
View
@@ -0,0 +1,30 @@
+(ns no.disassemble
+ (:import [org.eclipse.jdt.internal.core.util Disassembler]))
+
+(defn- classes
+ []
+ (no.disassemble.NoDisassemble/classes))
+
+(defn- sanitize
+ [classname]
+ (.replace classname \. \/))
+
+(comment
+ org.eclipse.jdt.core.util.ClassFileBytesDisassembler/DETAILED
+ org.eclipse.jdt.core.util.ClassFileBytesDisassembler/SYSTEM
+ org.eclipse.jdt.core.util.ClassFileBytesDisassembler/WORKING_COPY)
+
+(def levels
+ {:detailed 1
+ :default 2
+ :system 4
+ :compact 8
+ :working-copy 16})
+
+(defn disassemble
+ [class]
+ (let [cls-name (sanitize (.getCanonicalName class))
+ bytecode (get (classes) cls-name)]
+ (println cls-name)
+ (println bytecode)
+ (.disassemble (Disassembler.) bytecode "\n" (:detailed levels))))
@@ -0,0 +1,7 @@
+(ns nodisassemble.core-test
+ (:use clojure.test
+ nodisassemble.core))
+
+(deftest a-test
+ (testing "FIXME, I fail."
+ (is (= 0 1))))

0 comments on commit 53d30ce

Please sign in to comment.