14 Commits
1.0.2 ... 1.0.5

Author SHA1 Message Date
Shazron Abdullah
ad7c97d01f Updated version to 1.0.5 2014-03-20 17:03:52 -07:00
Shazron Abdullah
fa88a73a9a Fixes #20 - lldb startup super-slow unless ios-deploy.c is edited to match exact xcode version 2014-03-20 17:00:32 -07:00
Shazron Abdullah
83150622c2 Merge pull request #13 from zgramana/master
Fixes phonegap/ios-deploy#8.
2013-12-13 16:34:43 -08:00
Zachary Gramana
42f41798a6 Fixes phonegap/ios-deploy#8. 2013-12-13 16:02:14 -08:00
Shazron Abdullah
486d0d92e0 Merge pull request #12 from zgramana/master
Enabled LLDB interactive session. Perf improvement.
2013-12-12 13:39:43 -08:00
Zachary Gramana
c97735aaee Added back support for -n/--nostart option. 2013-12-10 11:18:13 -08:00
Zachary Gramana
d7c38e9e9f Enabled LLDB interactive session. Perf improvement. 2013-12-09 17:59:19 -08:00
Shazron Abdullah
6f78fbc5f3 Update README.md 2013-10-25 15:43:59 -07:00
Shazron Abdullah
3854bc429a Updated version to 1.0.4 2013-10-22 14:12:30 -07:00
Shazron Abdullah
2c99d25d53 Added -V, --version option 2013-10-22 14:10:52 -07:00
Shazron Abdullah
1fe3ce5244 Updated README 2013-10-22 14:01:00 -07:00
Shazron Abdullah
017b85e4e8 Use lldv instead of gdb debugger
from 621f67bd2d
2013-10-22 13:54:23 -07:00
Shazron Abdullah
79aff2586a Interim checkin for issue #5 to make it compile (still has runtime errors IndexError: list index out of range) 2013-09-19 14:31:56 -07:00
Shazron Abdullah
88db2f0555 v1.0.3 - support npm uninstall 2013-07-29 15:52:34 -07:00
5 changed files with 577 additions and 245 deletions

View File

@@ -1,4 +1,4 @@
IOS_CC = gcc IOS_CC = gcc -ObjC
IOS_SDK = $(shell xcode-select --print-path)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk IOS_SDK = $(shell xcode-select --print-path)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk
DEVICE_SUPPORT = $(shell xcode-select --print-path)/Platforms/iPhoneOS.platform/DeviceSupport DEVICE_SUPPORT = $(shell xcode-select --print-path)/Platforms/iPhoneOS.platform/DeviceSupport
@@ -11,10 +11,10 @@ demo.app: demo Info.plist
codesign -f -s "iPhone Developer" --entitlements Entitlements.plist demo.app codesign -f -s "iPhone Developer" --entitlements Entitlements.plist demo.app
demo: demo.c demo: demo.c
$(IOS_CC) -arch armv7 -isysroot $(IOS_SDK) -framework CoreFoundation -o demo demo.c $(IOS_CC) -g -arch armv7 -isysroot $(IOS_SDK) -framework CoreFoundation -o demo demo.c
ios-deploy: ios-deploy.c ios-deploy: clean ios-deploy.c
$(IOS_CC) -o ios-deploy -framework CoreFoundation -framework MobileDevice -F/System/Library/PrivateFrameworks ios-deploy.c $(IOS_CC) -g -o ios-deploy -framework Foundation -framework CoreFoundation -framework MobileDevice -F/System/Library/PrivateFrameworks ios-deploy.c
symlink: symlink:
cd $(DEVICE_SUPPORT); ln -sfn "`find . -type d -maxdepth 1 -exec basename {} \; | tail -1`" Latest cd $(DEVICE_SUPPORT); ln -sfn "`find . -type d -maxdepth 1 -exec basename {} \; | tail -1`" Latest
@@ -23,6 +23,9 @@ install: symlink ios-deploy
mkdir -p $(prefix)/bin mkdir -p $(prefix)/bin
cp ios-deploy $(prefix)/bin cp ios-deploy $(prefix)/bin
uninstall:
rm $(prefix)/bin/ios-deploy
debug: all debug: all
./ios-deploy --debug --bundle demo.app ./ios-deploy --debug --bundle demo.app

View File

@@ -448,6 +448,11 @@ void AMDAddLogFileDescriptor(int fd);
//kern_return_t AMDeviceSendMessage(service_conn_t socket, void *unused, CFPropertyListRef plist); //kern_return_t AMDeviceSendMessage(service_conn_t socket, void *unused, CFPropertyListRef plist);
//kern_return_t AMDeviceReceiveMessage(service_conn_t socket, CFDictionaryRef options, CFPropertyListRef * result); //kern_return_t AMDeviceReceiveMessage(service_conn_t socket, CFDictionaryRef options, CFPropertyListRef * result);
typedef int (*am_device_install_application_callback)(CFDictionaryRef, int);
mach_error_t AMDeviceInstallApplication(service_conn_t socket, CFStringRef path, CFDictionaryRef options, am_device_install_application_callback callback, void *user);
mach_error_t AMDeviceTransferApplication(service_conn_t socket, CFStringRef path, CFDictionaryRef options, am_device_install_application_callback callbackj, void *user);
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* Semi-private routines * Semi-private routines
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */

View File

@@ -10,10 +10,20 @@ Install and debug iPhone apps without using Xcode. Designed to work on unjailbro
## Usage ## Usage
* `ios-deploy [-d] -b <app> [device_id]` ./ios-deploy [OPTION]...
* Optional `-d` flag launches a remote GDB session after the app has been installed. -d, --debug launch the app in GDB after installation
* `<app>` must be an iPhone application bundle, *not* an IPA. -i, --id <device_id> the id of the device to connect to
* Optional `device_id`; useful when you have more than one iPhone/iPad connected. -c, --detect only detect if the device is connected
-b, --bundle <bundle.app> the path to the app bundle to be installed
-a, --args <args> command line arguments to pass to the app when launching it
-t, --timeout <timeout> number of seconds to wait for a device to be connected
-u, --unbuffered don't buffer stdout
-g, --gdbargs <args> extra arguments to pass to GDB when starting the debugger
-x, --gdbexec <file> GDB commands script file
-n, --nostart do not start the app when debugging
-v, --verbose enable verbose output
-m, --noinstall directly start debugging without app install (-d not required)
-V, --version print the executable version
## Demo ## Demo

