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