Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//
// Copyright (c) 2012-2013 Cédric Luthi / @0xced. All rights reserved.
//
#if TARGET_IPHONE_SIMULATOR
static const char *fakeCarrier;
static const char *fakeTime;
static int fakeCellSignalStrength = -1;
#import <objc/runtime.h>
// Set itemIsEnabled[3] to 1 to show cell signal strength
/*
dataNetworkType:
0 - GPRS
1 - E (EDGE)
2 - 3G
3 - 4G
4 - LTE
5 - Wi-Fi
6 - Personal Hotspot
7 - 1x
8 - Blank
*/
typedef struct {
char itemIsEnabled[23];
char timeString[64]; // time string in the middle of the status bar
int gsmSignalStrengthRaw;
int gsmSignalStrengthBars; // 0-5, cell signal strength
char serviceString[100];
BOOL serviceCrossfadeString[100];
BOOL serviceImages[2][100];
BOOL operatorDirectory[1024];
unsigned int serviceContentType;
int wifiSignalStrengthRaw;
int wifiSignalStrengthBars; // 0-3, wifi signal strength
unsigned int dataNetworkType; // network badge next to the carrier string
// ...
} StatusBarData;
typedef struct {
char itemIsEnabled[24];
char timeString[64];
int gsmSignalStrengthRaw;
int gsmSignalStrengthBars;
char serviceString[100];
BOOL serviceCrossfadeString[100];
BOOL serviceImages[2][100];
BOOL operatorDirectory[1024];
unsigned int serviceContentType;
int wifiSignalStrengthRaw;
int wifiSignalStrengthBars;
unsigned int dataNetworkType;
// ...
} StatusBarData_6;
typedef struct {
char itemIsEnabled[25];
char timeString[64];
int gsmSignalStrengthRaw;
int gsmSignalStrengthBars;
char serviceString[100];
BOOL serviceCrossfadeString[100];
BOOL serviceImages[2][100];
BOOL operatorDirectory[1024];
unsigned int serviceContentType;
int wifiSignalStrengthRaw;
int wifiSignalStrengthBars;
unsigned int dataNetworkType;
// ...
} StatusBarData_7;
@interface XCDFakeCarrier : NSObject
@end
@implementation XCDFakeCarrier
+ (void) load
{
fakeCarrier = getenv("FAKE_CARRIER");
fakeTime = getenv("FAKE_TIME");
const char *cellSignalEnv = getenv("FAKE_CELL_SIGNAL_STRENGTH");
if (cellSignalEnv) {
fakeCellSignalStrength = atoi(cellSignalEnv);
}
if (!fakeCarrier && !fakeTime && !cellSignalEnv)
{
NSLog(@"Skipping swizzling, no environment variables set (FAKE_CARRIER, FAKE_TIME, FAKE_CELL_SIGNAL_STRENGTH)");
return;
}
BOOL __block success = NO;
Class UIStatusBarComposedData = objc_getClass("UIStatusBarComposedData");
SEL selector = NSSelectorFromString(@"rawData");
Method method = class_getInstanceMethod(UIStatusBarComposedData, selector);
NSDictionary *statusBarDataInfo = @{ @"^{?=[23c][64c]ii[100c]": @"fake_rawData",
@"^{?=[24c][64c]ii[100c]": @"fake_rawData_6",
@"^{?=[25c][64c]ii[100c]": @"fake_rawData_7",
// use B instead of c for 64-bit
@"^{?=[23B][64c]ii[100c]": @"fake_rawData",
@"^{?=[24B][64c]ii[100c]": @"fake_rawData_6",
@"^{?=[25B][64c]ii[100c]": @"fake_rawData_7" };
[statusBarDataInfo enumerateKeysAndObjectsUsingBlock:^(NSString *statusBarDataTypeEncoding, NSString *fakeSelectorString, BOOL *stop) {
if (method && [@(method_getTypeEncoding(method)) hasPrefix:statusBarDataTypeEncoding])
{
SEL fakeSelector = NSSelectorFromString(fakeSelectorString);
Method fakeMethod = class_getInstanceMethod(self, fakeSelector);
success = class_addMethod(UIStatusBarComposedData, fakeSelector, method_getImplementation(fakeMethod), method_getTypeEncoding(fakeMethod));
fakeMethod = class_getInstanceMethod(UIStatusBarComposedData, fakeSelector);
method_exchangeImplementations(method, fakeMethod);
}
}];
if (success)
NSLog(@"Using \"%s\" fake carrier", fakeCarrier);
else
NSLog(@"XCDFakeCarrier failed to initialize");
}
- (StatusBarData *) fake_rawData
{
StatusBarData *rawData = [self fake_rawData];
if (fakeCarrier) {
strlcpy(rawData->serviceString, fakeCarrier, sizeof(rawData->serviceString));
}
if (fakeTime) {
strlcpy(rawData->timeString, fakeTime, sizeof(rawData->timeString));
}
if (fakeCellSignalStrength > -1) {
rawData->itemIsEnabled[3] = 1;
rawData->gsmSignalStrengthBars = fakeCellSignalStrength;
}
return rawData;
}
- (StatusBarData_6 *) fake_rawData_6
{
StatusBarData_6 *rawData = [self fake_rawData_6];
if (fakeCarrier) {
strlcpy(rawData->serviceString, fakeCarrier, sizeof(rawData->serviceString));
}
if (fakeTime) {
strlcpy(rawData->timeString, fakeTime, sizeof(rawData->timeString));
}
if (fakeCellSignalStrength > -1) {
rawData->itemIsEnabled[3] = 1;
rawData->gsmSignalStrengthBars = fakeCellSignalStrength;
}
return rawData;
}
- (StatusBarData_7 *) fake_rawData_7
{
StatusBarData_7 *rawData = [self fake_rawData_7];
if (fakeCarrier) {
strlcpy(rawData->serviceString, fakeCarrier, sizeof(rawData->serviceString));
}
if (fakeTime) {
strlcpy(rawData->timeString, fakeTime, sizeof(rawData->timeString));
}
if (fakeCellSignalStrength > -1) {
rawData->itemIsEnabled[3] = 1;
rawData->gsmSignalStrengthBars = fakeCellSignalStrength;
}
return rawData;
}
@end
#endif
@ApoorvKhatreja

This comment has been minimized.

Copy link

ApoorvKhatreja commented Jun 1, 2014

Hey! Could you elaborate on what exactly this is meant for, and how exactly does it work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.