diff options
author | Jay Freeman (saurik) <saurik@saurik.com> | 2011-02-19 06:40:05 -0800 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2011-02-19 06:40:05 -0800 |
commit | 5bc1277a7e4b3002f82031b4095fad5e901b806d (patch) | |
tree | 37d595da44e0d045fa9756db90f9a5f0986471ae | |
parent | 56296da00b08734c4491c75adef73afe358b9d4e (diff) |
Expose sysctl read access to JavaScript.
-rw-r--r-- | MobileCydia.mm | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm index 1e96e7b..3180efb 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -3913,6 +3913,10 @@ static NSString *Warning_; return @"format"; else if (selector == @selector(getAllSources)) return @"getAllSourcs"; + else if (selector == @selector(getKernelNumber:)) + return @"getKernelNumber"; + else if (selector == @selector(getKernelString:)) + return @"getKernelString"; else if (selector == @selector(getInstalledPackages)) return @"getInstalledPackages"; else if (selector == @selector(getPackageById:)) @@ -3951,6 +3955,40 @@ static NSString *Warning_; return [feature isEqualToString:@"window.open"]; } +- (NSNumber *) getKernelNumber:(NSString *)name { + const char *string([name UTF8String]); + + size_t size; + if (sysctlbyname(string, NULL, &size, NULL, 0) == -1) + return (id) [NSNull null]; + + if (size != sizeof(int)) + return (id) [NSNull null]; + + int value; + if (sysctlbyname(string, &value, &size, NULL, 0) == -1) + return (id) [NSNull null]; + + return [NSNumber numberWithInt:value]; +} + +- (NSString *) getKernelString:(NSString *)name { + const char *string([name UTF8String]); + + size_t size; + if (sysctlbyname(string, NULL, &size, NULL, 0) == -1) + return (id) [NSNull null]; + + char value[size + 1]; + if (sysctlbyname(string, value, &size, NULL, 0) == -1) + return (id) [NSNull null]; + + // XXX: just in case you request something ludicrous + value[size] = '\0'; + + return [NSString stringWithCString:value]; +} + - (void) addTrivialSource:(NSString *)href { [delegate_ performSelectorOnMainThread:@selector(addTrivialSource:) withObject:href waitUntilDone:NO]; } |