| 56 | } |
| 57 | |
| 58 | bool ElfObject::OpenFile(std::string srcfile, bool isPSXElf_, Error* error) |
| 59 | { |
| 60 | auto fp = FileSystem::OpenManagedCFile(srcfile.c_str(), "rb", error); |
| 61 | FILESYSTEM_STAT_DATA sd; |
| 62 | if (!fp || !FileSystem::StatFile(fp.get(), &sd)) |
| 63 | { |
| 64 | Error::SetString(error, fmt::format("Failed to read ELF from '{}'", srcfile)); |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | if (!isPSXElf_ && !CheckElfSize(sd.Size, error)) |
| 69 | return false; |
| 70 | |
| 71 | data.resize(static_cast<size_t>(sd.Size)); |
| 72 | if (std::fread(data.data(), data.size(), 1, fp.get()) != 1) |
| 73 | { |
| 74 | Error::SetString(error, fmt::format("Failed to read ELF from '{}'", srcfile)); |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | filename = std::move(srcfile); |
| 79 | isPSXElf = isPSXElf_; |
| 80 | InitElfHeaders(); |
| 81 | return true; |
| 82 | } |
| 83 | |
| 84 | void ElfObject::InitElfHeaders() |
| 85 | { |
no test coverage detected