Skip to content

Commit

Permalink
Merge pull request #1 from fr0l/filter_crashreports
Browse files Browse the repository at this point in the history
idevicecrashreport: Filter crash reports by filename
  • Loading branch information
fr0l authored Jul 29, 2019
2 parents 98ac7da + a84dc10 commit 8ce3312
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions tools/idevicecrashreport.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static int extract_raw_crash_report(const char* filename)
return res;
}

static int afc_client_copy_and_remove_crash_reports(afc_client_t afc, const char* device_directory, const char* host_directory)
static int afc_client_copy_and_remove_crash_reports(afc_client_t afc, const char* device_directory, const char* host_directory, const char* filename_filter)
{
afc_error_t afc_error;
int k;
Expand Down Expand Up @@ -226,12 +226,17 @@ static int afc_client_copy_and_remove_crash_reports(afc_client_t afc, const char
#else
mkdir(target_filename, 0755);
#endif
res = afc_client_copy_and_remove_crash_reports(afc, source_filename, target_filename);
res = afc_client_copy_and_remove_crash_reports(afc, source_filename, target_filename, filename_filter);

/* remove directory from device */
if (!keep_crash_reports)
afc_remove_path(afc, source_filename);
} else if (S_ISREG(stbuf.st_mode)) {

if (filename_filter != NULL && strstr(source_filename, filename_filter) == NULL) {
continue;
}

/* copy file to host */
afc_error = afc_file_open(afc, source_filename, AFC_FOPEN_RDONLY, &handle);
if(afc_error != AFC_E_SUCCESS) {
Expand Down Expand Up @@ -304,6 +309,7 @@ static void print_usage(int argc, char **argv)
printf(" -k, --keep\t\tcopy but do not remove crash reports from device\n");
printf(" -d, --debug\t\tenable communication debugging\n");
printf(" -u, --udid UDID\ttarget specific device by UDID\n");
printf(" -f, --filter NAME\tfilter crash reports by filename NAME (case sensitive)\n");
printf(" -h, --help\t\tprints usage information\n");
printf("\n");
printf("Homepage: <" PACKAGE_URL ">\n");
Expand All @@ -321,6 +327,7 @@ int main(int argc, char* argv[])

int i;
const char* udid = NULL;
const char* filename_filter = NULL;

/* parse cmdline args */
for (i = 1; i < argc; i++) {
Expand All @@ -337,6 +344,15 @@ int main(int argc, char* argv[])
udid = argv[i];
continue;
}
else if (!strcmp(argv[i], "-f") || !strcmp(argv[i], "--filter")) {
i++;
if (!argv[i] || !*argv[i]) {
print_usage(argc, argv);
return 0;
}
filename_filter = argv[i];
continue;
}
else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
print_usage(argc, argv);
return 0;
Expand Down Expand Up @@ -456,7 +472,7 @@ int main(int argc, char* argv[])
}

/* recursively copy crash reports from the device to a local directory */
if (afc_client_copy_and_remove_crash_reports(afc, ".", target_directory) < 0) {
if (afc_client_copy_and_remove_crash_reports(afc, ".", target_directory, filename_filter) < 0) {
fprintf(stderr, "ERROR: Failed to get crash reports from device.\n");
afc_client_free(afc);
idevice_free(device);
Expand Down

0 comments on commit 8ce3312

Please sign in to comment.