Skip to content

Instantly share code, notes, and snippets.

@mallowlabs
Created February 13, 2010 09:10
Show Gist options
  • Save mallowlabs/303356 to your computer and use it in GitHub Desktop.
Save mallowlabs/303356 to your computer and use it in GitHub Desktop.
Get compiled version of jar files.
#!/usr/bin/env ruby -Ku
require 'rubygems'
require 'zipruby'
version_map = {
45.3 => "J2SE 1.1",
46.0 => "J2SE 1.2",
47.0 => "J2SE 1.3",
48.0 => "J2SE 1.4",
49.0 => "Java SE 5",
50.0 => "Java SE 6"
}
def version(file)
a = file.read(10)
"#{a[6]*0xff+a[7]}.#{a[4]*0xff+a[5]}".to_f
end
ARGV.each do |path|
Zip::Archive.open(path) do |ar|
ar.each do |f|
next if f.directory? || !(f.name =‾ /\.class$/)
ar.fopen(f.name) do |h|
puts version_map[version(h)]
end
break
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment