int main(int argc, char* argv[]) /******************************/ { char tmpFile[L_tmpnam]; bool quiet; quiet = false; set_new_handler(outOfMemory); try { if( argc != 2 ) { if( argc == 3 && stricmp( argv[1], "/nologo" ) == 0 ) { quiet = true; argv[1] = argv[2]; } else { cerr << CVpackUsage; return 1; } } if( !quiet ) { cout << CVpackHeader << endl; } ::ConvertFName(argv[1]); ifstream fd(fName, ios::in | ios::binary); if ( !fd ) { throw FileError(fName); } tmpnam(tmpFile); CVpack packMaker(fd,tmpFile); //cerr << "calling packMaker.CreatePackExe()\n"; //cerr.flush(); packMaker.CreatePackExe(); //cout << "cvpack, packMaker.CreatePackExe() OK\n"; //cout.flush(); fd.close(); if ( remove(fName) ) { throw MiscError(strerror(errno)); } if ( rename(tmpFile,fName) ) { throw MiscError(strerror(errno)); } } catch (CVpackError& CVerr) { CVerr.ErrorPrint(); remove(tmpFile); exit(1); } return 0; }
// // newTypeIndex defaulted to 0 to indicate that a new type is to be enter. // void TypeIndexMap::Insert( const type_index oldTypeIndex, const type_index newTypeIndex ) /********************************************************/ { try { if ( newTypeIndex != 0 ) { _mappingTable[oldTypeIndex].globalIndex = newTypeIndex; _mappingTable[oldTypeIndex].isNewType = FALSE; } else { // check if running out of types. if ( _currentGlobalIndex >= 0xffff ) { throw MiscError("fatal : running out of type indices."); } _mappingTable[oldTypeIndex].globalIndex = _currentGlobalIndex++; _mappingTable[oldTypeIndex].isNewType = TRUE; } // testing code. _mappingTable[oldTypeIndex].isDone = TRUE; } catch (...) { cerr << "index : " << oldTypeIndex << endl; throw InternalError("packtype.cpp : TypeIndexMap::Lookup() index range failed."); } }
// // Retriever::CheckSig(). // Checks the validness of the CV signature. // void Retriever::CheckSig() /************************/ { if (( strncmp(_inputBuffer,NB09,4) == 0 )|| ( strncmp(_inputBuffer,NB11,4) == 0 )) { throw MiscError("file already packed."); } // NB05 is the only version that we support. if ( strncmp(_inputBuffer,NB05,4) != 0 ) { throw CVSigError(); } }
void CVpack::DoExeCode() /**********************/ { unsigned_32 length = _aRetriever.TellExeLength(); if ( length ) { char* buffer = new char [length]; if ( ! _aRetriever.ReadExeCode(buffer) ) { throw MiscError("error while reading executable code."); } _eMaker.DumpToExe(buffer,length); delete [] buffer; } _lfaBase = length; _ddeBase = _aRetriever.TellDDEBase(); }
void Error::translate(RemoteDB::Error e) { switch(e.code()) { //case SUCCESS : return "NoError"; case NOIMPL : throw NotImplementedError(e); case INVALID : throw InvalidError(e); case LOGIC : throw LogicError(e); case TIMEOUT : throw TimeoutError(e); case INTERNAL: throw InternalError(e); case NETWORK : throw NetworkError(e); case EMISC : throw MiscError(e); default : throw Error(e); } }
uint CVpack::DoSegMap() /*********************/ { uint cSeg = 0; unsigned_32 length; char* buffer; if ( _aRetriever.ReadSubsection(buffer,length,sstSegMap) ) { cSeg = * (unsigned_16 *) buffer; _newDir.Insert(sstSegMap,MODULE_INDEPENDENT,OFBase(),length); _eMaker.DumpToExe(buffer,length); } else { throw MiscError("no sstSegMap present."); } return( cSeg ); }