From 661d244eb7381c86e08cc3455d30b1796922e989 Mon Sep 17 00:00:00 2001 From: Joshua Hill Date: Thu, 15 Sep 2011 01:06:29 -0400 Subject: [PATCH] Initial Commit --- .autotools | 37 +++++ .cproject | 391 ++++++++++++++++++++++++++++++++++++++++++++++++ .project | 72 +++++++++ AUTHORS | 1 + COPYING | 1 + ChangeLog | 0 INSTALL | 234 +++++++++++++++++++++++++++++ Makefile.am | 1 + NEWS | 1 + README | 1 + autogen.sh | 7 + configure.ac | 19 +++ src/Makefile.am | 17 +++ src/absinthe.c | 136 +++++++++++++++++ src/absinthe.h | 14 ++ src/debug.h | 23 +++ src/device.c | 64 ++++++++ src/device.h | 23 +++ src/lockdown.c | 68 +++++++++ src/lockdown.h | 25 ++++ src/mb2.c | 64 ++++++++ src/mb2.h | 28 ++++ 22 files changed, 1227 insertions(+) create mode 100644 .autotools create mode 100644 .cproject create mode 100644 .project create mode 100644 AUTHORS create mode 100644 COPYING create mode 100644 ChangeLog create mode 100644 INSTALL create mode 100644 Makefile.am create mode 100644 NEWS create mode 100644 README create mode 100755 autogen.sh create mode 100644 configure.ac create mode 100644 src/Makefile.am create mode 100644 src/absinthe.c create mode 100644 src/absinthe.h create mode 100644 src/debug.h create mode 100644 src/device.c create mode 100644 src/device.h create mode 100644 src/lockdown.c create mode 100644 src/lockdown.h create mode 100644 src/mb2.c create mode 100644 src/mb2.h diff --git a/.autotools b/.autotools new file mode 100644 index 0000000..1f99745 --- /dev/null +++ b/.autotools @@ -0,0 +1,37 @@ + + + + + diff --git a/.cproject b/.cproject new file mode 100644 index 0000000..ceb34ac --- /dev/null +++ b/.cproject @@ -0,0 +1,391 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + make + + all + true + true + false + + + make + + am--refresh + true + true + false + + + make + + check + true + true + false + + + make + + clean + true + true + false + + + make + + ctags + true + true + false + + + make + + ctags-recursive + true + true + false + + + make + + dist + true + true + false + + + make + + dist-all + true + true + false + + + make + + dist-bzip2 + true + true + false + + + make + + dist-gzip + true + true + false + + + make + + dist-shar + true + true + false + + + make + + dist-tarZ + true + true + false + + + make + + dist-zip + true + true + false + + + make + + distcheck + true + true + false + + + make + + distclean + true + true + false + + + make + + distclean-tags + true + true + false + + + make + + distcleancheck + true + true + false + + + make + + distdir + true + true + false + + + make + + distuninstallcheck + true + true + false + + + make + + dvi + true + true + false + + + make + + html + true + true + false + + + make + + info + true + true + false + + + make + + install + true + true + false + + + make + + install-data + true + true + false + + + make + + install-dvi + true + true + false + + + make + + install-exec + true + true + false + + + make + + install-html + true + true + false + + + make + + install-info + true + true + false + + + make + + install-man + true + true + false + + + make + + install-pdf + true + true + false + + + make + + install-ps + true + true + false + + + make + + install-strip + true + true + false + + + make + + installcheck + true + true + false + + + make + + installdirs + true + true + false + + + make + + maintainer-clean + true + true + false + + + make + + Makefile + true + true + false + + + make + + mostlyclean + true + true + false + + + make + + pdf + true + true + false + + + make + + ps + true + true + false + + + make + + tags + true + true + false + + + make + + tags-recursive + true + true + false + + + make + + uninstall + true + true + false + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..5c81e31 --- /dev/null +++ b/.project @@ -0,0 +1,72 @@ + + + absinthe + + + + + + org.eclipse.linuxtools.cdt.autotools.core.genmakebuilderV2 + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.buildArguments + + + + org.eclipse.cdt.make.core.buildCommand + make + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + org.eclipse.linuxtools.cdt.autotools.core.autotoolsNatureV2 + + diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..56ea1eb --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Joshua Hill diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..54c4590 --- /dev/null +++ b/COPYING @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..e69de29 diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..5458714 --- /dev/null +++ b/INSTALL @@ -0,0 +1,234 @@ +Installation Instructions +************************* + +Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, +2006 Free Software Foundation, Inc. + +This file is free documentation; the Free Software Foundation gives +unlimited permission to copy, distribute and modify it. + +Basic Installation +================== + +Briefly, the shell commands `./configure; make; make install' should +configure, build, and install this package. The following +more-detailed instructions are generic; see the `README' file for +instructions specific to this package. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, and a +file `config.log' containing compiler output (useful mainly for +debugging `configure'). + + It can also use an optional file (typically called `config.cache' +and enabled with `--cache-file=config.cache' or simply `-C') that saves +the results of its tests to speed up reconfiguring. Caching is +disabled by default to prevent problems with accidental use of stale +cache files. + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If you are using the cache, and at +some point `config.cache' contains results you don't want to keep, you +may remove or edit it. + + The file `configure.ac' (or `configure.in') is used to create +`configure' by a program called `autoconf'. You need `configure.ac' if +you want to change it or regenerate `configure' using a newer version +of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. + + Running `configure' might take a while. While running, it prints + some messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + +Compilers and Options +===================== + +Some systems require unusual options for compilation or linking that the +`configure' script does not know about. Run `./configure --help' for +details on some of the pertinent environment variables. + + You can give `configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here +is an example: + + ./configure CC=c99 CFLAGS=-g LIBS=-lposix + + *Note Defining Variables::, for more details. + +Compiling For Multiple Architectures +==================================== + +You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you can use GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. + + With a non-GNU `make', it is safer to compile the package for one +architecture at a time in the source code directory. After you have +installed the package for one architecture, use `make distclean' before +reconfiguring for another architecture. + +Installation Names +================== + +By default, `make install' installs the package's commands under +`/usr/local/bin', include files under `/usr/local/include', etc. You +can specify an installation prefix other than `/usr/local' by giving +`configure' the option `--prefix=PREFIX'. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +pass the option `--exec-prefix=PREFIX' to `configure', the package uses +PREFIX as the prefix for installing programs and libraries. +Documentation and other data files still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=DIR' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + +Optional Features +================= + +Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + +Specifying the System Type +========================== + +There may be some features `configure' cannot figure out automatically, +but needs to determine by the type of machine the package will run on. +Usually, assuming the package is built to be run on the _same_ +architectures, `configure' can figure that out, but if it prints a +message saying it cannot guess the machine type, give it the +`--build=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name which has the form: + + CPU-COMPANY-SYSTEM + +where SYSTEM can have one of these forms: + + OS KERNEL-OS + + See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the machine type. + + If you are _building_ compiler tools for cross-compiling, you should +use the option `--target=TYPE' to select the type of system they will +produce code for. + + If you want to _use_ a cross compiler, that generates code for a +platform different from the build platform, you should specify the +"host" platform (i.e., that on which the generated programs will +eventually be run) with `--host=TYPE'. + +Sharing Defaults +================ + +If you want to set default values for `configure' scripts to share, you +can create a site shell script called `config.site' that gives default +values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Defining Variables +================== + +Variables not defined in a site shell script can be set in the +environment passed to `configure'. However, some packages may run +configure again during the build, and the customized values of these +variables may be lost. In order to avoid this problem, you should set +them in the `configure' command line, using `VAR=value'. For example: + + ./configure CC=/usr/local2/bin/gcc + +causes the specified `gcc' to be used as the C compiler (unless it is +overridden in the site shell script). + +Unfortunately, this technique does not work for `CONFIG_SHELL' due to +an Autoconf bug. Until the bug is fixed you can use this workaround: + + CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash + +`configure' Invocation +====================== + +`configure' recognizes the following options to control how it operates. + +`--help' +`-h' + Print a summary of the options to `configure', and exit. + +`--version' +`-V' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`--cache-file=FILE' + Enable the cache: use and save the results of the tests in FILE, + traditionally `config.cache'. FILE defaults to `/dev/null' to + disable caching. + +`--config-cache' +`-C' + Alias for `--cache-file=config.cache'. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`configure' also accepts some other, not widely useful, options. Run +`configure --help' for more details. + diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..1bfdcf4 --- /dev/null +++ b/Makefile.am @@ -0,0 +1 @@ +SUBDIRS=src diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..1e43e79 --- /dev/null +++ b/NEWS @@ -0,0 +1 @@ +Sample NEWS file for absinthe project. diff --git a/README b/README new file mode 100644 index 0000000..3a95628 --- /dev/null +++ b/README @@ -0,0 +1 @@ +Sample readme file for absinthe project. diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..129cbe0 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,7 @@ +#!/bin/sh +aclocal +autoconf +autoheader +automake -a -c +autoreconf -i +CFLAGS="-g -arch i386" ./configure diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..9e4224f --- /dev/null +++ b/configure.ac @@ -0,0 +1,19 @@ +dnl Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.59) +AC_INIT(absinthe, 1.0) + + +AC_CANONICAL_SYSTEM +AM_INIT_AUTOMAKE() + +AM_PROG_CC_C_O +AC_CONFIG_HEADERS(config.h) + +PKG_CHECK_MODULES(libimobiledevice, libimobiledevice-1.0 >= 1.1.0) +PKG_CHECK_MODULES(libcrypto, libcrypto >= 0.9.8) +PKG_CHECK_MODULES(libplist, libplist >= 0.15) + +AC_CONFIG_FILES(Makefile src/Makefile) +AC_OUTPUT + diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..f6e4a39 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,17 @@ +AM_CFLAGS = \ + $(GLOBAL_CFLAGS) \ + $(libimobiledevice_CFLAGS) \ + $(libplist_CFLAGS) \ + $(libcrypto_CFLAGS) + +AM_LDFLAGS = \ + $(GLOBAL_LIBS) \ + $(libimobiledevice_LIBS) \ + $(libplist_LIBS) \ + $(libcrypto_LIBS) + +bin_PROGRAMS = absinthe + +absinthe_SOURCES = absinthe.c device.c lockdown.c mb2.c +absinthe_CFLAGS = $(AM_CFLAGS) +absinthe_LDFLAGS = $(AM_LDFLAGS) \ No newline at end of file diff --git a/src/absinthe.c b/src/absinthe.c new file mode 100644 index 0000000..85c2ee0 --- /dev/null +++ b/src/absinthe.c @@ -0,0 +1,136 @@ +/** + * GreenPois0n Absinthe - absinthe.c + * Copyright (C) 2010 Chronic-Dev Team + * Copyright (C) 2010 Joshua Hill + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + **/ + +#include +#include +#include + +// Comment this out for production build to remove all debugging strings +#define _DEBUG +#include "mb2.h" +#include "debug.h" +#include "device.h" + +int main(int argc, char* argv[]) { + int err = 0; + + // Pass a UUID here if you want to target a single device, + // or NULL to select the first one it finds. + printf("Openning device connection\n"); + device_t* device = device_create(NULL); + if (device == NULL) { + error("Unable to find a device to use\n"); + return -1; + } + device_enable_debug(); + + // First we need to discover all the dylib base addresses so we can find our + // ROP gadgets for our payloads. We do this by crashing BackupAgent2 once, + // then downloading the crashreport from the crashreport service. + info("Opening connection to MobileBackup2 service\n"); + mb2_t* mb2 = mb2_connect(device); + if (mb2 == NULL) { + error("Unable to open connection to MobileBackup2 service"); + device_free(device); + return -1; + } +/* + // The second argument here is a pointer to the crashreport_t object containing + // our dylib base address, as well as the state the device was in last time + // it crashed. + info("Crashing MobileBackup2 exploit so we can fetch a clean crashreport\n"); + err = mb2_crash(mb2); + if (err < 0) { + debug("Unable to crash MobileBackup2 service\n", err); + device_free(device); + return -1; + } + // We'll just leak this for now since the program has crashed (hopefully) + //mb2_free(mb2); + + info("Giving the device a moment to write the crash report...\n"); + sleep(3); + + // Here we open crashreporter so we can download the mobilebackup2 crashreport + // and parse the "random" dylib addresses. Thank you ASLR for nothing. ;P + info("Opening connection to CrashReporter service\n"); + crashreporter_t* reporter = crashreporter_connect(device); + if (reporter == NULL) { + error("Unable to open connection to crash reporter\n"); + device_free(device); + return -1; + } + + // Read in the last crash since that's probably our fault anyways. Since dylib + // addresses are only randomized on boot, we now have base addresses to + // calculate the addresses of our ROP gadgets we need. + info("Reading in crash reports from mobile backup\n"); + crashreport_t* crash = crashreporter_last_crash(reporter); + if (crash == NULL) { + error("Unable to read last crash\n"); + device_free(device); + return -1; + } + crashreporter_free(reporter); + + // Open and initialize a connection to MobileBackup2 service again to perform + // our injection exploit + info("Opening connection to backup service\n"); + mb2 = mb2_connect(device); + if (mb2 == NULL) { + error("Unable to open connection to MobileBackup2 service\n"); + device_free(device); + return -1; + } + + // Due to Apple's new ASLR, before we can overwrite stack with our ROP payload, + // we're going to need to figure out where our data is being stored. Heap + // and stack are randomized on each execution. + info("Injecting ROP payload and leaking it's addresss\n"); + err = mb2_inject(mb2); + if(err < 0) { + error("Unable to inject ROP payload or discover it's offset\n"); + device_free(device); + return -1; + } + + // Now that we know where our data is, and we know where all the code is, we can + // pivot the stack onto our ROP payload and execute our kernel vulnerability. + info("Executing kernel exploit and patching codesign\n"); + err = mb2_exploit(mb2); + if(err < 0) { + error("Unable to execute kernel exploit and patch codesign\n"); + device_free(device); + return -1; + } + + // All done, not sure if we should clean this up yet + info("Closing MobileBackup2 service\n"); + mb2_free(mb2); + + // If open, then close and free structures + info("Cleaning up\n"); + if (crash) crashreport_free(crash); + if (reporter) crashreporter_free(reporter); +*/ + if (mb2) mb2_free(mb2); + if (device) device_free(device); + info("Done\n"); + return 0; +} diff --git a/src/absinthe.h b/src/absinthe.h new file mode 100644 index 0000000..858e6dd --- /dev/null +++ b/src/absinthe.h @@ -0,0 +1,14 @@ +/* + * absinthe.h + * + * Created on: Sep 12, 2011 + * Author: posixninja + */ + +#ifndef ABSINTHE_H_ +#define ABSINTHE_H_ + + + + +#endif /* ABSINTHE_H_ */ diff --git a/src/debug.h b/src/debug.h new file mode 100644 index 0000000..badfe4f --- /dev/null +++ b/src/debug.h @@ -0,0 +1,23 @@ +/* + * debug.h + * + * Created on: Sep 12, 2011 + * Author: posixninja + */ + +#ifndef DEBUG_H_ +#define DEBUG_H_ + +#include + +#ifdef _DEBUG +#define info(...) fprintf(stdout, __VA_ARGS__) +#define error(...) fprintf(stderr, __VA_ARGS__) +#define debug(...) fprintf(stderr, __VA_ARGS__) +#else +#define info(...) printf(__VA_ARGS__) +#define error(...) fprintf(stderr, __VA_ARGS__) +#define debug(...) +#endif + +#endif /* DEBUG_H_ */ diff --git a/src/device.c b/src/device.c new file mode 100644 index 0000000..b8d1247 --- /dev/null +++ b/src/device.c @@ -0,0 +1,64 @@ +/* + * device.c + * + * Created on: May 5, 2011 + * Author: posixninja + */ + +/* This is the application Controller. + * This file should contain functions to control the device + * through lockdownd services. This file acts as a proxy to + * the afc, mb2, and nos services and should handle messages. + */ + +#include +#include +#include +#include + +#include "device.h" + +device_t* device_create(const char* uuid) { + idevice_error_t err = 0; + device_t* device = NULL; + device = (device_t*) malloc(sizeof(device_t)); + if (device == NULL) { + return NULL; + } + memset(device, '\0', sizeof(device_t)); + + if (uuid == NULL) { + err = idevice_new(&(device->client), NULL); + if (err != IDEVICE_E_SUCCESS) { + fprintf(stderr, + "No device found with uuid %s, is it plugged in?\n", uuid); + return NULL; + } + idevice_get_uuid(device->client, (char**)&device->uuid); + + } else { + err = idevice_new(&(device->client), uuid); + if (err != IDEVICE_E_SUCCESS) { + fprintf(stderr, + "No device found with uuid %s, is it plugged in?\n", uuid); + return NULL; + } + device->uuid = strdup(uuid); + } + + return device; +} + +void device_free(device_t* device) { + if (device) { + if(device->uuid) { + free(device->uuid); + device->uuid = NULL; + } + free(device); + } +} + +void device_enable_debug() { + idevice_set_debug_level(3); +} diff --git a/src/device.h b/src/device.h new file mode 100644 index 0000000..00ff158 --- /dev/null +++ b/src/device.h @@ -0,0 +1,23 @@ +/* + * device.h + * + * Created on: May 5, 2011 + * Author: posixninja + */ + +#ifndef DEVICE_H_ +#define DEVICE_H_ + +#include + +typedef struct device_t { + idevice_t client; + unsigned char* uuid; + unsigned char* ecid; +} device_t; + +device_t* device_create(const char* uuid); +void device_free(device_t* device); +void device_enable_debug(); + +#endif /* DEVICE_H_ */ diff --git a/src/lockdown.c b/src/lockdown.c new file mode 100644 index 0000000..5474ee7 --- /dev/null +++ b/src/lockdown.c @@ -0,0 +1,68 @@ +/* + * lockdown.c + * + * Created on: May 5, 2011 + * Author: posixninja + */ + +#include +#include +#include +#include + +#include "device.h" +#include "lockdown.h" + +lockdown_t* lockdown_open(device_t* device) { + lockdownd_client_t lockdownd = NULL; + if (lockdownd_client_new_with_handshake(device->client, &lockdownd, "apparition") != LOCKDOWN_E_SUCCESS) { + return NULL; + } + + lockdown_t* lockdown = (lockdown_t*) malloc(sizeof(lockdown_t)); + if (lockdown == NULL) { + return NULL; + } + memset(lockdown, '\0', sizeof(lockdown_t)); + + lockdown->client = lockdownd; + lockdown->device = device; + return lockdown; +} + +int lockdown_start_service(lockdown_t* lockdown, const char* service, uint16_t* port) { + uint16_t port_value = 0; + lockdownd_start_service(lockdown->client, service, &port_value); + + if (port_value) { + printf("Started %s successfully on port %d!\n", service, port_value); + *port = port_value; + return 0; + } else { + + printf("%s failed to start!\n", service); + return -1; + } + + return -1; +} + +int lockdown_stop_service(lockdown_t* lockdown, const char* service) { + //TODO: Implement Me + return -1; +} + +int lockdown_close(lockdown_t* lockdown) { + lockdownd_client_free(lockdown->client); + lockdown->client = NULL; + return 0; +} + +void lockdown_free(lockdown_t* lockdown) { + if (lockdown) { + if (lockdown->client) { + lockdown_close(lockdown); + } + free(lockdown); + } +} diff --git a/src/lockdown.h b/src/lockdown.h new file mode 100644 index 0000000..316a137 --- /dev/null +++ b/src/lockdown.h @@ -0,0 +1,25 @@ +/* + * lockdown.h + * + * Created on: May 5, 2011 + * Author: posixninja + */ + +#ifndef LOCKDOWN_H_ +#define LOCKDOWN_H_ + +#include +#include "device.h" + +typedef struct lockdown_t { + device_t *device; + lockdownd_client_t client; +} lockdown_t; + +lockdown_t* lockdown_open(device_t* device); +int lockdown_start_service(lockdown_t* lockdown, const char* service, uint16_t* port); +int lockdown_stop_service(lockdown_t* lockdown, const char* service); +int lockdown_close(lockdown_t* lockdown); +void lockdown_free(lockdown_t* lockdown); + +#endif /* LOCKDOWN_H_ */ diff --git a/src/mb2.c b/src/mb2.c new file mode 100644 index 0000000..6bcc6d2 --- /dev/null +++ b/src/mb2.c @@ -0,0 +1,64 @@ +/* + * mb2.c + * + * Created on: May 5, 2011 + * Author: posixninja + */ + +#include +#include +#include + +#include "mb2.h" +#include "debug.h" + +mb2_t* mb2_create() { + mb2_t* mb2 = (mb2_t*) malloc(sizeof(mb2_t)); + if (mb2 != NULL) { + memset(mb2, '\0', sizeof(mb2_t)); + } + return mb2; +} + +mb2_t* mb2_connect(device_t* device) { + int err = 0; + uint16_t port = 0; + mb2_t* mb2 = NULL; + lockdown_t* lockdown = NULL; + + lockdown = lockdown_open(device); + if(lockdown == NULL) { + error("Unable to open connection to lockdownd\n"); + return NULL; + } + + err = lockdown_start_service(lockdown, "com.apple.mobilebackup2", &port); + if(err < 0) { + error("Unable to start MobileBackup2 service\n"); + return NULL; + } + lockdown_close(lockdown); + + mb2 = mb2_open(device, port); + if(mb2 == NULL) { + error("Unable to open connection to MobileBackup2 service\n"); + return NULL; + } + + return mb2; +} + +mb2_t* mb2_open(device_t* device, uint16_t port) { + return mb2_create(); +} + +void mb2_free(mb2_t* mb2) { + if (mb2) { + if (mb2->client) { + mobilebackup2_client_free(mb2->client); + mb2->client = NULL; + } + mb2->device = NULL; + free(mb2); + } +} diff --git a/src/mb2.h b/src/mb2.h new file mode 100644 index 0000000..220cf5d --- /dev/null +++ b/src/mb2.h @@ -0,0 +1,28 @@ +/* + * mb2.h + * Functions for lockdownd's mobilebackup2 service + * + * Created on: May 5, 2011 + * Author: posixninja + */ + +#ifndef MB2_H_ +#define MB2_H_ + +#include + +#include "device.h" +#include "lockdown.h" + +typedef struct mb2_t { + uint16_t port; + device_t* device; + mobilebackup2_client_t client; +} mb2_t; + +mb2_t* mb2_create(); +mb2_t* mb2_connect(device_t* device); +mb2_t* mb2_open(device_t* device, uint16_t port); +void mb2_free(mb2_t* mb2); + +#endif /* MB2_H_ */