| 43 | } |
| 44 | |
| 45 | void AutoDetect::game_libraries(Context *context) |
| 46 | { |
| 47 | /* Build a command to parse the first missing library from the game executable, |
| 48 | * look at game directory and sub-directories for it */ |
| 49 | std::ostringstream oss_ml; |
| 50 | oss_ml << "ldd " << context->gameexecutable; |
| 51 | oss_ml << " | awk '/ => not found/ { print $1 }' | head -1"; |
| 52 | |
| 53 | std::string missing_lib = queryCmd(oss_ml.str()); |
| 54 | if (missing_lib.empty()) return; |
| 55 | |
| 56 | std::cout << "Try to find the location of " << missing_lib << " among game files."<< std::endl; |
| 57 | |
| 58 | std::filesystem::path gamedir = context->gameexecutable.parent_path(); |
| 59 | std::ostringstream oss_lp; |
| 60 | oss_lp << "find " << gamedir << " -name " << missing_lib << " -type f -print -quit"; |
| 61 | |
| 62 | std::string found_lib = queryCmd(oss_lp.str()); |
| 63 | if (!found_lib.empty()) { |
| 64 | std::cout << "-> library was found at location " << found_lib << std::endl; |
| 65 | |
| 66 | std::filesystem::path found_lib_path = std::filesystem::path(found_lib); |
| 67 | std::filesystem::path found_lib_dir = found_lib_path.parent_path(); |
| 68 | |
| 69 | char* oldlibpath = getenv("LD_LIBRARY_PATH"); |
| 70 | std::string newlibpath = found_lib_dir.native(); |
| 71 | if (oldlibpath) { |
| 72 | newlibpath.append(":"); |
| 73 | newlibpath.append(oldlibpath); |
| 74 | } |
| 75 | setenv("LD_LIBRARY_PATH", newlibpath.c_str(), 1); |
| 76 | } |
| 77 | else { |
| 78 | std::cerr << "-> could not find the library among the game files" << std::endl; |
| 79 | } |
| 80 | |
| 81 | /* Try to download common missing libraries */ |
| 82 | if (context->config.allow_downloads != 1) |
| 83 | return; |
| 84 | |
| 85 | int gameArch = extractBinaryType(context->gameexecutable) & BT_TYPEMASK; |
| 86 | if (gameArch != BT_ELF32 && gameArch != BT_ELF64) |
| 87 | return; |
| 88 | |
| 89 | missing_lib = queryCmd(oss_ml.str()); |
| 90 | |
| 91 | while (! missing_lib.empty()) { |
| 92 | std::string libUrl, libDeb, libStr; |
| 93 | if (missing_lib == "libcrypto.so.1.0.0") { |
| 94 | if (gameArch == BT_ELF32) { |
| 95 | libUrl = "http://security.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0.0_1.0.2n-1ubuntu5.13_i386.deb"; |
| 96 | } |
| 97 | else { |
| 98 | libUrl = "http://security.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0.0_1.0.2n-1ubuntu5.13_amd64.deb"; |
| 99 | } |
| 100 | } |
| 101 | else if (missing_lib == "libssl.so.1.0.0") { |
| 102 | if (gameArch == BT_ELF32) { |
nothing calls this directly
no test coverage detected