📄 cydia.mm
字号:
/* Cydia - iPhone UIKit Front-End for Debian APT
* Copyright (C) 2008 Jay Freeman (saurik)
*/
/*
* Redistribution and use in source and binary
* forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the
* above copyright notice, this list of conditions
* and the following disclaimer.
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions
* and the following disclaimer in the documentation
* and/or other materials provided with the
* distribution.
* 3. The name of the author may not be used to endorse
* or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* #include Directives {{{ */
#include <objc/objc.h>
#include <objc/runtime.h>
#include <CoreGraphics/CoreGraphics.h>
#include <GraphicsServices/GraphicsServices.h>
#include <Foundation/Foundation.h>
#include <WebCore/DOMHTML.h>
#import <QuartzCore/CALayer.h>
#import <UIKit/UIKit.h>
// XXX: remove
#import <MessageUI/MailComposeController.h>
#include <WebKit/WebFrame.h>
#include <WebKit/WebView.h>
#include <sstream>
#include <string>
#include <ext/stdio_filebuf.h>
#include <apt-pkg/acquire.h>
#include <apt-pkg/acquire-item.h>
#include <apt-pkg/algorithms.h>
#include <apt-pkg/cachefile.h>
#include <apt-pkg/clean.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/debmetaindex.h>
#include <apt-pkg/error.h>
#include <apt-pkg/init.h>
#include <apt-pkg/mmap.h>
#include <apt-pkg/pkgrecords.h>
#include <apt-pkg/sha1.h>
#include <apt-pkg/sourcelist.h>
#include <apt-pkg/sptr.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
#include <notify.h>
#include <dlfcn.h>
extern "C" {
#include <mach-o/nlist.h>
}
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <errno.h>
#include <pcre.h>
#import "BrowserView.h"
#import "ResetView.h"
#import "UICaboodle.h"
/* }}} */
static const NSStringCompareOptions CompareOptions_ = NSCaseInsensitiveSearch | NSNumericSearch | NSDiacriticInsensitiveSearch | NSWidthInsensitiveSearch | NSForcedOrderingSearch;
/* iPhoneOS 2.0 Compatibility {{{ */
#ifdef __OBJC2__
@interface UICGColor : NSObject {
}
- (id) initWithCGColor:(CGColorRef)color;
@end
@interface NSObject (iPhoneOS)
- (CGColorRef) cgColor;
- (CGColorRef) CGColor;
- (void) set;
@end
@implementation NSObject (iPhoneOS)
- (CGColorRef) cgColor {
return [self CGColor];
}
- (CGColorRef) CGColor {
return (CGColorRef) self;
}
- (void) set {
[[[[objc_getClass("UICGColor") alloc] initWithCGColor:[self CGColor]] autorelease] set];
}
@end
@interface UITextView (iPhoneOS)
- (void) setTextSize:(float)size;
@end
@implementation UITextView (iPhoneOS)
- (void) setTextSize:(float)size {
[self setFont:[[self font] fontWithSize:size]];
}
@end
#endif
/* }}} */
extern NSString * const kCAFilterNearest;
@interface UIApplication (IdleTimer)
- (void) setIdleTimerDisabled:(char)arg0;
@end
/* Information Dictionaries {{{ */
@interface NSMutableArray (Cydia)
- (void) addInfoDictionary:(NSDictionary *)info;
@end
@implementation NSMutableArray (Cydia)
- (void) addInfoDictionary:(NSDictionary *)info {
[self addObject:info];
}
@end
@interface NSMutableDictionary (Cydia)
- (void) addInfoDictionary:(NSDictionary *)info;
@end
@implementation NSMutableDictionary (Cydia)
- (void) addInfoDictionary:(NSDictionary *)info {
NSString *bundle = [info objectForKey:@"CFBundleIdentifier"];
[self setObject:info forKey:bundle];
}
@end
/* }}} */
#define lprintf(args...) fprintf(stderr, args)
#define ForSaurik 0
extern "C" int UIApplicationMain(int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName);
extern NSString *kUIButtonBarButtonAction;
extern NSString *kUIButtonBarButtonInfo;
extern NSString *kUIButtonBarButtonInfoOffset;
extern NSString *kUIButtonBarButtonSelectedInfo;
extern NSString *kUIButtonBarButtonStyle;
extern NSString *kUIButtonBarButtonTag;
extern NSString *kUIButtonBarButtonTarget;
extern NSString *kUIButtonBarButtonTitle;
extern NSString *kUIButtonBarButtonTitleVerticalHeight;
extern NSString *kUIButtonBarButtonTitleWidth;
extern NSString *kUIButtonBarButtonType;
typedef enum {
kUIProgressIndicatorStyleLargeWhite = 0,
kUIProgressIndicatorStyleMediumWhite = 1,
kUIProgressIndicatorStyleMediumBrown = 2,
kUIProgressIndicatorStyleSmallWhite = 3,
kUIProgressIndicatorStyleSmallBlack = 4,
kUIProgressIndicatorStyleTinyWhite = 5,
} UIProgressIndicatorStyle;
typedef enum {
kUIControlEventMouseDown = 1 << 0,
kUIControlEventMouseMovedInside = 1 << 2, // mouse moved inside control target
kUIControlEventMouseMovedOutside = 1 << 3, // mouse moved outside control target
kUIControlEventMouseUpInside = 1 << 6, // mouse up inside control target
kUIControlEventMouseUpOutside = 1 << 7, // mouse up outside control target
kUIControlAllEvents = (kUIControlEventMouseDown | kUIControlEventMouseMovedInside | kUIControlEventMouseMovedOutside | kUIControlEventMouseUpInside | kUIControlEventMouseUpOutside)
} UIControlEventMasks;
@interface NSString (UIKit)
- (NSString *) stringByAddingPercentEscapes;
- (NSString *) stringByReplacingCharacter:(unsigned short)arg0 withCharacter:(unsigned short)arg1;
@end
@interface NSString (Cydia)
+ (NSString *) stringWithUTF8Bytes:(const char *)bytes length:(int)length;
- (NSComparisonResult) compareByPath:(NSString *)other;
@end
@implementation NSString (Cydia)
+ (NSString *) stringWithUTF8Bytes:(const char *)bytes length:(int)length {
char data[length + 1];
memcpy(data, bytes, length);
data[length] = '\0';
return [NSString stringWithUTF8String:data];
}
- (NSComparisonResult) compareByPath:(NSString *)other {
NSString *prefix = [self commonPrefixWithString:other options:0];
size_t length = [prefix length];
NSRange lrange = NSMakeRange(length, [self length] - length);
NSRange rrange = NSMakeRange(length, [other length] - length);
lrange = [self rangeOfString:@"/" options:0 range:lrange];
rrange = [other rangeOfString:@"/" options:0 range:rrange];
NSComparisonResult value;
if (lrange.location == NSNotFound && rrange.location == NSNotFound)
value = NSOrderedSame;
else if (lrange.location == NSNotFound)
value = NSOrderedAscending;
else if (rrange.location == NSNotFound)
value = NSOrderedDescending;
else
value = NSOrderedSame;
NSString *lpath = lrange.location == NSNotFound ? [self substringFromIndex:length] :
[self substringWithRange:NSMakeRange(length, lrange.location - length)];
NSString *rpath = rrange.location == NSNotFound ? [other substringFromIndex:length] :
[other substringWithRange:NSMakeRange(length, rrange.location - length)];
NSComparisonResult result = [lpath compare:rpath];
return result == NSOrderedSame ? value : result;
}
@end
/* Perl-Compatible RegEx {{{ */
class Pcre {
private:
pcre *code_;
pcre_extra *study_;
int capture_;
int *matches_;
const char *data_;
public:
Pcre(const char *regex) :
study_(NULL)
{
const char *error;
int offset;
code_ = pcre_compile(regex, 0, &error, &offset, NULL);
if (code_ == NULL) {
lprintf("%d:%s\n", offset, error);
_assert(false);
}
pcre_fullinfo(code_, study_, PCRE_INFO_CAPTURECOUNT, &capture_);
matches_ = new int[(capture_ + 1) * 3];
}
~Pcre() {
pcre_free(code_);
delete matches_;
}
NSString *operator [](size_t match) {
return [NSString stringWithUTF8Bytes:(data_ + matches_[match * 2]) length:(matches_[match * 2 + 1] - matches_[match * 2])];
}
bool operator ()(NSString *data) {
// XXX: length is for characters, not for bytes
return operator ()([data UTF8String], [data length]);
}
bool operator ()(const char *data, size_t size) {
data_ = data;
return pcre_exec(code_, study_, data, size, 0, 0, matches_, (capture_ + 1) * 3) >= 0;
}
};
/* }}} */
/* Mime Addresses {{{ */
@interface Address : NSObject {
NSString *name_;
NSString *address_;
}
- (NSString *) name;
- (NSString *) address;
+ (Address *) addressWithString:(NSString *)string;
- (Address *) initWithString:(NSString *)string;
@end
@implementation Address
- (void) dealloc {
[name_ release];
if (address_ != nil)
[address_ release];
[super dealloc];
}
- (NSString *) name {
return name_;
}
- (NSString *) address {
return address_;
}
+ (Address *) addressWithString:(NSString *)string {
return [[[Address alloc] initWithString:string] autorelease];
}
+ (NSArray *) _attributeKeys {
return [NSArray arrayWithObjects:@"address", @"name", nil];
}
- (NSArray *) attributeKeys {
return [[self class] _attributeKeys];
}
+ (BOOL) isKeyExcludedFromWebScript:(const char *)name {
return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name];
}
- (Address *) initWithString:(NSString *)string {
if ((self = [super init]) != nil) {
const char *data = [string UTF8String];
size_t size = [string length];
static Pcre address_r("^\"?(.*)\"? <([^>]*)>$");
if (address_r(data, size)) {
name_ = [address_r[1] retain];
address_ = [address_r[2] retain];
} else {
name_ = [[NSString alloc]
initWithBytes:data
length:size
encoding:kCFStringEncodingUTF8
];
address_ = nil;
}
} return self;
}
@end
/* }}} */
/* CoreGraphics Primitives {{{ */
class CGColor {
private:
CGColorRef color_;
public:
CGColor() :
color_(NULL)
{
}
CGColor(CGColorSpaceRef space, float red, float green, float blue, float alpha) :
color_(NULL)
{
Set(space, red, green, blue, alpha);
}
void Clear() {
if (color_ != NULL)
CGColorRelease(color_);
}
~CGColor() {
Clear();
}
void Set(CGColorSpaceRef space, float red, float green, float blue, float alpha) {
Clear();
float color[] = {red, green, blue, alpha};
color_ = CGColorCreate(space, color);
}
operator CGColorRef() {
return color_;
}
};
/* }}} */
extern "C" void UISetColor(CGColorRef color);
/* Random Global Variables {{{ */
static const int PulseInterval_ = 50000;
static const int ButtonBarHeight_ = 48;
static const float KeyboardTime_ = 0.3f;
static const char * const SpringBoard_ = "/System/Library/LaunchDaemons/com.apple.SpringBoard.plist";
static CGColor Blue_;
static CGColor Blueish_;
static CGColor Black_;
static CGColor Off_;
static CGColor Red_;
static CGColor White_;
static CGColor Gray_;
static NSString *App_;
static NSString *Home_;
static BOOL Sounds_Keyboard_;
static BOOL Advanced_;
#if !ForSaurik
static BOOL Loaded_;
#endif
static BOOL Ignored_;
static UIFont *Font12_;
static UIFont *Font12Bold_;
static UIFont *Font14_;
static UIFont *Font18Bold_;
static UIFont *Font22Bold_;
static const char *Firmware_ = NULL;
static const char *Machine_ = NULL;
static const NSString *UniqueID_ = NULL;
unsigned Major_;
unsigned Minor_;
unsigned BugFix_;
CFLocaleRef Locale_;
CGColorSpaceRef space_;
#define FW_LEAST(major, minor, bugfix) \
(major < Major_ || major == Major_ && \
(minor < Minor_ || minor == Minor_ && \
bugfix <= BugFix_))
bool bootstrap_;
bool reload_;
static NSDictionary *SectionMap_;
static NSMutableDictionary *Metadata_;
static _transient NSMutableDictionary *Settings_;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -