Skip to content

Commit

Permalink
增加拖拽的功能:
Browse files Browse the repository at this point in the history
1、首次打开时,会显示初始界面,可直接往界面上拖动Mach-O文件;
2、每次拖动文件的最大数量是3个文件;
  • Loading branch information
mythkiven committed Aug 14, 2019
1 parent 742c982 commit 26f8377
Show file tree
Hide file tree
Showing 14 changed files with 231 additions and 66 deletions.
7 changes: 7 additions & 0 deletions AppController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
[NSThread detachNewThreadSelector:@selector(printStat) toTarget:self withObject:nil];
#endif

// open a file dialogue
#ifdef false
/* default is to not open a file dialogue */
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"OpenAtLaunch"] != nil)
{
Expand All @@ -299,6 +301,11 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
}
}
}
#endif
//open a file dialogue
[self application:NSApp openFile:@"/"];


}

//----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions Attach.mm
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
if (readmem((mach_vm_offset_t*)loadcmds, address+mach_header_size, header.sizeofcmds, pid, &region_info))
{
NSLog(@"Can't read load commands");
free(loadcmds);
return KERN_FAILURE;
}

Expand Down
5 changes: 4 additions & 1 deletion Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*
*/

#import "MKDragView.h"

@class MVDataController;

@interface MVOutlineView : NSOutlineView
Expand All @@ -27,7 +29,7 @@
@end


@interface MVDocument : NSDocument
@interface MVDocument : NSDocument <NSDraggingDestination,MKDragViewDelegate>
{
IBOutlet MVOutlineView * leftView;
IBOutlet MVTableView * rightView;
Expand All @@ -38,6 +40,7 @@
IBOutlet NSButton * stopButton;
MVDataController * dataController;
int32_t threadCount;
BOOL isFirstLoad;
}
@property (nonatomic,readonly) MVDataController * dataController;

Expand Down
87 changes: 82 additions & 5 deletions Document.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#import "Layout.h"
#include <unistd.h>


#import "MKDragView.h"

//============================================================================
@implementation MVOutlineView

Expand Down Expand Up @@ -302,7 +305,7 @@ - (BOOL)isPartialStringValid:(NSString **)partialStringPtr
@end

//============================================================================
@implementation MVDocument
@implementation MVDocument

@synthesize dataController;

Expand Down Expand Up @@ -337,6 +340,8 @@ - (id)init
dataController = [[MVDataController alloc] init];
threadCount = 0;



NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
typeof(self) __weak weakSelf = self;

Expand Down Expand Up @@ -369,8 +374,73 @@ - (id)init
return self;
}




- (void)dragViewFileList:(NSArray *)fileList {
if(!fileList || [fileList count] <= 0) {
return;
}
NSInteger maxNum = 3;
for (int n = 0 ; n < [fileList count] ; n++) {
NSString *filePath = [fileList objectAtIndex:n];
BOOL isLastMachOView = [self onlyRunningMachOView:filePath];
if (isLastMachOView == YES){
if(maxNum == 0){
break;
}
maxNum --;

if (isFirstLoad) {
[[[NSApplication sharedApplication] mainWindow] hidesOnDeactivate];
[[[NSApplication sharedApplication] mainWindow] close];
[[[NSApplication sharedApplication] mainWindow] performClose:self];
}
[self openNewWindow:filePath];
}
}
}
- (void)openNewWindow:(NSString*)filePath{
isFirstLoad = NO;
__autoreleasing NSError *error;
NSDocumentController * documentController = [NSDocumentController sharedDocumentController];
MVDocument * document = [documentController openDocumentWithContentsOfURL:[NSURL fileURLWithPath:filePath]
display:YES
error:&error];
if (!document) {
[NSApp presentError:error];
}
}
- (BOOL)onlyRunningMachOView:(NSString*)filename {
NSURL * url = [NSURL fileURLWithPath:filename];
NSNumber * isRegularFile = nil;
[url getResourceValue:&isRegularFile forKey:NSURLIsRegularFileKey error:NULL];
if ([isRegularFile boolValue] == NO) {
return NO;
}
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;
}


