Skip to content

Commit

Permalink
Initial commit from SVN rev 215
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbinit committed Oct 13, 2012
0 parents commit 21bfff3
Show file tree
Hide file tree
Showing 68 changed files with 42,422 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.svn/*

English.lproj/.svn/all-wcprops
English.lproj/.svn/entries
English.lproj/.svn/text-base/InfoPlist.strings.svn-base
English.lproj/.svn/text-base/Layout.xib.svn-base
English.lproj/.svn/text-base/MainMenu.xib.svn-base
English.lproj/.svn/text-base/Preferences.xib.svn-base
mach-o/.svn/all-wcprops
mach-o/.svn/entries
mach-o/.svn/text-base/arch.h.svn-base
mach-o/.svn/text-base/compact_unwind_encoding.h.svn-base
mach-o/.svn/text-base/fat.h.svn-base
mach-o/.svn/text-base/loader.h.svn-base
mach-o/.svn/text-base/nlist.h.svn-base
mach-o/.svn/text-base/ranlib.h.svn-base
mach-o/.svn/text-base/reloc.h.svn-base
mach-o/.svn/text-base/swap.h.svn-base
mach-o/arm/.svn/all-wcprops
mach-o/arm/.svn/entries
mach-o/arm/.svn/text-base/reloc.h.svn-base
mach-o/x86_64/.svn/all-wcprops
mach-o/x86_64/.svn/entries
mach-o/x86_64/.svn/text-base/reloc.h.svn-base
machoview.xcodeproj/.svn/all-wcprops
machoview.xcodeproj/.svn/entries
machoview.xcodeproj/.svn/text-base/project.pbxproj.svn-base
otool_disasm/.svn/all-wcprops
otool_disasm/.svn/entries
otool_disasm/.svn/text-base/arm_disasm.c.svn-base
otool_disasm/.svn/text-base/arm_disasm.h.svn-base
otool_disasm/.svn/text-base/bytesex.c.svn-base
otool_disasm/.svn/text-base/i386_disasm.c.svn-base
otool_disasm/.svn/text-base/i386_disasm.h.svn-base
otool_disasm/.svn/text-base/ofile_print.h.svn-base
otool_disasm/.svn/text-base/otool.h.svn-base
otool_disasm/.svn/text-base/symbol.c.svn-base
otool_disasm/disasm.xcodeproj/.svn/all-wcprops
otool_disasm/disasm.xcodeproj/.svn/entries
otool_disasm/disasm.xcodeproj/.svn/text-base/project.pbxproj.svn-base
17 changes: 17 additions & 0 deletions AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* AppDelegate.h
* MachOView
*
* Created by psaghelyi on 15/06/2010.
*
*/

@interface AppDelegate : NSObject <NSApplicationDelegate,NSOpenSavePanelDelegate>
{
}

@end




239 changes: 239 additions & 0 deletions AppDelegate.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
/*
* AppDelegate.mm
* MachOView
*
* Created by psaghelyi on 15/06/2010.
*
*/

#import "Common.h"
#import "AppDelegate.h"
#import "DataController.h"
#import "Document.h"

// counters for statistics
int64_t nrow_total; // number of rows (loaded and empty)
int64_t nrow_loaded; // number of loaded rows

//============================================================================
@implementation AppDelegate

//----------------------------------------------------------------------------
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
{
return NO;
}

//----------------------------------------------------------------------------
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
{
return YES;
}

//----------------------------------------------------------------------------
- (IBAction)newDocument:(id)sender
{
NSLog(@"Not yet possible");
}

//----------------------------------------------------------------------------
- (BOOL)isOnlyRunningMachOView
{
NSProcessInfo * procInfo = [NSProcessInfo processInfo];
NSBundle * mainBundle = [NSBundle mainBundle];
NSString * versionString = [mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];

NSUInteger numberOfInstance = 0;

NSWorkspace * workspace = [NSWorkspace sharedWorkspace];
for (NSRunningApplication * runningApplication in [workspace runningApplications])
{
// check if process name matches
NSString * fileName = [[runningApplication executableURL] lastPathComponent];
if ([fileName isEqualToString: [procInfo processName]] == NO)
{
continue;
}

// check if version string matches
NSBundle * bundle = [NSBundle bundleWithURL:[runningApplication bundleURL]];
if ([versionString isEqualToString:[bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]] == YES && ++numberOfInstance > 1)
{
return NO;
}
}

return YES;
}

//----------------------------------------------------------------------------
- (IBAction)openDocument:(id)sender
{
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setTreatsFilePackagesAsDirectories:YES];
[openPanel setAllowsMultipleSelection:YES];
[openPanel setCanChooseDirectories:NO];
[openPanel setCanChooseFiles:YES];
[openPanel setDelegate:self]; // for filtering files in open panel with shouldShowFilename
[openPanel beginSheetModalForWindow:nil
completionHandler:^(NSInteger result)
{
if (result != NSOKButton)
{
return;
}
[openPanel orderOut:self]; // close panel before we might present an error
for (NSURL * url in [openPanel URLs])
{
[self application:NSApp openFile:[url path]];
}
}];
}

