Exemplo n.º 1
0
int main(int argc, char *argv[]) {
    if (argc < 2 || argc > 4) {
        printf("usage: %s [-d] <app> [device_id]\n", argv[0]);
        exit(1);
    }

    
    if (strcmp(argv[1], "-d") == 0) {
        assert(argc == 3 || argc == 4);
        debug = true;
        app_path = argv[2];
        if (argc == 4) {
            device_id = argv[3];
        }
        printf("------ Install phase ------\n");
    } else {
        assert(argc == 2 || argc == 3);
        app_path = argv[1];
        if (argc == 3) {
            device_id = argv[2];
        }
    }

    assert(access(app_path, F_OK) == 0);

    AMDSetLogLevel(5); // otherwise syslog gets flooded with crap
    printf("[....] Waiting for iOS device to be connected\n");

    struct am_device_notification *notify;
    AMDeviceNotificationSubscribe(&device_callback, 0, 0, NULL, &notify); 
    CFRunLoopRun();
}
Exemplo n.º 2
0
int main(int argc, char *argv[]) {
	if (argc > 1) {
		struct stat st;
		if (stat(dirname(argv[1]), &st)==-1 && errno==ENOENT) {
			fprintf(stderr, "Directory for writing does not exist.\n");
			exit(1);
		}
		
		realpath(argv[1], outputfile);
		gen_path = 1;
	}
	else {
		is_cwd = 1;
		getcwd(outputfile, PATH_MAX);
	}
	
	am_device_notification *notification;
	assert(AMDeviceNotificationSubscribe(device_notification_callback, 0, 0, NULL, &notification) == MDERR_OK);
	puts("Waiting for device.");
	
	signal(SIGINT, &sigint_handler);
	
	CFRunLoopRun();
	
	puts("Ending.");
	return 0;
}
Exemplo n.º 3
0
int main (int argc, char * const argv[])
{
    if ((argc == 2) && (strcmp(argv[1], "--help") == 0)) {
        fprintf(stderr, "Usage: %s [options]\nOptions:\n -d\t\t\tInclude connect/disconnect messages in standard out\n -u <udid>\t\tShow only logs from a specific device\n -p <process name>\tShow only logs from a specific process\n\nControl-C to disconnect\nMail bug reports and suggestions to <*****@*****.**>\n", argv[0]);
        return 1;
    }
    int c;
    bool use_separators = false;
    bool force_color = false;
    memset(requiredProcessName, '\0', 256);
    while ((c = getopt(argc, argv, "dcsu:p:")) != -1)
        switch (c)
    {
        case 'd':
            debug = 1;
            break;
        case 'c':
            force_color = true;
            break;
        case 's':
            use_separators = true;
            break;
        case 'u':
            if (requiredDeviceId)
                CFRelease(requiredDeviceId);
            requiredDeviceId = CFStringCreateWithCString(kCFAllocatorDefault, optarg, kCFStringEncodingASCII);
            break;
        case 'p':
            strcpy(requiredProcessName, optarg);
            break;
        case '?':
            if (optopt == 'u')
                fprintf(stderr, "Option -%c requires an argument.\n", optopt);
            else if (isprint(optopt))
                fprintf(stderr, "Unknown option `-%c'.\n", optopt);
            else
                fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
            return 1;
        default:
            abort();
    }
    if (force_color || isatty(1)) {
        printMessage = &write_colored;
        printSeparator = use_separators ? &color_separator : &no_separator;
    } else {
        printMessage = &write_fully;
        printSeparator = use_separators ? &plain_separator : &no_separator;
    }
    liveConnections = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, NULL);
    am_device_notification *notification;
    AMDeviceNotificationSubscribe(DeviceNotificationCallback, 0, 0, NULL, &notification);
    CFRunLoopRun();
    return 0;
}
int main(int argc, char** argv) {

    CFRunLoopTimerRef timer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent()+1, 0,0,0, timeout, NULL);
    CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes);

    am_device_notification* notification;
    check("Subscribing to device notification",
            AMDeviceNotificationSubscribe(&onDevice, 0,0,NULL, &notification));
    CFRunLoopRun();
    return 1;
}
Exemplo n.º 5
0
/** Initializes an iPhone, registering it's callbacks to recieve device notifications.
  * @param iphone Pointer to an iPhone struct with the dnc member is initialized to a DeviceNotification callback.
  */  
