Skip to content

Commit

Permalink
1.0! works using sneaky accessibility method and pids, cleaned up eve…
Browse files Browse the repository at this point in the history
…rything else
  • Loading branch information
insanj committed Apr 7, 2014
1 parent 9676790 commit 844863c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 35 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -7,6 +7,7 @@ include theos/makefiles/common.mk
TWEAK_NAME = SelfDestruct
SelfDestruct_FILES = SelfDestruct.xm
SelfDestruct_LDFLAGS = -lactivator -Ltheos/lib
SelfDestruct_FRAMEWORKS = UIKit
SelfDestruct_PRIVATE_FRAMEWORKS = SpringBoardServices

include $(THEOS_MAKE_PATH)/tweak.mk
Expand Down
22 changes: 7 additions & 15 deletions SelfDestruct.h
@@ -1,27 +1,19 @@
#include <UIKit/UIKit.h>
#include <substrate.h>
#import <libactivator/libactivator.h>

#import <sys/sysctl.h>
#import <dlfcn.h>
#define UIKITPATH "/System/Library/Frameworks/UIKit.framework/UIKit"
#define SBSERVPATH "/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices"

extern "C" {
mach_port_t SBSSpringBoardServerPort();
void SBFrontmostApplicationDisplayIdentifier(mach_port_t port, char *result);
NSString * SBSCopyFrontmostApplicationDisplayIdentifier();
}

@interface NSDistributedNotificationCenter : NSNotificationCenter
@end

@interface UIApplication (Private)
- (unsigned int)_frontmostApplicationPort;
@end

@interface SBApplication : UIApplication
@property(readonly, assign, nonatomic) int pid;

- (id)displayIdentifier;
- (id)displayName;
@end

@interface SpringBoard : SBApplication
- (id)_accessibilityFrontMostApplication;
@end

@interface SelfDestruct : NSObject <LAListener, UIAlertViewDelegate>
Expand Down
24 changes: 5 additions & 19 deletions SelfDestruct.xm
Expand Up @@ -2,30 +2,16 @@

@implementation SelfDestruct

/*static NSString *destruct_pullFrontAppIdentifier() {
char frontAppIdentifier[256];
memset(frontAppIdentifier, sizeof(frontAppIdentifier), 0);
SBFrontmostApplicationDisplayIdentifier(SBSSpringBoardServerPort(), frontAppIdentifier);
return [NSString stringWithCString:frontAppIdentifier encoding:NSASCIIStringEncoding];
}*/

static NSString *destruct_copyFrontAppIdentifier() {
return SBSCopyFrontmostApplicationDisplayIdentifier();
}

- (void)activator:(LAActivator *)activator receiveEvent:(LAEvent *)event {
NSLog(@"[SelfDestruct / DEBUG] Received activator event...");
NSString *front = destruct_copyFrontAppIdentifier();
NSLog(@"[SelfDestruct / DEBUG] Detected frontmost: %@", front);
SBApplication *frontMostApp = [(SpringBoard *)[UIApplication sharedApplication] _accessibilityFrontMostApplication];

if (!front) {
NSLog(@"[SelfDestruct / DEBUG] Cannot kill off an invalid process...");
if (frontMostApp) {
NSLog(@"[SelfDestruct] %@, have a nice day!", frontMostApp.displayName);
system([[NSString stringWithFormat:@"kill %i", frontMostApp.pid] UTF8String]);
}

else {
NSString *name = [[NSBundle bundleWithIdentifier:front] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
NSLog(@"[SelfDestruct] %@, have a nice day!", name);
system([[NSString stringWithFormat:@"killall -9 %@", name] UTF8String]);
NSLog(@"[SelfDestruct] Looks like there's no frontmost application, ignoring event...");
}

[event setHandled:YES];
Expand Down
2 changes: 1 addition & 1 deletion layout/DEBIAN/control
@@ -1,7 +1,7 @@
Package: com.insanj.selfdestruct
Name: SelfDestruct
Depends: mobilesubstrate, libactivator
Version: 0.1
Version: 1.0
Architecture: iphoneos-arm
Description: Kill foreground app (in case of emergency).
Maintainer: insanj <insanjmail@insanj.com>
Expand Down

0 comments on commit 844863c

Please sign in to comment.