Vim Tips Wiki
No edit summary
 
No edit summary
 
(9 intermediate revisions by 4 users not shown)
Line 1: Line 1:
  +
{{TipImported
{{review}}
 
{{Tip
 
 
|id=54
 
|id=54
  +
|previous=53
|title=View a Java Class File Decompiled thru Vim
 
  +
|next=58
|created=March 22, 2001 18:21
+
|created=March 22, 2001
 
|complexity=intermediate
 
|complexity=intermediate
|author=bhaskar_v_k--AT--hotmail.com
+
|author=bhaskar_v_k
 
|version=5.7
 
|version=5.7
 
|rating=148/48
 
|rating=148/48
  +
|category1=Java
|text=
 
  +
|category2=
Hi All,
 
 
}}
 
Do you wish you could view a Java Class File using Vim?
   
 
First of all you will need a Java Decompiler to decompile the Class File. I would suggest the JAD decompiler by Pavel Kouznetsov
Wish u could view a Java Class File using Vim,
 
  +
* http://www.varaneckas.com/jad
   
 
It's a command line decompiler and absolutely free.
Well ur query ends here.
 
   
 
Next create a vimscript file called jad.vim:
First of all u will need a Java Decompiler to decompile
 
   
  +
<pre>
the Class File.
 
 
augr class
 
au!
 
au bufreadpost,filereadpost *.class %!d:jad.exe -noctor -ff -i -p %
 
au bufreadpost,filereadpost *.class set readonly
 
au bufreadpost,filereadpost *.class set ft=java
 
au bufreadpost,filereadpost *.class normal gg=G
 
au bufreadpost,filereadpost *.class set nomodified
 
augr END
  +
</pre>
   
  +
Note: Keep the Jad.exe in a directory without white spaces. The -p options directs JAD to send the output to standard output instead of a .jad file. Other options are described on the JAD site.
I would suggest the JAD decompiler by Pavel Kouznetsov
 
   
 
Next add the following line in the [[vimrc]] file.
http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
 
   
  +
<pre>
 
so jad.vim
  +
</pre>
   
 
Next time you do vim abc.class, you have the source code for abc.class.
   
  +
NOTE: I have written the script so as to open the class file read only, So that you don't accidentally modify it. You can also extend this script to unjar a jar file and then view each file in the JAR file.
Its a command line decompiler and absolutely free.
 
   
 
==Comments==
U can use any command line decompiler of ur choice.
 
 
I modified this a little bit to use the improved file runtime organisation of vim60, I don't know if other will like it better but here it is:
 
I added to filetype.vim:
 
augroup filetypedetect
 
au! BufRead,BufNewFile *.jad setfiletype java
 
au! BufRead,BufNewFile *.class setfiletype class
 
augroup END
   
 
and created in ftplugin a class.vim with
 
%!jad.exe -noctor -ff -i -p %
 
set readonly
 
set ft=java
 
normal gg=G
 
set nomodified
   
 
Next create a vimscript file called jad.vim as
 
 
&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35; FILE START &#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;
 
 
augr class
 
 
au!
 
 
au bufreadpost,filereadpost *.class %!d:jad.exe -noctor -ff -i -p %
 
 
au bufreadpost,filereadpost *.class set readonly
 
 
au bufreadpost,filereadpost *.class set ft=java
 
 
au bufreadpost,filereadpost *.class normal gg=G
 
 
au bufreadpost,filereadpost *.class set nomodified
 
 
augr END
 
 
&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35; FILE END &#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;&#35;
 
 
 
 
Note:- Keep the Jad.exe in a directory with out white spaces.
 
 
The -p options directs JAD to send the output to standard output
 
 
instead of a .jad file. Other options are described on the JAD site.
 
 
 
 
Next add the following line in the .vimrc file.
 
 
so jad.vim
 
 
 
 
Next time u do vim abc.class. Viola u have the source code
 
 
for abc.class.
 
 
 
 
NOTE:- I have written the script so as to open the class file
 
 
read only, So that u dont accidently modify it.
 
 
U can also exted this script to unjar a jar file and then view each
 
 
file in the JAR file.
 
 
thanks
 
 
bhaskar
 
 
Any suggestions are welcome
 
 
 
}}
 
 
== Comments ==
 
Hi,
 
first I love this script
 
I modified this a little bit to use the improved file runtime organisation of vim60, I don't know if other will like it better but here it is:
 
I added to filetype.vim:
 
augroup filetypedetect
 
au! BufRead,BufNewFile *.jad setfiletype java
 
au! BufRead,BufNewFile *.class setfiletype class
 
augroup END
 
and created in ftplugin a class.vim with
 
%!jad.exe -noctor -ff -i -p %
 
set readonly
 
set ft=java
 
normal gg=G
 
set nomodified
 
 
b.cerrina--AT--wanadoo.fr
 
, August 21, 2001 13:54
 
 
----
 
----
If you don't want to 'hit ENTER' after every decompilation, you can add 'silent' to some of the lines:
+
If you don't want to 'hit ENTER' after every decompilation, you can add 'silent' to some of the lines:
   
au bufreadpost,filereadpost *.class silent %!jad -noctor -ff -i -p %
+
au bufreadpost,filereadpost *.class silent %!jad -noctor -ff -i -p %
   
