JAD is a java decompiler,
http://www.geocities.com/SiliconValley/Bridge/8617/jad.html.  Here is
little bit of emacs lisp to run jad from emacs.  If the current buffer
is a .class file, it just runs jad.  If the current buffer is a
zip/jar file, it extracts the file first, then runs jad.  Enjoy!

(defun jad-buffer ()
"Run jad over the contents of the current buffer and display it in a
jde-mode window.  If the current buffer is a jar or zip file, first
extract the file under the cursor." 
  (interactive)
  (let* ((name (file-name-nondirectory (buffer-file-name)))
         extracted-buffer)

    (if (string-match "\\.jar\\|\\.zip" name)
        (progn
          (setq extracted-buffer (archive-extract))
          (setq name (file-name-nondirectory (buffer-file-name)))))

    (if (string-match "\\.class$" name)
        (let ((new-buffer-name (replace-match ".java" nil nil name))
              (tmp-name (concat (substitute-in-file-name "$TMP/") name)))
          (write-file tmp-name)
          (call-process "jad" nil new-buffer-name nil 
                        "-b" "-dead" "-ff" "-l60" "-space" "-t2" "-p" tmp-name)

          (if extracted-buffer
              (kill-buffer extracted-buffer))

          (pop-to-buffer new-buffer-name)
          (goto-char (point-min))
          (jde-mode)))))

(eval-after-load "arc-mode"
 '(define-key archive-mode-map "j" 'jad-buffer))

-- 
Robert

Reply via email to