forked from eisop-plume-lib/plume-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
classfile_check_version
executable file
·40 lines (34 loc) · 1.05 KB
/
classfile_check_version
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#! /bin/csh -f
# usage <version> <classfile>
# Check that .class file's version is <= the specified version.
# This ensures that the class will run on a particular version of Java.
# For example,
# classfile_check_version 49 MyClass.class
# checks that the classfile will run in a 1.5 JVM (1.6 classfiles are version 50).
# For all class file format version numbers, see
# http://en.wikipedia.org/wiki/Class_(file_format)
## TODO: perhaps use plume/ClassFileVersion.java instead.
if ($#argv != 2) then
echo "Should be two arguments (version classfile)"
exit -1
endif
if (!( -e $2)) then
echo "$2 does not exist"
exit -1
endif
set header = (`xxd -l 8 $2 | sed 's/^0*0: //' | sed 's/ *.*$//'`)
#echo $header
#echo $#header
if (("$header[1]" != "cafe") || ("$header[2]" != "babe")) then
echo $2 is not a Java class file
exit -1
endif
# bc needs hex values in upper case
set HEAD = `echo $header[4] | tr '[:lower:]' '[:upper:]'`
set version = `echo "ibase=16; " $HEAD | bc`
if ($version > $1) then
echo $2 has version $version
exit -1
else
exit 0
endif