-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathInfoWindowController.m
executable file
·195 lines (156 loc) · 5.68 KB
/
InfoWindowController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//
// InfoWindowController.m
// KnockKnock
//
// Created by Patrick Wardle on 2/21/15.
// Copyright (c) 2015 Objective-See. All rights reserved.
//
#import "File.h"
#import "Consts.h"
#import "Command.h"
#import "Extension.h"
#import "Utilities.h"
#import "InfoWindowController.h"
@implementation InfoWindowController
@synthesize itemObj;
@synthesize plistWindowController;
//automatically invoked when window is loaded
// ->set to white
-(void)windowDidLoad
{
//super
[super windowDidLoad];
//not in dark mode?
// make window white
if(YES != isDarkMode())
{
//make white
self.window.backgroundColor = NSColor.whiteColor;
}
return;
}
//init method
// ->save item and load nib
-(id)initWithItem:(ItemBase*)selectedItem
{
self = [super init];
if(nil != self)
{
//load file info window
if(YES == [selectedItem isKindOfClass:[File class]])
{
//load nib
self.windowController = [[InfoWindowController alloc] initWithWindowNibName:@"FileInfoWindow"];
}
//load extension info window
else if(YES == [selectedItem isKindOfClass:[Extension class]])
{
//load nib
self.windowController = [[InfoWindowController alloc] initWithWindowNibName:@"ExtensionInfoWindow"];
}
//save item
self.windowController.itemObj = selectedItem;
}
return self;
}
//automatically called when nib is loaded
// ->save self into iVar, and center window
-(void)awakeFromNib
{
//configure UI
[self configure];
//center
[self.window center];
}
//configure window
// ->add item's attributes (name, path, etc.)
-(void)configure
{
//handle File class
if(YES == [self.itemObj isKindOfClass:[File class]])
{
//set icon
self.icon.image = getIconForBinary(self.itemObj.path, ((File*)itemObj).bundle);
//set name
[self.name setStringValue:self.itemObj.name];
//flagged files
// ->make name red!
if( (nil != ((File*)self.itemObj).vtInfo) &&
(0 != [((File*)self.itemObj).vtInfo[VT_RESULTS_POSITIVES] unsignedIntegerValue]) )
{
//set color (light red)
self.name.textColor = [NSColor redColor];
}
//set path
[self.path setStringValue:self.itemObj.path];
//set hash
[self.hashes setStringValue:[NSString stringWithFormat:@"%@ / %@", ((File*)self.itemObj).hashes[KEY_HASH_MD5], ((File*)self.itemObj).hashes[KEY_HASH_SHA1]]];
//set size
[self.size setStringValue:[NSString stringWithFormat:@"%llu bytes", ((File*)self.itemObj).attributes.fileSize]];
//set date
[self.date setStringValue:[NSString stringWithFormat:@"%@ (created) / %@ (modified)", ((File*)self.itemObj).attributes.fileCreationDate, ((File*)self.itemObj).attributes.fileModificationDate]];
//set plist
if(nil != ((File*)self.itemObj).plist)
{
//create/set attributes string
self.plist.attributedStringValue = [[NSMutableAttributedString alloc] initWithString:((File*)self.itemObj).plist attributes:@{NSFontAttributeName: [NSFont fontWithName:@"Menlo" size:11], NSLinkAttributeName:[NSURL URLWithString:@"#"], NSForegroundColorAttributeName:[NSColor blueColor], NSUnderlineStyleAttributeName:[NSNumber numberWithInt:NSSingleUnderlineStyle]}];
//add click event handler
[self.plist addGestureRecognizer:[[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(showPlist:)]];
}
//no plist
else
{
//set
[self.plist setStringValue:@"no plist for item"];
}
//set signing info
[self.sign setStringValue:[(File*)self.itemObj formatSigningInfo]];
}
//handle Extension class
if(YES == [self.itemObj isKindOfClass:[Extension class]])
{
//set icon
self.icon.image = getIconForBinary(((Extension*)itemObj).browser, nil);
//set name
[self.name setStringValue:self.itemObj.name];
//set path
[self.path setStringValue:self.itemObj.path];
//set description
// ->optional
if(nil != ((Extension*)self.itemObj).details)
{
//set
[self.details setStringValue:[NSString stringWithFormat:@"%@", ((Extension*)self.itemObj).details]];
}
//set id
[self.identifier setStringValue:[NSString stringWithFormat:@"%@", ((Extension*)self.itemObj).identifier]];
//set date
[self.date setStringValue:[NSString stringWithFormat:@"%@ (created) / %@ (modified)", ((File*)self.itemObj).attributes.fileCreationDate, ((File*)self.itemObj).attributes.fileModificationDate]];
//set signing info
//[self.sign setStringValue:[(File*)self.itemObj formatSigningInfo]];
}
return;
}
//invoked when user clicks on plist
// display plist window pane w/ contents
- (void)showPlist:(id)sender
{
//alloc sheet
self.plistWindowController = [[PlistWindowController alloc] initWithWindowNibName:@"PlistWindow"];
//set path
self.plistWindowController.plist = ((File*)self.itemObj).plist;
//show preferences
[self.window beginSheet:self.plistWindowController.window completionHandler:^(NSModalResponse returnCode) {
//unset window controller
self.plistWindowController = nil;
}];
return;
}
//automatically invoked when user clicks 'close'
// ->just close window
-(IBAction)closeWindow:(id)sender
{
//close
[self.window close];
}
@end