source: trunk/src/kernel32/winexedummy.cpp@ 22039

Last change on this file since 22039 was 22039, checked in by dmik, 13 years ago

kernel32: Add RegisterDummyExeEx.

This differs from RegisterDummyExe in that it also allows to specify a
resource tree to simulate the resource section of the real executable.

File size: 6.4 KB
Line 
1/* $Id: winexedummy.cpp,v 1.6 2004-01-15 10:39:09 sandervl Exp $ */
2
3/*
4 * Win32 Dummy Exe class
5 *
6 * Copyright 2001 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12#define INCL_DOSFILEMGR /* File Manager values */
13#define INCL_DOSERRORS /* DOS Error values */
14#define INCL_DOSPROCESS /* DOS Process values */
15#define INCL_DOSMISC /* DOS Miscellanous values */
16#define INCL_WIN
17#include <os2wrap.h> //Odin32 OS/2 api wrappers
18#include <stdio.h>
19#include <string.h>
20#include <stdlib.h>
21#include <misc.h>
22#include <win32type.h>
23#include "winexedummy.h"
24#include <winconst.h>
25#include <win32api.h>
26#include <wprocess.h>
27#include "initterm.h"
28
29static BOOL fIsDummyExe = FALSE;
30
31//******************************************************************************
32//Create Dummy Exe object
33//******************************************************************************
34BOOL WIN32API RegisterDummyExe(LPSTR pszExeName)
35{
36 return RegisterDummyExeEx (pszExeName, NULL);
37}
38//******************************************************************************
39//******************************************************************************
40BOOL WIN32API RegisterDummyExeEx(LPSTR pszExeName, PVOID pResData)
41{
42 if(WinExe != NULL)
43 return TRUE;
44
45 Win32DummyExe *winexe;
46
47 winexe = new Win32DummyExe(pszExeName, pResData);
48
49 if(winexe) {
50 InitCommandLine(FALSE);
51 winexe->start();
52 fIsDummyExe = TRUE;
53 }
54 else {
55 eprintf(("Win32DummyExe creation failed!\n"));
56 DebugInt3();
57 return FALSE;
58 }
59 return TRUE;
60}
61//******************************************************************************
62//******************************************************************************
63BOOL WIN32API IsDummyExeLoaded()
64{
65 return fIsDummyExe;
66}
67//******************************************************************************
68//******************************************************************************
69Win32DummyExe::Win32DummyExe(LPSTR pszExeName, PVOID pResData)
70 : Win32ImageBase(-1),
71 Win32ExeBase(-1), header(0)
72{
73 dprintf(("Win32DummyExe ctor: %s", pszExeName));
74 hinstance = (HINSTANCE)buildHeader(1, 0, IMAGE_SUBSYSTEM_WINDOWS_GUI);
75 strcpy(szModule, pszExeName);
76 strcpy(szFileName, pszExeName);
77 setFullPath(pszExeName);
78
79 //Pointer to PE resource tree generates by wrc (or NULL for system dlls)
80 pResRootDir = (PIMAGE_RESOURCE_DIRECTORY)pResData;
81}
82//******************************************************************************
83//******************************************************************************
84Win32DummyExe::~Win32DummyExe()
85{
86 if(header) {
87 DosFreeMem(header);
88 }
89}
90//******************************************************************************
91//******************************************************************************
92ULONG Win32DummyExe::start()
93{
94 return 0;
95}
96//******************************************************************************
97//******************************************************************************
98ULONG Win32DummyExe::getApi(char *name)
99{
100 return 0;
101}
102//******************************************************************************
103//******************************************************************************
104ULONG Win32DummyExe::getApi(int ordinal)
105{
106 return 0;
107}
108//******************************************************************************
109//******************************************************************************
110LPVOID Win32DummyExe::buildHeader(DWORD MajorImageVersion, DWORD MinorImageVersion,
111 DWORD Subsystem)
112{
113 APIRET rc;
114 IMAGE_DOS_HEADER *pdosheader;
115 PIMAGE_OPTIONAL_HEADER poh;
116 PIMAGE_FILE_HEADER pfh;
117 DWORD *ntsig;
118
119 // AH TODO: we are wasting 60kb address space here (unless using high memory)!!!
120 rc = DosAllocMem(&header, 4096, PAG_READ | PAG_WRITE | PAG_COMMIT | flAllocMem);
121 if(rc) {
122 dprintf(("ERROR: buildHeader DosAllocMem failed!! (rc=%x)", rc));
123 DebugInt3();
124 return NULL;
125 }
126 memcpy(header, dosHeader, sizeof(dosHeader));
127 ntsig = (DWORD *)((LPBYTE)header + sizeof(dosHeader));
128 *ntsig = IMAGE_NT_SIGNATURE;
129 pfh = (PIMAGE_FILE_HEADER)(ntsig+1);
130 pfh->Machine = IMAGE_FILE_MACHINE_I386;
131 pfh->NumberOfSections = 0;
132 pfh->TimeDateStamp = 0x3794f60f;
133 pfh->PointerToSymbolTable = 0;
134 pfh->NumberOfSymbols = 0;
135 pfh->SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER);
136 pfh->Characteristics = IMAGE_FILE_DLL | IMAGE_FILE_32BIT_MACHINE |
137 IMAGE_FILE_DEBUG_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE |
138 IMAGE_FILE_RELOCS_STRIPPED;
139 poh = (PIMAGE_OPTIONAL_HEADER)(pfh+1);
140 poh->Magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
141 poh->MajorLinkerVersion = 0x3;
142 poh->MinorLinkerVersion = 0xA;
143 poh->SizeOfCode = 0;
144 poh->SizeOfInitializedData = 0;
145 poh->SizeOfUninitializedData = 0;
146 poh->AddressOfEntryPoint = 0;
147 poh->BaseOfCode = 0;
148 poh->BaseOfData = 0;
149 poh->ImageBase = 0;
150 poh->SectionAlignment = 4096;
151 poh->FileAlignment = 512;
152 poh->MajorOperatingSystemVersion = MajorImageVersion;
153 poh->MinorOperatingSystemVersion = MinorImageVersion;
154 poh->MajorImageVersion = MajorImageVersion;
155 poh->MinorImageVersion = MinorImageVersion;
156 poh->MajorSubsystemVersion = ODINNT_MAJOR_VERSION;
157 poh->MinorSubsystemVersion = ODINNT_MINOR_VERSION;
158 poh->Win32VersionValue = 0;
159 poh->SizeOfImage = 0;
160 poh->SizeOfHeaders = 1024;
161 poh->CheckSum = 0;
162 poh->Subsystem = Subsystem;
163 poh->DllCharacteristics = 0;
164 poh->SizeOfStackReserve = 1*1024*1024;
165 poh->SizeOfStackCommit = 4096;
166 poh->SizeOfHeapReserve = 1*1024*1024;
167 poh->SizeOfHeapCommit = 4096;
168 poh->LoaderFlags = 0;
169 poh->NumberOfRvaAndSizes = 0;
170// poh->DataDirectory[0]
171
172 return header;
173}
174//******************************************************************************
175//******************************************************************************
Note: See TracBrowser for help on using the repository browser.