Moved from util/pe -> peParser. Added PE.getVersion().

This commit is contained in:
nathan 2016-02-10 22:15:35 +01:00
parent dc380d7b6d
commit 163ee6d542
41 changed files with 146 additions and 119 deletions

View File

@ -19,7 +19,7 @@ This project is **kept in sync** with the utilities library, so "jar hell" is no
<dependency>
<groupId>com.dorkbox</groupId>
<artifactId>PeParser</artifactId>
<version>1.2</version>
<version>2.0</version>
</dependency>
```
@ -31,3 +31,16 @@ https://oss.sonatype.org/content/repositories/releases/com/dorkbox/PeParser-Dork
<h2>License</h2>
This project is distributed under the terms of the Apache v2.0 License. See file "LICENSE" for further references.

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe;
package dorkbox.peParser;
import java.io.ByteArrayInputStream;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe;
package dorkbox.peParser;
public class DataLocation {

View File

@ -13,7 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe;
package dorkbox.peParser;
import dorkbox.peParser.headers.resources.ResourceDataEntry;
import dorkbox.peParser.headers.resources.ResourceDirectoryEntry;
import dorkbox.peParser.headers.resources.ResourceDirectoryHeader;
import dorkbox.peParser.types.ByteDefinition;
import dorkbox.peParser.types.ImageDataDir;
import dorkbox.util.OS;
import dorkbox.peParser.headers.COFFFileHeader;
import dorkbox.peParser.headers.Header;
import dorkbox.peParser.headers.OptionalHeader;
import dorkbox.peParser.headers.SectionTable;
import dorkbox.peParser.headers.SectionTableEntry;
import dorkbox.peParser.misc.DirEntry;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -23,19 +36,6 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.LinkedList;
import dorkbox.util.OS;
import dorkbox.util.pe.headers.COFFFileHeader;
import dorkbox.util.pe.headers.Header;
import dorkbox.util.pe.headers.OptionalHeader;
import dorkbox.util.pe.headers.SectionTable;
import dorkbox.util.pe.headers.SectionTableEntry;
import dorkbox.util.pe.headers.resources.ResourceDataEntry;
import dorkbox.util.pe.headers.resources.ResourceDirectoryEntry;
import dorkbox.util.pe.headers.resources.ResourceDirectoryHeader;
import dorkbox.util.pe.misc.DirEntry;
import dorkbox.util.pe.types.ByteDefinition;
import dorkbox.util.pe.types.ImageDataDir;
public class PE {
// info from:
// http://evilzone.org/tutorials/(paper)-portable-executable-format-and-its-rsrc-section/
@ -43,6 +43,13 @@ public class PE {
// http://www.csn.ul.ie/~caolan/pub/winresdump/winresdump/doc/pefile2.html
// http://msdn.microsoft.com/en-us/library/ms809762.aspx
/**
* Gets the version number.
*/
public static
String getVersion() {
return "2.0";
}
private static final int PE_OFFSET_LOCATION = 0x3c;
private static final byte[] PE_SIG = "PE\0\0".getBytes();
@ -202,7 +209,6 @@ public class PE {
}
}
@SuppressWarnings("null")
public ByteArrayInputStream getLargestResourceAsStream() {
for (ImageDataDir entry : this.optionalHeader.tables) {
if (entry.getType() == DirEntry.RESOURCE) {
@ -243,3 +249,12 @@ public class PE {
return null;
}
}

View File

@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.headers;
package dorkbox.peParser.headers;
import dorkbox.util.pe.ByteArray;
import dorkbox.util.pe.types.DWORD;
import dorkbox.util.pe.types.MachineType;
import dorkbox.util.pe.types.CoffCharacteristics;
import dorkbox.util.pe.types.TimeDate;
import dorkbox.util.pe.types.WORD;
import dorkbox.peParser.ByteArray;
import dorkbox.peParser.types.CoffCharacteristics;
import dorkbox.peParser.types.DWORD;
import dorkbox.peParser.types.MachineType;
import dorkbox.peParser.types.TimeDate;
import dorkbox.peParser.types.WORD;
public class COFFFileHeader extends Header {

View File

@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.headers;
package dorkbox.peParser.headers;
import java.util.ArrayList;
import java.util.List;
import dorkbox.util.pe.types.ByteDefinition;
import dorkbox.peParser.types.ByteDefinition;
public class Header {
public List<ByteDefinition<?>> headers = new ArrayList<ByteDefinition<?>>(0);

View File

@ -13,27 +13,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.headers;
package dorkbox.peParser.headers;
import java.util.ArrayList;
import java.util.List;
import dorkbox.util.pe.ByteArray;
import dorkbox.util.pe.misc.DirEntry;
import dorkbox.util.pe.misc.MagicNumberType;
import dorkbox.util.pe.types.ByteDefinition;
import dorkbox.util.pe.types.DWORD;
import dorkbox.util.pe.types.HeaderDefinition;
import dorkbox.util.pe.types.ImageBase;
import dorkbox.util.pe.types.ImageBase_Wide;
import dorkbox.util.pe.types.ImageDataDir;
import dorkbox.util.pe.types.ImageDataDirExtra;
import dorkbox.util.pe.types.MagicNumber;
import dorkbox.util.pe.types.DWORD_WIDE;
import dorkbox.util.pe.types.RVA;
import dorkbox.util.pe.types.DllCharacteristics;
import dorkbox.util.pe.types.Subsystem;
import dorkbox.util.pe.types.WORD;
import dorkbox.peParser.misc.DirEntry;
import dorkbox.peParser.ByteArray;
import dorkbox.peParser.misc.MagicNumberType;
import dorkbox.peParser.types.ByteDefinition;
import dorkbox.peParser.types.DWORD;
import dorkbox.peParser.types.HeaderDefinition;
import dorkbox.peParser.types.ImageBase;
import dorkbox.peParser.types.ImageBase_Wide;
import dorkbox.peParser.types.ImageDataDir;
import dorkbox.peParser.types.ImageDataDirExtra;
import dorkbox.peParser.types.MagicNumber;
import dorkbox.peParser.types.DWORD_WIDE;
import dorkbox.peParser.types.RVA;
import dorkbox.peParser.types.DllCharacteristics;
import dorkbox.peParser.types.Subsystem;
import dorkbox.peParser.types.WORD;
public class OptionalHeader extends Header {

View File

@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.headers;
package dorkbox.peParser.headers;
import java.util.ArrayList;
import java.util.List;
import dorkbox.util.pe.ByteArray;
import dorkbox.peParser.ByteArray;
public class SectionTable extends Header {

View File

@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.headers;
package dorkbox.peParser.headers;
import dorkbox.util.pe.ByteArray;
import dorkbox.util.pe.types.AsciiString;
import dorkbox.util.pe.types.HeaderDefinition;
import dorkbox.util.pe.types.DWORD;
import dorkbox.util.pe.types.SectionCharacteristics;
import dorkbox.util.pe.types.WORD;
import dorkbox.peParser.types.AsciiString;
import dorkbox.peParser.types.HeaderDefinition;
import dorkbox.peParser.ByteArray;
import dorkbox.peParser.types.DWORD;
import dorkbox.peParser.types.SectionCharacteristics;
import dorkbox.peParser.types.WORD;
public class SectionTableEntry extends Header {
@ -39,7 +39,6 @@ public class SectionTableEntry extends Header {
public final WORD NUMBER_OF_LINE_NUMBERS;
public final SectionCharacteristics CHARACTERISTICS;
@SuppressWarnings("unused")
public SectionTableEntry(ByteArray bytes, int entryNumber, int offset, int size) {
h(new HeaderDefinition("Section table entry: " + entryNumber));

View File

@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.headers.flags;
package dorkbox.peParser.headers.flags;
import dorkbox.util.bytes.UShort;
import java.util.ArrayList;
import java.util.List;
import dorkbox.util.bytes.UShort;
public enum Characteristics {
IMAGE_FILE_RELOCS_STRIPPED("1", "Resource information is stripped from the file"),

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.headers.flags;
package dorkbox.peParser.headers.flags;
import java.util.ArrayList;
import java.util.List;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.headers.flags;
package dorkbox.peParser.headers.flags;
import java.util.ArrayList;
import java.util.List;

View File

@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.headers.resources;
package dorkbox.peParser.headers.resources;
import dorkbox.util.pe.ByteArray;
import dorkbox.util.pe.headers.Header;
import dorkbox.util.pe.headers.SectionTableEntry;
import dorkbox.util.pe.types.DWORD;
import dorkbox.peParser.ByteArray;
import dorkbox.peParser.headers.Header;
import dorkbox.peParser.headers.SectionTableEntry;
import dorkbox.peParser.types.DWORD;
public class ResourceDataEntry extends Header {

View File

@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.headers.resources;
package dorkbox.peParser.headers.resources;
import dorkbox.util.pe.ByteArray;
import dorkbox.util.pe.headers.Header;
import dorkbox.util.pe.headers.SectionTableEntry;
import dorkbox.util.pe.types.DWORD;
import dorkbox.util.pe.types.ResourceDirName;
import dorkbox.peParser.ByteArray;
import dorkbox.peParser.headers.Header;
import dorkbox.peParser.headers.SectionTableEntry;
import dorkbox.peParser.types.DWORD;
import dorkbox.peParser.types.ResourceDirName;
public class ResourceDirectoryEntry extends Header {

View File

@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.headers.resources;
package dorkbox.peParser.headers.resources;
import dorkbox.util.pe.ByteArray;
import dorkbox.util.pe.headers.Header;
import dorkbox.util.pe.headers.SectionTableEntry;
import dorkbox.util.pe.types.DWORD;
import dorkbox.util.pe.types.TimeDate;
import dorkbox.util.pe.types.WORD;
import dorkbox.peParser.ByteArray;
import dorkbox.peParser.headers.Header;
import dorkbox.peParser.headers.SectionTableEntry;
import dorkbox.peParser.types.DWORD;
import dorkbox.peParser.types.TimeDate;
import dorkbox.peParser.types.WORD;
public class ResourceDirectoryHeader extends Header {

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.misc;
package dorkbox.peParser.misc;
public enum DirEntry {

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.misc;
package dorkbox.peParser.misc;
import dorkbox.util.bytes.UInteger;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.misc;
package dorkbox.peParser.misc;
import dorkbox.util.bytes.UShort;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.misc;
package dorkbox.peParser.misc;
import dorkbox.util.bytes.UShort;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.misc;
package dorkbox.peParser.misc;
import dorkbox.util.bytes.UInteger;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.misc;
package dorkbox.peParser.misc;
import dorkbox.util.bytes.UShort;

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import dorkbox.util.OS;
import dorkbox.util.pe.ByteArray;
import dorkbox.peParser.ByteArray;
public class AsciiString extends ByteDefinition<String> {

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
public abstract class ByteDefinition<T> {

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import dorkbox.util.OS;
import dorkbox.util.bytes.UShort;
import dorkbox.util.pe.headers.flags.Characteristics;
import dorkbox.peParser.headers.flags.Characteristics;
public class CoffCharacteristics extends ByteDefinition<Characteristics[]> {

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import dorkbox.util.OS;
import dorkbox.util.bytes.UInteger;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import dorkbox.util.OS;
import dorkbox.util.bytes.ULong;

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import dorkbox.peParser.headers.flags.DllCharacteristicsType;
import dorkbox.util.OS;
import dorkbox.util.bytes.UShort;
import dorkbox.util.pe.headers.flags.DllCharacteristicsType;
public class DllCharacteristics extends ByteDefinition<DllCharacteristicsType[]> {

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import dorkbox.util.OS;

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import dorkbox.util.OS;
import dorkbox.util.bytes.UInteger;
import dorkbox.util.pe.misc.ImageBaseType;
import dorkbox.peParser.misc.ImageBaseType;
public class ImageBase extends ByteDefinition<UInteger> {

View File

@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import dorkbox.util.OS;
import dorkbox.util.bytes.UInteger;
import dorkbox.util.bytes.ULong;
import dorkbox.util.pe.misc.ImageBaseType;
import dorkbox.peParser.misc.ImageBaseType;
public class ImageBase_Wide extends ByteDefinition<ULong> {

View File

@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import dorkbox.util.OS;
import dorkbox.util.bytes.UInteger;
import dorkbox.util.pe.ByteArray;
import dorkbox.util.pe.headers.Header;
import dorkbox.util.pe.headers.SectionTableEntry;
import dorkbox.util.pe.misc.DirEntry;
import dorkbox.peParser.ByteArray;
import dorkbox.peParser.headers.Header;
import dorkbox.peParser.headers.SectionTableEntry;
import dorkbox.peParser.misc.DirEntry;
public class ImageDataDir extends ByteDefinition<UInteger> {

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import dorkbox.util.OS;
import dorkbox.util.bytes.UInteger;
import dorkbox.util.pe.ByteArray;
import dorkbox.peParser.ByteArray;
public class ImageDataDirExtra extends ByteDefinition<UInteger> {

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import dorkbox.peParser.misc.MachineTypeType;
import dorkbox.util.OS;
import dorkbox.util.bytes.UShort;
import dorkbox.util.pe.misc.MachineTypeType;
public class MachineType extends ByteDefinition<MachineTypeType> {

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import dorkbox.util.OS;
import dorkbox.util.bytes.UShort;
import dorkbox.util.pe.misc.MagicNumberType;
import dorkbox.peParser.misc.MagicNumberType;
public class MagicNumber extends ByteDefinition<MagicNumberType> {

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import dorkbox.util.OS;
import dorkbox.util.bytes.UInteger;

View File

@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import dorkbox.peParser.misc.ResourceTypes;
import dorkbox.util.OS;
import dorkbox.util.bytes.UInteger;
import dorkbox.util.pe.ByteArray;
import dorkbox.util.pe.misc.ResourceTypes;
import dorkbox.peParser.ByteArray;
public class ResourceDirName extends ByteDefinition<String> {

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import dorkbox.peParser.headers.flags.SectionCharacteristicsType;
import dorkbox.util.OS;
import dorkbox.util.bytes.UInteger;
import dorkbox.util.pe.headers.flags.SectionCharacteristicsType;
public class SectionCharacteristics extends ByteDefinition<SectionCharacteristicsType[]> {

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import dorkbox.peParser.misc.SubsystemType;
import dorkbox.util.OS;
import dorkbox.util.bytes.UShort;
import dorkbox.util.pe.misc.SubsystemType;
public class Subsystem extends ByteDefinition<SubsystemType> {

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import dorkbox.util.OS;
import dorkbox.util.bytes.UInteger;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import java.util.Date;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.pe.types;
package dorkbox.peParser.types;
import dorkbox.util.OS;
import dorkbox.util.bytes.UShort;