source: trunk/abcl/contrib/abcl-introspect/fernflower.lisp

Last change on this file was 15283, checked in by Mark Evenson, 4 years ago

abcl-introspect: fernflower decompiler working
Adapted from (Alan Ruttenberg)

File size: 1.3 KB
Line 
1(defpackage :abcl-introspect/jvm/tools/fernflower
2  (:use :cl)
3  (:export
4   #:disassemble-class-bytes))
5(in-package :abcl-introspect/jvm/tools/fernflower)
6
7(defun fernflower-classpath ()
8  ;; Very ugly.  How to make more intelligble?
9  (slot-value (first (asdf:component-children (asdf:find-component  :fernflower "mvn-libs")))
10              'asdf/interface::resolved-classpath))
11
12(defun disassemble-class-bytes (object)
13  (uiop/stream::with-temporary-file (:pathname p :type "class")
14    (ext::write-class object p)
15    (let* ((directory
16             (namestring (truename (make-pathname :directory (pathname-directory p)))))
17     (path
18             (namestring (truename p)))
19           (command 
20       (format nil "java -cp ~a org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler ~a ~a"
21                     (fernflower-classpath) p directory))
22           (output
23             (namestring (make-pathname :defaults p :type "java"))))
24      (uiop:run-program command)
25      (let ((result (alexandria:read-file-into-string output)))
26        (sys::print-lines-with-prefix result)))))
27
28(eval-when (:load-toplevel :execute)
29  (pushnew `(:fernflower . abcl-introspect/jvm/tools/fernflower::disassemble-class-bytes)
30           sys::*disassemblers*)
31  (format cl:*load-verbose* "~&; ~a: Successfully added fernflower decompiler.~%" *package*))
32
33
Note: See TracBrowser for help on using the repository browser.