-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Buglife/master
Parse note sections, MapByteBuffer option for file reading
- Loading branch information
Showing
6 changed files
with
174 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package net.fornwall.jelf; | ||
|
||
import java.io.IOException; | ||
|
||
class ElfNote { | ||
private int nameSize; | ||
private int descSize; | ||
private int type; | ||
private String name; | ||
private String desc; | ||
private byte[] descBytes; | ||
ElfNote(ElfParser parser, long offset, int size) throws ElfException, IOException { | ||
parser.seek(offset); | ||
nameSize = parser.readInt(); | ||
descSize = parser.readInt(); | ||
type = parser.readInt(); | ||
byte nameBytes[] = new byte[nameSize]; | ||
descBytes = new byte[descSize]; | ||
int bytesRead = parser.read(nameBytes); | ||
if (bytesRead != nameSize) { | ||
throw new ElfException("Error reading note (read " + bytesRead + "bytes - expected to " + "read " + nameSize + "bytes)"); | ||
} | ||
while (bytesRead % 4 != 0) { // finish reading the padding to the nearest 4 bytes | ||
parser.readUnsignedByte(); | ||
bytesRead += 1; | ||
} | ||
bytesRead = parser.read(descBytes); | ||
if (bytesRead != descSize) { | ||
throw new ElfException("Error reading note (read " + bytesRead + "bytes - expected to " + "read " + descSize + "bytes)"); | ||
} | ||
while (bytesRead % 4 != 0) { // finish reading the padding to the nearest 4 bytes | ||
parser.readUnsignedByte(); | ||
bytesRead += 1; | ||
} | ||
name = new String(nameBytes, 0, nameSize-1); // unnecessary trailing 0 | ||
desc = new String(descBytes, 0, descSize); // There's no trailing 0 on desc | ||
} | ||
|
||
String getName() { | ||
return name; | ||
} | ||
|
||
int getType() { | ||
return type; | ||
} | ||
|
||
String getDesc() { | ||
return desc; | ||
} | ||
|
||
byte[] getDescBytes() { | ||
return descBytes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters