integrato ;)
iTunesBackupRestore Versione 1.0.1
Codice sorgente e informazioni dettagliate

 
Sorgente:
 
Come avevo già annunciato al rilascio della versione precedente da ora in poi sarà pubblicata la parte chiave del codice sorgente del programma, ovvero le funzioni di conversione dei backups (ora aggiornate e compatibili con tutti firmware/versioni di iTunes):

Ricerca RAW in array:
  1. char *find_str_in_data(char *data, size_t data_len,char *query,size_t query_len)
  2. {
  3. char *p = data;
  4. while (1)
  5. {
  6. if (data + data_len - p < query_len)
  7. break;
  8.  
  9. if (*p == query[0])
  10. {
  11. if (memcmp(p, query, query_len) == 0)
  12. return p;
  13. }
  14. p++;
  15. }
  16. return NULL;
  17. }
File originali xml
  1. BOOL ConvertBackupToXml(char *BkFile,char *xmlFile)
  2. {
  3. FILE *in,*out;
  4. long lSize,bufferOutDIM,stopPOS;
  5. char *bufferIn,*bufferOut,*stop;
  6.  
  7. in = fopen(BkFile,"rb");
  8. if (!in)
  9. {
  10. #ifdef _DEBUGGING_
  11. fprintf(debu,"ConvertBackupToXml() in == NULL\n");
  12. #endif
  13. return FALSE;
  14. }
  15.  
  16. fseek (in , 0 , SEEK_END);
  17. lSize = ftell(in);
  18. rewind (in);
  19. bufferIn = (char*) malloc (sizeof(char)*lSize);
  20. bufferOut = (char*) malloc (sizeof(char)*lSize);
  21.  
  22. fread (bufferIn,1,lSize,in);
  23.  
  24. bufferOut = find_str_in_data(bufferIn, lSize, "<?xml",5);
  25.  
  26. if (bufferOut == NULL)
  27. {
  28. #ifdef _DEBUGGING_
  29. fprintf(debu,"ConvertBackupToXml() bufferOut == NULL\n");
  30. #endif
  31. return FALSE;
  32. }
  33.  
  34. bufferOutDIM = lSize-(bufferOut-bufferIn);
  35.  
  36. stop = find_str_in_data(bufferOut,bufferOutDIM,"</plist>",8);
  37. stopPOS = stop-bufferOut+9;
  38.  
  39. if (stop == NULL)
  40. {
  41. #ifdef _DEBUGGING_
  42. fprintf(debu,"ConvertBackupToXml() stop == NULL\n");
  43. #endif
  44. return FALSE;
  45. }
  46.  
  47. out = fopen(xmlFile,"wb");
  48. if (!out)
  49. {
  50. #ifdef _DEBUGGING_
  51. fprintf(debu,"ConvertBackupToXml() out == NULL\n");
  52. #endif
  53. return FALSE;
  54. }
  55.  
  56. fwrite (bufferOut , 1 , stopPOS , out );
  57. fclose(in);
  58. fclose(out);
  59. return TRUE;
  60. }
