Skip to content

Instantly share code, notes, and snippets.

@rweichler
Last active November 16, 2015 05:50
Show Gist options
  • Save rweichler/fdd6a8b1b55488d8d2c6 to your computer and use it in GitHub Desktop.
Save rweichler/fdd6a8b1b55488d8d2c6 to your computer and use it in GitHub Desktop.
block ur ex gf without blocking her
#import <Foundation/Foundation.h>
#define Log(fmt, ...) NSLog(@"NoExGFStory: %@", [NSString stringWithFormat:fmt, ## __VA_ARGS__])
#define PREF_PATH "/var/mobile/Library/Preferences/com.r333d/blocked_snapchat_stories.txt"
//use a hashmap for fast lookups
static NSMutableDictionary *_blocked = nil;
// makes snapchat think the friend has 0 stories to display.
// this actually makes snapchat still think they still have stories,
// but its just 0. so theres a blank UITableViewCell in "Recent updates".
// completely removes the cell from "All Stories".
%hook FriendStories
-(BOOL)hasStories
{
NSString *username = [self performSelector:@selector(username)];
if([_blocked valueForKey:username]) {
return false;
} else {
return %orig;
}
}
%end
// removes the blank UITableViewCell in "Recent Updates".
// does not remove the cell in "All Stories". the above
// hook is for that.
%hook FriendStoriesCollection
-(NSMutableArray *)friendUsernamesWithUnviewedStories
{
NSMutableArray *arr = %orig;
for(int i = 0; i < arr.count; i++) {
NSString *name = arr[i];
// the usernames, for some reason, have an 'x' appended to the front
// of it. i have no idea why.
NSString *sub = [name substringFromIndex:1];
// just in case if snapchat removes the stupid 'x' in a future
// update, im checking for both in the dictionary.
if([_blocked valueForKey:sub] || [_blocked valueForKey:name]) {
[arr removeObjectAtIndex:i];
i--;
}
}
return arr;
}
%end
static void add_to_blocked(const char *name)
{
if(strlen(name) == 0) return;
NSString *str = [NSString stringWithUTF8String:name];
[_blocked setObject:[NSNumber numberWithBool:true] forKey:str];
}
%ctor {
// shitty preference loading.
// the loaded txt file should have
// a list of usernames separated
// by newlines.
FILE *f = fopen(PREF_PATH, "r");
if(f != NULL) {
_blocked = NSMutableDictionary.dictionary;
char line[BUFSIZ];
line[0] = '\0';
char ch;
do {
ch = fgetc(f);
if(ch == '\n' || ch == '\r' || ch == EOF) {
add_to_blocked(line);
line[0] = '\0';
} else {
int len = strlen(line);
line[len] = ch;
line[len + 1] = '\0';
}
} while(ch != EOF);
fclose(f);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment