- Timestamp:
- Aug 18, 1999, 2:24:53 PM (26 years ago)
- Location:
- trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/windll.cpp
r282 r544 1 /* $Id: windll.cpp,v 1. 8 1999-07-07 08:42:48sandervl Exp $ */1 /* $Id: windll.cpp,v 1.9 1999-08-18 12:24:16 sandervl Exp $ */ 2 2 3 3 /* … … 154 154 //****************************************************************************** 155 155 //****************************************************************************** 156 BOOL Win32Dll::init( )156 BOOL Win32Dll::init(ULONG reservedMem) 157 157 { 158 158 char *syspath; … … 177 177 else fclose(dllfile); 178 178 if(isPEImage(szFileName) == TRUE) { 179 fRet = Win32Image::init( );179 fRet = Win32Image::init(0); 180 180 dllEntryPoint = (WIN32DLLENTRY)entryPoint; 181 181 return fRet; -
trunk/src/kernel32/winimage.cpp
r532 r544 1 /* $Id: winimage.cpp,v 1. 9 1999-08-17 17:04:52sandervl Exp $ */1 /* $Id: winimage.cpp,v 1.10 1999-08-18 12:24:16 sandervl Exp $ */ 2 2 3 3 /* 4 4 * Win32 PE Image class 5 5 * 6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)6 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl) 7 7 * Copyright 1998 Knut St. Osmundsen 8 8 * … … 25 25 #include <stdlib.h> 26 26 27 //#include <iostream.h>28 //#include <fstream.h>29 27 #include <assert.h> 30 28 #include "misc.h" … … 136 134 137 135 if(NameTable) 138 DosFreeResource((PVOID)NameTable);136 DosFreeResource((PVOID)NameTable); 139 137 140 138 if(Win32Table) 141 DosFreeResource((PVOID)Win32Table);139 DosFreeResource((PVOID)Win32Table); 142 140 143 141 while(winres) 144 142 { 145 res = winres->next;146 delete(winres);147 winres = res;143 res = winres->next; 144 delete(winres); 145 winres = res; 148 146 } 149 147 if(realBaseAddress) 150 DosFreeMem((PVOID)realBaseAddress);148 DosFreeMem((PVOID)realBaseAddress); 151 149 152 150 if(nameexports) 153 free(nameexports);151 free(nameexports); 154 152 155 153 if(ordexports) 156 free(ordexports);154 free(ordexports); 157 155 if(fullpath) 158 free(fullpath);159 } 160 //****************************************************************************** 161 //****************************************************************************** 162 BOOL Win32Image::init( )156 free(fullpath); 157 } 158 //****************************************************************************** 159 //****************************************************************************** 160 BOOL Win32Image::init(ULONG reservedMem) 163 161 { 164 162 HFILE win32handle; … … 170 168 ULONG filesize, ulRead; 171 169 PIMAGE_SECTION_HEADER psh; 170 IMAGE_TLS_DIRECTORY *tlsDir = NULL; 172 171 int nSections, i; 173 172 … … 185 184 186 185 if (rc != NO_ERROR) { 187 sprintf(szErrorMsg, "Unable to open %32s\n", szFileName);186 sprintf(szErrorMsg, "Unable to open %32s\n", szFileName); 188 187 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 189 errorState = ERROR_INTERNAL;188 errorState = ERROR_INTERNAL; 190 189 return(FALSE); 191 190 } … … 198 197 win32file = malloc(filesize); 199 198 if(win32file == NULL) { 200 fout << "Error allocating memory" << endl;199 fout << "Error allocating memory" << endl; 201 200 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szMemErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 202 DosClose(win32handle); /* Close the file */203 errorState = ERROR_INTERNAL;204 return(FALSE);201 DosClose(win32handle); /* Close the file */ 202 errorState = ERROR_INTERNAL; 203 return(FALSE); 205 204 } 206 205 rc = DosRead(win32handle, win32file, filesize, &ulRead); 207 206 if(rc != NO_ERROR) { 208 fout << "DosRead returned " << rc << endl;207 fout << "DosRead returned " << rc << endl; 209 208 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szFileErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 210 DosClose(win32handle); /* Close the file */211 errorState = ERROR_INTERNAL;212 return(FALSE);209 DosClose(win32handle); /* Close the file */ 210 errorState = ERROR_INTERNAL; 211 return(FALSE); 213 212 } 214 213 215 214 if(GetPEFileHeader (win32file, &fh) == FALSE) { 216 fout << "Not a valid PE file (probably a 16 bits windows exe/dll)!" << endl;215 fout << "Not a valid PE file (probably a 16 bits windows exe/dll)!" << endl; 217 216 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szPEErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 218 DosClose(win32handle); /* Close the file */219 errorState = ERROR_INTERNAL;220 return(FALSE);217 DosClose(win32handle); /* Close the file */ 218 errorState = ERROR_INTERNAL; 219 return(FALSE); 221 220 } 222 221 223 222 if(!(fh.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)) {//not valid 224 fout << "Not a valid PE file!" << endl;223 fout << "Not a valid PE file!" << endl; 225 224 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szPEErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 226 DosClose(win32handle); /* Close the file */227 errorState = ERROR_INTERNAL;228 return(FALSE);225 DosClose(win32handle); /* Close the file */ 226 errorState = ERROR_INTERNAL; 227 return(FALSE); 229 228 } 230 229 if(fh.Machine != IMAGE_FILE_MACHINE_I386) { 231 fout << "You need a REAL CPU to run this code" << endl;230 fout << "You need a REAL CPU to run this code" << endl; 232 231 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szCPUErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 233 DosClose(win32handle); /* Close the file */234 errorState = ERROR_INTERNAL;235 return(FALSE);232 DosClose(win32handle); /* Close the file */ 233 errorState = ERROR_INTERNAL; 234 return(FALSE); 236 235 } 237 236 //IMAGE_FILE_SYSTEM == only drivers (device/file system/video etc)? 238 237 if(fh.Characteristics & IMAGE_FILE_SYSTEM) { 239 fout << "Can't convert system files" << endl;238 fout << "Can't convert system files" << endl; 240 239 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szExeErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE); 241 DosClose(win32handle); /* Close the file */242 errorState = ERROR_INTERNAL;243 return(FALSE);240 DosClose(win32handle); /* Close the file */ 241 errorState = ERROR_INTERNAL; 242 return(FALSE); 244 243 } 245 244 246 245 if(fh.Characteristics & IMAGE_FILE_RELOCS_STRIPPED) { 247 fout << "No fixups, might not run!" << endl;246 fout << "No fixups, might not run!" << endl; 248 247 } 249 248 … … 270 269 fout << endl << "*************************PE SECTIONS START**************************" << endl; 271 270 for (i=0; i<nSections; i++) { 272 fout << "Raw data size: " << psh[i].SizeOfRawData << endl; 273 fout << "Virtual Address: " << psh[i].VirtualAddress << endl; 274 fout << "Virtual Size: " << psh[i].Misc.VirtualSize << endl; 275 fout << "Pointer to raw data: " << psh[i].PointerToRawData << endl; 276 fout.setf(ios::hex, ios::basefield); 277 fout << "Section flags: " << psh[i].Characteristics << endl << endl; 278 fout.setf(ios::dec, ios::basefield); 271 fout << "Raw data size: " << hex(psh[i].SizeOfRawData) << endl; 272 fout << "Virtual Address: " << hex(psh[i].VirtualAddress) << endl; 273 fout << "Virtual Size: " << hex(psh[i].Misc.VirtualSize) << endl; 274 fout << "Pointer to raw data: " << hex(psh[i].PointerToRawData) << endl; 275 fout << "Section flags: " << hex(psh[i].Characteristics) << endl << endl; 279 276 if(strcmp(psh[i].Name, ".reloc") == 0) { 280 277 fout << ".reloc" << endl << endl; … … 298 295 continue; 299 296 } 297 if(strcmp(psh[i].Name, ".tls") == 0) 298 { 299 tlsDir = (IMAGE_TLS_DIRECTORY *)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_TLS); 300 if(tlsDir) { 301 fout << "TLS Directory" << endl; 302 fout << "TLS Address of Index " << hex((ULONG)tlsDir->AddressOfIndex) << endl; 303 fout << "TLS Address of Callbacks " << hex((ULONG)tlsDir->AddressOfCallBacks) << endl; 304 fout << "TLS SizeOfZeroFill " << hex(tlsDir->SizeOfZeroFill) << endl; 305 fout << "TLS Characteristics " << hex(tlsDir->Characteristics) << endl; 306 addSection(SECTION_TLS, (char *)win32file+psh[i].PointerToRawData, 307 psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase, 308 psh[i].Misc.VirtualSize); 309 } 310 continue; 311 } 312 300 313 if(strcmp(psh[i].Name, ".debug") == 0) { 301 314 fout << ".rdebug" << endl << endl; … … 371 384 372 385 if(imageSize != imageVirtEnd - oh.ImageBase) { 373 fout << "imageSize != imageVirtEnd - oh.ImageBase!" << endl;374 imageSize = imageVirtEnd - oh.ImageBase;375 } 376 if(allocSections( ) == FALSE) {377 fout << "Failed to allocate image memory, rc " << errorState << endl;378 return(FALSE);386 fout << "imageSize != imageVirtEnd - oh.ImageBase!" << endl; 387 imageSize = imageVirtEnd - oh.ImageBase; 388 } 389 if(allocSections(reservedMem) == FALSE) { 390 fout << "Failed to allocate image memory, rc " << errorState << endl; 391 return(FALSE); 379 392 } 380 393 fout << "OS/2 base address " << baseAddress << endl; 381 394 if(storeSections() == FALSE) { 382 fout << "Failed to store sections, rc " << errorState << endl;383 return(FALSE);395 fout << "Failed to store sections, rc " << errorState << endl; 396 return(FALSE); 384 397 } 385 398 entryPoint = baseAddress + oh.AddressOfEntryPoint; 386 399 387 if(setFixups((PIMAGE_BASE_RELOCATION)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_BASERELOC)) == FALSE) { 388 fout << "Failed to set fixups" << endl; 389 return(FALSE); 390 } 400 if(tlsDir != NULL) { 401 Section *sect = findSection(SECTION_TLS); 402 403 if(sect == NULL) { 404 fout << "Couldn't find TLS section!!" << endl; 405 return(FALSE); 406 } 407 setTLSAddress((char *)(sect->realvirtaddr + (tlsDir->StartAddressOfRawData - sect->virtaddr))); 408 setTLSInitSize(tlsDir->EndAddressOfRawData - tlsDir->StartAddressOfRawData); 409 setTLSTotalSize(tlsDir->EndAddressOfRawData - tlsDir->StartAddressOfRawData + tlsDir->SizeOfZeroFill); 410 411 sect = findSectionByAddr((ULONG)tlsDir->AddressOfIndex); 412 if(sect == NULL) { 413 fout << "Couldn't find TLS AddressOfIndex section!!" << endl; 414 return(FALSE); 415 } 416 setTLSIndexAddr((LPDWORD)(sect->realvirtaddr + ((ULONG)tlsDir->AddressOfIndex - sect->virtaddr))); 417 418 sect = findSectionByAddr((ULONG)tlsDir->AddressOfCallBacks); 419 if(sect == NULL) { 420 fout << "Couldn't find TLS AddressOfCallBacks section!!" << endl; 421 return(FALSE); 422 } 423 setTLSCallBackAddr((PIMAGE_TLS_CALLBACK *)(sect->realvirtaddr + ((ULONG)tlsDir->AddressOfCallBacks - sect->virtaddr))); 424 } 425 426 if(realBaseAddress != oh.ImageBase) { 427 if(setFixups((PIMAGE_BASE_RELOCATION)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_BASERELOC)) == FALSE) { 428 fout << "Failed to set fixups" << endl; 429 return(FALSE); 430 } 431 } 432 391 433 if(processImports((char *)win32file) == FALSE) { 392 fout << "Failed to process imports!" << endl;393 return(FALSE);434 fout << "Failed to process imports!" << endl; 435 return(FALSE); 394 436 } 395 437 396 438 if(fh.Characteristics & IMAGE_FILE_DLL) { 397 if(processExports((char *)win32file) == FALSE) {398 fout << "Failed to process exported apis" << endl;399 return(FALSE);400 }439 if(processExports((char *)win32file) == FALSE) { 440 fout << "Failed to process exported apis" << endl; 441 return(FALSE); 442 } 401 443 } 402 444 IMAGE_SECTION_HEADER sh; 403 445 if(GetSectionHdrByName (win32file, &sh, ".rsrc")) { 404 //get offset in resource object of directory entry405 pResDir = (PIMAGE_RESOURCE_DIRECTORY)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_RESOURCE);446 //get offset in resource object of directory entry 447 pResDir = (PIMAGE_RESOURCE_DIRECTORY)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_RESOURCE); 406 448 } 407 449 //set final memory protection flags (storeSections sets them to read/write) 408 450 if(setMemFlags() == FALSE) { 409 fout << "Failed to set memory protection" << endl;410 return(FALSE);451 fout << "Failed to set memory protection" << endl; 452 return(FALSE); 411 453 } 412 454 … … 428 470 429 471 if(type == SECTION_RESOURCE) { 430 pResSection = §ion[nrsections];472 pResSection = §ion[nrsections]; 431 473 } 432 474 virtsize = ((virtsize - 1) & ~0xFFF) + PAGE_SIZE; … … 435 477 436 478 if(virtaddress < imageVirtBase) 437 imageVirtBase = virtaddress;479 imageVirtBase = virtaddress; 438 480 if(virtaddress + virtsize > imageVirtEnd) 439 imageVirtEnd = virtaddress + virtsize;481 imageVirtEnd = virtaddress + virtsize; 440 482 441 483 nrsections++; … … 443 485 //****************************************************************************** 444 486 //****************************************************************************** 445 BOOL Win32Image::allocSections( )487 BOOL Win32Image::allocSections(ULONG reservedMem) 446 488 { 447 489 APIRET rc; 448 490 449 491 if(fh.Characteristics & IMAGE_FILE_RELOCS_STRIPPED) { 450 fout << "No fixups, might not run!" << endl;451 return allocFixedMem();492 fout << "No fixups, might not run!" << endl; 493 return allocFixedMem(reservedMem); 452 494 } 453 495 rc = DosAllocMem((PPVOID)&baseAddress, imageSize, PAG_READ); 454 496 if(rc) { 455 errorState = rc;456 return(FALSE);497 errorState = rc; 498 return(FALSE); 457 499 } 458 500 realBaseAddress = baseAddress; … … 460 502 } 461 503 //****************************************************************************** 504 //****************************************************************************** 505 Section *Win32Image::findSection(ULONG type) 506 { 507 for(int i=0;i<nrsections;i++) { 508 if(section[i].type == type) { 509 return §ion[i]; 510 } 511 } 512 return NULL; 513 } 514 //****************************************************************************** 515 //****************************************************************************** 516 Section *Win32Image::findSectionByAddr(ULONG addr) 517 { 518 for(int i=0;i<nrsections;i++) { 519 if(section[i].virtaddr <= addr && section[i].virtaddr + section[i].virtualsize > addr) { 520 return §ion[i]; 521 } 522 } 523 return NULL; 524 } 525 //****************************************************************************** 462 526 #define FALLOC_SIZE (1024*1024) 463 527 //****************************************************************************** 464 BOOL Win32Image::allocFixedMem( )528 BOOL Win32Image::allocFixedMem(ULONG reservedMem) 465 529 { 466 530 ULONG address = 0; … … 471 535 472 536 baseAddress = realBaseAddress = 0; 537 538 if(reservedMem && reservedMem <= oh.ImageBase && 539 ((oh.ImageBase - reservedMem) + imageSize < PELDR_RESERVEDMEMSIZE)) 540 { 541 //ok, it fits perfectly 542 realBaseAddress = oh.ImageBase; 543 baseAddress = oh.ImageBase; 544 return TRUE; 545 } 473 546 474 547 while(TRUE) { 475 rc = DosAllocMem((PPVOID)&address, FALLOC_SIZE, PAG_READ);476 if(rc) break;477 478 if(firstaddress == 0)479 firstaddress = address;480 481 fout << "DosAllocMem returned " << address << endl;482 if(address + FALLOC_SIZE >= oh.ImageBase) {483 if(address > oh.ImageBase) {//we've passed it!484 DosFreeMem((PVOID)address);485 return(FALSE);486 }487 //found the right address488 DosFreeMem((PVOID)address);489 //align at 64 kb boundary490 realBaseAddress = oh.ImageBase & 0xFFFF0000;491 diff = realBaseAddress - address;492 if(diff) {493 rc = DosAllocMem((PPVOID)&address, diff, PAG_READ);494 if(rc) break;495 }496 rc = DosAllocMem((PPVOID)&baseAddress, imageSize, PAG_READ);497 if(rc) break;498 499 if(baseAddress != realBaseAddress) {500 fout << "baseAddress != realBaseAddress!!" << endl;501 break;502 }503 if(diff) DosFreeMem((PVOID)address);504 505 address = realBaseAddress;506 realBaseAddress = baseAddress;507 baseAddress = oh.ImageBase;508 break;509 }510 lastaddress = address;548 rc = DosAllocMem((PPVOID)&address, FALLOC_SIZE, PAG_READ); 549 if(rc) break; 550 551 if(firstaddress == 0) 552 firstaddress = address; 553 554 fout << "DosAllocMem returned " << address << endl; 555 if(address + FALLOC_SIZE >= oh.ImageBase) { 556 if(address > oh.ImageBase) {//we've passed it! 557 DosFreeMem((PVOID)address); 558 return(FALSE); 559 } 560 //found the right address 561 DosFreeMem((PVOID)address); 562 //align at 64 kb boundary 563 realBaseAddress = oh.ImageBase & 0xFFFF0000; 564 diff = realBaseAddress - address; 565 if(diff) { 566 rc = DosAllocMem((PPVOID)&address, diff, PAG_READ); 567 if(rc) break; 568 } 569 rc = DosAllocMem((PPVOID)&baseAddress, imageSize, PAG_READ); 570 if(rc) break; 571 572 if(baseAddress != realBaseAddress) { 573 fout << "baseAddress != realBaseAddress!!" << endl; 574 break; 575 } 576 if(diff) DosFreeMem((PVOID)address); 577 578 address = realBaseAddress; 579 realBaseAddress = baseAddress; 580 baseAddress = oh.ImageBase; 581 break; 582 } 583 lastaddress = address; 511 584 } 512 585 while(firstaddress <= lastaddress) { 513 DosFreeMem((PVOID)firstaddress);514 firstaddress += FALLOC_SIZE;586 DosFreeMem((PVOID)firstaddress); 587 firstaddress += FALLOC_SIZE; 515 588 } 516 589 if(baseAddress == 0) //Let me guess.. MS Office app? 517 return(FALSE); 590 return(FALSE); 591 518 592 return(TRUE); 519 593 } … … 527 601 528 602 for(i=0;i<nrsections;i++) { 529 section[i].realvirtaddr = baseAddress + (section[i].virtaddr - oh.ImageBase);603 section[i].realvirtaddr = baseAddress + (section[i].virtaddr - oh.ImageBase); 530 604 } 531 605 for(i=0;i<nrsections;i++) { 532 pagFlags = PAG_COMMIT;533 switch(section[i].type) {606 pagFlags = PAG_COMMIT; 607 switch(section[i].type) { 534 608 case SECTION_CODE: 535 609 case (SECTION_CODE | SECTION_IMPORT): … … 539 613 case SECTION_READONLYDATA: 540 614 case SECTION_RESOURCE: 541 pagFlags |= PAG_WRITE | PAG_READ; 542 break; 615 case SECTION_TLS: 616 pagFlags |= PAG_WRITE | PAG_READ; 617 break; 543 618 case SECTION_EXPORT: 544 619 case SECTION_DEBUG: 545 620 case SECTION_RELOC: 546 pagFlags = 0; //don't commit547 break;548 }549 if(pagFlags == 0) continue; //debug or export section550 551 rc = DosSetMem((PVOID)section[i].realvirtaddr, section[i].virtualsize, pagFlags);552 if(rc) {553 errorState = rc;554 555 }556 if(section[i].type != SECTION_UNINITDATA) {557 assert(section[i].rawdata);558 memcpy((char *)section[i].realvirtaddr, section[i].rawdata, section[i].rawsize);559 }621 pagFlags = 0; //don't commit 622 break; 623 } 624 if(pagFlags == 0) continue; //debug or export section 625 626 rc = DosSetMem((PVOID)section[i].realvirtaddr, section[i].virtualsize, pagFlags); 627 if(rc) { 628 errorState = rc; 629 return(FALSE); 630 } 631 if(section[i].type != SECTION_UNINITDATA) { 632 assert(section[i].rawdata); 633 memcpy((char *)section[i].realvirtaddr, section[i].rawdata, section[i].rawsize); 634 } 560 635 } 561 636 return(TRUE); … … 570 645 571 646 for(i=0;i<nrsections;i++) { 572 pagFlags = 0;573 switch(section[i].type) {647 pagFlags = 0; 648 switch(section[i].type) { 574 649 case SECTION_CODE: 575 650 case (SECTION_CODE | SECTION_IMPORT): 576 pagFlags |= PAG_EXECUTE | PAG_READ;577 break;651 pagFlags |= PAG_EXECUTE | PAG_READ; 652 break; 578 653 case SECTION_INITDATA: 579 654 case SECTION_UNINITDATA: 580 655 case SECTION_IMPORT: //TODO: read only? 581 pagFlags |= PAG_WRITE | PAG_READ;582 break;656 pagFlags |= PAG_WRITE | PAG_READ; 657 break; 583 658 case SECTION_READONLYDATA: 584 659 case SECTION_RESOURCE: 585 pagFlags |= PAG_READ; 586 break; 660 case SECTION_TLS: 661 pagFlags |= PAG_READ; 662 break; 587 663 default: 588 continue;589 }590 rc = DosSetMem((PVOID)section[i].realvirtaddr, section[i].virtualsize, pagFlags);591 if(rc) {592 errorState = rc;593 return(FALSE);594 }664 continue; 665 } 666 rc = DosSetMem((PVOID)section[i].realvirtaddr, section[i].virtualsize, pagFlags); 667 if(rc) { 668 errorState = rc; 669 return(FALSE); 670 } 595 671 } 596 672 return(TRUE); … … 804 880 805 881 if(nameexports == NULL) { 806 nameExportSize= 4096;807 nameexports = (NameExport *)malloc(nameExportSize);808 curnameexport = nameexports;882 nameExportSize= 4096; 883 nameexports = (NameExport *)malloc(nameExportSize); 884 curnameexport = nameexports; 809 885 } 810 886 nsize = (ULONG)curnameexport - (ULONG)nameexports; 811 887 if(nsize + sizeof(NameExport) + strlen(apiname) > nameExportSize) { 812 nameExportSize += 4096;813 char *tmp = (char *)nameexports;814 nameexports = (NameExport *)malloc(nameExportSize);815 memcpy(nameexports, tmp, nsize);816 curnameexport = (NameExport *)((ULONG)nameexports + nsize);817 free(tmp);888 nameExportSize += 4096; 889 char *tmp = (char *)nameexports; 890 nameexports = (NameExport *)malloc(nameExportSize); 891 memcpy(nameexports, tmp, nsize); 892 curnameexport = (NameExport *)((ULONG)nameexports + nsize); 893 free(tmp); 818 894 } 819 895 curnameexport->virtaddr = baseAddress + (virtaddr - oh.ImageBase); … … 824 900 curnameexport->nlength = strlen(apiname) + 1; 825 901 if(curnameexport->nlength < sizeof(curnameexport->name)) 826 curnameexport->nlength = sizeof(curnameexport->name); 902 curnameexport->nlength = sizeof(curnameexport->name); 903 827 904 curnameexport = (NameExport *)((ULONG)curnameexport->name + curnameexport->nlength); 828 905 } … … 832 909 { 833 910 if(ordexports == NULL) { 834 ordexports = (OrdExport *)malloc(nrOrdExports * sizeof(OrdExport));835 curordexport = ordexports;911 ordexports = (OrdExport *)malloc(nrOrdExports * sizeof(OrdExport)); 912 curordexport = ordexports; 836 913 } 837 914 curordexport->virtaddr = baseAddress + (virtaddr - oh.ImageBase); … … 980 1057 WinDll = Win32Dll::findModule(pszCurModule); 981 1058 if(WinDll == NULL) 982 1059 { //not found, so load it 983 1060 WinDll = new Win32Dll(pszCurModule); 984 1061 … … 992 1069 fout << "********************** Loading Module *********************" << endl; 993 1070 fout << "**********************************************************************" << endl; 994 if(WinDll->init( ) == FALSE) {1071 if(WinDll->init(0) == FALSE) { 995 1072 fout << "Internal WinDll error " << WinDll->getError() << endl; 996 1073 return(FALSE); … … 1076 1153 if (rc != NO_ERROR) 1077 1154 { 1078 dprintf(("KERNEL32:Win32Image::isPEImage(%s) failed with %u\n", 1079 szFileName, 1080 rc)); 1081 return(FALSE); 1155 dprintf(("KERNEL32:Win32Image::isPEImage(%s) failed with %u\n", 1156 szFileName, rc)); 1157 return(FALSE); 1082 1158 } 1083 1159 … … 1087 1163 IMAGE_DOS_HEADER *pdoshdr = (IMAGE_DOS_HEADER *)malloc(sizeof(IMAGE_DOS_HEADER)); 1088 1164 if(pdoshdr == NULL) { 1089 DosClose(win32handle); /* Close the file */1090 return(FALSE);1165 DosClose(win32handle); /* Close the file */ 1166 return(FALSE); 1091 1167 } 1092 1168 rc = DosRead(win32handle, pdoshdr, sizeof(IMAGE_DOS_HEADER), &ulRead); 1093 1169 if(rc != NO_ERROR) { 1094 DosClose(win32handle); /* Close the file */1095 return(FALSE);1170 DosClose(win32handle); /* Close the file */ 1171 return(FALSE); 1096 1172 } 1097 1173 ULONG hdrsize = pdoshdr->e_lfanew + SIZE_OF_NT_SIGNATURE + sizeof(IMAGE_FILE_HEADER); … … 1103 1179 win32file = malloc(hdrsize); 1104 1180 if(win32file == NULL) { 1105 DosClose(win32handle); /* Close the file */1106 return(FALSE);1181 DosClose(win32handle); /* Close the file */ 1182 return(FALSE); 1107 1183 } 1108 1184 rc = DosRead(win32handle, win32file, hdrsize, &ulRead); 1109 1185 if(rc != NO_ERROR) { 1110 goto failure;1186 goto failure; 1111 1187 } 1112 1188 1113 1189 if(GetPEFileHeader (win32file, &fh) == FALSE) { 1114 goto failure;1190 goto failure; 1115 1191 } 1116 1192 1117 1193 if(!(fh.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)) {//not valid 1118 goto failure;1194 goto failure; 1119 1195 } 1120 1196 if(fh.Machine != IMAGE_FILE_MACHINE_I386) { 1121 goto failure;1197 goto failure; 1122 1198 } 1123 1199 //IMAGE_FILE_SYSTEM == only drivers (device/file system/video etc)? 1124 1200 if(fh.Characteristics & IMAGE_FILE_SYSTEM) { 1125 goto failure;1201 goto failure; 1126 1202 } 1127 1203 DosClose(win32handle); -
trunk/src/kernel32/wprocess.cpp
r532 r544 1 /* $Id: wprocess.cpp,v 1.2 0 1999-08-17 17:04:52sandervl Exp $ */1 /* $Id: wprocess.cpp,v 1.21 1999-08-18 12:24:17 sandervl Exp $ */ 2 2 3 3 /* … … 395 395 return(0); 396 396 397 module->init( );397 module->init(0); 398 398 if(module->getError() != NO_ERROR) { 399 399 dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile)); … … 467 467 return(0); 468 468 469 module->init( );469 module->init(0); 470 470 if(module->getError() != NO_ERROR) { 471 471 dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile)); -
trunk/src/peldr/initterm.cpp
r506 r544 1 /* $Id: initterm.cpp,v 1. 1 1999-08-16 13:54:06sandervl Exp $ */1 /* $Id: initterm.cpp,v 1.2 1999-08-18 12:24:32 sandervl Exp $ */ 2 2 3 3 /* … … 32 32 #include <odin.h> 33 33 #include <misc.h> /*PLF Wed 98-03-18 23:18:15*/ 34 #include <winimage.h> 34 35 35 36 /*-------------------------------------------------------------------*/ … … 75 76 // This is done before any Odin or PMWIN dll is loaded, so we'll get 76 77 // a very low virtual address. (which is exactly what we want) 77 rc = DosAllocMem((PPVOID)&reservedMemory, 16*1024*1024, PAG_WRITE | PAG_READ);78 rc = DosAllocMem((PPVOID)&reservedMemory, PELDR_RESERVEDMEMSIZE, PAG_WRITE | PAG_READ); 78 79 79 80 /*******************************************************************/ -
trunk/src/peldr/pe.cpp
r506 r544 1 /* $Id: pe.cpp,v 1. 5 1999-08-16 13:54:07sandervl Exp $ */1 /* $Id: pe.cpp,v 1.6 1999-08-18 12:24:32 sandervl Exp $ */ 2 2 3 3 /* … … 72 72 HMODULE hmodPMWin, hmodKernel32; 73 73 74 printf("memory allocated at %X\n", ReserveMem());75 76 74 rc = DosLoadModule(exeName, sizeof(exeName), "PMWIN.DLL", &hmodPMWin); 77 75 rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32INITIALIZE, NULL, (PFN *)&MyWinInitialize); … … 130 128 WinExe->setCommandLine(szCmdLine); 131 129 132 if(WinExe->init( ) == FALSE) {130 if(WinExe->init(ReserveMem()) == FALSE) { 133 131 delete WinExe; 134 132 return(1);
Note:
See TracChangeset
for help on using the changeset viewer.