File originali plist
  1. BOOL ConvertBackupTopList(char* BkFile,char *pListFile)
  2. {
  3. FILE *in,*out;
  4. long lSize,bufferOutDIM,stopPOS;
  5. char *bufferIn,*bufferOut,*stop;
  6. char end[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7. 0x00,0x00,0x00,0x00,0x00,0x00,0x01}; //default
  8. char end2[] = {0x00,0x08,0x00,0x13,0x00,0x18,0x00,0x20,
  9. 0x00}; //iTunes 8-1
  10. char end_7[] = {0x00,0x08,0x00,0x11,0x00,0x16,0x00,0x1E,
  11. 0x00}; //iTunes 7
  12. char end_71[] = {0x00,0x00,0x08,0x00,0x00,0x11,0x00,0x00,
  13. 0x16,0x00,0x00,0x1E}; //iTunes 7-1
  14. char end_empty[] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  15. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16. 0x09}; //empty bookmarks
  17. char end_empty1[] = {0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  18. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  19. 0x3A}; //empty history
  20.  
  21. in = fopen(BkFile,"rb");
  22. if (!in)
  23. {
  24. #ifdef _DEBUGGING_
  25. fprintf(debu,"ConvertBackupTopList() in == NULL\n");
  26. #endif
  27. return FALSE;
  28. }
  29.  
  30. fseek (in , 0 , SEEK_END);
  31. lSize = ftell(in);
  32. rewind (in);
  33. bufferIn = (char*) malloc (sizeof(char)*lSize);
  34. bufferOut = (char*) malloc (sizeof(char)*lSize);
  35.  
  36. fread (bufferIn,1,lSize,in);
  37.  
  38. bufferOut = find_str_in_data(
  39. find_str_in_data(
  40. find_str_in_data(bufferIn, lSize, "plist",5),
  41. lSize, "plist",5),
  42. lSize, "bplist",6);
  43.  
  44. if (bufferOut == NULL)
  45. {
  46. #ifdef _DEBUGGING_
  47. fprintf(debu,"ConvertBackupTopList() bufferOut == NULL\n");
  48. #endif
  49.  
  50. return FALSE;
  51. }
  52.  
  53. bufferOutDIM = lSize-(bufferOut-bufferIn);
  54.  
  55. stop = find_str_in_data(bufferOut,bufferOutDIM,end,15); //default
  56. stopPOS = stop-bufferOut+16;
  57.  
  58.  
  59. if (stop == NULL)
  60. {
  61. stop = find_str_in_data(bufferOut,bufferOutDIM,end2,9);
  62. stopPOS = stop-bufferOut;
  63.  
  64. if (stop == NULL) // S1.20
  65. {
  66. stop = find_str_in_data(bufferOut,bufferOutDIM,end_7,9);
  67. stopPOS = stop-bufferOut;
  68.  
  69. if (stop == NULL)
  70. {
  71. stop = find_str_in_data(bufferOut,bufferOutDIM,end_71,12);
  72. stopPOS = stop-bufferOut;
  73.  
  74. if (stop == NULL)
  75. {
  76. stop = find_str_in_data(bufferOut,bufferOutDIM,end_empty,17);
  77. stopPOS = stop-bufferOut+17; //included
  78.  
  79. if (stop == NULL)
  80. {
  81. stop = find_str_in_data(bufferOut,bufferOutDIM,end_empty1,17);
  82. stopPOS = stop-bufferOut+17; //included
  83.  
  84. if (stop == NULL)
  85. {
  86. #ifdef _DEBUGGING_
  87. fprintf(debu,"ConvertBackupTopList() stop == NULL\n");
  88. #endif
  89. return FALSE; //failed :(
  90. }
  91. }
  92. }
  93. }
  94. }
  95. }
  96.  
  97. out = fopen(pListFile,"wb");
  98. if (!out)
  99. {
  100. #ifdef _DEBUGGING_
  101. fprintf(debu,"ConvertBackupTopList() out == NULL\n");
  102. #endif
  103. return FALSE;
  104. }
  105.  
  106. fwrite (bufferOut , 1 , stopPOS , out );
  107. fclose(in);
  108. fclose(out);
  109.  
  110. return TRUE;
  111. }
