diff options
| -rw-r--r-- | src/ideviceinstaller.c | 124 |
1 files changed, 79 insertions, 45 deletions
diff --git a/src/ideviceinstaller.c b/src/ideviceinstaller.c index f45326f..5709b58 100644 --- a/src/ideviceinstaller.c +++ b/src/ideviceinstaller.c | |||
| @@ -657,6 +657,7 @@ int main(int argc, char **argv) | |||
| 657 | 657 | ||
| 658 | if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &client, "ideviceinstaller")) { | 658 | if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &client, "ideviceinstaller")) { |
| 659 | fprintf(stderr, "Could not connect to lockdownd. Exiting.\n"); | 659 | fprintf(stderr, "Could not connect to lockdownd. Exiting.\n"); |
| 660 | res = -1; | ||
| 660 | goto leave_cleanup; | 661 | goto leave_cleanup; |
| 661 | } | 662 | } |
| 662 | 663 | ||
| @@ -665,6 +666,7 @@ int main(int argc, char **argv) | |||
| 665 | &service) != LOCKDOWN_E_SUCCESS) || !service) { | 666 | &service) != LOCKDOWN_E_SUCCESS) || !service) { |
| 666 | fprintf(stderr, | 667 | fprintf(stderr, |
| 667 | "Could not start com.apple.mobile.notification_proxy!\n"); | 668 | "Could not start com.apple.mobile.notification_proxy!\n"); |
| 669 | res = -1; | ||
| 668 | goto leave_cleanup; | 670 | goto leave_cleanup; |
| 669 | } | 671 | } |
| 670 | 672 | ||
| @@ -677,6 +679,7 @@ int main(int argc, char **argv) | |||
| 677 | 679 | ||
| 678 | if (nperr != NP_E_SUCCESS) { | 680 | if (nperr != NP_E_SUCCESS) { |
| 679 | fprintf(stderr, "Could not connect to notification_proxy!\n"); | 681 | fprintf(stderr, "Could not connect to notification_proxy!\n"); |
| 682 | res = -1; | ||
| 680 | goto leave_cleanup; | 683 | goto leave_cleanup; |
| 681 | } | 684 | } |
| 682 | 685 | ||
| @@ -696,6 +699,7 @@ run_again: | |||
| 696 | &service) != LOCKDOWN_E_SUCCESS) || !service) { | 699 | &service) != LOCKDOWN_E_SUCCESS) || !service) { |
| 697 | fprintf(stderr, | 700 | fprintf(stderr, |
| 698 | "Could not start com.apple.mobile.installation_proxy!\n"); | 701 | "Could not start com.apple.mobile.installation_proxy!\n"); |
| 702 | res = -1; | ||
| 699 | goto leave_cleanup; | 703 | goto leave_cleanup; |
| 700 | } | 704 | } |
| 701 | 705 | ||
| @@ -708,6 +712,7 @@ run_again: | |||
| 708 | 712 | ||
| 709 | if (err != INSTPROXY_E_SUCCESS) { | 713 | if (err != INSTPROXY_E_SUCCESS) { |
| 710 | fprintf(stderr, "Could not connect to installation_proxy!\n"); | 714 | fprintf(stderr, "Could not connect to installation_proxy!\n"); |
| 715 | res = -1; | ||
| 711 | goto leave_cleanup; | 716 | goto leave_cleanup; |
| 712 | } | 717 | } |
| 713 | 718 | ||
| @@ -760,6 +765,7 @@ run_again: | |||
| 760 | if (!apps || (plist_get_node_type(apps) != PLIST_ARRAY)) { | 765 | if (!apps || (plist_get_node_type(apps) != PLIST_ARRAY)) { |
| 761 | fprintf(stderr, | 766 | fprintf(stderr, |
| 762 | "ERROR: instproxy_browse returnd an invalid plist!\n"); | 767 | "ERROR: instproxy_browse returnd an invalid plist!\n"); |
| 768 | res = -1; | ||
| 763 | goto leave_cleanup; | 769 | goto leave_cleanup; |
| 764 | } | 770 | } |
| 765 | 771 | ||
| @@ -785,6 +791,7 @@ run_again: | |||
| 785 | instproxy_client_options_free(client_opts); | 791 | instproxy_client_options_free(client_opts); |
| 786 | if (err != INSTPROXY_E_SUCCESS) { | 792 | if (err != INSTPROXY_E_SUCCESS) { |
| 787 | fprintf(stderr, "ERROR: instproxy_browse returned %d\n", err); | 793 | fprintf(stderr, "ERROR: instproxy_browse returned %d\n", err); |
| 794 | res = -1; | ||
| 788 | goto leave_cleanup; | 795 | goto leave_cleanup; |
| 789 | } | 796 | } |
| 790 | 797 | ||
| @@ -804,6 +811,7 @@ run_again: | |||
| 804 | if ((lockdownd_start_service(client, "com.apple.afc", &service) != | 811 | if ((lockdownd_start_service(client, "com.apple.afc", &service) != |
| 805 | LOCKDOWN_E_SUCCESS) || !service) { | 812 | LOCKDOWN_E_SUCCESS) || !service) { |
| 806 | fprintf(stderr, "Could not start com.apple.afc!\n"); | 813 | fprintf(stderr, "Could not start com.apple.afc!\n"); |
| 814 | res = -1; | ||
| 807 | goto leave_cleanup; | 815 | goto leave_cleanup; |
| 808 | } | 816 | } |
| 809 | 817 | ||
| @@ -812,11 +820,13 @@ run_again: | |||
| 812 | 820 | ||
| 813 | if (afc_client_new(device, service, &afc) != AFC_E_SUCCESS) { | 821 | if (afc_client_new(device, service, &afc) != AFC_E_SUCCESS) { |
| 814 | fprintf(stderr, "Could not connect to AFC!\n"); | 822 | fprintf(stderr, "Could not connect to AFC!\n"); |
| 823 | res = -1; | ||
| 815 | goto leave_cleanup; | 824 | goto leave_cleanup; |
| 816 | } | 825 | } |
| 817 | 826 | ||
| 818 | if (stat(appid, &fst) != 0) { | 827 | if (stat(appid, &fst) != 0) { |
| 819 | fprintf(stderr, "ERROR: stat: %s: %s\n", appid, strerror(errno)); | 828 | fprintf(stderr, "ERROR: stat: %s: %s\n", appid, strerror(errno)); |
| 829 | res = -1; | ||
| 820 | goto leave_cleanup; | 830 | goto leave_cleanup; |
| 821 | } | 831 | } |
| 822 | 832 | ||
| @@ -845,6 +855,7 @@ run_again: | |||
| 845 | zf = zip_open(appid, 0, &errp); | 855 | zf = zip_open(appid, 0, &errp); |
| 846 | if (!zf) { | 856 | if (!zf) { |
| 847 | fprintf(stderr, "ERROR: zip_open: %s: %d\n", appid, errp); | 857 | fprintf(stderr, "ERROR: zip_open: %s: %d\n", appid, errp); |
| 858 | res = -1; | ||
| 848 | goto leave_cleanup; | 859 | goto leave_cleanup; |
| 849 | } | 860 | } |
| 850 | 861 | ||
| @@ -917,6 +928,7 @@ run_again: | |||
| 917 | afc_file_close(afc, af); | 928 | afc_file_close(afc, af); |
| 918 | zip_fclose(zfile); | 929 | zip_fclose(zfile); |
| 919 | free(dstpath); | 930 | free(dstpath); |
| 931 | res = -1; | ||
| 920 | goto leave_cleanup; | 932 | goto leave_cleanup; |
| 921 | } | 933 | } |
| 922 | } | 934 | } |
| @@ -940,6 +952,7 @@ run_again: | |||
| 940 | 952 | ||
| 941 | if (asprintf(&pkgname, "%s/%s", PKG_PATH, basename(appid)) < 0) { | 953 | if (asprintf(&pkgname, "%s/%s", PKG_PATH, basename(appid)) < 0) { |
| 942 | fprintf(stderr, "ERROR: Out of memory allocating pkgname!?\n"); | 954 | fprintf(stderr, "ERROR: Out of memory allocating pkgname!?\n"); |
| 955 | res = -1; | ||
| 943 | goto leave_cleanup; | 956 | goto leave_cleanup; |
| 944 | } | 957 | } |
| 945 | 958 | ||
| @@ -947,55 +960,59 @@ run_again: | |||
| 947 | afc_upload_dir(afc, appid, pkgname); | 960 | afc_upload_dir(afc, appid, pkgname); |
| 948 | printf("DONE.\n"); | 961 | printf("DONE.\n"); |
| 949 | 962 | ||
| 950 | /* extract the CFBundleIdentifier from the package */ | 963 | /* extract the CFBundleIdentifier from the package */ |
| 951 | 964 | ||
| 952 | /* construct full filename to Info.plist */ | 965 | /* construct full filename to Info.plist */ |
| 953 | char *filename = (char*)malloc(strlen(appid)+10+1); | 966 | char *filename = (char*)malloc(strlen(appid)+10+1); |
| 954 | strcpy(filename, appid); | 967 | strcpy(filename, appid); |
| 955 | strcat(filename, "/Info.plist"); | 968 | strcat(filename, "/Info.plist"); |
| 956 | 969 | ||
| 957 | struct stat st; | 970 | struct stat st; |
| 958 | FILE *fp = NULL; | 971 | FILE *fp = NULL; |
| 959 | 972 | ||
| 960 | if (stat(filename, &st) == -1 || (fp = fopen(filename, "r")) == NULL) { | 973 | if (stat(filename, &st) == -1 || (fp = fopen(filename, "r")) == NULL) { |
| 961 | fprintf(stderr, "ERROR: could not locate %s in app!\n", filename); | 974 | fprintf(stderr, "ERROR: could not locate %s in app!\n", filename); |
| 962 | free(filename); | 975 | free(filename); |
| 963 | goto leave_cleanup; | 976 | res = -1; |
| 964 | } | 977 | goto leave_cleanup; |
| 965 | size_t filesize = st.st_size; | 978 | } |
| 966 | char *ibuf = malloc(filesize * sizeof(char)); | 979 | size_t filesize = st.st_size; |
| 967 | size_t amount = fread(ibuf, 1, filesize, fp); | 980 | char *ibuf = malloc(filesize * sizeof(char)); |
| 968 | if (amount != filesize) { | 981 | size_t amount = fread(ibuf, 1, filesize, fp); |
| 969 | fprintf(stderr, "ERROR: could not read %ld bytes from %s\n", filesize, filename); | 982 | if (amount != filesize) { |
| 970 | free(filename); | 983 | fprintf(stderr, "ERROR: could not read %ld bytes from %s\n", filesize, filename); |
| 971 | goto leave_cleanup; | 984 | free(filename); |
| 972 | } | 985 | res = -1; |
| 973 | fclose(fp); | 986 | goto leave_cleanup; |
| 974 | free(filename); | 987 | } |
| 975 | 988 | fclose(fp); | |
| 976 | plist_t info = NULL; | 989 | free(filename); |
| 977 | if (memcmp(ibuf, "bplist00", 8) == 0) { | 990 | |
| 978 | plist_from_bin(ibuf, filesize, &info); | 991 | plist_t info = NULL; |
| 979 | } else { | 992 | if (memcmp(ibuf, "bplist00", 8) == 0) { |
| 980 | plist_from_xml(ibuf, filesize, &info); | 993 | plist_from_bin(ibuf, filesize, &info); |
| 981 | } | 994 | } else { |
| 982 | free(ibuf); | 995 | plist_from_xml(ibuf, filesize, &info); |
| 983 | 996 | } | |
| 984 | if (!info) { | 997 | free(ibuf); |
| 985 | fprintf(stderr, "ERROR: could not parse Info.plist!\n"); | 998 | |
| 986 | goto leave_cleanup; | 999 | if (!info) { |
| 987 | } | 1000 | fprintf(stderr, "ERROR: could not parse Info.plist!\n"); |
| 988 | 1001 | res = -1; | |
| 989 | plist_t bname = plist_dict_get_item(info, "CFBundleIdentifier"); | 1002 | goto leave_cleanup; |
| 990 | if (bname) { | 1003 | } |
| 991 | plist_get_string_val(bname, &bundleidentifier); | 1004 | |
| 992 | } | 1005 | plist_t bname = plist_dict_get_item(info, "CFBundleIdentifier"); |
| 993 | plist_free(info); | 1006 | if (bname) { |
| 994 | info = NULL; | 1007 | plist_get_string_val(bname, &bundleidentifier); |
| 1008 | } | ||
| 1009 | plist_free(info); | ||
| 1010 | info = NULL; | ||
| 995 | } else { | 1011 | } else { |
| 996 | zf = zip_open(appid, 0, &errp); | 1012 | zf = zip_open(appid, 0, &errp); |
| 997 | if (!zf) { | 1013 | if (!zf) { |
| 998 | fprintf(stderr, "ERROR: zip_open: %s: %d\n", appid, errp); | 1014 | fprintf(stderr, "ERROR: zip_open: %s: %d\n", appid, errp); |
| 1015 | res = -1; | ||
| 999 | goto leave_cleanup; | 1016 | goto leave_cleanup; |
| 1000 | } | 1017 | } |
| 1001 | 1018 | ||
| @@ -1024,6 +1041,7 @@ run_again: | |||
| 1024 | 1041 | ||
| 1025 | if (zip_get_app_directory(zf, &app_directory_name)) { | 1042 | if (zip_get_app_directory(zf, &app_directory_name)) { |
| 1026 | fprintf(stderr, "Unable to locate app directory in archive!\n"); | 1043 | fprintf(stderr, "Unable to locate app directory in archive!\n"); |
| 1044 | res = -1; | ||
| 1027 | goto leave_cleanup; | 1045 | goto leave_cleanup; |
| 1028 | } | 1046 | } |
| 1029 | 1047 | ||
| @@ -1039,6 +1057,7 @@ run_again: | |||
| 1039 | free(filename); | 1057 | free(filename); |
| 1040 | zip_unchange_all(zf); | 1058 | zip_unchange_all(zf); |
| 1041 | zip_close(zf); | 1059 | zip_close(zf); |
| 1060 | res = -1; | ||
| 1042 | goto leave_cleanup; | 1061 | goto leave_cleanup; |
| 1043 | } | 1062 | } |
| 1044 | free(filename); | 1063 | free(filename); |
| @@ -1053,6 +1072,7 @@ run_again: | |||
| 1053 | fprintf(stderr, "Could not parse Info.plist!\n"); | 1072 | fprintf(stderr, "Could not parse Info.plist!\n"); |
| 1054 | zip_unchange_all(zf); | 1073 | zip_unchange_all(zf); |
| 1055 | zip_close(zf); | 1074 | zip_close(zf); |
| 1075 | res = -1; | ||
| 1056 | goto leave_cleanup; | 1076 | goto leave_cleanup; |
| 1057 | } | 1077 | } |
| 1058 | 1078 | ||
| @@ -1074,12 +1094,14 @@ run_again: | |||
| 1074 | fprintf(stderr, "Could not determine value for CFBundleExecutable!\n"); | 1094 | fprintf(stderr, "Could not determine value for CFBundleExecutable!\n"); |
| 1075 | zip_unchange_all(zf); | 1095 | zip_unchange_all(zf); |
| 1076 | zip_close(zf); | 1096 | zip_close(zf); |
| 1097 | res = -1; | ||
| 1077 | goto leave_cleanup; | 1098 | goto leave_cleanup; |
| 1078 | } | 1099 | } |
| 1079 | 1100 | ||
| 1080 | char *sinfname = NULL; | 1101 | char *sinfname = NULL; |
| 1081 | if (asprintf(&sinfname, "Payload/%s.app/SC_Info/%s.sinf", bundleexecutable, bundleexecutable) < 0) { | 1102 | if (asprintf(&sinfname, "Payload/%s.app/SC_Info/%s.sinf", bundleexecutable, bundleexecutable) < 0) { |
| 1082 | fprintf(stderr, "Out of memory!?\n"); | 1103 | fprintf(stderr, "Out of memory!?\n"); |
| 1104 | res = -1; | ||
| 1083 | goto leave_cleanup; | 1105 | goto leave_cleanup; |
| 1084 | } | 1106 | } |
| 1085 | free(bundleexecutable); | 1107 | free(bundleexecutable); |
| @@ -1099,6 +1121,7 @@ run_again: | |||
| 1099 | pkgname = NULL; | 1121 | pkgname = NULL; |
| 1100 | if (asprintf(&pkgname, "%s/%s", PKG_PATH, bundleidentifier) < 0) { | 1122 | if (asprintf(&pkgname, "%s/%s", PKG_PATH, bundleidentifier) < 0) { |
| 1101 | fprintf(stderr, "Out of memory!?\n"); | 1123 | fprintf(stderr, "Out of memory!?\n"); |
| 1124 | res = -1; | ||
| 1102 | goto leave_cleanup; | 1125 | goto leave_cleanup; |
| 1103 | } | 1126 | } |
| 1104 | 1127 | ||
| @@ -1162,12 +1185,14 @@ run_again: | |||
| 1162 | err = instproxy_lookup_archives(ipc, NULL, &dict); | 1185 | err = instproxy_lookup_archives(ipc, NULL, &dict); |
| 1163 | if (err != INSTPROXY_E_SUCCESS) { | 1186 | if (err != INSTPROXY_E_SUCCESS) { |
| 1164 | fprintf(stderr, "ERROR: lookup_archives returned %d\n", err); | 1187 | fprintf(stderr, "ERROR: lookup_archives returned %d\n", err); |
| 1188 | res = -1; | ||
| 1165 | goto leave_cleanup; | 1189 | goto leave_cleanup; |
| 1166 | } | 1190 | } |
| 1167 | 1191 | ||
| 1168 | if (!dict) { | 1192 | if (!dict) { |
| 1169 | fprintf(stderr, | 1193 | fprintf(stderr, |
| 1170 | "ERROR: lookup_archives did not return a plist!?\n"); | 1194 | "ERROR: lookup_archives did not return a plist!?\n"); |
| 1195 | res = -1; | ||
| 1171 | goto leave_cleanup; | 1196 | goto leave_cleanup; |
| 1172 | } | 1197 | } |
| 1173 | 1198 | ||
| @@ -1273,12 +1298,14 @@ run_again: | |||
| 1273 | if (stat(copy_path, &fst) != 0) { | 1298 | if (stat(copy_path, &fst) != 0) { |
| 1274 | fprintf(stderr, "ERROR: stat: %s: %s\n", copy_path, strerror(errno)); | 1299 | fprintf(stderr, "ERROR: stat: %s: %s\n", copy_path, strerror(errno)); |
| 1275 | free(copy_path); | 1300 | free(copy_path); |
| 1301 | res = -1; | ||
| 1276 | goto leave_cleanup; | 1302 | goto leave_cleanup; |
| 1277 | } | 1303 | } |
| 1278 | 1304 | ||
| 1279 | if (!S_ISDIR(fst.st_mode)) { | 1305 | if (!S_ISDIR(fst.st_mode)) { |
| 1280 | fprintf(stderr, "ERROR: '%s' is not a directory as expected.\n", copy_path); | 1306 | fprintf(stderr, "ERROR: '%s' is not a directory as expected.\n", copy_path); |
| 1281 | free(copy_path); | 1307 | free(copy_path); |
| 1308 | res = -1; | ||
| 1282 | goto leave_cleanup; | 1309 | goto leave_cleanup; |
| 1283 | } | 1310 | } |
| 1284 | 1311 | ||
| @@ -1290,6 +1317,7 @@ run_again: | |||
| 1290 | if ((lockdownd_start_service(client, "com.apple.afc", &service) != LOCKDOWN_E_SUCCESS) || !service) { | 1317 | if ((lockdownd_start_service(client, "com.apple.afc", &service) != LOCKDOWN_E_SUCCESS) || !service) { |
| 1291 | fprintf(stderr, "Could not start com.apple.afc!\n"); | 1318 | fprintf(stderr, "Could not start com.apple.afc!\n"); |
| 1292 | free(copy_path); | 1319 | free(copy_path); |
| 1320 | res = -1; | ||
| 1293 | goto leave_cleanup; | 1321 | goto leave_cleanup; |
| 1294 | } | 1322 | } |
| 1295 | 1323 | ||
| @@ -1298,6 +1326,7 @@ run_again: | |||
| 1298 | 1326 | ||
| 1299 | if (afc_client_new(device, service, &afc) != AFC_E_SUCCESS) { | 1327 | if (afc_client_new(device, service, &afc) != AFC_E_SUCCESS) { |
| 1300 | fprintf(stderr, "Could not connect to AFC!\n"); | 1328 | fprintf(stderr, "Could not connect to AFC!\n"); |
| 1329 | res = -1; | ||
| 1301 | goto leave_cleanup; | 1330 | goto leave_cleanup; |
| 1302 | } | 1331 | } |
| 1303 | } | 1332 | } |
| @@ -1318,6 +1347,7 @@ run_again: | |||
| 1318 | if (err_occurred) { | 1347 | if (err_occurred) { |
| 1319 | afc_client_free(afc); | 1348 | afc_client_free(afc); |
| 1320 | afc = NULL; | 1349 | afc = NULL; |
| 1350 | res = -1; | ||
| 1321 | goto leave_cleanup; | 1351 | goto leave_cleanup; |
| 1322 | } | 1352 | } |
| 1323 | FILE *f = NULL; | 1353 | FILE *f = NULL; |
| @@ -1326,6 +1356,7 @@ run_again: | |||
| 1326 | char *localfile = NULL; | 1356 | char *localfile = NULL; |
| 1327 | if (asprintf(&localfile, "%s/%s.ipa", copy_path, appid) < 0) { | 1357 | if (asprintf(&localfile, "%s/%s.ipa", copy_path, appid) < 0) { |
| 1328 | fprintf(stderr, "Out of memory!?\n"); | 1358 | fprintf(stderr, "Out of memory!?\n"); |
| 1359 | res = -1; | ||
| 1329 | goto leave_cleanup; | 1360 | goto leave_cleanup; |
| 1330 | } | 1361 | } |
| 1331 | free(copy_path); | 1362 | free(copy_path); |
| @@ -1351,6 +1382,7 @@ run_again: | |||
| 1351 | fclose(f); | 1382 | fclose(f); |
| 1352 | free(remotefile); | 1383 | free(remotefile); |
| 1353 | free(localfile); | 1384 | free(localfile); |
| 1385 | res = -1; | ||
| 1354 | goto leave_cleanup; | 1386 | goto leave_cleanup; |
| 1355 | } | 1387 | } |
| 1356 | 1388 | ||
| @@ -1381,6 +1413,7 @@ run_again: | |||
| 1381 | fprintf(stderr, "ERROR: could not open '%s' on device for reading!\n", remotefile); | 1413 | fprintf(stderr, "ERROR: could not open '%s' on device for reading!\n", remotefile); |
| 1382 | free(remotefile); | 1414 | free(remotefile); |
| 1383 | free(localfile); | 1415 | free(localfile); |
| 1416 | res = -1; | ||
| 1384 | goto leave_cleanup; | 1417 | goto leave_cleanup; |
| 1385 | } | 1418 | } |
| 1386 | 1419 | ||
| @@ -1430,6 +1463,7 @@ run_again: | |||
| 1430 | options = NULL; | 1463 | options = NULL; |
| 1431 | if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &client, "ideviceinstaller")) { | 1464 | if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &client, "ideviceinstaller")) { |
| 1432 | fprintf(stderr, "Could not connect to lockdownd. Exiting.\n"); | 1465 | fprintf(stderr, "Could not connect to lockdownd. Exiting.\n"); |
| 1466 | res = -1; | ||
| 1433 | goto leave_cleanup; | 1467 | goto leave_cleanup; |
| 1434 | } | 1468 | } |
| 1435 | goto run_again; | 1469 | goto run_again; |
