uint8 FBuildPatchUtils::VerifyFile(const FString& FileToVerify, const FSHAHashData& Hash1, const FSHAHashData& Hash2) { FBuildPatchFloatDelegate NoProgressDelegate; FBuildPatchBoolRetDelegate NoPauseDelegate; double NoDouble; return VerifyFile(FileToVerify, Hash1, Hash2, NoProgressDelegate, NoPauseDelegate, NoDouble); }
bool WINAPI SFileGetFileChecksums(HANDLE hMpq, const char * szFileName, LPDWORD pdwCrc32, char * pMD5) { DWORD dwVerifyResult; DWORD dwVerifyFlags = 0; if(pdwCrc32 != NULL) dwVerifyFlags |= SFILE_VERIFY_FILE_CRC; if(pMD5 != NULL) dwVerifyFlags |= SFILE_VERIFY_FILE_MD5; dwVerifyResult = VerifyFile(hMpq, szFileName, pdwCrc32, pMD5, dwVerifyFlags); // If verification failed, return zero if(dwVerifyResult & VERIFY_FILE_ERROR_MASK) { SetLastError(ERROR_FILE_CORRUPT); return false; } return true; }
DWORD WINAPI SFileVerifyFile(HANDLE hMpq, const char * szFileName, DWORD dwFlags) { return VerifyFile(hMpq, szFileName, NULL, NULL, dwFlags); }
/* Scrubs the given file data by overwriting Returns: SCRUB_OK - Successful SCRUB_VERIFY_ERR - Verification failure SCRUB_ERR - Errors occured */ int Scrubber::ScrubData(int fdFile, off64_t nFileSize, char* arrBuffer) { int nVal, nResult = SCRUB_OK; bool bRandomize; unsigned int nOptBuffSize; // Loop through pattern passes for(unsigned int nCurr = 0; nCurr < scrbPattern->lstPasses.size(); nCurr++) { // Get current item ScrubPass psCurr = scrbPattern->lstPasses[nCurr]; // Check if random pass if (scrbPattern->lstPasses[nCurr].pType == ScrubPass::RANDOM) { bRandomize = true; nOptBuffSize = this->nBufferSize; } else { bRandomize = false; nOptBuffSize = GetOptBuffSize(this->nBufferSize, psCurr.arr.size()); FillBuffer(arrBuffer, &psCurr.arr); } // Report scrub pass start WriteToLog(ScrubLogger::SCRUB_PASS_START, nCurr); // Fill file and check if successful if (FillFile(fdFile, nFileSize, arrBuffer, nOptBuffSize, bRandomize) < 0) { nResult = SCRUB_ERR; } // Report scrub pass ended with result WriteToLog(ScrubLogger::SCRUB_PASS_END, nResult); // Check if we need to verify if (scrbPattern->lstPasses[nCurr].pType == ScrubPass::VERIFY) { // Report verify file start WriteToLog(ScrubLogger::SCRUB_VERIFY_START, nCurr); // Verify file nVal = VerifyFile(fdFile, nFileSize, arrBuffer, nOptBuffSize); if (nResult == SCRUB_OK && nVal != SCRUB_OK) nResult = nVal; // Report verify file end WriteToLog(ScrubLogger::SCRUB_VERIFY_END, nVal); } } return nResult; }
/*************************************************************************************** Main (the main function) ***************************************************************************************/ int main(int argc, char* argv[]) { /////////////////////////////////////////////////////////////////////////////// // error check the command line parameters /////////////////////////////////////////////////////////////////////////////// if (argc != 2) { printf("~~~Improper Usage~~~\n\n"); printf("Usage Example: Sample 1.exe \"c:\\1.ape\"\n\n"); return 0; } /////////////////////////////////////////////////////////////////////////////// // variable declares /////////////////////////////////////////////////////////////////////////////// int nPercentageDone = 0; //the percentage done... continually updated by the decoder int nKillFlag = 0; //the kill flag for controlling the decoder int nRetVal = 0; //generic holder for return values char * pFilename = argv[1]; //the file to open /////////////////////////////////////////////////////////////////////////////// // attempt to verify the file /////////////////////////////////////////////////////////////////////////////// // set the start time and display the starting message g_nInitialTickCount = GetTickCount(); printf("Verifying '%s'...\n", pFilename); // do the verify (call unmac.dll) nRetVal = VerifyFile(pFilename, &nPercentageDone, ProgressCallback, &nKillFlag); // process the return value if (nRetVal == 0) printf("\nPassed...\n"); else printf("\nFailed (error: %d)\n", nRetVal); /////////////////////////////////////////////////////////////////////////////// // quit /////////////////////////////////////////////////////////////////////////////// return 0; }
CefRefPtr<CefResourceHandler> CWebApp::Create(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& scheme_name, CefRefPtr<CefRequest> request) { // browser or frame are NULL if the request does not orginate from a browser window // This is for exmaple true for the application cache or CEFURLRequests // (http://www.html5rocks.com/en/tutorials/appcache/beginner/) if (!browser || !frame) return nullptr; CWebCore* pWebCore = static_cast<CWebCore*>(g_pCore->GetWebCore()); auto pWebView = pWebCore->FindWebView(browser); if (!pWebView || !pWebView->IsLocal()) return nullptr; CefURLParts urlParts; if (!CefParseURL(request->GetURL(), urlParts)) return nullptr; if (scheme_name == "mtalocal") // Backward compatibility { // Get full path SString path = UTF16ToMbUTF8(urlParts.path.str).substr(2); // Check if we're dealing with an external resource if (path[0] == ':') { size_t end = path.find_first_of('/'); if (end != std::string::npos) { SString resourceName = path.substr(1, end - 1); SString resourcePath = path.substr(end); // Call this function recursively and use the mta scheme instead request->SetURL("http://mta/local/" + resourceName + resourcePath); return Create(browser, frame, "http", request); } return HandleError("404 - Not found", 404); } // Redirect mtalocal://* to http://mta/local/*, call recursively request->SetURL("http://mta/local/" + path); return Create(browser, frame, "http", request); } SString host = UTF16ToMbUTF8(urlParts.host.str); if (scheme_name == "http" && host == "mta") { // Scheme format: http://mta/resourceName/file.html or http://mta/local/file.html for the current resource // Get resource name and path SString path = UTF16ToMbUTF8(urlParts.path.str).substr(1); // Remove slash at the front size_t slashPos = path.find('/'); if (slashPos == std::string::npos) return HandleError("404 - Not found", 404); SString resourceName = path.substr(0, slashPos); SString resourcePath = path.substr(slashPos + 1); if (resourcePath.empty()) return HandleError("404 - Not found", 404); // Get mime type from extension CefString mimeType; size_t pos = resourcePath.find_last_of('.'); if (pos != std::string::npos) mimeType = CefGetMimeType(resourcePath.substr(pos + 1)); // Make sure we provide a mime type, even // when we cannot deduct it from the file extension if (mimeType.empty()) mimeType = "application/octet-stream"; if (pWebView->HasAjaxHandler(resourcePath)) { std::vector<SString> vecGet; std::vector<SString> vecPost; if (urlParts.query.str != nullptr) { SString strGet = UTF16ToMbUTF8(urlParts.query.str); std::vector<SString> vecTmp; strGet.Split("&", vecTmp); SString key; SString value; for (auto&& param : vecTmp) { param.Split("=", &key, &value); vecGet.push_back(key); vecGet.push_back(value); } } CefPostData::ElementVector vecPostElements; auto postData = request->GetPostData(); if (postData.get()) { request->GetPostData()->GetElements(vecPostElements); SString key; SString value; for (auto&& post : vecPostElements) { // Limit to 5MiB and allow byte data only size_t bytesCount = post->GetBytesCount(); if (bytesCount > 5 * 1024 * 1024 || post->GetType() != CefPostDataElement::Type::PDE_TYPE_BYTES) continue; // Make string from buffer std::unique_ptr<char[]> buffer{new char[bytesCount]}; post->GetBytes(bytesCount, buffer.get()); SStringX param(buffer.get(), bytesCount); // Parse POST data into vector std::vector<SString> vecTmp; param.Split("&", vecTmp); for (auto&& param : vecTmp) { param.Split("=", &key, &value); vecPost.push_back(key); vecPost.push_back(value); } } } auto handler = new CAjaxResourceHandler(vecGet, vecPost, mimeType); pWebView->HandleAjaxRequest(resourcePath, handler); return handler; } else { // Calculate MTA resource path if (resourceName != "local") path = ":" + resourceName + "/" + resourcePath; else path = resourcePath; // Calculate absolute path if (!pWebView->GetFullPathFromLocal(path)) return HandleError("404 - Not found", 404); // Verify local files if (!pWebView->VerifyFile(path)) return HandleError("403 - Access Denied", 403); // Finally, load the file stream auto stream = CefStreamReader::CreateForFile(path); if (stream.get()) return new CefStreamResourceHandler(mimeType, stream); return HandleError("404 - Not found", 404); } } // Return null if there is no matching scheme // This falls back to letting CEF handle the request return nullptr; }
// // D_DoomWadReboot // [denis] change wads at runtime // Returns false if there are missing files and fills the missingfiles // vector // // [SL] passing an IWAD as newwadfiles[0] is now optional // TODO: hash checking for patchfiles // bool D_DoomWadReboot( const std::vector<std::string> &newwadfiles, const std::vector<std::string> &newpatchfiles, const std::vector<std::string> &newwadhashes, const std::vector<std::string> &newpatchhashes ) { size_t i; bool hashcheck = (newwadfiles.size() == newwadhashes.size()); missingfiles.clear(); missinghashes.clear(); // already loaded these? if (lastWadRebootSuccess && !wadhashes.empty() && newwadhashes == std::vector<std::string>(wadhashes.begin()+1, wadhashes.end())) { // fast track if files have not been changed // denis - todo - actually check the file timestamps Printf (PRINT_HIGH, "Currently loaded WADs match server checksum\n\n"); return true; } lastWadRebootSuccess = false; if (gamestate == GS_LEVEL) G_ExitLevel(0, 0); S_Stop(); DThinker::DestroyAllThinkers(); // Close all open WAD files W_Close(); // [ML] 9/11/10: Reset custom wad level information from MAPINFO et al. for (i = 0; i < wadlevelinfos.size(); i++) { if (wadlevelinfos[i].snapshot) { delete wadlevelinfos[i].snapshot; wadlevelinfos[i].snapshot = NULL; } } wadlevelinfos.clear(); wadclusterinfos.clear(); // Restart the memory manager Z_Init(); SetLanguageIDs (); gamestate_t oldgamestate = gamestate; gamestate = GS_STARTUP; // prevent console from trying to use nonexistant font // [SL] 2012-12-06 - If we weren't provided with a new IWAD filename in // newwadfiles, use the previous IWAD. std::string iwad_filename, iwad_hash; if ((newwadfiles.empty() || !W_IsIWAD(newwadfiles[0])) && (wadfiles.size() >= 2)) { iwad_filename = wadfiles[1]; iwad_hash = wadhashes[1]; } else if (!newwadfiles.empty()) { iwad_filename = newwadfiles[0]; iwad_hash = hashcheck ? newwadhashes[0] : ""; } wadfiles.clear(); D_AddDefWads(iwad_filename); // add odamex.wad & IWAD // check if the wad files exist and if they match the MD5SUM std::string base_filename, full_filename; if (!VerifyFile(iwad_filename, base_filename, full_filename, iwad_hash)) { Printf(PRINT_HIGH, "could not find WAD: %s\n", base_filename.c_str()); missingfiles.push_back(base_filename); if (hashcheck) missinghashes.push_back(iwad_hash); } for (i = 0; i < newwadfiles.size(); i++) { std::string hash = hashcheck ? newwadhashes[i] : ""; // already added the IWAD with D_AddDefWads if (W_IsIWAD(newwadfiles[i])) continue; if (VerifyFile(newwadfiles[i], base_filename, full_filename, hash)) wadfiles.push_back(full_filename); else { Printf(PRINT_HIGH, "could not find WAD: %s\n", base_filename.c_str()); missingfiles.push_back(base_filename); if (hashcheck) missinghashes.push_back(newwadhashes[i]); } } modifiedgame = (wadfiles.size() > 2) || !patchfiles.empty(); // more than odamex.wad and IWAD? if (modifiedgame && (gameinfo.flags & GI_SHAREWARE)) I_Error("\nYou cannot load additional WADs with the shareware version. Register!"); wadhashes = W_InitMultipleFiles (wadfiles); // get skill / episode / map from parms strcpy(startmap, (gameinfo.flags & GI_MAPxx) ? "MAP01" : "E1M1"); UndoDehPatch(); patchfiles.clear(); // [RH] Initialize localizable strings. GStrings.ResetStrings (); GStrings.Compact (); D_DoDefDehackedPatch(newpatchfiles); D_NewWadInit(); // preserve state lastWadRebootSuccess = missingfiles.empty(); gamestate = oldgamestate; // GS_STARTUP would prevent netcode connecting properly return missingfiles.empty(); }
NTSTATUS DriverDispatchHandler (__in PDEVICE_OBJECT DeviceObject, __in PIRP Irp) { NTSTATUS nsStatus = STATUS_UNSUCCESSFUL; PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation (Irp); PBDKIT_DEVICE_EXTENSION pDevExt = (PBDKIT_DEVICE_EXTENSION)DeviceObject->DeviceExtension; WCHAR szImageName[MAX_PATH - 1] = {L"\0"}; ULONG ulLength = 0; do { if ( IrpSp->MajorFunction != IRP_MJ_SHUTDOWN ) { if ( !NT_SUCCESS(BDKitIsAuthorizedProcess(PsGetCurrentProcess())) ) { nsStatus=BDKitGetProcessImageNameByEProcess_s(PsGetCurrentProcess(), szImageName, sizeof(szImageName)); if ( !NT_SUCCESS(nsStatus) ) { Irp->IoStatus.Status = nsStatus = STATUS_ACCESS_DENIED; Irp->IoStatus.Information = 0; break; } #ifndef DBG nsStatus = VerifyFile(szImageName); if ( !NT_SUCCESS(nsStatus) ) { Irp->IoStatus.Status = nsStatus = STATUS_ACCESS_DENIED; Irp->IoStatus.Information = 0; break; } #endif nsStatus = BDKitAddAuthorizedProcess (PsGetCurrentProcess()); BDKit_If_Not_Break(NT_SUCCESS(nsStatus)); } } switch(IrpSp->MajorFunction) { case IRP_MJ_CREATE: { BDbgPrint ("[BDKIT]Open Deivce\r\n"); InterlockedIncrement((volatile LONG*)&pDevExt->DeviceRefence); Irp->IoStatus.Information = 0; Irp->IoStatus.Status = nsStatus = STATUS_SUCCESS; } break; case IRP_MJ_DEVICE_CONTROL: { nsStatus = DriverControlUtilityHandler (DeviceObject, Irp); } break; case IRP_MJ_CLOSE: { BDbgPrint ("[BDKIT]Close Device\r\n"); InterlockedDecrement((LONG volatile*)&pDevExt->DeviceRefence); Irp->IoStatus.Information = 0; Irp->IoStatus.Status = nsStatus = STATUS_SUCCESS; BDKitRemoveAuthorizedProcess (PsGetCurrentProcess()); } break; case IRP_MJ_SHUTDOWN: { //BDbgPrint ("[BDKIT]Clear Delete FileList\r\n"); //BDKitClearDeleteFileList (); Irp->IoStatus.Information = 0; Irp->IoStatus.Status = nsStatus = STATUS_SUCCESS; } break; default: { return DriverPassthroughHandler (DeviceObject, Irp); } } } while (FALSE); if ( nsStatus != STATUS_PENDING ) { IoCompleteRequest(Irp, IO_NO_INCREMENT); } return nsStatus; }