Skip to content

Commit 0467b69

Browse files
committed
Merge pull request #66 from dot-asm/master
Fix AFCFileRef[Read|Write] prototypes
2 parents 77116e3 + 4589cd5 commit 0467b69

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

MobileDevice.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,11 @@ afc_error_t AFCFileRefOpen(afc_connection *conn, const char *path,
396396
afc_error_t AFCFileRefSeek(afc_connection *conn, afc_file_ref ref,
397397
unsigned long long offset1, unsigned long long offset2);
398398
afc_error_t AFCFileRefRead(afc_connection *conn, afc_file_ref ref,
399-
void *buf, unsigned int *len);
399+
void *buf, size_t *len);
400400
afc_error_t AFCFileRefSetFileSize(afc_connection *conn, afc_file_ref ref,
401401
unsigned long long offset);
402402
afc_error_t AFCFileRefWrite(afc_connection *conn, afc_file_ref ref,
403-
const void *buf, unsigned int len);
403+
const void *buf, size_t len);
404404
afc_error_t AFCFileRefClose(afc_connection *conn, afc_file_ref ref);
405405

406406
afc_error_t AFCFileInfoOpen(afc_connection *conn, const char *path, struct
@@ -493,4 +493,4 @@ typedef unsigned int (*t_performOperation)(struct am_restore_device *rdev,
493493
}
494494
#endif
495495

496-
#endif
496+
#endif

ios-deploy.c

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -644,12 +644,12 @@ void write_lldb_prep_cmds(AMDeviceRef device, CFURLRef disk_app_url) {
644644
if (args) {
645645
CFStringRef cf_args = CFStringCreateWithCString(NULL, args, kCFStringEncodingASCII);
646646
CFStringFindAndReplace(cmds, CFSTR("{args}"), cf_args, range, 0);
647-
rangeLLDB.length = CFStringGetLength(pmodule);
648647
CFStringFindAndReplace(pmodule, CFSTR("{args}"), cf_args, rangeLLDB, 0);
649648

650649
CFRelease(cf_args);
651650
} else {
652-
CFStringFindAndReplace(cmds, CFSTR(" {args}"), CFSTR(""), range, 0);
651+
CFStringFindAndReplace(cmds, CFSTR("{args}"), CFSTR(""), range, 0);
652+
CFStringFindAndReplace(pmodule, CFSTR("{args}"), CFSTR(""), rangeLLDB, 0);
653653
}
654654
range.length = CFStringGetLength(cmds);
655655

@@ -1002,7 +1002,8 @@ CFStringRef get_bundle_id(CFURLRef app_url)
10021002
return bundle_id;
10031003
}
10041004

1005-
void read_dir(service_conn_t afcFd, afc_connection* afc_conn_p, const char* dir)
1005+
void read_dir(service_conn_t afcFd, afc_connection* afc_conn_p, const char* dir,
1006+
void(*callback)(afc_connection *conn,const char *dir,int file))
10061007
{
10071008
char *dir_ent;
10081009

@@ -1014,24 +1015,38 @@ void read_dir(service_conn_t afcFd, afc_connection* afc_conn_p, const char* dir)
10141015

10151016
printf("%s\n", dir);
10161017

1017-
afc_dictionary afc_dict;
1018-
afc_dictionary* afc_dict_p = &afc_dict;
1018+
afc_dictionary* afc_dict_p;
1019+
char *key, *val;
1020+
int not_dir;
1021+
10191022
AFCFileInfoOpen(afc_conn_p, dir, &afc_dict_p);
1020-
1021-
afc_directory afc_dir;
1022-
afc_directory* afc_dir_p = &afc_dir;
1023+
while((AFCKeyValueRead(afc_dict_p,&key,&val) == 0) && key && val) {
1024+
if (strcmp(key,"st_ifmt")==0) {
1025+
not_dir = strcmp(val,"S_IFDIR");
1026+
break;
1027+
}
1028+
}
1029+
AFCKeyValueClose(afc_dict_p);
1030+
1031+
if (not_dir) {
1032+
if (callback) (*callback)(afc_conn_p, dir, not_dir);
1033+
return;
1034+
}
1035+
1036+
afc_directory* afc_dir_p;
10231037
afc_error_t err = AFCDirectoryOpen(afc_conn_p, dir, &afc_dir_p);
10241038

1025-
if (err != 0)
1026-
{
1039+
if (err != 0) {
10271040
// Couldn't open dir - was probably a file
10281041
return;
1042+
} else {
1043+
if (callback) (*callback)(afc_conn_p, dir, not_dir);
10291044
}
10301045

10311046
while(true) {
10321047
err = AFCDirectoryRead(afc_conn_p, afc_dir_p, &dir_ent);
10331048

1034-
if (!dir_ent)
1049+
if (err != 0 || !dir_ent)
10351050
break;
10361051

10371052
if (strcmp(dir_ent, ".") == 0 || strcmp(dir_ent, "..") == 0)
@@ -1042,7 +1057,7 @@ void read_dir(service_conn_t afcFd, afc_connection* afc_conn_p, const char* dir)
10421057
if (dir_joined[strlen(dir)-1] != '/')
10431058
strcat(dir_joined, "/");
10441059
strcat(dir_joined, dir_ent);
1045-
read_dir(afcFd, afc_conn_p, dir_joined);
1060+
read_dir(afcFd, afc_conn_p, dir_joined, callback);
10461061
free(dir_joined);
10471062
}
10481063

@@ -1119,11 +1134,11 @@ void list_files(AMDeviceRef device)
11191134
{
11201135
service_conn_t houseFd = start_house_arrest_service(device);
11211136

1122-
afc_connection afc_conn;
1123-
afc_connection* afc_conn_p = &afc_conn;
1124-
AFCConnectionOpen(houseFd, 0, &afc_conn_p);
1125-
1126-
read_dir(houseFd, afc_conn_p, "/");
1137+
afc_connection* afc_conn_p;
1138+
if (AFCConnectionOpen(houseFd, 0, &afc_conn_p) == 0) {
1139+
read_dir(houseFd, afc_conn_p, "/", NULL);
1140+
AFCConnectionClose(afc_conn_p);
1141+
}
11271142
}
11281143

11291144
void upload_file(AMDeviceRef device) {
@@ -1135,7 +1150,7 @@ void upload_file(AMDeviceRef device) {
11351150
afc_connection* afc_conn_p = &afc_conn;
11361151
AFCConnectionOpen(houseFd, 0, &afc_conn_p);
11371152

1138-
// read_dir(houseFd, NULL, "/");
1153+
// read_dir(houseFd, NULL, "/", NULL);
11391154

11401155
if (!target_filename)
11411156
{

0 commit comments

Comments
 (0)