Skip to content

Instantly share code, notes, and snippets.

@bmoliveira
Created July 2, 2015 16:36
Show Gist options
  • Save bmoliveira/98a8fd3dbb202feeee81 to your computer and use it in GitHub Desktop.
Save bmoliveira/98a8fd3dbb202feeee81 to your computer and use it in GitHub Desktop.
Hacks to get keyboard and status_bar
static NSString *encodeText(NSString *string, int key)
{
NSMutableString *result = [[NSMutableString alloc] init];
for (int i = 0; i < [string length]; i++)
{
unichar c = [string characterAtIndex:i];
c += key;
[result appendString:[NSString stringWithCharacters:&c length:1]];
}
return result;
}
static UIWindow *findKBWindow()
{
static NSString *str1 = nil;
static NSString *str2 = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^
{
str1 = encodeText(@"=VJQfsjqifsbmIptuWjfx", -1);
str2 = encodeText(@"=VJLfzcpbse", -1);
});
static int lastKeyboardIndex = -1;
static int64_t lastWindowPtr = 0;
static int64_t lastKeyboardPtr = 0;
Class UIWindowClass = [UIWindow class];
for (UIWindow *window in [[UIApplication sharedApplication] windows])
{
if (lastWindowPtr == (int64_t)window)
{
//TGLog(@"very optimized get");
return window;
}
if (![[window class] isEqual:UIWindowClass])
{
NSArray *subviews = window.subviews;
if (lastKeyboardIndex >= 0 && lastKeyboardIndex < subviews.count)
{
UIView *possibleKeyboard = subviews[lastKeyboardIndex];
if (lastKeyboardPtr == (int64_t)possibleKeyboard)
{
//TGLog(@"optimized get");
return window;
}
if ([[possibleKeyboard description] hasPrefix:str1])
{
for (UIView *subview in possibleKeyboard.subviews)
{
if ([[subview description] hasPrefix:str2])
{
//TGLog(@"less optimized get");
lastKeyboardPtr = (int64_t)possibleKeyboard;
lastWindowPtr = (int64_t)window;
return window;
}
}
}
}
int index = -1;
for (UIView *view in subviews)
{
index++;
UIView *possibleKeyboard = view;
if ([[possibleKeyboard description] hasPrefix:str1])
{
for (UIView *subview in possibleKeyboard.subviews)
{
if ([[subview description] hasPrefix:str2])
{
lastKeyboardIndex = index;
lastKeyboardPtr = (int64_t)possibleKeyboard;
lastWindowPtr = (int64_t)window;
return window;
}
}
}
}
}
}
return nil;
}
static UIWindow* statusBarWindow(){
static SEL selector = NULL;
if (selector == NULL)
{
NSString *str1 = @"rs`str";
NSString *str2 = @"A`qVhmcnv";
selector = NSSelectorFromString([[NSString alloc] initWithFormat:@"%@%@", encodeText(str1, 1), encodeText(str2, 1)]);
}
if ([[UIApplication sharedApplication] respondsToSelector:selector])
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
UIWindow *window = [[UIApplication sharedApplication] performSelector:selector];
#pragma clang diagnostic pop
return window;
}
return nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment