// -*- mode: ObjC -*-

//  This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
//  Copyright (C) 1997-1998, 2000-2001, 2004-2007  Steve Nygard

#import <Foundation/NSObject.h>

#include <mach/machine.h> // For cpu_type_t, cpu_subtype_t
#include <mach-o/loader.h>

@class NSData;
@class CDSegmentCommand;

@class NSArray;
@class CDDylibCommand, CDMachOFile;

#ifdef HANDLE_OBJC2_ABI
@class CDSymbolTable;
#endif

@protocol CDMachOFileDelegate
- (void)machOFile:(CDMachOFile *)aMachOFile loadDylib:(CDDylibCommand *)aDylibCommand;
@end

@interface CDMachOFile : NSObject
{
    NSString *filename;
    unsigned int archiveOffset;
    NSData *data;
    struct mach_header header;
    NSArray *loadCommands;

    struct {
        unsigned int shouldSwapBytes:1;
    } _flags;

    id nonretainedDelegate;
}

extern NSString *CDNameForCPUType(cpu_type_t cputype, cpu_subtype_t cpusubtype);

+ (id)machOFileWithFilename:(NSString *)aFilename;

- (id)initWithFilename:(NSString *)aFilename;
- (id)initWithFilename:(NSString *)aFilename archiveOffset:(unsigned int)anArchiveOffset;
- (void)dealloc;

- (NSString *)filename;

- (unsigned int)archiveOffset;

- (BOOL)hasDifferentByteOrder;

- (id)delegate;
- (void)setDelegate:(id)newDelegate;

- (void)process;
- (NSArray *)_processLoadCommands;

- (NSArray *)loadCommands;
- (cpu_type_t)cpuType;
- (cpu_subtype_t)cpuSubtype;
- (unsigned long)filetype;
- (unsigned long)flags;

- (NSString *)filetypeDescription;
- (NSString *)flagDescription;
- (NSString *)description;

- (CDDylibCommand *)dylibIdentifier;

- (CDSegmentCommand *)segmentWithName:(NSString *)segmentName;
- (CDSegmentCommand *)segmentContainingAddress:(unsigned long)vmaddr;
- (const void *)pointerFromVMAddr:(unsigned long)vmaddr;
- (const void *)pointerFromVMAddr:(unsigned long)vmaddr segmentName:(NSString *)aSegmentName;
- (NSString *)stringFromVMAddr:(unsigned long)vmaddr;

- (const void *)bytes;
- (const void *)bytesAtOffset:(unsigned long)offset;

- (NSString *)importBaseName;

- (BOOL)hasProtectedSegments;

- (NSString *)loadCommandString:(BOOL)isVerbose;
- (NSString *)headerString:(BOOL)isVerbose;

- (NSString *)archName;

#ifdef HANDLE_OBJC2_ABI
- (CDSymbolTable *)symbolTable;
#endif

@end
