[IOSDevice4Delphi] IOS设备连接文件管理库 For Delphi
[IOSDevice4Delphi] IOS设备连接文件管理库 For Delphi
转载请注明地址:http://www.cnblogs.com/lahcs/archive/2013/04/19/3031172.html
首先申明:这个库是我根据网上的C/C++/C#代码进行代码翻译的结果。目前并不完善,仅处理了一些基础简单的操作,例如:设备信息读取、目录读取、文件上传下载删除,同时可能存在部分bug。代码及Demo仅作下载学习使用,请勿用于非法用途。
如果有修改或更新,烦请转发我一份,共同学习。
参考代码或资料:
The iPhone wiki :http://theiphonewiki.com/wiki/MobileDevice_Library (目前最详细的资料,提供了相关函数的详细解释及用法)
Manzana :http://manzana.googlecode.com/ (开源C#项目,可能已经被关闭,请各位自行搜索下载)
基本原理使用Windows版本iTunes提供的 iTunesMobileDevice.dll 动态链接库,调用其相关函数达到操作IOS设备的目的,函数导出表国内很多人都有发出来,但是较少有人进行详细解释。
我这里仅仅是通过参考The iPhone wiki上提供的C/C++的头文件,同时参考了Manzana等开源C#项目相关代码,翻译转换成Delphi,学习而已,各位大牛勿喷。。。
附iTunesMobileDevice.dll函数导出表:
Demo效果展示:
IOSDevice4Delphi核心代码:
AMoblieDeviceModule.pas
1 {*******************************************************} 2 { } 3 { IOS Device Management Class } 4 { } 5 { author : LAHCS } 6 { } 7 { E-Mail : lahcs@qq.com } 8 { } 9 { QQ : 307643816 } 10 { } 11 { Copy Right (C) 2013 } 12 { } 13 {*******************************************************} 14 { ReferenceList: 15 [The iPhone wiki] http://theiphonewiki.com/wiki/MobileDevice_Library 16 [Manzana] http://manzana.googlecode.com/ 17 } 18 unit AMoblieDeviceModule; 19 20 interface 21 22 uses 23 Windows, SysUtils, IniFiles, AMobileDevice, AMoblieDeviceFuncModule, AMoblieDeviceModuleDef; 24 25 type 26 TDeviceConnectEvent = procedure(Sender: TObject;Device: TAMoblieDevice) of object; 27 28 TAMobileDeviceModule = class(TObject) 29 private 30 FLastErrCode : Cardinal; 31 FOnDeciveConnect : TDeviceConnectEvent; 32 FOnDeviceDisconnect : TDeviceConnectEvent; 33 private 34 hiTunesMobileDeviceModule : HMODULE; 35 hCoreFoundationModule : HMODULE; 36 p_AMDeviceNotification : p_am_device_notification; 37 private 38 FDeviceList : THashedStringList; 39 private 40 function GetDevice(Value: Integer):TAMoblieDevice; 41 function GetDeviceCount:Integer; 42 private 43 procedure DoOnNotificationCallBack(value: p_am_device_notification_callback_info); 44 procedure DoOnDeviceConnectNotice(device: p_am_device); 45 procedure DoOnDeviceDisConnectNotice(device: p_am_device); 46 procedure DoOnDeviceOtherNotice(device: p_am_device); 47 public 48 function InitialModule():Boolean; 49 function Subscribe():Boolean; 50 public 51 constructor Create; 52 destructor Destroy; override; 53 public 54 property OnDeviceConnect : TDeviceConnectEvent 55 read FOnDeciveConnect 56 write FOnDeciveConnect; 57 58 property OnDeviceDisconnect : TDeviceConnectEvent 59 read FOnDeviceDisconnect 60 write FOnDeviceDisconnect; 61 62 property Item[index:Integer]:TAMoblieDevice 63 read GetDevice; 64 65 property Count : Integer 66 read GetDeviceCount; 67 end; 68 69 var 70 lpAMobileDeviceModule : TAMobileDeviceModule; 71 72 implementation 73 74 function SetDllDirectory(lpPathName:PWideChar): Bool; stdcall; external 'kernel32.dll' name 'SetDllDirectoryW'; 75 76 function GetArrayStr(Value:array of UCHAR):string; 77 var 78 i : Integer; 79 begin 80 Result := ''; 81 for i:= 0 to Length(Value) - 1 do 82 begin 83 Result := Result + IntToHex(Value[i],2); 84 end; 85 end; 86 87 procedure AMDeviceNotificationCallback( 88 value: p_am_device_notification_callback_info);cdecl; 89 begin 90 lpAMobileDeviceModule.DoOnNotificationCallBack(value); 91 end; 92 93 procedure LoadiTunesMobileDeviceModule(var hiTunesMobileDeviceModule:HMODULE;var fun_pointer:Pointer;fun_name:PChar); 94 begin 95 if hiTunesMobileDeviceModule = 0 then 96 Exit; 97 fun_pointer := GetProcAddress(hiTunesMobileDeviceModule,fun_name); 98 if fun_pointer = nil then 99 begin 100 FreeLibrary(hiTunesMobileDeviceModule); 101 hiTunesMobileDeviceModule := 0; 102 end; 103 end; 104 105 { TAMobileDeviceModule } 106 107 constructor TAMobileDeviceModule.Create; 108 begin 109 FDeviceList := THashedStringList.Create; 110 FuncModule := TAMoblieDeviceFuncModule.Create; 111 end; 112 113 destructor TAMobileDeviceModule.Destroy; 114 var 115 i : Integer; 116 begin 117 for i:= 0 to FDeviceList.Count - 1 do 118 TAMoblieDevice(FDeviceList.Objects[i]).Destroy; 119 120 FDeviceList.Clear; 121 FuncModule.Destroy; 122 inherited; 123 end; 124 125 function TAMobileDeviceModule.InitialModule:Boolean; 126 var 127 strEnvironmentPath : WideString; 128 FMDS_PATH , FAAS_PATH : WideString; 129 begin 130 Result := False; 131 FLastErrCode := $FFFFFFFF; 132 133 strEnvironmentPath := GetEnvironmentVariable('CommonProgramFiles'); 134 135 FMDS_PATH := strEnvironmentPath + MDS_PATH; 136 FAAS_PATH := strEnvironmentPath + AAS_PATH; 137 138 SetDllDirectory(PWideChar(FAAS_PATH)); 139 140 hiTunesMobileDeviceModule := LoadLibraryW(PWideChar(FMDS_PATH + 'iTunesMobileDevice.dll')); 141 if hiTunesMobileDeviceModule <> 0 then 142 begin 143 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AMDeviceNotificationSubscribe,'AMDeviceNotificationSubscribe'); 144 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AMDeviceNotificationUnsubscribe,'AMDeviceNotificationUnsubscribe'); 145 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AMDeviceConnect,'AMDeviceConnect'); 146 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AMDeviceDisconnect,'AMDeviceDisconnect'); 147 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AMDeviceIsPaired,'AMDeviceIsPaired'); 148 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AMDeviceValidatePairing,'AMDeviceValidatePairing'); 149 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AMDeviceStartSession,'AMDeviceStartSession'); 150 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AMDeviceStopSession,'AMDeviceStopSession'); 151 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AMDeviceStartService,'AMDeviceStartService'); 152 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AMDeviceCopyValue,'AMDeviceCopyValue'); 153 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCConnectionOpen,'AFCConnectionOpen'); 154 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCConnectionClose,'AFCConnectionClose'); 155 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCDirectoryOpen,'AFCDirectoryOpen'); 156 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCDirectoryRead,'AFCDirectoryRead'); 157 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCDirectoryClose,'AFCDirectoryClose'); 158 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCDirectoryCreate,'AFCDirectoryCreate'); 159 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCDeviceInfoOpen,'AFCDeviceInfoOpen'); 160 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCFileInfoOpen,'AFCFileInfoOpen'); 161 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCKeyValueRead,'AFCKeyValueRead'); 162 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCKeyValueClose,'AFCKeyValueClose'); 163 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCRemovePath,'AFCRemovePath'); 164 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCRenamePath,'AFCRenamePath'); 165 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCFileRefOpen,'AFCFileRefOpen'); 166 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCFileRefClose,'AFCFileRefClose'); 167 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCFileRefRead,'AFCFileRefRead'); 168 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCFileRefWrite,'AFCFileRefWrite'); 169 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCFlushData,'AFCFlushData'); 170 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCFileRefSeek,'AFCFileRefSeek'); 171 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCFileRefTell,'AFCFileRefTell'); 172 LoadiTunesMobileDeviceModule(hiTunesMobileDeviceModule,@FuncModule.lpf_AFCFileRefSetFileSize,'AFCFileRefSetFileSize'); 173 end 174 else 175 Exit; 176 177 hCoreFoundationModule := LoadLibraryW(PWideChar(FAAS_PATH + 'CoreFoundation.dll')); 178 if hCoreFoundationModule <> 0 then 179 begin 180 LoadiTunesMobileDeviceModule(hCoreFoundationModule,@FuncModule.lpf_CFStringCreateWithCString,'CFStringCreateWithCString'); 181 LoadiTunesMobileDeviceModule(hCoreFoundationModule,@FuncModule.lpf_CFPropertyListCreateFromXMLData,'CFPropertyListCreateFromXMLData'); 182 LoadiTunesMobileDeviceModule(hCoreFoundationModule,@FuncModule.lpf_CFPropertyListCreateXMLData,'CFPropertyListCreateXMLData'); 183 Result := True; 184 end 185 else 186 Exit; 187 end; 188 189 function TAMobileDeviceModule.Subscribe: Boolean; 190 begin 191 Result := False; 192 FLastErrCode := FuncModule.lpf_AMDeviceNotificationSubscribe(AMDeviceNotificationCallback,0,0,0,@p_AMDeviceNotification); 193 if FLastErrCode = 0 then 194 Result := True; 195 end; 196 197 procedure TAMobileDeviceModule.DoOnNotificationCallBack( 198 value: p_am_device_notification_callback_info); 199 begin 200 case value.msg of 201 ADNCI_MSG_CONNECTED : DoOnDeviceConnectNotice(value.dev); 202 ADNCI_MSG_DISCONNECTED : DoOnDeviceDisConnectNotice(value.dev); 203 ADNCI_MSG_UNKNOWN : DoOnDeviceOtherNotice(value.dev); 204 end; 205 end; 206 207 procedure TAMobileDeviceModule.DoOnDeviceConnectNotice( 208 device: p_am_device); 209 var 210 ADevice : TAMoblieDevice; 211 strHashKey : string; 212 intDeviceIndex : Integer; 213 begin 214 intDeviceIndex := 0; 215 strHashKey := inttoHex(device.device_id,8) + inttoHex(device.product_id,8); 216 if FDeviceList.Find(strHashKey,intDeviceIndex) then 217 begin 218 ADevice := TAMoblieDevice(FDeviceList.Objects[intDeviceIndex]); 219 if Assigned(ADevice) then 220 begin 221 ADevice.Device := device; 222 ADevice.ReConnect := True; 223 end; 224 end 225 else 226 begin 227 ADevice := TAMoblieDevice.Create(device); 228 FDeviceList.AddObject(strHashKey,ADevice); 229 end; 230 231 if Assigned(FOnDeciveConnect) then 232 FOnDeciveConnect(Self,ADevice); 233 end; 234 235 procedure TAMobileDeviceModule.DoOnDeviceDisConnectNotice( 236 device: p_am_device); 237 var 238 ADevice : TAMoblieDevice; 239 strHashKey : string; 240 intDeviceIndex : Integer; 241 begin 242 intDeviceIndex := 0; 243 strHashKey := inttoHex(device.device_id,8) + inttoHex(device.product_id,8); 244 if FDeviceList.Find(strHashKey,intDeviceIndex) then 245 begin 246 ADevice := TAMoblieDevice(FDeviceList.Objects[intDeviceIndex]); 247 if Assigned(ADevice) then 248 begin 249 ADevice.DisConnect; 250 if Assigned(FOnDeviceDisconnect) then 251 FOnDeviceDisconnect(Self,ADevice); 252 end; 253 end; 254 end; 255 256 procedure TAMobileDeviceModule.DoOnDeviceOtherNotice(device: p_am_device); 257 var 258 ADevice : TAMoblieDevice; 259 strHashKey : string; 260 intDeviceIndex : Integer; 261 begin 262 intDeviceIndex := 0; 263 strHashKey := inttoHex(device.device_id,8) + inttoHex(device.product_id,8); 264 if FDeviceList.Find(strHashKey,intDeviceIndex) then 265 begin 266 ADevice := TAMoblieDevice(FDeviceList.Objects[intDeviceIndex]); 267 if Assigned(ADevice) then 268 begin 269 ADevice.DisConnect; 270 end; 271 end; 272 end; 273 274 function TAMobileDeviceModule.GetDevice(Value: Integer): TAMoblieDevice; 275 begin 276 if (Value < 0) or (Value > FDeviceList.Count - 1) then 277 begin 278 Result := nil; 279 Exit; 280 end; 281 Result := TAMoblieDevice(FDeviceList.Objects[Value]); 282 end; 283 284 function TAMobileDeviceModule.GetDeviceCount: Integer; 285 begin 286 Result := FDeviceList.Count; 287 end; 288 289 end.
AMoblieDeviceFuncModule.pas
1 {*******************************************************} 2 { } 3 { iTunesMobileDevice Function Class } 4 { } 5 { author : LAHCS } 6 { } 7 { E-Mail : lahcs@qq.com } 8 { } 9 { QQ : 307643816 } 10 { } 11 { Copy Right (C) 2013 } 12 { } 13 {*******************************************************} 14 { ReferenceList: 15 [The iPhone wiki] http://theiphonewiki.com/wiki/MobileDevice_Library 16 [Manzana] http://manzana.googlecode.com/ 17 } 18 unit AMoblieDeviceFuncModule; 19 20 interface 21 22 uses 23 AMoblieDeviceModuleDef; 24 25 type 26 27 TAMoblieDeviceFuncModule = class(TObject) 28 public 29 lpf_CFStringCreateWithCString : FunType_CFStringCreateWithCString; 30 lpf_CFPropertyListCreateFromXMLData : FunType_CFPropertyListCreateFromXMLData; 31 lpf_CFPropertyListCreateXMLData : FunType_CFPropertyListCreateXMLData; 32 public 33 lpf_AMDeviceNotificationSubscribe : FunType_AMDeviceNotificationSubscribe; 34 lpf_AMDeviceNotificationUnsubscribe : FunType_AMDeviceNotificationUnsubscribe; 35 lpf_AMDeviceConnect : FunType_AMDeviceConnect; 36 lpf_AMDeviceDisconnect : FunType_AMDeviceDisconnect; 37 lpf_AMDeviceIsPaired : FunType_AMDeviceIsPaired; 38 lpf_AMDeviceValidatePairing : FunType_AMDeviceValidatePairing; 39 lpf_AMDeviceStartSession : FunType_AMDeviceStartSession; 40 lpf_AMDeviceStopSession : FunType_AMDeviceStopSession; 41 lpf_AMDeviceStartService : FunType_AMDeviceStartService; 42 lpf_AMDeviceCopyValue : FunType_AMDeviceCopyValue; 43 public 44 lpf_AFCConnectionOpen : FunType_AFCConnectionOpen; 45 lpf_AFCConnectionClose : FunType_AFCConnectionClose; 46 lpf_AFCDirectoryOpen : FunType_AFCDirectoryOpen; 47 lpf_AFCDirectoryRead : FunType_AFCDirectoryRead; 48 lpf_AFCDirectoryClose : FunType_AFCDirectoryClose; 49 lpf_AFCDirectoryCreate : FunType_AFCDirectoryCreate; 50 lpf_AFCDeviceInfoOpen : FunType_AFCDeviceInfoOpen; 51 lpf_AFCFileInfoOpen : FunType_AFCFileInfoOpen; 52 lpf_AFCKeyValueRead : FunType_AFCKeyValueRead; 53 lpf_AFCKeyValueClose : FunType_AFCKeyValueClose; 54 lpf_AFCRemovePath : FunType_AFCRemovePath; 55 lpf_AFCRenamePath : FunType_AFCRenamePath; 56 lpf_AFCFileRefOpen : FunType_AFCFileRefOpen; 57 lpf_AFCFileRefClose : FunType_AFCFileRefClose; 58 lpf_AFCFileRefRead : FunType_AFCFileRefRead; 59 lpf_AFCFileRefWrite : FunType_AFCFileRefWrite; 60 lpf_AFCFlushData : FunType_AFCFlushData; 61 lpf_AFCFileRefSeek : FunType_AFCFileRefSeek; 62 lpf_AFCFileRefTell : FunType_AFCFileRefTell; 63 lpf_AFCFileRefSetFileSize : FunType_AFCFileRefSetFileSize; 64 end; 65 66 var 67 FuncModule : TAMoblieDeviceFuncModule; 68 69 implementation 70 71 end.
AMoblieDeviceModuleDef.pas
1 {*******************************************************} 2 { } 3 { IOS Device Type Define Class } 4 { } 5 { author : LAHCS } 6 { } 7 { E-Mail : lahcs@qq.com } 8 { } 9 { QQ : 307643816 } 10 { } 11 { Copy Right (C) 2013 } 12 { } 13 {*******************************************************} 14 { ReferenceList: 15 [The iPhone wiki] http://theiphonewiki.com/wiki/MobileDevice_Library 16 [Manzana] http://manzana.googlecode.com/ 17 } 18 unit AMoblieDeviceModuleDef; 19 20 interface 21 22 uses 23 Windows; 24 25 const 26 AAS_PATH :WideString = '\Apple\Apple Application Support\'; 27 MDS_PATH :WideString = '\Apple\Mobile Device Support\'; 28 AFC_STRING : String = 'com.apple.afc'; 29 AFC2_STRING : String = 'com.apple.afc2'; 30 31 const 32 ADNCI_MSG_CONNECTED = 1; 33 ADNCI_MSG_DISCONNECTED = 2; 34 ADNCI_MSG_UNKNOWN = 3; 35 36 type 37 mach_error_t = UINT; 38 afc_error_t = UINT; 39 afc_file_ref = ULONGLONG; 40 41 {struct am_device 42 unsigned char unknown0[0x10]; /* 0 - zero */ 43 unsigned int device_id; /* 16 */ 44 unsigned int product_id; /* 20 - set to AMD_IPHONE_PRODUCT_ID */ 45 char *serial; /* 24 - set to AMD_IPHONE_SERIAL */ 46 unsigned int unknown1; /* 28 */ 47 unsigned char unknown2[0x4]; /* 32 */ 48 unsigned int lockdown_conn; /* 36 */ 49 unsigned char unknown3[0x8]; /* 40 */ 50 unsigned char unknown4[0x61]; /* 40 */ 51 unsigned char unknown5[0x8]; /* 40 */ 52 } 53 type 54 am_device = packed record 55 unknown0 : array [0..$10 - 1] of UCHAR; 56 device_id : UINT; 57 product_id : UINT; 58 serial : PChar; 59 unknown1 : UINT; 60 unknown2 : array [0..$4 - 1] of UCHAR; 61 lockdown_conn : UINT; 62 unknown3 : array [0..$8 - 1] of UCHAR; 63 unknown4 : array [0..$61 - 1] of UCHAR; 64 unknown5 : array [0..$8 - 1] of UCHAR; 65 end; 66 p_am_device = ^am_device; 67 68 { struct am_device_notification_callback_info 69 struct am_device *dev; /* 0 device */ 70 unsigned int msg; /* 4 one of ADNCI_MSG_* */ 71 } 72 type 73 am_device_notification_callback_info = record 74 dev : p_am_device; 75 msg : UINT; 76 end; 77 p_am_device_notification_callback_info = ^am_device_notification_callback_info; 78 79 {typedef void(*am_device_notification_callback)(struct 80 am_device_notification_callback_info *); } 81 82 type 83 am_device_notification_callback = procedure(value:p_am_device_notification_callback_info);cdecl; 84 p_am_device_notification_callback = ^am_device_notification_callback; 85 86 type 87 am_device_notification = record 88 unknown0 : UINT; 89 unknown1 : UINT; 90 unknown2 : UINT; 91 callback : p_am_device_notification_callback; 92 unknown3 : UINT; 93 end; 94 p_am_device_notification = ^am_device_notification; 95 p_p_am_device_notification = ^p_am_device_notification; 96 97 afc_connection = record 98 handle : UINT; 99 unknown0 : UINT; 100 unknown1 : UCHAR; 101 padding : array [0..3-1] of UCHAR; 102 unknown2 : UINT; 103 unknown3 : UINT; 104 unknown4 : UINT; 105 fs_block_size : UINT; 106 sock_block_size : UINT; 107 io_timeout : UINT; 108 afc_lock : Pointer; 109 context : UINT; 110 end; 111 p_afc_connection = ^afc_connection; 112 p_p_afc_connection = ^p_afc_connection; 113 114 afc_device_info = record 115 unknown : array [0..12 - 1] of UCHAR; 116 end; 117 118 afc_directory = record 119 unknown : UCHAR; 120 end; 121 p_afc_directory = ^afc_directory; 122 123 afc_dictionary = record 124 unknown : UCHAR; 125 end; 126 p_afc_dictionary = ^afc_dictionary; 127 128 //============================================================================== 129 // iTunesMobileDevice.dll 130 //============================================================================== 131 132 FunType_AMDeviceNotificationSubscribe 133 = function(callback:am_device_notification_callback;unused0,unused1,dn_unknown3:UINT;notification:p_p_am_device_notification):mach_error_t;cdecl; 134 135 FunType_AMDeviceNotificationUnsubscribe 136 = function(notification:p_am_device_notification):mach_error_t;cdecl; 137 138 FunType_AMDeviceConnect 139 = function(device:p_am_device):mach_error_t;cdecl; 140 141 FunType_AMDeviceIsPaired 142 = function(device:p_am_device):Integer;cdecl; 143 144 FunType_AMDeviceValidatePairing 145 = function(device:p_am_device):mach_error_t;cdecl; 146 147 FunType_AMDeviceStartSession 148 = function(device:p_am_device):mach_error_t;cdecl; 149 150 FunType_AMDeviceStartService 151 = function(device:p_am_device;service_name:Pointer;handle:p_p_afc_connection;unknown:PUINT):mach_error_t;cdecl; 152 153 FunType_AMDeviceStopSession 154 = function(device:p_am_device):mach_error_t;cdecl; 155 156 FunType_AFCConnectionClose 157 = function(conn:p_afc_connection):afc_error_t;cdecl; 158 159 FunType_AMDeviceDisconnect 160 = function(device:p_am_device):mach_error_t;cdecl; 161 162 //public extern static int AMDeviceGetConnectionID(ref AMDevice device); 163 164 //public extern static int AMRestoreModeDeviceCreate(uint unknown0, int connection_id, uint unknown1); 165 166 //public extern static IntPtr AMDeviceCopyValue(ref AMDevice device, uint unknown, byte[] cfstring); 167 FunType_AMDeviceCopyValue 168 = function(device:p_am_device;unknow: UINT;cfstring:Pointer):Pointer;cdecl; 169 //public extern static int AMRestoreRegisterForDeviceNotifications( 170 // DeviceRestoreNotificationCallback dfu_connect, 171 // DeviceRestoreNotificationCallback recovery_connect, 172 // DeviceRestoreNotificationCallback dfu_disconnect, 173 // DeviceRestoreNotificationCallback recovery_disconnect, 174 // uint unknown0, 175 // IntPtr user_info); 176 177 FunType_AFCConnectionOpen 178 = function(conn:p_afc_connection;io_timeout:UINT;pconn:p_p_afc_connection):afc_error_t;cdecl; 179 180 //public extern static int AFCDirectoryOpen(IntPtr conn, string path, ref IntPtr dir); 181 FunType_AFCDirectoryOpen 182 = function(conn:p_afc_connection;path:PChar;var dir: Pointer):afc_error_t;cdecl; 183 184 //public extern static int AFCDirectoryRead(IntPtr conn, IntPtr dir, ref IntPtr dirent); 185 FunType_AFCDirectoryRead 186 = function(conn:p_afc_connection;dir: Pointer;var dirent:Pointer):afc_error_t;cdecl; 187 188 //public extern static int AFCDirectoryClose(IntPtr conn, IntPtr dir); 189 FunType_AFCDirectoryClose 190 = function(conn:p_afc_connection;dir: Pointer):afc_error_t;cdecl; 191 192 //public extern static int AFCDirectoryCreate(IntPtr conn, string path); 193 FunType_AFCDirectoryCreate 194 = function(conn:p_afc_connection;path: PChar):afc_error_t;cdecl; 195 196 //public static extern unsafe int AFCDeviceInfoOpen(void* conn, ref void* dict); 197 FunType_AFCDeviceInfoOpen 198 = function(conn:p_afc_connection;var dict:Pointer):afc_error_t;cdecl; 199 200 //public extern static int AFCGetFileInfo(IntPtr conn, string path, ref IntPtr buffer, out uint length); 201 //FunType_AFCGetFileInfo 202 // = function(handle:p_afc_connection;path: PChar;var buffer:Pointer; var Length:UINT):afc_error_t;cdecl; 203 //unsafe public extern static int AFCFileInfoOpen(void* conn, string path, ref void* dict); 204 FunType_AFCFileInfoOpen 205 = function(conn:p_afc_connection;path: PChar;var dict:Pointer):afc_error_t;cdecl; 206 207 //public static extern unsafe int AFCKeyValueRead(void* dict, out void* key, out void* val); 208 FunType_AFCKeyValueRead 209 = function(dict: p_afc_dictionary;out key: PChar;out val: PChar):afc_error_t;cdecl; 210 211 //public static extern unsafe int AFCKeyValueClose(void* dict); 212 FunType_AFCKeyValueClose 213 = function(dict: p_afc_dictionary):afc_error_t;cdecl; 214 215 //public extern static int AFCRemovePath(IntPtr conn, string path); 216 FunType_AFCRemovePath 217 = function(conn:p_afc_connection;path: PChar):afc_error_t;cdecl; 218 219 //public extern static int AFCRenamePath(IntPtr conn, string old_path, string new_path); 220 FunType_AFCRenamePath 221 = function(conn:p_afc_connection;old_path: PChar;new_path:PChar):afc_error_t;cdecl; 222 223 //public extern static int AFCFileRefOpen(IntPtr conn, string path, int mode, int unknown, out Int64 handle); 224 FunType_AFCFileRefOpen 225 = function(conn:p_afc_connection;path: PChar;mode : Integer;unknow:Integer;var handle:Int64):afc_error_t;cdecl; 226 227 //public extern static int AFCFileRefClose(IntPtr conn, Int64 handle); 228 FunType_AFCFileRefClose 229 = function(conn:p_afc_connection;handle:Int64):afc_error_t;cdecl; 230 231 //public extern static int AFCFileRefRead(IntPtr conn, Int64 handle, byte[] buffer, ref uint len); 232 FunType_AFCFileRefRead 233 = function(conn:p_afc_connection;handle:Int64;buffer:Pointer;var len:UINT):afc_error_t;cdecl; 234 235 //public extern static int AFCFileRefWrite(IntPtr conn, Int64 handle, byte[] buffer, uint len); 236 FunType_AFCFileRefWrite 237 = function(conn:p_afc_connection;handle:Int64;buffer:Pointer;len:UINT):afc_error_t;cdecl; 238 239 //public extern static int AFCFlushData(IntPtr conn, Int64 handle); 240 FunType_AFCFlushData 241 = function(conn:p_afc_connection;handle:Int64):afc_error_t;cdecl; 242 243 //public extern static int AFCFileRefSeek(IntPtr conn, Int64 handle, uint pos, uint origin); 244 FunType_AFCFileRefSeek 245 = function(conn:p_afc_connection;handle:Int64;pos:UINT;origin:UINT):afc_error_t;cdecl; 246 247 //public extern static int AFCFileRefTell(IntPtr conn, Int64 handle, ref uint position); 248 FunType_AFCFileRefTell 249 = function(conn:p_afc_connection;handle:Int64;var position:UINT):afc_error_t;cdecl; 250 251 //public extern static int AFCFileRefSetFileSize(IntPtr conn, Int64 handle, uint size); 252 FunType_AFCFileRefSetFileSize 253 = function(conn:p_afc_connection;handle:Int64;size:UINT):afc_error_t;cdecl; 254 255 //============================================================================== 256 // CoreFoundation.dll 257 //============================================================================== 258 259 FunType_CFStringCreateWithCString 260 = function(allocator:Pointer;const data:PChar;encoding:UINT):Pointer;cdecl; 261 262 263 enum_CFPropertyListMutabilityOptions = 264 ( 265 kCFPropertyListImmutable = 0, 266 kCFPropertyListMutableContainers = 1, 267 kCFPropertyListMutableContainersAndLeaves = 2 268 ); 269 270 FunType_CFPropertyListCreateFromXMLData 271 = function(allocator: Pointer; const xmlData: PChar; 272 optionFlags: enum_CFPropertyListMutabilityOptions; 273 errorString: PChar):Pointer;cdecl; 274 275 FunType_CFPropertyListCreateXMLData 276 = function(allocator: Pointer; propertyList: Pointer):PChar;cdecl; 277 278 implementation 279 280 end.
Demo源码下载(包含IOSDevice4Delphi全部代码)
For D7:下载
For XE2:下载
编译环境:
Windows7 with sp1 + Delphi7/XE2 + AppleMobileDeviceSupport
AppleMobileDeviceSupport 可以直接安装 iTunes 获得,也可以不安装 iTunes 仅安装如下支持包:
先安装这个:
http://itools.hk/appledrv/10.6.3_x32/AppleApplicationSupport.msi
然后安装这个(32bit/64bit操作系统自行选择)
http://itools.hk/appledrv/10.6.3_x32/AppleMobileDeviceSupport.msi
http://itools.hk/appledrv/10.6.3_x64/AppleMobileDeviceSupport64.msi
转载请注明地址:http://www.cnblogs.com/lahcs/archive/2013/04/19/3031172.html