View File

@@ -1,61 +1,78 @@
//TODO: don't copy/mount DeveloperDiskImage.dmg if it's already done - Xcode checks this somehow //TODO: don't copy/mount DeveloperDiskImage.dmg if it's already done - Xcode checks this somehow
#import <CoreFoundation/CoreFoundation.h> #import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#include <unistd.h> #include <unistd.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/un.h> #include <sys/un.h>
#include <sys/sysctl.h>
#include <stdio.h> #include <stdio.h>
#include <signal.h> #include <signal.h>
#include <getopt.h> #include <getopt.h>
#include <pwd.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include "MobileDevice.h" #include "MobileDevice.h"
#define APP_VERSION "1.0.2" #define APP_VERSION "1.0.5"
#define FDVENDOR_PATH "/tmp/ios-deploy-remote-debugserver" #define PREP_CMDS_PATH "/tmp/fruitstrap-lldb-prep-cmds-"
#define PREP_CMDS_PATH "/tmp/ios-deploy-gdb-prep-cmds" #define LLDB_SHELL "python -u -c $'import time\ntime.sleep(1.0)\n%swhile True: time.sleep(0.1); cmd = raw_input(); print (cmd)' | lldb -s " PREP_CMDS_PATH
#define GDB_SHELL "`xcode-select -print-path`/Platforms/iPhoneOS.platform/Developer/usr/libexec/gdb/gdb-arm-apple-darwin --arch armv7 -q -x " PREP_CMDS_PATH
// approximation of what Xcode does: /*
#define GDB_PREP_CMDS CFSTR("set mi-show-protections off\n\ * Startup script passed to lldb.
set auto-raise-load-levels 1\n\ * To see how xcode interacts with lldb, put this into .lldbinit:
set shlib-path-substitutions /usr \"{ds_path}/Symbols/usr\" /System \"{ds_path}/Symbols/System\" \"{device_container}\" \"{disk_container}\" \"/private{device_container}\" \"{disk_container}\" /Developer \"{ds_path}/Symbols/Developer\"\n\ * log enable -v -f /Users/vargaz/lldb.log lldb all
set remote max-packet-size 1024\n\ * log enable -v -f /Users/vargaz/gdb-remote.log gdb-remote all
set sharedlibrary check-uuids on\n\ */
set env NSUnbufferedIO YES\n\ #define LLDB_PREP_CMDS CFSTR("\
set minimal-signal-handling 1\n\ platform select remote-ios --sysroot {symbols_path}\n\
set sharedlibrary load-rules \\\".*\\\" \\\".*\\\" container\n\ target create \"{disk_app}\"\n\
set inferior-auto-start-dyld 0\n\ script fruitstrap_device_app=\"{device_app}\"\n\
file \"{disk_app}\"\n\ script fruitstrap_connect_url=\"connect://127.0.0.1:12345\"\n\
set remote executable-directory {device_app}\n\ script fruitstrap_handle_command=\"command script add -s asynchronous -f {python_command}.fsrun_command run\"\n\
set remote noack-mode 1\n\ command script import \"{python_file_path}\"\n\
set trust-readonly-sections 1\n\ ")
target remote-mobile " FDVENDOR_PATH "\n\
mem 0x1000 0x3fffffff cache\n\ /*
mem 0x40000000 0xffffffff none\n\ * Some things do not seem to work when using the normal commands like process connect/launch, so we invoke them
mem 0x00000000 0x0fff none\n\ * through the python interface. Also, Launch () doesn't seem to work when ran from init_module (), so we add
run {args}\n\ * a command which can be used by the user to run it.
set minimal-signal-handling 0\n\ */
set inferior-auto-start-cfm off\n\ #define LLDB_FRUITSTRAP_MODULE CFSTR("\
set sharedLibrary load-rules dyld \".*libobjc.*\" all dyld \".*CoreFoundation.*\" all dyld \".*Foundation.*\" all dyld \".*libSystem.*\" all dyld \".*AppKit.*\" all dyld \".*PBGDBIntrospectionSupport.*\" all dyld \".*/usr/lib/dyld.*\" all dyld \".*CarbonDataFormatters.*\" all dyld \".*libauto.*\" all dyld \".*CFDataFormatters.*\" all dyld \"/System/Library/Frameworks\\\\\\\\|/System/Library/PrivateFrameworks\\\\\\\\|/usr/lib\" extern dyld \".*\" all exec \".*\" all\n\ import lldb\n\
sharedlibrary apply-load-rules all\n\ \n\
set inferior-auto-start-dyld 1\n\ def __lldb_init_module(debugger, internal_dict):\n\
continue\n\ # These two are passed in by the script which loads us\n\
quit\n") device_app=internal_dict['fruitstrap_device_app']\n\
connect_url=internal_dict['fruitstrap_connect_url']\n\
handle_command = internal_dict['fruitstrap_handle_command']\n\
lldb.target.modules[0].SetPlatformFileSpec(lldb.SBFileSpec(device_app))\n\
lldb.debugger.HandleCommand(handle_command)\n\
error=lldb.SBError()\n\
lldb.target.ConnectRemote(lldb.target.GetDebugger().GetListener(),connect_url,None,error)\n\
\n\
def fsrun_command(debugger, command, result, internal_dict):\n\
error=lldb.SBError()\n\
lldb.target.Launch(lldb.SBLaunchInfo(['{args}']),error)\n\
print str(error)\n\
")
typedef struct am_device * AMDeviceRef; typedef struct am_device * AMDeviceRef;
int AMDeviceSecureTransferPath(int zero, AMDeviceRef device, CFURLRef url, CFDictionaryRef options, void *callback, int cbarg); int AMDeviceSecureTransferPath(int zero, AMDeviceRef device, CFURLRef url, CFDictionaryRef options, void *callback, int cbarg);
int AMDeviceSecureInstallApplication(int zero, AMDeviceRef device, CFURLRef url, CFDictionaryRef options, void *callback, int cbarg); int AMDeviceSecureInstallApplication(int zero, AMDeviceRef device, CFURLRef url, CFDictionaryRef options, void *callback, int cbarg);
int AMDeviceMountImage(AMDeviceRef device, CFStringRef image, CFDictionaryRef options, void *callback, int cbarg); int AMDeviceMountImage(AMDeviceRef device, CFStringRef image, CFDictionaryRef options, void *callback, int cbarg);
int AMDeviceLookupApplications(AMDeviceRef device, int zero, CFDictionaryRef* result); mach_error_t AMDeviceLookupApplications(AMDeviceRef device, CFDictionaryRef options, CFDictionaryRef *result);
int AMDeviceTransferApplication(unsigned int fd, CFStringRef path, void* ptr, void *transfer_callback, void* ptr2);
int AMDeviceInstallApplication(unsigned int fd, CFStringRef path, CFDictionaryRef options, void *install_callback, void* ptr);
bool found_device = false, debug = false, verbose = false; bool found_device = false, debug = false, verbose = false, unbuffered = false, nostart = false, detect_only = false, install = true;
char *app_path = NULL; char *app_path = NULL;
char *device_id = NULL; char *device_id = NULL;
char *args = NULL; char *args = NULL;
int timeout = 0; int timeout = 0;
CFStringRef last_path = NULL; CFStringRef last_path = NULL;
service_conn_t gdbfd; service_conn_t gdbfd;
pid_t parent = 0;
Boolean path_exists(CFTypeRef path) { Boolean path_exists(CFTypeRef path) {
if (CFGetTypeID(path) == CFStringGetTypeID()) { if (CFGetTypeID(path) == CFStringGetTypeID()) {
@@ -70,92 +87,180 @@ Boolean path_exists(CFTypeRef path) {
} }
} }
CFStringRef copy_device_support_path(AMDeviceRef device) { CFStringRef find_path(CFStringRef rootPath, CFStringRef namePattern, CFStringRef expression) {
CFStringRef version = AMDeviceCopyValue(device, 0, CFSTR("ProductVersion")); FILE *fpipe = NULL;
CFStringRef build = AMDeviceCopyValue(device, 0, CFSTR("BuildVersion")); CFStringRef quotedRootPath = rootPath;
if (CFStringGetCharacterAtIndex(rootPath, 0) != '`') {
quotedRootPath = CFStringCreateWithFormat(NULL, NULL, CFSTR("'%@'"), rootPath);
}
CFStringRef cf_command = CFStringCreateWithFormat(NULL, NULL, CFSTR("find %@ -name '%@' %@ 2>/dev/null | sort | tail -n 1"), quotedRootPath, namePattern, expression);
if (quotedRootPath != rootPath) {
CFRelease(quotedRootPath);
}
char command[1024] = { '\0' };
CFStringGetCString(cf_command, command, sizeof(command), kCFStringEncodingUTF8);
CFRelease(cf_command);
if (!(fpipe = (FILE *)popen(command, "r")))
{
perror("Error encountered while opening pipe");
exit(EXIT_FAILURE);
}
char buffer[256] = { '\0' };
fgets(buffer, sizeof(buffer), fpipe);
pclose(fpipe);
strtok(buffer, "\n");
return CFStringCreateWithCString(NULL, buffer, kCFStringEncodingUTF8);
}
CFStringRef copy_long_shot_disk_image_path() {
return find_path(CFSTR("`xcode-select --print-path`"), CFSTR("DeveloperDiskImage.dmg"), CFSTR(""));
}
CFStringRef copy_xcode_dev_path() {
static char xcode_dev_path[256] = { '\0' };
if (strlen(xcode_dev_path) == 0) {
FILE *fpipe = NULL;
char *command = "xcode-select -print-path";
if (!(fpipe = (FILE *)popen(command, "r")))
{
perror("Error encountered while opening pipe");
exit(EXIT_FAILURE);
}
char buffer[256] = { '\0' };
fgets(buffer, sizeof(buffer), fpipe);
pclose(fpipe);
strtok(buffer, "\n");
strcpy(xcode_dev_path, buffer);
}
return CFStringCreateWithCString(NULL, xcode_dev_path, kCFStringEncodingUTF8);
}
const char *get_home() {
const char* home = getenv("HOME"); const char* home = getenv("HOME");
if (!home) {
struct passwd *pwd = getpwuid(getuid());
home = pwd->pw_dir;
}
return home;
}
CFStringRef copy_xcode_path_for(CFStringRef subPath, CFStringRef search) {
CFStringRef xcodeDevPath = copy_xcode_dev_path();
CFStringRef path; CFStringRef path;
bool found = false; bool found = false;
const char* home = get_home();
path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/%@ (%@)"), home, version, build);
found = path_exists(path);
if (!found) // Try using xcode-select --print-path
{ if (!found) {
path = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Developer/Platforms/iPhoneOS.platform/DeviceSupport/%@ (%@)"), version, build); path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/%@/%@"), xcodeDevPath, subPath, search);
found = path_exists(path); found = path_exists(path);
} }
if (!found) // Try find `xcode-select --print-path` with search as a name pattern
{ if (!found) {
path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/%@"), home, version); path = find_path(CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/%@"), xcodeDevPath, subPath), search, CFSTR("-maxdepth 1"));
found = CFStringGetLength(path) > 0 && path_exists(path);
}
// If not look in the default xcode location (xcode-select is sometimes wrong)
if (!found) {
path = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Applications/Xcode.app/Contents/Developer/%@&%@"), subPath, search);
found = path_exists(path); found = path_exists(path);
} }
if (!found) // If not look in the users home directory, Xcode can store device support stuff there
{ if (!found) {
path = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Developer/Platforms/iPhoneOS.platform/DeviceSupport/%@"), version); path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/%@/%@"), home, subPath, search);
found = path_exists(path);
}
if (!found)
{
path = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/Latest"));
found = path_exists(path); found = path_exists(path);
} }
CFRelease(xcodeDevPath);
if (found) {
return path;
} else {
CFRelease(path);
return NULL;
}
}
CFMutableArrayRef get_device_product_version_parts(AMDeviceRef device) {
CFStringRef version = AMDeviceCopyValue(device, 0, CFSTR("ProductVersion"));
CFArrayRef parts = CFStringCreateArrayBySeparatingStrings(NULL, version, CFSTR("."));
CFMutableArrayRef result = CFArrayCreateMutableCopy(NULL, CFArrayGetCount(parts), parts);
CFRelease(version); CFRelease(version);
CFRelease(parts);
return result;
}
CFStringRef copy_device_support_path(AMDeviceRef device) {
CFStringRef version = NULL;
CFStringRef build = AMDeviceCopyValue(device, 0, CFSTR("BuildVersion"));
CFStringRef path = NULL;
CFMutableArrayRef version_parts = get_device_product_version_parts(device);
while (CFArrayGetCount(version_parts) > 0) {
version = CFStringCreateByCombiningStrings(NULL, version_parts, CFSTR("."));
if (path == NULL) {
path = copy_xcode_path_for(CFSTR("iOS DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%@)"), version, build));
}
if (path == NULL) {
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%@)"), version, build));
}
if (path == NULL) {
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (*)"), version));
}
if (path == NULL) {
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport"), version);
}
if (path == NULL) {
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport/Latest"), CFSTR(""));
}
CFRelease(version);
if (path != NULL) {
break;
}
CFArrayRemoveValueAtIndex(version_parts, CFArrayGetCount(version_parts) - 1);
}
CFRelease(version_parts);
CFRelease(build); CFRelease(build);
if (!found) if (path == NULL)
{ {
CFRelease(path); printf("[ !! ] Unable to locate DeviceSupport directory.\n[ !! ] This probably means you don't have Xcode installed, you will need to launch the app manually and logging output will not be shown!\n");
printf("[ !! ] Unable to locate DeviceSupport directory.\n");
exit(1); exit(1);
} }
return path; return path;
} }
CFStringRef copy_developer_disk_image_path(AMDeviceRef device) { CFStringRef copy_developer_disk_image_path(CFStringRef deviceSupportPath) {
CFStringRef version = AMDeviceCopyValue(device, 0, CFSTR("ProductVersion")); CFStringRef path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/%@"), deviceSupportPath, CFSTR("DeveloperDiskImage.dmg"));
CFStringRef build = AMDeviceCopyValue(device, 0, CFSTR("BuildVersion")); if (!path_exists(path)) {
const char *home = getenv("HOME");
CFStringRef path;
bool found = false;
path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/%@ (%@)/DeveloperDiskImage.dmg"), home, version, build);
found = path_exists(path);
if (!found) {
path = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Developer/Platforms/iPhoneOS.platform/DeviceSupport/%@ (%@)/DeveloperDiskImage.dmg)"), version, build);
found = path_exists(path);
}
if (!found) {
path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/%@/DeveloperDiskImage.dmg"), home, version);
found = path_exists(path);
}
if (!found) {
path = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Developer/Platforms/iPhoneOS.platform/DeviceSupport/%@/DeveloperDiskImage.dmg"), version);
found = path_exists(path);
}
if (!found) {
path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%s/Library/Developer/Xcode/iOS DeviceSupport/Latest/DeveloperDiskImage.dmg"), home);
found = path_exists(path);
}
if (!found) {
path = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Developer/Platforms/iPhoneOS.platform/DeviceSupport/Latest/DeveloperDiskImage.dmg"));
found = path_exists(path);
}
if (!found)
{
path = CFStringCreateWithFormat(NULL, NULL, CFSTR("/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/Latest/DeveloperDiskImage.dmg"));
found = path_exists(path);
}
CFRelease(version);
CFRelease(build);
if (!found) {
CFRelease(path); CFRelease(path);
printf("[ !! ] Unable to locate DeviceSupport directory containing DeveloperDiskImage.dmg.\n"); path = NULL;
}
if (path == NULL) {
// Sometimes Latest seems to be missing in Xcode, in that case use find and hope for the best
path = copy_long_shot_disk_image_path();
if (CFStringGetLength(path) < 5) {
CFRelease(path);
path = NULL;
}
}
if (path == NULL)
{
printf("[ !! ] Unable to locate DeveloperDiskImage.dmg.\n[ !! ] This probably means you don't have Xcode installed, you will need to launch the app manually and logging output will not be shown!\n");
exit(1); exit(1);
} }
@@ -176,18 +281,14 @@ void mount_callback(CFDictionaryRef dict, int arg) {
void mount_developer_image(AMDeviceRef device) { void mount_developer_image(AMDeviceRef device) {
CFStringRef ds_path = copy_device_support_path(device); CFStringRef ds_path = copy_device_support_path(device);
CFStringRef image_path = copy_developer_disk_image_path(device); CFStringRef image_path = copy_developer_disk_image_path(ds_path);
CFStringRef sig_path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@.signature"), image_path); CFStringRef sig_path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@.signature"), image_path);
CFRelease(ds_path);
if (verbose) { if (verbose) {
printf("Device support path: "); printf("Device support path: %s\n", CFStringGetCStringPtr(ds_path, CFStringGetSystemEncoding()));
fflush(stdout); printf("Developer disk image: %s\n", CFStringGetCStringPtr(image_path, CFStringGetSystemEncoding()));
CFShow(ds_path);
printf("Developer disk image: ");
fflush(stdout);
CFShow(image_path);
} }
CFRelease(ds_path);
FILE* sig = fopen(CFStringGetCStringPtr(sig_path, kCFStringEncodingMacRoman), "rb"); FILE* sig = fopen(CFStringGetCStringPtr(sig_path, kCFStringEncodingMacRoman), "rb");
void *sig_buf = malloc(128); void *sig_buf = malloc(128);
@@ -215,7 +316,7 @@ void mount_developer_image(AMDeviceRef device) {
CFRelease(options); CFRelease(options);
} }
void transfer_callback(CFDictionaryRef dict, int arg) { mach_error_t transfer_callback(CFDictionaryRef dict, int arg) {
int percent; int percent;
CFStringRef status = CFDictionaryGetValue(dict, CFSTR("Status")); CFStringRef status = CFDictionaryGetValue(dict, CFSTR("Status"));
CFNumberGetValue(CFDictionaryGetValue(dict, CFSTR("PercentComplete")), kCFNumberSInt32Type, &percent); CFNumberGetValue(CFDictionaryGetValue(dict, CFSTR("PercentComplete")), kCFNumberSInt32Type, &percent);
@@ -232,54 +333,52 @@ void transfer_callback(CFDictionaryRef dict, int arg) {
} }
last_path = CFStringCreateCopy(NULL, path); last_path = CFStringCreateCopy(NULL, path);
} }
return 0;
} }
void install_callback(CFDictionaryRef dict, int arg) { mach_error_t install_callback(CFDictionaryRef dict, int arg) {
int percent; int percent;
CFStringRef status = CFDictionaryGetValue(dict, CFSTR("Status")); CFStringRef status = CFDictionaryGetValue(dict, CFSTR("Status"));
CFNumberGetValue(CFDictionaryGetValue(dict, CFSTR("PercentComplete")), kCFNumberSInt32Type, &percent); CFNumberGetValue(CFDictionaryGetValue(dict, CFSTR("PercentComplete")), kCFNumberSInt32Type, &percent);
printf("[%3d%%] %s\n", (percent / 2) + 50, CFStringGetCStringPtr(status, kCFStringEncodingMacRoman)); printf("[%3d%%] %s\n", (percent / 2) + 50, CFStringGetCStringPtr(status, kCFStringEncodingMacRoman));
} return 0;
void fdvendor_callback(CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef address, const void *data, void *info) {
CFSocketNativeHandle socket = (CFSocketNativeHandle)(*((CFSocketNativeHandle *)data));
struct msghdr message;
struct iovec iov[1];
struct cmsghdr *control_message = NULL;
char ctrl_buf[CMSG_SPACE(sizeof(int))];
char dummy_data[1];
memset(&message, 0, sizeof(struct msghdr));
memset(ctrl_buf, 0, CMSG_SPACE(sizeof(int)));
dummy_data[0] = ' ';
iov[0].iov_base = dummy_data;
iov[0].iov_len = sizeof(dummy_data);
message.msg_name = NULL;
message.msg_namelen = 0;
message.msg_iov = iov;
message.msg_iovlen = 1;
message.msg_controllen = CMSG_SPACE(sizeof(int));
message.msg_control = ctrl_buf;
control_message = CMSG_FIRSTHDR(&message);
control_message->cmsg_level = SOL_SOCKET;
control_message->cmsg_type = SCM_RIGHTS;
control_message->cmsg_len = CMSG_LEN(sizeof(int));
*((int *) CMSG_DATA(control_message)) = gdbfd;
sendmsg(socket, &message, 0);
CFSocketInvalidate(s);
CFRelease(s);
} }
CFURLRef copy_device_app_url(AMDeviceRef device, CFStringRef identifier) { CFURLRef copy_device_app_url(AMDeviceRef device, CFStringRef identifier) {
CFDictionaryRef result; CFDictionaryRef result = nil;
assert(AMDeviceLookupApplications(device, 0, &result) == 0);
NSArray *a = [NSArray arrayWithObjects:
@"CFBundleIdentifier", // absolute must
@"ApplicationDSID",
@"ApplicationType",
@"CFBundleExecutable",
@"CFBundleDisplayName",
@"CFBundleIconFile",
@"CFBundleName",
@"CFBundleShortVersionString",
@"CFBundleSupportedPlatforms",
@"CFBundleURLTypes",
@"CodeInfoIdentifier",
@"Container",
@"Entitlements",
@"HasSettingsBundle",
@"IsUpgradeable",
@"MinimumOSVersion",
@"Path",
@"SignerIdentity",
@"UIDeviceFamily",
@"UIFileSharingEnabled",
@"UIStatusBarHidden",
@"UISupportedInterfaceOrientations",
nil];
NSDictionary *optionsDict = [NSDictionary dictionaryWithObject:a forKey:@"ReturnAttributes"];
CFDictionaryRef options = (CFDictionaryRef)optionsDict;
afc_error_t resultStatus = AMDeviceLookupApplications(device, options, &result);
assert(resultStatus == 0);
CFDictionaryRef app_dict = CFDictionaryGetValue(result, identifier); CFDictionaryRef app_dict = CFDictionaryGetValue(result, identifier);
assert(app_dict != NULL); assert(app_dict != NULL);
@@ -307,17 +406,33 @@ CFStringRef copy_disk_app_identifier(CFURLRef disk_app_url) {
return bundle_identifier; return bundle_identifier;
} }
void write_gdb_prep_cmds(AMDeviceRef device, CFURLRef disk_app_url) { void write_lldb_prep_cmds(AMDeviceRef device, CFURLRef disk_app_url) {
CFMutableStringRef cmds = CFStringCreateMutableCopy(NULL, 0, GDB_PREP_CMDS); CFStringRef ds_path = copy_device_support_path(device);
CFStringRef symbols_path = CFStringCreateWithFormat(NULL, NULL, CFSTR("'%@/Symbols'"), ds_path);
CFMutableStringRef cmds = CFStringCreateMutableCopy(NULL, 0, LLDB_PREP_CMDS);
CFRange range = { 0, CFStringGetLength(cmds) }; CFRange range = { 0, CFStringGetLength(cmds) };
CFStringRef ds_path = copy_device_support_path(device); CFStringFindAndReplace(cmds, CFSTR("{symbols_path}"), symbols_path, range, 0);
range.length = CFStringGetLength(cmds);
CFStringFindAndReplace(cmds, CFSTR("{ds_path}"), ds_path, range, 0); CFStringFindAndReplace(cmds, CFSTR("{ds_path}"), ds_path, range, 0);
range.length = CFStringGetLength(cmds); range.length = CFStringGetLength(cmds);
CFMutableStringRef pmodule = CFStringCreateMutableCopy(NULL, 0, LLDB_FRUITSTRAP_MODULE);
if (args) { if (args) {
CFStringRef cf_args = CFStringCreateWithCString(NULL, args, kCFStringEncodingASCII); CFStringRef cf_args = CFStringCreateWithCString(NULL, args, kCFStringEncodingASCII);
CFStringFindAndReplace(cmds, CFSTR("{args}"), cf_args, range, 0); CFStringFindAndReplace(cmds, CFSTR("{args}"), cf_args, range, 0);
//format the arguments 'arg1 arg2 ....' to an argument list ['arg1', 'arg2', ...]
CFMutableStringRef argsListLLDB = CFStringCreateMutableCopy(NULL, 0, cf_args);
CFRange rangeLLDB = { 0, CFStringGetLength(argsListLLDB) };
CFStringFindAndReplace(argsListLLDB, CFSTR(" "), CFSTR(" "), rangeLLDB, 0);//remove multiple spaces
rangeLLDB.length = CFStringGetLength(argsListLLDB);
CFStringFindAndReplace(argsListLLDB, CFSTR(" "), CFSTR("', '"), rangeLLDB, 0);
rangeLLDB.length = CFStringGetLength(pmodule);
CFStringFindAndReplace(pmodule, CFSTR("{args}"), argsListLLDB, rangeLLDB, 0);
CFRelease(cf_args); CFRelease(cf_args);
} else { } else {
CFStringFindAndReplace(cmds, CFSTR(" {args}"), CFSTR(""), range, 0); CFStringFindAndReplace(cmds, CFSTR(" {args}"), CFSTR(""), range, 0);
@@ -347,11 +462,35 @@ void write_gdb_prep_cmds(AMDeviceRef device, CFURLRef disk_app_url) {
CFStringRef disk_container_path = CFURLCopyFileSystemPath(disk_container_url, kCFURLPOSIXPathStyle); CFStringRef disk_container_path = CFURLCopyFileSystemPath(disk_container_url, kCFURLPOSIXPathStyle);
CFStringFindAndReplace(cmds, CFSTR("{disk_container}"), disk_container_path, range, 0); CFStringFindAndReplace(cmds, CFSTR("{disk_container}"), disk_container_path, range, 0);
char python_file_path[300] = "/tmp/fruitstrap_";
char python_command[300] = "fruitstrap_";
if(device_id != NULL) {
strcat(python_file_path, device_id);
strcat(python_command, device_id);
}
strcat(python_file_path, ".py");
CFStringRef cf_python_command = CFStringCreateWithCString(NULL, python_command, kCFStringEncodingASCII);
CFStringFindAndReplace(cmds, CFSTR("{python_command}"), cf_python_command, range, 0);
range.length = CFStringGetLength(cmds);
CFStringRef cf_python_file_path = CFStringCreateWithCString(NULL, python_file_path, kCFStringEncodingASCII);
CFStringFindAndReplace(cmds, CFSTR("{python_file_path}"), cf_python_file_path, range, 0);
range.length = CFStringGetLength(cmds);
CFDataRef cmds_data = CFStringCreateExternalRepresentation(NULL, cmds, kCFStringEncodingASCII, 0); CFDataRef cmds_data = CFStringCreateExternalRepresentation(NULL, cmds, kCFStringEncodingASCII, 0);
FILE *out = fopen(PREP_CMDS_PATH, "w"); char prep_cmds_path[300] = PREP_CMDS_PATH;
if(device_id != NULL)
strcat(prep_cmds_path, device_id);
FILE *out = fopen(prep_cmds_path, "w");
fwrite(CFDataGetBytePtr(cmds_data), CFDataGetLength(cmds_data), 1, out); fwrite(CFDataGetBytePtr(cmds_data), CFDataGetLength(cmds_data), 1, out);
fclose(out); fclose(out);
CFDataRef pmodule_data = CFStringCreateExternalRepresentation(NULL, pmodule, kCFStringEncodingASCII, 0);
out = fopen(python_file_path, "w");
fwrite(CFDataGetBytePtr(pmodule_data), CFDataGetLength(pmodule_data), 1, out);
fclose(out);
CFRelease(cmds); CFRelease(cmds);
if (ds_path != NULL) CFRelease(ds_path); if (ds_path != NULL) CFRelease(ds_path);
CFRelease(bundle_identifier); CFRelease(bundle_identifier);
@@ -364,38 +503,181 @@ void write_gdb_prep_cmds(AMDeviceRef device, CFURLRef disk_app_url) {
CFRelease(disk_container_url); CFRelease(disk_container_url);
CFRelease(disk_container_path); CFRelease(disk_container_path);
CFRelease(cmds_data); CFRelease(cmds_data);
CFRelease(cf_python_command);
CFRelease(cf_python_file_path);
}
CFSocketRef server_socket;
CFSocketRef lldb_socket;
CFWriteStreamRef serverWriteStream = NULL;
CFWriteStreamRef lldbWriteStream = NULL;
void
server_callback (CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef address, const void *data, void *info)
{
int res;
//PRINT ("server: %s\n", CFDataGetBytePtr (data));
if (CFDataGetLength (data) == 0) {
// FIXME: Close the socket
//shutdown (CFSocketGetNative (lldb_socket), SHUT_RDWR);
//close (CFSocketGetNative (lldb_socket));
return;
}
res = write (CFSocketGetNative (lldb_socket), CFDataGetBytePtr (data), CFDataGetLength (data));
}
void lldb_callback(CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef address, const void *data, void *info)
{
//PRINT ("lldb: %s\n", CFDataGetBytePtr (data));
if (CFDataGetLength (data) == 0)
return;
write (gdbfd, CFDataGetBytePtr (data), CFDataGetLength (data));
}
void fdvendor_callback(CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef address, const void *data, void *info) {
CFSocketNativeHandle socket = (CFSocketNativeHandle)(*((CFSocketNativeHandle *)data));
assert (callbackType == kCFSocketAcceptCallBack);
//PRINT ("callback!\n");
lldb_socket = CFSocketCreateWithNative(NULL, socket, kCFSocketDataCallBack, &lldb_callback, NULL);
CFRunLoopAddSource(CFRunLoopGetMain(), CFSocketCreateRunLoopSource(NULL, lldb_socket, 0), kCFRunLoopCommonModes);
} }
void start_remote_debug_server(AMDeviceRef device) { void start_remote_debug_server(AMDeviceRef device) {
assert(AMDeviceStartService(device, CFSTR("com.apple.debugserver"), &gdbfd, NULL) == 0); char buf [256];
int res, err, i;
char msg [256];
int chsum, len;
struct stat s;
socklen_t buflen;
struct sockaddr name;
int namelen;
CFSocketRef fdvendor = CFSocketCreate(NULL, AF_UNIX, 0, 0, kCFSocketAcceptCallBack, &fdvendor_callback, NULL); assert(AMDeviceStartService(device, CFSTR("com.apple.debugserver"), &gdbfd, NULL) == 0);
assert (gdbfd);
/*
* The debugserver connection is through a fd handle, while lldb requires a host/port to connect, so create an intermediate
* socket to transfer data.
*/
server_socket = CFSocketCreateWithNative (NULL, gdbfd, kCFSocketDataCallBack, &server_callback, NULL);
CFRunLoopAddSource(CFRunLoopGetMain(), CFSocketCreateRunLoopSource(NULL, server_socket, 0), kCFRunLoopCommonModes);
struct sockaddr_in addr4;
memset(&addr4, 0, sizeof(addr4));
addr4.sin_len = sizeof(addr4);
addr4.sin_family = AF_INET;
addr4.sin_port = htons(12345);
addr4.sin_addr.s_addr = htonl(INADDR_ANY);
CFSocketRef fdvendor = CFSocketCreate(NULL, PF_INET, 0, 0, kCFSocketAcceptCallBack, &fdvendor_callback, NULL);
int yes = 1; int yes = 1;
setsockopt(CFSocketGetNative(fdvendor), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)); setsockopt(CFSocketGetNative(fdvendor), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
int flag = 1;
res = setsockopt(CFSocketGetNative(fdvendor), IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int));
assert (res == 0);
struct sockaddr_un address; CFDataRef address_data = CFDataCreate(NULL, (const UInt8 *)&addr4, sizeof(addr4));
memset(&address, 0, sizeof(address));
address.sun_family = AF_UNIX;
strcpy(address.sun_path, FDVENDOR_PATH);
address.sun_len = SUN_LEN(&address);
CFDataRef address_data = CFDataCreate(NULL, (const UInt8 *)&address, sizeof(address));
unlink(FDVENDOR_PATH);
CFSocketSetAddress(fdvendor, address_data); CFSocketSetAddress(fdvendor, address_data);
CFRelease(address_data); CFRelease(address_data);
CFRunLoopAddSource(CFRunLoopGetMain(), CFSocketCreateRunLoopSource(NULL, fdvendor, 0), kCFRunLoopCommonModes); CFRunLoopAddSource(CFRunLoopGetMain(), CFSocketCreateRunLoopSource(NULL, fdvendor, 0), kCFRunLoopCommonModes);
} }
void gdb_ready_handler(int signum) void kill_ptree_inner(pid_t root, int signum, struct kinfo_proc *kp, int kp_len) {
int i;
for (i = 0; i < kp_len; i++) {
if (kp[i].kp_eproc.e_ppid == root) {
kill_ptree_inner(kp[i].kp_proc.p_pid, signum, kp, kp_len);
}
}
if (root != getpid()) {
kill(root, signum);
}
}
int kill_ptree(pid_t root, int signum) {
int mib[3];
size_t len;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_ALL;
if (sysctl(mib, 3, NULL, &len, NULL, 0) == -1) {
return -1;
}
struct kinfo_proc *kp = calloc(1, len);
if (!kp) {
return -1;
}
if (sysctl(mib, 3, kp, &len, NULL, 0) == -1) {
free(kp);
return -1;
}
kill_ptree_inner(root, signum, kp, len / sizeof(struct kinfo_proc));
free(kp);
return 0;
}
void killed(int signum) {
// SIGKILL needed to kill lldb, probably a better way to do this.
kill(0, SIGKILL);
_exit(0);
}
void lldb_finished_handler(int signum)
{ {
_exit(0); _exit(0);
} }
void launch_debugger(AMDeviceRef device, CFURLRef url) {
AMDeviceConnect(device);
assert(AMDeviceIsPaired(device));
assert(AMDeviceValidatePairing(device) == 0);
assert(AMDeviceStartSession(device) == 0);
printf("------ Debug phase ------\n");
mount_developer_image(device); // put debugserver on the device
start_remote_debug_server(device); // start debugserver
write_lldb_prep_cmds(device, url); // dump the necessary lldb commands into a file
CFRelease(url);
printf("[100%%] Connecting to remote debug server\n");
printf("-------------------------\n");
signal(SIGHUP, lldb_finished_handler);
setpgid(getpid(), 0);
signal(SIGINT, killed);
signal(SIGTERM, killed);
parent = getpid();
int pid = fork();
if (pid == 0) {
char *runOption = nostart ? "" : "print \\\'run\\\'\n";
char lldb_shell[400];
sprintf(lldb_shell, LLDB_SHELL, runOption);
if(device_id != NULL)
strcat(lldb_shell, device_id);
system(lldb_shell); // launch lldb
kill(parent, SIGHUP); // "No. I am your father."
_exit(0);
}
}
void handle_device(AMDeviceRef device) { void handle_device(AMDeviceRef device) {
if (found_device) return; // handle one device only if (found_device) return; // handle one device only
CFStringRef found_device_id = AMDeviceCopyDeviceIdentifier(device); CFStringRef found_device_id = AMDeviceCopyDeviceIdentifier(device);
if (device_id != NULL) { if (device_id != NULL) {
@@ -408,22 +690,31 @@ void handle_device(AMDeviceRef device) {
found_device = true; found_device = true;
} }
if (detect_only) {
printf("[....] Found device (%s).\n", CFStringGetCStringPtr(found_device_id, CFStringGetSystemEncoding()));
exit(0);
}
CFRetain(device); // don't know if this is necessary? CFRetain(device); // don't know if this is necessary?
printf("[ 0%%] Found device (%s), beginning install\n", CFStringGetCStringPtr(found_device_id, CFStringGetSystemEncoding()));
AMDeviceConnect(device);
assert(AMDeviceIsPaired(device));
assert(AMDeviceValidatePairing(device) == 0);
assert(AMDeviceStartSession(device) == 0);
CFStringRef path = CFStringCreateWithCString(NULL, app_path, kCFStringEncodingASCII); CFStringRef path = CFStringCreateWithCString(NULL, app_path, kCFStringEncodingASCII);
CFURLRef relative_url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, false); CFURLRef relative_url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, false);
CFURLRef url = CFURLCopyAbsoluteURL(relative_url); CFURLRef url = CFURLCopyAbsoluteURL(relative_url);
CFRelease(relative_url); CFRelease(relative_url);
unsigned int afcFd; if(install) {
printf("[ 0%%] Found device (%s), beginning install\n", CFStringGetCStringPtr(found_device_id, CFStringGetSystemEncoding()));
AMDeviceConnect(device);
assert(AMDeviceIsPaired(device));
assert(AMDeviceValidatePairing(device) == 0);
assert(AMDeviceStartSession(device) == 0);
service_conn_t afcFd;
assert(AMDeviceStartService(device, CFSTR("com.apple.afc"), &afcFd, NULL) == 0); assert(AMDeviceStartService(device, CFSTR("com.apple.afc"), &afcFd, NULL) == 0);
assert(AMDeviceStopSession(device) == 0); assert(AMDeviceStopSession(device) == 0);
assert(AMDeviceDisconnect(device) == 0); assert(AMDeviceDisconnect(device) == 0);
@@ -440,7 +731,7 @@ void handle_device(AMDeviceRef device) {
assert(AMDeviceValidatePairing(device) == 0); assert(AMDeviceValidatePairing(device) == 0);
assert(AMDeviceStartSession(device) == 0); assert(AMDeviceStartSession(device) == 0);
unsigned int installFd; service_conn_t installFd;
assert(AMDeviceStartService(device, CFSTR("com.apple.mobile.installation_proxy"), &installFd, NULL) == 0); assert(AMDeviceStartService(device, CFSTR("com.apple.mobile.installation_proxy"), &installFd, NULL) == 0);
assert(AMDeviceStopSession(device) == 0); assert(AMDeviceStopSession(device) == 0);
@@ -459,34 +750,10 @@ void handle_device(AMDeviceRef device) {
CFRelease(options); CFRelease(options);
printf("[100%%] Installed package %s\n", app_path); printf("[100%%] Installed package %s\n", app_path);
}
if (!debug) exit(0); // no debug phase if (!debug) exit(0); // no debug phase
launch_debugger(device, url);
AMDeviceConnect(device);
assert(AMDeviceIsPaired(device));
assert(AMDeviceValidatePairing(device) == 0);
assert(AMDeviceStartSession(device) == 0);
printf("------ Debug phase ------\n");
mount_developer_image(device); // put debugserver on the device
start_remote_debug_server(device); // start debugserver
write_gdb_prep_cmds(device, url); // dump the necessary gdb commands into a file
CFRelease(url);
printf("[100%%] Connecting to remote debug server\n");
printf("-------------------------\n");
signal(SIGHUP, gdb_ready_handler);
pid_t parent = getpid();
int pid = fork();
if (pid == 0) {
system(GDB_SHELL); // launch gdb
kill(parent, SIGHUP); // "No. I am your father."
_exit(0);
}
} }
void device_callback(struct am_device_notification_callback_info *info, void *arg) { void device_callback(struct am_device_notification_callback_info *info, void *arg) {
@@ -500,16 +767,31 @@ void device_callback(struct am_device_notification_callback_info *info, void *ar
void timeout_callback(CFRunLoopTimerRef timer, void *info) { void timeout_callback(CFRunLoopTimerRef timer, void *info) {
if (!found_device) { if (!found_device) {
printf("Timed out waiting for device.\n"); printf("[....] Timed out waiting for device.\n");
exit(1); exit(1);
} }
} }
void usage(const char* app) { void usage(const char* app) {
printf("usage: %s [-V/--version] [-v/--verbose] [-d/--debug] [-i/--id device_id] -b/--bundle bundle.app [-a/--args arguments] [-t/--timeout timeout(seconds)]\n", app); printf(
"Usage: %s [OPTION]...\n"
" -d, --debug launch the app in GDB after installation\n"
" -i, --id <device_id> the id of the device to connect to\n"
" -c, --detect only detect if the device is connected\n"
" -b, --bundle <bundle.app> the path to the app bundle to be installed\n"
" -a, --args <args> command line arguments to pass to the app when launching it\n"
" -t, --timeout <timeout> number of seconds to wait for a device to be connected\n"
" -u, --unbuffered don't buffer stdout\n"
" -g, --gdbargs <args> extra arguments to pass to GDB when starting the debugger\n"
" -x, --gdbexec <file> GDB commands script file\n"
" -n, --nostart do not start the app when debugging\n"
" -v, --verbose enable verbose output\n"
" -m, --noinstall directly start debugging without app install (-d not required) \n"
" -V, --version print the executable version \n",
app);
} }
void version() { void show_version() {
printf("%s\n", APP_VERSION); printf("%s\n", APP_VERSION);
} }
@@ -521,14 +803,23 @@ int main(int argc, char *argv[]) {
{ "args", required_argument, NULL, 'a' }, { "args", required_argument, NULL, 'a' },
{ "verbose", no_argument, NULL, 'v' }, { "verbose", no_argument, NULL, 'v' },
{ "timeout", required_argument, NULL, 't' }, { "timeout", required_argument, NULL, 't' },
{ "gdbexec", no_argument, NULL, 'x' },
{ "unbuffered", no_argument, NULL, 'u' },
{ "nostart", no_argument, NULL, 'n' },
{ "detect", no_argument, NULL, 'c' },
{ "version", no_argument, NULL, 'V' }, { "version", no_argument, NULL, 'V' },
{ "noinstall", no_argument, NULL, 'm' },
{ NULL, 0, NULL, 0 }, { NULL, 0, NULL, 0 },
}; };
char ch; char ch;
while ((ch = getopt_long(argc, argv, "Vdvi:b:a:t:", longopts, NULL)) != -1) while ((ch = getopt_long(argc, argv, "Vmcdvuni:b:a:t:g:x:", longopts, NULL)) != -1)
{ {
switch (ch) { switch (ch) {
case 'm':
install = 0;
debug = 1;
break;
case 'd': case 'd':
debug = 1; debug = 1;
break; break;
@@ -544,26 +835,48 @@ int main(int argc, char *argv[]) {
case 'v': case 'v':
verbose = 1; verbose = 1;
break; break;
case 'V':
version();
return 1;
case 't': case 't':
timeout = atoi(optarg); timeout = atoi(optarg);
break; break;
case 'u':
unbuffered = 1;
break;
case 'n':
nostart = 1;
break;
case 'c':
detect_only = true;
break;
case 'V':
show_version();
return 1;
default: default:
usage(argv[0]); usage(argv[0]);
return 1; return 1;
} }
} }
if (!app_path) { if (!app_path && !detect_only) {
usage(argv[0]); usage(argv[0]);
exit(0); exit(0);
} }
printf("------ Install phase ------\n"); if (unbuffered) {
setbuf(stdout, NULL);
setbuf(stderr, NULL);
}
if (detect_only && timeout == 0) {
timeout = 5;
}
if (!detect_only) {
printf("------ Install phase ------\n");
}
if (app_path) {
assert(access(app_path, F_OK) == 0); assert(access(app_path, F_OK) == 0);
}
AMDSetLogLevel(5); // otherwise syslog gets flooded with crap AMDSetLogLevel(5); // otherwise syslog gets flooded with crap
if (timeout > 0) if (timeout > 0)

View File

@@ -1,11 +1,12 @@
{ {
"name": "ios-deploy", "name": "ios-deploy",
"version": "1.0.2", "version": "1.0.5",
"description": "launch iOS apps iOS devices from the command line (Xcode 4)", "description": "launch iOS apps iOS devices from the command line (Xcode 4)",
"main": "ios-deploy", "main": "ios-deploy",
"scripts": { "scripts": {
"install": "make install prefix=/usr/local" "preinstall": "make ios-deploy"
}, },
"bin" : "./ios-deploy" ,
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/phonegap/ios-deploy" "url": "https://github.com/phonegap/ios-deploy"