17#if !defined(_MSC_VER) && !defined(__MINGW32__)
36 switch ((
unsigned char)Magic[0]) {
42 if (Magic.size() < MinSize)
99 if (
startswith(Magic,
"\177ELF") && Magic.size() >= 18) {
100 bool Data2MSB = Magic[5] == 2;
101 unsigned high = Data2MSB ? 16 : 17;
102 unsigned low = Data2MSB ? 17 : 16;
103 if (Magic[high] == 0) {
104 switch (Magic[low]) {
127 if (Magic.size() >= 8 && Magic[7] < 43)
143 if (Magic[3] ==
char(0xCE))
147 if (Magic.size() >= MinSize)
148 type = Magic[12] << 24 | Magic[13] << 12 | Magic[14] << 8 | Magic[15];
149 }
else if (
startswith(Magic,
"\xCE\xFA\xED\xFE") ||
153 if (Magic[0] ==
char(0xCE))
157 if (Magic.size() >= MinSize)
158 type = Magic[15] << 24 | Magic[14] << 12 | Magic[13] << 8 | Magic[12];
201 if (Magic[1] == 0x01)
207 if (Magic[1] == 0x02)
213 if (
startswith(Magic,
"MZ") && Magic.size() >= 0x3c + 4) {
216 if (Magic.substr(off).startswith(
220 if (Magic.startswith(
"Microsoft C/C++ MSF 7.00\r\n"))
227 if (Magic[1] ==
char(0x86) || Magic[1] ==
char(0xaa))
245 if (Magic[1] ==
char(0xA6))
250 if (Magic[1] ==
char(0xA6))
264 return FileOrError.getError();
266 std::unique_ptr<MemoryBuffer> FileBuffer = std::move(*FileOrError);
269 return std::error_code();
#define offsetof(TYPE, MEMBER)
static bool startswith(StringRef Magic, const char(&S)[N])
Merge contiguous icmps into a memcmp
std::pair< llvm::MachO::Target, std::string > UUID
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static const char ClGlObjMagic[]
static const char WinResMagic[]
static const char BigObjMagic[]
static const char PEMagic[]
uint32_t read32le(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
file_magic - An "enum class" enumeration of file types based on magic (the first N bytes of the file)...
@ coff_import_library
COFF import library.
@ pdb
Windows PDB debug info file.
@ elf_relocatable
ELF Relocatable object file.
@ archive
ar style archive file
@ elf_shared_object
ELF dynamically linked shared lib.
@ goff_object
GOFF object file.
@ minidump
Windows minidump file.
@ macho_dynamically_linked_shared_lib
Mach-O dynlinked shared lib.
@ xcoff_object_64
64-bit XCOFF object file
@ elf_executable
ELF Executable image.
@ macho_dynamically_linked_shared_lib_stub
Mach-O Shared lib stub.
@ macho_preload_executable
Mach-O Preloaded Executable.
@ macho_file_set
Mach-O file set binary.
@ dxcontainer_object
DirectX container file.
@ macho_kext_bundle
Mach-O kext bundle file.
@ pecoff_executable
PECOFF executable file.
@ offload_binary
LLVM offload object file.
@ macho_universal_binary
Mach-O universal binary.
@ macho_core
Mach-O Core File.
@ wasm_object
WebAssembly Object file.
@ xcoff_object_32
32-bit XCOFF object file
@ windows_resource
Windows compiled resource file (.res)
@ elf_core
ELF core image.
@ macho_object
Mach-O Object file.
@ coff_object
COFF object file.
@ macho_bundle
Mach-O Bundle file.
@ coff_cl_gl_object
Microsoft cl.exe's intermediate code file.
@ cuda_fatbinary
CUDA Fatbinary object file.
@ macho_executable
Mach-O Executable.
@ macho_dsym_companion
Mach-O dSYM companion file.
@ unknown
Unrecognized file.
@ macho_fixed_virtual_memory_shared_lib
Mach-O Shared Lib, FVM.
@ macho_dynamic_linker
The Mach-O dynamic linker.
@ tapi_file
Text-based Dynamic Library Stub file.