| 1317 | } |
| 1318 | |
| 1319 | static fs::file CheckDebugSelf(const fs::file& s) |
| 1320 | { |
| 1321 | if (s.size() < 0x18) |
| 1322 | { |
| 1323 | return {}; |
| 1324 | } |
| 1325 | |
| 1326 | // Get the key version. |
| 1327 | s.seek(0x08); |
| 1328 | |
| 1329 | const u16 key_version = s.read<le_t<u16>>(); |
| 1330 | |
| 1331 | // Check for DEBUG version. |
| 1332 | if (key_version == 0x80 || key_version == 0xc0) |
| 1333 | { |
| 1334 | self_log.warning("Debug SELF detected! Removing fake header..."); |
| 1335 | |
| 1336 | // Get the real elf offset. |
| 1337 | s.seek(0x10); |
| 1338 | |
| 1339 | // Start at the real elf offset. |
| 1340 | s.seek(key_version == 0x80 ? +s.read<be_t<u64>>() : +s.read<le_t<u64>>()); |
| 1341 | |
| 1342 | // Write the real ELF file back. |
| 1343 | fs::file e = fs::make_stream<std::vector<u8>>(); |
| 1344 | |
| 1345 | // Copy the data. |
| 1346 | char buf[2048]; |
| 1347 | while (const u64 size = s.read(buf, 2048)) |
| 1348 | { |
| 1349 | e.write(buf, size); |
| 1350 | } |
| 1351 | |
| 1352 | return e; |
| 1353 | } |
| 1354 | |
| 1355 | // Leave the file untouched. |
| 1356 | return {}; |
| 1357 | } |
| 1358 | |
| 1359 | fs::file decrypt_self(const fs::file& elf_or_self, const u8* klic_key, SelfAdditionalInfo* out_info) |
| 1360 | { |
no test coverage detected