diff --git a/src/wtf/wtf.cc b/src/wtf/wtf.cc index 4853c73..adc431b 100644 --- a/src/wtf/wtf.cc +++ b/src/wtf/wtf.cc @@ -11,6 +11,8 @@ #include #include +namespace fs = std::filesystem; + int main(int argc, const char *argv[]) { // // Set up the arguments. @@ -47,9 +49,9 @@ int main(int argc, const char *argv[]) { Opts.Master.CrashesPath = Opts.Master.TargetPath / "crashes"; } - if (!std::filesystem::exists(Opts.Master.InputsPath) || - !std::filesystem::exists(Opts.Master.OutputsPath) || - !std::filesystem::exists(Opts.Master.CrashesPath)) { + if (!fs::exists(Opts.Master.InputsPath) || + !fs::exists(Opts.Master.OutputsPath) || + !fs::exists(Opts.Master.CrashesPath)) { throw CLI::ParseError( fmt::format("Expected to find inputs/outputs/crashes directories " "in '{}'.", @@ -101,6 +103,16 @@ int main(int argc, const char *argv[]) { CLI::App *RunCmd = Wtf.add_subcommand("run", "Run and trace options")->callback([&Opts] { + // + // If the state path is empty and a 'state' folder is available, let's + // use it. + // + + if (Opts.StatePath.empty() && fs::is_directory("state")) { + fmt::print("Found a 'state' folder in the cwd, so using it.\n"); + Opts.StatePath = "state"; + } + // // Populate other paths based on the based state path. // @@ -131,8 +143,7 @@ int main(int argc, const char *argv[]) { // Ensure that they exist just as a quick check. // - if (!std::filesystem::exists(Opts.DumpPath) || - !std::filesystem::exists(Opts.CpuStatePath)) { + if (!fs::exists(Opts.DumpPath) || !fs::exists(Opts.CpuStatePath)) { throw CLI::ParseError(fmt::format("Expected to find state/mem.dmp, " "state/regs.json files in '{}'.", Opts.StatePath.string()), @@ -151,7 +162,7 @@ int main(int argc, const char *argv[]) { } #ifdef LINUX - if (!std::filesystem::exists(Opts.SymbolFilePath)) { + if (!fs::exists(Opts.SymbolFilePath)) { throw CLI::ParseError( fmt::format("Expected to find a state/symbol-store.json file in " "'{}'. You need to generate it from Windows.", @@ -216,8 +227,7 @@ int main(int argc, const char *argv[]) { RunCmd->add_option("--state", Opts.StatePath, "State directory") ->check(CLI::ExistingDirectory) - ->description("State directory which contains memory and cpu state.") - ->required(); + ->description("State directory which contains memory and cpu state."); RunCmd ->add_option("--guest-files", Opts.GuestFilesPath, @@ -277,13 +287,12 @@ int main(int argc, const char *argv[]) { // Ensure that they exist just as a quick check. // - if (!std::filesystem::exists(Opts.DumpPath) || - !std::filesystem::exists(Opts.CpuStatePath)) { + if (!fs::exists(Opts.DumpPath) || !fs::exists(Opts.CpuStatePath)) { throw CLI::ParseError( - fmt::format("Expected to find a state/mem.dmp file, a " - "state/regs.json file, an inputs directory, an " - "outputs directory, a crashes directory in '{}'.", - Opts.Fuzz.TargetPath.string()), + fmt::format( + "Expected to find mem.dmp/regs.json files in '{}/state', " + "inputs/outputs/crashes directories in '{}'.", + Opts.Fuzz.TargetPath.string(), Opts.Fuzz.TargetPath.string()), EXIT_FAILURE); } @@ -304,7 +313,7 @@ int main(int argc, const char *argv[]) { } #ifdef LINUX - if (!std::filesystem::exists(Opts.SymbolFilePath)) { + if (!fs::exists(Opts.SymbolFilePath)) { throw CLI::ParseError( fmt::format("Expected to find a state/symbol-store.json file in " "'{}'; you need to generate it from Windows.",