<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.theiphonewiki.com/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Gojohnnyboi</id>
	<title>The iPhone Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.theiphonewiki.com/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Gojohnnyboi"/>
	<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/wiki/Special:Contributions/Gojohnnyboi"/>
	<updated>2026-05-06T17:02:29Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.14</generator>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=Preventing_Baseband_Update&amp;diff=17287</id>
		<title>Preventing Baseband Update</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=Preventing_Baseband_Update&amp;diff=17287"/>
		<updated>2011-04-06T19:32:44Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: /* Edit options.plist */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Edit options.plist===&lt;br /&gt;
# Unpack custom IPSW&lt;br /&gt;
# Decrypt Restore Ramdisk using [[xpwntool]] and mount it&lt;br /&gt;
# Navigate to /usr/local/share/restore &lt;br /&gt;
# Edit options.plist on the restore ramdisk &lt;br /&gt;
(Ignore any other settings specified in the plist, don't edit them)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	&amp;lt;key&amp;gt;UpdateBaseband&amp;lt;/key&amp;gt;&lt;br /&gt;
        &amp;lt;false/&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ol start=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reencrypt the restore ramdisk&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Repack the IPSW&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Prepare device for custom firmware using [[redsn0w]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Restore IPSW to [[iTunes]] in pwned [[DFU Mode]] using the appropriate method(Look at Restoring The Modified IPSW Section)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You must load a patched [[iBSS]]/[[iBEC]] for this to work. Using an original IPSW will not work, because redsn0w's pwned DFU Mode doesn't patch sigchecks in [[iBSS]] (which is loaded from the IPSW).&lt;br /&gt;
&lt;br /&gt;
===Idea===&lt;br /&gt;
One could hook the function HookAMRestorePerformRecoveryModeRestore in MobileDevice which iTunes uses, overriding the restore options CFDictionaryRef object. This would *THEORETICALLY* allow for not updating baseband without patches/jailbreak. A practical application for this is if someone absolutely needs to update to the latest firmware for work or other reasons, and can't as they must wait for PwnageTool to provide support.&lt;br /&gt;
&lt;br /&gt;
==Restoring The Modified IPSW==&lt;br /&gt;
Firmwares like 4.2.1 and above have baseband checks on the [[Restore Ramdisk]].If the modified IPSW is restored, iTunes will give a Error 1015 and iPhone will be in a recovery mode loop which cannot be exited by TinyUmbrella or the 'setenv auto-boot true' command&amp;lt;br /&amp;gt;&lt;br /&gt;
Fortunately, the [[Update Ramdisk]] does not contain that baseband check so if the Update Method is used which is mentioned below,iTunes will give error 1013 and it can be exited by TinyUmbrella and the irecovery command.&lt;br /&gt;
===Update Method===&lt;br /&gt;
*Windows Users, Open iTunes. hold the Shift button and click Update then select the modified IPSW&lt;br /&gt;
*Mac Users, Open iTunes, hold the Alt button and click Update then select the modified IPSW&lt;br /&gt;
===Restore Method===&lt;br /&gt;
*Windows Users, Open iTunes. hold the Shift button and click Restore then select the modified IPSW&lt;br /&gt;
*Mac Users, Open iTunes, hold the Alt button and click Restore then select the modified IPSW&lt;br /&gt;
&lt;br /&gt;
==[[TinyUmbrella]]/[[Cydia Server]] Method (iPhone 4)==&lt;br /&gt;
&lt;br /&gt;
The [[N90ap|iPhone 4]] requires a [[AT+XNONCE]] key signature from Apple in order to update the baseband. Pointing the hosts file to [[Cydia Server]] or running [[TinyUmbrella]] will allow this request for signature to be ignored, thus preventing a [[baseband]] update.&lt;br /&gt;
&lt;br /&gt;
*'''This only works if [[Cydia Server]]/[[TinyUmbrella]] accepts the firmware's SHSH.'''&lt;br /&gt;
*'''This method 'works' with [[iOS]] 4.2.1, but in the restore ramdisk there is a baseband version check. If it doesn't match, it will crash before the Apple logo with the loading bar (the 2nd, first-boot  one, not the restore one) appears. It will boot and crash again. The old 'Kick out of recovery mode' methods or &amp;quot;setenv auto-boot true&amp;quot; won't work, because it's not the problem that the auto-boot is false. So this method is actually not useful for [[iOS]] 4.2.1+.'''&lt;br /&gt;
*'''[[greenpois0n (jailbreak)|greenpois0n]] RC6 will fix this as part of the jailbreaking process. The latest version of TinyUmbrella also features a new Fix Recovery function.'''&lt;br /&gt;
# Edit the hosts file and add the line &amp;quot;74.208.10.249 gs.apple.com&amp;quot; without the quotes, or run [[TinyUmbrella]] after saving the firmware's SHSH. If [[Cydia Server]] hasn't got your [[SHSH]], but you have it locally, use TSS Server method in [[TinyUmbrella]].&lt;br /&gt;
# Use the &amp;quot;Restore&amp;quot; button in [[iTunes]] to update if your firmware version is below 4.2 else use the &amp;quot;Update&amp;quot; button in [[iTunes]] to update.&lt;br /&gt;
# You will get Error 1013 and it can be easily bypassed by using the Exit Recovery Mode button in [[TinyUmbrella]] or typing 'setenv auto-boot true' and 'saveenv' in [[iRecovery]]&lt;br /&gt;
&lt;br /&gt;
==[[User:Ih8sn0w|iH8Sn0w]]'s Method==&lt;br /&gt;
[[Sn0wbreeze]] has a &amp;quot;Baseband Preservation Mode&amp;quot; since version 2.2. User [[User:Ih8sn0w|IH8sn0w]] [http://twitter.com/iH8sn0w/status/19453808090288128 confirmed] that his method is not the same as the above mentioned methods.&lt;br /&gt;
&lt;br /&gt;
This method can also be used on the iPhone 3GS and the iPhone 4 to downgrade from the 4.3 betas back to 4.2.1, as long as the device can be restored (and activated) to iOS 4.1 or an earlier version.&lt;br /&gt;
&lt;br /&gt;
To get some more details about what [[sn0wbreeze]] with the option &amp;quot;Baseband Preservation Mode&amp;quot; does, here a short analysis - a comparison of the generated ipsw for iOS 4.3 (iPhone 4):&lt;br /&gt;
===root filesystem 038-0688-006.dmg===&lt;br /&gt;
I couldn't get vfdecrypt to run, so I cannot list the details. It is much smaller (360MB instead of 615MB), probably just without the baseband. (Details to be added.)&lt;br /&gt;
===restore ramdisk 038-0715-006.dmg===&lt;br /&gt;
====options.plist====&lt;br /&gt;
The file options.plist in the folder \ramdisk\usr\local\share\restore is changed. These are the changes:&lt;br /&gt;
*first entry added: CreateFilesystemPartitions = true&lt;br /&gt;
*changed value: SystemPartitionSize 1024 changed to 1050&lt;br /&gt;
*added last entry: UpdateBaseband = false&lt;br /&gt;
====asr====&lt;br /&gt;
In the folder \ramdisk\usr\sbin\ the file asr has been renamed to asr_orig and a patched file of size 180832 bytes added. The patches are:&lt;br /&gt;
&lt;br /&gt;
 0001321A: DF F8&lt;br /&gt;
 0001321A: FD E7&lt;br /&gt;
&lt;br /&gt;
 0002BFC6: ED B7 6C AA D3 AF A0 B4 90 08 6D 63 51 46 17 0B 8A 40 8D C4&lt;br /&gt;
 0002BFC6: 6E DB 54 D3 DB 60 A8 FB 74 47 28 EB 02 33 EA FA 20 B6 7E B5&lt;br /&gt;
&lt;br /&gt;
 0002C1BA: FA DE 0C 01&lt;br /&gt;
 0002C1BA: F6 B6 D0 8F&lt;br /&gt;
&lt;br /&gt;
====images====&lt;br /&gt;
Two files were changed from the Apple logo to the iH8sn0w logo. Both are called applelogo.png and they are located in \ramdisk\usr\share\progressui\images-1x\ and in \ramdisk\usr\share\progressui\images-2x\.&lt;br /&gt;
===patches in [[iBSS]]===&lt;br /&gt;
There are several patches in [[iBSS]] (first line is original, second line is the patched version):&lt;br /&gt;
 000000FC: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00&lt;br /&gt;
 000000FC: 03 A2 13 68 1B B1 50 68 C8 50 08 32 F9 E7 70 47 E0 A9 8C 00 30 E0 00 20 A4 AC 92 00 06 9B 0B B1 A8 AC 92 00 00 23 04 D0 D8 D3 71 00 EA D1 01 20 E4 A9 8C 00 00 20 2D E0 5C DB 27 00 01&lt;br /&gt;
 &lt;br /&gt;
 00012C26: FF F7 73 FE&lt;br /&gt;
 00012C26: 00 20 00 20&lt;br /&gt;
 &lt;br /&gt;
 00012C4C: FF F7 60 FE&lt;br /&gt;
 00012C4C: 00 20 00 20&lt;br /&gt;
 &lt;br /&gt;
 00012C70: FF F7 B6 FE&lt;br /&gt;
 00012C70: 00 20 00 20&lt;br /&gt;
 &lt;br /&gt;
 00012C98: FF F7 3A FE&lt;br /&gt;
 00012C98: 00 20 00 20&lt;br /&gt;
 &lt;br /&gt;
 00012CBA: FF F7 29 00&lt;br /&gt;
 00012CBA: 00 20 00 20&lt;br /&gt;
 &lt;br /&gt;
 00012CDE: FF F7 17 FE&lt;br /&gt;
 00012CDE: 00 20 00 20&lt;br /&gt;
 &lt;br /&gt;
 00012D02: FF F7 05 FE&lt;br /&gt;
 00012D02: 00 20 00 20&lt;br /&gt;
 &lt;br /&gt;
 00012D20: FF F7 F6 FD&lt;br /&gt;
 00012D20: 00 20 00 20&lt;br /&gt;
 &lt;br /&gt;
 00012D44: FF F7 E4 FD&lt;br /&gt;
 00012D44: 00 20 00 20&lt;br /&gt;
 &lt;br /&gt;
 0001345A: 08 F0 0D&lt;br /&gt;
 0001345A: EC F7 4F&lt;br /&gt;
 &lt;br /&gt;
 0001AD38: 4F F0 FF 30&lt;br /&gt;
 0001AD38: 00 20 00 20&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Baseband]]&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=17192</id>
		<title>MobileDevice Library</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=17192"/>
		<updated>2011-04-03T16:47:37Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: /* Private Function Address List */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MobileDevice Library is used by [[iTunes]] to transfer data between iPhone and computer over the USB connection.&lt;br /&gt;
&lt;br /&gt;
===PC Windows : iTunesMobileDevice.dll===&lt;br /&gt;
The DLL is written using Microsoft Visual C++ 8.0 DLL Method [2].&lt;br /&gt;
&lt;br /&gt;
* Location : Location is stored in '''iTunesMobileDeviceDLL''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Mobile Device Support\Shared''' key. Usually - C:\Program Files\Common Files\Apple\Mobile Device Support\bin\iTunesMobileDevice.dll.&lt;br /&gt;
&lt;br /&gt;
* Supporting CoreFoundation.dll (used for CFStringRef, CFPropertyListRef management) is located in the same dir (when using iTunes prior 9.0). &lt;br /&gt;
&lt;br /&gt;
* For iTunes 9.0 location of CoreFoundation.dll is stored in '''InstallDir''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Application Support''' key, usually C:\Program Files\Common Files\Apple\Apple Application Support\. CoreFoundation.dll from Mobile Device Support\bin should not be used.&lt;br /&gt;
&lt;br /&gt;
===Mac OSX : MobileDevice.framework===&lt;br /&gt;
&lt;br /&gt;
* Location : /System/Library/PrivateFrameworks/MobileDevice.framework&lt;br /&gt;
* Export command : &amp;quot;nm /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===MobileDevice Header (mobiledevice.h)===&lt;br /&gt;
&lt;br /&gt;
Reverse engineered C header for MobileDevice Library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* ----------------------------------------------------------------------------&lt;br /&gt;
 *   MobileDevice.h - interface to MobileDevice.framework &lt;br /&gt;
 * ------------------------------------------------------------------------- */&lt;br /&gt;
#pragma once&lt;br /&gt;
&lt;br /&gt;
#ifndef MOBILEDEVICE_H&lt;br /&gt;
#define MOBILEDEVICE_H&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
extern &amp;quot;C&amp;quot; {&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
#ifndef __GCC__&lt;br /&gt;
#pragma pack&lt;br /&gt;
#define __PACK&lt;br /&gt;
#else&lt;br /&gt;
#define __PACK __attribute__((__packed__))&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#if defined(WIN32)&lt;br /&gt;
#define __DLLIMPORT [DllImport(&amp;quot;iTunesMobileDevice.dll&amp;quot;)]&lt;br /&gt;
	using namespace System::Runtime::InteropServices;&lt;br /&gt;
#include &amp;lt;CoreFoundation.h&amp;gt;&lt;br /&gt;
	typedef unsigned int mach_error_t;&lt;br /&gt;
#elif defined(__APPLE__)&lt;br /&gt;
#define __DLLIMPORT&lt;br /&gt;
#include &amp;lt;CoreFoundation/CoreFoundation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;mach/error.h&amp;gt;&lt;br /&gt;
#endif	&lt;br /&gt;
	&lt;br /&gt;
	/* Error codes */&lt;br /&gt;
#define MDERR_APPLE_MOBILE  (err_system(0x3a))&lt;br /&gt;
#define MDERR_IPHONE        (err_sub(0))&lt;br /&gt;
	&lt;br /&gt;
	/* Apple Mobile (AM*) errors */&lt;br /&gt;
#define MDERR_OK                ERR_SUCCESS&lt;br /&gt;
#define MDERR_SYSCALL           (ERR_MOBILE_DEVICE | 0x01)&lt;br /&gt;
#define MDERR_OUT_OF_MEMORY     (ERR_MOBILE_DEVICE | 0x03)&lt;br /&gt;
#define MDERR_QUERY_FAILED      (ERR_MOBILE_DEVICE | 0x04) &lt;br /&gt;
#define MDERR_INVALID_ARGUMENT  (ERR_MOBILE_DEVICE | 0x0b)&lt;br /&gt;
#define MDERR_DICT_NOT_LOADED   (ERR_MOBILE_DEVICE | 0x25)&lt;br /&gt;
	&lt;br /&gt;
	/* Apple File Connection (AFC*) errors */&lt;br /&gt;
#define MDERR_AFC_OUT_OF_MEMORY 0x03&lt;br /&gt;
	&lt;br /&gt;
	/* USBMux errors */&lt;br /&gt;
#define MDERR_USBMUX_ARG_NULL   0x16&lt;br /&gt;
#define MDERR_USBMUX_FAILED     0xffffffff&lt;br /&gt;
	&lt;br /&gt;
	/* Messages passed to device notification callbacks: passed as part of&lt;br /&gt;
	 * am_device_notification_callback_info. */&lt;br /&gt;
#define ADNCI_MSG_CONNECTED     1&lt;br /&gt;
#define ADNCI_MSG_DISCONNECTED  2&lt;br /&gt;
#define ADNCI_MSG_UNSUBSCRIBED  3&lt;br /&gt;
	&lt;br /&gt;
#define AMD_IPHONE_PRODUCT_ID   0x1290&lt;br /&gt;
	//#define AMD_IPHONE_SERIAL       &amp;quot;&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
	/* Services, found in /System/Library/Lockdown/Services.plist */&lt;br /&gt;
#define AMSVC_AFC                   CFSTR(&amp;quot;com.apple.afc&amp;quot;)&lt;br /&gt;
#define AMSVC_BACKUP                CFSTR(&amp;quot;com.apple.mobilebackup&amp;quot;)&lt;br /&gt;
#define AMSVC_CRASH_REPORT_COPY     CFSTR(&amp;quot;com.apple.crashreportcopy&amp;quot;)&lt;br /&gt;
#define AMSVC_DEBUG_IMAGE_MOUNT     CFSTR(&amp;quot;com.apple.mobile.debug_image_mount&amp;quot;)&lt;br /&gt;
#define AMSVC_NOTIFICATION_PROXY    CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;)&lt;br /&gt;
#define AMSVC_PURPLE_TEST           CFSTR(&amp;quot;com.apple.purpletestr&amp;quot;)&lt;br /&gt;
#define AMSVC_SOFTWARE_UPDATE       CFSTR(&amp;quot;com.apple.mobile.software_update&amp;quot;)&lt;br /&gt;
#define AMSVC_SYNC                  CFSTR(&amp;quot;com.apple.mobilesync&amp;quot;)&lt;br /&gt;
#define AMSVC_SCREENSHOT            CFSTR(&amp;quot;com.apple.screenshotr&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSLOG_RELAY          CFSTR(&amp;quot;com.apple.syslog_relay&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSTEM_PROFILER       CFSTR(&amp;quot;com.apple.mobile.system_profiler&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned int afc_error_t;&lt;br /&gt;
	typedef unsigned int usbmux_error_t;&lt;br /&gt;
	&lt;br /&gt;
	struct am_recovery_device;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification_callback_info {&lt;br /&gt;
		struct am_device *dev;  /* 0    device */ &lt;br /&gt;
		unsigned int msg;       /* 4    one of ADNCI_MSG_* */&lt;br /&gt;
                struct am_device_notification* subscription; &lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
	&lt;br /&gt;
	/* This is a CoreFoundation object of class AMRecoveryModeDevice. */&lt;br /&gt;
	struct am_recovery_device {&lt;br /&gt;
		unsigned char unknown0[8];                          /* 0 */&lt;br /&gt;
		am_restore_device_notification_callback callback;   /* 8 */&lt;br /&gt;
		void *user_info;                                    /* 12 */&lt;br /&gt;
		unsigned char unknown1[12];                         /* 16 */&lt;br /&gt;
		unsigned int readwrite_pipe;                        /* 28 */&lt;br /&gt;
		unsigned char read_pipe;                            /* 32 */&lt;br /&gt;
		unsigned char write_ctrl_pipe;                      /* 33 */&lt;br /&gt;
		unsigned char read_unknown_pipe;                    /* 34 */&lt;br /&gt;
		unsigned char write_file_pipe;                      /* 35 */&lt;br /&gt;
		unsigned char write_input_pipe;                     /* 36 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* A CoreFoundation object of class AMRestoreModeDevice. */&lt;br /&gt;
	struct am_restore_device {&lt;br /&gt;
		unsigned char unknown[32];&lt;br /&gt;
		int port;&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device notification callback function. */&lt;br /&gt;
	typedef void(*am_device_notification_callback)(struct am_device_notification_callback_info *, int cookie);&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the _AMDDeviceAttached function.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void *amd_device_attached_callback;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
&lt;br /&gt;
	/* Structure that contains internal data used by AMDevice... functions. Never try &lt;br /&gt;
         * to access its members directly! Use AMDeviceCopyDeviceIdentifier, &lt;br /&gt;
         * AMDeviceGetConnectionID, AMDeviceRetain, AMDeviceRelease instead. */&lt;br /&gt;
	struct am_device {&lt;br /&gt;
		unsigned char unknown0[16]; /* 0 - zero */&lt;br /&gt;
		unsigned int device_id;     /* 16 */&lt;br /&gt;
		unsigned int product_id;    /* 20 - set to AMD_IPHONE_PRODUCT_ID */&lt;br /&gt;
		char *serial;               /* 24 - set to UDID, Unique Device Identifier */&lt;br /&gt;
		unsigned int unknown1;      /* 28 */&lt;br /&gt;
		unsigned int unknown2;      /* 32 - reference counter, increased by AMDeviceRetain, decreased by AMDeviceRelease*/&lt;br /&gt;
		unsigned int lockdown_conn; /* 36 */&lt;br /&gt;
		unsigned char unknown3[8];  /* 40 */&lt;br /&gt;
#if (__ITUNES_VER &amp;gt; 740)&lt;br /&gt;
		unsigned int unknown4;      /* 48 - used to store CriticalSection Handle*/&lt;br /&gt;
#endif&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
		unsigned char unknown5[24];  /* 52 */&lt;br /&gt;
#endif&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification {&lt;br /&gt;
		unsigned int unknown0;                      /* 0 */&lt;br /&gt;
		unsigned int unknown1;                      /* 4 */&lt;br /&gt;
		unsigned int unknown2;                      /* 8 */&lt;br /&gt;
		am_device_notification_callback callback;   /* 12 */ &lt;br /&gt;
		unsigned int cookie;                      /* 16 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct afc_connection {&lt;br /&gt;
		unsigned int handle;            /* 0 */&lt;br /&gt;
		unsigned int unknown0;          /* 4 */&lt;br /&gt;
		unsigned char unknown1;         /* 8 */&lt;br /&gt;
		unsigned char padding[3];       /* 9 */&lt;br /&gt;
		unsigned int unknown2;          /* 12 */&lt;br /&gt;
		unsigned int unknown3;          /* 16 */&lt;br /&gt;
		unsigned int unknown4;          /* 20 */&lt;br /&gt;
		unsigned int fs_block_size;     /* 24 */&lt;br /&gt;
		unsigned int sock_block_size;   /* 28: always 0x3c */&lt;br /&gt;
		unsigned int io_timeout;        /* 32: from AFCConnectionOpen, usu. 0 */&lt;br /&gt;
		void *afc_lock;                 /* 36 */&lt;br /&gt;
		unsigned int context;           /* 40 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
	struct afc_device_info {&lt;br /&gt;
		unsigned char unknown[12];  /* 0 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_directory {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_dictionary {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned long long afc_file_ref;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_1 {                  /* offset   value in iTunes */&lt;br /&gt;
		unsigned int unknown0;                  /* 0        1 */&lt;br /&gt;
		unsigned char *unknown1;                /* 4        ptr, maybe device? */&lt;br /&gt;
		amd_device_attached_callback callback;  /* 8        _AMDDeviceAttached */&lt;br /&gt;
		unsigned int unknown3;                  /* 12 */&lt;br /&gt;
		unsigned int unknown4;                  /* 16 */&lt;br /&gt;
		unsigned int unknown5;                  /* 20 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_2 {&lt;br /&gt;
		unsigned char unknown0[4144];&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_bootloader_control_packet {&lt;br /&gt;
		unsigned char opcode;       /* 0 */&lt;br /&gt;
		unsigned char length;       /* 1 */&lt;br /&gt;
		unsigned char magic[2];     /* 2: 0x34, 0x12 */&lt;br /&gt;
		unsigned char payload[0];   /* 4 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Registers a notification with the current run loop. The callback gets&lt;br /&gt;
	 *  copied into the notification struct, as well as being registered with the&lt;br /&gt;
	 *  current run loop. Cookie gets copied into cookie in the same.&lt;br /&gt;
	 *  (Cookie is a user info parameter that gets passed as an arg to&lt;br /&gt;
	 *  the callback) unused0 and unused1 are both 0 when iTunes calls this.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Never try to acces directly or copy contents of dev and subscription fields &lt;br /&gt;
	 *  in am_device_notification_callback_info. Treat them as abstract handles. &lt;br /&gt;
	 *  When done with connection use AMDeviceRelease to free resources allocated for am_device.&lt;br /&gt;
	 *  &lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK            if successful&lt;br /&gt;
	 *      MDERR_SYSCALL       if CFRunLoopAddSource() failed&lt;br /&gt;
	 *      MDERR_OUT_OF_MEMORY if we ran out of memory&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationSubscribe(am_device_notification_callback callback, &lt;br /&gt;
								unsigned int unused0, unsigned int unused1, &lt;br /&gt;
								unsigned int cookie, &lt;br /&gt;
								struct am_device_notification **subscription);&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
        /* Unregisters notifications. Buggy (iTunes 8.2): if you subscribe, unsubscribe and subscribe again, arriving &lt;br /&gt;
           notifications will contain cookie and subscription from 1st call to subscribe, not the 2nd one. iTunes &lt;br /&gt;
           calls this function only once on exit.&lt;br /&gt;
        */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationUnsubscribe(am_device_notification* subscription);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns device_id field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMDeviceGetConnectionID(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns serial field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyDeviceIdentifier(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Connects to the iPhone. Pass in the am_device structure that the&lt;br /&gt;
	 *  notification callback will give to you.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successfully connected&lt;br /&gt;
	 *      MDERR_SYSCALL           if setsockopt() failed&lt;br /&gt;
	 *      MDERR_QUERY_FAILED      if the daemon query failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if USBMuxConnectByPort returned 0xffffffff&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceConnect(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Calls PairingRecordPath() on the given device, than tests whether the path&lt;br /&gt;
	 *  which that function returns exists. During the initial connect, the path&lt;br /&gt;
	 *  returned by that function is '/', and so this returns 1.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      0   if the path did not exist&lt;br /&gt;
	 *      1   if it did&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceIsPaired(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDevicePair(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  iTunes calls this function immediately after testing whether the device is&lt;br /&gt;
	 *  paired. It creates a pairing file and establishes a Lockdown connection.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the supplied device is null&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceValidatePairing(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Creates a Lockdown session and adjusts the device structure appropriately&lt;br /&gt;
	 *  to indicate that the session has been started. iTunes calls this function&lt;br /&gt;
	 *  after validating pairing.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartSession(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* Reads various device settings. One of domain or cfstring arguments should be NULL.&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for cfstring:&lt;br /&gt;
	 * ActivationState&lt;br /&gt;
	 * ActivationStateAcknowledged&lt;br /&gt;
	 * BasebandBootloaderVersion&lt;br /&gt;
	 * BasebandVersion&lt;br /&gt;
	 * BluetoothAddress&lt;br /&gt;
	 * BuildVersion&lt;br /&gt;
	 * DeviceCertificate&lt;br /&gt;
	 * DeviceClass&lt;br /&gt;
	 * DeviceName&lt;br /&gt;
	 * DevicePublicKey&lt;br /&gt;
	 * FirmwareVersion&lt;br /&gt;
	 * HostAttached&lt;br /&gt;
	 * IntegratedCircuitCardIdentity&lt;br /&gt;
	 * InternationalMobileEquipmentIdentity&lt;br /&gt;
	 * InternationalMobileSubscriberIdentity&lt;br /&gt;
	 * ModelNumber&lt;br /&gt;
	 * PhoneNumber&lt;br /&gt;
	 * ProductType&lt;br /&gt;
	 * ProductVersion&lt;br /&gt;
	 * ProtocolVersion&lt;br /&gt;
	 * RegionInfo&lt;br /&gt;
	 * SBLockdownEverRegisteredKey&lt;br /&gt;
	 * SIMStatus&lt;br /&gt;
	 * SerialNumber&lt;br /&gt;
	 * SomebodySetTimeZone&lt;br /&gt;
	 * TimeIntervalSince1970&lt;br /&gt;
	 * TimeZone&lt;br /&gt;
	 * TimeZoneOffsetFromUTC&lt;br /&gt;
	 * TrustedHostAttached&lt;br /&gt;
	 * UniqueDeviceID&lt;br /&gt;
	 * Uses24HourClock&lt;br /&gt;
	 * WiFiAddress&lt;br /&gt;
	 * iTunesHasConnected&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for domain:&lt;br /&gt;
         * com.apple.mobile.battery&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyValue(struct am_device *device, CFStringRef domain, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* Starts a service and returns a socket file descriptor that can be used in order to further&lt;br /&gt;
	 * access the service. You should stop the session and disconnect before using&lt;br /&gt;
	 * the service. iTunes calls this function after starting a session. It starts &lt;br /&gt;
	 * the service and the SSL connection. service_name should be one of the AMSVC_*&lt;br /&gt;
	 * constants.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_SYSCALL           if the setsockopt() call failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartService(struct am_device *device, CFStringRef &lt;br /&gt;
									  service_name, int *socket_fd);&lt;br /&gt;
	&lt;br /&gt;
	/* Stops a session. You should do this before accessing services.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStopSession(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/* Decrements reference counter and, if nothing left, releases resources hold &lt;br /&gt;
	 * by connection, invalidates  pointer to device&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRelease(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Increments reference counter&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRetain(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Opens an Apple File Connection. You must start the appropriate service&lt;br /&gt;
	 * first with AMDeviceStartService(). In iTunes, io_timeout is 0.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_AFC_OUT_OF_MEMORY if malloc() failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionOpen(int socket_fd, unsigned int io_timeout,&lt;br /&gt;
								  struct afc_connection **conn);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        /* Copy an enviromental variable value from iBoot&lt;br /&gt;
         */&lt;br /&gt;
        __DLLIMPORT CFStringRef AMRecoveryModeCopyEnvironmentVariable(struct am_recovery_device *rdev, CFStringRef var);&lt;br /&gt;
	&lt;br /&gt;
	/* Pass in a pointer to an afc_dictionary structure. It will be filled. You can&lt;br /&gt;
	 * iterate it using AFCKeyValueRead. When done use AFCKeyValueClose. Possible keys:&lt;br /&gt;
	 * FSFreeBytes - free bytes on system device for afc2, user device for afc&lt;br /&gt;
	 * FSBlockSize - filesystem block size&lt;br /&gt;
	 * FSTotalBytes - size of device&lt;br /&gt;
	 * Model - iPhone1,1 etc.&lt;br /&gt;
&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDeviceInfoOpen(struct afc_connection *conn, struct&lt;br /&gt;
								  afc_dictionary **info);&lt;br /&gt;
	&lt;br /&gt;
	/* Turns debug mode on if the environment variable AFCDEBUG is set to a numeric&lt;br /&gt;
	 * value, or if the file '/AFCDEBUG' is present and contains a value. */&lt;br /&gt;
#if defined(__APPLE__)&lt;br /&gt;
	void AFCPlatformInitialize();&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
	/* Opens a directory on the iPhone. Pass in a pointer in dir to be filled in.&lt;br /&gt;
	 * Note that this normally only accesses the iTunes [[sandbox]]/partition as the&lt;br /&gt;
	 * root, which is /var/root/Media. Pathnames are specified with '/' delimiters&lt;br /&gt;
	 * as in Unix style. Use UTF-8 to specify non-ASCII symbols in path.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								 afc_directory **dir);&lt;br /&gt;
	&lt;br /&gt;
	/* Acquires the next entry in a directory previously opened with&lt;br /&gt;
	 * AFCDirectoryOpen(). When dirent is filled with a NULL value, then the end&lt;br /&gt;
	 * of the directory has been reached. '.' and '..' will be returned as the&lt;br /&gt;
	 * first two entries in each directory except the root; you may want to skip&lt;br /&gt;
	 * over them.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful, even if no entries remain&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryRead(struct afc_connection *conn, struct afc_directory *dir,&lt;br /&gt;
								 char **dirent);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryClose(afc_connection *conn, struct afc_directory *dir);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryCreate(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRemovePath(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRenamePath(afc_connection *conn, char *oldpath, char *newpath);&lt;br /&gt;
&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
	/* Creates symbolic or hard link&lt;br /&gt;
         * linktype - int64: 1 means hard link, 2 - soft (symbolic) link&lt;br /&gt;
         * target - absolute or relative path to link target&lt;br /&gt;
         * linkname - absolute path where to create new link&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCLinkPath(struct afc_connection *conn, long long int linktype, const char *target, &lt;br /&gt;
								                              const char *linkname);&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
	/* Opens file for reading or writing without locking it in any way. afc_file_ref should not be shared between threads - &lt;br /&gt;
         * opening file in one thread and closing it in another will lead to possible crash.&lt;br /&gt;
	 * path - UTF-8 encoded absolute path to file&lt;br /&gt;
	 * mode 2 = read, mode 3 = write; unknown = 0 &lt;br /&gt;
	 * ref - receives file handle&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefOpen(struct afc_connection *conn, char *path, unsigned&lt;br /&gt;
							   long long int mode, afc_file_ref *ref);&lt;br /&gt;
	/* Reads specified amount (len) of bytes from file into buf. Puts actual count of read bytes into len on return&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefRead(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   void *buf, unsigned int *len);&lt;br /&gt;
	/* Writes specified amount (len) of bytes from buf into file.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefWrite(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
								void *buf, unsigned int len);&lt;br /&gt;
	/* Moves the file pointer to a specified location.&lt;br /&gt;
	 * offset - Number of bytes from origin (int64)&lt;br /&gt;
	 * origin - 0 = from beginning, 1 = from current position, 2 = from end&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefSeek(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long offset, int origin, int unused);&lt;br /&gt;
&lt;br /&gt;
	/* Gets the current position of a file pointer into offset argument.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefTell(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long* offset);&lt;br /&gt;
&lt;br /&gt;
	/*  Truncates a file at the specified offset.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefSetFileSize(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long offset);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefLock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefUnlock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefClose(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
&lt;br /&gt;
	/* Opens dictionary describing specified file or directory (iTunes below 8.2 allowed using AFCGetFileInfo&lt;br /&gt;
	   to get the same information)&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileInfoOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								afc_dictionary **info);&lt;br /&gt;
&lt;br /&gt;
	/* Reads next entry from dictionary. When last entry is read, function returns NULL in key argument&lt;br /&gt;
	   Possible keys:&lt;br /&gt;
	     &amp;quot;st_size&amp;quot;:     val - size in bytes&lt;br /&gt;
	     &amp;quot;st_blocks&amp;quot;:   val - size in blocks&lt;br /&gt;
	     &amp;quot;st_nlink&amp;quot;:    val - number of hardlinks&lt;br /&gt;
	     &amp;quot;st_ifmt&amp;quot;:     val - &amp;quot;S_IFDIR&amp;quot; for folders&lt;br /&gt;
	                        &amp;quot;S_IFLNK&amp;quot; for symlinks&lt;br /&gt;
	     &amp;quot;LinkTarget&amp;quot;:  val - path to symlink target&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueRead(struct afc_dictionary *dict, char **key, char **&lt;br /&gt;
								val);&lt;br /&gt;
	/* Closes dictionary&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueClose(struct afc_dictionary *dict);&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the context field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetContext(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the fs_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetFSBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the io_timeout field of the given AFC connection. In iTunes this is&lt;br /&gt;
	 * 0. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetIOTimeout(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the sock_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetSocketBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Closes the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionClose(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Registers for device notifications related to the restore process. unknown0&lt;br /&gt;
	 * is zero when iTunes calls this. In iTunes,&lt;br /&gt;
	 * the callbacks are located at:&lt;br /&gt;
	 *      1: $3ac68e-$3ac6b1, calls $3ac542(unknown1, arg, 0)&lt;br /&gt;
	 *      2: $3ac66a-$3ac68d, calls $3ac542(unknown1, 0, arg)&lt;br /&gt;
	 *      3: $3ac762-$3ac785, calls $3ac6b2(unknown1, arg, 0)&lt;br /&gt;
	 *      4: $3ac73e-$3ac761, calls $3ac6b2(unknown1, 0, arg)&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreRegisterForDeviceNotifications(&lt;br /&gt;
				am_restore_device_notification_callback dfu_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback dfu_disconnect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_disconnect_callback,&lt;br /&gt;
				unsigned int unknown0,&lt;br /&gt;
				void *user_info);&lt;br /&gt;
	&lt;br /&gt;
	/* Causes the restore functions to spit out (unhelpful) progress messages to&lt;br /&gt;
	 * the file specified by the given path. iTunes always calls this right before&lt;br /&gt;
	 * restoring with a path of&lt;br /&gt;
	 * &amp;quot;$HOME/Library/Logs/iPhone Updater Logs/iPhoneUpdater X.log&amp;quot;, where X is an&lt;br /&gt;
	 * unused number.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreEnableFileLogging(char *path);&lt;br /&gt;
	&lt;br /&gt;
	/* Initializes a new option dictionary to default values. Pass the constant&lt;br /&gt;
	 * kCFAllocatorDefault as the allocator. The option dictionary looks as&lt;br /&gt;
	 * follows:&lt;br /&gt;
	 * {&lt;br /&gt;
	 *      NORImageType =&amp;gt; 'production',&lt;br /&gt;
	 *      AutoBootDelay =&amp;gt; 0,&lt;br /&gt;
	 *      KernelCacheType =&amp;gt; 'Release',&lt;br /&gt;
	 *      UpdateBaseband =&amp;gt; true,&lt;br /&gt;
	 *      DFUFileType =&amp;gt; 'RELEASE',&lt;br /&gt;
	 *      SystemImageType =&amp;gt; 'User',&lt;br /&gt;
	 *      CreateFilesystemPartitions =&amp;gt; true,&lt;br /&gt;
	 *      FlashNOR =&amp;gt; true,&lt;br /&gt;
	 *      RestoreBootArgs =&amp;gt; 'rd=md0 nand-enable-reformat=1 -progress'&lt;br /&gt;
	 *      BootImageType =&amp;gt; 'User'&lt;br /&gt;
	 *  }&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      the option dictionary   if successful&lt;br /&gt;
	 *      NULL                    if out of memory&lt;br /&gt;
	 */ &lt;br /&gt;
	__DLLIMPORT CFMutableDictionaryRef AMRestoreCreateDefaultOptions(CFAllocatorRef allocator);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRecoveryModeRestore(struct am_recovery_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRestoreModeRestore(struct am_restore_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT struct am_restore_device *AMRestoreModeDeviceCreate(unsigned int unknown0,&lt;br /&gt;
				unsigned int connection_id, unsigned int unknown1);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreCreatePathsForBundle(CFStringRef restore_bundle_path,&lt;br /&gt;
				CFStringRef kernel_cache_type, CFStringRef boot_image_type, unsigned int&lt;br /&gt;
				unknown0, CFStringRef *firmware_dir_path, CFStringRef *&lt;br /&gt;
				kernelcache_restore_path, unsigned int unknown1, CFStringRef *&lt;br /&gt;
				ramdisk_path);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreModeDeviceReboot(struct am_restore_device *rdev);	// Added by JB 30.07.2008&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceEnterRecovery(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDisconnect(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* to use this, start the service &amp;quot;com.apple.mobile.notification_proxy&amp;quot;, handle will be the socket to use */&lt;br /&gt;
	typedef void (*NOTIFY_CALLBACK)(CFSTR notification, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDPostNotification(SOCKET socket, CFStringRef  notification, CFStringRef userinfo);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDObserveNotification(SOCKET socket, CFSTR notification);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDListenForNotifications(SOCKET socket, NOTIFY_CALLBACK cb, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDShutdownNotificationProxy(SOCKET socket);&lt;br /&gt;
	&lt;br /&gt;
	/*edits by geohot*/&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDeactivate(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceActivate(struct am_device *device, CFDictionaryRef dict);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceRemoveValue(struct am_device *device, unsigned int, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Pass in a usbmux_listener_1 structure and a usbmux_listener_2 structure&lt;br /&gt;
	 *  pointer, which will be filled with the resulting usbmux_listener_2.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if completed successfully&lt;br /&gt;
	 *      MDERR_USBMUX_ARG_NULL   if one of the arguments was NULL&lt;br /&gt;
	 *      MDERR_USBMUX_FAILED     if the listener was not created successfully&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerCreate(struct usbmux_listener_1 *esi_fp8, struct&lt;br /&gt;
										usbmux_listener_2 **eax_fp12);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerHandleData(void *);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Private routines - here be dragons&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/* AMRestorePerformRestoreModeRestore() calls this function with a dictionary&lt;br /&gt;
	 * in order to perform certain special restore operations&lt;br /&gt;
	 * (RESTORED_OPERATION_*). It is thought that this function might enable&lt;br /&gt;
	 * significant access to the phone. */&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef unsigned int (*t_performOperation)(struct am_restore_device *rdev,&lt;br /&gt;
	 CFDictionaryRef op) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_performOperation _performOperation = (t_performOperation)0x3c39fa4b;&lt;br /&gt;
	 */ &lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef int (*t_socketForPort)(struct am_restore_device *rdev, unsigned int port)&lt;br /&gt;
	 __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_socketForPort _socketForPort = (t_socketForPort)(void *)0x3c39f36c;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef void (*t_restored_send_message)(int port, CFDictionaryRef msg);&lt;br /&gt;
	 t_restored_send_message _restored_send_message = (t_restored_send_message)0x3c3a4e40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef CFDictionaryRef (*t_restored_receive_message)(int port);&lt;br /&gt;
	 t_restored_receive_message _restored_receive_message = (t_restored_receive_message)0x3c3a4d40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendControlPacket)(struct am_recovery_device *rdev, unsigned&lt;br /&gt;
	 int msg1, unsigned int msg2, unsigned int unknown0, unsigned int *unknown1,&lt;br /&gt;
	 unsigned char *unknown2) __attribute__ ((regparm(3)));&lt;br /&gt;
	 t_sendControlPacket _sendControlPacket = (t_sendControlPacket)0x3c3a3da3;;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendCommandToDevice)(struct am_recovery_device *rdev,&lt;br /&gt;
	 CFStringRef cmd) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_sendCommandToDevice _sendCommandToDevice = (t_sendCommandToDevice)0x3c3a3e3b;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceReadPipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int read_pipe, unsigned char *data, unsigned int *len);&lt;br /&gt;
	 t_AMRUSBInterfaceReadPipe _AMRUSBInterfaceReadPipe = (t_AMRUSBInterfaceReadPipe)0x3c3a27e8;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceWritePipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int write_pipe, void *data, unsigned int len);&lt;br /&gt;
	 t_AMRUSBInterfaceWritePipe _AMRUSBInterfaceWritePipe = (t_AMRUSBInterfaceWritePipe)0x3c3a27cb;&lt;br /&gt;
	 */&lt;br /&gt;
	&lt;br /&gt;
	int performOperation(am_restore_device *rdev, CFMutableDictionaryRef message);&lt;br /&gt;
	int socketForPort(am_restore_device *rdev, unsigned int portnum);&lt;br /&gt;
	int sendCommandToDevice(am_recovery_device *rdev, CFStringRef cfs, int block);&lt;br /&gt;
	int sendFileToDevice(am_recovery_device *rdev, CFStringRef filename); &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
}&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
/* -*- mode:c; indent-tabs-mode:nil; c-basic-offset:2; tab-width:2; */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===AFC Connection===&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
===Locking the Device for Sync===&lt;br /&gt;
When iTunes sends a new song to the device, the device shows a &amp;quot;Sync in progress&amp;quot; screen and when complete, the Music app on the device re-reads the iTunesDB file so it picks up the new song.&lt;br /&gt;
&lt;br /&gt;
To get this behaviour, first start the notification service:&lt;br /&gt;
&amp;lt;pre&amp;gt;SOCKET socket;&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we post a notificaton message to signal that we are going to start a sync:&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncWillStart&amp;quot;), NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we open the itunes lock file:&lt;br /&gt;
&amp;lt;pre&amp;gt;afc_file_ref lockref;&lt;br /&gt;
AFCFileRefOpen(conn, &amp;quot;/com.apple.itunes.lock_sync&amp;quot;, 2, &amp;amp;lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now post a notification to say we are going to lock this file, and try and lock it.&lt;br /&gt;
If the AFCFileRefLock call fails, pause and repeat.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncLockRequest&amp;quot;), NULL);&lt;br /&gt;
mach_error_t error = AFCFileRefLock(conn, lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the file is successfully locked, post another notification, and stop the notification service.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket,CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidStart&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the sync can proceed, so copy your files across and make the changes to the iTunesDB.&lt;br /&gt;
&lt;br /&gt;
To release the lock, start the notification system again, unlock and close the lock file, and send a sync finished notification message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;AFCFileRefUnlock(conn, lockref);&lt;br /&gt;
AFCFileRefClose(conn, lockref);&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&lt;br /&gt;
AMDPostNotification(socket, &amp;amp;CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidFinish&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To handle &amp;quot;Slide to Cancel&amp;quot; and terminate sync when user slides cancel switch, use AMDObserveNotification to subscribe notifications about “com.apple.itunes-client.syncCancelRequest”. Then start listening for notifications (AMDListenForNotifications) until you get “AMDNotificationFaceplant”.&lt;br /&gt;
When notification got, you should unlock and close lock file handle (don’t sure if you need to post “syncDidFinish” to proxy, seems it doesn’t matter) and terminate sync gracefully.&lt;br /&gt;
The same notification is also got when you unplug your device, so you should always be ready for errors.&lt;br /&gt;
&lt;br /&gt;
NOTE: You may find that starting the notification_proxy service once and once only at the start of your app and using the same socket in calls to AMDPostNotification works better. iTunes opens and closes the notification_proxy regularly, but it appears to be a bit flakey when you open/close it all the time.&lt;br /&gt;
&lt;br /&gt;
===Known Functions===&lt;br /&gt;
&lt;br /&gt;
 AFCLockCreate&lt;br /&gt;
 AFCLockFree&lt;br /&gt;
 AFCLockLock&lt;br /&gt;
 AFCLockTryLock&lt;br /&gt;
 AFCLockUnlock&lt;br /&gt;
 AFCStringBufferAlloc&lt;br /&gt;
 AFCStringBufferAppend&lt;br /&gt;
 AFCStringBufferFree&lt;br /&gt;
 AFCStringCopy&lt;br /&gt;
 MISProfileCopyPayload&lt;br /&gt;
 MISProfileCopySignerSubjectSummary&lt;br /&gt;
 MISProfileCreateDataRepresentation&lt;br /&gt;
 MISProfileCreateWithData&lt;br /&gt;
 MISProfileCreateWithFile&lt;br /&gt;
 MISProfileGetValue&lt;br /&gt;
 MISProfileIsMutable&lt;br /&gt;
 MISProfileValidateSignature&lt;br /&gt;
 MISProfileValidateSignatureWithAnchors&lt;br /&gt;
 MISProfileWriteToFile&lt;br /&gt;
 MISProvisioningProfileCheckValidity&lt;br /&gt;
 MISProvisioningProfileGetCreationDate&lt;br /&gt;
 MISProvisioningProfileGetDeveloperCertificates&lt;br /&gt;
 MISProvisioningProfileGetExpirationDate&lt;br /&gt;
 MISProvisioningProfileGetName&lt;br /&gt;
 MISProvisioningProfileGetProvisionedDevices&lt;br /&gt;
 MISProvisioningProfileGetUUID&lt;br /&gt;
 MISProvisioningProfileGetVersion&lt;br /&gt;
 MISProvisioningProfileIncludesDevice&lt;br /&gt;
 MISProvisioningProfileProvisionsAllDevices&lt;br /&gt;
 MISProvisioningProfileValidateSignature&lt;br /&gt;
 AFCConnectionClose&lt;br /&gt;
 AFCConnectionGetContext&lt;br /&gt;
 AFCConnectionGetFSBlockSize&lt;br /&gt;
 AFCConnectionGetIOTimeout&lt;br /&gt;
 AFCConnectionGetSocketBlockSize&lt;br /&gt;
 AFCConnectionOpen&lt;br /&gt;
 AFCConnectionSetContext&lt;br /&gt;
 AFCConnectionSetFSBlockSize&lt;br /&gt;
 AFCConnectionSetFatalError&lt;br /&gt;
 AFCConnectionSetIOTimeout&lt;br /&gt;
 AFCConnectionSetSocketBlockSize&lt;br /&gt;
 AFCDeviceInfoOpen&lt;br /&gt;
 AFCDirectoryClose&lt;br /&gt;
 AFCDirectoryCreate&lt;br /&gt;
 AFCDirectoryOpen&lt;br /&gt;
 AFCDirectoryRead&lt;br /&gt;
 AFCDiscardBodyData&lt;br /&gt;
 AFCDiscardData&lt;br /&gt;
 AFCErrnoToAFCError&lt;br /&gt;
 AFCFileInfoOpen&lt;br /&gt;
 AFCFileRefClose&lt;br /&gt;
 AFCFileRefLock&lt;br /&gt;
 AFCFileRefOpen&lt;br /&gt;
 AFCFileRefRead&lt;br /&gt;
 AFCFileRefSeek&lt;br /&gt;
 AFCFileRefSetFileSize&lt;br /&gt;
 AFCFileRefTell&lt;br /&gt;
 AFCFileRefUnlock&lt;br /&gt;
 AFCFileRefWrite&lt;br /&gt;
 AFCFlushData&lt;br /&gt;
 AFCGetClientVersionString&lt;br /&gt;
 AFCGetDeviceInfo&lt;br /&gt;
 AFCGetFileInfo&lt;br /&gt;
 AFCInitHeader&lt;br /&gt;
 AFCKeyValueClose&lt;br /&gt;
 AFCKeyValueRead&lt;br /&gt;
 AFCParseDataPacketHeader&lt;br /&gt;
 AFCParseStatusPacket&lt;br /&gt;
 AFCReadData&lt;br /&gt;
 AFCReadPacket&lt;br /&gt;
 AFCReadPacketBody&lt;br /&gt;
 AFCReadPacketHeader&lt;br /&gt;
 AFCRemovePath&lt;br /&gt;
 AFCRenamePath&lt;br /&gt;
 AFCSendData&lt;br /&gt;
 AFCSendDataPacket&lt;br /&gt;
 AFCSendHeader&lt;br /&gt;
 AFCSendPacket&lt;br /&gt;
 AFCSendStatus&lt;br /&gt;
 AFCValidateHeader&lt;br /&gt;
 AMDFUModeDeviceGetLocationID&lt;br /&gt;
 AMDFUModeDeviceGetProductID&lt;br /&gt;
 AMDFUModeDeviceGetProductType&lt;br /&gt;
 AMDFUModeDeviceGetProgress&lt;br /&gt;
 AMDFUModeDeviceGetTypeID&lt;br /&gt;
 AMDListenForNotifications&lt;br /&gt;
 AMDObserveNotification&lt;br /&gt;
 AMDPostNotification&lt;br /&gt;
 AMDShutdownNotificationProxy&lt;br /&gt;
 AMDeviceActivate&lt;br /&gt;
 AMDeviceArchiveApplication&lt;br /&gt;
 AMDeviceConnect&lt;br /&gt;
 AMDeviceCopyDeviceIdentifier&lt;br /&gt;
 AMDeviceCopyProvisioningProfiles&lt;br /&gt;
 AMDeviceCopyValue&lt;br /&gt;
 AMDeviceDeactivate&lt;br /&gt;
 AMDeviceDisconnect&lt;br /&gt;
 AMDeviceEnterRecovery&lt;br /&gt;
 AMDeviceGetConnectionID&lt;br /&gt;
 AMDeviceInstallApplication&lt;br /&gt;
 AMDeviceInstallProvisioningProfile&lt;br /&gt;
 AMDeviceIsPaired&lt;br /&gt;
 AMDeviceIsValid&lt;br /&gt;
 AMDeviceLookupApplicationArchives&lt;br /&gt;
 AMDeviceLookupApplications&lt;br /&gt;
 AMDeviceNotificationGetThreadHandle&lt;br /&gt;
 AMDeviceNotificationSubscribe&lt;br /&gt;
 AMDeviceNotificationUnsubscribe&lt;br /&gt;
 AMDevicePair&lt;br /&gt;
 AMDeviceRelease&lt;br /&gt;
 AMDeviceRemoveApplicationArchive&lt;br /&gt;
 AMDeviceRemoveProvisioningProfile&lt;br /&gt;
 AMDeviceRemoveValue&lt;br /&gt;
 AMDeviceRestoreApplication&lt;br /&gt;
 AMDeviceRetain&lt;br /&gt;
 AMDeviceSetValue&lt;br /&gt;
 AMDeviceSoftwareUpdate&lt;br /&gt;
 AMDeviceStartHouseArrestService&lt;br /&gt;
 AMDeviceStartService&lt;br /&gt;
 AMDeviceStartSession&lt;br /&gt;
 AMDeviceStopSession&lt;br /&gt;
 AMDeviceTransferApplication&lt;br /&gt;
 AMDeviceUninstallApplication&lt;br /&gt;
 AMDeviceValidatePairing&lt;br /&gt;
 AMRecoveryModeDeviceCopyIMEI&lt;br /&gt;
 AMRecoveryModeDeviceCopySerialNumber&lt;br /&gt;
 AMRecoveryModeDeviceGetLocationID&lt;br /&gt;
 AMRecoveryModeDeviceGetProductID&lt;br /&gt;
 AMRecoveryModeDeviceGetProductType&lt;br /&gt;
 AMRecoveryModeDeviceGetProgress&lt;br /&gt;
 AMRecoveryModeDeviceGetSecurityEpoch&lt;br /&gt;
 AMRecoveryModeDeviceGetTypeID&lt;br /&gt;
 AMRecoveryModeDeviceReboot&lt;br /&gt;
 AMRecoveryModeDeviceSetAutoBoot&lt;br /&gt;
 AMRecoveryModeGetSoftwareBuildVersion&lt;br /&gt;
 AMRestoreCreateBootArgsByAddingArg&lt;br /&gt;
 AMRestoreCreateBootArgsByRemovingArg&lt;br /&gt;
 AMRestoreCreateDefaultOptions&lt;br /&gt;
 AMRestoreCreateDefaultOptionsForIdentification&lt;br /&gt;
 AMRestoreCreatePathsForBundle&lt;br /&gt;
 AMRestoreDisableFileLogging&lt;br /&gt;
 AMRestoreEnableExtraDFUDevices&lt;br /&gt;
 AMRestoreEnableFileLogging&lt;br /&gt;
 AMRestoreGetSupportedPayloadVersion&lt;br /&gt;
 AMRestoreModeDeviceCopyIMEI&lt;br /&gt;
 AMRestoreModeDeviceCopyRestoreLog&lt;br /&gt;
 AMRestoreModeDeviceCopySerialNumber&lt;br /&gt;
 AMRestoreModeDeviceCreate&lt;br /&gt;
 AMRestoreModeDeviceGetDeviceID&lt;br /&gt;
 AMRestoreModeDeviceGetLocationID&lt;br /&gt;
 AMRestoreModeDeviceGetProgress&lt;br /&gt;
 AMRestoreModeDeviceGetTypeID&lt;br /&gt;
 AMRestoreModeDeviceReboot&lt;br /&gt;
 AMRestorePerformDFURestore&lt;br /&gt;
 AMRestorePerformRecoveryModeRestore&lt;br /&gt;
 AMRestorePerformRestoreModeRestore&lt;br /&gt;
 AMRestoreRegisterForDeviceNotifications&lt;br /&gt;
 AMRestoreSetLogLevel&lt;br /&gt;
 AMSBackup&lt;br /&gt;
 AMSBeginSync&lt;br /&gt;
 AMSBeginSyncForDataClasses&lt;br /&gt;
 AMSCancelBackupRestore&lt;br /&gt;
 AMSCancelCrashReportCopy&lt;br /&gt;
 AMSCancelSync&lt;br /&gt;
 AMSCancelSyncDiagnostics&lt;br /&gt;
 AMSCleanup&lt;br /&gt;
 AMSConnectToCrashReportCopyTarget&lt;br /&gt;
 AMSCopyAndSubmitCrashLogs&lt;br /&gt;
 AMSCopyAndSubmitCrashLogsFromTarget&lt;br /&gt;
 AMSCopyApplicationListFromBackup&lt;br /&gt;
 AMSCopyCrashReportPath&lt;br /&gt;
 AMSCopyCrashReportsFromTarget&lt;br /&gt;
 AMSCopySourcesForRestoreCompatibleWith&lt;br /&gt;
 AMSDisconnectFromCrashReportCopyTarget&lt;br /&gt;
 AMSGetAOSUsername&lt;br /&gt;
 AMSGetApplicationProviderInfo&lt;br /&gt;
 AMSGetCalendarDayLimit&lt;br /&gt;
 AMSGetClientIdentifierAndDisplayNameForTarget&lt;br /&gt;
 AMSGetCollectionsForDataClassName&lt;br /&gt;
 AMSGetConflictInformation&lt;br /&gt;
 AMSGetConflictInformationForIdentifiers&lt;br /&gt;
 AMSGetCrashReportCopyPreferencesForTarget&lt;br /&gt;
 AMSGetDCAChangeInformation&lt;br /&gt;
 AMSGetDataChangeAlertInfo&lt;br /&gt;
 AMSGetDataClassInfoForTarget&lt;br /&gt;
 AMSGetLastSyncDateForDataClass&lt;br /&gt;
 AMSGetNewRecordCalendarName&lt;br /&gt;
 AMSGetNewRecordGroupName&lt;br /&gt;
 AMSGetNumberOfCrashReportsToCopy&lt;br /&gt;
 AMSGetNumberOfCrashReportsToSubmit&lt;br /&gt;
 AMSGetSourcesForRestore&lt;br /&gt;
 AMSGetSupportedDataClassNames&lt;br /&gt;
 AMSInitialize&lt;br /&gt;
 AMSRefreshCollectionsForDataClassName&lt;br /&gt;
 AMSRegisterCallbacks&lt;br /&gt;
 AMSRegisterClientWithTargetIdentifierAndDisplayName&lt;br /&gt;
 AMSResetSyncData&lt;br /&gt;
 AMSRestore&lt;br /&gt;
 AMSRestoreWithApplications&lt;br /&gt;
 AMSRunSyncDiagnostics&lt;br /&gt;
 AMSSetCalendarDayLimit&lt;br /&gt;
 AMSSetConflictWinners&lt;br /&gt;
 AMSSetCrashReportCopyPreferencesForTarget&lt;br /&gt;
 AMSSetDataChangeAlertInfo&lt;br /&gt;
 AMSSetDataClassInfoForTarget&lt;br /&gt;
 AMSSetDesignatedProviderForDataClassName&lt;br /&gt;
 AMSSetFilteredCollectionNamesForDataClassName&lt;br /&gt;
 AMSSetNewRecordCalendarName&lt;br /&gt;
 AMSSetNewRecordGroupName&lt;br /&gt;
 AMSSubmitCrashReportsFromTarget&lt;br /&gt;
 AMSSyncConflictsSelections&lt;br /&gt;
 AMSUnregisterTarget&lt;br /&gt;
 ASRServerHandleConnection&lt;br /&gt;
 GoogleSyncConduitCopyUsername&lt;br /&gt;
 GoogleSyncConduitRegisterClient&lt;br /&gt;
 GoogleSyncConduitSetUsernameAndPassword&lt;br /&gt;
 GoogleSyncConduitUnregisterClient&lt;br /&gt;
 GoogleSyncConduitValidateUser&lt;br /&gt;
 USBMuxConnectByPort&lt;br /&gt;
 USBMuxListenForDevices&lt;br /&gt;
 USBMuxListenerClose&lt;br /&gt;
 USBMuxListenerCreate&lt;br /&gt;
 USBMuxListenerGetEvent&lt;br /&gt;
 USBMuxListenerGetFD&lt;br /&gt;
 USBMuxListenerHandleData&lt;br /&gt;
 USBMuxListenerSetDebug&lt;br /&gt;
 YahooConduitCopyYahooID&lt;br /&gt;
 YahooConduitIsTokenValid&lt;br /&gt;
 YahooConduitLastSyncError&lt;br /&gt;
 YahooConduitRegister&lt;br /&gt;
 YahooConduitUnregister&lt;br /&gt;
 kAMDMobileDeviceVersionNumber&lt;br /&gt;
 kLDErrorInvalidResponse&lt;br /&gt;
 lockdown_activate&lt;br /&gt;
 lockdown_connection_create&lt;br /&gt;
 lockdown_connection_destroy&lt;br /&gt;
 lockdown_get_value&lt;br /&gt;
 lockdown_goodbye&lt;br /&gt;
 lockdown_pair&lt;br /&gt;
 lockdown_remove_value&lt;br /&gt;
 lockdown_service_start&lt;br /&gt;
 lockdown_session_start&lt;br /&gt;
 lockdown_session_stop&lt;br /&gt;
 lockdown_set_value&lt;br /&gt;
&lt;br /&gt;
===Private Functions===&lt;br /&gt;
&lt;br /&gt;
====How to find address of privates functions in iTunesMobileDevice.dll or MobileDevice.framework====&lt;br /&gt;
&lt;br /&gt;
In order to obtain the address of a usable private function in MobileDevice, you will have to be able to understand x86-64 assembly to reverse engineer it. A private function will not have its name exported in the mach-o symbol table, so in a debugger, like GDB, it will show up as part of another function. However, you will know that it is a separate function as a new stack frame is set up.&lt;br /&gt;
&lt;br /&gt;
====Private Function Address List====&lt;br /&gt;
&lt;br /&gt;
=====OSX.6 - iTunes 9.0.2(25)=====&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendCommandToiBoot(struct am_recovery_device *rdev, CFStringRef command, int u);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 868(0x364) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym(). &lt;br /&gt;
Address: 0x1000245ea&lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
1. rdev - the device you wish to send the command to.&lt;br /&gt;
2. a CFStringRef of the command to send.&lt;br /&gt;
3. an integer, whose use is currently unknown, but should be set to 0 to work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendFileToiDevice(struct am_recovery_device *rdev, CFStringRef filename);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 1763(0x6e3) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym().&lt;br /&gt;
Address: 0x100024969&lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
1. rdev - the device you wish to send the file to.&lt;br /&gt;
2. a CFStringRef of the path to the file to send.&lt;br /&gt;
&lt;br /&gt;
=====OSX.6 - iTunes 9.0.3(15)=====&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendCommandToiBoot(struct am_recovery_device *rdev, CFStringRef command, int u);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Addresss: AMRecoveryDeviceGetProductType() + 0x37f(895); full offset: 0x2a0ed&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendFileToiDevice(struct am_recovery_device *rdev, CFStringRef filename);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address: AMRecoveryDeviceGetProductType()+0x6f3(1790); full offset: 0x2a46c&lt;br /&gt;
&lt;br /&gt;
As of now, Apple has decided to make this functions public with the following names:&lt;br /&gt;
&lt;br /&gt;
_AMRecoveryModeDeviceSendFileToDevice &lt;br /&gt;
_AMRecoveryModeDeviceSendCommandToDevice&lt;br /&gt;
_AMRecoveryModeDeviceSendBlindCommandToDevice&lt;br /&gt;
&lt;br /&gt;
The last of those returns no response from the device. I can only assume that the parameters to these functions are the same or similar to the private ones. They're not the exact same function though, as it appears that these functions call the previously private ones.&lt;br /&gt;
&lt;br /&gt;
===Libraries Implementations===&lt;br /&gt;
&lt;br /&gt;
* [http://code.google.com/p/manzana/ Manzana (MobileDevice Library for Windows)]&lt;br /&gt;
* [http://www.libimobiledevice.org/ Libimobiledevice (provides the same functionality on GNU/Linux)]&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=K48AP&amp;diff=6571</id>
		<title>K48AP</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=K48AP&amp;diff=6571"/>
		<updated>2010-06-21T01:07:33Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:ipad_hero_20100127.jpg|thumb|right|250px|iPad]]This is the iPad. Announced on January 27, 2010. $499 for WiFi-only variant. Features 1 GHz Apple [[S5L8930]] CPU and 9.7&amp;quot; display. Runs iOS 3.2. &lt;br /&gt;
&lt;br /&gt;
== Application processor ==&lt;br /&gt;
It makes use of 1 GHz [[S5L8930|S5L8930]] CPU.&lt;br /&gt;
&lt;br /&gt;
== Baseband (3G version) ==&lt;br /&gt;
The iPad 3G uses the [[X-Gold 608]] baseband chip, same as in the iPhone 3G and 3GS. &lt;br /&gt;
Exact part is the Infineon 337S3754 PMB 8878 X-Gold baseband IC 5Y06115.&lt;br /&gt;
&lt;br /&gt;
== Specifications ==&lt;br /&gt;
'''Screen:''' 1024x768px&lt;br /&gt;
&lt;br /&gt;
'''Size:''' 9.56 inches (242.8 mm) (height) x 7.47 inches (189.7 mm) (width) x 0.5 inch (13.4 mm) (depth)&lt;br /&gt;
&lt;br /&gt;
'''Weight:''' 1.5 pounds (0.68 kg) Wi-Fi model; 1.6 pounds (0.73 kg) Wi-Fi + 3G model&lt;br /&gt;
&lt;br /&gt;
'''Battery:''' Up to 10 hours of Internet use, one month of standby&lt;br /&gt;
&lt;br /&gt;
'''3G:''' UMTS/HSDPA (850, 1900, 2100 MHz), GSM/EDGE (850, 900, 1800, 1900 MHz), data only&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=GenPass&amp;diff=6343</id>
		<title>GenPass</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=GenPass&amp;diff=6343"/>
		<updated>2010-05-11T20:17:57Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;note: in the iphone firmware, the decryption happens in /usr/sbin/asr, which can be found on the ramdisk.&lt;br /&gt;
&lt;br /&gt;
'''*NOTICE:''' GenPass is currently broken. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// genpass&lt;br /&gt;
// get asr key for 3.x firmware&lt;br /&gt;
//&lt;br /&gt;
// by posixninja, geohot, and chronic&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
#include &amp;lt;openssl/sha.h&amp;gt;&lt;br /&gt;
#include &amp;lt;openssl/evp.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define BUF_SIZE 0x100000&lt;br /&gt;
#define SHA256_DIGEST_LENGTH 32&lt;br /&gt;
&lt;br /&gt;
typedef unsigned char uint8;&lt;br /&gt;
typedef unsigned int uint32;&lt;br /&gt;
typedef unsigned long long uint64;&lt;br /&gt;
&lt;br /&gt;
uint64 u32_to_u64(uint32 msq, uint32 lsq) {&lt;br /&gt;
        uint64 ms = (uint64)msq;&lt;br /&gt;
        uint64 ls = (uint64)lsq;&lt;br /&gt;
        return ls | (ms &amp;lt;&amp;lt; 32);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
uint64 hash_platform(const char* platform) {&lt;br /&gt;
        uint8* md = malloc(SHA_DIGEST_LENGTH);&lt;br /&gt;
        SHA1(platform, strlen(platform), md);&lt;br /&gt;
        &lt;br /&gt;
        uint64 hash = u32_to_u64(&lt;br /&gt;
                                                         ((md[0] &amp;lt;&amp;lt; 24) | (md[1] &amp;lt;&amp;lt; 16) | (md[2] &amp;lt;&amp;lt; 8) | md[3]),&lt;br /&gt;
                                                         ((md[4] &amp;lt;&amp;lt; 24) | (md[5] &amp;lt;&amp;lt; 16) | (md[6] &amp;lt;&amp;lt; 8) | md[7])&lt;br /&gt;
                                                         );&lt;br /&gt;
        free(md);&lt;br /&gt;
        return hash;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
uint64 ramdisk_size(const char* ramdisk) {&lt;br /&gt;
        struct stat filestat;&lt;br /&gt;
        if(stat(ramdisk, &amp;amp;filestat) &amp;lt; 0) {&lt;br /&gt;
                return 0;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return (uint64)filestat.st_size;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void keydump(uint8* passphrase,int l) {&lt;br /&gt;
        int i=0;&lt;br /&gt;
        for(i=0; i&amp;lt;l; i++) {&lt;br /&gt;
                printf(&amp;quot;%02x&amp;quot;, passphrase[i]);&lt;br /&gt;
        } printf(&amp;quot;\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int compare(const uint32* a, const uint32* b) {&lt;br /&gt;
        if(*a &amp;lt; *b) return -1;&lt;br /&gt;
        if(*a &amp;gt; *b) return 1;&lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
const char platform[]=&amp;quot;s5l8900x&amp;quot;;&lt;br /&gt;
const char ramdisk[]=&amp;quot;ramdisk.dmg&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char* argv[]) {&lt;br /&gt;
        &lt;br /&gt;
        if(argc&amp;lt;3) {printf(&amp;quot;%s: &amp;lt;platform&amp;gt; &amp;lt;ramdisk&amp;gt; &amp;lt;main&amp;gt;\n&amp;quot;, argv[0]); return -1;}&lt;br /&gt;
        &lt;br /&gt;
        uint32 saltedHash[4];&lt;br /&gt;
        uint64 salt[4];&lt;br /&gt;
        &lt;br /&gt;
        salt[0] = 0xad79d29de5e2ac9e;&lt;br /&gt;
        salt[1] = 0xe6af2eb19e23925b;&lt;br /&gt;
        salt[2] = 0x3f1375b4bd88815c;&lt;br /&gt;
        salt[3] = 0x3bdff4e5564a9f87;&lt;br /&gt;
        &lt;br /&gt;
        FILE* fd = fopen(argv[2], &amp;quot;rb&amp;quot;);&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        int x = 0;&lt;br /&gt;
        SHA256_CTX ctx;&lt;br /&gt;
        uint8* buffer = NULL;&lt;br /&gt;
        uint8* passphrase = NULL;&lt;br /&gt;
        uint64 totalSize = ramdisk_size(argv[2]);&lt;br /&gt;
        uint64 platformHash = hash_platform(argv[1]);&lt;br /&gt;
        &lt;br /&gt;
        /*printf(&amp;quot;size: %I64x  plat: %s  plathash %I64x\n&amp;quot;, totalSize,&lt;br /&gt;
         platform,platformHash);*/&lt;br /&gt;
        &lt;br /&gt;
        for(i=0;i&amp;lt;4;i++)&lt;br /&gt;
        {&lt;br /&gt;
                salt[i]+=platformHash;&lt;br /&gt;
                //printf(&amp;quot;%d: %I64x\n&amp;quot;, i, salt[i]);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        for(i = 0; i &amp;lt; 4; i++) {&lt;br /&gt;
                saltedHash[i] = ((uint32)(salt[i] % totalSize)) &amp;amp; 0xFFFFFE00;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        qsort(&amp;amp;saltedHash, 4, 4, &amp;amp;compare);&lt;br /&gt;
        &lt;br /&gt;
        SHA256_Init(&amp;amp;ctx);&lt;br /&gt;
        SHA256_Update(&amp;amp;ctx, salt, 32);&lt;br /&gt;
        &lt;br /&gt;
        &lt;br /&gt;
        int r=0;&lt;br /&gt;
        i=0;    //hash count&lt;br /&gt;
        &lt;br /&gt;
        buffer = malloc(BUF_SIZE);&lt;br /&gt;
        passphrase = malloc(SHA256_DIGEST_LENGTH);&lt;br /&gt;
        &lt;br /&gt;
        while(r&amp;lt;totalSize) {&lt;br /&gt;
                x = fread(buffer, 1, BUF_SIZE, fd);&lt;br /&gt;
                SHA256_Update(&amp;amp;ctx, buffer, x);&lt;br /&gt;
                &lt;br /&gt;
                if(i&amp;lt;4)         //some salts remain&lt;br /&gt;
                {&lt;br /&gt;
                        if(r &amp;gt;= (saltedHash[i]+0x4000)) i++;&lt;br /&gt;
                        else if(  r &amp;lt; saltedHash[i] &amp;amp;&amp;amp; saltedHash[i] &amp;lt; (r+x) )&lt;br /&gt;
                        {&lt;br /&gt;
                                if( (saltedHash[i]+0x4000) &amp;lt; r ) &lt;br /&gt;
                                        SHA256_Update(&amp;amp;ctx, buffer, saltedHash[i]-r);&lt;br /&gt;
                                else SHA256_Update(&amp;amp;ctx, buffer+(saltedHash[i]-r), &lt;br /&gt;
                                                                   ( (x-(saltedHash[i]-r))&amp;lt;0x4000) ? (x-(saltedHash[i]-r)) : 0x4000 );&lt;br /&gt;
                        }&lt;br /&gt;
                }&lt;br /&gt;
                r+=x;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        fclose(fd);&lt;br /&gt;
        &lt;br /&gt;
        SHA256_Final(passphrase, &amp;amp;ctx);&lt;br /&gt;
        printf(&amp;quot;passphrase: &amp;quot;);&lt;br /&gt;
        keydump(passphrase, SHA256_DIGEST_LENGTH);&lt;br /&gt;
        &lt;br /&gt;
        if(buffer) free(buffer);&lt;br /&gt;
        &lt;br /&gt;
        if(argc==4)             //do main as well&lt;br /&gt;
        {&lt;br /&gt;
                fd=fopen(argv[3],&amp;quot;rb&amp;quot;);&lt;br /&gt;
                EVP_CIPHER_CTX ctx;&lt;br /&gt;
                &lt;br /&gt;
                int offset=0x1D4;&lt;br /&gt;
                uint8 data[0x30];&lt;br /&gt;
                uint8 out[0x30]; int outlen,tmplen;&lt;br /&gt;
                int a;&lt;br /&gt;
                for(a=0;a&amp;lt;7;a++)&lt;br /&gt;
                {&lt;br /&gt;
                        fseek(fd, offset, SEEK_SET); offset+=0x268;&lt;br /&gt;
                        fread(data, 1, 0x30, fd);&lt;br /&gt;
                        EVP_CIPHER_CTX_init(&amp;amp;ctx);&lt;br /&gt;
                        EVP_DecryptInit_ex(&amp;amp;ctx, EVP_des_ede3_cbc(),&lt;br /&gt;
                                                           NULL, passphrase, &amp;amp;passphrase[24]);&lt;br /&gt;
                        EVP_DecryptUpdate(&amp;amp;ctx, out, &amp;amp;outlen, data, 0x30);&lt;br /&gt;
                        if(!EVP_DecryptFinal_ex(&amp;amp;ctx, out + outlen, &amp;amp;tmplen))&lt;br /&gt;
                                printf(&amp;quot;not block %d\n&amp;quot;, a);&lt;br /&gt;
                        else&lt;br /&gt;
                                break;&lt;br /&gt;
                }&lt;br /&gt;
                printf(&amp;quot;vfdecryptk: &amp;quot;);&lt;br /&gt;
                keydump(out, 0x24);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        if(passphrase) free(passphrase);&lt;br /&gt;
        &lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:VFDecrypt]]&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=Talk:Ramdisk_Hack&amp;diff=6291</id>
		<title>Talk:Ramdisk Hack</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=Talk:Ramdisk_Hack&amp;diff=6291"/>
		<updated>2010-04-30T00:11:09Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: /* To the idiot that wrote the last comment about Zibri */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is just a 'overall' explanations to give someone that is not involved a 'clue'.&lt;br /&gt;
&lt;br /&gt;
Could please someone explain more specifically to enable an experienced user to follow the hack?&lt;br /&gt;
&lt;br /&gt;
== Ramdisk Hack ==&lt;br /&gt;
&lt;br /&gt;
It's not difficult at all. You just send a file to 1.1.4 or lower iBoot (iphuc: sendfiletophone or something) then &amp;quot;change&amp;quot; some boot-args. -wEsTbAeR--&lt;br /&gt;
&lt;br /&gt;
I believe that it is not difficult. But where do you put the file and how do you change boot args. And how you put the file there, because at this point it isn't jailbreaked yet!? -caique2001-&lt;br /&gt;
&lt;br /&gt;
== Re: Ramdisk Hack ==&lt;br /&gt;
&lt;br /&gt;
We don't talk to the iPhone via AFC. We talk to the iBoot (Recovery Mode), which is implemented in iPHUC too.&lt;br /&gt;
In iBoot you upload a file to RAM (no jailbreak required) and then change boot-args to boot it.&lt;br /&gt;
&lt;br /&gt;
* setenv boot-args rd=md0 -s -x pmd0=0x9340000.0xA00000&lt;br /&gt;
* saveenv&lt;br /&gt;
* fsboot&lt;br /&gt;
&lt;br /&gt;
I'm not sure about the last command, you must try it. If it does not work, try 'bootx'.&lt;br /&gt;
&lt;br /&gt;
- wEsTbAeR--&lt;br /&gt;
&lt;br /&gt;
== To the idiot that wrote the last comment about Zibri ==&lt;br /&gt;
&lt;br /&gt;
Get the fuck out of the community, and stop sucking dick. This is for facts, not fanboism.&lt;br /&gt;
&lt;br /&gt;
//cmdshft&lt;br /&gt;
&lt;br /&gt;
cmdshift: you are the idiot. it was a joke, and i believe it was posted by a member of the dev team, planetbeing. saying that he &amp;quot;invented ramdisks&amp;quot; and their workings is absolutely ridiculous, and that sir, is a fact. get over yourself.&lt;br /&gt;
&lt;br /&gt;
// gojohnnyboi&lt;br /&gt;
&lt;br /&gt;
How the fuck are you supposed to tell that it is a joke without at least a comment in the discussion page? People have been known to still give him way more credit than he deserves.&lt;br /&gt;
&lt;br /&gt;
// cmdshft&lt;br /&gt;
&lt;br /&gt;
because maybe... well.. um... its all an extreme hyperbole? of course he didn't invent ramdisks.&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=Talk:Ramdisk_Hack&amp;diff=6280</id>
		<title>Talk:Ramdisk Hack</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=Talk:Ramdisk_Hack&amp;diff=6280"/>
		<updated>2010-04-29T03:20:37Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: /* To the idiot that wrote the last comment about Zibri */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is just a 'overall' explanations to give someone that is not involved a 'clue'.&lt;br /&gt;
&lt;br /&gt;
Could please someone explain more specifically to enable an experienced user to follow the hack?&lt;br /&gt;
&lt;br /&gt;
== Ramdisk Hack ==&lt;br /&gt;
&lt;br /&gt;
It's not difficult at all. You just send a file to 1.1.4 or lower iBoot (iphuc: sendfiletophone or something) then &amp;quot;change&amp;quot; some boot-args. -wEsTbAeR--&lt;br /&gt;
&lt;br /&gt;
I believe that it is not difficult. But where do you put the file and how do you change boot args. And how you put the file there, because at this point it isn't jailbreaked yet!? -caique2001-&lt;br /&gt;
&lt;br /&gt;
== Re: Ramdisk Hack ==&lt;br /&gt;
&lt;br /&gt;
We don't talk to the iPhone via AFC. We talk to the iBoot (Recovery Mode), which is implemented in iPHUC too.&lt;br /&gt;
In iBoot you upload a file to RAM (no jailbreak required) and then change boot-args to boot it.&lt;br /&gt;
&lt;br /&gt;
* setenv boot-args rd=md0 -s -x pmd0=0x9340000.0xA00000&lt;br /&gt;
* saveenv&lt;br /&gt;
* fsboot&lt;br /&gt;
&lt;br /&gt;
I'm not sure about the last command, you must try it. If it does not work, try 'bootx'.&lt;br /&gt;
&lt;br /&gt;
- wEsTbAeR--&lt;br /&gt;
&lt;br /&gt;
== To the idiot that wrote the last comment about Zibri ==&lt;br /&gt;
&lt;br /&gt;
Get the fuck out of the community, and stop sucking dick. This is for facts, not fanboism.&lt;br /&gt;
&lt;br /&gt;
//cmdshft&lt;br /&gt;
&lt;br /&gt;
cmdshift: you are the idiot. it was a joke, and i believe it was posted by a member of the dev team, planetbeing. saying that he &amp;quot;invented ramdisks&amp;quot; and their workings is absolutely ridiculous, and that sir, is a fact. get over yourself.&lt;br /&gt;
&lt;br /&gt;
// gojohnnyboi&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=User_talk:Dialexio&amp;diff=5934</id>
		<title>User talk:Dialexio</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=User_talk:Dialexio&amp;diff=5934"/>
		<updated>2010-03-28T04:00:30Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;hey i need help&lt;br /&gt;
&lt;br /&gt;
with...?&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5916</id>
		<title>MobileDevice Library</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5916"/>
		<updated>2010-03-24T20:23:46Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MobileDevice Library is used by [[iTunes]] to transfer data between iPhone and computer over the USB connection.&lt;br /&gt;
&lt;br /&gt;
===PC Windows : iTunesMobileDevice.dll===&lt;br /&gt;
&lt;br /&gt;
* Location : Location is stored in '''iTunesMobileDeviceDLL''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Mobile Device Support\Shared''' key. Usually - C:\Program Files\Common Files\Apple\Mobile Device Support\bin\iTunesMobileDevice.dll.&lt;br /&gt;
&lt;br /&gt;
* Supporting CoreFoundation.dll (used for CFStringRef, CFPropertyListRef management) is located in the same dir (when using iTunes prior 9.0). &lt;br /&gt;
&lt;br /&gt;
* For iTunes 9.0 location of CoreFoundation.dll is stored in '''InstallDir''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Application Support''' key, usually C:\Program Files\Common Files\Apple\Apple Application Support\. CoreFoundation.dll from Mobile Device Support\bin should not be used.&lt;br /&gt;
&lt;br /&gt;
===Mac OSX : MobileDevice.framework===&lt;br /&gt;
&lt;br /&gt;
* Location : /System/Library/PrivateFrameworks/MobileDevice.framework&lt;br /&gt;
* Export command : &amp;quot;nm /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===MobileDevice Header (mobiledevice.h)===&lt;br /&gt;
&lt;br /&gt;
Reverse engineered C header for MobileDevice Library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* ----------------------------------------------------------------------------&lt;br /&gt;
 *   MobileDevice.h - interface to MobileDevice.framework &lt;br /&gt;
 * ------------------------------------------------------------------------- */&lt;br /&gt;
#pragma once&lt;br /&gt;
&lt;br /&gt;
#ifndef MOBILEDEVICE_H&lt;br /&gt;
#define MOBILEDEVICE_H&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
extern &amp;quot;C&amp;quot; {&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
#ifndef __GCC__&lt;br /&gt;
#pragma pack&lt;br /&gt;
#define __PACK&lt;br /&gt;
#else&lt;br /&gt;
#define __PACK __attribute__((__packed__))&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#if defined(WIN32)&lt;br /&gt;
#define __DLLIMPORT [DllImport(&amp;quot;iTunesMobileDevice.dll&amp;quot;)]&lt;br /&gt;
	using namespace System::Runtime::InteropServices;&lt;br /&gt;
#include &amp;lt;CoreFoundation.h&amp;gt;&lt;br /&gt;
	typedef unsigned int mach_error_t;&lt;br /&gt;
#elif defined(__APPLE__)&lt;br /&gt;
#define __DLLIMPORT&lt;br /&gt;
#include &amp;lt;CoreFoundation/CoreFoundation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;mach/error.h&amp;gt;&lt;br /&gt;
#endif	&lt;br /&gt;
	&lt;br /&gt;
	/* Error codes */&lt;br /&gt;
#define MDERR_APPLE_MOBILE  (err_system(0x3a))&lt;br /&gt;
#define MDERR_IPHONE        (err_sub(0))&lt;br /&gt;
	&lt;br /&gt;
	/* Apple Mobile (AM*) errors */&lt;br /&gt;
#define MDERR_OK                ERR_SUCCESS&lt;br /&gt;
#define MDERR_SYSCALL           (ERR_MOBILE_DEVICE | 0x01)&lt;br /&gt;
#define MDERR_OUT_OF_MEMORY     (ERR_MOBILE_DEVICE | 0x03)&lt;br /&gt;
#define MDERR_QUERY_FAILED      (ERR_MOBILE_DEVICE | 0x04) &lt;br /&gt;
#define MDERR_INVALID_ARGUMENT  (ERR_MOBILE_DEVICE | 0x0b)&lt;br /&gt;
#define MDERR_DICT_NOT_LOADED   (ERR_MOBILE_DEVICE | 0x25)&lt;br /&gt;
	&lt;br /&gt;
	/* Apple File Connection (AFC*) errors */&lt;br /&gt;
#define MDERR_AFC_OUT_OF_MEMORY 0x03&lt;br /&gt;
	&lt;br /&gt;
	/* USBMux errors */&lt;br /&gt;
#define MDERR_USBMUX_ARG_NULL   0x16&lt;br /&gt;
#define MDERR_USBMUX_FAILED     0xffffffff&lt;br /&gt;
	&lt;br /&gt;
	/* Messages passed to device notification callbacks: passed as part of&lt;br /&gt;
	 * am_device_notification_callback_info. */&lt;br /&gt;
#define ADNCI_MSG_CONNECTED     1&lt;br /&gt;
#define ADNCI_MSG_DISCONNECTED  2&lt;br /&gt;
#define ADNCI_MSG_UNSUBSCRIBED  3&lt;br /&gt;
	&lt;br /&gt;
#define AMD_IPHONE_PRODUCT_ID   0x1290&lt;br /&gt;
	//#define AMD_IPHONE_SERIAL       &amp;quot;&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
	/* Services, found in /System/Library/Lockdown/Services.plist */&lt;br /&gt;
#define AMSVC_AFC                   CFSTR(&amp;quot;com.apple.afc&amp;quot;)&lt;br /&gt;
#define AMSVC_BACKUP                CFSTR(&amp;quot;com.apple.mobilebackup&amp;quot;)&lt;br /&gt;
#define AMSVC_CRASH_REPORT_COPY     CFSTR(&amp;quot;com.apple.crashreportcopy&amp;quot;)&lt;br /&gt;
#define AMSVC_DEBUG_IMAGE_MOUNT     CFSTR(&amp;quot;com.apple.mobile.debug_image_mount&amp;quot;)&lt;br /&gt;
#define AMSVC_NOTIFICATION_PROXY    CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;)&lt;br /&gt;
#define AMSVC_PURPLE_TEST           CFSTR(&amp;quot;com.apple.purpletestr&amp;quot;)&lt;br /&gt;
#define AMSVC_SOFTWARE_UPDATE       CFSTR(&amp;quot;com.apple.mobile.software_update&amp;quot;)&lt;br /&gt;
#define AMSVC_SYNC                  CFSTR(&amp;quot;com.apple.mobilesync&amp;quot;)&lt;br /&gt;
#define AMSVC_SCREENSHOT            CFSTR(&amp;quot;com.apple.screenshotr&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSLOG_RELAY          CFSTR(&amp;quot;com.apple.syslog_relay&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSTEM_PROFILER       CFSTR(&amp;quot;com.apple.mobile.system_profiler&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned int afc_error_t;&lt;br /&gt;
	typedef unsigned int usbmux_error_t;&lt;br /&gt;
	&lt;br /&gt;
	struct am_recovery_device;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification_callback_info {&lt;br /&gt;
		struct am_device *dev;  /* 0    device */ &lt;br /&gt;
		unsigned int msg;       /* 4    one of ADNCI_MSG_* */&lt;br /&gt;
                struct am_device_notification* subscription; &lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
	&lt;br /&gt;
	/* This is a CoreFoundation object of class AMRecoveryModeDevice. */&lt;br /&gt;
	struct am_recovery_device {&lt;br /&gt;
		unsigned char unknown0[8];                          /* 0 */&lt;br /&gt;
		am_restore_device_notification_callback callback;   /* 8 */&lt;br /&gt;
		void *user_info;                                    /* 12 */&lt;br /&gt;
		unsigned char unknown1[12];                         /* 16 */&lt;br /&gt;
		unsigned int readwrite_pipe;                        /* 28 */&lt;br /&gt;
		unsigned char read_pipe;                            /* 32 */&lt;br /&gt;
		unsigned char write_ctrl_pipe;                      /* 33 */&lt;br /&gt;
		unsigned char read_unknown_pipe;                    /* 34 */&lt;br /&gt;
		unsigned char write_file_pipe;                      /* 35 */&lt;br /&gt;
		unsigned char write_input_pipe;                     /* 36 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* A CoreFoundation object of class AMRestoreModeDevice. */&lt;br /&gt;
	struct am_restore_device {&lt;br /&gt;
		unsigned char unknown[32];&lt;br /&gt;
		int port;&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device notification callback function. */&lt;br /&gt;
	typedef void(*am_device_notification_callback)(struct am_device_notification_callback_info *, int cookie);&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the _AMDDeviceAttached function.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void *amd_device_attached_callback;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
&lt;br /&gt;
	/* Structure that contains internal data used by AMDevice... functions. Never try &lt;br /&gt;
         * to access its members directly! Use AMDeviceCopyDeviceIdentifier, &lt;br /&gt;
         * AMDeviceGetConnectionID, AMDeviceRetain, AMDeviceRelease instead. */&lt;br /&gt;
	struct am_device {&lt;br /&gt;
		unsigned char unknown0[16]; /* 0 - zero */&lt;br /&gt;
		unsigned int device_id;     /* 16 */&lt;br /&gt;
		unsigned int product_id;    /* 20 - set to AMD_IPHONE_PRODUCT_ID */&lt;br /&gt;
		char *serial;               /* 24 - set to UDID, Unique Device Identifier */&lt;br /&gt;
		unsigned int unknown1;      /* 28 */&lt;br /&gt;
		unsigned int unknown2;      /* 32 - reference counter, increased by AMDeviceRetain, decreased by AMDeviceRelease*/&lt;br /&gt;
		unsigned int lockdown_conn; /* 36 */&lt;br /&gt;
		unsigned char unknown3[8];  /* 40 */&lt;br /&gt;
#if (__ITUNES_VER &amp;gt; 740)&lt;br /&gt;
		unsigned int unknown4;      /* 48 - used to store CriticalSection Handle*/&lt;br /&gt;
#endif&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
		unsigned char unknown5[24];  /* 52 */&lt;br /&gt;
#endif&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification {&lt;br /&gt;
		unsigned int unknown0;                      /* 0 */&lt;br /&gt;
		unsigned int unknown1;                      /* 4 */&lt;br /&gt;
		unsigned int unknown2;                      /* 8 */&lt;br /&gt;
		am_device_notification_callback callback;   /* 12 */ &lt;br /&gt;
		unsigned int cookie;                      /* 16 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct afc_connection {&lt;br /&gt;
		unsigned int handle;            /* 0 */&lt;br /&gt;
		unsigned int unknown0;          /* 4 */&lt;br /&gt;
		unsigned char unknown1;         /* 8 */&lt;br /&gt;
		unsigned char padding[3];       /* 9 */&lt;br /&gt;
		unsigned int unknown2;          /* 12 */&lt;br /&gt;
		unsigned int unknown3;          /* 16 */&lt;br /&gt;
		unsigned int unknown4;          /* 20 */&lt;br /&gt;
		unsigned int fs_block_size;     /* 24 */&lt;br /&gt;
		unsigned int sock_block_size;   /* 28: always 0x3c */&lt;br /&gt;
		unsigned int io_timeout;        /* 32: from AFCConnectionOpen, usu. 0 */&lt;br /&gt;
		void *afc_lock;                 /* 36 */&lt;br /&gt;
		unsigned int context;           /* 40 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
	struct afc_device_info {&lt;br /&gt;
		unsigned char unknown[12];  /* 0 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_directory {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_dictionary {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned long long afc_file_ref;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_1 {                  /* offset   value in iTunes */&lt;br /&gt;
		unsigned int unknown0;                  /* 0        1 */&lt;br /&gt;
		unsigned char *unknown1;                /* 4        ptr, maybe device? */&lt;br /&gt;
		amd_device_attached_callback callback;  /* 8        _AMDDeviceAttached */&lt;br /&gt;
		unsigned int unknown3;                  /* 12 */&lt;br /&gt;
		unsigned int unknown4;                  /* 16 */&lt;br /&gt;
		unsigned int unknown5;                  /* 20 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_2 {&lt;br /&gt;
		unsigned char unknown0[4144];&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_bootloader_control_packet {&lt;br /&gt;
		unsigned char opcode;       /* 0 */&lt;br /&gt;
		unsigned char length;       /* 1 */&lt;br /&gt;
		unsigned char magic[2];     /* 2: 0x34, 0x12 */&lt;br /&gt;
		unsigned char payload[0];   /* 4 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Registers a notification with the current run loop. The callback gets&lt;br /&gt;
	 *  copied into the notification struct, as well as being registered with the&lt;br /&gt;
	 *  current run loop. Cookie gets copied into cookie in the same.&lt;br /&gt;
	 *  (Cookie is a user info parameter that gets passed as an arg to&lt;br /&gt;
	 *  the callback) unused0 and unused1 are both 0 when iTunes calls this.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Never try to acces directly or copy contents of dev and subscription fields &lt;br /&gt;
	 *  in am_device_notification_callback_info. Treat them as abstract handles. &lt;br /&gt;
	 *  When done with connection use AMDeviceRelease to free resources allocated for am_device.&lt;br /&gt;
	 *  &lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK            if successful&lt;br /&gt;
	 *      MDERR_SYSCALL       if CFRunLoopAddSource() failed&lt;br /&gt;
	 *      MDERR_OUT_OF_MEMORY if we ran out of memory&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationSubscribe(am_device_notification_callback callback, &lt;br /&gt;
								unsigned int unused0, unsigned int unused1, &lt;br /&gt;
								unsigned int cookie, &lt;br /&gt;
								struct am_device_notification **subscription);&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
        /* Unregisters notifications. Buggy (iTunes 8.2): if you subscribe, unsubscribe and subscribe again, arriving &lt;br /&gt;
           notifications will contain cookie and subscription from 1st call to subscribe, not the 2nd one. iTunes &lt;br /&gt;
           calls this function only once on exit.&lt;br /&gt;
        */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationUnsubscribe(am_device_notification* subscription);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns device_id field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMDeviceGetConnectionID(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns serial field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyDeviceIdentifier(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Connects to the iPhone. Pass in the am_device structure that the&lt;br /&gt;
	 *  notification callback will give to you.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successfully connected&lt;br /&gt;
	 *      MDERR_SYSCALL           if setsockopt() failed&lt;br /&gt;
	 *      MDERR_QUERY_FAILED      if the daemon query failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if USBMuxConnectByPort returned 0xffffffff&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceConnect(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Calls PairingRecordPath() on the given device, than tests whether the path&lt;br /&gt;
	 *  which that function returns exists. During the initial connect, the path&lt;br /&gt;
	 *  returned by that function is '/', and so this returns 1.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      0   if the path did not exist&lt;br /&gt;
	 *      1   if it did&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceIsPaired(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDevicePair(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  iTunes calls this function immediately after testing whether the device is&lt;br /&gt;
	 *  paired. It creates a pairing file and establishes a Lockdown connection.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the supplied device is null&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceValidatePairing(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Creates a Lockdown session and adjusts the device structure appropriately&lt;br /&gt;
	 *  to indicate that the session has been started. iTunes calls this function&lt;br /&gt;
	 *  after validating pairing.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartSession(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* Reads various device settings. One of domain or cfstring arguments should be NULL.&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for cfstring:&lt;br /&gt;
	 * ActivationState&lt;br /&gt;
	 * ActivationStateAcknowledged&lt;br /&gt;
	 * BasebandBootloaderVersion&lt;br /&gt;
	 * BasebandVersion&lt;br /&gt;
	 * BluetoothAddress&lt;br /&gt;
	 * BuildVersion&lt;br /&gt;
	 * DeviceCertificate&lt;br /&gt;
	 * DeviceClass&lt;br /&gt;
	 * DeviceName&lt;br /&gt;
	 * DevicePublicKey&lt;br /&gt;
	 * FirmwareVersion&lt;br /&gt;
	 * HostAttached&lt;br /&gt;
	 * IntegratedCircuitCardIdentity&lt;br /&gt;
	 * InternationalMobileEquipmentIdentity&lt;br /&gt;
	 * InternationalMobileSubscriberIdentity&lt;br /&gt;
	 * ModelNumber&lt;br /&gt;
	 * PhoneNumber&lt;br /&gt;
	 * ProductType&lt;br /&gt;
	 * ProductVersion&lt;br /&gt;
	 * ProtocolVersion&lt;br /&gt;
	 * RegionInfo&lt;br /&gt;
	 * SBLockdownEverRegisteredKey&lt;br /&gt;
	 * SIMStatus&lt;br /&gt;
	 * SerialNumber&lt;br /&gt;
	 * SomebodySetTimeZone&lt;br /&gt;
	 * TimeIntervalSince1970&lt;br /&gt;
	 * TimeZone&lt;br /&gt;
	 * TimeZoneOffsetFromUTC&lt;br /&gt;
	 * TrustedHostAttached&lt;br /&gt;
	 * UniqueDeviceID&lt;br /&gt;
	 * Uses24HourClock&lt;br /&gt;
	 * WiFiAddress&lt;br /&gt;
	 * iTunesHasConnected&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for domain:&lt;br /&gt;
         * com.apple.mobile.battery&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyValue(struct am_device *device, CFStringRef domain, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* Starts a service and returns a socket file descriptor that can be used in order to further&lt;br /&gt;
	 * access the service. You should stop the session and disconnect before using&lt;br /&gt;
	 * the service. iTunes calls this function after starting a session. It starts &lt;br /&gt;
	 * the service and the SSL connection. service_name should be one of the AMSVC_*&lt;br /&gt;
	 * constants.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_SYSCALL           if the setsockopt() call failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartService(struct am_device *device, CFStringRef &lt;br /&gt;
									  service_name, int *socket_fd);&lt;br /&gt;
	&lt;br /&gt;
	/* Stops a session. You should do this before accessing services.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStopSession(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/* Decrements reference counter and, if nothing left, releases resources hold &lt;br /&gt;
	 * by connection, invalidates  pointer to device&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRelease(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Increments reference counter&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRetain(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Opens an Apple File Connection. You must start the appropriate service&lt;br /&gt;
	 * first with AMDeviceStartService(). In iTunes, io_timeout is 0.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_AFC_OUT_OF_MEMORY if malloc() failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionOpen(int socket_fd, unsigned int io_timeout,&lt;br /&gt;
								  struct afc_connection **conn);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        /* Copy an enviromental variable value from iBoot&lt;br /&gt;
         */&lt;br /&gt;
        __DLLIMPORT CFStringRef AMRecoveryModeCopyEnvironmentVariable(struct am_recovery_device *rdev, CFStringRef var);&lt;br /&gt;
	&lt;br /&gt;
	/* Pass in a pointer to an afc_dictionary structure. It will be filled. You can&lt;br /&gt;
	 * iterate it using AFCKeyValueRead. When done use AFCKeyValueClose. Possible keys:&lt;br /&gt;
	 * FSFreeBytes - free bytes on system device for afc2, user device for afc&lt;br /&gt;
	 * FSBlockSize - filesystem block size&lt;br /&gt;
	 * FSTotalBytes - size of device&lt;br /&gt;
	 * Model - iPhone1,1 etc.&lt;br /&gt;
&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDeviceInfoOpen(struct afc_connection *conn, struct&lt;br /&gt;
								  afc_dictionary **info);&lt;br /&gt;
	&lt;br /&gt;
	/* Turns debug mode on if the environment variable AFCDEBUG is set to a numeric&lt;br /&gt;
	 * value, or if the file '/AFCDEBUG' is present and contains a value. */&lt;br /&gt;
#if defined(__APPLE__)&lt;br /&gt;
	void AFCPlatformInitialize();&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
	/* Opens a directory on the iPhone. Pass in a pointer in dir to be filled in.&lt;br /&gt;
	 * Note that this normally only accesses the iTunes sandbox/partition as the&lt;br /&gt;
	 * root, which is /var/root/Media. Pathnames are specified with '/' delimiters&lt;br /&gt;
	 * as in Unix style. Use UTF-8 to specify non-ASCII symbols in path.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								 afc_directory **dir);&lt;br /&gt;
	&lt;br /&gt;
	/* Acquires the next entry in a directory previously opened with&lt;br /&gt;
	 * AFCDirectoryOpen(). When dirent is filled with a NULL value, then the end&lt;br /&gt;
	 * of the directory has been reached. '.' and '..' will be returned as the&lt;br /&gt;
	 * first two entries in each directory except the root; you may want to skip&lt;br /&gt;
	 * over them.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful, even if no entries remain&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryRead(struct afc_connection *conn, struct afc_directory *dir,&lt;br /&gt;
								 char **dirent);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryClose(afc_connection *conn, struct afc_directory *dir);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryCreate(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRemovePath(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRenamePath(afc_connection *conn, char *oldpath, char *newpath);&lt;br /&gt;
&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
	/* Creates symbolic or hard link&lt;br /&gt;
         * linktype - int64: 1 means hard link, 2 - soft (symbolic) link&lt;br /&gt;
         * target - absolute or relative path to link target&lt;br /&gt;
         * linkname - absolute path where to create new link&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCLinkPath(struct afc_connection *conn, long long int linktype, const char *target, &lt;br /&gt;
								                              const char *linkname);&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
	/* Opens file for reading or writing without locking it in any way. afc_file_ref should not be shared between threads - &lt;br /&gt;
         * opening file in one thread and closing it in another will lead to possible crash.&lt;br /&gt;
	 * path - UTF-8 encoded absolute path to file&lt;br /&gt;
	 * mode 2 = read, mode 3 = write; unknown = 0 &lt;br /&gt;
	 * ref - receives file handle&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefOpen(struct afc_connection *conn, char *path, unsigned&lt;br /&gt;
							   long long int mode, afc_file_ref *ref);&lt;br /&gt;
	/* Reads specified amount (len) of bytes from file into buf. Puts actual count of read bytes into len on return&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefRead(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   void *buf, unsigned int *len);&lt;br /&gt;
	/* Writes specified amount (len) of bytes from buf into file.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefWrite(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
								void *buf, unsigned int len);&lt;br /&gt;
	/* Moves the file pointer to a specified location.&lt;br /&gt;
	 * offset - Number of bytes from origin (int64)&lt;br /&gt;
	 * origin - 0 = from beginning, 1 = from current position, 2 = from end&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefSeek(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long offset, int origin, int unused);&lt;br /&gt;
&lt;br /&gt;
	/* Gets the current position of a file pointer into offset argument.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefTell(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long* offset);&lt;br /&gt;
&lt;br /&gt;
	/*  Truncates a file at the specified offset.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefSetFileSize(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long offset);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefLock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefUnlock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefClose(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
&lt;br /&gt;
	/* Opens dictionary describing specified file or directory (iTunes below 8.2 allowed using AFCGetFileInfo&lt;br /&gt;
	   to get the same information)&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileInfoOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								afc_dictionary **info);&lt;br /&gt;
&lt;br /&gt;
	/* Reads next entry from dictionary. When last entry is read, function returns NULL in key argument&lt;br /&gt;
	   Possible keys:&lt;br /&gt;
	     &amp;quot;st_size&amp;quot;:     val - size in bytes&lt;br /&gt;
	     &amp;quot;st_blocks&amp;quot;:   val - size in blocks&lt;br /&gt;
	     &amp;quot;st_nlink&amp;quot;:    val - number of hardlinks&lt;br /&gt;
	     &amp;quot;st_ifmt&amp;quot;:     val - &amp;quot;S_IFDIR&amp;quot; for folders&lt;br /&gt;
	                        &amp;quot;S_IFLNK&amp;quot; for symlinks&lt;br /&gt;
	     &amp;quot;LinkTarget&amp;quot;:  val - path to symlink target&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueRead(struct afc_dictionary *dict, char **key, char **&lt;br /&gt;
								val);&lt;br /&gt;
	/* Closes dictionary&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueClose(struct afc_dictionary *dict);&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the context field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetContext(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the fs_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetFSBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the io_timeout field of the given AFC connection. In iTunes this is&lt;br /&gt;
	 * 0. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetIOTimeout(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the sock_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetSocketBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Closes the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionClose(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Registers for device notifications related to the restore process. unknown0&lt;br /&gt;
	 * is zero when iTunes calls this. In iTunes,&lt;br /&gt;
	 * the callbacks are located at:&lt;br /&gt;
	 *      1: $3ac68e-$3ac6b1, calls $3ac542(unknown1, arg, 0)&lt;br /&gt;
	 *      2: $3ac66a-$3ac68d, calls $3ac542(unknown1, 0, arg)&lt;br /&gt;
	 *      3: $3ac762-$3ac785, calls $3ac6b2(unknown1, arg, 0)&lt;br /&gt;
	 *      4: $3ac73e-$3ac761, calls $3ac6b2(unknown1, 0, arg)&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreRegisterForDeviceNotifications(&lt;br /&gt;
				am_restore_device_notification_callback dfu_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback dfu_disconnect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_disconnect_callback,&lt;br /&gt;
				unsigned int unknown0,&lt;br /&gt;
				void *user_info);&lt;br /&gt;
	&lt;br /&gt;
	/* Causes the restore functions to spit out (unhelpful) progress messages to&lt;br /&gt;
	 * the file specified by the given path. iTunes always calls this right before&lt;br /&gt;
	 * restoring with a path of&lt;br /&gt;
	 * &amp;quot;$HOME/Library/Logs/iPhone Updater Logs/iPhoneUpdater X.log&amp;quot;, where X is an&lt;br /&gt;
	 * unused number.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreEnableFileLogging(char *path);&lt;br /&gt;
	&lt;br /&gt;
	/* Initializes a new option dictionary to default values. Pass the constant&lt;br /&gt;
	 * kCFAllocatorDefault as the allocator. The option dictionary looks as&lt;br /&gt;
	 * follows:&lt;br /&gt;
	 * {&lt;br /&gt;
	 *      NORImageType =&amp;gt; 'production',&lt;br /&gt;
	 *      AutoBootDelay =&amp;gt; 0,&lt;br /&gt;
	 *      KernelCacheType =&amp;gt; 'Release',&lt;br /&gt;
	 *      UpdateBaseband =&amp;gt; true,&lt;br /&gt;
	 *      DFUFileType =&amp;gt; 'RELEASE',&lt;br /&gt;
	 *      SystemImageType =&amp;gt; 'User',&lt;br /&gt;
	 *      CreateFilesystemPartitions =&amp;gt; true,&lt;br /&gt;
	 *      FlashNOR =&amp;gt; true,&lt;br /&gt;
	 *      RestoreBootArgs =&amp;gt; 'rd=md0 nand-enable-reformat=1 -progress'&lt;br /&gt;
	 *      BootImageType =&amp;gt; 'User'&lt;br /&gt;
	 *  }&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      the option dictionary   if successful&lt;br /&gt;
	 *      NULL                    if out of memory&lt;br /&gt;
	 */ &lt;br /&gt;
	__DLLIMPORT CFMutableDictionaryRef AMRestoreCreateDefaultOptions(CFAllocatorRef allocator);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRecoveryModeRestore(struct am_recovery_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRestoreModeRestore(struct am_restore_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT struct am_restore_device *AMRestoreModeDeviceCreate(unsigned int unknown0,&lt;br /&gt;
				unsigned int connection_id, unsigned int unknown1);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreCreatePathsForBundle(CFStringRef restore_bundle_path,&lt;br /&gt;
				CFStringRef kernel_cache_type, CFStringRef boot_image_type, unsigned int&lt;br /&gt;
				unknown0, CFStringRef *firmware_dir_path, CFStringRef *&lt;br /&gt;
				kernelcache_restore_path, unsigned int unknown1, CFStringRef *&lt;br /&gt;
				ramdisk_path);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreModeDeviceReboot(struct am_restore_device *rdev);	// Added by JB 30.07.2008&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceEnterRecovery(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDisconnect(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* to use this, start the service &amp;quot;com.apple.mobile.notification_proxy&amp;quot;, handle will be the socket to use */&lt;br /&gt;
	typedef void (*NOTIFY_CALLBACK)(CFSTR notification, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDPostNotification(SOCKET socket, CFStringRef  notification, CFStringRef userinfo);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDObserveNotification(SOCKET socket, CFSTR notification);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDListenForNotifications(SOCKET socket, NOTIFY_CALLBACK cb, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDShutdownNotificationProxy(SOCKET socket);&lt;br /&gt;
	&lt;br /&gt;
	/*edits by geohot*/&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDeactivate(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceActivate(struct am_device *device, CFDictionaryRef dict);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceRemoveValue(struct am_device *device, unsigned int, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Pass in a usbmux_listener_1 structure and a usbmux_listener_2 structure&lt;br /&gt;
	 *  pointer, which will be filled with the resulting usbmux_listener_2.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if completed successfully&lt;br /&gt;
	 *      MDERR_USBMUX_ARG_NULL   if one of the arguments was NULL&lt;br /&gt;
	 *      MDERR_USBMUX_FAILED     if the listener was not created successfully&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerCreate(struct usbmux_listener_1 *esi_fp8, struct&lt;br /&gt;
										usbmux_listener_2 **eax_fp12);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerHandleData(void *);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Private routines - here be dragons&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/* AMRestorePerformRestoreModeRestore() calls this function with a dictionary&lt;br /&gt;
	 * in order to perform certain special restore operations&lt;br /&gt;
	 * (RESTORED_OPERATION_*). It is thought that this function might enable&lt;br /&gt;
	 * significant access to the phone. */&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef unsigned int (*t_performOperation)(struct am_restore_device *rdev,&lt;br /&gt;
	 CFDictionaryRef op) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_performOperation _performOperation = (t_performOperation)0x3c39fa4b;&lt;br /&gt;
	 */ &lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef int (*t_socketForPort)(struct am_restore_device *rdev, unsigned int port)&lt;br /&gt;
	 __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_socketForPort _socketForPort = (t_socketForPort)(void *)0x3c39f36c;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef void (*t_restored_send_message)(int port, CFDictionaryRef msg);&lt;br /&gt;
	 t_restored_send_message _restored_send_message = (t_restored_send_message)0x3c3a4e40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef CFDictionaryRef (*t_restored_receive_message)(int port);&lt;br /&gt;
	 t_restored_receive_message _restored_receive_message = (t_restored_receive_message)0x3c3a4d40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendControlPacket)(struct am_recovery_device *rdev, unsigned&lt;br /&gt;
	 int msg1, unsigned int msg2, unsigned int unknown0, unsigned int *unknown1,&lt;br /&gt;
	 unsigned char *unknown2) __attribute__ ((regparm(3)));&lt;br /&gt;
	 t_sendControlPacket _sendControlPacket = (t_sendControlPacket)0x3c3a3da3;;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendCommandToDevice)(struct am_recovery_device *rdev,&lt;br /&gt;
	 CFStringRef cmd) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_sendCommandToDevice _sendCommandToDevice = (t_sendCommandToDevice)0x3c3a3e3b;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceReadPipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int read_pipe, unsigned char *data, unsigned int *len);&lt;br /&gt;
	 t_AMRUSBInterfaceReadPipe _AMRUSBInterfaceReadPipe = (t_AMRUSBInterfaceReadPipe)0x3c3a27e8;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceWritePipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int write_pipe, void *data, unsigned int len);&lt;br /&gt;
	 t_AMRUSBInterfaceWritePipe _AMRUSBInterfaceWritePipe = (t_AMRUSBInterfaceWritePipe)0x3c3a27cb;&lt;br /&gt;
	 */&lt;br /&gt;
	&lt;br /&gt;
	int performOperation(am_restore_device *rdev, CFMutableDictionaryRef message);&lt;br /&gt;
	int socketForPort(am_restore_device *rdev, unsigned int portnum);&lt;br /&gt;
	int sendCommandToDevice(am_recovery_device *rdev, CFStringRef cfs, int block);&lt;br /&gt;
	int sendFileToDevice(am_recovery_device *rdev, CFStringRef filename); &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
}&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
/* -*- mode:c; indent-tabs-mode:nil; c-basic-offset:2; tab-width:2; */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===AFC Connection===&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
===Locking the Device for Sync===&lt;br /&gt;
When iTunes sends a new song to the device, the device shows a &amp;quot;Sync in progress&amp;quot; screen and when complete, the Music app on the device re-reads the iTunesDB file so it picks up the new song.&lt;br /&gt;
&lt;br /&gt;
To get this behaviour, first start the notification service:&lt;br /&gt;
&amp;lt;pre&amp;gt;SOCKET socket;&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we post a notificaton message to signal that we are going to start a sync:&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncWillStart&amp;quot;), NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we open the itunes lock file:&lt;br /&gt;
&amp;lt;pre&amp;gt;afc_file_ref lockref;&lt;br /&gt;
AFCFileRefOpen(conn, &amp;quot;/com.apple.itunes.lock_sync&amp;quot;, 2, &amp;amp;lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now post a notification to say we are going to lock this file, and try and lock it.&lt;br /&gt;
If the AFCFileRefLock call fails, pause and repeat.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncLockRequest&amp;quot;), NULL);&lt;br /&gt;
mach_error_t error = AFCFileRefLock(conn, lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the file is successfully locked, post another notification, and stop the notification service.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket,CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidStart&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the sync can proceed, so copy your files across and make the changes to the iTunesDB.&lt;br /&gt;
&lt;br /&gt;
To release the lock, start the notification system again, unlock and close the lock file, and send a sync finished notification message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;AFCFileRefUnlock(conn, lockref);&lt;br /&gt;
AFCFileRefClose(conn, lockref);&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&lt;br /&gt;
AMDPostNotification(socket, &amp;amp;CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidFinish&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To handle &amp;quot;Slide to Cancel&amp;quot; and terminate sync when user slides cancel switch, use AMDObserveNotification to subscribe notifications about “com.apple.itunes-client.syncCancelRequest”. Then start listening for notifications (AMDListenForNotifications) until you get “AMDNotificationFaceplant”.&lt;br /&gt;
When notification got, you should unlock and close lock file handle (don’t sure if you need to post “syncDidFinish” to proxy, seems it doesn’t matter) and terminate sync gracefully.&lt;br /&gt;
The same notification is also got when you unplug your device, so you should always be ready for errors.&lt;br /&gt;
&lt;br /&gt;
NOTE: You may find that starting the notification_proxy service once and once only at the start of your app and using the same socket in calls to AMDPostNotification works better. iTunes opens and closes the notification_proxy regularly, but it appears to be a bit flakey when you open/close it all the time.&lt;br /&gt;
&lt;br /&gt;
===Private Functions===&lt;br /&gt;
&lt;br /&gt;
====How to find address of privates functions in iTunesMobileDevice.dll or MobileDevice.framework====&lt;br /&gt;
&lt;br /&gt;
In order to obtain the address of a usable private function in MobileDevice, you will have to be able to understand x86-64 assembly to reverse engineer it. A private function will not have its name exported in the mach-o symbol table, so in a debugger, like GDB, it will show up as part of another function. However, you will know that it is a separate function as a new stack frame is set up.&lt;br /&gt;
&lt;br /&gt;
====Private Function Address List====&lt;br /&gt;
&lt;br /&gt;
=====OSX.6 - iTunes 9.0.2(25)=====&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendCommandToiBoot(struct am_recovery_device *rdev, CFStringRef command, int u);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 868(0x364) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym(). &lt;br /&gt;
Address: 0x1000245ea&lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
1. rdev - the device you wish to send the command to.&lt;br /&gt;
2. a CFStringRef of the command to send.&lt;br /&gt;
3. an integer, whose use is currently unknown, but should be set to 0 to work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendFileToiDevice(struct am_recovery_device *rdev, CFStringRef filename);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 1763(0x6e3) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym().&lt;br /&gt;
Address: 0x100024969&lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
1. rdev - the device you wish to send the file to.&lt;br /&gt;
2. a CFStringRef of the path to the file to send.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====OSX.6 - iTunes 9.0.3(15)=====&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendCommandToiBoot(struct am_recovery_device *rdev, CFStringRef command, int u);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Addresss: AMRecoveryDeviceGetProductType() + 0x37f(895); full offset: 0x2a0ed&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendFileToiDevice(struct am_recovery_device *rdev, CFStringRef filename);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address: AMRecoveryDeviceGetProductType()+0x6f3(1790); full offset: 0x2a46c&lt;br /&gt;
&lt;br /&gt;
===Libraries Implementations===&lt;br /&gt;
&lt;br /&gt;
* [http://gojohnnyboi.com/source/afcinstall.cpp afcinstall (command line, os x file install via afc)]&lt;br /&gt;
* [http://code.google.com/p/iphuc/ iPhuc (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/iphucwin32/ iPhuc Win32 (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/manzana/ manzana (.Net Library)]&lt;br /&gt;
* [http://code.google.com/p/independence/source/browse/trunk/libPhoneInteraction/ libPhoneInteraction (C Library)]&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5915</id>
		<title>MobileDevice Library</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5915"/>
		<updated>2010-03-21T22:25:47Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MobileDevice Library is used by [[iTunes]] to transfer data between iPhone and computer over the USB connection.&lt;br /&gt;
&lt;br /&gt;
===PC Windows : iTunesMobileDevice.dll===&lt;br /&gt;
&lt;br /&gt;
* Location : Location is stored in '''iTunesMobileDeviceDLL''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Mobile Device Support\Shared''' key. Usually - C:\Program Files\Common Files\Apple\Mobile Device Support\bin\iTunesMobileDevice.dll.&lt;br /&gt;
&lt;br /&gt;
* Supporting CoreFoundation.dll (used for CFStringRef, CFPropertyListRef management) is located in the same dir (when using iTunes prior 9.0). &lt;br /&gt;
&lt;br /&gt;
* For iTunes 9.0 location of CoreFoundation.dll is stored in '''InstallDir''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Application Support''' key, usually C:\Program Files\Common Files\Apple\Apple Application Support\. CoreFoundation.dll from Mobile Device Support\bin should not be used.&lt;br /&gt;
&lt;br /&gt;
===Mac OSX : MobileDevice.framework===&lt;br /&gt;
&lt;br /&gt;
* Location : /System/Library/PrivateFrameworks/MobileDevice.framework&lt;br /&gt;
* Export command : &amp;quot;nm /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===MobileDevice Header (mobiledevice.h)===&lt;br /&gt;
&lt;br /&gt;
Reverse engineered C header for MobileDevice Library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* ----------------------------------------------------------------------------&lt;br /&gt;
 *   MobileDevice.h - interface to MobileDevice.framework &lt;br /&gt;
 * ------------------------------------------------------------------------- */&lt;br /&gt;
#pragma once&lt;br /&gt;
&lt;br /&gt;
#ifndef MOBILEDEVICE_H&lt;br /&gt;
#define MOBILEDEVICE_H&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
extern &amp;quot;C&amp;quot; {&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
#ifndef __GCC__&lt;br /&gt;
#pragma pack&lt;br /&gt;
#define __PACK&lt;br /&gt;
#else&lt;br /&gt;
#define __PACK __attribute__((__packed__))&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#if defined(WIN32)&lt;br /&gt;
#define __DLLIMPORT [DllImport(&amp;quot;iTunesMobileDevice.dll&amp;quot;)]&lt;br /&gt;
	using namespace System::Runtime::InteropServices;&lt;br /&gt;
#include &amp;lt;CoreFoundation.h&amp;gt;&lt;br /&gt;
	typedef unsigned int mach_error_t;&lt;br /&gt;
#elif defined(__APPLE__)&lt;br /&gt;
#define __DLLIMPORT&lt;br /&gt;
#include &amp;lt;CoreFoundation/CoreFoundation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;mach/error.h&amp;gt;&lt;br /&gt;
#endif	&lt;br /&gt;
	&lt;br /&gt;
	/* Error codes */&lt;br /&gt;
#define MDERR_APPLE_MOBILE  (err_system(0x3a))&lt;br /&gt;
#define MDERR_IPHONE        (err_sub(0))&lt;br /&gt;
	&lt;br /&gt;
	/* Apple Mobile (AM*) errors */&lt;br /&gt;
#define MDERR_OK                ERR_SUCCESS&lt;br /&gt;
#define MDERR_SYSCALL           (ERR_MOBILE_DEVICE | 0x01)&lt;br /&gt;
#define MDERR_OUT_OF_MEMORY     (ERR_MOBILE_DEVICE | 0x03)&lt;br /&gt;
#define MDERR_QUERY_FAILED      (ERR_MOBILE_DEVICE | 0x04) &lt;br /&gt;
#define MDERR_INVALID_ARGUMENT  (ERR_MOBILE_DEVICE | 0x0b)&lt;br /&gt;
#define MDERR_DICT_NOT_LOADED   (ERR_MOBILE_DEVICE | 0x25)&lt;br /&gt;
	&lt;br /&gt;
	/* Apple File Connection (AFC*) errors */&lt;br /&gt;
#define MDERR_AFC_OUT_OF_MEMORY 0x03&lt;br /&gt;
	&lt;br /&gt;
	/* USBMux errors */&lt;br /&gt;
#define MDERR_USBMUX_ARG_NULL   0x16&lt;br /&gt;
#define MDERR_USBMUX_FAILED     0xffffffff&lt;br /&gt;
	&lt;br /&gt;
	/* Messages passed to device notification callbacks: passed as part of&lt;br /&gt;
	 * am_device_notification_callback_info. */&lt;br /&gt;
#define ADNCI_MSG_CONNECTED     1&lt;br /&gt;
#define ADNCI_MSG_DISCONNECTED  2&lt;br /&gt;
#define ADNCI_MSG_UNSUBSCRIBED  3&lt;br /&gt;
	&lt;br /&gt;
#define AMD_IPHONE_PRODUCT_ID   0x1290&lt;br /&gt;
	//#define AMD_IPHONE_SERIAL       &amp;quot;&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
	/* Services, found in /System/Library/Lockdown/Services.plist */&lt;br /&gt;
#define AMSVC_AFC                   CFSTR(&amp;quot;com.apple.afc&amp;quot;)&lt;br /&gt;
#define AMSVC_BACKUP                CFSTR(&amp;quot;com.apple.mobilebackup&amp;quot;)&lt;br /&gt;
#define AMSVC_CRASH_REPORT_COPY     CFSTR(&amp;quot;com.apple.crashreportcopy&amp;quot;)&lt;br /&gt;
#define AMSVC_DEBUG_IMAGE_MOUNT     CFSTR(&amp;quot;com.apple.mobile.debug_image_mount&amp;quot;)&lt;br /&gt;
#define AMSVC_NOTIFICATION_PROXY    CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;)&lt;br /&gt;
#define AMSVC_PURPLE_TEST           CFSTR(&amp;quot;com.apple.purpletestr&amp;quot;)&lt;br /&gt;
#define AMSVC_SOFTWARE_UPDATE       CFSTR(&amp;quot;com.apple.mobile.software_update&amp;quot;)&lt;br /&gt;
#define AMSVC_SYNC                  CFSTR(&amp;quot;com.apple.mobilesync&amp;quot;)&lt;br /&gt;
#define AMSVC_SCREENSHOT            CFSTR(&amp;quot;com.apple.screenshotr&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSLOG_RELAY          CFSTR(&amp;quot;com.apple.syslog_relay&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSTEM_PROFILER       CFSTR(&amp;quot;com.apple.mobile.system_profiler&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned int afc_error_t;&lt;br /&gt;
	typedef unsigned int usbmux_error_t;&lt;br /&gt;
	&lt;br /&gt;
	struct am_recovery_device;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification_callback_info {&lt;br /&gt;
		struct am_device *dev;  /* 0    device */ &lt;br /&gt;
		unsigned int msg;       /* 4    one of ADNCI_MSG_* */&lt;br /&gt;
                struct am_device_notification* subscription; &lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
	&lt;br /&gt;
	/* This is a CoreFoundation object of class AMRecoveryModeDevice. */&lt;br /&gt;
	struct am_recovery_device {&lt;br /&gt;
		unsigned char unknown0[8];                          /* 0 */&lt;br /&gt;
		am_restore_device_notification_callback callback;   /* 8 */&lt;br /&gt;
		void *user_info;                                    /* 12 */&lt;br /&gt;
		unsigned char unknown1[12];                         /* 16 */&lt;br /&gt;
		unsigned int readwrite_pipe;                        /* 28 */&lt;br /&gt;
		unsigned char read_pipe;                            /* 32 */&lt;br /&gt;
		unsigned char write_ctrl_pipe;                      /* 33 */&lt;br /&gt;
		unsigned char read_unknown_pipe;                    /* 34 */&lt;br /&gt;
		unsigned char write_file_pipe;                      /* 35 */&lt;br /&gt;
		unsigned char write_input_pipe;                     /* 36 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* A CoreFoundation object of class AMRestoreModeDevice. */&lt;br /&gt;
	struct am_restore_device {&lt;br /&gt;
		unsigned char unknown[32];&lt;br /&gt;
		int port;&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device notification callback function. */&lt;br /&gt;
	typedef void(*am_device_notification_callback)(struct am_device_notification_callback_info *, int cookie);&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the _AMDDeviceAttached function.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void *amd_device_attached_callback;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
&lt;br /&gt;
	/* Structure that contains internal data used by AMDevice... functions. Never try &lt;br /&gt;
         * to access its members directly! Use AMDeviceCopyDeviceIdentifier, &lt;br /&gt;
         * AMDeviceGetConnectionID, AMDeviceRetain, AMDeviceRelease instead. */&lt;br /&gt;
	struct am_device {&lt;br /&gt;
		unsigned char unknown0[16]; /* 0 - zero */&lt;br /&gt;
		unsigned int device_id;     /* 16 */&lt;br /&gt;
		unsigned int product_id;    /* 20 - set to AMD_IPHONE_PRODUCT_ID */&lt;br /&gt;
		char *serial;               /* 24 - set to UDID, Unique Device Identifier */&lt;br /&gt;
		unsigned int unknown1;      /* 28 */&lt;br /&gt;
		unsigned int unknown2;      /* 32 - reference counter, increased by AMDeviceRetain, decreased by AMDeviceRelease*/&lt;br /&gt;
		unsigned int lockdown_conn; /* 36 */&lt;br /&gt;
		unsigned char unknown3[8];  /* 40 */&lt;br /&gt;
#if (__ITUNES_VER &amp;gt; 740)&lt;br /&gt;
		unsigned int unknown4;      /* 48 - used to store CriticalSection Handle*/&lt;br /&gt;
#endif&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
		unsigned char unknown5[24];  /* 52 */&lt;br /&gt;
#endif&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification {&lt;br /&gt;
		unsigned int unknown0;                      /* 0 */&lt;br /&gt;
		unsigned int unknown1;                      /* 4 */&lt;br /&gt;
		unsigned int unknown2;                      /* 8 */&lt;br /&gt;
		am_device_notification_callback callback;   /* 12 */ &lt;br /&gt;
		unsigned int cookie;                      /* 16 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct afc_connection {&lt;br /&gt;
		unsigned int handle;            /* 0 */&lt;br /&gt;
		unsigned int unknown0;          /* 4 */&lt;br /&gt;
		unsigned char unknown1;         /* 8 */&lt;br /&gt;
		unsigned char padding[3];       /* 9 */&lt;br /&gt;
		unsigned int unknown2;          /* 12 */&lt;br /&gt;
		unsigned int unknown3;          /* 16 */&lt;br /&gt;
		unsigned int unknown4;          /* 20 */&lt;br /&gt;
		unsigned int fs_block_size;     /* 24 */&lt;br /&gt;
		unsigned int sock_block_size;   /* 28: always 0x3c */&lt;br /&gt;
		unsigned int io_timeout;        /* 32: from AFCConnectionOpen, usu. 0 */&lt;br /&gt;
		void *afc_lock;                 /* 36 */&lt;br /&gt;
		unsigned int context;           /* 40 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
	struct afc_device_info {&lt;br /&gt;
		unsigned char unknown[12];  /* 0 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_directory {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_dictionary {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned long long afc_file_ref;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_1 {                  /* offset   value in iTunes */&lt;br /&gt;
		unsigned int unknown0;                  /* 0        1 */&lt;br /&gt;
		unsigned char *unknown1;                /* 4        ptr, maybe device? */&lt;br /&gt;
		amd_device_attached_callback callback;  /* 8        _AMDDeviceAttached */&lt;br /&gt;
		unsigned int unknown3;                  /* 12 */&lt;br /&gt;
		unsigned int unknown4;                  /* 16 */&lt;br /&gt;
		unsigned int unknown5;                  /* 20 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_2 {&lt;br /&gt;
		unsigned char unknown0[4144];&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_bootloader_control_packet {&lt;br /&gt;
		unsigned char opcode;       /* 0 */&lt;br /&gt;
		unsigned char length;       /* 1 */&lt;br /&gt;
		unsigned char magic[2];     /* 2: 0x34, 0x12 */&lt;br /&gt;
		unsigned char payload[0];   /* 4 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Registers a notification with the current run loop. The callback gets&lt;br /&gt;
	 *  copied into the notification struct, as well as being registered with the&lt;br /&gt;
	 *  current run loop. Cookie gets copied into cookie in the same.&lt;br /&gt;
	 *  (Cookie is a user info parameter that gets passed as an arg to&lt;br /&gt;
	 *  the callback) unused0 and unused1 are both 0 when iTunes calls this.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Never try to acces directly or copy contents of dev and subscription fields &lt;br /&gt;
	 *  in am_device_notification_callback_info. Treat them as abstract handles. &lt;br /&gt;
	 *  When done with connection use AMDeviceRelease to free resources allocated for am_device.&lt;br /&gt;
	 *  &lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK            if successful&lt;br /&gt;
	 *      MDERR_SYSCALL       if CFRunLoopAddSource() failed&lt;br /&gt;
	 *      MDERR_OUT_OF_MEMORY if we ran out of memory&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationSubscribe(am_device_notification_callback callback, &lt;br /&gt;
								unsigned int unused0, unsigned int unused1, &lt;br /&gt;
								unsigned int cookie, &lt;br /&gt;
								struct am_device_notification **subscription);&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
        /* Unregisters notifications. Buggy (iTunes 8.2): if you subscribe, unsubscribe and subscribe again, arriving &lt;br /&gt;
           notifications will contain cookie and subscription from 1st call to subscribe, not the 2nd one. iTunes &lt;br /&gt;
           calls this function only once on exit.&lt;br /&gt;
        */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationUnsubscribe(am_device_notification* subscription);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns device_id field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMDeviceGetConnectionID(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns serial field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyDeviceIdentifier(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Connects to the iPhone. Pass in the am_device structure that the&lt;br /&gt;
	 *  notification callback will give to you.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successfully connected&lt;br /&gt;
	 *      MDERR_SYSCALL           if setsockopt() failed&lt;br /&gt;
	 *      MDERR_QUERY_FAILED      if the daemon query failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if USBMuxConnectByPort returned 0xffffffff&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceConnect(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Calls PairingRecordPath() on the given device, than tests whether the path&lt;br /&gt;
	 *  which that function returns exists. During the initial connect, the path&lt;br /&gt;
	 *  returned by that function is '/', and so this returns 1.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      0   if the path did not exist&lt;br /&gt;
	 *      1   if it did&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceIsPaired(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDevicePair(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  iTunes calls this function immediately after testing whether the device is&lt;br /&gt;
	 *  paired. It creates a pairing file and establishes a Lockdown connection.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the supplied device is null&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceValidatePairing(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Creates a Lockdown session and adjusts the device structure appropriately&lt;br /&gt;
	 *  to indicate that the session has been started. iTunes calls this function&lt;br /&gt;
	 *  after validating pairing.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartSession(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* Reads various device settings. One of domain or cfstring arguments should be NULL.&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for cfstring:&lt;br /&gt;
	 * ActivationState&lt;br /&gt;
	 * ActivationStateAcknowledged&lt;br /&gt;
	 * BasebandBootloaderVersion&lt;br /&gt;
	 * BasebandVersion&lt;br /&gt;
	 * BluetoothAddress&lt;br /&gt;
	 * BuildVersion&lt;br /&gt;
	 * DeviceCertificate&lt;br /&gt;
	 * DeviceClass&lt;br /&gt;
	 * DeviceName&lt;br /&gt;
	 * DevicePublicKey&lt;br /&gt;
	 * FirmwareVersion&lt;br /&gt;
	 * HostAttached&lt;br /&gt;
	 * IntegratedCircuitCardIdentity&lt;br /&gt;
	 * InternationalMobileEquipmentIdentity&lt;br /&gt;
	 * InternationalMobileSubscriberIdentity&lt;br /&gt;
	 * ModelNumber&lt;br /&gt;
	 * PhoneNumber&lt;br /&gt;
	 * ProductType&lt;br /&gt;
	 * ProductVersion&lt;br /&gt;
	 * ProtocolVersion&lt;br /&gt;
	 * RegionInfo&lt;br /&gt;
	 * SBLockdownEverRegisteredKey&lt;br /&gt;
	 * SIMStatus&lt;br /&gt;
	 * SerialNumber&lt;br /&gt;
	 * SomebodySetTimeZone&lt;br /&gt;
	 * TimeIntervalSince1970&lt;br /&gt;
	 * TimeZone&lt;br /&gt;
	 * TimeZoneOffsetFromUTC&lt;br /&gt;
	 * TrustedHostAttached&lt;br /&gt;
	 * UniqueDeviceID&lt;br /&gt;
	 * Uses24HourClock&lt;br /&gt;
	 * WiFiAddress&lt;br /&gt;
	 * iTunesHasConnected&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for domain:&lt;br /&gt;
         * com.apple.mobile.battery&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyValue(struct am_device *device, CFStringRef domain, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* Starts a service and returns a socket file descriptor that can be used in order to further&lt;br /&gt;
	 * access the service. You should stop the session and disconnect before using&lt;br /&gt;
	 * the service. iTunes calls this function after starting a session. It starts &lt;br /&gt;
	 * the service and the SSL connection. service_name should be one of the AMSVC_*&lt;br /&gt;
	 * constants.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_SYSCALL           if the setsockopt() call failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartService(struct am_device *device, CFStringRef &lt;br /&gt;
									  service_name, int *socket_fd);&lt;br /&gt;
	&lt;br /&gt;
	/* Stops a session. You should do this before accessing services.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStopSession(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/* Decrements reference counter and, if nothing left, releases resources hold &lt;br /&gt;
	 * by connection, invalidates  pointer to device&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRelease(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Increments reference counter&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRetain(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Opens an Apple File Connection. You must start the appropriate service&lt;br /&gt;
	 * first with AMDeviceStartService(). In iTunes, io_timeout is 0.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_AFC_OUT_OF_MEMORY if malloc() failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionOpen(int socket_fd, unsigned int io_timeout,&lt;br /&gt;
								  struct afc_connection **conn);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        /* Copy an enviromental variable value from iBoot&lt;br /&gt;
         */&lt;br /&gt;
        __DLLIMPORT CFStringRef AMRecoveryModeCopyEnvironmentVariable(struct am_recovery_device *rdev, CFStringRef var);&lt;br /&gt;
	&lt;br /&gt;
	/* Pass in a pointer to an afc_dictionary structure. It will be filled. You can&lt;br /&gt;
	 * iterate it using AFCKeyValueRead. When done use AFCKeyValueClose. Possible keys:&lt;br /&gt;
	 * FSFreeBytes - free bytes on system device for afc2, user device for afc&lt;br /&gt;
	 * FSBlockSize - filesystem block size&lt;br /&gt;
	 * FSTotalBytes - size of device&lt;br /&gt;
	 * Model - iPhone1,1 etc.&lt;br /&gt;
&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDeviceInfoOpen(struct afc_connection *conn, struct&lt;br /&gt;
								  afc_dictionary **info);&lt;br /&gt;
	&lt;br /&gt;
	/* Turns debug mode on if the environment variable AFCDEBUG is set to a numeric&lt;br /&gt;
	 * value, or if the file '/AFCDEBUG' is present and contains a value. */&lt;br /&gt;
#if defined(__APPLE__)&lt;br /&gt;
	void AFCPlatformInitialize();&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
	/* Opens a directory on the iPhone. Pass in a pointer in dir to be filled in.&lt;br /&gt;
	 * Note that this normally only accesses the iTunes sandbox/partition as the&lt;br /&gt;
	 * root, which is /var/root/Media. Pathnames are specified with '/' delimiters&lt;br /&gt;
	 * as in Unix style. Use UTF-8 to specify non-ASCII symbols in path.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								 afc_directory **dir);&lt;br /&gt;
	&lt;br /&gt;
	/* Acquires the next entry in a directory previously opened with&lt;br /&gt;
	 * AFCDirectoryOpen(). When dirent is filled with a NULL value, then the end&lt;br /&gt;
	 * of the directory has been reached. '.' and '..' will be returned as the&lt;br /&gt;
	 * first two entries in each directory except the root; you may want to skip&lt;br /&gt;
	 * over them.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful, even if no entries remain&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryRead(struct afc_connection *conn, struct afc_directory *dir,&lt;br /&gt;
								 char **dirent);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryClose(afc_connection *conn, struct afc_directory *dir);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryCreate(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRemovePath(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRenamePath(afc_connection *conn, char *oldpath, char *newpath);&lt;br /&gt;
&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
	/* Creates symbolic or hard link&lt;br /&gt;
         * linktype - int64: 1 means hard link, 2 - soft (symbolic) link&lt;br /&gt;
         * target - absolute or relative path to link target&lt;br /&gt;
         * linkname - absolute path where to create new link&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCLinkPath(struct afc_connection *conn, long long int linktype, const char *target, &lt;br /&gt;
								                              const char *linkname);&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
	/* Opens file for reading or writing without locking it in any way. afc_file_ref should not be shared between threads - &lt;br /&gt;
         * opening file in one thread and closing it in another will lead to possible crash.&lt;br /&gt;
	 * path - UTF-8 encoded absolute path to file&lt;br /&gt;
	 * mode 2 = read, mode 3 = write; unknown = 0 &lt;br /&gt;
	 * ref - receives file handle&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefOpen(struct afc_connection *conn, char *path, unsigned&lt;br /&gt;
							   long long int mode, afc_file_ref *ref);&lt;br /&gt;
	/* Reads specified amount (len) of bytes from file into buf. Puts actual count of read bytes into len on return&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefRead(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   void *buf, unsigned int *len);&lt;br /&gt;
	/* Writes specified amount (len) of bytes from buf into file.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefWrite(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
								void *buf, unsigned int len);&lt;br /&gt;
	/* Moves the file pointer to a specified location.&lt;br /&gt;
	 * offset - Number of bytes from origin (int64)&lt;br /&gt;
	 * origin - 0 = from beginning, 1 = from current position, 2 = from end&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefSeek(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long offset, int origin, int unused);&lt;br /&gt;
&lt;br /&gt;
	/* Gets the current position of a file pointer into offset argument.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefTell(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long* offset);&lt;br /&gt;
&lt;br /&gt;
	/*  Truncates a file at the specified offset.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefSetFileSize(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long offset);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefLock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefUnlock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefClose(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
&lt;br /&gt;
	/* Opens dictionary describing specified file or directory (iTunes below 8.2 allowed using AFCGetFileInfo&lt;br /&gt;
	   to get the same information)&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileInfoOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								afc_dictionary **info);&lt;br /&gt;
&lt;br /&gt;
	/* Reads next entry from dictionary. When last entry is read, function returns NULL in key argument&lt;br /&gt;
	   Possible keys:&lt;br /&gt;
	     &amp;quot;st_size&amp;quot;:     val - size in bytes&lt;br /&gt;
	     &amp;quot;st_blocks&amp;quot;:   val - size in blocks&lt;br /&gt;
	     &amp;quot;st_nlink&amp;quot;:    val - number of hardlinks&lt;br /&gt;
	     &amp;quot;st_ifmt&amp;quot;:     val - &amp;quot;S_IFDIR&amp;quot; for folders&lt;br /&gt;
	                        &amp;quot;S_IFLNK&amp;quot; for symlinks&lt;br /&gt;
	     &amp;quot;LinkTarget&amp;quot;:  val - path to symlink target&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueRead(struct afc_dictionary *dict, char **key, char **&lt;br /&gt;
								val);&lt;br /&gt;
	/* Closes dictionary&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueClose(struct afc_dictionary *dict);&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the context field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetContext(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the fs_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetFSBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the io_timeout field of the given AFC connection. In iTunes this is&lt;br /&gt;
	 * 0. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetIOTimeout(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the sock_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetSocketBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Closes the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionClose(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Registers for device notifications related to the restore process. unknown0&lt;br /&gt;
	 * is zero when iTunes calls this. In iTunes,&lt;br /&gt;
	 * the callbacks are located at:&lt;br /&gt;
	 *      1: $3ac68e-$3ac6b1, calls $3ac542(unknown1, arg, 0)&lt;br /&gt;
	 *      2: $3ac66a-$3ac68d, calls $3ac542(unknown1, 0, arg)&lt;br /&gt;
	 *      3: $3ac762-$3ac785, calls $3ac6b2(unknown1, arg, 0)&lt;br /&gt;
	 *      4: $3ac73e-$3ac761, calls $3ac6b2(unknown1, 0, arg)&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreRegisterForDeviceNotifications(&lt;br /&gt;
				am_restore_device_notification_callback dfu_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback dfu_disconnect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_disconnect_callback,&lt;br /&gt;
				unsigned int unknown0,&lt;br /&gt;
				void *user_info);&lt;br /&gt;
	&lt;br /&gt;
	/* Causes the restore functions to spit out (unhelpful) progress messages to&lt;br /&gt;
	 * the file specified by the given path. iTunes always calls this right before&lt;br /&gt;
	 * restoring with a path of&lt;br /&gt;
	 * &amp;quot;$HOME/Library/Logs/iPhone Updater Logs/iPhoneUpdater X.log&amp;quot;, where X is an&lt;br /&gt;
	 * unused number.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreEnableFileLogging(char *path);&lt;br /&gt;
	&lt;br /&gt;
	/* Initializes a new option dictionary to default values. Pass the constant&lt;br /&gt;
	 * kCFAllocatorDefault as the allocator. The option dictionary looks as&lt;br /&gt;
	 * follows:&lt;br /&gt;
	 * {&lt;br /&gt;
	 *      NORImageType =&amp;gt; 'production',&lt;br /&gt;
	 *      AutoBootDelay =&amp;gt; 0,&lt;br /&gt;
	 *      KernelCacheType =&amp;gt; 'Release',&lt;br /&gt;
	 *      UpdateBaseband =&amp;gt; true,&lt;br /&gt;
	 *      DFUFileType =&amp;gt; 'RELEASE',&lt;br /&gt;
	 *      SystemImageType =&amp;gt; 'User',&lt;br /&gt;
	 *      CreateFilesystemPartitions =&amp;gt; true,&lt;br /&gt;
	 *      FlashNOR =&amp;gt; true,&lt;br /&gt;
	 *      RestoreBootArgs =&amp;gt; 'rd=md0 nand-enable-reformat=1 -progress'&lt;br /&gt;
	 *      BootImageType =&amp;gt; 'User'&lt;br /&gt;
	 *  }&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      the option dictionary   if successful&lt;br /&gt;
	 *      NULL                    if out of memory&lt;br /&gt;
	 */ &lt;br /&gt;
	__DLLIMPORT CFMutableDictionaryRef AMRestoreCreateDefaultOptions(CFAllocatorRef allocator);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRecoveryModeRestore(struct am_recovery_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRestoreModeRestore(struct am_restore_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT struct am_restore_device *AMRestoreModeDeviceCreate(unsigned int unknown0,&lt;br /&gt;
				unsigned int connection_id, unsigned int unknown1);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreCreatePathsForBundle(CFStringRef restore_bundle_path,&lt;br /&gt;
				CFStringRef kernel_cache_type, CFStringRef boot_image_type, unsigned int&lt;br /&gt;
				unknown0, CFStringRef *firmware_dir_path, CFStringRef *&lt;br /&gt;
				kernelcache_restore_path, unsigned int unknown1, CFStringRef *&lt;br /&gt;
				ramdisk_path);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreModeDeviceReboot(struct am_restore_device *rdev);	// Added by JB 30.07.2008&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceEnterRecovery(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDisconnect(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* to use this, start the service &amp;quot;com.apple.mobile.notification_proxy&amp;quot;, handle will be the socket to use */&lt;br /&gt;
	typedef void (*NOTIFY_CALLBACK)(CFSTR notification, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDPostNotification(SOCKET socket, CFStringRef  notification, CFStringRef userinfo);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDObserveNotification(SOCKET socket, CFSTR notification);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDListenForNotifications(SOCKET socket, NOTIFY_CALLBACK cb, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDShutdownNotificationProxy(SOCKET socket);&lt;br /&gt;
	&lt;br /&gt;
	/*edits by geohot*/&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDeactivate(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceActivate(struct am_device *device, CFDictionaryRef dict);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceRemoveValue(struct am_device *device, unsigned int, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Pass in a usbmux_listener_1 structure and a usbmux_listener_2 structure&lt;br /&gt;
	 *  pointer, which will be filled with the resulting usbmux_listener_2.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if completed successfully&lt;br /&gt;
	 *      MDERR_USBMUX_ARG_NULL   if one of the arguments was NULL&lt;br /&gt;
	 *      MDERR_USBMUX_FAILED     if the listener was not created successfully&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerCreate(struct usbmux_listener_1 *esi_fp8, struct&lt;br /&gt;
										usbmux_listener_2 **eax_fp12);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerHandleData(void *);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Private routines - here be dragons&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/* AMRestorePerformRestoreModeRestore() calls this function with a dictionary&lt;br /&gt;
	 * in order to perform certain special restore operations&lt;br /&gt;
	 * (RESTORED_OPERATION_*). It is thought that this function might enable&lt;br /&gt;
	 * significant access to the phone. */&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef unsigned int (*t_performOperation)(struct am_restore_device *rdev,&lt;br /&gt;
	 CFDictionaryRef op) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_performOperation _performOperation = (t_performOperation)0x3c39fa4b;&lt;br /&gt;
	 */ &lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef int (*t_socketForPort)(struct am_restore_device *rdev, unsigned int port)&lt;br /&gt;
	 __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_socketForPort _socketForPort = (t_socketForPort)(void *)0x3c39f36c;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef void (*t_restored_send_message)(int port, CFDictionaryRef msg);&lt;br /&gt;
	 t_restored_send_message _restored_send_message = (t_restored_send_message)0x3c3a4e40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef CFDictionaryRef (*t_restored_receive_message)(int port);&lt;br /&gt;
	 t_restored_receive_message _restored_receive_message = (t_restored_receive_message)0x3c3a4d40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendControlPacket)(struct am_recovery_device *rdev, unsigned&lt;br /&gt;
	 int msg1, unsigned int msg2, unsigned int unknown0, unsigned int *unknown1,&lt;br /&gt;
	 unsigned char *unknown2) __attribute__ ((regparm(3)));&lt;br /&gt;
	 t_sendControlPacket _sendControlPacket = (t_sendControlPacket)0x3c3a3da3;;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendCommandToDevice)(struct am_recovery_device *rdev,&lt;br /&gt;
	 CFStringRef cmd) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_sendCommandToDevice _sendCommandToDevice = (t_sendCommandToDevice)0x3c3a3e3b;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceReadPipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int read_pipe, unsigned char *data, unsigned int *len);&lt;br /&gt;
	 t_AMRUSBInterfaceReadPipe _AMRUSBInterfaceReadPipe = (t_AMRUSBInterfaceReadPipe)0x3c3a27e8;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceWritePipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int write_pipe, void *data, unsigned int len);&lt;br /&gt;
	 t_AMRUSBInterfaceWritePipe _AMRUSBInterfaceWritePipe = (t_AMRUSBInterfaceWritePipe)0x3c3a27cb;&lt;br /&gt;
	 */&lt;br /&gt;
	&lt;br /&gt;
	int performOperation(am_restore_device *rdev, CFMutableDictionaryRef message);&lt;br /&gt;
	int socketForPort(am_restore_device *rdev, unsigned int portnum);&lt;br /&gt;
	int sendCommandToDevice(am_recovery_device *rdev, CFStringRef cfs, int block);&lt;br /&gt;
	int sendFileToDevice(am_recovery_device *rdev, CFStringRef filename); &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
}&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
/* -*- mode:c; indent-tabs-mode:nil; c-basic-offset:2; tab-width:2; */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===AFC Connection===&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
===Locking the Device for Sync===&lt;br /&gt;
When iTunes sends a new song to the device, the device shows a &amp;quot;Sync in progress&amp;quot; screen and when complete, the Music app on the device re-reads the iTunesDB file so it picks up the new song.&lt;br /&gt;
&lt;br /&gt;
To get this behaviour, first start the notification service:&lt;br /&gt;
&amp;lt;pre&amp;gt;SOCKET socket;&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we post a notificaton message to signal that we are going to start a sync:&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncWillStart&amp;quot;), NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we open the itunes lock file:&lt;br /&gt;
&amp;lt;pre&amp;gt;afc_file_ref lockref;&lt;br /&gt;
AFCFileRefOpen(conn, &amp;quot;/com.apple.itunes.lock_sync&amp;quot;, 2, &amp;amp;lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now post a notification to say we are going to lock this file, and try and lock it.&lt;br /&gt;
If the AFCFileRefLock call fails, pause and repeat.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncLockRequest&amp;quot;), NULL);&lt;br /&gt;
mach_error_t error = AFCFileRefLock(conn, lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the file is successfully locked, post another notification, and stop the notification service.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket,CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidStart&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the sync can proceed, so copy your files across and make the changes to the iTunesDB.&lt;br /&gt;
&lt;br /&gt;
To release the lock, start the notification system again, unlock and close the lock file, and send a sync finished notification message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;AFCFileRefUnlock(conn, lockref);&lt;br /&gt;
AFCFileRefClose(conn, lockref);&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&lt;br /&gt;
AMDPostNotification(socket, &amp;amp;CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidFinish&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To handle &amp;quot;Slide to Cancel&amp;quot; and terminate sync when user slides cancel switch, use AMDObserveNotification to subscribe notifications about “com.apple.itunes-client.syncCancelRequest”. Then start listening for notifications (AMDListenForNotifications) until you get “AMDNotificationFaceplant”.&lt;br /&gt;
When notification got, you should unlock and close lock file handle (don’t sure if you need to post “syncDidFinish” to proxy, seems it doesn’t matter) and terminate sync gracefully.&lt;br /&gt;
The same notification is also got when you unplug your device, so you should always be ready for errors.&lt;br /&gt;
&lt;br /&gt;
NOTE: You may find that starting the notification_proxy service once and once only at the start of your app and using the same socket in calls to AMDPostNotification works better. iTunes opens and closes the notification_proxy regularly, but it appears to be a bit flakey when you open/close it all the time.&lt;br /&gt;
&lt;br /&gt;
===Private Functions===&lt;br /&gt;
&lt;br /&gt;
====How to find address of privates functions in iTunesMobileDevice.dll or MobileDevice.framework====&lt;br /&gt;
&lt;br /&gt;
In order to obtain the address of a usable private function in MobileDevice, you will have to be able to understand x86-64 assembly to reverse engineer it. A private function will not have its name exported in the mach-o symbol table, so in a debugger, like GDB, it will show up as part of another function. However, you will know that it is a separate function as a new stack frame is set up.&lt;br /&gt;
&lt;br /&gt;
====Private Function Address List====&lt;br /&gt;
&lt;br /&gt;
=====OSX.6 - iTunes 9.0.2(25)=====&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendCommandToiBoot(struct am_recovery_device *rdev, CFStringRef command, int u);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 868(0x364) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym(). &lt;br /&gt;
Address: 0x1000245ea&lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
1. rdev - the device you wish to send the command to.&lt;br /&gt;
2. a CFStringRef of the command to send.&lt;br /&gt;
3. an integer, whose use is currently unknown, but should be set to 0 to work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendFileToiDevice(struct am_recovery_device *rdev, CFStringRef filename);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 1763(0x6e3) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym().&lt;br /&gt;
Address: 0x100024969&lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
1. rdev - the device you wish to send the file to.&lt;br /&gt;
2. a CFStringRef of the path to the file to send.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====OSX.6 - iTunes 9.0.3(15)=====&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendCommandToiBoot(struct am_recovery_device *rdev, CFStringRef command, int u);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Addresss: AMRecoveryDeviceGetProductType() + 0x37f(895)&lt;br /&gt;
&lt;br /&gt;
===Libraries Implementations===&lt;br /&gt;
&lt;br /&gt;
* [http://gojohnnyboi.com/source/afcinstall.cpp afcinstall (command line, os x file install via afc)]&lt;br /&gt;
* [http://code.google.com/p/iphuc/ iPhuc (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/iphucwin32/ iPhuc Win32 (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/manzana/ manzana (.Net Library)]&lt;br /&gt;
* [http://code.google.com/p/independence/source/browse/trunk/libPhoneInteraction/ libPhoneInteraction (C Library)]&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5687</id>
		<title>MobileDevice Library</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5687"/>
		<updated>2009-11-22T16:30:42Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MobileDevice Library is used by [[iTunes]] to transfer data between iPhone and computer over the USB connection.&lt;br /&gt;
&lt;br /&gt;
===PC Windows : iTunesMobileDevice.dll===&lt;br /&gt;
&lt;br /&gt;
* Location : Location is stored in '''iTunesMobileDeviceDLL''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Mobile Device Support\Shared''' key. Usually - C:\Program Files\Common Files\Apple\Mobile Device Support\bin\iTunesMobileDevice.dll.&lt;br /&gt;
&lt;br /&gt;
* Supporting CoreFoundation.dll (used for CFStringRef, CFPropertyListRef management) is located in the same dir (when using iTunes prior 9.0). &lt;br /&gt;
&lt;br /&gt;
* For iTunes 9.0 location of CoreFoundation.dll is stored in '''InstallDir''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Application Support''' key, usually C:\Program Files\Common Files\Apple\Apple Application Support\. CoreFoundation.dll from Mobile Device Support\bin should not be used.&lt;br /&gt;
&lt;br /&gt;
===Mac OSX : MobileDevice.framework===&lt;br /&gt;
&lt;br /&gt;
* Location : /System/Library/PrivateFrameworks/MobileDevice.framework&lt;br /&gt;
* Export command : &amp;quot;nm /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===MobileDevice Header (mobiledevice.h)===&lt;br /&gt;
&lt;br /&gt;
Reverse engineered C header for MobileDevice Library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* ----------------------------------------------------------------------------&lt;br /&gt;
 *   MobileDevice.h - interface to MobileDevice.framework &lt;br /&gt;
 * ------------------------------------------------------------------------- */&lt;br /&gt;
#pragma once&lt;br /&gt;
&lt;br /&gt;
#ifndef MOBILEDEVICE_H&lt;br /&gt;
#define MOBILEDEVICE_H&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
extern &amp;quot;C&amp;quot; {&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
#ifndef __GCC__&lt;br /&gt;
#pragma pack&lt;br /&gt;
#define __PACK&lt;br /&gt;
#else&lt;br /&gt;
#define __PACK __attribute__((__packed__))&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#if defined(WIN32)&lt;br /&gt;
#define __DLLIMPORT [DllImport(&amp;quot;iTunesMobileDevice.dll&amp;quot;)]&lt;br /&gt;
	using namespace System::Runtime::InteropServices;&lt;br /&gt;
#include &amp;lt;CoreFoundation.h&amp;gt;&lt;br /&gt;
	typedef unsigned int mach_error_t;&lt;br /&gt;
#elif defined(__APPLE__)&lt;br /&gt;
#define __DLLIMPORT&lt;br /&gt;
#include &amp;lt;CoreFoundation/CoreFoundation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;mach/error.h&amp;gt;&lt;br /&gt;
#endif	&lt;br /&gt;
	&lt;br /&gt;
	/* Error codes */&lt;br /&gt;
#define MDERR_APPLE_MOBILE  (err_system(0x3a))&lt;br /&gt;
#define MDERR_IPHONE        (err_sub(0))&lt;br /&gt;
	&lt;br /&gt;
	/* Apple Mobile (AM*) errors */&lt;br /&gt;
#define MDERR_OK                ERR_SUCCESS&lt;br /&gt;
#define MDERR_SYSCALL           (ERR_MOBILE_DEVICE | 0x01)&lt;br /&gt;
#define MDERR_OUT_OF_MEMORY     (ERR_MOBILE_DEVICE | 0x03)&lt;br /&gt;
#define MDERR_QUERY_FAILED      (ERR_MOBILE_DEVICE | 0x04) &lt;br /&gt;
#define MDERR_INVALID_ARGUMENT  (ERR_MOBILE_DEVICE | 0x0b)&lt;br /&gt;
#define MDERR_DICT_NOT_LOADED   (ERR_MOBILE_DEVICE | 0x25)&lt;br /&gt;
	&lt;br /&gt;
	/* Apple File Connection (AFC*) errors */&lt;br /&gt;
#define MDERR_AFC_OUT_OF_MEMORY 0x03&lt;br /&gt;
	&lt;br /&gt;
	/* USBMux errors */&lt;br /&gt;
#define MDERR_USBMUX_ARG_NULL   0x16&lt;br /&gt;
#define MDERR_USBMUX_FAILED     0xffffffff&lt;br /&gt;
	&lt;br /&gt;
	/* Messages passed to device notification callbacks: passed as part of&lt;br /&gt;
	 * am_device_notification_callback_info. */&lt;br /&gt;
#define ADNCI_MSG_CONNECTED     1&lt;br /&gt;
#define ADNCI_MSG_DISCONNECTED  2&lt;br /&gt;
#define ADNCI_MSG_UNSUBSCRIBED  3&lt;br /&gt;
	&lt;br /&gt;
#define AMD_IPHONE_PRODUCT_ID   0x1290&lt;br /&gt;
	//#define AMD_IPHONE_SERIAL       &amp;quot;&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
	/* Services, found in /System/Library/Lockdown/Services.plist */&lt;br /&gt;
#define AMSVC_AFC                   CFSTR(&amp;quot;com.apple.afc&amp;quot;)&lt;br /&gt;
#define AMSVC_BACKUP                CFSTR(&amp;quot;com.apple.mobilebackup&amp;quot;)&lt;br /&gt;
#define AMSVC_CRASH_REPORT_COPY     CFSTR(&amp;quot;com.apple.crashreportcopy&amp;quot;)&lt;br /&gt;
#define AMSVC_DEBUG_IMAGE_MOUNT     CFSTR(&amp;quot;com.apple.mobile.debug_image_mount&amp;quot;)&lt;br /&gt;
#define AMSVC_NOTIFICATION_PROXY    CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;)&lt;br /&gt;
#define AMSVC_PURPLE_TEST           CFSTR(&amp;quot;com.apple.purpletestr&amp;quot;)&lt;br /&gt;
#define AMSVC_SOFTWARE_UPDATE       CFSTR(&amp;quot;com.apple.mobile.software_update&amp;quot;)&lt;br /&gt;
#define AMSVC_SYNC                  CFSTR(&amp;quot;com.apple.mobilesync&amp;quot;)&lt;br /&gt;
#define AMSVC_SCREENSHOT            CFSTR(&amp;quot;com.apple.screenshotr&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSLOG_RELAY          CFSTR(&amp;quot;com.apple.syslog_relay&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSTEM_PROFILER       CFSTR(&amp;quot;com.apple.mobile.system_profiler&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned int afc_error_t;&lt;br /&gt;
	typedef unsigned int usbmux_error_t;&lt;br /&gt;
	&lt;br /&gt;
	struct am_recovery_device;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification_callback_info {&lt;br /&gt;
		struct am_device *dev;  /* 0    device */ &lt;br /&gt;
		unsigned int msg;       /* 4    one of ADNCI_MSG_* */&lt;br /&gt;
                struct am_device_notification* subscription; &lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
	&lt;br /&gt;
	/* This is a CoreFoundation object of class AMRecoveryModeDevice. */&lt;br /&gt;
	struct am_recovery_device {&lt;br /&gt;
		unsigned char unknown0[8];                          /* 0 */&lt;br /&gt;
		am_restore_device_notification_callback callback;   /* 8 */&lt;br /&gt;
		void *user_info;                                    /* 12 */&lt;br /&gt;
		unsigned char unknown1[12];                         /* 16 */&lt;br /&gt;
		unsigned int readwrite_pipe;                        /* 28 */&lt;br /&gt;
		unsigned char read_pipe;                            /* 32 */&lt;br /&gt;
		unsigned char write_ctrl_pipe;                      /* 33 */&lt;br /&gt;
		unsigned char read_unknown_pipe;                    /* 34 */&lt;br /&gt;
		unsigned char write_file_pipe;                      /* 35 */&lt;br /&gt;
		unsigned char write_input_pipe;                     /* 36 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* A CoreFoundation object of class AMRestoreModeDevice. */&lt;br /&gt;
	struct am_restore_device {&lt;br /&gt;
		unsigned char unknown[32];&lt;br /&gt;
		int port;&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device notification callback function. */&lt;br /&gt;
	typedef void(*am_device_notification_callback)(struct am_device_notification_callback_info *, int cookie);&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the _AMDDeviceAttached function.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void *amd_device_attached_callback;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
&lt;br /&gt;
	/* Structure that contains internal data used by AMDevice... functions. Never try &lt;br /&gt;
         * to access its members directly! Use AMDeviceCopyDeviceIdentifier, &lt;br /&gt;
         * AMDeviceGetConnectionID, AMDeviceRetain, AMDeviceRelease instead. */&lt;br /&gt;
	struct am_device {&lt;br /&gt;
		unsigned char unknown0[16]; /* 0 - zero */&lt;br /&gt;
		unsigned int device_id;     /* 16 */&lt;br /&gt;
		unsigned int product_id;    /* 20 - set to AMD_IPHONE_PRODUCT_ID */&lt;br /&gt;
		char *serial;               /* 24 - set to UDID, Unique Device Identifier */&lt;br /&gt;
		unsigned int unknown1;      /* 28 */&lt;br /&gt;
		unsigned int unknown2;      /* 32 - reference counter, increased by AMDeviceRetain, decreased by AMDeviceRelease*/&lt;br /&gt;
		unsigned int lockdown_conn; /* 36 */&lt;br /&gt;
		unsigned char unknown3[8];  /* 40 */&lt;br /&gt;
#if (__ITUNES_VER &amp;gt; 740)&lt;br /&gt;
		unsigned int unknown4;      /* 48 - used to store CriticalSection Handle*/&lt;br /&gt;
#endif&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
		unsigned char unknown5[24];  /* 52 */&lt;br /&gt;
#endif&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification {&lt;br /&gt;
		unsigned int unknown0;                      /* 0 */&lt;br /&gt;
		unsigned int unknown1;                      /* 4 */&lt;br /&gt;
		unsigned int unknown2;                      /* 8 */&lt;br /&gt;
		am_device_notification_callback callback;   /* 12 */ &lt;br /&gt;
		unsigned int cookie;                      /* 16 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct afc_connection {&lt;br /&gt;
		unsigned int handle;            /* 0 */&lt;br /&gt;
		unsigned int unknown0;          /* 4 */&lt;br /&gt;
		unsigned char unknown1;         /* 8 */&lt;br /&gt;
		unsigned char padding[3];       /* 9 */&lt;br /&gt;
		unsigned int unknown2;          /* 12 */&lt;br /&gt;
		unsigned int unknown3;          /* 16 */&lt;br /&gt;
		unsigned int unknown4;          /* 20 */&lt;br /&gt;
		unsigned int fs_block_size;     /* 24 */&lt;br /&gt;
		unsigned int sock_block_size;   /* 28: always 0x3c */&lt;br /&gt;
		unsigned int io_timeout;        /* 32: from AFCConnectionOpen, usu. 0 */&lt;br /&gt;
		void *afc_lock;                 /* 36 */&lt;br /&gt;
		unsigned int context;           /* 40 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
	struct afc_device_info {&lt;br /&gt;
		unsigned char unknown[12];  /* 0 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_directory {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_dictionary {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned long long afc_file_ref;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_1 {                  /* offset   value in iTunes */&lt;br /&gt;
		unsigned int unknown0;                  /* 0        1 */&lt;br /&gt;
		unsigned char *unknown1;                /* 4        ptr, maybe device? */&lt;br /&gt;
		amd_device_attached_callback callback;  /* 8        _AMDDeviceAttached */&lt;br /&gt;
		unsigned int unknown3;                  /* 12 */&lt;br /&gt;
		unsigned int unknown4;                  /* 16 */&lt;br /&gt;
		unsigned int unknown5;                  /* 20 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_2 {&lt;br /&gt;
		unsigned char unknown0[4144];&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_bootloader_control_packet {&lt;br /&gt;
		unsigned char opcode;       /* 0 */&lt;br /&gt;
		unsigned char length;       /* 1 */&lt;br /&gt;
		unsigned char magic[2];     /* 2: 0x34, 0x12 */&lt;br /&gt;
		unsigned char payload[0];   /* 4 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Registers a notification with the current run loop. The callback gets&lt;br /&gt;
	 *  copied into the notification struct, as well as being registered with the&lt;br /&gt;
	 *  current run loop. Cookie gets copied into cookie in the same.&lt;br /&gt;
	 *  (Cookie is a user info parameter that gets passed as an arg to&lt;br /&gt;
	 *  the callback) unused0 and unused1 are both 0 when iTunes calls this.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Never try to acces directly or copy contents of dev and subscription fields &lt;br /&gt;
	 *  in am_device_notification_callback_info. Treat them as abstract handles. &lt;br /&gt;
	 *  When done with connection use AMDeviceRelease to free resources allocated for am_device.&lt;br /&gt;
	 *  &lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK            if successful&lt;br /&gt;
	 *      MDERR_SYSCALL       if CFRunLoopAddSource() failed&lt;br /&gt;
	 *      MDERR_OUT_OF_MEMORY if we ran out of memory&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationSubscribe(am_device_notification_callback callback, &lt;br /&gt;
								unsigned int unused0, unsigned int unused1, &lt;br /&gt;
								unsigned int cookie, &lt;br /&gt;
								struct am_device_notification **subscription);&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
        /* Unregisters notifications. Buggy (iTunes 8.2): if you subscribe, unsubscribe and subscribe again, arriving &lt;br /&gt;
           notifications will contain cookie and subscription from 1st call to subscribe, not the 2nd one. iTunes &lt;br /&gt;
           calls this function only once on exit.&lt;br /&gt;
        */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationUnsubscribe(am_device_notification* subscription);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns device_id field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMDeviceGetConnectionID(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns serial field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyDeviceIdentifier(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Connects to the iPhone. Pass in the am_device structure that the&lt;br /&gt;
	 *  notification callback will give to you.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successfully connected&lt;br /&gt;
	 *      MDERR_SYSCALL           if setsockopt() failed&lt;br /&gt;
	 *      MDERR_QUERY_FAILED      if the daemon query failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if USBMuxConnectByPort returned 0xffffffff&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceConnect(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Calls PairingRecordPath() on the given device, than tests whether the path&lt;br /&gt;
	 *  which that function returns exists. During the initial connect, the path&lt;br /&gt;
	 *  returned by that function is '/', and so this returns 1.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      0   if the path did not exist&lt;br /&gt;
	 *      1   if it did&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceIsPaired(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDevicePair(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  iTunes calls this function immediately after testing whether the device is&lt;br /&gt;
	 *  paired. It creates a pairing file and establishes a Lockdown connection.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the supplied device is null&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceValidatePairing(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Creates a Lockdown session and adjusts the device structure appropriately&lt;br /&gt;
	 *  to indicate that the session has been started. iTunes calls this function&lt;br /&gt;
	 *  after validating pairing.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartSession(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* Reads various device settings. One of domain or cfstring arguments should be NULL.&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for cfstring:&lt;br /&gt;
	 * ActivationState&lt;br /&gt;
	 * ActivationStateAcknowledged&lt;br /&gt;
	 * BasebandBootloaderVersion&lt;br /&gt;
	 * BasebandVersion&lt;br /&gt;
	 * BluetoothAddress&lt;br /&gt;
	 * BuildVersion&lt;br /&gt;
	 * DeviceCertificate&lt;br /&gt;
	 * DeviceClass&lt;br /&gt;
	 * DeviceName&lt;br /&gt;
	 * DevicePublicKey&lt;br /&gt;
	 * FirmwareVersion&lt;br /&gt;
	 * HostAttached&lt;br /&gt;
	 * IntegratedCircuitCardIdentity&lt;br /&gt;
	 * InternationalMobileEquipmentIdentity&lt;br /&gt;
	 * InternationalMobileSubscriberIdentity&lt;br /&gt;
	 * ModelNumber&lt;br /&gt;
	 * PhoneNumber&lt;br /&gt;
	 * ProductType&lt;br /&gt;
	 * ProductVersion&lt;br /&gt;
	 * ProtocolVersion&lt;br /&gt;
	 * RegionInfo&lt;br /&gt;
	 * SBLockdownEverRegisteredKey&lt;br /&gt;
	 * SIMStatus&lt;br /&gt;
	 * SerialNumber&lt;br /&gt;
	 * SomebodySetTimeZone&lt;br /&gt;
	 * TimeIntervalSince1970&lt;br /&gt;
	 * TimeZone&lt;br /&gt;
	 * TimeZoneOffsetFromUTC&lt;br /&gt;
	 * TrustedHostAttached&lt;br /&gt;
	 * UniqueDeviceID&lt;br /&gt;
	 * Uses24HourClock&lt;br /&gt;
	 * WiFiAddress&lt;br /&gt;
	 * iTunesHasConnected&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for domain:&lt;br /&gt;
         * com.apple.mobile.battery&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyValue(struct am_device *device, CFStringRef domain, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* Starts a service and returns a socket file descriptor that can be used in order to further&lt;br /&gt;
	 * access the service. You should stop the session and disconnect before using&lt;br /&gt;
	 * the service. iTunes calls this function after starting a session. It starts &lt;br /&gt;
	 * the service and the SSL connection. service_name should be one of the AMSVC_*&lt;br /&gt;
	 * constants.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_SYSCALL           if the setsockopt() call failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartService(struct am_device *device, CFStringRef &lt;br /&gt;
									  service_name, int *socket_fd);&lt;br /&gt;
	&lt;br /&gt;
	/* Stops a session. You should do this before accessing services.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStopSession(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/* Decrements reference counter and, if nothing left, releases resources hold &lt;br /&gt;
	 * by connection, invalidates  pointer to device&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRelease(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Increments reference counter&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRetain(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Opens an Apple File Connection. You must start the appropriate service&lt;br /&gt;
	 * first with AMDeviceStartService(). In iTunes, io_timeout is 0.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_AFC_OUT_OF_MEMORY if malloc() failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionOpen(int socket_fd, unsigned int io_timeout,&lt;br /&gt;
								  struct afc_connection **conn);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        /* Copy an enviromental variable value from iBoot&lt;br /&gt;
         */&lt;br /&gt;
        __DLLIMPORT CFStringRef AMRecoveryModeCopyEnvironmentVariable(struct am_recovery_device *rdev, CFStringRef var);&lt;br /&gt;
	&lt;br /&gt;
	/* Pass in a pointer to an afc_dictionary structure. It will be filled. You can&lt;br /&gt;
	 * iterate it using AFCKeyValueRead. When done use AFCKeyValueClose. Possible keys:&lt;br /&gt;
	 * FSFreeBytes - free bytes on system device for afc2, user device for afc&lt;br /&gt;
	 * FSBlockSize - filesystem block size&lt;br /&gt;
	 * FSTotalBytes - size of device&lt;br /&gt;
	 * Model - iPhone1,1 etc.&lt;br /&gt;
&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDeviceInfoOpen(struct afc_connection *conn, struct&lt;br /&gt;
								  afc_dictionary **info);&lt;br /&gt;
	&lt;br /&gt;
	/* Turns debug mode on if the environment variable AFCDEBUG is set to a numeric&lt;br /&gt;
	 * value, or if the file '/AFCDEBUG' is present and contains a value. */&lt;br /&gt;
#if defined(__APPLE__)&lt;br /&gt;
	void AFCPlatformInitialize();&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
	/* Opens a directory on the iPhone. Pass in a pointer in dir to be filled in.&lt;br /&gt;
	 * Note that this normally only accesses the iTunes sandbox/partition as the&lt;br /&gt;
	 * root, which is /var/root/Media. Pathnames are specified with '/' delimiters&lt;br /&gt;
	 * as in Unix style. Use UTF-8 to specify non-ASCII symbols in path.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								 afc_directory **dir);&lt;br /&gt;
	&lt;br /&gt;
	/* Acquires the next entry in a directory previously opened with&lt;br /&gt;
	 * AFCDirectoryOpen(). When dirent is filled with a NULL value, then the end&lt;br /&gt;
	 * of the directory has been reached. '.' and '..' will be returned as the&lt;br /&gt;
	 * first two entries in each directory except the root; you may want to skip&lt;br /&gt;
	 * over them.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful, even if no entries remain&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryRead(struct afc_connection *conn, struct afc_directory *dir,&lt;br /&gt;
								 char **dirent);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryClose(afc_connection *conn, struct afc_directory *dir);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryCreate(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRemovePath(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRenamePath(afc_connection *conn, char *oldpath, char *newpath);&lt;br /&gt;
&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
	/* Creates symbolic or hard link&lt;br /&gt;
         * linktype - int64: 1 means hard link, 2 - soft (symbolic) link&lt;br /&gt;
         * target - absolute or relative path to link target&lt;br /&gt;
         * linkname - absolute path where to create new link&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCLinkPath(struct afc_connection *conn, long long int linktype, const char *target, &lt;br /&gt;
								                              const char *linkname);&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
	/* Opens file for reading or writing without locking it in any way. afc_file_ref should not be shared between threads - &lt;br /&gt;
         * opening file in one thread and closing it in another will lead to possible crash.&lt;br /&gt;
	 * path - UTF-8 encoded absolute path to file&lt;br /&gt;
	 * mode 2 = read, mode 3 = write; unknown = 0 &lt;br /&gt;
	 * ref - receives file handle&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefOpen(struct afc_connection *conn, char *path, unsigned&lt;br /&gt;
							   long long int mode, afc_file_ref *ref);&lt;br /&gt;
	/* Reads specified amount (len) of bytes from file into buf. Puts actual count of read bytes into len on return&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefRead(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   void *buf, unsigned int *len);&lt;br /&gt;
	/* Writes specified amount (len) of bytes from buf into file.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefWrite(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
								void *buf, unsigned int len);&lt;br /&gt;
	/* Moves the file pointer to a specified location.&lt;br /&gt;
	 * offset - Number of bytes from origin (int64)&lt;br /&gt;
	 * origin - 0 = from beginning, 1 = from current position, 2 = from end&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefSeek(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long offset, int origin, int unused);&lt;br /&gt;
&lt;br /&gt;
	/* Gets the current position of a file pointer into offset argument.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefTell(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long* offset);&lt;br /&gt;
&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefLock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefUnlock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefClose(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
&lt;br /&gt;
	/* Opens dictionary describing specified file or directory (iTunes below 8.2 allowed using AFCGetFileInfo&lt;br /&gt;
	   to get the same information)&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileInfoOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								afc_dictionary **info);&lt;br /&gt;
&lt;br /&gt;
	/* Reads next entry from dictionary. When last entry is read, function returns NULL in key argument&lt;br /&gt;
	   Possible keys:&lt;br /&gt;
	     &amp;quot;st_size&amp;quot;:     val - size in bytes&lt;br /&gt;
	     &amp;quot;st_blocks&amp;quot;:   val - size in blocks&lt;br /&gt;
	     &amp;quot;st_nlink&amp;quot;:    val - number of hardlinks&lt;br /&gt;
	     &amp;quot;st_ifmt&amp;quot;:     val - &amp;quot;S_IFDIR&amp;quot; for folders&lt;br /&gt;
	                        &amp;quot;S_IFLNK&amp;quot; for symlinks&lt;br /&gt;
	     &amp;quot;LinkTarget&amp;quot;:  val - path to symlink target&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueRead(struct afc_dictionary *dict, char **key, char **&lt;br /&gt;
								val);&lt;br /&gt;
	/* Closes dictionary&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueClose(struct afc_dictionary *dict);&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the context field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetContext(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the fs_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetFSBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the io_timeout field of the given AFC connection. In iTunes this is&lt;br /&gt;
	 * 0. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetIOTimeout(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the sock_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetSocketBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Closes the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionClose(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Registers for device notifications related to the restore process. unknown0&lt;br /&gt;
	 * is zero when iTunes calls this. In iTunes,&lt;br /&gt;
	 * the callbacks are located at:&lt;br /&gt;
	 *      1: $3ac68e-$3ac6b1, calls $3ac542(unknown1, arg, 0)&lt;br /&gt;
	 *      2: $3ac66a-$3ac68d, calls $3ac542(unknown1, 0, arg)&lt;br /&gt;
	 *      3: $3ac762-$3ac785, calls $3ac6b2(unknown1, arg, 0)&lt;br /&gt;
	 *      4: $3ac73e-$3ac761, calls $3ac6b2(unknown1, 0, arg)&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreRegisterForDeviceNotifications(&lt;br /&gt;
				am_restore_device_notification_callback dfu_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback dfu_disconnect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_disconnect_callback,&lt;br /&gt;
				unsigned int unknown0,&lt;br /&gt;
				void *user_info);&lt;br /&gt;
	&lt;br /&gt;
	/* Causes the restore functions to spit out (unhelpful) progress messages to&lt;br /&gt;
	 * the file specified by the given path. iTunes always calls this right before&lt;br /&gt;
	 * restoring with a path of&lt;br /&gt;
	 * &amp;quot;$HOME/Library/Logs/iPhone Updater Logs/iPhoneUpdater X.log&amp;quot;, where X is an&lt;br /&gt;
	 * unused number.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreEnableFileLogging(char *path);&lt;br /&gt;
	&lt;br /&gt;
	/* Initializes a new option dictionary to default values. Pass the constant&lt;br /&gt;
	 * kCFAllocatorDefault as the allocator. The option dictionary looks as&lt;br /&gt;
	 * follows:&lt;br /&gt;
	 * {&lt;br /&gt;
	 *      NORImageType =&amp;gt; 'production',&lt;br /&gt;
	 *      AutoBootDelay =&amp;gt; 0,&lt;br /&gt;
	 *      KernelCacheType =&amp;gt; 'Release',&lt;br /&gt;
	 *      UpdateBaseband =&amp;gt; true,&lt;br /&gt;
	 *      DFUFileType =&amp;gt; 'RELEASE',&lt;br /&gt;
	 *      SystemImageType =&amp;gt; 'User',&lt;br /&gt;
	 *      CreateFilesystemPartitions =&amp;gt; true,&lt;br /&gt;
	 *      FlashNOR =&amp;gt; true,&lt;br /&gt;
	 *      RestoreBootArgs =&amp;gt; 'rd=md0 nand-enable-reformat=1 -progress'&lt;br /&gt;
	 *      BootImageType =&amp;gt; 'User'&lt;br /&gt;
	 *  }&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      the option dictionary   if successful&lt;br /&gt;
	 *      NULL                    if out of memory&lt;br /&gt;
	 */ &lt;br /&gt;
	__DLLIMPORT CFMutableDictionaryRef AMRestoreCreateDefaultOptions(CFAllocatorRef allocator);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRecoveryModeRestore(struct am_recovery_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRestoreModeRestore(struct am_restore_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT struct am_restore_device *AMRestoreModeDeviceCreate(unsigned int unknown0,&lt;br /&gt;
				unsigned int connection_id, unsigned int unknown1);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreCreatePathsForBundle(CFStringRef restore_bundle_path,&lt;br /&gt;
				CFStringRef kernel_cache_type, CFStringRef boot_image_type, unsigned int&lt;br /&gt;
				unknown0, CFStringRef *firmware_dir_path, CFStringRef *&lt;br /&gt;
				kernelcache_restore_path, unsigned int unknown1, CFStringRef *&lt;br /&gt;
				ramdisk_path);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreModeDeviceReboot(struct am_restore_device *rdev);	// Added by JB 30.07.2008&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceEnterRecovery(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDisconnect(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* to use this, start the service &amp;quot;com.apple.mobile.notification_proxy&amp;quot;, handle will be the socket to use */&lt;br /&gt;
	typedef void (*NOTIFY_CALLBACK)(CFSTR notification, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDPostNotification(SOCKET socket, CFStringRef  notification, CFStringRef userinfo);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDObserveNotification(SOCKET socket, CFSTR notification);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDListenForNotifications(SOCKET socket, NOTIFY_CALLBACK cb, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDShutdownNotificationProxy(SOCKET socket);&lt;br /&gt;
	&lt;br /&gt;
	/*edits by geohot*/&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDeactivate(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceActivate(struct am_device *device, CFDictionaryRef dict);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceRemoveValue(struct am_device *device, unsigned int, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Pass in a usbmux_listener_1 structure and a usbmux_listener_2 structure&lt;br /&gt;
	 *  pointer, which will be filled with the resulting usbmux_listener_2.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if completed successfully&lt;br /&gt;
	 *      MDERR_USBMUX_ARG_NULL   if one of the arguments was NULL&lt;br /&gt;
	 *      MDERR_USBMUX_FAILED     if the listener was not created successfully&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerCreate(struct usbmux_listener_1 *esi_fp8, struct&lt;br /&gt;
										usbmux_listener_2 **eax_fp12);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerHandleData(void *);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Private routines - here be dragons&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/* AMRestorePerformRestoreModeRestore() calls this function with a dictionary&lt;br /&gt;
	 * in order to perform certain special restore operations&lt;br /&gt;
	 * (RESTORED_OPERATION_*). It is thought that this function might enable&lt;br /&gt;
	 * significant access to the phone. */&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef unsigned int (*t_performOperation)(struct am_restore_device *rdev,&lt;br /&gt;
	 CFDictionaryRef op) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_performOperation _performOperation = (t_performOperation)0x3c39fa4b;&lt;br /&gt;
	 */ &lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef int (*t_socketForPort)(struct am_restore_device *rdev, unsigned int port)&lt;br /&gt;
	 __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_socketForPort _socketForPort = (t_socketForPort)(void *)0x3c39f36c;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef void (*t_restored_send_message)(int port, CFDictionaryRef msg);&lt;br /&gt;
	 t_restored_send_message _restored_send_message = (t_restored_send_message)0x3c3a4e40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef CFDictionaryRef (*t_restored_receive_message)(int port);&lt;br /&gt;
	 t_restored_receive_message _restored_receive_message = (t_restored_receive_message)0x3c3a4d40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendControlPacket)(struct am_recovery_device *rdev, unsigned&lt;br /&gt;
	 int msg1, unsigned int msg2, unsigned int unknown0, unsigned int *unknown1,&lt;br /&gt;
	 unsigned char *unknown2) __attribute__ ((regparm(3)));&lt;br /&gt;
	 t_sendControlPacket _sendControlPacket = (t_sendControlPacket)0x3c3a3da3;;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendCommandToDevice)(struct am_recovery_device *rdev,&lt;br /&gt;
	 CFStringRef cmd) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_sendCommandToDevice _sendCommandToDevice = (t_sendCommandToDevice)0x3c3a3e3b;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceReadPipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int read_pipe, unsigned char *data, unsigned int *len);&lt;br /&gt;
	 t_AMRUSBInterfaceReadPipe _AMRUSBInterfaceReadPipe = (t_AMRUSBInterfaceReadPipe)0x3c3a27e8;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceWritePipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int write_pipe, void *data, unsigned int len);&lt;br /&gt;
	 t_AMRUSBInterfaceWritePipe _AMRUSBInterfaceWritePipe = (t_AMRUSBInterfaceWritePipe)0x3c3a27cb;&lt;br /&gt;
	 */&lt;br /&gt;
	&lt;br /&gt;
	int performOperation(am_restore_device *rdev, CFMutableDictionaryRef message);&lt;br /&gt;
	int socketForPort(am_restore_device *rdev, unsigned int portnum);&lt;br /&gt;
	int sendCommandToDevice(am_recovery_device *rdev, CFStringRef cfs, int block);&lt;br /&gt;
	int sendFileToDevice(am_recovery_device *rdev, CFStringRef filename); &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
}&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
/* -*- mode:c; indent-tabs-mode:nil; c-basic-offset:2; tab-width:2; */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===AFC Connection===&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
===Locking the Device for Sync===&lt;br /&gt;
When iTunes sends a new song to the device, the device shows a &amp;quot;Sync in progress&amp;quot; screen and when complete, the Music app on the device re-reads the iTunesDB file so it picks up the new song.&lt;br /&gt;
&lt;br /&gt;
To get this behaviour, first start the notification service:&lt;br /&gt;
&amp;lt;pre&amp;gt;SOCKET socket;&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we post a notificaton message to signal that we are going to start a sync:&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncWillStart&amp;quot;), NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we open the itunes lock file:&lt;br /&gt;
&amp;lt;pre&amp;gt;afc_file_ref lockref;&lt;br /&gt;
AFCFileRefOpen(conn, &amp;quot;/com.apple.itunes.lock_sync&amp;quot;, 2, &amp;amp;lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now post a notification to say we are going to lock this file, and try and lock it.&lt;br /&gt;
If the AFCFileRefLock call fails, pause and repeat.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncLockRequest&amp;quot;), NULL);&lt;br /&gt;
mach_error_t error = AFCFileRefLock(conn, lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the file is successfully locked, post another notification, and stop the notification service.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket,CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidStart&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the sync can proceed, so copy your files across and make the changes to the iTunesDB.&lt;br /&gt;
&lt;br /&gt;
To release the lock, start the notification system again, unlock and close the lock file, and send a sync finished notification message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;AFCFileRefUnlock(conn, lockref);&lt;br /&gt;
AFCFileRefClose(conn, lockref);&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&lt;br /&gt;
AMDPostNotification(socket, &amp;amp;CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidFinish&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To handle &amp;quot;Slide to Cancel&amp;quot; and terminate sync when user slides cancel switch, use AMDObserveNotification to subscribe notifications about “com.apple.itunes-client.syncCancelRequest”. Then start listening for notifications (AMDListenForNotifications) until you get “AMDNotificationFaceplant”.&lt;br /&gt;
When notification got, you should unlock and close lock file handle (don’t sure if you need to post “syncDidFinish” to proxy, seems it doesn’t matter) and terminate sync gracefully.&lt;br /&gt;
The same notification is also got when you unplug your device, so you should always be ready for errors.&lt;br /&gt;
&lt;br /&gt;
NOTE: You may find that starting the notification_proxy service once and once only at the start of your app and using the same socket in calls to AMDPostNotification works better. iTunes opens and closes the notification_proxy regularly, but it appears to be a bit flakey when you open/close it all the time.&lt;br /&gt;
&lt;br /&gt;
===Private Functions===&lt;br /&gt;
&lt;br /&gt;
====How to find address of privates functions in iTunesMobileDevice.dll or MobileDevice.framework====&lt;br /&gt;
&lt;br /&gt;
In order to obtain the address of a usable private function in MobileDevice, you will have to be able to understand x86-64 assembly to reverse engineer it. A private function will not have its name exported in the mach-o symbol table, so in a debugger, like GDB, it will show up as part of another function. However, you will know that it is a separate function as a new stack frame is set up.&lt;br /&gt;
&lt;br /&gt;
====Private Function Address List====&lt;br /&gt;
&lt;br /&gt;
=====OSX.6 - iTunes 9.0.2(25)=====&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendCommandToiBoot(struct am_recovery_device *rdev, CFStringRef command, int u);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 868(0x364) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym(). &lt;br /&gt;
Address: 0x1000245ea&lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
1. rdev - the device you wish to send the command to.&lt;br /&gt;
2. a CFStringRef of the command to send.&lt;br /&gt;
3. an integer, whose use is currently unknown, but should be set to 0 to work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendFileToiDevice(struct am_recovery_device *rdev, CFStringRef filename);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 1763(0x6e3) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym().&lt;br /&gt;
Address: 0x100024969&lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
1. rdev - the device you wish to send the file to.&lt;br /&gt;
2. a CFStringRef of the path to the file to send.&lt;br /&gt;
&lt;br /&gt;
===Libraries Implementations===&lt;br /&gt;
&lt;br /&gt;
* [http://gojohnnyboi.com/source/afcinstall.cpp afcinstall (command line, os x file install via afc)]&lt;br /&gt;
* [http://code.google.com/p/iphuc/ iPhuc (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/iphucwin32/ iPhuc Win32 (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/manzana/ manzana (.Net Library)]&lt;br /&gt;
* [http://code.google.com/p/independence/source/browse/trunk/libPhoneInteraction/ libPhoneInteraction (C Library)]&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5686</id>
		<title>MobileDevice Library</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5686"/>
		<updated>2009-11-22T14:15:21Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MobileDevice Library is used by [[iTunes]] to transfer data between iPhone and computer over the USB connection.&lt;br /&gt;
&lt;br /&gt;
===PC Windows : iTunesMobileDevice.dll===&lt;br /&gt;
&lt;br /&gt;
* Location : Location is stored in '''iTunesMobileDeviceDLL''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Mobile Device Support\Shared''' key. Usually - C:\Program Files\Common Files\Apple\Mobile Device Support\bin\iTunesMobileDevice.dll.&lt;br /&gt;
&lt;br /&gt;
* Supporting CoreFoundation.dll (used for CFStringRef, CFPropertyListRef management) is located in the same dir (when using iTunes prior 9.0). &lt;br /&gt;
&lt;br /&gt;
* For iTunes 9.0 location of CoreFoundation.dll is stored in '''InstallDir''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Application Support''' key, usually C:\Program Files\Common Files\Apple\Apple Application Support\. CoreFoundation.dll from Mobile Device Support\bin should not be used.&lt;br /&gt;
&lt;br /&gt;
===Mac OSX : MobileDevice.framework===&lt;br /&gt;
&lt;br /&gt;
* Location : /System/Library/PrivateFrameworks/MobileDevice.framework&lt;br /&gt;
* Export command : &amp;quot;nm /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===MobileDevice Header (mobiledevice.h)===&lt;br /&gt;
&lt;br /&gt;
Reverse engineered C header for MobileDevice Library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* ----------------------------------------------------------------------------&lt;br /&gt;
 *   MobileDevice.h - interface to MobileDevice.framework &lt;br /&gt;
 * ------------------------------------------------------------------------- */&lt;br /&gt;
#pragma once&lt;br /&gt;
&lt;br /&gt;
#ifndef MOBILEDEVICE_H&lt;br /&gt;
#define MOBILEDEVICE_H&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
extern &amp;quot;C&amp;quot; {&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
#ifndef __GCC__&lt;br /&gt;
#pragma pack&lt;br /&gt;
#define __PACK&lt;br /&gt;
#else&lt;br /&gt;
#define __PACK __attribute__((__packed__))&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#if defined(WIN32)&lt;br /&gt;
#define __DLLIMPORT [DllImport(&amp;quot;iTunesMobileDevice.dll&amp;quot;)]&lt;br /&gt;
	using namespace System::Runtime::InteropServices;&lt;br /&gt;
#include &amp;lt;CoreFoundation.h&amp;gt;&lt;br /&gt;
	typedef unsigned int mach_error_t;&lt;br /&gt;
#elif defined(__APPLE__)&lt;br /&gt;
#define __DLLIMPORT&lt;br /&gt;
#include &amp;lt;CoreFoundation/CoreFoundation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;mach/error.h&amp;gt;&lt;br /&gt;
#endif	&lt;br /&gt;
	&lt;br /&gt;
	/* Error codes */&lt;br /&gt;
#define MDERR_APPLE_MOBILE  (err_system(0x3a))&lt;br /&gt;
#define MDERR_IPHONE        (err_sub(0))&lt;br /&gt;
	&lt;br /&gt;
	/* Apple Mobile (AM*) errors */&lt;br /&gt;
#define MDERR_OK                ERR_SUCCESS&lt;br /&gt;
#define MDERR_SYSCALL           (ERR_MOBILE_DEVICE | 0x01)&lt;br /&gt;
#define MDERR_OUT_OF_MEMORY     (ERR_MOBILE_DEVICE | 0x03)&lt;br /&gt;
#define MDERR_QUERY_FAILED      (ERR_MOBILE_DEVICE | 0x04) &lt;br /&gt;
#define MDERR_INVALID_ARGUMENT  (ERR_MOBILE_DEVICE | 0x0b)&lt;br /&gt;
#define MDERR_DICT_NOT_LOADED   (ERR_MOBILE_DEVICE | 0x25)&lt;br /&gt;
	&lt;br /&gt;
	/* Apple File Connection (AFC*) errors */&lt;br /&gt;
#define MDERR_AFC_OUT_OF_MEMORY 0x03&lt;br /&gt;
	&lt;br /&gt;
	/* USBMux errors */&lt;br /&gt;
#define MDERR_USBMUX_ARG_NULL   0x16&lt;br /&gt;
#define MDERR_USBMUX_FAILED     0xffffffff&lt;br /&gt;
	&lt;br /&gt;
	/* Messages passed to device notification callbacks: passed as part of&lt;br /&gt;
	 * am_device_notification_callback_info. */&lt;br /&gt;
#define ADNCI_MSG_CONNECTED     1&lt;br /&gt;
#define ADNCI_MSG_DISCONNECTED  2&lt;br /&gt;
#define ADNCI_MSG_UNSUBSCRIBED  3&lt;br /&gt;
	&lt;br /&gt;
#define AMD_IPHONE_PRODUCT_ID   0x1290&lt;br /&gt;
	//#define AMD_IPHONE_SERIAL       &amp;quot;&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
	/* Services, found in /System/Library/Lockdown/Services.plist */&lt;br /&gt;
#define AMSVC_AFC                   CFSTR(&amp;quot;com.apple.afc&amp;quot;)&lt;br /&gt;
#define AMSVC_BACKUP                CFSTR(&amp;quot;com.apple.mobilebackup&amp;quot;)&lt;br /&gt;
#define AMSVC_CRASH_REPORT_COPY     CFSTR(&amp;quot;com.apple.crashreportcopy&amp;quot;)&lt;br /&gt;
#define AMSVC_DEBUG_IMAGE_MOUNT     CFSTR(&amp;quot;com.apple.mobile.debug_image_mount&amp;quot;)&lt;br /&gt;
#define AMSVC_NOTIFICATION_PROXY    CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;)&lt;br /&gt;
#define AMSVC_PURPLE_TEST           CFSTR(&amp;quot;com.apple.purpletestr&amp;quot;)&lt;br /&gt;
#define AMSVC_SOFTWARE_UPDATE       CFSTR(&amp;quot;com.apple.mobile.software_update&amp;quot;)&lt;br /&gt;
#define AMSVC_SYNC                  CFSTR(&amp;quot;com.apple.mobilesync&amp;quot;)&lt;br /&gt;
#define AMSVC_SCREENSHOT            CFSTR(&amp;quot;com.apple.screenshotr&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSLOG_RELAY          CFSTR(&amp;quot;com.apple.syslog_relay&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSTEM_PROFILER       CFSTR(&amp;quot;com.apple.mobile.system_profiler&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned int afc_error_t;&lt;br /&gt;
	typedef unsigned int usbmux_error_t;&lt;br /&gt;
	&lt;br /&gt;
	struct am_recovery_device;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification_callback_info {&lt;br /&gt;
		struct am_device *dev;  /* 0    device */ &lt;br /&gt;
		unsigned int msg;       /* 4    one of ADNCI_MSG_* */&lt;br /&gt;
                struct am_device_notification* subscription; &lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
	&lt;br /&gt;
	/* This is a CoreFoundation object of class AMRecoveryModeDevice. */&lt;br /&gt;
	struct am_recovery_device {&lt;br /&gt;
		unsigned char unknown0[8];                          /* 0 */&lt;br /&gt;
		am_restore_device_notification_callback callback;   /* 8 */&lt;br /&gt;
		void *user_info;                                    /* 12 */&lt;br /&gt;
		unsigned char unknown1[12];                         /* 16 */&lt;br /&gt;
		unsigned int readwrite_pipe;                        /* 28 */&lt;br /&gt;
		unsigned char read_pipe;                            /* 32 */&lt;br /&gt;
		unsigned char write_ctrl_pipe;                      /* 33 */&lt;br /&gt;
		unsigned char read_unknown_pipe;                    /* 34 */&lt;br /&gt;
		unsigned char write_file_pipe;                      /* 35 */&lt;br /&gt;
		unsigned char write_input_pipe;                     /* 36 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* A CoreFoundation object of class AMRestoreModeDevice. */&lt;br /&gt;
	struct am_restore_device {&lt;br /&gt;
		unsigned char unknown[32];&lt;br /&gt;
		int port;&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device notification callback function. */&lt;br /&gt;
	typedef void(*am_device_notification_callback)(struct am_device_notification_callback_info *, int cookie);&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the _AMDDeviceAttached function.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void *amd_device_attached_callback;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
&lt;br /&gt;
	/* Structure that contains internal data used by AMDevice... functions. Never try &lt;br /&gt;
         * to access its members directly! Use AMDeviceCopyDeviceIdentifier, &lt;br /&gt;
         * AMDeviceGetConnectionID, AMDeviceRetain, AMDeviceRelease instead. */&lt;br /&gt;
	struct am_device {&lt;br /&gt;
		unsigned char unknown0[16]; /* 0 - zero */&lt;br /&gt;
		unsigned int device_id;     /* 16 */&lt;br /&gt;
		unsigned int product_id;    /* 20 - set to AMD_IPHONE_PRODUCT_ID */&lt;br /&gt;
		char *serial;               /* 24 - set to UDID, Unique Device Identifier */&lt;br /&gt;
		unsigned int unknown1;      /* 28 */&lt;br /&gt;
		unsigned int unknown2;      /* 32 - reference counter, increased by AMDeviceRetain, decreased by AMDeviceRelease*/&lt;br /&gt;
		unsigned int lockdown_conn; /* 36 */&lt;br /&gt;
		unsigned char unknown3[8];  /* 40 */&lt;br /&gt;
#if (__ITUNES_VER &amp;gt; 740)&lt;br /&gt;
		unsigned int unknown4;      /* 48 - used to store CriticalSection Handle*/&lt;br /&gt;
#endif&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
		unsigned char unknown5[24];  /* 52 */&lt;br /&gt;
#endif&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification {&lt;br /&gt;
		unsigned int unknown0;                      /* 0 */&lt;br /&gt;
		unsigned int unknown1;                      /* 4 */&lt;br /&gt;
		unsigned int unknown2;                      /* 8 */&lt;br /&gt;
		am_device_notification_callback callback;   /* 12 */ &lt;br /&gt;
		unsigned int cookie;                      /* 16 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct afc_connection {&lt;br /&gt;
		unsigned int handle;            /* 0 */&lt;br /&gt;
		unsigned int unknown0;          /* 4 */&lt;br /&gt;
		unsigned char unknown1;         /* 8 */&lt;br /&gt;
		unsigned char padding[3];       /* 9 */&lt;br /&gt;
		unsigned int unknown2;          /* 12 */&lt;br /&gt;
		unsigned int unknown3;          /* 16 */&lt;br /&gt;
		unsigned int unknown4;          /* 20 */&lt;br /&gt;
		unsigned int fs_block_size;     /* 24 */&lt;br /&gt;
		unsigned int sock_block_size;   /* 28: always 0x3c */&lt;br /&gt;
		unsigned int io_timeout;        /* 32: from AFCConnectionOpen, usu. 0 */&lt;br /&gt;
		void *afc_lock;                 /* 36 */&lt;br /&gt;
		unsigned int context;           /* 40 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
	struct afc_device_info {&lt;br /&gt;
		unsigned char unknown[12];  /* 0 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_directory {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_dictionary {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned long long afc_file_ref;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_1 {                  /* offset   value in iTunes */&lt;br /&gt;
		unsigned int unknown0;                  /* 0        1 */&lt;br /&gt;
		unsigned char *unknown1;                /* 4        ptr, maybe device? */&lt;br /&gt;
		amd_device_attached_callback callback;  /* 8        _AMDDeviceAttached */&lt;br /&gt;
		unsigned int unknown3;                  /* 12 */&lt;br /&gt;
		unsigned int unknown4;                  /* 16 */&lt;br /&gt;
		unsigned int unknown5;                  /* 20 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_2 {&lt;br /&gt;
		unsigned char unknown0[4144];&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_bootloader_control_packet {&lt;br /&gt;
		unsigned char opcode;       /* 0 */&lt;br /&gt;
		unsigned char length;       /* 1 */&lt;br /&gt;
		unsigned char magic[2];     /* 2: 0x34, 0x12 */&lt;br /&gt;
		unsigned char payload[0];   /* 4 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Registers a notification with the current run loop. The callback gets&lt;br /&gt;
	 *  copied into the notification struct, as well as being registered with the&lt;br /&gt;
	 *  current run loop. Cookie gets copied into cookie in the same.&lt;br /&gt;
	 *  (Cookie is a user info parameter that gets passed as an arg to&lt;br /&gt;
	 *  the callback) unused0 and unused1 are both 0 when iTunes calls this.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Never try to acces directly or copy contents of dev and subscription fields &lt;br /&gt;
	 *  in am_device_notification_callback_info. Treat them as abstract handles. &lt;br /&gt;
	 *  When done with connection use AMDeviceRelease to free resources allocated for am_device.&lt;br /&gt;
	 *  &lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK            if successful&lt;br /&gt;
	 *      MDERR_SYSCALL       if CFRunLoopAddSource() failed&lt;br /&gt;
	 *      MDERR_OUT_OF_MEMORY if we ran out of memory&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationSubscribe(am_device_notification_callback callback, &lt;br /&gt;
								unsigned int unused0, unsigned int unused1, &lt;br /&gt;
								unsigned int cookie, &lt;br /&gt;
								struct am_device_notification **subscription);&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
        /* Unregisters notifications. Buggy (iTunes 8.2): if you subscribe, unsubscribe and subscribe again, arriving &lt;br /&gt;
           notifications will contain cookie and subscription from 1st call to subscribe, not the 2nd one. iTunes &lt;br /&gt;
           calls this function only once on exit.&lt;br /&gt;
        */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationUnsubscribe(am_device_notification* subscription);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns device_id field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMDeviceGetConnectionID(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns serial field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyDeviceIdentifier(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Connects to the iPhone. Pass in the am_device structure that the&lt;br /&gt;
	 *  notification callback will give to you.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successfully connected&lt;br /&gt;
	 *      MDERR_SYSCALL           if setsockopt() failed&lt;br /&gt;
	 *      MDERR_QUERY_FAILED      if the daemon query failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if USBMuxConnectByPort returned 0xffffffff&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceConnect(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Calls PairingRecordPath() on the given device, than tests whether the path&lt;br /&gt;
	 *  which that function returns exists. During the initial connect, the path&lt;br /&gt;
	 *  returned by that function is '/', and so this returns 1.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      0   if the path did not exist&lt;br /&gt;
	 *      1   if it did&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceIsPaired(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDevicePair(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  iTunes calls this function immediately after testing whether the device is&lt;br /&gt;
	 *  paired. It creates a pairing file and establishes a Lockdown connection.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the supplied device is null&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceValidatePairing(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Creates a Lockdown session and adjusts the device structure appropriately&lt;br /&gt;
	 *  to indicate that the session has been started. iTunes calls this function&lt;br /&gt;
	 *  after validating pairing.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartSession(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* Reads various device settings. One of domain or cfstring arguments should be NULL.&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for cfstring:&lt;br /&gt;
	 * ActivationState&lt;br /&gt;
	 * ActivationStateAcknowledged&lt;br /&gt;
	 * BasebandBootloaderVersion&lt;br /&gt;
	 * BasebandVersion&lt;br /&gt;
	 * BluetoothAddress&lt;br /&gt;
	 * BuildVersion&lt;br /&gt;
	 * DeviceCertificate&lt;br /&gt;
	 * DeviceClass&lt;br /&gt;
	 * DeviceName&lt;br /&gt;
	 * DevicePublicKey&lt;br /&gt;
	 * FirmwareVersion&lt;br /&gt;
	 * HostAttached&lt;br /&gt;
	 * IntegratedCircuitCardIdentity&lt;br /&gt;
	 * InternationalMobileEquipmentIdentity&lt;br /&gt;
	 * InternationalMobileSubscriberIdentity&lt;br /&gt;
	 * ModelNumber&lt;br /&gt;
	 * PhoneNumber&lt;br /&gt;
	 * ProductType&lt;br /&gt;
	 * ProductVersion&lt;br /&gt;
	 * ProtocolVersion&lt;br /&gt;
	 * RegionInfo&lt;br /&gt;
	 * SBLockdownEverRegisteredKey&lt;br /&gt;
	 * SIMStatus&lt;br /&gt;
	 * SerialNumber&lt;br /&gt;
	 * SomebodySetTimeZone&lt;br /&gt;
	 * TimeIntervalSince1970&lt;br /&gt;
	 * TimeZone&lt;br /&gt;
	 * TimeZoneOffsetFromUTC&lt;br /&gt;
	 * TrustedHostAttached&lt;br /&gt;
	 * UniqueDeviceID&lt;br /&gt;
	 * Uses24HourClock&lt;br /&gt;
	 * WiFiAddress&lt;br /&gt;
	 * iTunesHasConnected&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for domain:&lt;br /&gt;
         * com.apple.mobile.battery&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyValue(struct am_device *device, CFStringRef domain, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* Starts a service and returns a socket file descriptor that can be used in order to further&lt;br /&gt;
	 * access the service. You should stop the session and disconnect before using&lt;br /&gt;
	 * the service. iTunes calls this function after starting a session. It starts &lt;br /&gt;
	 * the service and the SSL connection. service_name should be one of the AMSVC_*&lt;br /&gt;
	 * constants.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_SYSCALL           if the setsockopt() call failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartService(struct am_device *device, CFStringRef &lt;br /&gt;
									  service_name, int *socket_fd);&lt;br /&gt;
	&lt;br /&gt;
	/* Stops a session. You should do this before accessing services.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStopSession(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/* Decrements reference counter and, if nothing left, releases resources hold &lt;br /&gt;
	 * by connection, invalidates  pointer to device&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRelease(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Increments reference counter&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRetain(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Opens an Apple File Connection. You must start the appropriate service&lt;br /&gt;
	 * first with AMDeviceStartService(). In iTunes, io_timeout is 0.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_AFC_OUT_OF_MEMORY if malloc() failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionOpen(int socket_fd, unsigned int io_timeout,&lt;br /&gt;
								  struct afc_connection **conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Pass in a pointer to an afc_dictionary structure. It will be filled. You can&lt;br /&gt;
	 * iterate it using AFCKeyValueRead. When done use AFCKeyValueClose. Possible keys:&lt;br /&gt;
	 * FSFreeBytes - free bytes on system device for afc2, user device for afc&lt;br /&gt;
	 * FSBlockSize - filesystem block size&lt;br /&gt;
	 * FSTotalBytes - size of device&lt;br /&gt;
	 * Model - iPhone1,1 etc.&lt;br /&gt;
&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDeviceInfoOpen(struct afc_connection *conn, struct&lt;br /&gt;
								  afc_dictionary **info);&lt;br /&gt;
	&lt;br /&gt;
	/* Turns debug mode on if the environment variable AFCDEBUG is set to a numeric&lt;br /&gt;
	 * value, or if the file '/AFCDEBUG' is present and contains a value. */&lt;br /&gt;
#if defined(__APPLE__)&lt;br /&gt;
	void AFCPlatformInit();&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
	/* Opens a directory on the iPhone. Pass in a pointer in dir to be filled in.&lt;br /&gt;
	 * Note that this normally only accesses the iTunes sandbox/partition as the&lt;br /&gt;
	 * root, which is /var/root/Media. Pathnames are specified with '/' delimiters&lt;br /&gt;
	 * as in Unix style. Use UTF-8 to specify non-ASCII symbols in path.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								 afc_directory **dir);&lt;br /&gt;
	&lt;br /&gt;
	/* Acquires the next entry in a directory previously opened with&lt;br /&gt;
	 * AFCDirectoryOpen(). When dirent is filled with a NULL value, then the end&lt;br /&gt;
	 * of the directory has been reached. '.' and '..' will be returned as the&lt;br /&gt;
	 * first two entries in each directory except the root; you may want to skip&lt;br /&gt;
	 * over them.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful, even if no entries remain&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryRead(struct afc_connection *conn, struct afc_directory *dir,&lt;br /&gt;
								 char **dirent);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryClose(afc_connection *conn, struct afc_directory *dir);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryCreate(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRemovePath(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRenamePath(afc_connection *conn, char *oldpath, char *newpath);&lt;br /&gt;
&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
	/* Creates symbolic or hard link&lt;br /&gt;
         * linktype - int64: 1 means hard link, 2 - soft (symbolic) link&lt;br /&gt;
         * target - absolute or relative path to link target&lt;br /&gt;
         * linkname - absolute path where to create new link&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCLinkPath(struct afc_connection *conn, long long int linktype, const char *target, &lt;br /&gt;
								                              const char *linkname);&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
	/* Opens file for reading or writing without locking it in any way. afc_file_ref should not be shared between threads - &lt;br /&gt;
         * opening file in one thread and closing it in another will lead to possible crash.&lt;br /&gt;
	 * path - UTF-8 encoded absolute path to file&lt;br /&gt;
	 * mode 2 = read, mode 3 = write; unknown = 0 &lt;br /&gt;
	 * ref - receives file handle&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefOpen(struct afc_connection *conn, char *path, unsigned&lt;br /&gt;
							   long long int mode, afc_file_ref *ref);&lt;br /&gt;
	/* Reads specified amount (len) of bytes from file into buf. Puts actual count of read bytes into len on return&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefRead(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   void *buf, unsigned int *len);&lt;br /&gt;
	/* Writes specified amount (len) of bytes from buf into file.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefWrite(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
								void *buf, unsigned int len);&lt;br /&gt;
	/* Moves the file pointer to a specified location.&lt;br /&gt;
	 * offset - Number of bytes from origin (int64)&lt;br /&gt;
	 * origin - 0 = from beginning, 1 = from current position, 2 = from end&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefSeek(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long offset, int origin, int unused);&lt;br /&gt;
&lt;br /&gt;
	/* Gets the current position of a file pointer into offset argument.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefTell(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long* offset);&lt;br /&gt;
&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefLock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefUnlock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefClose(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
&lt;br /&gt;
	/* Opens dictionary describing specified file or directory (iTunes below 8.2 allowed using AFCGetFileInfo&lt;br /&gt;
	   to get the same information)&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileInfoOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								afc_dictionary **info);&lt;br /&gt;
&lt;br /&gt;
	/* Reads next entry from dictionary. When last entry is read, function returns NULL in key argument&lt;br /&gt;
	   Possible keys:&lt;br /&gt;
	     &amp;quot;st_size&amp;quot;:     val - size in bytes&lt;br /&gt;
	     &amp;quot;st_blocks&amp;quot;:   val - size in blocks&lt;br /&gt;
	     &amp;quot;st_nlink&amp;quot;:    val - number of hardlinks&lt;br /&gt;
	     &amp;quot;st_ifmt&amp;quot;:     val - &amp;quot;S_IFDIR&amp;quot; for folders&lt;br /&gt;
	                        &amp;quot;S_IFLNK&amp;quot; for symlinks&lt;br /&gt;
	     &amp;quot;LinkTarget&amp;quot;:  val - path to symlink target&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueRead(struct afc_dictionary *dict, char **key, char **&lt;br /&gt;
								val);&lt;br /&gt;
	/* Closes dictionary&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueClose(struct afc_dictionary *dict);&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the context field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetContext(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the fs_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetFSBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the io_timeout field of the given AFC connection. In iTunes this is&lt;br /&gt;
	 * 0. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetIOTimeout(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the sock_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetSocketBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Closes the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionClose(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Registers for device notifications related to the restore process. unknown0&lt;br /&gt;
	 * is zero when iTunes calls this. In iTunes,&lt;br /&gt;
	 * the callbacks are located at:&lt;br /&gt;
	 *      1: $3ac68e-$3ac6b1, calls $3ac542(unknown1, arg, 0)&lt;br /&gt;
	 *      2: $3ac66a-$3ac68d, calls $3ac542(unknown1, 0, arg)&lt;br /&gt;
	 *      3: $3ac762-$3ac785, calls $3ac6b2(unknown1, arg, 0)&lt;br /&gt;
	 *      4: $3ac73e-$3ac761, calls $3ac6b2(unknown1, 0, arg)&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreRegisterForDeviceNotifications(&lt;br /&gt;
				am_restore_device_notification_callback dfu_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback dfu_disconnect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_disconnect_callback,&lt;br /&gt;
				unsigned int unknown0,&lt;br /&gt;
				void *user_info);&lt;br /&gt;
	&lt;br /&gt;
	/* Causes the restore functions to spit out (unhelpful) progress messages to&lt;br /&gt;
	 * the file specified by the given path. iTunes always calls this right before&lt;br /&gt;
	 * restoring with a path of&lt;br /&gt;
	 * &amp;quot;$HOME/Library/Logs/iPhone Updater Logs/iPhoneUpdater X.log&amp;quot;, where X is an&lt;br /&gt;
	 * unused number.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreEnableFileLogging(char *path);&lt;br /&gt;
	&lt;br /&gt;
	/* Initializes a new option dictionary to default values. Pass the constant&lt;br /&gt;
	 * kCFAllocatorDefault as the allocator. The option dictionary looks as&lt;br /&gt;
	 * follows:&lt;br /&gt;
	 * {&lt;br /&gt;
	 *      NORImageType =&amp;gt; 'production',&lt;br /&gt;
	 *      AutoBootDelay =&amp;gt; 0,&lt;br /&gt;
	 *      KernelCacheType =&amp;gt; 'Release',&lt;br /&gt;
	 *      UpdateBaseband =&amp;gt; true,&lt;br /&gt;
	 *      DFUFileType =&amp;gt; 'RELEASE',&lt;br /&gt;
	 *      SystemImageType =&amp;gt; 'User',&lt;br /&gt;
	 *      CreateFilesystemPartitions =&amp;gt; true,&lt;br /&gt;
	 *      FlashNOR =&amp;gt; true,&lt;br /&gt;
	 *      RestoreBootArgs =&amp;gt; 'rd=md0 nand-enable-reformat=1 -progress'&lt;br /&gt;
	 *      BootImageType =&amp;gt; 'User'&lt;br /&gt;
	 *  }&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      the option dictionary   if successful&lt;br /&gt;
	 *      NULL                    if out of memory&lt;br /&gt;
	 */ &lt;br /&gt;
	__DLLIMPORT CFMutableDictionaryRef AMRestoreCreateDefaultOptions(CFAllocatorRef allocator);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRecoveryModeRestore(struct am_recovery_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRestoreModeRestore(struct am_restore_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT struct am_restore_device *AMRestoreModeDeviceCreate(unsigned int unknown0,&lt;br /&gt;
				unsigned int connection_id, unsigned int unknown1);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreCreatePathsForBundle(CFStringRef restore_bundle_path,&lt;br /&gt;
				CFStringRef kernel_cache_type, CFStringRef boot_image_type, unsigned int&lt;br /&gt;
				unknown0, CFStringRef *firmware_dir_path, CFStringRef *&lt;br /&gt;
				kernelcache_restore_path, unsigned int unknown1, CFStringRef *&lt;br /&gt;
				ramdisk_path);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreModeDeviceReboot(struct am_restore_device *rdev);	// Added by JB 30.07.2008&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceEnterRecovery(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDisconnect(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* to use this, start the service &amp;quot;com.apple.mobile.notification_proxy&amp;quot;, handle will be the socket to use */&lt;br /&gt;
	typedef void (*NOTIFY_CALLBACK)(CFSTR notification, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDPostNotification(SOCKET socket, CFStringRef  notification, CFStringRef userinfo);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDObserveNotification(SOCKET socket, CFSTR notification);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDListenForNotifications(SOCKET socket, NOTIFY_CALLBACK cb, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDShutdownNotificationProxy(SOCKET socket);&lt;br /&gt;
	&lt;br /&gt;
	/*edits by geohot*/&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDeactivate(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceActivate(struct am_device *device, CFDictionaryRef dict);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceRemoveValue(struct am_device *device, unsigned int, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Pass in a usbmux_listener_1 structure and a usbmux_listener_2 structure&lt;br /&gt;
	 *  pointer, which will be filled with the resulting usbmux_listener_2.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if completed successfully&lt;br /&gt;
	 *      MDERR_USBMUX_ARG_NULL   if one of the arguments was NULL&lt;br /&gt;
	 *      MDERR_USBMUX_FAILED     if the listener was not created successfully&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerCreate(struct usbmux_listener_1 *esi_fp8, struct&lt;br /&gt;
										usbmux_listener_2 **eax_fp12);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerHandleData(void *);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Private routines - here be dragons&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/* AMRestorePerformRestoreModeRestore() calls this function with a dictionary&lt;br /&gt;
	 * in order to perform certain special restore operations&lt;br /&gt;
	 * (RESTORED_OPERATION_*). It is thought that this function might enable&lt;br /&gt;
	 * significant access to the phone. */&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef unsigned int (*t_performOperation)(struct am_restore_device *rdev,&lt;br /&gt;
	 CFDictionaryRef op) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_performOperation _performOperation = (t_performOperation)0x3c39fa4b;&lt;br /&gt;
	 */ &lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef int (*t_socketForPort)(struct am_restore_device *rdev, unsigned int port)&lt;br /&gt;
	 __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_socketForPort _socketForPort = (t_socketForPort)(void *)0x3c39f36c;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef void (*t_restored_send_message)(int port, CFDictionaryRef msg);&lt;br /&gt;
	 t_restored_send_message _restored_send_message = (t_restored_send_message)0x3c3a4e40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef CFDictionaryRef (*t_restored_receive_message)(int port);&lt;br /&gt;
	 t_restored_receive_message _restored_receive_message = (t_restored_receive_message)0x3c3a4d40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendControlPacket)(struct am_recovery_device *rdev, unsigned&lt;br /&gt;
	 int msg1, unsigned int msg2, unsigned int unknown0, unsigned int *unknown1,&lt;br /&gt;
	 unsigned char *unknown2) __attribute__ ((regparm(3)));&lt;br /&gt;
	 t_sendControlPacket _sendControlPacket = (t_sendControlPacket)0x3c3a3da3;;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendCommandToDevice)(struct am_recovery_device *rdev,&lt;br /&gt;
	 CFStringRef cmd) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_sendCommandToDevice _sendCommandToDevice = (t_sendCommandToDevice)0x3c3a3e3b;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceReadPipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int read_pipe, unsigned char *data, unsigned int *len);&lt;br /&gt;
	 t_AMRUSBInterfaceReadPipe _AMRUSBInterfaceReadPipe = (t_AMRUSBInterfaceReadPipe)0x3c3a27e8;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceWritePipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int write_pipe, void *data, unsigned int len);&lt;br /&gt;
	 t_AMRUSBInterfaceWritePipe _AMRUSBInterfaceWritePipe = (t_AMRUSBInterfaceWritePipe)0x3c3a27cb;&lt;br /&gt;
	 */&lt;br /&gt;
	&lt;br /&gt;
	int performOperation(am_restore_device *rdev, CFMutableDictionaryRef message);&lt;br /&gt;
	int socketForPort(am_restore_device *rdev, unsigned int portnum);&lt;br /&gt;
	int sendCommandToDevice(am_recovery_device *rdev, CFStringRef cfs, int block);&lt;br /&gt;
	int sendFileToDevice(am_recovery_device *rdev, CFStringRef filename); &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
}&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
/* -*- mode:c; indent-tabs-mode:nil; c-basic-offset:2; tab-width:2; */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===AFC Connection===&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
===Locking the Device for Sync===&lt;br /&gt;
When iTunes sends a new song to the device, the device shows a &amp;quot;Sync in progress&amp;quot; screen and when complete, the Music app on the device re-reads the iTunesDB file so it picks up the new song.&lt;br /&gt;
&lt;br /&gt;
To get this behaviour, first start the notification service:&lt;br /&gt;
&amp;lt;pre&amp;gt;SOCKET socket;&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we post a notificaton message to signal that we are going to start a sync:&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncWillStart&amp;quot;), NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we open the itunes lock file:&lt;br /&gt;
&amp;lt;pre&amp;gt;afc_file_ref lockref;&lt;br /&gt;
AFCFileRefOpen(conn, &amp;quot;/com.apple.itunes.lock_sync&amp;quot;, 2, &amp;amp;lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now post a notification to say we are going to lock this file, and try and lock it.&lt;br /&gt;
If the AFCFileRefLock call fails, pause and repeat.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncLockRequest&amp;quot;), NULL);&lt;br /&gt;
mach_error_t error = AFCFileRefLock(conn, lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the file is successfully locked, post another notification, and stop the notification service.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket,CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidStart&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the sync can proceed, so copy your files across and make the changes to the iTunesDB.&lt;br /&gt;
&lt;br /&gt;
To release the lock, start the notification system again, unlock and close the lock file, and send a sync finished notification message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;AFCFileRefUnlock(conn, lockref);&lt;br /&gt;
AFCFileRefClose(conn, lockref);&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&lt;br /&gt;
AMDPostNotification(socket, &amp;amp;CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidFinish&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To handle &amp;quot;Slide to Cancel&amp;quot; and terminate sync when user slides cancel switch, use AMDObserveNotification to subscribe notifications about “com.apple.itunes-client.syncCancelRequest”. Then start listening for notifications (AMDListenForNotifications) until you get “AMDNotificationFaceplant”.&lt;br /&gt;
When notification got, you should unlock and close lock file handle (don’t sure if you need to post “syncDidFinish” to proxy, seems it doesn’t matter) and terminate sync gracefully.&lt;br /&gt;
The same notification is also got when you unplug your device, so you should always be ready for errors.&lt;br /&gt;
&lt;br /&gt;
NOTE: You may find that starting the notification_proxy service once and once only at the start of your app and using the same socket in calls to AMDPostNotification works better. iTunes opens and closes the notification_proxy regularly, but it appears to be a bit flakey when you open/close it all the time.&lt;br /&gt;
&lt;br /&gt;
===Private Functions===&lt;br /&gt;
&lt;br /&gt;
====How to find address of privates functions in iTunesMobileDevice.dll or MobileDevice.framework====&lt;br /&gt;
&lt;br /&gt;
In order to obtain the address of a usable private function in MobileDevice, you will have to be able to understand x86-64 assembly to reverse engineer it. A private function will not have its name exported in the mach-o symbol table, so in a debugger, like GDB, it will show up as part of another function. However, you will know that it is a separate function as a new stack frame is set up.&lt;br /&gt;
&lt;br /&gt;
====Private Function Address List====&lt;br /&gt;
&lt;br /&gt;
=====OSX.6 - iTunes 9.0.2(25)=====&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendCommandToiBoot(struct am_recovery_device *rdev, CFStringRef command, int u);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 868(0x364) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym(). &lt;br /&gt;
Address: 0x1000245ea&lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
1. rdev - the device you wish to send the command to.&lt;br /&gt;
2. a CFStringRef of the command to send.&lt;br /&gt;
3. an integer, whose use is currently unknown, but should be set to 0 to work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendFileToiDevice(struct am_recovery_device *rdev, CFStringRef filename);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 1763(0x6e3) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym().&lt;br /&gt;
Address: 0x100024969&lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
1. rdev - the device you wish to send the file to.&lt;br /&gt;
2. a CFStringRef of the path to the file to send.&lt;br /&gt;
&lt;br /&gt;
===Libraries Implementations===&lt;br /&gt;
&lt;br /&gt;
* [http://gojohnnyboi.com/source/afcinstall.cpp afcinstall (command line, os x file install via afc)]&lt;br /&gt;
* [http://code.google.com/p/iphuc/ iPhuc (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/iphucwin32/ iPhuc Win32 (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/manzana/ manzana (.Net Library)]&lt;br /&gt;
* [http://code.google.com/p/independence/source/browse/trunk/libPhoneInteraction/ libPhoneInteraction (C Library)]&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5681</id>
		<title>MobileDevice Library</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5681"/>
		<updated>2009-11-22T02:15:38Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MobileDevice Library is used by [[iTunes]] to transfer data between iPhone and computer over the USB connection.&lt;br /&gt;
&lt;br /&gt;
===PC Windows : iTunesMobileDevice.dll===&lt;br /&gt;
&lt;br /&gt;
* Location : Location is stored in '''iTunesMobileDeviceDLL''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Mobile Device Support\Shared''' key. Usually - C:\Program Files\Common Files\Apple\Mobile Device Support\bin\iTunesMobileDevice.dll.&lt;br /&gt;
&lt;br /&gt;
* Supporting CoreFoundation.dll (used for CFStringRef, CFPropertyListRef management) is located in the same dir (when using iTunes prior 9.0). &lt;br /&gt;
&lt;br /&gt;
* For iTunes 9.0 location of CoreFoundation.dll is stored in '''InstallDir''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Application Support''' key, usually C:\Program Files\Common Files\Apple\Apple Application Support\. CoreFoundation.dll from Mobile Device Support\bin should not be used.&lt;br /&gt;
&lt;br /&gt;
===Mac OSX : MobileDevice.framework===&lt;br /&gt;
&lt;br /&gt;
* Location : /System/Library/PrivateFrameworks/MobileDevice.framework&lt;br /&gt;
* Export command : &amp;quot;nm /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===MobileDevice Header (mobiledevice.h)===&lt;br /&gt;
&lt;br /&gt;
Reverse engineered C header for MobileDevice Library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* ----------------------------------------------------------------------------&lt;br /&gt;
 *   MobileDevice.h - interface to MobileDevice.framework &lt;br /&gt;
 * ------------------------------------------------------------------------- */&lt;br /&gt;
#pragma once&lt;br /&gt;
&lt;br /&gt;
#ifndef MOBILEDEVICE_H&lt;br /&gt;
#define MOBILEDEVICE_H&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
extern &amp;quot;C&amp;quot; {&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
#ifndef __GCC__&lt;br /&gt;
#pragma pack&lt;br /&gt;
#define __PACK&lt;br /&gt;
#else&lt;br /&gt;
#define __PACK __attribute__((__packed__))&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#if defined(WIN32)&lt;br /&gt;
#define __DLLIMPORT [DllImport(&amp;quot;iTunesMobileDevice.dll&amp;quot;)]&lt;br /&gt;
	using namespace System::Runtime::InteropServices;&lt;br /&gt;
#include &amp;lt;CoreFoundation.h&amp;gt;&lt;br /&gt;
	typedef unsigned int mach_error_t;&lt;br /&gt;
#elif defined(__APPLE__)&lt;br /&gt;
#define __DLLIMPORT&lt;br /&gt;
#include &amp;lt;CoreFoundation/CoreFoundation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;mach/error.h&amp;gt;&lt;br /&gt;
#endif	&lt;br /&gt;
	&lt;br /&gt;
	/* Error codes */&lt;br /&gt;
#define MDERR_APPLE_MOBILE  (err_system(0x3a))&lt;br /&gt;
#define MDERR_IPHONE        (err_sub(0))&lt;br /&gt;
	&lt;br /&gt;
	/* Apple Mobile (AM*) errors */&lt;br /&gt;
#define MDERR_OK                ERR_SUCCESS&lt;br /&gt;
#define MDERR_SYSCALL           (ERR_MOBILE_DEVICE | 0x01)&lt;br /&gt;
#define MDERR_OUT_OF_MEMORY     (ERR_MOBILE_DEVICE | 0x03)&lt;br /&gt;
#define MDERR_QUERY_FAILED      (ERR_MOBILE_DEVICE | 0x04) &lt;br /&gt;
#define MDERR_INVALID_ARGUMENT  (ERR_MOBILE_DEVICE | 0x0b)&lt;br /&gt;
#define MDERR_DICT_NOT_LOADED   (ERR_MOBILE_DEVICE | 0x25)&lt;br /&gt;
	&lt;br /&gt;
	/* Apple File Connection (AFC*) errors */&lt;br /&gt;
#define MDERR_AFC_OUT_OF_MEMORY 0x03&lt;br /&gt;
	&lt;br /&gt;
	/* USBMux errors */&lt;br /&gt;
#define MDERR_USBMUX_ARG_NULL   0x16&lt;br /&gt;
#define MDERR_USBMUX_FAILED     0xffffffff&lt;br /&gt;
	&lt;br /&gt;
	/* Messages passed to device notification callbacks: passed as part of&lt;br /&gt;
	 * am_device_notification_callback_info. */&lt;br /&gt;
#define ADNCI_MSG_CONNECTED     1&lt;br /&gt;
#define ADNCI_MSG_DISCONNECTED  2&lt;br /&gt;
#define ADNCI_MSG_UNSUBSCRIBED  3&lt;br /&gt;
	&lt;br /&gt;
#define AMD_IPHONE_PRODUCT_ID   0x1290&lt;br /&gt;
	//#define AMD_IPHONE_SERIAL       &amp;quot;&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
	/* Services, found in /System/Library/Lockdown/Services.plist */&lt;br /&gt;
#define AMSVC_AFC                   CFSTR(&amp;quot;com.apple.afc&amp;quot;)&lt;br /&gt;
#define AMSVC_BACKUP                CFSTR(&amp;quot;com.apple.mobilebackup&amp;quot;)&lt;br /&gt;
#define AMSVC_CRASH_REPORT_COPY     CFSTR(&amp;quot;com.apple.crashreportcopy&amp;quot;)&lt;br /&gt;
#define AMSVC_DEBUG_IMAGE_MOUNT     CFSTR(&amp;quot;com.apple.mobile.debug_image_mount&amp;quot;)&lt;br /&gt;
#define AMSVC_NOTIFICATION_PROXY    CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;)&lt;br /&gt;
#define AMSVC_PURPLE_TEST           CFSTR(&amp;quot;com.apple.purpletestr&amp;quot;)&lt;br /&gt;
#define AMSVC_SOFTWARE_UPDATE       CFSTR(&amp;quot;com.apple.mobile.software_update&amp;quot;)&lt;br /&gt;
#define AMSVC_SYNC                  CFSTR(&amp;quot;com.apple.mobilesync&amp;quot;)&lt;br /&gt;
#define AMSVC_SCREENSHOT            CFSTR(&amp;quot;com.apple.screenshotr&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSLOG_RELAY          CFSTR(&amp;quot;com.apple.syslog_relay&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSTEM_PROFILER       CFSTR(&amp;quot;com.apple.mobile.system_profiler&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned int afc_error_t;&lt;br /&gt;
	typedef unsigned int usbmux_error_t;&lt;br /&gt;
	&lt;br /&gt;
	struct am_recovery_device;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification_callback_info {&lt;br /&gt;
		struct am_device *dev;  /* 0    device */ &lt;br /&gt;
		unsigned int msg;       /* 4    one of ADNCI_MSG_* */&lt;br /&gt;
                struct am_device_notification* subscription; &lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
	&lt;br /&gt;
	/* This is a CoreFoundation object of class AMRecoveryModeDevice. */&lt;br /&gt;
	struct am_recovery_device {&lt;br /&gt;
		unsigned char unknown0[8];                          /* 0 */&lt;br /&gt;
		am_restore_device_notification_callback callback;   /* 8 */&lt;br /&gt;
		void *user_info;                                    /* 12 */&lt;br /&gt;
		unsigned char unknown1[12];                         /* 16 */&lt;br /&gt;
		unsigned int readwrite_pipe;                        /* 28 */&lt;br /&gt;
		unsigned char read_pipe;                            /* 32 */&lt;br /&gt;
		unsigned char write_ctrl_pipe;                      /* 33 */&lt;br /&gt;
		unsigned char read_unknown_pipe;                    /* 34 */&lt;br /&gt;
		unsigned char write_file_pipe;                      /* 35 */&lt;br /&gt;
		unsigned char write_input_pipe;                     /* 36 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* A CoreFoundation object of class AMRestoreModeDevice. */&lt;br /&gt;
	struct am_restore_device {&lt;br /&gt;
		unsigned char unknown[32];&lt;br /&gt;
		int port;&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device notification callback function. */&lt;br /&gt;
	typedef void(*am_device_notification_callback)(struct am_device_notification_callback_info *, int cookie);&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the _AMDDeviceAttached function.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void *amd_device_attached_callback;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
&lt;br /&gt;
	/* Structure that contains internal data used by AMDevice... functions. Never try &lt;br /&gt;
         * to access its members directly! Use AMDeviceCopyDeviceIdentifier, &lt;br /&gt;
         * AMDeviceGetConnectionID, AMDeviceRetain, AMDeviceRelease instead. */&lt;br /&gt;
	struct am_device {&lt;br /&gt;
		unsigned char unknown0[16]; /* 0 - zero */&lt;br /&gt;
		unsigned int device_id;     /* 16 */&lt;br /&gt;
		unsigned int product_id;    /* 20 - set to AMD_IPHONE_PRODUCT_ID */&lt;br /&gt;
		char *serial;               /* 24 - set to UDID, Unique Device Identifier */&lt;br /&gt;
		unsigned int unknown1;      /* 28 */&lt;br /&gt;
		unsigned int unknown2;      /* 32 - reference counter, increased by AMDeviceRetain, decreased by AMDeviceRelease*/&lt;br /&gt;
		unsigned int lockdown_conn; /* 36 */&lt;br /&gt;
		unsigned char unknown3[8];  /* 40 */&lt;br /&gt;
#if (__ITUNES_VER &amp;gt; 740)&lt;br /&gt;
		unsigned int unknown4;      /* 48 - used to store CriticalSection Handle*/&lt;br /&gt;
#endif&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
		unsigned char unknown5[24];  /* 52 */&lt;br /&gt;
#endif&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification {&lt;br /&gt;
		unsigned int unknown0;                      /* 0 */&lt;br /&gt;
		unsigned int unknown1;                      /* 4 */&lt;br /&gt;
		unsigned int unknown2;                      /* 8 */&lt;br /&gt;
		am_device_notification_callback callback;   /* 12 */ &lt;br /&gt;
		unsigned int cookie;                      /* 16 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct afc_connection {&lt;br /&gt;
		unsigned int handle;            /* 0 */&lt;br /&gt;
		unsigned int unknown0;          /* 4 */&lt;br /&gt;
		unsigned char unknown1;         /* 8 */&lt;br /&gt;
		unsigned char padding[3];       /* 9 */&lt;br /&gt;
		unsigned int unknown2;          /* 12 */&lt;br /&gt;
		unsigned int unknown3;          /* 16 */&lt;br /&gt;
		unsigned int unknown4;          /* 20 */&lt;br /&gt;
		unsigned int fs_block_size;     /* 24 */&lt;br /&gt;
		unsigned int sock_block_size;   /* 28: always 0x3c */&lt;br /&gt;
		unsigned int io_timeout;        /* 32: from AFCConnectionOpen, usu. 0 */&lt;br /&gt;
		void *afc_lock;                 /* 36 */&lt;br /&gt;
		unsigned int context;           /* 40 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
	struct afc_device_info {&lt;br /&gt;
		unsigned char unknown[12];  /* 0 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_directory {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_dictionary {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned long long afc_file_ref;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_1 {                  /* offset   value in iTunes */&lt;br /&gt;
		unsigned int unknown0;                  /* 0        1 */&lt;br /&gt;
		unsigned char *unknown1;                /* 4        ptr, maybe device? */&lt;br /&gt;
		amd_device_attached_callback callback;  /* 8        _AMDDeviceAttached */&lt;br /&gt;
		unsigned int unknown3;                  /* 12 */&lt;br /&gt;
		unsigned int unknown4;                  /* 16 */&lt;br /&gt;
		unsigned int unknown5;                  /* 20 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_2 {&lt;br /&gt;
		unsigned char unknown0[4144];&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_bootloader_control_packet {&lt;br /&gt;
		unsigned char opcode;       /* 0 */&lt;br /&gt;
		unsigned char length;       /* 1 */&lt;br /&gt;
		unsigned char magic[2];     /* 2: 0x34, 0x12 */&lt;br /&gt;
		unsigned char payload[0];   /* 4 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Registers a notification with the current run loop. The callback gets&lt;br /&gt;
	 *  copied into the notification struct, as well as being registered with the&lt;br /&gt;
	 *  current run loop. Cookie gets copied into cookie in the same.&lt;br /&gt;
	 *  (Cookie is a user info parameter that gets passed as an arg to&lt;br /&gt;
	 *  the callback) unused0 and unused1 are both 0 when iTunes calls this.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Never try to acces directly or copy contents of dev and subscription fields &lt;br /&gt;
	 *  in am_device_notification_callback_info. Treat them as abstract handles. &lt;br /&gt;
	 *  When done with connection use AMDeviceRelease to free resources allocated for am_device.&lt;br /&gt;
	 *  &lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK            if successful&lt;br /&gt;
	 *      MDERR_SYSCALL       if CFRunLoopAddSource() failed&lt;br /&gt;
	 *      MDERR_OUT_OF_MEMORY if we ran out of memory&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationSubscribe(am_device_notification_callback callback, &lt;br /&gt;
								unsigned int unused0, unsigned int unused1, &lt;br /&gt;
								unsigned int cookie, &lt;br /&gt;
								struct am_device_notification **subscription);&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
        /* Unregisters notifications. Buggy (iTunes 8.2): if you subscribe, unsubscribe and subscribe again, arriving &lt;br /&gt;
           notifications will contain cookie and subscription from 1st call to subscribe, not the 2nd one. iTunes &lt;br /&gt;
           calls this function only once on exit.&lt;br /&gt;
        */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationUnsubscribe(am_device_notification* subscription);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns device_id field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMDeviceGetConnectionID(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns serial field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyDeviceIdentifier(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Connects to the iPhone. Pass in the am_device structure that the&lt;br /&gt;
	 *  notification callback will give to you.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successfully connected&lt;br /&gt;
	 *      MDERR_SYSCALL           if setsockopt() failed&lt;br /&gt;
	 *      MDERR_QUERY_FAILED      if the daemon query failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if USBMuxConnectByPort returned 0xffffffff&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceConnect(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Calls PairingRecordPath() on the given device, than tests whether the path&lt;br /&gt;
	 *  which that function returns exists. During the initial connect, the path&lt;br /&gt;
	 *  returned by that function is '/', and so this returns 1.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      0   if the path did not exist&lt;br /&gt;
	 *      1   if it did&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceIsPaired(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDevicePair(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  iTunes calls this function immediately after testing whether the device is&lt;br /&gt;
	 *  paired. It creates a pairing file and establishes a Lockdown connection.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the supplied device is null&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceValidatePairing(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Creates a Lockdown session and adjusts the device structure appropriately&lt;br /&gt;
	 *  to indicate that the session has been started. iTunes calls this function&lt;br /&gt;
	 *  after validating pairing.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartSession(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* Reads various device settings. One of domain or cfstring arguments should be NULL.&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for cfstring:&lt;br /&gt;
	 * ActivationState&lt;br /&gt;
	 * ActivationStateAcknowledged&lt;br /&gt;
	 * BasebandBootloaderVersion&lt;br /&gt;
	 * BasebandVersion&lt;br /&gt;
	 * BluetoothAddress&lt;br /&gt;
	 * BuildVersion&lt;br /&gt;
	 * DeviceCertificate&lt;br /&gt;
	 * DeviceClass&lt;br /&gt;
	 * DeviceName&lt;br /&gt;
	 * DevicePublicKey&lt;br /&gt;
	 * FirmwareVersion&lt;br /&gt;
	 * HostAttached&lt;br /&gt;
	 * IntegratedCircuitCardIdentity&lt;br /&gt;
	 * InternationalMobileEquipmentIdentity&lt;br /&gt;
	 * InternationalMobileSubscriberIdentity&lt;br /&gt;
	 * ModelNumber&lt;br /&gt;
	 * PhoneNumber&lt;br /&gt;
	 * ProductType&lt;br /&gt;
	 * ProductVersion&lt;br /&gt;
	 * ProtocolVersion&lt;br /&gt;
	 * RegionInfo&lt;br /&gt;
	 * SBLockdownEverRegisteredKey&lt;br /&gt;
	 * SIMStatus&lt;br /&gt;
	 * SerialNumber&lt;br /&gt;
	 * SomebodySetTimeZone&lt;br /&gt;
	 * TimeIntervalSince1970&lt;br /&gt;
	 * TimeZone&lt;br /&gt;
	 * TimeZoneOffsetFromUTC&lt;br /&gt;
	 * TrustedHostAttached&lt;br /&gt;
	 * UniqueDeviceID&lt;br /&gt;
	 * Uses24HourClock&lt;br /&gt;
	 * WiFiAddress&lt;br /&gt;
	 * iTunesHasConnected&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for domain:&lt;br /&gt;
         * com.apple.mobile.battery&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyValue(struct am_device *device, CFStringRef domain, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* Starts a service and returns a socket file descriptor that can be used in order to further&lt;br /&gt;
	 * access the service. You should stop the session and disconnect before using&lt;br /&gt;
	 * the service. iTunes calls this function after starting a session. It starts &lt;br /&gt;
	 * the service and the SSL connection. service_name should be one of the AMSVC_*&lt;br /&gt;
	 * constants.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_SYSCALL           if the setsockopt() call failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartService(struct am_device *device, CFStringRef &lt;br /&gt;
									  service_name, int *socket_fd);&lt;br /&gt;
	&lt;br /&gt;
	/* Stops a session. You should do this before accessing services.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStopSession(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/* Decrements reference counter and, if nothing left, releases resources hold &lt;br /&gt;
	 * by connection, invalidates  pointer to device&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRelease(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Increments reference counter&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRetain(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Opens an Apple File Connection. You must start the appropriate service&lt;br /&gt;
	 * first with AMDeviceStartService(). In iTunes, io_timeout is 0.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_AFC_OUT_OF_MEMORY if malloc() failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionOpen(int socket_fd, unsigned int io_timeout,&lt;br /&gt;
								  struct afc_connection **conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Pass in a pointer to an afc_dictionary structure. It will be filled. You can&lt;br /&gt;
	 * iterate it using AFCKeyValueRead. When done use AFCKeyValueClose. Possible keys:&lt;br /&gt;
	 * FSFreeBytes - free bytes on system device for afc2, user device for afc&lt;br /&gt;
	 * FSBlockSize - filesystem block size&lt;br /&gt;
	 * FSTotalBytes - size of device&lt;br /&gt;
	 * Model - iPhone1,1 etc.&lt;br /&gt;
&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDeviceInfoOpen(struct afc_connection *conn, struct&lt;br /&gt;
								  afc_dictionary **info);&lt;br /&gt;
	&lt;br /&gt;
	/* Turns debug mode on if the environment variable AFCDEBUG is set to a numeric&lt;br /&gt;
	 * value, or if the file '/AFCDEBUG' is present and contains a value. */&lt;br /&gt;
#if defined(__APPLE__)&lt;br /&gt;
	void AFCPlatformInit();&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
	/* Opens a directory on the iPhone. Pass in a pointer in dir to be filled in.&lt;br /&gt;
	 * Note that this normally only accesses the iTunes sandbox/partition as the&lt;br /&gt;
	 * root, which is /var/root/Media. Pathnames are specified with '/' delimiters&lt;br /&gt;
	 * as in Unix style. Use UTF-8 to specify non-ASCII symbols in path.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								 afc_directory **dir);&lt;br /&gt;
	&lt;br /&gt;
	/* Acquires the next entry in a directory previously opened with&lt;br /&gt;
	 * AFCDirectoryOpen(). When dirent is filled with a NULL value, then the end&lt;br /&gt;
	 * of the directory has been reached. '.' and '..' will be returned as the&lt;br /&gt;
	 * first two entries in each directory except the root; you may want to skip&lt;br /&gt;
	 * over them.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful, even if no entries remain&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryRead(struct afc_connection *conn, struct afc_directory *dir,&lt;br /&gt;
								 char **dirent);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryClose(afc_connection *conn, struct afc_directory *dir);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryCreate(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRemovePath(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRenamePath(afc_connection *conn, char *oldpath, char *newpath);&lt;br /&gt;
&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
	/* Creates symbolic or hard link&lt;br /&gt;
         * linktype - int64: 1 means hard link, 2 - soft (symbolic) link&lt;br /&gt;
         * target - absolute or relative path to link target&lt;br /&gt;
         * linkname - absolute path where to create new link&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCLinkPath(struct afc_connection *conn, long long int linktype, const char *target, &lt;br /&gt;
								                              const char *linkname);&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
	/* Opens file for reading or writing without locking it in any way. afc_file_ref should not be shared between threads - &lt;br /&gt;
         * opening file in one thread and closing it in another will lead to possible crash.&lt;br /&gt;
	 * path - UTF-8 encoded absolute path to file&lt;br /&gt;
	 * mode 2 = read, mode 3 = write; unknown = 0 &lt;br /&gt;
	 * ref - receives file handle&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefOpen(struct afc_connection *conn, char *path, unsigned&lt;br /&gt;
							   long long int mode, afc_file_ref *ref);&lt;br /&gt;
	/* Reads specified amount (len) of bytes from file into buf. Puts actual count of read bytes into len on return&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefRead(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   void *buf, unsigned int *len);&lt;br /&gt;
	/* Writes specified amount (len) of bytes from buf into file.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefWrite(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
								void *buf, unsigned int len);&lt;br /&gt;
	/* Moves the file pointer to a specified location.&lt;br /&gt;
	 * offset - Number of bytes from origin (int64)&lt;br /&gt;
	 * origin - 0 = from beginning, 1 = from current position, 2 = from end&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefSeek(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long offset, int origin, int unused);&lt;br /&gt;
&lt;br /&gt;
	/* Gets the current position of a file pointer into offset argument.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefTell(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long* offset);&lt;br /&gt;
&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefLock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefUnlock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefClose(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
&lt;br /&gt;
	/* Opens dictionary describing specified file or directory (iTunes below 8.2 allowed using AFCGetFileInfo&lt;br /&gt;
	   to get the same information)&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileInfoOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								afc_dictionary **info);&lt;br /&gt;
&lt;br /&gt;
	/* Reads next entry from dictionary. When last entry is read, function returns NULL in key argument&lt;br /&gt;
	   Possible keys:&lt;br /&gt;
	     &amp;quot;st_size&amp;quot;:     val - size in bytes&lt;br /&gt;
	     &amp;quot;st_blocks&amp;quot;:   val - size in blocks&lt;br /&gt;
	     &amp;quot;st_nlink&amp;quot;:    val - number of hardlinks&lt;br /&gt;
	     &amp;quot;st_ifmt&amp;quot;:     val - &amp;quot;S_IFDIR&amp;quot; for folders&lt;br /&gt;
	                        &amp;quot;S_IFLNK&amp;quot; for symlinks&lt;br /&gt;
	     &amp;quot;LinkTarget&amp;quot;:  val - path to symlink target&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueRead(struct afc_dictionary *dict, char **key, char **&lt;br /&gt;
								val);&lt;br /&gt;
	/* Closes dictionary&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueClose(struct afc_dictionary *dict);&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the context field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetContext(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the fs_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetFSBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the io_timeout field of the given AFC connection. In iTunes this is&lt;br /&gt;
	 * 0. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetIOTimeout(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the sock_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetSocketBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Closes the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionClose(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Registers for device notifications related to the restore process. unknown0&lt;br /&gt;
	 * is zero when iTunes calls this. In iTunes,&lt;br /&gt;
	 * the callbacks are located at:&lt;br /&gt;
	 *      1: $3ac68e-$3ac6b1, calls $3ac542(unknown1, arg, 0)&lt;br /&gt;
	 *      2: $3ac66a-$3ac68d, calls $3ac542(unknown1, 0, arg)&lt;br /&gt;
	 *      3: $3ac762-$3ac785, calls $3ac6b2(unknown1, arg, 0)&lt;br /&gt;
	 *      4: $3ac73e-$3ac761, calls $3ac6b2(unknown1, 0, arg)&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreRegisterForDeviceNotifications(&lt;br /&gt;
				am_restore_device_notification_callback dfu_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback dfu_disconnect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_disconnect_callback,&lt;br /&gt;
				unsigned int unknown0,&lt;br /&gt;
				void *user_info);&lt;br /&gt;
	&lt;br /&gt;
	/* Causes the restore functions to spit out (unhelpful) progress messages to&lt;br /&gt;
	 * the file specified by the given path. iTunes always calls this right before&lt;br /&gt;
	 * restoring with a path of&lt;br /&gt;
	 * &amp;quot;$HOME/Library/Logs/iPhone Updater Logs/iPhoneUpdater X.log&amp;quot;, where X is an&lt;br /&gt;
	 * unused number.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreEnableFileLogging(char *path);&lt;br /&gt;
	&lt;br /&gt;
	/* Initializes a new option dictionary to default values. Pass the constant&lt;br /&gt;
	 * kCFAllocatorDefault as the allocator. The option dictionary looks as&lt;br /&gt;
	 * follows:&lt;br /&gt;
	 * {&lt;br /&gt;
	 *      NORImageType =&amp;gt; 'production',&lt;br /&gt;
	 *      AutoBootDelay =&amp;gt; 0,&lt;br /&gt;
	 *      KernelCacheType =&amp;gt; 'Release',&lt;br /&gt;
	 *      UpdateBaseband =&amp;gt; true,&lt;br /&gt;
	 *      DFUFileType =&amp;gt; 'RELEASE',&lt;br /&gt;
	 *      SystemImageType =&amp;gt; 'User',&lt;br /&gt;
	 *      CreateFilesystemPartitions =&amp;gt; true,&lt;br /&gt;
	 *      FlashNOR =&amp;gt; true,&lt;br /&gt;
	 *      RestoreBootArgs =&amp;gt; 'rd=md0 nand-enable-reformat=1 -progress'&lt;br /&gt;
	 *      BootImageType =&amp;gt; 'User'&lt;br /&gt;
	 *  }&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      the option dictionary   if successful&lt;br /&gt;
	 *      NULL                    if out of memory&lt;br /&gt;
	 */ &lt;br /&gt;
	__DLLIMPORT CFMutableDictionaryRef AMRestoreCreateDefaultOptions(CFAllocatorRef allocator);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRecoveryModeRestore(struct am_recovery_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRestoreModeRestore(struct am_restore_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT struct am_restore_device *AMRestoreModeDeviceCreate(unsigned int unknown0,&lt;br /&gt;
				unsigned int connection_id, unsigned int unknown1);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreCreatePathsForBundle(CFStringRef restore_bundle_path,&lt;br /&gt;
				CFStringRef kernel_cache_type, CFStringRef boot_image_type, unsigned int&lt;br /&gt;
				unknown0, CFStringRef *firmware_dir_path, CFStringRef *&lt;br /&gt;
				kernelcache_restore_path, unsigned int unknown1, CFStringRef *&lt;br /&gt;
				ramdisk_path);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreModeDeviceReboot(struct am_restore_device *rdev);	// Added by JB 30.07.2008&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceEnterRecovery(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDisconnect(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* to use this, start the service &amp;quot;com.apple.mobile.notification_proxy&amp;quot;, handle will be the socket to use */&lt;br /&gt;
	typedef void (*NOTIFY_CALLBACK)(CFSTR notification, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDPostNotification(SOCKET socket, CFStringRef  notification, CFStringRef userinfo);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDObserveNotification(SOCKET socket, CFSTR notification);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDListenForNotifications(SOCKET socket, NOTIFY_CALLBACK cb, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDShutdownNotificationProxy(SOCKET socket);&lt;br /&gt;
	&lt;br /&gt;
	/*edits by geohot*/&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDeactivate(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceActivate(struct am_device *device, CFDictionaryRef dict);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceRemoveValue(struct am_device *device, unsigned int, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Pass in a usbmux_listener_1 structure and a usbmux_listener_2 structure&lt;br /&gt;
	 *  pointer, which will be filled with the resulting usbmux_listener_2.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if completed successfully&lt;br /&gt;
	 *      MDERR_USBMUX_ARG_NULL   if one of the arguments was NULL&lt;br /&gt;
	 *      MDERR_USBMUX_FAILED     if the listener was not created successfully&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerCreate(struct usbmux_listener_1 *esi_fp8, struct&lt;br /&gt;
										usbmux_listener_2 **eax_fp12);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerHandleData(void *);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Private routines - here be dragons&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/* AMRestorePerformRestoreModeRestore() calls this function with a dictionary&lt;br /&gt;
	 * in order to perform certain special restore operations&lt;br /&gt;
	 * (RESTORED_OPERATION_*). It is thought that this function might enable&lt;br /&gt;
	 * significant access to the phone. */&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef unsigned int (*t_performOperation)(struct am_restore_device *rdev,&lt;br /&gt;
	 CFDictionaryRef op) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_performOperation _performOperation = (t_performOperation)0x3c39fa4b;&lt;br /&gt;
	 */ &lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef int (*t_socketForPort)(struct am_restore_device *rdev, unsigned int port)&lt;br /&gt;
	 __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_socketForPort _socketForPort = (t_socketForPort)(void *)0x3c39f36c;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef void (*t_restored_send_message)(int port, CFDictionaryRef msg);&lt;br /&gt;
	 t_restored_send_message _restored_send_message = (t_restored_send_message)0x3c3a4e40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef CFDictionaryRef (*t_restored_receive_message)(int port);&lt;br /&gt;
	 t_restored_receive_message _restored_receive_message = (t_restored_receive_message)0x3c3a4d40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendControlPacket)(struct am_recovery_device *rdev, unsigned&lt;br /&gt;
	 int msg1, unsigned int msg2, unsigned int unknown0, unsigned int *unknown1,&lt;br /&gt;
	 unsigned char *unknown2) __attribute__ ((regparm(3)));&lt;br /&gt;
	 t_sendControlPacket _sendControlPacket = (t_sendControlPacket)0x3c3a3da3;;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendCommandToDevice)(struct am_recovery_device *rdev,&lt;br /&gt;
	 CFStringRef cmd) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_sendCommandToDevice _sendCommandToDevice = (t_sendCommandToDevice)0x3c3a3e3b;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceReadPipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int read_pipe, unsigned char *data, unsigned int *len);&lt;br /&gt;
	 t_AMRUSBInterfaceReadPipe _AMRUSBInterfaceReadPipe = (t_AMRUSBInterfaceReadPipe)0x3c3a27e8;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceWritePipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int write_pipe, void *data, unsigned int len);&lt;br /&gt;
	 t_AMRUSBInterfaceWritePipe _AMRUSBInterfaceWritePipe = (t_AMRUSBInterfaceWritePipe)0x3c3a27cb;&lt;br /&gt;
	 */&lt;br /&gt;
	&lt;br /&gt;
	int performOperation(am_restore_device *rdev, CFMutableDictionaryRef message);&lt;br /&gt;
	int socketForPort(am_restore_device *rdev, unsigned int portnum);&lt;br /&gt;
	int sendCommandToDevice(am_recovery_device *rdev, CFStringRef cfs, int block);&lt;br /&gt;
	int sendFileToDevice(am_recovery_device *rdev, CFStringRef filename); &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
}&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
/* -*- mode:c; indent-tabs-mode:nil; c-basic-offset:2; tab-width:2; */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===AFC Connection===&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
===Locking the Device for Sync===&lt;br /&gt;
When iTunes sends a new song to the device, the device shows a &amp;quot;Sync in progress&amp;quot; screen and when complete, the Music app on the device re-reads the iTunesDB file so it picks up the new song.&lt;br /&gt;
&lt;br /&gt;
To get this behaviour, first start the notification service:&lt;br /&gt;
&amp;lt;pre&amp;gt;SOCKET socket;&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we post a notificaton message to signal that we are going to start a sync:&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncWillStart&amp;quot;), NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we open the itunes lock file:&lt;br /&gt;
&amp;lt;pre&amp;gt;afc_file_ref lockref;&lt;br /&gt;
AFCFileRefOpen(conn, &amp;quot;/com.apple.itunes.lock_sync&amp;quot;, 2, &amp;amp;lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now post a notification to say we are going to lock this file, and try and lock it.&lt;br /&gt;
If the AFCFileRefLock call fails, pause and repeat.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncLockRequest&amp;quot;), NULL);&lt;br /&gt;
mach_error_t error = AFCFileRefLock(conn, lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the file is successfully locked, post another notification, and stop the notification service.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket,CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidStart&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the sync can proceed, so copy your files across and make the changes to the iTunesDB.&lt;br /&gt;
&lt;br /&gt;
To release the lock, start the notification system again, unlock and close the lock file, and send a sync finished notification message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;AFCFileRefUnlock(conn, lockref);&lt;br /&gt;
AFCFileRefClose(conn, lockref);&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&lt;br /&gt;
AMDPostNotification(socket, &amp;amp;CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidFinish&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To handle &amp;quot;Slide to Cancel&amp;quot; and terminate sync when user slides cancel switch, use AMDObserveNotification to subscribe notifications about “com.apple.itunes-client.syncCancelRequest”. Then start listening for notifications (AMDListenForNotifications) until you get “AMDNotificationFaceplant”.&lt;br /&gt;
When notification got, you should unlock and close lock file handle (don’t sure if you need to post “syncDidFinish” to proxy, seems it doesn’t matter) and terminate sync gracefully.&lt;br /&gt;
The same notification is also got when you unplug your device, so you should always be ready for errors.&lt;br /&gt;
&lt;br /&gt;
NOTE: You may find that starting the notification_proxy service once and once only at the start of your app and using the same socket in calls to AMDPostNotification works better. iTunes opens and closes the notification_proxy regularly, but it appears to be a bit flakey when you open/close it all the time.&lt;br /&gt;
&lt;br /&gt;
===Private Functions===&lt;br /&gt;
&lt;br /&gt;
====How to find address of privates functions in iTunesMobileDevice.dll or MobileDevice.framework====&lt;br /&gt;
&lt;br /&gt;
In order to obtain the address of a usable private function in MobileDevice, you will have to be able to understand x86-64 assembly to reverse engineer it. A private function will not have its name exported in the mach-o symbol table, so in a debugger, like GDB, it will show up as part of another function. However, you will know that it is a separate function as a new stack frame is set up.&lt;br /&gt;
&lt;br /&gt;
====Private Function Address List====&lt;br /&gt;
&lt;br /&gt;
=====OSX.6 - iTunes 9.0.2(25)=====&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendCommandToiBoot(struct am_recovery_device *rdev, CFStringRef command, int u);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 868(0x364) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym(). &lt;br /&gt;
Address: 0x1000245ea&lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
1. rdev - the device you wish to send the command to.&lt;br /&gt;
2. a CFStringRef of the command to send.&lt;br /&gt;
3. an integer, whose use is currently unknown, but should be set to 0 to work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendFileToiDevice(struct am_recovery_device *rdev, CFStringRef filename);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 1168(0x490) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym().&lt;br /&gt;
Address: 0x100024969&lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
1. rdev - the device you wish to send the file to.&lt;br /&gt;
2. a CFStringRef of the path to the file to send.&lt;br /&gt;
&lt;br /&gt;
===Libraries Implementations===&lt;br /&gt;
&lt;br /&gt;
* [http://gojohnnyboi.com/source/afcinstall.cpp afcinstall (command line, os x file install via afc)]&lt;br /&gt;
* [http://code.google.com/p/iphuc/ iPhuc (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/iphucwin32/ iPhuc Win32 (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/manzana/ manzana (.Net Library)]&lt;br /&gt;
* [http://code.google.com/p/independence/source/browse/trunk/libPhoneInteraction/ libPhoneInteraction (C Library)]&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5680</id>
		<title>MobileDevice Library</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5680"/>
		<updated>2009-11-21T21:24:59Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MobileDevice Library is used by [[iTunes]] to transfer data between iPhone and computer over the USB connection.&lt;br /&gt;
&lt;br /&gt;
===PC Windows : iTunesMobileDevice.dll===&lt;br /&gt;
&lt;br /&gt;
* Location : Location is stored in '''iTunesMobileDeviceDLL''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Mobile Device Support\Shared''' key. Usually - C:\Program Files\Common Files\Apple\Mobile Device Support\bin\iTunesMobileDevice.dll.&lt;br /&gt;
&lt;br /&gt;
* Supporting CoreFoundation.dll (used for CFStringRef, CFPropertyListRef management) is located in the same dir (when using iTunes prior 9.0). &lt;br /&gt;
&lt;br /&gt;
* For iTunes 9.0 location of CoreFoundation.dll is stored in '''InstallDir''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Application Support''' key, usually C:\Program Files\Common Files\Apple\Apple Application Support\. CoreFoundation.dll from Mobile Device Support\bin should not be used.&lt;br /&gt;
&lt;br /&gt;
===Mac OSX : MobileDevice.framework===&lt;br /&gt;
&lt;br /&gt;
* Location : /System/Library/PrivateFrameworks/MobileDevice.framework&lt;br /&gt;
* Export command : &amp;quot;nm /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===MobileDevice Header (mobiledevice.h)===&lt;br /&gt;
&lt;br /&gt;
Reverse engineered C header for MobileDevice Library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* ----------------------------------------------------------------------------&lt;br /&gt;
 *   MobileDevice.h - interface to MobileDevice.framework &lt;br /&gt;
 * ------------------------------------------------------------------------- */&lt;br /&gt;
#pragma once&lt;br /&gt;
&lt;br /&gt;
#ifndef MOBILEDEVICE_H&lt;br /&gt;
#define MOBILEDEVICE_H&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
extern &amp;quot;C&amp;quot; {&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
#ifndef __GCC__&lt;br /&gt;
#pragma pack&lt;br /&gt;
#define __PACK&lt;br /&gt;
#else&lt;br /&gt;
#define __PACK __attribute__((__packed__))&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#if defined(WIN32)&lt;br /&gt;
#define __DLLIMPORT [DllImport(&amp;quot;iTunesMobileDevice.dll&amp;quot;)]&lt;br /&gt;
	using namespace System::Runtime::InteropServices;&lt;br /&gt;
#include &amp;lt;CoreFoundation.h&amp;gt;&lt;br /&gt;
	typedef unsigned int mach_error_t;&lt;br /&gt;
#elif defined(__APPLE__)&lt;br /&gt;
#define __DLLIMPORT&lt;br /&gt;
#include &amp;lt;CoreFoundation/CoreFoundation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;mach/error.h&amp;gt;&lt;br /&gt;
#endif	&lt;br /&gt;
	&lt;br /&gt;
	/* Error codes */&lt;br /&gt;
#define MDERR_APPLE_MOBILE  (err_system(0x3a))&lt;br /&gt;
#define MDERR_IPHONE        (err_sub(0))&lt;br /&gt;
	&lt;br /&gt;
	/* Apple Mobile (AM*) errors */&lt;br /&gt;
#define MDERR_OK                ERR_SUCCESS&lt;br /&gt;
#define MDERR_SYSCALL           (ERR_MOBILE_DEVICE | 0x01)&lt;br /&gt;
#define MDERR_OUT_OF_MEMORY     (ERR_MOBILE_DEVICE | 0x03)&lt;br /&gt;
#define MDERR_QUERY_FAILED      (ERR_MOBILE_DEVICE | 0x04) &lt;br /&gt;
#define MDERR_INVALID_ARGUMENT  (ERR_MOBILE_DEVICE | 0x0b)&lt;br /&gt;
#define MDERR_DICT_NOT_LOADED   (ERR_MOBILE_DEVICE | 0x25)&lt;br /&gt;
	&lt;br /&gt;
	/* Apple File Connection (AFC*) errors */&lt;br /&gt;
#define MDERR_AFC_OUT_OF_MEMORY 0x03&lt;br /&gt;
	&lt;br /&gt;
	/* USBMux errors */&lt;br /&gt;
#define MDERR_USBMUX_ARG_NULL   0x16&lt;br /&gt;
#define MDERR_USBMUX_FAILED     0xffffffff&lt;br /&gt;
	&lt;br /&gt;
	/* Messages passed to device notification callbacks: passed as part of&lt;br /&gt;
	 * am_device_notification_callback_info. */&lt;br /&gt;
#define ADNCI_MSG_CONNECTED     1&lt;br /&gt;
#define ADNCI_MSG_DISCONNECTED  2&lt;br /&gt;
#define ADNCI_MSG_UNSUBSCRIBED  3&lt;br /&gt;
	&lt;br /&gt;
#define AMD_IPHONE_PRODUCT_ID   0x1290&lt;br /&gt;
	//#define AMD_IPHONE_SERIAL       &amp;quot;&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
	/* Services, found in /System/Library/Lockdown/Services.plist */&lt;br /&gt;
#define AMSVC_AFC                   CFSTR(&amp;quot;com.apple.afc&amp;quot;)&lt;br /&gt;
#define AMSVC_BACKUP                CFSTR(&amp;quot;com.apple.mobilebackup&amp;quot;)&lt;br /&gt;
#define AMSVC_CRASH_REPORT_COPY     CFSTR(&amp;quot;com.apple.crashreportcopy&amp;quot;)&lt;br /&gt;
#define AMSVC_DEBUG_IMAGE_MOUNT     CFSTR(&amp;quot;com.apple.mobile.debug_image_mount&amp;quot;)&lt;br /&gt;
#define AMSVC_NOTIFICATION_PROXY    CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;)&lt;br /&gt;
#define AMSVC_PURPLE_TEST           CFSTR(&amp;quot;com.apple.purpletestr&amp;quot;)&lt;br /&gt;
#define AMSVC_SOFTWARE_UPDATE       CFSTR(&amp;quot;com.apple.mobile.software_update&amp;quot;)&lt;br /&gt;
#define AMSVC_SYNC                  CFSTR(&amp;quot;com.apple.mobilesync&amp;quot;)&lt;br /&gt;
#define AMSVC_SCREENSHOT            CFSTR(&amp;quot;com.apple.screenshotr&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSLOG_RELAY          CFSTR(&amp;quot;com.apple.syslog_relay&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSTEM_PROFILER       CFSTR(&amp;quot;com.apple.mobile.system_profiler&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned int afc_error_t;&lt;br /&gt;
	typedef unsigned int usbmux_error_t;&lt;br /&gt;
	&lt;br /&gt;
	struct am_recovery_device;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification_callback_info {&lt;br /&gt;
		struct am_device *dev;  /* 0    device */ &lt;br /&gt;
		unsigned int msg;       /* 4    one of ADNCI_MSG_* */&lt;br /&gt;
                struct am_device_notification* subscription; &lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
	&lt;br /&gt;
	/* This is a CoreFoundation object of class AMRecoveryModeDevice. */&lt;br /&gt;
	struct am_recovery_device {&lt;br /&gt;
		unsigned char unknown0[8];                          /* 0 */&lt;br /&gt;
		am_restore_device_notification_callback callback;   /* 8 */&lt;br /&gt;
		void *user_info;                                    /* 12 */&lt;br /&gt;
		unsigned char unknown1[12];                         /* 16 */&lt;br /&gt;
		unsigned int readwrite_pipe;                        /* 28 */&lt;br /&gt;
		unsigned char read_pipe;                            /* 32 */&lt;br /&gt;
		unsigned char write_ctrl_pipe;                      /* 33 */&lt;br /&gt;
		unsigned char read_unknown_pipe;                    /* 34 */&lt;br /&gt;
		unsigned char write_file_pipe;                      /* 35 */&lt;br /&gt;
		unsigned char write_input_pipe;                     /* 36 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* A CoreFoundation object of class AMRestoreModeDevice. */&lt;br /&gt;
	struct am_restore_device {&lt;br /&gt;
		unsigned char unknown[32];&lt;br /&gt;
		int port;&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device notification callback function. */&lt;br /&gt;
	typedef void(*am_device_notification_callback)(struct am_device_notification_callback_info *, int cookie);&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the _AMDDeviceAttached function.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void *amd_device_attached_callback;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
&lt;br /&gt;
	/* Structure that contains internal data used by AMDevice... functions. Never try &lt;br /&gt;
         * to access its members directly! Use AMDeviceCopyDeviceIdentifier, &lt;br /&gt;
         * AMDeviceGetConnectionID, AMDeviceRetain, AMDeviceRelease instead. */&lt;br /&gt;
	struct am_device {&lt;br /&gt;
		unsigned char unknown0[16]; /* 0 - zero */&lt;br /&gt;
		unsigned int device_id;     /* 16 */&lt;br /&gt;
		unsigned int product_id;    /* 20 - set to AMD_IPHONE_PRODUCT_ID */&lt;br /&gt;
		char *serial;               /* 24 - set to UDID, Unique Device Identifier */&lt;br /&gt;
		unsigned int unknown1;      /* 28 */&lt;br /&gt;
		unsigned int unknown2;      /* 32 - reference counter, increased by AMDeviceRetain, decreased by AMDeviceRelease*/&lt;br /&gt;
		unsigned int lockdown_conn; /* 36 */&lt;br /&gt;
		unsigned char unknown3[8];  /* 40 */&lt;br /&gt;
#if (__ITUNES_VER &amp;gt; 740)&lt;br /&gt;
		unsigned int unknown4;      /* 48 - used to store CriticalSection Handle*/&lt;br /&gt;
#endif&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
		unsigned char unknown5[24];  /* 52 */&lt;br /&gt;
#endif&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification {&lt;br /&gt;
		unsigned int unknown0;                      /* 0 */&lt;br /&gt;
		unsigned int unknown1;                      /* 4 */&lt;br /&gt;
		unsigned int unknown2;                      /* 8 */&lt;br /&gt;
		am_device_notification_callback callback;   /* 12 */ &lt;br /&gt;
		unsigned int cookie;                      /* 16 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct afc_connection {&lt;br /&gt;
		unsigned int handle;            /* 0 */&lt;br /&gt;
		unsigned int unknown0;          /* 4 */&lt;br /&gt;
		unsigned char unknown1;         /* 8 */&lt;br /&gt;
		unsigned char padding[3];       /* 9 */&lt;br /&gt;
		unsigned int unknown2;          /* 12 */&lt;br /&gt;
		unsigned int unknown3;          /* 16 */&lt;br /&gt;
		unsigned int unknown4;          /* 20 */&lt;br /&gt;
		unsigned int fs_block_size;     /* 24 */&lt;br /&gt;
		unsigned int sock_block_size;   /* 28: always 0x3c */&lt;br /&gt;
		unsigned int io_timeout;        /* 32: from AFCConnectionOpen, usu. 0 */&lt;br /&gt;
		void *afc_lock;                 /* 36 */&lt;br /&gt;
		unsigned int context;           /* 40 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
	struct afc_device_info {&lt;br /&gt;
		unsigned char unknown[12];  /* 0 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_directory {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_dictionary {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned long long afc_file_ref;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_1 {                  /* offset   value in iTunes */&lt;br /&gt;
		unsigned int unknown0;                  /* 0        1 */&lt;br /&gt;
		unsigned char *unknown1;                /* 4        ptr, maybe device? */&lt;br /&gt;
		amd_device_attached_callback callback;  /* 8        _AMDDeviceAttached */&lt;br /&gt;
		unsigned int unknown3;                  /* 12 */&lt;br /&gt;
		unsigned int unknown4;                  /* 16 */&lt;br /&gt;
		unsigned int unknown5;                  /* 20 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_2 {&lt;br /&gt;
		unsigned char unknown0[4144];&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_bootloader_control_packet {&lt;br /&gt;
		unsigned char opcode;       /* 0 */&lt;br /&gt;
		unsigned char length;       /* 1 */&lt;br /&gt;
		unsigned char magic[2];     /* 2: 0x34, 0x12 */&lt;br /&gt;
		unsigned char payload[0];   /* 4 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Registers a notification with the current run loop. The callback gets&lt;br /&gt;
	 *  copied into the notification struct, as well as being registered with the&lt;br /&gt;
	 *  current run loop. Cookie gets copied into cookie in the same.&lt;br /&gt;
	 *  (Cookie is a user info parameter that gets passed as an arg to&lt;br /&gt;
	 *  the callback) unused0 and unused1 are both 0 when iTunes calls this.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Never try to acces directly or copy contents of dev and subscription fields &lt;br /&gt;
	 *  in am_device_notification_callback_info. Treat them as abstract handles. &lt;br /&gt;
	 *  When done with connection use AMDeviceRelease to free resources allocated for am_device.&lt;br /&gt;
	 *  &lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK            if successful&lt;br /&gt;
	 *      MDERR_SYSCALL       if CFRunLoopAddSource() failed&lt;br /&gt;
	 *      MDERR_OUT_OF_MEMORY if we ran out of memory&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationSubscribe(am_device_notification_callback callback, &lt;br /&gt;
								unsigned int unused0, unsigned int unused1, &lt;br /&gt;
								unsigned int cookie, &lt;br /&gt;
								struct am_device_notification **subscription);&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
        /* Unregisters notifications. Buggy (iTunes 8.2): if you subscribe, unsubscribe and subscribe again, arriving &lt;br /&gt;
           notifications will contain cookie and subscription from 1st call to subscribe, not the 2nd one. iTunes &lt;br /&gt;
           calls this function only once on exit.&lt;br /&gt;
        */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationUnsubscribe(am_device_notification* subscription);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns device_id field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMDeviceGetConnectionID(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns serial field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyDeviceIdentifier(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Connects to the iPhone. Pass in the am_device structure that the&lt;br /&gt;
	 *  notification callback will give to you.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successfully connected&lt;br /&gt;
	 *      MDERR_SYSCALL           if setsockopt() failed&lt;br /&gt;
	 *      MDERR_QUERY_FAILED      if the daemon query failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if USBMuxConnectByPort returned 0xffffffff&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceConnect(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Calls PairingRecordPath() on the given device, than tests whether the path&lt;br /&gt;
	 *  which that function returns exists. During the initial connect, the path&lt;br /&gt;
	 *  returned by that function is '/', and so this returns 1.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      0   if the path did not exist&lt;br /&gt;
	 *      1   if it did&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceIsPaired(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDevicePair(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  iTunes calls this function immediately after testing whether the device is&lt;br /&gt;
	 *  paired. It creates a pairing file and establishes a Lockdown connection.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the supplied device is null&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceValidatePairing(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Creates a Lockdown session and adjusts the device structure appropriately&lt;br /&gt;
	 *  to indicate that the session has been started. iTunes calls this function&lt;br /&gt;
	 *  after validating pairing.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartSession(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* Reads various device settings. One of domain or cfstring arguments should be NULL.&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for cfstring:&lt;br /&gt;
	 * ActivationState&lt;br /&gt;
	 * ActivationStateAcknowledged&lt;br /&gt;
	 * BasebandBootloaderVersion&lt;br /&gt;
	 * BasebandVersion&lt;br /&gt;
	 * BluetoothAddress&lt;br /&gt;
	 * BuildVersion&lt;br /&gt;
	 * DeviceCertificate&lt;br /&gt;
	 * DeviceClass&lt;br /&gt;
	 * DeviceName&lt;br /&gt;
	 * DevicePublicKey&lt;br /&gt;
	 * FirmwareVersion&lt;br /&gt;
	 * HostAttached&lt;br /&gt;
	 * IntegratedCircuitCardIdentity&lt;br /&gt;
	 * InternationalMobileEquipmentIdentity&lt;br /&gt;
	 * InternationalMobileSubscriberIdentity&lt;br /&gt;
	 * ModelNumber&lt;br /&gt;
	 * PhoneNumber&lt;br /&gt;
	 * ProductType&lt;br /&gt;
	 * ProductVersion&lt;br /&gt;
	 * ProtocolVersion&lt;br /&gt;
	 * RegionInfo&lt;br /&gt;
	 * SBLockdownEverRegisteredKey&lt;br /&gt;
	 * SIMStatus&lt;br /&gt;
	 * SerialNumber&lt;br /&gt;
	 * SomebodySetTimeZone&lt;br /&gt;
	 * TimeIntervalSince1970&lt;br /&gt;
	 * TimeZone&lt;br /&gt;
	 * TimeZoneOffsetFromUTC&lt;br /&gt;
	 * TrustedHostAttached&lt;br /&gt;
	 * UniqueDeviceID&lt;br /&gt;
	 * Uses24HourClock&lt;br /&gt;
	 * WiFiAddress&lt;br /&gt;
	 * iTunesHasConnected&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for domain:&lt;br /&gt;
         * com.apple.mobile.battery&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyValue(struct am_device *device, CFStringRef domain, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* Starts a service and returns a socket file descriptor that can be used in order to further&lt;br /&gt;
	 * access the service. You should stop the session and disconnect before using&lt;br /&gt;
	 * the service. iTunes calls this function after starting a session. It starts &lt;br /&gt;
	 * the service and the SSL connection. service_name should be one of the AMSVC_*&lt;br /&gt;
	 * constants.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_SYSCALL           if the setsockopt() call failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartService(struct am_device *device, CFStringRef &lt;br /&gt;
									  service_name, int *socket_fd);&lt;br /&gt;
	&lt;br /&gt;
	/* Stops a session. You should do this before accessing services.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStopSession(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/* Decrements reference counter and, if nothing left, releases resources hold &lt;br /&gt;
	 * by connection, invalidates  pointer to device&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRelease(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Increments reference counter&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRetain(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Opens an Apple File Connection. You must start the appropriate service&lt;br /&gt;
	 * first with AMDeviceStartService(). In iTunes, io_timeout is 0.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_AFC_OUT_OF_MEMORY if malloc() failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionOpen(int socket_fd, unsigned int io_timeout,&lt;br /&gt;
								  struct afc_connection **conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Pass in a pointer to an afc_dictionary structure. It will be filled. You can&lt;br /&gt;
	 * iterate it using AFCKeyValueRead. When done use AFCKeyValueClose. Possible keys:&lt;br /&gt;
	 * FSFreeBytes - free bytes on system device for afc2, user device for afc&lt;br /&gt;
	 * FSBlockSize - filesystem block size&lt;br /&gt;
	 * FSTotalBytes - size of device&lt;br /&gt;
	 * Model - iPhone1,1 etc.&lt;br /&gt;
&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDeviceInfoOpen(struct afc_connection *conn, struct&lt;br /&gt;
								  afc_dictionary **info);&lt;br /&gt;
	&lt;br /&gt;
	/* Turns debug mode on if the environment variable AFCDEBUG is set to a numeric&lt;br /&gt;
	 * value, or if the file '/AFCDEBUG' is present and contains a value. */&lt;br /&gt;
#if defined(__APPLE__)&lt;br /&gt;
	void AFCPlatformInit();&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
	/* Opens a directory on the iPhone. Pass in a pointer in dir to be filled in.&lt;br /&gt;
	 * Note that this normally only accesses the iTunes sandbox/partition as the&lt;br /&gt;
	 * root, which is /var/root/Media. Pathnames are specified with '/' delimiters&lt;br /&gt;
	 * as in Unix style. Use UTF-8 to specify non-ASCII symbols in path.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								 afc_directory **dir);&lt;br /&gt;
	&lt;br /&gt;
	/* Acquires the next entry in a directory previously opened with&lt;br /&gt;
	 * AFCDirectoryOpen(). When dirent is filled with a NULL value, then the end&lt;br /&gt;
	 * of the directory has been reached. '.' and '..' will be returned as the&lt;br /&gt;
	 * first two entries in each directory except the root; you may want to skip&lt;br /&gt;
	 * over them.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful, even if no entries remain&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryRead(struct afc_connection *conn, struct afc_directory *dir,&lt;br /&gt;
								 char **dirent);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryClose(afc_connection *conn, struct afc_directory *dir);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryCreate(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRemovePath(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRenamePath(afc_connection *conn, char *oldpath, char *newpath);&lt;br /&gt;
&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
	/* Creates symbolic or hard link&lt;br /&gt;
         * linktype - int64: 1 means hard link, 2 - soft (symbolic) link&lt;br /&gt;
         * target - absolute or relative path to link target&lt;br /&gt;
         * linkname - absolute path where to create new link&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCLinkPath(struct afc_connection *conn, long long int linktype, const char *target, &lt;br /&gt;
								                              const char *linkname);&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
	/* Opens file for reading or writing without locking it in any way. afc_file_ref should not be shared between threads - &lt;br /&gt;
         * opening file in one thread and closing it in another will lead to possible crash.&lt;br /&gt;
	 * path - UTF-8 encoded absolute path to file&lt;br /&gt;
	 * mode 2 = read, mode 3 = write; unknown = 0 &lt;br /&gt;
	 * ref - receives file handle&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefOpen(struct afc_connection *conn, char *path, unsigned&lt;br /&gt;
							   long long int mode, afc_file_ref *ref);&lt;br /&gt;
	/* Reads specified amount (len) of bytes from file into buf. Puts actual count of read bytes into len on return&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefRead(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   void *buf, unsigned int *len);&lt;br /&gt;
	/* Writes specified amount (len) of bytes from buf into file.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefWrite(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
								void *buf, unsigned int len);&lt;br /&gt;
	/* Moves the file pointer to a specified location.&lt;br /&gt;
	 * offset - Number of bytes from origin (int64)&lt;br /&gt;
	 * origin - 0 = from beginning, 1 = from current position, 2 = from end&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefSeek(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long offset, int origin, int unused);&lt;br /&gt;
&lt;br /&gt;
	/* Gets the current position of a file pointer into offset argument.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefTell(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long* offset);&lt;br /&gt;
&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefLock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefUnlock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefClose(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
&lt;br /&gt;
	/* Opens dictionary describing specified file or directory (iTunes below 8.2 allowed using AFCGetFileInfo&lt;br /&gt;
	   to get the same information)&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileInfoOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								afc_dictionary **info);&lt;br /&gt;
&lt;br /&gt;
	/* Reads next entry from dictionary. When last entry is read, function returns NULL in key argument&lt;br /&gt;
	   Possible keys:&lt;br /&gt;
	     &amp;quot;st_size&amp;quot;:     val - size in bytes&lt;br /&gt;
	     &amp;quot;st_blocks&amp;quot;:   val - size in blocks&lt;br /&gt;
	     &amp;quot;st_nlink&amp;quot;:    val - number of hardlinks&lt;br /&gt;
	     &amp;quot;st_ifmt&amp;quot;:     val - &amp;quot;S_IFDIR&amp;quot; for folders&lt;br /&gt;
	                        &amp;quot;S_IFLNK&amp;quot; for symlinks&lt;br /&gt;
	     &amp;quot;LinkTarget&amp;quot;:  val - path to symlink target&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueRead(struct afc_dictionary *dict, char **key, char **&lt;br /&gt;
								val);&lt;br /&gt;
	/* Closes dictionary&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueClose(struct afc_dictionary *dict);&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the context field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetContext(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the fs_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetFSBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the io_timeout field of the given AFC connection. In iTunes this is&lt;br /&gt;
	 * 0. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetIOTimeout(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the sock_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetSocketBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Closes the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionClose(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Registers for device notifications related to the restore process. unknown0&lt;br /&gt;
	 * is zero when iTunes calls this. In iTunes,&lt;br /&gt;
	 * the callbacks are located at:&lt;br /&gt;
	 *      1: $3ac68e-$3ac6b1, calls $3ac542(unknown1, arg, 0)&lt;br /&gt;
	 *      2: $3ac66a-$3ac68d, calls $3ac542(unknown1, 0, arg)&lt;br /&gt;
	 *      3: $3ac762-$3ac785, calls $3ac6b2(unknown1, arg, 0)&lt;br /&gt;
	 *      4: $3ac73e-$3ac761, calls $3ac6b2(unknown1, 0, arg)&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreRegisterForDeviceNotifications(&lt;br /&gt;
				am_restore_device_notification_callback dfu_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback dfu_disconnect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_disconnect_callback,&lt;br /&gt;
				unsigned int unknown0,&lt;br /&gt;
				void *user_info);&lt;br /&gt;
	&lt;br /&gt;
	/* Causes the restore functions to spit out (unhelpful) progress messages to&lt;br /&gt;
	 * the file specified by the given path. iTunes always calls this right before&lt;br /&gt;
	 * restoring with a path of&lt;br /&gt;
	 * &amp;quot;$HOME/Library/Logs/iPhone Updater Logs/iPhoneUpdater X.log&amp;quot;, where X is an&lt;br /&gt;
	 * unused number.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreEnableFileLogging(char *path);&lt;br /&gt;
	&lt;br /&gt;
	/* Initializes a new option dictionary to default values. Pass the constant&lt;br /&gt;
	 * kCFAllocatorDefault as the allocator. The option dictionary looks as&lt;br /&gt;
	 * follows:&lt;br /&gt;
	 * {&lt;br /&gt;
	 *      NORImageType =&amp;gt; 'production',&lt;br /&gt;
	 *      AutoBootDelay =&amp;gt; 0,&lt;br /&gt;
	 *      KernelCacheType =&amp;gt; 'Release',&lt;br /&gt;
	 *      UpdateBaseband =&amp;gt; true,&lt;br /&gt;
	 *      DFUFileType =&amp;gt; 'RELEASE',&lt;br /&gt;
	 *      SystemImageType =&amp;gt; 'User',&lt;br /&gt;
	 *      CreateFilesystemPartitions =&amp;gt; true,&lt;br /&gt;
	 *      FlashNOR =&amp;gt; true,&lt;br /&gt;
	 *      RestoreBootArgs =&amp;gt; 'rd=md0 nand-enable-reformat=1 -progress'&lt;br /&gt;
	 *      BootImageType =&amp;gt; 'User'&lt;br /&gt;
	 *  }&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      the option dictionary   if successful&lt;br /&gt;
	 *      NULL                    if out of memory&lt;br /&gt;
	 */ &lt;br /&gt;
	__DLLIMPORT CFMutableDictionaryRef AMRestoreCreateDefaultOptions(CFAllocatorRef allocator);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRecoveryModeRestore(struct am_recovery_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRestoreModeRestore(struct am_restore_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT struct am_restore_device *AMRestoreModeDeviceCreate(unsigned int unknown0,&lt;br /&gt;
				unsigned int connection_id, unsigned int unknown1);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreCreatePathsForBundle(CFStringRef restore_bundle_path,&lt;br /&gt;
				CFStringRef kernel_cache_type, CFStringRef boot_image_type, unsigned int&lt;br /&gt;
				unknown0, CFStringRef *firmware_dir_path, CFStringRef *&lt;br /&gt;
				kernelcache_restore_path, unsigned int unknown1, CFStringRef *&lt;br /&gt;
				ramdisk_path);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreModeDeviceReboot(struct am_restore_device *rdev);	// Added by JB 30.07.2008&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceEnterRecovery(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDisconnect(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* to use this, start the service &amp;quot;com.apple.mobile.notification_proxy&amp;quot;, handle will be the socket to use */&lt;br /&gt;
	typedef void (*NOTIFY_CALLBACK)(CFSTR notification, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDPostNotification(SOCKET socket, CFStringRef  notification, CFStringRef userinfo);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDObserveNotification(SOCKET socket, CFSTR notification);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDListenForNotifications(SOCKET socket, NOTIFY_CALLBACK cb, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDShutdownNotificationProxy(SOCKET socket);&lt;br /&gt;
	&lt;br /&gt;
	/*edits by geohot*/&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDeactivate(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceActivate(struct am_device *device, CFDictionaryRef dict);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceRemoveValue(struct am_device *device, unsigned int, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Pass in a usbmux_listener_1 structure and a usbmux_listener_2 structure&lt;br /&gt;
	 *  pointer, which will be filled with the resulting usbmux_listener_2.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if completed successfully&lt;br /&gt;
	 *      MDERR_USBMUX_ARG_NULL   if one of the arguments was NULL&lt;br /&gt;
	 *      MDERR_USBMUX_FAILED     if the listener was not created successfully&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerCreate(struct usbmux_listener_1 *esi_fp8, struct&lt;br /&gt;
										usbmux_listener_2 **eax_fp12);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerHandleData(void *);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Private routines - here be dragons&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/* AMRestorePerformRestoreModeRestore() calls this function with a dictionary&lt;br /&gt;
	 * in order to perform certain special restore operations&lt;br /&gt;
	 * (RESTORED_OPERATION_*). It is thought that this function might enable&lt;br /&gt;
	 * significant access to the phone. */&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef unsigned int (*t_performOperation)(struct am_restore_device *rdev,&lt;br /&gt;
	 CFDictionaryRef op) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_performOperation _performOperation = (t_performOperation)0x3c39fa4b;&lt;br /&gt;
	 */ &lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef int (*t_socketForPort)(struct am_restore_device *rdev, unsigned int port)&lt;br /&gt;
	 __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_socketForPort _socketForPort = (t_socketForPort)(void *)0x3c39f36c;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef void (*t_restored_send_message)(int port, CFDictionaryRef msg);&lt;br /&gt;
	 t_restored_send_message _restored_send_message = (t_restored_send_message)0x3c3a4e40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef CFDictionaryRef (*t_restored_receive_message)(int port);&lt;br /&gt;
	 t_restored_receive_message _restored_receive_message = (t_restored_receive_message)0x3c3a4d40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendControlPacket)(struct am_recovery_device *rdev, unsigned&lt;br /&gt;
	 int msg1, unsigned int msg2, unsigned int unknown0, unsigned int *unknown1,&lt;br /&gt;
	 unsigned char *unknown2) __attribute__ ((regparm(3)));&lt;br /&gt;
	 t_sendControlPacket _sendControlPacket = (t_sendControlPacket)0x3c3a3da3;;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendCommandToDevice)(struct am_recovery_device *rdev,&lt;br /&gt;
	 CFStringRef cmd) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_sendCommandToDevice _sendCommandToDevice = (t_sendCommandToDevice)0x3c3a3e3b;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceReadPipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int read_pipe, unsigned char *data, unsigned int *len);&lt;br /&gt;
	 t_AMRUSBInterfaceReadPipe _AMRUSBInterfaceReadPipe = (t_AMRUSBInterfaceReadPipe)0x3c3a27e8;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceWritePipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int write_pipe, void *data, unsigned int len);&lt;br /&gt;
	 t_AMRUSBInterfaceWritePipe _AMRUSBInterfaceWritePipe = (t_AMRUSBInterfaceWritePipe)0x3c3a27cb;&lt;br /&gt;
	 */&lt;br /&gt;
	&lt;br /&gt;
	int performOperation(am_restore_device *rdev, CFMutableDictionaryRef message);&lt;br /&gt;
	int socketForPort(am_restore_device *rdev, unsigned int portnum);&lt;br /&gt;
	int sendCommandToDevice(am_recovery_device *rdev, CFStringRef cfs, int block);&lt;br /&gt;
	int sendFileToDevice(am_recovery_device *rdev, CFStringRef filename); &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
}&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
/* -*- mode:c; indent-tabs-mode:nil; c-basic-offset:2; tab-width:2; */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===AFC Connection===&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
===Locking the Device for Sync===&lt;br /&gt;
When iTunes sends a new song to the device, the device shows a &amp;quot;Sync in progress&amp;quot; screen and when complete, the Music app on the device re-reads the iTunesDB file so it picks up the new song.&lt;br /&gt;
&lt;br /&gt;
To get this behaviour, first start the notification service:&lt;br /&gt;
&amp;lt;pre&amp;gt;SOCKET socket;&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we post a notificaton message to signal that we are going to start a sync:&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncWillStart&amp;quot;), NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we open the itunes lock file:&lt;br /&gt;
&amp;lt;pre&amp;gt;afc_file_ref lockref;&lt;br /&gt;
AFCFileRefOpen(conn, &amp;quot;/com.apple.itunes.lock_sync&amp;quot;, 2, &amp;amp;lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now post a notification to say we are going to lock this file, and try and lock it.&lt;br /&gt;
If the AFCFileRefLock call fails, pause and repeat.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncLockRequest&amp;quot;), NULL);&lt;br /&gt;
mach_error_t error = AFCFileRefLock(conn, lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the file is successfully locked, post another notification, and stop the notification service.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket,CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidStart&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the sync can proceed, so copy your files across and make the changes to the iTunesDB.&lt;br /&gt;
&lt;br /&gt;
To release the lock, start the notification system again, unlock and close the lock file, and send a sync finished notification message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;AFCFileRefUnlock(conn, lockref);&lt;br /&gt;
AFCFileRefClose(conn, lockref);&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&lt;br /&gt;
AMDPostNotification(socket, &amp;amp;CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidFinish&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To handle &amp;quot;Slide to Cancel&amp;quot; and terminate sync when user slides cancel switch, use AMDObserveNotification to subscribe notifications about “com.apple.itunes-client.syncCancelRequest”. Then start listening for notifications (AMDListenForNotifications) until you get “AMDNotificationFaceplant”.&lt;br /&gt;
When notification got, you should unlock and close lock file handle (don’t sure if you need to post “syncDidFinish” to proxy, seems it doesn’t matter) and terminate sync gracefully.&lt;br /&gt;
The same notification is also got when you unplug your device, so you should always be ready for errors.&lt;br /&gt;
&lt;br /&gt;
NOTE: You may find that starting the notification_proxy service once and once only at the start of your app and using the same socket in calls to AMDPostNotification works better. iTunes opens and closes the notification_proxy regularly, but it appears to be a bit flakey when you open/close it all the time.&lt;br /&gt;
&lt;br /&gt;
===Private Functions===&lt;br /&gt;
&lt;br /&gt;
====How to find address of privates functions in iTunesMobileDevice.dll or MobileDevice.framework====&lt;br /&gt;
&lt;br /&gt;
In order to obtain the address of a usable private function in MobileDevice, you will have to be able to understand x86-64 assembly to reverse engineer it. A private function will not have its name exported in the mach-o symbol table, so in a debugger, like GDB, it will show up as part of another function. However, you will know that it is a separate function as a new stack frame is set up.&lt;br /&gt;
&lt;br /&gt;
====Private Function Address List====&lt;br /&gt;
&lt;br /&gt;
=====OSX.6 - iTunes 9.0.2(25)=====&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendCommandToiBoot(struct am_recovery_device *rdev, CFStringRef command, int u);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 868(0x364) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym(). &lt;br /&gt;
Address: 0x245ea&lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
1. rdev - the device you wish to send the command to.&lt;br /&gt;
2. a CFStringRef of the command to send.&lt;br /&gt;
3. an integer, whose use is currently unknown, but should be set to 0 to work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendFileToiDevice(struct am_recovery_device *rdev, CFStringRef filename);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 1168(0x490) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym().&lt;br /&gt;
Address: 0x24716&lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
1. rdev - the device you wish to send the file to.&lt;br /&gt;
2. a CFStringRef of the path to the file to send.&lt;br /&gt;
&lt;br /&gt;
===Libraries Implementations===&lt;br /&gt;
&lt;br /&gt;
* [http://gojohnnyboi.com/source/afcinstall.cpp afcinstall (command line, os x file install via afc)]&lt;br /&gt;
* [http://code.google.com/p/iphuc/ iPhuc (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/iphucwin32/ iPhuc Win32 (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/manzana/ manzana (.Net Library)]&lt;br /&gt;
* [http://code.google.com/p/independence/source/browse/trunk/libPhoneInteraction/ libPhoneInteraction (C Library)]&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5679</id>
		<title>MobileDevice Library</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5679"/>
		<updated>2009-11-21T21:23:28Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MobileDevice Library is used by [[iTunes]] to transfer data between iPhone and computer over the USB connection.&lt;br /&gt;
&lt;br /&gt;
===PC Windows : iTunesMobileDevice.dll===&lt;br /&gt;
&lt;br /&gt;
* Location : Location is stored in '''iTunesMobileDeviceDLL''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Mobile Device Support\Shared''' key. Usually - C:\Program Files\Common Files\Apple\Mobile Device Support\bin\iTunesMobileDevice.dll.&lt;br /&gt;
&lt;br /&gt;
* Supporting CoreFoundation.dll (used for CFStringRef, CFPropertyListRef management) is located in the same dir (when using iTunes prior 9.0). &lt;br /&gt;
&lt;br /&gt;
* For iTunes 9.0 location of CoreFoundation.dll is stored in '''InstallDir''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Application Support''' key, usually C:\Program Files\Common Files\Apple\Apple Application Support\. CoreFoundation.dll from Mobile Device Support\bin should not be used.&lt;br /&gt;
&lt;br /&gt;
===Mac OSX : MobileDevice.framework===&lt;br /&gt;
&lt;br /&gt;
* Location : /System/Library/PrivateFrameworks/MobileDevice.framework&lt;br /&gt;
* Export command : &amp;quot;nm /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===MobileDevice Header (mobiledevice.h)===&lt;br /&gt;
&lt;br /&gt;
Reverse engineered C header for MobileDevice Library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* ----------------------------------------------------------------------------&lt;br /&gt;
 *   MobileDevice.h - interface to MobileDevice.framework &lt;br /&gt;
 * ------------------------------------------------------------------------- */&lt;br /&gt;
#pragma once&lt;br /&gt;
&lt;br /&gt;
#ifndef MOBILEDEVICE_H&lt;br /&gt;
#define MOBILEDEVICE_H&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
extern &amp;quot;C&amp;quot; {&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
#ifndef __GCC__&lt;br /&gt;
#pragma pack&lt;br /&gt;
#define __PACK&lt;br /&gt;
#else&lt;br /&gt;
#define __PACK __attribute__((__packed__))&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#if defined(WIN32)&lt;br /&gt;
#define __DLLIMPORT [DllImport(&amp;quot;iTunesMobileDevice.dll&amp;quot;)]&lt;br /&gt;
	using namespace System::Runtime::InteropServices;&lt;br /&gt;
#include &amp;lt;CoreFoundation.h&amp;gt;&lt;br /&gt;
	typedef unsigned int mach_error_t;&lt;br /&gt;
#elif defined(__APPLE__)&lt;br /&gt;
#define __DLLIMPORT&lt;br /&gt;
#include &amp;lt;CoreFoundation/CoreFoundation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;mach/error.h&amp;gt;&lt;br /&gt;
#endif	&lt;br /&gt;
	&lt;br /&gt;
	/* Error codes */&lt;br /&gt;
#define MDERR_APPLE_MOBILE  (err_system(0x3a))&lt;br /&gt;
#define MDERR_IPHONE        (err_sub(0))&lt;br /&gt;
	&lt;br /&gt;
	/* Apple Mobile (AM*) errors */&lt;br /&gt;
#define MDERR_OK                ERR_SUCCESS&lt;br /&gt;
#define MDERR_SYSCALL           (ERR_MOBILE_DEVICE | 0x01)&lt;br /&gt;
#define MDERR_OUT_OF_MEMORY     (ERR_MOBILE_DEVICE | 0x03)&lt;br /&gt;
#define MDERR_QUERY_FAILED      (ERR_MOBILE_DEVICE | 0x04) &lt;br /&gt;
#define MDERR_INVALID_ARGUMENT  (ERR_MOBILE_DEVICE | 0x0b)&lt;br /&gt;
#define MDERR_DICT_NOT_LOADED   (ERR_MOBILE_DEVICE | 0x25)&lt;br /&gt;
	&lt;br /&gt;
	/* Apple File Connection (AFC*) errors */&lt;br /&gt;
#define MDERR_AFC_OUT_OF_MEMORY 0x03&lt;br /&gt;
	&lt;br /&gt;
	/* USBMux errors */&lt;br /&gt;
#define MDERR_USBMUX_ARG_NULL   0x16&lt;br /&gt;
#define MDERR_USBMUX_FAILED     0xffffffff&lt;br /&gt;
	&lt;br /&gt;
	/* Messages passed to device notification callbacks: passed as part of&lt;br /&gt;
	 * am_device_notification_callback_info. */&lt;br /&gt;
#define ADNCI_MSG_CONNECTED     1&lt;br /&gt;
#define ADNCI_MSG_DISCONNECTED  2&lt;br /&gt;
#define ADNCI_MSG_UNSUBSCRIBED  3&lt;br /&gt;
	&lt;br /&gt;
#define AMD_IPHONE_PRODUCT_ID   0x1290&lt;br /&gt;
	//#define AMD_IPHONE_SERIAL       &amp;quot;&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
	/* Services, found in /System/Library/Lockdown/Services.plist */&lt;br /&gt;
#define AMSVC_AFC                   CFSTR(&amp;quot;com.apple.afc&amp;quot;)&lt;br /&gt;
#define AMSVC_BACKUP                CFSTR(&amp;quot;com.apple.mobilebackup&amp;quot;)&lt;br /&gt;
#define AMSVC_CRASH_REPORT_COPY     CFSTR(&amp;quot;com.apple.crashreportcopy&amp;quot;)&lt;br /&gt;
#define AMSVC_DEBUG_IMAGE_MOUNT     CFSTR(&amp;quot;com.apple.mobile.debug_image_mount&amp;quot;)&lt;br /&gt;
#define AMSVC_NOTIFICATION_PROXY    CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;)&lt;br /&gt;
#define AMSVC_PURPLE_TEST           CFSTR(&amp;quot;com.apple.purpletestr&amp;quot;)&lt;br /&gt;
#define AMSVC_SOFTWARE_UPDATE       CFSTR(&amp;quot;com.apple.mobile.software_update&amp;quot;)&lt;br /&gt;
#define AMSVC_SYNC                  CFSTR(&amp;quot;com.apple.mobilesync&amp;quot;)&lt;br /&gt;
#define AMSVC_SCREENSHOT            CFSTR(&amp;quot;com.apple.screenshotr&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSLOG_RELAY          CFSTR(&amp;quot;com.apple.syslog_relay&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSTEM_PROFILER       CFSTR(&amp;quot;com.apple.mobile.system_profiler&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned int afc_error_t;&lt;br /&gt;
	typedef unsigned int usbmux_error_t;&lt;br /&gt;
	&lt;br /&gt;
	struct am_recovery_device;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification_callback_info {&lt;br /&gt;
		struct am_device *dev;  /* 0    device */ &lt;br /&gt;
		unsigned int msg;       /* 4    one of ADNCI_MSG_* */&lt;br /&gt;
                struct am_device_notification* subscription; &lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
	&lt;br /&gt;
	/* This is a CoreFoundation object of class AMRecoveryModeDevice. */&lt;br /&gt;
	struct am_recovery_device {&lt;br /&gt;
		unsigned char unknown0[8];                          /* 0 */&lt;br /&gt;
		am_restore_device_notification_callback callback;   /* 8 */&lt;br /&gt;
		void *user_info;                                    /* 12 */&lt;br /&gt;
		unsigned char unknown1[12];                         /* 16 */&lt;br /&gt;
		unsigned int readwrite_pipe;                        /* 28 */&lt;br /&gt;
		unsigned char read_pipe;                            /* 32 */&lt;br /&gt;
		unsigned char write_ctrl_pipe;                      /* 33 */&lt;br /&gt;
		unsigned char read_unknown_pipe;                    /* 34 */&lt;br /&gt;
		unsigned char write_file_pipe;                      /* 35 */&lt;br /&gt;
		unsigned char write_input_pipe;                     /* 36 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* A CoreFoundation object of class AMRestoreModeDevice. */&lt;br /&gt;
	struct am_restore_device {&lt;br /&gt;
		unsigned char unknown[32];&lt;br /&gt;
		int port;&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device notification callback function. */&lt;br /&gt;
	typedef void(*am_device_notification_callback)(struct am_device_notification_callback_info *, int cookie);&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the _AMDDeviceAttached function.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void *amd_device_attached_callback;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
&lt;br /&gt;
	/* Structure that contains internal data used by AMDevice... functions. Never try &lt;br /&gt;
         * to access its members directly! Use AMDeviceCopyDeviceIdentifier, &lt;br /&gt;
         * AMDeviceGetConnectionID, AMDeviceRetain, AMDeviceRelease instead. */&lt;br /&gt;
	struct am_device {&lt;br /&gt;
		unsigned char unknown0[16]; /* 0 - zero */&lt;br /&gt;
		unsigned int device_id;     /* 16 */&lt;br /&gt;
		unsigned int product_id;    /* 20 - set to AMD_IPHONE_PRODUCT_ID */&lt;br /&gt;
		char *serial;               /* 24 - set to UDID, Unique Device Identifier */&lt;br /&gt;
		unsigned int unknown1;      /* 28 */&lt;br /&gt;
		unsigned int unknown2;      /* 32 - reference counter, increased by AMDeviceRetain, decreased by AMDeviceRelease*/&lt;br /&gt;
		unsigned int lockdown_conn; /* 36 */&lt;br /&gt;
		unsigned char unknown3[8];  /* 40 */&lt;br /&gt;
#if (__ITUNES_VER &amp;gt; 740)&lt;br /&gt;
		unsigned int unknown4;      /* 48 - used to store CriticalSection Handle*/&lt;br /&gt;
#endif&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
		unsigned char unknown5[24];  /* 52 */&lt;br /&gt;
#endif&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification {&lt;br /&gt;
		unsigned int unknown0;                      /* 0 */&lt;br /&gt;
		unsigned int unknown1;                      /* 4 */&lt;br /&gt;
		unsigned int unknown2;                      /* 8 */&lt;br /&gt;
		am_device_notification_callback callback;   /* 12 */ &lt;br /&gt;
		unsigned int cookie;                      /* 16 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct afc_connection {&lt;br /&gt;
		unsigned int handle;            /* 0 */&lt;br /&gt;
		unsigned int unknown0;          /* 4 */&lt;br /&gt;
		unsigned char unknown1;         /* 8 */&lt;br /&gt;
		unsigned char padding[3];       /* 9 */&lt;br /&gt;
		unsigned int unknown2;          /* 12 */&lt;br /&gt;
		unsigned int unknown3;          /* 16 */&lt;br /&gt;
		unsigned int unknown4;          /* 20 */&lt;br /&gt;
		unsigned int fs_block_size;     /* 24 */&lt;br /&gt;
		unsigned int sock_block_size;   /* 28: always 0x3c */&lt;br /&gt;
		unsigned int io_timeout;        /* 32: from AFCConnectionOpen, usu. 0 */&lt;br /&gt;
		void *afc_lock;                 /* 36 */&lt;br /&gt;
		unsigned int context;           /* 40 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
	struct afc_device_info {&lt;br /&gt;
		unsigned char unknown[12];  /* 0 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_directory {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_dictionary {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned long long afc_file_ref;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_1 {                  /* offset   value in iTunes */&lt;br /&gt;
		unsigned int unknown0;                  /* 0        1 */&lt;br /&gt;
		unsigned char *unknown1;                /* 4        ptr, maybe device? */&lt;br /&gt;
		amd_device_attached_callback callback;  /* 8        _AMDDeviceAttached */&lt;br /&gt;
		unsigned int unknown3;                  /* 12 */&lt;br /&gt;
		unsigned int unknown4;                  /* 16 */&lt;br /&gt;
		unsigned int unknown5;                  /* 20 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_2 {&lt;br /&gt;
		unsigned char unknown0[4144];&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_bootloader_control_packet {&lt;br /&gt;
		unsigned char opcode;       /* 0 */&lt;br /&gt;
		unsigned char length;       /* 1 */&lt;br /&gt;
		unsigned char magic[2];     /* 2: 0x34, 0x12 */&lt;br /&gt;
		unsigned char payload[0];   /* 4 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Registers a notification with the current run loop. The callback gets&lt;br /&gt;
	 *  copied into the notification struct, as well as being registered with the&lt;br /&gt;
	 *  current run loop. Cookie gets copied into cookie in the same.&lt;br /&gt;
	 *  (Cookie is a user info parameter that gets passed as an arg to&lt;br /&gt;
	 *  the callback) unused0 and unused1 are both 0 when iTunes calls this.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Never try to acces directly or copy contents of dev and subscription fields &lt;br /&gt;
	 *  in am_device_notification_callback_info. Treat them as abstract handles. &lt;br /&gt;
	 *  When done with connection use AMDeviceRelease to free resources allocated for am_device.&lt;br /&gt;
	 *  &lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK            if successful&lt;br /&gt;
	 *      MDERR_SYSCALL       if CFRunLoopAddSource() failed&lt;br /&gt;
	 *      MDERR_OUT_OF_MEMORY if we ran out of memory&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationSubscribe(am_device_notification_callback callback, &lt;br /&gt;
								unsigned int unused0, unsigned int unused1, &lt;br /&gt;
								unsigned int cookie, &lt;br /&gt;
								struct am_device_notification **subscription);&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
        /* Unregisters notifications. Buggy (iTunes 8.2): if you subscribe, unsubscribe and subscribe again, arriving &lt;br /&gt;
           notifications will contain cookie and subscription from 1st call to subscribe, not the 2nd one. iTunes &lt;br /&gt;
           calls this function only once on exit.&lt;br /&gt;
        */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationUnsubscribe(am_device_notification* subscription);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns device_id field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMDeviceGetConnectionID(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns serial field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyDeviceIdentifier(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Connects to the iPhone. Pass in the am_device structure that the&lt;br /&gt;
	 *  notification callback will give to you.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successfully connected&lt;br /&gt;
	 *      MDERR_SYSCALL           if setsockopt() failed&lt;br /&gt;
	 *      MDERR_QUERY_FAILED      if the daemon query failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if USBMuxConnectByPort returned 0xffffffff&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceConnect(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Calls PairingRecordPath() on the given device, than tests whether the path&lt;br /&gt;
	 *  which that function returns exists. During the initial connect, the path&lt;br /&gt;
	 *  returned by that function is '/', and so this returns 1.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      0   if the path did not exist&lt;br /&gt;
	 *      1   if it did&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceIsPaired(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDevicePair(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  iTunes calls this function immediately after testing whether the device is&lt;br /&gt;
	 *  paired. It creates a pairing file and establishes a Lockdown connection.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the supplied device is null&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceValidatePairing(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Creates a Lockdown session and adjusts the device structure appropriately&lt;br /&gt;
	 *  to indicate that the session has been started. iTunes calls this function&lt;br /&gt;
	 *  after validating pairing.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartSession(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* Reads various device settings. One of domain or cfstring arguments should be NULL.&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for cfstring:&lt;br /&gt;
	 * ActivationState&lt;br /&gt;
	 * ActivationStateAcknowledged&lt;br /&gt;
	 * BasebandBootloaderVersion&lt;br /&gt;
	 * BasebandVersion&lt;br /&gt;
	 * BluetoothAddress&lt;br /&gt;
	 * BuildVersion&lt;br /&gt;
	 * DeviceCertificate&lt;br /&gt;
	 * DeviceClass&lt;br /&gt;
	 * DeviceName&lt;br /&gt;
	 * DevicePublicKey&lt;br /&gt;
	 * FirmwareVersion&lt;br /&gt;
	 * HostAttached&lt;br /&gt;
	 * IntegratedCircuitCardIdentity&lt;br /&gt;
	 * InternationalMobileEquipmentIdentity&lt;br /&gt;
	 * InternationalMobileSubscriberIdentity&lt;br /&gt;
	 * ModelNumber&lt;br /&gt;
	 * PhoneNumber&lt;br /&gt;
	 * ProductType&lt;br /&gt;
	 * ProductVersion&lt;br /&gt;
	 * ProtocolVersion&lt;br /&gt;
	 * RegionInfo&lt;br /&gt;
	 * SBLockdownEverRegisteredKey&lt;br /&gt;
	 * SIMStatus&lt;br /&gt;
	 * SerialNumber&lt;br /&gt;
	 * SomebodySetTimeZone&lt;br /&gt;
	 * TimeIntervalSince1970&lt;br /&gt;
	 * TimeZone&lt;br /&gt;
	 * TimeZoneOffsetFromUTC&lt;br /&gt;
	 * TrustedHostAttached&lt;br /&gt;
	 * UniqueDeviceID&lt;br /&gt;
	 * Uses24HourClock&lt;br /&gt;
	 * WiFiAddress&lt;br /&gt;
	 * iTunesHasConnected&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for domain:&lt;br /&gt;
         * com.apple.mobile.battery&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyValue(struct am_device *device, CFStringRef domain, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* Starts a service and returns a socket file descriptor that can be used in order to further&lt;br /&gt;
	 * access the service. You should stop the session and disconnect before using&lt;br /&gt;
	 * the service. iTunes calls this function after starting a session. It starts &lt;br /&gt;
	 * the service and the SSL connection. service_name should be one of the AMSVC_*&lt;br /&gt;
	 * constants.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_SYSCALL           if the setsockopt() call failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartService(struct am_device *device, CFStringRef &lt;br /&gt;
									  service_name, int *socket_fd);&lt;br /&gt;
	&lt;br /&gt;
	/* Stops a session. You should do this before accessing services.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStopSession(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/* Decrements reference counter and, if nothing left, releases resources hold &lt;br /&gt;
	 * by connection, invalidates  pointer to device&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRelease(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Increments reference counter&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRetain(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Opens an Apple File Connection. You must start the appropriate service&lt;br /&gt;
	 * first with AMDeviceStartService(). In iTunes, io_timeout is 0.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_AFC_OUT_OF_MEMORY if malloc() failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionOpen(int socket_fd, unsigned int io_timeout,&lt;br /&gt;
								  struct afc_connection **conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Pass in a pointer to an afc_dictionary structure. It will be filled. You can&lt;br /&gt;
	 * iterate it using AFCKeyValueRead. When done use AFCKeyValueClose. Possible keys:&lt;br /&gt;
	 * FSFreeBytes - free bytes on system device for afc2, user device for afc&lt;br /&gt;
	 * FSBlockSize - filesystem block size&lt;br /&gt;
	 * FSTotalBytes - size of device&lt;br /&gt;
	 * Model - iPhone1,1 etc.&lt;br /&gt;
&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDeviceInfoOpen(struct afc_connection *conn, struct&lt;br /&gt;
								  afc_dictionary **info);&lt;br /&gt;
	&lt;br /&gt;
	/* Turns debug mode on if the environment variable AFCDEBUG is set to a numeric&lt;br /&gt;
	 * value, or if the file '/AFCDEBUG' is present and contains a value. */&lt;br /&gt;
#if defined(__APPLE__)&lt;br /&gt;
	void AFCPlatformInit();&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
	/* Opens a directory on the iPhone. Pass in a pointer in dir to be filled in.&lt;br /&gt;
	 * Note that this normally only accesses the iTunes sandbox/partition as the&lt;br /&gt;
	 * root, which is /var/root/Media. Pathnames are specified with '/' delimiters&lt;br /&gt;
	 * as in Unix style. Use UTF-8 to specify non-ASCII symbols in path.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								 afc_directory **dir);&lt;br /&gt;
	&lt;br /&gt;
	/* Acquires the next entry in a directory previously opened with&lt;br /&gt;
	 * AFCDirectoryOpen(). When dirent is filled with a NULL value, then the end&lt;br /&gt;
	 * of the directory has been reached. '.' and '..' will be returned as the&lt;br /&gt;
	 * first two entries in each directory except the root; you may want to skip&lt;br /&gt;
	 * over them.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful, even if no entries remain&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryRead(struct afc_connection *conn, struct afc_directory *dir,&lt;br /&gt;
								 char **dirent);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryClose(afc_connection *conn, struct afc_directory *dir);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryCreate(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRemovePath(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRenamePath(afc_connection *conn, char *oldpath, char *newpath);&lt;br /&gt;
&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
	/* Creates symbolic or hard link&lt;br /&gt;
         * linktype - int64: 1 means hard link, 2 - soft (symbolic) link&lt;br /&gt;
         * target - absolute or relative path to link target&lt;br /&gt;
         * linkname - absolute path where to create new link&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCLinkPath(struct afc_connection *conn, long long int linktype, const char *target, &lt;br /&gt;
								                              const char *linkname);&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
	/* Opens file for reading or writing without locking it in any way. afc_file_ref should not be shared between threads - &lt;br /&gt;
         * opening file in one thread and closing it in another will lead to possible crash.&lt;br /&gt;
	 * path - UTF-8 encoded absolute path to file&lt;br /&gt;
	 * mode 2 = read, mode 3 = write; unknown = 0 &lt;br /&gt;
	 * ref - receives file handle&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefOpen(struct afc_connection *conn, char *path, unsigned&lt;br /&gt;
							   long long int mode, afc_file_ref *ref);&lt;br /&gt;
	/* Reads specified amount (len) of bytes from file into buf. Puts actual count of read bytes into len on return&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefRead(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   void *buf, unsigned int *len);&lt;br /&gt;
	/* Writes specified amount (len) of bytes from buf into file.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefWrite(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
								void *buf, unsigned int len);&lt;br /&gt;
	/* Moves the file pointer to a specified location.&lt;br /&gt;
	 * offset - Number of bytes from origin (int64)&lt;br /&gt;
	 * origin - 0 = from beginning, 1 = from current position, 2 = from end&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefSeek(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long offset, int origin, int unused);&lt;br /&gt;
&lt;br /&gt;
	/* Gets the current position of a file pointer into offset argument.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefTell(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long* offset);&lt;br /&gt;
&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefLock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefUnlock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefClose(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
&lt;br /&gt;
	/* Opens dictionary describing specified file or directory (iTunes below 8.2 allowed using AFCGetFileInfo&lt;br /&gt;
	   to get the same information)&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileInfoOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								afc_dictionary **info);&lt;br /&gt;
&lt;br /&gt;
	/* Reads next entry from dictionary. When last entry is read, function returns NULL in key argument&lt;br /&gt;
	   Possible keys:&lt;br /&gt;
	     &amp;quot;st_size&amp;quot;:     val - size in bytes&lt;br /&gt;
	     &amp;quot;st_blocks&amp;quot;:   val - size in blocks&lt;br /&gt;
	     &amp;quot;st_nlink&amp;quot;:    val - number of hardlinks&lt;br /&gt;
	     &amp;quot;st_ifmt&amp;quot;:     val - &amp;quot;S_IFDIR&amp;quot; for folders&lt;br /&gt;
	                        &amp;quot;S_IFLNK&amp;quot; for symlinks&lt;br /&gt;
	     &amp;quot;LinkTarget&amp;quot;:  val - path to symlink target&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueRead(struct afc_dictionary *dict, char **key, char **&lt;br /&gt;
								val);&lt;br /&gt;
	/* Closes dictionary&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueClose(struct afc_dictionary *dict);&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the context field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetContext(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the fs_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetFSBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the io_timeout field of the given AFC connection. In iTunes this is&lt;br /&gt;
	 * 0. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetIOTimeout(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the sock_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetSocketBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Closes the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionClose(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Registers for device notifications related to the restore process. unknown0&lt;br /&gt;
	 * is zero when iTunes calls this. In iTunes,&lt;br /&gt;
	 * the callbacks are located at:&lt;br /&gt;
	 *      1: $3ac68e-$3ac6b1, calls $3ac542(unknown1, arg, 0)&lt;br /&gt;
	 *      2: $3ac66a-$3ac68d, calls $3ac542(unknown1, 0, arg)&lt;br /&gt;
	 *      3: $3ac762-$3ac785, calls $3ac6b2(unknown1, arg, 0)&lt;br /&gt;
	 *      4: $3ac73e-$3ac761, calls $3ac6b2(unknown1, 0, arg)&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreRegisterForDeviceNotifications(&lt;br /&gt;
				am_restore_device_notification_callback dfu_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback dfu_disconnect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_disconnect_callback,&lt;br /&gt;
				unsigned int unknown0,&lt;br /&gt;
				void *user_info);&lt;br /&gt;
	&lt;br /&gt;
	/* Causes the restore functions to spit out (unhelpful) progress messages to&lt;br /&gt;
	 * the file specified by the given path. iTunes always calls this right before&lt;br /&gt;
	 * restoring with a path of&lt;br /&gt;
	 * &amp;quot;$HOME/Library/Logs/iPhone Updater Logs/iPhoneUpdater X.log&amp;quot;, where X is an&lt;br /&gt;
	 * unused number.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreEnableFileLogging(char *path);&lt;br /&gt;
	&lt;br /&gt;
	/* Initializes a new option dictionary to default values. Pass the constant&lt;br /&gt;
	 * kCFAllocatorDefault as the allocator. The option dictionary looks as&lt;br /&gt;
	 * follows:&lt;br /&gt;
	 * {&lt;br /&gt;
	 *      NORImageType =&amp;gt; 'production',&lt;br /&gt;
	 *      AutoBootDelay =&amp;gt; 0,&lt;br /&gt;
	 *      KernelCacheType =&amp;gt; 'Release',&lt;br /&gt;
	 *      UpdateBaseband =&amp;gt; true,&lt;br /&gt;
	 *      DFUFileType =&amp;gt; 'RELEASE',&lt;br /&gt;
	 *      SystemImageType =&amp;gt; 'User',&lt;br /&gt;
	 *      CreateFilesystemPartitions =&amp;gt; true,&lt;br /&gt;
	 *      FlashNOR =&amp;gt; true,&lt;br /&gt;
	 *      RestoreBootArgs =&amp;gt; 'rd=md0 nand-enable-reformat=1 -progress'&lt;br /&gt;
	 *      BootImageType =&amp;gt; 'User'&lt;br /&gt;
	 *  }&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      the option dictionary   if successful&lt;br /&gt;
	 *      NULL                    if out of memory&lt;br /&gt;
	 */ &lt;br /&gt;
	__DLLIMPORT CFMutableDictionaryRef AMRestoreCreateDefaultOptions(CFAllocatorRef allocator);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRecoveryModeRestore(struct am_recovery_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRestoreModeRestore(struct am_restore_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT struct am_restore_device *AMRestoreModeDeviceCreate(unsigned int unknown0,&lt;br /&gt;
				unsigned int connection_id, unsigned int unknown1);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreCreatePathsForBundle(CFStringRef restore_bundle_path,&lt;br /&gt;
				CFStringRef kernel_cache_type, CFStringRef boot_image_type, unsigned int&lt;br /&gt;
				unknown0, CFStringRef *firmware_dir_path, CFStringRef *&lt;br /&gt;
				kernelcache_restore_path, unsigned int unknown1, CFStringRef *&lt;br /&gt;
				ramdisk_path);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreModeDeviceReboot(struct am_restore_device *rdev);	// Added by JB 30.07.2008&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceEnterRecovery(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDisconnect(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* to use this, start the service &amp;quot;com.apple.mobile.notification_proxy&amp;quot;, handle will be the socket to use */&lt;br /&gt;
	typedef void (*NOTIFY_CALLBACK)(CFSTR notification, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDPostNotification(SOCKET socket, CFStringRef  notification, CFStringRef userinfo);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDObserveNotification(SOCKET socket, CFSTR notification);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDListenForNotifications(SOCKET socket, NOTIFY_CALLBACK cb, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDShutdownNotificationProxy(SOCKET socket);&lt;br /&gt;
	&lt;br /&gt;
	/*edits by geohot*/&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDeactivate(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceActivate(struct am_device *device, CFDictionaryRef dict);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceRemoveValue(struct am_device *device, unsigned int, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Pass in a usbmux_listener_1 structure and a usbmux_listener_2 structure&lt;br /&gt;
	 *  pointer, which will be filled with the resulting usbmux_listener_2.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if completed successfully&lt;br /&gt;
	 *      MDERR_USBMUX_ARG_NULL   if one of the arguments was NULL&lt;br /&gt;
	 *      MDERR_USBMUX_FAILED     if the listener was not created successfully&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerCreate(struct usbmux_listener_1 *esi_fp8, struct&lt;br /&gt;
										usbmux_listener_2 **eax_fp12);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerHandleData(void *);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Private routines - here be dragons&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/* AMRestorePerformRestoreModeRestore() calls this function with a dictionary&lt;br /&gt;
	 * in order to perform certain special restore operations&lt;br /&gt;
	 * (RESTORED_OPERATION_*). It is thought that this function might enable&lt;br /&gt;
	 * significant access to the phone. */&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef unsigned int (*t_performOperation)(struct am_restore_device *rdev,&lt;br /&gt;
	 CFDictionaryRef op) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_performOperation _performOperation = (t_performOperation)0x3c39fa4b;&lt;br /&gt;
	 */ &lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef int (*t_socketForPort)(struct am_restore_device *rdev, unsigned int port)&lt;br /&gt;
	 __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_socketForPort _socketForPort = (t_socketForPort)(void *)0x3c39f36c;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef void (*t_restored_send_message)(int port, CFDictionaryRef msg);&lt;br /&gt;
	 t_restored_send_message _restored_send_message = (t_restored_send_message)0x3c3a4e40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef CFDictionaryRef (*t_restored_receive_message)(int port);&lt;br /&gt;
	 t_restored_receive_message _restored_receive_message = (t_restored_receive_message)0x3c3a4d40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendControlPacket)(struct am_recovery_device *rdev, unsigned&lt;br /&gt;
	 int msg1, unsigned int msg2, unsigned int unknown0, unsigned int *unknown1,&lt;br /&gt;
	 unsigned char *unknown2) __attribute__ ((regparm(3)));&lt;br /&gt;
	 t_sendControlPacket _sendControlPacket = (t_sendControlPacket)0x3c3a3da3;;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendCommandToDevice)(struct am_recovery_device *rdev,&lt;br /&gt;
	 CFStringRef cmd) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_sendCommandToDevice _sendCommandToDevice = (t_sendCommandToDevice)0x3c3a3e3b;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceReadPipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int read_pipe, unsigned char *data, unsigned int *len);&lt;br /&gt;
	 t_AMRUSBInterfaceReadPipe _AMRUSBInterfaceReadPipe = (t_AMRUSBInterfaceReadPipe)0x3c3a27e8;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceWritePipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int write_pipe, void *data, unsigned int len);&lt;br /&gt;
	 t_AMRUSBInterfaceWritePipe _AMRUSBInterfaceWritePipe = (t_AMRUSBInterfaceWritePipe)0x3c3a27cb;&lt;br /&gt;
	 */&lt;br /&gt;
	&lt;br /&gt;
	int performOperation(am_restore_device *rdev, CFMutableDictionaryRef message);&lt;br /&gt;
	int socketForPort(am_restore_device *rdev, unsigned int portnum);&lt;br /&gt;
	int sendCommandToDevice(am_recovery_device *rdev, CFStringRef cfs, int block);&lt;br /&gt;
	int sendFileToDevice(am_recovery_device *rdev, CFStringRef filename); &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
}&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
/* -*- mode:c; indent-tabs-mode:nil; c-basic-offset:2; tab-width:2; */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===AFC Connection===&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
===Locking the Device for Sync===&lt;br /&gt;
When iTunes sends a new song to the device, the device shows a &amp;quot;Sync in progress&amp;quot; screen and when complete, the Music app on the device re-reads the iTunesDB file so it picks up the new song.&lt;br /&gt;
&lt;br /&gt;
To get this behaviour, first start the notification service:&lt;br /&gt;
&amp;lt;pre&amp;gt;SOCKET socket;&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we post a notificaton message to signal that we are going to start a sync:&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncWillStart&amp;quot;), NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we open the itunes lock file:&lt;br /&gt;
&amp;lt;pre&amp;gt;afc_file_ref lockref;&lt;br /&gt;
AFCFileRefOpen(conn, &amp;quot;/com.apple.itunes.lock_sync&amp;quot;, 2, &amp;amp;lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now post a notification to say we are going to lock this file, and try and lock it.&lt;br /&gt;
If the AFCFileRefLock call fails, pause and repeat.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncLockRequest&amp;quot;), NULL);&lt;br /&gt;
mach_error_t error = AFCFileRefLock(conn, lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the file is successfully locked, post another notification, and stop the notification service.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket,CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidStart&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the sync can proceed, so copy your files across and make the changes to the iTunesDB.&lt;br /&gt;
&lt;br /&gt;
To release the lock, start the notification system again, unlock and close the lock file, and send a sync finished notification message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;AFCFileRefUnlock(conn, lockref);&lt;br /&gt;
AFCFileRefClose(conn, lockref);&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&lt;br /&gt;
AMDPostNotification(socket, &amp;amp;CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidFinish&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To handle &amp;quot;Slide to Cancel&amp;quot; and terminate sync when user slides cancel switch, use AMDObserveNotification to subscribe notifications about “com.apple.itunes-client.syncCancelRequest”. Then start listening for notifications (AMDListenForNotifications) until you get “AMDNotificationFaceplant”.&lt;br /&gt;
When notification got, you should unlock and close lock file handle (don’t sure if you need to post “syncDidFinish” to proxy, seems it doesn’t matter) and terminate sync gracefully.&lt;br /&gt;
The same notification is also got when you unplug your device, so you should always be ready for errors.&lt;br /&gt;
&lt;br /&gt;
NOTE: You may find that starting the notification_proxy service once and once only at the start of your app and using the same socket in calls to AMDPostNotification works better. iTunes opens and closes the notification_proxy regularly, but it appears to be a bit flakey when you open/close it all the time.&lt;br /&gt;
&lt;br /&gt;
===Private Functions===&lt;br /&gt;
&lt;br /&gt;
====How to find address of privates functions in iTunesMobileDevice.dll or MobileDevice.framework====&lt;br /&gt;
&lt;br /&gt;
In order to obtain the address of a usable private function in MobileDevice, you will have to be able to understand x86-64 assembly to reverse engineer it. A private function will not have its name exported in the mach-o symbol table, so in a debugger, like GDB, it will show up as part of another function. However, you will know that it is a separate function as a new stack frame is set up.&lt;br /&gt;
&lt;br /&gt;
====Private Function Address List====&lt;br /&gt;
&lt;br /&gt;
=====OSX.6 - iTunes 9.0.2(25)=====&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendCommandToiBoot(struct am_recovery_device *rdev, CFStringRef command, int u);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 868(0x364) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym(). &lt;br /&gt;
Address: 0x245ea&lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
1. rdev - the device you wish to send the command to&lt;br /&gt;
2. a CFStringRef of the command to send&lt;br /&gt;
3. an integer, whose use is currently unknown, but should be set to 0 to work.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendFileToiDevice(struct am_recovery_device *rdev, CFStringRef filename);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 1168(0x490) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym().&lt;br /&gt;
Address: 0x24716&lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
1. rdev - the device you wish to send the file to&lt;br /&gt;
2. a CFStringRef of the path to the file to send&lt;br /&gt;
&lt;br /&gt;
===Libraries Implementations===&lt;br /&gt;
&lt;br /&gt;
* [http://gojohnnyboi.com/source/afcinstall.cpp afcinstall (command line, os x file install via afc)]&lt;br /&gt;
* [http://code.google.com/p/iphuc/ iPhuc (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/iphucwin32/ iPhuc Win32 (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/manzana/ manzana (.Net Library)]&lt;br /&gt;
* [http://code.google.com/p/independence/source/browse/trunk/libPhoneInteraction/ libPhoneInteraction (C Library)]&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5678</id>
		<title>MobileDevice Library</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5678"/>
		<updated>2009-11-21T21:22:38Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: /* OSX.6 - iTunes 9.0.2(25) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MobileDevice Library is used by [[iTunes]] to transfer data between iPhone and computer over the USB connection.&lt;br /&gt;
&lt;br /&gt;
===PC Windows : iTunesMobileDevice.dll===&lt;br /&gt;
&lt;br /&gt;
* Location : Location is stored in '''iTunesMobileDeviceDLL''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Mobile Device Support\Shared''' key. Usually - C:\Program Files\Common Files\Apple\Mobile Device Support\bin\iTunesMobileDevice.dll.&lt;br /&gt;
&lt;br /&gt;
* Supporting CoreFoundation.dll (used for CFStringRef, CFPropertyListRef management) is located in the same dir (when using iTunes prior 9.0). &lt;br /&gt;
&lt;br /&gt;
* For iTunes 9.0 location of CoreFoundation.dll is stored in '''InstallDir''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Application Support''' key, usually C:\Program Files\Common Files\Apple\Apple Application Support\. CoreFoundation.dll from Mobile Device Support\bin should not be used.&lt;br /&gt;
&lt;br /&gt;
===Mac OSX : MobileDevice.framework===&lt;br /&gt;
&lt;br /&gt;
* Location : /System/Library/PrivateFrameworks/MobileDevice.framework&lt;br /&gt;
* Export command : &amp;quot;nm /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===MobileDevice Header (mobiledevice.h)===&lt;br /&gt;
&lt;br /&gt;
Reverse engineered C header for MobileDevice Library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* ----------------------------------------------------------------------------&lt;br /&gt;
 *   MobileDevice.h - interface to MobileDevice.framework &lt;br /&gt;
 * ------------------------------------------------------------------------- */&lt;br /&gt;
#pragma once&lt;br /&gt;
&lt;br /&gt;
#ifndef MOBILEDEVICE_H&lt;br /&gt;
#define MOBILEDEVICE_H&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
extern &amp;quot;C&amp;quot; {&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
#ifndef __GCC__&lt;br /&gt;
#pragma pack&lt;br /&gt;
#define __PACK&lt;br /&gt;
#else&lt;br /&gt;
#define __PACK __attribute__((__packed__))&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#if defined(WIN32)&lt;br /&gt;
#define __DLLIMPORT [DllImport(&amp;quot;iTunesMobileDevice.dll&amp;quot;)]&lt;br /&gt;
	using namespace System::Runtime::InteropServices;&lt;br /&gt;
#include &amp;lt;CoreFoundation.h&amp;gt;&lt;br /&gt;
	typedef unsigned int mach_error_t;&lt;br /&gt;
#elif defined(__APPLE__)&lt;br /&gt;
#define __DLLIMPORT&lt;br /&gt;
#include &amp;lt;CoreFoundation/CoreFoundation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;mach/error.h&amp;gt;&lt;br /&gt;
#endif	&lt;br /&gt;
	&lt;br /&gt;
	/* Error codes */&lt;br /&gt;
#define MDERR_APPLE_MOBILE  (err_system(0x3a))&lt;br /&gt;
#define MDERR_IPHONE        (err_sub(0))&lt;br /&gt;
	&lt;br /&gt;
	/* Apple Mobile (AM*) errors */&lt;br /&gt;
#define MDERR_OK                ERR_SUCCESS&lt;br /&gt;
#define MDERR_SYSCALL           (ERR_MOBILE_DEVICE | 0x01)&lt;br /&gt;
#define MDERR_OUT_OF_MEMORY     (ERR_MOBILE_DEVICE | 0x03)&lt;br /&gt;
#define MDERR_QUERY_FAILED      (ERR_MOBILE_DEVICE | 0x04) &lt;br /&gt;
#define MDERR_INVALID_ARGUMENT  (ERR_MOBILE_DEVICE | 0x0b)&lt;br /&gt;
#define MDERR_DICT_NOT_LOADED   (ERR_MOBILE_DEVICE | 0x25)&lt;br /&gt;
	&lt;br /&gt;
	/* Apple File Connection (AFC*) errors */&lt;br /&gt;
#define MDERR_AFC_OUT_OF_MEMORY 0x03&lt;br /&gt;
	&lt;br /&gt;
	/* USBMux errors */&lt;br /&gt;
#define MDERR_USBMUX_ARG_NULL   0x16&lt;br /&gt;
#define MDERR_USBMUX_FAILED     0xffffffff&lt;br /&gt;
	&lt;br /&gt;
	/* Messages passed to device notification callbacks: passed as part of&lt;br /&gt;
	 * am_device_notification_callback_info. */&lt;br /&gt;
#define ADNCI_MSG_CONNECTED     1&lt;br /&gt;
#define ADNCI_MSG_DISCONNECTED  2&lt;br /&gt;
#define ADNCI_MSG_UNSUBSCRIBED  3&lt;br /&gt;
	&lt;br /&gt;
#define AMD_IPHONE_PRODUCT_ID   0x1290&lt;br /&gt;
	//#define AMD_IPHONE_SERIAL       &amp;quot;&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
	/* Services, found in /System/Library/Lockdown/Services.plist */&lt;br /&gt;
#define AMSVC_AFC                   CFSTR(&amp;quot;com.apple.afc&amp;quot;)&lt;br /&gt;
#define AMSVC_BACKUP                CFSTR(&amp;quot;com.apple.mobilebackup&amp;quot;)&lt;br /&gt;
#define AMSVC_CRASH_REPORT_COPY     CFSTR(&amp;quot;com.apple.crashreportcopy&amp;quot;)&lt;br /&gt;
#define AMSVC_DEBUG_IMAGE_MOUNT     CFSTR(&amp;quot;com.apple.mobile.debug_image_mount&amp;quot;)&lt;br /&gt;
#define AMSVC_NOTIFICATION_PROXY    CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;)&lt;br /&gt;
#define AMSVC_PURPLE_TEST           CFSTR(&amp;quot;com.apple.purpletestr&amp;quot;)&lt;br /&gt;
#define AMSVC_SOFTWARE_UPDATE       CFSTR(&amp;quot;com.apple.mobile.software_update&amp;quot;)&lt;br /&gt;
#define AMSVC_SYNC                  CFSTR(&amp;quot;com.apple.mobilesync&amp;quot;)&lt;br /&gt;
#define AMSVC_SCREENSHOT            CFSTR(&amp;quot;com.apple.screenshotr&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSLOG_RELAY          CFSTR(&amp;quot;com.apple.syslog_relay&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSTEM_PROFILER       CFSTR(&amp;quot;com.apple.mobile.system_profiler&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned int afc_error_t;&lt;br /&gt;
	typedef unsigned int usbmux_error_t;&lt;br /&gt;
	&lt;br /&gt;
	struct am_recovery_device;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification_callback_info {&lt;br /&gt;
		struct am_device *dev;  /* 0    device */ &lt;br /&gt;
		unsigned int msg;       /* 4    one of ADNCI_MSG_* */&lt;br /&gt;
                struct am_device_notification* subscription; &lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
	&lt;br /&gt;
	/* This is a CoreFoundation object of class AMRecoveryModeDevice. */&lt;br /&gt;
	struct am_recovery_device {&lt;br /&gt;
		unsigned char unknown0[8];                          /* 0 */&lt;br /&gt;
		am_restore_device_notification_callback callback;   /* 8 */&lt;br /&gt;
		void *user_info;                                    /* 12 */&lt;br /&gt;
		unsigned char unknown1[12];                         /* 16 */&lt;br /&gt;
		unsigned int readwrite_pipe;                        /* 28 */&lt;br /&gt;
		unsigned char read_pipe;                            /* 32 */&lt;br /&gt;
		unsigned char write_ctrl_pipe;                      /* 33 */&lt;br /&gt;
		unsigned char read_unknown_pipe;                    /* 34 */&lt;br /&gt;
		unsigned char write_file_pipe;                      /* 35 */&lt;br /&gt;
		unsigned char write_input_pipe;                     /* 36 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* A CoreFoundation object of class AMRestoreModeDevice. */&lt;br /&gt;
	struct am_restore_device {&lt;br /&gt;
		unsigned char unknown[32];&lt;br /&gt;
		int port;&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device notification callback function. */&lt;br /&gt;
	typedef void(*am_device_notification_callback)(struct am_device_notification_callback_info *, int cookie);&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the _AMDDeviceAttached function.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void *amd_device_attached_callback;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
&lt;br /&gt;
	/* Structure that contains internal data used by AMDevice... functions. Never try &lt;br /&gt;
         * to access its members directly! Use AMDeviceCopyDeviceIdentifier, &lt;br /&gt;
         * AMDeviceGetConnectionID, AMDeviceRetain, AMDeviceRelease instead. */&lt;br /&gt;
	struct am_device {&lt;br /&gt;
		unsigned char unknown0[16]; /* 0 - zero */&lt;br /&gt;
		unsigned int device_id;     /* 16 */&lt;br /&gt;
		unsigned int product_id;    /* 20 - set to AMD_IPHONE_PRODUCT_ID */&lt;br /&gt;
		char *serial;               /* 24 - set to UDID, Unique Device Identifier */&lt;br /&gt;
		unsigned int unknown1;      /* 28 */&lt;br /&gt;
		unsigned int unknown2;      /* 32 - reference counter, increased by AMDeviceRetain, decreased by AMDeviceRelease*/&lt;br /&gt;
		unsigned int lockdown_conn; /* 36 */&lt;br /&gt;
		unsigned char unknown3[8];  /* 40 */&lt;br /&gt;
#if (__ITUNES_VER &amp;gt; 740)&lt;br /&gt;
		unsigned int unknown4;      /* 48 - used to store CriticalSection Handle*/&lt;br /&gt;
#endif&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
		unsigned char unknown5[24];  /* 52 */&lt;br /&gt;
#endif&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification {&lt;br /&gt;
		unsigned int unknown0;                      /* 0 */&lt;br /&gt;
		unsigned int unknown1;                      /* 4 */&lt;br /&gt;
		unsigned int unknown2;                      /* 8 */&lt;br /&gt;
		am_device_notification_callback callback;   /* 12 */ &lt;br /&gt;
		unsigned int cookie;                      /* 16 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct afc_connection {&lt;br /&gt;
		unsigned int handle;            /* 0 */&lt;br /&gt;
		unsigned int unknown0;          /* 4 */&lt;br /&gt;
		unsigned char unknown1;         /* 8 */&lt;br /&gt;
		unsigned char padding[3];       /* 9 */&lt;br /&gt;
		unsigned int unknown2;          /* 12 */&lt;br /&gt;
		unsigned int unknown3;          /* 16 */&lt;br /&gt;
		unsigned int unknown4;          /* 20 */&lt;br /&gt;
		unsigned int fs_block_size;     /* 24 */&lt;br /&gt;
		unsigned int sock_block_size;   /* 28: always 0x3c */&lt;br /&gt;
		unsigned int io_timeout;        /* 32: from AFCConnectionOpen, usu. 0 */&lt;br /&gt;
		void *afc_lock;                 /* 36 */&lt;br /&gt;
		unsigned int context;           /* 40 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
	struct afc_device_info {&lt;br /&gt;
		unsigned char unknown[12];  /* 0 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_directory {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_dictionary {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned long long afc_file_ref;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_1 {                  /* offset   value in iTunes */&lt;br /&gt;
		unsigned int unknown0;                  /* 0        1 */&lt;br /&gt;
		unsigned char *unknown1;                /* 4        ptr, maybe device? */&lt;br /&gt;
		amd_device_attached_callback callback;  /* 8        _AMDDeviceAttached */&lt;br /&gt;
		unsigned int unknown3;                  /* 12 */&lt;br /&gt;
		unsigned int unknown4;                  /* 16 */&lt;br /&gt;
		unsigned int unknown5;                  /* 20 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_2 {&lt;br /&gt;
		unsigned char unknown0[4144];&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_bootloader_control_packet {&lt;br /&gt;
		unsigned char opcode;       /* 0 */&lt;br /&gt;
		unsigned char length;       /* 1 */&lt;br /&gt;
		unsigned char magic[2];     /* 2: 0x34, 0x12 */&lt;br /&gt;
		unsigned char payload[0];   /* 4 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Registers a notification with the current run loop. The callback gets&lt;br /&gt;
	 *  copied into the notification struct, as well as being registered with the&lt;br /&gt;
	 *  current run loop. Cookie gets copied into cookie in the same.&lt;br /&gt;
	 *  (Cookie is a user info parameter that gets passed as an arg to&lt;br /&gt;
	 *  the callback) unused0 and unused1 are both 0 when iTunes calls this.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Never try to acces directly or copy contents of dev and subscription fields &lt;br /&gt;
	 *  in am_device_notification_callback_info. Treat them as abstract handles. &lt;br /&gt;
	 *  When done with connection use AMDeviceRelease to free resources allocated for am_device.&lt;br /&gt;
	 *  &lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK            if successful&lt;br /&gt;
	 *      MDERR_SYSCALL       if CFRunLoopAddSource() failed&lt;br /&gt;
	 *      MDERR_OUT_OF_MEMORY if we ran out of memory&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationSubscribe(am_device_notification_callback callback, &lt;br /&gt;
								unsigned int unused0, unsigned int unused1, &lt;br /&gt;
								unsigned int cookie, &lt;br /&gt;
								struct am_device_notification **subscription);&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
        /* Unregisters notifications. Buggy (iTunes 8.2): if you subscribe, unsubscribe and subscribe again, arriving &lt;br /&gt;
           notifications will contain cookie and subscription from 1st call to subscribe, not the 2nd one. iTunes &lt;br /&gt;
           calls this function only once on exit.&lt;br /&gt;
        */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationUnsubscribe(am_device_notification* subscription);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns device_id field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMDeviceGetConnectionID(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns serial field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyDeviceIdentifier(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Connects to the iPhone. Pass in the am_device structure that the&lt;br /&gt;
	 *  notification callback will give to you.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successfully connected&lt;br /&gt;
	 *      MDERR_SYSCALL           if setsockopt() failed&lt;br /&gt;
	 *      MDERR_QUERY_FAILED      if the daemon query failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if USBMuxConnectByPort returned 0xffffffff&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceConnect(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Calls PairingRecordPath() on the given device, than tests whether the path&lt;br /&gt;
	 *  which that function returns exists. During the initial connect, the path&lt;br /&gt;
	 *  returned by that function is '/', and so this returns 1.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      0   if the path did not exist&lt;br /&gt;
	 *      1   if it did&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceIsPaired(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDevicePair(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  iTunes calls this function immediately after testing whether the device is&lt;br /&gt;
	 *  paired. It creates a pairing file and establishes a Lockdown connection.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the supplied device is null&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceValidatePairing(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Creates a Lockdown session and adjusts the device structure appropriately&lt;br /&gt;
	 *  to indicate that the session has been started. iTunes calls this function&lt;br /&gt;
	 *  after validating pairing.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartSession(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* Reads various device settings. One of domain or cfstring arguments should be NULL.&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for cfstring:&lt;br /&gt;
	 * ActivationState&lt;br /&gt;
	 * ActivationStateAcknowledged&lt;br /&gt;
	 * BasebandBootloaderVersion&lt;br /&gt;
	 * BasebandVersion&lt;br /&gt;
	 * BluetoothAddress&lt;br /&gt;
	 * BuildVersion&lt;br /&gt;
	 * DeviceCertificate&lt;br /&gt;
	 * DeviceClass&lt;br /&gt;
	 * DeviceName&lt;br /&gt;
	 * DevicePublicKey&lt;br /&gt;
	 * FirmwareVersion&lt;br /&gt;
	 * HostAttached&lt;br /&gt;
	 * IntegratedCircuitCardIdentity&lt;br /&gt;
	 * InternationalMobileEquipmentIdentity&lt;br /&gt;
	 * InternationalMobileSubscriberIdentity&lt;br /&gt;
	 * ModelNumber&lt;br /&gt;
	 * PhoneNumber&lt;br /&gt;
	 * ProductType&lt;br /&gt;
	 * ProductVersion&lt;br /&gt;
	 * ProtocolVersion&lt;br /&gt;
	 * RegionInfo&lt;br /&gt;
	 * SBLockdownEverRegisteredKey&lt;br /&gt;
	 * SIMStatus&lt;br /&gt;
	 * SerialNumber&lt;br /&gt;
	 * SomebodySetTimeZone&lt;br /&gt;
	 * TimeIntervalSince1970&lt;br /&gt;
	 * TimeZone&lt;br /&gt;
	 * TimeZoneOffsetFromUTC&lt;br /&gt;
	 * TrustedHostAttached&lt;br /&gt;
	 * UniqueDeviceID&lt;br /&gt;
	 * Uses24HourClock&lt;br /&gt;
	 * WiFiAddress&lt;br /&gt;
	 * iTunesHasConnected&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for domain:&lt;br /&gt;
         * com.apple.mobile.battery&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyValue(struct am_device *device, CFStringRef domain, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* Starts a service and returns a socket file descriptor that can be used in order to further&lt;br /&gt;
	 * access the service. You should stop the session and disconnect before using&lt;br /&gt;
	 * the service. iTunes calls this function after starting a session. It starts &lt;br /&gt;
	 * the service and the SSL connection. service_name should be one of the AMSVC_*&lt;br /&gt;
	 * constants.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_SYSCALL           if the setsockopt() call failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartService(struct am_device *device, CFStringRef &lt;br /&gt;
									  service_name, int *socket_fd);&lt;br /&gt;
	&lt;br /&gt;
	/* Stops a session. You should do this before accessing services.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStopSession(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/* Decrements reference counter and, if nothing left, releases resources hold &lt;br /&gt;
	 * by connection, invalidates  pointer to device&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRelease(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Increments reference counter&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRetain(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Opens an Apple File Connection. You must start the appropriate service&lt;br /&gt;
	 * first with AMDeviceStartService(). In iTunes, io_timeout is 0.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_AFC_OUT_OF_MEMORY if malloc() failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionOpen(int socket_fd, unsigned int io_timeout,&lt;br /&gt;
								  struct afc_connection **conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Pass in a pointer to an afc_dictionary structure. It will be filled. You can&lt;br /&gt;
	 * iterate it using AFCKeyValueRead. When done use AFCKeyValueClose. Possible keys:&lt;br /&gt;
	 * FSFreeBytes - free bytes on system device for afc2, user device for afc&lt;br /&gt;
	 * FSBlockSize - filesystem block size&lt;br /&gt;
	 * FSTotalBytes - size of device&lt;br /&gt;
	 * Model - iPhone1,1 etc.&lt;br /&gt;
&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDeviceInfoOpen(struct afc_connection *conn, struct&lt;br /&gt;
								  afc_dictionary **info);&lt;br /&gt;
	&lt;br /&gt;
	/* Turns debug mode on if the environment variable AFCDEBUG is set to a numeric&lt;br /&gt;
	 * value, or if the file '/AFCDEBUG' is present and contains a value. */&lt;br /&gt;
#if defined(__APPLE__)&lt;br /&gt;
	void AFCPlatformInit();&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
	/* Opens a directory on the iPhone. Pass in a pointer in dir to be filled in.&lt;br /&gt;
	 * Note that this normally only accesses the iTunes sandbox/partition as the&lt;br /&gt;
	 * root, which is /var/root/Media. Pathnames are specified with '/' delimiters&lt;br /&gt;
	 * as in Unix style. Use UTF-8 to specify non-ASCII symbols in path.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								 afc_directory **dir);&lt;br /&gt;
	&lt;br /&gt;
	/* Acquires the next entry in a directory previously opened with&lt;br /&gt;
	 * AFCDirectoryOpen(). When dirent is filled with a NULL value, then the end&lt;br /&gt;
	 * of the directory has been reached. '.' and '..' will be returned as the&lt;br /&gt;
	 * first two entries in each directory except the root; you may want to skip&lt;br /&gt;
	 * over them.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful, even if no entries remain&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryRead(struct afc_connection *conn, struct afc_directory *dir,&lt;br /&gt;
								 char **dirent);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryClose(afc_connection *conn, struct afc_directory *dir);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryCreate(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRemovePath(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRenamePath(afc_connection *conn, char *oldpath, char *newpath);&lt;br /&gt;
&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
	/* Creates symbolic or hard link&lt;br /&gt;
         * linktype - int64: 1 means hard link, 2 - soft (symbolic) link&lt;br /&gt;
         * target - absolute or relative path to link target&lt;br /&gt;
         * linkname - absolute path where to create new link&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCLinkPath(struct afc_connection *conn, long long int linktype, const char *target, &lt;br /&gt;
								                              const char *linkname);&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
	/* Opens file for reading or writing without locking it in any way. afc_file_ref should not be shared between threads - &lt;br /&gt;
         * opening file in one thread and closing it in another will lead to possible crash.&lt;br /&gt;
	 * path - UTF-8 encoded absolute path to file&lt;br /&gt;
	 * mode 2 = read, mode 3 = write; unknown = 0 &lt;br /&gt;
	 * ref - receives file handle&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefOpen(struct afc_connection *conn, char *path, unsigned&lt;br /&gt;
							   long long int mode, afc_file_ref *ref);&lt;br /&gt;
	/* Reads specified amount (len) of bytes from file into buf. Puts actual count of read bytes into len on return&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefRead(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   void *buf, unsigned int *len);&lt;br /&gt;
	/* Writes specified amount (len) of bytes from buf into file.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefWrite(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
								void *buf, unsigned int len);&lt;br /&gt;
	/* Moves the file pointer to a specified location.&lt;br /&gt;
	 * offset - Number of bytes from origin (int64)&lt;br /&gt;
	 * origin - 0 = from beginning, 1 = from current position, 2 = from end&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefSeek(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long offset, int origin, int unused);&lt;br /&gt;
&lt;br /&gt;
	/* Gets the current position of a file pointer into offset argument.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefTell(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long* offset);&lt;br /&gt;
&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefLock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefUnlock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefClose(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
&lt;br /&gt;
	/* Opens dictionary describing specified file or directory (iTunes below 8.2 allowed using AFCGetFileInfo&lt;br /&gt;
	   to get the same information)&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileInfoOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								afc_dictionary **info);&lt;br /&gt;
&lt;br /&gt;
	/* Reads next entry from dictionary. When last entry is read, function returns NULL in key argument&lt;br /&gt;
	   Possible keys:&lt;br /&gt;
	     &amp;quot;st_size&amp;quot;:     val - size in bytes&lt;br /&gt;
	     &amp;quot;st_blocks&amp;quot;:   val - size in blocks&lt;br /&gt;
	     &amp;quot;st_nlink&amp;quot;:    val - number of hardlinks&lt;br /&gt;
	     &amp;quot;st_ifmt&amp;quot;:     val - &amp;quot;S_IFDIR&amp;quot; for folders&lt;br /&gt;
	                        &amp;quot;S_IFLNK&amp;quot; for symlinks&lt;br /&gt;
	     &amp;quot;LinkTarget&amp;quot;:  val - path to symlink target&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueRead(struct afc_dictionary *dict, char **key, char **&lt;br /&gt;
								val);&lt;br /&gt;
	/* Closes dictionary&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueClose(struct afc_dictionary *dict);&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the context field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetContext(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the fs_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetFSBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the io_timeout field of the given AFC connection. In iTunes this is&lt;br /&gt;
	 * 0. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetIOTimeout(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the sock_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetSocketBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Closes the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionClose(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Registers for device notifications related to the restore process. unknown0&lt;br /&gt;
	 * is zero when iTunes calls this. In iTunes,&lt;br /&gt;
	 * the callbacks are located at:&lt;br /&gt;
	 *      1: $3ac68e-$3ac6b1, calls $3ac542(unknown1, arg, 0)&lt;br /&gt;
	 *      2: $3ac66a-$3ac68d, calls $3ac542(unknown1, 0, arg)&lt;br /&gt;
	 *      3: $3ac762-$3ac785, calls $3ac6b2(unknown1, arg, 0)&lt;br /&gt;
	 *      4: $3ac73e-$3ac761, calls $3ac6b2(unknown1, 0, arg)&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreRegisterForDeviceNotifications(&lt;br /&gt;
				am_restore_device_notification_callback dfu_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback dfu_disconnect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_disconnect_callback,&lt;br /&gt;
				unsigned int unknown0,&lt;br /&gt;
				void *user_info);&lt;br /&gt;
	&lt;br /&gt;
	/* Causes the restore functions to spit out (unhelpful) progress messages to&lt;br /&gt;
	 * the file specified by the given path. iTunes always calls this right before&lt;br /&gt;
	 * restoring with a path of&lt;br /&gt;
	 * &amp;quot;$HOME/Library/Logs/iPhone Updater Logs/iPhoneUpdater X.log&amp;quot;, where X is an&lt;br /&gt;
	 * unused number.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreEnableFileLogging(char *path);&lt;br /&gt;
	&lt;br /&gt;
	/* Initializes a new option dictionary to default values. Pass the constant&lt;br /&gt;
	 * kCFAllocatorDefault as the allocator. The option dictionary looks as&lt;br /&gt;
	 * follows:&lt;br /&gt;
	 * {&lt;br /&gt;
	 *      NORImageType =&amp;gt; 'production',&lt;br /&gt;
	 *      AutoBootDelay =&amp;gt; 0,&lt;br /&gt;
	 *      KernelCacheType =&amp;gt; 'Release',&lt;br /&gt;
	 *      UpdateBaseband =&amp;gt; true,&lt;br /&gt;
	 *      DFUFileType =&amp;gt; 'RELEASE',&lt;br /&gt;
	 *      SystemImageType =&amp;gt; 'User',&lt;br /&gt;
	 *      CreateFilesystemPartitions =&amp;gt; true,&lt;br /&gt;
	 *      FlashNOR =&amp;gt; true,&lt;br /&gt;
	 *      RestoreBootArgs =&amp;gt; 'rd=md0 nand-enable-reformat=1 -progress'&lt;br /&gt;
	 *      BootImageType =&amp;gt; 'User'&lt;br /&gt;
	 *  }&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      the option dictionary   if successful&lt;br /&gt;
	 *      NULL                    if out of memory&lt;br /&gt;
	 */ &lt;br /&gt;
	__DLLIMPORT CFMutableDictionaryRef AMRestoreCreateDefaultOptions(CFAllocatorRef allocator);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRecoveryModeRestore(struct am_recovery_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRestoreModeRestore(struct am_restore_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT struct am_restore_device *AMRestoreModeDeviceCreate(unsigned int unknown0,&lt;br /&gt;
				unsigned int connection_id, unsigned int unknown1);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreCreatePathsForBundle(CFStringRef restore_bundle_path,&lt;br /&gt;
				CFStringRef kernel_cache_type, CFStringRef boot_image_type, unsigned int&lt;br /&gt;
				unknown0, CFStringRef *firmware_dir_path, CFStringRef *&lt;br /&gt;
				kernelcache_restore_path, unsigned int unknown1, CFStringRef *&lt;br /&gt;
				ramdisk_path);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreModeDeviceReboot(struct am_restore_device *rdev);	// Added by JB 30.07.2008&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceEnterRecovery(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDisconnect(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* to use this, start the service &amp;quot;com.apple.mobile.notification_proxy&amp;quot;, handle will be the socket to use */&lt;br /&gt;
	typedef void (*NOTIFY_CALLBACK)(CFSTR notification, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDPostNotification(SOCKET socket, CFStringRef  notification, CFStringRef userinfo);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDObserveNotification(SOCKET socket, CFSTR notification);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDListenForNotifications(SOCKET socket, NOTIFY_CALLBACK cb, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDShutdownNotificationProxy(SOCKET socket);&lt;br /&gt;
	&lt;br /&gt;
	/*edits by geohot*/&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDeactivate(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceActivate(struct am_device *device, CFDictionaryRef dict);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceRemoveValue(struct am_device *device, unsigned int, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Pass in a usbmux_listener_1 structure and a usbmux_listener_2 structure&lt;br /&gt;
	 *  pointer, which will be filled with the resulting usbmux_listener_2.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if completed successfully&lt;br /&gt;
	 *      MDERR_USBMUX_ARG_NULL   if one of the arguments was NULL&lt;br /&gt;
	 *      MDERR_USBMUX_FAILED     if the listener was not created successfully&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerCreate(struct usbmux_listener_1 *esi_fp8, struct&lt;br /&gt;
										usbmux_listener_2 **eax_fp12);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerHandleData(void *);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Private routines - here be dragons&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/* AMRestorePerformRestoreModeRestore() calls this function with a dictionary&lt;br /&gt;
	 * in order to perform certain special restore operations&lt;br /&gt;
	 * (RESTORED_OPERATION_*). It is thought that this function might enable&lt;br /&gt;
	 * significant access to the phone. */&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef unsigned int (*t_performOperation)(struct am_restore_device *rdev,&lt;br /&gt;
	 CFDictionaryRef op) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_performOperation _performOperation = (t_performOperation)0x3c39fa4b;&lt;br /&gt;
	 */ &lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef int (*t_socketForPort)(struct am_restore_device *rdev, unsigned int port)&lt;br /&gt;
	 __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_socketForPort _socketForPort = (t_socketForPort)(void *)0x3c39f36c;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef void (*t_restored_send_message)(int port, CFDictionaryRef msg);&lt;br /&gt;
	 t_restored_send_message _restored_send_message = (t_restored_send_message)0x3c3a4e40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef CFDictionaryRef (*t_restored_receive_message)(int port);&lt;br /&gt;
	 t_restored_receive_message _restored_receive_message = (t_restored_receive_message)0x3c3a4d40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendControlPacket)(struct am_recovery_device *rdev, unsigned&lt;br /&gt;
	 int msg1, unsigned int msg2, unsigned int unknown0, unsigned int *unknown1,&lt;br /&gt;
	 unsigned char *unknown2) __attribute__ ((regparm(3)));&lt;br /&gt;
	 t_sendControlPacket _sendControlPacket = (t_sendControlPacket)0x3c3a3da3;;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendCommandToDevice)(struct am_recovery_device *rdev,&lt;br /&gt;
	 CFStringRef cmd) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_sendCommandToDevice _sendCommandToDevice = (t_sendCommandToDevice)0x3c3a3e3b;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceReadPipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int read_pipe, unsigned char *data, unsigned int *len);&lt;br /&gt;
	 t_AMRUSBInterfaceReadPipe _AMRUSBInterfaceReadPipe = (t_AMRUSBInterfaceReadPipe)0x3c3a27e8;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceWritePipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int write_pipe, void *data, unsigned int len);&lt;br /&gt;
	 t_AMRUSBInterfaceWritePipe _AMRUSBInterfaceWritePipe = (t_AMRUSBInterfaceWritePipe)0x3c3a27cb;&lt;br /&gt;
	 */&lt;br /&gt;
	&lt;br /&gt;
	int performOperation(am_restore_device *rdev, CFMutableDictionaryRef message);&lt;br /&gt;
	int socketForPort(am_restore_device *rdev, unsigned int portnum);&lt;br /&gt;
	int sendCommandToDevice(am_recovery_device *rdev, CFStringRef cfs, int block);&lt;br /&gt;
	int sendFileToDevice(am_recovery_device *rdev, CFStringRef filename); &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
}&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
/* -*- mode:c; indent-tabs-mode:nil; c-basic-offset:2; tab-width:2; */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===AFC Connection===&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
===Locking the Device for Sync===&lt;br /&gt;
When iTunes sends a new song to the device, the device shows a &amp;quot;Sync in progress&amp;quot; screen and when complete, the Music app on the device re-reads the iTunesDB file so it picks up the new song.&lt;br /&gt;
&lt;br /&gt;
To get this behaviour, first start the notification service:&lt;br /&gt;
&amp;lt;pre&amp;gt;SOCKET socket;&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we post a notificaton message to signal that we are going to start a sync:&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncWillStart&amp;quot;), NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we open the itunes lock file:&lt;br /&gt;
&amp;lt;pre&amp;gt;afc_file_ref lockref;&lt;br /&gt;
AFCFileRefOpen(conn, &amp;quot;/com.apple.itunes.lock_sync&amp;quot;, 2, &amp;amp;lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now post a notification to say we are going to lock this file, and try and lock it.&lt;br /&gt;
If the AFCFileRefLock call fails, pause and repeat.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncLockRequest&amp;quot;), NULL);&lt;br /&gt;
mach_error_t error = AFCFileRefLock(conn, lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the file is successfully locked, post another notification, and stop the notification service.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket,CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidStart&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the sync can proceed, so copy your files across and make the changes to the iTunesDB.&lt;br /&gt;
&lt;br /&gt;
To release the lock, start the notification system again, unlock and close the lock file, and send a sync finished notification message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;AFCFileRefUnlock(conn, lockref);&lt;br /&gt;
AFCFileRefClose(conn, lockref);&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&lt;br /&gt;
AMDPostNotification(socket, &amp;amp;CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidFinish&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To handle &amp;quot;Slide to Cancel&amp;quot; and terminate sync when user slides cancel switch, use AMDObserveNotification to subscribe notifications about “com.apple.itunes-client.syncCancelRequest”. Then start listening for notifications (AMDListenForNotifications) until you get “AMDNotificationFaceplant”.&lt;br /&gt;
When notification got, you should unlock and close lock file handle (don’t sure if you need to post “syncDidFinish” to proxy, seems it doesn’t matter) and terminate sync gracefully.&lt;br /&gt;
The same notification is also got when you unplug your device, so you should always be ready for errors.&lt;br /&gt;
&lt;br /&gt;
NOTE: You may find that starting the notification_proxy service once and once only at the start of your app and using the same socket in calls to AMDPostNotification works better. iTunes opens and closes the notification_proxy regularly, but it appears to be a bit flakey when you open/close it all the time.&lt;br /&gt;
&lt;br /&gt;
===Private Functions===&lt;br /&gt;
&lt;br /&gt;
====How to find address of privates functions in iTunesMobileDevice.dll or MobileDevice.framework====&lt;br /&gt;
&lt;br /&gt;
In order to obtain the address of a usable private function in MobileDevice, you will have to be able to understand x86-64 assembly to reverse engineer it. A private function will not have its name exported in the mach-o symbol table, so in a debugger, like GDB, it will show up as part of another function. However, you will know that it is a separate function as a new stack frame is set up.&lt;br /&gt;
&lt;br /&gt;
====Private Function Address List====&lt;br /&gt;
&lt;br /&gt;
=====OSX.6 - iTunes 9.0.2(25)=====&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendCommandToiBoot(struct am_recovery_device *rdev, CFStringRef command, int u);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 868(0x364) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym(). &lt;br /&gt;
Address: 0x245ea&lt;br /&gt;
-Parameters-&lt;br /&gt;
1. rdev - the device you wish to send the command to&lt;br /&gt;
2. a CFStringRef of the command to send&lt;br /&gt;
3. an integer, whose use is currently unknown, but should be set to 0 to work.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendFileToiDevice(struct am_recovery_device *rdev, CFStringRef filename);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 1168(0x490) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym().&lt;br /&gt;
Address: 0x24716&lt;br /&gt;
-Parameters-&lt;br /&gt;
1. rdev - the device you wish to send the file to&lt;br /&gt;
2. a CFStringRef of the path to the file to send&lt;br /&gt;
&lt;br /&gt;
===Libraries Implementations===&lt;br /&gt;
&lt;br /&gt;
* [http://gojohnnyboi.com/source/afcinstall.cpp afcinstall (command line, os x file install via afc)]&lt;br /&gt;
* [http://code.google.com/p/iphuc/ iPhuc (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/iphucwin32/ iPhuc Win32 (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/manzana/ manzana (.Net Library)]&lt;br /&gt;
* [http://code.google.com/p/independence/source/browse/trunk/libPhoneInteraction/ libPhoneInteraction (C Library)]&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5677</id>
		<title>MobileDevice Library</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5677"/>
		<updated>2009-11-21T21:18:11Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MobileDevice Library is used by [[iTunes]] to transfer data between iPhone and computer over the USB connection.&lt;br /&gt;
&lt;br /&gt;
===PC Windows : iTunesMobileDevice.dll===&lt;br /&gt;
&lt;br /&gt;
* Location : Location is stored in '''iTunesMobileDeviceDLL''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Mobile Device Support\Shared''' key. Usually - C:\Program Files\Common Files\Apple\Mobile Device Support\bin\iTunesMobileDevice.dll.&lt;br /&gt;
&lt;br /&gt;
* Supporting CoreFoundation.dll (used for CFStringRef, CFPropertyListRef management) is located in the same dir (when using iTunes prior 9.0). &lt;br /&gt;
&lt;br /&gt;
* For iTunes 9.0 location of CoreFoundation.dll is stored in '''InstallDir''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Application Support''' key, usually C:\Program Files\Common Files\Apple\Apple Application Support\. CoreFoundation.dll from Mobile Device Support\bin should not be used.&lt;br /&gt;
&lt;br /&gt;
===Mac OSX : MobileDevice.framework===&lt;br /&gt;
&lt;br /&gt;
* Location : /System/Library/PrivateFrameworks/MobileDevice.framework&lt;br /&gt;
* Export command : &amp;quot;nm /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===MobileDevice Header (mobiledevice.h)===&lt;br /&gt;
&lt;br /&gt;
Reverse engineered C header for MobileDevice Library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* ----------------------------------------------------------------------------&lt;br /&gt;
 *   MobileDevice.h - interface to MobileDevice.framework &lt;br /&gt;
 * ------------------------------------------------------------------------- */&lt;br /&gt;
#pragma once&lt;br /&gt;
&lt;br /&gt;
#ifndef MOBILEDEVICE_H&lt;br /&gt;
#define MOBILEDEVICE_H&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
extern &amp;quot;C&amp;quot; {&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
#ifndef __GCC__&lt;br /&gt;
#pragma pack&lt;br /&gt;
#define __PACK&lt;br /&gt;
#else&lt;br /&gt;
#define __PACK __attribute__((__packed__))&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#if defined(WIN32)&lt;br /&gt;
#define __DLLIMPORT [DllImport(&amp;quot;iTunesMobileDevice.dll&amp;quot;)]&lt;br /&gt;
	using namespace System::Runtime::InteropServices;&lt;br /&gt;
#include &amp;lt;CoreFoundation.h&amp;gt;&lt;br /&gt;
	typedef unsigned int mach_error_t;&lt;br /&gt;
#elif defined(__APPLE__)&lt;br /&gt;
#define __DLLIMPORT&lt;br /&gt;
#include &amp;lt;CoreFoundation/CoreFoundation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;mach/error.h&amp;gt;&lt;br /&gt;
#endif	&lt;br /&gt;
	&lt;br /&gt;
	/* Error codes */&lt;br /&gt;
#define MDERR_APPLE_MOBILE  (err_system(0x3a))&lt;br /&gt;
#define MDERR_IPHONE        (err_sub(0))&lt;br /&gt;
	&lt;br /&gt;
	/* Apple Mobile (AM*) errors */&lt;br /&gt;
#define MDERR_OK                ERR_SUCCESS&lt;br /&gt;
#define MDERR_SYSCALL           (ERR_MOBILE_DEVICE | 0x01)&lt;br /&gt;
#define MDERR_OUT_OF_MEMORY     (ERR_MOBILE_DEVICE | 0x03)&lt;br /&gt;
#define MDERR_QUERY_FAILED      (ERR_MOBILE_DEVICE | 0x04) &lt;br /&gt;
#define MDERR_INVALID_ARGUMENT  (ERR_MOBILE_DEVICE | 0x0b)&lt;br /&gt;
#define MDERR_DICT_NOT_LOADED   (ERR_MOBILE_DEVICE | 0x25)&lt;br /&gt;
	&lt;br /&gt;
	/* Apple File Connection (AFC*) errors */&lt;br /&gt;
#define MDERR_AFC_OUT_OF_MEMORY 0x03&lt;br /&gt;
	&lt;br /&gt;
	/* USBMux errors */&lt;br /&gt;
#define MDERR_USBMUX_ARG_NULL   0x16&lt;br /&gt;
#define MDERR_USBMUX_FAILED     0xffffffff&lt;br /&gt;
	&lt;br /&gt;
	/* Messages passed to device notification callbacks: passed as part of&lt;br /&gt;
	 * am_device_notification_callback_info. */&lt;br /&gt;
#define ADNCI_MSG_CONNECTED     1&lt;br /&gt;
#define ADNCI_MSG_DISCONNECTED  2&lt;br /&gt;
#define ADNCI_MSG_UNSUBSCRIBED  3&lt;br /&gt;
	&lt;br /&gt;
#define AMD_IPHONE_PRODUCT_ID   0x1290&lt;br /&gt;
	//#define AMD_IPHONE_SERIAL       &amp;quot;&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
	/* Services, found in /System/Library/Lockdown/Services.plist */&lt;br /&gt;
#define AMSVC_AFC                   CFSTR(&amp;quot;com.apple.afc&amp;quot;)&lt;br /&gt;
#define AMSVC_BACKUP                CFSTR(&amp;quot;com.apple.mobilebackup&amp;quot;)&lt;br /&gt;
#define AMSVC_CRASH_REPORT_COPY     CFSTR(&amp;quot;com.apple.crashreportcopy&amp;quot;)&lt;br /&gt;
#define AMSVC_DEBUG_IMAGE_MOUNT     CFSTR(&amp;quot;com.apple.mobile.debug_image_mount&amp;quot;)&lt;br /&gt;
#define AMSVC_NOTIFICATION_PROXY    CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;)&lt;br /&gt;
#define AMSVC_PURPLE_TEST           CFSTR(&amp;quot;com.apple.purpletestr&amp;quot;)&lt;br /&gt;
#define AMSVC_SOFTWARE_UPDATE       CFSTR(&amp;quot;com.apple.mobile.software_update&amp;quot;)&lt;br /&gt;
#define AMSVC_SYNC                  CFSTR(&amp;quot;com.apple.mobilesync&amp;quot;)&lt;br /&gt;
#define AMSVC_SCREENSHOT            CFSTR(&amp;quot;com.apple.screenshotr&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSLOG_RELAY          CFSTR(&amp;quot;com.apple.syslog_relay&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSTEM_PROFILER       CFSTR(&amp;quot;com.apple.mobile.system_profiler&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned int afc_error_t;&lt;br /&gt;
	typedef unsigned int usbmux_error_t;&lt;br /&gt;
	&lt;br /&gt;
	struct am_recovery_device;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification_callback_info {&lt;br /&gt;
		struct am_device *dev;  /* 0    device */ &lt;br /&gt;
		unsigned int msg;       /* 4    one of ADNCI_MSG_* */&lt;br /&gt;
                struct am_device_notification* subscription; &lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
	&lt;br /&gt;
	/* This is a CoreFoundation object of class AMRecoveryModeDevice. */&lt;br /&gt;
	struct am_recovery_device {&lt;br /&gt;
		unsigned char unknown0[8];                          /* 0 */&lt;br /&gt;
		am_restore_device_notification_callback callback;   /* 8 */&lt;br /&gt;
		void *user_info;                                    /* 12 */&lt;br /&gt;
		unsigned char unknown1[12];                         /* 16 */&lt;br /&gt;
		unsigned int readwrite_pipe;                        /* 28 */&lt;br /&gt;
		unsigned char read_pipe;                            /* 32 */&lt;br /&gt;
		unsigned char write_ctrl_pipe;                      /* 33 */&lt;br /&gt;
		unsigned char read_unknown_pipe;                    /* 34 */&lt;br /&gt;
		unsigned char write_file_pipe;                      /* 35 */&lt;br /&gt;
		unsigned char write_input_pipe;                     /* 36 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* A CoreFoundation object of class AMRestoreModeDevice. */&lt;br /&gt;
	struct am_restore_device {&lt;br /&gt;
		unsigned char unknown[32];&lt;br /&gt;
		int port;&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device notification callback function. */&lt;br /&gt;
	typedef void(*am_device_notification_callback)(struct am_device_notification_callback_info *, int cookie);&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the _AMDDeviceAttached function.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void *amd_device_attached_callback;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
&lt;br /&gt;
	/* Structure that contains internal data used by AMDevice... functions. Never try &lt;br /&gt;
         * to access its members directly! Use AMDeviceCopyDeviceIdentifier, &lt;br /&gt;
         * AMDeviceGetConnectionID, AMDeviceRetain, AMDeviceRelease instead. */&lt;br /&gt;
	struct am_device {&lt;br /&gt;
		unsigned char unknown0[16]; /* 0 - zero */&lt;br /&gt;
		unsigned int device_id;     /* 16 */&lt;br /&gt;
		unsigned int product_id;    /* 20 - set to AMD_IPHONE_PRODUCT_ID */&lt;br /&gt;
		char *serial;               /* 24 - set to UDID, Unique Device Identifier */&lt;br /&gt;
		unsigned int unknown1;      /* 28 */&lt;br /&gt;
		unsigned int unknown2;      /* 32 - reference counter, increased by AMDeviceRetain, decreased by AMDeviceRelease*/&lt;br /&gt;
		unsigned int lockdown_conn; /* 36 */&lt;br /&gt;
		unsigned char unknown3[8];  /* 40 */&lt;br /&gt;
#if (__ITUNES_VER &amp;gt; 740)&lt;br /&gt;
		unsigned int unknown4;      /* 48 - used to store CriticalSection Handle*/&lt;br /&gt;
#endif&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
		unsigned char unknown5[24];  /* 52 */&lt;br /&gt;
#endif&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification {&lt;br /&gt;
		unsigned int unknown0;                      /* 0 */&lt;br /&gt;
		unsigned int unknown1;                      /* 4 */&lt;br /&gt;
		unsigned int unknown2;                      /* 8 */&lt;br /&gt;
		am_device_notification_callback callback;   /* 12 */ &lt;br /&gt;
		unsigned int cookie;                      /* 16 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct afc_connection {&lt;br /&gt;
		unsigned int handle;            /* 0 */&lt;br /&gt;
		unsigned int unknown0;          /* 4 */&lt;br /&gt;
		unsigned char unknown1;         /* 8 */&lt;br /&gt;
		unsigned char padding[3];       /* 9 */&lt;br /&gt;
		unsigned int unknown2;          /* 12 */&lt;br /&gt;
		unsigned int unknown3;          /* 16 */&lt;br /&gt;
		unsigned int unknown4;          /* 20 */&lt;br /&gt;
		unsigned int fs_block_size;     /* 24 */&lt;br /&gt;
		unsigned int sock_block_size;   /* 28: always 0x3c */&lt;br /&gt;
		unsigned int io_timeout;        /* 32: from AFCConnectionOpen, usu. 0 */&lt;br /&gt;
		void *afc_lock;                 /* 36 */&lt;br /&gt;
		unsigned int context;           /* 40 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
	struct afc_device_info {&lt;br /&gt;
		unsigned char unknown[12];  /* 0 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_directory {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_dictionary {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned long long afc_file_ref;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_1 {                  /* offset   value in iTunes */&lt;br /&gt;
		unsigned int unknown0;                  /* 0        1 */&lt;br /&gt;
		unsigned char *unknown1;                /* 4        ptr, maybe device? */&lt;br /&gt;
		amd_device_attached_callback callback;  /* 8        _AMDDeviceAttached */&lt;br /&gt;
		unsigned int unknown3;                  /* 12 */&lt;br /&gt;
		unsigned int unknown4;                  /* 16 */&lt;br /&gt;
		unsigned int unknown5;                  /* 20 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_2 {&lt;br /&gt;
		unsigned char unknown0[4144];&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_bootloader_control_packet {&lt;br /&gt;
		unsigned char opcode;       /* 0 */&lt;br /&gt;
		unsigned char length;       /* 1 */&lt;br /&gt;
		unsigned char magic[2];     /* 2: 0x34, 0x12 */&lt;br /&gt;
		unsigned char payload[0];   /* 4 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Registers a notification with the current run loop. The callback gets&lt;br /&gt;
	 *  copied into the notification struct, as well as being registered with the&lt;br /&gt;
	 *  current run loop. Cookie gets copied into cookie in the same.&lt;br /&gt;
	 *  (Cookie is a user info parameter that gets passed as an arg to&lt;br /&gt;
	 *  the callback) unused0 and unused1 are both 0 when iTunes calls this.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Never try to acces directly or copy contents of dev and subscription fields &lt;br /&gt;
	 *  in am_device_notification_callback_info. Treat them as abstract handles. &lt;br /&gt;
	 *  When done with connection use AMDeviceRelease to free resources allocated for am_device.&lt;br /&gt;
	 *  &lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK            if successful&lt;br /&gt;
	 *      MDERR_SYSCALL       if CFRunLoopAddSource() failed&lt;br /&gt;
	 *      MDERR_OUT_OF_MEMORY if we ran out of memory&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationSubscribe(am_device_notification_callback callback, &lt;br /&gt;
								unsigned int unused0, unsigned int unused1, &lt;br /&gt;
								unsigned int cookie, &lt;br /&gt;
								struct am_device_notification **subscription);&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
        /* Unregisters notifications. Buggy (iTunes 8.2): if you subscribe, unsubscribe and subscribe again, arriving &lt;br /&gt;
           notifications will contain cookie and subscription from 1st call to subscribe, not the 2nd one. iTunes &lt;br /&gt;
           calls this function only once on exit.&lt;br /&gt;
        */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationUnsubscribe(am_device_notification* subscription);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns device_id field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMDeviceGetConnectionID(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns serial field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyDeviceIdentifier(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Connects to the iPhone. Pass in the am_device structure that the&lt;br /&gt;
	 *  notification callback will give to you.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successfully connected&lt;br /&gt;
	 *      MDERR_SYSCALL           if setsockopt() failed&lt;br /&gt;
	 *      MDERR_QUERY_FAILED      if the daemon query failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if USBMuxConnectByPort returned 0xffffffff&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceConnect(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Calls PairingRecordPath() on the given device, than tests whether the path&lt;br /&gt;
	 *  which that function returns exists. During the initial connect, the path&lt;br /&gt;
	 *  returned by that function is '/', and so this returns 1.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      0   if the path did not exist&lt;br /&gt;
	 *      1   if it did&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceIsPaired(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDevicePair(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  iTunes calls this function immediately after testing whether the device is&lt;br /&gt;
	 *  paired. It creates a pairing file and establishes a Lockdown connection.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the supplied device is null&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceValidatePairing(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Creates a Lockdown session and adjusts the device structure appropriately&lt;br /&gt;
	 *  to indicate that the session has been started. iTunes calls this function&lt;br /&gt;
	 *  after validating pairing.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartSession(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* Reads various device settings. One of domain or cfstring arguments should be NULL.&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for cfstring:&lt;br /&gt;
	 * ActivationState&lt;br /&gt;
	 * ActivationStateAcknowledged&lt;br /&gt;
	 * BasebandBootloaderVersion&lt;br /&gt;
	 * BasebandVersion&lt;br /&gt;
	 * BluetoothAddress&lt;br /&gt;
	 * BuildVersion&lt;br /&gt;
	 * DeviceCertificate&lt;br /&gt;
	 * DeviceClass&lt;br /&gt;
	 * DeviceName&lt;br /&gt;
	 * DevicePublicKey&lt;br /&gt;
	 * FirmwareVersion&lt;br /&gt;
	 * HostAttached&lt;br /&gt;
	 * IntegratedCircuitCardIdentity&lt;br /&gt;
	 * InternationalMobileEquipmentIdentity&lt;br /&gt;
	 * InternationalMobileSubscriberIdentity&lt;br /&gt;
	 * ModelNumber&lt;br /&gt;
	 * PhoneNumber&lt;br /&gt;
	 * ProductType&lt;br /&gt;
	 * ProductVersion&lt;br /&gt;
	 * ProtocolVersion&lt;br /&gt;
	 * RegionInfo&lt;br /&gt;
	 * SBLockdownEverRegisteredKey&lt;br /&gt;
	 * SIMStatus&lt;br /&gt;
	 * SerialNumber&lt;br /&gt;
	 * SomebodySetTimeZone&lt;br /&gt;
	 * TimeIntervalSince1970&lt;br /&gt;
	 * TimeZone&lt;br /&gt;
	 * TimeZoneOffsetFromUTC&lt;br /&gt;
	 * TrustedHostAttached&lt;br /&gt;
	 * UniqueDeviceID&lt;br /&gt;
	 * Uses24HourClock&lt;br /&gt;
	 * WiFiAddress&lt;br /&gt;
	 * iTunesHasConnected&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for domain:&lt;br /&gt;
         * com.apple.mobile.battery&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyValue(struct am_device *device, CFStringRef domain, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* Starts a service and returns a socket file descriptor that can be used in order to further&lt;br /&gt;
	 * access the service. You should stop the session and disconnect before using&lt;br /&gt;
	 * the service. iTunes calls this function after starting a session. It starts &lt;br /&gt;
	 * the service and the SSL connection. service_name should be one of the AMSVC_*&lt;br /&gt;
	 * constants.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_SYSCALL           if the setsockopt() call failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartService(struct am_device *device, CFStringRef &lt;br /&gt;
									  service_name, int *socket_fd);&lt;br /&gt;
	&lt;br /&gt;
	/* Stops a session. You should do this before accessing services.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStopSession(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/* Decrements reference counter and, if nothing left, releases resources hold &lt;br /&gt;
	 * by connection, invalidates  pointer to device&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRelease(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Increments reference counter&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRetain(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Opens an Apple File Connection. You must start the appropriate service&lt;br /&gt;
	 * first with AMDeviceStartService(). In iTunes, io_timeout is 0.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_AFC_OUT_OF_MEMORY if malloc() failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionOpen(int socket_fd, unsigned int io_timeout,&lt;br /&gt;
								  struct afc_connection **conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Pass in a pointer to an afc_dictionary structure. It will be filled. You can&lt;br /&gt;
	 * iterate it using AFCKeyValueRead. When done use AFCKeyValueClose. Possible keys:&lt;br /&gt;
	 * FSFreeBytes - free bytes on system device for afc2, user device for afc&lt;br /&gt;
	 * FSBlockSize - filesystem block size&lt;br /&gt;
	 * FSTotalBytes - size of device&lt;br /&gt;
	 * Model - iPhone1,1 etc.&lt;br /&gt;
&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDeviceInfoOpen(struct afc_connection *conn, struct&lt;br /&gt;
								  afc_dictionary **info);&lt;br /&gt;
	&lt;br /&gt;
	/* Turns debug mode on if the environment variable AFCDEBUG is set to a numeric&lt;br /&gt;
	 * value, or if the file '/AFCDEBUG' is present and contains a value. */&lt;br /&gt;
#if defined(__APPLE__)&lt;br /&gt;
	void AFCPlatformInit();&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
	/* Opens a directory on the iPhone. Pass in a pointer in dir to be filled in.&lt;br /&gt;
	 * Note that this normally only accesses the iTunes sandbox/partition as the&lt;br /&gt;
	 * root, which is /var/root/Media. Pathnames are specified with '/' delimiters&lt;br /&gt;
	 * as in Unix style. Use UTF-8 to specify non-ASCII symbols in path.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								 afc_directory **dir);&lt;br /&gt;
	&lt;br /&gt;
	/* Acquires the next entry in a directory previously opened with&lt;br /&gt;
	 * AFCDirectoryOpen(). When dirent is filled with a NULL value, then the end&lt;br /&gt;
	 * of the directory has been reached. '.' and '..' will be returned as the&lt;br /&gt;
	 * first two entries in each directory except the root; you may want to skip&lt;br /&gt;
	 * over them.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful, even if no entries remain&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryRead(struct afc_connection *conn, struct afc_directory *dir,&lt;br /&gt;
								 char **dirent);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryClose(afc_connection *conn, struct afc_directory *dir);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryCreate(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRemovePath(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRenamePath(afc_connection *conn, char *oldpath, char *newpath);&lt;br /&gt;
&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
	/* Creates symbolic or hard link&lt;br /&gt;
         * linktype - int64: 1 means hard link, 2 - soft (symbolic) link&lt;br /&gt;
         * target - absolute or relative path to link target&lt;br /&gt;
         * linkname - absolute path where to create new link&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCLinkPath(struct afc_connection *conn, long long int linktype, const char *target, &lt;br /&gt;
								                              const char *linkname);&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
	/* Opens file for reading or writing without locking it in any way. afc_file_ref should not be shared between threads - &lt;br /&gt;
         * opening file in one thread and closing it in another will lead to possible crash.&lt;br /&gt;
	 * path - UTF-8 encoded absolute path to file&lt;br /&gt;
	 * mode 2 = read, mode 3 = write; unknown = 0 &lt;br /&gt;
	 * ref - receives file handle&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefOpen(struct afc_connection *conn, char *path, unsigned&lt;br /&gt;
							   long long int mode, afc_file_ref *ref);&lt;br /&gt;
	/* Reads specified amount (len) of bytes from file into buf. Puts actual count of read bytes into len on return&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefRead(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   void *buf, unsigned int *len);&lt;br /&gt;
	/* Writes specified amount (len) of bytes from buf into file.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefWrite(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
								void *buf, unsigned int len);&lt;br /&gt;
	/* Moves the file pointer to a specified location.&lt;br /&gt;
	 * offset - Number of bytes from origin (int64)&lt;br /&gt;
	 * origin - 0 = from beginning, 1 = from current position, 2 = from end&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefSeek(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long offset, int origin, int unused);&lt;br /&gt;
&lt;br /&gt;
	/* Gets the current position of a file pointer into offset argument.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefTell(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long* offset);&lt;br /&gt;
&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefLock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefUnlock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefClose(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
&lt;br /&gt;
	/* Opens dictionary describing specified file or directory (iTunes below 8.2 allowed using AFCGetFileInfo&lt;br /&gt;
	   to get the same information)&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileInfoOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								afc_dictionary **info);&lt;br /&gt;
&lt;br /&gt;
	/* Reads next entry from dictionary. When last entry is read, function returns NULL in key argument&lt;br /&gt;
	   Possible keys:&lt;br /&gt;
	     &amp;quot;st_size&amp;quot;:     val - size in bytes&lt;br /&gt;
	     &amp;quot;st_blocks&amp;quot;:   val - size in blocks&lt;br /&gt;
	     &amp;quot;st_nlink&amp;quot;:    val - number of hardlinks&lt;br /&gt;
	     &amp;quot;st_ifmt&amp;quot;:     val - &amp;quot;S_IFDIR&amp;quot; for folders&lt;br /&gt;
	                        &amp;quot;S_IFLNK&amp;quot; for symlinks&lt;br /&gt;
	     &amp;quot;LinkTarget&amp;quot;:  val - path to symlink target&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueRead(struct afc_dictionary *dict, char **key, char **&lt;br /&gt;
								val);&lt;br /&gt;
	/* Closes dictionary&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueClose(struct afc_dictionary *dict);&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the context field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetContext(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the fs_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetFSBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the io_timeout field of the given AFC connection. In iTunes this is&lt;br /&gt;
	 * 0. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetIOTimeout(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the sock_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetSocketBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Closes the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionClose(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Registers for device notifications related to the restore process. unknown0&lt;br /&gt;
	 * is zero when iTunes calls this. In iTunes,&lt;br /&gt;
	 * the callbacks are located at:&lt;br /&gt;
	 *      1: $3ac68e-$3ac6b1, calls $3ac542(unknown1, arg, 0)&lt;br /&gt;
	 *      2: $3ac66a-$3ac68d, calls $3ac542(unknown1, 0, arg)&lt;br /&gt;
	 *      3: $3ac762-$3ac785, calls $3ac6b2(unknown1, arg, 0)&lt;br /&gt;
	 *      4: $3ac73e-$3ac761, calls $3ac6b2(unknown1, 0, arg)&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreRegisterForDeviceNotifications(&lt;br /&gt;
				am_restore_device_notification_callback dfu_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback dfu_disconnect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_disconnect_callback,&lt;br /&gt;
				unsigned int unknown0,&lt;br /&gt;
				void *user_info);&lt;br /&gt;
	&lt;br /&gt;
	/* Causes the restore functions to spit out (unhelpful) progress messages to&lt;br /&gt;
	 * the file specified by the given path. iTunes always calls this right before&lt;br /&gt;
	 * restoring with a path of&lt;br /&gt;
	 * &amp;quot;$HOME/Library/Logs/iPhone Updater Logs/iPhoneUpdater X.log&amp;quot;, where X is an&lt;br /&gt;
	 * unused number.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreEnableFileLogging(char *path);&lt;br /&gt;
	&lt;br /&gt;
	/* Initializes a new option dictionary to default values. Pass the constant&lt;br /&gt;
	 * kCFAllocatorDefault as the allocator. The option dictionary looks as&lt;br /&gt;
	 * follows:&lt;br /&gt;
	 * {&lt;br /&gt;
	 *      NORImageType =&amp;gt; 'production',&lt;br /&gt;
	 *      AutoBootDelay =&amp;gt; 0,&lt;br /&gt;
	 *      KernelCacheType =&amp;gt; 'Release',&lt;br /&gt;
	 *      UpdateBaseband =&amp;gt; true,&lt;br /&gt;
	 *      DFUFileType =&amp;gt; 'RELEASE',&lt;br /&gt;
	 *      SystemImageType =&amp;gt; 'User',&lt;br /&gt;
	 *      CreateFilesystemPartitions =&amp;gt; true,&lt;br /&gt;
	 *      FlashNOR =&amp;gt; true,&lt;br /&gt;
	 *      RestoreBootArgs =&amp;gt; 'rd=md0 nand-enable-reformat=1 -progress'&lt;br /&gt;
	 *      BootImageType =&amp;gt; 'User'&lt;br /&gt;
	 *  }&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      the option dictionary   if successful&lt;br /&gt;
	 *      NULL                    if out of memory&lt;br /&gt;
	 */ &lt;br /&gt;
	__DLLIMPORT CFMutableDictionaryRef AMRestoreCreateDefaultOptions(CFAllocatorRef allocator);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRecoveryModeRestore(struct am_recovery_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRestoreModeRestore(struct am_restore_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT struct am_restore_device *AMRestoreModeDeviceCreate(unsigned int unknown0,&lt;br /&gt;
				unsigned int connection_id, unsigned int unknown1);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreCreatePathsForBundle(CFStringRef restore_bundle_path,&lt;br /&gt;
				CFStringRef kernel_cache_type, CFStringRef boot_image_type, unsigned int&lt;br /&gt;
				unknown0, CFStringRef *firmware_dir_path, CFStringRef *&lt;br /&gt;
				kernelcache_restore_path, unsigned int unknown1, CFStringRef *&lt;br /&gt;
				ramdisk_path);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreModeDeviceReboot(struct am_restore_device *rdev);	// Added by JB 30.07.2008&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceEnterRecovery(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDisconnect(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* to use this, start the service &amp;quot;com.apple.mobile.notification_proxy&amp;quot;, handle will be the socket to use */&lt;br /&gt;
	typedef void (*NOTIFY_CALLBACK)(CFSTR notification, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDPostNotification(SOCKET socket, CFStringRef  notification, CFStringRef userinfo);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDObserveNotification(SOCKET socket, CFSTR notification);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDListenForNotifications(SOCKET socket, NOTIFY_CALLBACK cb, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDShutdownNotificationProxy(SOCKET socket);&lt;br /&gt;
	&lt;br /&gt;
	/*edits by geohot*/&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDeactivate(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceActivate(struct am_device *device, CFDictionaryRef dict);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceRemoveValue(struct am_device *device, unsigned int, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Pass in a usbmux_listener_1 structure and a usbmux_listener_2 structure&lt;br /&gt;
	 *  pointer, which will be filled with the resulting usbmux_listener_2.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if completed successfully&lt;br /&gt;
	 *      MDERR_USBMUX_ARG_NULL   if one of the arguments was NULL&lt;br /&gt;
	 *      MDERR_USBMUX_FAILED     if the listener was not created successfully&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerCreate(struct usbmux_listener_1 *esi_fp8, struct&lt;br /&gt;
										usbmux_listener_2 **eax_fp12);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerHandleData(void *);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Private routines - here be dragons&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/* AMRestorePerformRestoreModeRestore() calls this function with a dictionary&lt;br /&gt;
	 * in order to perform certain special restore operations&lt;br /&gt;
	 * (RESTORED_OPERATION_*). It is thought that this function might enable&lt;br /&gt;
	 * significant access to the phone. */&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef unsigned int (*t_performOperation)(struct am_restore_device *rdev,&lt;br /&gt;
	 CFDictionaryRef op) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_performOperation _performOperation = (t_performOperation)0x3c39fa4b;&lt;br /&gt;
	 */ &lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef int (*t_socketForPort)(struct am_restore_device *rdev, unsigned int port)&lt;br /&gt;
	 __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_socketForPort _socketForPort = (t_socketForPort)(void *)0x3c39f36c;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef void (*t_restored_send_message)(int port, CFDictionaryRef msg);&lt;br /&gt;
	 t_restored_send_message _restored_send_message = (t_restored_send_message)0x3c3a4e40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef CFDictionaryRef (*t_restored_receive_message)(int port);&lt;br /&gt;
	 t_restored_receive_message _restored_receive_message = (t_restored_receive_message)0x3c3a4d40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendControlPacket)(struct am_recovery_device *rdev, unsigned&lt;br /&gt;
	 int msg1, unsigned int msg2, unsigned int unknown0, unsigned int *unknown1,&lt;br /&gt;
	 unsigned char *unknown2) __attribute__ ((regparm(3)));&lt;br /&gt;
	 t_sendControlPacket _sendControlPacket = (t_sendControlPacket)0x3c3a3da3;;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendCommandToDevice)(struct am_recovery_device *rdev,&lt;br /&gt;
	 CFStringRef cmd) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_sendCommandToDevice _sendCommandToDevice = (t_sendCommandToDevice)0x3c3a3e3b;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceReadPipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int read_pipe, unsigned char *data, unsigned int *len);&lt;br /&gt;
	 t_AMRUSBInterfaceReadPipe _AMRUSBInterfaceReadPipe = (t_AMRUSBInterfaceReadPipe)0x3c3a27e8;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceWritePipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int write_pipe, void *data, unsigned int len);&lt;br /&gt;
	 t_AMRUSBInterfaceWritePipe _AMRUSBInterfaceWritePipe = (t_AMRUSBInterfaceWritePipe)0x3c3a27cb;&lt;br /&gt;
	 */&lt;br /&gt;
	&lt;br /&gt;
	int performOperation(am_restore_device *rdev, CFMutableDictionaryRef message);&lt;br /&gt;
	int socketForPort(am_restore_device *rdev, unsigned int portnum);&lt;br /&gt;
	int sendCommandToDevice(am_recovery_device *rdev, CFStringRef cfs, int block);&lt;br /&gt;
	int sendFileToDevice(am_recovery_device *rdev, CFStringRef filename); &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
}&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
/* -*- mode:c; indent-tabs-mode:nil; c-basic-offset:2; tab-width:2; */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===AFC Connection===&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
===Locking the Device for Sync===&lt;br /&gt;
When iTunes sends a new song to the device, the device shows a &amp;quot;Sync in progress&amp;quot; screen and when complete, the Music app on the device re-reads the iTunesDB file so it picks up the new song.&lt;br /&gt;
&lt;br /&gt;
To get this behaviour, first start the notification service:&lt;br /&gt;
&amp;lt;pre&amp;gt;SOCKET socket;&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we post a notificaton message to signal that we are going to start a sync:&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncWillStart&amp;quot;), NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we open the itunes lock file:&lt;br /&gt;
&amp;lt;pre&amp;gt;afc_file_ref lockref;&lt;br /&gt;
AFCFileRefOpen(conn, &amp;quot;/com.apple.itunes.lock_sync&amp;quot;, 2, &amp;amp;lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now post a notification to say we are going to lock this file, and try and lock it.&lt;br /&gt;
If the AFCFileRefLock call fails, pause and repeat.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncLockRequest&amp;quot;), NULL);&lt;br /&gt;
mach_error_t error = AFCFileRefLock(conn, lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the file is successfully locked, post another notification, and stop the notification service.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket,CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidStart&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the sync can proceed, so copy your files across and make the changes to the iTunesDB.&lt;br /&gt;
&lt;br /&gt;
To release the lock, start the notification system again, unlock and close the lock file, and send a sync finished notification message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;AFCFileRefUnlock(conn, lockref);&lt;br /&gt;
AFCFileRefClose(conn, lockref);&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&lt;br /&gt;
AMDPostNotification(socket, &amp;amp;CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidFinish&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To handle &amp;quot;Slide to Cancel&amp;quot; and terminate sync when user slides cancel switch, use AMDObserveNotification to subscribe notifications about “com.apple.itunes-client.syncCancelRequest”. Then start listening for notifications (AMDListenForNotifications) until you get “AMDNotificationFaceplant”.&lt;br /&gt;
When notification got, you should unlock and close lock file handle (don’t sure if you need to post “syncDidFinish” to proxy, seems it doesn’t matter) and terminate sync gracefully.&lt;br /&gt;
The same notification is also got when you unplug your device, so you should always be ready for errors.&lt;br /&gt;
&lt;br /&gt;
NOTE: You may find that starting the notification_proxy service once and once only at the start of your app and using the same socket in calls to AMDPostNotification works better. iTunes opens and closes the notification_proxy regularly, but it appears to be a bit flakey when you open/close it all the time.&lt;br /&gt;
&lt;br /&gt;
===Private Functions===&lt;br /&gt;
&lt;br /&gt;
====How to find address of privates functions in iTunesMobileDevice.dll or MobileDevice.framework====&lt;br /&gt;
&lt;br /&gt;
In order to obtain the address of a usable private function in MobileDevice, you will have to be able to understand x86-64 assembly to reverse engineer it. A private function will not have its name exported in the mach-o symbol table, so in a debugger, like GDB, it will show up as part of another function. However, you will know that it is a separate function as a new stack frame is set up.&lt;br /&gt;
&lt;br /&gt;
====Private Function Address List====&lt;br /&gt;
&lt;br /&gt;
=====OSX.6 - iTunes 9.0.2(25)=====&lt;br /&gt;
&amp;lt;pre&amp;gt;unsigned int sendCommandToiBoot(struct am_recovery_device *rdev, CFStringRef command, int u);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Address is obtainable by adding 868(0x364) to the address of AMRecoveryDeviceGetProductType(), a public symbol that you can obtain via nlist() or dlsym(). &lt;br /&gt;
Address: 0x245ea&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Libraries Implementations===&lt;br /&gt;
&lt;br /&gt;
* [http://gojohnnyboi.com/source/afcinstall.cpp afcinstall (command line, os x file install via afc)]&lt;br /&gt;
* [http://code.google.com/p/iphuc/ iPhuc (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/iphucwin32/ iPhuc Win32 (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/manzana/ manzana (.Net Library)]&lt;br /&gt;
* [http://code.google.com/p/independence/source/browse/trunk/libPhoneInteraction/ libPhoneInteraction (C Library)]&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5659</id>
		<title>MobileDevice Library</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=MobileDevice_Library&amp;diff=5659"/>
		<updated>2009-11-19T01:02:56Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MobileDevice Library is used by [[iTunes]] to transfer data between iPhone and computer over the USB connection.&lt;br /&gt;
&lt;br /&gt;
===PC Windows : iTunesMobileDevice.dll===&lt;br /&gt;
&lt;br /&gt;
* Location : Location is stored in '''iTunesMobileDeviceDLL''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Mobile Device Support\Shared''' key. Usually - C:\Program Files\Common Files\Apple\Mobile Device Support\bin\iTunesMobileDevice.dll.&lt;br /&gt;
&lt;br /&gt;
* Supporting CoreFoundation.dll (used for CFStringRef, CFPropertyListRef management) is located in the same dir (when using iTunes prior 9.0). &lt;br /&gt;
&lt;br /&gt;
* For iTunes 9.0 location of CoreFoundation.dll is stored in '''InstallDir''' registry value under '''HKLM\SOFTWARE\Apple Inc.\Apple Application Support''' key, usually C:\Program Files\Common Files\Apple\Apple Application Support\. CoreFoundation.dll from Mobile Device Support\bin should not be used.&lt;br /&gt;
&lt;br /&gt;
===Mac OSX : MobileDevice.framework===&lt;br /&gt;
&lt;br /&gt;
* Location : /System/Library/PrivateFrameworks/MobileDevice.framework&lt;br /&gt;
* Export command : &amp;quot;nm /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===MobileDevice Header (mobiledevice.h)===&lt;br /&gt;
&lt;br /&gt;
Reverse engineered C header for MobileDevice Library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* ----------------------------------------------------------------------------&lt;br /&gt;
 *   MobileDevice.h - interface to MobileDevice.framework &lt;br /&gt;
 * ------------------------------------------------------------------------- */&lt;br /&gt;
#pragma once&lt;br /&gt;
&lt;br /&gt;
#ifndef MOBILEDEVICE_H&lt;br /&gt;
#define MOBILEDEVICE_H&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
extern &amp;quot;C&amp;quot; {&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
#ifndef __GCC__&lt;br /&gt;
#pragma pack&lt;br /&gt;
#define __PACK&lt;br /&gt;
#else&lt;br /&gt;
#define __PACK __attribute__((__packed__))&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#if defined(WIN32)&lt;br /&gt;
#define __DLLIMPORT [DllImport(&amp;quot;iTunesMobileDevice.dll&amp;quot;)]&lt;br /&gt;
	using namespace System::Runtime::InteropServices;&lt;br /&gt;
#include &amp;lt;CoreFoundation.h&amp;gt;&lt;br /&gt;
	typedef unsigned int mach_error_t;&lt;br /&gt;
#elif defined(__APPLE__)&lt;br /&gt;
#define __DLLIMPORT&lt;br /&gt;
#include &amp;lt;CoreFoundation/CoreFoundation.h&amp;gt;&lt;br /&gt;
#include &amp;lt;mach/error.h&amp;gt;&lt;br /&gt;
#endif	&lt;br /&gt;
	&lt;br /&gt;
	/* Error codes */&lt;br /&gt;
#define MDERR_APPLE_MOBILE  (err_system(0x3a))&lt;br /&gt;
#define MDERR_IPHONE        (err_sub(0))&lt;br /&gt;
	&lt;br /&gt;
	/* Apple Mobile (AM*) errors */&lt;br /&gt;
#define MDERR_OK                ERR_SUCCESS&lt;br /&gt;
#define MDERR_SYSCALL           (ERR_MOBILE_DEVICE | 0x01)&lt;br /&gt;
#define MDERR_OUT_OF_MEMORY     (ERR_MOBILE_DEVICE | 0x03)&lt;br /&gt;
#define MDERR_QUERY_FAILED      (ERR_MOBILE_DEVICE | 0x04) &lt;br /&gt;
#define MDERR_INVALID_ARGUMENT  (ERR_MOBILE_DEVICE | 0x0b)&lt;br /&gt;
#define MDERR_DICT_NOT_LOADED   (ERR_MOBILE_DEVICE | 0x25)&lt;br /&gt;
	&lt;br /&gt;
	/* Apple File Connection (AFC*) errors */&lt;br /&gt;
#define MDERR_AFC_OUT_OF_MEMORY 0x03&lt;br /&gt;
	&lt;br /&gt;
	/* USBMux errors */&lt;br /&gt;
#define MDERR_USBMUX_ARG_NULL   0x16&lt;br /&gt;
#define MDERR_USBMUX_FAILED     0xffffffff&lt;br /&gt;
	&lt;br /&gt;
	/* Messages passed to device notification callbacks: passed as part of&lt;br /&gt;
	 * am_device_notification_callback_info. */&lt;br /&gt;
#define ADNCI_MSG_CONNECTED     1&lt;br /&gt;
#define ADNCI_MSG_DISCONNECTED  2&lt;br /&gt;
#define ADNCI_MSG_UNSUBSCRIBED  3&lt;br /&gt;
	&lt;br /&gt;
#define AMD_IPHONE_PRODUCT_ID   0x1290&lt;br /&gt;
	//#define AMD_IPHONE_SERIAL       &amp;quot;&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
	/* Services, found in /System/Library/Lockdown/Services.plist */&lt;br /&gt;
#define AMSVC_AFC                   CFSTR(&amp;quot;com.apple.afc&amp;quot;)&lt;br /&gt;
#define AMSVC_BACKUP                CFSTR(&amp;quot;com.apple.mobilebackup&amp;quot;)&lt;br /&gt;
#define AMSVC_CRASH_REPORT_COPY     CFSTR(&amp;quot;com.apple.crashreportcopy&amp;quot;)&lt;br /&gt;
#define AMSVC_DEBUG_IMAGE_MOUNT     CFSTR(&amp;quot;com.apple.mobile.debug_image_mount&amp;quot;)&lt;br /&gt;
#define AMSVC_NOTIFICATION_PROXY    CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;)&lt;br /&gt;
#define AMSVC_PURPLE_TEST           CFSTR(&amp;quot;com.apple.purpletestr&amp;quot;)&lt;br /&gt;
#define AMSVC_SOFTWARE_UPDATE       CFSTR(&amp;quot;com.apple.mobile.software_update&amp;quot;)&lt;br /&gt;
#define AMSVC_SYNC                  CFSTR(&amp;quot;com.apple.mobilesync&amp;quot;)&lt;br /&gt;
#define AMSVC_SCREENSHOT            CFSTR(&amp;quot;com.apple.screenshotr&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSLOG_RELAY          CFSTR(&amp;quot;com.apple.syslog_relay&amp;quot;)&lt;br /&gt;
#define AMSVC_SYSTEM_PROFILER       CFSTR(&amp;quot;com.apple.mobile.system_profiler&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned int afc_error_t;&lt;br /&gt;
	typedef unsigned int usbmux_error_t;&lt;br /&gt;
	&lt;br /&gt;
	struct am_recovery_device;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification_callback_info {&lt;br /&gt;
		struct am_device *dev;  /* 0    device */ &lt;br /&gt;
		unsigned int msg;       /* 4    one of ADNCI_MSG_* */&lt;br /&gt;
                struct am_device_notification* subscription; &lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
	&lt;br /&gt;
	/* This is a CoreFoundation object of class AMRecoveryModeDevice. */&lt;br /&gt;
	struct am_recovery_device {&lt;br /&gt;
		unsigned char unknown0[8];                          /* 0 */&lt;br /&gt;
		am_restore_device_notification_callback callback;   /* 8 */&lt;br /&gt;
		void *user_info;                                    /* 12 */&lt;br /&gt;
		unsigned char unknown1[12];                         /* 16 */&lt;br /&gt;
		unsigned int readwrite_pipe;                        /* 28 */&lt;br /&gt;
		unsigned char read_pipe;                            /* 32 */&lt;br /&gt;
		unsigned char write_ctrl_pipe;                      /* 33 */&lt;br /&gt;
		unsigned char read_unknown_pipe;                    /* 34 */&lt;br /&gt;
		unsigned char write_file_pipe;                      /* 35 */&lt;br /&gt;
		unsigned char write_input_pipe;                     /* 36 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* A CoreFoundation object of class AMRestoreModeDevice. */&lt;br /&gt;
	struct am_restore_device {&lt;br /&gt;
		unsigned char unknown[32];&lt;br /&gt;
		int port;&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device notification callback function. */&lt;br /&gt;
	typedef void(*am_device_notification_callback)(struct am_device_notification_callback_info *, int cookie);&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the _AMDDeviceAttached function.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void *amd_device_attached_callback;&lt;br /&gt;
	&lt;br /&gt;
	/* The type of the device restore notification callback functions.&lt;br /&gt;
	 * TODO: change to correct type. */&lt;br /&gt;
	typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *);&lt;br /&gt;
&lt;br /&gt;
	/* Structure that contains internal data used by AMDevice... functions. Never try &lt;br /&gt;
         * to access its members directly! Use AMDeviceCopyDeviceIdentifier, &lt;br /&gt;
         * AMDeviceGetConnectionID, AMDeviceRetain, AMDeviceRelease instead. */&lt;br /&gt;
	struct am_device {&lt;br /&gt;
		unsigned char unknown0[16]; /* 0 - zero */&lt;br /&gt;
		unsigned int device_id;     /* 16 */&lt;br /&gt;
		unsigned int product_id;    /* 20 - set to AMD_IPHONE_PRODUCT_ID */&lt;br /&gt;
		char *serial;               /* 24 - set to UDID, Unique Device Identifier */&lt;br /&gt;
		unsigned int unknown1;      /* 28 */&lt;br /&gt;
		unsigned int unknown2;      /* 32 - reference counter, increased by AMDeviceRetain, decreased by AMDeviceRelease*/&lt;br /&gt;
		unsigned int lockdown_conn; /* 36 */&lt;br /&gt;
		unsigned char unknown3[8];  /* 40 */&lt;br /&gt;
#if (__ITUNES_VER &amp;gt; 740)&lt;br /&gt;
		unsigned int unknown4;      /* 48 - used to store CriticalSection Handle*/&lt;br /&gt;
#endif&lt;br /&gt;
#if (__ITUNES_VER &amp;gt;= 800)&lt;br /&gt;
		unsigned char unknown5[24];  /* 52 */&lt;br /&gt;
#endif&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_device_notification {&lt;br /&gt;
		unsigned int unknown0;                      /* 0 */&lt;br /&gt;
		unsigned int unknown1;                      /* 4 */&lt;br /&gt;
		unsigned int unknown2;                      /* 8 */&lt;br /&gt;
		am_device_notification_callback callback;   /* 12 */ &lt;br /&gt;
		unsigned int cookie;                      /* 16 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct afc_connection {&lt;br /&gt;
		unsigned int handle;            /* 0 */&lt;br /&gt;
		unsigned int unknown0;          /* 4 */&lt;br /&gt;
		unsigned char unknown1;         /* 8 */&lt;br /&gt;
		unsigned char padding[3];       /* 9 */&lt;br /&gt;
		unsigned int unknown2;          /* 12 */&lt;br /&gt;
		unsigned int unknown3;          /* 16 */&lt;br /&gt;
		unsigned int unknown4;          /* 20 */&lt;br /&gt;
		unsigned int fs_block_size;     /* 24 */&lt;br /&gt;
		unsigned int sock_block_size;   /* 28: always 0x3c */&lt;br /&gt;
		unsigned int io_timeout;        /* 32: from AFCConnectionOpen, usu. 0 */&lt;br /&gt;
		void *afc_lock;                 /* 36 */&lt;br /&gt;
		unsigned int context;           /* 40 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
	struct afc_device_info {&lt;br /&gt;
		unsigned char unknown[12];  /* 0 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_directory {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
&lt;br /&gt;
	struct afc_dictionary {&lt;br /&gt;
		unsigned char unknown[0];   /* size unknown */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	typedef unsigned long long afc_file_ref;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_1 {                  /* offset   value in iTunes */&lt;br /&gt;
		unsigned int unknown0;                  /* 0        1 */&lt;br /&gt;
		unsigned char *unknown1;                /* 4        ptr, maybe device? */&lt;br /&gt;
		amd_device_attached_callback callback;  /* 8        _AMDDeviceAttached */&lt;br /&gt;
		unsigned int unknown3;                  /* 12 */&lt;br /&gt;
		unsigned int unknown4;                  /* 16 */&lt;br /&gt;
		unsigned int unknown5;                  /* 20 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct usbmux_listener_2 {&lt;br /&gt;
		unsigned char unknown0[4144];&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	struct am_bootloader_control_packet {&lt;br /&gt;
		unsigned char opcode;       /* 0 */&lt;br /&gt;
		unsigned char length;       /* 1 */&lt;br /&gt;
		unsigned char magic[2];     /* 2: 0x34, 0x12 */&lt;br /&gt;
		unsigned char payload[0];   /* 4 */&lt;br /&gt;
	} __PACK;&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Registers a notification with the current run loop. The callback gets&lt;br /&gt;
	 *  copied into the notification struct, as well as being registered with the&lt;br /&gt;
	 *  current run loop. Cookie gets copied into cookie in the same.&lt;br /&gt;
	 *  (Cookie is a user info parameter that gets passed as an arg to&lt;br /&gt;
	 *  the callback) unused0 and unused1 are both 0 when iTunes calls this.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Never try to acces directly or copy contents of dev and subscription fields &lt;br /&gt;
	 *  in am_device_notification_callback_info. Treat them as abstract handles. &lt;br /&gt;
	 *  When done with connection use AMDeviceRelease to free resources allocated for am_device.&lt;br /&gt;
	 *  &lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK            if successful&lt;br /&gt;
	 *      MDERR_SYSCALL       if CFRunLoopAddSource() failed&lt;br /&gt;
	 *      MDERR_OUT_OF_MEMORY if we ran out of memory&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationSubscribe(am_device_notification_callback callback, &lt;br /&gt;
								unsigned int unused0, unsigned int unused1, &lt;br /&gt;
								unsigned int cookie, &lt;br /&gt;
								struct am_device_notification **subscription);&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
        /* Unregisters notifications. Buggy (iTunes 8.2): if you subscribe, unsubscribe and subscribe again, arriving &lt;br /&gt;
           notifications will contain cookie and subscription from 1st call to subscribe, not the 2nd one. iTunes &lt;br /&gt;
           calls this function only once on exit.&lt;br /&gt;
        */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceNotificationUnsubscribe(am_device_notification* subscription);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns device_id field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMDeviceGetConnectionID(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Returns serial field of am_device structure&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyDeviceIdentifier(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/*  Connects to the iPhone. Pass in the am_device structure that the&lt;br /&gt;
	 *  notification callback will give to you.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successfully connected&lt;br /&gt;
	 *      MDERR_SYSCALL           if setsockopt() failed&lt;br /&gt;
	 *      MDERR_QUERY_FAILED      if the daemon query failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if USBMuxConnectByPort returned 0xffffffff&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceConnect(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Calls PairingRecordPath() on the given device, than tests whether the path&lt;br /&gt;
	 *  which that function returns exists. During the initial connect, the path&lt;br /&gt;
	 *  returned by that function is '/', and so this returns 1.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      0   if the path did not exist&lt;br /&gt;
	 *      1   if it did&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceIsPaired(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDevicePair(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  iTunes calls this function immediately after testing whether the device is&lt;br /&gt;
	 *  paired. It creates a pairing file and establishes a Lockdown connection.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the supplied device is null&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceValidatePairing(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/*  Creates a Lockdown session and adjusts the device structure appropriately&lt;br /&gt;
	 *  to indicate that the session has been started. iTunes calls this function&lt;br /&gt;
	 *  after validating pairing.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 *      MDERR_DICT_NOT_LOADED   if the load_dict() call failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartSession(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* Reads various device settings. One of domain or cfstring arguments should be NULL.&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for cfstring:&lt;br /&gt;
	 * ActivationState&lt;br /&gt;
	 * ActivationStateAcknowledged&lt;br /&gt;
	 * BasebandBootloaderVersion&lt;br /&gt;
	 * BasebandVersion&lt;br /&gt;
	 * BluetoothAddress&lt;br /&gt;
	 * BuildVersion&lt;br /&gt;
	 * DeviceCertificate&lt;br /&gt;
	 * DeviceClass&lt;br /&gt;
	 * DeviceName&lt;br /&gt;
	 * DevicePublicKey&lt;br /&gt;
	 * FirmwareVersion&lt;br /&gt;
	 * HostAttached&lt;br /&gt;
	 * IntegratedCircuitCardIdentity&lt;br /&gt;
	 * InternationalMobileEquipmentIdentity&lt;br /&gt;
	 * InternationalMobileSubscriberIdentity&lt;br /&gt;
	 * ModelNumber&lt;br /&gt;
	 * PhoneNumber&lt;br /&gt;
	 * ProductType&lt;br /&gt;
	 * ProductVersion&lt;br /&gt;
	 * ProtocolVersion&lt;br /&gt;
	 * RegionInfo&lt;br /&gt;
	 * SBLockdownEverRegisteredKey&lt;br /&gt;
	 * SIMStatus&lt;br /&gt;
	 * SerialNumber&lt;br /&gt;
	 * SomebodySetTimeZone&lt;br /&gt;
	 * TimeIntervalSince1970&lt;br /&gt;
	 * TimeZone&lt;br /&gt;
	 * TimeZoneOffsetFromUTC&lt;br /&gt;
	 * TrustedHostAttached&lt;br /&gt;
	 * UniqueDeviceID&lt;br /&gt;
	 * Uses24HourClock&lt;br /&gt;
	 * WiFiAddress&lt;br /&gt;
	 * iTunesHasConnected&lt;br /&gt;
         *&lt;br /&gt;
         * Possible values for domain:&lt;br /&gt;
         * com.apple.mobile.battery&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT CFStringRef AMDeviceCopyValue(struct am_device *device, CFStringRef domain, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* Starts a service and returns a socket file descriptor that can be used in order to further&lt;br /&gt;
	 * access the service. You should stop the session and disconnect before using&lt;br /&gt;
	 * the service. iTunes calls this function after starting a session. It starts &lt;br /&gt;
	 * the service and the SSL connection. service_name should be one of the AMSVC_*&lt;br /&gt;
	 * constants.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_SYSCALL           if the setsockopt() call failed&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStartService(struct am_device *device, CFStringRef &lt;br /&gt;
									  service_name, int *socket_fd);&lt;br /&gt;
	&lt;br /&gt;
	/* Stops a session. You should do this before accessing services.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_INVALID_ARGUMENT  if the Lockdown conn has not been established&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceStopSession(struct am_device *device);&lt;br /&gt;
	&lt;br /&gt;
	/* Decrements reference counter and, if nothing left, releases resources hold &lt;br /&gt;
	 * by connection, invalidates  pointer to device&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRelease(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Increments reference counter&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT void AMDeviceRetain(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
	/* Opens an Apple File Connection. You must start the appropriate service&lt;br /&gt;
	 * first with AMDeviceStartService(). In iTunes, io_timeout is 0.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 *      MDERR_AFC_OUT_OF_MEMORY if malloc() failed&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionOpen(int socket_fd, unsigned int io_timeout,&lt;br /&gt;
								  struct afc_connection **conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Pass in a pointer to an afc_dictionary structure. It will be filled. You can&lt;br /&gt;
	 * iterate it using AFCKeyValueRead. When done use AFCKeyValueClose. Possible keys:&lt;br /&gt;
	 * FSFreeBytes - free bytes on system device for afc2, user device for afc&lt;br /&gt;
	 * FSBlockSize - filesystem block size&lt;br /&gt;
	 * FSTotalBytes - size of device&lt;br /&gt;
	 * Model - iPhone1,1 etc.&lt;br /&gt;
&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDeviceInfoOpen(struct afc_connection *conn, struct&lt;br /&gt;
								  afc_dictionary **info);&lt;br /&gt;
	&lt;br /&gt;
	/* Turns debug mode on if the environment variable AFCDEBUG is set to a numeric&lt;br /&gt;
	 * value, or if the file '/AFCDEBUG' is present and contains a value. */&lt;br /&gt;
#if defined(__APPLE__)&lt;br /&gt;
	void AFCPlatformInit();&lt;br /&gt;
#endif&lt;br /&gt;
	&lt;br /&gt;
	/* Opens a directory on the iPhone. Pass in a pointer in dir to be filled in.&lt;br /&gt;
	 * Note that this normally only accesses the iTunes sandbox/partition as the&lt;br /&gt;
	 * root, which is /var/root/Media. Pathnames are specified with '/' delimiters&lt;br /&gt;
	 * as in Unix style. Use UTF-8 to specify non-ASCII symbols in path.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								 afc_directory **dir);&lt;br /&gt;
	&lt;br /&gt;
	/* Acquires the next entry in a directory previously opened with&lt;br /&gt;
	 * AFCDirectoryOpen(). When dirent is filled with a NULL value, then the end&lt;br /&gt;
	 * of the directory has been reached. '.' and '..' will be returned as the&lt;br /&gt;
	 * first two entries in each directory except the root; you may want to skip&lt;br /&gt;
	 * over them.&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      MDERR_OK                if successful, even if no entries remain&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryRead(struct afc_connection *conn, struct afc_directory *dir,&lt;br /&gt;
								 char **dirent);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryClose(afc_connection *conn, struct afc_directory *dir);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCDirectoryCreate(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRemovePath(afc_connection *conn, char *dirname);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCRenamePath(afc_connection *conn, char *oldpath, char *newpath);&lt;br /&gt;
&lt;br /&gt;
	/* Creates symbolic or hard link&lt;br /&gt;
         * linktype - int64: 1 means hard link, 2 - soft (symbolic) link&lt;br /&gt;
         * target - absolute or relative path to link target&lt;br /&gt;
         * linkname - absolute path where to create new link&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCLinkPath(struct afc_connection *conn, long long int linktype, const char *target, &lt;br /&gt;
								                              const char *linkname);&lt;br /&gt;
&lt;br /&gt;
	/* Opens file for reading or writing without locking it in any way. afc_file_ref should not be shared between threads - &lt;br /&gt;
         * opening file in one thread and closing it in another will lead to possible crash.&lt;br /&gt;
	 * path - UTF-8 encoded absolute path to file&lt;br /&gt;
	 * mode 2 = read, mode 3 = write; unknown = 0 &lt;br /&gt;
	 * ref - receives file handle&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefOpen(struct afc_connection *conn, char *path, unsigned&lt;br /&gt;
							   long long int mode, afc_file_ref *ref);&lt;br /&gt;
	/* Reads specified amount (len) of bytes from file into buf. Puts actual count of read bytes into len on return&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefRead(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   void *buf, unsigned int *len);&lt;br /&gt;
	/* Writes specified amount (len) of bytes from buf into file.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefWrite(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
								void *buf, unsigned int len);&lt;br /&gt;
	/* Moves the file pointer to a specified location.&lt;br /&gt;
	 * offset - Number of bytes from origin (int64)&lt;br /&gt;
	 * origin - 0 = from beginning, 1 = from current position, 2 = from end&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefSeek(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long offset, int origin, int unused);&lt;br /&gt;
&lt;br /&gt;
	/* Gets the current position of a file pointer into offset argument.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefTell(struct afc_connection *conn, afc_file_ref ref,&lt;br /&gt;
							   unsigned long long* offset);&lt;br /&gt;
&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefLock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefUnlock(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileRefClose(struct afc_connection *conn, afc_file_ref ref);&lt;br /&gt;
&lt;br /&gt;
	/* Opens dictionary describing specified file or directory (iTunes below 8.2 allowed using AFCGetFileInfo&lt;br /&gt;
	   to get the same information)&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCFileInfoOpen(struct afc_connection *conn, char *path, struct&lt;br /&gt;
								afc_dictionary **info);&lt;br /&gt;
&lt;br /&gt;
	/* Reads next entry from dictionary. When last entry is read, function returns NULL in key argument&lt;br /&gt;
	   Possible keys:&lt;br /&gt;
	     &amp;quot;st_size&amp;quot;:     val - size in bytes&lt;br /&gt;
	     &amp;quot;st_blocks&amp;quot;:   val - size in blocks&lt;br /&gt;
	     &amp;quot;st_nlink&amp;quot;:    val - number of hardlinks&lt;br /&gt;
	     &amp;quot;st_ifmt&amp;quot;:     val - &amp;quot;S_IFDIR&amp;quot; for folders&lt;br /&gt;
	                        &amp;quot;S_IFLNK&amp;quot; for symlinks&lt;br /&gt;
	     &amp;quot;LinkTarget&amp;quot;:  val - path to symlink target&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueRead(struct afc_dictionary *dict, char **key, char **&lt;br /&gt;
								val);&lt;br /&gt;
	/* Closes dictionary&lt;br /&gt;
	*/&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCKeyValueClose(struct afc_dictionary *dict);&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the context field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetContext(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the fs_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetFSBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the io_timeout field of the given AFC connection. In iTunes this is&lt;br /&gt;
	 * 0. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetIOTimeout(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Returns the sock_block_size field of the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT unsigned int AFCConnectionGetSocketBlockSize(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Closes the given AFC connection. */&lt;br /&gt;
	__DLLIMPORT afc_error_t AFCConnectionClose(struct afc_connection *conn);&lt;br /&gt;
	&lt;br /&gt;
	/* Registers for device notifications related to the restore process. unknown0&lt;br /&gt;
	 * is zero when iTunes calls this. In iTunes,&lt;br /&gt;
	 * the callbacks are located at:&lt;br /&gt;
	 *      1: $3ac68e-$3ac6b1, calls $3ac542(unknown1, arg, 0)&lt;br /&gt;
	 *      2: $3ac66a-$3ac68d, calls $3ac542(unknown1, 0, arg)&lt;br /&gt;
	 *      3: $3ac762-$3ac785, calls $3ac6b2(unknown1, arg, 0)&lt;br /&gt;
	 *      4: $3ac73e-$3ac761, calls $3ac6b2(unknown1, 0, arg)&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreRegisterForDeviceNotifications(&lt;br /&gt;
				am_restore_device_notification_callback dfu_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_connect_callback,&lt;br /&gt;
				am_restore_device_notification_callback dfu_disconnect_callback,&lt;br /&gt;
				am_restore_device_notification_callback recovery_disconnect_callback,&lt;br /&gt;
				unsigned int unknown0,&lt;br /&gt;
				void *user_info);&lt;br /&gt;
	&lt;br /&gt;
	/* Causes the restore functions to spit out (unhelpful) progress messages to&lt;br /&gt;
	 * the file specified by the given path. iTunes always calls this right before&lt;br /&gt;
	 * restoring with a path of&lt;br /&gt;
	 * &amp;quot;$HOME/Library/Logs/iPhone Updater Logs/iPhoneUpdater X.log&amp;quot;, where X is an&lt;br /&gt;
	 * unused number.&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreEnableFileLogging(char *path);&lt;br /&gt;
	&lt;br /&gt;
	/* Initializes a new option dictionary to default values. Pass the constant&lt;br /&gt;
	 * kCFAllocatorDefault as the allocator. The option dictionary looks as&lt;br /&gt;
	 * follows:&lt;br /&gt;
	 * {&lt;br /&gt;
	 *      NORImageType =&amp;gt; 'production',&lt;br /&gt;
	 *      AutoBootDelay =&amp;gt; 0,&lt;br /&gt;
	 *      KernelCacheType =&amp;gt; 'Release',&lt;br /&gt;
	 *      UpdateBaseband =&amp;gt; true,&lt;br /&gt;
	 *      DFUFileType =&amp;gt; 'RELEASE',&lt;br /&gt;
	 *      SystemImageType =&amp;gt; 'User',&lt;br /&gt;
	 *      CreateFilesystemPartitions =&amp;gt; true,&lt;br /&gt;
	 *      FlashNOR =&amp;gt; true,&lt;br /&gt;
	 *      RestoreBootArgs =&amp;gt; 'rd=md0 nand-enable-reformat=1 -progress'&lt;br /&gt;
	 *      BootImageType =&amp;gt; 'User'&lt;br /&gt;
	 *  }&lt;br /&gt;
	 *&lt;br /&gt;
	 * Returns:&lt;br /&gt;
	 *      the option dictionary   if successful&lt;br /&gt;
	 *      NULL                    if out of memory&lt;br /&gt;
	 */ &lt;br /&gt;
	__DLLIMPORT CFMutableDictionaryRef AMRestoreCreateDefaultOptions(CFAllocatorRef allocator);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented public routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRecoveryModeRestore(struct am_recovery_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestorePerformRestoreModeRestore(struct am_restore_device *&lt;br /&gt;
				rdev, CFDictionaryRef opts, void *callback, void *user_info);&lt;br /&gt;
	__DLLIMPORT struct am_restore_device *AMRestoreModeDeviceCreate(unsigned int unknown0,&lt;br /&gt;
				unsigned int connection_id, unsigned int unknown1);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreCreatePathsForBundle(CFStringRef restore_bundle_path,&lt;br /&gt;
				CFStringRef kernel_cache_type, CFStringRef boot_image_type, unsigned int&lt;br /&gt;
				unknown0, CFStringRef *firmware_dir_path, CFStringRef *&lt;br /&gt;
				kernelcache_restore_path, unsigned int unknown1, CFStringRef *&lt;br /&gt;
				ramdisk_path);&lt;br /&gt;
	__DLLIMPORT unsigned int AMRestoreModeDeviceReboot(struct am_restore_device *rdev);	// Added by JB 30.07.2008&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceEnterRecovery(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDisconnect(struct am_device *device);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/* to use this, start the service &amp;quot;com.apple.mobile.notification_proxy&amp;quot;, handle will be the socket to use */&lt;br /&gt;
	typedef void (*NOTIFY_CALLBACK)(CFSTR notification, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDPostNotification(SOCKET socket, CFStringRef  notification, CFStringRef userinfo);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDObserveNotification(SOCKET socket, CFSTR notification);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDListenForNotifications(SOCKET socket, NOTIFY_CALLBACK cb, USERDATA data);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDShutdownNotificationProxy(SOCKET socket);&lt;br /&gt;
	&lt;br /&gt;
	/*edits by geohot*/&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceDeactivate(struct am_device *device);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceActivate(struct am_device *device, CFDictionaryRef dict);&lt;br /&gt;
	__DLLIMPORT mach_error_t AMDeviceRemoveValue(struct am_device *device, unsigned int, CFStringRef cfstring);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/*  Pass in a usbmux_listener_1 structure and a usbmux_listener_2 structure&lt;br /&gt;
	 *  pointer, which will be filled with the resulting usbmux_listener_2.&lt;br /&gt;
	 *&lt;br /&gt;
	 *  Returns:&lt;br /&gt;
	 *      MDERR_OK                if completed successfully&lt;br /&gt;
	 *      MDERR_USBMUX_ARG_NULL   if one of the arguments was NULL&lt;br /&gt;
	 *      MDERR_USBMUX_FAILED     if the listener was not created successfully&lt;br /&gt;
	 */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerCreate(struct usbmux_listener_1 *esi_fp8, struct&lt;br /&gt;
										usbmux_listener_2 **eax_fp12);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented semi-private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	__DLLIMPORT usbmux_error_t USBMuxListenerHandleData(void *);&lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Private routines - here be dragons&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	/* AMRestorePerformRestoreModeRestore() calls this function with a dictionary&lt;br /&gt;
	 * in order to perform certain special restore operations&lt;br /&gt;
	 * (RESTORED_OPERATION_*). It is thought that this function might enable&lt;br /&gt;
	 * significant access to the phone. */&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef unsigned int (*t_performOperation)(struct am_restore_device *rdev,&lt;br /&gt;
	 CFDictionaryRef op) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_performOperation _performOperation = (t_performOperation)0x3c39fa4b;&lt;br /&gt;
	 */ &lt;br /&gt;
	&lt;br /&gt;
	/* ----------------------------------------------------------------------------&lt;br /&gt;
	 *   Less-documented private routines&lt;br /&gt;
	 * ------------------------------------------------------------------------- */&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	/*&lt;br /&gt;
	 typedef int (*t_socketForPort)(struct am_restore_device *rdev, unsigned int port)&lt;br /&gt;
	 __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_socketForPort _socketForPort = (t_socketForPort)(void *)0x3c39f36c;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef void (*t_restored_send_message)(int port, CFDictionaryRef msg);&lt;br /&gt;
	 t_restored_send_message _restored_send_message = (t_restored_send_message)0x3c3a4e40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef CFDictionaryRef (*t_restored_receive_message)(int port);&lt;br /&gt;
	 t_restored_receive_message _restored_receive_message = (t_restored_receive_message)0x3c3a4d40;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendControlPacket)(struct am_recovery_device *rdev, unsigned&lt;br /&gt;
	 int msg1, unsigned int msg2, unsigned int unknown0, unsigned int *unknown1,&lt;br /&gt;
	 unsigned char *unknown2) __attribute__ ((regparm(3)));&lt;br /&gt;
	 t_sendControlPacket _sendControlPacket = (t_sendControlPacket)0x3c3a3da3;;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_sendCommandToDevice)(struct am_recovery_device *rdev,&lt;br /&gt;
	 CFStringRef cmd) __attribute__ ((regparm(2)));&lt;br /&gt;
	 t_sendCommandToDevice _sendCommandToDevice = (t_sendCommandToDevice)0x3c3a3e3b;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceReadPipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int read_pipe, unsigned char *data, unsigned int *len);&lt;br /&gt;
	 t_AMRUSBInterfaceReadPipe _AMRUSBInterfaceReadPipe = (t_AMRUSBInterfaceReadPipe)0x3c3a27e8;&lt;br /&gt;
	 &lt;br /&gt;
	 typedef unsigned int (*t_AMRUSBInterfaceWritePipe)(unsigned int readwrite_pipe, unsigned&lt;br /&gt;
	 int write_pipe, void *data, unsigned int len);&lt;br /&gt;
	 t_AMRUSBInterfaceWritePipe _AMRUSBInterfaceWritePipe = (t_AMRUSBInterfaceWritePipe)0x3c3a27cb;&lt;br /&gt;
	 */&lt;br /&gt;
	&lt;br /&gt;
	int performOperation(am_restore_device *rdev, CFMutableDictionaryRef message);&lt;br /&gt;
	int socketForPort(am_restore_device *rdev, unsigned int portnum);&lt;br /&gt;
	int sendCommandToDevice(am_recovery_device *rdev, CFStringRef cfs, int block);&lt;br /&gt;
	int sendFileToDevice(am_recovery_device *rdev, CFStringRef filename); &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
#ifdef __cplusplus&lt;br /&gt;
}&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
/* -*- mode:c; indent-tabs-mode:nil; c-basic-offset:2; tab-width:2; */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===AFC Connection===&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
===Locking the Device for Sync===&lt;br /&gt;
When iTunes sends a new song to the device, the device shows a &amp;quot;Sync in progress&amp;quot; screen and when complete, the Music app on the device re-reads the iTunesDB file so it picks up the new song.&lt;br /&gt;
&lt;br /&gt;
To get this behaviour, first start the notification service:&lt;br /&gt;
&amp;lt;pre&amp;gt;SOCKET socket;&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we post a notificaton message to signal that we are going to start a sync:&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncWillStart&amp;quot;), NULL);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we open the itunes lock file:&lt;br /&gt;
&amp;lt;pre&amp;gt;afc_file_ref lockref;&lt;br /&gt;
AFCFileRefOpen(conn, &amp;quot;/com.apple.itunes.lock_sync&amp;quot;, 2, &amp;amp;lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now post a notification to say we are going to lock this file, and try and lock it.&lt;br /&gt;
If the AFCFileRefLock call fails, pause and repeat.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket, CFSTR(&amp;quot;com.apple.itunes-mobdev.syncLockRequest&amp;quot;), NULL);&lt;br /&gt;
mach_error_t error = AFCFileRefLock(conn, lockref);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the file is successfully locked, post another notification, and stop the notification service.&lt;br /&gt;
&amp;lt;pre&amp;gt;AMDPostNotification(socket,CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidStart&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the sync can proceed, so copy your files across and make the changes to the iTunesDB.&lt;br /&gt;
&lt;br /&gt;
To release the lock, start the notification system again, unlock and close the lock file, and send a sync finished notification message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;AFCFileRefUnlock(conn, lockref);&lt;br /&gt;
AFCFileRefClose(conn, lockref);&lt;br /&gt;
AMDeviceStartService(dev, CFSTR(&amp;quot;com.apple.mobile.notification_proxy&amp;quot;), &amp;amp;socket, NULL);&lt;br /&gt;
AMDPostNotification(socket, &amp;amp;CFSTR(&amp;quot;com.apple.itunes-mobdev.syncDidFinish&amp;quot;), NULL);&lt;br /&gt;
AMDShutdownNotificationProxy(socket);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To handle &amp;quot;Slide to Cancel&amp;quot; and terminate sync when user slides cancel switch, use AMDObserveNotification to subscribe notifications about “com.apple.itunes-client.syncCancelRequest”. Then start listening for notifications (AMDListenForNotifications) until you get “AMDNotificationFaceplant”.&lt;br /&gt;
When notification got, you should unlock and close lock file handle (don’t sure if you need to post “syncDidFinish” to proxy, seems it doesn’t matter) and terminate sync gracefully.&lt;br /&gt;
The same notification is also got when you unplug your device, so you should always be ready for errors.&lt;br /&gt;
&lt;br /&gt;
NOTE: You may find that starting the notification_proxy service once and once only at the start of your app and using the same socket in calls to AMDPostNotification works better. iTunes opens and closes the notification_proxy regularly, but it appears to be a bit flakey when you open/close it all the time.&lt;br /&gt;
&lt;br /&gt;
===Private Functions===&lt;br /&gt;
&lt;br /&gt;
====How to find address of privates functions in iTunesMobileDevice.dll or MobileDevice.framework ?====&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Libraries Implementations===&lt;br /&gt;
&lt;br /&gt;
* [http://gojohnnyboi.com/source/afcinstall.cpp afcinstall (command line, os x file install via afc)]&lt;br /&gt;
* [http://code.google.com/p/iphuc/ iPhuc (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/iphucwin32/ iPhuc Win32 (Command line utility)]&lt;br /&gt;
* [http://code.google.com/p/manzana/ manzana (.Net Library)]&lt;br /&gt;
* [http://code.google.com/p/independence/source/browse/trunk/libPhoneInteraction/ libPhoneInteraction (C Library)]&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=Sugar_Bowl_5F138_(iPod2,1)&amp;diff=3084</id>
		<title>Sugar Bowl 5F138 (iPod2,1)</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=Sugar_Bowl_5F138_(iPod2,1)&amp;diff=3084"/>
		<updated>2009-02-20T03:42:00Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: /* Update Ramdisk */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Notes==&lt;br /&gt;
* Vulnerable to the [[ARM7 Go]] backdoor / exploit&lt;br /&gt;
&lt;br /&gt;
==Decryption Keys==&lt;br /&gt;
===Root Filesystem===&lt;br /&gt;
'''Use in vfdecrypt''': d1b957a0a5e56903adc523c5fa99f5d165c3963aea48274770b766b44ecdebab7b5a8f30&lt;br /&gt;
&lt;br /&gt;
===LLB===&lt;br /&gt;
'''IV''': ce97a7c82ef864675ed3680597ec2aef &lt;br /&gt;
&lt;br /&gt;
'''Key''': 27732a6bbfb14a07250a2e4682bf3cba&lt;br /&gt;
&lt;br /&gt;
===iBoot===&lt;br /&gt;
'''IV''': b3633afbe02e0e9ba4d7366c47abe5a8&lt;br /&gt;
&lt;br /&gt;
'''Key''': 2d916dabb6dfd4594dbe3635b4c71662&lt;br /&gt;
&lt;br /&gt;
===DeviceTree===&lt;br /&gt;
'''IV''': ccff634ee12735f01916c4a6b20ff145&lt;br /&gt;
&lt;br /&gt;
'''Key''': e17bcd568df1cddc8fecbf5487d5c3ce&lt;br /&gt;
&lt;br /&gt;
===Kernel===&lt;br /&gt;
'''IV''': a191291290d487ff0731969c5fc8d918&lt;br /&gt;
&lt;br /&gt;
'''Key''': 0e4d23fa675999d5959dd10c8dd73d20&lt;br /&gt;
&lt;br /&gt;
===Apple Logo===&lt;br /&gt;
'''IV''': 64238fb03291422522b5dd283fc3895c&lt;br /&gt;
&lt;br /&gt;
'''Key''': 859fd4d382b8385156fc581a7f1d9722&lt;br /&gt;
&lt;br /&gt;
===Recovery Mode Logo===&lt;br /&gt;
'''IV''': 47621cf22dc1b45ada5aaa4b0124dded&lt;br /&gt;
&lt;br /&gt;
'''Key''': c9de0834428ca28ecf5392ec9195ce79&lt;br /&gt;
&lt;br /&gt;
===Restore Ramdisk===&lt;br /&gt;
'''Name''': 018-4166-1.dmg&lt;br /&gt;
&lt;br /&gt;
'''IV''': 2f4481855ca39e67dfbf3d19b8ade60e&lt;br /&gt;
&lt;br /&gt;
'''Key''': 6d4a00c0a08e90a3b024885f45bcb720&lt;br /&gt;
&lt;br /&gt;
===Update Ramdisk===&lt;br /&gt;
'''Name''': 018-4177-1.dmg&lt;br /&gt;
&lt;br /&gt;
'''IV''': 5447fa2ce0e2a6e39ffe8983be161e88&lt;br /&gt;
&lt;br /&gt;
'''Key''': 87ecb5a20030a9350cf50de6a43413ac&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=Sugar_Bowl_5F138_(iPod2,1)&amp;diff=3083</id>
		<title>Sugar Bowl 5F138 (iPod2,1)</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=Sugar_Bowl_5F138_(iPod2,1)&amp;diff=3083"/>
		<updated>2009-02-20T03:37:13Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: /* Root Filesystem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Notes==&lt;br /&gt;
* Vulnerable to the [[ARM7 Go]] backdoor / exploit&lt;br /&gt;
&lt;br /&gt;
==Decryption Keys==&lt;br /&gt;
===Root Filesystem===&lt;br /&gt;
'''Use in vfdecrypt''': d1b957a0a5e56903adc523c5fa99f5d165c3963aea48274770b766b44ecdebab7b5a8f30&lt;br /&gt;
&lt;br /&gt;
===LLB===&lt;br /&gt;
'''IV''': ce97a7c82ef864675ed3680597ec2aef &lt;br /&gt;
&lt;br /&gt;
'''Key''': 27732a6bbfb14a07250a2e4682bf3cba&lt;br /&gt;
&lt;br /&gt;
===iBoot===&lt;br /&gt;
'''IV''': b3633afbe02e0e9ba4d7366c47abe5a8&lt;br /&gt;
&lt;br /&gt;
'''Key''': 2d916dabb6dfd4594dbe3635b4c71662&lt;br /&gt;
&lt;br /&gt;
===DeviceTree===&lt;br /&gt;
'''IV''': ccff634ee12735f01916c4a6b20ff145&lt;br /&gt;
&lt;br /&gt;
'''Key''': e17bcd568df1cddc8fecbf5487d5c3ce&lt;br /&gt;
&lt;br /&gt;
===Kernel===&lt;br /&gt;
'''IV''': a191291290d487ff0731969c5fc8d918&lt;br /&gt;
&lt;br /&gt;
'''Key''': 0e4d23fa675999d5959dd10c8dd73d20&lt;br /&gt;
&lt;br /&gt;
===Apple Logo===&lt;br /&gt;
'''IV''': 64238fb03291422522b5dd283fc3895c&lt;br /&gt;
&lt;br /&gt;
'''Key''': 859fd4d382b8385156fc581a7f1d9722&lt;br /&gt;
&lt;br /&gt;
===Recovery Mode Logo===&lt;br /&gt;
'''IV''': 47621cf22dc1b45ada5aaa4b0124dded&lt;br /&gt;
&lt;br /&gt;
'''Key''': c9de0834428ca28ecf5392ec9195ce79&lt;br /&gt;
&lt;br /&gt;
===Restore Ramdisk===&lt;br /&gt;
'''Name''': 018-4166-1.dmg&lt;br /&gt;
&lt;br /&gt;
'''IV''': 2f4481855ca39e67dfbf3d19b8ade60e&lt;br /&gt;
&lt;br /&gt;
'''Key''': 6d4a00c0a08e90a3b024885f45bcb720&lt;br /&gt;
&lt;br /&gt;
===Update Ramdisk===&lt;br /&gt;
'''Name''':&lt;br /&gt;
&lt;br /&gt;
'''IV''': &lt;br /&gt;
&lt;br /&gt;
'''Key''':&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=Sugar_Bowl_5F138_(iPod2,1)&amp;diff=3082</id>
		<title>Sugar Bowl 5F138 (iPod2,1)</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=Sugar_Bowl_5F138_(iPod2,1)&amp;diff=3082"/>
		<updated>2009-02-20T03:35:20Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: /* Recovery Mode Logo */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Notes==&lt;br /&gt;
* Vulnerable to the [[ARM7 Go]] backdoor / exploit&lt;br /&gt;
&lt;br /&gt;
==Decryption Keys==&lt;br /&gt;
===Root Filesystem===&lt;br /&gt;
'''Use in vfdecrypt''': &lt;br /&gt;
&lt;br /&gt;
===LLB===&lt;br /&gt;
'''IV''': ce97a7c82ef864675ed3680597ec2aef &lt;br /&gt;
&lt;br /&gt;
'''Key''': 27732a6bbfb14a07250a2e4682bf3cba&lt;br /&gt;
&lt;br /&gt;
===iBoot===&lt;br /&gt;
'''IV''': b3633afbe02e0e9ba4d7366c47abe5a8&lt;br /&gt;
&lt;br /&gt;
'''Key''': 2d916dabb6dfd4594dbe3635b4c71662&lt;br /&gt;
&lt;br /&gt;
===DeviceTree===&lt;br /&gt;
'''IV''': ccff634ee12735f01916c4a6b20ff145&lt;br /&gt;
&lt;br /&gt;
'''Key''': e17bcd568df1cddc8fecbf5487d5c3ce&lt;br /&gt;
&lt;br /&gt;
===Kernel===&lt;br /&gt;
'''IV''': a191291290d487ff0731969c5fc8d918&lt;br /&gt;
&lt;br /&gt;
'''Key''': 0e4d23fa675999d5959dd10c8dd73d20&lt;br /&gt;
&lt;br /&gt;
===Apple Logo===&lt;br /&gt;
'''IV''': 64238fb03291422522b5dd283fc3895c&lt;br /&gt;
&lt;br /&gt;
'''Key''': 859fd4d382b8385156fc581a7f1d9722&lt;br /&gt;
&lt;br /&gt;
===Recovery Mode Logo===&lt;br /&gt;
'''IV''': 47621cf22dc1b45ada5aaa4b0124dded&lt;br /&gt;
&lt;br /&gt;
'''Key''': c9de0834428ca28ecf5392ec9195ce79&lt;br /&gt;
&lt;br /&gt;
===Restore Ramdisk===&lt;br /&gt;
'''Name''': 018-4166-1.dmg&lt;br /&gt;
&lt;br /&gt;
'''IV''': 2f4481855ca39e67dfbf3d19b8ade60e&lt;br /&gt;
&lt;br /&gt;
'''Key''': 6d4a00c0a08e90a3b024885f45bcb720&lt;br /&gt;
&lt;br /&gt;
===Update Ramdisk===&lt;br /&gt;
'''Name''':&lt;br /&gt;
&lt;br /&gt;
'''IV''': &lt;br /&gt;
&lt;br /&gt;
'''Key''':&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=Sugar_Bowl_5F138_(iPod2,1)&amp;diff=3081</id>
		<title>Sugar Bowl 5F138 (iPod2,1)</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=Sugar_Bowl_5F138_(iPod2,1)&amp;diff=3081"/>
		<updated>2009-02-20T03:34:12Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: /* Apple Logo */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Notes==&lt;br /&gt;
* Vulnerable to the [[ARM7 Go]] backdoor / exploit&lt;br /&gt;
&lt;br /&gt;
==Decryption Keys==&lt;br /&gt;
===Root Filesystem===&lt;br /&gt;
'''Use in vfdecrypt''': &lt;br /&gt;
&lt;br /&gt;
===LLB===&lt;br /&gt;
'''IV''': ce97a7c82ef864675ed3680597ec2aef &lt;br /&gt;
&lt;br /&gt;
'''Key''': 27732a6bbfb14a07250a2e4682bf3cba&lt;br /&gt;
&lt;br /&gt;
===iBoot===&lt;br /&gt;
'''IV''': b3633afbe02e0e9ba4d7366c47abe5a8&lt;br /&gt;
&lt;br /&gt;
'''Key''': 2d916dabb6dfd4594dbe3635b4c71662&lt;br /&gt;
&lt;br /&gt;
===DeviceTree===&lt;br /&gt;
'''IV''': ccff634ee12735f01916c4a6b20ff145&lt;br /&gt;
&lt;br /&gt;
'''Key''': e17bcd568df1cddc8fecbf5487d5c3ce&lt;br /&gt;
&lt;br /&gt;
===Kernel===&lt;br /&gt;
'''IV''': a191291290d487ff0731969c5fc8d918&lt;br /&gt;
&lt;br /&gt;
'''Key''': 0e4d23fa675999d5959dd10c8dd73d20&lt;br /&gt;
&lt;br /&gt;
===Apple Logo===&lt;br /&gt;
'''IV''': 64238fb03291422522b5dd283fc3895c&lt;br /&gt;
&lt;br /&gt;
'''Key''': 859fd4d382b8385156fc581a7f1d9722&lt;br /&gt;
&lt;br /&gt;
===Recovery Mode Logo===&lt;br /&gt;
'''IV''': &lt;br /&gt;
&lt;br /&gt;
'''Key''': &lt;br /&gt;
&lt;br /&gt;
===Restore Ramdisk===&lt;br /&gt;
'''Name''': 018-4166-1.dmg&lt;br /&gt;
&lt;br /&gt;
'''IV''': 2f4481855ca39e67dfbf3d19b8ade60e&lt;br /&gt;
&lt;br /&gt;
'''Key''': 6d4a00c0a08e90a3b024885f45bcb720&lt;br /&gt;
&lt;br /&gt;
===Update Ramdisk===&lt;br /&gt;
'''Name''':&lt;br /&gt;
&lt;br /&gt;
'''IV''': &lt;br /&gt;
&lt;br /&gt;
'''Key''':&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=Sugar_Bowl_5F138_(iPod2,1)&amp;diff=3080</id>
		<title>Sugar Bowl 5F138 (iPod2,1)</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=Sugar_Bowl_5F138_(iPod2,1)&amp;diff=3080"/>
		<updated>2009-02-20T03:30:44Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: /* LLB */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Notes==&lt;br /&gt;
* Vulnerable to the [[ARM7 Go]] backdoor / exploit&lt;br /&gt;
&lt;br /&gt;
==Decryption Keys==&lt;br /&gt;
===Root Filesystem===&lt;br /&gt;
'''Use in vfdecrypt''': &lt;br /&gt;
&lt;br /&gt;
===LLB===&lt;br /&gt;
'''IV''': ce97a7c82ef864675ed3680597ec2aef &lt;br /&gt;
&lt;br /&gt;
'''Key''': 27732a6bbfb14a07250a2e4682bf3cba&lt;br /&gt;
&lt;br /&gt;
===iBoot===&lt;br /&gt;
'''IV''': b3633afbe02e0e9ba4d7366c47abe5a8&lt;br /&gt;
&lt;br /&gt;
'''Key''': 2d916dabb6dfd4594dbe3635b4c71662&lt;br /&gt;
&lt;br /&gt;
===DeviceTree===&lt;br /&gt;
'''IV''': ccff634ee12735f01916c4a6b20ff145&lt;br /&gt;
&lt;br /&gt;
'''Key''': e17bcd568df1cddc8fecbf5487d5c3ce&lt;br /&gt;
&lt;br /&gt;
===Kernel===&lt;br /&gt;
'''IV''': a191291290d487ff0731969c5fc8d918&lt;br /&gt;
&lt;br /&gt;
'''Key''': 0e4d23fa675999d5959dd10c8dd73d20&lt;br /&gt;
&lt;br /&gt;
===Apple Logo===&lt;br /&gt;
'''IV''': &lt;br /&gt;
&lt;br /&gt;
'''Key''': &lt;br /&gt;
&lt;br /&gt;
===Recovery Mode Logo===&lt;br /&gt;
'''IV''': &lt;br /&gt;
&lt;br /&gt;
'''Key''': &lt;br /&gt;
&lt;br /&gt;
===Restore Ramdisk===&lt;br /&gt;
'''Name''': 018-4166-1.dmg&lt;br /&gt;
&lt;br /&gt;
'''IV''': 2f4481855ca39e67dfbf3d19b8ade60e&lt;br /&gt;
&lt;br /&gt;
'''Key''': 6d4a00c0a08e90a3b024885f45bcb720&lt;br /&gt;
&lt;br /&gt;
===Update Ramdisk===&lt;br /&gt;
'''Name''':&lt;br /&gt;
&lt;br /&gt;
'''IV''': &lt;br /&gt;
&lt;br /&gt;
'''Key''':&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=Talk:Main_Page&amp;diff=3017</id>
		<title>Talk:Main Page</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=Talk:Main_Page&amp;diff=3017"/>
		<updated>2009-02-10T00:02:41Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==MobileDevice sendCommandToDevice==&lt;br /&gt;
I need the address of this function in the new MobileDevice framework for OS X, and possibly a way to obtain it in the future. Would somebody help me out? (Post it on the MobileDevice page)&lt;br /&gt;
&lt;br /&gt;
== How do I make a template ==&lt;br /&gt;
&lt;br /&gt;
Hey since I am doing a bunch of these directory pages is it possible to get a template made or something? I'm not sure how this wiki program works.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== no offense... ==&lt;br /&gt;
&lt;br /&gt;
but user pages are not myspaces guys :P&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I like the new layout&amp;lt;br&amp;gt;&lt;br /&gt;
~geohot&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Wow good thinkin ==&lt;br /&gt;
&lt;br /&gt;
Good work geohot I am going to try to add as much of the file structure as I can. This should help everyone quickly find the proper folder, please help with summaries and such since my BSD knowledge is limited :-), also adding things like default permissions etc would be helpful.&lt;br /&gt;
&lt;br /&gt;
Thanks again&lt;br /&gt;
&lt;br /&gt;
partyK1d24&lt;br /&gt;
&lt;br /&gt;
== Unlock completed? ==&lt;br /&gt;
&lt;br /&gt;
Well, considering that Dev-Team had completed an unlock, we can change the &amp;quot;Unlock&amp;quot; bar background in the main page to green, right?&lt;br /&gt;
On the other hand, the unlock is not available to all baseband versions.&lt;br /&gt;
&lt;br /&gt;
~Oranav&lt;br /&gt;
&lt;br /&gt;
== yellow ==&lt;br /&gt;
&lt;br /&gt;
I made it yellow since it is (1) not yet released and (2) only works with some basebands. also, get it? '''yellow'''sn0w? :)&lt;br /&gt;
&lt;br /&gt;
== Jailbreak (S5L8720x) ==&lt;br /&gt;
&lt;br /&gt;
Why it has been changed to orange?  It should be red.&lt;br /&gt;
&lt;br /&gt;
== ugly ==&lt;br /&gt;
&lt;br /&gt;
red is ugly as a mofo. orange is fine, really :P&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=Main_Page&amp;diff=3016</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=Main_Page&amp;diff=3016"/>
		<updated>2009-02-10T00:00:14Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!-- Logo by iHassan --&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:Iptwiki.jpg‎]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;table border=1 width=100%&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td bgcolor=#64ff64 width=33%&amp;gt;&amp;lt;center&amp;gt;&amp;lt;b&amp;gt;[[Pwnage|Jailbreak (S5L8900)]]&amp;lt;/b&amp;gt;&amp;lt;/center&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td bgcolor=yellow width=33%&amp;gt;&amp;lt;center&amp;gt;&amp;lt;b&amp;gt;[[S5L8720|Break Chain of Trust (S5L8720)]]&amp;lt;/b&amp;gt;&amp;lt;/center&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td bgcolor=orange width=33%&amp;gt;&amp;lt;center&amp;gt;&amp;lt;b&amp;gt;[[Unlock 2.0|Unlock 02.30.03 or break the chain of trust of the X-Gold]]&amp;lt;/b&amp;gt;&amp;lt;/center&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td colspan=3&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;[[Disclaimer]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;lt;!-- Just a try to make the layout more comfortable -caique2001 --&amp;gt;&lt;br /&gt;
{| cellspacing=&amp;quot;3&amp;quot; width=&amp;quot;100%&amp;quot;&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
|width=&amp;quot;20%&amp;quot; class=&amp;quot;MainPageBG&amp;quot; style=&amp;quot;border: 1px #999999; color: #000; background-color: rgb(255,255,255)&amp;quot;|&lt;br /&gt;
&amp;lt;div style=&amp;quot;padding: .3em .7em .7em&amp;quot;&amp;gt; &amp;lt;BR&amp;gt; &amp;lt;BR&amp;gt; __TOC__ &amp;lt;/div&amp;gt;&lt;br /&gt;
|width=&amp;quot;80%&amp;quot; class=&amp;quot;MainPageBG&amp;quot; style=&amp;quot;border: 1px #c6c9ff; color: #000; background-color: #f0f0ff&amp;quot;|&lt;br /&gt;
&amp;lt;div style=&amp;quot;padding: .3em .7em .7em&amp;quot;&amp;gt; {{Welcome}} &amp;lt;/div&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==To-Do List==&lt;br /&gt;
&lt;br /&gt;
==Software==&lt;br /&gt;
* [[Filesystem]]&lt;br /&gt;
* [[Device Nodes]]&lt;br /&gt;
* [[System Log]]&lt;br /&gt;
* [[IPhoneLinux|Linux on iPhone]]&lt;br /&gt;
&lt;br /&gt;
==Hardware==&lt;br /&gt;
* [[m68ap|iPhone (m68ap)]]&lt;br /&gt;
* [[n82ap|iPhone 3G (n82ap)]]&lt;br /&gt;
* [[n45ap|iPod touch (n45ap)]]&lt;br /&gt;
* [[n72ap|iPod touch 2nd Generation (n72ap)]]&lt;br /&gt;
&lt;br /&gt;
==App Processor (Jailbreak)==&lt;br /&gt;
The [[iPhone]], [[iPod touch]], and [[iPhone 3G]] makes use of the [[S5L8900]] platform as application processor, while the [[iPod touch 2G]] uses the [[S5L8720]]. Here is where the [[Jailbreak|jailbreak]] applies.&lt;br /&gt;
&lt;br /&gt;
==Baseband (Unlock)==&lt;br /&gt;
&lt;br /&gt;
The [[Baseband Device]] is where the [[unlock]] applies.&lt;br /&gt;
&lt;br /&gt;
==File formats==&lt;br /&gt;
* [[8900 File Format]]&lt;br /&gt;
* [[IMG2 File Format]]&lt;br /&gt;
* [[IMG3 File Format]]&lt;br /&gt;
* [[secpack]]&lt;br /&gt;
* [[secpack 2.0]]&lt;br /&gt;
* [[seczone]]&lt;br /&gt;
&lt;br /&gt;
==Protocols==&lt;br /&gt;
* [[Recovery Mode (Protocols)|Recovery Mode]]&lt;br /&gt;
* [[DFU 0x1222]]&lt;br /&gt;
* [[WTF 0x1227]]&lt;br /&gt;
* [[Normal Mode]]&lt;br /&gt;
* [[Restore Mode]]&lt;br /&gt;
* [[Baseband Bootrom Protocol]]&lt;br /&gt;
* [[Interactive Mode|Baseband Bootloader Protocol]]&lt;br /&gt;
&lt;br /&gt;
==Keys==&lt;br /&gt;
* [[AES Keys]]&lt;br /&gt;
* [[Apple Certificate]]&lt;br /&gt;
* [[Baseband RSA Keys]]&lt;br /&gt;
* [[Baseband TEA Keys]]&lt;br /&gt;
* [[IMG3 Keys / IVs]]&lt;br /&gt;
* [[NCK]]&lt;br /&gt;
* [[VFDecrypt Keys|Root Filesystem DMG Keys]]&lt;br /&gt;
&lt;br /&gt;
==Application Development==&lt;br /&gt;
* [[Toolchain]] (Includes tutorials)&lt;br /&gt;
* [[Toolchain 2.0]] (Includes tutorials)&lt;br /&gt;
* [[Frameworks]]&lt;br /&gt;
* [[MobileDevice Library]]&lt;br /&gt;
* [[Apple Certification Process]]&lt;br /&gt;
* [[Bypassing iPhone Code Signatures]]&lt;br /&gt;
* [[Distribution Methods]]&lt;br /&gt;
&lt;br /&gt;
==Tutorials==&lt;br /&gt;
See [[Tutorials|here]].&lt;br /&gt;
&lt;br /&gt;
==Useful Links==&lt;br /&gt;
See [[Useful Links|here]].&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
* [[Jailbreak]]&lt;br /&gt;
* [[Activation]]&lt;br /&gt;
* [[Unlock]]&lt;br /&gt;
* [[Baseband Device|Baseband]]&lt;br /&gt;
* [[Baseband Bootloader|Bootloader]]&lt;br /&gt;
* [[DFU]]&lt;br /&gt;
* [[iBoot]]&lt;br /&gt;
* [[iBEC]]&lt;br /&gt;
* [[iBSS]]&lt;br /&gt;
* [[NORID]]&lt;br /&gt;
* [[CHIPID]]&lt;br /&gt;
&lt;br /&gt;
==Other Useful Hacks==&lt;br /&gt;
* [[Bluetooth]]&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=Main_Page&amp;diff=2959</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=Main_Page&amp;diff=2959"/>
		<updated>2009-02-05T20:00:08Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: /* Protocols */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!-- Logo by iHassan --&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:Iptwiki.jpg‎]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;table border=1 width=100%&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td bgcolor=#64ff64 width=33%&amp;gt;&amp;lt;center&amp;gt;&amp;lt;b&amp;gt;[http://www.theiphonewiki.com/wiki/index.php?title=Category:Jailbreaks Jailbreak (S5L8900x)]&amp;lt;/b&amp;gt;&amp;lt;/center&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td bgcolor=yellow width=33%&amp;gt;&amp;lt;center&amp;gt;&amp;lt;b&amp;gt;[[ARM7_Go|Jailbreak (S5L8720x)]] (TODO - Find method to make untethered)&amp;lt;/b&amp;gt;&amp;lt;/center&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td bgcolor=orange width=33%&amp;gt;&amp;lt;center&amp;gt;&amp;lt;b&amp;gt;[[Unlock 2.0|Unlock 02.30.03 or break the chain of trust of the X-Gold]]&amp;lt;/b&amp;gt;&amp;lt;/center&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td colspan=3&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;[[Disclaimer]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;lt;!-- Just a try to make the layout more comfortable -caique2001 --&amp;gt;&lt;br /&gt;
{| cellspacing=&amp;quot;3&amp;quot; width=&amp;quot;100%&amp;quot;&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
|width=&amp;quot;20%&amp;quot; class=&amp;quot;MainPageBG&amp;quot; style=&amp;quot;border: 1px #999999; color: #000; background-color: rgb(255,255,255)&amp;quot;|&lt;br /&gt;
&amp;lt;div style=&amp;quot;padding: .3em .7em .7em&amp;quot;&amp;gt; &amp;lt;BR&amp;gt; &amp;lt;BR&amp;gt; __TOC__ &amp;lt;/div&amp;gt;&lt;br /&gt;
|width=&amp;quot;80%&amp;quot; class=&amp;quot;MainPageBG&amp;quot; style=&amp;quot;border: 1px #c6c9ff; color: #000; background-color: #f0f0ff&amp;quot;|&lt;br /&gt;
&amp;lt;div style=&amp;quot;padding: .3em .7em .7em&amp;quot;&amp;gt; {{Welcome}} &amp;lt;/div&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
==Software==&lt;br /&gt;
* [[Filesystem]]&lt;br /&gt;
* [[Device Nodes]]&lt;br /&gt;
* [[System Log]]&lt;br /&gt;
* [[IPhoneLinux|Linux on iPhone]]&lt;br /&gt;
&lt;br /&gt;
==Hardware==&lt;br /&gt;
* [[m68ap|iPhone (m68ap)]]&lt;br /&gt;
* [[n82ap|iPhone 3G (n82ap)]]&lt;br /&gt;
* [[n45ap|iPod touch (n45ap)]]&lt;br /&gt;
* [[n72ap|iPod touch 2nd Generation (n72ap)]]&lt;br /&gt;
&lt;br /&gt;
==App Processor (Jailbreak)==&lt;br /&gt;
The iPhone makes use of the [[S5L8900]] platform as application processor. Here is where the [[Jailbreak|jailbreak]] applies.&lt;br /&gt;
&lt;br /&gt;
==Baseband (Unlock)==&lt;br /&gt;
&lt;br /&gt;
The [[Baseband Device]] is where the [[unlock]] applies.&lt;br /&gt;
&lt;br /&gt;
==File formats==&lt;br /&gt;
* [[8900 File Format]]&lt;br /&gt;
* [[IMG2 File Format]]&lt;br /&gt;
* [[IMG3 File Format]]&lt;br /&gt;
* [[secpack]]&lt;br /&gt;
* [[secpack 2.0]]&lt;br /&gt;
* [[seczone]]&lt;br /&gt;
&lt;br /&gt;
==Protocols==&lt;br /&gt;
* [[Recovery Mode 0x1280]]&lt;br /&gt;
* [[Recovery Mode 0x1281]]&lt;br /&gt;
* [[DFU 0x1222]]&lt;br /&gt;
* [[WTF 0x1227]]&lt;br /&gt;
* [[Normal Mode 0x1290]]&lt;br /&gt;
* [[Normal Mode 0x1293]]&lt;br /&gt;
* [[Restore Mode]]&lt;br /&gt;
* [[Baseband Bootrom Protocol]]&lt;br /&gt;
* [[Interactive Mode|Baseband Bootloader Protocol]]&lt;br /&gt;
&lt;br /&gt;
==Keys==&lt;br /&gt;
* [[AES Keys]]&lt;br /&gt;
* [[Apple Certificate]]&lt;br /&gt;
* [[Baseband RSA Keys]]&lt;br /&gt;
* [[Baseband TEA Keys]]&lt;br /&gt;
* [[IMG3 Keys / IVs]]&lt;br /&gt;
* [[NCK]]&lt;br /&gt;
* [[VFDecrypt Keys|Root Filesystem DMG Keys]]&lt;br /&gt;
&lt;br /&gt;
==Application Development==&lt;br /&gt;
* [[Toolchain]] (Includes tutorials)&lt;br /&gt;
* [[Toolchain 2.0]] (Includes tutorials)&lt;br /&gt;
* [[Frameworks]]&lt;br /&gt;
* [[MobileDevice Library]]&lt;br /&gt;
* [[Apple Certification Process]]&lt;br /&gt;
* [[Bypassing iPhone Code Signatures]]&lt;br /&gt;
* [[Distribution Methods]]&lt;br /&gt;
&lt;br /&gt;
==Tutorials==&lt;br /&gt;
See [[Tutorials|here]].&lt;br /&gt;
&lt;br /&gt;
==Useful Links==&lt;br /&gt;
See [[Useful Links|here]].&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
* [[Jailbreak]]&lt;br /&gt;
* [[Activation]]&lt;br /&gt;
* [[Unlock]]&lt;br /&gt;
* [[Baseband Device|Baseband]]&lt;br /&gt;
* [[Baseband Bootloader|Bootloader]]&lt;br /&gt;
* [[DFU]]&lt;br /&gt;
* [[iBoot]]&lt;br /&gt;
* [[iBEC]]&lt;br /&gt;
* [[iBSS]]&lt;br /&gt;
* [[NORID]]&lt;br /&gt;
* [[CHIPID]]&lt;br /&gt;
&lt;br /&gt;
==Other Useful Hacks==&lt;br /&gt;
* [[Bluetooth]]&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=Toolchain_2.0&amp;diff=2267</id>
		<title>Toolchain 2.0</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=Toolchain_2.0&amp;diff=2267"/>
		<updated>2008-10-05T06:16:37Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: /* Mac OS X */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article explains how to build a tool chain for iPhone OS 2.0. &lt;br /&gt;
&lt;br /&gt;
'''Please note that this section is under development.'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Mac OS X ==&lt;br /&gt;
Until a valid iPhone ARM toolchain installer can be legally distributed throughout the public (grr NDA), the alternative is simple. Install the Apple iPhone SDK, and use it's compiler, and specify the correct architecture, like so:&lt;br /&gt;
&lt;br /&gt;
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.1.sdk&lt;br /&gt;
&lt;br /&gt;
For extra headers that you have either obtained from an external source, or dumped from the iphone or iphone simulator frameworks yourself, place them in a custom include directory and pass the -I option through the compiler like so:&lt;br /&gt;
&lt;br /&gt;
..../gcc -I &amp;quot;YOUR INCLUDE DIRECTORY&amp;quot;.......&lt;br /&gt;
&lt;br /&gt;
Use saurik's codesign tool (ldid) to sign the binary like so:&lt;br /&gt;
&lt;br /&gt;
ldid -S &amp;lt;binary&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More on this coming soon.&lt;br /&gt;
&lt;br /&gt;
== Windows XP ==&lt;br /&gt;
&lt;br /&gt;
=== Extraction of iPhone OS 2.0 SDK ===&lt;br /&gt;
* Download the iPhone OS 2.0 SDK from [http://developer.apple.com/iphone/index.action Apple iPhone Dev Center].&lt;br /&gt;
* Download and install ''HFSExplorer'' from [http://hem.bredband.net/catacombae/hfsx.html catacombae software].&lt;br /&gt;
* Start ''HFSExplorer'' and choose the menu ''File&amp;amp;rarr;Open UDIF Disk Image (.dmg)...''&lt;br /&gt;
* Select the iPhone 2.0 SDK disk image ''iphone_sdk_final.dmg'' and press ''Open''&lt;br /&gt;
* When the tool asks ''Which partition to read'' leave it at ''&amp;quot;Mac_OS_X&amp;quot; (Apple_HFS)'' and press ''OK''&lt;br /&gt;
* Go to ''Packages'' and select the package you want to extract, e.g. ''iPhoneSDKHeadersAndLibs.pkg'' for the iPhone OS 2.0 header files.&lt;br /&gt;
* With right mouse button choose ''Extract data'' to extract an installation package.&lt;br /&gt;
* Please note that in order to extract this .pkg file on Windows, you must compile xar using Cygwin.  Make sure you have libxml2, libxml2-devel, openssl and openssl-devel.  You can then follow the instructions below.&lt;br /&gt;
&lt;br /&gt;
== Linux ==&lt;br /&gt;
Currently we can only describe how to get the headers from the iPhone OS 2.0 SDK.&lt;br /&gt;
&lt;br /&gt;
=== Extraction of iPhone OS 2.0 Installation Packages (.pkg) ===&lt;br /&gt;
* Extract &amp;lt;tt&amp;gt;iPhoneSDKHeadersAndLibs.pkg&amp;lt;/tt&amp;gt; from iPhone OS 2.0 SDK:&lt;br /&gt;
 mount -t hfs -o loop /path/to/iphone_sdk_final.dmg /somepath/somedir&lt;br /&gt;
:Copy &amp;lt;tt&amp;gt;iPhoneSDKHeadersAndLibs.pkg&amp;lt;/tt&amp;gt; from &amp;lt;tt&amp;gt;/somepath/somedir&amp;lt;/tt&amp;gt;&lt;br /&gt;
* Use the ''[http://code.google.com/p/xar/ eXtensible ARchiver]'' &amp;lt;tt&amp;gt;xar&amp;lt;/tt&amp;gt; to extract the file &amp;lt;tt&amp;gt;Payload&amp;lt;/tt&amp;gt; file containing the actual header files:&lt;br /&gt;
 xar -xf iPhoneSDKHeadersAndLibs.pkg Payload&lt;br /&gt;
*Extract the contents of the resulting &amp;lt;tt&amp;gt;Payload&amp;lt;/tt&amp;gt; file&lt;br /&gt;
 zcat Payload | cpio -id&lt;br /&gt;
or&lt;br /&gt;
 zcat Payload | cpio -id '*.h'&lt;br /&gt;
to extract only all header files included in the package.&lt;br /&gt;
&lt;br /&gt;
=== Framework Headers ===&lt;br /&gt;
This section assumes that&lt;br /&gt;
 zcat Payload | cpio -id '*.h'&lt;br /&gt;
got used in previous section.&lt;br /&gt;
&lt;br /&gt;
If you want to move all Framework headers into an ''include'' directory continue&lt;br /&gt;
as follows:&lt;br /&gt;
&lt;br /&gt;
* Remove the project XCode templates since they will not be required anymore:&lt;br /&gt;
 rm -rf Platforms/iPhoneOS.platform/Developer/Library&lt;br /&gt;
&lt;br /&gt;
* Create your target ''include'' directory:&lt;br /&gt;
 mkdir include&lt;br /&gt;
&lt;br /&gt;
* Get just the ''System'' and ''usr'' directories from the iPhone Os 2.0 SDK and remove the empty ''Platforms'' directory hierarchy:&lt;br /&gt;
 mv Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/* .&lt;br /&gt;
 rmdir -p Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/&lt;br /&gt;
&lt;br /&gt;
* Move the Framework headers to current directory and clean-up empty directory hierarchy:&lt;br /&gt;
 mv System/Library/Frameworks/* .&lt;br /&gt;
 rmdir -p System/Library/Frameworks/&lt;br /&gt;
&lt;br /&gt;
* Rename/move all Framework header directories into ''include'' directory and cleanup&lt;br /&gt;
 mv AddressBook.framework/Headers include/AddressBook&lt;br /&gt;
 mv AddressBookUI.framework/Headers include/AddressBookUI&lt;br /&gt;
 mv AudioToolbox.framework/Headers include/AudioToolbox&lt;br /&gt;
 mv AudioUnit.framework/Headers include/AudioUnit&lt;br /&gt;
 mv CFNetwork.framework/Headers include/CFNetwork&lt;br /&gt;
 mv CoreAudio.framework/Headers include/CoreAudio&lt;br /&gt;
 mv CoreFoundation.framework/Headers include/CoreFoundation&lt;br /&gt;
 mv CoreGraphics.framework/Headers include/CoreGraphics&lt;br /&gt;
 mv CoreLocation.framework/Headers include/CoreLocation&lt;br /&gt;
 mv Foundation.framework/Headers include/Foundation&lt;br /&gt;
 mv MediaPlayer.framework/Headers include/MediaPlayer&lt;br /&gt;
 mv OpenAL.framework/Headers include/OpenAL&lt;br /&gt;
 mv OpenGLES.framework/Headers include/OpenGLES&lt;br /&gt;
 mv QuartzCore.framework/Headers include/QuartzCore&lt;br /&gt;
 mv Security.framework/Headers include/Security&lt;br /&gt;
 mv SystemConfiguration.framework/Headers include/SystemConfiguration&lt;br /&gt;
 mv UIKit.framework/Headers include/UIKit&lt;br /&gt;
 rmdir -p *.framework&lt;br /&gt;
&lt;br /&gt;
* The remaining directories are ''include'' with all Framework headers and ''usr'' with all system related headers.&lt;br /&gt;
&lt;br /&gt;
* Move the ''usr/include'' headers also into new ''include'' directory, remove ''usr/lib'' since gcc includes will not be needed (at least not on iPhone toolchain), and clean up:&lt;br /&gt;
 mv usr/include/* include/&lt;br /&gt;
 rm -rf usr/lib&lt;br /&gt;
 rmdir -p usr/include/&lt;br /&gt;
&lt;br /&gt;
* You may still remove the ''Payload'' file since we don't need it anymore:&lt;br /&gt;
 rm Payload&lt;br /&gt;
&lt;br /&gt;
* Create a tar file so that you can directly transfer to your iPhone:&lt;br /&gt;
 tar --group 0 --owner 0 -cvf include.tar include&lt;br /&gt;
&lt;br /&gt;
* You are done.&lt;br /&gt;
&lt;br /&gt;
* Now you may transfer the ''include.tar'' to your iPhone (as user root), login to your iPhone via ssh and execute following commands to extract the header files (on your iPhone):&lt;br /&gt;
 cd /var&lt;br /&gt;
 tar xf /private/var/root/include.tar&lt;br /&gt;
&lt;br /&gt;
== iPhone/iPod Touch ==&lt;br /&gt;
There is a tool chain available after jailbreak from the [[Cydia|Cydia installer]]. You just need to install&lt;br /&gt;
the '''GNU C Compiler''' from Cydia to get the development environment on your iPhone&lt;br /&gt;
or iPod Touch. BigBoss has some comments on this Toolchain on his&lt;br /&gt;
webpage ''[http://thebigboss.org/moreinfo/Toolchain2.php Toolchain 2.0]''.&lt;br /&gt;
&lt;br /&gt;
If you want to use the header files from iPhone OS 2.0, you can obtain them from the&lt;br /&gt;
iPhone OS 2.0 SDK as described in section ''[[#Framework Headers|Framework Headers]]''.&lt;br /&gt;
&lt;br /&gt;
'''NOTE:'''&lt;br /&gt;
When using iphone-gcc ( the native compiler ) to compile iPhone applications, you must do one of the following:&lt;br /&gt;
# Patch the SDK header files for use with the compiler ( stupid thing doesn't like the new headers! ) or&lt;br /&gt;
# Use the old header files ( which are great, but some things dont work/exist the same anymore! ) or&lt;br /&gt;
# Use the following settings in your Makefile to avoid warnings and errors during compilation and linking:&lt;br /&gt;
 CC=/usr/bin/gcc&lt;br /&gt;
 &lt;br /&gt;
 CFLAGS=-fsigned-char -g -ObjC -fobjc-exceptions \&lt;br /&gt;
   -Wall -Wundeclared-selector -Wreturn-type -Wnested-externs \&lt;br /&gt;
   -Wredundant-decls \&lt;br /&gt;
   -Wbad-function-cast \&lt;br /&gt;
   -Wchar-subscripts \&lt;br /&gt;
   -Winline -Wswitch -Wshadow \&lt;br /&gt;
   -I/var/include \&lt;br /&gt;
   -I/var/include/gcc/darwin/4.0 \&lt;br /&gt;
   -D_CTYPE_H_ \&lt;br /&gt;
   -D_BSD_ARM_SETJMP_H \&lt;br /&gt;
   -D_UNISTD_H_&lt;br /&gt;
 &lt;br /&gt;
 CPPFLAGS=&lt;br /&gt;
 &lt;br /&gt;
 LD=$(CC)&lt;br /&gt;
 &lt;br /&gt;
 LDFLAGS=-lobjc \&lt;br /&gt;
   -F/System/Library/Frameworks \&lt;br /&gt;
   -framework CoreFoundation \&lt;br /&gt;
   -framework Foundation \&lt;br /&gt;
   -framework UIKit \&lt;br /&gt;
   -framework CoreGraphics \&lt;br /&gt;
   -L/usr/lib -lc /usr/lib/libgcc_s.1.dylib \&lt;br /&gt;
   -bind_at_load \&lt;br /&gt;
   -multiply_defined suppress&lt;br /&gt;
&lt;br /&gt;
If you want to test the iPhone 2.0 Toolchain, you may use this [[HelloWorld on iPhone|HelloWorld]] example.&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=Toolchain_2.0&amp;diff=1696</id>
		<title>Toolchain 2.0</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=Toolchain_2.0&amp;diff=1696"/>
		<updated>2008-08-12T23:08:25Z</updated>

		<summary type="html">&lt;p&gt;Gojohnnyboi: /* iPhone/iPod Touch */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article explains how to build a tool chain for iPhone OS 2.0. &lt;br /&gt;
&lt;br /&gt;
'''Please note that this section is under development.'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Mac OS X ==&lt;br /&gt;
fill this in. somebody did not get this memo :P&lt;br /&gt;
&lt;br /&gt;
toolchain != apple sdk&lt;br /&gt;
&lt;br /&gt;
== Windows XP ==&lt;br /&gt;
&lt;br /&gt;
=== Extraction of iPhone OS 2.0 SDK ===&lt;br /&gt;
* Download the iPhone OS 2.0 SDK from [http://developer.apple.com/iphone/index.action Apple iPhone Dev Center].&lt;br /&gt;
* Download and install ''HFSExplorer'' from [http://hem.bredband.net/catacombae/hfsx.html catacombae software].&lt;br /&gt;
* Start ''HFSExplorer'' and choose the menu ''File&amp;amp;rarr;Open UDIF Disk Image (.dmg)...''&lt;br /&gt;
* Select the iPhone 2.0 SDK disk image ''iphone_sdk_final.dmg'' and press ''Open''&lt;br /&gt;
* When the tool asks ''Which partition to read'' leave it at ''&amp;quot;Mac_OS_X&amp;quot; (Apple_HFS)'' and press ''OK''&lt;br /&gt;
* Go to ''Packages'' and select the package you want to extract, e.g. ''iPhoneSDKHeadersAndLibs.pkg'' for the iPhone OS 2.0 header files.&lt;br /&gt;
* With right mouse button choose ''Extract data'' to extract an installation package.&lt;br /&gt;
* Please note that in order to extract this .pkg file on Windows, you must compile xar using Cygwin.  Make sure you have libxml.  You can then follow the instructions below.&lt;br /&gt;
&lt;br /&gt;
== Linux ==&lt;br /&gt;
Currently we can only describe how to get the headers from the iPhone OS 2.0 SDK.&lt;br /&gt;
&lt;br /&gt;
=== Extraction of iPhone OS 2.0 Installation Packages (.pkg) ===&lt;br /&gt;
* Extract &amp;lt;tt&amp;gt;iPhoneSDKHeadersAndLibs.pkg&amp;lt;/tt&amp;gt; from iPhone OS 2.0 SDK:&lt;br /&gt;
 mount -t hfs -o loop /path/to/iphone_sdk_final.dmg /somepath/somedir&lt;br /&gt;
:Copy &amp;lt;tt&amp;gt;iPhoneSDKHeadersAndLibs.pkg&amp;lt;/tt&amp;gt; from &amp;lt;tt&amp;gt;/somepath/somedir&amp;lt;/tt&amp;gt;&lt;br /&gt;
* Use the ''eXtensible ARchiver'' &amp;lt;tt&amp;gt;xar&amp;lt;/tt&amp;gt; to extract the file &amp;lt;tt&amp;gt;Payload&amp;lt;/tt&amp;gt; file containing the actual header files:&lt;br /&gt;
 xar -xf iPhoneSDKHeadersAndLibs.pkg Payload&lt;br /&gt;
* Rename the &amp;lt;tt&amp;gt;Payload&amp;lt;/tt&amp;gt; file since it is gzipped:&lt;br /&gt;
 mv Payload Payload.gz&lt;br /&gt;
* Uncompress the &amp;lt;tt&amp;gt;Payload.gz&amp;lt;/tt&amp;gt; file:&lt;br /&gt;
 gunzip Payload.gz&lt;br /&gt;
* Extract the contents of the resulting &amp;lt;tt&amp;gt;Payload&amp;lt;/tt&amp;gt; file:&lt;br /&gt;
 cat Payload | cpio -i&lt;br /&gt;
or&lt;br /&gt;
 cat Payload | cpio -i -d '*.h'&lt;br /&gt;
to extract only all header files included in the package.&lt;br /&gt;
&lt;br /&gt;
=== Framework Headers ===&lt;br /&gt;
This section assumes that&lt;br /&gt;
 cat Payload | cpio -i -d '*.h'&lt;br /&gt;
got used in previous section.&lt;br /&gt;
&lt;br /&gt;
If you want to move all Framework headers into an ''include'' directory continue&lt;br /&gt;
as follows:&lt;br /&gt;
&lt;br /&gt;
* Remove the project XCode templates since they will not be required anymore:&lt;br /&gt;
 rm -rf Platforms/iPhoneOS.platform/Developer/Library&lt;br /&gt;
&lt;br /&gt;
* Create your target ''include'' directory:&lt;br /&gt;
 mkdir include&lt;br /&gt;
&lt;br /&gt;
* Get just the ''System'' and ''usr'' directories from the iPhone Os 2.0 SDK and remove the empty ''Platforms'' directory hierarchy:&lt;br /&gt;
 mv Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/* .&lt;br /&gt;
 rmdir -p Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/&lt;br /&gt;
&lt;br /&gt;
* Move the Framework headers to current directory and clean-up empty directory hierarchy:&lt;br /&gt;
 mv System/Library/Frameworks/* .&lt;br /&gt;
 rmdir -p System/Library/Frameworks/&lt;br /&gt;
&lt;br /&gt;
* Rename/move all Framework header directories into ''include'' directory and cleanup&lt;br /&gt;
 mv AddressBook.framework/Headers include/AddressBook&lt;br /&gt;
 mv AddressBookUI.framework/Headers include/AddressBookUI&lt;br /&gt;
 mv AudioToolbox.framework/Headers include/AudioToolbox&lt;br /&gt;
 mv AudioUnit.framework/Headers include/AudioUnit&lt;br /&gt;
 mv CFNetwork.framework/Headers include/CFNetwork&lt;br /&gt;
 mv CoreAudio.framework/Headers include/CoreAudio&lt;br /&gt;
 mv CoreFoundation.framework/Headers include/CoreFoundation&lt;br /&gt;
 mv CoreGraphics.framework/Headers include/CoreGraphics&lt;br /&gt;
 mv CoreLocation.framework/Headers include/CoreLocation&lt;br /&gt;
 mv Foundation.framework/Headers include/Foundation&lt;br /&gt;
 mv MediaPlayer.framework/Headers include/MediaPlayer&lt;br /&gt;
 mv OpenAL.framework/Headers include/OpenAL&lt;br /&gt;
 mv OpenGLES.framework/Headers include/OpenGLES&lt;br /&gt;
 mv QuartzCore.framework/Headers include/QuartzCore&lt;br /&gt;
 mv Security.framework/Headers include/Security&lt;br /&gt;
 mv SystemConfiguration.framework/Headers include/SystemConfiguration&lt;br /&gt;
 mv UIKit.framework/Headers include/UIKit&lt;br /&gt;
 rmdir -p *.framework&lt;br /&gt;
&lt;br /&gt;
* The remaining directories are ''include'' with all Framework headers and ''usr'' with all system related headers.&lt;br /&gt;
&lt;br /&gt;
* You may still remove the ''Payload'' file since we don't need it anymore:&lt;br /&gt;
 rm Payload&lt;br /&gt;
&lt;br /&gt;
* You are done.&lt;br /&gt;
&lt;br /&gt;
== iPhone/iPod Touch ==&lt;br /&gt;
There is a tool chain available after jailbreak from the [[Cydia|Cydia installer]]. You just need to install&lt;br /&gt;
the '''iPhone 2.0 Toolchain''' from Cydia to get a 1.1.x based development environment on your iPhone&lt;br /&gt;
or iPod Touch. The maintainer of this package - BigBoss - has some comments on this Toolchain on his&lt;br /&gt;
webpage ''[http://thebigboss.org/moreinfo/Toolchain2.php Toolchain 2.0]''.&lt;br /&gt;
&lt;br /&gt;
If you want to use the header files from iPhone OS 2.0, you can obtain them from the&lt;br /&gt;
iPhone OS 2.0 SDK as described in section ''[[#Framework Headers|Framework Headers]]''.&lt;br /&gt;
&lt;br /&gt;
**NOTE**&lt;br /&gt;
When using iphone-gcc ( the native compiler ) to compile iPhone applications, you must do one of the following:&lt;br /&gt;
1. Patch the SDK header files for use with the compiler ( stupid thing doesn't like the new headers! )&lt;br /&gt;
or&lt;br /&gt;
2. Use the old header files ( which are great, but some things dont work/exist the same anymore! )&lt;/div&gt;</summary>
		<author><name>Gojohnnyboi</name></author>
		
	</entry>
</feed>