open class file as binary

handle read to return early


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@1086 379699f6-c40d-0410-875b-85095c16579e
branch_1_1
jochen 26 years ago
parent dd3b440b9b
commit 48d5c63aec
  1. 32
      jode/javaDependencies.pl.in

@ -39,11 +39,22 @@
my $buff; my $buff;
sub readUTF { sub readInBuff ($) {
read FILE, $buff, 2 or die "Can't read UTF8 length"; my $count = $_[0];
my $offset = 0;
while ($count > 0) {
my $result = read FILE, $buff, $count, $offset or 0;
$offset += $result;
$count -= $result;
}
$offset;
}
sub readUTF () {
readInBuff 2 or die "Can't read UTF8 length";
my $ulength = unpack("n", $buff) & 0xffff; my $ulength = unpack("n", $buff) & 0xffff;
return "" if $ulength == 0; return "" if $ulength == 0;
read FILE, $buff, $ulength or die "Can't read UTF8 string $ulength"; readInBuff $ulength or die "Can't read UTF8 string $ulength";
unpack("a$ulength", $buff); unpack("a$ulength", $buff);
} }
@ -54,15 +65,16 @@ my ($filename, %done);
%done=(); %done=();
for $filename ($clazz, glob("$base\\\$*.class")) { for $filename ($clazz, glob("$base\\\$*.class")) {
open FILE, $filename; open FILE, $filename;
binmode FILE;
read FILE, $buff, 8 or die "Can't read header"; readInBuff 8 or die "Can't read header";
my ($magic, $minor, $major) = unpack("Nnn", $buff); my ($magic, $minor, $major) = unpack("Nnn", $buff);
die "Wrong magic $magic" if $magic != 0xcafebabe; die "Wrong magic $magic" if $magic != 0xcafebabe;
die "Wrong minor $minor" if $minor > 3; die "Wrong minor $minor" if $minor > 3;
die "Wrong minor $major" if $major != 45; die "Wrong minor $major" if $major != 45;
read FILE, $buff, 2 or die "Can't read cpool length"; readInBuff 2 or die "Can't read cpool length";
my ($length) = unpack("n", $buff) & 0xffff; my ($length) = unpack("n", $buff) & 0xffff;
@ -72,7 +84,7 @@ for $filename ($clazz, glob("$base\\\$*.class")) {
my @clazzes; my @clazzes;
for ($number = 1; $number < $length; $number++) { for ($number = 1; $number < $length; $number++) {
read FILE, $buff, 1 or die "Can't read constant tag"; readInBuff 1 or die "Can't read constant tag";
my ($tag) = unpack("C", $buff); my ($tag) = unpack("C", $buff);
#print STDERR "$number/$length: $tag"; #print STDERR "$number/$length: $tag";
@ -87,27 +99,27 @@ for $filename ($clazz, glob("$base\\\$*.class")) {
/^(3|4|9|10|11|12)$/ && do { /^(3|4|9|10|11|12)$/ && do {
# INTEGER, FLOAT, FIELDREF, METHODREF, IFACEREF, NAMEANDTYPE # INTEGER, FLOAT, FIELDREF, METHODREF, IFACEREF, NAMEANDTYPE
read FILE, $buff, 4; readInBuff 4;
last tags; last tags;
}; };
/^(5|6)$/ && do { /^(5|6)$/ && do {
# LONG, DOUBLE # LONG, DOUBLE
read FILE, $buff, 8; readInBuff 8;
$number++; $number++;
last tags; last tags;
}; };
/^7$/ && do { /^7$/ && do {
# CLASS # CLASS
read FILE, $buff, 2; readInBuff 2;
push @clazzes, (unpack("n", $buff) & 0xffff); push @clazzes, (unpack("n", $buff) & 0xffff);
last tags; last tags;
}; };
/^8$/ && do { /^8$/ && do {
# STRING # STRING
read FILE, $buff, 2; readInBuff 2;
last tags; last tags;
}; };
die "Unknown tag: $tag, $number/$length, $filename"; die "Unknown tag: $tag, $number/$length, $filename";

Loading…
Cancel
Save