bool CheckArguments(int argc, const char * argv) { if ((argc == 5) || (argc == 4)) { if (IsPathExists(argv)) return true; else return false; } else if ((argc == 2) && (std::string(argv) == "help")) { std::cout << "replace.exe <inputFile> <outputFile> <searchString> <replaceString>" << std::endl; return false; } else if (argc > 5) { std::cout << "Error. The number of arguments exceeds the limit. Use 'help' for more information." << std::endl; return false; } else { std::cout << "Error. Not enough arguments. Use 'help' for more information." << std::endl; return false; } }
BOOL AoIsFileExist(PCSTR FileName) { WCHAR OriginalPath[MAX_NTPATH], HookedPath[MAX_NTPATH]; if (GetFileName(HookedPath, countof(HookedPath), OriginalPath, countof(OriginalPath), FileName) == HookedPath) return TRUE; return IsPathExists(OriginalPath); }
bool SPFileHelper::CreatePath( SPString path ) { if (path.size() == 0 || path == L"/" || path == L"\\") { return true; } if(IsPathExists(path.c_str())) { return true; } if(!CreatePath(GetUpperPath(path))) { return false; } if( FALSE == CreateDirectory(path.c_str(), NULL)) { return false; } return true; }
PWSTR GetFileName( PWSTR HookedPath, ULONG HookedPathCount, PWSTR OriginalPath, ULONG OriginalCount, LPCSTR InputFileName, BOOL IsInputUnicode = FALSE ) { ULONG_PTR Length, AppPathLength; PWSTR FileName; static WCHAR szDataPath[] = L"data\\"; static WCHAR szPatch[] = L"patch\\\\"; static WCHAR szPatch2[] = L"patch2\\"; if (IsInputUnicode) { StrCopyW(OriginalPath, (PWSTR)InputFileName); } else { AnsiToUnicode(OriginalPath, OriginalCount, (PSTR)InputFileName, -1); } PLDR_MODULE Module; Module = FindLdrModuleByHandle(NULL); AppPathLength = (Module->FullDllName.Length - Module->BaseDllName.Length) / sizeof(WCHAR); Length = RtlGetFullPathName_U(OriginalPath, HookedPathCount * sizeof(WCHAR), HookedPath, NULL); Length = Length / sizeof(WCHAR) + 1; FileName = HookedPath + AppPathLength; LOOP_ONCE { if (StrNICompareW(FileName, szDataPath, countof(szDataPath) - 1) || StrNICompareW(Module->FullDllName.Buffer, HookedPath, AppPathLength)) { FileName = OriginalPath; break; } FileName += countof(szDataPath) - 2; RtlMoveMemory( FileName + countof(szPatch) - countof(szDataPath), FileName, (Length - (FileName - HookedPath)) * sizeof(*FileName) ); FileName -= countof(szDataPath) - 2; CopyStruct(FileName, szPatch, sizeof(szPatch) - sizeof(*szPatch)); WriteLog(L"pass1: %s", HookedPath); if (IsPathExists(HookedPath)) { FileName = HookedPath; break; } CopyStruct(FileName, szPatch2, sizeof(szPatch2) - sizeof(*szPatch2)); FileName = IsPathExists(HookedPath) ? HookedPath : OriginalPath; WriteLog(L"pass2: %s", HookedPath); } WriteLog(L"%d, %s -> %s", FileName == HookedPath, OriginalPath, HookedPath); return FileName; }