File originali sql3lite
  1. BOOL ConvertBackupToSQL3(char *BkFile, char * SQL3File)
  2. {
  3. FILE *in,*out;
  4. long lSize,bufferOutDIM,stopPOS;
  5. char *bufferIn,*bufferOut,*stop,c;
  6. //check backup version
  7. BOOL iTunes7 = TRUE;
  8.  
  9. char end[] = {0x00,0x08,0x00,0x11,0x00,0x16,0x00,0x1E,
  10. 0x00}; //iTunes 7
  11. char end_1[] = {0x00,0x00,0x08,0x00,0x00,0x11,0x00,0x00,
  12. 0x16,0x00,0x00,0x1E}; //iTunes 7-1
  13. char end2[] = {0x00,0x08,0x00,0x13,0x00,0x18,0x00,0x20,
  14. 0x00}; //iTunes 8
  15. char end2_1[] = {0x00,0x00,0x08,0x00,0x00,0x13,0x00,0x00,
  16. 0x18,0x00,0x00,0x20}; //iTunes 8-1
  17.  
  18. in = fopen(BkFile,"rb");
  19. if (!in)
  20. {
  21. #ifdef _DEBUGGING_
  22. fprintf(debu,"ConvertBackupToSQL3() in == NULL\n");
  23. #endif
  24. return FALSE;
  25. }
  26.  
  27. fseek (in , 17 , SEEK_SET);
  28. c = fgetc(in);
  29. if ((int)c == 0x09)
  30. {
  31. c = fgetc(in);
  32. if ((int)c == 0x0A)
  33. iTunes7 = FALSE; // iTunes8
  34.  
  35. }
  36.  
  37. fseek (in , 0 , SEEK_END);
  38. lSize = ftell (in);
  39. rewind (in);
  40. bufferIn = (char*) malloc (sizeof(char)*lSize);
  41. bufferOut = (char*) malloc (sizeof(char)*lSize);
  42. fread (bufferIn,1,lSize,in);
  43.  
  44. bufferOut = find_str_in_data(bufferIn, lSize, "SQLite format 3",15);
  45.  
  46. if (bufferOut == NULL)
  47. {
  48. #ifdef _DEBUGGING_
  49. fprintf(debu,"ConvertBackupToSQL3() bufferOut == NULL\n");
  50. #endif
  51. return FALSE;
  52. }
  53.  
  54. bufferOutDIM = lSize-(bufferOut-bufferIn);
  55.  
  56. if (iTunes7)
  57. {
  58. stop = find_str_in_data(bufferOut,bufferOutDIM,end,9); //iTunes 7
  59. if (stop == NULL)
  60. stop = find_str_in_data(bufferOut,bufferOutDIM,end_1,12); //iTunes 7-1
  61. }
  62. else
  63. {
  64. stop = find_str_in_data(bufferOut,bufferOutDIM,end2,9); //iTunes 8
  65. if (stop == NULL)
  66. stop = find_str_in_data(bufferOut,bufferOutDIM,end2_1,12); //iTunes 8-1
  67. }
  68.  
  69.  
  70. if (stop == NULL) //failed :(
  71. {
  72. #ifdef _DEBUGGING_
  73. fprintf(debu,"ConvertBackupToSQL3() stop == NULL\n");
  74. #endif
  75. return FALSE;
  76. }
  77.  
  78. stopPOS = stop-bufferOut;
  79.  
  80. out = fopen(SQL3File,"wb");
  81. if (!out)
  82. {
  83. #ifdef _DEBUGGING_
  84. fprintf(debu,"ConvertBackupToSQL3() out == NULL\n");
  85. #endif
  86. return FALSE;
  87. }
  88.  
  89. fwrite (bufferOut , 1 , stopPOS , out );
  90. fclose(in);
  91. fclose(out);
  92.  
  93. return TRUE;
  94. }
Queste funzioni devono essere richiamate per converite i file presenti nella cartella di backup dal formato .mdbackup al formato originario.
Per identificare quali file del backup *.mdbackup corrispondono alla relativa impostazione fare riferimento alla.
La tabella sottostante invece riporta il metodo di conversione richiesto da ogni impostazione con il relativo nome originario. Per la posizione dei file convertiti all'interno del firmware iPhone fare sempre riferimento alla.
Impostazioni
Funzione di conversione
Nome originario
Chiamate
ConvertBackupToSQL3()
call_history.db
SMS
ConvertBackupToSQL3()
sms.db
Contatti
ConvertBackupToSQL3()
AddressBook.sqlitedb
Contatti (Immagini)
ConvertBackupToSQL3()
AddressBookImages.sqlitedb
Calendario
ConvertBackupToSQL3()
Calendar.sqlitedb
Note
ConvertBackupToSQL3()
notes.db
Safari Bookmarks
ConvertBackupTopList() (firmware 2.x.x) oppure ConvertBackupToXml() (firmware 1.x.x)
Bookmarks.plist
Safari History
ConvertBackupTopList() (firmware 2.x.x) oppure ConvertBackupToXml() (firmware 1.x.x)
History.plist
Safari SuspendState
ConvertBackupTopList() (firmware 2.x.x) oppure ConvertBackupToXml() (firmware 1.x.x)
SuspendState.plist
TouTube Bookmarks
ConvertBackupTopList() (firmware 2.x.x) oppure ConvertBackupToXml() (firmware 1.x.x)
Bookmarks.plist
Account Mail
ConvertBackupToXml() (firmware 2.x.x) oppure ConvertBackupTopList() (firmware 1.x.x)
Accounts.plist
WiFi1
ConvertBackupToXml()
com.apple.network.identification.plist
WiFi2
ConvertBackupToXml()
com.apple.wifi.plist
Password WiFi e Mail
ConvertBackupToSQL3()
keychain-2.db

 
Download Sorgenti:
 

 
iTunesBackupRestore librerie e file utilizzati:
 
In questa versione, per il supporto multilingua, è stato aggiunto l'utilizzo della classe.

Script Execution Time: 0.0485 seconds - Visite: 667949
Copyright © 2007-2018 Suondmao v0.1.5-1