diff options
author | Jay Freeman (saurik) <saurik@saurik.com> | 2011-03-03 12:21:33 -0800 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2011-03-07 02:41:35 -0800 |
commit | 947a8eefa4cc11fbccdb9b1495ec0f0f28663bd9 (patch) | |
tree | 5b6b5e4fa2d67bc472c2855bc0c4016d61301e52 | |
parent | ef777b72342d7c61fc50f6707fac34b460536452 (diff) |
Simplify IORegistry work.
-rw-r--r-- | MobileCydia.mm | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm index c0ade05..0548647 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -939,6 +939,34 @@ bool isSectionVisible(NSString *section) { return hidden == nil || ![hidden boolValue]; } +static id CYIOGetValue(const char *path, NSString *property) { + io_registry_entry_t entry(IORegistryEntryFromPath(kIOMasterPortDefault, path)); + if (entry == MACH_PORT_NULL) + return nil; + + CFTypeRef value(IORegistryEntryCreateCFProperty(entry, (CFStringRef) property, kCFAllocatorDefault, 0)); + IOObjectRelease(entry); + + if (value == NULL) + return nil; + return [(id) value autorelease]; +} + +static NSString *CYHex(NSData *data, bool reverse, bool capital) { + if (data == nil) + return nil; + + size_t length([data length]); + uint8_t bytes[length]; + [data getBytes:bytes]; + + char string[length * 2 + 1]; + for (size_t i(0); i != length; ++i) + sprintf(string + i * 2, capital ? "%.2X" : "%.2x", bytes[reverse ? length - i - 1 : i]); + + return [NSString stringWithUTF8String:string]; +} + @class Cydia; /* Delegate Prototypes {{{ */ @@ -10043,28 +10071,8 @@ int main(int argc, char *argv[]) { _pooled else Machine_ = machine; - if (CFMutableDictionaryRef dict = IOServiceMatching("IOPlatformExpertDevice")) { - if (io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, dict)) { - if (CFTypeRef serial = IORegistryEntryCreateCFProperty(service, CFSTR(kIOPlatformSerialNumberKey), kCFAllocatorDefault, 0)) { - SerialNumber_ = [NSString stringWithString:(NSString *)serial]; - CFRelease(serial); - } - - if (CFTypeRef ecid = IORegistryEntrySearchCFProperty(service, kIODeviceTreePlane, CFSTR("unique-chip-id"), kCFAllocatorDefault, kIORegistryIterateRecursively)) { - NSData *data((NSData *) ecid); - size_t length([data length]); - uint8_t bytes[length]; - [data getBytes:bytes]; - char string[length * 2 + 1]; - for (size_t i(0); i != length; ++i) - sprintf(string + i * 2, "%.2X", bytes[length - i - 1]); - ChipID_ = [NSString stringWithUTF8String:string]; - CFRelease(ecid); - } - - IOObjectRelease(service); - } - } + SerialNumber_ = CYIOGetValue("IOService:/", @"IOPlatformSerialNumber"); + ChipID_ = CYHex(CYIOGetValue("IODeviceTree:/chosen", @"unique-chip-id"), true, true); UniqueID_ = [[UIDevice currentDevice] uniqueIdentifier]; |