Skip to content

Commit

Permalink
#8 ELF: fix header length issue
Browse files Browse the repository at this point in the history
  • Loading branch information
amosshi committed Jun 23, 2020
1 parent 87e2418 commit 344ea37
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ public static byte[] readZipEntryAsBytes(final ZipFile zipFile, final ZipEntry z
final long fileSize = zipEntry.getSize();
final byte contents[] = new byte[(int) fileSize];
ByteBuffer byteBuf = ByteBuffer.allocate(contents.length);
InputStream is = null;
int bytesRead = 0;
InputStream is;
int bytesRead;
int bytesAll = 0;

try {
Expand Down Expand Up @@ -216,6 +216,7 @@ public static void skip(final InputStream is, final long skip) throws IOExceptio
}
}

@Deprecated
public static void skipBytes(final DataInput di, final int skip) throws IOException {
long skippedBytes = di.skipBytes(skip);
if (skippedBytes != skip) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public FileComponenPlaceHolder(final PosDataInputStream posDataInputStream, int

if (length > 0) {
this.length = length;
BytesTool.skipBytes(posDataInputStream, length);
BytesTool.skip(posDataInputStream, length);
} else {
this.length = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1623,7 +1623,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi
InstructionParsed parsed = new InstructionParsed(curPos, this.code);
parsed.cpIndex = pdis.readUnsignedShort();
parsed.nArgs = pdis.readUnsignedByte();
BytesTool.skipBytes(pdis, 1);
BytesTool.skip(pdis, 1);

parsed.opCodeText = String.format("%s interface=%d, nargs=%d", this.name(), parsed.cpIndex, parsed.nArgs);
return parsed;
Expand All @@ -1639,7 +1639,7 @@ protected InstructionParsed parse(final int curPos, final PosDataInputStream pdi
parsed.cpIndex = pdis.readUnsignedShort();

// Skip 2 zero bytes
BytesTool.skipBytes(pdis, 2);
BytesTool.skip(pdis, 2);
parsed.opCodeText = this.name();
return parsed;
}
Expand Down Expand Up @@ -1985,7 +1985,7 @@ private void skipPad(final PosDataInputStream pdis) throws IOException {
int skip = pdis.getPos() % 4;
skip = (skip > 0) ? 4 - skip : skip;
if (skip > 0) {
BytesTool.skipBytes(pdis, skip);
BytesTool.skip(pdis, skip);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class Elf64_Ehdr extends FileComponent implements GenerateTreeNode {
this.e_shnum = input.read_Elf64_Half();
this.e_shstrndx = input.read_Elf64_Half();

super.length = input.getPos();
super.length = input.getPos() - super.startPos;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ElfFile(File file) throws IOException, FileFormatException {

PosDataInputStream input = new PosDataInputStream(new PosByteArrayInputStream(this.fileByteArray));
this.ident = new Identification(input);

PosDataInputStreamElf inputElf = new PosDataInputStreamElf(new PosByteArrayInputStream(this.fileByteArray), this.ident.EI_DATA);
BytesTool.skip(input, Identification.EI_NIDENT);
this.header = new Elf64_Ehdr(inputElf);
Expand Down

0 comments on commit 344ea37

Please sign in to comment.