//----------------------------------------------------------------------------
- (NSString *)windowNibName
- (NSString *)windowNibName // 1
{
// Implement this to return a nib to load OR implement -makeWindowControllers to manually create your controllers.
return @"Layout";
Expand Down Expand Up @@ -478,7 +548,6 @@ - (void)handleThreadStateChanged:(NSNotification *)notification
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[super windowControllerDidLoadNib:aController];

// fill in initial data sources
[statusText setStringValue:@"Loading..."];
for (MVLayout * layout in dataController.layouts)
Expand All @@ -491,7 +560,8 @@ - (void)windowControllerDidLoadNib:(NSWindowController *)aController
[leftView expandItem:dataController.rootNode];

// finish processing in background
[statusText setStringValue:@"Processing in background..."];
[statusText setStringValue: isFirstLoad ? @"Please drag in the MachO file" : @"Processing in background..."];
stopButton.hidden = isFirstLoad;
for (MVLayout * layout in dataController.layouts)
{
#ifdef MV_NO_MULTITHREAD
Expand Down Expand Up @@ -519,6 +589,13 @@ - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
{
// create a temporary copy for patching
if([absoluteURL.absoluteString isEqualToString:@"file:///"]){
isFirstLoad = YES;
return YES;
}else{
isFirstLoad = NO;
}

const char *tmp = [[MVDocument temporaryDirectory] UTF8String];
char *tmpFilePath = strdup(tmp);
if (mktemp(tmpFilePath) == NULL)
Expand All @@ -531,7 +608,7 @@ - (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSEr
NSURL * tmpURL = [NSURL fileURLWithPath:[NSString stringWithUTF8String:tmpFilePath]];
free(tmpFilePath);

[[NSFileManager defaultManager] copyItemAtURL:absoluteURL
[[NSFileManager defaultManager] copyItemAtURL:absoluteURL//file:///Users/apple/Desktop/Product_jinGangWallet
toURL:tmpURL
error:outError];
if (*outError) return NO;
Expand Down
32 changes: 18 additions & 14 deletions English.lproj/Credits.rtf
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
{\rtf1\ansi\ansicpg1252\cocoartf1187\cocoasubrtf340
{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fnil\fcharset0 Menlo-Regular;}
{\colortbl;\red255\green255\blue255;}
{\rtf1\ansi\ansicpg936\cocoartf1671\cocoasubrtf500
{\fonttbl\f0\fswiss\fcharset0 Helvetica-Bold;\f1\fswiss\fcharset0 Helvetica;\f2\fnil\fcharset0 Menlo-Regular;
\f3\froman\fcharset0 Times-Roman;}
{\colortbl;\red255\green255\blue255;\red0\green0\blue233;}
{\*\expandedcolortbl;;\cssrgb\c0\c0\c93333;}
\paperw11900\paperh16840\vieww9600\viewh8400\viewkind0
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\partightenfactor0

\f0\b\fs24 \cf0 Engineering:
\b0 \
\f1\b0 \
Peter Saghelyi\

\f1\fs22 \CocoaLigature0 fG!
\f0\fs24 \CocoaLigature1 \
\
\f2\fs22 \CocoaLigature0 fG!
\f1\fs24 \CocoaLigature1 \
MythKiven({\field{\*\fldinst{HYPERLINK "https://github.com/mythkiven"}}{\fldrslt
\f3 \cf2 \expnd0\expndtw0\kerning0
\ul \ulc2 \outl0\strokewidth0 \strokec2 https://github.com/mythkiven}})\

\b Human Interface Design:
\b0 \
\f0\b Human Interface Design:
\f1\b0 \
...\
\

\b Testing:
\b0 \
\f0\b Testing:
\f1\b0 \
...\
\

\b Documentation:
\b0 \
\f0\b Documentation:
\f1\b0 \
...\
}
40 changes: 23 additions & 17 deletions English.lproj/Layout.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4514" systemVersion="13C64" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment defaultVersion="1070" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4514"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="MVDocument">
Expand All @@ -18,8 +19,8 @@
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application"/>
<window title="Mach-O Browser" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" animationBehavior="default" id="3" userLabel="Window">
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Mach-O Browser" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" animationBehavior="default" id="3" userLabel="Window">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES" texturedBackground="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="142" y="376" width="900" height="400"/>
Expand All @@ -36,14 +37,14 @@
<rect key="frame" x="0.0" y="0.0" width="271" height="346"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<scrollView autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" usesPredominantAxisScrolling="NO" id="21">
<scrollView autohidesScrollers="YES" horizontalLineScroll="98" horizontalPageScroll="10" verticalLineScroll="98" verticalPageScroll="10" usesPredominantAxisScrolling="NO" id="21">
<rect key="frame" x="0.0" y="0.0" width="271" height="346"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<clipView key="contentView" id="SJy-4x-n7j">
<rect key="frame" x="1" y="1" width="269" height="344"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<outlineView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnReordering="NO" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" typeSelect="NO" indentationPerLevel="16" autoresizesOutlineColumn="YES" outlineTableColumn="25" id="24" userLabel="Mach-O Tree" customClass="MVOutlineView">
<outlineView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnReordering="NO" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" typeSelect="NO" rowHeight="96" rowSizeStyle="automatic" viewBased="YES" indentationPerLevel="16" autoresizesOutlineColumn="YES" outlineTableColumn="25" id="24" userLabel="Mach-O Tree" customClass="MVOutlineView">
<rect key="frame" x="0.0" y="0.0" width="269" height="344"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
Expand Down Expand Up @@ -71,13 +72,12 @@
</connections>
</outlineView>
</subviews>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</clipView>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="23">
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="23">
<rect key="frame" x="1" y="330" width="314" height="15"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="22">
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="22">
<rect key="frame" x="315" y="1" width="15" height="329"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
Expand All @@ -92,7 +92,7 @@
<rect key="frame" x="0.0" y="0.0" width="619" height="346"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<clipView key="contentView" id="wjX-dU-5S1">
<rect key="frame" x="1" y="17" width="617" height="328"/>
<rect key="frame" x="1" y="0.0" width="617" height="345"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" columnReordering="NO" autosaveColumns="NO" headerView="9" id="10" userLabel="Details Table" customClass="MVTableView">
Expand Down Expand Up @@ -163,13 +163,12 @@
</connections>
</tableView>
</subviews>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</clipView>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="11">
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="11">
<rect key="frame" x="1" y="534" width="442" height="15"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="12">
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="12">
<rect key="frame" x="397" y="17" width="15" height="415"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
Expand Down Expand Up @@ -203,7 +202,7 @@
<segmentedControl verticalHuggingPriority="750" id="109">
<rect key="frame" x="46" y="374" width="196" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<segmentedCell key="cell" refusesFirstResponder="YES" state="on" alignment="left" style="rounded" trackingMode="selectOne" id="110">
<segmentedCell key="cell" refusesFirstResponder="YES" state="on" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="110">
<font key="font" metaFont="system"/>
<segments>
<segment label="RAW" image="redApple" width="95" selected="YES"/>
Expand All @@ -218,6 +217,13 @@
<rect key="frame" x="637" y="1" width="245" height="20"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
</progressIndicator>
<customView id="KOy-Ls-c9X" customClass="MKDragView">
<rect key="frame" x="0.0" y="24" width="900" height="373"/>
<autoresizingMask key="autoresizingMask"/>
<connections>
<outlet property="delegate" destination="-2" id="2xk-yu-F1A"/>
</connections>
</customView>
<textField verticalHuggingPriority="750" id="116">
<rect key="frame" x="17" y="5" width="390" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
Expand Down Expand Up @@ -252,4 +258,4 @@
<image name="redApple" width="512" height="512"/>
<image name="stop" width="64" height="64"/>
</resources>
</document>
</document>
10 changes: 5 additions & 5 deletions Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<plist version="1.0">
<dict>
<key>CFBuildDate</key>
<string>Wed Aug 14 21:08:17 CST 2019</string>
<string>Thu Aug 15 01:07:21 CST 2019</string>
<key>CFBuildNumber</key>
<string>9135</string>
<string>9276</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
Expand Down Expand Up @@ -36,15 +36,15 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME} fG!'s branch</string>
<string>${PRODUCT_NAME} MythKiven's branch</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.4</string>
<string>2.5</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>9135</string>
<string>9276</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
Expand Down
Loading

0 comments on commit 26f8377

Please sign in to comment.