Adding PE file support
[tpg/acess2.git] / Kernel / bin / pe.h
diff --git a/Kernel/bin/pe.h b/Kernel/bin/pe.h
new file mode 100644 (file)
index 0000000..4e85cf9
--- /dev/null
@@ -0,0 +1,136 @@
+/*\r
+AcessOS/AcessBasic v1\r
+PE Loader\r
+HEADER\r
+*/\r
+#ifndef _EXE_PE_H\r
+#define _EXE_PE_H\r
+\r
+enum ePE_MACHINES {\r
+       PE_MACHINE_I386 = 0x14c,        // Intel 386+\r
+       PE_MACHINE_IA64 = 0x200         // Intel-64\r
+};\r
+\r
+enum ePE_DIR_INDX {\r
+       PE_DIR_EXPORT,          // 0\r
+       PE_DIR_IMPORT,          // 1\r
+       PE_DIR_RESOURCE,        // 2\r
+       PE_DIR_EXCEPTION,       // 3\r
+       PE_DIR_SECRURITY,       // 4\r
+       PE_DIR_RELOC,           // 5\r
+       PE_DIR_DEBUG,           // 6\r
+       PE_DIR_COPYRIGHT,       // 7\r
+       PE_DIR_ARCHITECTURE,// 8\r
+       PE_DIR_GLOBALPTR,       // 9\r
+       PE_DIR_TLS,                     // 10\r
+       PE_DIR_LOAD_CFG,        // 11\r
+       PE_DIR_BOUND_IMPORT,// 12\r
+       PE_DIR_IAT,                     // 13\r
+       PE_DIR_DELAY_IMPORT,// 14\r
+       PE_DIR_COM_DESCRIPTOR,  //15\r
+       PE_DIR_LAST\r
+};\r
+\r
+typedef struct {\r
+       Uint32  RVA;\r
+       Uint32  Size;\r
+} tPE_DATA_DIR;\r
+\r
+typedef struct {\r
+       Uint32  *ImportLookupTable;     //0x80000000 is Ordninal Flag\r
+       Uint32  TimeStamp;\r
+       Uint32  FowarderChain;\r
+       char    *DLLName;\r
+       Uint32  *ImportAddressTable;    // Array of Addresses - To be edited by loader\r
+} tPE_IMPORT_DIR;\r
+\r
+typedef struct {\r
+       Uint16  Hint;\r
+       char    Name[]; // Zero Term String\r
+} tPE_HINT_NAME;\r
+\r
+typedef struct {\r
+       char    Name[8];\r
+       Uint32  VirtualSize;\r
+       Uint32  RVA;\r
+       Uint32  RawSize;\r
+       Uint32  RawOffs;\r
+       Uint32  RelocationsPtr; //Set to 0 in executables\r
+       Uint32  LineNumberPtr;  //Pointer to Line Numbers\r
+       Uint16  RelocationCount;        // Set to 0 in executables\r
+       Uint16  LineNumberCount;\r
+       Uint32  Flags;\r
+} tPE_SECTION_HEADER;\r
+\r
+#define PE_SECTION_FLAG_CODE   0x00000020      // Section contains executable code.\r
+#define PE_SECTION_FLAG_IDATA  0x00000040      // Section contains initialized data.\r
+#define PE_SECTION_FLAG_UDATA  0x00000080      // Section contains uninitialized data.\r
+#define PE_SECTION_FLAG_DISCARDABLE    0x02000000      // Section can be discarded as needed.\r
+#define PE_SECTION_FLAG_MEM_NOT_CACHED 0x04000000      // Section cannot be cached.\r
+#define PE_SECTION_FLAG_MEM_NOT_PAGED  0x08000000      // Section is not pageable.\r
+#define PE_SECTION_FLAG_MEM_SHARED     0x10000000      // Section can be shared in memory.\r
+#define PE_SECTION_FLAG_MEM_EXECUTE    0x20000000      // Section can be executed as code.\r
+#define PE_SECTION_FLAG_MEM_READ       0x40000000      // Section can be read.\r
+#define PE_SECTION_FLAG_MEM_WRITE      0x80000000      // Section can be written to.\r
+\r
+typedef struct {\r
+       Uint32  page;\r
+       Uint32  size;\r
+       Uint16  ents[];\r
+} tPE_FIXUP_BLOCK;\r
+\r
+//File Header\r
+typedef struct {\r
+       Uint16  Machine;\r
+       Uint16  SectionCount;\r
+       Uint32  CreationTimestamp;\r
+       Uint32  SymbolTableOffs;\r
+       Uint32  SymbolCount;\r
+       Uint16  OptHeaderSize;\r
+       Uint16  Flags;\r
+} tPE_FILE_HEADER;\r
+\r
+typedef struct {\r
+       Uint16  Magic;  //0x10b: 32Bit, 0x20b: 64Bit\r
+       Uint16  LinkerVersion;\r
+       Uint32  CodeSize;       //Sum of all Code Segment Sizes\r
+       Uint32  DataSize;       //Sum of all Intialised Data Segments\r
+       Uint32  BssSize;        //Sum of all Unintialised Data Segments\r
+       Uint32  EntryPoint;\r
+       Uint32  CodeRVA;\r
+       Uint32  DataRVA;\r
+       Uint32  ImageBase;      //Prefered Base Address\r
+       Uint32  SectionAlignment;\r
+       Uint32  FileAlignment;\r
+       Uint32  WindowsVersion; //Unused/Irrelevent\r
+       Uint32  ImageVersion;   //Unused/Irrelevent\r
+       Uint32  SubsystemVersion;       //Unused, Set to 4\r
+       Uint32  Win32Version;   //Unused\r
+       Uint32  ImageSize;\r
+       Uint32  HeaderSize;\r
+       Uint32  Checksum;       //Unknown Method, Can be set to 0\r
+       Uint16  Subsystem;      //Required Windows Subsystem (None, GUI, Console)\r
+       Uint16  DllFlags;\r
+       Uint32  MaxStackSize;           //Reserved Stack Size\r
+       Uint32  InitialStackSize;       //Commited Stack Size\r
+       Uint32  InitialReservedHeap;    // Reserved Heap Size\r
+       Uint32  InitialCommitedHeap;    // Commited Heap Size\r
+       Uint32  LoaderFlags;    // Obselete\r
+       Uint32  NumberOfDirEntries;\r
+       tPE_DATA_DIR    Directory[16];\r
+} tPE_OPT_HEADER;\r
+\r
+// Root Header\r
+typedef struct {\r
+       Uint32  Signature;\r
+       tPE_FILE_HEADER FileHeader;\r
+       tPE_OPT_HEADER  OptHeader;\r
+} tPE_IMAGE_HEADERS;\r
+\r
+typedef struct {\r
+       Uint16  Ident;\r
+       Uint16  Resvd[29];\r
+       Uint32  PeHdrOffs;              // File address of new exe header\r
+} tPE_DOS_HEADER;\r
+\r
+#endif\r

UCC git Repository :: git.ucc.asn.au