Get the file header type. See "include/loader/filemgr.h".
| 360 | |
| 361 | // Get the file header type. See "include/loader/filemgr.h". |
| 362 | FileMgr::FileHeader FileMgr::getHeaderType() { |
| 363 | if (Size >= 4) { |
| 364 | Byte WASMMagic[] = {0x00, 0x61, 0x73, 0x6D}; |
| 365 | Byte ELFMagic[] = {0x7F, 0x45, 0x4C, 0x46}; |
| 366 | Byte MAC32agic[] = {0xCE, 0xFA, 0xED, 0xFE}; |
| 367 | Byte MAC64agic[] = {0xCF, 0xFA, 0xED, 0xFE}; |
| 368 | if (std::equal(WASMMagic, WASMMagic + 4, Data)) { |
| 369 | return FileMgr::FileHeader::Wasm; |
| 370 | } else if (std::equal(ELFMagic, ELFMagic + 4, Data)) { |
| 371 | return FileMgr::FileHeader::ELF; |
| 372 | } else if (std::equal(MAC32agic, MAC32agic + 4, Data)) { |
| 373 | return FileMgr::FileHeader::MachO_32; |
| 374 | } else if (std::equal(MAC64agic, MAC64agic + 4, Data)) { |
| 375 | return FileMgr::FileHeader::MachO_64; |
| 376 | } |
| 377 | } |
| 378 | if (Size >= 2) { |
| 379 | Byte DLLMagic[] = {0x4D, 0x5A}; |
| 380 | if (std::equal(DLLMagic, DLLMagic + 2, Data)) { |
| 381 | return FileMgr::FileHeader::DLL; |
| 382 | } |
| 383 | } |
| 384 | return FileMgr::FileHeader::Unknown; |
| 385 | } |
| 386 | |
| 387 | // Jump a section. See "include/loader/filemgr.h". |
| 388 | Expect<void> FileMgr::jumpContent() { |