and maybe even:
+
and maybe even:
   
au bufreadpost,filereadpost *.class silent normal gg=G
+
au bufreadpost,filereadpost *.class silent normal gg=G
   
(thanks to myitcv on &#35;vim--AT--EFnet)
 
 
 
roel--AT--SP-AM_almende.com
 
, February 24, 2004 6:00
 
 
----
 
----
 
I can now select any class file, right click, and select the "Edit with Vim" option to view the source.
Nice script!!
 
 
I can now select any class file, right click, and select the "Edit with Vim" option to view the source.
 
   
I'm just wondering, how do I change this to if I do the same to a jar file, and it will show me the contents of the jar file, as in a jar -tf, and if I select any of the entries, I can view the source?
+
I'm just wondering, how do I change this to if I do the same to a jar file, and it will show me the contents of the jar file, as in a jar -tf, and if I select any of the entries, I can view the source?
   
I tried opening the jar file using WinZip, and if I view any of the entries in it using vim, I'll get something like this:
+
I tried opening the jar file using WinZip, and if I view any of the entries in it using vim, I'll get something like this:
JavaClassFileReadException: can't open input file on `C:\Documents'
+
JavaClassFileReadException: can't open input file on `C:\Documents'
JavaClassFileReadException: can't open input file on `and'
+
JavaClassFileReadException: can't open input file on `and'
JavaClassFileReadException: can't open input file on `Settings\gwunwai\Local'
+
JavaClassFileReadException: can't open input file on `Settings\gwunwai\Local'
JavaClassFileReadException: can't open input file on `Settings\Temp\Version.class'
+
JavaClassFileReadException: can't open input file on `Settings\Temp\Version.class'
   
I think that's because WinZip extracts the zip entries into my temp directory, which contains white spaces.
+
I think that's because WinZip extracts the zip entries into my temp directory, which contains white spaces.
   
 
Is there some way around this?
 
Is there some way around this?
   
gwunwai--AT--pacific.net.sg
 
, June 6, 2004 23:06
 
 
----
 
----
you can change the command to %!jad.exe -noctor -ff -i -p "%"
+
you can change the command to %!jad.exe -noctor -ff -i -p "%"
 
(enclosed the % with quotes). It worked for me
 
(enclosed the % with quotes). It worked for me
   
'''Anonymous'''
 
, July 13, 2005 11:18
 
 
----
 
----
<!-- parsed by vimtips.py in 0.625483 seconds-->
 

Latest revision as of 01:55, 5 April 2009

Tip 54 Printable Monobook Previous Next

created March 22, 2001 · complexity intermediate · author bhaskar_v_k · version 5.7


Do you wish you could view a Java Class File using Vim?

First of all you will need a Java Decompiler to decompile the Class File. I would suggest the JAD decompiler by Pavel Kouznetsov

It's a command line decompiler and absolutely free.

Next create a vimscript file called jad.vim:

augr class
au!
au bufreadpost,filereadpost *.class %!d:jad.exe -noctor -ff -i -p %
au bufreadpost,filereadpost *.class set readonly
au bufreadpost,filereadpost *.class set ft=java
au bufreadpost,filereadpost *.class normal gg=G
au bufreadpost,filereadpost *.class set nomodified
augr END

Note: Keep the Jad.exe in a directory without white spaces. The -p options directs JAD to send the output to standard output instead of a .jad file. Other options are described on the JAD site.

Next add the following line in the vimrc file.

so jad.vim

Next time you do vim abc.class, you have the source code for abc.class.

NOTE: I have written the script so as to open the class file read only, So that you don't accidentally modify it. You can also extend this script to unjar a jar file and then view each file in the JAR file.

Comments[]

I modified this a little bit to use the improved file runtime organisation of vim60, I don't know if other will like it better but here it is: I added to filetype.vim:

augroup filetypedetect
au! BufRead,BufNewFile *.jad setfiletype java
au! BufRead,BufNewFile *.class setfiletype class
augroup END

and created in ftplugin a class.vim with

%!jad.exe -noctor -ff -i -p %
set readonly
set ft=java
normal gg=G
set nomodified

If you don't want to 'hit ENTER' after every decompilation, you can add 'silent' to some of the lines:

au bufreadpost,filereadpost *.class silent %!jad -noctor -ff -i -p %

and maybe even:

au bufreadpost,filereadpost *.class silent normal gg=G

I can now select any class file, right click, and select the "Edit with Vim" option to view the source.

I'm just wondering, how do I change this to if I do the same to a jar file, and it will show me the contents of the jar file, as in a jar -tf, and if I select any of the entries, I can view the source?

I tried opening the jar file using WinZip, and if I view any of the entries in it using vim, I'll get something like this: JavaClassFileReadException: can't open input file on `C:\Documents' JavaClassFileReadException: can't open input file on `and' JavaClassFileReadException: can't open input file on `Settings\gwunwai\Local' JavaClassFileReadException: can't open input file on `Settings\Temp\Version.class'

I think that's because WinZip extracts the zip entries into my temp directory, which contains white spaces.

Is there some way around this?


you can change the command to %!jad.exe -noctor -ff -i -p "%" (enclosed the % with quotes). It worked for me