Changeset 3993 for trunk/src/kernel32/winimagelx.cpp
- Timestamp:
- Aug 11, 2000, 12:56:27 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/winimagelx.cpp
r3765 r3993 1 /* $Id: winimagelx.cpp,v 1. 8 2000-06-28 18:08:35sandervl Exp $ */1 /* $Id: winimagelx.cpp,v 1.9 2000-08-11 10:56:19 sandervl Exp $ */ 2 2 3 3 /* 4 4 * Win32 LX Image base class 5 5 * 6 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)6 * Copyright 1999-2000 Sander van Leeuwen (sandervl@xs4all.nl) 7 7 * 8 * TODO: headers not complete 9 * 8 10 * Project Odin Software License can be found in LICENSE.TXT 9 11 * … … 40 42 #include "dbglocal.h" 41 43 44 static BYTE dosHeader[] = { 45 0x4D, 0x5A, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x0B, 0x00, 46 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 47 0x6A, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 48 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 49 0xB4, 0x30, 0xCD, 0x21, 0x86, 0xC4, 0x3D, 0x0A, 0x14, 0x72, 0x42, 0xBE, 0x80, 0x00, 0x8A, 0x1C, 50 0x32, 0xFF, 0x46, 0x88, 0x38, 0x2E, 0x8C, 0x1E, 0x6E, 0x00, 0x8E, 0x06, 0x2C, 0x00, 0x33, 0xC0, 51 0x8B, 0xF8, 0xB9, 0x00, 0x80, 0xFC, 0xF2, 0xAE, 0x75, 0x23, 0x49, 0x78, 0x20, 0xAE, 0x75, 0xF6, 52 0x47, 0x47, 0x0E, 0x1F, 0x2E, 0x89, 0x3E, 0x68, 0x00, 0x2E, 0x8C, 0x06, 0x6A, 0x00, 0xBE, 0x5C, 53 0x00, 0xB9, 0x6C, 0x63, 0xBB, 0x25, 0x00, 0xB4, 0x64, 0xCD, 0x21, 0x73, 0x0B, 0xBA, 0x7C, 0x00, 54 0x0E, 0x1F, 0xB4, 0x09, 0xCD, 0x21, 0xB0, 0x01, 0xB4, 0x4C, 0xCD, 0x21, 0x20, 0x00, 0x01, 0x00, 55 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x00, 0x00, 0x00, 56 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x54, 0x68, 0x69, 0x73, 57 0x20, 0x70, 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x20, 0x6D, 0x75, 0x73, 0x74, 0x20, 0x62, 0x65, 58 0x20, 0x72, 0x75, 0x6E, 0x20, 0x75, 0x6E, 0x64, 0x65, 0x72, 0x20, 0x57, 0x69, 0x6E, 0x33, 0x32, 59 0x2E, 0x0D, 0x0A, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 60 }; 61 42 62 //****************************************************************************** 43 63 //****************************************************************************** 44 64 Win32LxImage::Win32LxImage(HINSTANCE hInstance, PVOID pResData) 45 : Win32ImageBase(hInstance) 65 : Win32ImageBase(hInstance), header(0) 46 66 { 47 67 APIRET rc; … … 67 87 Win32LxImage::~Win32LxImage() 68 88 { 89 if(header) { 90 DosFreeMem(header); 91 } 69 92 } 70 93 //****************************************************************************** … … 75 98 ULONG apiaddr; 76 99 77 rc = DosQueryProcAddr(hinstance , 0, name, (PFN *)&apiaddr);100 rc = DosQueryProcAddr(hinstanceOS2, 0, name, (PFN *)&apiaddr); 78 101 if(rc) 79 102 { 80 if(rc == ERROR_INVALID_HANDLE) 81 {//handle invalid for some silly reason, so load module again (initterm entrypoint not called twice) 82 char szErrName[CCHMAXPATH]; 83 84 rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hinstance); 85 if(!rc) 86 rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr); 87 } 88 if(rc) return(0); 103 dprintf(("Win32LxImage::getApi -> rc = %d", rc)); 104 return(0); 89 105 } 90 106 return(apiaddr); … … 97 113 ULONG apiaddr; 98 114 99 rc = DosQueryProcAddr(hinstance , ordinal, NULL, (PFN *)&apiaddr);115 rc = DosQueryProcAddr(hinstanceOS2, ordinal, NULL, (PFN *)&apiaddr); 100 116 if(rc) { 101 if(rc == ERROR_INVALID_HANDLE) 102 {//SvL(?): handle invalid for some silly reason, so load module again (initterm entrypoint not called twice) 103 //KSO: AFAIK you'll have to load the module calling DosLoadModule to use it's handle in API calls. 104 // CPREF->DosGetResource->hmod: ... A value other than zero is a module handle that was returned by DosLoadModule. 105 // You may consider adding a DosLoadModule call during RegisterLxDll or somewhere. 106 char szErrName[CCHMAXPATH]; 107 108 rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hinstance); 109 if(!rc) 110 rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr); 111 } 112 if(rc) return(0); 117 dprintf(("Win32LxImage::getApi -> rc = %d", rc)); 118 return(0); 113 119 } 114 120 return(apiaddr); … … 116 122 //****************************************************************************** 117 123 //****************************************************************************** 124 LPVOID Win32LxImage::buildHeader(DWORD MajorImageVersion, DWORD MinorImageVersion, 125 DWORD Subsystem) 126 { 127 APIRET rc; 128 IMAGE_DOS_HEADER *pdosheader; 129 PIMAGE_OPTIONAL_HEADER poh; 130 PIMAGE_FILE_HEADER pfh; 131 DWORD *ntsig; 118 132 133 rc = DosAllocMem(&header, 4096, PAG_READ | PAG_WRITE | PAG_COMMIT); 134 if(rc) { 135 dprintf(("ERROR: buildHeader DosAllocMem failed!! (rc=%x)", rc)); 136 DebugInt3(); 137 return NULL; 138 } 139 memcpy(header, dosHeader, sizeof(dosHeader)); 140 ntsig = (DWORD *)((LPBYTE)header + sizeof(dosHeader)); 141 *ntsig = IMAGE_NT_SIGNATURE; 142 pfh = (PIMAGE_FILE_HEADER)(ntsig+1); 143 pfh->Machine = IMAGE_FILE_MACHINE_I386; 144 pfh->NumberOfSections = 0; 145 pfh->TimeDateStamp = 0x3794f60f; 146 pfh->PointerToSymbolTable = 0; 147 pfh->NumberOfSymbols = 0; 148 pfh->SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER); 149 pfh->Characteristics = IMAGE_FILE_DLL | IMAGE_FILE_32BIT_MACHINE | 150 IMAGE_FILE_DEBUG_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE | 151 IMAGE_FILE_RELOCS_STRIPPED; 152 poh = (PIMAGE_OPTIONAL_HEADER)(pfh+1); 153 poh->Magic = IMAGE_NT_OPTIONAL_HDR_MAGIC; 154 poh->MajorLinkerVersion = 0x3; 155 poh->MinorLinkerVersion = 0xA; 156 poh->SizeOfCode = 0; 157 poh->SizeOfInitializedData = 0; 158 poh->SizeOfUninitializedData = 0; 159 poh->AddressOfEntryPoint = 0; 160 poh->BaseOfCode = 0; 161 poh->BaseOfData = 0; 162 poh->ImageBase = 0; 163 poh->SectionAlignment = 4096; 164 poh->FileAlignment = 512; 165 poh->MajorOperatingSystemVersion = MajorImageVersion; 166 poh->MinorOperatingSystemVersion = MinorImageVersion; 167 poh->MajorImageVersion = MajorImageVersion; 168 poh->MinorImageVersion = MinorImageVersion; 169 poh->MajorSubsystemVersion = ODINNT_MAJOR_VERSION; 170 poh->MinorSubsystemVersion = ODINNT_MINOR_VERSION; 171 poh->Reserved1 = 0; 172 poh->SizeOfImage = 0; 173 poh->SizeOfHeaders = 1024; 174 poh->CheckSum = 0; 175 poh->Subsystem = Subsystem; 176 poh->DllCharacteristics = 0; 177 poh->SizeOfStackReserve = 1*1024*1024; 178 poh->SizeOfStackCommit = 4096; 179 poh->SizeOfHeapReserve = 1*1024*1024; 180 poh->SizeOfHeapCommit = 4096; 181 poh->LoaderFlags = 0; 182 poh->NumberOfRvaAndSizes = 0; 183 // poh->DataDirectory[0] 184 185 return header; 186 } 187 //****************************************************************************** 188 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.