[10397] | 1 | /* $Id: winexedummy.cpp,v 1.6 2004-01-15 10:39:09 sandervl Exp $ */
|
---|
[7797] | 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>
|
---|
[21916] | 23 | #include "winexedummy.h"
|
---|
[7797] | 24 | #include <winconst.h>
|
---|
| 25 | #include <win32api.h>
|
---|
| 26 | #include <wprocess.h>
|
---|
[8877] | 27 | #include "initterm.h"
|
---|
[7797] | 28 |
|
---|
[10386] | 29 | static BOOL fIsDummyExe = FALSE;
|
---|
| 30 |
|
---|
[7797] | 31 | //******************************************************************************
|
---|
| 32 | //Create Dummy Exe object
|
---|
| 33 | //******************************************************************************
|
---|
| 34 | BOOL WIN32API RegisterDummyExe(LPSTR pszExeName)
|
---|
| 35 | {
|
---|
[22039] | 36 | return RegisterDummyExeEx (pszExeName, NULL);
|
---|
| 37 | }
|
---|
| 38 | //******************************************************************************
|
---|
| 39 | //******************************************************************************
|
---|
| 40 | BOOL WIN32API RegisterDummyExeEx(LPSTR pszExeName, PVOID pResData)
|
---|
| 41 | {
|
---|
| 42 | if(WinExe != NULL)
|
---|
[21302] | 43 | return TRUE;
|
---|
[7797] | 44 |
|
---|
[8877] | 45 | Win32DummyExe *winexe;
|
---|
[7797] | 46 |
|
---|
[22039] | 47 | winexe = new Win32DummyExe(pszExeName, pResData);
|
---|
[7797] | 48 |
|
---|
[8877] | 49 | if(winexe) {
|
---|
[7797] | 50 | InitCommandLine(FALSE);
|
---|
[10386] | 51 | winexe->start();
|
---|
| 52 | fIsDummyExe = TRUE;
|
---|
[8877] | 53 | }
|
---|
| 54 | else {
|
---|
[7797] | 55 | eprintf(("Win32DummyExe creation failed!\n"));
|
---|
| 56 | DebugInt3();
|
---|
[8877] | 57 | return FALSE;
|
---|
| 58 | }
|
---|
| 59 | return TRUE;
|
---|
[7797] | 60 | }
|
---|
| 61 | //******************************************************************************
|
---|
| 62 | //******************************************************************************
|
---|
[10386] | 63 | BOOL WIN32API IsDummyExeLoaded()
|
---|
| 64 | {
|
---|
| 65 | return fIsDummyExe;
|
---|
| 66 | }
|
---|
| 67 | //******************************************************************************
|
---|
| 68 | //******************************************************************************
|
---|
[22039] | 69 | Win32DummyExe::Win32DummyExe(LPSTR pszExeName, PVOID pResData)
|
---|
[7797] | 70 | : Win32ImageBase(-1),
|
---|
| 71 | Win32ExeBase(-1), header(0)
|
---|
| 72 | {
|
---|
[8877] | 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);
|
---|
[22039] | 78 |
|
---|
| 79 | //Pointer to PE resource tree generates by wrc (or NULL for system dlls)
|
---|
| 80 | pResRootDir = (PIMAGE_RESOURCE_DIRECTORY)pResData;
|
---|
[7797] | 81 | }
|
---|
| 82 | //******************************************************************************
|
---|
| 83 | //******************************************************************************
|
---|
| 84 | Win32DummyExe::~Win32DummyExe()
|
---|
| 85 | {
|
---|
[8877] | 86 | if(header) {
|
---|
| 87 | DosFreeMem(header);
|
---|
| 88 | }
|
---|
[7797] | 89 | }
|
---|
| 90 | //******************************************************************************
|
---|
| 91 | //******************************************************************************
|
---|
| 92 | ULONG Win32DummyExe::start()
|
---|
| 93 | {
|
---|
| 94 | return 0;
|
---|
| 95 | }
|
---|
| 96 | //******************************************************************************
|
---|
| 97 | //******************************************************************************
|
---|
| 98 | ULONG Win32DummyExe::getApi(char *name)
|
---|
| 99 | {
|
---|
| 100 | return 0;
|
---|
| 101 | }
|
---|
| 102 | //******************************************************************************
|
---|
| 103 | //******************************************************************************
|
---|
| 104 | ULONG Win32DummyExe::getApi(int ordinal)
|
---|
| 105 | {
|
---|
| 106 | return 0;
|
---|
| 107 | }
|
---|
| 108 | //******************************************************************************
|
---|
| 109 | //******************************************************************************
|
---|
| 110 | LPVOID Win32DummyExe::buildHeader(DWORD MajorImageVersion, DWORD MinorImageVersion,
|
---|
| 111 | DWORD Subsystem)
|
---|
| 112 | {
|
---|
[8877] | 113 | APIRET rc;
|
---|
| 114 | IMAGE_DOS_HEADER *pdosheader;
|
---|
| 115 | PIMAGE_OPTIONAL_HEADER poh;
|
---|
| 116 | PIMAGE_FILE_HEADER pfh;
|
---|
| 117 | DWORD *ntsig;
|
---|
[7797] | 118 |
|
---|
[8887] | 119 | // AH TODO: we are wasting 60kb address space here (unless using high memory)!!!
|
---|
[8877] | 120 | rc = DosAllocMem(&header, 4096, PAG_READ | PAG_WRITE | PAG_COMMIT | flAllocMem);
|
---|
| 121 | if(rc) {
|
---|
[8887] | 122 | dprintf(("ERROR: buildHeader DosAllocMem failed!! (rc=%x)", rc));
|
---|
[7797] | 123 | DebugInt3();
|
---|
[8887] | 124 | return NULL;
|
---|
[8877] | 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;
|
---|
[9971] | 158 | poh->Win32VersionValue = 0;
|
---|
[8877] | 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;
|
---|
[7797] | 170 | // poh->DataDirectory[0]
|
---|
| 171 |
|
---|
[8877] | 172 | return header;
|
---|
[7797] | 173 | }
|
---|
| 174 | //******************************************************************************
|
---|
| 175 | //******************************************************************************
|
---|