Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/ios-deploy/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,14 @@ const int error_id_to_message_count = sizeof(error_id_to_message) / sizeof(error
const char* get_error_message(unsigned int error) {
const char* id = NULL;

// this creates an error code to match what's defined in `errorcode_to_id`;
// taken from https://github.com/samdmarshall/SDMMobileDevice/blob/c3e1e97b1310c7a7a10f68281752760038b75e16/Framework/include/SDMMobileDevice/SDMMD_Error.h#L512
// note that the `error & 0xff` isn't done here because there are defined errors like `0xe8008001`
const unsigned int error_code = error | 0xe8000000;

// Lookup error localization id
for (int i = 0; i < errorcode_to_id_count; i++) {
if (errorcode_to_id[i].error == error) {
if (errorcode_to_id[i].error == error_code) {
id = errorcode_to_id[i].id;
break;
}
Expand Down
40 changes: 35 additions & 5 deletions src/ios-deploy/ios-deploy.m
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@
} \
} while (false);

// Checks for MobileDevice.framework errors and tries to print them.
#define log_error(call) \
do { \
unsigned int err = (unsigned int)call; \
if (err != 0) \
{ \
const char* msg = get_error_message(err); \
NSString *description = msg ? [NSString stringWithUTF8String:msg] : @"unknown."; \
NSLogJSON(@{@"Event": @"Error", @"Code": @(err), @"Status": description}); \
log_on_error(@"Error 0x%x: %@ " #call, err, description); \
} \
} while (false);



void disable_ssl(ServiceConnRef con)
{
Expand All @@ -175,6 +189,18 @@ void disable_ssl(ServiceConnRef con)
con->sslContext = NULL;
}

void log_on_error(NSString* format, ...)
{
va_list valist;
va_start(valist, format);
NSString* str = [[[NSString alloc] initWithFormat:format arguments:valist] autorelease];
va_end(valist);

if (!_json_output) {
NSLog(@"[ !! ] %@", str);
}
}


void on_error(NSString* format, ...)
{
Expand Down Expand Up @@ -1523,7 +1549,7 @@ CFStringRef copy_bundle_id(CFURLRef app_url)
return bundle_id;
}

typedef enum { READ_DIR_FILE, READ_DIR_BEFORE_DIR, READ_DIR_AFTER_DIR } read_dir_cb_reason;
typedef enum { READ_DIR_FILE, READ_DIR_FIFO, READ_DIR_BEFORE_DIR, READ_DIR_AFTER_DIR } read_dir_cb_reason;

void read_dir(AFCConnectionRef afc_conn_p, const char* dir,
void(*callback)(AFCConnectionRef conn, const char *dir, read_dir_cb_reason reason))
Expand All @@ -1533,6 +1559,7 @@ void read_dir(AFCConnectionRef afc_conn_p, const char* dir,
afc_dictionary* afc_dict_p;
char *key, *val;
int not_dir = 0;
bool is_fifo = 0;

unsigned int code = AFCFileInfoOpen(afc_conn_p, dir, &afc_dict_p);
if (code != 0) {
Expand All @@ -1549,6 +1576,7 @@ void read_dir(AFCConnectionRef afc_conn_p, const char* dir,
while((AFCKeyValueRead(afc_dict_p,&key,&val) == 0) && key && val) {
if (strcmp(key,"st_ifmt")==0) {
not_dir = strcmp(val,"S_IFDIR");
is_fifo = !strcmp(val, "S_IFIFO");
if (_json_output) {
ifmt = [NSString stringWithUTF8String:val];
} else {
Expand Down Expand Up @@ -1582,7 +1610,7 @@ void read_dir(AFCConnectionRef afc_conn_p, const char* dir,
}

if (not_dir) {
if (callback) (*callback)(afc_conn_p, dir, READ_DIR_FILE);
if (callback) (*callback)(afc_conn_p, dir, is_fifo ? READ_DIR_FIFO : READ_DIR_FILE);
return;
}

Expand Down Expand Up @@ -1734,7 +1762,7 @@ AFCConnectionRef start_house_arrest_service(AMDeviceRef device) {

void list_files_callback(AFCConnectionRef conn, const char *name, read_dir_cb_reason reason)
{
if (reason == READ_DIR_FILE) {
if (reason == READ_DIR_FILE || reason == READ_DIR_FIFO) {
NSLogOut(@"%@", [NSString stringWithUTF8String:name]);
} else if (reason == READ_DIR_BEFORE_DIR) {
NSLogOut(@"%@/", [NSString stringWithUTF8String:name]);
Expand Down Expand Up @@ -1852,7 +1880,7 @@ void copy_file_callback(AFCConnectionRef afc_conn_p, const char *name, read_dir_

if (*local_name=='\0') return;

if (reason == READ_DIR_FILE) {
if (reason == READ_DIR_FILE || reason == READ_DIR_FIFO) {
NSLogOut(@"%@", [NSString stringWithUTF8String:name]);
afc_file_ref fref;
int err = AFCFileRefOpen(afc_conn_p,name,1,&fref);
Expand Down Expand Up @@ -2058,7 +2086,9 @@ void rmtree_callback(AFCConnectionRef conn, const char *name, read_dir_cb_reason
{
if (reason == READ_DIR_FILE || reason == READ_DIR_AFTER_DIR) {
NSLogVerbose(@"Deleting %s", name);
check_error(AFCRemovePath(conn, name));
log_error(AFCRemovePath(conn, name));
} else if (reason == READ_DIR_FIFO) {
NSLogVerbose(@"Skipping %s", name);
}
}

Expand Down