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

Last change on this file since 8766 was 7797, checked in by sandervl, 24 years ago

added dummy exe class

File size: 5.5 KB
Line 
1/* $Id: winexedummy.cpp,v 1.1 2002-02-03 13:16:22 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
28//******************************************************************************
29//Create Dummy Exe object
30//******************************************************************************
31BOOL WIN32API RegisterDummyExe(LPSTR pszExeName)
32{
33 if(WinExe != NULL) //should never happen
34 delete(WinExe);
35
36 Win32DummyExe *winexe;
37
38 winexe = new Win32DummyExe(pszExeName);
39
40 if(winexe) {
41 InitCommandLine(FALSE);
42 winexe->start();
43 }
44 else {
45 eprintf(("Win32DummyExe creation failed!\n"));
46 DebugInt3();
47 return FALSE;
48 }
49 return TRUE;
50}
51//******************************************************************************
52//******************************************************************************
53Win32DummyExe::Win32DummyExe(LPSTR pszExeName)
54 : Win32ImageBase(-1),
55 Win32ExeBase(-1), header(0)
56{
57 dprintf(("Win32DummyExe ctor: %s", pszExeName));
58 hinstance = (HINSTANCE)buildHeader(1, 0, IMAGE_SUBSYSTEM_WINDOWS_GUI);
59 strcpy(szModule, pszExeName);
60 strcpy(szFileName, pszExeName);
61 setFullPath(pszExeName);
62}
63//******************************************************************************
64//******************************************************************************
65Win32DummyExe::~Win32DummyExe()
66{
67 if(header) {
68 DosFreeMem(header);
69 }
70}
71//******************************************************************************
72//******************************************************************************
73ULONG Win32DummyExe::start()
74{
75 return 0;
76}
77//******************************************************************************
78//******************************************************************************
79ULONG Win32DummyExe::getApi(char *name)
80{
81 return 0;
82}
83//******************************************************************************
84//******************************************************************************
85ULONG Win32DummyExe::getApi(int ordinal)
86{
87 return 0;
88}
89//******************************************************************************
90//******************************************************************************
91LPVOID Win32DummyExe::buildHeader(DWORD MajorImageVersion, DWORD MinorImageVersion,
92 DWORD Subsystem)
93{
94 APIRET rc;
95 IMAGE_DOS_HEADER *pdosheader;
96 PIMAGE_OPTIONAL_HEADER poh;
97 PIMAGE_FILE_HEADER pfh;
98 DWORD *ntsig;
99
100 rc = DosAllocMem(&header, 4096, PAG_READ | PAG_WRITE | PAG_COMMIT);
101 if(rc) {
102 dprintf(("ERROR: buildHeader DosAllocMem failed!! (rc=%x)", rc));
103 DebugInt3();
104 return NULL;
105 }
106 memcpy(header, dosHeader, sizeof(dosHeader));
107 ntsig = (DWORD *)((LPBYTE)header + sizeof(dosHeader));
108 *ntsig = IMAGE_NT_SIGNATURE;
109 pfh = (PIMAGE_FILE_HEADER)(ntsig+1);
110 pfh->Machine = IMAGE_FILE_MACHINE_I386;
111 pfh->NumberOfSections = 0;
112 pfh->TimeDateStamp = 0x3794f60f;
113 pfh->PointerToSymbolTable = 0;
114 pfh->NumberOfSymbols = 0;
115 pfh->SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER);
116 pfh->Characteristics = IMAGE_FILE_DLL | IMAGE_FILE_32BIT_MACHINE |
117 IMAGE_FILE_DEBUG_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE |
118 IMAGE_FILE_RELOCS_STRIPPED;
119 poh = (PIMAGE_OPTIONAL_HEADER)(pfh+1);
120 poh->Magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
121 poh->MajorLinkerVersion = 0x3;
122 poh->MinorLinkerVersion = 0xA;
123 poh->SizeOfCode = 0;
124 poh->SizeOfInitializedData = 0;
125 poh->SizeOfUninitializedData = 0;
126 poh->AddressOfEntryPoint = 0;
127 poh->BaseOfCode = 0;
128 poh->BaseOfData = 0;
129 poh->ImageBase = 0;
130 poh->SectionAlignment = 4096;
131 poh->FileAlignment = 512;
132 poh->MajorOperatingSystemVersion = MajorImageVersion;
133 poh->MinorOperatingSystemVersion = MinorImageVersion;
134 poh->MajorImageVersion = MajorImageVersion;
135 poh->MinorImageVersion = MinorImageVersion;
136 poh->MajorSubsystemVersion = ODINNT_MAJOR_VERSION;
137 poh->MinorSubsystemVersion = ODINNT_MINOR_VERSION;
138 poh->Reserved1 = 0;
139 poh->SizeOfImage = 0;
140 poh->SizeOfHeaders = 1024;
141 poh->CheckSum = 0;
142 poh->Subsystem = Subsystem;
143 poh->DllCharacteristics = 0;
144 poh->SizeOfStackReserve = 1*1024*1024;
145 poh->SizeOfStackCommit = 4096;
146 poh->SizeOfHeapReserve = 1*1024*1024;
147 poh->SizeOfHeapCommit = 4096;
148 poh->LoaderFlags = 0;
149 poh->NumberOfRvaAndSizes = 0;
150// poh->DataDirectory[0]
151
152 return header;
153}
154//******************************************************************************
155//******************************************************************************
Note: See TracBrowser for help on using the repository browser.