Changeset 8003 for trunk/tools
- Timestamp:
- Feb 24, 2002, 3:47:28 AM (24 years ago)
- Location:
- trunk/tools/common
- Files:
-
- 10 added
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/common/common.mak
r7995 r8003 1 # $Id: common.mak,v 1. 5 2002-02-23 23:27:18bird Exp $1 # $Id: common.mak,v 1.6 2002-02-24 02:47:23 bird Exp $ 2 2 3 3 # … … 40 40 $(OBJDIR)\kFileSDF.obj \ 41 41 $(OBJDIR)\kFileFormatBase.obj \ 42 $(OBJDIR)\kFile.obj 42 $(OBJDIR)\kFile.obj \ 43 $(OBJDIR)\kFileInterfaces.obj \ 44 $(OBJDIR)\kAssert.obj \ 45 $(OBJDIR)\kError.obj \ 43 46 44 47 -
trunk/tools/common/kDef2Wat.cpp
r5531 r8003 1 /* $Id: kDef2Wat.cpp,v 1. 2 2001-04-17 00:26:10bird Exp $1 /* $Id: kDef2Wat.cpp,v 1.3 2002-02-24 02:47:23 bird Exp $ 2 2 * 3 3 * Converter for IBM/MS linker definition files (.DEF) to Watcom linker directives and options. … … 14 14 * Header Files * 15 15 *******************************************************************************/ 16 #include <os2.h>17 16 #include "kTypes.h" 17 #include "kError.h" 18 18 #include "kFile.h" 19 #include "kFileInterfaces.h" 19 20 #include "kFileFormatBase.h" 20 #include "kInterfaces.h"21 21 #include "kFileDef.h" 22 22 … … 58 58 try 59 59 { 60 kFile InFile(pszInput); 61 kFileDef def(&InFile); 60 kFileDef def(new kFile(pszInput)); 62 61 try 63 62 { … … 75 74 kFile::StdOut.printf("Successfully converted %s to %s\n", pszInput, pszOutput); 76 75 } 77 catch ( int errorcode)76 catch (kError err) 78 77 { 79 kFile::StdErr.printf("Append file %s to %s, errorcode=%d\n", pszAppend, pszInput, err orcode);78 kFile::StdErr.printf("Append file %s to %s, errorcode=%d\n", pszAppend, pszInput, err.getErrno()); 80 79 return -3; 81 80 } 82 81 } 83 82 } 84 catch ( int errorcode)83 catch (kError err) 85 84 { 86 kFile::StdErr.printf("Failed to read .DEF file (%s), errorcode=%d\n", pszInput, err orcode);85 kFile::StdErr.printf("Failed to read .DEF file (%s), errorcode=%d\n", pszInput, err.getErrno()); 87 86 return -3; 88 87 } 89 88 } 90 catch ( int errorcode)89 catch (kError err) 91 90 { 92 kFile::StdErr.printf("Failed to read .DEF file (%s), errorcode=%d\n", pszInput, err orcode);91 kFile::StdErr.printf("Failed to read .DEF file (%s), errorcode=%d\n", pszInput, err.getErrno()); 93 92 return -2; 94 93 } -
trunk/tools/common/kDump.cpp
r5531 r8003 1 /* $Id: kDump.cpp,v 1. 3 2001-04-17 00:26:10bird Exp $1 /* $Id: kDump.cpp,v 1.4 2002-02-24 02:47:24 bird Exp $ 2 2 * 3 3 * Generic dumper... … … 19 19 * Header Files * 20 20 *******************************************************************************/ 21 #include <os2.h>22 23 21 #include <stdio.h> 24 22 23 #include "kTypes.h" 24 #include "kError.h" 25 25 #include "kFile.h" 26 26 #include "kFileFormatBase.h" 27 #include "k Interfaces.h"27 #include "kFileInterfaces.h" 28 28 #include "kFileDef.h" 29 29 #include "kFileLX.h" … … 42 42 try 43 43 { 44 kFile file(argv[argi]);45 44 kFileFormatBase * pFile = NULL; 46 try {pFile = new kFilePE( &file);}47 catch ( interr)45 try {pFile = new kFilePE(new kFile(argv[argi]));} 46 catch (kError err) 48 47 { 49 try {pFile = new kFileLX( &file);}50 catch ( interr)48 try {pFile = new kFileLX(new kFile(argv[argi]));} 49 catch (kError err) 51 50 { 52 try {pFile = new kFileDef( &file);}53 catch ( interr)51 try {pFile = new kFileDef(new kFile(argv[argi]));} 52 catch (kError err) 54 53 { 55 54 kFile::StdErr.printf("Failed to recognize file %s.\n", argv[argi]); … … 68 67 } 69 68 } 70 catch ( interr)69 catch (kError err) 71 70 { 72 fprintf(stderr, "Fatal: Failed to open file %s err=%d.\n", argv[argi], err );71 fprintf(stderr, "Fatal: Failed to open file %s err=%d.\n", argv[argi], err.getErrno()); 73 72 return -1; 74 73 } -
trunk/tools/common/kFile.cpp
r7093 r8003 1 /* $Id: kFile.cpp,v 1. 9 2001-10-17 14:21:10bird Exp $1 /* $Id: kFile.cpp,v 1.10 2002-02-24 02:47:24 bird Exp $ 2 2 * 3 3 * kFile - Simple (for the time being) file class. … … 27 27 #include <stdlib.h> 28 28 29 #include "kTypes.h" 30 #include "kError.h" 29 31 #include "kFile.h" 30 32 … … 43 45 * @remark 44 46 */ 45 BOOLkFile::refreshFileStatus()47 KBOOL kFile::refreshFileStatus() 46 48 { 47 49 if (fStdDev) … … 50 52 if (!fStatusClean) 51 53 { 52 rc = DosQueryFileInfo( hFile, FIL_QUERYEASIZE, &filestatus, sizeof(filestatus));54 rc = DosQueryFileInfo(OSData.os2.hFile, FIL_QUERYEASIZE, &OSData.os2.filestatus, sizeof(OSData.os2.filestatus)); 53 55 fStatusClean = (rc == NO_ERROR); 54 56 if (!fStatusClean && fThrowErrors) 55 throw ( (int)rc);57 throw (kError(rc)); 56 58 } 57 59 else … … 66 68 * @returns Success indicator. 67 69 */ 68 BOOLkFile::position()70 KBOOL kFile::position() 69 71 { 70 72 /* … … 75 77 { 76 78 ULONG off; 77 rc = DosSetFilePtr( hFile, offVirtual, FILE_BEGIN, &off);79 rc = DosSetFilePtr(OSData.os2.hFile, offVirtual, FILE_BEGIN, &off); 78 80 if (rc != NO_ERROR || off != offVirtual) 79 81 { 80 82 if (fThrowErrors) 81 throw ( (int)rc);83 throw (kError(rc)); 82 84 return FALSE; 83 85 } … … 99 101 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 100 102 */ 101 BOOL kFile::bufferRead(ULONG offFile) throw (int)103 KBOOL kFile::bufferRead(unsigned long offFile) throw(kError) 102 104 { 103 105 ULONG cbRead; … … 108 110 109 111 /* check that the request is valid */ 110 if (offFile > filestatus.cbFile)112 if (offFile > OSData.os2.filestatus.cbFile) 111 113 return FALSE; 112 114 … … 123 125 124 126 /* If readonly file optimize end of file */ 125 if (fReadOnly && cbBuffer + offFile > filestatus.cbFile)126 offFile = filestatus.cbFile > cbBuffer ?filestatus.cbFile - cbBuffer : 0UL;127 if (fReadOnly && cbBuffer + offFile > OSData.os2.filestatus.cbFile) 128 offFile = OSData.os2.filestatus.cbFile > cbBuffer ? OSData.os2.filestatus.cbFile - cbBuffer : 0UL; 127 129 128 130 /* need to change file ptr? */ … … 130 132 { 131 133 ULONG ul; 132 rc = DosSetFilePtr( hFile, offFile, FILE_BEGIN, &ul);134 rc = DosSetFilePtr(OSData.os2.hFile, offFile, FILE_BEGIN, &ul); 133 135 if (rc != NO_ERROR) 134 136 { 135 137 if (fThrowErrors) 136 throw ( (int)rc);138 throw (kError(rc)); 137 139 return FALSE; 138 140 } … … 141 143 142 144 /* read from the file */ 143 cbRead = min(filestatus.cbFile - offFile, cbBuffer);144 rc = DosRead( hFile, pachBuffer, cbRead, &cbRead);145 cbRead = KMIN(OSData.os2.filestatus.cbFile - offFile, cbBuffer); 146 rc = DosRead(OSData.os2.hFile, pachBuffer, cbRead, &cbRead); 145 147 if (rc == NO_ERROR) 146 148 { … … 156 158 fBufferDirty = FALSE; 157 159 if (fThrowErrors) 158 throw ( (int)rc);160 throw (kError(rc)); 159 161 return FALSE; 160 162 } … … 169 171 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 170 172 */ 171 BOOL kFile::bufferCommit(void) throw (int)173 KBOOL kFile::bufferCommit(void) throw(kError) 172 174 { 173 175 ULONG cbWrote; … … 181 183 if (offBuffer != offReal) 182 184 { 183 rc = DosSetFilePtr( hFile, offBuffer, FILE_BEGIN, &ul);185 rc = DosSetFilePtr(OSData.os2.hFile, offBuffer, FILE_BEGIN, &ul); 184 186 if (rc != NO_ERROR) 185 187 { 186 188 if (fThrowErrors) 187 throw ( (int)rc);189 throw (kError(rc)); 188 190 return FALSE; 189 191 } … … 192 194 193 195 /* write to the file */ 194 rc = DosWrite( hFile, pachBuffer, cbBufferValid, &cbWrote);196 rc = DosWrite(OSData.os2.hFile, pachBuffer, cbBufferValid, &cbWrote); 195 197 fStatusClean = FALSE; 196 198 if (rc == NO_ERROR) … … 201 203 else 202 204 { 203 DosSetFilePtr( hFile, offReal, FILE_BEGIN, &ul);205 DosSetFilePtr(OSData.os2.hFile, offReal, FILE_BEGIN, &ul); 204 206 if (fThrowErrors) 205 throw ( (int)rc);207 throw (kError(rc)); 206 208 return FALSE; 207 209 } … … 222 224 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 223 225 */ 224 kFile::kFile(HFILE hFile, BOOL fReadOnly)226 kFile::kFile(HFILE hFile, KBOOL fReadOnly) 225 227 : fReadOnly(fReadOnly), 226 228 fStatusClean(FALSE), … … 229 231 offReal(0), 230 232 pszFilename(NULL), 231 hFile(hFile),232 233 fStdDev(TRUE), 233 234 pachBuffer(NULL), … … 236 237 fBufferDirty(FALSE) 237 238 { 239 OSData.os2.hFile = hFile; 238 240 if (!refreshFileStatus()) 239 throw ( (int)rc);241 throw (kError(rc)); 240 242 this->pszFilename = strdup(""); 241 243 } … … 252 254 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 253 255 */ 254 kFile::kFile(const char *pszFilename, BOOL fReadOnly/*=TRUE*/)256 kFile::kFile(const char *pszFilename, KBOOL fReadOnly/*=TRUE*/) 255 257 : fReadOnly(fReadOnly), 256 258 fStatusClean(FALSE), … … 283 285 } 284 286 285 rc = DosOpen((PCSZ)pszFilename, & hFile, &ulAction, 0, FILE_NORMAL,287 rc = DosOpen((PCSZ)pszFilename, &OSData.os2.hFile, &ulAction, 0, FILE_NORMAL, 286 288 fulOpenFlags, fulOpenMode, NULL); 287 289 if (rc != NO_ERROR) 288 throw ( (int)rc);290 throw (kError(rc)); 289 291 290 292 if (!refreshFileStatus()) 291 throw ( (int)rc);293 throw (kError(rc)); 292 294 293 295 char szFullName[CCHMAXPATH]; … … 299 301 300 302 /* Buffering */ 301 cbBuffer = (fReadOnly && filestatus.cbFile < 32768) ?filestatus.cbFile : 8192;303 cbBuffer = (fReadOnly && OSData.os2.filestatus.cbFile < 32768) ? OSData.os2.filestatus.cbFile : 8192; 302 304 pachBuffer = new char[cbBuffer]; 303 305 if (pachBuffer == NULL) 304 306 throw (ERROR_NOT_ENOUGH_MEMORY); 305 if (fReadOnly && filestatus.cbFile < 32768)307 if (fReadOnly && OSData.os2.filestatus.cbFile < 32768) 306 308 { 307 309 if (!bufferRead(0)) 308 throw ( (int)rc);310 throw (kError(rc)); 309 311 } 310 312 } … … 320 322 if (pachBuffer) 321 323 delete pachBuffer; 322 DosClose( hFile);324 DosClose(OSData.os2.hFile); 323 325 } 324 326 … … 326 328 /** 327 329 * Reads <cbBuffer> bytes from the current file posistion into the buffer. 328 * @returns success indicator. (TRUE/FALSE)330 * @returns 0 on success. kError error number. 329 331 * @param pvBuffer Output buffer. 330 332 * @param cbBuffer Amount of bytes to read. 331 333 */ 332 BOOLkFile::read(void *pvBuffer, long cbBuffer)334 int kFile::read(void *pvBuffer, long cbBuffer) 333 335 { 334 336 ULONG cbRead; … … 336 338 /* Validate parameters */ 337 339 if (cbBuffer == 0) 338 return TRUE;340 return NO_ERROR; 339 341 if (cbBuffer < 0) 340 342 { 341 343 rc = ERROR_INVALID_PARAMETER; 342 344 if (fThrowErrors) 343 throw ( (int)rc);344 return FALSE;345 throw (kError(rc)); 346 return rc; 345 347 } 346 348 347 349 /* refresh file status (cbFile) */ 348 350 if (!refreshFileStatus()) 349 return FALSE;351 return rc; 350 352 351 353 /* check if valid request */ 352 if ( offVirtual > filestatus.cbFile353 || offVirtual + cbBuffer > filestatus.cbFile354 if ( offVirtual > OSData.os2.filestatus.cbFile 355 || offVirtual + cbBuffer > OSData.os2.filestatus.cbFile 354 356 ) 355 357 { /* invalid request */ 356 358 rc = ERROR_NO_DATA; 357 359 } 358 else if (this->cbBufferValid == filestatus.cbFile && offBuffer == 0)360 else if (this->cbBufferValid == OSData.os2.filestatus.cbFile && offBuffer == 0) 359 361 { 360 362 /* … … 386 388 { /* copy data from buffer */ 387 389 cbRead = cbBufferValid - offVirtual + offBuffer; 388 cbRead = min(cbRead, cbBuffer);390 cbRead = KMIN(cbRead, cbBuffer); 389 391 memcpy(pvBuffer, &pachBuffer[offVirtual - offBuffer], (size_t)cbRead); 390 392 offVirtual += cbRead; … … 396 398 /* read into buffer */ 397 399 if (!bufferRead(offVirtual)) 398 return FALSE;400 return rc; 399 401 } 400 402 } … … 406 408 * unbuffered read. 407 409 */ 408 rc = DosRead( hFile, pvBuffer, cbBuffer, &cbRead);410 rc = DosRead(OSData.os2.hFile, pvBuffer, cbBuffer, &cbRead); 409 411 if (rc == NO_ERROR) 410 412 offVirtual = offReal += cbRead; … … 412 414 413 415 /* check for error and return accordingly */ 414 if (rc) 415 { 416 if (fThrowErrors) 417 throw ((int)rc); 418 return FALSE; 419 } 420 return TRUE; 416 if (rc && fThrowErrors) 417 throw (kError(rc)); 418 return rc; 421 419 } 422 420 … … 424 422 /** 425 423 * Reads <cbBuffer> bytes at file offset <off>. 426 * @returns success indicator. (TRUE/FALSE)424 * @returns 0 on success. kError error number. 427 425 * @param pvBuffer Output buffer. 428 426 * @param cbBuffer Amount of bytes to read. 429 427 * @param off Absolute file offset. 430 428 */ 431 BOOL kFile::readAt(void *pvBuffer, long cbBuffer, long off) 432 { 433 return set(off) && read(pvBuffer, cbBuffer); 429 int kFile::readAt(void *pvBuffer, long cbBuffer, long off) 430 { 431 if (set(off)) 432 return rc; 433 read(pvBuffer, cbBuffer); 434 return rc; 434 435 } 435 436 … … 439 440 * (The memory block has a '\0' at the end just in case you 440 441 * are using it as a long string.) 442 * Must call the static kFile::mapFree function to free the memory block. 441 443 * @returns Pointer to file in memory. 442 444 */ 443 void * kFile:: readFile() throw(int)445 void * kFile::mapFile() throw(kError) 444 446 { 445 447 void *pv; … … 450 452 { 451 453 if (fThrowErrors) 452 throw (ERROR_NOT_ENOUGH_MEMORY);454 throw (kError(kError::NOT_ENOUGH_MEMORY)); 453 455 return NULL; 454 456 } 455 457 456 458 /* go the start of the file and read it. */ 457 if ( start() &&read(pv, this->getSize()))459 if (!start() && !read(pv, this->getSize())) 458 460 return pv; // successfull exit! 459 461 … … 467 469 * Reads a single line from the file into the given buffer. 468 470 * Newline is stripped! 469 * @returns Success indicator.471 * @returns 0 on success. kError error number. 470 472 * @param pszBuffer Pointer to string buffer. 471 473 * Will hold a zero-string upon successful return. … … 475 477 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 476 478 */ 477 BOOL kFile::readln(char *pszBuffer, long cchBuffer) throw (int)479 int kFile::readln(char *pszBuffer, long cchBuffer) throw(kError) 478 480 { 479 481 long cbRead; … … 481 483 /* refresh file status (cbFile) */ 482 484 if (!refreshFileStatus()) 483 return FALSE;485 return rc; 484 486 485 487 /* … … 488 490 * Loop buffer by buffer looking for a newline. 489 491 */ 490 cbRead = min(max((long)filestatus.cbFile - (long)offVirtual, 0), cchBuffer-1);492 cbRead = KMIN(KMAX((long)OSData.os2.filestatus.cbFile - (long)offVirtual, 0), cchBuffer-1); 491 493 if (cbRead == 0) 492 return FALSE;494 return rc = ERROR_HANDLE_EOF; 493 495 494 496 while (cbRead > 0) … … 502 504 if (offVirtual >= offBuffer + cbBufferValid || offVirtual < offBuffer) 503 505 if (!bufferRead(offVirtual)) 504 return FALSE;506 return rc; 505 507 506 508 /* Scan buffer for new line */ … … 542 544 else 543 545 offVirtual++; 544 return TRUE;545 } 546 } 547 548 return TRUE;546 return NO_ERROR; 547 } 548 } 549 550 return NO_ERROR; 549 551 } 550 552 … … 552 554 /** 553 555 * Writes <cbBuffer> bytes to the file at the current file position. 554 * @returns success indicator. (TRUE/FALSE)556 * @returns 0 on success. kError error number. 555 557 * @param pvBuffer Output buffer. 556 558 * @param cbBuffer Amount of bytes to write. 557 559 */ 558 BOOLkFile::write(const void *pv, long cb)560 int kFile::write(const void *pv, long cb) 559 561 { 560 562 if (fReadOnly) … … 604 606 offVirtual += cb + cbAddPost; 605 607 fBufferDirty = TRUE; 606 return TRUE;608 return NO_ERROR; 607 609 } 608 610 … … 634 636 { /* don't fit anywhere... */ 635 637 if (!bufferCommit()) 636 return FALSE;638 return rc; 637 639 offBuffer = offVirtual; 638 640 cbWrite = cbBufferValid = cb > cbBuffer ? cbBuffer : cb; … … 648 650 offVirtual += cbAddPost; 649 651 650 return TRUE;652 return NO_ERROR; 651 653 } 652 654 else if (position()) … … 654 656 ULONG cbWrote; 655 657 656 rc = DosWrite( hFile, (PVOID)pv, cb, &cbWrote);658 rc = DosWrite(OSData.os2.hFile, (PVOID)pv, cb, &cbWrote); 657 659 if (rc == NO_ERROR) 658 660 { 659 661 offVirtual = offReal += cbWrote; 660 return TRUE;662 return NO_ERROR; 661 663 } 662 664 } … … 664 666 665 667 if (fThrowErrors) 666 throw ( (int)rc);667 return FALSE;668 throw (kError(rc)); 669 return rc; 668 670 } 669 671 … … 671 673 /** 672 674 * Write <cbBuffer> bytes at file offset <off> from <pvBuffer>. 673 * @returns success indicator. (TRUE/FALSE)675 * @returns 0 on success. kError error number. 674 676 * @param pvBuffer Output buffer. 675 677 * @param cbBuffer Amount of bytes to write. 676 678 * @param off Absolute file offset. 677 679 */ 678 BOOL kFile::writeAt(void *pvBuffer, long cbBuffer, long off) 679 { 680 return set(off) && write(pvBuffer, cbBuffer); 680 int kFile::writeAt(const void *pvBuffer, long cbBuffer, long off) 681 { 682 if (set(off)) 683 return rc; 684 return write(pvBuffer, cbBuffer); 681 685 } 682 686 … … 693 697 * @remark Currently limited to 64KB of result data. 694 698 */ 695 int kFile::printf(const char *pszFormat, ...) throw (int)699 int kFile::printf(const char *pszFormat, ...) throw(kError) 696 700 { 697 701 long offStart = getPos(); … … 725 729 /** 726 730 * Sets the filesize. 727 * @returns Success indicator.731 * @returns 0 on success. kError error number. 728 732 * @param cbFile New filesize. 729 733 * Defaults to 0xffffffff, which results in 730 734 * cutting the file at the current position. 731 735 */ 732 BOOLkFile::setSize(unsigned long cbFile/*= ~0UL*/)736 int kFile::setSize(unsigned long cbFile/*= ~0UL*/) 733 737 { 734 738 if (cbFile == ~0UL) 735 739 cbFile = offVirtual; 736 rc = DosSetFileSize( hFile, cbFile);740 rc = DosSetFileSize(OSData.os2.hFile, cbFile); 737 741 if (rc != NO_ERROR && fThrowErrors) 738 throw ( (int)rc);739 740 return rc == NO_ERROR;742 throw (kError(rc)); 743 744 return rc; 741 745 } 742 746 … … 752 756 char * pachBuffer = new char[1024*256]; 753 757 long pos = AppendFile.getPos(); 754 BOOLfAppend = AppendFile.fThrowErrors;755 BOOLfThis = fThrowErrors;758 KBOOL fAppend = AppendFile.fThrowErrors; 759 KBOOL fThis = fThrowErrors; 756 760 757 761 setThrowOnErrors(); … … 762 766 AppendFile.refreshFileStatus(); 763 767 764 cb = min(1024*256, AppendFile.filestatus.cbFile);768 cb = KMIN(1024*256, AppendFile.OSData.os2.filestatus.cbFile); 765 769 while (cb > 0) 766 770 { 767 771 AppendFile.read(pachBuffer, cb); 768 772 write(pachBuffer, cb); 769 cb = min(1024*256, (long)AppendFile.filestatus.cbFile - (long)AppendFile.offVirtual);773 cb = KMIN(1024*256, (long)AppendFile.OSData.os2.filestatus.cbFile - (long)AppendFile.offVirtual); 770 774 } 771 775 … … 781 785 /** 782 786 * Seek relative to the current position. 783 * @returns Success indicator.787 * @returns 0 on success. kError error number. 784 788 * @param off Relative reposition. 785 789 */ 786 BOOLkFile::move(long off)790 int kFile::move(long off) 787 791 { 788 792 if ((off + offVirtual) & 0x80000000UL) /* above 2GB or negative */ … … 790 794 else 791 795 { 792 if (off + offVirtual > filestatus.cbFile && fReadOnly) /* can't expand readonly file. */796 if (off + offVirtual > OSData.os2.filestatus.cbFile && fReadOnly) /* can't expand readonly file. */ 793 797 rc = ERROR_HANDLE_EOF; 794 798 else 795 799 { 796 800 offVirtual += off; 797 return TRUE;801 return rc = NO_ERROR; 798 802 } 799 803 } 800 804 801 805 if (fThrowErrors) 802 throw ( (int)rc);803 return FALSE;806 throw (kError(rc)); 807 return rc; 804 808 } 805 809 … … 807 811 /** 808 812 * Seek to an absolute position in the file (off). 809 * @returns Success indicator.813 * @returns 0 on success. kError error number. 810 814 * @param off New file position. 811 815 */ 812 BOOLkFile::set(long off)816 int kFile::set(long off) 813 817 { 814 818 if (off < 0) … … 816 820 else 817 821 { 818 if ((unsigned long)off > filestatus.cbFile && fReadOnly)822 if ((unsigned long)off > OSData.os2.filestatus.cbFile && fReadOnly) 819 823 rc = ERROR_HANDLE_EOF; 820 824 else 821 825 { 822 826 offVirtual = off; 823 rc = NO_ERROR; 824 return TRUE; 827 return rc = NO_ERROR; 825 828 } 826 829 } 827 830 if (fThrowErrors) 828 throw ( (int)rc);829 return FALSE;831 throw (kError(rc)); 832 return rc; 830 833 } 831 834 … … 833 836 /** 834 837 * Seek to the end of the file. 835 * @returns Success indicator. TRUE / FALSE.838 * @returns 0 on success. kError error number. 836 839 * @remark Will only throw error if refreshFileStatus failes. 837 840 */ 838 BOOLkFile::end()841 int kFile::end() 839 842 { 840 843 if (!refreshFileStatus()) 841 return FALSE;842 843 if (!fReadOnly && pachBuffer && offBuffer != ~0UL && offBuffer + cbBufferValid > filestatus.cbFile)844 return rc; 845 846 if (!fReadOnly && pachBuffer && offBuffer != ~0UL && offBuffer + cbBufferValid > OSData.os2.filestatus.cbFile) 844 847 /* a writable file with buffer might have uncommited data in the buffer. */ 845 848 offVirtual = offBuffer + cbBufferValid; 846 849 else 847 offVirtual = filestatus.cbFile; 848 849 rc = NO_ERROR; 850 return TRUE; 850 offVirtual = OSData.os2.filestatus.cbFile; 851 852 return rc = NO_ERROR; 851 853 } 852 854 … … 854 856 /** 855 857 * Seek to the start of the file. 856 * @returns TRUE.858 * @returns 0 on success. kError error number. 857 859 * @remark Will never throw errors. 858 860 */ 859 BOOLkFile::start()861 int kFile::start() 860 862 { 861 863 offVirtual = 0; 862 rc = NO_ERROR; 863 return TRUE; 864 return rc = NO_ERROR; 864 865 } 865 866 … … 876 877 return -1; 877 878 878 return filestatus.cbFile;879 return OSData.os2.filestatus.cbFile; 879 880 } 880 881 … … 897 898 * @remark Will only throw error if refreshFileStatus failes. 898 899 */ 899 BOOLkFile::isEOF()900 KBOOL kFile::isEOF() 900 901 { 901 902 #if 0 902 throw (ERROR_NOT_SUPPORTED); //this method don't currently work! Need to use flag!903 throw (kError(kError::NOT_SUPPORTED)); //this method don't currently work! Need to use flag! 903 904 #else 904 905 if (!fReadOnly && !refreshFileStatus()) 905 return ( BOOL)-1;906 907 return filestatus.cbFile <= offVirtual; //??? - !!!906 return (KBOOL)-1; 907 908 return OSData.os2.filestatus.cbFile <= offVirtual; //??? - !!! 908 909 #endif 909 910 } … … 913 914 * Set error behaviour to fail by throwing the OS/2 return code when an 914 915 * error occures. 915 * @returns TRUE;916 916 * @remark Will never throw errors. 917 917 */ 918 BOOLkFile::setThrowOnErrors()918 void kFile::setThrowOnErrors() 919 919 { 920 920 fThrowErrors = TRUE; 921 921 rc = NO_ERROR; 922 return TRUE;923 922 } 924 923 … … 926 925 /** 927 926 * Set error behaviour to fail by return FALSE when an error has occures. 928 * @returns TRUE;929 927 * @remark Will never throw errors. 930 928 */ 931 BOOLkFile::setFailOnErrors()929 void kFile::setFailOnErrors() 932 930 { 933 931 fThrowErrors = FALSE; 934 932 rc = NO_ERROR; 935 return TRUE;936 933 } 937 934 … … 957 954 * @remark May throw errors. 958 955 */ 959 void *kFile:: readFile(const char *pszFilename)956 void *kFile::mapFile(const char *pszFilename) 960 957 { 961 958 kFile file(pszFilename); 962 return file.readFile(); 963 } 964 959 file.setThrowOnErrors(); 960 return file.mapFile(); 961 } 962 963 964 965 /** 966 * Frees a file mapping done by one of the mapFile members of kFile. 967 * @param pvFileMapping The pointer mapFile returned. 968 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 969 */ 970 void kFile::mapFree(void *pvFileMapping) 971 { 972 if (pvFileMapping) 973 free(pvFileMapping); 974 } 975 -
trunk/tools/common/kFile.h
r7093 r8003 1 /* $Id: kFile.h,v 1. 9 2001-10-17 14:22:33bird Exp $1 /* $Id: kFile.h,v 1.10 2002-02-24 02:47:24 bird Exp $ 2 2 * 3 3 * kFile - Simple (for the time being) file class. … … 22 22 class kFile 23 23 { 24 /** @cat constructors */ 25 private: 26 #ifndef __OS2DEFS__ 27 kFile(unsigned long hFile, KBOOL fReadOnly); 28 #else 29 kFile(HFILE hFile, KBOOL fReadOnly); 30 #endif 31 public: 32 kFile(const char *pszFilename, KBOOL fReadOnly = TRUE) throw(kError); 33 ~kFile(); 34 35 /** @cat File I/O methods */ 36 int read(void *pvBuffer, long cbBuffer) throw(kError); 37 int readAt(void *pvBuffer, long cbBuffer, long off) throw(kError); 38 int readln(char *pszBuffer, long cchBuffer); 39 40 int write(const void *pvBuffer, long cbBuffer) throw(kError); 41 int writeAt(const void *pvBuffer, long cbBuffer, long off) throw(kError); 42 43 int printf(const char *pszFormat, ...) throw(kError); 44 45 int setSize(unsigned long cbFile = ~0UL); 46 47 kFile & operator+=(kFile &AppendFile); 48 49 void * mapFile() throw(kError); 50 static void * mapFile(const char *pszFilename) throw(kError); 51 static void mapFree(void *pvFileMapping) throw(kError); 52 53 54 /** @cat File seek methods */ 55 int move(long off) throw(kError); 56 int set(long off) throw(kError); 57 int end() throw(kError); 58 int start(); 59 60 /** @cat Query methods */ 61 long getSize() throw(kError); 62 long getPos() const throw(kError); 63 KBOOL isEOF() throw(kError); 64 const char * getFilename() { return pszFilename; } 65 66 /** @cat Error handling */ 67 void setThrowOnErrors(); 68 void setFailOnErrors(); 69 int getLastError() const; 70 71 /** standard files */ 72 static kFile StdOut; 73 static kFile StdIn; 74 static kFile StdErr; 75 76 24 77 protected: 25 78 /** @cat Main datamembers */ 26 HFILE hFile; /* Pointer to stdio filehandle */ 27 BOOL fReadOnly; /* True if readonly access, False is readwrite. */ 28 BOOL fStdDev; /* True if stdio, stderr or stdin. Filestatus is invalid with this is set.*/ 29 APIRET rc; /* Last error (return code). */ 30 FILESTATUS4 filestatus; /* Filestatus data. */ 31 BOOL fStatusClean; /* True if filestatus is clean. False is not clean */ 32 BOOL fThrowErrors; /* When true we'll throw the rc on errors, else return FALSE. */ 33 PSZ pszFilename; /* Pointer to filename. */ 79 KBOOL fReadOnly; /* True if readonly access, False is readwrite. */ 80 KBOOL fStdDev; /* True if stdio, stderr or stdin. Filestatus is invalid with this is set.*/ 81 unsigned long rc; /* Last error (return code). */ 82 KBOOL fStatusClean; /* True if filestatus is clean. False is not clean */ 83 KBOOL fThrowErrors; /* When true we'll throw the rc on errors, else return FALSE. */ 84 char * pszFilename; /* Pointer to filename. */ 34 85 35 86 /** @cat Position datamembers */ … … 42 93 unsigned long offBuffer; /* Virtual file offset where the buffer starts. */ 43 94 unsigned long cbBufferValid; /* Count of valid bytes in the buffer. */ 44 BOOL fBufferDirty; /* Dirty flag. Set when the buffer needs to be committed. */ 95 KBOOL fBufferDirty; /* Dirty flag. Set when the buffer needs to be committed. */ 96 97 /** @cat OS specific data */ 98 union _kFileOSSpecific 99 { 100 char achFiller[14+2 + 16]; /* OS2 uses 16 bytes currently. Add 16-bytes just in case. */ 101 #ifdef __OS2DEF__ 102 struct _kFileOS2 103 { 104 HFILE hFile; /* Pointer to stdio filehandle */ 105 FILESTATUS4 filestatus; /* Filestatus data. */ 106 } os2; 107 #endif 108 } OSData; 45 109 46 110 /** @cat internal buffer methods */ 47 BOOL bufferRead(ULONG offFile) throw (int);48 BOOL bufferCommit(void) throw (int);111 KBOOL bufferRead(unsigned long offFile) throw(kError); 112 KBOOL bufferCommit(void) throw(kError); 49 113 50 114 /** @cat internal methods for maintaing internal structures. */ 51 BOOL refreshFileStatus() throw(int);52 BOOL position() throw(int);115 KBOOL refreshFileStatus() throw(kError); 116 KBOOL position() throw(kError); 53 117 54 /** @cat constructors */55 private:56 kFile(HFILE hFile, BOOL fReadOnly);57 public:58 kFile(const char *pszFilename, BOOL fReadOnly = TRUE) throw(int);59 ~kFile();60 61 /** @cat File I/O methods */62 BOOL read(void *pvBuffer, long cbBuffer) throw(int);63 BOOL readAt(void *pvBuffer, long cbBuffer, long off) throw(int);64 void * readFile() throw(int);65 static void * readFile(const char *pszFilename) throw(int);66 BOOL readln(char *pszBuffer, long cchBuffer);67 68 BOOL write(const void *pv, long cb) throw(int);69 BOOL writeAt(void *pvBuffer, long cbBuffer, long off) throw(int);70 71 int printf(const char *pszFormat, ...) throw (int);72 73 BOOL setSize(unsigned long cbFile = ~0UL);74 75 kFile & operator+=(kFile &AppendFile);76 77 /** @cat File seek methods */78 BOOL move(long off) throw(int);79 BOOL set(long off) throw(int);80 BOOL end() throw(int);81 BOOL start();82 83 /** @cat Query methods */84 long getSize() throw(int);85 long getPos() const throw(int);86 BOOL isEOF() throw(int);87 const char * getFilename() { return pszFilename; }88 89 /** @cat Error handling */90 BOOL setThrowOnErrors();91 BOOL setFailOnErrors();92 int getLastError() const;93 94 /** standard files */95 static kFile StdOut;96 static kFile StdIn;97 static kFile StdErr;98 118 }; 99 119 -
trunk/tools/common/kFileDef.cpp
r5531 r8003 1 /* 1 /* $Id: kFileDef.cpp,v 1.8 2002-02-24 02:47:25 bird Exp $ 2 * 2 3 * kFileDef - Definition files. 3 4 * 4 * Copyright (c) 1999 knut st. osmundsen5 * Copyright (c) 1999-2001 knut st. osmundsen 5 6 * 6 7 */ … … 21 22 * Header Files * 22 23 *******************************************************************************/ 23 #include <os2.h>24 24 #include <stdio.h> 25 25 #include <string.h> 26 26 #include <stdlib.h> 27 #include <assert.h> 28 27 28 #include "kTypes.h" 29 #include "kError.h" 29 30 #include "kFile.h" 30 31 #include "kFileFormatBase.h" 31 #include "k Interfaces.h"32 #include "kFileInterfaces.h" 32 33 #include "kFileDef.h" 34 33 35 34 36 /******************************************************************************* … … 43 45 * Internal Functions * 44 46 *******************************************************************************/ 45 static char *dupeString(const char *psz, BOOL fSkipFirstWord = FALSE);47 static char *dupeString(const char *psz, KBOOL fSkipFirstWord = FALSE); 46 48 static char *trim(char *psz); 47 49 static char *ltrim(const char *psz); … … 57 59 * @param fSkipFirstWord Skips the first word before duplicating the string. 58 60 */ 59 static char *dupeString(const char *psz, BOOL fSkipFirstWord/* = FALSE*/)61 static char *dupeString(const char *psz, KBOOL fSkipFirstWord/* = FALSE*/) 60 62 { 61 63 char *pszDupe; … … 117 119 118 120 119 kFileDef::kFileDef(kFile *pFile) throw(int) 120 :pszType(NULL), pszModName(NULL), pszBase(NULL), pszCode(NULL), pszData(NULL), pszDescription(NULL), 121 kFileDef::kFileDef(kFile *pFile) : 122 kFileFormatBase(pFile), 123 pszType(NULL), pszModName(NULL), pszBase(NULL), pszCode(NULL), pszData(NULL), pszDescription(NULL), 121 124 pszExeType(NULL), pszHeapSize(NULL), pszOld(NULL), pszProtmode(NULL), pszStackSize(NULL), 122 125 pszStub(NULL), pSegments(NULL), pImports(NULL), pExports(NULL), … … 125 128 chAppType(kFileDef::unknown) 126 129 { 127 /* determin file size */ 128 129 if (pFile->start()) 130 { 131 try 132 { 133 this->read(pFile); 134 } 135 catch (int err) 136 { 137 throw (err); 138 } 139 } 140 else 141 throw (0x001); 142 } 130 pFile->setThrowOnErrors(); 131 pFile->start(); 132 read(pFile); 133 } 143 134 144 135 … … 191 182 * @remark throws errorcode on error (TODO: errorhandling) 192 183 */ 193 void kFileDef::read(kFile *pFile) throw (int)184 void kFileDef::read(kFile *pFile) 194 185 { 195 186 char *pszTmp; … … 201 192 while (psz != NULL) 202 193 { 203 BOOLfNext = TRUE;194 KBOOL fNext = TRUE; 204 195 205 196 /* if-switch */ 206 197 if (StringCase(psz, "LIBRARY")) 207 198 { 208 if (pszType != NULL) throw ( 0x101);199 if (pszType != NULL) throw (kError(kError::DEF_MULIPLE_MODULE_STATEMENT)); 209 200 pszType = dupeString(psz); 210 201 fLibrary = TRUE; 211 202 if (!setModuleName()) 212 throw ( 0x107);203 throw (kError(kError::DEF_BAD_LIBRARY_STATEMENT)); 213 204 fInitInstance = stristr(pszType, "INITINSTANCE") != NULL; 214 205 fInitGlobal = stristr(pszType, "INITGLOBAL") != NULL || !fInitInstance; … … 218 209 else if (StringCase(psz, "NAME")) 219 210 { 220 if (pszType != NULL) throw ( 0x101);211 if (pszType != NULL) throw (kError(kError::DEF_MULIPLE_MODULE_STATEMENT)); 221 212 pszType = dupeString(psz); 222 213 fProgram = TRUE; … … 233 224 else if (StringCase(psz, "PHYSICAL DEVICE")) //gap is fixed to one space, this may be fixed in readln. 234 225 { 235 if (pszType != NULL) throw ( 0x101);226 if (pszType != NULL) throw (kError(kError::DEF_MULIPLE_MODULE_STATEMENT)); 236 227 pszType = dupeString(psz); 237 228 fPhysicalDevice = TRUE; … … 240 231 else if (StringCase(psz, "VIRTUAL DEVICE")) //gap is fixed to one space, this may be fixed in readln. 241 232 { 242 if (pszType != NULL) throw ( 0x101);233 if (pszType != NULL) throw (kError(kError::DEF_MULIPLE_MODULE_STATEMENT)); 243 234 pszType = dupeString(psz); 244 235 fVirtualDevice = TRUE; … … 301 292 { 302 293 (**ppi).ulOrdinal = strtol(psz, &pszTmp, 0); 303 if (psz ==pszTmp) throw (0x102);294 if (psz ==pszTmp) throw (kError(kError::DEF_BAD_IMPORT)); 304 295 } 305 296 else … … 355 346 psz = pszTmp + 1; 356 347 (**ppe).ulOrdinal = strtol(psz, &pszTmp, 0); 357 if (pszTmp == psz) throw ( 0x103);348 if (pszTmp == psz) throw (kError(kError::DEF_BAD_EXPORT)); 358 349 psz = trim(pszTmp); 359 350 … … 380 371 { /* 2 */ 381 372 (**ppe).cParam = strtol(psz, &pszTmp, 0); 382 if (pszTmp == psz) throw ( 0x104);373 if (pszTmp == psz) throw (kError(kError::DEF_BAD_EXPORT)); 383 374 } 384 375 } … … 391 382 } 392 383 else 393 throw (0x105);384 throw (kError(kError::DEF_UNKOWN_VERB)); 394 385 395 386 /* next ? */ … … 400 391 /* sanity check */ 401 392 if (pszType == NULL) 402 throw ( (int)0x106);393 throw (kError(kError::DEF_NO_MODULE_STATEMENT)); 403 394 } 404 395 … … 412 403 * @remark tabs are expanded. string is trimmed. comments removed. 413 404 */ 414 char *kFileDef::readln(kFile *pFile, char *pszBuffer, int cbBuffer) throw (int)405 char *kFileDef::readln(kFile *pFile, char *pszBuffer, int cbBuffer) 415 406 { 416 407 int i; … … 420 411 { 421 412 /* read line */ 422 if ( !pFile->readln(pszBuffer, cbBuffer))413 if (pFile->readln(pszBuffer, cbBuffer)) 423 414 { 424 415 if (!pFile->isEOF()) 425 throw ( 0x201);426 return FALSE;416 throw (kError(pFile->getLastError())); 417 return NULL; 427 418 } 428 419 … … 472 463 * @remark TODO - we are going to check WORDS. 473 464 */ 474 BOOL kFileDef::isKeyword(const char *psz)465 KBOOL kFileDef::isKeyword(const char *psz) 475 466 { 476 467 return psz != NULL … … 503 494 * @remark Assumes that pszBuffer is large enough. 504 495 */ 505 BOOL kFileDef::setModuleName(void)496 KBOOL kFileDef::setModuleName(void) 506 497 { 507 498 char *pszEnd; 508 499 char *pszStart; 509 500 510 assert(pszType);501 kASSERT(pszType); 511 502 512 503 /* skip the first word */ … … 534 525 * @param cchBuffer Size of the buffer (defaults to 260 chars). 535 526 */ 536 BOOL kFileDef::moduleGetName(char *pszBuffer, int cchSize/* = 260*/)527 KBOOL kFileDef::moduleGetName(char *pszBuffer, int cchSize/* = 260*/) 537 528 { 538 529 int cch; … … 554 545 * @param pExport Pointer to export structure. 555 546 */ 556 BOOLkFileDef::exportFindFirst(kExportEntry *pExport)547 KBOOL kFileDef::exportFindFirst(kExportEntry *pExport) 557 548 { 558 549 if (pExports != NULL && pExport != NULL) … … 581 572 * @param pExport Pointer to export structure. 582 573 */ 583 BOOLkFileDef::exportFindNext(kExportEntry *pExport)574 KBOOL kFileDef::exportFindNext(kExportEntry *pExport) 584 575 { 585 576 if (pExport != NULL && pExport->pv != NULL) … … 624 615 * @remark stub 625 616 */ 626 BOOL kFileDef::exportLookup(unsigned long ulOrdinal, kExportEntry *pExport)627 { 628 assert(!"not implemented.");617 KBOOL kFileDef::exportLookup(unsigned long ulOrdinal, kExportEntry *pExport) 618 { 619 kASSERT(!"not implemented."); 629 620 ulOrdinal = ulOrdinal; 630 621 pExport = pExport; … … 639 630 * @remark stub 640 631 */ 641 BOOL kFileDef::exportLookup(const char * pszName, kExportEntry *pExport)642 { 643 assert(!"not implemented.");632 KBOOL kFileDef::exportLookup(const char * pszName, kExportEntry *pExport) 633 { 634 kASSERT(!"not implemented."); 644 635 pszName = pszName; 645 636 pExport = pExport; … … 658 649 * @remark 659 650 */ 660 BOOL kFileDef::makeWatcomLinkFileAddtion(kFile *pFile) throw(int)651 KBOOL kFileDef::makeWatcomLinkFileAddtion(kFile *pOut) 661 652 { 662 653 PDEFSEGMENT pSeg; 663 654 PDEFIMPORT pImp; 664 655 PDEFEXPORT pExp; 665 p File->setThrowOnErrors();656 pOut->setThrowOnErrors(); 666 657 667 658 /* 668 659 * Write a little remark first to tell that converted stuff starts here. 669 660 */ 670 p File->printf("#\n# Directives generated from .DEF-file.\n#\n");661 pOut->printf("#\n# Directives generated from .DEF-file.\n#\n"); 671 662 672 663 /* Format - Module type */ 673 p File->printf("FORMAT OS2 LX %s %s %s\n",664 pOut->printf("FORMAT OS2 LX %s %s %s\n", 674 665 fLibrary ? "DLL" : 675 666 (fProgram ? (chAppType == pm ? "PM" … … 684 675 /* Module name */ 685 676 if (pszModName) 686 p File->printf("OPTION MODNAME=%s\n", pszModName);677 pOut->printf("OPTION MODNAME=%s\n", pszModName); 687 678 688 679 /* Description */ 689 680 if (pszDescription) 690 p File->printf("OPTION DESCRIPTION '%s'\n", pszDescription);681 pOut->printf("OPTION DESCRIPTION '%s'\n", pszDescription); 691 682 692 683 /* Base */ 693 684 if (pszBase) 694 p File->printf("OPTION OFFSET=%s\n", pszBase);685 pOut->printf("OPTION OFFSET=%s\n", pszBase); 695 686 696 687 /* Stub */ 697 688 if (pszStub) 698 p File->printf("OPTION STUB='%s'\n", pszStub);689 pOut->printf("OPTION STUB='%s'\n", pszStub); 699 690 700 691 /* Old */ 701 692 if (pszOld) 702 p File->printf("OPTION OLDLIBRARY=%s\n", pszOld);693 pOut->printf("OPTION OLDLIBRARY=%s\n", pszOld); 703 694 704 695 /* Protected mode */ 705 696 if (pszProtmode) 706 p File->printf("OPTION PROTMODE\n", pszProtmode);697 pOut->printf("OPTION PROTMODE\n", pszProtmode); 707 698 708 699 /* Stacksize */ 709 700 if (pszStackSize) 710 p File->printf("OPTION STACK=%s\n", pszStackSize);701 pOut->printf("OPTION STACK=%s\n", pszStackSize); 711 702 712 703 /* HeapSize */ 713 704 if (pszHeapSize) 714 p File->printf("OPTION HEAPSIZE=%s\n", pszHeapSize);705 pOut->printf("OPTION HEAPSIZE=%s\n", pszHeapSize); 715 706 716 707 /* Code - not supported */ … … 724 715 while (pSeg != NULL) 725 716 { 726 p File->printf("SEGMENT %s\n", pSeg->psz);717 pOut->printf("SEGMENT %s\n", pSeg->psz); 727 718 pSeg = pSeg->pNext; 728 719 } … … 735 726 { 736 727 if (pImp->pszName == NULL) 737 p File->printf("IMPORT '%s' '%s'.%d\n", pImp->pszIntName, pImp->pszDll, pImp->ulOrdinal);728 pOut->printf("IMPORT '%s' '%s'.%d\n", pImp->pszIntName, pImp->pszDll, pImp->ulOrdinal); 738 729 else 739 p File->printf("IMPORT '%s' '%s'.'%s'\n", pImp->pszIntName, pImp->pszDll, pImp->pszName);730 pOut->printf("IMPORT '%s' '%s'.'%s'\n", pImp->pszIntName, pImp->pszDll, pImp->pszName); 740 731 pImp = pImp->pNext; 741 732 } … … 747 738 while (pExp != NULL) 748 739 { 749 p File->printf("EXPORT '%s'", pExp->pszName);740 pOut->printf("EXPORT '%s'", pExp->pszName); 750 741 if (pExp->ulOrdinal != ~0UL) 751 p File->printf(".%d", pExp->ulOrdinal);742 pOut->printf(".%d", pExp->ulOrdinal); 752 743 if (pExp->pszIntName) 753 p File->printf("='%s'", pExp->pszIntName);744 pOut->printf("='%s'", pExp->pszIntName); 754 745 if (pExp->fResident) 755 p File->printf(" RESIDENT");746 pOut->printf(" RESIDENT"); 756 747 if (pExp->cParam != ~0UL) 757 p File->printf(" %d", pExp->cParam * 2); /* .DEFs this is number of words. Watcom should have bytes. */758 p File->printf("\n");748 pOut->printf(" %d", pExp->cParam * 2); /* .DEFs this is number of words. Watcom should have bytes. */ 749 pOut->printf("\n"); 759 750 pExp = pExp->pNext; 760 751 } -
trunk/tools/common/kFileDef.h
r5531 r8003 50 50 char *pszName; 51 51 char *pszIntName; 52 BOOLfResident;52 KBOOL fResident; 53 53 unsigned long cParam; 54 54 struct _DefExport *pNext; … … 66 66 /**@cat pointers to different sections */ 67 67 char *pszType; 68 BOOLfProgram;69 BOOLfLibrary;70 BOOLfPhysicalDevice;71 BOOLfVirtualDevice;72 BOOLfInitInstance;73 BOOLfTermInstance;74 BOOLfInitGlobal;75 BOOLfTermGlobal;68 KBOOL fProgram; 69 KBOOL fLibrary; 70 KBOOL fPhysicalDevice; 71 KBOOL fVirtualDevice; 72 KBOOL fInitInstance; 73 KBOOL fTermInstance; 74 KBOOL fInitGlobal; 75 KBOOL fTermGlobal; 76 76 char *pszModName; 77 77 char chAppType; … … 94 94 95 95 /**@cat internal functions */ 96 void read(kFile *pFile) throw ( int);97 char *readln(kFile *pFile, char *pszBuffer, int cbBuffer) throw ( int);98 BOOLisKeyword(const char *psz);99 BOOLsetModuleName(void);96 void read(kFile *pFile) throw (kError); 97 char *readln(kFile *pFile, char *pszBuffer, int cbBuffer) throw (kError); 98 KBOOL isKeyword(const char *psz); 99 KBOOL setModuleName(void); 100 100 101 101 public: 102 102 /**@cat Constructor/Destructor */ 103 kFileDef(kFile *pFile) throw( int);103 kFileDef(kFile *pFile) throw(kError); 104 104 virtual ~kFileDef(); 105 105 106 106 /** @cat Module information methods. */ 107 BOOLmoduleGetName(char *pszBuffer, int cchSize = 260);107 KBOOL moduleGetName(char *pszBuffer, int cchSize = 260); 108 108 109 109 /** @cat Export enumeration methods. */ 110 BOOLexportFindFirst(kExportEntry *pExport);111 BOOLexportFindNext(kExportEntry *pExport);110 KBOOL exportFindFirst(kExportEntry *pExport); 111 KBOOL exportFindNext(kExportEntry *pExport); 112 112 void exportFindClose(kExportEntry *pExport); 113 113 114 114 /** @cat Export Lookup methods */ 115 BOOLexportLookup(unsigned long ulOrdinal, kExportEntry *pExport);116 BOOLexportLookup(const char * pszName, kExportEntry *pExport);115 KBOOL exportLookup(unsigned long ulOrdinal, kExportEntry *pExport); 116 KBOOL exportLookup(const char * pszName, kExportEntry *pExport); 117 117 118 118 /**@cat queries... */ 119 BOOLisDef() const { return TRUE;}119 KBOOL isDef() const { return TRUE;} 120 120 char const *queryModuleName(void) const { return pszModName; } 121 121 char const *queryType(void) const { return pszType; } … … 132 132 133 133 /**@cat Operations */ 134 BOOL makeWatcomLinkFileAddtion(kFile *pFile) throw(int);134 KBOOL makeWatcomLinkFileAddtion(kFile *pFile) throw(kError); 135 135 136 136 enum {fullscreen = 0, pmvio = 2, pm = 3, unknown = 255}; -
trunk/tools/common/kFileFormatBase.cpp
r6066 r8003 1 /* $Id: kFileFormatBase.cpp,v 1. 5 2001-06-22 17:07:47bird Exp $1 /* $Id: kFileFormatBase.cpp,v 1.6 2002-02-24 02:47:25 bird Exp $ 2 2 * 3 3 * kFileFormatBase - Base class for kFile<format> classes. 4 4 * 5 * Copyright (c) 1999-200 0 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)5 * Copyright (c) 1999-2001 knut st. osmundsen (knut.stange.osmundsen@mynd.no) 6 6 * 7 7 * Project Odin Software License can be found in LICENSE.TXT … … 14 14 * Header Files * 15 15 *******************************************************************************/ 16 #include <os2.h> 16 #include "kTypes.h" 17 #include "kError.h" 18 #include "kFile.h" 19 #include "kFileInterfaces.h" 20 #include "kFileFormatBase.h" 17 21 18 #include <malloc.h>19 #include <string.h>20 #include <stdio.h>21 22 22 #include "kFile.h" 23 #include "kInterfaces.h" 24 #include "kFileFormatBase.h" 23 24 /** 25 * Constructor. 26 * Saves the file object pointer. 27 * @param pFile This will be deleted if the object is 28 * successfully constructed (by the destructor). 29 * @status completely implemented. 30 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 31 */ 32 kFileFormatBase::kFileFormatBase(kFile *pFile) 33 : pFile(pFile) 34 { 35 } 36 37 38 /** 39 * Destructor. 40 * Deletes the file object if it exists. 41 * @status completely implemented. 42 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 43 */ 44 kFileFormatBase::~kFileFormatBase() 45 { 46 if (pFile) 47 delete pFile; 48 pFile = NULL; 49 } 25 50 26 51 … … 30 55 * @param pOut Output file. 31 56 */ 32 BOOL kFileFormatBase::dump(kFile *pOut)57 KBOOL kFileFormatBase::dump(kFile *pOut) 33 58 { 34 59 pOut->printf("Sorry, dump() is not implemented for this file format.\n"); … … 36 61 } 37 62 38 39 kFileFormatBase::~kFileFormatBase()40 {41 42 }43 -
trunk/tools/common/kFileFormatBase.h
r6066 r8003 1 /* $Id: kFileFormatBase.h,v 1. 6 2001-06-22 17:07:47bird Exp $1 /* $Id: kFileFormatBase.h,v 1.7 2002-02-24 02:47:25 bird Exp $ 2 2 * 3 3 * kFileFormatBase - Base class for kFile<format> classes. … … 33 33 { 34 34 public: 35 virtual KBOOL isDef() const { return FALSE;} 36 virtual KBOOL isPe() const { return FALSE;} 37 virtual KBOOL isLx() const { return FALSE;} 38 virtual KBOOL dump(kFile *pOut); 35 39 36 virtual ~kFileFormatBase(); 40 kFileFormatBase(kFile *pFile) throw (kError); 41 virtual ~kFileFormatBase() throw (kError); 37 42 38 virtual BOOL isDef() const { return FALSE;} 39 virtual BOOL isPe() const { return FALSE;} 40 virtual BOOL isLx() const { return FALSE;} 41 virtual BOOL dump(kFile *pOut); 42 43 protected: 44 kFile *pFile; 43 45 }; 44 46 -
trunk/tools/common/kFileLX.cpp
r6932 r8003 1 /* $Id: kFileLX.cpp,v 1. 6 2001-10-03 01:44:49bird Exp $1 /* $Id: kFileLX.cpp,v 1.7 2002-02-24 02:47:26 bird Exp $ 2 2 * 3 3 * … … 9 9 */ 10 10 11 /*******************************************************************************12 * Defined Constants *13 *******************************************************************************/14 /* emx fixups */15 #ifdef __EMX__16 #define __stdcall17 #define max(a,b) (((a) > (b)) ? (a) : (b))18 #define min(a,b) (((a) < (b)) ? (a) : (b))19 #endif20 #define INCL_DOSERRORS21 #define FOR_EXEHDR 1 /* exe386.h flag */22 #define DWORD ULONG /* Used by exe386.h / newexe.h */23 #define WORD USHORT /* Used by exe386.h / newexe.h */24 25 26 11 /****************************************************************************** 27 12 * Header Files * 28 13 ******************************************************************************/ 29 #ifdef __EMX__ 30 #define INT INT_ 31 #define PCHAR PCHAR_ 32 #endif 33 #include <os2.h> 34 #ifdef __EMX__ 35 #undef PCHAR 36 #undef INT 37 #endif 38 #include <newexe.h> 39 #include <exe386.h> 14 #include <MZexe.h> 15 #include <LXexe.h> 40 16 41 17 #include <stdio.h> 42 18 #include <stdlib.h> 43 19 #include <string.h> 44 #include <malloc.h> 45 46 #include <assert.h> 47 20 21 #include "kTypes.h" 22 #include "kError.h" 48 23 #include "kFile.h" 49 24 #include "kFileFormatBase.h" 50 #include "k Interfaces.h"25 #include "kFileInterfaces.h" 51 26 #include "kFileLX.h" 52 27 … … 55 30 * Structures and Typedefs * 56 31 *******************************************************************************/ 57 typedef struct _ export_state32 typedef struct _LXExportState 58 33 { 59 34 struct b32_bundle * pb32; /* Pointer to current bundle. */ … … 62 37 int iOrdinal; /* The current ordinal. */ 63 38 } EXPSTATE, *PEXPSTATE; 39 40 41 /** 42 * relocFind*() state info. 43 * Stored as kRelocEntry::pv1. 44 */ 45 typedef struct _LXRelocState 46 { 47 unsigned long ulSegment; /* The current segment. (0-based) */ 48 unsigned long ulPage; /* The current page. (0-based index) */ 49 char * pchFixupRec; /* The current fixup record. */ 50 unsigned short usSrcOffIdx; /* The current source offset index. (0-based) */ 51 } LXRELOCSTATE, *PLXRELOCSTATE; 64 52 65 53 … … 72 60 73 61 62 /******************************************************************************* 63 * Internal Functions * 64 *******************************************************************************/ 65 inline void memcpyw(char *pch1, const char *pch2, size_t cch); 66 inline void memcpyb(char *pch1, const char *pch2, size_t cch); 67 68 74 69 /** 75 70 * Internal worker which lookup the name corresponding to an ordinal. … … 78 73 * @param pszBuffer. 79 74 */ 80 BOOL kFileLX::queryExportName(int iOrdinal, char *pszBuffer)81 { 82 PUSHORTpus;83 PUCHARpuch;75 KBOOL kFileLX::queryExportName(int iOrdinal, char *pszBuffer) 76 { 77 unsigned short *pus; 78 unsigned char * puch; 84 79 85 80 /* resident name table */ 86 81 if (pe32->e32_restab) 87 82 { 88 puch = ( PUCHAR)pvBase + offLXHdr + pe32->e32_restab;83 puch = (unsigned char *)pvBase + offLXHdr + pe32->e32_restab; 89 84 while (*puch != 0) 90 85 { 91 pus = ( PUSHORT)(puch + 1 + *puch);86 pus = (unsigned short *)(puch + 1 + *puch); 92 87 if (*pus == iOrdinal) 93 88 { … … 103 98 if (pe32->e32_nrestab) 104 99 { 105 puch = ( PUCHAR)pvBase + pe32->e32_nrestab;100 puch = (unsigned char *)pvBase + pe32->e32_nrestab; 106 101 while (*puch != 0) 107 102 { 108 pus = ( PUSHORT)(puch + 1 + *puch);103 pus = (unsigned short *)(puch + 1 + *puch); 109 104 if (*pus == iOrdinal) 110 105 { … … 120 115 } 121 116 117 /** 118 * Converts a FLAT address to an obj:offset address. 119 * @returns The offset into the object. 120 * -1 (0xffffffff) on error. 121 * @param ulAddress Address to map. 122 * @param pulObject Pointer to variable which will receive the object number (0-based). 123 */ 124 unsigned long kFileLX::lxAddressToObjectOffset(unsigned long ulAddress, unsigned long * pulObject) const 125 { 126 int i; 127 128 /* look for a object which contains the given address */ 129 for (i = 0; i < pe32->e32_objcnt; i++) 130 { 131 if ( paObject[i].o32_base <= ulAddress 132 && paObject[i].o32_base + paObject[i].o32_size > ulAddress) 133 { 134 if (pulObject) 135 *pulObject = i; 136 return ulAddress - paObject[i].o32_base; 137 } 138 } 139 140 return ~0UL; /* not found */ 141 } 142 143 144 /** 145 * Converts an sel:off address, where sel is one of the special selectors, 146 * to a obj:off address. 147 * @returns The offset into the object. 148 * -1 (0xffffffff) on error. 149 * @param offObject Offset into the selector described by *pulObject. 150 * @param pulObject IN: Special selector. 151 * OUT: Pointer to variable which will receive the object number (0-based). 152 */ 153 unsigned long kFileLX::lxSpecialSelectorToObjectOffset(unsigned long offObject, unsigned long * pulObject) const 154 { 155 switch (*pulObject) 156 { 157 case kRelocEntry::enmRVASelector: 158 return lxAddressToObjectOffset(offObject + paObject[0].o32_base, pulObject); 159 160 case kRelocEntry::enmVASelector: 161 return lxAddressToObjectOffset(offObject, pulObject); 162 163 default: 164 kASSERT(!"Internal error line"); 165 } 166 167 return ~0UL; 168 } 169 170 171 /** 172 * Validates a FLAT address. 173 * @returns TRUE if valid, FALSE if invalid. 174 * @param ulAddress FLAT address to validate. 175 */ 176 KBOOL kFileLX::lxValidateAddress(unsigned long ulAddress) const 177 { 178 int i; 179 180 /* look for a object which contains the given address */ 181 for (i = 0; i < pe32->e32_objcnt; i++) 182 { 183 if ( paObject[i].o32_base <= ulAddress 184 && paObject[i].o32_base + paObject[i].o32_size > ulAddress) 185 { 186 return TRUE; 187 } 188 } 189 190 return FALSE; 191 } 192 193 194 /** 195 * Validates a object:offset address. 196 * @returns TRUE if valid, FALSE if invalid. 197 * @param ulObject Object number. (0-based) 198 * @param offObject Offset into that object. 199 */ 200 KBOOL kFileLX::lxValidateObjectOffset(unsigned long ulObject, unsigned long offObject) const 201 { 202 return pe32->e32_objcnt > ulObject && offObject < paObject[ulObject].o32_size; 203 } 204 205 206 207 /** 208 * Gets the module name corresponding to the given ordinal. 209 * @returns Pointer to sz of the modulename. The caller is responsible for freeing it. 210 * NULL if invalid ordinal. 211 * @param ordModule Ordinal number of the module name. (1-based) 212 */ 213 char *kFileLX::lxGetImportModuleName(unsigned long ordModule) const 214 { 215 if (pe32->e32_impmodcnt < ordModule) 216 return NULL; 217 218 char *pch = (char*)pe32 + pe32->e32_impmod; 219 while (--ordModule) 220 pch += *pch + 1; 221 222 if (!*pch) 223 return NULL; 224 225 /* Copy the module name. */ 226 char *psz = new char[*pch + 1]; 227 strncpy(psz, pch + 1, *pch); 228 psz[*pch] = '\0'; 229 return psz; 230 } 231 232 233 /** 234 * Gets the proc name at the given offset. 235 * @returns Pointer to sz of the proc name. The caller is responsible for freeing it. 236 * NULL if invalid offset. 237 * @param offProc Offset of the proc name. 238 */ 239 char *kFileLX::lxGetImportProcName(unsigned long offProc) const 240 { 241 char *pch = (char*)pe32 + pe32->e32_impproc + offProc; 242 if (!*pch) 243 return NULL; 244 245 /* Copy the proc name. */ 246 char *psz = new char[*pch + 1]; 247 strncpy(psz, pch + 1, *pch); 248 psz[*pch] = '\0'; 249 return psz; 250 } 251 122 252 123 253 … … 126 256 * @param pszFilename LX executable image name. 127 257 */ 128 kFileLX::kFileLX(const char *pszFilename) throw (int)129 :pvBase(NULL)258 kFileLX::kFileLX(const char *pszFilename) : 259 kFileFormatBase(NULL), pvBase(NULL) 130 260 { 131 261 struct exe_hdr * pehdr; 132 262 133 263 /* create filemapping */ 134 pvBase = kFile::readFile(pszFilename); 135 if (pvBase == NULL) 136 throw(1); 137 264 pvBase = kFile::mapFile(pszFilename); 138 265 pehdr = (struct exe_hdr*)pvBase; 139 266 if (pehdr->e_magic == EMAGIC) … … 143 270 144 271 pe32 = (struct e32_exe*)((char*)pvBase + offLXHdr); 145 if (*( PUSHORT)pe32 != E32MAGIC)146 { 147 free(pvBase);272 if (*(unsigned short *)pe32 != E32MAGIC) 273 { 274 kFile::mapFree(pvBase); 148 275 pvBase = NULL; 149 throw( 2);276 throw(kError(kError::INVALID_EXE_SIGNATURE)); 150 277 } 151 278 152 279 paObject = pe32->e32_objtab && pe32->e32_objcnt 153 ? (struct o32_obj *)((char*)pvBase + pe32->e32_objtab + offLXHdr) : NULL;280 ? (struct o32_obj *)((char *)pe32 + pe32->e32_objtab) : NULL; 154 281 paMap = pe32->e32_objmap 155 ? (struct o32_map*)((char*)pvBase + pe32->e32_objmap + offLXHdr) : NULL; 282 ? (struct o32_map *)((char *)pe32 + pe32->e32_objmap) : NULL; 283 paulFixupPageTable = pe32->e32_fpagetab 284 ? (unsigned long *)((char *)pe32 + pe32->e32_fpagetab) : NULL; 285 pchFixupRecs = pe32->e32_frectab 286 ? (char *)((char *)pe32 + pe32->e32_frectab) : NULL; 156 287 } 157 288 … … 161 292 * @param pFile Pointer to opened LX file. 162 293 */ 163 kFileLX::kFileLX(kFile *pFile) throw (int)164 :pvBase(NULL)294 kFileLX::kFileLX(kFile *pFile) : 295 kFileFormatBase(pFile), pvBase(NULL) 165 296 { 166 297 struct exe_hdr * pehdr; 167 298 168 299 /* create filemapping */ 169 pvBase = pFile->readFile(); 170 if (pvBase == NULL) 171 throw(1); 300 pFile->setThrowOnErrors(); 301 pvBase = pFile->mapFile(); 172 302 173 303 pehdr = (struct exe_hdr*)pvBase; … … 178 308 179 309 pe32 = (struct e32_exe*)((char*)pvBase + offLXHdr); 180 if (*( PUSHORT)pe32 != E32MAGIC)181 { 182 free(pvBase);310 if (*(unsigned short *)pe32 != E32MAGIC) 311 { 312 kFile::mapFree(pvBase); 183 313 pvBase = NULL; 184 throw( 2);314 throw(kError(kError::INVALID_EXE_SIGNATURE)); 185 315 } 186 316 187 317 paObject = pe32->e32_objtab && pe32->e32_objcnt 188 ? (struct o32_obj *)((char*)pvBase + pe32->e32_objtab + offLXHdr) : NULL;318 ? (struct o32_obj *)((char *)pe32 + pe32->e32_objtab) : NULL; 189 319 paMap = pe32->e32_objmap 190 ? (struct o32_map*)((char*)pvBase + pe32->e32_objmap + offLXHdr) : NULL; 320 ? (struct o32_map *)((char *)pe32 + pe32->e32_objmap) : NULL; 321 paulFixupPageTable = pe32->e32_fpagetab 322 ? (unsigned long *)((char *)pe32 + pe32->e32_fpagetab) : NULL; 323 pchFixupRecs = pe32->e32_frectab 324 ? (char *)((char *)pe32 + pe32->e32_frectab) : NULL; 191 325 } 192 326 … … 199 333 { 200 334 if (pvBase != NULL) 201 free(pvBase);335 kFile::mapFree(pvBase); 202 336 pvBase = NULL; 203 337 } … … 211 345 * @param cchBuffer Size of the buffer (defaults to 260 chars). 212 346 */ 213 BOOL kFileLX::moduleGetName(char *pszBuffer, int cchBuffer/*= 260*/)347 KBOOL kFileLX::moduleGetName(char *pszBuffer, int cchBuffer/*= 260*/) 214 348 { 215 349 /* The module name is the 0 ordinal entry in resident name table */ 216 assert(cchBuffer >= 255);350 kASSERT(cchBuffer >= 255); 217 351 return queryExportName(0, pszBuffer); 218 352 } … … 224 358 * @param pExport Pointer to export structure. 225 359 */ 226 BOOL kFileLX::exportFindFirst(kExportEntry *pExport)360 KBOOL kFileLX::exportFindFirst(kExportEntry *pExport) 227 361 { 228 362 struct b32_bundle * pBundle = (struct b32_bundle*)((char*)pvBase + pe32->e32_enttab + offLXHdr); … … 274 408 break; 275 409 default: 276 assert(!"ARG!!!! invalid bundle type!");410 kASSERT(!"ARG!!!! invalid bundle type!"); 277 411 } 278 412 279 413 /* store status - current export entry */ 280 PEXPSTATE pExpState = (PEXPSTATE)malloc(sizeof(EXPSTATE));414 PEXPSTATE pExpState = new EXPSTATE; 281 415 pExport->pv = pExpState; 282 416 pExpState->pb32 = pBundle; … … 300 434 * @param pExport Pointer to export structure. 301 435 */ 302 BOOL kFileLX::exportFindNext(kExportEntry *pExport)436 KBOOL kFileLX::exportFindNext(kExportEntry *pExport) 303 437 { 304 438 static int acbEntry[] = … … 357 491 pExpState->pb32 = (struct b32_bundle*)((char*)(pExpState->pb32 + 1) + 358 492 pExpState->pb32->b32_cnt * acbEntry[pExpState->pb32->b32_type & ~TYPEINFO]); 359 pExpState->iOrdinal++;360 493 while (pExpState->pb32->b32_cnt != 0) 361 494 { 362 495 /* skip empty bundles */ 363 if(pExpState->pb32->b32_cnt != 0 && pExpState->pb32->b32_type == EMPTY)496 while (pExpState->pb32->b32_cnt != 0 && pExpState->pb32->b32_type == EMPTY) 364 497 { 365 498 pExpState->iOrdinal += pExpState->pb32->b32_cnt; 366 499 pExpState->pb32 = (struct b32_bundle*)((char*)pExpState->pb32 + 2); 367 continue;368 500 } 369 501 370 502 /* FIXME forwarders are not implemented so we'll skip them too. */ 371 if(pExpState->pb32->b32_cnt != 0 && (pExpState->pb32->b32_type & ~TYPEINFO) == ENTRYFWD)503 while (pExpState->pb32->b32_cnt != 0 && (pExpState->pb32->b32_type & ~TYPEINFO) == ENTRYFWD) 372 504 { 373 505 pExpState->iOrdinal += pExpState->pb32->b32_cnt; 374 506 pExpState->pb32 = (struct b32_bundle*)((char*)(pExpState->pb32 + 1) + pExpState->pb32->b32_cnt * 7); 375 continue;376 507 } 377 508 … … 403 534 pExport->ulOffset = pExpState->pe32->e32_variant.e32_callgate.offset; 404 535 break; 405 406 536 default: 407 assert(!"ARG!!!! invalid bundle type!");537 kASSERT(!"ARG!!!! invalid bundle type!"); 408 538 } 409 539 … … 430 560 void kFileLX::exportFindClose(kExportEntry *pExport) 431 561 { 432 free(pExport->pv);562 delete pExport->pv; 433 563 pExport->pv = NULL; 434 564 return; … … 443 573 * @remark stub 444 574 */ 445 BOOL kFileLX::exportLookup(unsigned long ulOrdinal, kExportEntry *pExport)446 { 447 assert(!"not implemented.");575 KBOOL kFileLX::exportLookup(unsigned long ulOrdinal, kExportEntry *pExport) 576 { 577 kASSERT(!"not implemented."); 448 578 ulOrdinal = ulOrdinal; 449 579 pExport = pExport; … … 458 588 * @remark stub 459 589 */ 460 BOOL kFileLX::exportLookup(const char * pszName, kExportEntry *pExport)461 { 462 assert(!"not implemented.");590 KBOOL kFileLX::exportLookup(const char * pszName, kExportEntry *pExport) 591 { 592 kASSERT(!"not implemented."); 463 593 pszName = pszName; 464 594 pExport = pExport; … … 490 620 } 491 621 492 #if 0 493 494 /** @cat Get and put page methods. (the first ones are generic) */ 495 BOOL kFileLX::getPage(char *pachPage, ULONG ulAddress) 622 623 /** 624 * Get a code, data or resource page from the file. 625 * @returns 0 on success. kError number on error. 626 * @param pachPage Pointer to a buffer of the size of a page which 627 * will receive the page data on the specified address. 628 * @param ulAddress Page address. This must be page aligned. 629 */ 630 int kFileLX::pageGet(char *pachPage, unsigned long ulAddress) const 496 631 { 497 632 int iObj; 498 633 499 634 for (iObj = 0; iObj < pe32->e32_objcnt; iObj++) 500 if ( paObject[iObj].o32_base >ulAddress635 if ( paObject[iObj].o32_base <= ulAddress 501 636 && paObject[iObj].o32_base + paObject[iObj].o32_size > ulAddress 502 637 ) 503 return getPage(pachPage, iObj, ulAddress - paObject[iObj].o32_base); 504 505 return FALSE; 506 } 507 508 BOOL kFileLX::getPage(char *pachPage, int iObject, int offObject) 509 { 510 offObject &= ~(PAGESIZE - 1); 511 if ( iObject >= pe32->e32_objcnt 512 && offObject >= paObject[iObject].o32_size 513 ) 514 return FALSE; 638 return pageGet(pachPage, iObj, ulAddress - paObject[iObj].o32_base); 639 640 return kError::INVALID_ADDRESS; 641 } 642 643 /** 644 * Get a code, data or resource page from the file. 645 * @returns 0 on success. kError number on error. 646 * @param pachPage Pointer to a buffer of the size of a page which 647 * will receive the page data on the specified address. 648 * @param iSegment Segment number. (0-based) 649 * @param offObject Offset into the object. This must be page aligned. 650 * @remark Object = Section. 651 */ 652 int kFileLX::pageGet(char *pachPage, int iSegment, int offObject) const 653 { 654 /* 655 * Validation. 656 */ 657 if (offObject & (pe32->e32_pagesize - 1)) 658 return kError::BAD_ALIGNMENT; 659 if (iSegment >= pe32->e32_objcnt) 660 return kError::INVALID_SEGMENT_NUMBER; 661 if (offObject >= paObject[iSegment].o32_size) 662 return kError::INVALID_OFFSET; 515 663 516 664 /* 517 665 * Is there a pagemap entry for the requested page? 518 666 */ 519 if ((offObject >> PAGESHIFT) < paObject[iObject].o32_mapsize)667 if ((offObject / pe32->e32_pagesize) < paObject[iSegment].o32_mapsize) 520 668 { /* yes */ 521 int iPage = (offObject >> PAGESIZE) + paObject[iObject].o32_pagemap - 1;669 int iPage = (offObject / pe32->e32_pagesize) + paObject[iSegment].o32_pagemap - 1; 522 670 char * pchPageData = (char*)((paMap[iPage].o32_pagedataoffset << pe32->e32_pageshift) + pe32->e32_datapage + (char*)pvBase); 523 671 524 if (pchPageData)672 switch (paMap[iPage].o32_pageflags) 525 673 { 674 case VALID: 675 memcpy(pachPage, pchPageData, paMap[iPage].o32_pagesize); 676 if (paMap[iPage].o32_pagesize < pe32->e32_pagesize) 677 memset(pachPage + paMap[iPage].o32_pagesize, 0, pe32->e32_pagesize - paMap[iPage].o32_pagesize); 678 break; 679 680 case ITERDATA: 681 { 682 char achTempBuffer[0x1004]; 683 memcpy(achTempBuffer, pchPageData, paMap[iPage].o32_pagesize); 684 memset(achTempBuffer + paMap[iPage].o32_pagesize, 0, 4); 685 return kFileLX::expandPage1(pachPage, pe32->e32_pagesize, achTempBuffer, paMap[iPage].o32_pagesize); 686 } 687 688 case INVALID: 689 return kError::INVALID_PAGE; 690 691 case ZEROED: 692 memset(pachPage, 0, pe32->e32_pagesize); 693 break; 694 695 case ITERDATA2: 696 { 697 char achTempBuffer[0x1004]; 698 memcpy(achTempBuffer, pchPageData, paMap[iPage].o32_pagesize); 699 memset(achTempBuffer + paMap[iPage].o32_pagesize, 0, 4); 700 return kFileLX::expandPage2(pachPage, pe32->e32_pagesize, achTempBuffer, paMap[iPage].o32_pagesize); 701 } 702 703 case RANGE: 704 default: 705 return kError::BAD_EXE_FORMAT; 526 706 } 527 707 528 708 } 529 709 else 530 { /* no, so it's a zero page */ 531 memset(pachPage, 0, PAGESIZE); 532 } 533 534 return FALSE; 535 } 536 537 BOOL kFileLX::putPage(const char *pachPage, ULONG ulAddress) 538 { 539 return FALSE; 540 } 541 542 BOOL kFileLX::putPage(const char *pachPage, int iObject, int offObject) 543 { 544 return FALSE; 545 } 546 547 BOOL kFileLX::getPageLX(char *pachPage, int iObject, int iPage) 548 { 549 return FALSE; 550 } 551 552 BOOL kFileLX::getPageLX(char *pachPage, int iPage) 553 { 554 return FALSE; 555 } 556 557 BOOL kFileLX::putPageLX(const char *pachPage, int iObject, int iPage) 558 { 559 return FALSE; 560 } 561 562 BOOL kFileLX::putPageLX(const char *pachPage, int iPage) 563 { 564 return FALSE; 710 { /* no, so it's a zerofilled page */ 711 memset(pachPage, 0, pe32->e32_pagesize); 712 } 713 714 return 0; 715 } 716 717 718 /** 719 * Updates or adds a code, data, or resource page to the file. 720 * @returns 0 on success. kError number on error. 721 * @param pachPage Pointer to a buffer of the size of a page which 722 * holds the page data. 723 * @param ulAddress Page address. This must be page aligned. 724 */ 725 int kFileLX::pagePut(const char *pachPage, unsigned long ulAddress) 726 { 727 int iObj; 728 729 for (iObj = 0; iObj < pe32->e32_objcnt; iObj++) 730 if ( paObject[iObj].o32_base <= ulAddress 731 && paObject[iObj].o32_base + paObject[iObj].o32_size > ulAddress 732 ) 733 return pagePut(pachPage, iObj, ulAddress - paObject[iObj].o32_base); 734 735 return kError::INVALID_ADDRESS; 736 } 737 738 739 /** 740 * Updates or adds a code, data, or resource page to the file. 741 * @returns 0 on success. kError number on error. 742 * @param pachPage Pointer to a buffer of the size of a page which 743 * holds the page data. 744 * @param iSegment Segment number. (0-based) 745 * @param offObject Offset into the object. This must be page aligned. 746 */ 747 int kFileLX::pagePut(const char *pachPage, int iSegment, int offObject) 748 { 749 /* 750 * Validation. 751 */ 752 if (offObject & (pe32->e32_pagesize - 1)) 753 return kError::BAD_ALIGNMENT; 754 if (iSegment >= pe32->e32_objcnt) 755 return kError::INVALID_SEGMENT_NUMBER; 756 if (offObject >= paObject[iSegment].o32_size) 757 return kError::INVALID_OFFSET; 758 759 /* 760 * Is there a pagemap entry for the page? 761 */ 762 if ((offObject / pe32->e32_pagesize) < paObject[iSegment].o32_mapsize) 763 { /* yes */ 764 int iPage = (offObject / pe32->e32_pagesize) + paObject[iSegment].o32_pagemap - 1; 765 char * pchPageData = (char*)((paMap[iPage].o32_pagedataoffset << pe32->e32_pageshift) + pe32->e32_datapage + (char*)pvBase); 766 const char *pchPageToWrite = NULL; 767 int cchPageToWrite = 0; 768 long offPageToWrite = (paMap[iPage].o32_pagedataoffset << pe32->e32_pageshift) + pe32->e32_datapage; 769 770 switch (paMap[iPage].o32_pageflags) 771 { 772 case VALID: 773 pchPageToWrite = pachPage; 774 cchPageToWrite = 0x1000; 775 if (paMap[iPage].o32_pagesize != 0x1000) 776 { 777 /* 778 * Check that everything after pagesize is zero. 779 */ 780 for (const char *pch = &pachPage[paMap[iPage].o32_pagesize]; pch < &pachPage[0x1000]; pch++) 781 if (*pch) 782 return kError::NOT_SUPPORTED; 783 cchPageToWrite = paMap[iPage].o32_pagesize; 784 } 785 break; 786 787 case ITERDATA: 788 case ITERDATA2: 789 { 790 char * pchCompressedPage = (char*)alloca(pe32->e32_pagesize+4); 791 792 /* remove spaces at the end of the page. */ 793 int cchPage = pe32->e32_pagesize; 794 while (pachPage[cchPage-1] == '\0') 795 cchPage--; 796 797 /* call the compression function */ 798 if (paMap[iPage].o32_pageflags == ITERDATA) 799 cchPageToWrite = kFileLX::compressPage1(pchCompressedPage, pachPage, cchPage); 800 else 801 cchPageToWrite = kFileLX::compressPage2(pchCompressedPage, pachPage, cchPage); 802 //if (cchPageToWrite != paMap[iPage].o32_pagesize) 803 // printf("compressPageX returned %d (%x) previous size %d (%x)\n", cchPageToWrite, cchPageToWrite, paMap[iPage].o32_pagesize, paMap[iPage].o32_pagesize); 804 if (cchPageToWrite < 0) 805 return kError::NOT_SUPPORTED; 806 #if 0 807 int cbLeft = KMIN(2, paMap[iPage].o32_pagesize - cchPageToWrite); 808 if (cbLeft > 0) 809 { 810 memset(&pchCompressedPage[cchPageToWrite], 0, cbLeft); 811 cchPageToWrite += cbLeft; 812 } 813 #else 814 kASSERT(paMap[iPage].o32_pagesize - cchPageToWrite >= 0); 815 memset(&pchCompressedPage[cchPageToWrite], 0, paMap[iPage].o32_pagesize - cchPageToWrite); 816 cchPageToWrite = paMap[iPage].o32_pagesize; 817 #endif 818 pchPageToWrite = pchCompressedPage; 819 break; 820 } 821 822 case ZEROED: 823 { 824 /* 825 * If the passed in page is not a zero page we'll fail. 826 */ 827 for (unsigned long * pul = (unsigned long *)pachPage; (char*)pul < &pachPage[0x1000]; pul++) 828 if (*pul) 829 return kError::NOT_SUPPORTED; 830 return 0; 831 } 832 833 case INVALID: 834 return kError::INVALID_PAGE; 835 836 case RANGE: 837 default: 838 return kError::BAD_EXE_FORMAT; 839 } 840 841 /* 842 * Write stuff to file. 843 */ 844 pFile->setFailOnErrors(); 845 return pFile->writeAt((void*)pchPageToWrite, cchPageToWrite, offPageToWrite); 846 } 847 else 848 { /* 849 * No, it's a zerofilled page 850 * If the passed in page is not a zero page we'll fail. 851 */ 852 for (unsigned long * pul = (unsigned long *)pachPage; (char*)pul < &pachPage[0x1000]; pul++) 853 if (*pul) 854 return kError::NOT_SUPPORTED; 855 } 856 857 return 0; 858 } 859 860 861 /** 862 * Get pagesize for the file. 863 * @returns Pagesize in bytes. 864 */ 865 int kFileLX::pageGetPageSize() const 866 { 867 return pe32->e32_pagesize; 565 868 } 566 869 … … 569 872 * Expands a page compressed with the old exepack method introduced with OS/2 2.0. 570 873 * (/EXEPACK or just /EXEPACK) 571 * @returns Successindicator.572 * @param pachPage Pointer to output page. size: PAGESIZE874 * @returns 0 on success. kError error code on error. 875 * @param pachPage Pointer to output page. size: cchPage 573 876 * Upon successful return this will contain the expanded page data. 877 * @param cchPage Page size. 574 878 * @param pachSrcPage Pointer to source data. size: cchSrcPage. 575 879 * This data should be compressed with EXEPACK:2! 880 * @param cchSrcPage Size of compressed data. 576 881 * @sketch Have no good idea right now. 577 882 * @status Completely implemented. … … 579 884 * @remark 580 885 */ 581 BOOL kFileLX::expandPage1(char *pachPage, const char * pachSrcPage, int cchSrcPage)886 int kFileLX::expandPage1(char *pachPage, int cchPage, const char * pachSrcPage, int cchSrcPage) 582 887 { 583 888 struct LX_Iter *pIter = (struct LX_Iter *)pachSrcPage; … … 585 890 586 891 /* Validate size of data. */ 587 if (cchSrcPage >= PAGESIZE- 2)588 return FALSE;892 if (cchSrcPage >= cchPage - 2) 893 return kError::BAD_ITERPAGE; 589 894 590 895 /* 591 896 * Expand the page. 592 897 */ 593 while (pIter->LX_nIter )898 while (pIter->LX_nIter && cchSrcPage > 0) 594 899 { 595 900 /* Check if we're out of bound. */ 596 if ( pachPage - pachDes Page + pIter->LX_nIter * pIter->LX_nBytes > PAGESIZE901 if ( pachPage - pachDestPage + pIter->LX_nIter * pIter->LX_nBytes > cchPage 597 902 || cchSrcPage <= 0) 598 return FALSE; 903 return kError::BAD_ITERPAGE; 904 905 //if (pIter->LX_nIter == 1) 906 // printf("get 0x%03x stored %3d bytes\n", pachPage - pachDestPage, pIter->LX_nBytes); 907 //else 908 // printf("get 0x%03x %3d iterations %3d bytes\n", pachPage - pachDestPage, pIter->LX_nIter, pIter->LX_nBytes); 599 909 600 910 if (pIter->LX_nBytes == 1) 601 911 { /* one databyte */ 602 memset(pachPage, &pIter->LX_Iterdata, pIter->LX_nIter);603 p chPage += pIter->LX_nIter;604 cchSrcPage -= pIter->LX_nIter + 4;912 memset(pachPage, pIter->LX_Iterdata, pIter->LX_nIter); 913 pachPage += pIter->LX_nIter; 914 cchSrcPage -= 4 + 1; 605 915 pIter++; 606 916 } 607 917 else 608 918 { 609 for (int i = 0; i < pIter->LX_nIter; i++, pachPage += pIter->LX_nBytes)919 for (int i = pIter->LX_nIter; i > 0; i--, pachPage += pIter->LX_nBytes) 610 920 memcpy(pachPage, &pIter->LX_Iterdata, pIter->LX_nBytes); 611 921 cchSrcPage -= 4 + pIter->LX_nBytes; 612 pIter = (pIter)((char*)pIter 4 + pIter->LX_nBytes); 613 } 614 } 615 return TRUE; 616 #if 0 617 /* example code */ 618 int off; 619 struct LX_Iter *pIter; 620 char * pch = pvPage; /* Current position on page */ 621 622 off = pe32->e32_datapage + (pObjMap->o32_pagedataoffset << pe32->e32_pageshift); 623 if (pObjMap->o32_pagesize && (off + pObjMap->o32_pagesize - 1) >= cbFile) 624 { 625 fprintf(stderr, "Error: Page resides outside of the file.\n"); 626 return 1; 627 } 628 pIter = (struct LX_Iter *)((char*)pvFile + off); 629 630 /* expand page */ 631 while (pIter->LX_nIter > 0) 632 { 633 if (pch + (pIter->LX_nBytes * pIter->LX_nIter) > (char*)pvPage + OBJPAGELEN) 634 { 635 fprintf(stderr, "Error: Iterated page expands to more than a page!\n"); 636 return 1; 637 } 638 639 if (pIter->LX_nBytes == 1) 640 { 641 memset(pch, pIter->LX_Iterdata, pIter->LX_nIter); 642 pch += pIter->LX_nIter; 643 pIter++; 644 } 645 else 646 { 647 int i; 648 for (i = 0; i < pIter->LX_nIter; i++, pch += pIter->LX_nBytes) 649 memcpy(pch, &pIter->LX_Iterdata, pIter->LX_nBytes); 650 #if 1 /* curious */ 651 if (pIter->LX_nBytes > 2) fprintf(stdout, "pIter->LX_nBytes = %\n", pIter->LX_nBytes); 652 #endif 653 654 pIter = (struct LX_Iter*)((char*)pIter + 4 + pIter->LX_nBytes); 655 } 656 } 657 658 return FALSE; 659 #endif 660 } 922 pIter = (struct LX_Iter *)((char*)pIter + 4 + pIter->LX_nBytes); 923 } 924 } 925 926 /* 927 * Zero remaining part of the page. 928 */ 929 if (pachPage - pachDestPage < cchPage) 930 memset(pachPage, 0, cchPage - (pachPage - pachDestPage)); 931 932 return 0; 933 } 661 934 662 935 … … 664 937 * Expands a page compressed with the exepack method introduced with OS/2 Warp 3.0. 665 938 * (/EXEPACK:2) 666 * @returns Successindicator.939 * @returns 0 on success. kError error code on error. 667 940 * @param pachPage Pointer to output page. size: PAGESIZE 668 941 * Upon successful return this will contain the expanded page data. 942 * @param cchPage Page size. 669 943 * @param pachSrcPage Pointer to source data. size: cchSrcPage. 670 944 * This data should be compressed with EXEPACK:2! 945 * @param cchSrcPage Size of compressed data. 671 946 * @sketch Have no good idea right now. 672 * @status Stub.947 * @status Completely implemented and tested. 673 948 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 949 * @remark tested. 950 */ 951 int kFileLX::expandPage2(char *pachPage, int cchPage, const char * pachSrcPage, int cchSrcPage) 952 { 953 char * pachDestPage = pachPage; /* Store the pointer for boundrary checking. */ 954 955 while (cchSrcPage > 0) 956 { 957 /* 958 * Bit 0 and 1 is the encoding type. 959 */ 960 switch (*pachSrcPage & 0x03) 961 { 962 /* 963 * 964 * 0 1 2 3 4 5 6 7 965 * type | | 966 * ---------------- 967 * cch <cch bytes of data> 968 * 969 * Bits 2-7 is, if not zero, the length of an uncompressed run 970 * starting at the following byte. 971 * 972 * 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 973 * type | | | | | | 974 * ---------------- ---------------------- ----------------------- 975 * zero cch char to multiply 976 * 977 * If the bits are zero, the following two bytes describes a 978 * 1 byte interation run. First byte is count, second is the byte to copy. 979 * A count of zero is means end of data, and we simply stops. In that case 980 * the rest of the data should be zero. 981 */ 982 case 0: 983 { 984 if (*pachSrcPage) 985 { 986 int cch = *pachSrcPage >> 2; 987 if (cchPage < cch || cchSrcPage < cch + 1) 988 return kError::BAD_COMPESSED_PAGE; 989 memcpy(pachPage, pachSrcPage+1, cch); 990 pachPage += cch, cchPage -= cch; 991 pachSrcPage += cch + 1, cchSrcPage -= cch + 1; 992 break; 993 } 994 if (cchSrcPage < 2) 995 return kError::BAD_COMPESSED_PAGE; 996 int cch = pachSrcPage[1]; 997 if (cch) 998 { 999 if (cchSrcPage < 3 || cchPage < cch) 1000 return kError::BAD_COMPESSED_PAGE; 1001 memset(pachPage, pachSrcPage[2], cch); 1002 pachPage += cch, cchPage -= cch; 1003 pachSrcPage += 3, cchSrcPage -= 3; 1004 break; 1005 } 1006 goto endloop; 1007 } 1008 1009 1010 /* 1011 * 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1012 * type | | | | | | 1013 * ---- ------- ------------------------- 1014 * cch1 cch2 - 3 offset <cch1 bytes of data> 1015 * 1016 * Two bytes layed out as described above, followed by cch1 bytes of data to be copied. 1017 * The cch2(+3) and offset describes an amount of data to be copied from the expanded 1018 * data relative to the current position. The data copied as you would expect it to be. 1019 */ 1020 case 1: 1021 { 1022 if (cchSrcPage < 2) 1023 return kError::BAD_COMPESSED_PAGE; 1024 int off = *(unsigned short*)pachSrcPage >> 7; 1025 int cch1 = *pachSrcPage >> 2 & 3; 1026 int cch2 = (*pachSrcPage >> 4 & 7) + 3; 1027 pachSrcPage += 2, cchSrcPage -= 2; 1028 if (cchSrcPage < cch1 || cchPage < cch1 + cch2 || pachPage + cch1 - off < pachDestPage) 1029 return kError::BAD_COMPESSED_PAGE; 1030 memcpy(pachPage, pachSrcPage, cch1); 1031 pachPage += cch1, cchPage -= cch1; 1032 pachSrcPage += cch1, cchSrcPage -= cch1; 1033 memcpyb(pachPage, pachPage - off, cch2); //memmove doesn't do a good job here for some stupid reason. 1034 pachPage += cch2, cchPage -= cch2; 1035 break; 1036 } 1037 1038 1039 /* 1040 * 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1041 * type | | | | 1042 * ---- ---------------------------------- 1043 * cch-3 offset 1044 * 1045 * Two bytes layed out as described above. 1046 * The cch(+3) and offset describes an amount of data to be copied from the expanded 1047 * data relative to the current position. 1048 * 1049 * If offset == 1 the data is not copied as expected, but in the memcpyw manner. 1050 */ 1051 case 2: 1052 { 1053 if (cchSrcPage < 2) 1054 return kError::BAD_COMPESSED_PAGE; 1055 int off = *(unsigned short*)pachSrcPage >> 4; 1056 int cch = (*pachSrcPage >> 2 & 3) + 3; 1057 pachSrcPage += 2, cchSrcPage -= 2; 1058 if (cchPage < cch || pachPage - off < pachDestPage) 1059 return kError::BAD_COMPESSED_PAGE; 1060 memcpyw(pachPage, pachPage - off, cch); 1061 pachPage += cch, cchPage -= cch; 1062 break; 1063 } 1064 1065 1066 /* 1067 * 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 1068 * type | | | | | | 1069 * ---------- ---------------- ---------------------------------- 1070 * cch1 cch2 offset <cch1 bytes of data> 1071 * 1072 * Three bytes layed out as described above, followed by cch1 bytes of data to be copied. 1073 * The cch2 and offset describes an amount of data to be copied from the expanded 1074 * data relative to the current position. 1075 * 1076 * If offset == 1 the data is not copied as expected, but in the memcpyw manner. 1077 */ 1078 case 3: 1079 { 1080 if (cchSrcPage < 3) 1081 return kError::BAD_COMPESSED_PAGE; 1082 int cch1 = *pachSrcPage >> 2 & 0x000f; 1083 int cch2 = *(unsigned short*)pachSrcPage >> 6 & 0x003f; 1084 int off = *(unsigned short*)(pachSrcPage+1) >> 4; 1085 pachSrcPage += 3, cchSrcPage -= 3; 1086 if (cchSrcPage < cch1 || cchPage < cch1 + cch2 || pachPage - off + cch1 < pachDestPage) 1087 return kError::BAD_COMPESSED_PAGE; 1088 memcpy(pachPage, pachSrcPage, cch1); 1089 pachPage += cch1, cchPage -= cch1; 1090 pachSrcPage += cch1, cchSrcPage -= cch1; 1091 memcpyw(pachPage, pachPage - off, cch2); 1092 pachPage += cch2, cchPage -= cch2; 1093 break; 1094 } 1095 } 1096 } 1097 1098 endloop:; 1099 1100 1101 /* 1102 * Zero the rest of the page. 1103 */ 1104 if (cchPage > 0) 1105 memset(pachPage, 0, cchPage); 1106 1107 return 0; 1108 } 1109 1110 1111 /** 1112 * This is a special memcpy for expandPage2 which performs a word based copy. 1113 * The difference between this, memmove and memcpy is that we'll allways read words. 1114 * @param pch1 Target pointer. 1115 * @param pch2 Source pointer. 1116 * @param cch size of memory block to copy from pch2 to pch1. 1117 * @author knut st. osmundsen (kosmunds@csc.com) 674 1118 * @remark 675 1119 */ 676 BOOL kFileLX::expandPage2(char *pachPage, const char * pachSrcPage, int cchSrcPage) 677 { 678 NOREF(pachPage); 679 NOREF(pachSrcPage); 680 NOREF(cchSrcPage); 681 return FALSE; 682 } 1120 inline void memcpyw(char *pch1, const char *pch2, size_t cch) 1121 { 1122 /* 1123 * Use memcpy if possible. 1124 */ 1125 if ((pch2 > pch1 ? pch2 - pch1 : pch1 - pch2) >= 4) 1126 { 1127 memcpy(pch1, pch2, cch); /* BUGBUG! ASSUMES that memcpy move NO more than 4 bytes at the time! */ 1128 return; 1129 } 1130 1131 /* 1132 * Difference is less than 3 bytes. 1133 */ 1134 if (cch & 1) 1135 *pch1++ = *pch2++; 1136 1137 #if 0 //haven't found anyone yet. (not a big surprize!) 1138 /* Looking for a very special case! I wanna see if my theory is right. */ 1139 if ((pch2 > pch1 ? pch2 - pch1 : pch1 - pch2) <= 1) 1140 INT3(); 1141 #endif 1142 1143 for (cch >>= 1; cch > 0; cch--, pch1 += 2, pch2 += 2) 1144 *(unsigned short *)pch1 = *(unsigned short *)pch2; 1145 } 1146 1147 1148 /** 1149 * This is a special memcpy for expandPage2 which performs a memmove operation. 1150 * The difference between this and memmove is that this one works. 1151 * 1152 * @param pch1 Target pointer. 1153 * @param pch2 Source pointer. 1154 * @param cch size of memory block to copy from pch2 to pch1. 1155 * @author knut st. osmundsen (kosmunds@csc.com) 1156 */ 1157 inline void memcpyb(char *pch1, const char *pch2, size_t cch) 1158 { 1159 /* 1160 * Use memcpy if possible. 1161 */ 1162 if ((pch2 > pch1 ? pch2 - pch1 : pch1 - pch2) >= 4) 1163 { 1164 memcpy(pch1, pch2, cch); /* BUGBUG! ASSUMES that memcpy move NO more than 4 bytes at the time! */ 1165 return; 1166 } 1167 1168 /* 1169 * Difference is less than 3 bytes. 1170 */ 1171 while(cch--) 1172 *pch1++ = *pch2++; 1173 } 1174 683 1175 684 1176 … … 689 1181 * PAGESIZE if failed to compress the page. 690 1182 * -1 on error. 691 * @param pachPage Pointer to output buffer. size: PAGESIZE.1183 * @param pachPage Pointer to output buffer. size: cchSrcPage. 692 1184 * This will hold the compressed page data upon return. 693 * @param pachSrcPage Pointer to page to compress. size: PAGESIZE. 1185 * @param pachSrcPage Pointer to page to compress. size: cchSrcPage. 1186 * @param cchSrcPage Page size. 694 1187 * @sketch 695 1188 * @status stub. … … 697 1190 * @remark Not implemented. 698 1191 */ 699 int kFileLX::compressPage1(char *pachPage, const char * pachSrcPage) 700 { 701 NOREF(pachPage); 702 NOREF(pachSrcPage); 1192 1193 int compressPage1Search(const char *pch, const char **ppchSearch, const char *pchEnd, int *pcIterations) 1194 { 1195 int cch; 1196 const char* pchStart = pch; 1197 const char* pchSearch = *ppchSearch; 1198 1199 // if (pch < pchSearch) 1200 // pch = pchSearch - 1; 1201 while ((cch = pchSearch - pch) > 0) 1202 { 1203 int cchLeft = pchEnd - pchSearch; 1204 if (cchLeft < cch) 1205 {pch++; continue;} 1206 int cIter = 1; 1207 const char *pchMatch = pchSearch; 1208 while (pchMatch < pchEnd && !memcmp(pchMatch, pch, cch)) 1209 pchMatch += cch, cIter++; 1210 1211 int cchCost = pchStart < pch ? cch + 8 : cch + 4; 1212 if (cIter == 1 || cIter * cch < cchCost) 1213 {pch++; continue;} 1214 *ppchSearch = pch; 1215 *pcIterations = cIter; 1216 return cch; 1217 } 1218 703 1219 return -1; 704 1220 } 1221 1222 int compressPage1SearchStored(const char *pchStart, const char *pchEnd, int *pcchRun) 1223 { 1224 if (pchStart+1 == pchEnd) 1225 return FALSE; 1226 1227 const char *pch = pchStart; 1228 char ch = *pch++; 1229 while (pch < pchEnd) 1230 if (*pch++ != ch) 1231 break; 1232 1233 if (pch == pchEnd) 1234 { 1235 *pcchRun = 1; 1236 return TRUE; 1237 } 1238 1239 int cch = pchEnd - pchStart; 1240 if (cch < 4 && cch % 2 != 0) 1241 return FALSE; 1242 1243 unsigned short* pus = (unsigned short*)pchStart; 1244 unsigned short us = *pus++; 1245 while ((const char*)pus < pchEnd) 1246 if (*pus++ != us) 1247 return 0; 1248 1249 *pcchRun = 2; 1250 return TRUE; 1251 } 1252 1253 1254 int kFileLX::compressPage1(char *pachPage, const char * pachSrcPage, int cchSrcPage) 1255 { 1256 union 1257 { 1258 char * pch; 1259 unsigned short * push; 1260 struct LX_Iter * pIter; 1261 } Dst; 1262 Dst.pch = pachPage; 1263 const char *pch = pachSrcPage; 1264 const char *pchSearch = pch; 1265 const char *pchEnd = pch + cchSrcPage; 1266 while (pchSearch < pchEnd) 1267 { 1268 int cIterations; 1269 int cchPattern = compressPage1Search(pch, &pchSearch, pchEnd, &cIterations); 1270 if (cchPattern > 0) 1271 { /* Found pattern. */ 1272 /* make uncompressed chunk. */ 1273 if (pch < pchSearch) 1274 { 1275 int cchRun; 1276 int cch = pchSearch - pch; 1277 if (cch < 9 && cch > 1 && compressPage1SearchStored(pch, pchSearch, &cchRun)) 1278 { 1279 /* make compressed chunk. */ 1280 Dst.pIter->LX_nIter = cch / cchRun; 1281 Dst.pIter->LX_nBytes = cchRun; 1282 memcpy(&Dst.pIter->LX_Iterdata, pch, cchPattern); 1283 //printf("put 0x%03x %3d iterations %3d bytes\n", pch - pachSrcPage, Dst.pIter->LX_nIter, Dst.pIter->LX_nBytes); 1284 Dst.pch += cchRun + 4; 1285 } 1286 else 1287 { /* make uncompressed chunk */ 1288 Dst.pIter->LX_nIter = 1; 1289 Dst.pIter->LX_nBytes = cch; 1290 memcpy(&Dst.pIter->LX_Iterdata, pch, cch); 1291 //printf("put 0x%03x stored %3d bytes\n", pch - pachSrcPage, Dst.pIter->LX_nBytes); 1292 Dst.pch += cch + 4; 1293 } 1294 pch += cch; 1295 } 1296 1297 /* make compressed chunk. */ 1298 Dst.pIter->LX_nIter = cIterations; 1299 Dst.pIter->LX_nBytes = cchPattern; 1300 memcpy(&Dst.pIter->LX_Iterdata, pch, cchPattern); 1301 //printf("put 0x%03x %3d iterations %3d bytes\n", pch - pachSrcPage, Dst.pIter->LX_nIter, Dst.pIter->LX_nBytes); 1302 Dst.pch += cchPattern + 4; 1303 pchSearch = pch += cchPattern * cIterations; 1304 } 1305 else 1306 { /* No pattern - got the next byte in the source page. */ 1307 pchSearch++; 1308 } 1309 } 1310 1311 /* make final uncompressed chunk(s) */ 1312 if (pch < pchSearch) 1313 { 1314 int cch = pchSearch - pch; 1315 Dst.pIter->LX_nIter = 1; 1316 Dst.pIter->LX_nBytes = cch; 1317 memcpy(&Dst.pIter->LX_Iterdata, pch, cch); 1318 //printf("put 0x%03x stored %3d bytes %d\n", pch - pachSrcPage, Dst.pIter->LX_nBytes, cch); 1319 Dst.pch += cch + 4; 1320 pch += cch; 1321 } 1322 1323 1324 1325 /* write terminating word - this is really not needed AFAIK, but it makes debugging easier. */ 1326 //*Dst.push++ = 0; 1327 return Dst.pch - pachPage; 1328 } 1329 705 1330 706 1331 … … 711 1336 * PAGESIZE if failed to compress the page. 712 1337 * -1 on error. 713 * @param pachPage Pointer to output buffer. size: PAGESIZE.1338 * @param pachPage Pointer to output buffer. size: cchSrcPage. 714 1339 * This will hold the compressed page data upon return. 715 * @param pachSrcPage Pointer to page to compress. size: PAGESIZE. 1340 * @param pachSrcPage Pointer to page to compress. size: cchSrcPage. 1341 * @param cchSrcPage Page size. 716 1342 * @sketch Have no idea! 717 1343 * @status stub. … … 719 1345 * @remark Not implemented. 720 1346 */ 721 int kFileLX::compressPage2(char *pachPage, const char * pachSrcPage) 722 { 723 NOREF(pachPage); 724 NOREF(pachSrcPage); 1347 int kFileLX::compressPage2(char *pachPage, const char * pachSrcPage, int cchSrcPage) 1348 { 1349 KNOREF(pachPage); 1350 KNOREF(pachSrcPage); 1351 KNOREF(cchSrcPage); 725 1352 return -1; 726 1353 } 727 1354 728 #endif 1355 1356 /** 1357 * Start a relocation enumeration. 1358 * @returns TRUE: Found relocation. 1359 * FALSE: No more relocations. 1360 * @param ulSegment Segment number. Special selector may be specified. 1361 * @param offSegment Offset into the segment described by ulSegment. 1362 * @param preloc Pointer to a relocation 'handle' structure. 1363 * This is used for communicating the relocations in 1364 * a generic format and for keeping track of the current position. 1365 * Please, DO NOT change any members of this structure. 1366 */ 1367 KBOOL kFileLX::relocFindFirst(unsigned long ulSegment, unsigned long offSegment, kRelocEntry *preloc) 1368 { 1369 if (ulSegment >= kRelocEntry::enmFirstSelector) 1370 offSegment = lxSpecialSelectorToObjectOffset(offSegment, &ulSegment); 1371 1372 if ( lxValidateObjectOffset(ulSegment, offSegment) 1373 && pe32->e32_frectab != 0 1374 && pe32->e32_fpagetab != 0 1375 ) 1376 { 1377 PLXRELOCSTATE pState = new LXRELOCSTATE; 1378 pState->ulSegment = ulSegment; 1379 pState->ulPage = paObject[ulSegment].o32_pagemap - 1; 1380 pState->pchFixupRec = pchFixupRecs + paulFixupPageTable[pState->ulPage]; 1381 pState->usSrcOffIdx = 0; 1382 preloc->pv1 = (void*)pState; 1383 preloc->fFlags = 0; 1384 preloc->Info.Name.pszModule = NULL; 1385 preloc->Info.Name.pszName = NULL; 1386 return relocFindNext(preloc); 1387 } 1388 1389 return FALSE; 1390 } 1391 1392 1393 /** 1394 * Start a relocation enumeration. 1395 * @returns TRUE: Found relocation. 1396 * FALSE: No more relocations. 1397 * @param ulAddress Address to start from. 1398 * @param preloc Pointer to a relocation 'handle' structure. 1399 * This is used for communicating the relocations in 1400 * a generic format and for keeping track of the current position. 1401 * Please, DO NOT change any members of this structure. 1402 */ 1403 KBOOL kFileLX::relocFindFirst(unsigned long ulAddress, kRelocEntry *preloc) 1404 { 1405 return relocFindFirst(kRelocEntry::enmVASelector, ulAddress, preloc); 1406 } 1407 1408 1409 /** 1410 * Get the next relocation. 1411 * @returns TRUE: Found relocation. 1412 * FALSE: No more relocations. 1413 * @param preloc Pointer to a relocation 'handle' structure. 1414 * @remark preloc have to be opened by relocFindFirst before calling relocFindNext! 1415 */ 1416 KBOOL kFileLX::relocFindNext(kRelocEntry *preloc) 1417 { 1418 PLXRELOCSTATE pState = (PLXRELOCSTATE)preloc->pv1; 1419 int iObj = pState->ulSegment; 1420 KBOOL fFound = FALSE; 1421 1422 while (iObj < pe32->e32_objcnt) 1423 { 1424 int iPage = pState->ulPage; 1425 1426 while (iPage < paObject[iObj].o32_mapsize + paObject[iObj].o32_pagemap - 1) 1427 { 1428 char * pchFixupRecEnd = pchFixupRecs + paulFixupPageTable[iPage + 1]; 1429 1430 while (pState->pchFixupRec < pchFixupRecEnd) 1431 { 1432 char * pch; /* Fixup record walker. */ 1433 union _rel 1434 { 1435 unsigned long ul; 1436 char * pch; 1437 struct r32_rlc *prlc; 1438 } rel; /* Fixup record */ 1439 1440 /* 1441 * If we're completed here we'll simply return. 1442 */ 1443 if (fFound) 1444 return TRUE; 1445 1446 1447 /* 1448 * Do some init and cleanup. 1449 */ 1450 rel.pch = pState->pchFixupRec; 1451 if (preloc->isName()) 1452 { 1453 delete (void*)preloc->Info.Name.pszModule; 1454 delete (void*)preloc->Info.Name.pszName; 1455 preloc->Info.Name.pszName = preloc->Info.Name.pszModule = NULL; 1456 } 1457 1458 1459 /* 1460 * We've got a problem! chained relocation records! 1461 */ 1462 switch (rel.prlc->nr_stype & NRSTYP) 1463 { 1464 case NRSBYT: preloc->fFlags = kRelocEntry::enm8 | kRelocEntry::enmOffset; break; 1465 case NRSSEG: preloc->fFlags = kRelocEntry::enm16_00 | kRelocEntry::enmOffset; break; 1466 case NRSPTR: preloc->fFlags = kRelocEntry::enm16_16 | kRelocEntry::enmOffset; break; 1467 case NRSOFF: preloc->fFlags = kRelocEntry::enm16 | kRelocEntry::enmOffset; break; 1468 case NRPTR48: preloc->fFlags = kRelocEntry::enm16_32 | kRelocEntry::enmOffset; break; 1469 case NROFF32: preloc->fFlags = kRelocEntry::enm32 | kRelocEntry::enmOffset; break; 1470 case NRSOFF32: preloc->fFlags = kRelocEntry::enm32 | kRelocEntry::enmRelEnd; break; 1471 default: 1472 kASSERT(FALSE); 1473 return FALSE; 1474 } 1475 1476 /* Set endian flag. */ 1477 if (pe32->e32_border == E32LEBO && pe32->e32_border == E32LEWO) 1478 preloc->fFlags |= kRelocEntry::enmLittleEndian; 1479 else if (pe32->e32_border == E32BEBO && pe32->e32_border == E32BEWO) 1480 preloc->fFlags |= kRelocEntry::enmBigEndian; 1481 else 1482 { 1483 kASSERT(FALSE); 1484 return FALSE; 1485 } 1486 1487 1488 /* 1489 * LX target type. 1490 */ 1491 pch = rel.pch + 3 + (rel.prlc->nr_stype & NRCHAIN ? 0 : 1); /* place pch at the 4th member. */ 1492 switch (rel.prlc->nr_flags & NRRTYP) 1493 { 1494 case NRRINT: 1495 preloc->fFlags |= kRelocEntry::enmInternal; 1496 if (rel.prlc->nr_flags & NR16OBJMOD) 1497 { 1498 preloc->Info.Internal.ulSegment = *(unsigned short *)pch - 1; 1499 pch += 2; 1500 } 1501 else 1502 { 1503 preloc->Info.Internal.ulSegment = *(unsigned char *)pch - 1; 1504 pch += 1; 1505 } 1506 if (rel.prlc->nr_flags & NR32BITOFF) 1507 { 1508 preloc->Info.Internal.offSegment = *(unsigned long *)pch; 1509 pch += 4; 1510 } 1511 else 1512 { 1513 preloc->Info.Internal.offSegment = *(unsigned short *)pch; 1514 pch += 2; 1515 } 1516 break; 1517 1518 case NRRORD: 1519 preloc->fFlags |= kRelocEntry::enmOrdDLL; 1520 if (rel.prlc->nr_flags & NR16OBJMOD) 1521 { 1522 preloc->Info.Name.pszModule = lxGetImportModuleName(*(unsigned short *)pch); 1523 pch += 2; 1524 } 1525 else 1526 { 1527 preloc->Info.Name.pszModule = lxGetImportModuleName(*(unsigned char *)pch); 1528 pch += 1; 1529 } 1530 if (rel.prlc->nr_flags & NR32BITOFF) 1531 { 1532 sprintf(preloc->Info.Name.pszName = new char[16], "#%lu", *(unsigned long *)pch); 1533 preloc->Info.Name.ulOrdinal = (unsigned)*(unsigned long *)pch; 1534 pch += 4; 1535 } 1536 else if (rel.prlc->nr_flags & NR8BITORD) 1537 { 1538 sprintf(preloc->Info.Name.pszName = new char[8], "#%u", (unsigned)*(unsigned char *)pch); 1539 preloc->Info.Name.ulOrdinal = (unsigned)*(unsigned char *)pch; 1540 pch += 1; 1541 } 1542 else 1543 { 1544 sprintf(preloc->Info.Name.pszName = new char[12], "#%u", (unsigned)*(unsigned short *)pch); 1545 preloc->Info.Name.ulOrdinal = (unsigned)*(unsigned short *)pch; 1546 pch += 2; 1547 } 1548 break; 1549 1550 case NRRNAM: 1551 preloc->fFlags |= kRelocEntry::enmNameDLL; 1552 if (rel.prlc->nr_flags & NR16OBJMOD) 1553 { 1554 preloc->Info.Name.pszModule = lxGetImportModuleName(*(unsigned short *)pch); 1555 pch += 2; 1556 } 1557 else 1558 { 1559 preloc->Info.Name.pszModule = lxGetImportModuleName(*(unsigned char *)pch); 1560 pch += 1; 1561 } 1562 preloc->Info.Name.ulOrdinal = ~0UL;; 1563 if (rel.prlc->nr_flags & NR32BITOFF) 1564 { 1565 preloc->Info.Name.pszName = lxGetImportProcName(*(unsigned long *)pch); 1566 pch += 4; 1567 } 1568 else 1569 { 1570 preloc->Info.Name.pszName = lxGetImportProcName(*(unsigned short *)pch); 1571 pch += 2; 1572 } 1573 break; 1574 1575 case NRRENT: 1576 preloc->fFlags |= kRelocEntry::enmInternal; 1577 kASSERT(!"Not Implemented"); 1578 return FALSE; 1579 } 1580 1581 /* addiative fixup? */ 1582 if (rel.prlc->nr_flags & NRADD) 1583 { 1584 preloc->fFlags |= kRelocEntry::enmAdditive; 1585 if (rel.prlc->nr_flags & NR32BITADD) 1586 { 1587 preloc->ulAdd = *(unsigned long *)pch; 1588 pch += 4; 1589 } 1590 else 1591 { 1592 preloc->ulAdd = *(unsigned short *)pch; 1593 pch += 2; 1594 } 1595 } 1596 1597 /* 1598 * obj:offset of the fixup 1599 * If the offset is negative we'll skip it (ie. not set the found flag). 1600 */ 1601 preloc->ulSegment = iObj; 1602 preloc->offSegment = (iPage - paObject[iObj].o32_pagemap + 1) * pe32->e32_pagesize; 1603 if (rel.prlc->nr_stype & NRCHAIN) 1604 { 1605 while (pState->usSrcOffIdx < (unsigned char)rel.prlc->r32_soff) 1606 { 1607 if (!(((unsigned short *)pch)[pState->usSrcOffIdx] & 0x8000)) 1608 { 1609 preloc->offSegment += ((unsigned short*)pch)[pState->usSrcOffIdx]; 1610 fFound = TRUE; 1611 break; 1612 } 1613 pState->usSrcOffIdx++; 1614 } 1615 } 1616 else 1617 { 1618 preloc->offSegment += rel.prlc->r32_soff; 1619 if (!(rel.prlc->r32_soff & 0x8000)) 1620 fFound = TRUE; 1621 } 1622 1623 1624 /* 1625 * Go to the next relocation. 1626 */ 1627 if (rel.prlc->nr_stype & NRCHAIN) 1628 { 1629 if (++pState->usSrcOffIdx >= (unsigned char)rel.prlc->r32_soff) 1630 { 1631 pState->pchFixupRec = pState->pchFixupRec + (KSIZE)pch - rel.ul + ((unsigned char)rel.prlc->r32_soff) * 2; 1632 pState->usSrcOffIdx = 0; 1633 } 1634 } 1635 else 1636 pState->pchFixupRec = pState->pchFixupRec + (KSIZE)pch - rel.ul; 1637 } 1638 1639 1640 /* next page */ 1641 pState->ulPage = ++iPage; 1642 pState->pchFixupRec = pchFixupRecEnd; 1643 pState->usSrcOffIdx = 0; /* Source Offset Index */ 1644 } 1645 1646 1647 /* next object */ 1648 pState->ulSegment = ++iObj; 1649 if (iObj >= pe32->e32_objcnt) 1650 break; 1651 pState->ulPage = paObject[iObj].o32_pagemap - 1; 1652 pState->pchFixupRec = pchFixupRecs + paulFixupPageTable[pState->ulPage]; 1653 pState->usSrcOffIdx = 0; /* Source Offset Index */ 1654 } 1655 1656 return fFound; 1657 } 1658 1659 1660 /** 1661 * Closes a relocatation search/enumeration. 1662 * Will free any internally allocated resources. 1663 * 1664 * @param preloc The enumeration 'handel'. 1665 * @remark This function *must* be called to close a search/enumeration. 1666 */ 1667 void kFileLX::relocFindClose(kRelocEntry *preloc) 1668 { 1669 /* free name storage */ 1670 if (preloc->isName()) 1671 { 1672 delete (void*)preloc->Info.Name.pszModule; 1673 delete (void*)preloc->Info.Name.pszName; 1674 preloc->Info.Name.pszName = preloc->Info.Name.pszModule = NULL; 1675 } 1676 1677 /* free state info */ 1678 memset(preloc->pv1, 0xff, sizeof(LXRELOCSTATE)); 1679 delete preloc->pv1; 1680 preloc->pv1 = (void*)0xdeadbeef; 1681 } 1682 1683 1684 -
trunk/tools/common/kFileLX.h
r5531 r8003 1 /* $Id: kFileLX.h,v 1. 5 2001-04-17 00:26:11bird Exp $1 /* $Id: kFileLX.h,v 1.6 2002-02-24 02:47:26 bird Exp $ 2 2 * 3 3 * kFileLX - Linear Executable file reader. … … 12 12 #define _kFileLX_h_ 13 13 14 struct e32_exe; 15 struct o32_obj; 16 struct o32_map; 14 17 15 18 16 17 class kFileLX : public kFileFormatBase, public kExecutableI /*, public kPageI*/ 19 class kFileLX : public kFileFormatBase, public kExecutableI, public kPageI, public kRelocI 18 20 { 19 protected:20 PVOID pvBase; /* Pointer to filemapping. */21 ULONG cbFile; /* Size of filemapping. */22 ULONG offLXHdr; /* Offset of the LX header. */23 struct e32_exe * pe32; /* Pointer to the exe header within the filemapping. */24 struct o32_obj * paObject; /* Pointer to the objecttable. */25 struct o32_map * paMap; /* Pointer to page map table. */26 27 BOOL queryExportName(int iOrdinal, char *pszBuffer);28 29 21 public: 30 kFileLX(const char *pszFilename) throw ( int);31 kFileLX(kFile *pFile) throw ( int);22 kFileLX(const char *pszFilename) throw (kError); 23 kFileLX(kFile *pFile) throw (kError); 32 24 ~kFileLX(); 33 25 34 26 /** @cat Module information methods. */ 35 BOOLmoduleGetName(char *pszBuffer, int cchSize = 260);27 KBOOL moduleGetName(char *pszBuffer, int cchSize = 260); 36 28 37 /** @cat Export enumeration methods. */ 38 BOOL exportFindFirst(kExportEntry *pExport); 39 BOOL exportFindNext(kExportEntry *pExport); 40 void exportFindClose(kExportEntry *pExport); 41 42 /** @cat Export Lookup methods */ 43 BOOL exportLookup(unsigned long ulOrdinal, kExportEntry *pExport); 44 BOOL exportLookup(const char * pszName, kExportEntry *pExport); 45 46 virtual BOOL isLx() const {return TRUE;}; 29 /** @cat Misc */ 30 virtual KBOOL isLx() const {return TRUE;}; 47 31 48 32 struct o32_obj * getObject(int iObject); 49 33 int getObjectCount(); 50 34 51 #if 0 52 /** @cat Get and put page methods. (the first ones are generic) */ 53 BOOL getPage(char *pachPage, ULONG ulAddress); 54 BOOL getPage(char *pachPage, int iObject, int offObject); 55 BOOL putPage(const char *pachPage, ULONG ulAddress); 56 BOOL putPage(const char *pachPage, int iObject, int offObject); 35 /** @cat Export enumeration methods. */ 36 KBOOL exportFindFirst(kExportEntry *pExport); 37 KBOOL exportFindNext(kExportEntry *pExport); 38 void exportFindClose(kExportEntry *pExport); 57 39 58 BOOL getPageLX(char *pachPage, int iObject, int iPage); 59 BOOL getPageLX(char *pachPage, int iPage); 60 BOOL putPageLX(const char *pachPage, int iObject, int iPage); 61 BOOL putPageLX(const char *pachPage, int iPage); 40 /** @cat Export Lookup methods */ 41 KBOOL exportLookup(unsigned long ulOrdinal, kExportEntry *pExport); 42 KBOOL exportLookup(const char * pszName, kExportEntry *pExport); 43 44 /** @cat Get and put page methods. */ 45 int pageGet(char *pachPage, unsigned long ulAddress) const; 46 int pageGet(char *pachPage, int iObject, int offObject) const; 47 int pagePut(const char *pachPage, unsigned long ulAddress); 48 int pagePut(const char *pachPage, int iObject, int offObject); 49 int pageGetPageSize() const; 62 50 63 51 /** @cat Compression and expansion methods compatible with exepack:1 and exepack:2. */ 64 static BOOL expandPage1(char *pachPage, const char * pachSrcPage, int cchSrcPage); 65 static BOOL expandPage2(char *pachPage, const char * pachSrcPage, int cchSrcPage); 66 static int compressPage1(char *pachPage, const char * pachSrcPage); 67 static int compressPage2(char *pachPage, const char * pachSrcPage); 52 static int expandPage1(char *pachPage, int cchPage, const char * pachSrcPage, int cchSrcPage); 53 static int expandPage2(char *pachPage, int cchPage, const char * pachSrcPage, int cchSrcPage); 54 static int compressPage1(char *pachPage, const char * pachSrcPage, int cchSrcPage); 55 static int compressPage2(char *pachPage, const char * pachSrcPage, int cchSrcPage); 56 57 /** @cat Relocation methods */ 58 KBOOL relocFindFirst(unsigned long iSegment, unsigned long offObject, kRelocEntry *preloc); 59 KBOOL relocFindFirst(unsigned long ulAddress, kRelocEntry *preloc); 60 KBOOL relocFindNext(kRelocEntry *preloc); 61 void relocFindClose(kRelocEntry *preloc); 62 63 64 protected: 65 /** @cat Internal data */ 66 void * pvBase; /* Pointer to filemapping. */ 67 unsigned long cbFile; /* Size of filemapping. */ 68 unsigned long offLXHdr; /* Offset of the LX header. */ 69 struct e32_exe * pe32; /* Pointer to the exe header within the filemapping. */ 70 struct o32_obj * paObject; /* Pointer to the objecttable. */ 71 struct o32_map * paMap; /* Pointer to page map table. */ 72 unsigned long * paulFixupPageTable; /* Pointer to the fixup page table. */ 73 char * pchFixupRecs; /* Pointer to the fixup record table. */ 74 75 /** @cat Export and Module information worker. */ 76 KBOOL queryExportName(int iOrdinal, char *pszBuffer); 77 78 /** @cat Get and put page workers. */ 79 /* 80 int pageGetLX(char *pachPage, int iObject, int iPage) const; 81 int pageGetLX(char *pachPage, int iPage) const; 82 int pagePutLX(const char *pachPage, int iObject, int iPage); 83 int pagePutLX(const char *pachPage, int iPage); 84 */ 85 86 /** @cat Address mapping helpers. */ 87 unsigned long lxAddressToObjectOffset(unsigned long ulAddress, unsigned long * pulObject) const; 88 unsigned long lxSpecialSelectorToObjectOffset(unsigned long offObject, unsigned long * pulObject) const; 89 KBOOL lxValidateObjectOffset(unsigned long ulObject, unsigned long offOffset) const; 90 KBOOL lxValidateAddress(unsigned long ulAddress) const; 91 92 /** @cat Import Helpers */ 93 char * lxGetImportModuleName(unsigned long ordModule) const; 94 char * lxGetImportProcName(unsigned long offProc) const; 95 }; 96 68 97 #endif 69 };70 #endif -
trunk/tools/common/kFilePE.cpp
r5531 r8003 1 /* 1 /* $Id: kFilePE.cpp,v 1.5 2002-02-24 02:47:26 bird Exp $ 2 * 2 3 * kFilePE - PE files. 3 4 * … … 6 7 */ 7 8 8 /*******************************************************************************9 * Defined Constants *10 *******************************************************************************/11 /* emx fixups */12 #ifdef __EMX__13 #define __stdcall14 #define max(a,b) (((a) > (b)) ? (a) : (b))15 #define min(a,b) (((a) < (b)) ? (a) : (b))16 #endif17 18 9 /****************************************************************************** 19 10 * Header Files * 20 11 ******************************************************************************/ 21 #ifdef __EMX__22 #define INT INT_23 #define PCHAR PCHAR_24 #endif25 #include <os2.h>26 #ifdef __EMX__27 #undef PCHAR28 #undef INT29 #endif30 #include <stdio.h>31 #include <stdlib.h>32 12 #include <string.h> 33 #include <malloc.h> 34 #include <assert.h> 35 #include <peexe.h> 13 14 #include "MZexe.h" 15 #include "PEexe.h" 16 17 #include "kTypes.h" 18 #include "kError.h" 36 19 #include "kFile.h" 37 20 #include "kFileFormatBase.h" 38 #include "kInterfaces.h" 39 #include "kFilePe.h" 21 #include "kFileInterfaces.h" 22 #include "kFilePE.h" 23 40 24 41 25 /******************************************************************************* … … 46 30 #endif 47 31 32 48 33 /** 49 34 * Constructs a kFilePE object for a file. 50 35 * @param pFile File to create object from. 51 * @remark throws errorcode (TODO: errorhandling.) 52 */ 53 kFilePE::kFilePE(kFile *pFile) throw(int) : pvBase(NULL), 36 * @remark throws errorcode 37 */ 38 kFilePE::kFilePE(kFile *pFile) : 39 kFileFormatBase(pFile), 40 pvBase(NULL), 54 41 pDosHdr(NULL), pFileHdr(NULL), pOptHdr(NULL), paDataDir(NULL), paSectionHdr(NULL), 55 42 pExportDir(NULL), … … 67 54 { 68 55 IMAGE_DOS_HEADER doshdr; 69 70 /* read dos-header - assumes there is one */ 71 if ( pFile->readAt(&doshdr, sizeof(doshdr), 0) 72 && doshdr.e_magic == IMAGE_DOS_SIGNATURE 73 && doshdr.e_lfanew > sizeof(doshdr) 74 ) 75 { 76 IMAGE_NT_HEADERS pehdr; 77 78 /* read pe headers */ 79 if ( pFile->readAt(&pehdr, sizeof(pehdr), doshdr.e_lfanew) 80 && pehdr.Signature == IMAGE_NT_SIGNATURE 81 && pehdr.FileHeader.SizeOfOptionalHeader == sizeof(IMAGE_OPTIONAL_HEADER) 82 && pehdr.OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR_MAGIC) 83 { 56 long offPEHdr = 0; 57 IMAGE_NT_HEADERS pehdr; 58 59 /* read dos-header (If tehre is one) */ 60 pFile->setThrowOnErrors(); 61 pFile->readAt(&doshdr, sizeof(doshdr), 0); 62 if (doshdr.e_magic == IMAGE_DOS_SIGNATURE) 63 { 64 if (doshdr.e_lfanew <= sizeof(doshdr)) 65 throw(kError(kError::INVALID_EXE_SIGNATURE)); 66 offPEHdr = doshdr.e_lfanew; 67 } 68 69 /* read pe headers and do minor verifications */ 70 pFile->readAt(&pehdr, sizeof(pehdr), offPEHdr); 71 if (pehdr.Signature != IMAGE_NT_SIGNATURE) 72 throw(kError(kError::INVALID_EXE_SIGNATURE)); 73 if ( pehdr.FileHeader.SizeOfOptionalHeader != sizeof(IMAGE_OPTIONAL_HEADER) 74 || pehdr.OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR_MAGIC) 75 throw(kError(kError::BAD_EXE_FORMAT)); 76 84 77 /* create mapping */ 85 pvBase = calloc((size_t)pehdr.OptionalHeader.SizeOfImage, 1); 86 if (pvBase != NULL) 87 { 78 pvBase = new char [pehdr.OptionalHeader.SizeOfImage]; 79 if (pvBase == NULL) 80 throw(kError(kError::NOT_ENOUGH_MEMORY)); 81 memset(pvBase, 0, pehdr.OptionalHeader.SizeOfImage); 82 88 83 /* 89 84 printf("%ld\n", pehdr.OptionalHeader.SizeOfHeaders); 90 85 printf("%ld\n", sizeof(IMAGE_NT_HEADERS) + sizeof(IMAGE_SECTION_HEADER) * pehdr.FileHeader.NumberOfSections); 91 assert(pehdr.OptionalHeader.SizeOfHeaders ==86 kASSERT(pehdr.OptionalHeader.SizeOfHeaders == 92 87 sizeof(IMAGE_NT_HEADERS) + sizeof(IMAGE_SECTION_HEADER) * pehdr.FileHeader.NumberOfSections); 93 88 */ 94 if (pFile->readAt(pvBase, pehdr.OptionalHeader.SizeOfHeaders, 0))89 try 95 90 { 91 /* read optional header */ 92 pFile->readAt(pvBase, pehdr.OptionalHeader.SizeOfHeaders, 0); 93 96 94 /* read sections */ 97 95 for (int i = 0; i < pehdr.FileHeader.NumberOfSections; i++) 98 96 { 99 ULONGcbSection;97 unsigned long cbSection; 100 98 PIMAGE_SECTION_HEADER pSectionHdr = 101 99 #if 0 102 IMAGE_FIRST_SECTION(((ULONG)pvBase + ((PIMAGE_DOS_HEADER)pvBase)->e_lfanew));100 IMAGE_FIRST_SECTION(((unsigned long)pvBase + ((PIMAGE_DOS_HEADER)pvBase)->e_lfanew)); 103 101 #else 104 (PIMAGE_SECTION_HEADER) ( (ULONG)pvBase + doshdr.e_lfanew + sizeof(IMAGE_NT_HEADERS) );102 (PIMAGE_SECTION_HEADER) ( (unsigned long)pvBase + doshdr.e_lfanew + sizeof(IMAGE_NT_HEADERS) ); 105 103 #endif 106 104 pSectionHdr += i; 107 105 108 cbSection = min(pSectionHdr->Misc.VirtualSize, pSectionHdr->SizeOfRawData); 109 if ( cbSection 110 && !pFile->readAt((char*)pvBase + pSectionHdr->VirtualAddress, 111 cbSection, 112 pSectionHdr->PointerToRawData) 113 ) 114 { 115 /* error */ 116 free(pvBase); 117 pvBase = NULL; 118 throw(6); 119 } 120 } 106 cbSection = KMIN(pSectionHdr->Misc.VirtualSize, pSectionHdr->SizeOfRawData); 107 if (cbSection) 108 pFile->readAt((char*)pvBase + pSectionHdr->VirtualAddress, 109 cbSection, pSectionHdr->PointerToRawData); 110 } 121 111 122 112 /* set pointers */ … … 124 114 { 125 115 pDosHdr = (PIMAGE_DOS_HEADER)pvBase; 126 pFileHdr = (PIMAGE_FILE_HEADER)((DWORD)pvBase + pDosHdr->e_lfanew + 4);116 pFileHdr = (PIMAGE_FILE_HEADER)((char*)pvBase + pDosHdr->e_lfanew + 4); 127 117 } 128 118 else 129 pFileHdr = (PIMAGE_FILE_HEADER)((DWORD)pvBase + 4);119 pFileHdr = (PIMAGE_FILE_HEADER)((char*)pvBase + 4); 130 120 131 121 pOptHdr = (PIMAGE_OPTIONAL_HEADER)((int)pFileHdr + sizeof(*pFileHdr)); … … 142 132 { 143 133 if (paDataDir[i].VirtualAddress < pOptHdr->SizeOfImage) 144 ((PULONG)&this->pExportDir)[i] = (int)pvBase + paDataDir[i].VirtualAddress; 145 #ifdef DEBUG 146 else 147 fprintf(stderr, "bad directory pointer %d\n", i); 148 #endif 134 ((unsigned long*)&this->pExportDir)[i] = (int)pvBase + paDataDir[i].VirtualAddress; 149 135 } 150 136 } 151 137 } 152 else 153 throw(4); 154 } 155 else 156 throw(3); 157 } 158 else 159 throw(2); 160 } 161 else 162 throw(1); 138 catch (kError err) 139 { 140 delete(pvBase); 141 pvBase = NULL; 142 throw(err); 143 } 163 144 } 164 145 … … 170 151 { 171 152 if (pvBase) 172 delete pvBase;153 delete(pvBase); 173 154 } 174 155 … … 180 161 * @param cchBuffer Size of the buffer (defaults to 260 chars). 181 162 */ 182 BOOL kFilePE::moduleGetName(char *pszBuffer, int cchSize/* = 260*/)163 KBOOL kFilePE::moduleGetName(char *pszBuffer, int cchSize/* = 260*/) 183 164 { 184 165 if (pExportDir && pExportDir->Name) … … 203 184 * @remark 204 185 */ 205 BOOLkFilePE::exportFindFirst(kExportEntry *pExport)186 KBOOL kFilePE::exportFindFirst(kExportEntry *pExport) 206 187 { 207 188 if (pExportDir && pExportDir->NumberOfFunctions) … … 222 203 * @remark 223 204 */ 224 BOOLkFilePE::exportFindNext(kExportEntry *pExport)205 KBOOL kFilePE::exportFindNext(kExportEntry *pExport) 225 206 { 226 207 if (pExportDir && pExportDir->NumberOfFunctions) … … 283 264 * @remark stub 284 265 */ 285 BOOL kFilePE::exportLookup(unsigned long ulOrdinal, kExportEntry *pExport)286 { 287 assert(!"not implemented.");266 KBOOL kFilePE::exportLookup(unsigned long ulOrdinal, kExportEntry *pExport) 267 { 268 kASSERT(!"not implemented."); 288 269 ulOrdinal = ulOrdinal; 289 270 pExport = pExport; … … 298 279 * @remark stub 299 280 */ 300 BOOL kFilePE::exportLookup(const char * pszName, kExportEntry *pExport)301 { 302 assert(!"not implemented.");281 KBOOL kFilePE::exportLookup(const char * pszName, kExportEntry *pExport) 282 { 283 kASSERT(!"not implemented."); 303 284 pszName = pszName; 304 285 pExport = pExport; … … 310 291 * Mini dump function. 311 292 */ 312 BOOL kFilePE::dump(kFile *pOut)293 KBOOL kFilePE::dump(kFile *pOut) 313 294 { 314 295 int i,j,k; … … 428 409 if (pTLSDir[i].AddressOfCallBacks) 429 410 { 430 PULONGpaulIndex;431 PULONGpaulCallback;432 ULONGulBorlandRVAFix = 0UL;411 unsigned long * paulIndex; 412 unsigned long * paulCallback; 413 unsigned long ulBorlandRVAFix = 0UL; 433 414 434 415 /* Check if the addresses in the TLSDir is RVAs or real addresses */ … … 437 418 438 419 j = 0; 439 paulIndex = ( PULONG)((ULONG)pTLSDir[i].AddressOfIndex - ulBorlandRVAFix + (ULONG)this->pvBase);440 paulCallback = ( PULONG)((ULONG)pTLSDir[i].AddressOfCallBacks - ulBorlandRVAFix + (ULONG)this->pvBase);420 paulIndex = (unsigned long *)((unsigned long)pTLSDir[i].AddressOfIndex - ulBorlandRVAFix + (unsigned long)this->pvBase); 421 paulCallback = (unsigned long *)((unsigned long)pTLSDir[i].AddressOfCallBacks - ulBorlandRVAFix + (unsigned long)this->pvBase); 441 422 if (*paulCallback) 442 423 { -
trunk/tools/common/kFilePE.h
r5531 r8003 1 /* $Id: kFilePE.h,v 1.4 2001-04-17 00:26:11 bird Exp $ 1 /* $Id: kFilePE.h,v 1.5 2002-02-24 02:47:27 bird Exp $ 2 * 2 3 * kFilePE - PE files. 3 4 * … … 9 10 #define _kFilePE_h_ 10 11 11 /******************************************************************************* 12 * Defined Constants * 13 *******************************************************************************/ 14 15 #if !defined(__WINE_PEEXE_H) && !defined(_WINNT_) 16 #if 1 17 #define PIMAGE_DOS_HEADER void* 18 #define PIMAGE_FILE_HEADER void* 19 #define PIMAGE_OPTIONAL_HEADER void* 20 #define PIMAGE_DATA_DIRECTORY void* 21 #define PIMAGE_SECTION_HEADER void* 22 #define PIMAGE_EXPORT_DIRECTORY void* 23 #define PIMAGE_IMPORT_DESCRIPTOR void* 24 #define PIMAGE_RESOURCE_DIRECTORY void* 25 #define PIMAGE_BASE_RELOCATION void* 26 #define PIMAGE_DEBUG_DIRECTORY void* 27 #define PSZ void* 28 #define PULONG void* 29 #define PIMAGE_TLS_DIRECTORY void* 30 #define PIMAGE_LOAD_CONFIG_DIRECTORY void* 31 #define PIMAGE_IMPORT_DESCRIPTOR void* 32 #define PIMAGE_THUNK_DATA void* 33 #define PIMAGE_IMPORT_DESCRIPTOR void* 34 #else 35 #include <peexe.h> 36 #endif 12 #ifndef _peexe_h_ 13 #define PIMAGE_DOS_HEADER void * 14 #define PIMAGE_FILE_HEADER void * 15 #define PIMAGE_OPTIONAL_HEADER void * 16 #define PIMAGE_DATA_DIRECTORY void * 17 #define PIMAGE_SECTION_HEADER void * 18 #define PIMAGE_EXPORT_DIRECTORY void * 19 #define PIMAGE_IMPORT_DESCRIPTOR void * 20 #define PIMAGE_RESOURCE_DIRECTORY void * 21 #define PIMAGE_BASE_RELOCATION void * 22 #define PIMAGE_DEBUG_DIRECTORY void * 23 #define PIMAGE_TLS_DIRECTORY void * 24 #define PIMAGE_LOAD_CONFIG_DIRECTORY void * 25 #define PIMAGE_IMPORT_DESCRIPTOR void * 26 #define PIMAGE_THUNK_DATA void * 27 #define PIMAGE_IMPORT_DESCRIPTOR void * 37 28 #endif 38 29 39 30 40 /*******************************************************************************41 * Structures and Typedefs *42 *******************************************************************************/43 44 31 /** 45 32 * PE (portable executable) files. 46 * TODO: error handling.47 33 * @author knut st. osmundsen 48 34 */ … … 50 36 { 51 37 private: 52 void *pvBase;38 void * pvBase; /* The file mapping. */ 53 39 54 /* headers */55 PIMAGE_DOS_HEADER pDosHdr;56 PIMAGE_FILE_HEADER pFileHdr;57 PIMAGE_OPTIONAL_HEADER pOptHdr;58 PIMAGE_DATA_DIRECTORY paDataDir;59 PIMAGE_SECTION_HEADER paSectionHdr;40 /* headers - pointers within the filemapping. */ 41 PIMAGE_DOS_HEADER pDosHdr; 42 PIMAGE_FILE_HEADER pFileHdr; 43 PIMAGE_OPTIONAL_HEADER pOptHdr; 44 PIMAGE_DATA_DIRECTORY paDataDir; 45 PIMAGE_SECTION_HEADER paSectionHdr; 60 46 61 47 /** @cat … … 65 51 PIMAGE_IMPORT_DESCRIPTOR pImportDir; /* 1 */ 66 52 PIMAGE_RESOURCE_DIRECTORY pRsrcDir; /* 2 */ 67 PVOIDpExcpDir; /* 3 */68 PVOIDpSecDir; /* 4 */53 void * pExcpDir; /* 3 */ 54 void * pSecDir; /* 4 */ 69 55 PIMAGE_BASE_RELOCATION pBRelocDir; /* 5 */ 70 56 PIMAGE_DEBUG_DIRECTORY pDebugDir; /* 6 */ 71 PSZpCopyright; /* 7 */72 PULONGpulGlobalPtr; /* 8 */ //is this the correct pointer type?57 char * pCopyright; /* 7 */ 58 unsigned long * pulGlobalPtr; /* 8 */ //is this the correct pointer type? 73 59 PIMAGE_TLS_DIRECTORY pTLSDir; /* 9 */ 74 60 PIMAGE_LOAD_CONFIG_DIRECTORY pLoadConfigDir; /* 10 */ … … 76 62 PIMAGE_THUNK_DATA pIATDir; /* 12 */ //is this the correct pointer type? 77 63 PIMAGE_IMPORT_DESCRIPTOR pDelayImportDir;/* 13 */ 78 PVOIDpComDir; /* 14 */79 PVOIDpv15; /* 15 */64 void * pComDir; /* 14 */ 65 void * pv15; /* 15 */ 80 66 81 67 public: 82 kFilePE(kFile *pFile) throw (int);68 kFilePE(kFile *pFile) throw (kError); 83 69 virtual ~kFilePE(); 84 70 85 71 /** @cat Module information methods. */ 86 BOOLmoduleGetName(char *pszBuffer, int cchSize = 260);72 KBOOL moduleGetName(char *pszBuffer, int cchSize = 260); 87 73 88 74 /** @cat Export enumeration methods. */ 89 BOOLexportFindFirst(kExportEntry *pExport);90 BOOLexportFindNext(kExportEntry *pExport);75 KBOOL exportFindFirst(kExportEntry *pExport); 76 KBOOL exportFindNext(kExportEntry *pExport); 91 77 void exportFindClose(kExportEntry *pExport); 92 78 93 79 /** @cat Export Lookup methods */ 94 BOOLexportLookup(unsigned long ulOrdinal, kExportEntry *pExport);95 BOOLexportLookup(const char * pszName, kExportEntry *pExport);80 KBOOL exportLookup(unsigned long ulOrdinal, kExportEntry *pExport); 81 KBOOL exportLookup(const char * pszName, kExportEntry *pExport); 96 82 97 BOOL isPe() const{ return TRUE;}83 KBOOL isPe() const { return TRUE;} 98 84 99 BOOLdump(kFile *pOut);85 KBOOL dump(kFile *pOut); 100 86 }; 101 87 -
trunk/tools/common/kFileSDF.cpp
r5534 r8003 1 /* $Id: kFileSDF.cpp,v 1. 1 2001-04-17 04:16:03bird Exp $1 /* $Id: kFileSDF.cpp,v 1.2 2002-02-24 02:47:27 bird Exp $ 2 2 * 3 3 * kFileSDF- Structure Defintion File class Implementation. … … 18 18 * Header Files * 19 19 *******************************************************************************/ 20 #include <os2.h>21 22 20 #include <string.h> 23 #include <malloc.h> 24 25 #include "kInterfaces.h" 21 22 #include "kTypes.h" 23 #include "kError.h" 24 #include "kFileInterfaces.h" 26 25 #include "kFile.h" 27 26 #include "kFileFormatBase.h" … … 34 33 35 34 35 36 36 /******************************************************************************* 37 37 * Global Variables * 38 38 *******************************************************************************/ 39 #if 139 #if 0 40 40 static kFileSDF tst((kFile*)NULL); 41 41 #endif … … 67 67 * 68 68 */ 69 void kFileSDF::parseSDFFile(void *pvFile) throw(int)69 void kFileSDF::parseSDFFile(void *pvFile) 70 70 { 71 71 /* … … 75 75 if ( pHdr->cStructs >= 0x8000 /* 32k is a reasonable limit. */ 76 76 || pHdr->cTypes >= 0x8000) 77 throw( 1);77 throw(kError(kError::SDF_TOO_MANY)); 78 78 79 79 /* … … 160 160 * @remark Will throw error codes. 161 161 */ 162 kFileSDF::kFileSDF(kFile *pFile) throw(int):163 papStructs(NULL), pHdr(NULL), paTypes(NULL)162 kFileSDF::kFileSDF(kFile *pFile) : 163 kFileFormatBase(pFile), papStructs(NULL), pHdr(NULL), paTypes(NULL) 164 164 { 165 165 long cchFile = pFile->getSize(); 166 void * pvFile = pFile-> readFile();166 void * pvFile = pFile->mapFile(); 167 167 168 168 /* … … 197 197 catch (int err) 198 198 { 199 free(pvFile);199 kFile::mapFree(pvFile); 200 200 if (papStructs); 201 201 delete papStructs; … … 209 209 if (papStructs); 210 210 delete papStructs; 211 free(pHdr); 212 } 211 kFile::mapFree(pHdr); 212 } 213 214 215 216 kDbgTypeEntry * kFileSDF::dbgtypeFindFirst(int flFlags) 217 { 218 return NULL; 219 } 220 221 kDbgTypeEntry * kFileSDF::dbgtypeFindNext(kDbgTypeEntry *kDbgTypeEntry) 222 { 223 return NULL; 224 } 225 226 void kFileSDF::dbgtypeFindClose(kDbgTypeEntry *kDbgTypeEntry) 227 { 228 return; 229 } 230 231 kDbgTypeEntry * kFileSDF::dbgtypeLookup(const char *pszName, int flFlags) 232 { 233 return NULL; 234 } 235 236 237 238 239 KBOOL kFileSDF::dump(kFile *pOut) 240 { 241 return FALSE; 242 } 243 -
trunk/tools/common/kFileSDF.h
r5534 r8003 1 /* $Id: kFileSDF.h,v 1. 1 2001-04-17 04:16:03bird Exp $1 /* $Id: kFileSDF.h,v 1.2 2002-02-24 02:47:27 bird Exp $ 2 2 * 3 3 * kFileSDF- Structure Defintion File class declaration. … … 68 68 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 69 69 */ 70 class kFileSDF : public kFileFormatBase 70 class kFileSDF : public kFileFormatBase, public kDbgTypeI 71 71 { 72 72 private: … … 75 75 PSDFTYPE paTypes; 76 76 77 void parseSDFFile(void *pvFile) throw (int);77 void parseSDFFile(void *pvFile) throw (kError); 78 78 PSDFTYPE getType(const char *pszType); 79 79 PSDFSTRUCT getStruct(const char *pszStruct); 80 80 81 81 public: 82 kFileSDF(kFile *pFile) throw (int);82 kFileSDF(kFile *pFile) throw (kError); 83 83 ~kFileSDF(); 84 84 85 BOOL dump(kFile *pOut); 85 /** @cat Debug Type information methods. */ 86 kDbgTypeEntry * dbgtypeFindFirst(int flFlags); 87 kDbgTypeEntry * dbgtypeFindNext(kDbgTypeEntry *kDbgTypeEntry); 88 void dbgtypeFindClose(kDbgTypeEntry *kDbgTypeEntry); 89 90 kDbgTypeEntry * dbgtypeLookup(const char *pszName, int flFlags); 91 92 /** @cat Generic dump */ 93 KBOOL dump(kFile *pOut); 86 94 }; 95 -
trunk/tools/common/kLIFO.cpp
r824 r8003 1 /* $Id: kLIFO.cpp,v 1. 1 1999-09-05 02:09:17 bird Exp $ */1 /* $Id: kLIFO.cpp,v 1.2 2002-02-24 02:47:27 bird Exp $ */ 2 2 /* 3 3 * Simple LIFO template class implementation. … … 160 160 */ 161 161 template <class kEntry> 162 BOOL kLIFO<kEntry>::isEmpty(void) const162 KBOOL kLIFO<kEntry>::isEmpty(void) const 163 163 { 164 164 return pTop == NULL; … … 190 190 */ 191 191 template <class kEntry> 192 BOOL kLIFO<kEntry>::exists(const kEntry *pEntry) const192 KBOOL kLIFO<kEntry>::exists(const kEntry *pEntry) const 193 193 { 194 194 kEntry *pCurrentEntry = pTop; -
trunk/tools/common/kLIFO.h
r824 r8003 1 /* $Id: kLIFO.h,v 1. 1 1999-09-05 02:09:17 bird Exp $ */1 /* $Id: kLIFO.h,v 1.2 2002-02-24 02:47:27 bird Exp $ */ 2 2 /* 3 3 * Simple LIFO template class. … … 33 33 virtual void unwind(kEntry *pToEntry); 34 34 virtual void popPush(const kEntry *pToEntry, kLIFO<kEntry> &lifoTo); 35 BOOLisEmpty(void) const;35 KBOOL isEmpty(void) const; 36 36 37 37 virtual kEntry *find(const char *pszKey) const; 38 virtual BOOLexists(const kEntry *pEntry) const;38 virtual KBOOL exists(const kEntry *pEntry) const; 39 39 }; 40 40 -
trunk/tools/common/kList.cpp
r4129 r8003 1 /* $Id: kList.cpp,v 1. 3 2000-08-31 03:00:13bird Exp $ */1 /* $Id: kList.cpp,v 1.4 2002-02-24 02:47:28 bird Exp $ */ 2 2 /* 3 3 * Simple list and sorted list template class. … … 49 49 } 50 50 #ifdef DEBUG 51 if (cEntries != 0) 52 fprintf(stderr, 53 "%s(%d, %s)internal processing warning - cEntires was incorrect upon list destruction.", 54 __FILE__, __LINE__, __FUNCTION__); 51 kASSERT(cEntries == 0); 55 52 #endif 56 53 cEntries = 0; … … 195 192 } 196 193 #ifdef DEBUG 197 if (cEntries != 0) 198 fprintf(stderr, 199 "%s(%d, %s)internal processing warning - cEntires was incorrect upon list destruction.", 200 __FILE__, __LINE__, __FUNCTION__); 194 kASSERT(cEntries == 0); 201 195 #endif 202 196 cEntries = 0; -
trunk/tools/common/kList.h
r4129 r8003 1 /* $Id: kList.h,v 1. 3 2000-08-31 03:00:13bird Exp $ */1 /* $Id: kList.h,v 1.4 2002-02-24 02:47:28 bird Exp $ */ 2 2 /* 3 3 * Simple list and sorted list template class. … … 77 77 public: 78 78 #if 0 //MUST BE IMPLEMENTED! 79 virtual BOOL operator==(const k..Entry &entry) const = 0;80 virtual BOOL operator!=(const k..Entry &entry) const = 0;81 virtual BOOL operator< (const k..Entry &entry) const = 0;82 virtual BOOL operator<=(const k..Entry &entry) const = 0;83 virtual BOOL operator> (const k..Entry &entry) const = 0;84 virtual BOOL operator>=(const k..Entry &entry) const = 0;79 virtual KBOOL operator==(const k..Entry &entry) const = 0; 80 virtual KBOOL operator!=(const k..Entry &entry) const = 0; 81 virtual KBOOL operator< (const k..Entry &entry) const = 0; 82 virtual KBOOL operator<=(const k..Entry &entry) const = 0; 83 virtual KBOOL operator> (const k..Entry &entry) const = 0; 84 virtual KBOOL operator>=(const k..Entry &entry) const = 0; 85 85 #endif 86 86 };
Note:
See TracChangeset
for help on using the changeset viewer.