I’ve been looking for a decent tool to determine the byte code version for a Java .class file. You know, the one based on the numbers after the CAFEBABE magic (you can read more about this here or here).
There are some tools around for this, but most of them written in Java. I really don’t see the point in starting a JVM just to read 4 bytes from a file, so I wrote a short Perl script for this. Again, I am no Perl expert so this is probably not the best solution performance-wise and such.
Usage
1. Running the script with no arguments – will result in scanning the current directory recursively for .class files. The results are grouped by directory and a total number of files is also displayed. Directories that do not contain any .class files will be ignored, in order to keep a clean output. Below is a short sample.
cosmin@cosminaru:~/work/quizine$ bcversion.pl
* /home/cosmin/work/quizine/src/main/webroot/WEB-INF/classes/org/quizine (2 files)
QuizineException.class -> 1.6
ApplicationContext.class -> 1.6
* /home/cosmin/work/quizine/src/main/webroot/WEB-INF/classes/org/quizine/web (2 files)
ErrorHandlerFilter.class -> 1.6
SessionContext.class -> 1.6
* /home/cosmin/work/quizine/src/main/webroot/WEB-INF/classes/org/quizine/web/actions (1 files)
ActionBase.class -> 1.6
2. If you provide one or more arguments, the script will only scan the content of these arguments. If the argument is a file then the byte code version is displayed for that file. If it is a directory then it will be scanned recursively, just like above.
Note: The paths from the argument list should all be relative to the current directory in order for the script to work correctly.
cosmin@cosminaru:~.../model/quiz$ bcversion.pl AbstractQuestion.class result
* AbstractQuestion.class -> 1.6
* /home/cosmin/work/quizine/src/main/webroot/WEB-INF/classes/org/quizine/model/quiz/result (5 files)
QuestionnaireResult.class -> 1.6
BooleanAnswer.class -> 1.6
AbstractAnswer.class -> 1.6
SingleChoiceAnswer.class -> 1.6
MultipleChoiceAnswer.class -> 1.6
I’ll probably want to scan JAR files and directories containing JAR files. But the really poor Perl docs for reading ZIP buffers didn’t quite help me. If you think think you can give a hand with that, drop a note
.
Download:
You can get the script from here.
1 comment so far ↓
[...] deci deunazi pe un foarte interesant blog o chestie foarte interesanta. Si m-am gandit ca merita mentionata. Suna cam vag, nu [...]
Leave a Comment