void iPhone_init(iPhone *iphone)
{
    void* notification = malloc(sizeof(void*));
    int ret = AMDeviceNotificationSubscribe(iphone->dnc, 0, 0, 0, notification);
    if(ret != 0)
        iPhone_SetLastError("AMDeviceNotificationSubscribe failed with error %d", ret);
    
    /*
    ret = AMRestoreRegisterForDeviceNotifications(iphone->drn1, iphone->drn2, iphone->drn3, iphone->drn4, 0, NULL);
    if(ret != 0)
        iPhone_SetLastError("AMRestoreRegisterForDeviceNotifications failed with error %d", ret);
    */ /* Can't really do anything in recovery mode anyway. */
    free(notification);
}
void FIOSDeviceHelper::Initialize()
{
    static bool bIsInitialized = false;
    
    if (!bIsInitialized)
    {
        void *subscribe;
        int32 rc = AMDeviceNotificationSubscribe((void*)FIOSDeviceHelper::DeviceCallback, 0, 0, 0, &subscribe);
        if (rc < 0)
        {
            //@todo right out to the log that we can't subscribe
        }
        bIsInitialized = true;
    }
}
Exemplo n.º 7
0
int main(int argc, char **argv)
{
	if (argc != 4) {
		fprintf(stderr, "Usage: %s DeveloperDiskImage.dmg DeveloperDiskImage.dmg.signature Root.dmg\n", argv[0]);
		return 1;
	}

	timesl = 209999;

	real_dmg = argv[1];
	real_dmg_signature = argv[2];
	ddi_dmg = argv[3];

	AMDAddLogFileDescriptor(2);
	am_device_notification *notif;
	assert(!AMDeviceNotificationSubscribe(cb, 0, 0, NULL, &notif));
	CFRunLoopRun();
	return 0;
}
Exemplo n.º 8
0
Arquivo: itmd.c Projeto: dzhshf/ssh-rd
MUX_API void itmd_run(pfn_javaMobileDeviceCallbackProc_t callback, void* context)
{
	void* unkOut = NULL;
#ifdef WIN32
	win32_dispatch_thread_init(); // otherwise we lose the first event if the device is already connected
#endif

    s_restoreContext = (PITMD_CONTEXT) malloc(sizeof(ITMD_CONTEXT));
    s_restoreContext->restoreOptions = NULL;
    s_restoreContext->javaCallback = callback;
    s_restoreContext->javaContext = context;
    AMRestoreRegisterForDeviceNotifications(dfuConnect, recoveryConnect, dfuDisconnect, recoveryDisconnect, 0, s_restoreContext);
    AMDeviceNotificationSubscribe(mux_notification_callback, 0, 0, s_restoreContext, &unkOut);

#ifdef WIN32
	win32_dispatch_thread_run();
#else
	CFRunLoopRun();
#endif
}
Exemplo n.º 9
0
// Attaches the API: loads the DLL
// Returns:
//		IPOD_ERR_OK				when successful
//		IPOD_ERR_DLL_NOT_FOUND	when the iTunesMobileDevice.dll could not be loaded
//
t_iPodError CiPoTApi::AttachDLL()
{
	HKEY hSetting = NULL;
	DWORD length = 0;
	CString path;
	int pos;
	t_MachError ret;
	t_AMDeviceNotification *notif; 

	if (m_iPodState == IPOD_STATE_NO_DLL) {
		if (m_pCoreFoundationPath == NULL) {
			if (::RegCreateKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Apple Inc.\\Apple Application Support"), &hSetting) != ERROR_SUCCESS)
			{
				::RegCloseKey(hSetting);
				return IPOD_ERR_DLL_NOT_FOUND;
			}
			if (::RegQueryValueEx(hSetting, _T("InstallDir"), NULL, NULL, NULL, &length) != ERROR_SUCCESS)
			{
				::RegCloseKey(hSetting);
				return IPOD_ERR_DLL_NOT_FOUND;
			}
			m_pCoreFoundationPath = new char[length+19+1]; // \CoreFoundation.dll = 19
			::RegQueryValueEx(hSetting, _T("InstallDir"), NULL, NULL, (LPBYTE)m_pCoreFoundationPath, &length);
			::RegCloseKey(hSetting);


			// Adds the folder to the current system path:	
			path.GetEnvironmentVariable("PATH");
			path = (path + ";") + m_pCoreFoundationPath;
			SetEnvironmentVariable("PATH", path);

			if (m_pCoreFoundationPath[lstrlen(m_pCoreFoundationPath)-1] != '\\')
				strcat(m_pCoreFoundationPath, "\\");
			strcat(m_pCoreFoundationPath, "CoreFoundation.dll");
		}
		
		if (m_piTunesMobileDevicePath == NULL) {
			// Adds iTunesMobileDevice.dll folder to the path, from the registry:
			if (::RegCreateKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Apple Inc.\\Apple Mobile Device Support\\Shared"), &hSetting) != ERROR_SUCCESS)
			{
				::RegCloseKey(hSetting);
				return IPOD_ERR_DLL_NOT_FOUND;
			}
			if (::RegQueryValueEx(hSetting, _T("iTunesMobileDeviceDLL"), NULL, NULL, NULL, &length) != ERROR_SUCCESS)
			{
				::RegCloseKey(hSetting);
				return IPOD_ERR_DLL_NOT_FOUND;
			}
			m_piTunesMobileDevicePath = new char[length+1];
			::RegQueryValueEx(hSetting, _T("iTunesMobileDeviceDLL"), NULL, NULL, (LPBYTE)m_piTunesMobileDevicePath, &length);
			::RegCloseKey(hSetting);

			// Adds the folder to the current system path:	
			path.GetEnvironmentVariable("PATH");
			path = (path + ";") + m_piTunesMobileDevicePath;
			pos = path.ReverseFind('\\');
			if (pos >= 0)
				path.Truncate(pos);
			SetEnvironmentVariable("PATH", path);
		}

		// Loads the iTunesMobileDevice DLL routines
		m_iTunesDll = LoadLibrary(m_piTunesMobileDevicePath);
		if (m_iTunesDll) {
			AMDeviceNotificationSubscribe = (tf_AMDeviceNotificationSubscribe)GetProcAddress(m_iTunesDll, "AMDeviceNotificationSubscribe");
			AMDeviceConnect = (tf_AMDeviceConnect)GetProcAddress(m_iTunesDll, "AMDeviceConnect");
			AMDeviceDisconnect = (tf_AMDeviceDisconnect)GetProcAddress(m_iTunesDll, "AMDeviceDisconnect");
			AMDeviceIsPaired = (tf_AMDeviceIsPaired)GetProcAddress(m_iTunesDll, "AMDeviceIsPaired");
			AMDeviceValidatePairing = (tf_AMDeviceValidatePairing)GetProcAddress(m_iTunesDll, "AMDeviceValidatePairing");
			AMDeviceStartSession = (tf_AMDeviceStartSession)GetProcAddress(m_iTunesDll, "AMDeviceStartSession");
			AMDeviceStartService = (tf_AMDeviceStartService)GetProcAddress(m_iTunesDll, "AMDeviceStartService");
			AMDeviceStopSession = (tf_AMDeviceStopSession)GetProcAddress(m_iTunesDll, "AMDeviceStopSession");
			AFCConnectionOpen = (tf_AFCConnectionOpen)GetProcAddress(m_iTunesDll, "AFCConnectionOpen");
			AFCDeviceInfoOpen = (tf_AFCDeviceInfoOpen)GetProcAddress(m_iTunesDll, "AFCDeviceInfoOpen");
			AFCDirectoryOpen = (tf_AFCDirectoryOpen)GetProcAddress(m_iTunesDll, "AFCDirectoryOpen");
			AFCDirectoryRead = (tf_AFCDirectoryRead)GetProcAddress(m_iTunesDll, "AFCDirectoryRead");
			AFCDirectoryClose = (tf_AFCDirectoryClose)GetProcAddress(m_iTunesDll, "AFCDirectoryClose");
			AFCFileInfoOpen = (tf_AFCFileInfoOpen)GetProcAddress(m_iTunesDll, "AFCFileInfoOpen");
			AFCKeyValueRead = (tf_AFCKeyValueRead)GetProcAddress(m_iTunesDll, "AFCKeyValueRead");
			AFCKeyValueClose = (tf_AFCKeyValueClose)GetProcAddress(m_iTunesDll, "AFCKeyValueClose");
			AFCFileRefOpen = (tf_AFCFileRefOpen)GetProcAddress(m_iTunesDll, "AFCFileRefOpen");
			AFCFileRefClose = (tf_AFCFileRefClose)GetProcAddress(m_iTunesDll, "AFCFileRefClose");
			AFCFileRefRead = (tf_AFCFileRefRead)GetProcAddress(m_iTunesDll, "AFCFileRefRead");
			AFCFileRefWrite = (tf_AFCFileRefWrite)GetProcAddress(m_iTunesDll, "AFCFileRefWrite");
			AFCRemovePath = (tf_AFCRemovePath)GetProcAddress(m_iTunesDll, "AFCRemovePath");
			AFCDirectoryCreate = (tf_AFCDirectoryCreate)GetProcAddress(m_iTunesDll, "AFCDirectoryCreate");
			AFCRenamePath = (tf_AFCRenamePath)GetProcAddress(m_iTunesDll, "AFCRenamePath");
		} else
			return IPOD_ERR_DLL_NOT_FOUND;

		// Loads the CoreFoundation DLL routines
		m_CoreFoundationDll = LoadLibrary(m_pCoreFoundationPath);
		if (m_CoreFoundationDll) {
					 _CFStringMakeConstantString = (tf_CFStringMakeConstantString) GetProcAddress(m_CoreFoundationDll, "__CFStringMakeConstantString");
					 CFWriteStreamCreateWithFile = (tf_CFWriteStreamCreateWithFile)GetProcAddress(m_CoreFoundationDll, "CFWriteStreamCreateWithFile");
           CFReadStreamCreateWithFile = (tf_CFReadStreamCreateWithFile)GetProcAddress(m_CoreFoundationDll, "CFReadStreamCreateWithFile");
           CFStringCreateWithCString = (tf_CFStringCreateWithCString)GetProcAddress(m_CoreFoundationDll, "CFStringCreateWithCString");
           CFURLCreateWithFileSystemPath = (tf_CFURLCreateWithFileSystemPath)GetProcAddress(m_CoreFoundationDll, "CFURLCreateWithFileSystemPath");
           CFReadStreamOpen = (tf_CFReadStreamOpen)GetProcAddress(m_CoreFoundationDll, "CFReadStreamOpen");
           CFWriteStreamOpen = (tf_CFWriteStreamOpen)GetProcAddress(m_CoreFoundationDll, "CFWriteStreamOpen");
           CFPropertyListCreateFromStream = (tf_CFPropertyListCreateFromStream)GetProcAddress(m_CoreFoundationDll, "CFPropertyListCreateFromStream");
           CFReadStreamClose = (tf_CFReadStreamClose)GetProcAddress(m_CoreFoundationDll, "CFReadStreamClose");
           CFPropertyListIsValid = (tf_CFPropertyListIsValid)GetProcAddress(m_CoreFoundationDll, "CFPropertyListIsValid");
           CFPropertyListWriteToStream = (tf_CFPropertyListWriteToStream)GetProcAddress(m_CoreFoundationDll, "CFPropertyListWriteToStream");
           CFWriteStreamClose = (tf_CFWriteStreamClose)GetProcAddress(m_CoreFoundationDll, "CFWriteStreamClose");
           CFRelease = (tf_CFRelease)GetProcAddress(m_CoreFoundationDll, "CFRelease");
           CFURLCreateDataAndPropertiesFromResource = (tf_CFURLCreateDataAndPropertiesFromResource)GetProcAddress(m_CoreFoundationDll, "CFURLCreateDataAndPropertiesFromResource");
           CFPropertyListCreateFromXMLData = (tf_CFPropertyListCreateFromXMLData)GetProcAddress(m_CoreFoundationDll, "CFPropertyListCreateFromXMLData");
           CFPropertyListCreateXMLData = (tf_CFPropertyListCreateXMLData)GetProcAddress(m_CoreFoundationDll, "CFPropertyListCreateXMLData");
           CFURLWriteDataAndPropertiesToResource = (tf_CFURLWriteDataAndPropertiesToResource)GetProcAddress(m_CoreFoundationDll, "CFURLWriteDataAndPropertiesToResource");
            bCanTranslatePLIST = true;
		} else
			return IPOD_ERR_DLL_NOT_FOUND;
		m_iPodState = IPOD_STATE_UNCONNECTED;
	}
	// Registers the static notification call-back method
	ret = AMDeviceNotificationSubscribe(&CiPoTApi::NotificationHandler, 0, 0, 0, &notif);
	return (ret == MDERR_OK) ? IPOD_ERR_OK : IPOD_IPOD_NOT_FOUND;
}
Exemplo n.º 10
0
int main(int argc, char *argv[]) {
    static struct option longopts[] = {
        { "debug", no_argument, NULL, 'd' },
        { "id", required_argument, NULL, 'i' },
        { "bundle", required_argument, NULL, 'b' },
        { "args", required_argument, NULL, 'a' },
        { "verbose", no_argument, NULL, 'v' },
        { "timeout", required_argument, NULL, 't' },
        { "unbuffered", no_argument, NULL, 'u' },
        { "gdbargs", required_argument, NULL, 'g' },
        { "nostart", no_argument, NULL, 'n' },
        { NULL, 0, NULL, 0 },
    };
    char ch;

    while ((ch = getopt_long(argc, argv, "dvuni:b:a:t:g:", longopts, NULL)) != -1)
    {
        switch (ch) {
        case 'd':
            debug = 1;
            break;
        case 'i':
            device_id = optarg;
            break;
        case 'b':
            app_path = optarg;
            break;
        case 'a':
            args = optarg;
            break;
        case 'v':
            verbose = 1;
            break;
        case 't':
            timeout = atoi(optarg);
            break;
        case 'u':
            unbuffered = 1;
            break;
        case 'g':
            gdb_args = optarg;
            break;
        case 'n':
            nostart = 1;
            break;
        default:
            usage(argv[0]);
            return 1;
        }
    }

    if (!app_path) {
        usage(argv[0]);
        exit(0);
    }

    if (unbuffered) {
        setbuf(stdout, NULL);
        setbuf(stderr, NULL);
    }

    printf("------ Install phase ------\n");

    assert(access(app_path, F_OK) == 0);

    AMDSetLogLevel(5); // otherwise syslog gets flooded with crap
    if (timeout > 0)
    {
        CFRunLoopTimerRef timer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent() + timeout, 0, 0, 0, timeout_callback, NULL);
        CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes);
        printf("[....] Waiting up to %d seconds for iOS device to be connected\n", timeout);
    }
    else
    {
        printf("[....] Waiting for iOS device to be connected\n");
    }

    struct am_device_notification *notify;
    AMDeviceNotificationSubscribe(&device_callback, 0, 0, NULL, &notify);
    CFRunLoopRun();
}
Exemplo n.º 11
0
int main(int argc, char *argv[]) {
    static struct option global_longopts[]= {
        { "quiet", no_argument, NULL, 'q' },
        { "verbose", no_argument, NULL, 'v' },
        { "timeout", required_argument, NULL, 't' },

        { "id", required_argument, NULL, 'i' },
        { "bundle", required_argument, NULL, 'b' },
        { "file", required_argument, NULL, 'f' },
        { "target", required_argument, NULL, 1 },
        { "bundle-id", required_argument, NULL, 0 },

        { "debug", no_argument, NULL, 'd' },
        { "args", required_argument, NULL, 'a' },

        { NULL, 0, NULL, 0 },
    };

    char ch;
    while ((ch = getopt_long(argc, argv, "qvi:b:f:da:t:", global_longopts, NULL)) != -1)
    {
        switch (ch) {
            case 0:
                bundle_id = optarg;
                break;
            case 'q':
                quiet = 1;
                break;
            case 'v':
                verbose = 1;
                break;
            case 'd':
                debug = 1;
                break;
            case 't':
                timeout = atoi(optarg);
                break;
            case 'b':
                app_path = optarg;
                break;
            case 'f':
                doc_file_path = optarg;
                break;
            case 1:
                target_filename = optarg;
                break;
            case 'a':
                args = optarg;
                break;
            case 'i':
                device_id = optarg;
                break;

            default:
                usage(argv[0]);
                return 1;
        }
    }

    if (optind >= argc) {
        usage(argv [0]);
        exit(EXIT_SUCCESS);
    }

    operation = OP_NONE;
    if (strcmp (argv [optind], "install") == 0) {
        operation = OP_INSTALL;
    } else if (strcmp (argv [optind], "uninstall") == 0) {
        operation = OP_UNINSTALL;
    } else if (strcmp (argv [optind], "list-devices") == 0) {
        operation = OP_LIST_DEVICES;
    } else if (strcmp (argv [optind], "upload") == 0) {
        operation = OP_UPLOAD_FILE;
    } else if (strcmp (argv [optind], "list-files") == 0) {
        operation = OP_LIST_FILES;
    } else {
        usage (argv [0]);
        exit (0);
    }

    if (!args_are_valid()) {
        usage(argv[0]);
        exit(0);
    }

    if (operation == OP_INSTALL)
        assert(access(app_path, F_OK) == 0);

    AMDSetLogLevel(1+4+2+8+16+32+64+128); // otherwise syslog gets flooded with crap
    if (timeout > 0)
    {
        CFRunLoopTimerRef timer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent() + timeout, 0, 0, 0, timeout_callback, NULL);
        CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes);
        PRINT("[....] Waiting up to %d seconds for iOS device to be connected\n", timeout);
    }
    else
    {
        PRINT("[....] Waiting for iOS device to be connected\n");
    }

    struct am_device_notification *notify;
    AMDeviceNotificationSubscribe(&device_callback, 0, 0, NULL, &notify);

    CFRunLoopRun();
}
Exemplo n.º 12
0
int main(int argc, char* argv[])
{
	struct stat st;

	init_libxpwn(&argc, argv);
	libxpwn_log(logCB);
	libxpwn_loglevel(2);

	printf("---------------------------PLEASE READ THIS---------------------------\n");
	printf("Please make certain that all iTunes related processes are not running\n");
	printf("at this time (use Task Manager, etc. to end them).\n");
	printf("---------------------------PLEASE READ THIS---------------------------\n\n\n");

	if(argc < 3) {
		printf("usage: %s <custom.ipsw> <n82ap|m68ap|n45ap> [loglevel]\n", argv[0]);
		printf("n82ap = 3G iPhone, m68ap = First-generation iPhone, n45ap = iPod touch\n");
		return 0;
	}

	if(argc >= 4) {
		int logLevel;
		sscanf(argv[3], "%d", &logLevel);
		libxpwn_loglevel(logLevel);
	}

	if(stat("restore.img3", &st) < 0) {
		fprintf(stderr, "missing restore.img3\n");
		return 1;
	}

	Stage = 0;
	Status = Disconnected;

	char ibssName[100];
	char wtfName[100];
	sprintf(ibssName, "Firmware/dfu/iBSS.%s.RELEASE.dfu", argv[2]);
	sprintf(wtfName, "Firmware/dfu/WTF.%s.RELEASE.dfu", argv[2]);

	data = NULL;
	loadZipFile(argv[1], &data, "Firmware/dfu/WTF.s5l8900xall.RELEASE.dfu");
	loadZipFile(argv[1], &data, ibssName);
	loadZipFile(argv[1], &data, wtfName);
	loadZipFile(argv[1], &data, "Restore.plist");

	AbstractFile* xallFile = getFileFromOutputState(&data, "Firmware/dfu/WTF.s5l8900xall.RELEASE.dfu");
	AbstractFile* wtfFile = getFileFromOutputState(&data, wtfName);
	AbstractFile* ibssFile = getFileFromOutputState(&data, ibssName);
	AbstractFile* restoreFile = getFileFromOutputState(&data, "Restore.plist");

	GetTempPath(MAX_PATH, tmpFilePath);

	strcat(tmpFilePath, "/restore");
	if(stat(tmpFilePath, &st) < 0) {
		mkdir(tmpFilePath, 0755);
	}

	strcpy(tmpFirmwarePath, tmpFilePath);
	strcat(tmpFirmwarePath, "/Firmware");
	if(stat(tmpFirmwarePath, &st) < 0) {
		mkdir(tmpFirmwarePath, 0755);
	}

	strcpy(tmpDFUPath, tmpFirmwarePath);
	strcat(tmpDFUPath, "/dfu");
	if(stat(tmpDFUPath, &st) < 0) {
		mkdir(tmpDFUPath, 0755);
	}

	strcpy(tmpXALLPath, tmpFilePath);
	strcat(tmpXALLPath, "/");
	strcat(tmpXALLPath, "Firmware/dfu/WTF.s5l8900xall.RELEASE.dfu");

	strcpy(tmpWTFPath, tmpFilePath);
	strcat(tmpWTFPath, "/");
	strcat(tmpWTFPath, wtfName);

	strcpy(tmpIBSSPath, tmpFilePath);
	strcat(tmpIBSSPath, "/");
	strcat(tmpIBSSPath, ibssName);

	strcpy(tmpRestorePath, tmpFilePath);
	strcat(tmpRestorePath, "/");
	strcat(tmpRestorePath, "Restore.plist");

	FILE* file;
	void* buffer;
	size_t length;

	length = xallFile->getLength(xallFile);
	buffer = malloc(length);
	xallFile->read(xallFile, buffer, length);
       	file = fopen(tmpXALLPath, "wb");
	fwrite(buffer, 1, length, file);
	fclose(file);
	free(buffer);
	xallFile->close(xallFile);

	length = wtfFile->getLength(wtfFile);
	buffer = malloc(length);
	wtfFile->read(wtfFile, buffer, length);
       	file = fopen(tmpWTFPath, "wb");
	fwrite(buffer, 1, length, file);
	fclose(file);
	free(buffer);
	wtfFile->close(wtfFile);

	length = ibssFile->getLength(ibssFile);
	buffer = malloc(length);
	ibssFile->read(ibssFile, buffer, length);
       	file = fopen(tmpIBSSPath, "wb");
	fwrite(buffer, 1, length, file);
	fclose(file);
	free(buffer);
	ibssFile->close(ibssFile);

	extractedIPSWPath = argv[1];
	length = restoreFile->getLength(restoreFile);
	buffer = malloc(length);
	restoreFile->read(restoreFile, buffer, length);
       	file = fopen(tmpRestorePath, "wb");
	fwrite(buffer, 1, length, file);
	fclose(file);
	free(buffer);
	restoreFile->close(restoreFile);

	extractedIPSWPath = tmpFilePath;
	bootImagePath = "restore.img3";

	fprintf(stdout, "\nGetting iPhone/iPod status...\n");
	fflush(stdout);

	if(LoadWindowsDLL() < 0) {
		printf("Failed to load iTunes Mobile Device driver!\n");
		cleanup_and_exit();
	}
	
	mach_error_t ret;
	struct am_device_notification *notif; 
	
	ret = AMDeviceNotificationSubscribe(notification, 0, 0, 0, &notif);
	if(ret < 0) {
		printf("Failed to subscribe for device notifications!\n");
		cleanup_and_exit();
	}
	
	ret = AMRestoreRegisterForDeviceNotifications(
						dfu_connect_callback,
						recovery_connect_callback,
						dfu_disconnect_callback,
						recovery_disconnect_callback,
						0,
						NULL);
						
	if(ret < 0) {
		printf("Failed to subscribe for device restore notifications!\n");
		cleanup_and_exit();
	}


	sleep(2);

	char responseBuffer[10];
	int countdown;

	if(Status == Disconnected) {
connectDevice:
		fprintf(stdout, "Is your iPhone/iPod connected to your computer via USB?\n");
		fprintf(stdout, "Please answer (y/n): ");
		fflush(stdout);
		fgets(responseBuffer, 10, stdin);
		if(responseBuffer[0] == 'y' || responseBuffer[0] == 'Y') {
			goto isPoweringOn;
		} else if(responseBuffer[0] == 'n' || responseBuffer[0] == 'N') {
			fprintf(stdout, "Please connect your iPhone/iPod to your computer\n");
			fprintf(stdout, "Press enter when you have connected your iPhone/iPod... ");
			fflush(stdout);
			fgets(responseBuffer, 10, stdin);
			sleep(2);
			if(Status != Disconnected) {
				goto turnOffDevice;
			} else {
isPoweringOn:
				fprintf(stdout, "Is your iPhone currently powering on?\n");
				fprintf(stdout, "Please answer (y/n): ");
				fflush(stdout);
				fgets(responseBuffer, 10, stdin);
				if(responseBuffer[0] == 'y' || responseBuffer[0] == 'Y') {
					fprintf(stdout, "Waiting for iPhone/iPod to power on...\n");
					fflush(stdout);
					while(Status == Disconnected) {
						sleep(1);
					}
					goto turnOffDevice;
				} else if(responseBuffer[0] == 'n' || responseBuffer[0] == 'N') {
					goto beginDFU;
				} else {
					goto isPoweringOn;
				}
			}
		} else {
			goto connectDevice;
		}
	} else {
turnOffDevice:
		fprintf(stdout, "Please turn off your iPhone/iPod without disconnecting the cable connecting it to the computer\n");
		fprintf(stdout, "Press enter when you have turned off your iPhone/iPod... ");
		fflush(stdout);
		fgets(responseBuffer, 10, stdin);

		fprintf(stdout, "Waiting for iPhone/iPod to power off...\n");
		fflush(stdout);
		while(Status != Disconnected) {
			sleep(1);
		}
	}

beginDFU:
	fprintf(stdout, "\n!!! Your device should now be off. If it is not, please make sure it is before proceeding !!!\n\n");

	fprintf(stdout, "Timing is crucial for the following tasks. I will ask you to do the following (DON'T START YET):\n");
	fprintf(stdout, "\t1. Press and hold down the power button for five seconds\n");
	fprintf(stdout, "\t2. Without letting go of the power button, press and hold down the power AND home buttons for ten seconds\n");
	fprintf(stdout, "\t3. Without letting go of the home button, release the power button\n");
	fprintf(stdout, "\t4. Wait 30 seconds while holding down the home button\n");
	fprintf(stdout, "\nTry to get the timing as correct as possible, but don't fret if you miss it by a few seconds. It might still work, and if it doesn't, you can always try again. If you fail, you can always just turn the phone completely off by holding power and home for ten seconds, then pushing power to turn it back on.\n");
	fprintf(stdout, "\nAre you ready to begin?\n");
	fprintf(stdout, "Please answer (y/n): ");
	fflush(stdout);
	fgets(responseBuffer, 10, stdin);
	if(responseBuffer[0] != 'y' && responseBuffer[0] != 'Y')
		goto beginDFU;

	for(countdown = 5; countdown > 0; countdown--) {
		fprintf(stdout, "Beginning process in %d seconds...\n", countdown);
		fflush(stdout);
		sleep(1);
	}

	fprintf(stdout, "\nPress and hold down the POWER button (you should now be just holding the power button)... ");
	fflush(stdout);

	for(countdown = 5; countdown > 0; countdown--) {
		fprintf(stdout, "%d... ", countdown);
		fflush(stdout);
		sleep(1);
	}


	fprintf(stdout, "\n\nPress and hold down the HOME button, DO NOT LET GO OF THE POWER BUTTON (you should now be just holding both the power and home buttons)... ");
	fflush(stdout);

	for(countdown = 10; countdown > 0; countdown--) {
		fprintf(stdout, "%d... ", countdown);
		fflush(stdout);
		sleep(1);
	}

	fprintf(stdout, "\n\nRelease the POWER button, DO NOT LET GO OF THE HOME BUTTON (you should now be just holding the home button)... ");
	fflush(stdout);

	Stage = 2;

	for(countdown = 30; countdown > 0; countdown--) {
		if(Status != Disconnected)
			goto waitForFinish;

		fprintf(stdout, "%d... ", countdown);
		fflush(stdout);
		sleep(1);
	}

	fprintf(stdout, "\n\nEither you did not follow instructions correctly or your USB hardware is malfunctioning. Please use another USB port to connect your iPhone/iPod (NOT through a USB hub) and consider restarting your computer before trying again.\n");
	fflush(stdout);
	cleanup_and_exit();

waitForFinish:
	while(1) {
		msleep(1);
	}
}
Exemplo n.º 13
0
int main (int argc, char * const argv[])
{


// todo: remove:
//     double timeout = 0;

//     if ((argc == 2) && (strcmp(argv[1], "--help") == 0)) {
//         fprintf(stderr,
//                 "Usage: %s [options]\nOptions:\n"
//                 " -d           Include connect/disconnect messages in standard out,\n"
//                 "              and exit reason in standard err.\n"
//                 " -u <udid>    Show only logs from a specific device.\n"
//                 " -t <timeout> Exit after the specified timeout, in seconds (can be decimal),\n"
//                 "              if there have been no more logs in that timeframe.\n"
//                 " -x           (Must use with -t.) Exit unconditionally after the timeout,\n" 
//                 "              even if more logs are coming in.\n"
//                 "\nControl-C to disconnect\n"
//                 "Mail bug reports and suggestions to <*****@*****.**>\n",
//                 argv[0]);
//         // TODO: merge up:
//         fprintf(stderr, "Usage: %s [options]\nOptions:\n -d\t\t\tInclude connect/disconnect messages in standard out\n -u <udid>\t\tShow only logs from a specific device\n -p <process name>\tShow only logs from a specific process\n\nControl-C to disconnect\nMail bug reports and suggestions to <*****@*****.**>\n", argv[0]);
//         return 1;
//     }
//     int c;
//     bool use_separators = false;
 
//     // old petrich:
//     // while ((c = getopt(argc, argv, "dsu:")) != -1)
//     // pontillo:
//     // while ((c = getopt(argc, argv, "dxt:u:")) != -1)
//     //HEAD:
//     bool force_color = false;
//     memset(requiredProcessName, '\0', 256);
//     while ((c = getopt(argc, argv, "dcsu:p:")) != -1)
// //end HEAD.
//         switch (c)
//     {
//         case 'd':
//             debug = 1;
//             break;
//         case 'c':
//             force_color = true;
//             break;
//         case 's':
//             use_separators = true;
//             break;
//         case 'u':
//             if (requiredDeviceId)
//                 CFRelease(requiredDeviceId);
//             requiredDeviceId = CFStringCreateWithCString(kCFAllocatorDefault, optarg, kCFStringEncodingASCII);
//             break;
//         case 't':
//             timeout = atof(optarg);
//             break;
//         case 'x':
//             exitAfterTimeout = 1;
//         case 'p':
//             strcpy(requiredProcessName, optarg);
//             break;
//         case '?':
//             if (optopt == 'u' || optopt == 't')
//                 fprintf(stderr, "Option -%c requires an argument.\n", optopt);
//             else if (isprint(optopt))
//                 fprintf(stderr, "Unknown option `-%c'.\n", optopt);
//             else
//                 fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
//             return 1;
//         default:
//             abort();
//     }
// TODO: merge up ^


    int c;
    
    static struct option long_options[] =
    {
        {"udid", required_argument, NULL, 'u'},
        {"simulator", required_argument, NULL, 's'},
        {"process", required_argument, NULL, 'p'},
        {"regex", required_argument, NULL, 'r'},
        {"help", no_argument, NULL, 'h'},
        {"debug", no_argument, (int*)&debug, 1},
        {"use-separators", no_argument, (int*)&use_separators, 1},
        {"force-color", no_argument, (int*)&force_color, 1},
        {NULL, 0, NULL, 0}
    };
    
    int option_index = 0;
    
    while((c = getopt_long(argc, argv, "u:s:p:r:", long_options, &option_index)) != -1){
        switch (c){
            case 0:
                break;
            case 'u':
                if(requiredDeviceId)
                        CFRelease(requiredDeviceId);
                requiredDeviceId = CFStringCreateWithCString(kCFAllocatorDefault, optarg, kCFStringEncodingASCII);
                break;
            case 's':
            {
                int pathLength = strlen(optarg) + strlen(getpwuid(getuid())->pw_dir) + strlen("/Library/Logs/iOS Simulator//system.log");
                simulatorLogPath = malloc(pathLength + 1);/* Don't forget null terminator! */
                sprintf(simulatorLogPath, "%s/Library/Logs/iOS Simulator/%s/system.log", getpwuid(getuid())->pw_dir, optarg);
                
                if(access(simulatorLogPath, F_OK) == -1){
                    fprintf(stderr, "Error: Log for iOS Simulator version %s not found.\n", optarg);
                    return 1;
                }
                break;
            }
            case 'p':
                requiredProcessName = malloc(strlen(optarg) + 1);
                requiredProcessName[strlen(optarg)] = '\0';

                strcpy(requiredProcessName, optarg);
                break;
            case 'r':
            {
                requiredRegexPattern = malloc(strlen(optarg) + 1);
                requiredRegexPattern[strlen(optarg)] = '\0';

                strcpy(requiredRegexPattern, optarg);

                int status = regcomp(&requiredRegex, requiredRegexPattern, REG_EXTENDED);
                if (status != 0) {
                    char errorMessage[2048];
                    regerror(status, &requiredRegex, errorMessage, 2048);
                    fprintf(stderr, "Error: Regex error compiling '%s': %s\n", requiredRegexPattern, errorMessage);
                    return 1;
                }
                break;
            }
            case 'h':
            case '?':
                goto usage;
                break;
            default:
                abort();
        }
    }
    
    if(requiredDeviceId && simulatorLogPath){
        fprintf(stderr, "Error: --simulator and --udid cannot be used simultaneously.\n");
        return 1;
    }
    
    if(simulatorLogPath && debug){
        printf("Warning: ignoring --debug flag due to --simulator.\n");
    }
    
    if (force_color || isatty(1)) {
        printMessage = &write_colored;
        printSeparator = use_separators ? &color_separator : &no_separator;
    } else {
        printMessage = &write_fully;
        printSeparator = use_separators ? &plain_separator : &no_separator;
    }
    
    if(simulatorLogPath){
        log_simulator();
        return 1;
    }else{
        liveConnections = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, NULL);
        am_device_notification *notification;
        AMDeviceNotificationSubscribe(DeviceNotificationCallback, 0, 0, NULL, &notification);
    }
    CFRunLoopRun();
    return 0;
    
usage:
    fprintf(stderr,
            "Usage: %s [options]\nOptions:\n"
            " --udid <udid>          Show only logs from a specific device\n"
            " --simulator <version>  Show logs from iOS Simulator\n"
            " --debug                Include connect/disconnect messages in standard out\n"
            " --use-separators       Skip a line between each line.\n"
            " --process              Filter by process name.\n"
            " --regex                Filter by regular expression.\n"
            " --force-color          Force colored text.\n"
            "Control-C to disconnect\n"
            "Mail bug reports and suggestions to <*****@*****.**>\n", argv[0]);
    return 1;
}
Exemplo n.º 14
0
void register_device_notification()
{
  AMDeviceNotificationSubscribe(&on_device_notification, 0, 0, 0, &command.notification);
  CFRunLoopRun();
}