Public feed #602582

Unnamed

public text v1 · immutable
Raw Edit
·published 2007-07-04 04:37 UTC
rendered paste body
/*
 * Copyright (C) 2007 Anonymous
 * 
 * This software is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * 
 * See the GNU General Public License version 2 for more details.
 */

#include <stdio.h>
#include <string.h>
#include <CoreFoundation/CoreFoundation.h>
#include <MobileDevice/MobileDevice.h>

#import <Cocoa/Cocoa.h>

static NSString * arg1;
static NSString * arg2;

void device_notification_callback(struct am_device_notification_callback_info * info) {
	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    mach_error_t err;
    struct am_device *dev = info->dev;

    NSLog(@"Found iPhone Device: %d\n", info->msg);

	NSLog(@"Connecting...");
    if(AMDeviceConnect(dev) == 0) {
		NSLog(@"Checking Pairing...");
		err = AMDeviceIsPaired(dev);
		err = AMDeviceValidatePairing(dev); 

		NSLog(@"Starting device session...");
		if(AMDeviceStartSession(dev) == 0) {
			AMDeviceRemoveValue(dev, 0, @"ActivationStateAcknowledged");

			NSLog(@"ActivationState: %@", AMDeviceCopyValue(dev, NULL, @"ActivationState"));

			if([arg1 isEqualToString:@"--deactivate"] || [arg1 isEqualToString:@"--activate"]) {
				NSLog(@"Deactivating your iPhone...");
				AMDeviceDeactivate(dev);
				NSLog(@"New ActivationState: %@", AMDeviceCopyValue(dev, NULL, @"ActivationState"));
			}

			if([arg1 isEqualToString:@"--activate"]) {
				NSLog(@"Activating your iPhone...");

				NSDictionary * activationDict = [[NSDictionary alloc] initWithContentsOfFile:arg2];

				if(activationDict != nil) {
					err = AMDeviceActivate(dev, [activationDict valueForKey:@"ActivationRecord"]);

					NSLog(@"New ActivationState: %@", AMDeviceCopyValue(dev, NULL, @"ActivationState"));

					if(err == 0) {
						NSLog(@"Your iPhone was successfully activated.");
					} else {
						NSLog(@"Your iPhone could not be activated.");
					}
					
					[activationDict release];
				} else {
					NSLog(@"Could not read %@!", arg2);
				}
			}
		}

		AMDeviceStopSession(dev);
	}

	[pool release];

	exit(0);
}

int main(int argc, char *argv[]) {
	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

	BOOL doWork = NO;

	arg1 = argv[1] ? [NSString stringWithFormat:@"%s", argv[1]] : @"--help";
	arg2 = argv[2] ? [NSString stringWithFormat:@"%s", argv[2]] : @"";

	CFShow(@"iPhoneActivatorTool 1.0\n");
	
	if([arg1 isEqualToString:@"--deactivate"] || [arg1 isEqualToString:@"--state"]) doWork = YES;
	else if([arg1 isEqualToString:@"--activate"] && [[NSFileManager defaultManager] fileExistsAtPath:arg2]) doWork = YES;

	if(doWork) {
		mach_error_t err;
		struct am_device_notification *notif;

		err = AMDeviceNotificationSubscribe(device_notification_callback, 0, 0, 0, &notif);

		CFRunLoopRun();
	} else {
		CFShow(@"./tool [ --help || --deactivate || --activate <file.plist> ]\n\n");
		CFShow(@"options:");
		CFShow(@"\t--help\t\t\t\t\tShows this information");
		CFShow(@"\t--state\t\t\t\t\tPrints the current phone activation state");
		CFShow(@"\t--deactivate\t\t\t\tDeactivates the phone");
		CFShow(@"\t--activate <file.plist>\t\t\tActivates the phone using specified plist");
	}

	[pool release];

    return 0;
}