Skip to content

Instantly share code, notes, and snippets.

@dnicolson
Created July 6, 2021 17:29
Show Gist options
  • Save dnicolson/e1293effdd6ea2cb3885c4341113c3fd to your computer and use it in GitHub Desktop.
Save dnicolson/e1293effdd6ea2cb3885c4341113c3fd to your computer and use it in GitHub Desktop.
List the bundle IDs of all apps on an iOS device
// clang ios-bundle-ids.c -o ios-bundle-ids -lplist-2.0 -limobiledevice-1.0 && ./ios-bundle-ids
#include <stdio.h>
#include <stdlib.h>
#include <libimobiledevice/libimobiledevice.h>
#include <libimobiledevice/installation_proxy.h>
void list_available_apps(idevice_t dev)
{
instproxy_client_t ip = NULL;
if (instproxy_client_start_service(dev, &ip, NULL) != INSTPROXY_E_SUCCESS) {
fprintf(stderr, "ERROR: Couldn't connect to installation proxy on device\n");
goto leave_cleanup;
}
plist_t client_opts = instproxy_client_options_new();
instproxy_client_options_add(client_opts, "ApplicationType", "Any", NULL);
instproxy_client_options_set_return_attributes(client_opts,
"CFBundleIdentifier",
"CFBundleDisplayName",
"CFBundleVersion",
"UIFileSharingEnabled",
NULL
);
plist_t apps = NULL;
instproxy_browse(ip, client_opts, &apps);
if (!apps || (plist_get_node_type(apps) != PLIST_ARRAY)) {
fprintf(stderr, "ERROR: instproxy_browse returned an invalid plist?!\n");
goto leave_cleanup;
}
/* output colum titles */
printf("\"%s\",\"%s\",\"%s\"\n", "CFBundleIdentifier", "CFBundleVersion", "CFBundleDisplayName");
/* output rows with app information */
uint32_t i = 0;
for (i = 0; i < plist_array_get_size(apps); i++) {
plist_t node = plist_array_get_item(apps, i);
if (node && plist_get_node_type(node) == PLIST_DICT) {
plist_t val;
char *bid = NULL;
char *ver = NULL;
char *name = NULL;
val = plist_dict_get_item(node, "CFBundleIdentifier");
if (val) {
plist_get_string_val(val, &bid);
}
val = plist_dict_get_item(node, "CFBundleVersion");
if (val) {
plist_get_string_val(val, &ver);
}
val = plist_dict_get_item(node, "CFBundleDisplayName");
if (val) {
plist_get_string_val(val, &name);
}
printf("\"%s\",\"%s\",\"%s\"\n", bid, ver, name);
free(bid);
free(ver);
free(name);
}
}
plist_free(apps);
leave_cleanup:
instproxy_client_free(ip);
idevice_free(dev);
}
int main()
{
/* Unique Device Identifier */
static char *udid = NULL;
/* Device Handle */
idevice_t device = NULL;
/* Try to connect to first USB device */
if (idevice_new_with_options(&device, NULL, IDEVICE_LOOKUP_USBMUX) != IDEVICE_E_SUCCESS) {
printf("ERROR: No device found!\n");
return -1;
}
/* Retrieve the udid of the connected device */
if (idevice_get_udid(device, &udid) != IDEVICE_E_SUCCESS) {
printf("ERROR: Unable to get the device UDID.\n");
idevice_free(device);
return -1;
}
/* Outputs device identifier */
printf("Connected with UDID: %s\n", udid);
list_available_apps(device);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment