#include #include #include #include #include #include #include #include #include /** * execute a program from an absolute path * * \param path absolute path to program (duh) * \return program return value, 1 if it does not exist or -1 on error */ int Pii_ExecuteProgram(const std::string& path) { if (pid_t child = fork()) { int exitcode = -1; waitpid(child, &exitcode, 0); return exitcode; } else { char* args[] = { strdup(path.c_str()), nullptr }; execv(args[0], args); // this should only be reached if we cant load the program std::exit(1); } } /** * Abort the boot process and drop the user into a recovery shell */ [[noreturn]] void Pii_AbortBoot() { std::cout << "Unable to complete preinitialization. You have been dropped into a minimal recovery environment. Good luck." << std::endl; Pii_ExecuteProgram("/Windows/System32/bash.exe"); std::exit(1); } int main() { // dynamic linking fun std::cout << "Regenerating dynamic linker cache\n"; Pii_ExecuteProgram("/Windows/System32/ldconfig.exe"); // boot still failed // for (const auto& ent : std::filesystem::directory_iterator("/Windows/System32")) { // std::cout << ent << " s:" << ent.is_symlink() << " d:" << ent.is_directory() << "\n"; //} // we are never ok Pii_AbortBoot(); return 0; }