- Timestamp:
- Oct 23, 1999, 2:34:48 PM (26 years ago)
- Location:
- trunk/src/kernel32
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/directory.cpp
r1370 r1410 1 /* $Id: directory.cpp,v 1. 6 1999-10-20 08:09:04sandervl Exp $ */1 /* $Id: directory.cpp,v 1.7 1999-10-23 12:34:46 sandervl Exp $ */ 2 2 3 3 /* … … 23 23 #include <heapstring.h> 24 24 #include <options.h> 25 25 #include "initterm.h" 26 26 27 27 ODINDEBUGCHANNEL(KERNEL32-DIRECTORY) … … 175 175 { 176 176 LPSTR lpstrEnv = getenv("WIN32.DIR.SYSTEM"); /* query environment */ 177 178 if (lpstrEnv != NULL) 179 { 180 lstrcpynA(lpBuffer, /* copy environment variable to buffer */ 181 lpstrEnv, 182 uSize); 183 return (lstrlenA(lpBuffer)); /* return number of copies bytes */ 184 } 185 else 186 { 187 int len; 188 189 len = PROFILE_GetOdinIniString(ODINDIRECTORIES,"SYSTEM","",lpBuffer,uSize); 190 if (len > 2) { 191 return len; 192 } 193 else {//SvL: Use path of kernel32.dll instead of calling Open32 api (which returns \OS2\SYSTEM) 194 lstrcpynA(lpBuffer, kernel32Path, uSize); 195 return lstrlenA(lpBuffer); 196 } 197 } 198 } 199 200 201 /***************************************************************************** 202 * Name : GetSystemDirectoryW 203 * Purpose : 204 * Parameters: 205 * Variables : 206 * Result : 207 * Remark : 208 * Status : 209 * 210 * Author : Patrick Haller [Wed, 1999/09/28 20:44] 211 *****************************************************************************/ 212 213 ODINFUNCTION2(UINT,GetSystemDirectoryW,LPWSTR,lpBuffer, 214 UINT, uSize) 215 { 216 char *asciibuffer = (char *)malloc(uSize+1); 217 UINT rc; 218 219 rc = GetSystemDirectoryA(asciibuffer, uSize); 220 if(rc) AsciiToUnicode(asciibuffer, lpBuffer); 221 free(asciibuffer); 222 return(rc); 223 } 224 225 226 /***************************************************************************** 227 * Name : GetWindowsDirectoryA 228 * Purpose : 229 * Parameters: 230 * Variables : 231 * Result : 232 * Remark : 233 * Status : 234 * 235 * Author : Patrick Haller [Wed, 1999/09/28 20:44] 236 *****************************************************************************/ 237 238 ODINFUNCTION2(UINT,GetWindowsDirectoryA,LPSTR,lpBuffer, 239 UINT,uSize) 240 { 241 LPSTR lpstrEnv = getenv("WIN32.DIR.WINDOWS"); /* query environment */ 177 242 178 243 if (lpstrEnv != NULL) … … 186 251 int len; 187 252 188 len = PROFILE_GetOdinIniString(ODINDIRECTORIES,"SYSTEM","",lpBuffer,uSize);189 if (len > 2) return len;190 else191 /* if no override by environment is available */192 return O32_GetSystemDirectory(lpBuffer,uSize);193 }194 }195 196 197 /*****************************************************************************198 * Name : GetSystemDirectoryW199 * Purpose :200 * Parameters:201 * Variables :202 * Result :203 * Remark :204 * Status :205 *206 * Author : Patrick Haller [Wed, 1999/09/28 20:44]207 *****************************************************************************/208 209 ODINFUNCTION2(UINT,GetSystemDirectoryW,LPWSTR,lpBuffer,210 UINT, uSize)211 {212 char *asciibuffer = (char *)malloc(uSize+1);213 UINT rc;214 215 rc = GetSystemDirectoryA(asciibuffer, uSize);216 if(rc) AsciiToUnicode(asciibuffer, lpBuffer);217 free(asciibuffer);218 return(rc);219 }220 221 222 /*****************************************************************************223 * Name : GetWindowsDirectoryA224 * Purpose :225 * Parameters:226 * Variables :227 * Result :228 * Remark :229 * Status :230 *231 * Author : Patrick Haller [Wed, 1999/09/28 20:44]232 *****************************************************************************/233 234 ODINFUNCTION2(UINT,GetWindowsDirectoryA,LPSTR,lpBuffer,235 UINT,uSize)236 {237 LPSTR lpstrEnv = getenv("WIN32.DIR.WINDOWS"); /* query environment */238 239 if (lpstrEnv != NULL)240 {241 lstrcpynA(lpBuffer, /* copy environment variable to buffer */242 lpstrEnv,243 uSize);244 return (lstrlenA(lpBuffer)); /* return number of copies bytes */245 } else246 {247 int len;248 249 253 len = PROFILE_GetOdinIniString(ODINDIRECTORIES,"WINDOWS","",lpBuffer,uSize); 250 254 if (len > 2) return len; -
trunk/src/kernel32/initterm.cpp
r1370 r1410 1 /* $Id: initterm.cpp,v 1.1 5 1999-10-20 08:09:04sandervl Exp $ */1 /* $Id: initterm.cpp,v 1.16 1999-10-23 12:34:46 sandervl Exp $ */ 2 2 3 3 /* … … 39 39 #include <win32type.h> 40 40 #include <odinlx.h> 41 #include "oslibmisc.h" 41 42 42 43 /*-------------------------------------------------------------------*/ … … 63 64 ULONG flAllocMem = 0; 64 65 int loadNr = 0; 66 char kernel32Path[CCHMAXPATH] = ""; 65 67 66 68 /****************************************************************************/ … … 88 90 { 89 91 case 0 : 92 { 90 93 loadNr = globLoadNr++; 91 94 95 strcpy(kernel32Path, OSLibGetDllName(hModule)); 96 char *endofpath = strrchr(kernel32Path, '\\'); 97 *(endofpath+1) = 0; 92 98 dprintf(("kernel32 init\n")); 93 99 _ctordtorInit(); … … 120 126 PROFILE_LoadOdinIni(); 121 127 break; 128 } 122 129 case 1 : 123 130 UnregisterLxDll(hModule); -
trunk/src/kernel32/initterm.h
r646 r1410 1 /* $Id: initterm.h,v 1. 1 1999-08-23 13:55:08sandervl Exp $ */1 /* $Id: initterm.h,v 1.2 1999-10-23 12:34:47 sandervl Exp $ */ 2 2 /* 3 3 * KERNEL32 DLL entry point header … … 31 31 /* flag to optimize DosAllocMem to use all the memory on SMP machines */ 32 32 extern ULONG flAllocMem; 33 extern char kernel32Path[]; 33 34 34 35 #endif -
trunk/src/kernel32/makefile
r1280 r1410 1 # $Id: makefile,v 1.4 4 1999-10-14 09:21:42sandervl Exp $1 # $Id: makefile,v 1.45 1999-10-23 12:34:47 sandervl Exp $ 2 2 3 3 # … … 33 33 winexepe2lx.obj winexelx.obj winexepeldr.obj WINRES.OBJ \ 34 34 pefile.OBJ winimgres.OBJ wintls.obj async.OBJ fileio.obj \ 35 atom.obj disk.obj directory.obj cvtbitmap.obj hmmmap.obj \35 atom.obj disk.obj directory.obj cvtbitmap.obj hmmmap.obj winfakepeldr.obj \ 36 36 cvtmenu.obj cvtaccel.obj cvticon.obj cvticongrp.obj oslibexcept.obj \ 37 37 cvtcursor.obj cvtcursorgrp.obj stubs.obj interlock.obj toolhelp.obj … … 93 93 94 94 directory.obj: directory.cpp \ 95 $(PDWIN32_INCLUDE)\unicode.h 95 $(PDWIN32_INCLUDE)\unicode.h \ 96 initterm.h 96 97 97 98 disk.obj: disk.cpp \ … … 174 175 $(PDWIN32_INCLUDE)\windllpeldr.h \ 175 176 $(PDWIN32_INCLUDE)\winimagebase.h \ 177 $(PDWIN32_INCLUDE)\winfakepeldr.h \ 176 178 $(PDWIN32_INCLUDE)\versionos2.h \ 177 179 $(PDWIN32_INCLUDE)\wprocess.h \ … … 342 344 $(PDWIN32_INCLUDE)\winimagelx.h $(PDWIN32_INCLUDE)\odinlx.h $(PDWIN32_INCLUDE)\winimagebase.h $(PDWIN32_INCLUDE)\winimagelx.h 343 345 winexepeldr.obj: winexepeldr.cpp $(PDWIN32_INCLUDE)\winexebase.h $(PDWIN32_INCLUDE)\winexepeldr.h $(PDWIN32_INCLUDE)\winimagepeldr.h $(PDWIN32_INCLUDE)\winimagebase.h 346 winfakepeldr.obj: winfakepeldr.cpp $(PDWIN32_INCLUDE)\winimagepeldr.h $(PDWIN32_INCLUDE)\winimagebase.h $(PDWIN32_INCLUDE)\winfakepeldr.h 344 347 345 348 winimgres.OBJ: winimgres.cpp $(PDWIN32_INCLUDE)\winimagebase.h $(PDWIN32_INCLUDE)\pefile.h $(PDWIN32_INCLUDE)\winimagepe2lx.h $(PDWIN32_INCLUDE)\winimagepeldr.h $(PDWIN32_INCLUDE)\winimagelx.h $(PDWIN32_INCLUDE)\winres.h -
trunk/src/kernel32/misc.cpp
r922 r1410 1 /* $Id: misc.cpp,v 1.1 1 1999-09-13 14:57:07 phallerExp $ */1 /* $Id: misc.cpp,v 1.12 1999-10-23 12:34:47 sandervl Exp $ */ 2 2 3 3 /* … … 257 257 sprintf(logname, "odin32_%d.log", loadNr); 258 258 flog = fopen(logname, "w"); 259 if(flog == NULL) {//probably running exe on readonly device 260 sprintf(logname, "%sodin32_%d.log", kernel32Path, loadNr); 261 flog = fopen(logname, "w"); 262 } 259 263 } 260 264 else -
trunk/src/kernel32/winimagepeldr.cpp
r1284 r1410 1 /* $Id: winimagepeldr.cpp,v 1. 7 1999-10-14 09:57:35sandervl Exp $ */1 /* $Id: winimagepeldr.cpp,v 1.8 1999-10-23 12:34:48 sandervl Exp $ */ 2 2 3 3 /* … … 8 8 * 9 9 * Project Odin Software License can be found in LICENSE.TXT 10 * 11 * 12 * NOTE: RSRC_LOAD is a special flag to only load the resource directory 13 * of a PE image. Processing imports, sections etc is not done. 14 * Nor is it put into the linked list of dlls (if it's a dll). 15 * This is useful for GetVersionSize/Resource in case it wants to 16 * get version info of an image that is not loaded. 17 * So an instance of this type can't be used for anything but resource lookup! 10 18 * 11 19 */ … … 59 67 //****************************************************************************** 60 68 //****************************************************************************** 61 Win32PeLdrImage::Win32PeLdrImage(char *szFileName ) :69 Win32PeLdrImage::Win32PeLdrImage(char *szFileName, int loadtype) : 62 70 Win32ImageBase(-1), 63 71 nrsections(0), imageSize(0), 64 72 imageVirtBase(-1), realBaseAddress(0), imageVirtEnd(0), 65 73 nrNameExports(0), nrOrdExports(0), nameexports(NULL), ordexports(NULL), 66 pResSection(NULL) 67 { 74 pResSection(NULL), fImgMapping(0) 75 { 76 loadType = loadtype; 77 68 78 strcpy(this->szFileName, szFileName); 69 79 … … 83 93 sprintf(logname, "pe_%d.log", loadNr); 84 94 fout.open(logname, ios::out | ios::trunc); 95 if(fout.good() == FALSE) { 96 sprintf(logname, "%spe_%d.log", kernel32Path, loadNr); 97 fout.open(logname, ios::out | ios::trunc); 98 } 85 99 dprintf(("PE LOGFILE for %s: %s", szModule, logname)); 86 100 foutInit = TRUE; … … 99 113 if(ordexports) 100 114 free(ordexports); 115 116 //SvL: Only happens for images that aren't really loaded (RSRC_LOAD) 117 if(fImgMapping) CloseHandle(fImgMapping); 118 fImgMapping = 0; 101 119 } 102 120 //****************************************************************************** … … 104 122 BOOL Win32PeLdrImage::init(ULONG reservedMem) 105 123 { 106 HANDLE fImgMapping = 0;107 124 char szErrorMsg[64]; 108 125 LPVOID win32file = NULL; … … 172 189 nSections = NR_SECTIONS(win32file); 173 190 174 if ((psh = (PIMAGE_SECTION_HEADER)SECTIONHDROFF (win32file)) != NULL) { 191 if(loadType == REAL_LOAD) 192 { 193 if ((psh = (PIMAGE_SECTION_HEADER)SECTIONHDROFF (win32file)) != NULL) { 175 194 fout << endl << "*************************PE SECTIONS START**************************" << endl; 176 195 for (i=0; i<nSections; i++) { … … 281 300 goto failure; 282 301 } 283 }284 fout << "*************************PE SECTIONS END **************************" << endl;285 imageSize += imageVirtBase - oh.ImageBase;286 fout << "Total size of Image " << imageSize << endl;287 fout << "imageVirtBase " << imageVirtBase << endl;288 fout << "imageVirtEnd " << imageVirtEnd << endl;289 290 //In case there are any gaps between sections, adjust size291 if(imageSize != imageVirtEnd - oh.ImageBase) {302 } 303 fout << "*************************PE SECTIONS END **************************" << endl; 304 imageSize += imageVirtBase - oh.ImageBase; 305 fout << "Total size of Image " << imageSize << endl; 306 fout << "imageVirtBase " << imageVirtBase << endl; 307 fout << "imageVirtEnd " << imageVirtEnd << endl; 308 309 //In case there are any gaps between sections, adjust size 310 if(imageSize != imageVirtEnd - oh.ImageBase) { 292 311 fout << "imageSize != imageVirtEnd - oh.ImageBase!" << endl; 293 312 imageSize = imageVirtEnd - oh.ImageBase; 294 }295 if(allocSections(reservedMem) == FALSE) {313 } 314 if(allocSections(reservedMem) == FALSE) { 296 315 fout << "Failed to allocate image memory, rc " << errorState << endl; 297 316 goto failure; 298 }299 fout << "OS/2 base address " << realBaseAddress << endl;300 if(storeSections((char *)win32file) == FALSE) {317 } 318 fout << "OS/2 base address " << realBaseAddress << endl; 319 if(storeSections((char *)win32file) == FALSE) { 301 320 fout << "Failed to store sections, rc " << errorState << endl; 302 321 goto failure; 303 }304 if(oh.AddressOfEntryPoint) {322 } 323 if(oh.AddressOfEntryPoint) { 305 324 entryPoint = realBaseAddress + oh.AddressOfEntryPoint; 306 }307 else {308 fout << "EntryPoint == NULL" << endl; 325 } 326 else { 327 fout << "EntryPoint == NULL" << endl; 309 328 entryPoint = NULL; 310 }311 312 if(tlsDir != NULL) {313 Section *sect = findSection(SECTION_TLS);329 } 330 331 if(tlsDir != NULL) { 332 Section *sect = findSection(SECTION_TLS); 314 333 315 334 if(sect == NULL) { … … 334 353 } 335 354 setTLSCallBackAddr((PIMAGE_TLS_CALLBACK *)(sect->realvirtaddr + ((ULONG)tlsDir->AddressOfCallBacks - sect->virtaddr))); 336 }337 338 if(realBaseAddress != oh.ImageBase) {355 } 356 357 if(realBaseAddress != oh.ImageBase) { 339 358 if(setFixups((PIMAGE_BASE_RELOCATION)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_BASERELOC)) == FALSE) { 340 359 fout << "Failed to set fixups" << endl; 341 360 goto failure; 342 361 } 343 }344 if(fh.Characteristics & IMAGE_FILE_DLL) {362 } 363 if(fh.Characteristics & IMAGE_FILE_DLL) { 345 364 if(processExports((char *)win32file) == FALSE) { 346 365 fout << "Failed to process exported apis" << endl; 347 366 goto failure; 348 367 } 349 } 350 351 //SvL: Use pointer to image header as module handle now. Some apps needs this 352 hinstance = (HINSTANCE)realBaseAddress; 368 } 369 370 //SvL: Use pointer to image header as module handle now. Some apps needs this 371 hinstance = (HINSTANCE)realBaseAddress; 372 } 353 373 354 374 //PH: get pResDir pointer correct first, since processImports may … … 361 381 } 362 382 363 if(processImports((char *)win32file) == FALSE) { 383 if (loadType == REAL_LOAD) 384 { 385 if(processImports((char *)win32file) == FALSE) { 364 386 fout << "Failed to process imports!" << endl; 365 goto failure;366 }367 368 //set final memory protection flags (storeSections sets them to read/write)369 if(setMemFlags() == FALSE) {387 goto failure; 388 } 389 390 //set final memory protection flags (storeSections sets them to read/write) 391 if(setMemFlags() == FALSE) { 370 392 fout << "Failed to set memory protection" << endl; 371 393 goto failure; 372 } 373 374 CloseHandle(fImgMapping); 394 } 395 CloseHandle(fImgMapping); 396 fImgMapping = 0; 397 } 375 398 return(TRUE); 376 399 failure: 377 400 if(fImgMapping) CloseHandle(fImgMapping); 401 fImgMapping = 0; 378 402 errorState = ERROR_INTERNAL; 379 403 return FALSE; -
trunk/src/kernel32/wprocess.cpp
r1403 r1410 1 /* $Id: wprocess.cpp,v 1. 39 1999-10-22 18:07:24sandervl Exp $ */1 /* $Id: wprocess.cpp,v 1.40 1999-10-23 12:34:48 sandervl Exp $ */ 2 2 3 3 /* … … 24 24 #include <winexebase.h> 25 25 #include <windllpeldr.h> 26 #include <winfakepeldr.h> 26 27 27 28 #ifdef __IBMCPP__ … … 605 606 if(lpszCommandLine) { 606 607 cmdline = (char *)malloc(strlen(lpszImageName)+strlen(lpszCommandLine) + 16); 607 sprintf(cmdline, " %s %s", lpszImageName, lpszCommandLine);608 sprintf(cmdline, "PE.EXE %s %s", lpszImageName, lpszCommandLine); 608 609 fAllocStr = TRUE; 609 610 } 610 else cmdline = (char *)lpszImageName; 611 else { 612 cmdline = (char *)malloc(strlen(lpszImageName) + 16); 613 sprintf(cmdline, "PE.EXE %s", lpszImageName); 614 fAllocStr = TRUE; 615 } 611 616 } 612 else cmdline = (char *)lpszCommandLine; 613 617 else { 618 cmdline = (char *)malloc(strlen(lpszCommandLine) + 16); 619 sprintf(cmdline, "PE.EXE %s", lpszCommandLine); 620 fAllocStr = TRUE; 621 } 614 622 dprintf(("KERNEL32: CreateProcess %s\n", cmdline)); 615 623 rc = O32_CreateProcess("PE.EXE", (LPCSTR)cmdline, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); 616 624 if(fAllocStr) 617 free(cmdline);625 free(cmdline); 618 626 619 627 dprintf(("KERNEL32: CreateProcess returned %d\n", rc)); … … 674 682 { 675 683 Win32ImageBase *winimage; 684 Win32PeLdrRsrcImg *rsrcimg; 676 685 677 686 dprintf(("GetVersionStruct")); … … 681 690 else { 682 691 winimage = (Win32ImageBase *)Win32DllBase::findModule(modname); 683 if(winimage == NULL) { 684 dprintf(("GetVersionStruct can't find Win32Image for %s\n", modname)); 685 return(FALSE); 692 if(winimage == NULL) 693 { 694 if(Win32ImageBase::isPEImage(modname) == FALSE) 695 { 696 HINSTANCE hInstance; 697 698 //must be an LX dll, just load it (app will probably load it anyway) 699 hInstance = LoadLibraryA(modname); 700 if(hInstance == 0) 701 return 0; 702 winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance); 703 if(winimage) { 704 return winimage->getVersionStruct(verstruct, bufLength); 705 } 706 return 0; 707 } 708 //SvL: Try to load it 709 rsrcimg = new Win32PeLdrRsrcImg(modname); 710 if(rsrcimg == NULL) 711 return 0; 712 713 rsrcimg->init(0); 714 if(rsrcimg->getError() != NO_ERROR) 715 { 716 dprintf(("GetVersionStruct can't load %s\n", modname)); 717 delete rsrcimg; 718 return(FALSE); 719 } 720 BOOL rc = rsrcimg->getVersionStruct(verstruct, bufLength); 721 delete rsrcimg; 722 return rc; 686 723 } 687 724 } … … 693 730 { 694 731 Win32ImageBase *winimage; 732 Win32PeLdrRsrcImg *rsrcimg; 695 733 696 734 dprintf(("GetVersionSize of %s\n", modname)); … … 701 739 else { 702 740 winimage = (Win32ImageBase *)Win32DllBase::findModule(modname); 703 if(winimage == NULL) { 704 dprintf(("GetVersionSize can't find Win32Image for %s\n", modname)); 705 return(FALSE); 741 if(winimage == NULL) 742 { 743 if(Win32ImageBase::isPEImage(modname) == FALSE) 744 { 745 HINSTANCE hInstance; 746 747 //must be an LX dll, just load it (app will probably load it anyway) 748 hInstance = LoadLibraryA(modname); 749 if(hInstance == 0) 750 return 0; 751 winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance); 752 if(winimage) { 753 return winimage->getVersionSize(); 754 } 755 return 0; 756 } 757 758 //SvL: Try to load it 759 rsrcimg = new Win32PeLdrRsrcImg(modname); 760 if(rsrcimg == NULL) 761 return 0; 762 763 rsrcimg->init(0); 764 if(rsrcimg->getError() != NO_ERROR) 765 { 766 dprintf(("GetVersionSize can't load %s\n", modname)); 767 delete rsrcimg; 768 return(FALSE); 769 } 770 rsrcimg->init(0); 771 int size = rsrcimg->getVersionSize(); 772 delete rsrcimg; 773 return size; 706 774 } 707 775 }
Note:
See TracChangeset
for help on using the changeset viewer.