//===- FuzzerIOWindows.cpp - IO utils for Windows. ------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // IO functions implementation for Windows. //===----------------------------------------------------------------------===// #include"FuzzerPlatform.h" #if LIBFUZZER_WINDOWS
int ListFilesInDirRecursive(const std::string &Dir, long *Epoch,
Vector<std::string> *V, bool TopDir) { int Res; auto E = GetEpoch(Dir); if (Epoch) if (E && *Epoch >= E) return 0;
std::string Path(Dir);
assert(!Path.empty()); if (Path.back() != '\\')
Path.push_back('\\');
Path.push_back('*');
// Get the first directory entry.
WIN32_FIND_DATAA FindInfo;
HANDLE FindHandle(FindFirstFileA(Path.c_str(), &FindInfo)); if (FindHandle == INVALID_HANDLE_VALUE)
{ if (GetLastError() == ERROR_FILE_NOT_FOUND) return 0;
Printf("No such file or directory: %s; exiting\n", Dir.c_str()); return 1;
}
do {
std::string FileName = DirPlusFile(Dir, FindInfo.cFileName);
staticbool IsSeparator(char C) { return C == '\\' || C == '/';
}
// Parse disk designators, like "C:\". If Relative == true, also accepts: "C:". // Returns number of characters considered if successful. static size_t ParseDrive(const std::string &FileName, const size_t Offset, bool Relative = true) { if (Offset + 1 >= FileName.size() || FileName[Offset + 1] != ':') return 0; if (Offset + 2 >= FileName.size() || !IsSeparator(FileName[Offset + 2])) { if (!Relative) // Accept relative path? return 0; else return 2;
} return 3;
}
// Parse a file name, like: SomeFile.txt // Returns number of characters considered if successful. static size_t ParseFileName(const std::string &FileName, const size_t Offset) {
size_t Pos = Offset; const size_t End = FileName.size(); for(; Pos < End && !IsSeparator(FileName[Pos]); ++Pos)
; return Pos - Offset;
}
// Parse a directory ending in separator, like: `SomeDir\` // Returns number of characters considered if successful. static size_t ParseDir(const std::string &FileName, const size_t Offset) {
size_t Pos = Offset; const size_t End = FileName.size(); if (Pos >= End || IsSeparator(FileName[Pos])) return 0; for(; Pos < End && !IsSeparator(FileName[Pos]); ++Pos)
; if (Pos >= End) return 0;
++Pos; // Include separator. return Pos - Offset;
}
// Parse a servername and share, like: `SomeServer\SomeShare\` // Returns number of characters considered if successful. static size_t ParseServerAndShare(const std::string &FileName, const size_t Offset) {
size_t Pos = Offset, Res; if (!(Res = ParseDir(FileName, Pos))) return 0;
Pos += Res; if (!(Res = ParseDir(FileName, Pos))) return 0;
Pos += Res; return Pos - Offset;
}
// Parse the given Ref string from the position Offset, to exactly match the given // string Patt. // Returns number of characters considered if successful. static size_t ParseCustomString(const std::string &Ref, size_t Offset, constchar *Patt) {
size_t Len = strlen(Patt); if (Offset + Len > Ref.size()) return 0; return Ref.compare(Offset, Len, Patt) == 0 ? Len : 0;
}
// Parse a location, like: // \\?\UNC\Server\Share\ \\?\C:\ \\Server\Share\ \ C:\ C: // Returns number of characters considered if successful. static size_t ParseLocation(const std::string &FileName) {
size_t Pos = 0, Res;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.