//----------------------------------------------------------------------------
- (BOOL)panel:(id)sender shouldShowFilename:(NSString*)filename
{
NSURL * url = [NSURL fileURLWithPath:filename];

// can enter directories
NSNumber * isDirectory = nil;
[url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:NULL];
if ([isDirectory boolValue] == YES)
{
return YES;
}

// skip symbolic links, etc.
NSNumber * isRegularFile = nil;
[url getResourceValue:&isRegularFile forKey:NSURLIsRegularFileKey error:NULL];
if ([isRegularFile boolValue] == NO)
{
return NO;
}

// check for magic values at front
NSFileHandle * fileHandle = [NSFileHandle fileHandleForReadingAtPath:filename];
NSData * magicData = [fileHandle readDataOfLength:8];
[fileHandle closeFile];

if ([magicData length] < sizeof(uint32_t))
{
return NO;
}

uint32_t magic = *(uint32_t*)[magicData bytes];
if (magic == MH_MAGIC || magic == MH_MAGIC_64 ||
magic == FAT_CIGAM || magic == FAT_MAGIC)
{
return YES;
}

if ([magicData length] < sizeof(uint64_t))
{
return NO;
}

if (*(uint64_t*)[magicData bytes] == *(uint64_t*)"!<arch>\n")
{
return YES;
}

return NO;
}

//----------------------------------------------------------------------------
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
BOOL isFirstMachOView = [self isOnlyRunningMachOView];

NSFileManager * fileManager = [NSFileManager defaultManager];
NSString * tempDir = [MVDocument temporaryDirectory];

__autoreleasing NSError * error;

// remove previously forgotten temporary files
if (isFirstMachOView && [fileManager fileExistsAtPath:tempDir isDirectory:NULL] == YES)
{
if ([fileManager removeItemAtPath:tempDir error:&error] == NO)
{
[NSApp presentError:error];
}
}

// create placeholder for temporary files
if ([fileManager fileExistsAtPath:tempDir isDirectory:NULL] == NO)
{
if ([fileManager createDirectoryAtPath:tempDir
withIntermediateDirectories:NO
attributes:nil
error:&error] == NO)
{
[NSApp presentError:error];
}
}
}

//----------------------------------------------------------------------------
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
#ifdef MV_STATISTICS
nrow_total = nrow_loaded = 0;
[NSThread detachNewThreadSelector:@selector(printStat) toTarget:self withObject:nil];
#endif

// if there is no document yet, then pop up an open file dialogue
if ([[[NSDocumentController sharedDocumentController] documents] count] == 0)
{
[self openDocument:nil];
}
}

//----------------------------------------------------------------------------
- (void)applicationWillTerminate:(NSNotification *)aNotification
{
BOOL isLastMachOView = [self isOnlyRunningMachOView];

if (isLastMachOView == YES)
{
// remove temporary files
NSFileManager * fileManager = [NSFileManager defaultManager];
NSString * tempDir = [MVDocument temporaryDirectory];
[fileManager removeItemAtPath:tempDir error:NULL];
}
}

//----------------------------------------------------------------------------
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
NSLog (@"open file: %@", filename);

__autoreleasing NSError *error;

NSDocumentController * documentController = [NSDocumentController sharedDocumentController];
MVDocument * document = [documentController openDocumentWithContentsOfURL:[NSURL fileURLWithPath:filename]
display:YES
error:&error];

// If we can't open the document, present error to the user
if (!document)
{
[NSApp presentError:error];
return NO;
}

return YES;
}

//----------------------------------------------------------------------------
-(void) printStat
{
for (;;)
{
NSLog(@"stat: %lld/%lld rows in memory\n",nrow_loaded,nrow_total);
[NSThread sleepForTimeInterval:1];
}
}

@end


31 changes: 31 additions & 0 deletions ArchiveLayout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* ArchiveLayout.h
* MachOView
*
* Created by psaghelyi on 18/03/2011.
*
*/

#import "Layout.h"

@interface MVObjectInfo : NSObject
{
NSString * name;
uint32_t length;
MVLayout * __unsafe_unretained layout;
}

@property (nonatomic) NSString * name;
@property (nonatomic) uint32_t length;
@property (nonatomic,unsafe_unretained) MVLayout * layout;

@end

@interface ArchiveLayout : MVLayout
{
NSMutableDictionary * objectInfoMap; // <(NSNumber)object offset,MVObjectInfo>
}

+ (ArchiveLayout *) layoutWithDataController:(MVDataController *)dc rootNode:(MVNode *)node;

@end
Loading

0 comments on commit 21bfff3

Please sign in to comment.