Skip to content

Commit

Permalink
New format
Browse files Browse the repository at this point in the history
UFSNotificationList replaces UFSAssociationTable and UFSAssociation as the class that handles the notification tracking.
  • Loading branch information
uroboro committed Jun 3, 2014
1 parent 024b673 commit 81256e7
Show file tree
Hide file tree
Showing 11 changed files with 844 additions and 240 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,5 @@ pip-log.txt
.theos
theos
packages
obj
obj
_
674 changes: 674 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ and:


_install:
@sudo -c 'make internal-install'
@sudo make internal-install

#now do 'make a clean package and _install'

remove:
@apt-get remove $(THEOS_PACKAGE_NAME)

after-install::
install.exec "killall -9 SpringBoard backboardd"
5 changes: 4 additions & 1 deletion NotificationExplorer.plist
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{ Filter = {} }
{
Filter = {
};
}
172 changes: 84 additions & 88 deletions sources/Tweak.xm
Original file line number Diff line number Diff line change
@@ -1,46 +1,55 @@
#import <notify.h>
#import "UFSAssociationTable.h"
#import "UFSNotificationList.h"

#define CMCLog(format, ...) \
NSLog(@"\033[1;36m(%s) in [%s:%d]\033[0m \033[5;32;40m:::\033[0m \033[0;31m%@\033[0m", __PRETTY_FUNCTION__, __FILE__, __LINE__, [NSString stringWithFormat:format, ## __VA_ARGS__])

#define UNKNOWN_OBJ_FORMAT(object) @"unknown instance (%p) of class %@", object, NSStringFromClass([object class])
#define CMCLogObject(object) CMCLog(@"unknown instance (%p) of class %@", object, NSStringFromClass([object class])

#define CMCLogObject(object) CMCLog(UNKNOWN_OBJ_FORMAT(object))
//convenient macros

#define STRINGIFY_(x) # x
#define STRINGIFY(x) STRINGIFY_(x)

#define PASTE_(a,b) a ## b
#define PASTE(a,b) PASTE_(a,b)

#define DICT(n, args...) \
[NSMutableDictionary dictionaryWithObjectsAndKeys:(n), @"data", args, nil]
#define fhook_prefix_orig original_
#define fhook_prefix_custom custom_
#define fhook(returnValue, name, ...) \
static returnValue(* PASTE(fhook_prefix_orig, name))(__VA_ARGS__);\
returnValue PASTE(fhook_prefix_custom, name)(__VA_ARGS__)

#define ADDOBJPAIR(d, o) [d setObject:(o) forKey:(o)]
#define fhook_orig(name, ...) PASTE(fhook_prefix_orig, name)(__VA_ARGS__)

#define ADDATTRIBUTE_(a, b, c, class) do {\
NSMutableDictionary *att = UFSAssociationTableGet_(a, class);\
if (att) { ADDOBJPAIR(att, c); } else { UFSAssociationTableAdd_(a, DICT(b, c, c), class); }\
} while (0)
#define ADDATTRIBUTE(a, b, c) ADDATTRIBUTE_(a, b, c, [self class])
#define fhookit(name) MSHookFunction(name, PASTE(fhook_prefix_custom, name), &(PASTE(fhook_prefix_orig, name)))

//end macros

%group gNSNotificationCenter
%hook NSNotificationCenter

- (void)addObserver:(id)observer selector:(SEL)aSelector name:(NSString *)notificationName object:(id)anObject {
%orig;
ADDATTRIBUTE(notificationName, @"notification", @"observe");
[[UFSNotificationList sharedInstance] addAPI:@"NSNotificationCenter" action:@"observe" type:@"notification" toNotification:notificationName];;
}

- (void)postNotification:(NSNotification *)notification {
%orig;
ADDATTRIBUTE([notification name], @"notification", @"post");
NSString *notificationName = [notification name];
[[UFSNotificationList sharedInstance] addAPI:@"NSNotificationCenter" action:@"post" type:@"notification" toNotification:notificationName];;
}
- (void)postNotificationName:(NSString *)notificationName object:(id)anObject {
%orig;
ADDATTRIBUTE(notificationName, @"notification", @"post");
[[UFSNotificationList sharedInstance] addAPI:@"NSNotificationCenter" action:@"post" type:@"notification" toNotification:notificationName];;
}
- (void)postNotificationName:(NSString *)notificationName object:(id)anObject userInfo:(NSDictionary *)userInfo {
%orig;
ADDATTRIBUTE(notificationName, @"notification", @"post");
[[UFSNotificationList sharedInstance] addAPI:@"NSNotificationCenter" action:@"post" type:@"notification" toNotification:notificationName];;
}
%end
%end /* gNSNotificationCenter */

%group gCPDistributedNotificationCenter

@interface CPDistributedNotificationCenter : NSObject
- (id)_initWithServerName:(NSString *)serverName;
Expand All @@ -51,40 +60,41 @@ NSLog(@"\033[1;36m(%s) in [%s:%d]\033[0m \033[5;32;40m:::\033[0m \033[0;31m%@\03
@end

%hook CPDistributedNotificationCenter

- (id)_initWithServerName:(NSString *)serverName {
id r = %orig;
ADDATTRIBUTE(serverName, @"server", @"init");
[[UFSNotificationList sharedInstance] addAPI:@"CPDistributedNotificationCenter" action:@"init" type:@"server" toNotification:serverName];;
return r;
}
- (void)deliverNotification:(NSString *)notificationName userInfo:(NSDictionary *)userInfo {
%orig;
ADDATTRIBUTE(notificationName, @"notification", @"deliver");
[[UFSNotificationList sharedInstance] addAPI:@"CPDistributedNotificationCenter" action:@"deliver" type:@"notification" toNotification:notificationName];;
}
- (void)postNotificationName:(NSString *)notificationName {
%orig;
ADDATTRIBUTE(notificationName, @"notification", @"post");
[[UFSNotificationList sharedInstance] addAPI:@"CPDistributedNotificationCenter" action:@"post" type:@"notification" toNotification:notificationName];;
}
- (void)postNotificationName:(NSString *)notificationName userInfo:(NSDictionary *)userInfo {
%orig;
ADDATTRIBUTE(notificationName, @"notification", @"post");
[[UFSNotificationList sharedInstance] addAPI:@"CPDistributedNotificationCenter" action:@"post" type:@"notification" toNotification:notificationName];;
}
- (BOOL)postNotificationName:(NSString *)notificationName userInfo:(NSDictionary *)userInfo toBundleIdentifier:(NSString *)bundleIdentifier {
BOOL r = %orig;
ADDATTRIBUTE(notificationName, @"notification", @"post");
[[UFSNotificationList sharedInstance] addAPI:@"CPDistributedNotificationCenter" action:@"post" type:@"notification" toNotification:notificationName];;
return r;
}

%end
%end /* gCPDistributedNotificationCenter */

%group gCPDistributedMessagingCenter

typedef struct XXStruct_kUSYWB {
unsigned _field1[8];
} XXStruct_kUSYWB;

@interface CPDistributedMessagingCenter : NSObject {
}
- (void)_dispatchMessageNamed:(id)named userInfo:(id)info reply:(id *)reply auditToken:(void *)token; //token being a XXStruct_kUSYWB
- (id)_initWithServerName:(id)serverName;
- (void)_dispatchMessageNamed:(id)named userInfo:(id)info reply:(id *)reply auditToken:(void *)token; //token being a XXStruct_kUSYWB
- (BOOL)_sendMessage:(id)message userInfo:(id)info receiveReply:(id *)reply error:(id *)error toTarget:(id)target selector:(SEL)selector context:(void *)context;
- (BOOL)_sendMessage:(id)message userInfoData:(id)data oolKey:(id)key oolData:(id)data4 receiveReply:(id *)reply error:(id *)error;
- (void)registerForMessageName:(id)messageName target:(id)target selector:(SEL)selector;
Expand All @@ -95,153 +105,141 @@ typedef struct XXStruct_kUSYWB {
@end

%hook CPDistributedMessagingCenter

- (void)_dispatchMessageNamed:(id)named userInfo:(id)info reply:(id *)reply auditToken:(void *)token {
%orig;
ADDATTRIBUTE(named, @"message", @"dispatch");
}
- (id)_initWithServerName:(id)serverName {
id r = %orig;
ADDATTRIBUTE(serverName, @"server", @"init");
[[UFSNotificationList sharedInstance] addAPI:@"CPDistributedMessagingCenter" action:@"init" type:@"server" toNotification:serverName];;
return r;
}
- (void)_dispatchMessageNamed:(id)named userInfo:(id)info reply:(id *)reply auditToken:(void *)token {
%orig;
[[UFSNotificationList sharedInstance] addAPI:@"CPDistributedMessagingCenter" action:@"dispatch" type:@"message" toNotification:named];;
}
- (BOOL)_sendMessage:(id)message userInfo:(id)info receiveReply:(id *)reply error:(id *)error toTarget:(id)target selector:(SEL)selector context:(void *)context {
BOOL r = %orig;
CMCLogObject(message);
//NSLog(@"unknown instance (%p) of class %@", message, NSStringFromClass([message class]));
ADDATTRIBUTE(message, @"message", @"send");
[[UFSNotificationList sharedInstance] addAPI:@"CPDistributedMessagingCenter" action:@"send" type:@"message" toNotification:message];;
return r;
}
- (BOOL)_sendMessage:(id)message userInfoData:(id)data oolKey:(id)key oolData:(id)data4 receiveReply:(id *)reply error:(id *)error {
BOOL r = %orig;
ADDATTRIBUTE(message, @"message", @"send");
[[UFSNotificationList sharedInstance] addAPI:@"CPDistributedMessagingCenter" action:@"send" type:@"message" toNotification:message];;
return r;
}
- (void)registerForMessageName:(id)messageName target:(id)target selector:(SEL)selector {
%orig;
ADDATTRIBUTE(messageName, @"message", @"register");
[[UFSNotificationList sharedInstance] addAPI:@"CPDistributedMessagingCenter" action:@"register" type:@"message" toNotification:messageName];;
}
- (id)sendMessageAndReceiveReplyName:(id)name userInfo:(id)info {
id r = %orig;
ADDATTRIBUTE(name, @"message", @"send");
[[UFSNotificationList sharedInstance] addAPI:@"CPDistributedMessagingCenter" action:@"send" type:@"message" toNotification:name];;
return r;
}
- (id)sendMessageAndReceiveReplyName:(id)name userInfo:(id)info error:(id *)error {
id r = %orig;
ADDATTRIBUTE(name, @"message", @"send");
[[UFSNotificationList sharedInstance] addAPI:@"CPDistributedMessagingCenter" action:@"send" type:@"message" toNotification:name];;
return r;
}
- (void)sendMessageAndReceiveReplyName:(id)name userInfo:(id)info toTarget:(id)target selector:(SEL)selector context:(void *)context {
%orig;
ADDATTRIBUTE(name, @"message", @"send");
[[UFSNotificationList sharedInstance] addAPI:@"CPDistributedMessagingCenter" action:@"send" type:@"message" toNotification:name];;
}
- (BOOL)sendMessageName:(id)name userInfo:(id)info {
BOOL r = %orig;
ADDATTRIBUTE(name, @"message", @"send");
[[UFSNotificationList sharedInstance] addAPI:@"CPDistributedMessagingCenter" action:@"send" type:@"message" toNotification:name];;
return r;
}

%end
%end /* gCPDistributedMessagingCenter */

//End class hooking
//Start function hooking

//convenient macros

#define paste(a,b) a ## b

#define fhook(returnValue, name, ...) \
static returnValue(* paste(original_, name))(__VA_ARGS__);\
returnValue paste(custom_, name)(__VA_ARGS__)

#define fhookit(name) MSHookFunction(name, paste(custom_, name), &(paste(original_, name)))

//end macros

@interface CoreFoundationNotificationCenter : NSObject
@end

@implementation CoreFoundationNotificationCenter
@end
//Start function hooking

// CFNotificationCenter
fhook(void, CFNotificationCenterAddObserver, CFNotificationCenterRef center, const void *observer, CFNotificationCallback callBack, CFStringRef name, const void *object, CFNotificationSuspensionBehavior suspensionBehavior) {
original_CFNotificationCenterAddObserver(center, observer, callBack, name, object, suspensionBehavior);
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *nameString = (name != NULL)? (NSString *)name:@"all";
ADDATTRIBUTE_(nameString, @"notification", @"observe", [CoreFoundationNotificationCenter class]);
NSString *notificationName = (name != NULL)? (NSString *)name:@"all";
[[UFSNotificationList sharedInstance] addAPI:@"CFNotificationCenter" action:@"observe" type:@"notification" toNotification:notificationName];;
[pool release];
}

fhook(void, CFNotificationCenterPostNotification, CFNotificationCenterRef center, CFStringRef name, const void *object, CFDictionaryRef userInfo, Boolean deliverImmediately) {
original_CFNotificationCenterPostNotification(center, name, object, userInfo, deliverImmediately);
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
ADDATTRIBUTE_((NSString *)name, @"notification", @"post", [CoreFoundationNotificationCenter class]);
NSString *notificationName = (NSString *)name;
[[UFSNotificationList sharedInstance] addAPI:@"CFNotificationCenter" action:@"post" type:@"notification" toNotification:notificationName];;
[pool release];
}

fhook(void, CFNotificationCenterPostNotificationWithOptions, CFNotificationCenterRef center, CFStringRef name, const void *object, CFDictionaryRef userInfo, CFOptionFlags options) {
original_CFNotificationCenterPostNotificationWithOptions(center, name, object, userInfo, options);
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
ADDATTRIBUTE_((NSString *)name, @"notification", @"post", [CoreFoundationNotificationCenter class]);
NSString *notificationName = (NSString *)name;
[[UFSNotificationList sharedInstance] addAPI:@"CFNotificationCenter" action:@"post" type:@"notification" toNotification:notificationName];;
[pool release];
}

@interface CNotifications : NSObject
@end

@implementation CNotifications
@end

// notify_*
fhook(uint32_t, notify_post, const char *name) {
uint32_t r = original_notify_post(name);
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *nameString = [NSString stringWithUTF8String:name];

ADDATTRIBUTE_(nameString, @"notification", @"post", [CNotifications class]);
NSString *notificationName = [NSString stringWithUTF8String:name];
[[UFSNotificationList sharedInstance] addAPI:@"CNotifications" action:@"post" type:@"notification" toNotification:notificationName];;
[pool release];
return r;
}
fhook(uint32_t, notify_register_check, const char *name, int *out_token) {
uint32_t r = original_notify_register_check(name, out_token);
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *nameString = [NSString stringWithUTF8String:name];

ADDATTRIBUTE_(nameString, @"notification", @"register", [CNotifications class]);
NSString *notificationName = [NSString stringWithUTF8String:name];
[[UFSNotificationList sharedInstance] addAPI:@"CNotifications" action:@"register" type:@"notification" toNotification:notificationName];;
[pool release];
return r;
}
fhook(uint32_t, notify_register_signal, const char *name, int sig, int *out_token) {
uint32_t r = original_notify_register_signal(name, sig, out_token);
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *nameString = [NSString stringWithUTF8String:name];

ADDATTRIBUTE_(nameString, @"notification", @"register", [CNotifications class]);
NSString *notificationName = [NSString stringWithUTF8String:name];
[[UFSNotificationList sharedInstance] addAPI:@"CNotifications" action:@"register" type:@"notification" toNotification:notificationName];;
[pool release];
return r;
}
fhook(uint32_t, notify_register_mach_port, const char *name, mach_port_t *notify_port, int flags, int *out_token) {
uint32_t r = original_notify_register_mach_port(name, notify_port, flags, out_token);
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *nameString = [NSString stringWithUTF8String:name];

ADDATTRIBUTE_(nameString, @"notification", @"register", [CNotifications class]);
NSString *notificationName = [NSString stringWithUTF8String:name];
[[UFSNotificationList sharedInstance] addAPI:@"CNotifications" action:@"register" type:@"notification" toNotification:notificationName];;
[pool release];
return r;
}
fhook(uint32_t, notify_register_file_descriptor, const char *name, int *notify_fd, int flags, int *out_token) {
uint32_t r = original_notify_register_file_descriptor(name, notify_fd, flags, out_token);
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *nameString = [NSString stringWithUTF8String:name];

ADDATTRIBUTE_(nameString, @"notification", @"register", [CNotifications class]);
NSString *notificationName = [NSString stringWithUTF8String:name];
[[UFSNotificationList sharedInstance] addAPI:@"CNotifications" action:@"register" type:@"notification" toNotification:notificationName];;
[pool release];
return r;
}

%ctor {
if ([[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.Facebook.Messenger"]) {
return;
}
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

[UFSAssociationTable sharedInstance];
[UFSNotificationList sharedInstance];

if (%c(NSNotificationCenter)){
CMCLog(@"Initing group: %s", STRINGIFY(PASTE(g,NSNotificationCenter)));
%init(gNSNotificationCenter);
}
if (%c(CPDistributedNotificationCenter)){
CMCLog(@"Initing group: %s", STRINGIFY(PASTE(g,CPDistributedNotificationCenter)));
%init(gCPDistributedNotificationCenter);
}
if (%c(CPDistributedMessagingCenter)){
CMCLog(@"Initing group: %s", STRINGIFY(PASTE(g,CPDistributedMessagingCenter)));
%init(gCPDistributedMessagingCenter);
}
[pool release];

fhookit(CFNotificationCenterAddObserver);
fhookit(CFNotificationCenterPostNotification);
Expand All @@ -252,6 +250,4 @@ fhook(uint32_t, notify_register_file_descriptor, const char *name, int *notify_f
fhookit(notify_register_signal);
fhookit(notify_register_mach_port);
fhookit(notify_register_file_descriptor);

[pool release];
}
16 changes: 0 additions & 16 deletions sources/UFSAssociation.h

This file was deleted.

Loading

0 comments on commit 81256e7

Please sign in to comment.