storoj / libimobiledevice-win32

win32 port of libimobiledevice (http://libimobiledevice.org)
64 stars 61 forks source link

Enanle to use Mobilesync #18

Open vipinbeni opened 9 years ago

vipinbeni commented 9 years ago

Hi Sir,

I am using this library in my vc++ application for synchronization of contact and i want to list all contact from devices to my application on windows systems . i am using following code

int main(void) { int count, i, err; lockdownd_service_descriptor_t port = NULL; usbmuxd_device_info_t _devices; idevice_t idevice; idevice_connection_t connection; lockdownd_client_t ldclient; mobilesync_client_t sync_client = NULL; char host_id; err = usbmuxd_get_device_list(&devices); if(err != 1) { printf("usbmuxd_get_device_list error %d, exiting.\n", err); closeall(NULL, NULL, NULL, &devices); return 0; } for(count = 0; devices[count].handle > 0; count++); / First device only _/ err = idevice_new(&idevice, devices[0].udid); if(err != 0) { printf("idevice_new error %d, exiting.\n", err); close_all(NULL, NULL, idevice, &devices); return 0; } err = lockdownd_client_new_with_handshake(idevice, &ldclient, "mobilesync"); if(err != 0) { printf("lockdownd_client_new_with_handshake %d, exiting.\n", err); close_all(NULL, ldclient, idevice, &devices); return 0; } userpref_get_host_id(&host_id); err = lockdownd_start_service(ldclient, "com.apple.mobilesync", &port); if(err != 0) { printf("lockdownd_start_service %d, exiting.\n", err); close_all(NULL, ldclient, idevice, &devices); return 0; } err = mobilesync_client_new(idevice, port, &sync_client); if(err != 0) { printf("mobilesync_client_new %d, exiting.\n", err); close_all(sync_client, ldclient, idevice, &devices); return 0; } plist_t data = NULL; plist_t msg = NULL; plist_t responset = NULL; char * response; / Initial handshake _/ msg = plist_new_array(); plist_array_append_item(msg, plist_new_string("SDMessageSyncDataClassWithDevice")); plist_array_append_item(msg, plist_new_string("com.apple.Contacts")); plist_array_append_item(msg, plist_new_string("---")); plist_array_append_item(msg, plist_newstring("2013-07-29 22-34-00 00")); / plist_array_append_item(msg, plist_newstring("SDSyncTypeSlow")); / plist_array_append_item(msg, plist_new_uint(106)); plist_array_append_item(msg, plist_new_string("_EmptyParameterString_")); err = mobilesync_send(sync_client, msg); plist_free(msg); msg = NULL; if(err != 0) { printf("mobilesync_send %d, exiting.\n", err); close_all(sync_client, ldclient, idevice, &devices); return 0; } plist_free(msg); msg = NULL; err = mobilesync_receive(sync_client, &msg); if(err != 0) { printf("mobilesync_receive %d, exiting.\n", err); close_all(sync_client, ldclient, idevice, &devices); return 0; } response_t = plist_array_get_item(msg, 0); plist_get_string_val(response_t, &response); if(strcmp(response, "SDMessageSyncDataClassWithComputer") != 0) { close_all(sync_client, ldclient, idevice, &devices); return 0; } msg = plist_new_array(); plist_array_append_item(msg, plist_new_string("SDMessageGetAllRecordsFromDevice")); plist_array_append_item(msg, plist_new_string("com.apple.Contacts")); err = mobilesync_send(sync_client, msg); plist_free(msg); msg = NULL; if(err != 0) { printf("mobilesync_send %d, exiting.\n", err); close_all(sync_client, ldclient, idevice, &devices); return 0;; } char * xml = NULL; unsigned int xml_size; err = mobilesync_receive(sync_client, &msg); if(err != 0) { printf("mobilesync_receive %d, exiting.\n", err); close_all(syncclient, ldclient, idevice, &devices); return 0; } / both checks are voluntary _/ if(plist_getparent(msg) == NULL) / check whether it's a root node _/ if(plist_get_node_type(msg) == PLISTARRAY) / check whether root node is an array / plist_to_xml(msg, &xml, &xml_size); printf("%s\n", xml); close_all(sync_client, ldclient, idevice, &devices); return 0; }

But am not getting my contact in xml file .

instead when i am using com.apple.Bookmarks its work fine.

please correct me where i am going wrong please help as i am working on it from many days help me out pls.

Thanks

vipinbeni commented 9 years ago

@airwolf2026 Sir Thanks for your help on contact sync.But how can we sync photo and music to iphone pls guide me as i am placing them using afc but they are not synchronize with iphone i want to sync them as i tunes select a folder and put all image to iphone.

thanks vipin

airwolf2026 commented 9 years ago

Hi, If you want to sync photos to idevice,you should know ATC(ath.exe) protocol,not just afc...

Use the tool Bus Hound to analyse the atc protocol.

vipinbeni commented 9 years ago

Dear Sir , could you pls tell me more where i found detail about ATC ath.exe protocol or how cal i use this tool as you previously also tell me Bus Hound but i am not able to use it to analyses the protocol. give me brief how i use this tool pls Sir Help me to use this tool or give me detail how can i use ath.exe .

thanks a lot

airwolf2026 commented 9 years ago

Sorry,This is too complicated to explain.See Bus Hound's help Doc

vipinbeni commented 9 years ago

Sir i have already install it in machine but i am not able to know how can i use it for analysis . is it is this perisoft.net/bushound/

Dear Sir could you give me a little example about use of ath.exe what parameter is passes to it

vipinbeni commented 9 years ago

Hi Sir actually i don't understand how to use ATH.exe it don't show any argument --help

prateek1108 commented 9 years ago

hello sir, Even i want to do same thing as discussed regarding ATH.exe (i.e. syncing photos to iPhone) and i had tried Bus Hound's software but i didn't get how to properly use that or what arguments i must give to ath.exe to sync photo's with iphone... Please Sir can you please give argument example for Ath.exe its really a big help for me ..... And thank a tone for guiding me a ragrding a way to do my work

airwolf2026 commented 9 years ago

You need another tool IDA,Or OD to reverse the ath.exe.

prateek1108 commented 9 years ago

Thank u sir , i had tried the tool IDA as per your guidance, this software shows the internal structure and functions in this exe......its very complicated for me to get my solution.... Sir Can u please give me example of ATH.exe Command line argument to sync photos stored in D:\ in computer with iphone connected by usb...........

vipinbeni commented 9 years ago

Hi Sir, What is three staring parameter in _main function method of this . first is int and two other is char * type what value we have to pass on it

pls help sir .

airwolf2026 commented 9 years ago

these parameter are named pipe.... you can't call ath.exe to sync photos,see AirTrafficHost.dll in ida.

prateek1108 commented 9 years ago

hello sir, Thank alot for replying me , By using IDA i am able get the list of all functions available in Airtraffichost.dll , but sir i am not getting how the function i will call or in which sequence i will call function and how that ath.exe will be call ..........Can You please provide me step or sample code to use Airtarffichost.dll...........................thank for replying me and please sir your help is very much precious for me ...

airwolf2026 commented 9 years ago

Call Airtraffichost.dll's func "ATHostConnectionCreateWithLibrary" to start ath.exe ...

Other sequence use the OD to debug the iTunes process photo syncs

vipinbeni commented 9 years ago

Dear Sir , Is there is a sample code in any language for this any open source or example source available as we found itunesmobiledevices.dll sample and source at net but i can not find any header information of ATHostConnectionCreateWithLibrary function structure and type of argument passed in it ad we found in mobiledevice.h avialable in many sample

where i got structure of this Airtraffichost.dll functions.

thanks a lot sir

airwolf2026 commented 9 years ago

Sorry,there is no example or open source. you need reverse engineering to process these protocol

vipinbeni commented 9 years ago

Its Ok Sir Please let me how how can i start this please guide me

what is the process i follow and how can i call Call Airtraffichost.dll's func "ATHostConnectionCreateWithLibrary" without knowing its structure

pls help me to start in reverse engineering of this process .

thanks a lot.

prateek1108 commented 9 years ago

thank you sir ,I had opened Airtraffichost.dll's func "ATHostConnectionCreateWithLibrary" in IDA tool and put a break point in this function......and started sync photos through itunes but my handle is not coming to break point i had applied...........is i am doing anything wrong in this step.

prateek1108 commented 9 years ago

Hello Sir, Please provide me the steps to follow regarding how to use and get the desired output by Airtraffichost.dll's func "ATHostConnectionCreateWithLibrary"

airwolf2026 commented 9 years ago

The ATHostConnectionCreateWithLibrary func is the easy to analyse between a lot of iTunes's private func. If you can't analyse the args, how about other funcs?

prateek1108 commented 9 years ago

hello sir, I found this command is given to ath.exe on command line: "C:\Program Files\Common Files\Apple\Mobile Device Support\ATH.exe" --pipe .\pipe\30405054-351489484413192R .\pipe\30405054-351489484413192W --target 26990a955a3411800ebeb51969eb1fadd783c8b2 I just want to know how this pipeline would be create is it create by general code of pipeline or any specific code is there to make pipeline for ath.exe......

airwolf2026 commented 9 years ago

don't need to know the detail, you just call ATHostConnectionCreateWithLibrary , the func will maintain the pipeline.

vipinbeni commented 9 years ago

Dear Sir could you create a Little sample code for me as i try a lot but not succeed till now how we can call these func pls help sir.

thanks a lot

prateek1108 commented 9 years ago

hello sir, Even i am trying from my side and also searched on net for this function(ATHostConnectionCreateWithLibrary) but i didn't get anything help to do my work ....please sir it would be really a a big help for me if you can provide a sample code to do my desired work ....

vipinbeni commented 9 years ago

Dear Sir could you create a Little sample code for how call this ATHostConnectionCreateWithLibrary function pls sir give me a little sample code pls help me

Thanks a lot .

vipinbeni commented 9 years ago

Dear Sir, could you please help me here as i want to know that detail of some other library https://github.com/fadingred/libgpod fadingred/libgpod can i use this as in this we found about iTunes .PhotoDB and iTunesCDB can this help us to insert photo and music to iPhone

please reply sir or give as any other help to do this please please please ............

thanks

airwolf2026 commented 9 years ago

If you want to see musics in PC iTunes,when Insert music to iPhone need to write iTunesCDB.

vipinbeni commented 9 years ago

Respected Sir , little more explanation i need

how can i insert music to iphone using this as i want to insert music using this and libimobiledevice-win32 to iphone. or can we insert photo using PhotoDB classes of this sample. i am using source from here http://code.h4ck.org.cn/libgpod-0.8.3-for-windows/src please sir give me a direction please.

help me sir .

airwolf2026 commented 9 years ago

Insert music or photo(not the camera photo) are all use ath.exe from iOS5.0

iTunesCDB just show the music info to iTunes(in my opinion)

vipinbeni commented 9 years ago

Dear Sir ,

Thanks for your quick Reply but please lead us how we use ath.exe please provide me to way in c/ c++ where i found header structre whel load these dll using loadlibrary method and pointer of function is needde to Call Airtraffichost.dll's func "

ATHostConnectionCreateWithLibrary"

lease write a small sample for us as we required it at any cost sir.

Please help us Sir

Please please ..............

On Tue, Nov 11, 2014 at 1:58 PM, airwolf2026 notifications@github.com wrote:

Insert music or photo(not the camera photo) are all use ath.exe from iOS5.0

iTunesCDB just show the music info to iTunes(in my opinion)

— Reply to this email directly or view it on GitHub https://github.com/storoj/libimobiledevice-win32/issues/18#issuecomment-62516202 .

Thanks Vipin Kumar Beniwal

airwolf2026 commented 9 years ago

Hi,vipinbeni

CFString iTunesPrefsID = CFStringMakeConstantString("iTunesPrefsID");
CFString deviceUDID= CFStringMakeConstantString("UDID");
Handle athHandle = ATHostConnectionCreateWithLibrary(iTunesPrefsID ,deviceUDID,NULL);
if(athHandle!=Invalid)
{
   SendPowerAssertion(athHandle);//blabla
}

Use IDA and OD to get other functions struct...

airwolf2026 commented 9 years ago

Sorry,vipinbeni I didn't have a full solution.I just know about the process.

vipinbeni commented 9 years ago

Respected Sir ,

Could you pls provide full process in detail and how to get structure of function using iDA and OD as i am trying but not succeeded till today. could you do some work to help me out here .

a lot of thanks.

prateek1108 commented 9 years ago

hello sir, I had also tried this code as per your guidance, can you please provide me the C++ structures for functions in this dll. i had also check the dll in IDA and OD, But i need the structure as in libimobiledevice code the structure are there in mobiledevice,h. Please help me out regarding it would really a big help for me.....please help me out

vipinbeni commented 9 years ago

i am using this way but get error no 2 could not connect to parent

      ================

[6716 @ Sat Dec 28 18:09:32 2013] [YSLoader ATH.exe] parent process: 6740 "iTunes.exe"

[6716 @ Sat Dec 28 18:09:32 2013] [YSLoader ATH.exe] main thread 6300

[6716 @ Sat Dec 28 18:09:32 2013] [YSLoader ATH.exe] command line: "C:\Program Files (x86)\Common Files\Apple\Mobile Device Support\ATH.exe" --pipe .\pipe\30344133-1433379007416740R .\pipe\30344133-1433379007416740W --target 7e282630f37079c20d7db3e48efcefb86f2f44f6 --library 88D5E3B913AA9672

airwolf2026 commented 9 years ago

Hi,vipinbeni

If i have time i would write a sample code about "com.apple.atc" service like Libimobilelib on github. "com.apple.atc" service running on iOS device from iOS 5.0, which comunicate with ATH.exe

showman123 commented 9 years ago

Hi sr, In this line Handle athHandle = ATHostConnectionCreateWithLibrary(iTunesPrefsID,deviceUDID,NULL); where i get the value of iTunesPrefsID.I try to find this value but could not any specific solution Please guid me to the value of iTunesPrefsID

airwolf2026 commented 9 years ago

The iTunesPrefsID is in the file "iTunes_Control/iTunes/iTunesPrefs" ,which is on device

showman123 commented 9 years ago

Hi sir Thankyou for your quick reply i had already search iTunesPrefsID in iTunesPrefs and iTunesPrefs.plist please sir can you tell me exactly where is iTunesPrefsID in iTunesPrefs

showman123 commented 9 years ago

Hi sir, After searching i found that iTunesPrefsID is working as --library parameter for ath.exe but still can't find iTunesPrefsID parameter.Please guide me to find it

airwolf2026 commented 9 years ago

Sorry,I've made a mistake,LibraryID is "iTunesPrefsID "

vipinbeni commented 9 years ago

@airwolf2026 Sir I will wait and try till you write a sample code about "com.apple.atc"

showman123 commented 9 years ago

hi sr, Please give me some hint about where can i get this LibraryID.

showman123 commented 9 years ago

Sir, ATHostConnectionCreateWithLibrary() function execute successfully.But i can't find how to pass song data for insert into iphone.Please help me.I really need this.

airwolf2026 commented 9 years ago

Hi ,showman, After call ATHostConnectionCreateWithLibrary function,you need to call ATHostSendPowerAssertion to device, then you should receive "SyncAllowed",after that call ATHostSendSyncRequest() ....blabla

showman123 commented 9 years ago

k Thanks Sir I will try this and get back to you Thanks a lot.

showman123 commented 9 years ago

Hi sir, Handle athHandle = ATHostConnectionCreateWithLibrary(iTunesPrefsID ,deviceUDID,NULL); unsigned char* str; str=ATHostConnectionSendPowerAssertion(athHandle,NULL,NULL)); It gives me exception.I don't know what i am doing wrong.I am also pass UUID as third parameter but again it gives exception.Please help me to figure it out

showman123 commented 9 years ago

hi sr, I am also passing LibraryID as second parameter and then exception gone but there is no result.Please give me some hint

airwolf2026 commented 9 years ago

int errorCode = ATHostConnectionSendPowerAssertion(athHandle);

showman123 commented 9 years ago

Sir , HANDLE rt=NULL; rt=ATHostConnectionCreateWithLibrary(pftypeCFStringMakeConstantString2("5C2514F04405CBE7"),pftypeCFStringMakeConstantString2("0945eb63dd8441f23beaa7ee173d8bf88a0c8e43"),NULL); if(rt) { int errorcode; errorcode=ATHostConnectionSendPowerAssertion(rt); } Here ATHostConnectionSendPowerAssertion(rt) gives access voilation exeception.Please guide me where i am wrong Thankyou sir

airwolf2026 commented 9 years ago

Sorry, I made a mistake,ATHostConnectionSendPowerAssertion has two args. The first one is handle, the second one is a CFBoolean