m (Category: Java)
m (minor reformatting)
Line 9: Line 9:
 
|rating=9/7
 
|rating=9/7
 
|text=
 
|text=
 
   
 
Here's a plugin to automatically decompile Java .class files as they're read in. Tweak the javap flags for what you want to see. I didn't post this as a script because it's too simple and it's really more useful for demonstrating how to read decompilable files (or other binary files that can be converted to text).
 
Here's a plugin to automatically decompile Java .class files as they're read in. Tweak the javap flags for what you want to see. I didn't post this as a script because it's too simple and it's really more useful for demonstrating how to read decompilable files (or other binary files that can be converted to text).
 
function s:ReadClass(dir, classname)
 
 
execute "cd " . a:dir
 
 
execute "0read !javap -c " . a:classname
 
  +
1
function s:ReadClass(dir, classname)
 
 
setlocal readonly
 
 
setlocal nomodified
execute "cd " . a:dir
 
 
endfunction
 
  +
execute "0read !javap -c " . a:classname
 
 
autocmd BufReadCmd *.class
 
 
\ call <SID>ReadClass(expand("<afile>:p:h"), expand("<afile>:t:r"))
1
 
 
setlocal readonly
 
 
setlocal nomodified
 
 
endfunction
 
 
 
 
 
 
autocmd BufReadCmd *.class
 
 
\ call <SID>ReadClass(expand("<afile>:p:h"), expand("<afile>:t:r"))
 
 
 
 
 
 
}}
 
}}
   
 
== Comments ==
 
== Comments ==
 
 
It doesn't work when package is used in java code.
 
It doesn't work when package is used in java code.
   
Foo.java
+
Foo.java
  +
 
package com.foo.test;
+
package com.foo.test;
class Foo
+
class Foo
{
+
{
  +
 
}
+
}
   
 
The question is how to save package information?
 
The question is how to save package information?
Line 60: Line 40:
 
----
 
----
 
For jad:
 
For jad:
 
au BufReadCmd *.class setl readonly nomodified | %!jad -p <afile>
 
au BufReadCmd *.class setl readonly nomodified | %!jad -p <afile>
 
   
   

Revision as of 13:32, 25 July 2007

Previous TipNext Tip

Tip: #155 - Decompile Java .class files automatically

Created: November 7, 2001 3:16 Complexity: intermediate Author: Lawrence Kesteloot Version: 6.0 Karma: 9/7 Imported from: Tip#155

Here's a plugin to automatically decompile Java .class files as they're read in. Tweak the javap flags for what you want to see. I didn't post this as a script because it's too simple and it's really more useful for demonstrating how to read decompilable files (or other binary files that can be converted to text).

function s:ReadClass(dir, classname) 
  execute "cd " . a:dir 
  execute "0read !javap -c " . a:classname 
  1 
  setlocal readonly 
  setlocal nomodified 
endfunction 

autocmd BufReadCmd *.class 
  \ call <SID>ReadClass(expand("<afile>:p:h"), expand("<afile>:t:r"))

Comments

It doesn't work when package is used in java code.

Foo.java 

package com.foo.test; 
class Foo 
{ 

} 

The question is how to save package information?

maxiangjiang--AT--hotmail.com , November 7, 2001 10:14


For jad:

au BufReadCmd *.class setl readonly nomodified | %!jad -p <afile> 


do1--AT--yandex.ru , March 6, 2006 4:06


Community content is available under CC-BY-SA unless otherwise noted.