├── .gitignore ├── Makefile.am ├── autogen.sh ├── configure.ac ├── igetnonce.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist └── igetnonce ├── Makefile.am ├── all.h ├── common.c ├── common.h ├── dfu.c ├── dfu.h ├── endianness.h ├── idevicerestore.c ├── idevicerestore.h ├── main.c ├── normal.c ├── normal.h ├── recovery.c └── recovery.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | *.patch 3 | *.diff 4 | */.libs 5 | */.deps 6 | *.a 7 | *.o 8 | *.la 9 | *.lo 10 | *.so 11 | *Makefile 12 | *Makefile.in 13 | aclocal.m4 14 | autom4te.cache 15 | compile 16 | config.* 17 | configure 18 | depcomp 19 | install-sh 20 | libtool 21 | ltmain.sh 22 | m4 23 | missing 24 | */igetnonce* 25 | stamp-h1 26 | xcuserdata -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = foreign 2 | SUBDIRS=igetnonce 3 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | gprefix=`which glibtoolize 2>&1 >/dev/null` 4 | if [ $? -eq 0 ]; then 5 | glibtoolize --force 6 | else 7 | libtoolize --force 8 | fi 9 | 10 | aclocal -I m4 11 | autoconf 12 | autoheader 13 | automake --add-missing 14 | 15 | if [ -z $NOCONFIGURE ]; then 16 | ./configure "$@" 17 | fi 18 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_PREREQ([2.69]) 2 | AC_INIT([igetnonce], [1.0], [tihmstar@gmail.com]) 3 | 4 | # Prepare for automake. 5 | AM_INIT_AUTOMAKE([foreign]) 6 | AC_CONFIG_HEADERS([config.h]) 7 | 8 | # Check for operating system. 9 | AC_MSG_CHECKING([whether we need platform-specific build settings]) 10 | case $host_os in 11 | darwin* ) 12 | ;; 13 | esac 14 | 15 | # Checks for programs. 16 | AC_PROG_CC 17 | CFLAGS+=" -std=c11" 18 | AC_PROG_INSTALL 19 | AC_PROG_LIBTOOL 20 | 21 | # Versioning. 22 | CFLAGS+=" -D IGETNONCE_VERSION_COUNT=\\\"$(git rev-list --count HEAD | tr -d '\n')\\\"" 23 | CFLAGS+=" -D IGETNONCE_VERSION_SHA=\\\"$(git rev-parse HEAD | tr -d '\n')\\\"" 24 | 25 | # Checks for libraries. 26 | PKG_CHECK_MODULES(libimobiledevice, libimobiledevice-1.0 >= 1.2.1) 27 | PKG_CHECK_MODULES(libirecovery, libirecovery >= 0.2.0) 28 | PKG_CHECK_MODULES(libusbmuxd, libusbmuxd >= 0.29.1) 29 | PKG_CHECK_MODULES(openssl, openssl >= 0.9.8) 30 | 31 | # Checks for header files. 32 | AC_CHECK_HEADERS([getopt.h stdio.h]) 33 | 34 | # Checks for typedefs, structures, and compiler characteristics. 35 | AC_TYPE_INT32_T 36 | AC_TYPE_INT64_T 37 | AC_TYPE_SIZE_T 38 | AC_TYPE_UINT32_T 39 | AC_TYPE_UINT64_T 40 | 41 | # Checks for library functions. 42 | AC_FUNC_ERROR_AT_LINE 43 | AC_FUNC_FSEEKO 44 | AC_FUNC_MALLOC 45 | AC_CHECK_FUNCS([memset strdup strrchr]) 46 | 47 | AC_OUTPUT([ 48 | Makefile 49 | igetnonce/Makefile 50 | ]) 51 | -------------------------------------------------------------------------------- /igetnonce.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 47; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 5669113823B4B50700C93279 /* libusbmuxd.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5669113723B4B50700C93279 /* libusbmuxd.a */; }; 11 | 5669113B23B4B52E00C93279 /* libirecovery.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5669113A23B4B52E00C93279 /* libirecovery.a */; }; 12 | 5669113D23B4B53E00C93279 /* libimobiledevice.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5669113C23B4B53E00C93279 /* libimobiledevice.a */; }; 13 | 5669113F23B4B63F00C93279 /* endianness.h in Sources */ = {isa = PBXBuildFile; fileRef = 873FC1221E22D7B40089AE60 /* endianness.h */; }; 14 | 5669114023B4B64600C93279 /* all.h in Sources */ = {isa = PBXBuildFile; fileRef = 5669113623B4B4C300C93279 /* all.h */; }; 15 | 5669114223B4B7C500C93279 /* libcrypto.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5669114123B4B7C400C93279 /* libcrypto.a */; }; 16 | 873FC1291E22D7B40089AE60 /* common.c in Sources */ = {isa = PBXBuildFile; fileRef = 873FC11E1E22D7B40089AE60 /* common.c */; }; 17 | 873FC12A1E22D7B40089AE60 /* dfu.c in Sources */ = {isa = PBXBuildFile; fileRef = 873FC1201E22D7B40089AE60 /* dfu.c */; }; 18 | 873FC12B1E22D7B40089AE60 /* idevicerestore.c in Sources */ = {isa = PBXBuildFile; fileRef = 873FC1231E22D7B40089AE60 /* idevicerestore.c */; }; 19 | 873FC12C1E22D7B40089AE60 /* normal.c in Sources */ = {isa = PBXBuildFile; fileRef = 873FC1251E22D7B40089AE60 /* normal.c */; }; 20 | 873FC12D1E22D7B40089AE60 /* recovery.c in Sources */ = {isa = PBXBuildFile; fileRef = 873FC1271E22D7B40089AE60 /* recovery.c */; }; 21 | 87FBE6521D2BCC0700FB5E05 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 87FBE6511D2BCC0700FB5E05 /* main.c */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXCopyFilesBuildPhase section */ 25 | 87FBE64C1D2BCC0700FB5E05 /* CopyFiles */ = { 26 | isa = PBXCopyFilesBuildPhase; 27 | buildActionMask = 2147483647; 28 | dstPath = /usr/share/man/man1/; 29 | dstSubfolderSpec = 0; 30 | files = ( 31 | ); 32 | runOnlyForDeploymentPostprocessing = 1; 33 | }; 34 | /* End PBXCopyFilesBuildPhase section */ 35 | 36 | /* Begin PBXFileReference section */ 37 | 5669113623B4B4C300C93279 /* all.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = all.h; sourceTree = ""; }; 38 | 5669113723B4B50700C93279 /* libusbmuxd.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libusbmuxd.a; path = ../../../../../usr/local/lib/libusbmuxd.a; sourceTree = ""; }; 39 | 5669113A23B4B52E00C93279 /* libirecovery.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libirecovery.a; path = ../../../../../usr/local/lib/libirecovery.a; sourceTree = ""; }; 40 | 5669113C23B4B53E00C93279 /* libimobiledevice.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libimobiledevice.a; path = ../../../../../usr/local/lib/libimobiledevice.a; sourceTree = ""; }; 41 | 5669114123B4B7C400C93279 /* libcrypto.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libcrypto.a; path = ../../../../../usr/local/lib/libcrypto.a; sourceTree = ""; }; 42 | 873FC11E1E22D7B40089AE60 /* common.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = common.c; sourceTree = ""; }; 43 | 873FC11F1E22D7B40089AE60 /* common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = common.h; sourceTree = ""; }; 44 | 873FC1201E22D7B40089AE60 /* dfu.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dfu.c; sourceTree = ""; }; 45 | 873FC1211E22D7B40089AE60 /* dfu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dfu.h; sourceTree = ""; }; 46 | 873FC1221E22D7B40089AE60 /* endianness.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = endianness.h; sourceTree = ""; }; 47 | 873FC1231E22D7B40089AE60 /* idevicerestore.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = idevicerestore.c; sourceTree = ""; }; 48 | 873FC1241E22D7B40089AE60 /* idevicerestore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = idevicerestore.h; sourceTree = ""; }; 49 | 873FC1251E22D7B40089AE60 /* normal.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = normal.c; sourceTree = ""; }; 50 | 873FC1261E22D7B40089AE60 /* normal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = normal.h; sourceTree = ""; }; 51 | 873FC1271E22D7B40089AE60 /* recovery.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = recovery.c; sourceTree = ""; }; 52 | 873FC1281E22D7B40089AE60 /* recovery.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = recovery.h; sourceTree = ""; }; 53 | 87FBE64E1D2BCC0700FB5E05 /* igetnonce */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = igetnonce; sourceTree = BUILT_PRODUCTS_DIR; }; 54 | 87FBE6511D2BCC0700FB5E05 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = ""; }; 55 | /* End PBXFileReference section */ 56 | 57 | /* Begin PBXFrameworksBuildPhase section */ 58 | 87FBE64B1D2BCC0700FB5E05 /* Frameworks */ = { 59 | isa = PBXFrameworksBuildPhase; 60 | buildActionMask = 2147483647; 61 | files = ( 62 | 5669113D23B4B53E00C93279 /* libimobiledevice.a in Frameworks */, 63 | 5669113B23B4B52E00C93279 /* libirecovery.a in Frameworks */, 64 | 5669114223B4B7C500C93279 /* libcrypto.a in Frameworks */, 65 | 5669113823B4B50700C93279 /* libusbmuxd.a in Frameworks */, 66 | ); 67 | runOnlyForDeploymentPostprocessing = 0; 68 | }; 69 | /* End PBXFrameworksBuildPhase section */ 70 | 71 | /* Begin PBXGroup section */ 72 | 873FC12E1E22D7E40089AE60 /* Frameworks */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | 5669113723B4B50700C93279 /* libusbmuxd.a */, 76 | 5669113A23B4B52E00C93279 /* libirecovery.a */, 77 | 5669113C23B4B53E00C93279 /* libimobiledevice.a */, 78 | 5669114123B4B7C400C93279 /* libcrypto.a */, 79 | ); 80 | name = Frameworks; 81 | sourceTree = ""; 82 | }; 83 | 87FBE6451D2BCC0700FB5E05 = { 84 | isa = PBXGroup; 85 | children = ( 86 | 87FBE6501D2BCC0700FB5E05 /* igetnonce */, 87 | 87FBE64F1D2BCC0700FB5E05 /* Products */, 88 | 873FC12E1E22D7E40089AE60 /* Frameworks */, 89 | ); 90 | sourceTree = ""; 91 | }; 92 | 87FBE64F1D2BCC0700FB5E05 /* Products */ = { 93 | isa = PBXGroup; 94 | children = ( 95 | 87FBE64E1D2BCC0700FB5E05 /* igetnonce */, 96 | ); 97 | name = Products; 98 | sourceTree = ""; 99 | }; 100 | 87FBE6501D2BCC0700FB5E05 /* igetnonce */ = { 101 | isa = PBXGroup; 102 | children = ( 103 | 5669113623B4B4C300C93279 /* all.h */, 104 | 873FC11E1E22D7B40089AE60 /* common.c */, 105 | 873FC11F1E22D7B40089AE60 /* common.h */, 106 | 873FC1201E22D7B40089AE60 /* dfu.c */, 107 | 873FC1211E22D7B40089AE60 /* dfu.h */, 108 | 873FC1221E22D7B40089AE60 /* endianness.h */, 109 | 873FC1231E22D7B40089AE60 /* idevicerestore.c */, 110 | 873FC1241E22D7B40089AE60 /* idevicerestore.h */, 111 | 873FC1251E22D7B40089AE60 /* normal.c */, 112 | 873FC1261E22D7B40089AE60 /* normal.h */, 113 | 873FC1271E22D7B40089AE60 /* recovery.c */, 114 | 873FC1281E22D7B40089AE60 /* recovery.h */, 115 | 87FBE6511D2BCC0700FB5E05 /* main.c */, 116 | ); 117 | path = igetnonce; 118 | sourceTree = ""; 119 | }; 120 | /* End PBXGroup section */ 121 | 122 | /* Begin PBXNativeTarget section */ 123 | 87FBE64D1D2BCC0700FB5E05 /* igetnonce */ = { 124 | isa = PBXNativeTarget; 125 | buildConfigurationList = 87FBE6551D2BCC0700FB5E05 /* Build configuration list for PBXNativeTarget "igetnonce" */; 126 | buildPhases = ( 127 | 87FBE64A1D2BCC0700FB5E05 /* Sources */, 128 | 87FBE64B1D2BCC0700FB5E05 /* Frameworks */, 129 | 87FBE64C1D2BCC0700FB5E05 /* CopyFiles */, 130 | 5669113E23B4B5AE00C93279 /* Versioning */, 131 | ); 132 | buildRules = ( 133 | ); 134 | dependencies = ( 135 | ); 136 | name = igetnonce; 137 | productName = igetnonce; 138 | productReference = 87FBE64E1D2BCC0700FB5E05 /* igetnonce */; 139 | productType = "com.apple.product-type.tool"; 140 | }; 141 | /* End PBXNativeTarget section */ 142 | 143 | /* Begin PBXProject section */ 144 | 87FBE6461D2BCC0700FB5E05 /* Project object */ = { 145 | isa = PBXProject; 146 | attributes = { 147 | LastUpgradeCheck = 1130; 148 | ORGANIZATIONNAME = tihmstar; 149 | TargetAttributes = { 150 | 87FBE64D1D2BCC0700FB5E05 = { 151 | CreatedOnToolsVersion = 7.2; 152 | }; 153 | }; 154 | }; 155 | buildConfigurationList = 87FBE6491D2BCC0700FB5E05 /* Build configuration list for PBXProject "igetnonce" */; 156 | compatibilityVersion = "Xcode 6.3"; 157 | developmentRegion = en; 158 | hasScannedForEncodings = 0; 159 | knownRegions = ( 160 | en, 161 | Base, 162 | ); 163 | mainGroup = 87FBE6451D2BCC0700FB5E05; 164 | productRefGroup = 87FBE64F1D2BCC0700FB5E05 /* Products */; 165 | projectDirPath = ""; 166 | projectRoot = ""; 167 | targets = ( 168 | 87FBE64D1D2BCC0700FB5E05 /* igetnonce */, 169 | ); 170 | }; 171 | /* End PBXProject section */ 172 | 173 | /* Begin PBXShellScriptBuildPhase section */ 174 | 5669113E23B4B5AE00C93279 /* Versioning */ = { 175 | isa = PBXShellScriptBuildPhase; 176 | buildActionMask = 2147483647; 177 | files = ( 178 | ); 179 | inputFileListPaths = ( 180 | ); 181 | inputPaths = ( 182 | ); 183 | name = Versioning; 184 | outputFileListPaths = ( 185 | ); 186 | outputPaths = ( 187 | ); 188 | runOnlyForDeploymentPostprocessing = 0; 189 | shellPath = /bin/sh; 190 | shellScript = "#!/bin/bash\nsed -i '.bak' \"s/.*IGETNONCE_VERSION_COMMIT.*/#define IGETNONCE_VERSION_COMMIT \\\"$(git rev-list --count HEAD)\\\"/\" ./igetnonce/all.h 2>/dev/null || sed -i \"s/.*IGETNONCE_VERSION_COMMIT.*/#define IGETNONCE_VERSION_COMMIT \\\"$(git rev-list --count HEAD)\\\"/\" ./igetnonce/all.h 2>/dev/null\nsed -i '.bak' \"s/.*IGETNONCE_VERSION_SHA.*/#define IGETNONCE_VERSION_SHA \\\"$(git rev-list --count HEAD)\\\"/\" ./igetnonce/all.h 2>/dev/null || sed -i \"s/.*IGETNONCE_VERSION_SHA.*/#define IGETNONCE_VERSION_SHA \\\"$(git rev-list --count HEAD)\\\"/\" ./igetnonce/all.h 2>/dev/null\n"; 191 | }; 192 | /* End PBXShellScriptBuildPhase section */ 193 | 194 | /* Begin PBXSourcesBuildPhase section */ 195 | 87FBE64A1D2BCC0700FB5E05 /* Sources */ = { 196 | isa = PBXSourcesBuildPhase; 197 | buildActionMask = 2147483647; 198 | files = ( 199 | 5669114023B4B64600C93279 /* all.h in Sources */, 200 | 873FC12D1E22D7B40089AE60 /* recovery.c in Sources */, 201 | 873FC12A1E22D7B40089AE60 /* dfu.c in Sources */, 202 | 873FC12C1E22D7B40089AE60 /* normal.c in Sources */, 203 | 873FC1291E22D7B40089AE60 /* common.c in Sources */, 204 | 5669113F23B4B63F00C93279 /* endianness.h in Sources */, 205 | 873FC12B1E22D7B40089AE60 /* idevicerestore.c in Sources */, 206 | 87FBE6521D2BCC0700FB5E05 /* main.c in Sources */, 207 | ); 208 | runOnlyForDeploymentPostprocessing = 0; 209 | }; 210 | /* End PBXSourcesBuildPhase section */ 211 | 212 | /* Begin XCBuildConfiguration section */ 213 | 87FBE6531D2BCC0700FB5E05 /* Debug */ = { 214 | isa = XCBuildConfiguration; 215 | buildSettings = { 216 | ALWAYS_SEARCH_USER_PATHS = NO; 217 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 218 | CLANG_CXX_LIBRARY = "libc++"; 219 | CLANG_ENABLE_MODULES = YES; 220 | CLANG_ENABLE_OBJC_ARC = YES; 221 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 222 | CLANG_WARN_BOOL_CONVERSION = YES; 223 | CLANG_WARN_COMMA = YES; 224 | CLANG_WARN_CONSTANT_CONVERSION = YES; 225 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 226 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 227 | CLANG_WARN_EMPTY_BODY = YES; 228 | CLANG_WARN_ENUM_CONVERSION = YES; 229 | CLANG_WARN_INFINITE_RECURSION = YES; 230 | CLANG_WARN_INT_CONVERSION = YES; 231 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 232 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 233 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 234 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 235 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 236 | CLANG_WARN_STRICT_PROTOTYPES = YES; 237 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 238 | CLANG_WARN_UNREACHABLE_CODE = YES; 239 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 240 | CODE_SIGN_IDENTITY = "-"; 241 | COPY_PHASE_STRIP = NO; 242 | DEBUG_INFORMATION_FORMAT = dwarf; 243 | ENABLE_STRICT_OBJC_MSGSEND = YES; 244 | ENABLE_TESTABILITY = YES; 245 | GCC_C_LANGUAGE_STANDARD = gnu99; 246 | GCC_DYNAMIC_NO_PIC = NO; 247 | GCC_NO_COMMON_BLOCKS = YES; 248 | GCC_OPTIMIZATION_LEVEL = 0; 249 | GCC_PREPROCESSOR_DEFINITIONS = ( 250 | "DEBUG=1", 251 | "$(inherited)", 252 | ); 253 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 254 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 255 | GCC_WARN_UNDECLARED_SELECTOR = YES; 256 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 257 | GCC_WARN_UNUSED_FUNCTION = YES; 258 | GCC_WARN_UNUSED_VARIABLE = YES; 259 | HEADER_SEARCH_PATHS = /usr/local/include; 260 | LIBRARY_SEARCH_PATHS = /usr/local/lib; 261 | MACOSX_DEPLOYMENT_TARGET = 10.11; 262 | MTL_ENABLE_DEBUG_INFO = YES; 263 | ONLY_ACTIVE_ARCH = YES; 264 | PRODUCT_BUNDLE_IDENTIFIER = net.tihmstar.igetnonce; 265 | PRODUCT_NAME = igetnonce; 266 | SDKROOT = macosx; 267 | }; 268 | name = Debug; 269 | }; 270 | 87FBE6541D2BCC0700FB5E05 /* Release */ = { 271 | isa = XCBuildConfiguration; 272 | buildSettings = { 273 | ALWAYS_SEARCH_USER_PATHS = NO; 274 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 275 | CLANG_CXX_LIBRARY = "libc++"; 276 | CLANG_ENABLE_MODULES = YES; 277 | CLANG_ENABLE_OBJC_ARC = YES; 278 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 279 | CLANG_WARN_BOOL_CONVERSION = YES; 280 | CLANG_WARN_COMMA = YES; 281 | CLANG_WARN_CONSTANT_CONVERSION = YES; 282 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 283 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 284 | CLANG_WARN_EMPTY_BODY = YES; 285 | CLANG_WARN_ENUM_CONVERSION = YES; 286 | CLANG_WARN_INFINITE_RECURSION = YES; 287 | CLANG_WARN_INT_CONVERSION = YES; 288 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 289 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 290 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 291 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 292 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 293 | CLANG_WARN_STRICT_PROTOTYPES = YES; 294 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 295 | CLANG_WARN_UNREACHABLE_CODE = YES; 296 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 297 | CODE_SIGN_IDENTITY = "-"; 298 | COPY_PHASE_STRIP = NO; 299 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 300 | ENABLE_NS_ASSERTIONS = NO; 301 | ENABLE_STRICT_OBJC_MSGSEND = YES; 302 | GCC_C_LANGUAGE_STANDARD = gnu99; 303 | GCC_NO_COMMON_BLOCKS = YES; 304 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 305 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 306 | GCC_WARN_UNDECLARED_SELECTOR = YES; 307 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 308 | GCC_WARN_UNUSED_FUNCTION = YES; 309 | GCC_WARN_UNUSED_VARIABLE = YES; 310 | HEADER_SEARCH_PATHS = /usr/local/include; 311 | LIBRARY_SEARCH_PATHS = /usr/local/lib; 312 | MACOSX_DEPLOYMENT_TARGET = 10.11; 313 | MTL_ENABLE_DEBUG_INFO = NO; 314 | PRODUCT_BUNDLE_IDENTIFIER = net.tihmstar.igetnonce; 315 | PRODUCT_NAME = igetnonce; 316 | SDKROOT = macosx; 317 | }; 318 | name = Release; 319 | }; 320 | 87FBE6561D2BCC0700FB5E05 /* Debug */ = { 321 | isa = XCBuildConfiguration; 322 | buildSettings = { 323 | ALWAYS_SEARCH_USER_PATHS = YES; 324 | HEADER_SEARCH_PATHS = /usr/local/include; 325 | LIBRARY_SEARCH_PATHS = /usr/local/lib; 326 | PRODUCT_NAME = "$(TARGET_NAME)"; 327 | }; 328 | name = Debug; 329 | }; 330 | 87FBE6571D2BCC0700FB5E05 /* Release */ = { 331 | isa = XCBuildConfiguration; 332 | buildSettings = { 333 | ALWAYS_SEARCH_USER_PATHS = YES; 334 | HEADER_SEARCH_PATHS = /usr/local/include; 335 | LIBRARY_SEARCH_PATHS = /usr/local/lib; 336 | PRODUCT_NAME = "$(TARGET_NAME)"; 337 | }; 338 | name = Release; 339 | }; 340 | /* End XCBuildConfiguration section */ 341 | 342 | /* Begin XCConfigurationList section */ 343 | 87FBE6491D2BCC0700FB5E05 /* Build configuration list for PBXProject "igetnonce" */ = { 344 | isa = XCConfigurationList; 345 | buildConfigurations = ( 346 | 87FBE6531D2BCC0700FB5E05 /* Debug */, 347 | 87FBE6541D2BCC0700FB5E05 /* Release */, 348 | ); 349 | defaultConfigurationIsVisible = 0; 350 | defaultConfigurationName = Release; 351 | }; 352 | 87FBE6551D2BCC0700FB5E05 /* Build configuration list for PBXNativeTarget "igetnonce" */ = { 353 | isa = XCConfigurationList; 354 | buildConfigurations = ( 355 | 87FBE6561D2BCC0700FB5E05 /* Debug */, 356 | 87FBE6571D2BCC0700FB5E05 /* Release */, 357 | ); 358 | defaultConfigurationIsVisible = 0; 359 | defaultConfigurationName = Release; 360 | }; 361 | /* End XCConfigurationList section */ 362 | }; 363 | rootObject = 87FBE6461D2BCC0700FB5E05 /* Project object */; 364 | } 365 | -------------------------------------------------------------------------------- /igetnonce.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /igetnonce.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /igetnonce/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS = $(libirecovery_CFLAGS) $(libimobiledevice_CFLAGS) $(libusbmuxd_CFLAGS) $(openssl_CFLAGS) 2 | AM_LDFLAGS = $(libirecovery_LIBS) $(libimobiledevice_LIBS) $(libusbmuxd_LIBS) $(openssl_LIBS) 3 | 4 | bin_PROGRAMS = igetnonce 5 | igetnonce_CFLAGS = $(AM_CFLAGS) 6 | igetnonce_LDADD = $(AM_LDFLAGS) 7 | igetnonce_SOURCES = common.c dfu.c idevicerestore.c normal.c recovery.c main.c 8 | 9 | -------------------------------------------------------------------------------- /igetnonce/all.h: -------------------------------------------------------------------------------- 1 | // 2 | // all.h 3 | // igetnonce 4 | // 5 | // Created by tihmstar on 08.01.17. 6 | // Copyright © 2017 tihmstar. All rights reserved. 7 | // 8 | 9 | #ifndef all_h 10 | #define all_h 11 | 12 | #ifdef DEBUG // this is for developing with Xcode 13 | #define IGETNONCE_VERSION_COMMIT "Debug" 14 | #define IGETNONCE_VERSION_SHA "Build: " __DATE__ " " __TIME__ 15 | #else 16 | #endif 17 | 18 | #endif /* all_h */ 19 | -------------------------------------------------------------------------------- /igetnonce/common.c: -------------------------------------------------------------------------------- 1 | /* 2 | * common.c 3 | * Misc functions used in idevicerestore 4 | * 5 | * Copyright (c) 2012 Martin Szulecki. All Rights Reserved. 6 | * Copyright (c) 2012 Nikias Bassen. All Rights Reserved. 7 | * Copyright (c) 2010 Joshua Hill. All Rights Reserved. 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "common.h" 32 | 33 | #define MAX_PRINT_LEN 64*1024 34 | 35 | struct idevicerestore_mode_t idevicerestore_modes[] = { 36 | { 0, "WTF" }, 37 | { 1, "DFU" }, 38 | { 2, "Recovery" }, 39 | { 3, "Restore" }, 40 | { 4, "Normal" }, 41 | { -1, NULL } 42 | }; 43 | 44 | int idevicerestore_debug = 0; 45 | 46 | #define idevicerestore_err_buff_size 256 47 | static char idevicerestore_err_buff[idevicerestore_err_buff_size] = {0, }; 48 | 49 | static FILE* info_stream = NULL; 50 | static FILE* error_stream = NULL; 51 | static FILE* debug_stream = NULL; 52 | 53 | static int info_disabled = 0; 54 | static int error_disabled = 0; 55 | static int debug_disabled = 0; 56 | 57 | void info(const char* format, ...) 58 | { 59 | if (info_disabled) return; 60 | va_list vargs; 61 | va_start(vargs, format); 62 | vfprintf((info_stream) ? info_stream : stdout, format, vargs); 63 | va_end(vargs); 64 | } 65 | 66 | void error(const char* format, ...) 67 | { 68 | va_list vargs, vargs2; 69 | va_start(vargs, format); 70 | va_copy(vargs2, vargs); 71 | vsnprintf(idevicerestore_err_buff, idevicerestore_err_buff_size, format, vargs); 72 | va_end(vargs); 73 | if (!error_disabled) { 74 | vfprintf((error_stream) ? error_stream : stderr, format, vargs2); 75 | } 76 | va_end(vargs2); 77 | } 78 | 79 | void debug(const char* format, ...) 80 | { 81 | if (debug_disabled) return; 82 | if (!idevicerestore_debug) { 83 | return; 84 | } 85 | va_list vargs; 86 | va_start(vargs, format); 87 | vfprintf((debug_stream) ? debug_stream : stderr, format, vargs); 88 | va_end(vargs); 89 | } 90 | 91 | void idevicerestore_set_info_stream(FILE* strm) 92 | { 93 | if (strm) { 94 | info_disabled = 0; 95 | info_stream = strm; 96 | } else { 97 | info_disabled = 1; 98 | } 99 | } 100 | 101 | void idevicerestore_set_error_stream(FILE* strm) 102 | { 103 | if (strm) { 104 | error_disabled = 0; 105 | error_stream = strm; 106 | } else { 107 | error_disabled = 1; 108 | } 109 | } 110 | 111 | void idevicerestore_set_debug_stream(FILE* strm) 112 | { 113 | if (strm) { 114 | debug_disabled = 0; 115 | debug_stream = strm; 116 | } else { 117 | debug_disabled = 1; 118 | } 119 | } 120 | 121 | const char* idevicerestore_get_error(void) 122 | { 123 | if (idevicerestore_err_buff[0] == 0) { 124 | return NULL; 125 | } else { 126 | char* p = NULL; 127 | while ((strlen(idevicerestore_err_buff) > 0) && (p = strrchr(idevicerestore_err_buff, '\n'))) { 128 | p[0] = '\0'; 129 | } 130 | return (const char*)idevicerestore_err_buff; 131 | } 132 | } 133 | 134 | int write_file(const char* filename, const void* data, size_t size) { 135 | size_t bytes = 0; 136 | FILE* file = NULL; 137 | 138 | debug("Writing data to %s\n", filename); 139 | file = fopen(filename, "wb"); 140 | if (file == NULL) { 141 | error("write_file: Unable to open file %s\n", filename); 142 | return -1; 143 | } 144 | 145 | bytes = fwrite(data, 1, size, file); 146 | fclose(file); 147 | 148 | if (bytes != size) { 149 | error("ERROR: Unable to write entire file: %s: %d of %d\n", filename, (int)bytes, (int)size); 150 | return -1; 151 | } 152 | 153 | return (int)size; 154 | } 155 | 156 | int read_file(const char* filename, void** data, size_t* size) { 157 | size_t bytes = 0; 158 | size_t length = 0; 159 | FILE* file = NULL; 160 | char* buffer = NULL; 161 | debug("Reading data from %s\n", filename); 162 | 163 | *size = 0; 164 | *data = NULL; 165 | 166 | file = fopen(filename, "rb"); 167 | if (file == NULL) { 168 | error("read_file: File %s not found\n", filename); 169 | return -1; 170 | } 171 | 172 | fseeko(file, 0, SEEK_END); 173 | length = ftello(file); 174 | rewind(file); 175 | 176 | buffer = (char*) malloc(length); 177 | if (buffer == NULL) { 178 | error("ERROR: Out of memory\n"); 179 | fclose(file); 180 | return -1; 181 | } 182 | bytes = fread(buffer, 1, length, file); 183 | fclose(file); 184 | 185 | if (bytes != length) { 186 | error("ERROR: Unable to read entire file\n"); 187 | free(buffer); 188 | return -1; 189 | } 190 | 191 | *size = length; 192 | *data = buffer; 193 | return 0; 194 | } 195 | 196 | void debug_plist(plist_t plist) { 197 | uint32_t size = 0; 198 | char* data = NULL; 199 | plist_to_xml(plist, &data, &size); 200 | if (size <= MAX_PRINT_LEN) 201 | info("%s:printing %i bytes plist:\n%s", __FILE__, size, data); 202 | else 203 | info("%s:supressed printing %i bytes plist...\n", __FILE__, size); 204 | free(data); 205 | } 206 | 207 | void print_progress_bar(double progress) { 208 | #ifndef WIN32 209 | if (info_disabled) return; 210 | int i = 0; 211 | if(progress < 0) return; 212 | if(progress > 100) progress = 100; 213 | info("\r["); 214 | for(i = 0; i < 50; i++) { 215 | if(i < progress / 2) info("="); 216 | else info(" "); 217 | } 218 | info("] %5.1f%%", progress); 219 | if(progress == 100) info("\n"); 220 | fflush((info_stream) ? info_stream : stdout); 221 | #endif 222 | } 223 | 224 | #define GET_RAND(min, max) ((rand() % (max - min)) + min) 225 | 226 | char *generate_guid(void) 227 | { 228 | char *guid = (char *) malloc(sizeof(char) * 37); 229 | const char *chars = "ABCDEF0123456789"; 230 | srand((unsigned int)time(NULL)); 231 | int i = 0; 232 | 233 | for (i = 0; i < 36; i++) { 234 | if (i == 8 || i == 13 || i == 18 || i == 23) { 235 | guid[i] = '-'; 236 | continue; 237 | } else { 238 | guid[i] = chars[GET_RAND(0, 16)]; 239 | } 240 | } 241 | guid[36] = '\0'; 242 | return guid; 243 | } 244 | 245 | -------------------------------------------------------------------------------- /igetnonce/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * common.h 3 | * Misc functions used in idevicerestore 4 | * 5 | * Copyright (c) 2012 Martin Szulecki. All Rights Reserved. 6 | * Copyright (c) 2012 Nikias Bassen. All Rights Reserved. 7 | * Copyright (c) 2010 Joshua Hill. All Rights Reserved. 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #ifndef IDEVICERESTORE_COMMON_H 25 | #define IDEVICERESTORE_COMMON_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #include 32 | #include 33 | 34 | #include "idevicerestore.h" 35 | 36 | #define MODE_UNKNOWN -1 37 | #define MODE_WTF 0 38 | #define MODE_DFU 1 39 | #define MODE_RECOVERY 2 40 | #define MODE_RESTORE 3 41 | #define MODE_NORMAL 4 42 | 43 | #define FLAG_QUIT 1 44 | 45 | #define CPFM_FLAG_SECURITY_MODE 1 << 0 46 | #define CPFM_FLAG_PRODUCTION_MODE 1 << 1 47 | 48 | #define IBOOT_FLAG_IMAGE4_AWARE 1 << 2 49 | #define IBOOT_FLAG_EFFECTIVE_SECURITY_MODE 1 << 3 50 | #define IBOOT_FLAG_EFFECTIVE_PRODUCTION_MODE 1 << 4 51 | 52 | struct dfu_client_t; 53 | struct normal_client_t; 54 | struct restore_client_t; 55 | struct recovery_client_t; 56 | 57 | struct idevicerestore_mode_t { 58 | int index; 59 | const char* string; 60 | }; 61 | 62 | struct idevicerestore_entry_t { 63 | char* name; 64 | char* path; 65 | char* filename; 66 | char* blob_data; 67 | uint32_t blob_size; 68 | struct idevicerestore_entry* next; 69 | struct idevicerestore_entry* prev; 70 | }; 71 | 72 | struct idevicerestore_client_t { 73 | int flags; 74 | char *otamanifest; 75 | plist_t tss; 76 | char* tss_url; 77 | plist_t version_data; 78 | uint64_t ecid; 79 | unsigned char* nonce; 80 | int nonce_size; 81 | int image4supported; 82 | plist_t preflight_info; 83 | char* udid; 84 | char* srnm; 85 | char* ipsw; 86 | const char* filesystem; 87 | struct dfu_client_t* dfu; 88 | struct normal_client_t* normal; 89 | struct restore_client_t* restore; 90 | struct recovery_client_t* recovery; 91 | irecv_device_t device; 92 | struct idevicerestore_entry_t** entries; 93 | struct idevicerestore_mode_t* mode; 94 | char* version; 95 | char* build; 96 | int build_major; 97 | char* restore_boot_args; 98 | char* cache_dir; 99 | idevicerestore_progress_cb_t progress_cb; 100 | void* progress_cb_data; 101 | }; 102 | 103 | extern struct idevicerestore_mode_t idevicerestore_modes[]; 104 | 105 | extern int idevicerestore_debug; 106 | 107 | void info(const char* format, ...); 108 | void error(const char* format, ...); 109 | void debug(const char* format, ...); 110 | char *generate_guid(void); 111 | 112 | void idevicerestore_progress(struct idevicerestore_client_t* client, int step, double progress); 113 | 114 | #ifdef __cplusplus 115 | } 116 | #endif 117 | 118 | #endif 119 | -------------------------------------------------------------------------------- /igetnonce/dfu.c: -------------------------------------------------------------------------------- 1 | /* 2 | * dfu.c 3 | * Functions for handling idevices in DFU mode 4 | * 5 | * Copyright (c) 2010-2013 Martin Szulecki. All Rights Reserved. 6 | * Copyright (c) 2012-2015 Nikias Bassen. All Rights Reserved. 7 | * Copyright (c) 2010 Joshua Hill. All Rights Reserved. 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "dfu.h" 31 | #include "recovery.h" 32 | #include "idevicerestore.h" 33 | #include "common.h" 34 | 35 | int dfu_progress_callback(irecv_client_t client, const irecv_event_t* event) { 36 | // if (event->type == IRECV_PROGRESS) { 37 | // print_progress_bar(event->progress); 38 | // } 39 | return 0; 40 | } 41 | 42 | int dfu_client_new(struct idevicerestore_client_t* client) { 43 | int i = 0; 44 | int attempts = 10; 45 | irecv_client_t dfu = NULL; 46 | irecv_error_t dfu_error = IRECV_E_UNKNOWN_ERROR; 47 | 48 | if (client->dfu == NULL) { 49 | client->dfu = (struct dfu_client_t*)malloc(sizeof(struct dfu_client_t)); 50 | memset(client->dfu, 0, sizeof(struct dfu_client_t)); 51 | if (client->dfu == NULL) { 52 | error("ERROR: Out of memory\n"); 53 | return -1; 54 | } 55 | } 56 | 57 | for (i = 1; i <= attempts; i++) { 58 | dfu_error = irecv_open_with_ecid(&dfu, client->ecid); 59 | if (dfu_error == IRECV_E_SUCCESS) { 60 | break; 61 | } 62 | 63 | if (i >= attempts) { 64 | error("ERROR: Unable to connect to device in DFU mode\n"); 65 | return -1; 66 | } 67 | 68 | sleep(1); 69 | debug("Retrying connection...\n"); 70 | } 71 | 72 | irecv_event_subscribe(dfu, IRECV_PROGRESS, &dfu_progress_callback, NULL); 73 | client->dfu->client = dfu; 74 | return 0; 75 | } 76 | 77 | void dfu_client_free(struct idevicerestore_client_t* client) { 78 | if(client != NULL) { 79 | if (client->dfu != NULL) { 80 | if(client->dfu->client != NULL) { 81 | irecv_close(client->dfu->client); 82 | client->dfu->client = NULL; 83 | } 84 | free(client->dfu); 85 | } 86 | client->dfu = NULL; 87 | } 88 | } 89 | 90 | int dfu_check_mode(struct idevicerestore_client_t* client, int* mode) { 91 | irecv_client_t dfu = NULL; 92 | irecv_error_t dfu_error = IRECV_E_SUCCESS; 93 | int probe_mode = -1; 94 | 95 | irecv_init(); 96 | dfu_error = irecv_open_with_ecid(&dfu, client->ecid); 97 | if (dfu_error != IRECV_E_SUCCESS) { 98 | return -1; 99 | } 100 | 101 | irecv_get_mode(dfu, &probe_mode); 102 | 103 | if ((probe_mode != IRECV_K_DFU_MODE) && (probe_mode != IRECV_K_WTF_MODE)) { 104 | irecv_close(dfu); 105 | return -1; 106 | } 107 | 108 | *mode = (probe_mode == IRECV_K_WTF_MODE) ? MODE_WTF : MODE_DFU; 109 | 110 | irecv_close(dfu); 111 | 112 | return 0; 113 | } 114 | 115 | const char* dfu_check_hardware_model(struct idevicerestore_client_t* client) { 116 | irecv_client_t dfu = NULL; 117 | irecv_error_t dfu_error = IRECV_E_SUCCESS; 118 | irecv_device_t device = NULL; 119 | 120 | irecv_init(); 121 | dfu_error = irecv_open_with_ecid(&dfu, client->ecid); 122 | if (dfu_error != IRECV_E_SUCCESS) { 123 | return NULL; 124 | } 125 | 126 | dfu_error = irecv_devices_get_device_by_client(dfu, &device); 127 | if (dfu_error != IRECV_E_SUCCESS) { 128 | return NULL; 129 | } 130 | 131 | irecv_close(dfu); 132 | 133 | return device->hardware_model; 134 | } 135 | 136 | int dfu_send_buffer(struct idevicerestore_client_t* client, unsigned char* buffer, unsigned int size) 137 | { 138 | irecv_error_t err = 0; 139 | 140 | info("Sending data (%d bytes)...\n", size); 141 | 142 | err = irecv_send_buffer(client->dfu->client, buffer, size, 1); 143 | if (err != IRECV_E_SUCCESS) { 144 | error("ERROR: Unable to send data: %s\n", irecv_strerror(err)); 145 | return -1; 146 | } 147 | 148 | return 0; 149 | } 150 | 151 | 152 | 153 | int dfu_get_cpid(struct idevicerestore_client_t* client, unsigned int* cpid) { 154 | if(client->dfu == NULL) { 155 | if (dfu_client_new(client) < 0) { 156 | return -1; 157 | } 158 | } 159 | 160 | const struct irecv_device_info *device_info = irecv_get_device_info(client->dfu->client); 161 | if (!device_info) { 162 | return -1; 163 | } 164 | 165 | *cpid = device_info->cpid; 166 | 167 | return 0; 168 | } 169 | 170 | int dfu_get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) { 171 | if(client->dfu == NULL) { 172 | if (dfu_client_new(client) < 0) { 173 | return -1; 174 | } 175 | } 176 | 177 | const struct irecv_device_info *device_info = irecv_get_device_info(client->dfu->client); 178 | if (!device_info) { 179 | return -1; 180 | } 181 | 182 | *ecid = device_info->ecid; 183 | 184 | return 0; 185 | } 186 | 187 | int dfu_is_image4_supported(struct idevicerestore_client_t* client) 188 | { 189 | if(client->dfu == NULL) { 190 | if (dfu_client_new(client) < 0) { 191 | return 0; 192 | } 193 | } 194 | 195 | const struct irecv_device_info *device_info = irecv_get_device_info(client->dfu->client); 196 | if (!device_info) { 197 | return 0; 198 | } 199 | 200 | return (device_info->ibfl & IBOOT_FLAG_IMAGE4_AWARE); 201 | } 202 | 203 | int dfu_get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { 204 | if(client->dfu == NULL) { 205 | if (dfu_client_new(client) < 0) { 206 | return -1; 207 | } 208 | } 209 | 210 | const struct irecv_device_info *device_info = irecv_get_device_info(client->dfu->client); 211 | if (!device_info) { 212 | return -1; 213 | } 214 | 215 | if (device_info->ap_nonce && device_info->ap_nonce_size > 0) { 216 | *nonce = (unsigned char*)malloc(device_info->ap_nonce_size); 217 | if (!*nonce) { 218 | return -1; 219 | } 220 | *nonce_size = device_info->ap_nonce_size; 221 | memcpy(*nonce, device_info->ap_nonce, *nonce_size); 222 | } 223 | 224 | return 0; 225 | } 226 | 227 | int dfu_get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { 228 | if(client->dfu == NULL) { 229 | if (dfu_client_new(client) < 0) { 230 | return -1; 231 | } 232 | } 233 | 234 | const struct irecv_device_info *device_info = irecv_get_device_info(client->dfu->client); 235 | if (!device_info) { 236 | return -1; 237 | } 238 | 239 | if (device_info->sep_nonce && device_info->sep_nonce_size > 0) { 240 | *nonce = (unsigned char*)malloc(device_info->sep_nonce_size); 241 | if (!*nonce) { 242 | return -1; 243 | } 244 | *nonce_size = device_info->sep_nonce_size; 245 | memcpy(*nonce, device_info->sep_nonce, *nonce_size); 246 | } 247 | 248 | return 0; 249 | } 250 | -------------------------------------------------------------------------------- /igetnonce/dfu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * dfu.h 3 | * Functions for handling idevices in DFU mode 4 | * 5 | * Copyright (c) 2010-2013 Martin Szulecki. All Rights Reserved. 6 | * Copyright (c) 2012-2015 Nikias Bassen. All Rights Reserved. 7 | * Copyright (c) 2010 Joshua Hill. All Rights Reserved. 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #ifndef IDEVICERESTORE_DFU_H 25 | #define IDEVICERESTORE_DFU_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #include 32 | #include "common.h" 33 | 34 | struct dfu_client_t { 35 | irecv_client_t client; 36 | const char* ipsw; 37 | plist_t tss; 38 | }; 39 | 40 | int dfu_client_new(struct idevicerestore_client_t* client); 41 | void dfu_client_free(struct idevicerestore_client_t* client); 42 | int dfu_check_mode(struct idevicerestore_client_t* client, int* mode); 43 | const char* dfu_check_hardware_model(struct idevicerestore_client_t* client); 44 | int dfu_get_cpid(struct idevicerestore_client_t* client, unsigned int* cpid); 45 | int dfu_get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid); 46 | int dfu_get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size); 47 | int dfu_get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size); 48 | int dfu_enter_recovery(struct idevicerestore_client_t* client, plist_t build_identity); 49 | 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /igetnonce/endianness.h: -------------------------------------------------------------------------------- 1 | #ifndef ENDIANNESS_H 2 | #define ENDIANNESS_H 3 | 4 | #ifndef __LITTLE_ENDIAN 5 | #define __LITTLE_ENDIAN 1234 6 | #endif 7 | 8 | #ifndef __BIG_ENDIAN 9 | #define __BIG_ENDIAN 4321 10 | #endif 11 | 12 | #ifndef __BYTE_ORDER 13 | #ifdef __LITTLE_ENDIAN__ 14 | #define __BYTE_ORDER __LITTLE_ENDIAN 15 | #else 16 | #ifdef __BIG_ENDIAN__ 17 | #define __BYTE_ORDER __BIG_ENDIAN 18 | #endif 19 | #endif 20 | #endif 21 | 22 | #ifndef be16toh 23 | #if __BYTE_ORDER == __BIG_ENDIAN 24 | #define be16toh(x) (x) 25 | #else 26 | #define be16toh(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8)) 27 | #endif 28 | #endif 29 | 30 | #ifndef le16toh 31 | #if __BYTE_ORDER == __BIG_ENDIAN 32 | #define le16toh(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8)) 33 | #else 34 | #define le16toh(x) (x) 35 | #endif 36 | #endif 37 | 38 | 39 | #ifndef __bswap_32 40 | #define __bswap_32(x) ((((x) & 0xFF000000) >> 24) \ 41 | | (((x) & 0x00FF0000) >> 8) \ 42 | | (((x) & 0x0000FF00) << 8) \ 43 | | (((x) & 0x000000FF) << 24)) 44 | #endif 45 | 46 | #ifndef be32toh 47 | #if __BYTE_ORDER == __BIG_ENDIAN 48 | #define be32toh(x) (x) 49 | #else 50 | #define be32toh(x) __bswap_32(x) 51 | #endif 52 | #endif 53 | 54 | #ifndef htobe32 55 | #define htobe32 be32toh 56 | #endif 57 | 58 | #ifndef le32toh 59 | #if __BYTE_ORDER == __BIG_ENDIAN 60 | #define le32toh(x) __bswap_32(x) 61 | #else 62 | #define le32toh(x) (x) 63 | #endif 64 | #endif 65 | 66 | #ifndef htole32 67 | #define htole32 le32toh 68 | #endif 69 | 70 | #ifndef __bswap_64 71 | #define __bswap_64(x) ((((x) & 0xFF00000000000000ull) >> 56) \ 72 | | (((x) & 0x00FF000000000000ull) >> 40) \ 73 | | (((x) & 0x0000FF0000000000ull) >> 24) \ 74 | | (((x) & 0x000000FF00000000ull) >> 8) \ 75 | | (((x) & 0x00000000FF000000ull) << 8) \ 76 | | (((x) & 0x0000000000FF0000ull) << 24) \ 77 | | (((x) & 0x000000000000FF00ull) << 40) \ 78 | | (((x) & 0x00000000000000FFull) << 56)) 79 | #endif 80 | 81 | #ifndef htobe64 82 | #if __BYTE_ORDER == __BIG_ENDIAN 83 | #define htobe64(x) (x) 84 | #else 85 | #define htobe64(x) __bswap_64(x) 86 | #endif 87 | #endif 88 | 89 | #ifndef be64toh 90 | #define be64toh htobe64 91 | #endif 92 | 93 | #ifndef le64toh 94 | #if __BYTE_ORDER == __LITTLE_ENDIAN 95 | #define le64toh(x) (x) 96 | #else 97 | #define le64toh(x) __bswap_64(x) 98 | #endif 99 | #endif 100 | 101 | #ifndef htole64 102 | #define htole64 le64toh 103 | #endif 104 | 105 | #endif /* ENDIANNESS_H */ 106 | -------------------------------------------------------------------------------- /igetnonce/idevicerestore.c: -------------------------------------------------------------------------------- 1 | /* 2 | * idevicerestore.c 3 | * Restore device firmware and filesystem 4 | * 5 | * Copyright (c) 2010-2015 Martin Szulecki. All Rights Reserved. 6 | * Copyright (c) 2012-2015 Nikias Bassen. All Rights Reserved. 7 | * Copyright (c) 2010 Joshua Hill. All Rights Reserved. 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include "config.h" 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "dfu.h" 38 | #include "common.h" 39 | #include "normal.h" 40 | #include "recovery.h" 41 | #include "idevicerestore.h" 42 | 43 | struct idevicerestore_client_t* idevicerestore_client_new(void) 44 | { 45 | struct idevicerestore_client_t* client = (struct idevicerestore_client_t*) malloc(sizeof(struct idevicerestore_client_t)); 46 | if (client == NULL) { 47 | error("ERROR: Out of memory\n"); 48 | return NULL; 49 | } 50 | memset(client, '\0', sizeof(struct idevicerestore_client_t)); 51 | return client; 52 | } 53 | 54 | void idevicerestore_client_free(struct idevicerestore_client_t* client) 55 | { 56 | if (!client) { 57 | return; 58 | } 59 | 60 | if (client->tss_url) { 61 | free(client->tss_url); 62 | } 63 | if (client->version_data) { 64 | plist_free(client->version_data); 65 | } 66 | if (client->nonce) { 67 | free(client->nonce); 68 | } 69 | if (client->udid) { 70 | free(client->udid); 71 | } 72 | if (client->srnm) { 73 | free(client->srnm); 74 | } 75 | if (client->ipsw) { 76 | free(client->ipsw); 77 | } 78 | if (client->version) { 79 | free(client->version); 80 | } 81 | if (client->build) { 82 | free(client->build); 83 | } 84 | if (client->restore_boot_args) { 85 | free(client->restore_boot_args); 86 | } 87 | if (client->cache_dir) { 88 | free(client->cache_dir); 89 | } 90 | free(client); 91 | } 92 | 93 | 94 | int check_mode(struct idevicerestore_client_t* client) { 95 | int mode = MODE_UNKNOWN; 96 | int dfumode = MODE_UNKNOWN; 97 | 98 | if (recovery_check_mode(client) == 0) { 99 | mode = MODE_RECOVERY; 100 | } 101 | 102 | else if (dfu_check_mode(client, &dfumode) == 0) { 103 | mode = dfumode; 104 | } 105 | 106 | else if (normal_check_mode(client) == 0) { 107 | mode = MODE_NORMAL; 108 | } 109 | 110 | // else if (restore_check_mode(client) == 0) { 111 | // mode = MODE_RESTORE; 112 | // } 113 | 114 | if (mode == MODE_UNKNOWN) { 115 | client->mode = NULL; 116 | } else { 117 | client->mode = &idevicerestore_modes[mode]; 118 | } 119 | return mode; 120 | } 121 | 122 | const char* check_hardware_model(struct idevicerestore_client_t* client) { 123 | const char* hw_model = NULL; 124 | int mode = MODE_UNKNOWN; 125 | 126 | if (client->mode) { 127 | mode = client->mode->index; 128 | } 129 | 130 | switch (mode) { 131 | // case MODE_RESTORE: 132 | // hw_model = restore_check_hardware_model(client); 133 | // break; 134 | 135 | case MODE_NORMAL: 136 | hw_model = normal_check_hardware_model(client); 137 | break; 138 | 139 | case MODE_DFU: 140 | case MODE_RECOVERY: 141 | hw_model = dfu_check_hardware_model(client); 142 | break; 143 | default: 144 | break; 145 | } 146 | 147 | if (hw_model != NULL) { 148 | irecv_devices_get_device_by_hardware_model(hw_model, &client->device); 149 | } 150 | 151 | return hw_model; 152 | } 153 | 154 | int get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) { 155 | int mode = MODE_UNKNOWN; 156 | 157 | if (client->mode) { 158 | mode = client->mode->index; 159 | } 160 | 161 | switch (mode) { 162 | case MODE_NORMAL: 163 | if (normal_get_ecid(client, ecid) < 0) { 164 | *ecid = 0; 165 | return -1; 166 | } 167 | break; 168 | 169 | case MODE_DFU: 170 | if (dfu_get_ecid(client, ecid) < 0) { 171 | *ecid = 0; 172 | return -1; 173 | } 174 | break; 175 | 176 | case MODE_RECOVERY: 177 | if (recovery_get_ecid(client, ecid) < 0) { 178 | *ecid = 0; 179 | return -1; 180 | } 181 | break; 182 | 183 | default: 184 | error("ERROR: Device is in an invalid state\n"); 185 | *ecid = 0; 186 | return -1; 187 | } 188 | 189 | return 0; 190 | } 191 | 192 | int get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { 193 | int mode = MODE_UNKNOWN; 194 | 195 | *nonce = NULL; 196 | *nonce_size = 0; 197 | if (client->mode) { 198 | mode = client->mode->index; 199 | } 200 | 201 | switch (mode) { 202 | case MODE_NORMAL: 203 | if (normal_get_ap_nonce(client, nonce, nonce_size) < 0) { 204 | info("failed\n"); 205 | return -1; 206 | } 207 | break; 208 | case MODE_DFU: 209 | if (dfu_get_ap_nonce(client, nonce, nonce_size) < 0) { 210 | info("failed\n"); 211 | return -1; 212 | } 213 | break; 214 | case MODE_RECOVERY: 215 | if (recovery_get_ap_nonce(client, nonce, nonce_size) < 0) { 216 | info("failed\n"); 217 | return -1; 218 | } 219 | break; 220 | 221 | default: 222 | info("failed\n"); 223 | error("ERROR: Device is in an invalid state\n"); 224 | return -1; 225 | } 226 | 227 | int i = 0; 228 | info("ApNonce="); 229 | for (i = 0; i < *nonce_size; i++) { 230 | info("%02x", (*nonce)[i]); 231 | } 232 | info("\n"); 233 | 234 | return 0; 235 | } 236 | 237 | int get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { 238 | int mode = MODE_UNKNOWN; 239 | 240 | *nonce = NULL; 241 | *nonce_size = 0; 242 | 243 | if (client->mode) { 244 | mode = client->mode->index; 245 | } 246 | 247 | switch (mode) { 248 | case MODE_NORMAL: 249 | if (normal_get_sep_nonce(client, nonce, nonce_size) < 0) { 250 | info("failed\n"); 251 | return -1; 252 | } 253 | break; 254 | case MODE_DFU: 255 | if (dfu_get_sep_nonce(client, nonce, nonce_size) < 0) { 256 | info("failed\n"); 257 | return -1; 258 | } 259 | break; 260 | case MODE_RECOVERY: 261 | if (recovery_get_sep_nonce(client, nonce, nonce_size) < 0) { 262 | info("failed\n"); 263 | return -1; 264 | } 265 | break; 266 | 267 | default: 268 | info("failed\n"); 269 | error("ERROR: Device is in an invalid state\n"); 270 | return -1; 271 | } 272 | 273 | int i = 0; 274 | info("SepNonce="); 275 | for (i = 0; i < *nonce_size; i++) { 276 | info("%02x", (*nonce)[i]); 277 | } 278 | info("\n"); 279 | 280 | return 0; 281 | } 282 | -------------------------------------------------------------------------------- /igetnonce/idevicerestore.h: -------------------------------------------------------------------------------- 1 | /* 2 | * idevicerestore.h 3 | * Restore device firmware and filesystem 4 | * 5 | * Copyright (c) 2010-2012 Martin Szulecki. All Rights Reserved. 6 | * Copyright (c) 2012-2015 Nikias Bassen. All Rights Reserved. 7 | * Copyright (c) 2010 Joshua Hill. All Rights Reserved. 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #ifndef IDEVICERESTORE_H 25 | #define IDEVICERESTORE_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #include 32 | #include 33 | 34 | // the flag with value 1 is reserved for internal use only. don't use it. 35 | #define FLAG_DEBUG 1 << 1 36 | #define FLAG_ERASE 1 << 2 37 | #define FLAG_CUSTOM 1 << 3 38 | #define FLAG_EXCLUDE 1 << 4 39 | #define FLAG_PWN 1 << 5 40 | #define FLAG_NOACTION 1 << 6 41 | #define FLAG_SHSHONLY 1 << 7 42 | #define FLAG_LATEST 1 << 8 43 | #define FLAG_DOWNGRADE 1 << 9 44 | #define FLAG_OTAMANIFEST 1 << 10 45 | #define FLAG_BOOT 1 << 11 46 | #define FLAG_PANICLOG 1 << 12 47 | #define FLAG_NOBOOTX 1 << 13 48 | 49 | struct idevicerestore_client_t; 50 | 51 | enum { 52 | RESTORE_STEP_DETECT = 0, 53 | RESTORE_STEP_PREPARE, 54 | RESTORE_STEP_UPLOAD_FS, 55 | RESTORE_STEP_VERIFY_FS, 56 | RESTORE_STEP_FLASH_FW, 57 | RESTORE_STEP_FLASH_BB, 58 | RESTORE_NUM_STEPS 59 | }; 60 | 61 | typedef void (*idevicerestore_progress_cb_t)(int step, double step_progress, void* userdata); 62 | 63 | struct idevicerestore_client_t* idevicerestore_client_new(void); 64 | void idevicerestore_client_free(struct idevicerestore_client_t* client); 65 | 66 | int idevicerestore_start(struct idevicerestore_client_t* client); 67 | 68 | int check_mode(struct idevicerestore_client_t* client); 69 | const char* check_hardware_model(struct idevicerestore_client_t* client); 70 | int get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid); 71 | int get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size); 72 | int get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size); 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /igetnonce/main.c: -------------------------------------------------------------------------------- 1 | // 2 | // main.c 3 | // igetnonce 4 | // 5 | // Created by tihmstar on 05.07.16. 6 | // Copyright © 2016 tihmstar. All rights reserved. 7 | // 8 | 9 | #include 10 | #include 11 | 12 | #include "all.h" 13 | 14 | #include "idevicerestore.h" 15 | #include "common.h" 16 | 17 | int64_t parseECID(const char *ecid){ 18 | const char *ecidBK = ecid; 19 | int isHex = 0; 20 | int64_t ret = 0; 21 | 22 | while (*ecid && !isHex) { 23 | char c = *(ecid++); 24 | if (c >= '0' && c<='9') { 25 | ret *=10; 26 | ret += c - '0'; 27 | }else{ 28 | isHex = 1; 29 | ret = 0; 30 | } 31 | } 32 | 33 | if (isHex) { 34 | while (*ecidBK) { 35 | char c = *(ecidBK++); 36 | ret *=16; 37 | if (c >= '0' && c<='9') { 38 | ret += c - '0'; 39 | }else if (c >= 'a' && c <= 'f'){ 40 | ret += 10 + c - 'a'; 41 | }else if (c >= 'A' && c <= 'F'){ 42 | ret += 10 + c - 'A'; 43 | }else{ 44 | return 0; //ERROR parsing failed 45 | } 46 | } 47 | } 48 | 49 | return ret; 50 | } 51 | 52 | int main(int argc, const char * argv[]) { 53 | printf("Version: "IGETNONCE_VERSION_SHA" - "IGETNONCE_VERSION_COUNT"\n"); 54 | struct idevicerestore_client_t* client = idevicerestore_client_new(); 55 | 56 | if (argc >= 3){ 57 | if (strncmp(argv[1],"-e",2) == 0){ 58 | if ((client->ecid = parseECID(argv[2])) == 0){ 59 | printf("Error: can't parse ECID \"%s\", continuing without ecid\n",argv[2]); 60 | }else{ 61 | printf("User specified ECID=%llx\n",client->ecid); 62 | } 63 | } 64 | } 65 | 66 | if (check_mode(client) < 0 || client->mode->index == MODE_UNKNOWN || 67 | ((client->flags & FLAG_DOWNGRADE) && client->mode->index != MODE_DFU && client->mode->index != MODE_RECOVERY)) { 68 | error("ERROR: Unable to discover device mode. Please make sure a device is attached.\n"); 69 | return -1; 70 | } 71 | 72 | if (check_hardware_model(client) == NULL || client->device == NULL) { 73 | error("ERROR: Unable to discover device model\n"); 74 | return -1; 75 | } 76 | 77 | info("Identified device as %s, %s ", client->device->hardware_model, client->device->product_type); 78 | 79 | switch (client->mode->index) { 80 | case MODE_NORMAL: 81 | info("in normal mode... "); 82 | break; 83 | case MODE_DFU: 84 | info("in DFU mode... "); 85 | break; 86 | case MODE_RECOVERY: 87 | info("in recovery mode... "); 88 | break; 89 | default: 90 | info("failed\n"); 91 | error("ERROR: Device is in an invalid state\n"); 92 | return -1; 93 | } 94 | info("\n"); 95 | 96 | if ((client->flags & FLAG_PWN) && (client->mode->index != MODE_DFU)) { 97 | error("ERROR: you need to put your device into DFU mode to pwn it.\n"); 98 | return -1; 99 | } 100 | 101 | if (!client->ecid && get_ecid(client, &client->ecid) < 0) { 102 | error("ERROR: Unable to find device ECID\n"); 103 | return -1; 104 | } 105 | info("ecid=%llx\n",client->ecid); 106 | 107 | if (client->mode->index == MODE_NORMAL) { 108 | error("WARNING: Getting a ApNonce in normal mode will overwrite the generator in NVRAM!\n"); 109 | info("Continue anyway? [y/n] : "); 110 | char cont[2] = "n"; 111 | scanf("%c", cont); 112 | if (strncmp(cont, "y", 1) != 0) return -1; 113 | } 114 | 115 | unsigned char* nonce = NULL; 116 | int nonce_size = 0; 117 | 118 | if (get_ap_nonce(client, &nonce, &nonce_size) < 0) { 119 | error("NOTE: Unable to get ApNonce from device\n"); 120 | } 121 | if (get_sep_nonce(client, &nonce, &nonce_size) < 0) { 122 | error("NOTE: Unable to get SepNonce from device\n"); 123 | } 124 | 125 | return 0; 126 | } 127 | -------------------------------------------------------------------------------- /igetnonce/normal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * normal.h 3 | * Functions for handling idevices in normal mode 4 | * 5 | * Copyright (c) 2012-2015 Nikias Bassen. All Rights Reserved. 6 | * Copyright (c) 2012 Martin Szulecki. All Rights Reserved. 7 | * Copyright (c) 2010 Joshua Hill. All Rights Reserved. 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "common.h" 34 | #include "normal.h" 35 | #include "recovery.h" 36 | 37 | static int normal_device_connected = 0; 38 | 39 | void normal_device_callback(const idevice_event_t* event, void* userdata) { 40 | struct idevicerestore_client_t* client = (struct idevicerestore_client_t*) userdata; 41 | if (event->event == IDEVICE_DEVICE_ADD) { 42 | normal_device_connected = 1; 43 | 44 | } else if (event->event == IDEVICE_DEVICE_REMOVE) { 45 | normal_device_connected = 0; 46 | client->flags &= FLAG_QUIT; 47 | } 48 | } 49 | 50 | int normal_client_new(struct idevicerestore_client_t* client) { 51 | struct normal_client_t* normal = (struct normal_client_t*) malloc(sizeof(struct normal_client_t)); 52 | if (normal == NULL) { 53 | error("ERROR: Out of memory\n"); 54 | return -1; 55 | } 56 | 57 | if (normal_open_with_timeout(client) < 0) { 58 | normal_client_free(client); 59 | return -1; 60 | } 61 | 62 | client->normal = normal; 63 | return 0; 64 | } 65 | 66 | void normal_client_free(struct idevicerestore_client_t* client) { 67 | struct normal_client_t* normal = NULL; 68 | if (client) { 69 | normal = client->normal; 70 | if(normal) { 71 | if(normal->client) { 72 | lockdownd_client_free(normal->client); 73 | normal->client = NULL; 74 | } 75 | if(normal->device) { 76 | idevice_free(normal->device); 77 | normal->device = NULL; 78 | } 79 | } 80 | free(normal); 81 | client->normal = NULL; 82 | } 83 | } 84 | 85 | static int normal_idevice_new(struct idevicerestore_client_t* client, idevice_t* device) 86 | { 87 | int num_devices = 0; 88 | char **devices = NULL; 89 | idevice_t dev = NULL; 90 | idevice_error_t device_error; 91 | 92 | *device = NULL; 93 | 94 | if (client->udid) { 95 | device_error = idevice_new(&dev, client->udid); 96 | if (device_error != IDEVICE_E_SUCCESS) { 97 | error("ERROR: %s: can't open device with UDID %s\n", __func__, client->udid); 98 | return -1; 99 | } 100 | *device = dev; 101 | return 0; 102 | } 103 | 104 | idevice_get_device_list(&devices, &num_devices); 105 | if (num_devices == 0) { 106 | return -1; 107 | } 108 | lockdownd_client_t lockdown = NULL; 109 | int j; 110 | for (j = 0; j < num_devices; j++) { 111 | if (lockdown != NULL) { 112 | lockdownd_client_free(lockdown); 113 | lockdown = NULL; 114 | } 115 | if (dev != NULL) { 116 | idevice_free(dev); 117 | dev = NULL; 118 | } 119 | device_error = idevice_new(&dev, devices[j]); 120 | if (device_error != IDEVICE_E_SUCCESS) { 121 | error("ERROR: %s: can't open device with UDID %s\n", __func__, devices[j]); 122 | continue; 123 | } 124 | 125 | if (lockdownd_client_new(dev, &lockdown, "idevicerestore") != LOCKDOWN_E_SUCCESS) { 126 | error("ERROR: %s: can't connect to lockdownd on device with UDID %s\n", __func__, devices[j]); 127 | continue; 128 | 129 | } 130 | char* type = NULL; 131 | if (lockdownd_query_type(lockdown, &type) != LOCKDOWN_E_SUCCESS) { 132 | continue; 133 | } 134 | if (strcmp(type, "com.apple.mobile.lockdown") != 0) { 135 | free(type); 136 | continue; 137 | } 138 | free(type); 139 | 140 | plist_t node = NULL; 141 | if ((lockdownd_get_value(lockdown, NULL, "UniqueChipID", &node) != LOCKDOWN_E_SUCCESS) || !node || (plist_get_node_type(node) != PLIST_UINT)){ 142 | if (node) { 143 | plist_free(node); 144 | } 145 | continue; 146 | } 147 | lockdownd_client_free(lockdown); 148 | lockdown = NULL; 149 | 150 | uint64_t this_ecid = 0; 151 | plist_get_uint_val(node, &this_ecid); 152 | plist_free(node); 153 | 154 | if (client->ecid != 0) { 155 | if (this_ecid != client->ecid) { 156 | continue; 157 | } 158 | } else { 159 | client->ecid = this_ecid; 160 | } 161 | client->udid = strdup(devices[j]); 162 | *device = dev; 163 | break; 164 | } 165 | idevice_device_list_free(devices); 166 | 167 | return 0; 168 | } 169 | 170 | int normal_check_mode(struct idevicerestore_client_t* client) { 171 | idevice_t device = NULL; 172 | 173 | normal_idevice_new(client, &device); 174 | if (!device) { 175 | return -1; 176 | } 177 | idevice_free(device); 178 | 179 | return 0; 180 | } 181 | 182 | int normal_open_with_timeout(struct idevicerestore_client_t* client) { 183 | int i = 0; 184 | int attempts = 10; 185 | idevice_t device = NULL; 186 | 187 | // no context exists so bail 188 | if(client == NULL) { 189 | return -1; 190 | } 191 | 192 | normal_device_connected = 0; 193 | 194 | // create our normal client if it doesn't yet exist 195 | if(client->normal == NULL) { 196 | client->normal = (struct normal_client_t*) malloc(sizeof(struct normal_client_t)); 197 | if(client->normal == NULL) { 198 | error("ERROR: Out of memory\n"); 199 | return -1; 200 | } 201 | } 202 | 203 | for (i = 1; i <= attempts; i++) { 204 | normal_idevice_new(client, &device); 205 | if (device) { 206 | normal_device_connected = 1; 207 | break; 208 | } 209 | 210 | if (i == attempts) { 211 | error("ERROR: Unable to connect to device in normal mode\n"); 212 | return -1; 213 | } 214 | sleep(2); 215 | } 216 | 217 | client->normal->device = device; 218 | 219 | return 0; 220 | } 221 | 222 | const char* normal_check_hardware_model(struct idevicerestore_client_t* client) { 223 | idevice_t device = NULL; 224 | char* product_type = NULL; 225 | irecv_device_t irecv_device = NULL; 226 | lockdownd_client_t lockdown = NULL; 227 | lockdownd_error_t lockdown_error = LOCKDOWN_E_SUCCESS; 228 | 229 | normal_idevice_new(client, &device); 230 | if (!device) { 231 | return product_type; 232 | } 233 | 234 | lockdown_error = lockdownd_client_new_with_handshake(device, &lockdown, "idevicerestore"); 235 | if (lockdown_error != LOCKDOWN_E_SUCCESS) { 236 | lockdown_error = lockdownd_client_new(device, &lockdown, "idevicerestore"); 237 | } 238 | if (lockdown_error != LOCKDOWN_E_SUCCESS) { 239 | idevice_free(device); 240 | return product_type; 241 | } 242 | 243 | plist_t pval = NULL; 244 | lockdownd_get_value(lockdown, NULL, "HardwareModel", &pval); 245 | if (pval && (plist_get_node_type(pval) == PLIST_STRING)) { 246 | char* strval = NULL; 247 | plist_get_string_val(pval, &strval); 248 | if (strval) { 249 | irecv_devices_get_device_by_hardware_model(strval, &irecv_device); 250 | free(strval); 251 | } 252 | } 253 | if (pval) { 254 | plist_free(pval); 255 | } 256 | 257 | return (irecv_device) ? irecv_device->hardware_model : NULL; 258 | } 259 | 260 | int normal_enter_recovery(struct idevicerestore_client_t* client) { 261 | idevice_t device = NULL; 262 | lockdownd_client_t lockdown = NULL; 263 | idevice_error_t device_error = IDEVICE_E_SUCCESS; 264 | lockdownd_error_t lockdown_error = LOCKDOWN_E_SUCCESS; 265 | 266 | device_error = idevice_new(&device, client->udid); 267 | if (device_error != IDEVICE_E_SUCCESS) { 268 | error("ERROR: Unable to find device\n"); 269 | return -1; 270 | } 271 | 272 | lockdown_error = lockdownd_client_new(device, &lockdown, "idevicerestore"); 273 | if (lockdown_error != LOCKDOWN_E_SUCCESS) { 274 | error("ERROR: Unable to connect to lockdownd service\n"); 275 | idevice_free(device); 276 | return -1; 277 | } 278 | 279 | lockdown_error = lockdownd_enter_recovery(lockdown); 280 | if (lockdown_error != LOCKDOWN_E_SUCCESS) { 281 | error("ERROR: Unable to place device in recovery mode\n"); 282 | lockdownd_client_free(lockdown); 283 | idevice_free(device); 284 | return -1; 285 | } 286 | 287 | lockdownd_client_free(lockdown); 288 | idevice_free(device); 289 | lockdown = NULL; 290 | device = NULL; 291 | 292 | if (recovery_client_new(client) < 0) { 293 | error("ERROR: Unable to enter recovery mode\n"); 294 | return -1; 295 | } 296 | 297 | client->mode = &idevicerestore_modes[MODE_RECOVERY]; 298 | return 0; 299 | } 300 | 301 | static int normal_get_nonce_by_key(struct idevicerestore_client_t* client, const char* key, unsigned char** nonce, int* nonce_size) { 302 | idevice_t device = NULL; 303 | plist_t nonce_node = NULL; 304 | lockdownd_client_t lockdown = NULL; 305 | idevice_error_t device_error = IDEVICE_E_SUCCESS; 306 | lockdownd_error_t lockdown_error = LOCKDOWN_E_SUCCESS; 307 | 308 | device_error = idevice_new(&device, client->udid); 309 | if (device_error != IDEVICE_E_SUCCESS) { 310 | return -1; 311 | } 312 | 313 | lockdown_error = lockdownd_client_new(device, &lockdown, "idevicerestore"); 314 | if (lockdown_error != LOCKDOWN_E_SUCCESS) { 315 | error("ERROR: Unable to connect to lockdownd\n"); 316 | idevice_free(device); 317 | return -1; 318 | } 319 | 320 | lockdown_error = lockdownd_get_value(lockdown, NULL, key, &nonce_node); 321 | if (lockdown_error != LOCKDOWN_E_SUCCESS) { 322 | error("Unable to get %s from lockdownd\n", key); 323 | lockdownd_client_free(lockdown); 324 | idevice_free(device); 325 | return -1; 326 | } 327 | 328 | if (!nonce_node || plist_get_node_type(nonce_node) != PLIST_DATA) { 329 | error("Unable to get %s\n", key); 330 | lockdownd_client_free(lockdown); 331 | idevice_free(device); 332 | return -1; 333 | } 334 | 335 | uint64_t n_size = 0; 336 | plist_get_data_val(nonce_node, (char**)nonce, &n_size); 337 | *nonce_size = (int)n_size; 338 | plist_free(nonce_node); 339 | 340 | lockdownd_client_free(lockdown); 341 | idevice_free(device); 342 | lockdown = NULL; 343 | device = NULL; 344 | 345 | return 0; 346 | } 347 | 348 | int normal_get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { 349 | return normal_get_nonce_by_key(client, "SEPNonce", nonce, nonce_size); 350 | } 351 | 352 | int normal_get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { 353 | return normal_get_nonce_by_key(client, "ApNonce", nonce, nonce_size); 354 | } 355 | 356 | int normal_get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) { 357 | idevice_t device = NULL; 358 | plist_t unique_chip_node = NULL; 359 | lockdownd_client_t lockdown = NULL; 360 | idevice_error_t device_error = IDEVICE_E_SUCCESS; 361 | lockdownd_error_t lockdown_error = LOCKDOWN_E_SUCCESS; 362 | 363 | device_error = idevice_new(&device, client->udid); 364 | if (device_error != IDEVICE_E_SUCCESS) { 365 | return -1; 366 | } 367 | 368 | lockdown_error = lockdownd_client_new(device, &lockdown, "idevicerestore"); 369 | if (lockdown_error != LOCKDOWN_E_SUCCESS) { 370 | error("ERROR: Unable to connect to lockdownd\n"); 371 | idevice_free(device); 372 | return -1; 373 | } 374 | 375 | lockdown_error = lockdownd_get_value(lockdown, NULL, "UniqueChipID", &unique_chip_node); 376 | if (lockdown_error != LOCKDOWN_E_SUCCESS) { 377 | error("ERROR: Unable to get UniqueChipID from lockdownd\n"); 378 | lockdownd_client_free(lockdown); 379 | idevice_free(device); 380 | return -1; 381 | } 382 | 383 | if (!unique_chip_node || plist_get_node_type(unique_chip_node) != PLIST_UINT) { 384 | error("ERROR: Unable to get ECID\n"); 385 | lockdownd_client_free(lockdown); 386 | idevice_free(device); 387 | return -1; 388 | } 389 | plist_get_uint_val(unique_chip_node, ecid); 390 | plist_free(unique_chip_node); 391 | 392 | lockdownd_client_free(lockdown); 393 | idevice_free(device); 394 | lockdown = NULL; 395 | device = NULL; 396 | return 0; 397 | } 398 | -------------------------------------------------------------------------------- /igetnonce/normal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * normal.h 3 | * Functions for handling idevices in normal mode 4 | * 5 | * Copyright (c) 2012 Martin Szulecki. All Rights Reserved. 6 | * Copyright (c) 2012-2015 Nikias Bassen. All Rights Reserved. 7 | * Copyright (c) 2010 Joshua Hill. All Rights Reserved. 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #ifndef IDEVICERESTORE_NORMAL_H 25 | #define IDEVICERESTORE_NORMAL_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | struct normal_client_t { 37 | idevice_t device; 38 | lockdownd_client_t client; 39 | const char* ipsw; 40 | plist_t tss; 41 | }; 42 | 43 | 44 | int normal_check_mode(struct idevicerestore_client_t* client); 45 | const char* normal_check_hardware_model(struct idevicerestore_client_t* client); 46 | int normal_client_new(struct idevicerestore_client_t* client); 47 | void normal_client_free(struct idevicerestore_client_t* client); 48 | int normal_open_with_timeout(struct idevicerestore_client_t* client); 49 | int normal_get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid); 50 | int normal_get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size); 51 | int normal_get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /igetnonce/recovery.c: -------------------------------------------------------------------------------- 1 | /* 2 | * recovery.c 3 | * Functions for handling idevices in recovery mode 4 | * 5 | * Copyright (c) 2010-2012 Martin Szulecki. All Rights Reserved. 6 | * Copyright (c) 2012 Nikias Bassen. All Rights Reserved. 7 | * Copyright (c) 2010 Joshua Hill. All Rights Reserved. 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "idevicerestore.h" 34 | #include "recovery.h" 35 | 36 | int recovery_progress_callback(irecv_client_t client, const irecv_event_t* event) { 37 | if (event->type == IRECV_PROGRESS) { 38 | //print_progress_bar(event->progress); 39 | } 40 | return 0; 41 | } 42 | 43 | void recovery_client_free(struct idevicerestore_client_t* client) { 44 | if(client) { 45 | if (client->recovery) { 46 | if(client->recovery->client) { 47 | irecv_close(client->recovery->client); 48 | client->recovery->client = NULL; 49 | } 50 | free(client->recovery); 51 | client->recovery = NULL; 52 | } 53 | } 54 | } 55 | 56 | int recovery_client_new(struct idevicerestore_client_t* client) { 57 | int i = 0; 58 | int attempts = 20; 59 | irecv_client_t recovery = NULL; 60 | irecv_error_t recovery_error = IRECV_E_UNKNOWN_ERROR; 61 | 62 | if(client->recovery == NULL) { 63 | client->recovery = (struct recovery_client_t*)malloc(sizeof(struct recovery_client_t)); 64 | if (client->recovery == NULL) { 65 | error("ERROR: Out of memory\n"); 66 | return -1; 67 | } 68 | memset(client->recovery, 0, sizeof(struct recovery_client_t)); 69 | } 70 | 71 | for (i = 1; i <= attempts; i++) { 72 | recovery_error = irecv_open_with_ecid(&recovery, client->ecid); 73 | if (recovery_error == IRECV_E_SUCCESS) { 74 | break; 75 | } 76 | 77 | if (i >= attempts) { 78 | error("ERROR: Unable to connect to device in recovery mode\n"); 79 | return -1; 80 | } 81 | 82 | sleep(4); 83 | debug("Retrying connection...\n"); 84 | } 85 | 86 | if (client->srnm == NULL) { 87 | const struct irecv_device_info *device_info = irecv_get_device_info(recovery); 88 | if (device_info && device_info->srnm) { 89 | client->srnm = strdup(device_info->srnm); 90 | info("INFO: device serial number is %s\n", client->srnm); 91 | } 92 | } 93 | 94 | irecv_event_subscribe(recovery, IRECV_PROGRESS, &recovery_progress_callback, NULL); 95 | client->recovery->client = recovery; 96 | return 0; 97 | } 98 | 99 | int recovery_check_mode(struct idevicerestore_client_t* client) { 100 | irecv_client_t recovery = NULL; 101 | irecv_error_t recovery_error = IRECV_E_SUCCESS; 102 | int mode = 0; 103 | 104 | irecv_init(); 105 | recovery_error=irecv_open_with_ecid(&recovery, client->ecid); 106 | 107 | if (recovery_error != IRECV_E_SUCCESS) { 108 | return -1; 109 | } 110 | 111 | irecv_get_mode(recovery, &mode); 112 | 113 | if ((mode == IRECV_K_DFU_MODE) || (mode == IRECV_K_WTF_MODE)) { 114 | irecv_close(recovery); 115 | return -1; 116 | } 117 | 118 | irecv_close(recovery); 119 | recovery = NULL; 120 | 121 | return 0; 122 | } 123 | 124 | 125 | int recovery_get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) { 126 | if(client->recovery == NULL) { 127 | if (recovery_client_new(client) < 0) { 128 | return -1; 129 | } 130 | } 131 | 132 | const struct irecv_device_info *device_info = irecv_get_device_info(client->recovery->client); 133 | if (!device_info) { 134 | return -1; 135 | } 136 | 137 | *ecid = device_info->ecid; 138 | 139 | return 0; 140 | } 141 | 142 | int recovery_get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { 143 | if(client->recovery == NULL) { 144 | if (recovery_client_new(client) < 0) { 145 | return -1; 146 | } 147 | } 148 | 149 | const struct irecv_device_info *device_info = irecv_get_device_info(client->recovery->client); 150 | if (!device_info) { 151 | return -1; 152 | } 153 | 154 | if (device_info->ap_nonce && device_info->ap_nonce_size > 0) { 155 | *nonce = (unsigned char*)malloc(device_info->ap_nonce_size); 156 | if (!*nonce) { 157 | return -1; 158 | } 159 | *nonce_size = device_info->ap_nonce_size; 160 | memcpy(*nonce, device_info->ap_nonce, *nonce_size); 161 | } 162 | 163 | return 0; 164 | } 165 | 166 | int recovery_get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { 167 | if(client->recovery == NULL) { 168 | if (recovery_client_new(client) < 0) { 169 | return -1; 170 | } 171 | } 172 | 173 | const struct irecv_device_info *device_info = irecv_get_device_info(client->recovery->client); 174 | if (!device_info) { 175 | return -1; 176 | } 177 | 178 | if (device_info->sep_nonce && device_info->sep_nonce_size > 0) { 179 | *nonce = (unsigned char*)malloc(device_info->sep_nonce_size); 180 | if (!*nonce) { 181 | return -1; 182 | } 183 | *nonce_size = device_info->sep_nonce_size; 184 | memcpy(*nonce, device_info->sep_nonce, *nonce_size); 185 | } 186 | 187 | return 0; 188 | } 189 | 190 | int recovery_send_reset(struct idevicerestore_client_t* client) 191 | { 192 | irecv_send_command(client->recovery->client, "reset"); 193 | return 0; 194 | } 195 | 196 | -------------------------------------------------------------------------------- /igetnonce/recovery.h: -------------------------------------------------------------------------------- 1 | /* 2 | * recovery.h 3 | * Functions for handling idevices in recovery mode 4 | * 5 | * Copyright (c) 2010-2012 Martin Szulecki. All Rights Reserved. 6 | * Copyright (c) 2012 Nikias Bassen. All Rights Reserved. 7 | * Copyright (c) 2010 Joshua Hill. All Rights Reserved. 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #ifndef IDEVICERESTORE_RECOVERY_H 25 | #define IDEVICERESTORE_RECOVERY_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include "common.h" 36 | 37 | struct recovery_client_t { 38 | irecv_client_t client; 39 | const char* ipsw; 40 | plist_t tss; 41 | }; 42 | 43 | int recovery_check_mode(struct idevicerestore_client_t* client); 44 | int recovery_client_new(struct idevicerestore_client_t* client); 45 | void recovery_client_free(struct idevicerestore_client_t* client); 46 | int recovery_get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid); 47 | int recovery_get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size); 48 | int recovery_get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size); 49 | 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | --------------------------------------------------------------------------------