#include <WebKit/DOMHTMLIFrameElement.h>
#include <algorithm>
+#include <fstream>
#include <iomanip>
#include <set>
#include <sstream>
#include <string>
-#include <ext/stdio_filebuf.h>
+#include "fdstream.hpp"
#undef ABS
+#include "apt.h"
#include <apt-pkg/acquire.h>
#include <apt-pkg/acquire-item.h>
#include <apt-pkg/algorithms.h>
};
// }}}
+@implementation NSDictionary (Cydia)
+- (id) invokeUndefinedMethodFromWebScript:(NSString *)name withArguments:(NSArray *)arguments {
+ if (false);
+ else if ([name isEqualToString:@"get"])
+ return [self objectForKey:[arguments objectAtIndex:0]];
+ else if ([name isEqualToString:@"keys"])
+ return [self allKeys];
+ return nil;
+} @end
+
static NSString *Colon_;
NSString *Elision_;
static NSString *Error_;
CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast<const uint8_t *>(data), size, kCFStringEncodingISOLatin1, NO, kCFAllocatorNull);
}
+static _finline CFStringRef CYStringCreate(const std::string &data) {
+ return CYStringCreate(data.data(), data.size());
+}
+
static _finline CFStringRef CYStringCreate(const char *data) {
return CYStringCreate(data, strlen(data));
}
- (NSString *) installed;
- (BOOL) uninstalled;
-- (BOOL) valid;
- (BOOL) upgradableAndEssential:(BOOL)essential;
- (BOOL) essential;
- (BOOL) broken;
_end
_profile(Package$parse$Tagline)
- const char *start, *end;
- if (parser->ShortDesc(start, end)) {
- const char *stop(reinterpret_cast<const char *>(memchr(start, '\n', end - start)));
- if (stop == NULL)
- stop = end;
- while (stop != start && stop[-1] == '\r')
- --stop;
- parsed->tagline_.set(pool_, start, stop - start);
- }
+ parsed->tagline_.set(pool_, parser->ShortDesc());
_end
_profile(Package$parse$Retain)
version_ = version;
- pkgCache::PkgIterator iterator(version.ParentPkg());
+ pkgCache::PkgIterator iterator(version_.ParentPkg());
iterator_ = iterator;
_profile(Package$initWithVersion$Version)
- if (!version_.end())
- file_ = version_.FileList();
- else {
- pkgCache &cache([database_ cache]);
- file_ = pkgCache::VerFileIterator(cache, cache.VerFileP);
- }
+ file_ = version_.FileList();
_end
_profile(Package$initWithVersion$Cache)
- name_.set(NULL, iterator.Display());
+ name_.set(NULL, version_.Display());
latest_.set(NULL, StripVersion_(version_.VerStr()));
} while (false); _end
_profile(Package$initWithVersion$Tags)
+#ifdef __arm64__
+ pkgCache::TagIterator tag(version_.TagList());
+#else
pkgCache::TagIterator tag(iterator.TagList());
+#endif
if (!tag.end()) {
tags_ = [NSMutableArray arrayWithCapacity:8];
return iterator_;
}
+- (NSArray *) downgrades {
+ NSMutableArray *versions([NSMutableArray arrayWithCapacity:4]);
+
+ for (auto version(iterator_.VersionList()); !version.end(); ++version) {
+ if (version == version_)
+ continue;
+ Package *package([[[Package allocWithZone:NULL] initWithVersion:version withZone:NULL inPool:NULL database:database_] autorelease]);
+ if ([package source] == nil)
+ continue;
+ [versions addObject:package];
+ }
+
+ return versions;
+}
+
- (NSString *) section {
if (section$_ == nil) {
if (section_ == NULL)
}
- (NSString *) longSection {
- return LocalizeSection([self section]);
+ if (NSString *section = [self section])
+ return LocalizeSection(section);
+ else
+ return nil;
}
- (NSString *) shortSection {
@synchronized (database_) {
pkgRecords::Parser &parser([database_ records]->Lookup(file_));
-
- const char *start, *end;
- if (!parser.ShortDesc(start, end))
+ std::string value(parser.ShortDesc());
+ if (value.empty())
return nil;
-
- if (end - start > 200)
- end = start + 200;
-
- /*
- if (const char *stop = reinterpret_cast<const char *>(memchr(start, '\n', end - start)))
- end = stop;
-
- while (end != start && end[-1] == '\r')
- --end;
- */
-
- return [(id) CYStringCreate(start, end - start) autorelease];
+ if (value.size() > 200)
+ value.resize(200);
+ return [(id) CYStringCreate(value) autorelease];
} }
- (unichar) index {
return installed_.empty();
}
-- (BOOL) valid {
- return !version_.end();
-}
-
- (BOOL) upgradableAndEssential:(BOOL)essential {
_profile(Package$upgradableAndEssential)
pkgCache::VerIterator current(iterator_.CurrentVer());
if (current.end())
return essential && essential_;
else
- return !version_.end() && version_ != current;
+ return version_ != current;
_end
}
- (void) clear {
@synchronized (database_) {
+ if ([database_ era] != era_ || file_.end())
+ return;
+
pkgProblemResolver *resolver = [database_ resolver];
resolver->Clear(iterator_);
- (void) install {
@synchronized (database_) {
+ if ([database_ era] != era_ || file_.end())
+ return;
+
pkgProblemResolver *resolver = [database_ resolver];
resolver->Clear(iterator_);
resolver->Protect(iterator_);
pkgCacheFile &cache([database_ cache]);
+ cache->SetCandidateVersion(version_);
cache->SetReInstall(iterator_, false);
cache->MarkInstall(iterator_, false);
- (void) remove {
@synchronized (database_) {
+ if ([database_ era] != era_ || file_.end())
+ return;
+
pkgProblemResolver *resolver = [database_ resolver];
resolver->Clear(iterator_);
resolver->Remove(iterator_);
}
- (void) _readCydia:(NSNumber *)fd {
- __gnu_cxx::stdio_filebuf<char> ib([fd intValue], std::ios::in);
- std::istream is(&ib);
+ boost::fdistream is([fd intValue]);
std::string line;
static RegEx finish_r("finish:([^:]*)");
}
- (void) _readStatus:(NSNumber *)fd {
- __gnu_cxx::stdio_filebuf<char> ib([fd intValue], std::ios::in);
- std::istream is(&ib);
+ boost::fdistream is([fd intValue]);
std::string line;
static RegEx conffile_r("status: [^ ]* : conffile-prompt : (.*?) *");
}
- (void) _readOutput:(NSNumber *)fd {
- __gnu_cxx::stdio_filebuf<char> ib([fd intValue], std::ios::in);
- std::istream is(&ib);
+ boost::fdistream is([fd intValue]);
std::string line;
while (std::getline(is, line)) {
@synchronized (self) {
if (static_cast<pkgDepCache *>(cache_) == NULL)
return nil;
- pkgCache::PkgIterator iterator(cache_->FindPkg([name UTF8String]));
+ pkgCache::PkgIterator iterator(cache_->FindPkg([name UTF8String]
+#ifdef __arm64__
+ , "any"
+#endif
+ ));
return iterator.end() ? nil : [Package packageWithIterator:iterator withZone:NULL inPool:NULL database:self];
} }
opened = cache_.Open(progress, false);
_end
if (!opened) {
- // XXX: what if there are errors, but Open() == true? this should be merged with popError:
+ // XXX: this block should probably be merged with popError: in some way
while (!_error->empty()) {
std::string error;
bool warning(!_error->PopMessage(error));
}
return;
- }
+ } else if ([self popErrorWithTitle:title forOperation:true])
+ return;
_trace();
unlink("/tmp/cydia.chk");
NSString *nextended(Cache("extended_states"));
struct stat info;
- if (stat([nextended UTF8String], &info) != -1 && (info.st_mode & S_IFMT) == S_IFREG) {
- system([[NSString stringWithFormat:@"/usr/libexec/cydia/cydo /bin/mv -f %@ %@", ShellEscape(nextended), ShellEscape(oextended)] UTF8String]);
- system([[NSString stringWithFormat:@"/usr/libexec/cydia/cydo /bin/chown 0:0 %@", ShellEscape(oextended)] UTF8String]);
- }
+ if (stat([nextended UTF8String], &info) != -1 && (info.st_mode & S_IFMT) == S_IFREG)
+ system([[NSString stringWithFormat:@"/usr/libexec/cydia/cydo /bin/cp --remove-destination %@ %@", ShellEscape(nextended), ShellEscape(oextended)] UTF8String]);
unlink([nextended UTF8String]);
symlink([oextended UTF8String], [nextended UTF8String]);
+ (NSArray *) _attributeKeys {
return [NSArray arrayWithObjects:
+ @"bittage",
@"bbsnum",
@"build",
+ @"cells",
@"coreFoundationVersionNumber",
@"device",
@"ecid",
return Cydia_;
}
+- (unsigned) bittage {
+#if 0
+#elif defined(__arm64__)
+ return 64;
+#elif defined(__arm__)
+ return 32;
+#else
+ return 0;
+#endif
+}
+
- (NSString *) build {
return System_;
}
return (id) Idiom_ ?: [NSNull null];
}
+- (NSArray *) cells {
+ auto *$_CTServerConnectionCreate(reinterpret_cast<id (*)(void *, void *, void *)>(dlsym(RTLD_DEFAULT, "_CTServerConnectionCreate")));
+ if ($_CTServerConnectionCreate == NULL)
+ return nil;
+
+ struct CTResult { int flag; int error; };
+ auto *$_CTServerConnectionCellMonitorCopyCellInfo(reinterpret_cast<CTResult (*)(CFTypeRef, void *, CFArrayRef *)>(dlsym(RTLD_DEFAULT, "_CTServerConnectionCellMonitorCopyCellInfo")));
+ if ($_CTServerConnectionCellMonitorCopyCellInfo == NULL)
+ return nil;
+
+ _H<const void> connection($_CTServerConnectionCreate(NULL, NULL, NULL), true);
+ if (connection == nil)
+ return nil;
+
+ int count(0);
+ CFArrayRef cells(NULL);
+ auto result($_CTServerConnectionCellMonitorCopyCellInfo(connection, &count, &cells));
+ if (result.flag != 0)
+ return nil;
+
+ return [(NSArray *) cells autorelease];
+}
+
- (NSString *) mcc {
if (CFStringRef (*$CTSIMSupportCopyMobileSubscriberCountryCode)(CFAllocatorRef) = reinterpret_cast<CFStringRef (*)(CFAllocatorRef)>(dlsym(RTLD_DEFAULT, "CTSIMSupportCopyMobileSubscriberCountryCode")))
return [(NSString *) (*$CTSIMSupportCopyMobileSubscriberCountryCode)(kCFAllocatorDefault) autorelease];
}
- (NSArray *) getDisplayIdentifiers {
- NSSet *set([SBSCopyDisplayIdentifiers() autorelease]);
- if (set == nil || ![set isKindOfClass:[NSSet class]])
- return [NSArray array];
- return [set allObjects];
+ return SBSCopyApplicationDisplayIdentifiers(false, false);
}
- (NSString *) getLocalizedNameForDisplayIdentifier:(NSString *)identifier {
NSString *directory = [stack lastObject];
[stack addObject:[file stringByAppendingString:@"/"]];
[files_ replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%*s%@",
- ([stack count] - 2) * 3, "",
+ int(([stack count] - 2) * 3), "",
[file substringFromIndex:[directory length]]
]];
}
_H<NSString> name_;
bool commercial_;
std::vector<std::pair<_H<NSString>, _H<NSString>>> buttons_;
+ _H<UIActionSheet> sheet_;
_H<UIBarButtonItem> button_;
+ _H<NSArray> versions_;
}
- (id) initWithDatabase:(Database *)database forPackage:(NSString *)name withReferrer:(NSString *)referrer;
return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@", (id) name_]];
}
+- (void) _clickButtonWithPackage:(Package *)package {
+ [delegate_ installPackage:package];
+}
+
- (void) _clickButtonWithName:(NSString *)name {
if ([name isEqualToString:@"CLEAR"])
- [delegate_ clearPackage:package_];
- else if ([name isEqualToString:@"INSTALL"])
- [delegate_ installPackage:package_];
- else if ([name isEqualToString:@"REINSTALL"])
- [delegate_ installPackage:package_];
+ return [delegate_ clearPackage:package_];
else if ([name isEqualToString:@"REMOVE"])
- [delegate_ removePackage:package_];
- else if ([name isEqualToString:@"UPGRADE"])
- [delegate_ installPackage:package_];
+ return [delegate_ removePackage:package_];
+ else if ([name isEqualToString:@"DOWNGRADE"]) {
+ sheet_ = [[[UIActionSheet alloc]
+ initWithTitle:nil
+ delegate:self
+ cancelButtonTitle:nil
+ destructiveButtonTitle:nil
+ otherButtonTitles:nil
+ ] autorelease];
+
+ for (Package *version in (id) versions_)
+ [sheet_ addButtonWithTitle:[version latest]];
+ [sheet_ setContext:@"version"];
+
+ [delegate_ showActionSheet:sheet_ fromItem:[[self navigationItem] rightBarButtonItem]];
+ return;
+ }
+
+ else if ([name isEqualToString:@"INSTALL"]);
+ else if ([name isEqualToString:@"REINSTALL"]);
+ else if ([name isEqualToString:@"UPGRADE"]);
else _assert(false);
+
+ [delegate_ installPackage:package_];
}
- (void) actionSheet:(UIActionSheet *)sheet clickedButtonAtIndex:(NSInteger)button {
NSString *context([sheet context]);
+ if (sheet_ == sheet)
+ sheet_ = nil;
if ([context isEqualToString:@"modify"]) {
if (button != [sheet cancelButtonIndex]) {
[self _clickButtonWithName:buttons_[button].first];
}
+ [sheet dismissWithClickedButtonIndex:button animated:YES];
+ } else if ([context isEqualToString:@"version"]) {
+ if (button != [sheet cancelButtonIndex]) {
+ Package *version([versions_ objectAtIndex:button]);
+ if (IsWildcat_)
+ [self performSelector:@selector(_clickButtonWithPackage:) withObject:version afterDelay:0];
+ else
+ [self _clickButtonWithPackage:version];
+ }
+
[sheet dismissWithClickedButtonIndex:button animated:YES];
}
}
for (const auto &button : buttons_)
[buttons addObject:button.second];
- UIActionSheet *sheet = [[[UIActionSheet alloc]
+ sheet_ = [[[UIActionSheet alloc]
initWithTitle:nil
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil
] autorelease];
- for (NSString *button in buttons) [sheet addButtonWithTitle:button];
- if (!IsWildcat_) {
- [sheet addButtonWithTitle:UCLocalize("CANCEL")];
- [sheet setCancelButtonIndex:[sheet numberOfButtons] - 1];
- }
- [sheet setContext:@"modify"];
+ for (NSString *button in buttons)
+ [sheet_ addButtonWithTitle:button];
+ [sheet_ setContext:@"modify"];
- [delegate_ showActionSheet:sheet fromItem:[[self navigationItem] rightBarButtonItem]];
+ [delegate_ showActionSheet:sheet_ fromItem:[[self navigationItem] rightBarButtonItem]];
}
}
- (void) reloadData {
[super reloadData];
+ [sheet_ dismissWithClickedButtonIndex:[sheet_ cancelButtonIndex] animated:YES];
+ sheet_ = nil;
+
package_ = [database_ packageWithName:name_];
+ versions_ = [package_ downgrades];
buttons_.clear();
buttons_.push_back(std::make_pair(@"REINSTALL", UCLocalize("REINSTALL")));
if (![package_ uninstalled])
buttons_.push_back(std::make_pair(@"REMOVE", UCLocalize("REMOVE")));
+ if ([versions_ count] != 0)
+ buttons_.push_back(std::make_pair(@"DOWNGRADE", UCLocalize("DOWNGRADE")));
}
NSString *title;
_profile(PackageTable$reloadData$Filter)
for (Package *package in packages)
- if ([package valid] && filter(package))
+ if (filter(package))
[filtered addObject:package];
_end
[section addToCount];
_profile(SectionsView$reloadData$Filter)
- if (![package valid] || ![package visible])
+ if (![package visible])
continue;
_end
[window_ makeKey:self];
[window_ setHidden:NO];
+ if (access("/.cydia_no_stash", F_OK) == 0);
+ else {
+
if (false) stash: {
[self addStashController];
// XXX: this would be much cleaner as a yieldToSelector:
Stash_("/usr/share");
//Stash_("/var/lib");
+ }
+
database_ = [Database sharedInstance];
[database_ setDelegate:self];
}
- (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item {
+ if (!IsWildcat_) {
+ [sheet addButtonWithTitle:UCLocalize("CANCEL")];
+ [sheet setCancelButtonIndex:[sheet numberOfButtons] - 1];
+ }
+
if (item != nil && IsWildcat_) {
[sheet showFromBarButtonItem:item animated:YES];
} else {
return [(NSMutableDictionary *) copy autorelease];
}
+int main_store(int, char *argv[]);
+
int main(int argc, char *argv[]) {
+#ifdef __arm64__
+ const char *argv0(argv[0]);
+ if (const char *slash = strrchr(argv0, '/'))
+ argv0 = slash + 1;
+ if (false);
+ else if (!strcmp(argv0, "store"))
+ return main_store(argc, argv);
+#endif
+
int fd(open("/tmp/cydia.log", O_WRONLY | O_APPEND | O_CREAT, 0644));
dup2(fd, 2);
close(fd);
Locale_ = CFLocaleCopyCurrent();
Languages_ = [NSLocale preferredLanguages];
- //CFStringRef locale(CFLocaleGetIdentifier(Locale_));
- //NSLog(@"%@", [Languages_ description]);
+ std::string languages;
+ const char *translation(NULL);
- const char *lang;
+ // XXX: this isn't really a language, but this is compatible with older Cydia builds
if (Locale_ != NULL)
- lang = [(NSString *) CFLocaleGetIdentifier(Locale_) UTF8String];
- else if (Languages_ != nil && [Languages_ count] != 0)
- lang = [[Languages_ objectAtIndex:0] UTF8String];
- else
- // XXX: consider just setting to C and then falling through?
- lang = NULL;
-
- if (lang != NULL) {
- RegEx pattern("([a-z][a-z])(?:-[A-Za-z]*)?(_[A-Z][A-Z])?");
- lang = !pattern(lang) ? NULL : [pattern->*@"%1$@%2$@" UTF8String];
- }
+ if (const char *language = [(NSString *) CFLocaleGetIdentifier(Locale_) UTF8String]) {
+ RegEx pattern("([a-z][a-z])(?:-[A-Za-z]*)?(_[A-Z][A-Z])?");
+ if (pattern(language)) {
+ translation = strdup([pattern->*@"%1$@%2$@" UTF8String]);
+ languages += translation;
+ languages += ",";
+ }
+ }
- NSLog(@"Setting Language: %s", lang);
+ if (Languages_ != nil)
+ for (NSString *language : Languages_) {
+ languages += [language UTF8String];
+ languages += ",";
+ }
- if (lang != NULL) {
- setenv("LANG", lang, true);
- std::setlocale(LC_ALL, lang);
- }
+ languages += "en";
+ NSLog(@"Setting Language: [%s] %s", translation, languages.c_str());
/* }}} */
/* Index Collation {{{ */
if (Class $UILocalizedIndexedCollation = objc_getClass("UILocalizedIndexedCollation")) { @try {
Advanced_ = YES;
Cache_ = [[NSString stringWithFormat:@"%@/Library/Caches/com.saurik.Cydia", @"/var/mobile"] retain];
+ mkdir([Cache_ UTF8String], 0755);
/*Method alloc = class_getClassMethod([NSObject class], @selector(alloc));
alloc_ = alloc->method_imp;
_assert(pkgInitConfig(*_config));
_assert(pkgInitSystem(*_config, _system));
- if (lang != NULL)
- _config->Set("APT::Acquire::Translation", lang);
+ _config->Set("Acquire::AllowInsecureRepositories", true);
+ _config->Set("Acquire::Check-Valid-Until", false);
+ _config->Set("Dir::Bin::Methods::store", "/Applications/Cydia.app/store");
+
+ _config->Set("pkgCacheGen::ForceEssential", "");
+
+ if (translation != NULL)
+ _config->Set("APT::Acquire::Translation", translation);
+ _config->Set("Acquire::Languages", languages);
// XXX: this timeout might be important :(
//_config->Set("Acquire::http::Timeout", 15);
_config->Set("Acquire::http::MaxParallel", usermem >= 384 * 1024 * 1024 ? 16 : 3);
- mkdir([Cache_ UTF8String], 0755);
mkdir([Cache("archives") UTF8String], 0755);
mkdir([Cache("archives/partial") UTF8String], 0755);
_config->Set("Dir::Cache", [Cache_ UTF8String]);
std::string logs("/var/mobile/Library/Logs/Cydia");
mkdir(logs.c_str(), 0755);
- _config->Set("Dir::Log::Terminal", logs + "/apt.log");
+ _config->Set("Dir::Log", logs);
_config->Set("Dir::Bin::dpkg", "/usr/libexec/cydia/cydo");
/* }}} */