runtime_loader: Detect and trigger on PE binaries
* Previously PE binaries would trigger the "incorrectly executable" dialog. Now we get a special message for B_LEGACY_EXECUTABLE and B_UNKNOWN_EXECUTABLE * Legacy at the moment is a R3 x86 PE binary. This could be extended to gcc2 binaries someday far, far, down the road though * The check for legacy is based on a PE flag I see set on every R3 binary (that isn't set on dos ones) * Unknown is something we know *is* an executable, but can't do anything with (such as an MSDOS or Windows application) * No performance drops as we do the PE scan last * Tested on x86 and x86_gcc2
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2013-2014, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Alexander von Gluck IV, <[email protected]>
|
||||
*/
|
||||
#ifndef _PE_COMMON_H
|
||||
#define _PE_COMMON_H
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <ByteOrder.h>
|
||||
|
||||
|
||||
// Magic strings
|
||||
#define MZ_MAGIC "MZ"
|
||||
#define PE_MAGIC "PE"
|
||||
#define PE_OPTIONAL_MAGIC_PE32 0x010b
|
||||
#define PE_OPTIONAL_MAGIC_PE32P 0x020b
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint16 magic; /* == MZ_MAGIC */
|
||||
uint16 bytesInLastBlock;
|
||||
uint16 blocksInFile;
|
||||
uint16 numRelocations;
|
||||
uint16 headerParagraphs;
|
||||
uint16 minExtraParagraphs;
|
||||
uint16 maxExtraParagraphs;
|
||||
uint16 ss;
|
||||
uint16 sp;
|
||||
uint16 checksum;
|
||||
uint16 ip;
|
||||
uint16 cs;
|
||||
uint16 relocationTableOffset;
|
||||
uint16 overlayNumber;
|
||||
uint16 reserved[4];
|
||||
uint16 oemID;
|
||||
uint16 oemInfo;
|
||||
uint16 reserved2[10];
|
||||
uint32 lfaNew; // PE Header start addr
|
||||
} MzHeader;
|
||||
|
||||
typedef struct {
|
||||
uint32 magic; // == PE_MAGIC */
|
||||
uint16 machine;
|
||||
uint16 numberOfSections;
|
||||
uint32 timeDateStamp;
|
||||
uint32 pointerToSymbolTable;
|
||||
uint32 numberOfSymbols;
|
||||
uint16 sizeOfOptionalHeader;
|
||||
uint16 characteristics;
|
||||
} PeHeader;
|
||||
|
||||
typedef struct {
|
||||
uint16 magic; // == 0x010b - PE32, 0x020b - PE32+ (64 bit)
|
||||
uint8 majorLinkerVersion;
|
||||
uint8 minorLinkerVersion;
|
||||
uint32 sizeOfCode;
|
||||
uint32 sizeOfInitializedData;
|
||||
uint32 sizeOfUninitializedData;
|
||||
uint32 addressOfEntryPoint;
|
||||
uint32 baseOfCode;
|
||||
uint32 baseOfData;
|
||||
uint32 imageBase;
|
||||
uint32 sectionAlignment;
|
||||
uint32 fileAlignment;
|
||||
uint16 majorOperatingSystemVersion;
|
||||
uint16 minorOperatingSystemVersion;
|
||||
uint16 majorImageVersion;
|
||||
uint16 minorImageVersion;
|
||||
uint16 majorSubsystemVersion;
|
||||
uint16 minorSubsystemVersion;
|
||||
uint32 win32VersionValue;
|
||||
uint32 sizeOfImage;
|
||||
uint32 sizeOfHeaders;
|
||||
uint32 checksum;
|
||||
uint16 subsystem;
|
||||
uint16 llCharacteristics;
|
||||
uint32 sizeOfStackReserve;
|
||||
uint32 sizeOfStackCommit;
|
||||
uint32 sizeOfHeapReserve;
|
||||
uint32 sizeOfHeapCommit;
|
||||
uint32 loaderFlags;
|
||||
uint32 numberOfRvaAndSizes;
|
||||
} Pe32OptionalHeader;
|
||||
|
||||
#endif /* _PE_COMMON_H */
|
||||
Reference in New Issue
Block a user