📜 ⬆️ ⬇️

Another way to get custom data in iOS

Hello!

I want to show how, without using private APIs (= without using private frameworks / classes / functions), you can collect a variety of data about device usage.

Here is a description of the information you can get:


')
Actually, the essence of the method:
typedef struct { BOOL itemIsEnabled[24]; char timeString[64]; int gsmSignalStrengthRaw; int gsmSignalStrengthBars; char serviceString[100]; char serviceCrossfadeString[100]; char serviceImages[2][100]; char operatorDirectory[1024]; unsigned serviceContentType; int wifiSignalStrengthRaw; int wifiSignalStrengthBars; unsigned dataNetworkType; int batteryCapacity; unsigned batteryState; char batteryDetailString[150]; int bluetoothBatteryCapacity; int thermalColor; unsigned thermalSunlightMode : 1; unsigned slowActivity : 1; unsigned syncActivity : 1; char activityDisplayId[256]; unsigned bluetoothConnected : 1; unsigned displayRawGSMSignal : 1; unsigned displayRawWifiSignal : 1; unsigned locationIconType : 1; } iOS6Data; // retrieve data char *app = (__bridge void *)([UIApplication sharedApplication]); ptrdiff_t providerOffset = 52; char *provider = *(char**)(app + providerOffset); ptrdiff_t iOS6DataOffset = 116; iOS6Data *data = (iOS6Data*)(provider + iOS6DataOffset); 


Minimum program demonstrating the capabilities of the approach
 enum { kTimeItem = 0, kLockItem, kAirplaneItem, kSignalStrengthItem, kServiceItem, kDataNetworkItem, kBatteryItem, kBatteryPercentItem, kNotChargingItem, kBluetoothBatteryItem, kBluetoothItem, kTTYItem, kAlarmItem, kPlusItem, kPlayItem, kLocationItem, kRotationLockItem, kDoubleHeightItem, kAirPlayItem, kVPNItem, kCallForwardItem, kActivityItem, kThermalColorItem }; typedef struct { BOOL itemIsEnabled[24]; char timeString[64]; int gsmSignalStrengthRaw; int gsmSignalStrengthBars; char serviceString[100]; char serviceCrossfadeString[100]; char serviceImages[2][100]; char operatorDirectory[1024]; unsigned serviceContentType; int wifiSignalStrengthRaw; int wifiSignalStrengthBars; unsigned dataNetworkType; int batteryCapacity; unsigned batteryState; char batteryDetailString[150]; int bluetoothBatteryCapacity; int thermalColor; unsigned thermalSunlightMode : 1; unsigned slowActivity : 1; unsigned syncActivity : 1; char activityDisplayId[256]; unsigned bluetoothConnected : 1; unsigned displayRawGSMSignal : 1; unsigned displayRawWifiSignal : 1; unsigned locationIconType : 1; } iOS6Data; void proof_of_concept() { // we need to check runtime before start NSString *systemVersion = [[UIDevice currentDevice] systemVersion] ; NSScanner *scanner = [NSScanner scannerWithString:systemVersion]; int runtime; [scanner scanInt:&runtime]; if (runtime != 6) { NSLog(@" ,     iOS 6"); UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"   " message:@"    iOS 6." delegate:nil cancelButtonTitle:@"" otherButtonTitles:nil]; [alertView show]; return; } // retrieve data char *app = (__bridge void *)([UIApplication sharedApplication]); ptrdiff_t providerOffset = 52; char *provider = *(char**)(app + providerOffset); ptrdiff_t iOS6DataOffset = 116; iOS6Data *data = (iOS6Data*)(provider + iOS6DataOffset); // usage example NSMutableString *example = [NSMutableString stringWithCapacity:1000]; [example appendFormat: @"  : %d \n", data->gsmSignalStrengthRaw ]; [example appendFormat: @" : %@\n", @(data->batteryDetailString)]; switch (data->dataNetworkType) { case 2: [example appendString: @"   : 2G\n"]; break; case 3: [example appendString: @"   : 3G\n"]; break; case 5: [example appendString: @"   : WiFi\n"]; default: break; } if (data->itemIsEnabled[kAlarmItem]) { [example appendString:@" "]; } if (data->itemIsEnabled[kCallForwardItem]) { [example appendString:@"  "]; } if (data->itemIsEnabled[kAirplaneItem]) { [example appendString:@" \" \""]; } NSLog(@"%@", example); UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Info" message:example delegate:nil cancelButtonTitle:@"" otherButtonTitles: nil]; [alertView show]; } 



Pros:

Minuses:


If you are interested in how it works, where do constants and descriptions of data structures come from, write in the comments, I will add the article.

Source: https://habr.com/ru/post/183650/


All Articles