Changeset 4129 for trunk/tools
- Timestamp:
- Aug 31, 2000, 5:00:13 AM (25 years ago)
- Location:
- trunk/tools/common
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/common/kFile.cpp
r3629 r4129 1 /* $Id: kFile.cpp,v 1. 3 2000-05-29 19:45:57bird Exp $1 /* $Id: kFile.cpp,v 1.4 2000-08-31 03:00:12 bird Exp $ 2 2 * 3 3 * kFile - Simple (for the time being) file class. … … 39 39 if (!fStatusClean) 40 40 { 41 rc = (int)DosQueryFileInfo(hFile, FIL_QUERYEASIZE, &filestatus, sizeof(filestatus));41 rc = DosQueryFileInfo(hFile, FIL_QUERYEASIZE, &filestatus, sizeof(filestatus)); 42 42 fStatusClean = (rc == NO_ERROR); 43 43 if (!fStatusClean && fThrowErrors) 44 throw ( rc);44 throw ((int)rc); 45 45 } 46 46 else … … 64 64 { 65 65 ULONG off; 66 rc = (int)DosSetFilePtr(hFile, offVirtual, FILE_BEGIN, &off);66 rc = DosSetFilePtr(hFile, offVirtual, FILE_BEGIN, &off); 67 67 if (rc != NO_ERROR || off != offVirtual) 68 68 { 69 69 if (fThrowErrors) 70 throw ( rc);70 throw ((int)rc); 71 71 return FALSE; 72 72 } … … 86 86 * FALSE: Open the file readwrite appending 87 87 * existing files. 88 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)88 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 89 89 */ 90 90 kFile::kFile(const char *pszFilename, BOOL fReadOnly/*=TRUE*/) … … 93 93 fThrowErrors(FALSE), 94 94 offVirtual(0), 95 offReal(0) 95 offReal(0), 96 pszFilename(NULL) 96 97 { 97 98 ULONG fulOpenFlags; … … 113 114 } 114 115 115 rc = (int)DosOpen((PCSZ)pszFilename, &hFile, &ulAction, 0, FILE_NORMAL,116 116 rc = DosOpen((PCSZ)pszFilename, &hFile, &ulAction, 0, FILE_NORMAL, 117 fulOpenFlags, fulOpenMode, NULL); 117 118 if (rc != NO_ERROR) 118 throw ( rc);119 throw ((int)rc); 119 120 120 121 if (!refreshFileStatus()) 121 throw (rc); 122 throw ((int)rc); 123 124 char szFullName[CCHMAXPATH]; 125 if (DosQueryPathInfo(pszFilename, FIL_QUERYFULLNAME, szFullName, sizeof(szFullName))) 126 strcpy(szFullName, pszFilename); 127 this->pszFilename = strdup(szFullName); 128 if (this->pszFilename == NULL) 129 throw (ERROR_NOT_ENOUGH_MEMORY); 122 130 } 123 131 … … 143 151 { 144 152 ULONG cbRead; 145 rc = (int)DosRead(hFile, pvBuffer, cbBuffer, &cbRead);153 rc = DosRead(hFile, pvBuffer, cbBuffer, &cbRead); 146 154 if (rc == NO_ERROR) 147 155 { … … 152 160 153 161 if (fThrowErrors) 154 throw ( rc);162 throw ((int)rc); 155 163 return FALSE; 156 164 } … … 171 179 172 180 /** 181 * Reads the entire file into a single memory block. 182 * (The memory block has a '\0' at the end just in case you 183 * are using it as a long string.) 184 * @returns Pointer to file in memory. 185 */ 186 void * kFile::readFile() throw(int) 187 { 188 void *pv; 189 190 /* allocate memory for the file */ 191 pv = calloc((size_t)this->getSize() + 1, 1); 192 if (pv == NULL) 193 { 194 if (fThrowErrors) 195 throw(ERROR_NOT_ENOUGH_MEMORY); 196 return NULL; 197 } 198 199 /* go the start of the file and read it. */ 200 if (start() && read(pv, this->getSize())) 201 return pv; // successfull exit! 202 203 /* we failed, cleanup and return NULL */ 204 free(pv); 205 return NULL; 206 } 207 208 209 /** 173 210 * Writes <cbBuffer> bytes to the file at the current file position. 174 211 * @returns success indicator. (TRUE/FALSE) … … 186 223 ULONG cbWrote; 187 224 188 rc = (int)DosWrite(hFile, pvBuffer, cbBuffer, &cbWrote);225 rc = DosWrite(hFile, pvBuffer, cbBuffer, &cbWrote); 189 226 if (rc == NO_ERROR) 190 227 { … … 197 234 198 235 if (fThrowErrors) 199 throw (rc);236 throw ((int)rc); 200 237 return FALSE; 201 238 } … … 253 290 free(pszBuffer); 254 291 255 return getPos() - offStart; 256 } 257 292 return (int)(getPos() - offStart); 293 } 294 295 296 /** 297 * Sets the filesize. 298 * @returns Success indicator. 299 * @param cbFile New filesize. 300 * Defaults to 0xffffffff, which results in 301 * cutting the file at the current position. 302 */ 303 BOOL kFile::setSize(unsigned long cbFile/*= ~0UL*/) 304 { 305 if (cbFile == ~0UL) 306 cbFile = offVirtual; 307 rc = DosSetFileSize(hFile, cbFile); 308 if (rc != NO_ERROR && fThrowErrors) 309 throw ((int)rc); 310 311 return rc == NO_ERROR; 312 } 258 313 259 314 … … 280 335 281 336 if (fThrowErrors) 282 throw (rc);337 throw ((int)rc); 283 338 return FALSE; 284 339 } … … 306 361 } 307 362 if (fThrowErrors) 308 throw (rc);363 throw ((int)rc); 309 364 return FALSE; 310 365 } -
trunk/tools/common/kFile.h
r3629 r4129 1 /* $Id: kFile.h,v 1. 3 2000-05-29 19:45:58bird Exp $1 /* $Id: kFile.h,v 1.4 2000-08-31 03:00:13 bird Exp $ 2 2 * 3 3 * kFile - Simple (for the time being) file class. … … 26 26 HFILE hFile; /* Pointer to stdio filehandle */ 27 27 BOOL fReadOnly; /* True if readonly access, False is readwrite. */ 28 intrc; /* Last error (return code). */28 APIRET rc; /* Last error (return code). */ 29 29 FILESTATUS4 filestatus; /* Filestatus data. */ 30 30 BOOL fStatusClean; /* True if filestatus is clean. False is not clean */ 31 31 BOOL fThrowErrors; /* When true we'll throw the rc on errors, else return FALSE. */ 32 PSZ pszFilename; /* Pointer to filename. */ 32 33 33 34 /** @cat Position datamembers */ … … 49 50 BOOL read(void *pvBuffer, long cbBuffer) throw(int); 50 51 BOOL readAt(void *pvBuffer, long cbBuffer, long off) throw(int); 52 void * readFile() throw(int); 51 53 52 54 BOOL write(void *pvBuffer, long cbBuffer) throw(int); … … 54 56 55 57 int printf(const char *pszFormat, ...) throw (int); 58 59 BOOL setSize(unsigned long cbFile = ~0UL); 56 60 57 61 /** @cat File seek methods */ … … 65 69 long getPos() const throw(int); 66 70 BOOL isEOF() throw(int); 71 const char * getFilename() { return pszFilename; } 67 72 68 73 /** @cat Error handling */ -
trunk/tools/common/kFileFormatBase.h
r3246 r4129 1 /* $Id: kFileFormatBase.h,v 1. 2 2000-03-27 10:18:40bird Exp $1 /* $Id: kFileFormatBase.h,v 1.3 2000-08-31 03:00:13 bird Exp $ 2 2 * 3 3 * kFileFormatBase - Base class for kFile<format> classes. … … 29 29 typedef struct _ExportEntry 30 30 { 31 unsigned long ulOrdinal; 32 char achName[MAXEXPORTNAME]; 33 char achIntName[MAXEXPORTNAME]; /* not used by PEFile */ 31 unsigned long ulOrdinal; 32 char achName[MAXEXPORTNAME]; 33 char achIntName[MAXEXPORTNAME]; /* not used by PEFile */ 34 35 /* these don't apply for .DEF files. (should have a flag for that...) */ 36 unsigned long offset; 37 unsigned long iObject; 38 34 39 /* internal - do not use! */ 35 40 void *pv; -
trunk/tools/common/kFileLX.cpp
r3246 r4129 1 /* $Id: kFileLX.cpp,v 1. 1 2000-03-27 10:18:41bird Exp $1 /* $Id: kFileLX.cpp,v 1.2 2000-08-31 03:00:13 bird Exp $ 2 2 * 3 3 * … … 49 49 #include "kFileLX.h" 50 50 51 /******************************************************************************* 52 * Structures and Typedefs * 53 *******************************************************************************/ 54 typedef struct _export_state 55 { 56 struct b32_bundle * pb32; /* Pointer to current bundle. */ 57 int iOrdinalBundle; /* The ordinal the bundle starts at. */ 58 struct e32_entry * pe32; /* Pointer to the current bundle entry. */ 59 int iOrdinal; /* The current ordinal. */ 60 } EXPSTATE, *PEXPSTATE; 61 62 63 64 BOOL kFileLX::queryExportName(int iOrdinal, char *pszBuffer) 65 { 66 PUSHORT pus; 67 PUCHAR puch; 68 69 /* resident name table */ 70 if (pe32->e32_restab) 71 { 72 puch = (PUCHAR)pvBase + offLXHdr + pe32->e32_restab; 73 while (*puch != 0) 74 { 75 pus = (PUSHORT)(puch + 1 + *puch); 76 if (*pus == iOrdinal) 77 { 78 memcpy(pszBuffer, puch + 1, *puch); 79 pszBuffer[*puch] = '\0'; 80 return TRUE; 81 } 82 puch += *puch + 1 + 2; 83 } 84 } 85 86 /* not found, check the non-resident name table too */ 87 if (pe32->e32_nrestab) 88 { 89 puch = (PUCHAR)pvBase + pe32->e32_nrestab; 90 while (*puch != 0) 91 { 92 pus = (PUSHORT)(puch + 1 + *puch); 93 if (*pus == iOrdinal) 94 { 95 memcpy(pszBuffer, puch + 1, *puch); 96 pszBuffer[*puch] = '\0'; 97 return TRUE; 98 } 99 puch += *puch + 1 + 2; 100 } 101 } 102 103 return FALSE; 104 } 51 105 52 106 … … 101 155 BOOL kFileLX::queryModuleName(char *pszBuffer) 102 156 { 103 /* not implemented */ 104 assert("not implemented!"); 157 /* The module name is the 0 ordinal entry in resident name table */ 158 return queryExportName(0, pszBuffer); 159 } 160 161 162 163 BOOL kFileLX::findFirstExport(PEXPORTENTRY pExport) 164 { 165 struct b32_bundle * pBundle = (struct b32_bundle*)((char*)pvBase + pe32->e32_enttab + offLXHdr); 166 struct e32_entry * pEntry; 167 int iOrdinal = 1; 168 169 if (pe32->e32_enttab) 170 { 171 while (pBundle->b32_cnt != 0) 172 { 173 /* skip empty bundles */ 174 while (pBundle->b32_cnt != 0 && pBundle->b32_type == EMPTY) 175 { 176 iOrdinal += pBundle->b32_cnt; 177 pBundle = (struct b32_bundle*)((char*)pBundle + 2); 178 } 179 180 /* FIXME forwarders are not implemented so we'll skip them too. */ 181 while (pBundle->b32_cnt != 0 && (pBundle->b32_type & ~TYPEINFO) == ENTRYFWD) 182 { 183 iOrdinal += pBundle->b32_cnt; 184 pBundle = (struct b32_bundle*)((char*)(pBundle + 1) + pBundle->b32_cnt * 7); 185 } 186 187 /* we'll ignore any flags for the moment - TODO */ 188 if (pBundle->b32_cnt != 0) 189 { 190 pExport->ulOrdinal = iOrdinal; 191 pExport->iObject = pBundle->b32_obj; 192 193 /* look for name */ 194 pExport->achIntName[0] = '\0'; 195 if (!queryExportName(iOrdinal, pExport->achName)) 196 pExport->achName[0] = '\0'; 197 198 pEntry = (struct e32_entry*)(pBundle+1); 199 switch (pBundle->b32_type & ~TYPEINFO) 200 { 201 case ENTRY16: 202 pExport->offset = pEntry->e32_variant.e32_offset.offset16; 203 break; 204 205 case ENTRY32: 206 pExport->offset = pEntry->e32_variant.e32_offset.offset32; 207 break; 208 209 case GATE16: 210 pExport->offset = pEntry->e32_variant.e32_callgate.offset; 211 break; 212 default: 213 assert(!"ARG!!!! invalid bundle type!"); 214 } 215 216 /* store status - current export entry */ 217 PEXPSTATE pExpState = (PEXPSTATE)malloc(sizeof(EXPSTATE)); 218 pExport->pv = pExpState; 219 pExpState->pb32 = pBundle; 220 pExpState->iOrdinalBundle = iOrdinal; 221 pExpState->pe32 = pEntry; 222 pExpState->iOrdinal = iOrdinal; 223 return TRUE; 224 } 225 } 226 227 } 228 105 229 return FALSE; 106 230 } … … 108 232 109 233 110 BOOL kFileLX::findFirstExport(PEXPORTENTRY pExport) 111 { 112 /* not implemented */ 113 assert("not implemented!"); 234 BOOL kFileLX::findNextExport(PEXPORTENTRY pExport) 235 { 236 static int acbEntry[] = 237 { 238 0, /* EMPTY */ 239 3, /* ENTRY16 */ 240 5, /* GATE16 */ 241 5, /* ENTRY32 */ 242 7 /* ENTRYFWD */ 243 }; 244 245 PEXPSTATE pExpState = (PEXPSTATE)pExport->pv; 246 247 /* 248 * Get more ordinals from the current bundle if any left. 249 */ 250 if (pExpState->pb32->b32_cnt > (pExpState->iOrdinal - pExpState->iOrdinalBundle + 1)) 251 { 252 /* skip to the next entry */ 253 pExpState->iOrdinal++; 254 pExpState->pe32 = (struct e32_entry*)((char*)pExpState->pe32 255 + acbEntry[pExpState->pb32->b32_type & ~TYPEINFO]); 256 257 /* fill output struct */ 258 pExport->ulOrdinal = pExpState->iOrdinal; 259 pExport->iObject = pExpState->pb32->b32_obj; 260 261 /* look for name */ 262 pExport->achIntName[0] = '\0'; 263 if (!queryExportName(pExpState->iOrdinal, pExport->achName)) 264 pExport->achName[0] = '\0'; 265 266 /* offset */ 267 switch (pExpState->pb32->b32_type & ~TYPEINFO) 268 { 269 case ENTRY16: 270 pExport->offset = pExpState->pe32->e32_variant.e32_offset.offset16; 271 break; 272 273 case ENTRY32: 274 pExport->offset = pExpState->pe32->e32_variant.e32_offset.offset32; 275 break; 276 277 case GATE16: 278 pExport->offset = pExpState->pe32->e32_variant.e32_callgate.offset; 279 break; 280 } 281 282 return TRUE; 283 } 284 285 /* 286 * next bundle. 287 */ 288 pExpState->pb32 = (struct b32_bundle*)((char*)(pExpState->pb32 + 1) + 289 pExpState->pb32->b32_cnt * acbEntry[pExpState->pb32->b32_type & ~TYPEINFO]); 290 while (pExpState->pb32->b32_cnt != 0) 291 { 292 /* skip empty bundles */ 293 while (pExpState->pb32->b32_cnt != 0 && pExpState->pb32->b32_type == EMPTY) 294 { 295 pExpState->iOrdinal += pExpState->pb32->b32_cnt; 296 pExpState->pb32 = (struct b32_bundle*)((char*)pExpState->pb32 + 2); 297 } 298 299 /* FIXME forwarders are not implemented so we'll skip them too. */ 300 while (pExpState->pb32->b32_cnt != 0 && (pExpState->pb32->b32_type & ~TYPEINFO) == ENTRYFWD) 301 { 302 pExpState->iOrdinal += pExpState->pb32->b32_cnt; 303 pExpState->pb32 = (struct b32_bundle*)((char*)(pExpState->pb32 + 1) + pExpState->pb32->b32_cnt * 7); 304 } 305 306 /* we'll ignore any flags for the moment - TODO */ 307 if (pExpState->pb32->b32_cnt != 0) 308 { 309 pExpState->iOrdinalBundle = pExpState->iOrdinal; 310 311 pExport->ulOrdinal = pExpState->iOrdinal; 312 pExport->iObject = pExpState->pb32->b32_obj; 313 314 /* look for name */ 315 pExport->achIntName[0] = '\0'; 316 if (!queryExportName(pExpState->iOrdinal, pExport->achName)) 317 pExport->achName[0] = '\0'; 318 319 pExpState->pe32 = (struct e32_entry*)(pExpState->pb32+1); 320 switch (pExpState->pb32->b32_type & ~TYPEINFO) 321 { 322 case ENTRY16: 323 pExport->offset = pExpState->pe32->e32_variant.e32_offset.offset16; 324 break; 325 326 case ENTRY32: 327 pExport->offset = pExpState->pe32->e32_variant.e32_offset.offset32; 328 break; 329 330 case GATE16: 331 pExport->offset = pExpState->pe32->e32_variant.e32_callgate.offset; 332 break; 333 default: 334 assert(!"ARG!!!! invalid bundle type!"); 335 } 336 337 return TRUE; 338 } 339 } 340 341 342 /* 343 * No more exports - clean up 344 */ 345 free(pExport->pv); 346 pExport->pv = NULL; 114 347 return FALSE; 115 348 } 116 117 118 119 BOOL kFileLX::findNextExport(PEXPORTENTRY pExport)120 {121 /* not implemented */122 assert("not implemented!");123 return FALSE;124 }125 126 349 127 350 … … 140 363 141 364 365 /** 366 * Gets the count of LX objects. 367 * @returns Count of LX objects. 368 */ 369 int kFileLX::getObjectCount() 370 { 371 return (int)pe32->e32_objcnt; 372 } 373 -
trunk/tools/common/kFileLX.h
r3246 r4129 1 /* $Id: kFileLX.h,v 1. 1 2000-03-27 10:18:41bird Exp $1 /* $Id: kFileLX.h,v 1.2 2000-08-31 03:00:13 bird Exp $ 2 2 * 3 3 * kFileLX - Linear Executable file reader. … … 23 23 struct o32_obj * paObject; 24 24 25 BOOL queryExportName(int iOrdinal, char *pszBuffer); 26 25 27 public: 26 28 kFileLX(const char *pszFilename); 27 29 ~kFileLX(); 28 30 29 virtual BOOL queryModuleName(char *pszBuffer);30 virtual BOOL findFirstExport(PEXPORTENTRY pExport);31 virtual BOOL findNextExport(PEXPORTENTRY pExport);32 virtual BOOL isLx() const {return TRUE;};31 virtual BOOL queryModuleName(char *pszBuffer); 32 virtual BOOL findFirstExport(PEXPORTENTRY pExport); 33 virtual BOOL findNextExport(PEXPORTENTRY pExport); 34 virtual BOOL isLx() const {return TRUE;}; 33 35 34 struct o32_obj * getObject(int iObject); 36 struct o32_obj * getObject(int iObject); 37 int getObjectCount(); 35 38 36 39 -
trunk/tools/common/kList.cpp
r3237 r4129 1 /* $Id: kList.cpp,v 1. 2 2000-03-25 23:17:46bird Exp $ */1 /* $Id: kList.cpp,v 1.3 2000-08-31 03:00:13 bird Exp $ */ 2 2 /* 3 3 * Simple list and sorted list template class. … … 90 90 } 91 91 92 assert(p != NULL); 93 92 94 pEntry->setNext(p); 93 95 if (pPrev != NULL) … … 126 128 kEntry *kSortedList<kEntry>::getFirst(void) const 127 129 { 130 128 131 return pFirst; 129 132 } … … 226 229 } 227 230 231 #if 0 232 /** 233 * Inserts an entry into the list in an ascending sorted fashion. 234 * @param pEntry Pointer to entry to insert. 235 */ 236 template <class kEntry> 237 void kList<kEntry>::insertSorted(kEntry *pEntry) 238 { 239 if (pEntry == NULL) 240 return; 241 if (pFirst == NULL) 242 { 243 pEntry->setNext(NULL); 244 pLast = pFirst = pEntry; 245 } 246 else 247 { /* linear search */ 248 kEntry *pCur = pFirst; 249 250 pCur-> 251 252 pEntry->setNext(NULL); 253 pLast->setNext(pEntry); 254 pLast = pEntry; 255 } 256 cEntries++; 257 } 258 #endif 259 228 260 229 261 /** -
trunk/tools/common/kList.h
r3237 r4129 1 /* $Id: kList.h,v 1. 2 2000-03-25 23:17:47bird Exp $ */1 /* $Id: kList.h,v 1.3 2000-08-31 03:00:13 bird Exp $ */ 2 2 /* 3 3 * Simple list and sorted list template class. 4 * Note: simple list is not implemented yet, as it is not yet needed.5 4 * 6 5 * Copyright (c) 1999 knut st. osmundsen … … 9 8 #ifndef _lkList_h_ 10 9 #define _lkList_h_ 10 11 11 12 12 /** … … 40 40 return pNext; 41 41 } 42 }; 42 43 43 #if 0 44 /* !MUST IMPLEMENT! */ 45 BOOL operator==(const k... &entry) const; 46 BOOL operator!=(const k... &entry) const; 47 BOOL operator< (const k... &entry) const; 48 BOOL operator<=(const k... &entry) const; 49 BOOL operator> (const k... &entry) const; 50 BOOL operator>=(const k... &entry) const; 44 45 46 /** 47 * List template. Not Implemented yet. 48 * @author knut st. osmundsen 49 */ 50 template <class kEntry> 51 class kList 52 { 53 private: 54 kEntry *pFirst; 55 kEntry *pLast; 56 unsigned long cEntries; 57 58 public: 59 kList(void); 60 ~kList(void); 61 62 void destroy(void); 63 void insert(kEntry *pEntry); 64 kEntry * getFirst(void) const; 65 kEntry * getLast(void) const; 66 unsigned long getCount(void) const; 67 }; 68 69 70 /** 71 * List entry parent function. 72 * @purpose Serve as a base class for list sorted entries. 73 * @author knut st. osmundsen 74 */ 75 class kSortedListEntry : public kListEntry 76 { 77 public: 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; 51 85 #endif 52 86 }; … … 78 112 79 113 80 /**81 * List template. Not Implemented yet.82 * @author knut st. osmundsen83 */84 template <class kEntry>85 class kList86 {87 private:88 kEntry *pFirst;89 kEntry *pLast;90 unsigned long cEntries;91 92 public:93 kList(void);94 ~kList(void);95 96 void destroy(void);97 void insert(kEntry *pEntry);98 kEntry * getFirst(void) const;99 kEntry * getLast(void) const;100 unsigned long getCount(void) const;101 };102 103 114 #endif 104 115
Note:
See TracChangeset
for help on using the changeset viewer.