static bool ModInfo_LoadFromFile(ModInfo* pMod, const char* pFilename) { if (!pMod) return false; if (!gEnv || !gEnv->pCryPak) { assert(0); return false; } ICryPak* pCryPak = gEnv->pCryPak; FILE* f = pCryPak->FOpen(pFilename, "rb", ICryPak::FOPEN_ONDISK); if (!f) return false; pCryPak->FSeek(f, 0, SEEK_END); const size_t fileSize = pCryPak->FTell(f); pCryPak->FSeek(f, 0, SEEK_SET); if (fileSize == 0) { pCryPak->FClose(f); return false; } std::vector<char> buffer; buffer.resize(fileSize); if (pCryPak->FRead(&buffer[0], fileSize, f) != fileSize) { pCryPak->FClose(f); return false; } pCryPak->FClose(f); std::auto_ptr<IXmlParser> pParser(GetISystem()->GetXmlUtils()->CreateXmlParser()); XmlNodeRef pRoot = pParser->ParseBuffer(&buffer[0], buffer.size(), true); if (!pRoot) return false; if (!ModInfo_LoadFromXML(pMod, pRoot)) return false; return true; }
DLLEXPORT FPDF_DOCUMENT STDCALL FPDFAvail_GetDocument(FPDF_AVAIL avail, FPDF_BYTESTRING password) { CFPDF_DataAvail* pDataAvail = static_cast<CFPDF_DataAvail*>(avail); if (!pDataAvail) return nullptr; std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser); pParser->SetPassword(password); std::unique_ptr<CPDF_Document> pDocument( new CPDF_Document(std::move(pParser))); CPDF_Parser::Error error = pDocument->GetParser()->StartLinearizedParse( pDataAvail->m_pDataAvail->GetFileRead(), pDocument.get()); if (error != CPDF_Parser::SUCCESS) { ProcessParseError(error); return nullptr; } pDataAvail->m_pDataAvail->SetDocument(pDocument.get()); CheckUnSupportError(pDocument.get(), FPDF_ERR_SUCCESS); return FPDFDocumentFromCPDFDocument(pDocument.release()); }
void CNetListener::addListener(const char *pszParser, const unsigned short &usType, const char *pszHost, const unsigned short &usPort) { CParser *pParser(m_pParserMgr->getParser(pszParser)); H_ASSERT(NULL != pParser, "get parser error."); CNetInfo *pNetInfo = new(std::nothrow) CNetInfo(this, pParser, usType, pszHost, usPort); if (NULL == pNetInfo) { H_LOG(LOGLV_ERROR, "%s", H_ERR_MEMORY); return; } CAddListenAdjure *pAdjure = new(std::nothrow) CAddListenAdjure(pNetInfo); if (NULL == pAdjure) { H_SafeDelete(pNetInfo); H_LOG(LOGLV_ERROR, "%s", H_ERR_MEMORY); return; } Adjure(pAdjure); }
//----------------------------------------------------------------------------- //Function Name : void* DlSymByDependencyOrdering(const void* aHandle, // const char* aName) //Description : To search for symbol named name in statically dependent dll // on aSymInfoHeader, is dependencies, also dependencies of // dependencies using Dependency-ordering. //Return Value : Valid address if name found otherwise NULL //----------------------------------------------------------------------------- void* DlSymByDependencyOrdering(const void* aHandle,const char* aName) { //Get 0th ordinal datastructure of dll denoted by handle. LoadedDlls()->Lock(); TInt idx = LoadedDlls()->Find(aHandle); //check if handle not found if ( KErrNotFound == idx ) { LoadedDlls()->UnLock(); SetError(KDlSymErrBadHandle); return NULL; } TDllEntry& dllEntry = LoadedDlls()->At(idx); // The below 'if' condition prevents the symbol lookup on non-STDDLL // Check for the symbol information, if not found // return with KDlSymErrNoSupport if( !dllEntry.iSymbolHeader ) { LoadedDlls()->UnLock(); SetError(KDlSymErrNoSupport); return NULL; } TBuf8<KMaxFileName> fileName; if(CnvUtfConverter::ConvertFromUnicodeToUtf8(fileName,dllEntry.iLibrary.FileName()) != 0) { LoadedDlls()->UnLock(); return NULL; } TE32ExpSymInfoHdr* symInfoHeader = dllEntry.iSymbolHeader; //Queue for using Breadthfirst search / Dependency ordering. RArray<TImageData> dependentDllQue; TImageData imageData((char*)fileName.PtrZ(), symInfoHeader); //add first item in queue TInt err = dependentDllQue.Append(imageData); if ( KErrNone != err ) { LoadedDlls()->UnLock(); dependentDllQue.Close(); SetError(KDlSymErrNoMemory); return NULL; } char* curDll = NULL; char* dependentDll = NULL; HMODULE handleToDll = NULL; TBuf<KMaxFileName> dependentfileName; TE32ExpSymInfoHdr* tempSymInfoHeader = NULL; void* symAddr = NULL; TPtrC8 tempPtr; //Array of searched dlls. Used to check circular dependency //this is array of pointer to name of dll in image RPointerArray<TE32ExpSymInfoHdr> searchedDlls; //Breath First search for Dependancy ordering. while(dependentDllQue.Count()) { imageData = dependentDllQue[0]; curDll = imageData.iFileName; symInfoHeader = imageData.iSymInfoHeader; dependentDllQue.Remove(0); // The below 'if' condition prevents the symbol lookup on dependent non-STDDLL if(!symInfoHeader) { continue; } tempPtr.Set((unsigned char*)curDll, strlen(curDll)); dependentfileName.Copy(tempPtr); TParsePtr pParser(dependentfileName); dependentfileName = pParser.NameAndExt(); //Search in this dll's symbol table handleToDll = Emulator::GetModuleHandle(dependentfileName.PtrZ()); symAddr = Emulator::GetProcAddress(handleToDll,aName); //check if symbol is found if( symAddr ) { LoadedDlls()->UnLock(); dependentDllQue.Close(); searchedDlls.Close(); return symAddr; } //Insert this to searched list err = searchedDlls.Append(symInfoHeader); if ( KErrNone != err ) { LoadedDlls()->UnLock(); dependentDllQue.Close(); searchedDlls.Close(); SetError(KDlSymErrNoMemory); return NULL; } //Add list of dependencies dependentDll = (char*) symInfoHeader + sizeof(TE32ExpSymInfoHdr); //Add at last to make it Queue, needed for Dependency ordering for (TInt i = 0; i < symInfoHeader->iDllCount; i++) { tempPtr.Set((unsigned char*)dependentDll, strlen(dependentDll)); dependentfileName.Copy(tempPtr); //get i'th dependency handleToDll = Emulator::GetModuleHandle(dependentfileName.PtrZ()); Emulator::TModule aModule((HINSTANCE)handleToDll); tempSymInfoHeader = (TE32ExpSymInfoHdr*)aModule.Section(KWin32SectionName_NmdExpData); //check i'th dependency is OE dll e.i. equal to zero or not //and also its not already searched if ( tempSymInfoHeader && searchedDlls.Find(tempSymInfoHeader) == KErrNotFound ) { imageData.iFileName = dependentDll; imageData.iSymInfoHeader = tempSymInfoHeader; err = dependentDllQue.Append(imageData); if ( KErrNone != err ) { LoadedDlls()->UnLock(); dependentDllQue.Close(); searchedDlls.Close(); SetError(KDlSymErrNoMemory); return NULL; } } //advance to next dependent dll dependentDll += tempPtr.Length() + 1; } } LoadedDlls()->UnLock(); dependentDllQue.Close(); searchedDlls.Close(); //Symbol not found return NULL SetError(KDlSymErrNotFound); return NULL; }
//----------------------------------------------------------------------------- //Function Name : TInt SearchSymbolByLoadordering(TE32ExpSymInfoHdr* symInfoHeader // , char* aFileName, const char* aName, // RPointerArray<TE32ExpSymInfoHdr>& aSearchedDlls, // void*& aSymAddress) //Description : To search for symbol named name in statically dependent dll // on aSymInfoHeader, it may be belonging to EXE or a DLL, also // dependencies of dependencies using Load-ordering. It also sets // valid address in aSymAddress if name found, and all sll it searched in // aSearchedDlls param. //Return Value : KErrNone if symbol found otherwise system wide error codes. //----------------------------------------------------------------------------- TInt SearchSymbolByLoadordering(const TE32ExpSymInfoHdr* symInfoHeader, const char* aFileName, const char* aName, RPointerArray<TE32ExpSymInfoHdr>& aSearchedDlls, void*& aSymAddress) { //This is used as stack for Load-ordering or Depthfirst search. RArray<TImageData> dependentDllStack; //here on emulator we need two things one is Name to find symbol in that list, //second is TE32ExpSymInfoHdr to find dependencies TImageData imageData((char*)aFileName, (TE32ExpSymInfoHdr*)symInfoHeader); aSymAddress = NULL; //Add exe on the stack TInt err = dependentDllStack.Append(imageData); if ( KErrNone != err ) { dependentDllStack.Close(); return KErrNoMemory; } TE32ExpSymInfoHdr* tempSymInfoHeader = NULL; TInt lastIdx = 0; char* curDll = NULL; char* dependentDll = NULL; HMODULE handleToDll = NULL; TPtrC8 tempPtr; TBuf<KMaxFileName> dependentfileName; //Retunn address would be stored in this void* symAddr = NULL; //user to maintain load ordering RArray<TImageData> curDependentDll; TImageData tempImageData; //Depth First search for Load-ordering. while ( lastIdx >= 0 ) { //Take first dll on the stack i.e. topmost imageData = dependentDllStack[lastIdx]; symInfoHeader = imageData.iSymInfoHeader; //Remove from stack dependentDllStack.Remove(lastIdx); if(!symInfoHeader) { //skip non-std binaries... lastIdx = dependentDllStack.Count() - 1; continue; } curDll = imageData.iFileName; tempPtr.Set((unsigned char*)curDll, strlen(curDll)); dependentfileName.Copy(tempPtr); TParsePtr pParser(dependentfileName); dependentfileName = pParser.NameAndExt(); //Search in this dll's symbol table handleToDll = Emulator::GetModuleHandle(dependentfileName.PtrZ()); symAddr = Emulator::GetProcAddress(handleToDll,aName); //Check if Symbol is found if( symAddr ) { dependentDllStack.Close(); aSymAddress = symAddr; return KErrNone; } //Add this dll to list of searched dlls err = aSearchedDlls.Append(symInfoHeader); if ( KErrNone != err ) { dependentDllStack.Close(); return KErrNoMemory; } dependentDll = (char*) symInfoHeader + sizeof(TE32ExpSymInfoHdr); //if this image is an exe - the these would be some symbols if ( symInfoHeader->iSymCount ) {//skip all symbol addresse char* curSymbolStr = dependentDll + (KFourByteOffset * symInfoHeader->iSymCount); //skip all symbol names for (TInt i = 0; i < symInfoHeader->iSymCount; ++i ) { curSymbolStr += strlen(curSymbolStr) + 1; } //initialise first dependent dll name dependentDll = curSymbolStr; } //Store names of all dependent dlls of current dll/exe store there name in //curDependentDll. This is done to maintain load ordering. for (TInt i = 0; i < symInfoHeader->iDllCount; ++i) { tempPtr.Set((unsigned char*)dependentDll, strlen(dependentDll)); dependentfileName.Copy(tempPtr); handleToDll = Emulator::GetModuleHandle(dependentfileName.PtrZ()); Emulator::TModule aModule((HINSTANCE)handleToDll); tempSymInfoHeader = (TE32ExpSymInfoHdr*)aModule.Section(KWin32SectionName_NmdExpData); if ( tempSymInfoHeader && aSearchedDlls.Find(tempSymInfoHeader) == KErrNotFound ) { tempImageData.iFileName = dependentDll; tempImageData.iSymInfoHeader = tempSymInfoHeader; err = curDependentDll.Append(tempImageData); if ( KErrNone != err ) { dependentDllStack.Close(); curDependentDll.Close(); return KErrNoMemory; } } //advance to next dependent dll dependentDll += tempPtr.Length() + 1; } //add in load order to dependentDllStack for (TInt i = curDependentDll.Count() - 1; i >= 0; --i) { err = dependentDllStack.Append(curDependentDll[i]); if ( KErrNone != err ) { dependentDllStack.Close(); curDependentDll.Close(); return KErrNoMemory; } } curDependentDll.Close(); lastIdx = dependentDllStack.Count() - 1; } dependentDllStack.Close(); return KErrNotFound; }