Added image functions

Include pe.h in windows.h to avoid conflicts

svn path=/trunk/; revision=1076
This commit is contained in:
Eric Kohl 2000-03-18 14:02:01 +00:00
parent 1042f1ae27
commit 2c6fae9c20
16 changed files with 223 additions and 78 deletions

View file

@ -1,4 +1,4 @@
/* $Id: rtl.h,v 1.29 2000/03/08 01:52:52 ekohl Exp $
/* $Id: rtl.h,v 1.30 2000/03/18 13:53:26 ekohl Exp $
*
*/
@ -619,6 +619,38 @@ RtlGetProcessHeap (
VOID
);
PVOID
STDCALL
RtlImageDirectoryEntryToData (
PVOID BaseAddress,
BOOLEAN bFlag,
ULONG Directory,
PULONG Size
);
PIMAGE_NT_HEADERS
STDCALL
RtlImageNtHeader (
PVOID BaseAddress
);
PIMAGE_SECTION_HEADER
STDCALL
RtlImageRvaToSection (
PIMAGE_NT_HEADERS NtHeader,
PVOID BaseAddress,
ULONG Rva
);
ULONG
STDCALL
RtlImageRvaToVa (
PIMAGE_NT_HEADERS NtHeader,
PVOID BaseAddress,
ULONG Rva,
PIMAGE_SECTION_HEADER *SectionHeader
);
VOID
STDCALL
RtlInitAnsiString (

View file

@ -17,7 +17,6 @@ VOID LdrInitModuleManagement(VOID);
NTSTATUS LdrProcessDriver(PVOID ModuleLoadBase);
NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
PVOID* LdrStartupAddress);
PIMAGE_NT_HEADERS RtlImageNtHeader(PVOID BaseAddress);
PVOID LdrpGetSystemDllEntryPoint(VOID);
NTSTATUS LdrpMapImage(HANDLE ProcessHandle,
HANDLE SectionHandle,

View file

@ -17,6 +17,13 @@
#define IMAGE_DOS_MAGIC 0x5a4d
#define IMAGE_PE_MAGIC 0x00004550
#define IMAGE_DOS_SIGNATURE 0x5a4d
#define IMAGE_OS2_SIGNATURE 0x454e
#define IMAGE_OS2_SIGNATURE_LE 0x454c
#define IMAGE_VXD_SIGNATURE 0x454c
#define IMAGE_NT_SIGNATURE 0x00004550
typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header
WORD e_magic; // Magic number
WORD e_cblp; // Bytes on last page of file
@ -334,17 +341,17 @@ typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
// an empty name, zero ID, and zero flags.
typedef struct _IMAGE_MENU_HEADER{
WORD wVersion; // Currently zero
WORD cbHeaderSize; // Also zero
WORD wVersion; // Currently zero
WORD cbHeaderSize; // Also zero
} IMAGE_MENU_HEADER, *PIMAGE_MENU_HEADER;
typedef struct _IMAGE_POPUP_MENU_ITEM{
WORD fItemFlags;
WORD fItemFlags;
WCHAR szItemText[1];
} IMAGE_POPUP_MENU_ITEM, *PIMAGE_POPUP_MENU_ITEM;
typedef struct _IMAGE_NORMAL_MENU_ITEM{
WORD fItemFlags;
WORD fItemFlags;
WORD wMenuID;
WCHAR szItemText[1];
} IMAGE_NORMAL_MENU_ITEM, *PIMAGE_NORMAL_MENU_ITEM;
@ -379,7 +386,7 @@ typedef struct _IMAGE_NORMAL_MENU_ITEM{
// entries will be present.
typedef struct _IMAGE_DIALOG_BOX_HEADER1{
DWORD IStyle;
DWORD IStyle;
DWORD IExtendedStyle; // New for Windows NT
WORD nControls; // Number of Controls
WORD x;
@ -396,16 +403,16 @@ typedef struct _IMAGE_DIALOG_BOX_HEADER1{
typedef union _NAME_OR_ORDINAL{ // Name or Ordinal ID
struct _ORD_ID{
WORD flgId;
WORD Id;
WORD Id;
} ORD_ID;
WCHAR szName[1];
WCHAR szName[1];
} NAME_OR_ORDINAL, *PNAME_OR_ORDINAL;
// The data for each control starts on a DWORD boundary (which may require
// some padding from the previous control), and its format is as follows:
typedef struct _IMAGE_CONTROL_DATA{
DWORD IStyle;
DWORD IStyle;
DWORD IExtendedStyle;
WORD x;
WORD y;

View file

@ -4555,37 +4555,7 @@ typedef struct
} LOCALGROUP_INFO_0, *PLOCALGROUP_INFO_0, *LPLOCALGROUP_INFO_0;
/* PE executable header. */
#ifndef WIN32_NO_PEHDR
typedef struct
{
WORD e_magic; /* Magic number, 0x5a4d */
WORD e_cblp; /* Bytes on last page of file, 0x90 */
WORD e_cp; /* Pages in file, 0x3 */
WORD e_crlc; /* Relocations, 0x0 */
WORD e_cparhdr; /* Size of header in paragraphs, 0x4 */
WORD e_minalloc; /* Minimum extra paragraphs needed, 0x0 */
WORD e_maxalloc; /* Maximum extra paragraphs needed, 0xFFFF */
WORD e_ss; /* Initial (relative) SS value, 0x0 */
WORD e_sp; /* Initial SP value, 0xb8 */
WORD e_csum; /* Checksum, 0x0 */
WORD e_ip; /* Initial IP value, 0x0 */
WORD e_cs; /* Initial (relative) CS value, 0x0 */
WORD e_lfarlc; /* File address of relocation table, 0x40 */
WORD e_ovno; /* Overlay number, 0x0 */
WORD e_res[4]; /* Reserved words, all 0x0 */
WORD e_oemid; /* OEM identifier (for e_oeminfo), 0x0 */
WORD e_oeminfo; /* OEM information; e_oemid specific, 0x0 */
WORD e_res2[10]; /* Reserved words, all 0x0 */
LONG e_lfanew; /* File address of new exe header, 0x80 */
/* We leave out the next two fields, since they aren't in the
Windows header file. */
/* DWORD dos_message[16]; * text which always follows dos header */
/* DWORD nt_signature; * required NT signature, 0x4550 */
} IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
#endif /* WIN32_NO_PEHDR */
/* Windows.h now includes pe.h to avoid conflicts! */
#ifdef __cplusplus
}

View file

@ -58,6 +58,9 @@
#include <funcs.h>
#endif
/* WIN32 PE file format */
#include <pe.h>
#endif /* ! defined (RC_INVOKED) */
/* WIN32 error codes */

View file

@ -1,4 +1,4 @@
; $Id: ntdll.def,v 1.46 2000/03/12 01:17:23 ekohl Exp $
; $Id: ntdll.def,v 1.47 2000/03/18 13:58:33 ekohl Exp $
;
; ReactOS Operating System
;
@ -388,13 +388,13 @@ RtlGetProcessHeap@0
;RtlGetUserInfoHeap
;RtlGuidToPropertySetName
RtlIdentifierAuthoritySid@4
;RtlImageDirectoryEntryToData
;RtlImageNtHeader
;RtlImageRvaToSection
;RtlImageRvaToVa
RtlImageDirectoryEntryToData@16
RtlImageNtHeader@4
RtlImageRvaToSection@12
RtlImageRvaToVa@16
;RtlImpersonateSelf
RtlInitAnsiString@8
;RtlInitcodePageTable
;RtlInitCodePageTable
;RtlInitNlsTables
RtlInitString@8
RtlInitUnicodeString@8

View file

@ -1,4 +1,4 @@
; $Id: ntdll.edf,v 1.35 2000/03/12 01:17:23 ekohl Exp $
; $Id: ntdll.edf,v 1.36 2000/03/18 13:58:33 ekohl Exp $
;
; ReactOS Operating System
;
@ -303,6 +303,10 @@ RtlGetLongestNtPathLength=RtlGetLongestNtPathLength@0
RtlGetOwnerSecurityDescriptor=RtlGetOwnerSecurityDescriptor@12
RtlGetProcessHeap=RtlGetProcessHeap@0
RtlIdentifierAuthoritySid=RtlIdentifierAuthoritySid@4
RtlImageDirectoryEntryToData=RtlImageDirectoryEntryToData@16
RtlImageNtHeader=RtlImageNtHeader@4
RtlImageRvaToSection=RtlImageRvaToSection@12
RtlImageRvaToVa=RtlImageRvaToVa@16
RtlInitAnsiString=RtlInitAnsiString@8
RtlInitString=RtlInitString@8
RtlInitUnicodeString=RtlInitUnicodeString@8

View file

@ -1,4 +1,4 @@
/* $Id: startup.c,v 1.20 2000/02/27 02:05:53 ekohl Exp $
/* $Id: startup.c,v 1.21 2000/03/18 13:57:02 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -11,13 +11,8 @@
/* INCLUDES *****************************************************************/
#include <reactos/config.h>
#define WIN32_NO_STATUS
#define WIN32_NO_PEHDR
#include <windows.h>
#include <ddk/ntddk.h>
#include <pe.h>
#include <string.h>
#include <wchar.h>
#include <windows.h>
#include <ntdll/ldr.h>
#include <ntdll/rtl.h>
#include <csrss/csrss.h>
@ -30,6 +25,8 @@
DLL LdrDllListHead;
extern unsigned int _image_base__;
ULONG NtGlobalFlag = 0;
/* FUNCTIONS *****************************************************************/
@ -61,7 +58,9 @@ VOID LdrStartup(VOID)
DPRINT("ImageBase is null\n");
for(;;);
}
NtGlobalFlag = Peb->NtGlobalFlag;
/* If MZ header exists */
PEDosHeader = (PIMAGE_DOS_HEADER) ImageBase;
DPRINT("PEDosHeader %x\n", PEDosHeader);

View file

@ -1,4 +1,4 @@
/* $Id: utils.c,v 1.24 2000/02/13 16:05:16 dwelch Exp $
/* $Id: utils.c,v 1.25 2000/03/18 13:57:02 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -11,11 +11,8 @@
/* INCLUDES *****************************************************************/
#include <reactos/config.h>
#define WIN32_NO_STATUS
#define WIN32_NO_PEHDR
#include <windows.h>
#include <ddk/ntddk.h>
#include <pe.h>
#include <windows.h>
#include <string.h>
#include <internal/string.h>
#include <wchar.h>

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.41 2000/03/12 01:16:41 ekohl Exp $
# $Id: makefile,v 1.42 2000/03/18 13:57:43 ekohl Exp $
#
# ReactOS Operating System
#
@ -30,7 +30,7 @@ DBG_OBJECTS = dbg/brkpoint.o dbg/print.o
RTL_OBJECTS = rtl/critical.o rtl/error.o rtl/heap.o rtl/largeint.o \
rtl/math.o rtl/mem.o rtl/nls.o rtl/process.o rtl/sd.o \
rtl/thread.o rtl/unicode.o rtl/env.o rtl/path.o rtl/ppb.o \
rtl/bitmap.o rtl/time.o rtl/acl.o rtl/sid.o
rtl/bitmap.o rtl/time.o rtl/acl.o rtl/sid.o rtl/image.o
STDIO_OBJECTS = stdio/sprintf.o stdio/swprintf.o

View file

@ -0,0 +1,140 @@
/* $Id: image.c,v 1.1 2000/03/18 13:56:01 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: lib/ntdll/rtl/image.c
* PURPOSE: Image handling functions
* UPDATE HISTORY:
* 17/03/2000 Created by Eric Kohl
*/
#include <ddk/ntddk.h>
#include <ntdll/rtl.h>
/* FUNCTIONS ****************************************************************/
PIMAGE_NT_HEADERS
STDCALL
RtlImageNtHeader (
PVOID BaseAddress
)
{
PIMAGE_NT_HEADERS NtHeader;
PIMAGE_DOS_HEADER DosHeader = (PIMAGE_DOS_HEADER)BaseAddress;
if (DosHeader && DosHeader->e_magic == IMAGE_DOS_SIGNATURE)
{
NtHeader = (PIMAGE_NT_HEADERS)(BaseAddress + DosHeader->e_lfanew);
if (NtHeader->Signature == IMAGE_NT_SIGNATURE)
return NtHeader;
}
return NULL;
}
PVOID
STDCALL
RtlImageDirectoryEntryToData (
PVOID BaseAddress,
BOOLEAN bFlag,
ULONG Directory,
PULONG Size
)
{
PIMAGE_NT_HEADERS NtHeader;
PIMAGE_SECTION_HEADER SectionHeader;
ULONG Va;
ULONG Count;
NtHeader = RtlImageNtHeader (BaseAddress);
if (NtHeader == NULL)
return NULL;
if (Directory >= NtHeader->OptionalHeader.NumberOfRvaAndSizes)
return NULL;
Va = NtHeader->OptionalHeader.DataDirectory[Directory].VirtualAddress;
if (Va == 0)
return NULL;
if (Size)
*Size = NtHeader->OptionalHeader.DataDirectory[Directory].Size;
if (bFlag)
return (PVOID)(BaseAddress + Va);
/* image mapped as ordinary file, we must find raw pointer */
SectionHeader = (PIMAGE_SECTION_HEADER)(NtHeader + 1);
Count = NtHeader->FileHeader.NumberOfSections;
while (Count--)
{
if (SectionHeader->VirtualAddress == Va)
return (PVOID)(BaseAddress + SectionHeader->PointerToRawData);
SectionHeader++;
}
return NULL;
}
PIMAGE_SECTION_HEADER
STDCALL
RtlImageRvaToSection (
PIMAGE_NT_HEADERS NtHeader,
PVOID BaseAddress,
ULONG Rva
)
{
PIMAGE_SECTION_HEADER Section;
ULONG Va;
ULONG Count;
Count = NtHeader->FileHeader.NumberOfSections;
Section = (PIMAGE_SECTION_HEADER)((ULONG)&NtHeader->OptionalHeader +
NtHeader->FileHeader.SizeOfOptionalHeader);
while (Count)
{
Va = Section->VirtualAddress;
if ((Va <= Rva) &&
(Rva < Va + Section->SizeOfRawData))
return Section;
Section++;
}
return NULL;
}
ULONG
STDCALL
RtlImageRvaToVa (
PIMAGE_NT_HEADERS NtHeader,
PVOID BaseAddress,
ULONG Rva,
PIMAGE_SECTION_HEADER *SectionHeader
)
{
PIMAGE_SECTION_HEADER Section = NULL;
if (SectionHeader)
Section = *SectionHeader;
if (Section == NULL ||
Rva < Section->VirtualAddress ||
Rva >= Section->VirtualAddress + Section->SizeOfRawData)
{
Section = RtlImageRvaToSection (NtHeader, BaseAddress, Rva);
if (Section == NULL)
return 0;
if (SectionHeader)
*SectionHeader = Section;
}
return (ULONG)(BaseAddress +
Rva +
Section->PointerToRawData -
Section->VirtualAddress);
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: ppb.c,v 1.4 2000/02/19 19:34:49 ekohl Exp $
/* $Id: ppb.c,v 1.5 2000/03/18 13:56:01 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -11,12 +11,7 @@
/* INCLUDES ****************************************************************/
#define WIN32_NO_PEHDR
#include <ddk/ntddk.h>
#include <wchar.h>
#include <string.h>
#include <pe.h>
#include <internal/i386/segment.h>
#include <ntdll/ldr.h>
#include <internal/teb.h>
#include <ntdll/base.h>

View file

@ -1,4 +1,4 @@
/* $Id: process.c,v 1.16 2000/02/25 23:58:03 ekohl Exp $
/* $Id: process.c,v 1.17 2000/03/18 13:56:01 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -11,11 +11,7 @@
/* INCLUDES ****************************************************************/
#define WIN32_NO_PEHDR
#include <ddk/ntddk.h>
#include <wchar.h>
#include <string.h>
#include <pe.h>
#include <internal/i386/segment.h>
#include <ntdll/ldr.h>
#include <internal/teb.h>

View file

@ -26,7 +26,9 @@
/* FUNCTIONS ****************************************************************/
PIMAGE_NT_HEADERS RtlImageNtHeader(PVOID BaseAddress)
PIMAGE_NT_HEADERS
STDCALL
RtlImageNtHeader(PVOID BaseAddress)
{
PIMAGE_DOS_HEADER DosHeader;
PIMAGE_NT_HEADERS NTHeaders;

View file

@ -1,4 +1,4 @@
; $Id: ntoskrnl.def,v 1.58 2000/03/17 21:02:56 jfilby Exp $
; $Id: ntoskrnl.def,v 1.59 2000/03/18 14:02:01 ekohl Exp $
;
; reactos/ntoskrnl/ntoskrnl.def
;
@ -386,7 +386,7 @@ RtlGetDefaultCodePage@8
;RtlGetElementGenericTable
RtlGetGroupSecurityDescriptor@12
RtlGetOwnerSecurityDescriptor@12
;RtlImageNtHeader
RtlImageNtHeader@4
RtlInitAnsiString@8
;RtlInitCodePageTable
RtlInitString@8

View file

@ -1,4 +1,4 @@
; $Id: ntoskrnl.edf,v 1.45 2000/03/17 21:02:56 jfilby Exp $
; $Id: ntoskrnl.edf,v 1.46 2000/03/18 14:02:01 ekohl Exp $
;
; reactos/ntoskrnl/ntoskrnl.def
;
@ -346,6 +346,7 @@ RtlGetDaclSecurityDescriptor=RtlGetDaclSecurityDescriptor@16
RtlGetDefaultCodePage=RtlGetDefaultCodePage@8
RtlGetGroupSecurityDescriptor=RtlGetGroupSecurityDescriptor@12
RtlGetOwnerSecurityDescriptor=RtlGetOwnerSecurityDescriptor@12
RtlImageNtHeader=RtlImageNtHeader@4
RtlInitAnsiString=RtlInitAnsiString@8
RtlInitString=RtlInitString@8
RtlInitUnicodeString=RtlInitUnicodeString@8