1 //===- MachOObject.cpp - Mach-O Object File Wrapper -----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Object/MachOObject.h"
11 #include "llvm/ADT/StringRef.h"
12 #include "llvm/Support/MemoryBuffer.h"
15 using namespace object;
17 MachOObject::MachOObject(MemoryBuffer *Buffer_, bool IsLittleEndian_,
19 : Buffer(Buffer_), IsLittleEndian(IsLittleEndian_), Is64Bit(Is64Bit_) {
22 MachOObject *MachOObject::LoadFromBuffer(MemoryBuffer *Buffer,
23 std::string *ErrorStr) {
24 // First, check the magic value and initialize the basic object info.
25 bool IsLittleEndian = false, Is64Bit = false;
26 StringRef Magic = Buffer->getBuffer().slice(0, 4);
27 if (Magic == "\xFE\xED\xFA\xCE") {
28 } else if (Magic == "\xCE\xFA\xED\xFE") {
29 IsLittleEndian = true;
30 } else if (Magic == "\xFE\xED\xFA\xCF") {
32 } else if (Magic == "\xCF\xFA\xED\xFE") {
33 IsLittleEndian = true;
36 *ErrorStr = "not a Mach object file";
40 OwningPtr<MachOObject> Object(new MachOObject(Buffer, IsLittleEndian,
43 if (ErrorStr) *ErrorStr = "";