+static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
+static CGImageRef *(*_UIImageRefAtPath)(NSString *path, bool cache, UIImageOrientation *orientation);
+static UIImage *(*_UIImageWithName)(NSString *name);
+static NSBundle *(*_UIKitBundle)();
+static void (*_UISharedImageInitialize)(bool);
+static int (*_UISharedImageNameGetIdentifier)(NSString *);
+static UIImage *(*_UISharedImageWithIdentifier)(int);
+
+static UIImage *$_UIImageWithName(NSString *name) {
+ int id(_UISharedImageNameGetIdentifier(name));
+ if (Debug_)
+ NSLog(@"WB:Debug: UIImageWithName(\"%@\", %d)", name, id);
+
+ if (id == -1)
+ return _UIImageAtPath(name, _UIKitBundle());
+ else {
+ NSNumber *key([NSNumber numberWithInt:id]);
+ UIImage *image = [UIImages_ objectForKey:key];
+ if (image != nil)
+ return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
+ if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
+ image = [[$UIImage alloc] initWithContentsOfFile:path];
+ if (image != nil)
+ [image autorelease];
+ }
+ if (image == nil)
+ image = _UISharedImageWithIdentifier(id);
+ [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
+ return image;
+ }
+}
+
+// ldr pc, [pc, #-4]
+#define ldr_pc_$pc_m4$ 0xe51ff004
+
+template <typename Type_>
+static void WBReplace(Type_ *symbol, Type_ *replace, Type_ **result) {
+ if (Debug_)
+ NSLog(@"WB:Notice: Remapping %p to %p", symbol, replace);
+ if (symbol == NULL)
+ return;
+
+ int page = getpagesize();
+ uintptr_t base = reinterpret_cast<uintptr_t>(symbol) / page * page;
+
+ mach_port_t self = mach_task_self();
+
+ if (kern_return_t error = vm_protect(self, base, page, FALSE, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_COPY)) {
+ NSLog(@"WB:Error:vm_protect():%d", error);
+ return;
+ }
+
+ uint32_t *code = reinterpret_cast<uint32_t *>(symbol);
+ uint32_t backup[2] = {code[0], code[1]};
+
+ code[0] = ldr_pc_$pc_m4$;
+ code[1] = reinterpret_cast<uint32_t>(replace);
+
+ __clear_cache(reinterpret_cast<char *>(code), reinterpret_cast<char *>(code + 2));
+
+ if (kern_return_t error = vm_protect(self, base, page, FALSE, VM_PROT_READ | VM_PROT_EXECUTE))
+ NSLog(@"WB:Error:vm_protect():%d", error);
+
+ if (result != NULL) {
+ uint32_t *buffer = reinterpret_cast<uint32_t *>(mmap(
+ NULL, sizeof(uint32_t) * 4,
+ PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE,
+ -1, 0
+ ));
+
+ if (buffer == MAP_FAILED) {
+ NSLog(@"WB:Error:mmap():%d", errno);
+ return;
+ }
+
+ buffer[0] = backup[0];
+ buffer[1] = backup[1];
+ buffer[2] = ldr_pc_$pc_m4$;
+ buffer[3] = reinterpret_cast<uint32_t>(code + 2);
+
+ if (mprotect(buffer, sizeof(uint32_t) * 4, PROT_READ | PROT_EXEC) == -1) {
+ NSLog(@"WB:Error:mprotect():%d", errno);
+ return;
+ }
+
+ *result = reinterpret_cast<Type_ *>(buffer);
+ }
+}
+
+template <typename Type_>
+static void WBReplace(Type_ *symbol, Type_ *replace) {
+ return WBReplace(symbol, replace, static_cast<Type_ **>(NULL));
+}
+
+#define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
+#define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
+
+/*static void UIWebDocumentView$setViewportSize$forDocumentTypes$(UIWebDocumentView *self, SEL sel, CGSize size, int type) {
+ NSLog(@"WB:Examine: %f:%f:%u", size.width, size.height, type);
+}*/
+
+static bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long, char *, bool &);
+
+static bool $_Z24GetFileNameForThisActionmPcRb(unsigned long a0, char *a1, bool &a2) {
+ bool value = _Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
+ if (Debug_)
+ NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
+
+ if (value) {
+ NSString *path = [NSString stringWithUTF8String:a1];
+ if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
+ NSString *file = [path substringFromIndex:31];
+ NSLog(@"%@", file);
+ for (NSString *theme in themes_) {
+ NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
+ if ([Manager_ fileExistsAtPath:path]) {
+ strcpy(a1, [path UTF8String]);
+ continue;
+ }
+ }
+ }
+ }
+ return value;
+}
+
+static void ChangeWallpaper(
+ CFNotificationCenterRef center,
+ void *observer,
+ CFStringRef name,
+ const void *object,
+ CFDictionaryRef info
+) {
+ if (Debug_)
+ NSLog(@"WB:Debug:ChangeWallpaper!");
+ UIImage *image;
+ if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"Wallpaper.png", @"Wallpaper.jpg", nil])) {
+ image = [[$UIImage alloc] initWithContentsOfFile:path];
+ if (image != nil)
+ image = [image autorelease];
+ } else image = nil;
+ [Wallpaper_ setImage:image];
+}