├── .gitignore ├── CommonConstants.h ├── CommonConstants.m ├── Firmware.m ├── Firmware ├── Firmware.h ├── FirmwareBundle.h ├── FirmwareBundle.m ├── FirmwareDownload.h ├── FirmwareDownload.m ├── FirmwareManager.h └── FirmwareManager.m ├── IPhoneUSB.m ├── InstanceManager.h ├── InstanceManager.m ├── MessageManager.h ├── MessageManager.m ├── Misc ├── ArrayAdditions.h ├── ArrayAdditions.m ├── DrawAdditions.h ├── DrawAdditions.m ├── SpotlightSearch.h ├── SpotlightSearch.m ├── StringAdditions.h ├── StringAdditions.m ├── SupportClasses.h ├── SupportClasses.m ├── WorkspaceAdditions.h └── WorkspaceAdditions.m ├── MobileDeviceServices ├── .DS_Store └── MobileDeviceInterface.h ├── Pusher.pch ├── README.md ├── RamdiskBuilder.h ├── RamdiskBuilder.m ├── RootFSDecrypt.c ├── RootFSDecrypt.h ├── SecureTask.h ├── Support ├── 8900Parser.c ├── 8900Parser.h ├── AppleCRC32.c ├── AppleCRC32.h ├── Img3Parser.c ├── Img3Parser.h ├── MobileDevice.h ├── OpenSSLHelper.h ├── OpenSSLHelper.m ├── compression.c ├── compression.h └── zlib.h ├── WorkerThread.h ├── WorkerThread.m ├── core ├── IPhoneUSB.h └── SecureTask.m ├── dpkg ├── dpkg.h ├── dpkg.m └── dpkg.pch ├── libpng ├── png.c ├── png.h ├── pngconf.h ├── pngerror.c ├── pnggccrd.c ├── pngget.c ├── pngmem.c ├── pngpread.c ├── pngread.c ├── pngrio.c ├── pngrtran.c ├── pngrutil.c ├── pngset.c ├── pngtrans.c ├── pngvcrd.c ├── pngwio.c ├── pngwrite.c ├── pngwtran.c └── pngwutil.c ├── main.m ├── patch.c ├── patch.h ├── png.c ├── png.h └── ramdisk ├── Makefile ├── PusherEncryptor.app.zip ├── dpkg-restate.c ├── dpkg-version ├── .DS_Store └── var │ ├── .DS_Store │ └── db │ ├── .DS_Store │ └── ripdev │ └── dpkg-version.plist ├── dpkg.dmg ├── dpkg.dmg.zip ├── install-installerd.c ├── kc-patch ├── Makefile ├── compression.c ├── compression.h ├── kc-patch.c ├── libcrypto.a ├── patch.c └── patch.h ├── nor.c ├── pusher.c ├── pusher.dmg ├── pusher.dmg.zip └── utilities.c /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | core/.DS_Store 3 | Firmware/.DS_Store 4 | ramdisk/.DS_Store 5 | Support/.DS_Store 6 | -------------------------------------------------------------------------------- /CommonConstants.h: -------------------------------------------------------------------------------- 1 | // Settings 2 | 3 | #ifdef DEBUG 4 | #define Log(...) NSLog(__VA_ARGS__) 5 | #else 6 | #define Log(...) {} 7 | #endif 8 | 9 | extern unsigned int RequiredFreeMegaBytes; 10 | extern float RoundSquareViewRadius; 11 | extern float SelectionBorderWidth; 12 | extern NSString* SystemTempDir; 13 | extern NSString* SystemVolumesDir; 14 | extern NSString* IPwnerDir; 15 | extern NSString* RootFilesystemTemp; 16 | extern NSString* CustomRamdisk; 17 | extern NSString* CustomRamdiskTemp; 18 | extern NSString* CustomRamdiskMountVolume; 19 | extern NSString* CustomRamdiskIPwnerDir; 20 | extern NSString* CustomRamdiskIBoot; 21 | extern NSString* CustomRamdiskLLB; 22 | extern NSString* CustomRamdiskBootArgs; 23 | extern unsigned int CustomRamdiskOffset; 24 | extern NSString* CustomLogoPicture; 25 | extern NSString* CustomRecoveryPicture; 26 | extern NSString* BootNeuterLauncher; 27 | extern NSString* BootNeuterLauncherTemp; 28 | extern NSString* BootNeuterArg1; 29 | extern NSString* BootNeuterArg2; 30 | extern NSString* BootNeuterArg3; 31 | extern NSString* BootNeuterArg4; 32 | extern NSString* BootNeuterArg5; 33 | extern NSString* BL39SHA1; 34 | extern NSString* BL46SHA1; 35 | extern NSString* MagicIBootSHA1; 36 | extern NSString* BL39ImageFile; 37 | extern NSString* BL46ImageFile; 38 | extern NSString* MagicIBootFile; 39 | extern NSString* IBootPayloadFile; 40 | extern NSString* InstallerPackagesDir; 41 | extern NSString* CydiaPackagesDir; 42 | extern NSString* PusherHelperPath; 43 | extern NSString* X12220000Path; 44 | extern NSString* NoSpaceLeftString; 45 | extern NSString* LogSeparatorLine; 46 | 47 | // Nib hashes 48 | extern NSString* MainMenuHash; 49 | extern NSString* AboutBoxHash; 50 | extern NSString* SelectPlatformHash; 51 | extern NSString* LocalizableStringsHash; 52 | 53 | // User defaults 54 | extern NSString* FirstRunKey; 55 | extern NSString* LastFirmwarePathKey; 56 | extern NSString* VendorIDKey; 57 | 58 | // Toolbar 59 | extern NSString* PwnageToolbarIdentifier; 60 | extern NSString* ToolbarLogoItemIdentifier; 61 | extern NSString* ToolbarTitleItemIdentifier; 62 | extern NSString* ToolbarLogItemIdentifier; 63 | extern NSString* ToolbarExitItemIdentifier; 64 | 65 | // User defaults keys 66 | extern NSString* InstallerSourcesKey; 67 | extern NSString* CydiaSourcesKey; 68 | 69 | // Message button keys 70 | extern NSString* ButtonInvocationKey; 71 | extern NSString* ButtonImageKey; 72 | extern NSString* ButtonAltImageKey; 73 | 74 | // Wizard step controller keys 75 | extern NSString* StepControllerKey; 76 | extern NSString* StepIndexKey; 77 | 78 | // IThread Dict Keys 79 | extern NSString* NeedsFirmwareKey; 80 | extern NSString* FirmwareKey; 81 | extern NSString* CustomPackageManagerKey; 82 | extern NSString* InstallerPackageManagerKey; 83 | extern NSString* CustomIPSWFileKey; 84 | extern NSString* IPSWDictionaryKey; 85 | extern NSString* BBUpdateKey; 86 | extern NSString* BootNeuterKey; 87 | extern NSString* BLUpdateKey; 88 | extern NSString* BLUpg46Key; 89 | extern NSString* BLDng39Key; 90 | extern NSString* BL39ImageKey; 91 | extern NSString* BL46ImageKey; 92 | extern NSString* BBUnlockKey; 93 | extern NSString* AutoDeleteBootNeuterKey; 94 | extern NSString* PhoneActivationKey; 95 | extern NSString* BootLogoKey; 96 | extern NSString* RecoveryLogoKey; 97 | extern NSString* CustomBootLogoKey; 98 | extern NSString* CustomRecoveryLogoKey; 99 | extern NSString* RootPartitionSizeKey; 100 | extern NSString* MagicIBootKey; 101 | extern NSString* MachPortKey; 102 | 103 | // Mach Port Messages 104 | extern unsigned int ThreadStartMessage; 105 | extern unsigned int ThreadStopMessage; 106 | extern unsigned int SunStartMessage; 107 | extern unsigned int SunStopMessage; 108 | extern unsigned int SetTextMessage; 109 | extern unsigned int SelectPlatformMessage; 110 | extern unsigned int FirmwareFoundMessage; 111 | extern unsigned int BuilderStatusMessage; 112 | extern unsigned int BuilderStopMessage; 113 | extern unsigned int UploadTotalBytesMessage; 114 | extern unsigned int UploadedBytesMessage; 115 | extern unsigned int UploadFileMessage; 116 | extern unsigned int UploadSuccessMessage; 117 | extern unsigned int UploadFailedMessage; 118 | 119 | extern NSString* TextKey; 120 | extern NSString* SunKey; 121 | 122 | // Notifications 123 | extern NSString* CollectionItemClickedNotification; 124 | extern NSString* CollectionItemDoubleClickedNotification; 125 | extern NSString* CollectionItemSelectedNotification; 126 | extern NSString* CollectionItemKey; 127 | extern NSString* DoubleClickedKey; 128 | 129 | extern NSString* MoveToStepNotification; 130 | 131 | extern NSString* CustomPackageSelectedNotification; 132 | extern NSString* InstallerPackageSelectedNotification; 133 | extern NSString* CydiaPackageSelectedNotification; 134 | extern NSString* FreeSpaceChangedNotification; 135 | 136 | enum PwnageStatus 137 | { 138 | PSITunes = 0, 139 | PSWaiting, 140 | PSNormal, 141 | PSRecovery, 142 | PSDFU, 143 | PSSuccess, 144 | PSFailed 145 | }; 146 | 147 | enum BuilderStatus 148 | { 149 | BSStart = 0, 150 | BSSuccess, 151 | BSFailed 152 | }; 153 | 154 | // Custom package bundle Info.plist keys 155 | extern NSString* CPIdentifierKey; 156 | extern NSString* CPNameKey; 157 | extern NSString* CPDescriptionKey; 158 | extern NSString* CPHiddenKey; 159 | extern NSString* CPSupportedFirmwareKey; 160 | extern NSString* CPCommandsKey; 161 | extern NSString* CPSizeKey; 162 | 163 | // Installer package bundle Info.plist keys 164 | extern NSString* IPInfoKey; 165 | extern NSString* IPPackagesKey; 166 | extern NSString* IPIdentifierKey; 167 | extern NSString* IPNameKey; 168 | extern NSString* IPDescriptionKey; 169 | extern NSString* IPSizeKey; 170 | extern NSString* IPVersionKey; 171 | extern NSString* IPLocationKey; 172 | extern NSString* IPHashKey; 173 | extern NSString* IPUrlKey; 174 | extern NSString* IPStatusKey; 175 | 176 | // Installer source keys 177 | extern NSString* ISNameKey; 178 | 179 | // Cydia package bundle keys 180 | extern NSString* YPIdentifierKey; 181 | extern NSString* YPNameKey; 182 | extern NSString* YPVersionKey; 183 | extern NSString* YPDescriptionKey; 184 | extern NSString* YPArchitectureKey; 185 | extern NSString* YPSizeKey; 186 | extern NSString* YPHashKey; 187 | extern NSString* YPLocationKey; 188 | extern NSString* YPStatusKey; 189 | 190 | // Firmware bundle Info.plist Keys 191 | extern NSString* FilenameKey; 192 | extern NSString* VersionKey; 193 | extern NSString* PlatformKey; 194 | extern NSString* SHA1Key; 195 | extern NSString* RootFilesystemKey; 196 | extern NSString* RootFilesystemMountVolumeKey; 197 | extern NSString* RootFilesystemKeyKey; 198 | extern NSString* RootFilesystemSizeKey; 199 | extern NSString* RootFilesystemUsedSpaceKey; 200 | extern NSString* RamdiskMountVolumeKey; 201 | extern NSString* DownloadUrlKey; 202 | 203 | extern NSString* PreInstalledPackagesKey; 204 | extern NSString* FirmwarePatchesKey; 205 | extern NSString* FilesystemPatchesKey; 206 | extern NSString* BasebandPatchesKey; 207 | 208 | extern NSString* NameKey; 209 | extern NSString* FileKey; 210 | extern NSString* PathKey; 211 | extern NSString* PatchKey; 212 | extern NSString* Patch2Key; 213 | extern NSString* TypeFlagKey; 214 | extern NSString* ActionKey; 215 | extern NSString* MoreActionsKey; 216 | extern NSString* KeyKey; 217 | extern NSString* IVKey; 218 | 219 | extern NSString* ActionPatch; 220 | extern NSString* ActionAdd; 221 | extern NSString* ActionReplaceKernel; 222 | extern NSString* ActionSetOwner; 223 | extern NSString* ActionSetPermission; 224 | extern NSString* OwnerKey; 225 | extern NSString* PermissionKey; 226 | extern NSString* ActionRunScript; 227 | 228 | extern NSString* FSCoreFilesInstallationKey; 229 | extern NSString* FSFilesystemJailbreakKey; 230 | extern NSString* FSPhoneActivationKey; 231 | 232 | extern NSString* FWLLBKey; 233 | extern NSString* FWIBootKey; 234 | extern NSString* FWIBSSKey; 235 | extern NSString* FWIBECKey; 236 | extern NSString* FWWTFKey; 237 | extern NSString* FWWTF2Key; 238 | extern NSString* FWDeviceTreeKey; 239 | extern NSString* FWUpdateRamdiskKey; 240 | extern NSString* FWRestoreRamdiskKey; 241 | extern NSString* FWAppleLogoKey; 242 | extern NSString* FWRecoveryModeKey; 243 | extern NSString* FWKernelCacheKey; 244 | 245 | extern NSString* BBUpdaterKey; 246 | extern NSString* BBBasebandFLSKey; 247 | extern NSString* BBBasebandEEPKey; 248 | extern NSString* BBBootloader39Key; 249 | extern NSString* BBBootloader46Key; 250 | 251 | extern NSString* RestoreOptionsKey; 252 | extern NSString* CreateFilesystemPartitionsKey; 253 | /*! 254 | @header CommonConstants.h 255 | @project Pusher 256 | @author Alexander Maksimenko 257 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 258 | */ 259 | 260 | extern NSString* SystemPartitionSizeKey; 261 | extern NSString* UpdateBasebandKey; 262 | 263 | typedef enum 264 | { 265 | wmSimple = 0, 266 | wmAdvanced 267 | } WizardMode; 268 | 269 | typedef enum 270 | { 271 | wsPlatform = 0, 272 | wsFirmware, 273 | wsBuilderBuild, 274 | wsEnterDFU, 275 | wsQuickPwn 276 | } WizardStep; 277 | 278 | typedef enum 279 | { 280 | Unknown = 0, 281 | IPhone = 1, 282 | IPod = 2, 283 | IPhone3G = 3 284 | } Platform; 285 | 286 | typedef enum 287 | { 288 | TextMessage = 0, 289 | BubbleMessage, 290 | ErrorMessage 291 | } MessageKind; 292 | 293 | typedef enum 294 | { 295 | dmNone = 0, 296 | dmAnyClick, 297 | dmInnerClick, 298 | dmOuterClick 299 | } DismissMode; 300 | 301 | typedef enum 302 | { 303 | rtRestore = 0, 304 | rtUpdate 305 | } RamdiskType; -------------------------------------------------------------------------------- /CommonConstants.m: -------------------------------------------------------------------------------- 1 | /*! 2 | @source CommonConstants.m 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | // Settings 9 | unsigned int RequiredFreeMegaBytes = 500; 10 | float RoundSquareViewRadius = 5; 11 | float SelectionBorderWidth = 5; 12 | NSString* SystemTempDir = @"/tmp/ipsw"; 13 | NSString* SystemVolumesDir = @"/Volumes"; 14 | NSString* IPwnerDir = @"iPwner"; 15 | NSString* RootFilesystemTemp = @"rootfs.dmg"; 16 | NSString* CustomRamdisk = @"ramdisk.dmg"; 17 | NSString* CustomRamdiskTemp = @"ramdisk_temp.dmg"; 18 | NSString* CustomRamdiskMountVolume = @"iPwnerRamdisk"; 19 | NSString* CustomRamdiskIPwnerDir = @"ipwner"; 20 | NSString* CustomRamdiskIBoot = @"iboot.img2"; 21 | NSString* CustomRamdiskLLB = @"llb.img2"; 22 | unsigned int CustomRamdiskOffset = 0x0AB00000; 23 | NSString* CustomRamdiskBootArgs = @"setenv boot-args -v pmd0=0x%08X.0x%08X pmd1=0x8000000.0x8000000 rd=md0"; 24 | NSString* CustomLogoPicture = @"logo.img2"; 25 | NSString* CustomRecoveryPicture = @"recovery.img2"; 26 | NSString* BootNeuterLauncher = @"System/Library/LaunchDaemons/com.devteam.bootneuter.auto.plist"; 27 | NSString* BootNeuterLauncherTemp = @"com.devteam.bootneuter.auto.plist"; 28 | NSString* BootNeuterArg1 = @"-autoMode"; 29 | NSString* BootNeuterArg2 = @"-unlockBaseband"; 30 | NSString* BootNeuterArg3 = @"-bootLoader"; 31 | NSString* BootNeuterArg4 = @"-selfDestruct"; 32 | NSString* BootNeuterArg5 = @"-RegisterForSystemEvents"; 33 | NSString* BL39SHA1 = @"285247AAFFCB9E816283A62AFC5A3B452757009D"; 34 | NSString* BL46SHA1 = @"DFF1055659DA2C3EDDDC6D4A6EE74C76B27F4BE8"; 35 | NSString* MagicIBootSHA1 = @"18FF0E1697D6F3EA5C8FB7698C114CC5DA4B5594"; 36 | NSString* BL39ImageFile = @"bl39.bin"; 37 | NSString* BL46ImageFile = @"bl46.bin"; 38 | NSString* MagicIBootFile = @"iboot.bin"; 39 | NSString* IBootPayloadFile = @"payload.bin"; 40 | NSString* InstallerPackagesDir = @"/var/mobile/Media/Installer"; 41 | NSString* CydiaPackagesDir = @"/var/root/Media/Cydia/AutoInstall"; 42 | NSString* PusherHelperPath = @"Contents/MacOS/PusherHelper"; 43 | NSString* X12220000Path = @"~/Library/iTunes/Device Support/x12220000_4_Recovery.ipsw"; 44 | NSString* NoSpaceLeftString = @"No space left on device"; 45 | NSString* LogSeparatorLine = @"------------------------------"; 46 | 47 | // Resource hashes 48 | NSString* MainMenuHash = @"F620157A1205826F82CF71483FC3579ACCD24967"; 49 | NSString* AboutBoxHash = @"62AB294EDA3B347CD24F9E71CBF55511B254322E"; 50 | NSString* SelectPlatformHash = @"4020981E7B9E67C4CFE1A84FE46CF17297412F4E"; 51 | NSString* LocalizableStringsHash = @"E4055F3C22E585667A4D738081CED6460990109C"; 52 | 53 | // User defaults 54 | NSString* FirstRunKey = @"FirstRun"; 55 | NSString* LastFirmwarePathKey = @"LastFirmwarePath"; 56 | NSString* VendorIDKey = @"VendorID"; 57 | 58 | // Toolbar 59 | NSString* PwnageToolbarIdentifier = @"PwnageToolbarIdentifier"; 60 | NSString* ToolbarLogoItemIdentifier = @"ToolbarLogoItemIdentifier"; 61 | NSString* ToolbarTitleItemIdentifier = @"ToolbarTitleItemIdentifier"; 62 | NSString* ToolbarLogItemIdentifier = @"ToolbarLogItemIdentifier"; 63 | NSString* ToolbarExitItemIdentifier = @"ToolbarExitItemIdentifier"; 64 | 65 | // User defaults keys 66 | NSString* InstallerSourcesKey = @"InstallerSourcesKey"; 67 | NSString* CydiaSourcesKey = @"CydiaSourcesKey"; 68 | 69 | // Message button keys 70 | NSString* ButtonInvocationKey = @"ButtonInvocationKey"; 71 | NSString* ButtonImageKey = @"ButtonImageKey"; 72 | NSString* ButtonAltImageKey = @"ButtonAltImageKey"; 73 | 74 | // Wizard step controller keys 75 | NSString* StepControllerKey = @"StepControllerKey"; 76 | NSString* StepIndexKey = @"StepIndexKey"; 77 | 78 | // IThread Dict Keys 79 | NSString* NeedsFirmwareKey = @"NeedsFirmwareKey"; 80 | NSString* FirmwareKey = @"FirmwareKey"; 81 | NSString* CustomPackageManagerKey = @"CustomPackageManagerKey"; 82 | NSString* InstallerPackageManagerKey = @"InstallerPackageManagerKey"; 83 | NSString* CustomIPSWFileKey = @"CustomIPSWFile"; 84 | NSString* BBUpdateKey = @"BBUpdate"; 85 | NSString* BootNeuterKey = @"BootNeuter"; 86 | NSString* BLUpdateKey = @"BLUpdate"; 87 | NSString* BLUpg46Key = @"BLUpg46"; 88 | NSString* BLDng39Key = @"BLDng39"; 89 | NSString* BL39ImageKey = @"BL39Image"; 90 | NSString* BL46ImageKey = @"BL46Image"; 91 | NSString* BBUnlockKey = @"BBUnlock"; 92 | NSString* AutoDeleteBootNeuterKey = @"AutoDeleteBootNeuter"; 93 | NSString* PhoneActivationKey = @"PhoneActivation"; 94 | NSString* BootLogoKey = @"BootLogo"; 95 | NSString* RecoveryLogoKey = @"RecoveryLogo"; 96 | NSString* CustomBootLogoKey = @"CustomBootLogo"; 97 | NSString* CustomRecoveryLogoKey = @"CustomRecoveryLogo"; 98 | NSString* RootPartitionSizeKey = @"RootPartitionSize"; 99 | NSString* MagicIBootKey = @"MagicIBoot"; 100 | NSString* MachPortKey = @"MachPort"; 101 | 102 | // Mach Port Messages 103 | unsigned int ThreadStartMessage = 'thst'; 104 | unsigned int ThreadStopMessage = 'thsp'; 105 | unsigned int SunStartMessage = 'sust'; 106 | unsigned int SunStopMessage = 'susp'; 107 | unsigned int SetTextMessage = 'stxm'; 108 | unsigned int SelectPlatformMessage = 'splm'; 109 | unsigned int FirmwareFoundMessage = 'ffom'; 110 | unsigned int BuilderStatusMessage = 'bsts'; 111 | unsigned int BuilderStopMessage = 'bsms'; 112 | unsigned int UploadTotalBytesMessage = 'utbm'; 113 | unsigned int UploadedBytesMessage = 'ubym'; 114 | unsigned int UploadFileMessage = 'ufim'; 115 | unsigned int UploadSuccessMessage = 'uscm'; 116 | unsigned int UploadFailedMessage = 'uflm'; 117 | 118 | NSString* TextKey = @"Text"; 119 | NSString* SunKey = @"Sun"; 120 | 121 | // Notifications 122 | NSString* CollectionItemClickedNotification = @"CollectionItemClickedNotification"; 123 | NSString* CollectionItemDoubleClickedNotification = @"CollectionItemDoubleClickedNotification"; 124 | NSString* CollectionItemSelectedNotification = @"CollectionItemSelectedNotification"; 125 | NSString* CollectionItemKey = @"CollectionItem"; 126 | NSString* DoubleClickedKey = @"DoubleClickedKey"; 127 | 128 | NSString* MoveToStepNotification = @"MoveToStepNotification"; 129 | 130 | NSString* CustomPackageSelectedNotification = @"CustomPackageSelectedNotification"; 131 | NSString* InstallerPackageSelectedNotification = @"InstallerPackageSelectedNotification"; 132 | NSString* CydiaPackageSelectedNotification = @"CydiaPackageSelectedNotification"; 133 | NSString* FreeSpaceChangedNotification = @"FreeSpaceChangedNotification"; 134 | 135 | // Custom package bundle Info.plist keys 136 | NSString* CPIdentifierKey = @"Identifier"; 137 | NSString* CPNameKey = @"Name"; 138 | NSString* CPDescriptionKey = @"Description"; 139 | NSString* CPHiddenKey = @"Hidden"; 140 | NSString* CPSupportedFirmwareKey = @"SupportedFirmware"; 141 | NSString* CPCommandsKey = @"Commands"; 142 | NSString* CPSizeKey = @"Size"; 143 | 144 | // Installer package bundle Info.plist keys 145 | NSString* IPInfoKey = @"info"; 146 | NSString* IPPackagesKey = @"packages"; 147 | NSString* IPIdentifierKey = @"identifier"; 148 | NSString* IPNameKey = @"name"; 149 | NSString* IPDescriptionKey = @"description"; 150 | NSString* IPSizeKey = @"size"; 151 | NSString* IPVersionKey = @"version"; 152 | NSString* IPLocationKey = @"location"; 153 | NSString* IPHashKey = @"hash"; 154 | NSString* IPUrlKey = @"url"; 155 | NSString* IPStatusKey = @"status"; 156 | 157 | // Installer source keys 158 | NSString* ISNameKey = @"name"; 159 | 160 | // Cydia package bundle keys 161 | NSString* YPIdentifierKey = @"Package"; 162 | NSString* YPNameKey = @"Name"; 163 | NSString* YPVersionKey = @"Version"; 164 | NSString* YPDescriptionKey = @"Description"; 165 | NSString* YPArchitectureKey = @"Architecture"; 166 | NSString* YPSizeKey = @"Size"; 167 | NSString* YPHashKey = @"MD5sum"; 168 | NSString* YPLocationKey = @"Filename"; 169 | NSString* YPStatusKey = @"Status"; 170 | 171 | // Firmware bundle Info.plist Keys 172 | NSString* FilenameKey = @"Filename"; 173 | NSString* VersionKey = @"Version"; 174 | NSString* PlatformKey = @"Platform"; 175 | NSString* SHA1Key = @"SHA1"; 176 | NSString* RootFilesystemKey = @"RootFilesystem"; 177 | NSString* RootFilesystemMountVolumeKey = @"RootFilesystemMountVolume"; 178 | NSString* RootFilesystemKeyKey = @"RootFilesystemKey"; 179 | NSString* RootFilesystemSizeKey = @"RootFilesystemSize"; 180 | NSString* RootFilesystemUsedSpaceKey = @"RootFilesystemUsedSpace"; 181 | NSString* RamdiskMountVolumeKey = @"RamdiskMountVolume"; 182 | NSString* DownloadUrlKey = @"DownloadUrl"; 183 | 184 | NSString* PreInstalledPackagesKey = @"PreInstalledPackages"; 185 | NSString* FirmwarePatchesKey = @"FirmwarePatches"; 186 | NSString* FilesystemPatchesKey = @"FilesystemPatches"; 187 | NSString* BasebandPatchesKey = @"BasebandPatches"; 188 | 189 | NSString* NameKey = @"Name"; 190 | NSString* FileKey = @"File"; 191 | NSString* PathKey = @"Path"; 192 | NSString* PatchKey = @"Patch"; 193 | NSString* Patch2Key = @"Patch2"; 194 | NSString* TypeFlagKey = @"TypeFlag"; 195 | NSString* ActionKey = @"Action"; 196 | NSString* MoreActionsKey = @"MoreActions"; 197 | NSString* KeyKey = @"Key"; 198 | NSString* IVKey = @"IV"; 199 | 200 | NSString* ActionPatch = @"Patch"; 201 | NSString* ActionAdd = @"Add"; 202 | NSString* ActionReplaceKernel = @"ReplaceKernel"; 203 | NSString* ActionSetOwner = @"SetOwner"; 204 | NSString* ActionSetPermission = @"SetPermission"; 205 | NSString* OwnerKey = @"Owner"; 206 | NSString* PermissionKey = @"Permission"; 207 | NSString* ActionRunScript = @"RunScript"; 208 | 209 | NSString* FSCoreFilesInstallationKey = @"Core Files Installation"; 210 | NSString* FSFilesystemJailbreakKey = @"Filesystem Jailbreak"; 211 | NSString* FSPhoneActivationKey = @"Phone Activation"; 212 | 213 | NSString* FWLLBKey = @"LLB"; 214 | NSString* FWIBootKey = @"iBoot"; 215 | NSString* FWIBSSKey = @"iBSS"; 216 | NSString* FWIBECKey = @"iBEC"; 217 | NSString* FWWTFKey = @"WTF"; 218 | NSString* FWWTF2Key = @"WTF 2"; 219 | NSString* FWDeviceTreeKey = @"DeviceTree"; 220 | NSString* FWUpdateRamdiskKey = @"Update Ramdisk"; 221 | NSString* FWRestoreRamdiskKey = @"Restore Ramdisk"; 222 | NSString* FWAppleLogoKey = @"AppleLogo"; 223 | NSString* FWRecoveryModeKey = @"RecoveryMode"; 224 | NSString* FWKernelCacheKey = @"KernelCache"; 225 | 226 | NSString* BBUpdaterKey = @"BBUpdater"; 227 | NSString* BBBasebandFLSKey = @"Baseband FLS"; 228 | NSString* BBBasebandEEPKey = @"Baseband EEP"; 229 | NSString* BBBootloader39Key = @"Bootloader 3.9"; 230 | NSString* BBBootloader46Key = @"Bootloader 4.6"; 231 | 232 | NSString* RestoreOptionsKey = @"usr/local/share/restore/options.plist"; 233 | NSString* CreateFilesystemPartitionsKey = @"CreateFilesystemPartitions"; 234 | NSString* SystemPartitionSizeKey = @"SystemPartitionSize"; 235 | NSString* UpdateBasebandKey = @"UpdateBaseband"; 236 | 237 | -------------------------------------------------------------------------------- /Firmware/Firmware.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header Firmware.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | @class FirmwareBundle; 9 | 10 | @interface Firmware : NSObject 11 | { 12 | FirmwareBundle* _bundle; 13 | NSString* _path; 14 | } 15 | 16 | -(id) initWithBundle:(FirmwareBundle*) info path:(NSString*) path; 17 | 18 | -(NSString*) bundlePath; 19 | 20 | -(NSString*) path; 21 | -(NSString*) name; 22 | -(int) version; 23 | -(Platform) platform; 24 | -(NSString*) filename; 25 | -(NSString*) rootFilesystem; 26 | -(NSString*) rootFilesystemKey; 27 | -(NSString*) rootFilesystemMountVolume; 28 | -(double) rootFilesystemSize; 29 | -(double) rootFilesystemUsedSpace; 30 | -(NSString*) ramdiskMountVolume; 31 | 32 | -(NSArray*) preInstalledCustomPackages; 33 | -(NSDictionary*) firmwarePatches; 34 | -(NSDictionary*) filesystemPatches; 35 | -(NSDictionary*) basebandPatches; 36 | 37 | -(BOOL) bbUpdateAvailable; 38 | -(BOOL) phoneActivationAvailable; 39 | 40 | -(BOOL) unzipTo:(NSString*) path; 41 | 42 | -(NSString*) allFlashDir; 43 | -(NSString*) appleLogoFile; 44 | -(NSString*) iBootFile; 45 | -(NSString*) iBSSFile; 46 | -(NSString*) wtfFile; 47 | -(NSString*) restoreRamdiskFile; 48 | -(NSString*) deviceTreeFile; 49 | -(NSString*) kernelCacheFile; 50 | 51 | -(BOOL) patchIBoot; 52 | -(BOOL) extractRamdisk:(RamdiskType) type to:(NSString*) file; 53 | -(BOOL) makeRamdisk:(RamdiskType) type from:(NSString*) file encrypt:(BOOL) encrypt; 54 | 55 | +(BOOL) checkCustomPicture:(NSString*) file; 56 | -(BOOL) makeBootLogo:(NSString*) file; 57 | -(BOOL) makeRecoveryLogo:(NSString*) file; 58 | 59 | -(BOOL) patchFirmwareModule:(NSString*) file ofType:(int) type withPatch:(NSString*) patch key:(NSString*) key iv:(NSString*) iv exploit:(BOOL) exploit; 60 | -(BOOL) applyPatch:(NSString*) patch toFile:(NSString*) file; 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /Firmware/FirmwareBundle.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header FirmwareBundle.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | @interface FirmwareBundle : NSObject 9 | { 10 | NSDictionary* _info; 11 | NSString* _path; 12 | } 13 | 14 | -(id) initWithInfo:(NSDictionary*) info path:(NSString*) path; 15 | 16 | -(NSString*) path; 17 | -(NSString*) name; 18 | -(int) version; 19 | -(Platform) platform; 20 | -(NSString*) filename; 21 | -(NSString*) sha1; 22 | -(NSString*) rootFilesystem; 23 | -(NSString*) rootFilesystemKey; 24 | -(NSString*) rootFilesystemMountVolume; 25 | -(double) rootFilesystemSize; 26 | -(double) rootFilesystemUsedSpace; 27 | -(NSString*) ramdiskMountVolume; 28 | -(NSString*) downloadUrl; 29 | 30 | -(NSArray*) preInstalledCustomPackages; 31 | -(NSDictionary*) firmwarePatches; 32 | -(NSDictionary*) filesystemPatches; 33 | -(NSDictionary*) basebandPatches; 34 | 35 | -(BOOL) bbUpdateAvailable; 36 | -(BOOL) phoneActivationAvailable; 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /Firmware/FirmwareBundle.m: -------------------------------------------------------------------------------- 1 | /*! 2 | @source FirmwareBundle.m 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #import "FirmwareBundle.h" 9 | 10 | @implementation FirmwareBundle 11 | 12 | -(id) initWithInfo:(NSDictionary*) info path:(NSString*) path 13 | { 14 | self = [super init]; 15 | 16 | _info = [info retain]; 17 | _path = [path copy]; 18 | 19 | return self; 20 | } 21 | 22 | -(void) dealloc 23 | { 24 | [_info release]; 25 | [_path release]; 26 | 27 | [super dealloc]; 28 | } 29 | 30 | -(void) encodeWithCoder:(NSCoder*) encoder 31 | { 32 | [encoder encodeObject:_info]; 33 | [encoder encodeObject:_path]; 34 | } 35 | 36 | -(id) initWithCoder:(NSCoder*) decoder 37 | { 38 | [_info release]; 39 | _info = [[decoder decodeObject] retain]; 40 | 41 | [_path release]; 42 | _path = [[decoder decodeObject] copy]; 43 | 44 | return self; 45 | } 46 | 47 | -(NSString*) path 48 | { 49 | return [[_path copy] autorelease]; 50 | } 51 | 52 | -(NSString*) name 53 | { 54 | return [_info objectForKey:NameKey]; 55 | } 56 | 57 | -(int) version 58 | { 59 | return [[_info objectForKey:VersionKey] intValue]; 60 | } 61 | 62 | -(Platform) platform 63 | { 64 | return [[_info objectForKey:PlatformKey] intValue]; 65 | } 66 | 67 | -(NSString*) filename 68 | { 69 | return [_info objectForKey:FilenameKey]; 70 | } 71 | 72 | -(NSString*) sha1 73 | { 74 | return [_info objectForKey:SHA1Key]; 75 | } 76 | 77 | -(NSString*) rootFilesystem 78 | { 79 | return [_info objectForKey:RootFilesystemKey]; 80 | } 81 | 82 | -(NSString*) rootFilesystemKey 83 | { 84 | return [_info objectForKey:RootFilesystemKeyKey]; 85 | } 86 | 87 | -(NSString*) rootFilesystemMountVolume 88 | { 89 | return [_info objectForKey:RootFilesystemMountVolumeKey]; 90 | } 91 | 92 | -(double) rootFilesystemSize 93 | { 94 | return (double)[[_info objectForKey:RootFilesystemSizeKey] intValue]; 95 | } 96 | 97 | -(double) rootFilesystemUsedSpace 98 | { 99 | return (double)[[_info objectForKey:RootFilesystemUsedSpaceKey] intValue]; 100 | } 101 | 102 | -(NSString*) ramdiskMountVolume 103 | { 104 | return [_info objectForKey:RamdiskMountVolumeKey]; 105 | } 106 | 107 | -(NSString*) downloadUrl 108 | { 109 | return [_info objectForKey:DownloadUrlKey]; 110 | } 111 | 112 | -(NSArray*) preInstalledCustomPackages 113 | { 114 | return [_info objectForKey:PreInstalledPackagesKey]; 115 | } 116 | 117 | -(NSDictionary*) firmwarePatches 118 | { 119 | return [_info objectForKey:FirmwarePatchesKey]; 120 | } 121 | 122 | -(NSDictionary*) filesystemPatches 123 | { 124 | return [_info objectForKey:FilesystemPatchesKey]; 125 | } 126 | 127 | -(NSDictionary*) basebandPatches 128 | { 129 | return [_info objectForKey:BasebandPatchesKey]; 130 | } 131 | 132 | -(BOOL) bbUpdateAvailable 133 | { 134 | return ([_info objectForKey:BasebandPatchesKey] != nil); 135 | } 136 | 137 | -(BOOL) phoneActivationAvailable 138 | { 139 | return ([[_info objectForKey:FilesystemPatchesKey] objectForKey:FSPhoneActivationKey] != nil); 140 | } 141 | 142 | @end -------------------------------------------------------------------------------- /Firmware/FirmwareDownload.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header FirmwareDownload.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | @class FirmwareBundle; 9 | 10 | @interface FirmwareDownload : NSObject 11 | { 12 | NSString* _file; 13 | NSURLDownload* _download; 14 | long long _expectedLength; 15 | long long _bytesReceived; 16 | } 17 | 18 | -(id) initWithFirmwareFile:(NSString*) file andDownload:(NSURLDownload*) download; 19 | 20 | -(NSString*) file; 21 | -(NSURLDownload*) download; 22 | 23 | -(long long) expectedLength; 24 | -(void) setExpectedLength:(long long) value; 25 | 26 | -(long long) bytesReceived; 27 | -(void) setBytesReceived:(long long) value; 28 | 29 | -(double) percentComplete; 30 | 31 | @end -------------------------------------------------------------------------------- /Firmware/FirmwareDownload.m: -------------------------------------------------------------------------------- 1 | /*! 2 | @source FirmwareDownload.m 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #import "FirmwareDownload.h" 9 | 10 | @implementation FirmwareDownload 11 | 12 | -(id) initWithFirmwareFile:(NSString*) file andDownload:(NSURLDownload*) download 13 | { 14 | self = [super init]; 15 | 16 | _file = file; 17 | _download = download; 18 | _bytesReceived = 0; 19 | _expectedLength = 0; 20 | 21 | return self; 22 | } 23 | 24 | -(NSString*) file 25 | { 26 | return _file; 27 | } 28 | 29 | -(NSURLDownload*) download 30 | { 31 | return _download; 32 | } 33 | 34 | -(long long) expectedLength 35 | { 36 | return _expectedLength; 37 | } 38 | 39 | -(void) setExpectedLength:(long long) value 40 | { 41 | _expectedLength = value; 42 | } 43 | 44 | -(long long) bytesReceived 45 | { 46 | return _bytesReceived; 47 | } 48 | 49 | -(void) setBytesReceived:(long long) value 50 | { 51 | _bytesReceived = value; 52 | } 53 | 54 | -(double) percentComplete 55 | { 56 | return (_bytesReceived / (double)_expectedLength) * 100; 57 | } 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /Firmware/FirmwareManager.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header FirmwareManager.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | @class Firmware, FirmwareDownload; 9 | 10 | @interface FirmwareManager : NSObject 11 | { 12 | NSMutableArray* _firmwareBundles; 13 | } 14 | 15 | -(void) loadFirmwareBundles; 16 | 17 | -(Firmware*) firmwareForFile:(NSString*) file platform:(Platform) platform; 18 | -(Firmware*) firmwareByFile:(NSString*) file platform:(Platform) platform; 19 | 20 | -(FirmwareDownload*) downloadFirmwareForPlatform:(Platform) platform delegate:(id) delegate; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Firmware/FirmwareManager.m: -------------------------------------------------------------------------------- 1 | /*! 2 | @source FirmwareManager.m 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #import "OpenSSLHelper.h" 9 | #import "Firmware.h" 10 | #import "FirmwareBundle.h" 11 | #import "FirmwareManager.h" 12 | #import "FirmwareDownload.h" 13 | 14 | @implementation FirmwareManager 15 | 16 | -(id) init 17 | { 18 | self = [super init]; 19 | 20 | _firmwareBundles = [[NSMutableArray alloc] init]; 21 | [self loadFirmwareBundles]; 22 | 23 | return self; 24 | } 25 | 26 | -(void) dealloc 27 | { 28 | [_firmwareBundles release]; 29 | 30 | [super dealloc]; 31 | } 32 | 33 | -(void) loadFirmwareBundles 34 | { 35 | [_firmwareBundles removeAllObjects]; 36 | 37 | NSString* path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"FirmwareBundles"]; 38 | NSFileManager* fm = [NSFileManager defaultManager]; 39 | NSArray* files = [fm directoryContentsAtPath:path]; 40 | int i = 0; 41 | int count = [files count]; 42 | 43 | for(i = 0; i < count; i++) 44 | { 45 | NSString* bundlePath = [files objectAtIndex:i]; 46 | if([[bundlePath pathExtension] isEqualToString:@"bundle"]) 47 | { 48 | bundlePath = [path stringByAppendingPathComponent:bundlePath]; 49 | NSDictionary* info = [NSDictionary dictionaryWithContentsOfFile:[bundlePath stringByAppendingPathComponent:@"Info.plist"]]; 50 | if(info != nil) 51 | { 52 | FirmwareBundle* fwb = [[[FirmwareBundle alloc] initWithInfo:info path:bundlePath] autorelease]; 53 | if (fwb != nil) 54 | [_firmwareBundles addObject: fwb]; 55 | } 56 | } 57 | } 58 | } 59 | 60 | -(Firmware*) firmwareForFile:(NSString*) file platform:(Platform) platform 61 | { 62 | NSString* shaValue = nil; 63 | 64 | NSEnumerator* enumerator = [_firmwareBundles objectEnumerator]; 65 | FirmwareBundle* firmwareBundle; 66 | while(firmwareBundle = [enumerator nextObject]) 67 | if([firmwareBundle platform] == platform) 68 | { 69 | if(shaValue == nil) 70 | shaValue = [OpenSSLHelper shaStringForFile:file]; 71 | 72 | if([shaValue compare:[firmwareBundle sha1] options:NSCaseInsensitiveSearch] == NSOrderedSame) 73 | return [[[Firmware alloc] initWithBundle:firmwareBundle path:file] autorelease]; 74 | } 75 | 76 | return nil; 77 | } 78 | 79 | -(Firmware*) firmwareByFile:(NSString*) file platform:(Platform) platform 80 | { 81 | NSString* shaValue = nil; 82 | 83 | NSEnumerator* enumerator = [_firmwareBundles objectEnumerator]; 84 | FirmwareBundle* firmwareBundle; 85 | while(firmwareBundle = [enumerator nextObject]) 86 | if([[file lastPathComponent] isEqualToString:[firmwareBundle filename]] && [firmwareBundle platform] == platform) 87 | { 88 | if(shaValue == nil) 89 | shaValue = [OpenSSLHelper shaStringForFile:file]; 90 | 91 | if([shaValue compare:[firmwareBundle sha1] options:NSCaseInsensitiveSearch] == NSOrderedSame) 92 | return [[[Firmware alloc] initWithBundle:firmwareBundle path:file] autorelease]; 93 | } 94 | 95 | return nil; 96 | } 97 | 98 | -(FirmwareDownload*) downloadFirmwareForPlatform:(Platform) platform delegate:(id) delegate 99 | { 100 | NSEnumerator* enumerator = [_firmwareBundles objectEnumerator]; 101 | FirmwareBundle* firmwareBundle = nil; 102 | while(firmwareBundle = [enumerator nextObject]) 103 | if([firmwareBundle platform] == platform) 104 | break; 105 | 106 | if(firmwareBundle == nil) 107 | return nil; 108 | 109 | NSString* downloadUrl = [firmwareBundle downloadUrl]; 110 | NSURL* url = [NSURL URLWithString:downloadUrl]; 111 | NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; 112 | NSURLDownload* download = [[NSURLDownload alloc] initWithRequest:request delegate:delegate]; 113 | 114 | if(download) 115 | { 116 | NSString* path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Desktop"] stringByAppendingPathComponent:[downloadUrl lastPathComponent]]; 117 | FirmwareDownload* firmwareDownload = [[[FirmwareDownload alloc] initWithFirmwareFile:path andDownload:download] autorelease]; 118 | 119 | [download setDestination:path allowOverwrite:YES]; 120 | 121 | return firmwareDownload; 122 | } 123 | 124 | return nil; 125 | } 126 | 127 | @end 128 | -------------------------------------------------------------------------------- /InstanceManager.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header InstanceManager.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | @class MainWindowController, FirmwareManager, BuilderSettings, Firmware, WizardStepController; 9 | 10 | @interface InstanceManager : NSObject 11 | 12 | +(void) init; 13 | +(void) unInit; 14 | 15 | +(FirmwareManager*) firmwareManager; 16 | 17 | +(MainWindowController*) mainController; 18 | +(void) setMainController:(MainWindowController*) controller; 19 | 20 | +(BOOL) isUILocked; 21 | +(void) setUILocked:(BOOL) value; 22 | 23 | +(void) setPushState:(PushButtonState) state; 24 | +(void) setText:(NSString*) text; 25 | +(void) setButtonText:(NSString*) text; 26 | +(void) enableSun:(BOOL) value; 27 | 28 | +(WizardStepController*) stepController; 29 | +(void) setStepController:(WizardStepController*) stepController; 30 | 31 | +(Platform) platform; 32 | +(void) setPlatform:(Platform) value; 33 | 34 | +(Firmware*) firmware; 35 | +(void) setFirmware:(Firmware*) value; 36 | 37 | +(NSString*) ramdiskPath; 38 | +(void) setRamdiskPath:(NSString*) value; 39 | 40 | +(NSArray*) searchFilesWithContentType:(NSString*) contentType name:(NSString*) name size:(int) size; 41 | +(void) deleteTempFiles; 42 | +(BOOL) checkFreeSpace:(unsigned long long) bytes atPath:(NSString*) path; 43 | 44 | +(void) runLoop; 45 | +(BOOL) checkURL:(NSURL*) url; 46 | 47 | @end 48 | 49 | @interface InstanceManager (IPhoneUSB) 50 | 51 | +(void) usbDelegateAdd:(id) delegate; 52 | +(void) usbDelegateRemove:(id) delegate; 53 | +(void) usbSendCommand:(NSString*) cmd; 54 | +(void) usbUploadFile:(NSString*) file; 55 | 56 | @end 57 | 58 | @interface InstanceManager (StringAndMessage) 59 | 60 | +(void) stopMessage; 61 | +(void) showBubble:(NSAttributedString*) text onSide:(MAWindowPosition) side ofView:(NSView*) view withTimeout:(int) seconds andDismissMode:(DismissMode) dismissMode; 62 | +(void) showError:(NSAttributedString*) text withTimeout:(int) seconds buttons:(NSArray*) buttons; 63 | +(void) showMessage:(NSAttributedString*) text withTimeout:(int) seconds buttons:(NSArray*) buttons; 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /InstanceManager.m: -------------------------------------------------------------------------------- 1 | /*! 2 | @source InstanceManager.m 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #import "MainWindowController.h" 9 | #import "SpotlightSearch.h" 10 | #import "OpenSSLHelper.h" 11 | #import "IPhoneUSB.h" 12 | #import "WizardStepController.h" 13 | #import "MessageManager.h" 14 | #import "Firmware.h" 15 | #import "FirmwareManager.h" 16 | #import "InstanceManager.h" 17 | 18 | static FirmwareManager* _firmwareManager; 19 | 20 | static MainWindowController* _mainController = nil; 21 | static MessageManager* _messageManager = nil; 22 | static SpotlightSearch* _spotlightSearch = nil; 23 | static BOOL _isUILocked = NO; 24 | 25 | static WizardStepController* _stepController = nil; 26 | 27 | static IPhoneUSB* _iPhoneUSB; 28 | static Platform _platform = Unknown; 29 | static Firmware* _firmware = nil; 30 | static NSString* _ramdiskPath = nil; 31 | 32 | @implementation InstanceManager 33 | 34 | +(void) init 35 | { 36 | _platform = Unknown; 37 | _firmwareManager = [[FirmwareManager alloc] init]; 38 | _spotlightSearch = [[SpotlightSearch alloc] init]; 39 | _messageManager = [[MessageManager alloc] init]; 40 | } 41 | 42 | +(void) unInit 43 | { 44 | if(_iPhoneUSB) 45 | { 46 | [_iPhoneUSB stopService]; 47 | [_iPhoneUSB release]; 48 | _iPhoneUSB = nil; 49 | } 50 | 51 | [_firmware release]; 52 | _firmware = nil; 53 | 54 | [_firmwareManager release]; 55 | _firmwareManager = nil; 56 | 57 | [_messageManager release]; 58 | _messageManager = nil; 59 | 60 | [_spotlightSearch release]; 61 | _spotlightSearch = nil; 62 | 63 | [InstanceManager deleteTempFiles]; 64 | } 65 | 66 | +(FirmwareManager*) firmwareManager 67 | { 68 | return _firmwareManager; 69 | } 70 | 71 | +(MainWindowController*) mainController 72 | { 73 | return _mainController; 74 | } 75 | 76 | +(void) setMainController:(MainWindowController*) value 77 | { 78 | _mainController = value; 79 | } 80 | 81 | +(BOOL) isUILocked 82 | { 83 | return _isUILocked; 84 | } 85 | 86 | +(void) setUILocked:(BOOL) value 87 | { 88 | _isUILocked = value; 89 | } 90 | 91 | +(void) setPushState:(PushButtonState) state 92 | { 93 | [_mainController setPushState:state]; 94 | } 95 | 96 | +(void) setText:(NSString*) text 97 | { 98 | [_mainController setText:text]; 99 | } 100 | 101 | +(void) setButtonText:(NSString*) text 102 | { 103 | [_mainController setButtonText:text]; 104 | } 105 | 106 | +(void) enableSun:(BOOL) value 107 | { 108 | [_mainController enableSun:value]; 109 | } 110 | 111 | +(WizardStepController*) stepController 112 | { 113 | return _stepController; 114 | } 115 | 116 | +(void) setStepController:(WizardStepController*) stepController 117 | { 118 | _stepController = stepController; 119 | [_stepController begin]; 120 | } 121 | 122 | +(Platform) platform 123 | { 124 | return _platform; 125 | } 126 | 127 | +(void) setPlatform:(Platform) value 128 | { 129 | _platform = value; 130 | } 131 | 132 | +(Firmware*) firmware 133 | { 134 | return _firmware; 135 | } 136 | 137 | +(void) setFirmware:(Firmware*) value 138 | { 139 | [_firmware release]; 140 | _firmware = [value retain]; 141 | 142 | if(_firmware != nil) 143 | [[NSUserDefaults standardUserDefaults] setObject:[_firmware path] forKey:LastFirmwarePathKey]; 144 | } 145 | 146 | +(NSString*) ramdiskPath 147 | { 148 | return _ramdiskPath; 149 | } 150 | 151 | +(void) setRamdiskPath:(NSString*) value 152 | { 153 | [_ramdiskPath release]; 154 | _ramdiskPath = [value copy]; 155 | } 156 | 157 | +(NSArray*) searchFilesWithContentType:(NSString*) contentType name:(NSString*) name size:(int) size 158 | { 159 | return [_spotlightSearch searchFilesWithContentType:contentType name:name size:size]; 160 | } 161 | 162 | +(void) deleteTempFiles 163 | { 164 | NSFileManager* fileManager = [NSFileManager defaultManager]; 165 | 166 | if([fileManager fileExistsAtPath:SystemTempDir]) 167 | [fileManager removeFileAtPath:SystemTempDir handler:nil]; 168 | } 169 | 170 | +(BOOL) checkFreeSpace:(unsigned long long) bytes atPath:(NSString*) path 171 | { 172 | NSFileManager* fileManager = [NSFileManager defaultManager]; 173 | NSDictionary* attrs = [fileManager fileSystemAttributesAtPath:path]; 174 | 175 | return ([[attrs objectForKey:NSFileSystemFreeSize] unsignedLongLongValue] > bytes); 176 | } 177 | 178 | +(void) runLoop 179 | { 180 | NSEvent* event; 181 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 182 | 183 | @try 184 | { 185 | while(event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:0.1] inMode:NSDefaultRunLoopMode dequeue:YES]) 186 | if([event type] == NSAppKitDefined || [event type] == NSSystemDefined) 187 | [NSApp sendEvent:event]; 188 | } 189 | @catch (NSException *ex) 190 | { 191 | Log(@"%@ %@", [ex name], [ex reason]); 192 | } 193 | @finally 194 | { 195 | [pool release]; 196 | } 197 | } 198 | 199 | +(BOOL) checkURL:(NSURL*) url 200 | { 201 | NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5]; 202 | NSURLResponse* response = nil; 203 | NSError* error = nil; 204 | 205 | [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 206 | 207 | return (error == nil); 208 | } 209 | 210 | @end 211 | 212 | @implementation InstanceManager (IPhoneUSB) 213 | 214 | +(void) usbDelegateAdd:(id) delegate 215 | { 216 | Log(@"%@ Add usb delegate", delegate); 217 | 218 | if(_iPhoneUSB == nil) 219 | { 220 | _iPhoneUSB = [[IPhoneUSB alloc] init]; 221 | [_iPhoneUSB startService]; 222 | } 223 | 224 | [_iPhoneUSB setDelegate:delegate]; 225 | } 226 | 227 | +(void) usbDelegateRemove:(id) delegate 228 | { 229 | Log(@"%@ Remove usb delegate", delegate); 230 | 231 | if([_iPhoneUSB delegate] == delegate) 232 | [_iPhoneUSB setDelegate:nil]; 233 | } 234 | 235 | +(void) usbSendCommand:(NSString*) cmd 236 | { 237 | [_iPhoneUSB sendCommand:cmd]; 238 | } 239 | 240 | +(void) usbUploadFile:(NSString*) file 241 | { 242 | [_iPhoneUSB uploadFile:file]; 243 | } 244 | 245 | @end 246 | 247 | @implementation InstanceManager (StringAndMessage) 248 | 249 | +(void) stopMessage 250 | { 251 | [_messageManager stopFloatingMessage]; 252 | } 253 | 254 | +(void) showBubble:(NSAttributedString*) text onSide:(MAWindowPosition) side ofView:(NSView*) view withTimeout:(int) seconds andDismissMode:(DismissMode) dismissMode 255 | { 256 | [_messageManager showBubble:text onSide:side ofView:view withTimeout:seconds andDismissMode:dismissMode]; 257 | } 258 | 259 | +(void) showError:(NSAttributedString*) text withTimeout:(int) seconds buttons:(NSArray*) buttons 260 | { 261 | NSBeep(); 262 | [_messageManager showMessage:text ofKind:ErrorMessage withTimeout:seconds buttons:buttons]; 263 | } 264 | 265 | +(void) showMessage:(NSAttributedString*) text withTimeout:(int) seconds buttons:(NSArray*) buttons 266 | { 267 | [_messageManager showMessage:text ofKind:TextMessage withTimeout:seconds buttons:buttons]; 268 | } 269 | 270 | @end 271 | -------------------------------------------------------------------------------- /MessageManager.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header MessageManager.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | @class FloatingMessage; 9 | 10 | @interface MessageManager : NSObject 11 | { 12 | FloatingMessage* _floatingMessage; 13 | NSTimer* _floatingMessageTimer; 14 | } 15 | 16 | -(void) showBubble:(NSAttributedString*) text onSide:(MAWindowPosition) side ofView:(NSView*) view withTimeout:(int) seconds andDismissMode:(DismissMode) dismissMode; 17 | -(void) showMessage:(NSAttributedString*) text ofKind:(MessageKind) kind withTimeout:(int) seconds buttons:(NSArray*) buttons; 18 | 19 | -(void) stopFloatingMessage; 20 | -(void) startFloatingMessageTimer:(int) seconds; 21 | 22 | -(void) runFloatingMessageLoop; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /MessageManager.m: -------------------------------------------------------------------------------- 1 | /*! 2 | @source MessageManager.m 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #import "FloatingMessage.h" 9 | #import "MessageManager.h" 10 | 11 | @implementation MessageManager 12 | 13 | -(id) init 14 | { 15 | self = [super init]; 16 | 17 | _floatingMessage = nil; 18 | _floatingMessageTimer = nil; 19 | 20 | return self; 21 | } 22 | 23 | -(void) dealloc 24 | { 25 | 26 | [super dealloc]; 27 | } 28 | 29 | -(void) showBubble:(NSAttributedString*) text onSide:(MAWindowPosition) side ofView:(NSView*) view withTimeout:(int) seconds andDismissMode:(DismissMode) dismissMode 30 | { 31 | NSDisableScreenUpdates(); 32 | 33 | [self stopFloatingMessage]; 34 | 35 | _floatingMessage = [[FloatingMessage alloc] initWithText:text ofKind:BubbleMessage onSide:side ofView:view withDismissMode:dismissMode]; 36 | [_floatingMessage run]; 37 | 38 | if(seconds > 0) 39 | [self startFloatingMessageTimer:seconds]; 40 | 41 | NSEnableScreenUpdates(); 42 | 43 | [self runFloatingMessageLoop]; 44 | } 45 | 46 | -(void) showMessage:(NSAttributedString*) text ofKind:(MessageKind) kind withTimeout:(int) seconds buttons:(NSArray*) buttons 47 | { 48 | NSDisableScreenUpdates(); 49 | 50 | [self stopFloatingMessage]; 51 | 52 | _floatingMessage = [[FloatingMessage alloc] initWithText:text ofKind:kind onWindow:[[InstanceManager mainController] window] buttons:buttons]; 53 | [_floatingMessage run]; 54 | 55 | if(seconds > 0) 56 | [self startFloatingMessageTimer:seconds]; 57 | 58 | NSEnableScreenUpdates(); 59 | 60 | [self runFloatingMessageLoop]; 61 | } 62 | 63 | -(void) stopFloatingMessage 64 | { 65 | if(_floatingMessage != nil) 66 | { 67 | [_floatingMessageTimer invalidate]; 68 | _floatingMessageTimer = nil; 69 | 70 | [_floatingMessage stop]; 71 | [_floatingMessage release]; 72 | _floatingMessage = nil; 73 | } 74 | } 75 | 76 | -(void) startFloatingMessageTimer:(int) seconds 77 | { 78 | NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:[MessageManager instanceMethodSignatureForSelector:@selector(stopFloatingMessage)]]; 79 | [invocation setSelector:@selector(stopFloatingMessage)]; 80 | [invocation setTarget:self]; 81 | 82 | _floatingMessageTimer = [NSTimer scheduledTimerWithTimeInterval:seconds invocation:invocation repeats:NO]; 83 | } 84 | 85 | -(void) runFloatingMessageLoop 86 | { 87 | NSDate* distantPast = [NSDate distantPast]; 88 | NSEvent* event; 89 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 90 | 91 | @try 92 | { 93 | while([_floatingMessage isRunning]) 94 | { 95 | event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:distantPast inMode:NSDefaultRunLoopMode dequeue:YES]; 96 | 97 | if(event != nil) 98 | { 99 | if([event type] == NSLeftMouseDown) 100 | { 101 | switch([_floatingMessage dismissMode]) 102 | { 103 | case dmNone: 104 | if([event window] != [_floatingMessage window]) 105 | NSBeep(); 106 | break; 107 | case dmAnyClick: 108 | [self stopFloatingMessage]; 109 | [NSApp sendEvent:event]; 110 | break; 111 | case dmInnerClick: 112 | if([event window] == [_floatingMessage window]) 113 | [self stopFloatingMessage]; 114 | else 115 | NSBeep(); 116 | break; 117 | case dmOuterClick: 118 | if([event window] != [_floatingMessage window]) 119 | [self stopFloatingMessage]; 120 | break; 121 | } 122 | } 123 | 124 | if([event window] == [_floatingMessage window] || [event type] == NSAppKitDefined || [event type] == NSSystemDefined) 125 | [NSApp sendEvent:event]; 126 | } 127 | } 128 | } 129 | @catch (NSException *ex) 130 | { 131 | Log(@"%@ %@", [ex name], [ex reason]); 132 | } 133 | @finally 134 | { 135 | [pool release]; 136 | } 137 | } 138 | 139 | @end 140 | -------------------------------------------------------------------------------- /Misc/ArrayAdditions.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header ArrayAdditions.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | @interface NSArray (Additions) 9 | 10 | -(NSArray*) objectsWithProperty:(SEL) selector equalTo:(id) value; 11 | -(NSArray*) objectsWithProperty:(SEL) selector equalToString:(NSString*) value; 12 | 13 | @end 14 | 15 | -------------------------------------------------------------------------------- /Misc/ArrayAdditions.m: -------------------------------------------------------------------------------- 1 | /*! 2 | @source ArrayAdditions.m 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #import "ArrayAdditions.h" 9 | 10 | @implementation NSArray (Additions) 11 | 12 | -(NSArray*) objectsWithProperty:(SEL) selector equalTo:(id) value 13 | { 14 | NSMutableArray* objects = [[[NSMutableArray alloc] init] autorelease]; 15 | 16 | NSEnumerator* enumerator = [self objectEnumerator]; 17 | id object; 18 | while(object = [enumerator nextObject]) 19 | if([object respondsToSelector:selector] && [object performSelector:selector] == value) 20 | [objects addObject:object]; 21 | 22 | return objects; 23 | } 24 | 25 | -(NSArray*) objectsWithProperty:(SEL) selector equalToString:(NSString*) value 26 | { 27 | NSMutableArray* objects = [[[NSMutableArray alloc] init] autorelease]; 28 | 29 | NSEnumerator* enumerator = [self objectEnumerator]; 30 | id object; 31 | while(object = [enumerator nextObject]) 32 | if([object respondsToSelector:selector] && [value isEqualToString:[object performSelector:selector]]) 33 | [objects addObject:object]; 34 | 35 | return objects;} 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /Misc/DrawAdditions.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header DrawAdditions.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #define LEFT_BOTTOM_CORNER 1 9 | #define LEFT_TOP_CORNER 2 10 | #define RIGHT_TOP_CORNER 4 11 | #define RIGHT_BOTTOM_CORNER 8 12 | #define ALL_CORNERS 15 13 | 14 | @interface NSBezierPath (RoundedRects) 15 | 16 | -(void) appendRoundedTop:(NSRect) rect radius:(float) radius; 17 | -(void) appendRoundedBottom:(NSRect) rect radius:(float) radius; 18 | 19 | -(void) appendRoundedRect:(NSRect) rect radius:(float) radius; 20 | -(void) appendRoundedRect:(NSRect) rect radiusX:(float) radiusX radiusY:(float) radiusY; 21 | -(void) appendRoundedRect:(NSRect) rect corners:(int) corners radius:(float) radius; 22 | -(void) appendRoundedRect:(NSRect) rect corners:(int) corners radiusX:(float) radiusX radiusY:(float) radiusY; 23 | 24 | -(void) customVerticalFillWithCallbacks:(CGFunctionCallbacks)functionCallbacks firstColor:(NSColor *)firstColor secondColor:(NSColor *)secondColor; 25 | -(void) linearGradientFillWithStartColor:(NSColor*) startColor endColor:(NSColor*) endColor; 26 | -(void) bilinearGradientFillWithOuterColor:(NSColor*) outerColor innerColor:(NSColor*) innerColor; 27 | 28 | @end 29 | 30 | @interface NSColor (RGBA) 31 | 32 | +(NSColor*) colorWithRGBA:(unsigned int) rgba; 33 | 34 | @end -------------------------------------------------------------------------------- /Misc/DrawAdditions.m: -------------------------------------------------------------------------------- 1 | /*! 2 | @source DrawAdditions.m 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #import "DrawAdditions.h" 9 | 10 | @implementation NSBezierPath (RoundedRects) 11 | 12 | -(void) appendRoundedTop:(NSRect) rect radius:(float) radius 13 | { 14 | float radControl = radius * 0.5; 15 | 16 | [self moveToPoint:NSMakePoint(rect.origin.x, rect.origin.y + rect.size.height - radius)]; 17 | [self relativeCurveToPoint:NSMakePoint(radius, radius) controlPoint1:NSMakePoint(0, radControl) controlPoint2:NSMakePoint (radius - radControl, radius)]; 18 | [self relativeLineToPoint:NSMakePoint(rect.size.width - 2 * radius, 0)]; 19 | [self relativeCurveToPoint:NSMakePoint(radius, -radius) controlPoint1:NSMakePoint(radControl, 0) controlPoint2:NSMakePoint (radius, radControl - radius)]; 20 | } 21 | 22 | -(void) appendRoundedBottom:(NSRect) rect radius:(float) radius 23 | { 24 | float radControl = radius * 0.5; 25 | 26 | [self moveToPoint:NSMakePoint(rect.origin.x, rect.origin.y + radius)]; 27 | [self relativeCurveToPoint:NSMakePoint(radius, -radius) controlPoint1:NSMakePoint(0, -radControl) controlPoint2:NSMakePoint (radius - radControl, -radius)]; 28 | [self relativeLineToPoint:NSMakePoint(rect.size.width - 2 * radius, 0)]; 29 | [self relativeCurveToPoint:NSMakePoint(radius, radius) controlPoint1:NSMakePoint(radControl, 0) controlPoint2:NSMakePoint (radius, radius - radControl)]; 30 | } 31 | 32 | -(void) appendRoundedRect:(NSRect) rect radius:(float) radius 33 | { 34 | [self appendRoundedRect:rect corners:ALL_CORNERS radius:radius]; 35 | } 36 | 37 | -(void) appendRoundedRect:(NSRect) rect radiusX:(float) radiusX radiusY:(float) radiusY 38 | { 39 | [self appendRoundedRect:rect corners:ALL_CORNERS radiusX:radiusX radiusY:radiusY]; 40 | } 41 | 42 | -(void) appendRoundedRect:(NSRect) rect corners:(int) corners radius:(float) radius 43 | { 44 | [self appendRoundedRect:rect corners:corners radiusX:radius radiusY:radius]; 45 | } 46 | 47 | -(void) appendRoundedRect:(NSRect) rect corners:(int) corners radiusX:(float) radiusX radiusY:(float) radiusY 48 | { 49 | // if the radius is larger than the rectangle, slim it down 50 | if(radiusX > rect.size.width / 2.0) 51 | radiusX = rect.size.width / 2.0; 52 | 53 | if(radiusY > rect.size.height / 2.0) 54 | radiusY = rect.size.height / 2.0; 55 | 56 | float radControlX = radiusX * 0.5522847498; 57 | float radControlY = radiusY * 0.5522847498; 58 | 59 | // inner rect is offset by the radius on each side 60 | NSRect innerRect = NSMakeRect(rect.origin.x + radiusX, rect.origin.y + radiusY, rect.size.width - radiusX * 2, rect.size.height - radiusY * 2 ); 61 | 62 | // starting in the lower left corner 63 | if((corners & LEFT_BOTTOM_CORNER) == LEFT_BOTTOM_CORNER) 64 | [self moveToPoint:NSMakePoint(rect.origin.x, innerRect.origin.y)]; 65 | else 66 | [self moveToPoint:NSMakePoint(rect.origin.x, rect.origin.y)]; 67 | 68 | // left side 69 | if((corners & LEFT_BOTTOM_CORNER) == LEFT_BOTTOM_CORNER && (corners & LEFT_TOP_CORNER) == LEFT_TOP_CORNER) 70 | [self relativeLineToPoint:NSMakePoint(0, innerRect.size.height)]; 71 | else if((corners & LEFT_BOTTOM_CORNER) == LEFT_BOTTOM_CORNER || (corners & LEFT_TOP_CORNER) == LEFT_TOP_CORNER) 72 | [self relativeLineToPoint:NSMakePoint(0, rect.size.height - radiusY)]; 73 | else 74 | [self relativeLineToPoint:NSMakePoint(0, rect.size.height)]; 75 | 76 | // upper left corner 77 | if((corners & LEFT_TOP_CORNER) == LEFT_TOP_CORNER) 78 | [self relativeCurveToPoint:NSMakePoint(radiusX,radiusY) controlPoint1:NSMakePoint(0,radControlY) controlPoint2:NSMakePoint(radiusX - radControlX, radiusY)]; 79 | 80 | // top side 81 | if((corners & LEFT_TOP_CORNER) == LEFT_TOP_CORNER && (corners & RIGHT_TOP_CORNER) == RIGHT_TOP_CORNER) 82 | [self relativeLineToPoint:NSMakePoint(innerRect.size.width, 0)]; 83 | else if((corners & LEFT_TOP_CORNER) == LEFT_TOP_CORNER || (corners & RIGHT_TOP_CORNER) == RIGHT_TOP_CORNER) 84 | [self relativeLineToPoint:NSMakePoint(rect.size.width - radiusX, 0)]; 85 | else 86 | [self relativeLineToPoint:NSMakePoint(rect.size.width, 0)]; 87 | 88 | // upper right corner 89 | if((corners & RIGHT_TOP_CORNER) == RIGHT_TOP_CORNER) 90 | [self relativeCurveToPoint:NSMakePoint(radiusX, -radiusY) controlPoint1:NSMakePoint(radControlX, 0) controlPoint2:NSMakePoint(radiusX, radControlY - radiusY)]; 91 | 92 | // right side 93 | if((corners & RIGHT_TOP_CORNER) == RIGHT_TOP_CORNER && (corners & RIGHT_BOTTOM_CORNER) == RIGHT_BOTTOM_CORNER) 94 | [self relativeLineToPoint:NSMakePoint(0, -innerRect.size.height)]; 95 | else if((corners & RIGHT_TOP_CORNER) == RIGHT_TOP_CORNER || (corners & RIGHT_BOTTOM_CORNER) == RIGHT_BOTTOM_CORNER) 96 | [self relativeLineToPoint:NSMakePoint(0, -(rect.size.height - radiusY))]; 97 | else 98 | [self relativeLineToPoint:NSMakePoint(0, -rect.size.height)]; 99 | 100 | // lower right corner 101 | if((corners & RIGHT_BOTTOM_CORNER) == RIGHT_BOTTOM_CORNER) 102 | [self relativeCurveToPoint:NSMakePoint(-radiusX, -radiusY) controlPoint1:NSMakePoint(0, -radControlY) controlPoint2:NSMakePoint (radControlX - radiusX, -radiusY)]; 103 | 104 | // bottom side 105 | if((corners & RIGHT_BOTTOM_CORNER) == RIGHT_BOTTOM_CORNER && (corners & LEFT_BOTTOM_CORNER) == LEFT_BOTTOM_CORNER) 106 | [self relativeLineToPoint:NSMakePoint(-innerRect.size.width, 0)]; 107 | else if((corners & RIGHT_BOTTOM_CORNER) == RIGHT_BOTTOM_CORNER || (corners & LEFT_BOTTOM_CORNER) == LEFT_BOTTOM_CORNER) 108 | [self relativeLineToPoint:NSMakePoint(-(rect.size.width - radiusX), 0)]; 109 | else 110 | [self relativeLineToPoint:NSMakePoint(-rect.size.width, 0)]; 111 | 112 | // lower left corner 113 | if((corners & LEFT_BOTTOM_CORNER) == LEFT_BOTTOM_CORNER) 114 | [self relativeCurveToPoint:NSMakePoint(-radiusX, radiusY) controlPoint1:NSMakePoint(-radControlX, 0) controlPoint2:NSMakePoint(-radiusX, radControlY)]; 115 | } 116 | 117 | static void linearShadedColor(void* info, const float* in, float* out) 118 | { 119 | float* colors = info; 120 | *out++ = colors[0] + *in * colors[8]; 121 | *out++ = colors[1] + *in * colors[9]; 122 | *out++ = colors[2] + *in * colors[10]; 123 | *out++ = colors[3] + *in * colors[11]; 124 | } 125 | 126 | static void bilinearShadedColor(void* info, const float* in, float* out) 127 | { 128 | float* colors = info; 129 | float factor = (*in) * 2.0; 130 | 131 | if (*in < 0.5) 132 | factor = 2.0 - factor; 133 | 134 | *out++ = colors[0] + factor * colors[8]; 135 | *out++ = colors[1] + factor * colors[9]; 136 | *out++ = colors[2] + factor * colors[10]; 137 | *out++ = colors[3] + factor * colors[11]; 138 | } 139 | 140 | -(void) linearGradientFillWithStartColor:(NSColor*) startColor endColor:(NSColor*) endColor 141 | { 142 | static const CGFunctionCallbacks callbacks = {0, &linearShadedColor, NULL}; 143 | 144 | [self customVerticalFillWithCallbacks:callbacks firstColor:startColor secondColor:endColor]; 145 | } 146 | 147 | -(void) bilinearGradientFillWithOuterColor:(NSColor*) outerColor innerColor:(NSColor*) innerColor 148 | { 149 | static const CGFunctionCallbacks callbacks = {0, &bilinearShadedColor, NULL}; 150 | 151 | [self customVerticalFillWithCallbacks:callbacks firstColor:innerColor secondColor:outerColor]; 152 | } 153 | 154 | -(void) customVerticalFillWithCallbacks:(CGFunctionCallbacks) functionCallbacks firstColor:(NSColor*) firstColor secondColor:(NSColor*) secondColor 155 | { 156 | CGColorSpaceRef colorspace; 157 | CGShadingRef shading; 158 | CGPoint startPoint = {0, 0}; 159 | CGPoint endPoint = {0, 0}; 160 | CGFunctionRef function; 161 | float colors[12]; // pointer to color values 162 | 163 | // get my context 164 | CGContextRef currentContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; 165 | 166 | NSColor *deviceDependentFirstColor = [firstColor colorUsingColorSpaceName:NSDeviceRGBColorSpace]; 167 | NSColor *deviceDependentSecondColor = [secondColor colorUsingColorSpaceName:NSDeviceRGBColorSpace]; 168 | 169 | // set up colors for gradient 170 | colors[0] = [deviceDependentFirstColor redComponent]; 171 | colors[1] = [deviceDependentFirstColor greenComponent]; 172 | colors[2] = [deviceDependentFirstColor blueComponent]; 173 | colors[3] = [deviceDependentFirstColor alphaComponent]; 174 | 175 | colors[4] = [deviceDependentSecondColor redComponent]; 176 | colors[5] = [deviceDependentSecondColor greenComponent]; 177 | colors[6] = [deviceDependentSecondColor blueComponent]; 178 | colors[7] = [deviceDependentSecondColor alphaComponent]; 179 | 180 | // difference between start and end color for each color components 181 | colors[8] = (colors[4]-colors[0]); 182 | colors[9] = (colors[5]-colors[1]); 183 | colors[10] = (colors[6]-colors[2]); 184 | colors[11] = (colors[7]-colors[3]); 185 | 186 | // draw gradient 187 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 188 | colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); 189 | #else 190 | colorspace = CGColorSpaceCreateDeviceRGB(); 191 | #endif 192 | size_t components = 1 + CGColorSpaceGetNumberOfComponents(colorspace); 193 | static const float domain[2] = {0.0, 1.0}; 194 | static const float range[10] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; 195 | 196 | // Create a CGFunctionRef that describes a function taking 1 input and kChannelsPerColor outputs. 197 | function = CGFunctionCreate(colors, 1, domain, components, range, &functionCallbacks); 198 | 199 | startPoint.x = 0; 200 | startPoint.y = [self bounds].origin.y; 201 | endPoint.x = 0; 202 | endPoint.y = NSMaxY([self bounds]); 203 | 204 | shading = CGShadingCreateAxial(colorspace, startPoint, endPoint, function, NO, NO); 205 | 206 | CGContextSaveGState(currentContext); 207 | [self addClip]; 208 | CGContextDrawShading(currentContext, shading); 209 | CGContextRestoreGState(currentContext); 210 | 211 | CGShadingRelease(shading); 212 | CGFunctionRelease(function); 213 | CGColorSpaceRelease(colorspace); 214 | } 215 | 216 | @end 217 | 218 | @implementation NSColor (RGBA) 219 | 220 | +(NSColor*) colorWithRGBA:(unsigned int) rgba 221 | { 222 | // Log(@"colorWithRGBA - RGBA: %u, R:%f G:%f B:%f A:%f", rgba, (float)(rgba >> 24) / 255, (float)((rgba >> 16) & 0xFF) / 255, (float)((rgba >> 8) & 0xFF) / 255, (float)(rgba & 0xFF) / 255); 223 | return [NSColor colorWithDeviceRed:(float)(rgba >> 24) / 255 green:(float)((rgba >> 16) & 0xFF) / 255 blue:(float)((rgba >> 8) & 0xFF) / 255 alpha:(float)(rgba & 0xFF) / 255]; 224 | } 225 | 226 | @end -------------------------------------------------------------------------------- /Misc/SpotlightSearch.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header SpotlightSearch.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | @interface SpotlightSearch : NSObject 9 | { 10 | NSMetadataQuery* _mdQuery; 11 | NSMutableArray* _results; 12 | 13 | BOOL _isSpotlightAvailable; 14 | BOOL _searchDidFinish; 15 | NSString* _searchName; 16 | int _searchSize; 17 | } 18 | 19 | -(BOOL) isSpotlightAvailable; 20 | -(NSArray*) searchFilesWithContentType:(NSString*) contentType name:(NSString*) name size:(int) size; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Misc/SpotlightSearch.m: -------------------------------------------------------------------------------- 1 | /*! 2 | @source SpotlightSearch.m 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #import 9 | #import "SpotlightSearch.h" 10 | 11 | @implementation SpotlightSearch 12 | 13 | -(id) init 14 | { 15 | self = [super init]; 16 | 17 | _mdQuery = [[NSMetadataQuery alloc] init]; 18 | _results = [[NSMutableArray alloc] init]; 19 | 20 | [[NSNotificationCenter defaultCenter] addObserver:self 21 | selector:@selector(queryHandler:) 22 | name:NSMetadataQueryDidFinishGatheringNotification object:_mdQuery]; 23 | 24 | _isSpotlightAvailable = [self isSpotlightAvailable]; 25 | 26 | return self; 27 | } 28 | 29 | -(void) dealloc 30 | { 31 | [_mdQuery release]; 32 | [_results release]; 33 | 34 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 35 | 36 | [super dealloc]; 37 | } 38 | 39 | -(BOOL) isSpotlightAvailable 40 | { 41 | int err; 42 | struct kinfo_proc* result_ptr = NULL; 43 | static const int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 }; 44 | size_t length; 45 | BOOL done = NO; 46 | 47 | do 48 | { 49 | length = 0; 50 | 51 | err = sysctl((int*)name, (sizeof(name) / sizeof(*name)) - 1, NULL, &length, NULL, 0); 52 | 53 | if(err == -1) 54 | err = errno; 55 | 56 | if(err == 0) 57 | { 58 | result_ptr = (struct kinfo_proc*)malloc(length); 59 | 60 | if(result_ptr == NULL) 61 | err = ENOMEM; 62 | } 63 | 64 | if(err == 0) 65 | { 66 | err = sysctl((int*)name, (sizeof(name) / sizeof(*name)) - 1, result_ptr, &length, NULL, 0); 67 | 68 | if(err == -1) 69 | err = errno; 70 | 71 | if(err == 0) 72 | { 73 | done = YES; 74 | } 75 | else if(err == ENOMEM) 76 | { 77 | result_ptr = NULL; 78 | err = 0; 79 | } 80 | } 81 | } 82 | while(err == 0 && done == NO); 83 | 84 | if(err != 0 && result_ptr != NULL) 85 | { 86 | free(result_ptr); 87 | result_ptr = NULL; 88 | } 89 | 90 | BOOL result = NO; 91 | 92 | if(result_ptr != NULL) 93 | { 94 | int count = length / sizeof(struct kinfo_proc); 95 | int i = 0; 96 | 97 | for(i = 0; i < count; ++i) 98 | { 99 | struct kinfo_proc kp = result_ptr[i]; 100 | if(strcmp(kp.kp_proc.p_comm, "mds") == 0) 101 | { 102 | result = YES; 103 | break; 104 | } 105 | } 106 | 107 | free(result_ptr); 108 | } 109 | 110 | return result; 111 | } 112 | 113 | -(NSArray*) searchFilesWithContentType:(NSString*) contentType name:(NSString*) name size:(int) size 114 | { 115 | [_results removeAllObjects]; 116 | 117 | if(_isSpotlightAvailable) 118 | { 119 | _searchDidFinish = NO; 120 | _searchName = name; 121 | _searchSize = size; 122 | 123 | NSString* queryString = [NSString stringWithFormat:@"kMDItemContentType == '%@'", contentType]; 124 | NSPredicate* predicate = [NSPredicate predicateWithFormat: queryString]; 125 | [_mdQuery setPredicate:predicate]; 126 | [_mdQuery startQuery]; 127 | 128 | while(!_searchDidFinish) 129 | [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 130 | } 131 | 132 | return _results; 133 | } 134 | 135 | -(void) queryHandler:(NSNotification*) notification 136 | { 137 | NSEnumerator* enumerator = [[_mdQuery results] objectEnumerator]; 138 | NSMetadataItem* item; 139 | while(item = [enumerator nextObject]) 140 | { 141 | NSString* fsName = [item valueForAttribute:@"kMDItemFSName"]; 142 | NSNumber* fsSize = [item valueForAttribute:@"kMDItemFSSize"]; 143 | NSString* path = [item valueForAttribute:@"kMDItemPath"]; 144 | 145 | if(fsName != nil && fsSize != nil && path != nil) 146 | if(_searchName == nil || [fsName isEqualToString:_searchName]) 147 | if(_searchSize == 0 || [fsSize intValue] == _searchSize) 148 | [_results addObject:path]; 149 | } 150 | 151 | _searchDidFinish = YES; 152 | } 153 | 154 | @end 155 | -------------------------------------------------------------------------------- /Misc/StringAdditions.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header StringAdditions.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | @interface NSAttributedString (Additions) 9 | 10 | -(void) drawInRect:(NSRect) bounds withAlignment:(NSTextAlignment) alignment; 11 | 12 | @end 13 | 14 | @interface NSString (Additions) 15 | 16 | -(NSString*) urlEncoded; 17 | -(NSAttributedString*) hyperlink; 18 | -(void) drawInRect:(NSRect) bounds withFont:(NSFont*) font color:(NSColor*) color alignment:(NSTextAlignment) alignment; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Misc/StringAdditions.m: -------------------------------------------------------------------------------- 1 | /*! 2 | @source StringAdditions.m 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #import "SupportClasses.h" 9 | #import "StringAdditions.h" 10 | 11 | @implementation NSAttributedString (Additions) 12 | 13 | -(void) drawInRect:(NSRect) bounds withAlignment:(NSTextAlignment) alignment 14 | { 15 | NSTextStorage* ts = [[[NSTextStorage alloc] initWithAttributedString:self] autorelease]; 16 | 17 | NSLayoutManager* lm = [[[NSLayoutManager alloc] init] autorelease]; 18 | NSTextContainer* tc = [[[NSTextContainer alloc] init] autorelease]; 19 | [lm addTextContainer:tc]; 20 | [ts addLayoutManager:lm]; 21 | 22 | NSRange glyphRange = [lm glyphRangeForTextContainer:tc]; 23 | NSRect usedBounds = [lm usedRectForTextContainer:tc]; 24 | 25 | switch(alignment) 26 | { 27 | case NSRightTextAlignment: 28 | bounds.origin.x += NSWidth(bounds) - NSWidth(usedBounds); 29 | break; 30 | case NSCenterTextAlignment: 31 | bounds.origin.x += (NSWidth(bounds) - NSWidth(usedBounds)) / 2; 32 | break; 33 | } 34 | 35 | [lm drawGlyphsForGlyphRange:glyphRange atPoint:bounds.origin]; 36 | } 37 | 38 | @end 39 | 40 | @implementation NSString (Additions) 41 | 42 | -(NSString*) urlEncoded 43 | { 44 | NSString* result = (NSString*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)self, NULL, CFSTR("?=&+"), kCFStringEncodingUTF8); 45 | return [result autorelease]; 46 | } 47 | 48 | -(NSAttributedString*) hyperlink 49 | { 50 | NSDictionary* attrs = [NSDictionary dictionaryWithObjectsAndKeys: 51 | [NSNumber numberWithInt:NSSingleUnderlineStyle], NSUnderlineStyleAttributeName, 52 | self, NSLinkAttributeName, 53 | [NSColor colorWithCalibratedRed:0.1 green:0.1 blue:1.0 alpha:1.0], NSForegroundColorAttributeName, 54 | [NSCursor openHandCursor], NSCursorAttributeName, 55 | nil]; 56 | 57 | return [[[NSAttributedString alloc] initWithString:self attributes:attrs] autorelease]; 58 | } 59 | 60 | -(void) drawInRect:(NSRect) bounds withFont:(NSFont*) font color:(NSColor*) color alignment:(NSTextAlignment) alignment 61 | { 62 | NSTextStorage* ts = [[[NSTextStorage alloc] initWithString:self attributes:[NSDictionary dictionaryWithObjectsAndKeys: 63 | font, NSFontAttributeName, 64 | color, NSForegroundColorAttributeName, 65 | nil]] autorelease]; 66 | 67 | NSLayoutManager* lm = [[[NSLayoutManager alloc] init] autorelease]; 68 | NSTextContainer* tc = [[[NSTextContainer alloc] init] autorelease]; 69 | [lm addTextContainer:tc]; 70 | [ts addLayoutManager:lm]; 71 | 72 | NSRange glyphRange = [lm glyphRangeForTextContainer:tc]; 73 | NSRect usedBounds = [lm usedRectForTextContainer:tc]; 74 | 75 | switch(alignment) 76 | { 77 | case NSRightTextAlignment: 78 | bounds.origin.x += NSWidth(bounds) - NSWidth(usedBounds); 79 | break; 80 | case NSCenterTextAlignment: 81 | bounds.origin.x += (NSWidth(bounds) - NSWidth(usedBounds)) / 2; 82 | break; 83 | } 84 | 85 | [lm drawGlyphsForGlyphRange:glyphRange atPoint:bounds.origin]; 86 | } 87 | 88 | @end 89 | -------------------------------------------------------------------------------- /Misc/SupportClasses.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header SupportClasses.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | @interface MacOSVersion : NSObject 9 | 10 | +(BOOL) is104OrLater; 11 | +(BOOL) is105OrLater; 12 | +(BOOL) is106OrLater; 13 | 14 | @end 15 | 16 | @interface Drawing : NSObject 17 | 18 | +(NSSize) sizeForString:(NSString*) string withAttributes:(NSDictionary*) dict; 19 | +(NSSize) sizeForString:(NSString*) string withFont:(NSFont*) font; 20 | +(NSSize) sizeForAttributedString:(NSAttributedString*) string; 21 | +(float) heightForFont:(NSFont*) font; 22 | 23 | +(NSRect) boundingRectForAttributedString:(NSAttributedString*) as withBounds:(NSSize) boundsSize; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Misc/SupportClasses.m: -------------------------------------------------------------------------------- 1 | /*! 2 | @source SupportClasses.m 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #import "SupportClasses.h" 9 | 10 | @implementation MacOSVersion : NSObject 11 | 12 | +(BOOL) is104OrLater 13 | { 14 | SInt32 sys = 0; 15 | Gestalt(gestaltSystemVersion, &sys); 16 | 17 | return sys >= 0x1040; 18 | } 19 | 20 | +(BOOL) is105OrLater 21 | { 22 | SInt32 sys = 0; 23 | Gestalt(gestaltSystemVersion, &sys); 24 | 25 | return sys >= 0x1050; 26 | } 27 | 28 | +(BOOL) is106OrLater 29 | { 30 | SInt32 sys = 0; 31 | Gestalt(gestaltSystemVersion, &sys); 32 | 33 | return sys >= 0x1060; 34 | } 35 | 36 | @end 37 | 38 | @implementation Drawing 39 | 40 | +(NSSize) sizeForString:(NSString*) string withAttributes:(NSDictionary*) dict 41 | { 42 | NSAttributedString* as = [[[NSAttributedString alloc] initWithString:string attributes:dict] autorelease]; 43 | return [Drawing sizeForAttributedString:as]; 44 | } 45 | 46 | +(NSSize) sizeForString:(NSString*) string withFont:(NSFont*) font 47 | { 48 | return [Drawing sizeForString:string withAttributes:[NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]]; 49 | } 50 | 51 | +(NSSize) sizeForAttributedString:(NSAttributedString*) as 52 | { 53 | return [Drawing boundingRectForAttributedString:as withBounds:NSMakeSize(1e6, 1e6)].size; 54 | } 55 | 56 | +(float) heightForFont:(NSFont*) font 57 | { 58 | return [Drawing sizeForString:@"0" withFont:font].height; 59 | } 60 | 61 | +(NSRect) boundingRectForAttributedString:(NSAttributedString*) as withBounds:(NSSize) boundsSize 62 | { 63 | if(as == nil || [as length] == 0) 64 | return NSZeroRect; 65 | 66 | NSTextStorage* ts = [[[NSTextStorage alloc] initWithAttributedString:as] autorelease]; 67 | NSTextContainer* tc = [[[NSTextContainer alloc] initWithContainerSize:NSMakeSize(boundsSize.width,1e6)] autorelease]; 68 | NSLayoutManager* lm = [[[NSLayoutManager alloc] init] autorelease]; 69 | 70 | [tc setLineFragmentPadding:1]; 71 | [tc setWidthTracksTextView:NO]; 72 | [tc setHeightTracksTextView:NO]; 73 | [lm addTextContainer:tc]; 74 | [lm setUsesScreenFonts:NO]; 75 | [ts addLayoutManager:lm]; 76 | 77 | [lm glyphRangeForTextContainer:tc]; 78 | 79 | return [lm usedRectForTextContainer:tc]; 80 | } 81 | 82 | @end -------------------------------------------------------------------------------- /Misc/WorkspaceAdditions.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header WorkspaceAdditions.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | @interface NSWorkspace (Additions) 9 | 10 | -(NSImage*) fullIconForFile:(NSString*) fullPath; 11 | -(NSImage*) fullIconForType:(OSType) iconType; 12 | -(NSImage*) fullIconForExtension:(NSString*) extension; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Misc/WorkspaceAdditions.m: -------------------------------------------------------------------------------- 1 | /*! 2 | @source WorkspaceAdditions.m 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #import "WorkspaceAdditions.h" 9 | 10 | @implementation NSWorkspace (Additions) 11 | 12 | -(NSImage*) fullIconFromIconRef:(IconRef) iconRef 13 | { 14 | NSImage *image = nil; 15 | IconFamilyHandle iconFamily = NULL; 16 | 17 | OSStatus err = IconRefToIconFamily(iconRef, kSelectorAllAvailableData, &iconFamily); 18 | 19 | if(err == noErr && iconFamily) 20 | { 21 | NSData *data = [NSData dataWithBytes:*iconFamily length:GetHandleSize((Handle)iconFamily)]; 22 | 23 | image = [[[NSImage alloc] initWithData:data] autorelease]; 24 | 25 | DisposeHandle((Handle)iconFamily); 26 | } 27 | 28 | return image; 29 | } 30 | 31 | -(NSImage*) fullIconForFile:(NSString*) fullPath 32 | { 33 | const UInt8 *filePath = (const UInt8 *)[fullPath fileSystemRepresentation]; 34 | 35 | if(!filePath) 36 | return nil; 37 | 38 | FSRef ref; 39 | Boolean isDir; 40 | OSStatus err = FSPathMakeRef(filePath, &ref, &isDir); 41 | 42 | if(err != noErr) 43 | return nil; 44 | 45 | SInt16 label; 46 | IconRef iconRef = nil; 47 | err = GetIconRefFromFileInfo(&ref, 0, NULL, kFSCatInfoNone, NULL, kIconServicesNormalUsageFlag, &iconRef, &label); 48 | 49 | if(err != noErr) 50 | return nil; 51 | 52 | NSImage *image = [self fullIconFromIconRef:iconRef]; 53 | ReleaseIconRef(iconRef); 54 | 55 | return image; 56 | } 57 | 58 | -(NSImage*) fullIconForType:(OSType) iconType 59 | { 60 | IconRef iconRef = NULL; 61 | NSImage *image = nil; 62 | 63 | OSStatus error = GetIconRef(kOnSystemDisk, kSystemIconsCreator, iconType, &iconRef); 64 | 65 | if(!error && iconRef) 66 | { 67 | image = [self fullIconFromIconRef:iconRef]; 68 | ReleaseIconRef(iconRef); 69 | } 70 | 71 | return image; 72 | } 73 | 74 | -(NSImage*) fullIconForExtension:(NSString*) extension 75 | { 76 | IconRef iconRef = NULL; 77 | NSImage *image = nil; 78 | 79 | OSStatus error = GetIconRefFromTypeInfo(0, 0, (CFStringRef)extension, 0, 0, &iconRef); 80 | 81 | if(!error && iconRef) 82 | { 83 | image = [self fullIconFromIconRef:iconRef]; 84 | ReleaseIconRef(iconRef); 85 | } 86 | 87 | return image; 88 | } 89 | 90 | @end 91 | -------------------------------------------------------------------------------- /MobileDeviceServices/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AppTapp/Pusher-Exploit/b713b3e1fee9d18c4bc916f147afa3425107f7f6/MobileDeviceServices/.DS_Store -------------------------------------------------------------------------------- /MobileDeviceServices/MobileDeviceInterface.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | 5 | #include 6 | #include 7 | 8 | /* Error codes */ 9 | #define MDERR_APPLE_MOBILE (err_system(0x3a)) 10 | #define MDERR_IPHONE (err_sub(0)) 11 | 12 | /* Apple Mobile (AM*) errors */ 13 | #define MDERR_OK ERR_SUCCESS 14 | #define MDERR_SYSCALL (ERR_MOBILE_DEVICE | 0x01) 15 | #define MDERR_OUT_OF_MEMORY (ERR_MOBILE_DEVICE | 0x03) 16 | #define MDERR_QUERY_FAILED (ERR_MOBILE_DEVICE | 0x04) 17 | #define MDERR_INVALID_ARGUMENT (ERR_MOBILE_DEVICE | 0x0b) 18 | #define MDERR_DICT_NOT_LOADED (ERR_MOBILE_DEVICE | 0x25) 19 | 20 | /* Apple File Connection (AFC*) errors */ 21 | #define MDERR_AFC_OUT_OF_MEMORY 0x03 22 | 23 | /* USBMux errors */ 24 | #define MDERR_USBMUX_ARG_NULL 0x16 25 | #define MDERR_USBMUX_FAILED 0xffffffff 26 | 27 | /* Messages passed to device notification callbacks: passed as part of 28 | * am_device_notification_callback_info. */ 29 | #define ADNCI_MSG_CONNECTED 1 30 | #define ADNCI_MSG_DISCONNECTED 2 31 | #define ADNCI_MSG_UNKNOWN 3 32 | 33 | #define AMD_IPHONE_PRODUCT_ID 0x1290 34 | //#define AMD_IPHONE_SERIAL "" 35 | 36 | /* Services, found in /System/Library/Lockdown/Services.plist */ 37 | #define AMSVC_AFC CFSTR("com.apple.afc") 38 | #define AMSVC_BACKUP CFSTR("com.apple.mobilebackup") 39 | #define AMSVC_CRASH_REPORT_COPY CFSTR("com.apple.crashreportcopy") 40 | #define AMSVC_DEBUG_IMAGE_MOUNT CFSTR("com.apple.mobile.debug_image_mount") 41 | #define AMSVC_NOTIFICATION_PROXY CFSTR("com.apple.mobile.notification_proxy") 42 | #define AMSVC_PURPLE_TEST CFSTR("com.apple.purpletestr") 43 | #define AMSVC_SOFTWARE_UPDATE CFSTR("com.apple.mobile.software_update") 44 | #define AMSVC_SYNC CFSTR("com.apple.mobilesync") 45 | #define AMSVC_SCREENSHOT CFSTR("com.apple.screenshotr") 46 | #define AMSVC_SYSLOG_RELAY CFSTR("com.apple.syslog_relay") 47 | #define AMSVC_SYSTEM_PROFILER CFSTR("com.apple.mobile.system_profiler") 48 | 49 | typedef unsigned int afc_error_t; 50 | typedef unsigned int usbmux_error_t; 51 | 52 | struct am_device_notification_callback_info 53 | { 54 | struct am_device* dev; /* 0 device */ 55 | unsigned int msg; /* 4 one of ADNCI_MSG_* */ 56 | }; 57 | 58 | typedef void(*am_device_notification_callback)(struct am_device_notification_callback_info*, void*); 59 | 60 | struct am_device 61 | { 62 | unsigned char unknown0[16]; /* 0 - zero */ 63 | unsigned int device_id; /* 16 */ 64 | unsigned int product_id; /* 20 - set to AMD_IPHONE_PRODUCT_ID */ 65 | char* serial; /* 24 - set to AMD_IPHONE_SERIAL */ 66 | unsigned int unknown1; /* 28 */ 67 | unsigned char unknown2[4]; /* 32 */ 68 | unsigned int lockdown_connection; /* 36 */ 69 | unsigned char unknown3[8]; /* 40 */ 70 | }; 71 | 72 | struct am_device_notification 73 | { 74 | unsigned int reserved; 75 | void* usbmuxListener; 76 | void* usbmuxRunLoopSource; 77 | am_device_notification_callback callback; 78 | void* userinfo; 79 | }; 80 | 81 | struct afc_connection 82 | { 83 | unsigned int handle; /* 0 */ 84 | unsigned int unknown0; /* 4 */ 85 | unsigned char unknown1; /* 8 */ 86 | unsigned char padding[3]; /* 9 */ 87 | unsigned int unknown2; /* 12 */ 88 | unsigned int unknown3; /* 16 */ 89 | unsigned int unknown4; /* 20 */ 90 | unsigned int fs_block_size; /* 24 */ 91 | unsigned int sock_block_size; /* 28: always 0x3c */ 92 | unsigned int io_timeout; /* 32: from AFCConnectionOpen, usu. 0 */ 93 | void* afc_lock; /* 36 */ 94 | unsigned int context; /* 40 */ 95 | }; 96 | 97 | /* ---------------------------------------------------------------------------- 98 | * Public routines 99 | * ------------------------------------------------------------------------- */ 100 | 101 | /* Registers a notification with the current run loop. The callback gets 102 | * copied into the notification struct, as well as being registered with the 103 | * current run loop. dn_unknown3 gets copied into unknown3 in the same. 104 | * (Maybe dn_unknown3 is a user info parameter that gets passed as an arg to 105 | * the callback?) unused0 and unused1 are both 0 when iTunes calls this. 106 | * In iTunes the callback is located from $3db78e-$3dbbaf. 107 | * 108 | * Returns: 109 | * MDERR_OK if successful 110 | * MDERR_SYSCALL if CFRunLoopAddSource() failed 111 | * MDERR_OUT_OF_MEMORY if we ran out of memory 112 | */ 113 | 114 | extern mach_error_t AMDeviceNotificationSubscribe(am_device_notification_callback 115 | callback, unsigned int unused0, unsigned int unused1, void* 116 | userinfo, struct am_device_notification **notification); 117 | 118 | extern mach_error_t AMDeviceNotificationUnsubscribe(struct am_device_notification *notification); 119 | 120 | /* Connects to the iPhone. Pass in the am_device structure that the 121 | * notification callback will give to you. 122 | * 123 | * Returns: 124 | * MDERR_OK if successfully connected 125 | * MDERR_SYSCALL if setsockopt() failed 126 | * MDERR_QUERY_FAILED if the daemon query failed 127 | * MDERR_INVALID_ARGUMENT if USBMuxConnectByPort returned 0xffffffff 128 | */ 129 | 130 | extern mach_error_t AMDeviceConnect(struct am_device *device); 131 | extern mach_error_t AMDeviceDisconnect(struct am_device *device); 132 | 133 | /* Calls PairingRecordPath() on the given device, than tests whether the path 134 | * which that function returns exists. During the initial connect, the path 135 | * returned by that function is '/', and so this returns 1. 136 | * 137 | * Returns: 138 | * 0 if the path did not exist 139 | * 1 if it did 140 | */ 141 | 142 | extern mach_error_t AMDevicePair(struct am_device *device); 143 | extern mach_error_t AMDeviceUnpair(struct am_device *device); 144 | extern int AMDeviceIsPaired(struct am_device *device); 145 | 146 | /* iTunes calls this function immediately after testing whether the device is 147 | * paired. It creates a pairing file and establishes a Lockdown connection. 148 | * 149 | * Returns: 150 | * MDERR_OK if successful 151 | * MDERR_INVALID_ARGUMENT if the supplied device is null 152 | * MDERR_DICT_NOT_LOADED if the load_dict() call failed 153 | */ 154 | 155 | extern mach_error_t AMDeviceValidatePairing(struct am_device *device); 156 | extern CFStringRef AMDeviceCopyValue(struct am_device* device, unsigned int unused, CFStringRef value); 157 | 158 | /* Creates a Lockdown session and adjusts the device structure appropriately 159 | * to indicate that the session has been started. iTunes calls this function 160 | * after validating pairing. 161 | * 162 | * Returns: 163 | * MDERR_OK if successful 164 | * MDERR_INVALID_ARGUMENT if the Lockdown conn has not been established 165 | * MDERR_DICT_NOT_LOADED if the load_dict() call failed 166 | */ 167 | 168 | extern mach_error_t AMDeviceStartSession(struct am_device *device); 169 | 170 | /* Starts a service and returns a handle that can be used in order to further 171 | * access the service. You should stop the session and disconnect before using 172 | * the service. iTunes calls this function after starting a session. It starts 173 | * the service and the SSL connection. unknown may safely be 174 | * NULL (it is when iTunes calls this), but if it is not, then it will be 175 | * filled upon function exit. service_name should be one of the AMSVC_* 176 | * constants. If the service is AFC (AMSVC_AFC), then the handle is the handle 177 | * that will be used for further AFC* calls. 178 | * 179 | * Returns: 180 | * MDERR_OK if successful 181 | * MDERR_SYSCALL if the setsockopt() call failed 182 | * MDERR_INVALID_ARGUMENT if the Lockdown conn has not been established 183 | */ 184 | 185 | extern mach_error_t AMDeviceStartService(struct am_device* device, CFStringRef 186 | service_name, int* handle, void* unknown); 187 | 188 | /* Stops a session. You should do this before accessing services. 189 | * 190 | * Returns: 191 | * MDERR_OK if successful 192 | * MDERR_INVALID_ARGUMENT if the Lockdown conn has not been established 193 | */ 194 | 195 | extern mach_error_t AMDeviceStopSession(struct am_device* device); 196 | 197 | /* Opens an Apple File Connection. You must start the appropriate service 198 | * first with AMDeviceStartService(). In iTunes, io_timeout is 0. 199 | * 200 | * Returns: 201 | * MDERR_OK if successful 202 | * MDERR_AFC_OUT_OF_MEMORY if malloc() failed 203 | */ 204 | 205 | extern afc_error_t AFCConnectionOpen(int handle, unsigned int io_timeout, struct afc_connection** conn); 206 | 207 | /* Closes the given AFC connection. */ 208 | extern afc_error_t AFCConnectionClose(struct afc_connection* conn); 209 | 210 | /* Pass in a pointer to an afc_device_info structure. It will be filled. */ 211 | extern afc_error_t AFCDeviceInfoOpen(struct afc_connection* conn, void** iter); 212 | extern afc_error_t AFCFileInfoOpen(struct afc_connection* conn, const char* path, void** iter); 213 | extern afc_error_t AFCKeyValueRead(void* iter, char** key, char** val); 214 | extern afc_error_t AFCKeyValueClose(void* iter); 215 | 216 | /* Opens a directory on the iPhone. Pass in a pointer in dir to be filled in. 217 | * Note that this normally only accesses the iTunes sandbox/partition as the 218 | * root, which is /var/root/Media. Pathnames are specified with '/' delimiters 219 | * as in Unix style. 220 | * 221 | * Returns: 222 | * MDERR_OK if successful 223 | */ 224 | 225 | extern afc_error_t AFCDirectoryOpen(struct afc_connection* conn, const char* path, void** iter); 226 | 227 | /* Acquires the next entry in a directory previously opened with 228 | * AFCDirectoryOpen(). When dirent is filled with a NULL value, then the end 229 | * of the directory has been reached. '.' and '..' will be returned as the 230 | * first two entries in each directory except the root; you may want to skip 231 | * over them. 232 | * 233 | * Returns: 234 | * MDERR_OK if successful, even if no entries remain 235 | */ 236 | 237 | extern afc_error_t AFCDirectoryRead(struct afc_connection* conn, void* iter, char** val); 238 | extern afc_error_t AFCDirectoryClose(struct afc_connection* conn, void* iter); 239 | extern afc_error_t AFCDirectoryCreate(struct afc_connection* conn, const char* dirname); 240 | extern afc_error_t AFCRemovePath(struct afc_connection* conn, const char* dirname); 241 | extern afc_error_t AFCRenamePath(struct afc_connection* conn, const char* oldpath, const char* newpath); 242 | extern afc_error_t AFCLinkPath(struct afc_connection* conn, unsigned long long type, const char* oldpath, const char* newpath) WEAK_IMPORT_ATTRIBUTE; 243 | 244 | /* mode 2 = read, mode 3 = write; unknown = 0 */ 245 | extern afc_error_t AFCFileRefOpen(struct afc_connection* conn, const char* path, unsigned long long mode, unsigned long long* fd); 246 | extern afc_error_t AFCFileRefRead(struct afc_connection* conn, unsigned long long fd, void* buf, unsigned int* len); 247 | extern afc_error_t AFCFileRefWrite(struct afc_connection* conn, unsigned long long fd, const void* buf, unsigned int len); 248 | extern afc_error_t AFCFileRefClose(struct afc_connection* conn, unsigned long long fd); 249 | extern afc_error_t AFCFileRefLock(struct afc_connection* conn, unsigned long long fd); 250 | extern afc_error_t AFCFileRefUnlock(struct afc_connection* conn, unsigned long long fd); 251 | 252 | extern mach_error_t AMDPostNotification(int handle, CFStringRef notification, void* userinfo); 253 | extern mach_error_t AMDShutdownNotificationProxy(int handle); 254 | 255 | #ifdef __cplusplus 256 | } 257 | #endif -------------------------------------------------------------------------------- /Pusher.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #import "CommonConstants.h" 4 | #import "DrawAdditions.h" 5 | #import "ArrayAdditions.h" 6 | #import "StringAdditions.h" 7 | #import "WorkspaceAdditions.h" 8 | #import "SupportClasses.h" 9 | 10 | #import "FloatingWindow.h" 11 | #import "PushButton.h" 12 | #import "InstanceManager.h" 13 | #endif 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pusher Exploit 2 | 3 | Exploit for iPhone OS 2.X by iPhone Dev Team & Ripdev member Wizdaz 4 | 5 | ### Credits 6 | 7 | Project: Pusher 8 | 9 | Author: Alexander Maksimenko (Wizdaz) 10 | 11 | Copyright: Copyright (c) 2009 Ripdev. All rights reserved. 12 | 13 | https://ripdev.org 14 | 15 | ### What is this? 16 | 17 | The Exploit is part of Pusher, a jailbreak for iPhoneOS 2.x developed by Ripdev. 18 | This exploit, or a variant of it was used in other more familair jailbreak tools at the time, such as Pwnagetool. 19 | Some parts of the jailbreak itself are also included. In the future, the entire jailbreak will likey be open sourced, including the interface code. For the moment though, enjoy this =) 20 | 21 | ### Why open source it now? 22 | 23 | Open sourced for purposes of educating & aiding development of new jailbreaks for legacy iOS versions. 24 | 25 | More projects will be open sourced soon, stay tuned! 26 | 27 | 28 | До скорой встречи ;) 29 | -------------------------------------------------------------------------------- /RamdiskBuilder.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header RamdiskBuilder.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #import "WorkerThread.h" 9 | #import "SecureTask.h" 10 | 11 | @class Firmware, InstallerPackageManager, InstallerPackageBundle, CustomPackageManager, CustomPackageBundle, CydiaPackageBundle; 12 | 13 | @interface RamdiskBuilder : WorkerThread 14 | { 15 | Firmware* _firmware; 16 | SecureTask* _secureTask; 17 | 18 | BOOL _abortBuilding; 19 | } 20 | 21 | -(BOOL) buildRamdisk; 22 | -(BOOL) patchFirmware; 23 | -(BOOL) copyRamdisk; 24 | -(BOOL) rebuildRamdisk; 25 | 26 | -(BOOL) actionPatch:(NSString*) file :(NSString*) patch; 27 | -(BOOL) actionAdd:(NSString*) file :(NSString*) path; 28 | -(BOOL) actionReplaceKernel:(NSString*) file :(NSString*) path; 29 | -(BOOL) actionSetOwner:(NSString*) file :(NSString*) owner; 30 | -(BOOL) actionSetPermission:(NSString*) file :(NSString*) permission; 31 | -(BOOL) actionRunScript:(NSString*) file :(NSString*) path; 32 | 33 | -(NSString*) safePath:(NSString*) string; 34 | 35 | @end -------------------------------------------------------------------------------- /RamdiskBuilder.m: -------------------------------------------------------------------------------- 1 | /*! 2 | @source RamdiskBuilder.m 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #import "RootFSDecrypt.h" 9 | #import "Firmware.h" 10 | #import "OpenSSLHelper.h" 11 | #import "RamdiskBuilder.h" 12 | 13 | @implementation RamdiskBuilder 14 | 15 | -(id) init 16 | { 17 | self = [super init]; 18 | 19 | _firmware = nil; 20 | _secureTask = [[SecureTask alloc] init]; 21 | 22 | return self; 23 | } 24 | 25 | -(void) dealloc 26 | { 27 | [_firmware release]; 28 | [_secureTask release]; 29 | 30 | [super dealloc]; 31 | } 32 | 33 | -(void) threadTask:(NSDictionary*) dict 34 | { 35 | _abortBuilding = NO; 36 | 37 | [self sendMessage:BuilderStatusMessage withData:[NSArchiver archivedDataWithRootObject:[NSNumber numberWithInt:BSStart]]]; 38 | 39 | if([[InstanceManager firmware] unzipTo:SystemTempDir] && [self buildRamdisk]) 40 | [self sendMessage:BuilderStatusMessage withData:[NSArchiver archivedDataWithRootObject:[NSNumber numberWithInt:BSSuccess]]]; 41 | else 42 | [self sendMessage:BuilderStatusMessage withData:[NSArchiver archivedDataWithRootObject:[NSNumber numberWithInt:BSFailed]]]; 43 | } 44 | 45 | -(BOOL) buildRamdisk 46 | { 47 | if(![self patchFirmware] || _abortBuilding) 48 | return NO; 49 | 50 | if(![self copyRamdisk] || _abortBuilding) 51 | return NO; 52 | 53 | return YES; 54 | } 55 | 56 | -(BOOL) copyRamdisk 57 | { 58 | // Copy ramdisk 59 | 60 | NSFileManager* fileManager = [NSFileManager defaultManager]; 61 | 62 | NSString* ramdisk = [SystemTempDir stringByAppendingPathComponent:[[InstanceManager firmware] restoreRamdiskFile]]; 63 | NSString* ramdiskResource = [InstanceManager ramdiskPath]; 64 | 65 | [fileManager removeFileAtPath:ramdisk handler:nil]; 66 | 67 | if(![fileManager copyPath:ramdiskResource toPath:ramdisk handler:nil]) 68 | { 69 | Log(@"Failed to copy pusher ramdisk to temp location"); 70 | return NO; 71 | } 72 | 73 | [OpenSSLHelper updateFile:ramdisk with:Decrypt]; 74 | 75 | return YES; 76 | } 77 | 78 | -(BOOL) rebuildRamdisk 79 | { 80 | // Copy ramdisk 81 | 82 | NSFileManager* fileManager = [NSFileManager defaultManager]; 83 | 84 | NSString* ramdisk = [SystemTempDir stringByAppendingPathComponent:CustomRamdisk]; 85 | NSString* ramdiskResource = [InstanceManager ramdiskPath]; 86 | 87 | if(![fileManager copyPath:ramdiskResource toPath:ramdisk handler:nil]) 88 | { 89 | Log(@"Failed to copy pusher ramdisk to temp location"); 90 | return NO; 91 | } 92 | 93 | if(![[InstanceManager firmware] makeRamdisk:rtRestore from:ramdisk encrypt:NO]) 94 | { 95 | Log(@"Failed to inject pusher ramdisk to restore ramdisk"); 96 | return NO; 97 | } 98 | 99 | if(![fileManager removeFileAtPath:ramdisk handler:nil]) 100 | { 101 | Log(@"Failed to remove temp copy of pusher ramdisk"); 102 | return NO; 103 | } 104 | 105 | return YES; 106 | } 107 | 108 | -(BOOL) patchFirmware 109 | { 110 | NSDictionary* patches = [[InstanceManager firmware] firmwarePatches]; 111 | NSArray* keys = [patches allKeys]; 112 | unsigned int keysCount = [keys count]; 113 | unsigned int i; 114 | 115 | for(i = 0;i < keysCount;i++) 116 | { 117 | NSString* module = [keys objectAtIndex:i]; 118 | 119 | if([module isEqualToString:FWWTF2Key] || [module isEqualToString:FWIBSSKey] || [module isEqualToString:FWKernelCacheKey]) 120 | { 121 | if([[patches objectForKey:module] objectForKey:PatchKey] != nil) 122 | { 123 | NSDictionary* dict = [patches objectForKey:module]; 124 | int type = [[dict objectForKey:TypeFlagKey] intValue]; 125 | NSString* file = [SystemTempDir stringByAppendingPathComponent:[dict objectForKey:FileKey]]; 126 | NSString* patch = [[InstanceManager firmware] bundlePath]; 127 | NSString* key = [dict objectForKey:KeyKey]; 128 | NSString* iv = [dict objectForKey:IVKey]; 129 | BOOL exploit = NO; 130 | 131 | if([module isEqualToString:FWWTF2Key]) 132 | exploit = YES; 133 | 134 | patch = [patch stringByAppendingPathComponent:[dict objectForKey:PatchKey]]; 135 | 136 | if(![[InstanceManager firmware] patchFirmwareModule:file ofType:type withPatch:patch key:key iv:iv exploit:exploit]) 137 | { 138 | Log(@"Failed to patch %@", file); 139 | return NO; 140 | } 141 | } 142 | } 143 | } 144 | 145 | if(![[InstanceManager firmware] makeBootLogo:[[NSBundle mainBundle] pathForResource:@"logo" ofType:@"png"]]) 146 | { 147 | Log(@"Failed to make boot logo"); 148 | return NO; 149 | } 150 | 151 | return YES; 152 | } 153 | 154 | -(BOOL) actionPatch:(NSString*) file :(NSString*) patch 155 | { 156 | char* args[5] = {"/usr/bin/bspatch", (char*)[[self safePath:file] UTF8String], (char*)[[self safePath:file] UTF8String], (char*)[[self safePath:patch] UTF8String], NULL}; 157 | 158 | // Log(@"patch %@ with %@", [self safePath:file], [self safePath:patch]); 159 | 160 | if(![_secureTask runTaskWithArgs:args]) 161 | return NO; 162 | 163 | return YES; 164 | } 165 | 166 | -(BOOL) actionAdd:(NSString*) file :(NSString*) path 167 | { 168 | BOOL isDir = NO; 169 | 170 | char* args[4] = {"/bin/mkdir", "-p", (char*)[[self safePath:[path stringByDeletingLastPathComponent]] UTF8String], NULL}; 171 | 172 | // Log(@"mkdir %@", [self safePath:[path stringByDeletingLastPathComponent]]); 173 | 174 | if(![_secureTask runTaskWithArgs:args]) 175 | return NO; 176 | 177 | [[NSFileManager defaultManager] fileExistsAtPath:file isDirectory:&isDir]; 178 | 179 | char* args2[5] = {"/bin/cp", isDir ? "-vfR" : "-vf", (char*)[[self safePath:file] UTF8String], (char*)[[self safePath:path] UTF8String], NULL}; 180 | 181 | // Log(@"cp %@ to %@", [self safePath:file], [self safePath:path]); 182 | 183 | if(![_secureTask runTaskWithArgs:args2]) 184 | return NO; 185 | 186 | if([[_secureTask output] rangeOfString:NoSpaceLeftString].length > 0) 187 | { 188 | Log(@"No free space left"); 189 | return NO; 190 | } 191 | 192 | return YES; 193 | } 194 | 195 | -(BOOL) actionReplaceKernel:(NSString*) file :(NSString*) path 196 | { 197 | char* args[5] = {"/bin/cp", "-vf", (char*)[[self safePath:file] UTF8String], (char*)[[self safePath:path] UTF8String], NULL}; 198 | 199 | // Log(@"cp %@ to %@", [self safePath:file], [self safePath:path]); 200 | 201 | if(![_secureTask runTaskWithArgs:args]) 202 | return NO; 203 | 204 | return YES; 205 | } 206 | 207 | -(BOOL) actionSetOwner:(NSString*) file :(NSString*) owner 208 | { 209 | BOOL isDir = NO; 210 | [[NSFileManager defaultManager] fileExistsAtPath:file isDirectory:&isDir]; 211 | 212 | char* args[5] = {"/usr/sbin/chown", "-v", (char*)[owner UTF8String], (char*)[[self safePath:file] UTF8String], NULL}; 213 | 214 | // Log(@"chown %@", [self safePath:file]); 215 | 216 | if(![_secureTask runTaskWithArgs:args]) 217 | return NO; 218 | 219 | return YES; 220 | } 221 | 222 | -(BOOL) actionSetPermission:(NSString*) file :(NSString*) permission 223 | { 224 | BOOL isDir = NO; 225 | [[NSFileManager defaultManager] fileExistsAtPath:file isDirectory:&isDir]; 226 | 227 | char* args[5] = {"/bin/chmod", "-v", (char*)[permission UTF8String], (char*)[[self safePath:file] UTF8String], NULL}; 228 | 229 | if(![_secureTask runTaskWithArgs:args]) 230 | return NO; 231 | 232 | return YES; 233 | } 234 | 235 | -(BOOL) actionRunScript:(NSString*) file :(NSString*) path 236 | { 237 | char* args[4] = {"/bin/sh", (char*)[[self safePath:file] UTF8String], (char*)[[self safePath:path] UTF8String], NULL}; 238 | 239 | if(![_secureTask runTaskWithArgs:args]) 240 | return NO; 241 | 242 | return YES; 243 | } 244 | 245 | -(NSString*) safePath:(NSString*) string 246 | { 247 | return [NSString stringWithFormat:@"\"%@\"", string]; 248 | } 249 | 250 | -(void) handlePortMessage:(NSPortMessage*) portMessage 251 | { 252 | unsigned int message = [portMessage msgid]; 253 | 254 | if(message == BuilderStopMessage) 255 | _abortBuilding = YES; 256 | } 257 | 258 | @end -------------------------------------------------------------------------------- /RootFSDecrypt.c: -------------------------------------------------------------------------------- 1 | /*! 2 | @source RootFSDecrypt.m 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | typedef struct 18 | { 19 | unsigned char sig[8]; 20 | uint32_t version; 21 | uint32_t enc_iv_size; 22 | uint32_t unk1; 23 | uint32_t unk2; 24 | uint32_t unk3; 25 | uint32_t unk4; 26 | uint32_t unk5; 27 | unsigned char uuid[16]; 28 | uint32_t blocksize; 29 | uint64_t datasize; 30 | uint64_t dataoffset; 31 | uint8_t filler1[0x260]; 32 | uint32_t kdf_algorithm; 33 | uint32_t kdf_prng_algorithm; 34 | uint32_t kdf_iteration_count; 35 | uint32_t kdf_salt_len; /* in bytes */ 36 | uint8_t kdf_salt[32]; 37 | uint32_t blob_enc_iv_size; 38 | uint8_t blob_enc_iv[32]; 39 | uint32_t blob_enc_key_bits; 40 | uint32_t blob_enc_algorithm; 41 | uint32_t blob_enc_padding; 42 | uint32_t blob_enc_mode; 43 | uint32_t encrypted_keyblob_size; 44 | uint8_t encrypted_keyblob[0x30]; 45 | } cencrypted_v2_pwheader; 46 | 47 | uint32_t fs_swap32(uint32_t x) 48 | { 49 | x = (x>>24) | 50 | ((x<<8) & 0x00FF0000) | 51 | ((x>>8) & 0x0000FF00) | 52 | (x<<24); 53 | 54 | return x; 55 | } 56 | 57 | uint32_t fs_endian_swap32(uint32_t x) 58 | { 59 | #ifdef __i386__ 60 | 61 | x = fs_swap32(x); 62 | 63 | #endif 64 | 65 | return x; 66 | } 67 | 68 | uint64_t fs_endian_swap64(uint64_t x) 69 | { 70 | #ifdef __i386__ 71 | 72 | x = ((uint64_t) fs_endian_swap32((uint32_t)(x >> 32))) | (((uint64_t) fs_endian_swap32((uint32_t) (x & 0xFFFFFFFF))) << 32); 73 | 74 | #endif 75 | 76 | return x; 77 | } 78 | 79 | void adjust_v2_header_byteorder(cencrypted_v2_pwheader *pwhdr) 80 | { 81 | pwhdr->blocksize = fs_endian_swap32(pwhdr->blocksize); 82 | pwhdr->datasize = fs_endian_swap64(pwhdr->datasize); 83 | pwhdr->dataoffset = fs_endian_swap64(pwhdr->dataoffset); 84 | pwhdr->kdf_algorithm = fs_endian_swap32(pwhdr->kdf_algorithm); 85 | pwhdr->kdf_prng_algorithm = fs_endian_swap32(pwhdr->kdf_prng_algorithm); 86 | pwhdr->kdf_iteration_count = fs_endian_swap32(pwhdr->kdf_iteration_count); 87 | pwhdr->kdf_salt_len = fs_endian_swap32(pwhdr->kdf_salt_len); 88 | pwhdr->blob_enc_iv_size = fs_endian_swap32(pwhdr->blob_enc_iv_size); 89 | pwhdr->blob_enc_key_bits = fs_endian_swap32(pwhdr->blob_enc_key_bits); 90 | pwhdr->blob_enc_algorithm = fs_endian_swap32(pwhdr->blob_enc_algorithm); 91 | pwhdr->blob_enc_padding = fs_endian_swap32(pwhdr->blob_enc_padding); 92 | pwhdr->blob_enc_mode = fs_endian_swap32(pwhdr->blob_enc_mode); 93 | pwhdr->encrypted_keyblob_size = fs_endian_swap32(pwhdr->encrypted_keyblob_size); 94 | } 95 | 96 | void convert_hex(const char *str, uint8_t *bytes, int len) 97 | { 98 | int rpos, wpos = 0; 99 | 100 | for(rpos = 0; rpos < len; rpos++) 101 | sscanf(&str[rpos*2], "%02hhx", &bytes[wpos++]); 102 | } 103 | 104 | HMAC_CTX hmacsha1_ctx; 105 | AES_KEY aes_decrypt_key; 106 | uint32_t CHUNK_SIZE = 4096; 107 | 108 | void dump_hex(uint8_t *buf, uint8_t size) 109 | { 110 | int i = 0; 111 | 112 | for(i = 0;i < size;i++) 113 | printf("%02X",buf[i]); 114 | 115 | printf("\n"); 116 | } 117 | 118 | void compute_iv(uint32_t chunk_no, uint8_t *iv) 119 | { 120 | unsigned char mdResult[SHA_DIGEST_LENGTH]; 121 | unsigned int mdLen; 122 | 123 | chunk_no = ntohl(chunk_no); 124 | HMAC_Init_ex(&hmacsha1_ctx, NULL, 0, NULL, NULL); 125 | HMAC_Update(&hmacsha1_ctx, (unsigned char *)&chunk_no, sizeof(uint32_t)); 126 | HMAC_Final(&hmacsha1_ctx, mdResult, &mdLen); 127 | memcpy(iv, mdResult, AES_BLOCK_SIZE); 128 | } 129 | 130 | void decrypt_chunk(uint8_t *ctext, uint8_t *ptext, uint32_t chunk_no) 131 | { 132 | uint8_t iv[AES_BLOCK_SIZE]; 133 | 134 | compute_iv(chunk_no, iv); 135 | AES_cbc_encrypt(ctext, ptext, CHUNK_SIZE, &aes_decrypt_key, iv, AES_DECRYPT); 136 | } 137 | 138 | int decryptRootFS(const char* key, const char* filename, const char* output) 139 | { 140 | FILE *in, *out; 141 | cencrypted_v2_pwheader v2header; 142 | 143 | uint8_t hmacsha1_key[SHA_DIGEST_LENGTH], aes_key[AES_BLOCK_SIZE], *inbuf, *outbuf; 144 | uint32_t chunk_no; 145 | 146 | convert_hex(key, aes_key, AES_BLOCK_SIZE); 147 | convert_hex(key + 2 * AES_BLOCK_SIZE, hmacsha1_key, SHA_DIGEST_LENGTH); 148 | 149 | if ((in = fopen(filename, "rb")) == NULL) 150 | { 151 | fprintf(stderr, "Error: unable to open %s\n", filename); 152 | return -1; 153 | } 154 | 155 | if ((out = fopen(output, "wb")) == NULL) 156 | { 157 | fprintf(stderr, "Error: unable to open %s\n", output); 158 | return -1; 159 | } 160 | 161 | fseek(in, 0L, SEEK_SET); 162 | if (fread(&v2header, sizeof(cencrypted_v2_pwheader), 1, in) < 1) 163 | { 164 | fprintf(stderr, "RootFS header corrupted\n"); 165 | return -1; 166 | } 167 | 168 | adjust_v2_header_byteorder(&v2header); 169 | CHUNK_SIZE = v2header.blocksize; 170 | 171 | HMAC_CTX_init(&hmacsha1_ctx); 172 | HMAC_Init_ex(&hmacsha1_ctx, hmacsha1_key, sizeof(hmacsha1_key), EVP_sha1(), NULL); 173 | AES_set_decrypt_key(aes_key, AES_BLOCK_SIZE * 8, &aes_decrypt_key); 174 | 175 | fseek(in, (uint32_t)v2header.dataoffset, SEEK_SET); 176 | 177 | inbuf = (uint8_t*)malloc(CHUNK_SIZE); 178 | outbuf = (uint8_t*)malloc(CHUNK_SIZE); 179 | 180 | chunk_no = 0; 181 | while(fread(inbuf, CHUNK_SIZE, 1, in) > 0) 182 | { 183 | decrypt_chunk(inbuf, outbuf, chunk_no); 184 | chunk_no++; 185 | if(((uint32_t)v2header.datasize - ftell(out)) < CHUNK_SIZE) 186 | { 187 | fwrite(outbuf, (uint32_t)v2header.datasize - ftell(out), 1, out); 188 | break; 189 | } 190 | fwrite(outbuf, CHUNK_SIZE, 1, out); 191 | } 192 | 193 | free(inbuf); 194 | free(outbuf); 195 | 196 | fclose(in); 197 | fclose(out); 198 | 199 | return 0; 200 | } 201 | -------------------------------------------------------------------------------- /RootFSDecrypt.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header RootFSDecrypt.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | void convert_hex(const char *str, uint8_t *bytes, int len); 9 | int decryptRootFS(const char* key, const char* filename, const char* output); -------------------------------------------------------------------------------- /SecureTask.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header SecureTask.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | @interface SecureTask : NSObject 12 | { 13 | AuthorizationRef authorizationRef; 14 | NSMutableString* _output; 15 | NSString* _helperPath; 16 | } 17 | 18 | -(BOOL) isAuthenticated:(NSString*) task; 19 | -(BOOL) authenticate:(NSString*) task; 20 | -(void) deauthenticate; 21 | 22 | -(BOOL) runTaskWithArgs:(char * const *) args; 23 | -(void) drainOutput:(FILE*) file; 24 | -(int) readPid:(FILE*) file; 25 | -(NSString*) output; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Support/8900Parser.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header 8900Parser.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | struct h8900 9 | { 10 | unsigned int magic; 11 | unsigned char version[3]; 12 | unsigned char encrypted; 13 | unsigned int u; 14 | unsigned int dataSize; 15 | unsigned int sigOffset; 16 | unsigned int certOffset; 17 | unsigned int certSize; 18 | unsigned char sig1[32]; 19 | unsigned int epoch; 20 | unsigned char sig2[16]; 21 | unsigned char unknown3[1968]; 22 | }; 23 | 24 | struct f8900 25 | { 26 | unsigned char sig[0x80]; 27 | unsigned char cert[0xc0a]; 28 | }; 29 | 30 | struct hKernel 31 | { 32 | unsigned int magic; 33 | unsigned int compress_type; 34 | unsigned int adler32; 35 | unsigned int uncompressed_size; 36 | unsigned int compressed_size; 37 | unsigned int reserved[11]; 38 | char platform_name[64]; 39 | char root_path[256]; 40 | unsigned char data[0]; 41 | }; 42 | 43 | struct hImg2 44 | { 45 | unsigned int magic; 46 | unsigned int name; 47 | unsigned int u1; 48 | unsigned int u2; 49 | unsigned int dataLenPadded; 50 | unsigned int dataLen; 51 | unsigned int u3; 52 | unsigned int u4; 53 | unsigned char sig1[64]; 54 | unsigned int u5; 55 | unsigned int crc; 56 | unsigned int u6; 57 | unsigned int u7; 58 | unsigned int srev; 59 | unsigned int u8; 60 | char text[872]; 61 | unsigned char sig2[32]; 62 | }; 63 | 64 | struct hBootIm 65 | { 66 | char magic[8]; 67 | unsigned int checksum; 68 | unsigned int comp; 69 | unsigned int type; 70 | unsigned short width; 71 | unsigned short height; 72 | unsigned int u[10]; 73 | }; 74 | 75 | typedef struct h8900 h8900; 76 | typedef struct f8900 f8900; 77 | typedef struct hKernel hKernel; 78 | typedef struct hImg2 hImg2; 79 | typedef struct hBootIm hBootIm; 80 | 81 | #define Encrypted8900 0x3 82 | 83 | #define IsImg2File 0x1 84 | #define IsBootImFile 0x2 85 | #define IsKernelFile 0x4 86 | #define IsPlainFile 0x8 87 | 88 | int parse8900(const char* filename, h8900* pHeader8900, f8900* pFooter8900, hKernel* pHeaderKernel, hImg2* pHeaderImg2, hBootIm* pHeaderBootIm, int* pFlags, int extract, const char* output); 89 | int extractFile(unsigned char* p, unsigned int size, hKernel* pHeaderKernel, hImg2* pHeaderImg2, hBootIm* pHeaderBootIm, int* pFlags, const char* filename); 90 | 91 | int doKernelFile(const char* filename, h8900* pHeader8900, f8900* pFooter8900, hKernel* pHeaderKernel, const char* output); 92 | int doPlainFile(const char* filename, h8900* pHeader8900, f8900* pFooter8900, const char* output, int exploit); 93 | int doImg2File(const char* filename, h8900* pHeader8900, f8900* pFooter8900, hImg2* pHeaderImg2, const char* output); 94 | int doBootImFile(const char* filename, h8900* pHeader8900, f8900* pFooter8900, hImg2* pHeaderImg2, hBootIm* pHeaderBootIm, const char* output); 95 | 96 | unsigned char* read_png(FILE *fp, unsigned int *width, unsigned int *height, unsigned int *gray); 97 | int check_png(const char* filename); 98 | 99 | void resignHeader8900(h8900* pHeader8900); 100 | unsigned int swap32(unsigned int x); 101 | unsigned short swap16(unsigned short x); 102 | unsigned int endian_swap(unsigned int x); 103 | unsigned short endian_swap16(unsigned short x); 104 | 105 | -------------------------------------------------------------------------------- /Support/AppleCRC32.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "8900Parser.h" 3 | #include "AppleCRC32.h" 4 | 5 | static unsigned int crc_table[256] = { 6 | 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 7 | 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, 8 | 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, 9 | 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, 10 | 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L, 11 | 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, 12 | 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, 13 | 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL, 14 | 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, 15 | 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL, 16 | 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, 17 | 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, 18 | 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L, 19 | 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, 20 | 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, 21 | 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L, 22 | 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, 23 | 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L, 24 | 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, 25 | 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, 26 | 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL, 27 | 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, 28 | 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L, 29 | 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL, 30 | 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, 31 | 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L, 32 | 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, 33 | 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, 34 | 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L, 35 | 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, 36 | 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, 37 | 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L, 38 | 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, 39 | 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL, 40 | 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, 41 | 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, 42 | 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL, 43 | 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, 44 | 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, 45 | 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L, 46 | 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, 47 | 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L, 48 | 0x68ddb3f8l, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, 49 | 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, 50 | 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L, 51 | 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, 52 | 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, 53 | 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L, 54 | 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, 55 | 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L, 56 | 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, 57 | 0x2d02ef8dL 58 | }; 59 | 60 | #define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8); 61 | #define DO2(buf) DO1(buf); DO1(buf); 62 | #define DO4(buf) DO2(buf); DO2(buf); 63 | #define DO8(buf) DO4(buf); DO4(buf); 64 | 65 | unsigned int AppleCRC32Checksum(unsigned int* ckSum, const unsigned char *buf, unsigned int len) 66 | { 67 | unsigned int crc; 68 | 69 | crc = *ckSum; 70 | 71 | if(buf == 0) 72 | return crc; 73 | 74 | while(len >= 8) 75 | { 76 | DO8(buf); 77 | len -= 8; 78 | } 79 | 80 | if(len) 81 | { 82 | do 83 | { 84 | DO1(buf); 85 | } 86 | while (--len); 87 | } 88 | 89 | crc = endian_swap(crc); 90 | 91 | *ckSum = crc; 92 | 93 | return crc; 94 | } 95 | -------------------------------------------------------------------------------- /Support/AppleCRC32.h: -------------------------------------------------------------------------------- 1 | unsigned int AppleCRC32Checksum(unsigned int* ckSum, const unsigned char *buf, unsigned int len); 2 | -------------------------------------------------------------------------------- /Support/Img3Parser.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header Img3Parser.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | struct hImg3 9 | { 10 | unsigned int magic; 11 | unsigned int size; 12 | unsigned int imageSize; 13 | unsigned int shshOffset; 14 | unsigned int name; 15 | }; 16 | 17 | struct hImg3Element 18 | { 19 | unsigned int magic; 20 | unsigned int size; 21 | unsigned int dataSize; 22 | }; 23 | 24 | typedef struct hImg3 hImg3; 25 | typedef struct hImg3Element hImg3Element; 26 | 27 | struct Img3Element 28 | { 29 | hImg3Element header; 30 | void* data; 31 | void* nextElement; 32 | }; 33 | 34 | typedef struct Img3Element Img3Element; 35 | 36 | int parseImg3(const char* filename, hImg3* pHeaderImg3, Img3Element* pElement, hKernel* pHeaderKernel, hBootIm* pHeaderBootIm, int* pFlags, int extract, const char* output, const char* key, const char* iv); 37 | int extractImg3File(Img3Element* pElement, hKernel* pHeaderKernel, hBootIm* pHeaderBootIm, int* pFlags, const char* filename, const char* key, const char* iv); 38 | int doImg3File(const char* filename, hImg3* pHeaderImg3, Img3Element* pElement, hKernel* pHeaderKernel, hBootIm* pHeaderBootIm, int* pFlags, const char* output, const char* key, const char* iv); 39 | Img3Element* getDataElement(Img3Element* pElement); 40 | unsigned int getElementsSize(Img3Element* pElement); 41 | unsigned int getSHSHOffset(Img3Element* pElement); 42 | void freeElements(Img3Element* pElement); 43 | 44 | void aes_decrypt(void* p, unsigned int size, const char* key, const char* iv); 45 | void aes_encrypt(void* p, unsigned int size, const char* key, const char* iv); 46 | -------------------------------------------------------------------------------- /Support/MobileDevice.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define ADNCI_MSG_CONNECTED 1 5 | #define ADNCI_MSG_DISCONNECTED 2 6 | #define ADNCI_MSG_UNKNOWN 3 7 | 8 | struct am_recovery_device; 9 | 10 | struct am_device_notification_callback_info 11 | { 12 | struct am_device *dev; /* 0 device */ 13 | unsigned int msg; /* 4 one of ADNCI_MSG_* */ 14 | } __attribute__ ((packed)); 15 | typedef struct am_device_notification_callback_info am_device_notification_callback_info; 16 | 17 | typedef void (*am_restore_device_notification_callback)(struct am_recovery_device *); 18 | 19 | struct am_recovery_device 20 | { 21 | void *unknown0; 22 | void *unknown1; 23 | am_restore_device_notification_callback callback; /* 8 */ 24 | void *user_info; /* 12 */ 25 | unsigned int unknown3[1]; /* 16 */ 26 | unsigned int readwrite_pipe; /* 28 */ 27 | unsigned int read_pipe; /* 32 */ 28 | unsigned int write_ctrl_pipe; /* 33 */ 29 | unsigned int read_unknown_pipe; /* 34 */ 30 | unsigned int write_file_pipe; /* 35 */ 31 | unsigned int write_input_pipe; /* 36 */ 32 | } __attribute__ ((packed)); 33 | typedef struct am_recovery_device am_recovery_device; 34 | 35 | typedef void(*am_device_notification_callback)(am_device_notification_callback_info *); 36 | 37 | struct am_device 38 | { 39 | unsigned char unknown0[16]; /* 0 - zero */ 40 | unsigned int device_id; /* 16 */ 41 | unsigned int product_id; /* 20 - set to AMD_IPHONE_PRODUCT_ID */ 42 | char *serial; /* 24 - set to AMD_IPHONE_SERIAL */ 43 | unsigned int unknown1; /* 28 */ 44 | unsigned char unknown2[4]; /* 32 */ 45 | unsigned int lockdown_conn; /* 36 */ 46 | unsigned char unknown3[8]; /* 40 */ 47 | } __attribute__ ((packed)); 48 | typedef struct am_device am_device; 49 | 50 | struct am_device_notification 51 | { 52 | unsigned int unknown0; /* 0 */ 53 | unsigned int unknown1; /* 4 */ 54 | unsigned int unknown2; /* 8 */ 55 | am_device_notification_callback callback; /* 12 */ 56 | unsigned int unknown3; /* 16 */ 57 | } __attribute__ ((packed)); 58 | typedef struct am_device_notification am_device_notification; 59 | 60 | mach_error_t AMDeviceNotificationSubscribe(am_device_notification_callback 61 | callback, unsigned int unused0, unsigned int unused1, unsigned int 62 | dn_unknown3, am_device_notification **notification); 63 | mach_error_t AMDeviceNotificationUnsubscribe(); 64 | unsigned int AMRestoreRegisterForDeviceNotifications( 65 | am_restore_device_notification_callback dfu_connect_callback, 66 | am_restore_device_notification_callback recovery_connect_callback, 67 | am_restore_device_notification_callback dfu_disconnect_callback, 68 | am_restore_device_notification_callback recovery_disconnect_callback, 69 | unsigned int unknown0, 70 | void *user_info); 71 | mach_error_t AMDeviceConnect(am_device *device); 72 | int AMDeviceIsPaired(am_device *device); 73 | mach_error_t AMDeviceValidatePairing(am_device *device); 74 | mach_error_t AMDeviceStartSession(am_device *device); 75 | mach_error_t AMDeviceEnterRecovery(am_device *device); 76 | 77 | -------------------------------------------------------------------------------- /Support/OpenSSLHelper.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header OpenSSLHelper.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | typedef enum 9 | { 10 | Decrypt = 0, 11 | Encrypt 12 | } AES_MODE; 13 | 14 | @interface OpenSSLHelper : NSObject 15 | 16 | +(NSString*) shaStringForData:(NSData*) data; 17 | +(NSString*) shaStringForBytes:(const void*) data withSize:(unsigned int) size; 18 | +(NSString*) shaStringForFile:(NSString*) file; 19 | 20 | +(NSString*) md5StringForData:(NSData*) data; 21 | +(NSString*) md5StringForBytes:(const void*) data withSize:(unsigned int) size; 22 | 23 | +(void*) updateFile:(NSString*) file with:(AES_MODE) mode; 24 | +(void) aesEncrypt:(void*) buf size:(int) size key:(void*) key iv:(void*) iv; 25 | +(void) aesDecrypt:(void*) buf size:(int) size key:(void*) key iv:(void*) iv; 26 | 27 | @end -------------------------------------------------------------------------------- /Support/OpenSSLHelper.m: -------------------------------------------------------------------------------- 1 | /*! 2 | @source OpenSSLHelper.m 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #import 9 | #import 10 | #import 11 | #import "OpenSSLHelper.h" 12 | 13 | #define DATA_READ_SIZE 1000000 14 | 15 | unsigned char update_key[AES_BLOCK_SIZE] = {0x42, 0x41, 0x53, 0x48, 0x5F, 0x56, 0x45, 0x52, 0x53, 0x49, 0x4F, 0x4E, 0x09, 0x31, 0x2E, 0x30}; 16 | 17 | @implementation OpenSSLHelper 18 | 19 | +(NSString*) shaStringForData:(NSData*) data 20 | { 21 | return [OpenSSLHelper shaStringForBytes:[data bytes] withSize:[data length]]; 22 | } 23 | 24 | +(NSString*) shaStringForBytes:(const void*) data withSize:(unsigned int) size 25 | { 26 | SHA_CTX sctx; 27 | 28 | unsigned int i = 0; 29 | unsigned char md[SHA_DIGEST_LENGTH] = {0}; 30 | 31 | SHA1_Init(&sctx); 32 | SHA1_Update(&sctx,data,size); 33 | SHA1_Final(&(md[0]),&sctx); 34 | 35 | NSMutableString* result = [[[NSMutableString alloc] init] autorelease]; 36 | 37 | for(;i < SHA_DIGEST_LENGTH;i++) 38 | [result appendFormat:@"%02X", md[i]]; 39 | 40 | return result; 41 | } 42 | 43 | +(NSString*) shaStringForFile:(NSString*) file 44 | { 45 | NSFileHandle* fh = [NSFileHandle fileHandleForReadingAtPath:file]; 46 | SHA_CTX sctx; 47 | 48 | unsigned int i = 0; 49 | unsigned char md[SHA_DIGEST_LENGTH] = {0}; 50 | 51 | SHA1_Init(&sctx); 52 | 53 | NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; 54 | NSData* data = [fh readDataOfLength:DATA_READ_SIZE]; 55 | 56 | while([data length] > 0) 57 | { 58 | SHA1_Update(&sctx,[data bytes],[data length]); 59 | 60 | [pool release]; 61 | pool = [[NSAutoreleasePool alloc] init]; 62 | 63 | data = [fh readDataOfLength:DATA_READ_SIZE]; 64 | } 65 | 66 | [pool release]; 67 | 68 | SHA1_Final(&(md[0]),&sctx); 69 | 70 | NSMutableString* result = [[[NSMutableString alloc] init] autorelease]; 71 | 72 | for(;i < SHA_DIGEST_LENGTH;i++) 73 | [result appendFormat:@"%02X", md[i]]; 74 | 75 | return result; 76 | } 77 | 78 | +(NSString*) md5StringForData:(NSData*) data 79 | { 80 | return [OpenSSLHelper md5StringForBytes:[data bytes] withSize:[data length]]; 81 | } 82 | 83 | +(NSString*) md5StringForBytes:(const void*) data withSize:(unsigned int) size 84 | { 85 | MD5_CTX sctx; 86 | 87 | unsigned int i = 0; 88 | unsigned char md[MD5_DIGEST_LENGTH] = {0}; 89 | 90 | MD5_Init(&sctx); 91 | MD5_Update(&sctx,data,size); 92 | MD5_Final(&(md[0]),&sctx); 93 | 94 | NSMutableString* result = [[[NSMutableString alloc] init] autorelease]; 95 | 96 | for(;i < MD5_DIGEST_LENGTH;i++) 97 | [result appendFormat:@"%02X", md[i]]; 98 | 99 | return result; 100 | } 101 | 102 | +(void*) updateFile:(NSString*) file with:(AES_MODE) mode 103 | { 104 | NSFileHandle* fh = [NSFileHandle fileHandleForUpdatingAtPath:file]; 105 | unsigned char iv[AES_BLOCK_SIZE] = {0}; 106 | unsigned long long pos = 0; 107 | 108 | NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; 109 | NSMutableData* data = [[[fh readDataOfLength:AES_BLOCK_SIZE * 32] mutableCopy] autorelease]; 110 | 111 | while([data length] > 0) 112 | { 113 | void* p = [data mutableBytes]; 114 | unsigned len = [data length]; 115 | 116 | if(mode) 117 | [OpenSSLHelper aesEncrypt:p size:len key:update_key iv:iv]; 118 | else 119 | [OpenSSLHelper aesDecrypt:p size:len key:update_key iv:iv]; 120 | 121 | [fh seekToFileOffset:pos]; 122 | [fh writeData:data]; 123 | 124 | pos += len; 125 | 126 | [pool release]; 127 | pool = [[NSAutoreleasePool alloc] init]; 128 | 129 | data = [[[fh readDataOfLength:AES_BLOCK_SIZE * 32] mutableCopy] autorelease]; 130 | } 131 | 132 | [pool release]; 133 | 134 | [fh closeFile]; 135 | 136 | return NULL; 137 | } 138 | 139 | +(void) aesEncrypt:(void*) buf size:(int) size key:(void*) key iv:(void*) iv 140 | { 141 | AES_KEY ectx; 142 | AES_set_encrypt_key( key, 128, &ectx ); 143 | AES_cbc_encrypt(buf, buf, size, &ectx, iv, AES_ENCRYPT ); 144 | } 145 | 146 | +(void) aesDecrypt:(void*) buf size:(int) size key:(void*) key iv:(void*) iv 147 | { 148 | AES_KEY dctx; 149 | AES_set_decrypt_key( key, 128, &dctx ); 150 | AES_cbc_encrypt(buf, buf, size, &dctx, iv, AES_DECRYPT ); 151 | } 152 | 153 | @end -------------------------------------------------------------------------------- /Support/compression.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "compression.h" 5 | 6 | #define __private_extern__ extern 7 | #define bzero(p, n) memset((void *)(p), 0, (n)) 8 | 9 | __private_extern__ u_int32_t 10 | local_adler32(u_int8_t *buffer, int32_t length) 11 | { 12 | int32_t cnt; 13 | u_int32_t result, lowHalf, highHalf; 14 | 15 | lowHalf = 1; 16 | highHalf = 0; 17 | 18 | for (cnt = 0; cnt < length; cnt++) { 19 | if ((cnt % 5000) == 0) { 20 | lowHalf %= 65521L; 21 | highHalf %= 65521L; 22 | } 23 | 24 | lowHalf += buffer[cnt]; 25 | highHalf += lowHalf; 26 | } 27 | 28 | lowHalf %= 65521L; 29 | highHalf %= 65521L; 30 | 31 | result = (highHalf << 16) | lowHalf; 32 | 33 | return result; 34 | } 35 | 36 | /************************************************************** 37 | LZSS.C -- A Data Compression Program 38 | *************************************************************** 39 | 4/6/1989 Haruhiko Okumura 40 | Use, distribute, and modify this program freely. 41 | Please send me your improved versions. 42 | PC-VAN SCIENCE 43 | NIFTY-Serve PAF01022 44 | CompuServe 74050,1022 45 | 46 | **************************************************************/ 47 | 48 | #define N 4096 /* size of ring buffer - must be power of 2 */ 49 | #define F 18 /* upper limit for match_length */ 50 | #define THRESHOLD 2 /* encode string into position and length 51 | if match_length is greater than this */ 52 | #define NIL N /* index for root of binary search trees */ 53 | 54 | struct encode_state { 55 | /* 56 | * left & right children & parent. These constitute binary search trees. 57 | */ 58 | int lchild[N + 1], rchild[N + 257], parent[N + 1]; 59 | 60 | /* ring buffer of size N, with extra F-1 bytes to aid string comparison */ 61 | u_int8_t text_buf[N + F - 1]; 62 | 63 | /* 64 | * match_length of longest match. 65 | * These are set by the insert_node() procedure. 66 | */ 67 | int match_position, match_length; 68 | }; 69 | 70 | 71 | __private_extern__ int 72 | decompress_lzss(u_int8_t *dst, u_int8_t *src, u_int32_t srclen) 73 | { 74 | /* ring buffer of size N, with extra F-1 bytes to aid string comparison */ 75 | u_int8_t text_buf[N + F - 1]; 76 | u_int8_t *dststart = dst; 77 | u_int8_t *srcend = src + srclen; 78 | int i, j, k, r, c; 79 | unsigned int flags; 80 | 81 | dst = dststart; 82 | srcend = src + srclen; 83 | for (i = 0; i < N - F; i++) 84 | text_buf[i] = ' '; 85 | r = N - F; 86 | flags = 0; 87 | for ( ; ; ) { 88 | if (((flags >>= 1) & 0x100) == 0) { 89 | if (src < srcend) c = *src++; else break; 90 | flags = c | 0xFF00; /* uses higher byte cleverly */ 91 | } /* to count eight */ 92 | if (flags & 1) { 93 | if (src < srcend) c = *src++; else break; 94 | *dst++ = c; 95 | text_buf[r++] = c; 96 | r &= (N - 1); 97 | } else { 98 | if (src < srcend) i = *src++; else break; 99 | if (src < srcend) j = *src++; else break; 100 | i |= ((j & 0xF0) << 4); 101 | j = (j & 0x0F) + THRESHOLD; 102 | for (k = 0; k <= j; k++) { 103 | c = text_buf[(i + k) & (N - 1)]; 104 | *dst++ = c; 105 | text_buf[r++] = c; 106 | r &= (N - 1); 107 | } 108 | } 109 | } 110 | 111 | return (int)(dst - dststart); 112 | } 113 | 114 | /* 115 | * initialize state, mostly the trees 116 | * 117 | * For i = 0 to N - 1, rchild[i] and lchild[i] will be the right and left 118 | * children of node i. These nodes need not be initialized. Also, parent[i] 119 | * is the parent of node i. These are initialized to NIL (= N), which stands 120 | * for 'not used.' For i = 0 to 255, rchild[N + i + 1] is the root of the 121 | * tree for strings that begin with character i. These are initialized to NIL. 122 | * Note there are 256 trees. */ 123 | static void init_state(struct encode_state *sp) 124 | { 125 | int i; 126 | 127 | bzero(sp, sizeof(*sp)); 128 | 129 | for (i = 0; i < N - F; i++) 130 | sp->text_buf[i] = ' '; 131 | for (i = N + 1; i <= N + 256; i++) 132 | sp->rchild[i] = NIL; 133 | for (i = 0; i < N; i++) 134 | sp->parent[i] = NIL; 135 | } 136 | 137 | /* 138 | * Inserts string of length F, text_buf[r..r+F-1], into one of the trees 139 | * (text_buf[r]'th tree) and returns the longest-match position and length 140 | * via the global variables match_position and match_length. 141 | * If match_length = F, then removes the old node in favor of the new one, 142 | * because the old one will be deleted sooner. Note r plays double role, 143 | * as tree node and position in buffer. 144 | */ 145 | static void insert_node(struct encode_state *sp, int r) 146 | { 147 | int i, p, cmp; 148 | u_int8_t *key; 149 | 150 | cmp = 1; 151 | key = &sp->text_buf[r]; 152 | p = N + 1 + key[0]; 153 | sp->rchild[r] = sp->lchild[r] = NIL; 154 | sp->match_length = 0; 155 | for ( ; ; ) { 156 | if (cmp >= 0) { 157 | if (sp->rchild[p] != NIL) 158 | p = sp->rchild[p]; 159 | else { 160 | sp->rchild[p] = r; 161 | sp->parent[r] = p; 162 | return; 163 | } 164 | } else { 165 | if (sp->lchild[p] != NIL) 166 | p = sp->lchild[p]; 167 | else { 168 | sp->lchild[p] = r; 169 | sp->parent[r] = p; 170 | return; 171 | } 172 | } 173 | for (i = 1; i < F; i++) { 174 | if ((cmp = key[i] - sp->text_buf[p + i]) != 0) 175 | break; 176 | } 177 | if (i > sp->match_length) { 178 | sp->match_position = p; 179 | if ((sp->match_length = i) >= F) 180 | break; 181 | } 182 | } 183 | sp->parent[r] = sp->parent[p]; 184 | sp->lchild[r] = sp->lchild[p]; 185 | sp->rchild[r] = sp->rchild[p]; 186 | sp->parent[sp->lchild[p]] = r; 187 | sp->parent[sp->rchild[p]] = r; 188 | if (sp->rchild[sp->parent[p]] == p) 189 | sp->rchild[sp->parent[p]] = r; 190 | else 191 | sp->lchild[sp->parent[p]] = r; 192 | sp->parent[p] = NIL; /* remove p */ 193 | } 194 | 195 | /* deletes node p from tree */ 196 | static void delete_node(struct encode_state *sp, int p) 197 | { 198 | int q; 199 | 200 | if (sp->parent[p] == NIL) 201 | return; /* not in tree */ 202 | if (sp->rchild[p] == NIL) 203 | q = sp->lchild[p]; 204 | else if (sp->lchild[p] == NIL) 205 | q = sp->rchild[p]; 206 | else { 207 | q = sp->lchild[p]; 208 | if (sp->rchild[q] != NIL) { 209 | do { 210 | q = sp->rchild[q]; 211 | } while (sp->rchild[q] != NIL); 212 | sp->rchild[sp->parent[q]] = sp->lchild[q]; 213 | sp->parent[sp->lchild[q]] = sp->parent[q]; 214 | sp->lchild[q] = sp->lchild[p]; 215 | sp->parent[sp->lchild[p]] = q; 216 | } 217 | sp->rchild[q] = sp->rchild[p]; 218 | sp->parent[sp->rchild[p]] = q; 219 | } 220 | sp->parent[q] = sp->parent[p]; 221 | if (sp->rchild[sp->parent[p]] == p) 222 | sp->rchild[sp->parent[p]] = q; 223 | else 224 | sp->lchild[sp->parent[p]] = q; 225 | sp->parent[p] = NIL; 226 | } 227 | 228 | __private_extern__ u_int8_t * 229 | compress_lzss(u_int8_t *dst, u_int32_t dstlen, u_int8_t *src, u_int32_t srcLen) 230 | { 231 | /* Encoding state, mostly tree but some current match stuff */ 232 | struct encode_state *sp; 233 | 234 | int i, c, len, r, s, last_match_length, code_buf_ptr; 235 | u_int8_t code_buf[17], mask; 236 | u_int8_t *srcend = src + srcLen; 237 | u_int8_t *dstend = dst + dstlen; 238 | 239 | /* initialize trees */ 240 | sp = (struct encode_state *) malloc(sizeof(*sp)); 241 | init_state(sp); 242 | 243 | /* 244 | * code_buf[1..16] saves eight units of code, and code_buf[0] works 245 | * as eight flags, "1" representing that the unit is an unencoded 246 | * letter (1 byte), "0" a position-and-length pair (2 bytes). 247 | * Thus, eight units require at most 16 bytes of code. 248 | */ 249 | code_buf[0] = 0; 250 | code_buf_ptr = mask = 1; 251 | 252 | /* Clear the buffer with any character that will appear often. */ 253 | s = 0; r = N - F; 254 | 255 | /* Read F bytes into the last F bytes of the buffer */ 256 | for (len = 0; len < F && src < srcend; len++) 257 | sp->text_buf[r + len] = *src++; 258 | if (!len) 259 | return 0; /* text of size zero */ 260 | 261 | /* 262 | * Insert the F strings, each of which begins with one or more 263 | * 'space' characters. Note the order in which these strings are 264 | * inserted. This way, degenerate trees will be less likely to occur. 265 | */ 266 | for (i = 1; i <= F; i++) 267 | insert_node(sp, r - i); 268 | 269 | /* 270 | * Finally, insert the whole string just read. 271 | * The global variables match_length and match_position are set. 272 | */ 273 | insert_node(sp, r); 274 | do { 275 | /* match_length may be spuriously long near the end of text. */ 276 | if (sp->match_length > len) 277 | sp->match_length = len; 278 | if (sp->match_length <= THRESHOLD) { 279 | sp->match_length = 1; /* Not long enough match. Send one byte. */ 280 | code_buf[0] |= mask; /* 'send one byte' flag */ 281 | code_buf[code_buf_ptr++] = sp->text_buf[r]; /* Send uncoded. */ 282 | } else { 283 | /* Send position and length pair. Note match_length > THRESHOLD. */ 284 | code_buf[code_buf_ptr++] = (u_int8_t) sp->match_position; 285 | code_buf[code_buf_ptr++] = (u_int8_t) 286 | ( ((sp->match_position >> 4) & 0xF0) 287 | | (sp->match_length - (THRESHOLD + 1)) ); 288 | } 289 | if ((mask <<= 1) == 0) { /* Shift mask left one bit. */ 290 | /* Send at most 8 units of code together */ 291 | for (i = 0; i < code_buf_ptr; i++) 292 | if (dst < dstend) 293 | *dst++ = code_buf[i]; 294 | else 295 | return 0; 296 | code_buf[0] = 0; 297 | code_buf_ptr = mask = 1; 298 | } 299 | last_match_length = sp->match_length; 300 | for (i = 0; i < last_match_length && src < srcend; i++) { 301 | delete_node(sp, s); /* Delete old strings and */ 302 | c = *src++; 303 | sp->text_buf[s] = c; /* read new bytes */ 304 | 305 | /* 306 | * If the position is near the end of buffer, extend the buffer 307 | * to make string comparison easier. 308 | */ 309 | if (s < F - 1) 310 | sp->text_buf[s + N] = c; 311 | 312 | /* Since this is a ring buffer, increment the position modulo N. */ 313 | s = (s + 1) & (N - 1); 314 | r = (r + 1) & (N - 1); 315 | 316 | /* Register the string in text_buf[r..r+F-1] */ 317 | insert_node(sp, r); 318 | } 319 | while (i++ < last_match_length) { 320 | delete_node(sp, s); 321 | 322 | /* After the end of text, no need to read, */ 323 | s = (s + 1) & (N - 1); 324 | r = (r + 1) & (N - 1); 325 | /* but buffer may not be empty. */ 326 | if (--len) 327 | insert_node(sp, r); 328 | } 329 | } while (len > 0); /* until length of string to be processed is zero */ 330 | 331 | if (code_buf_ptr > 1) { /* Send remaining code. */ 332 | for (i = 0; i < code_buf_ptr; i++) 333 | if (dst < dstend) 334 | *dst++ = code_buf[i]; 335 | else 336 | return 0; 337 | } 338 | 339 | return dst; 340 | } 341 | 342 | -------------------------------------------------------------------------------- /Support/compression.h: -------------------------------------------------------------------------------- 1 | typedef unsigned int u_int32_t; 2 | typedef unsigned short u_int16_t; 3 | typedef unsigned char u_int8_t; 4 | typedef signed int int32_t; 5 | typedef signed short int16_t; 6 | typedef signed char int8_t; 7 | 8 | extern u_int32_t local_adler32(u_int8_t *buffer, int32_t length); 9 | extern int decompress_lzss(u_int8_t *dst, u_int8_t *src, u_int32_t srclen); 10 | extern u_int8_t *compress_lzss(u_int8_t *dst, u_int32_t dstlen, u_int8_t *src, u_int32_t srcLen); 11 | -------------------------------------------------------------------------------- /WorkerThread.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header WorkerThread.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | @interface WorkerThread : NSObject 9 | { 10 | NSMachPort* _port; 11 | } 12 | 13 | -(void) instanceThreadMethod:(NSDictionary*) dict; 14 | 15 | -(void) checkinThread; 16 | -(void) threadTask:(NSDictionary*) dict; 17 | 18 | -(void) startSun; 19 | -(void) stopSun; 20 | -(void) setText:(NSString*) text; 21 | 22 | -(void) sendMessage:(int) msg withData:(NSData*) data; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /WorkerThread.m: -------------------------------------------------------------------------------- 1 | /*! 2 | @source WorkerThread.m 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #import "WorkerThread.h" 9 | 10 | @implementation WorkerThread 11 | 12 | -(id) init 13 | { 14 | self = [super init]; 15 | 16 | _port = nil; 17 | 18 | return self; 19 | } 20 | 21 | -(void) dealloc 22 | { 23 | [_port release]; 24 | 25 | [super dealloc]; 26 | } 27 | 28 | -(void) instanceThreadMethod:(NSDictionary*) dict 29 | { 30 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 31 | 32 | @try 33 | { 34 | _port = [[dict objectForKey:MachPortKey] retain]; 35 | 36 | [self checkinThread]; 37 | [self threadTask:dict]; 38 | } 39 | @catch (NSException *ex) 40 | { 41 | Log(@"%@ %@", [ex name], [ex reason]); 42 | } 43 | @finally 44 | { 45 | [pool release]; 46 | } 47 | } 48 | 49 | -(void) checkinThread 50 | { 51 | NSPort* port = [NSMachPort port]; 52 | if(port) 53 | { 54 | [port setDelegate:self]; 55 | [[NSRunLoop currentRunLoop] addPort:port forMode:NSDefaultRunLoopMode]; 56 | 57 | NSPortMessage* msg = [[NSPortMessage alloc] initWithSendPort:_port receivePort:port components:nil]; 58 | if(msg) 59 | { 60 | [msg setMsgid:ThreadStartMessage]; 61 | [msg sendBeforeDate:[NSDate date]]; 62 | } 63 | } 64 | } 65 | 66 | -(void) threadTask:(NSDictionary*) dict 67 | { 68 | 69 | } 70 | 71 | -(void) startSun 72 | { 73 | [self sendMessage:SunStartMessage withData:nil]; 74 | } 75 | 76 | -(void) stopSun 77 | { 78 | [self sendMessage:SunStopMessage withData:nil]; 79 | } 80 | 81 | -(void) setText:(NSString*) text 82 | { 83 | [InstanceManager setText:text]; 84 | } 85 | 86 | -(void) sendMessage:(int) msg withData:(NSData*) data 87 | { 88 | NSPortMessage* portMessage = [[NSPortMessage alloc] initWithSendPort:_port receivePort:nil components:(data == nil ? nil : [NSArray arrayWithObject:data])]; 89 | 90 | if(msg) 91 | { 92 | [portMessage setMsgid:msg]; 93 | 94 | BOOL res = FALSE; 95 | 96 | while(!res) 97 | res = [portMessage sendBeforeDate:[NSDate date]]; 98 | 99 | if(!res) 100 | Log(@"Failed to send port message: %d\n", portMessage); 101 | } 102 | } 103 | 104 | @end 105 | -------------------------------------------------------------------------------- /core/IPhoneUSB.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header IPhoneUSB.h 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #import 9 | #import 10 | #import 11 | #import 12 | 13 | /* DFU commands */ 14 | #define DFU_DETACH 0 15 | #define DFU_DNLOAD 1 16 | #define DFU_UPLOAD 2 17 | #define DFU_GETSTATUS 3 18 | #define DFU_CLRSTATUS 4 19 | #define DFU_GETSTATE 5 20 | #define DFU_ABORT 6 21 | 22 | /* DFU states */ 23 | #define DFU_STATE_APP_IDLE 0x00 24 | #define DFU_STATE_APP_DETACH 0x01 25 | #define DFU_STATE_DFU_IDLE 0x02 26 | #define DFU_STATE_DFU_DOWNLOAD_SYNC 0x03 27 | #define DFU_STATE_DFU_DOWNLOAD_BUSY 0x04 28 | #define DFU_STATE_DFU_DOWNLOAD_IDLE 0x05 29 | #define DFU_STATE_DFU_MANIFEST_SYNC 0x06 30 | #define DFU_STATE_DFU_MANIFEST 0x07 31 | #define DFU_STATE_DFU_MANIFEST_WAIT_RESET 0x08 32 | #define DFU_STATE_DFU_UPLOAD_IDLE 0x09 33 | #define DFU_STATE_DFU_ERROR 0x0a 34 | 35 | /* DFU status */ 36 | #define DFU_STATUS_OK 0x00 37 | #define DFU_STATUS_ERROR_TARGET 0x01 38 | #define DFU_STATUS_ERROR_FILE 0x02 39 | #define DFU_STATUS_ERROR_WRITE 0x03 40 | #define DFU_STATUS_ERROR_ERASE 0x04 41 | #define DFU_STATUS_ERROR_CHECK_ERASED 0x05 42 | #define DFU_STATUS_ERROR_PROG 0x06 43 | #define DFU_STATUS_ERROR_VERIFY 0x07 44 | #define DFU_STATUS_ERROR_ADDRESS 0x08 45 | #define DFU_STATUS_ERROR_NOTDONE 0x09 46 | #define DFU_STATUS_ERROR_FIRMWARE 0x0a 47 | #define DFU_STATUS_ERROR_VENDOR 0x0b 48 | #define DFU_STATUS_ERROR_USBR 0x0c 49 | #define DFU_STATUS_ERROR_POR 0x0d 50 | #define DFU_STATUS_ERROR_UNKNOWN 0x0e 51 | #define DFU_STATUS_ERROR_STALLEDPKT 0x0f 52 | 53 | typedef struct 54 | { 55 | unsigned char bStatus; 56 | unsigned int bwPollTimeout; 57 | unsigned char bState; 58 | unsigned char iString; 59 | } dfu_status; 60 | 61 | @protocol IPhoneDelegateProtocol 62 | 63 | -(void) processIPodNormalConnected:(id) sender; 64 | -(void) processIPhoneNormalConnected:(id) sender; 65 | -(void) processIPhone3GNormalConnected:(id) sender; 66 | -(void) processIPhoneRecoveryConnected:(id) sender; 67 | -(void) processIPhoneRecovery2Connected:(id) sender; 68 | -(void) processIPhoneDFUConnected:(id) sender; 69 | -(void) processIPhoneDFU2Connected:(id) sender; 70 | 71 | -(void) processIPodNormal:(id) sender; 72 | -(void) processIPhoneNormal:(id) sender; 73 | -(void) processIPhone3GNormal:(id) sender; 74 | -(void) processIPhoneRecovery:(id) sender; 75 | -(void) processIPhoneRecovery2:(id) sender; 76 | -(void) processIPhoneDFU:(id) sender; 77 | -(void) processIPhoneDFU2:(id) sender; 78 | 79 | -(void) processIPodNormalDisconnected:(id) sender; 80 | -(void) processIPhoneNormalDisconnected:(id) sender; 81 | -(void) processIPhoneRecoveryDisconnected:(id) sender; 82 | -(void) processIPhoneDFUDisconnected:(id) sender; 83 | -(void) processIPhoneDFU2Disconnected:(id) sender; 84 | 85 | -(void) processBeginUpload:(unsigned long long) bytes; 86 | -(void) processUploaded:(unsigned long long) bytes; 87 | 88 | -(void) processIPhoneError:(NSString*) err :(id) sender; 89 | -(void) processIPhoneMsg:(NSString*) msg :(id) sender; 90 | 91 | @end 92 | 93 | @interface IPhoneUSB : NSObject 94 | { 95 | enum 96 | { 97 | DisconnectMode = 0, 98 | IPodNormalMode, 99 | IPhoneNormalMode, 100 | IPhone3GNormalMode, 101 | RecoveryMode, 102 | Recovery2Mode, 103 | DFUMode, 104 | DFU2Mode 105 | } USBMode; 106 | 107 | IONotificationPortRef _ioKitNotificationPort; 108 | CFRunLoopSourceRef _notificationRunLoopSource; 109 | 110 | id _delegate; 111 | 112 | IOUSBDeviceInterface** _dev; 113 | IOUSBInterfaceInterface** _intf; 114 | NSLock* _lock; 115 | 116 | int _mode; 117 | BOOL _enabled; 118 | BOOL _newInterface; 119 | 120 | UInt8 _ctrlIn; 121 | UInt8 _ctrlOut; 122 | 123 | UInt8 _serialIn; 124 | UInt8 _serialOut; 125 | 126 | UInt8 _fileIn; 127 | UInt8 _fileOut; 128 | 129 | unsigned short _transaction; 130 | 131 | BOOL _usbNotificationsOnly; 132 | } 133 | 134 | -(id) delegate; 135 | -(void) setDelegate:(id) delegate; 136 | 137 | -(void) ioKitSetUp; 138 | -(void) ioKitTearDown; 139 | 140 | -(void) restartService; 141 | -(void) startService; 142 | -(void) stopService; 143 | -(BOOL) serviceStatus; 144 | 145 | -(void) registerForUSBNotifications; 146 | -(void) usbDeviceAdded:(io_iterator_t) iterator; 147 | -(void) usbDeviceRemoved:(io_iterator_t) iterator; 148 | 149 | -(void) ifIPhoneRemoved:(io_object_t) device; 150 | -(void) ifIPhoneAdded:(io_object_t) device; 151 | 152 | -(void) dealWithDevice; 153 | -(void) dealWithInterface:(io_service_t) usbInterfaceRef; 154 | 155 | - (void)enableUSBNotificationOnlyMode; 156 | 157 | @end 158 | 159 | @interface IPhoneUSB (IPhoneIO) 160 | 161 | -(IOReturn) resetDevice; 162 | 163 | -(IOReturn) writeSerial:(void*) data :(unsigned int) size; 164 | -(IOReturn) readSerial:(void*) data :(unsigned int*) pSize; 165 | 166 | -(IOReturn) sendRequest:(IOUSBDevRequest*) request; 167 | -(IOReturn) sendCommand:(NSString*) cmd; 168 | 169 | -(void) uploadFile:(NSString*) file; 170 | -(dfu_status) uploadFileChunk:(void*) buf :(unsigned short) length; 171 | -(IOReturn) dfuAbort; 172 | -(dfu_status) dfuStatus; 173 | -(IOReturn) dfuClearStatus; 174 | -(NSString*) stringForDFUStatus:(int) status; 175 | 176 | @end -------------------------------------------------------------------------------- /core/SecureTask.m: -------------------------------------------------------------------------------- 1 | /*! 2 | @source SecureTask.m 3 | @project Pusher 4 | @author Alexander Maksimenko 5 | @copyright Copyright (c) 2009 Ripdev. All rights reserved. 6 | */ 7 | 8 | #import "SecureTask.h" 9 | 10 | @implementation SecureTask 11 | 12 | -(id) init 13 | { 14 | self = [super init]; 15 | 16 | authorizationRef = NULL; 17 | _output = [[NSMutableString alloc] init]; 18 | _helperPath = [[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:PusherHelperPath] retain]; 19 | 20 | return self; 21 | } 22 | 23 | -(void) dealloc 24 | { 25 | [self deauthenticate]; 26 | 27 | [_output release]; 28 | [_helperPath release]; 29 | 30 | [super dealloc]; 31 | } 32 | 33 | -(BOOL) isAuthenticated:(NSString*) task 34 | { 35 | OSStatus err = 0; 36 | 37 | if(authorizationRef == NULL) 38 | { 39 | err = AuthorizationCreate (NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authorizationRef); 40 | 41 | if(err != errAuthorizationSuccess) 42 | return NO; 43 | } 44 | 45 | AuthorizationFlags flags; 46 | AuthorizationRights rights; 47 | AuthorizationItem items[1]; 48 | const char* taskC = [task UTF8String]; 49 | 50 | items[0].name = kAuthorizationRightExecute; 51 | items[0].value = (void*)taskC; 52 | items[0].valueLength = strlen(taskC); 53 | items[0].flags = 0; 54 | 55 | rights.count = 1; 56 | rights.items = items; 57 | 58 | flags = kAuthorizationFlagExtendRights; 59 | 60 | err = AuthorizationCopyRights(authorizationRef,&rights,kAuthorizationEmptyEnvironment,flags,NULL); 61 | 62 | return (err == errAuthorizationSuccess); 63 | } 64 | 65 | -(void) deauthenticate 66 | { 67 | if(authorizationRef) 68 | { 69 | AuthorizationFree(authorizationRef,kAuthorizationFlagDestroyRights); 70 | authorizationRef = NULL; 71 | } 72 | } 73 | 74 | -(BOOL) fetchPassword:(NSString*) task 75 | { 76 | OSStatus err = 0; 77 | AuthorizationFlags flags; 78 | AuthorizationRights rights; 79 | AuthorizationItem items[1]; 80 | const char* taskC = [task UTF8String]; 81 | 82 | items[0].name = kAuthorizationRightExecute; 83 | items[0].value = (void*)taskC; 84 | items[0].valueLength = strlen(taskC); 85 | items[0].flags = 0; 86 | 87 | rights.count = 1; 88 | rights.items = items; 89 | 90 | flags = kAuthorizationFlagDefaults | 91 | kAuthorizationFlagInteractionAllowed | 92 | kAuthorizationFlagExtendRights; 93 | 94 | err = AuthorizationCopyRights(authorizationRef,&rights,kAuthorizationEmptyEnvironment,flags,NULL); 95 | 96 | return (err == errAuthorizationSuccess); 97 | } 98 | 99 | -(BOOL) authenticate:(NSString*) task 100 | { 101 | if(![self isAuthenticated:task]) 102 | [self fetchPassword:task]; 103 | 104 | return [self isAuthenticated:task]; 105 | } 106 | 107 | -(BOOL) runTaskWithArgs:(char * const *) args 108 | { 109 | if(![self authenticate:_helperPath]) 110 | { 111 | Log(@"Failed to authenticate helper execution"); 112 | return FALSE; 113 | } 114 | 115 | FILE* f = NULL; 116 | OSStatus err = AuthorizationExecuteWithPrivileges(authorizationRef, [_helperPath UTF8String], 0, args, &f); 117 | 118 | if(err == errAuthorizationSuccess) 119 | { 120 | // wait for child process to end 121 | pid_t pid = [self readPid:f]; 122 | [self drainOutput:f]; 123 | 124 | int status; 125 | 126 | // Log(@"Waiting for pwange helper with pid %d", pid); 127 | 128 | if(waitpid(pid, &status, 0) != pid) 129 | { 130 | Log(@"Failed to waitpid helper pid"); 131 | return NO; 132 | } 133 | 134 | if(!WIFEXITED(status)) 135 | { 136 | Log(@"Failed to waitpid(), returned %d", status); 137 | return NO; 138 | } 139 | } 140 | else 141 | Log(@"Failed to AuthorizationExecuteWithPrivileges(), returned %d", err); 142 | 143 | return (err == errAuthorizationSuccess); 144 | } 145 | 146 | -(void) drainOutput:(FILE*) file 147 | { 148 | [_output setString:@""]; 149 | 150 | int c = 0; 151 | char buffer[100]; 152 | 153 | for(;;) 154 | { 155 | c = fread(buffer, 1, sizeof(buffer), file); 156 | 157 | if(c < 1) 158 | break; 159 | 160 | fwrite(buffer, 1, c, stdout); 161 | 162 | buffer[c] = 0; 163 | [_output appendString:[NSString stringWithUTF8String:&buffer[0]]]; 164 | } 165 | 166 | fclose(file); 167 | } 168 | 169 | -(int) readPid:(FILE*) file 170 | { 171 | pid_t pid = 0; 172 | char pidnum[1024]; 173 | 174 | int i = 0; 175 | char ch = 0; 176 | while(fread(&ch, 1, sizeof(ch), file) == sizeof(ch) && (ch != '\n') && (i < sizeof(pidnum))) 177 | pidnum[i++] = ch; 178 | 179 | pidnum[i] = 0; 180 | 181 | if(ch != '\n') 182 | return -1; 183 | 184 | sscanf(pidnum, "%d", &pid); 185 | 186 | if(pid == 0) 187 | return -1; 188 | 189 | return pid; 190 | } 191 | 192 | -(NSString*) output 193 | { 194 | return _output; 195 | } 196 | 197 | @end 198 | -------------------------------------------------------------------------------- /dpkg/dpkg.h: -------------------------------------------------------------------------------- 1 | @interface DpkgManager : NSObject 2 | { 3 | } 4 | 5 | -(NSArray*) packages; 6 | 7 | -(BOOL) installPackage:(NSString*) fileName ignoreDependency:(BOOL) ignoreDependency error:(NSString**) error; 8 | -(BOOL) removePackageWithId:(NSString*) id ignoreDependency:(BOOL) ignoreDependency forceEssential:(BOOL) forceEssential error:(NSString**) error; 9 | 10 | -(NSString*) infoPlistPathForPackageWithId:(NSString*) id; 11 | 12 | @end 13 | -------------------------------------------------------------------------------- /dpkg/dpkg.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "dpkg.h" 3 | 4 | 5 | #define DPKG_OUTPUT "/tmp/dpkg.log" 6 | 7 | @interface DpkgManager (Private) 8 | 9 | -(void) clearOutput; 10 | -(NSString*) readOutput; 11 | -(NSString*) readStatus; 12 | 13 | -(NSMutableArray*) dependencyFromString:(NSString*) string; 14 | 15 | @end 16 | 17 | @implementation DpkgManager (Private) 18 | 19 | -(void) clearOutput 20 | { 21 | unlink(DPKG_OUTPUT); 22 | } 23 | 24 | -(NSString*) readOutput 25 | { 26 | NSString* output = [NSString stringWithContentsOfFile:[NSString stringWithUTF8String:DPKG_OUTPUT]]; 27 | output = [output stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 28 | 29 | return output; 30 | } 31 | 32 | -(NSString*) readStatus 33 | { 34 | NSString* status = [self readOutput]; 35 | NSArray* lines = [status componentsSeparatedByString:@"\n"]; 36 | status = [lines lastObject]; 37 | 38 | return status; 39 | } 40 | 41 | -(NSMutableArray*) dependencyFromString:(NSString*) string 42 | { 43 | NSMutableArray* result = nil; 44 | 45 | if(string != nil) 46 | { 47 | NSArray* components = [string componentsSeparatedByString:@","]; 48 | if([components count] > 0) 49 | { 50 | NSString* dependString = nil; 51 | 52 | for(dependString in components) 53 | { 54 | NSString* correctDependString = dependString; 55 | 56 | NSRange findedRange = [correctDependString rangeOfString:@"("]; 57 | if(findedRange.location < [correctDependString length]) 58 | correctDependString = [correctDependString substringToIndex:(findedRange.location - 1)]; 59 | 60 | correctDependString = [correctDependString stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" "]]; 61 | 62 | if([correctDependString length] > 0) 63 | { 64 | if(result == nil) 65 | result = [NSMutableArray arrayWithCapacity:0]; 66 | 67 | [result addObject:[correctDependString lowercaseString]]; 68 | } 69 | } 70 | } 71 | } 72 | 73 | return result; 74 | } 75 | 76 | @end 77 | 78 | @implementation DpkgManager 79 | 80 | -(id) init 81 | { 82 | self = [super init]; 83 | 84 | return self; 85 | } 86 | 87 | -(void) dealloc 88 | { 89 | [self clearOutput]; 90 | 91 | [super dealloc]; 92 | } 93 | 94 | -(NSArray*) packages 95 | { 96 | NSMutableArray* packages = [NSMutableArray array]; 97 | NSMutableDictionary* dict = [NSMutableDictionary dictionary]; 98 | NSString* desc = nil; 99 | BOOL isInstalled = NO; 100 | 101 | NSString* file = [NSString stringWithContentsOfFile:@"/var/lib/dpkg/status"]; 102 | if(file) 103 | { 104 | NSArray* lines = [file componentsSeparatedByString:@"\n"]; 105 | NSEnumerator* enumerator = [lines objectEnumerator]; 106 | NSString* line; 107 | while(line = [enumerator nextObject]) 108 | { 109 | NSRange range = [line rangeOfString:@" " options:0 range:NSMakeRange(0, [line length])]; 110 | if(range.location != NSNotFound) 111 | { 112 | NSString* key = [line substringToIndex:range.location]; 113 | NSString* value = [line substringFromIndex:range.location + 1]; 114 | 115 | if([key isEqualToString:@"Status:"]) 116 | isInstalled = [value isEqualToString:@"install ok installed"]; 117 | else if([key isEqualToString:@"Package:"]) 118 | [dict setObject:value forKey:PackageIdKey]; 119 | else if([key isEqualToString:@"Name:"]) 120 | [dict setObject:value forKey:PackageNameKey]; 121 | else if([key isEqualToString:@"Version:"]) 122 | [dict setObject:value forKey:PackageVersionKey]; 123 | else if([key isEqualToString:@"Description:"]) 124 | desc = value; 125 | else if([key isEqualToString:@"Section:"]) 126 | [dict setObject:value forKey:PackageCategoryKey]; 127 | else if([key isEqualToString:@"Depends:"]) 128 | { 129 | NSArray* dependency = [self dependencyFromString:value]; 130 | if(dependency) 131 | [dict setObject:dependency forKey:PackageDependencyKey]; 132 | } 133 | else if([key isEqualToString:@"Author:"]) 134 | [dict setObject:value forKey:PackageAuthorKey]; 135 | else if([key isEqualToString:@"Maintainer:"]) 136 | [dict setObject:value forKey:PackageMaintainerKey]; 137 | else if([key isEqualToString:@"Essential:"] && [value isEqualToString:@"yes"]) 138 | [dict setObject:[NSNumber numberWithBool:YES] forKey:PackageEssentialKey]; 139 | else if([key isEqualToString:@"Icon:"]) 140 | [dict setObject:value forKey:PackageIconKey]; 141 | else if([key isEqualToString:@"Depiction:"]) 142 | [dict setObject:value forKey:PackageDepictionKey]; 143 | else if([key isEqualToString:@"Homepage:"]) 144 | [dict setObject:value forKey:PackageHomepageKey]; 145 | else if([key isEqualToString:@"Website:"]) 146 | [dict setObject:value forKey:PackageWebsiteKey]; 147 | else 148 | { 149 | if(desc) 150 | { 151 | if(range.location == 0 && [value length] > 0) 152 | desc = [desc stringByAppendingFormat:@" %@", value]; 153 | else 154 | { 155 | [dict setObject:desc forKey:PackageDescriptionKey]; 156 | desc = nil; 157 | } 158 | } 159 | } 160 | } 161 | else 162 | { 163 | if(isInstalled) 164 | { 165 | if(desc) 166 | { 167 | [dict setObject:desc forKey:PackageDescriptionKey]; 168 | desc = nil; 169 | } 170 | 171 | [packages addObject:dict]; 172 | isInstalled = NO; 173 | } 174 | 175 | dict = [NSMutableDictionary dictionary]; 176 | } 177 | } 178 | } 179 | 180 | return packages; 181 | } 182 | 183 | -(BOOL) installPackage:(NSString*) fileName ignoreDependency:(BOOL) ignoreDependency error:(NSString**) error 184 | { 185 | [self clearOutput]; 186 | 187 | NSString* dpkg = nil; 188 | if(ignoreDependency) 189 | dpkg = [NSString stringWithFormat:@"dpkg -i --force-depends --log=%s %@", DPKG_OUTPUT, fileName]; 190 | else 191 | dpkg = [NSString stringWithFormat:@"dpkg -i --log=%s %@", DPKG_OUTPUT, fileName]; 192 | 193 | setenv("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1); 194 | system([dpkg UTF8String]); 195 | 196 | NSString* status = [self readStatus]; 197 | 198 | if(status == nil || [status rangeOfString:@"status installed"].length == 0) 199 | { 200 | if(status == nil) 201 | status = @"Failed to read dpkg status"; 202 | 203 | *error = status; 204 | 205 | return NO; 206 | } 207 | 208 | return YES; 209 | } 210 | 211 | -(BOOL) removePackageWithId:(NSString*) id ignoreDependency:(BOOL) ignoreDependency forceEssential:(BOOL) forceEssential error:(NSString**) error 212 | { 213 | [self clearOutput]; 214 | 215 | NSString* dpkg = [NSString stringWithFormat:@"dpkg -P"]; 216 | 217 | if(ignoreDependency) 218 | dpkg = [dpkg stringByAppendingString:@" --force-depends"]; 219 | 220 | if(forceEssential) 221 | dpkg = [dpkg stringByAppendingString:@" --force-remove-essential"]; 222 | 223 | dpkg = [dpkg stringByAppendingFormat:@" --log=%s %@", DPKG_OUTPUT, id]; 224 | 225 | setenv("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1); 226 | system([dpkg UTF8String]); 227 | 228 | NSString* status = [self readStatus]; 229 | if(status == nil || [status rangeOfString:@"status not-installed"].length == 0) 230 | { 231 | if(status == nil) 232 | status = @"Failed to read dpkg status"; 233 | 234 | *error = status; 235 | 236 | return NO; 237 | } 238 | 239 | return YES; 240 | } 241 | 242 | -(NSString*) infoPlistPathForPackageWithId:(NSString*) id 243 | { 244 | [self clearOutput]; 245 | 246 | NSString* dpkg = [NSString stringWithFormat:@"dpkg -L %@ > %s", id, DPKG_OUTPUT]; 247 | setenv("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1); 248 | system([dpkg UTF8String]); 249 | 250 | NSArray* lines = [[self readOutput] componentsSeparatedByString:@"\n"]; 251 | NSEnumerator* enumerator = [lines objectEnumerator]; 252 | NSString* line; 253 | while(line = [enumerator nextObject]) 254 | if([line hasPrefix:@"/Applications"] && [line hasSuffix:@"Info.plist"]) 255 | return line; 256 | 257 | return nil; 258 | } 259 | 260 | @end 261 | -------------------------------------------------------------------------------- /dpkg/dpkg.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | 4 | #import 5 | #import 6 | #import 7 | #import 8 | #import 9 | #import 10 | #import 11 | #import 12 | #import 13 | #import 14 | #import 15 | #import 16 | #import 17 | #import 18 | #import 19 | #import 20 | #endif 21 | -------------------------------------------------------------------------------- /libpng/pngerror.c: -------------------------------------------------------------------------------- 1 | 2 | /* pngerror.c - stub functions for i/o and memory allocation 3 | * 4 | * Last changed in libpng 1.2.22 [October 13, 2007] 5 | * For conditions of distribution and use, see copyright notice in png.h 6 | * Copyright (c) 1998-2007 Glenn Randers-Pehrson 7 | * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 8 | * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 9 | * 10 | * This file provides a location for all error handling. Users who 11 | * need special error handling are expected to write replacement functions 12 | * and use png_set_error_fn() to use those functions. See the instructions 13 | * at each function. 14 | */ 15 | 16 | #define PNG_INTERNAL 17 | #include "png.h" 18 | 19 | #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) 20 | static void /* PRIVATE */ 21 | png_default_error PNGARG((png_structp png_ptr, 22 | png_const_charp error_message)); 23 | #ifndef PNG_NO_WARNINGS 24 | static void /* PRIVATE */ 25 | png_default_warning PNGARG((png_structp png_ptr, 26 | png_const_charp warning_message)); 27 | #endif /* PNG_NO_WARNINGS */ 28 | 29 | /* This function is called whenever there is a fatal error. This function 30 | * should not be changed. If there is a need to handle errors differently, 31 | * you should supply a replacement error function and use png_set_error_fn() 32 | * to replace the error function at run-time. 33 | */ 34 | #ifndef PNG_NO_ERROR_TEXT 35 | void PNGAPI 36 | png_error(png_structp png_ptr, png_const_charp error_message) 37 | { 38 | #ifdef PNG_ERROR_NUMBERS_SUPPORTED 39 | char msg[16]; 40 | if (png_ptr != NULL) 41 | { 42 | if (png_ptr->flags& 43 | (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) 44 | { 45 | if (*error_message == '#') 46 | { 47 | int offset; 48 | for (offset=1; offset<15; offset++) 49 | if (*(error_message+offset) == ' ') 50 | break; 51 | if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT) 52 | { 53 | int i; 54 | for (i=0; iflags&PNG_FLAG_STRIP_ERROR_TEXT) 65 | { 66 | msg[0]='0'; 67 | msg[1]='\0'; 68 | error_message=msg; 69 | } 70 | } 71 | } 72 | } 73 | #endif 74 | if (png_ptr != NULL && png_ptr->error_fn != NULL) 75 | (*(png_ptr->error_fn))(png_ptr, error_message); 76 | 77 | /* If the custom handler doesn't exist, or if it returns, 78 | use the default handler, which will not return. */ 79 | png_default_error(png_ptr, error_message); 80 | } 81 | #else 82 | void PNGAPI 83 | png_err(png_structp png_ptr) 84 | { 85 | if (png_ptr != NULL && png_ptr->error_fn != NULL) 86 | (*(png_ptr->error_fn))(png_ptr, '\0'); 87 | 88 | /* If the custom handler doesn't exist, or if it returns, 89 | use the default handler, which will not return. */ 90 | png_default_error(png_ptr, '\0'); 91 | } 92 | #endif /* PNG_NO_ERROR_TEXT */ 93 | 94 | #ifndef PNG_NO_WARNINGS 95 | /* This function is called whenever there is a non-fatal error. This function 96 | * should not be changed. If there is a need to handle warnings differently, 97 | * you should supply a replacement warning function and use 98 | * png_set_error_fn() to replace the warning function at run-time. 99 | */ 100 | void PNGAPI 101 | png_warning(png_structp png_ptr, png_const_charp warning_message) 102 | { 103 | int offset = 0; 104 | if (png_ptr != NULL) 105 | { 106 | #ifdef PNG_ERROR_NUMBERS_SUPPORTED 107 | if (png_ptr->flags& 108 | (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) 109 | #endif 110 | { 111 | if (*warning_message == '#') 112 | { 113 | for (offset=1; offset<15; offset++) 114 | if (*(warning_message+offset) == ' ') 115 | break; 116 | } 117 | } 118 | if (png_ptr != NULL && png_ptr->warning_fn != NULL) 119 | (*(png_ptr->warning_fn))(png_ptr, warning_message+offset); 120 | } 121 | else 122 | png_default_warning(png_ptr, warning_message+offset); 123 | } 124 | #endif /* PNG_NO_WARNINGS */ 125 | 126 | 127 | /* These utilities are used internally to build an error message that relates 128 | * to the current chunk. The chunk name comes from png_ptr->chunk_name, 129 | * this is used to prefix the message. The message is limited in length 130 | * to 63 bytes, the name characters are output as hex digits wrapped in [] 131 | * if the character is invalid. 132 | */ 133 | #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97)) 134 | static PNG_CONST char png_digit[16] = { 135 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 136 | 'A', 'B', 'C', 'D', 'E', 'F' 137 | }; 138 | 139 | #define PNG_MAX_ERROR_TEXT 64 140 | 141 | #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) 142 | static void /* PRIVATE */ 143 | png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp 144 | error_message) 145 | { 146 | int iout = 0, iin = 0; 147 | 148 | while (iin < 4) 149 | { 150 | int c = png_ptr->chunk_name[iin++]; 151 | if (isnonalpha(c)) 152 | { 153 | buffer[iout++] = '['; 154 | buffer[iout++] = png_digit[(c & 0xf0) >> 4]; 155 | buffer[iout++] = png_digit[c & 0x0f]; 156 | buffer[iout++] = ']'; 157 | } 158 | else 159 | { 160 | buffer[iout++] = (png_byte)c; 161 | } 162 | } 163 | 164 | if (error_message == NULL) 165 | buffer[iout] = '\0'; 166 | else 167 | { 168 | buffer[iout++] = ':'; 169 | buffer[iout++] = ' '; 170 | png_memcpy(buffer+iout, error_message, PNG_MAX_ERROR_TEXT); 171 | buffer[iout+PNG_MAX_ERROR_TEXT-1] = '\0'; 172 | } 173 | } 174 | 175 | #ifdef PNG_READ_SUPPORTED 176 | void PNGAPI 177 | png_chunk_error(png_structp png_ptr, png_const_charp error_message) 178 | { 179 | char msg[18+PNG_MAX_ERROR_TEXT]; 180 | if (png_ptr == NULL) 181 | png_error(png_ptr, error_message); 182 | else 183 | { 184 | png_format_buffer(png_ptr, msg, error_message); 185 | png_error(png_ptr, msg); 186 | } 187 | } 188 | #endif /* PNG_READ_SUPPORTED */ 189 | #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */ 190 | 191 | #ifndef PNG_NO_WARNINGS 192 | void PNGAPI 193 | png_chunk_warning(png_structp png_ptr, png_const_charp warning_message) 194 | { 195 | char msg[18+PNG_MAX_ERROR_TEXT]; 196 | if (png_ptr == NULL) 197 | png_warning(png_ptr, warning_message); 198 | else 199 | { 200 | png_format_buffer(png_ptr, msg, warning_message); 201 | png_warning(png_ptr, msg); 202 | } 203 | } 204 | #endif /* PNG_NO_WARNINGS */ 205 | 206 | 207 | /* This is the default error handling function. Note that replacements for 208 | * this function MUST NOT RETURN, or the program will likely crash. This 209 | * function is used by default, or if the program supplies NULL for the 210 | * error function pointer in png_set_error_fn(). 211 | */ 212 | static void /* PRIVATE */ 213 | png_default_error(png_structp png_ptr, png_const_charp error_message) 214 | { 215 | #ifndef PNG_NO_CONSOLE_IO 216 | #ifdef PNG_ERROR_NUMBERS_SUPPORTED 217 | if (*error_message == '#') 218 | { 219 | int offset; 220 | char error_number[16]; 221 | for (offset=0; offset<15; offset++) 222 | { 223 | error_number[offset] = *(error_message+offset+1); 224 | if (*(error_message+offset) == ' ') 225 | break; 226 | } 227 | if((offset > 1) && (offset < 15)) 228 | { 229 | error_number[offset-1]='\0'; 230 | fprintf(stderr, "libpng error no. %s: %s\n", error_number, 231 | error_message+offset); 232 | } 233 | else 234 | fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset); 235 | } 236 | else 237 | #endif 238 | fprintf(stderr, "libpng error: %s\n", error_message); 239 | #endif 240 | 241 | #ifdef PNG_SETJMP_SUPPORTED 242 | if (png_ptr) 243 | { 244 | # ifdef USE_FAR_KEYWORD 245 | { 246 | jmp_buf jmpbuf; 247 | png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf)); 248 | longjmp(jmpbuf, 1); 249 | } 250 | # else 251 | longjmp(png_ptr->jmpbuf, 1); 252 | # endif 253 | } 254 | #else 255 | PNG_ABORT(); 256 | #endif 257 | #ifdef PNG_NO_CONSOLE_IO 258 | error_message = error_message; /* make compiler happy */ 259 | #endif 260 | } 261 | 262 | #ifndef PNG_NO_WARNINGS 263 | /* This function is called when there is a warning, but the library thinks 264 | * it can continue anyway. Replacement functions don't have to do anything 265 | * here if you don't want them to. In the default configuration, png_ptr is 266 | * not used, but it is passed in case it may be useful. 267 | */ 268 | static void /* PRIVATE */ 269 | png_default_warning(png_structp png_ptr, png_const_charp warning_message) 270 | { 271 | #ifndef PNG_NO_CONSOLE_IO 272 | # ifdef PNG_ERROR_NUMBERS_SUPPORTED 273 | if (*warning_message == '#') 274 | { 275 | int offset; 276 | char warning_number[16]; 277 | for (offset=0; offset<15; offset++) 278 | { 279 | warning_number[offset]=*(warning_message+offset+1); 280 | if (*(warning_message+offset) == ' ') 281 | break; 282 | } 283 | if((offset > 1) && (offset < 15)) 284 | { 285 | warning_number[offset-1]='\0'; 286 | fprintf(stderr, "libpng warning no. %s: %s\n", warning_number, 287 | warning_message+offset); 288 | } 289 | else 290 | fprintf(stderr, "libpng warning: %s\n", warning_message); 291 | } 292 | else 293 | # endif 294 | fprintf(stderr, "libpng warning: %s\n", warning_message); 295 | #else 296 | warning_message = warning_message; /* make compiler happy */ 297 | #endif 298 | png_ptr = png_ptr; /* make compiler happy */ 299 | } 300 | #endif /* PNG_NO_WARNINGS */ 301 | 302 | /* This function is called when the application wants to use another method 303 | * of handling errors and warnings. Note that the error function MUST NOT 304 | * return to the calling routine or serious problems will occur. The return 305 | * method used in the default routine calls longjmp(png_ptr->jmpbuf, 1) 306 | */ 307 | void PNGAPI 308 | png_set_error_fn(png_structp png_ptr, png_voidp error_ptr, 309 | png_error_ptr error_fn, png_error_ptr warning_fn) 310 | { 311 | if (png_ptr == NULL) 312 | return; 313 | png_ptr->error_ptr = error_ptr; 314 | png_ptr->error_fn = error_fn; 315 | png_ptr->warning_fn = warning_fn; 316 | } 317 | 318 | 319 | /* This function returns a pointer to the error_ptr associated with the user 320 | * functions. The application should free any memory associated with this 321 | * pointer before png_write_destroy and png_read_destroy are called. 322 | */ 323 | png_voidp PNGAPI 324 | png_get_error_ptr(png_structp png_ptr) 325 | { 326 | if (png_ptr == NULL) 327 | return NULL; 328 | return ((png_voidp)png_ptr->error_ptr); 329 | } 330 | 331 | 332 | #ifdef PNG_ERROR_NUMBERS_SUPPORTED 333 | void PNGAPI 334 | png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode) 335 | { 336 | if(png_ptr != NULL) 337 | { 338 | png_ptr->flags &= 339 | ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode); 340 | } 341 | } 342 | #endif 343 | #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ 344 | -------------------------------------------------------------------------------- /libpng/pnggccrd.c: -------------------------------------------------------------------------------- 1 | /* pnggccrd.c was removed from libpng-1.2.20. */ 2 | 3 | /* This code snippet is for use by configure's compilation test. */ 4 | 5 | #if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && \ 6 | defined(PNG_MMX_CODE_SUPPORTED) 7 | int PNGAPI png_dummy_mmx_support(void); 8 | 9 | static int _mmx_supported = 2; // 0: no MMX; 1: MMX supported; 2: not tested 10 | 11 | int PNGAPI 12 | png_dummy_mmx_support(void) __attribute__((noinline)); 13 | 14 | int PNGAPI 15 | png_dummy_mmx_support(void) 16 | { 17 | int result; 18 | #if defined(PNG_MMX_CODE_SUPPORTED) // superfluous, but what the heck 19 | __asm__ __volatile__ ( 20 | #if defined(__x86_64__) 21 | "pushq %%rbx \n\t" // rbx gets clobbered by CPUID instruction 22 | "pushq %%rcx \n\t" // so does rcx... 23 | "pushq %%rdx \n\t" // ...and rdx (but rcx & rdx safe on Linux) 24 | "pushfq \n\t" // save Eflag to stack 25 | "popq %%rax \n\t" // get Eflag from stack into rax 26 | "movq %%rax, %%rcx \n\t" // make another copy of Eflag in rcx 27 | "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21) 28 | "pushq %%rax \n\t" // save modified Eflag back to stack 29 | "popfq \n\t" // restore modified value to Eflag reg 30 | "pushfq \n\t" // save Eflag to stack 31 | "popq %%rax \n\t" // get Eflag from stack 32 | "pushq %%rcx \n\t" // save original Eflag to stack 33 | "popfq \n\t" // restore original Eflag 34 | #else 35 | "pushl %%ebx \n\t" // ebx gets clobbered by CPUID instruction 36 | "pushl %%ecx \n\t" // so does ecx... 37 | "pushl %%edx \n\t" // ...and edx (but ecx & edx safe on Linux) 38 | "pushfl \n\t" // save Eflag to stack 39 | "popl %%eax \n\t" // get Eflag from stack into eax 40 | "movl %%eax, %%ecx \n\t" // make another copy of Eflag in ecx 41 | "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21) 42 | "pushl %%eax \n\t" // save modified Eflag back to stack 43 | "popfl \n\t" // restore modified value to Eflag reg 44 | "pushfl \n\t" // save Eflag to stack 45 | "popl %%eax \n\t" // get Eflag from stack 46 | "pushl %%ecx \n\t" // save original Eflag to stack 47 | "popfl \n\t" // restore original Eflag 48 | #endif 49 | "xorl %%ecx, %%eax \n\t" // compare new Eflag with original Eflag 50 | "jz 0f \n\t" // if same, CPUID instr. is not supported 51 | 52 | "xorl %%eax, %%eax \n\t" // set eax to zero 53 | // ".byte 0x0f, 0xa2 \n\t" // CPUID instruction (two-byte opcode) 54 | "cpuid \n\t" // get the CPU identification info 55 | "cmpl $1, %%eax \n\t" // make sure eax return non-zero value 56 | "jl 0f \n\t" // if eax is zero, MMX is not supported 57 | 58 | "xorl %%eax, %%eax \n\t" // set eax to zero and... 59 | "incl %%eax \n\t" // ...increment eax to 1. This pair is 60 | // faster than the instruction "mov eax, 1" 61 | "cpuid \n\t" // get the CPU identification info again 62 | "andl $0x800000, %%edx \n\t" // mask out all bits but MMX bit (23) 63 | "cmpl $0, %%edx \n\t" // 0 = MMX not supported 64 | "jz 0f \n\t" // non-zero = yes, MMX IS supported 65 | 66 | "movl $1, %%eax \n\t" // set return value to 1 67 | "jmp 1f \n\t" // DONE: have MMX support 68 | 69 | "0: \n\t" // .NOT_SUPPORTED: target label for jump instructions 70 | "movl $0, %%eax \n\t" // set return value to 0 71 | "1: \n\t" // .RETURN: target label for jump instructions 72 | #if defined(__x86_64__) 73 | "popq %%rdx \n\t" // restore rdx 74 | "popq %%rcx \n\t" // restore rcx 75 | "popq %%rbx \n\t" // restore rbx 76 | #else 77 | "popl %%edx \n\t" // restore edx 78 | "popl %%ecx \n\t" // restore ecx 79 | "popl %%ebx \n\t" // restore ebx 80 | #endif 81 | 82 | // "ret \n\t" // DONE: no MMX support 83 | // (fall through to standard C "ret") 84 | 85 | : "=a" (result) // output list 86 | 87 | : // any variables used on input (none) 88 | 89 | // no clobber list 90 | // , "%ebx", "%ecx", "%edx" // GRR: we handle these manually 91 | // , "memory" // if write to a variable gcc thought was in a reg 92 | // , "cc" // "condition codes" (flag bits) 93 | ); 94 | _mmx_supported = result; 95 | #else 96 | _mmx_supported = 0; 97 | #endif /* PNG_MMX_CODE_SUPPORTED */ 98 | 99 | return _mmx_supported; 100 | } 101 | #endif 102 | -------------------------------------------------------------------------------- /libpng/pngrio.c: -------------------------------------------------------------------------------- 1 | 2 | /* pngrio.c - functions for data input 3 | * 4 | * Last changed in libpng 1.2.13 November 13, 2006 5 | * For conditions of distribution and use, see copyright notice in png.h 6 | * Copyright (c) 1998-2006 Glenn Randers-Pehrson 7 | * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 8 | * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 9 | * 10 | * This file provides a location for all input. Users who need 11 | * special handling are expected to write a function that has the same 12 | * arguments as this and performs a similar function, but that possibly 13 | * has a different input method. Note that you shouldn't change this 14 | * function, but rather write a replacement function and then make 15 | * libpng use it at run time with png_set_read_fn(...). 16 | */ 17 | 18 | #define PNG_INTERNAL 19 | #include "png.h" 20 | 21 | #if defined(PNG_READ_SUPPORTED) 22 | 23 | /* Read the data from whatever input you are using. The default routine 24 | reads from a file pointer. Note that this routine sometimes gets called 25 | with very small lengths, so you should implement some kind of simple 26 | buffering if you are using unbuffered reads. This should never be asked 27 | to read more then 64K on a 16 bit machine. */ 28 | void /* PRIVATE */ 29 | png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) 30 | { 31 | png_debug1(4,"reading %d bytes\n", (int)length); 32 | if (png_ptr->read_data_fn != NULL) 33 | (*(png_ptr->read_data_fn))(png_ptr, data, length); 34 | else 35 | png_error(png_ptr, "Call to NULL read function"); 36 | } 37 | 38 | #if !defined(PNG_NO_STDIO) 39 | /* This is the function that does the actual reading of data. If you are 40 | not reading from a standard C stream, you should create a replacement 41 | read_data function and use it at run time with png_set_read_fn(), rather 42 | than changing the library. */ 43 | #ifndef USE_FAR_KEYWORD 44 | void PNGAPI 45 | png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) 46 | { 47 | png_size_t check; 48 | 49 | if(png_ptr == NULL) return; 50 | /* fread() returns 0 on error, so it is OK to store this in a png_size_t 51 | * instead of an int, which is what fread() actually returns. 52 | */ 53 | #if defined(_WIN32_WCE) 54 | if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) 55 | check = 0; 56 | #else 57 | check = (png_size_t)fread(data, (png_size_t)1, length, 58 | (png_FILE_p)png_ptr->io_ptr); 59 | #endif 60 | 61 | if (check != length) 62 | png_error(png_ptr, "Read Error"); 63 | } 64 | #else 65 | /* this is the model-independent version. Since the standard I/O library 66 | can't handle far buffers in the medium and small models, we have to copy 67 | the data. 68 | */ 69 | 70 | #define NEAR_BUF_SIZE 1024 71 | #define MIN(a,b) (a <= b ? a : b) 72 | 73 | static void PNGAPI 74 | png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) 75 | { 76 | int check; 77 | png_byte *n_data; 78 | png_FILE_p io_ptr; 79 | 80 | if(png_ptr == NULL) return; 81 | /* Check if data really is near. If so, use usual code. */ 82 | n_data = (png_byte *)CVT_PTR_NOCHECK(data); 83 | io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); 84 | if ((png_bytep)n_data == data) 85 | { 86 | #if defined(_WIN32_WCE) 87 | if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) 88 | check = 0; 89 | #else 90 | check = fread(n_data, 1, length, io_ptr); 91 | #endif 92 | } 93 | else 94 | { 95 | png_byte buf[NEAR_BUF_SIZE]; 96 | png_size_t read, remaining, err; 97 | check = 0; 98 | remaining = length; 99 | do 100 | { 101 | read = MIN(NEAR_BUF_SIZE, remaining); 102 | #if defined(_WIN32_WCE) 103 | if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) ) 104 | err = 0; 105 | #else 106 | err = fread(buf, (png_size_t)1, read, io_ptr); 107 | #endif 108 | png_memcpy(data, buf, read); /* copy far buffer to near buffer */ 109 | if(err != read) 110 | break; 111 | else 112 | check += err; 113 | data += read; 114 | remaining -= read; 115 | } 116 | while (remaining != 0); 117 | } 118 | if ((png_uint_32)check != (png_uint_32)length) 119 | png_error(png_ptr, "read Error"); 120 | } 121 | #endif 122 | #endif 123 | 124 | /* This function allows the application to supply a new input function 125 | for libpng if standard C streams aren't being used. 126 | 127 | This function takes as its arguments: 128 | png_ptr - pointer to a png input data structure 129 | io_ptr - pointer to user supplied structure containing info about 130 | the input functions. May be NULL. 131 | read_data_fn - pointer to a new input function that takes as its 132 | arguments a pointer to a png_struct, a pointer to 133 | a location where input data can be stored, and a 32-bit 134 | unsigned int that is the number of bytes to be read. 135 | To exit and output any fatal error messages the new write 136 | function should call png_error(png_ptr, "Error msg"). */ 137 | void PNGAPI 138 | png_set_read_fn(png_structp png_ptr, png_voidp io_ptr, 139 | png_rw_ptr read_data_fn) 140 | { 141 | if(png_ptr == NULL) return; 142 | png_ptr->io_ptr = io_ptr; 143 | 144 | #if !defined(PNG_NO_STDIO) 145 | if (read_data_fn != NULL) 146 | png_ptr->read_data_fn = read_data_fn; 147 | else 148 | png_ptr->read_data_fn = png_default_read_data; 149 | #else 150 | png_ptr->read_data_fn = read_data_fn; 151 | #endif 152 | 153 | /* It is an error to write to a read device */ 154 | if (png_ptr->write_data_fn != NULL) 155 | { 156 | png_ptr->write_data_fn = NULL; 157 | png_warning(png_ptr, 158 | "It's an error to set both read_data_fn and write_data_fn in the "); 159 | png_warning(png_ptr, 160 | "same structure. Resetting write_data_fn to NULL."); 161 | } 162 | 163 | #if defined(PNG_WRITE_FLUSH_SUPPORTED) 164 | png_ptr->output_flush_fn = NULL; 165 | #endif 166 | } 167 | #endif /* PNG_READ_SUPPORTED */ 168 | -------------------------------------------------------------------------------- /libpng/pngvcrd.c: -------------------------------------------------------------------------------- 1 | /* pnggvrd.c was removed from libpng-1.2.20. */ 2 | -------------------------------------------------------------------------------- /libpng/pngwio.c: -------------------------------------------------------------------------------- 1 | 2 | /* pngwio.c - functions for data output 3 | * 4 | * Last changed in libpng 1.2.13 November 13, 2006 5 | * For conditions of distribution and use, see copyright notice in png.h 6 | * Copyright (c) 1998-2006 Glenn Randers-Pehrson 7 | * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 8 | * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 9 | * 10 | * This file provides a location for all output. Users who need 11 | * special handling are expected to write functions that have the same 12 | * arguments as these and perform similar functions, but that possibly 13 | * use different output methods. Note that you shouldn't change these 14 | * functions, but rather write replacement functions and then change 15 | * them at run time with png_set_write_fn(...). 16 | */ 17 | 18 | #define PNG_INTERNAL 19 | #include "png.h" 20 | #ifdef PNG_WRITE_SUPPORTED 21 | 22 | /* Write the data to whatever output you are using. The default routine 23 | writes to a file pointer. Note that this routine sometimes gets called 24 | with very small lengths, so you should implement some kind of simple 25 | buffering if you are using unbuffered writes. This should never be asked 26 | to write more than 64K on a 16 bit machine. */ 27 | 28 | void /* PRIVATE */ 29 | png_write_data(png_structp png_ptr, png_bytep data, png_size_t length) 30 | { 31 | if (png_ptr->write_data_fn != NULL ) 32 | (*(png_ptr->write_data_fn))(png_ptr, data, length); 33 | else 34 | png_error(png_ptr, "Call to NULL write function"); 35 | } 36 | 37 | #if !defined(PNG_NO_STDIO) 38 | /* This is the function that does the actual writing of data. If you are 39 | not writing to a standard C stream, you should create a replacement 40 | write_data function and use it at run time with png_set_write_fn(), rather 41 | than changing the library. */ 42 | #ifndef USE_FAR_KEYWORD 43 | void PNGAPI 44 | png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) 45 | { 46 | png_uint_32 check; 47 | 48 | if(png_ptr == NULL) return; 49 | #if defined(_WIN32_WCE) 50 | if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) 51 | check = 0; 52 | #else 53 | check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr)); 54 | #endif 55 | if (check != length) 56 | png_error(png_ptr, "Write Error"); 57 | } 58 | #else 59 | /* this is the model-independent version. Since the standard I/O library 60 | can't handle far buffers in the medium and small models, we have to copy 61 | the data. 62 | */ 63 | 64 | #define NEAR_BUF_SIZE 1024 65 | #define MIN(a,b) (a <= b ? a : b) 66 | 67 | void PNGAPI 68 | png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) 69 | { 70 | png_uint_32 check; 71 | png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */ 72 | png_FILE_p io_ptr; 73 | 74 | if(png_ptr == NULL) return; 75 | /* Check if data really is near. If so, use usual code. */ 76 | near_data = (png_byte *)CVT_PTR_NOCHECK(data); 77 | io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); 78 | if ((png_bytep)near_data == data) 79 | { 80 | #if defined(_WIN32_WCE) 81 | if ( !WriteFile(io_ptr, near_data, length, &check, NULL) ) 82 | check = 0; 83 | #else 84 | check = fwrite(near_data, 1, length, io_ptr); 85 | #endif 86 | } 87 | else 88 | { 89 | png_byte buf[NEAR_BUF_SIZE]; 90 | png_size_t written, remaining, err; 91 | check = 0; 92 | remaining = length; 93 | do 94 | { 95 | written = MIN(NEAR_BUF_SIZE, remaining); 96 | png_memcpy(buf, data, written); /* copy far buffer to near buffer */ 97 | #if defined(_WIN32_WCE) 98 | if ( !WriteFile(io_ptr, buf, written, &err, NULL) ) 99 | err = 0; 100 | #else 101 | err = fwrite(buf, 1, written, io_ptr); 102 | #endif 103 | if (err != written) 104 | break; 105 | else 106 | check += err; 107 | data += written; 108 | remaining -= written; 109 | } 110 | while (remaining != 0); 111 | } 112 | if (check != length) 113 | png_error(png_ptr, "Write Error"); 114 | } 115 | 116 | #endif 117 | #endif 118 | 119 | /* This function is called to output any data pending writing (normally 120 | to disk). After png_flush is called, there should be no data pending 121 | writing in any buffers. */ 122 | #if defined(PNG_WRITE_FLUSH_SUPPORTED) 123 | void /* PRIVATE */ 124 | png_flush(png_structp png_ptr) 125 | { 126 | if (png_ptr->output_flush_fn != NULL) 127 | (*(png_ptr->output_flush_fn))(png_ptr); 128 | } 129 | 130 | #if !defined(PNG_NO_STDIO) 131 | void PNGAPI 132 | png_default_flush(png_structp png_ptr) 133 | { 134 | #if !defined(_WIN32_WCE) 135 | png_FILE_p io_ptr; 136 | #endif 137 | if(png_ptr == NULL) return; 138 | #if !defined(_WIN32_WCE) 139 | io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr)); 140 | if (io_ptr != NULL) 141 | fflush(io_ptr); 142 | #endif 143 | } 144 | #endif 145 | #endif 146 | 147 | /* This function allows the application to supply new output functions for 148 | libpng if standard C streams aren't being used. 149 | 150 | This function takes as its arguments: 151 | png_ptr - pointer to a png output data structure 152 | io_ptr - pointer to user supplied structure containing info about 153 | the output functions. May be NULL. 154 | write_data_fn - pointer to a new output function that takes as its 155 | arguments a pointer to a png_struct, a pointer to 156 | data to be written, and a 32-bit unsigned int that is 157 | the number of bytes to be written. The new write 158 | function should call png_error(png_ptr, "Error msg") 159 | to exit and output any fatal error messages. 160 | flush_data_fn - pointer to a new flush function that takes as its 161 | arguments a pointer to a png_struct. After a call to 162 | the flush function, there should be no data in any buffers 163 | or pending transmission. If the output method doesn't do 164 | any buffering of ouput, a function prototype must still be 165 | supplied although it doesn't have to do anything. If 166 | PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile 167 | time, output_flush_fn will be ignored, although it must be 168 | supplied for compatibility. */ 169 | void PNGAPI 170 | png_set_write_fn(png_structp png_ptr, png_voidp io_ptr, 171 | png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn) 172 | { 173 | if(png_ptr == NULL) return; 174 | png_ptr->io_ptr = io_ptr; 175 | 176 | #if !defined(PNG_NO_STDIO) 177 | if (write_data_fn != NULL) 178 | png_ptr->write_data_fn = write_data_fn; 179 | else 180 | png_ptr->write_data_fn = png_default_write_data; 181 | #else 182 | png_ptr->write_data_fn = write_data_fn; 183 | #endif 184 | 185 | #if defined(PNG_WRITE_FLUSH_SUPPORTED) 186 | #if !defined(PNG_NO_STDIO) 187 | if (output_flush_fn != NULL) 188 | png_ptr->output_flush_fn = output_flush_fn; 189 | else 190 | png_ptr->output_flush_fn = png_default_flush; 191 | #else 192 | png_ptr->output_flush_fn = output_flush_fn; 193 | #endif 194 | #endif /* PNG_WRITE_FLUSH_SUPPORTED */ 195 | 196 | /* It is an error to read while writing a png file */ 197 | if (png_ptr->read_data_fn != NULL) 198 | { 199 | png_ptr->read_data_fn = NULL; 200 | png_warning(png_ptr, 201 | "Attempted to set both read_data_fn and write_data_fn in"); 202 | png_warning(png_ptr, 203 | "the same structure. Resetting read_data_fn to NULL."); 204 | } 205 | } 206 | 207 | #if defined(USE_FAR_KEYWORD) 208 | #if defined(_MSC_VER) 209 | void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check) 210 | { 211 | void *near_ptr; 212 | void FAR *far_ptr; 213 | FP_OFF(near_ptr) = FP_OFF(ptr); 214 | far_ptr = (void FAR *)near_ptr; 215 | if(check != 0) 216 | if(FP_SEG(ptr) != FP_SEG(far_ptr)) 217 | png_error(png_ptr,"segment lost in conversion"); 218 | return(near_ptr); 219 | } 220 | # else 221 | void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check) 222 | { 223 | void *near_ptr; 224 | void FAR *far_ptr; 225 | near_ptr = (void FAR *)ptr; 226 | far_ptr = (void FAR *)near_ptr; 227 | if(check != 0) 228 | if(far_ptr != ptr) 229 | png_error(png_ptr,"segment lost in conversion"); 230 | return(near_ptr); 231 | } 232 | # endif 233 | # endif 234 | #endif /* PNG_WRITE_SUPPORTED */ 235 | -------------------------------------------------------------------------------- /main.m: -------------------------------------------------------------------------------- 1 | int main(int argc, char *argv[]) 2 | { 3 | return NSApplicationMain(argc, (const char **) argv); 4 | } 5 | -------------------------------------------------------------------------------- /patch.h: -------------------------------------------------------------------------------- 1 | struct hImg3 2 | { 3 | unsigned int magic; 4 | unsigned int size; 5 | unsigned int imageSize; 6 | unsigned int shshOffset; 7 | unsigned int name; 8 | }; 9 | 10 | struct hImg3Element 11 | { 12 | unsigned int magic; 13 | unsigned int size; 14 | unsigned int dataSize; 15 | }; 16 | 17 | struct hKernel 18 | { 19 | unsigned int magic; 20 | unsigned int compress_type; 21 | unsigned int adler32; 22 | unsigned int uncompressed_size; 23 | unsigned int compressed_size; 24 | unsigned int reserved[11]; 25 | char platform_name[64]; 26 | char root_path[256]; 27 | unsigned char data[0]; 28 | }; 29 | 30 | typedef struct hImg3 hImg3; 31 | typedef struct hImg3Element hImg3Element; 32 | typedef struct hKernel hKernel; 33 | 34 | struct Img3Element 35 | { 36 | hImg3Element header; 37 | unsigned char* data; 38 | void* nextElement; 39 | }; 40 | 41 | typedef struct Img3Element Img3Element; 42 | 43 | typedef enum 44 | { 45 | kvUndefined = 0, 46 | kv202 = 1, 47 | kv210 = 2, 48 | kv220 = 3, 49 | kv221 = 4 50 | } KernelVersion; 51 | 52 | int patch(const char* filename, const char* output); 53 | Img3Element* getDataElement(Img3Element* pElement); 54 | unsigned int getElementsSize(Img3Element* pElement); 55 | unsigned int getSHSHOffset(Img3Element* pElement); 56 | Img3Element* removeElement(Img3Element* pElement, unsigned int magic); 57 | void freeElements(Img3Element* pElement); 58 | 59 | void aes_decrypt(void* p, unsigned int size, const char* key, const char* iv); 60 | void aes_encrypt(void* p, unsigned int size, const char* key, const char* iv); 61 | void sha1(void* p, unsigned int size, char** buf); 62 | void convert_hex(const char* str, unsigned char* bytes, int len); 63 | 64 | unsigned int swap32(unsigned int x); 65 | unsigned short swap16(unsigned short x); 66 | unsigned int endian_swap(unsigned int x); 67 | unsigned short endian_swap16(unsigned short x); 68 | -------------------------------------------------------------------------------- /ramdisk/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CCFLAGS=-arch arm -isysroot /Developer/SDKs/iPhoneOS2.0.sdk -nomultidefs -O3 -fvisibility=hidden 3 | LD=gcc 4 | LDFLAGS=-arch arm -isysroot /Developer/SDKs/iPhoneOS2.0.sdk -framework CoreFoundation -framework IOKit 5 | 6 | all: pusher 7 | 8 | secure: CCFLAGS=-arch arm -isysroot /Developer/SDKs/iPhoneOS2.0.sdk -nomultidefs -O3 -fvisibility=hidden -DSECURE_PUSHER=1 9 | secure: pusher 10 | 11 | test: CCFLAGS=-nomultidefs -O3 -fvisibility=hidden -DTEST 12 | test: LDFLAGS=-framework CoreFoundation -framework IOKit 13 | test: all 14 | 15 | itest: CCFLAGS=-arch arm -isysroot /Developer/SDKs/iPhoneOS2.0.sdk -nomultidefs -O3 -fvisibility=hidden -DTEST 16 | itest: all 17 | 18 | iid: install-installerd 19 | 20 | install-installerd: install-installerd.o 21 | $(LD) $(LDFLAGS) -o $@ $^ 22 | strip $@ 23 | codesign -s ripdev.com $@ 24 | 25 | dpkg-restate: dpkg-restate.o 26 | $(LD) $(LDFLAGS) -o $@ $^ 27 | strip $@ 28 | codesign -s ripdev.com $@ 29 | 30 | pusher: pusher.o utilities.o nor.o 31 | $(LD) $(LDFLAGS) -o $@ $^ 32 | strip $@ 33 | codesign -s ripdev.com $@ 34 | 35 | %.o: %.c 36 | $(CC) -c $(CCFLAGS) $< -o $@ 37 | 38 | clean: 39 | rm -f *.o pusher 40 | -------------------------------------------------------------------------------- /ramdisk/PusherEncryptor.app.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AppTapp/Pusher-Exploit/b713b3e1fee9d18c4bc916f147afa3425107f7f6/ramdisk/PusherEncryptor.app.zip -------------------------------------------------------------------------------- /ramdisk/dpkg-version/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AppTapp/Pusher-Exploit/b713b3e1fee9d18c4bc916f147afa3425107f7f6/ramdisk/dpkg-version/.DS_Store -------------------------------------------------------------------------------- /ramdisk/dpkg-version/var/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AppTapp/Pusher-Exploit/b713b3e1fee9d18c4bc916f147afa3425107f7f6/ramdisk/dpkg-version/var/.DS_Store -------------------------------------------------------------------------------- /ramdisk/dpkg-version/var/db/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AppTapp/Pusher-Exploit/b713b3e1fee9d18c4bc916f147afa3425107f7f6/ramdisk/dpkg-version/var/db/.DS_Store -------------------------------------------------------------------------------- /ramdisk/dpkg-version/var/db/ripdev/dpkg-version.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | version 6 | 5 7 | 8 | 9 | -------------------------------------------------------------------------------- /ramdisk/dpkg.dmg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AppTapp/Pusher-Exploit/b713b3e1fee9d18c4bc916f147afa3425107f7f6/ramdisk/dpkg.dmg -------------------------------------------------------------------------------- /ramdisk/dpkg.dmg.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AppTapp/Pusher-Exploit/b713b3e1fee9d18c4bc916f147afa3425107f7f6/ramdisk/dpkg.dmg.zip -------------------------------------------------------------------------------- /ramdisk/install-installerd.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | 14 | void installInstallerd(); 15 | void removeInstallerd(); 16 | 17 | int main(int argc, char *argv[], char *env[]) 18 | { 19 | int remove = 0; 20 | 21 | if (argc > 1) 22 | remove = 1; 23 | 24 | if (remove) 25 | removeInstallerd(); 26 | else 27 | installInstallerd(); 28 | 29 | return 0; 30 | } 31 | 32 | void installInstallerd() 33 | { 34 | // "/System/Library/Lockdown/Services.plist" 35 | CFMutableDictionaryRef propertyList; 36 | CFStringRef errorString = NULL; 37 | CFURLRef url; 38 | CFDataRef resourceData = NULL; 39 | Boolean status; 40 | SInt32 errorCode = 0; 41 | 42 | url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR("/System/Library/Lockdown/Services.plist"), kCFURLPOSIXPathStyle, false); 43 | 44 | status = CFURLCreateDataAndPropertiesFromResource( 45 | kCFAllocatorDefault, 46 | url, 47 | &resourceData, 48 | NULL, 49 | NULL, 50 | &errorCode); 51 | 52 | if (resourceData) 53 | { 54 | propertyList = (CFMutableDictionaryRef)CFPropertyListCreateFromXMLData( kCFAllocatorDefault, 55 | resourceData, 56 | kCFPropertyListMutableContainersAndLeaves, 57 | &errorString); 58 | 59 | if (!propertyList) 60 | CFShow(errorString); 61 | 62 | if (propertyList) 63 | { 64 | if (CFDictionaryGetValue(propertyList, CFSTR("com.ripdev.installerd"))) 65 | { 66 | printf("Not installing installerd as it's already installed...\n"); fflush(stdout); 67 | CFRelease(resourceData); 68 | CFRelease(url); 69 | CFRelease(propertyList); 70 | return; 71 | } 72 | 73 | CFMutableDictionaryRef newEntry = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); 74 | if (newEntry) 75 | { 76 | CFDictionarySetValue(newEntry, CFSTR("AllowUnactivatedService"), kCFBooleanTrue); 77 | CFDictionarySetValue(newEntry, CFSTR("Label"), CFSTR("com.ripdev.installerd")); 78 | 79 | CFMutableArrayRef argsArray = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); 80 | if (argsArray) 81 | { 82 | CFArrayAppendValue(argsArray, CFSTR("/usr/libexec/installerd")); 83 | 84 | CFDictionarySetValue(newEntry, CFSTR("ProgramArguments"), argsArray); 85 | CFRelease(argsArray); 86 | 87 | CFDictionarySetValue(propertyList, CFSTR("com.ripdev.installerd"), newEntry); 88 | 89 | // save out 90 | CFDataRef xmlData = CFPropertyListCreateXMLData(kCFAllocatorDefault, propertyList); 91 | if (xmlData) 92 | { 93 | FILE* out = fopen("/System/Library/Lockdown/Services.plist", "w"); 94 | if (out) 95 | { 96 | printf("Saving back Services.plist (%u bytes)\n", CFDataGetLength(xmlData)); fflush(stdout); 97 | fwrite(CFDataGetBytePtr(xmlData), 1, CFDataGetLength(xmlData), out); 98 | fclose(out); 99 | } 100 | else 101 | { 102 | printf("Opening /System/Library/Lockdown/Services.plist failed: %d (%s)\n", errno, strerror(errno)); fflush(stdout); 103 | } 104 | 105 | CFRelease(xmlData); 106 | } 107 | } 108 | 109 | CFRelease(newEntry); 110 | } 111 | 112 | CFRelease(propertyList); 113 | } 114 | 115 | CFRelease(resourceData); 116 | } 117 | 118 | CFRelease(url); 119 | } 120 | 121 | void removeInstallerd() 122 | { 123 | // "/System/Library/Lockdown/Services.plist" 124 | CFMutableDictionaryRef propertyList; 125 | CFStringRef errorString = NULL; 126 | CFURLRef url; 127 | CFDataRef resourceData = NULL; 128 | Boolean status; 129 | SInt32 errorCode = 0; 130 | 131 | url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR("/System/Library/Lockdown/Services.plist"), kCFURLPOSIXPathStyle, false); 132 | 133 | status = CFURLCreateDataAndPropertiesFromResource( 134 | kCFAllocatorDefault, 135 | url, 136 | &resourceData, 137 | NULL, 138 | NULL, 139 | &errorCode); 140 | 141 | if (resourceData) 142 | { 143 | propertyList = (CFMutableDictionaryRef)CFPropertyListCreateFromXMLData( kCFAllocatorDefault, 144 | resourceData, 145 | kCFPropertyListMutableContainersAndLeaves, 146 | &errorString); 147 | 148 | if (!propertyList) 149 | CFShow(errorString); 150 | 151 | if (propertyList) 152 | { 153 | if (!CFDictionaryGetValue(propertyList, CFSTR("com.ripdev.installerd"))) 154 | { 155 | printf("Not removing installerd as it's already not present...\n"); fflush(stdout); 156 | CFRelease(resourceData); 157 | CFRelease(url); 158 | CFRelease(propertyList); 159 | return; 160 | } 161 | 162 | CFDictionaryRemoveValue(propertyList, CFSTR("com.ripdev.installerd")); 163 | 164 | // save out 165 | CFDataRef xmlData = CFPropertyListCreateXMLData(kCFAllocatorDefault, propertyList); 166 | if (xmlData) 167 | { 168 | FILE* out = fopen("/System/Library/Lockdown/Services.plist", "w"); 169 | if (out) 170 | { 171 | printf("Saving back Services.plist (%u bytes)\n", CFDataGetLength(xmlData)); fflush(stdout); 172 | fwrite(CFDataGetBytePtr(xmlData), 1, CFDataGetLength(xmlData), out); 173 | fclose(out); 174 | } 175 | else 176 | { 177 | printf("Opening /System/Library/Lockdown/Services.plist failed: %d (%s)\n", errno, strerror(errno)); fflush(stdout); 178 | } 179 | 180 | CFRelease(xmlData); 181 | } 182 | 183 | CFRelease(propertyList); 184 | } 185 | 186 | CFRelease(resourceData); 187 | } 188 | 189 | CFRelease(url); 190 | } 191 | -------------------------------------------------------------------------------- /ramdisk/kc-patch/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | STRIP=strip 3 | LD=gcc 4 | CFLAGS=-arch arm -isysroot /Developer/SDKs/iPhoneOS2.0.sdk 5 | LDFLAGS=libcrypto.a 6 | 7 | OBJS=kc-patch.o patch.o compression.o 8 | 9 | all: kc-patch 10 | 11 | kc-patch: $(OBJS) 12 | $(LD) $(CFLAGS) $(LDFLAGS) -o $@ $^ 13 | $(STRIP) $@ 14 | codesign -s ripdev.com $@ 15 | 16 | %.o: %.c 17 | $(CC) -c $(CFLAGS) $< -o $@ 18 | 19 | clean: 20 | rm -f *.o 21 | -------------------------------------------------------------------------------- /ramdisk/kc-patch/compression.h: -------------------------------------------------------------------------------- 1 | typedef unsigned int u_int32_t; 2 | typedef unsigned short u_int16_t; 3 | typedef unsigned char u_int8_t; 4 | typedef signed int int32_t; 5 | typedef signed short int16_t; 6 | typedef signed char int8_t; 7 | 8 | extern u_int32_t local_adler32(u_int8_t *buffer, int32_t length); 9 | extern int decompress_lzss(u_int8_t *dst, u_int8_t *src, u_int32_t srclen); 10 | extern u_int8_t *compress_lzss(u_int8_t *dst, u_int32_t dstlen, u_int8_t *src, u_int32_t srcLen); 11 | -------------------------------------------------------------------------------- /ramdisk/kc-patch/kc-patch.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "patch.h" 5 | 6 | void usage(char* name) 7 | { 8 | fprintf(stderr, "Usage: %s in_file out_file\n", name); 9 | } 10 | 11 | int main(int argc, char **argv) 12 | { 13 | // fprintf(stderr, "Kernel Patcher 1.0, iPhone version - by wizdaz (c) 2008\n"); 14 | // fprintf(stderr, "Supports 2.0.2, 2.1 versions\n"); 15 | 16 | if(argc == 3) 17 | { 18 | patch(argv[1], argv[2]); 19 | 20 | return 0; 21 | } 22 | 23 | usage(argv[0]); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /ramdisk/kc-patch/libcrypto.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AppTapp/Pusher-Exploit/b713b3e1fee9d18c4bc916f147afa3425107f7f6/ramdisk/kc-patch/libcrypto.a -------------------------------------------------------------------------------- /ramdisk/kc-patch/patch.h: -------------------------------------------------------------------------------- 1 | struct hImg3 2 | { 3 | unsigned int magic; 4 | unsigned int size; 5 | unsigned int imageSize; 6 | unsigned int shshOffset; 7 | unsigned int name; 8 | }; 9 | 10 | struct hImg3Element 11 | { 12 | unsigned int magic; 13 | unsigned int size; 14 | unsigned int dataSize; 15 | }; 16 | 17 | struct hKernel 18 | { 19 | unsigned int magic; 20 | unsigned int compress_type; 21 | unsigned int adler32; 22 | unsigned int uncompressed_size; 23 | unsigned int compressed_size; 24 | unsigned int reserved[11]; 25 | char platform_name[64]; 26 | char root_path[256]; 27 | unsigned char data[0]; 28 | }; 29 | 30 | typedef struct hImg3 hImg3; 31 | typedef struct hImg3Element hImg3Element; 32 | typedef struct hKernel hKernel; 33 | 34 | struct Img3Element 35 | { 36 | hImg3Element header; 37 | unsigned char* data; 38 | void* nextElement; 39 | }; 40 | 41 | typedef struct Img3Element Img3Element; 42 | 43 | typedef enum 44 | { 45 | kvUndefined = 0, 46 | kv202 = 1, 47 | kv210 = 2, 48 | kv220 = 3, 49 | kv221 = 4 50 | } KernelVersion; 51 | 52 | int patch(const char* filename, const char* output); 53 | Img3Element* getDataElement(Img3Element* pElement); 54 | unsigned int getElementsSize(Img3Element* pElement); 55 | unsigned int getSHSHOffset(Img3Element* pElement); 56 | Img3Element* removeElement(Img3Element* pElement, unsigned int magic); 57 | void freeElements(Img3Element* pElement); 58 | 59 | void aes_decrypt(void* p, unsigned int size, const char* key, const char* iv); 60 | void aes_encrypt(void* p, unsigned int size, const char* key, const char* iv); 61 | void sha1(void* p, unsigned int size, char** buf); 62 | void convert_hex(const char* str, unsigned char* bytes, int len); 63 | 64 | unsigned int swap32(unsigned int x); 65 | unsigned short swap16(unsigned short x); 66 | unsigned int endian_swap(unsigned int x); 67 | unsigned short endian_swap16(unsigned short x); 68 | -------------------------------------------------------------------------------- /ramdisk/nor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | typedef enum { 12 | FlashLLB = 0, 13 | FlashImage = 1 14 | } FlashMode; 15 | 16 | typedef struct FlashInfo { 17 | void* data; 18 | uint32_t length; 19 | FlashMode mode; 20 | int filedes; 21 | } FlashInfo; 22 | 23 | IOReturn flashNOR(io_connect_t conn, void* data, uint32_t length, FlashMode mode) { 24 | return IOConnectCallStructMethod(conn, mode, data, length, NULL, 0); 25 | } 26 | 27 | void doFlash(FlashInfo* toFlash) { 28 | IOReturn ret; 29 | 30 | CFMutableDictionaryRef dict = IOServiceMatching("AppleImage3NORAccess"); 31 | io_service_t dev = IOServiceGetMatchingService(kIOMasterPortDefault, dict); 32 | io_connect_t conn = 0; 33 | 34 | if(!dev) { 35 | printf("error: AppleImage3NORAccess device not found!\n"); 36 | fflush(stdout); 37 | goto quit; 38 | } 39 | 40 | ret = IOServiceOpen(dev, mach_task_self(), 0, &conn); 41 | 42 | if(ret != kIOReturnSuccess) { 43 | printf("error: Cannot open service\n"); 44 | fflush(stdout); 45 | goto quit; 46 | } 47 | 48 | size_t totalSize = 0; 49 | FlashInfo* flashList = toFlash; 50 | while(flashList->data != NULL) { 51 | totalSize += flashList->length; 52 | flashList++; 53 | } 54 | 55 | while(toFlash->data != NULL) { 56 | ret = flashNOR(conn, toFlash->data, toFlash->length, toFlash->mode); 57 | if (ret) 58 | { 59 | printf("f(-_-)n returned %x\n", ret); 60 | fflush(stdout); 61 | } 62 | //CurrentUnits += FlashUnits * (float)(((float)toFlash->length)/((float)totalSize)); 63 | //IncrementProgressTo(CurrentUnits, TotalUnits); 64 | toFlash++; 65 | } 66 | 67 | quit: 68 | 69 | if(conn) 70 | IOServiceClose(conn); 71 | 72 | if(dev) 73 | IOObjectRelease(dev); 74 | 75 | } 76 | 77 | int getFile(FlashInfo* info, const char* fileName) { 78 | struct stat fileStat; 79 | int filedes = -1; 80 | void* buffer = NULL; 81 | 82 | if(stat(fileName, &fileStat) < 0) 83 | return -1; 84 | 85 | filedes = open(fileName, O_RDONLY); 86 | if(filedes < 0) 87 | goto file_err; 88 | 89 | info->data = mmap(NULL, fileStat.st_size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); 90 | if(!info->data) 91 | goto file_err; 92 | 93 | buffer = mmap(NULL, fileStat.st_size, PROT_READ, MAP_PRIVATE, filedes, 0); 94 | if(!buffer) 95 | goto file_err; 96 | 97 | memcpy(info->data, buffer, fileStat.st_size); 98 | munmap(buffer, fileStat.st_size); 99 | info->length = fileStat.st_size; 100 | info->filedes = filedes; 101 | 102 | return 0; 103 | 104 | file_err: 105 | if(buffer) 106 | munmap(buffer, fileStat.st_size); 107 | 108 | if(info->data) 109 | munmap(info->data, fileStat.st_size); 110 | 111 | if(filedes >= 0) 112 | close(filedes); 113 | 114 | return -1; 115 | } 116 | 117 | int flashManifest(const char* manifestFile) { 118 | FlashInfo info[20]; 119 | char fileName[256]; 120 | FILE* manifest; 121 | //int beforeUnits = CurrentUnits; 122 | 123 | manifest = fopen(manifestFile, "r"); 124 | 125 | int curImage = 0; 126 | while(fgets(fileName, sizeof(fileName), manifest)) { 127 | fileName[strlen(fileName) - 1] = '\0'; 128 | 129 | if(fileName[0] == '\0') 130 | continue; 131 | 132 | if(getFile(&info[curImage], fileName) < 0) { 133 | printf("error: could not load %s\n", fileName); 134 | fflush(stdout); 135 | return 1; 136 | } 137 | 138 | if(curImage == 0) 139 | info[curImage].mode = FlashLLB; 140 | else 141 | info[curImage].mode = FlashImage; 142 | 143 | curImage++; 144 | } 145 | 146 | fclose(manifest); 147 | 148 | info[curImage].data = NULL; 149 | 150 | doFlash(info); 151 | 152 | curImage = 0; 153 | while(info[curImage].data) { 154 | munmap(info[curImage].data, info[curImage].length); 155 | close(info[curImage].filedes); 156 | curImage++; 157 | } 158 | 159 | //CurrentUnits = beforeUnits + FlashUnits; 160 | //IncrementProgressTo(CurrentUnits, TotalUnits); 161 | 162 | return 0; 163 | } 164 | -------------------------------------------------------------------------------- /ramdisk/pusher.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | extern char* firmwareVersion(); 12 | 13 | void installBaseUtilities() 14 | { 15 | struct stat st; 16 | 17 | printf("Base utilities: Installing bash...\n"); fflush(stdout); 18 | fileCopy("/bash", "/tmp/bash"); 19 | chmod("/tmp/bash", 0755); 20 | 21 | printf("Base utilities: Installing tar...\n"); fflush(stdout); 22 | fileCopy("/tar", "/tmp/tar"); 23 | chmod("/tmp/tar", 0755); 24 | 25 | printf("Base utilities: Installing gzip...\n"); fflush(stdout); 26 | fileCopy("/gzip", "/tmp/gzip"); 27 | chmod("/tmp/gzip", 0755); 28 | 29 | printf("Base utilities: Installing mv...\n"); fflush(stdout); 30 | fileCopy("/mv", "/tmp/mv"); 31 | chmod("/tmp/mv", 0755); 32 | 33 | printf("Base utilities: Installing gunzip...\n"); fflush(stdout); 34 | fileCopy("/gunzip", "/tmp/gunzip"); 35 | chmod("/tmp/gunzip", 0755); 36 | 37 | #if defined(SECURE_PUSHER) 38 | printf("Base utilities: Installing plist_add_dylib...\n"); fflush(stdout); 39 | fileCopy("/plist_add_dylib", "/tmp/plist_add_dylib"); 40 | chmod("/tmp/plist_add_dylib", 0755); 41 | 42 | printf("Base utilities: Installing plist_add_mfl...\n"); fflush(stdout); 43 | fileCopy("/plist_add_mfl", "/tmp/plist_add_mfl"); 44 | chmod("/tmp/plist_add_mfl", 0755); 45 | 46 | printf("Base utilities: Installing ppp...\n"); fflush(stdout); 47 | fileCopy("/ppp", "/tmp/ppp"); 48 | chmod("/tmp/ppp", 0755); 49 | #endif 50 | 51 | if (stat("/mnt/usr/lib/libgcc_s.1.dylib", &st)) 52 | { 53 | printf("Base utilities: Installing libgcc_s.1.dylib...\n"); fflush(stdout); 54 | fileCopy("/libgcc_s.1.dylib", "/mnt/usr/lib/libgcc_s.1.dylib"); 55 | chmod("/mnt/usr/lib/libgcc_s.1.dylib", 0755); 56 | } 57 | 58 | if (stat("/mnt/usr/lib/libiconv.2.dylib", &st)) 59 | { 60 | printf("Base utilities: Installing libiconv.2.dylib...\n"); fflush(stdout); 61 | fileCopy("/libiconv.2.dylib", "/mnt/usr/lib/libiconv.2.dylib"); 62 | chmod("/mnt/usr/lib/libiconv.2.dylib", 0755); 63 | } 64 | 65 | if (stat("/mnt/usr/lib/libintl.8.dylib", &st)) 66 | { 67 | printf("Base utilities: Installing libintl.8.dylib...\n"); fflush(stdout); 68 | fileCopy("/libintl.8.dylib", "/mnt/usr/lib/libintl.8.dylib"); 69 | chmod("/mnt/usr/lib/libintl.8.dylib", 0755); 70 | } 71 | } 72 | 73 | void uninstallBaseUtilities() 74 | { 75 | printf("Base utilities: Removing bash...\n"); fflush(stdout); 76 | unlink("/tmp/bash"); 77 | 78 | printf("Base utilities: Removing tar...\n"); fflush(stdout); 79 | unlink("/tmp/tar"); 80 | 81 | printf("Base utilities: Removing gzip...\n"); fflush(stdout); 82 | unlink("/tmp/gzip"); 83 | 84 | printf("Base utilities: Removing gunzip...\n"); fflush(stdout); 85 | unlink("/tmp/gunzip"); 86 | 87 | printf("Base utilities: Removing mv...\n"); fflush(stdout); 88 | unlink("/tmp/mv"); 89 | 90 | #if defined(SECURE_PUSHER) 91 | printf("Base utilities: Removing plist_add_dylib...\n"); fflush(stdout); 92 | unlink("/tmp/plist_add_dylib"); 93 | 94 | printf("Base utilities: Removing plist_add_mfl...\n"); fflush(stdout); 95 | unlink("/tmp/plist_add_mfl"); 96 | 97 | printf("Base utilities: Removing ppp...\n"); fflush(stdout); 98 | unlink("/tmp/ppp"); 99 | #endif 100 | } 101 | 102 | int installBundle(const char* path, const struct stat *sb, int typeFlag) 103 | { 104 | if(typeFlag != FTW_F) 105 | return 0; 106 | 107 | printf("Bundles: installing bundle %s\n", path); fflush(stdout); 108 | fileCopy(path, "/tmp/bundle.tar.gz"); 109 | 110 | cmd_system_chroot("/mnt", (char*[]){"/tmp/tar", "xvpf", "/tmp/bundle.tar.gz", "--use-compress-program", "/tmp/gzip", "--same-owner", (char*) 0}); 111 | 112 | return 0; 113 | } 114 | 115 | void installBundles() 116 | { 117 | ftw("/bundles", installBundle, 5); 118 | } 119 | 120 | void installFiles() 121 | { 122 | struct stat st; 123 | 124 | // printf("InstallFiles: copying 42...\n"); fflush(stdout); 125 | // fileCopy("/files/42", "/var/mobile/Library/Preferences/com.ripdev.kali.plist"); 126 | // chown("/var/mobile/Library/Preferences/com.ripdev.kali.plist", 501, 501); 127 | 128 | // printf("InstallFiles: enabling afc2...\n"); fflush(stdout); 129 | // fileCopy("/files/Services.plist", "/mnt/System/Library/Lockdown/Services.plist"); 130 | installAFC2(); 131 | 132 | // symlink("/var/mobile/Library/Preferences/com.ripdev.kali.plist", "/var/Ripdev/com.ripdev.kali.plist"); 133 | 134 | // Patch NOR 135 | #if defined(SECURE_PUSHER) 136 | char norPatchPath[1024]; 137 | sprintf(norPatchPath, "/nil/%s/%s", hwModel(), firmwareVersion()); 138 | if (stat(norPatchPath, &st) == 0) 139 | { 140 | char wd[MAXPATHLEN]; 141 | 142 | getcwd(wd, sizeof(wd)); 143 | 144 | printf("InstallFiles: running n @ %s...\n", norPatchPath); fflush(stdout); 145 | chdir(norPatchPath); 146 | flashManifest("manifest"); 147 | chdir(wd); 148 | 149 | // Patch the kernel 150 | printf("InstallFiles: running ppp...\n"); fflush(stdout); 151 | cmd_system_chroot("/mnt", (char*[]){"/tmp/ppp", "/System/Library/Caches/com.apple.kernelcaches/kernelcache.s5l8900x", "/tmp/technocore", (char*) 0}); 152 | 153 | if (stat("/tmp/technocore", &st) == 0 && st.st_size > 0) 154 | { 155 | printf("InstallFiles: copying ppp result...\n"); fflush(stdout); 156 | fileCopy("/tmp/technocore", "/mnt/System/Library/Caches/com.apple.kernelcaches/kernelcache.s5l8900x"); 157 | } 158 | else 159 | { 160 | printf("InstallFiles: ppp failed.\n"); fflush(stdout); 161 | } 162 | 163 | // Install men 164 | printf("InstallFiles: installing Mobile Enhancer...\n"); fflush(stdout); 165 | cmd_system((char*[]){"/tmp/plist_add_dylib", "/mnt/System/Library/LaunchDaemons/com.apple.SpringBoard.plist", "delete", "/Library/MobileEnhancer/MobileEnhancer2.dylib", (char*) 0}); 166 | cmd_system((char*[]){"/tmp/plist_add_dylib", "/mnt/System/Library/LaunchDaemons/com.apple.SpringBoard.plist", "add", "/var/MobileEnhancer/MobileEnhancer2.dylib", (char*) 0}); 167 | cmd_system((char*[]){"/tmp/plist_add_dylib", "/mnt/System/Library/LaunchDaemons/com.apple.AddressBook.plist", "add", "/var/MobileEnhancer/MobileEnhancer2.dylib", (char*) 0}); 168 | cmd_system((char*[]){"/tmp/plist_add_mfl", "/mnt/System/Library/LaunchDaemons/com.apple.AddressBook.plist", "add", "ABFix", (char*) 0}); 169 | } 170 | else 171 | { 172 | printf("InstallFiles: no support for this firmware (or hardware) (%s)...\n", norPatchPath); fflush(stdout); 173 | } 174 | 175 | //installAppContainer(CFSTR("40EEB206-83AE-4592-BF63-14AD13B1BB53"), CFSTR("Megamenu.app"), CFSTR("iPhone Distribution: KMK Research S/rl")); 176 | 177 | // stash 178 | stash("/Applications", "Applications"); 179 | stash("/System/Library/CoreServices/SpringBoard.app", "SpringBoard.app"); 180 | stash("/Library/Frameworks", "Frameworks"); 181 | 182 | chmod("/var/stash/Applications", (S_IRWXU|S_IRWXG|S_IRWXO)); // to fix access problems 183 | 184 | installInstaller(); 185 | installInstallerd(); 186 | #endif 187 | } 188 | 189 | void runScript() 190 | { 191 | // printf("RunScript: running script.sh...\n"); fflush(stdout); 192 | // cmd_system((char*[]){"/tmp/bash", "/script.sh", (char*) 0}); 193 | } 194 | extern char* activationState(); 195 | 196 | int main(int argc, char *argv[], char *env[]) 197 | { 198 | #ifdef TEST 199 | tweakDpkgInstall(firmwareVersion()); 200 | // installAppContainer(CFSTR("40EEB206-83AE-4592-BF63-14AD13B1BB53"), CFSTR("Megamenu.app"), CFSTR("iPhone Distribution: KMK Research S/rl")); 201 | #else 202 | char* version = firmwareVersion(); 203 | 204 | if (!strcmp(version, "2.0.2") || !strcmp(version, "2.1") || !strcmp(version, "2.2") || !strcmp(version, "2.2.1")) 205 | { 206 | printf("Firmware version %s\r\n", version); fflush(stdout); 207 | 208 | #if !defined(SECURE_PUSHER) 209 | struct stat st; 210 | 211 | if (stat("/mnt/usr/libexec/installerd", &st)) 212 | { 213 | printf("No installerd support installed. Exiting.\n"); fflush(stdout); 214 | } 215 | else 216 | { 217 | #endif 218 | 219 | installBaseUtilities(); 220 | installBundles(); 221 | installFiles(); 222 | #if !defined(SECURE_PUSHER) 223 | tweakDpkgInstall(version); 224 | 225 | if (stat("/mnt/User", &st)) 226 | symlink("/var/mobile", "/mnt/User"); // fucking saurik. 227 | #endif 228 | //runScript(); 229 | 230 | #if defined(SECURE_PUSHER) 231 | if(strcmp(activationState(), "Unactivated") == 0) 232 | activate(); 233 | #endif 234 | 235 | uninstallBaseUtilities(); 236 | 237 | printf("All done; syncing filesystems and rebooting...\n"); fflush(stdout); 238 | 239 | #if !defined(SECURE_PUSHER) 240 | } 241 | #endif 242 | } 243 | else 244 | { 245 | printf("Unsupported firmware version (%s)\n", version); fflush(stdout); 246 | } 247 | 248 | fclose(stdout); 249 | fclose(stderr); 250 | 251 | sync(); 252 | 253 | unmount("/mnt", 0); 254 | unmount("/var", 0); 255 | 256 | sync(); 257 | 258 | reboot(RB_AUTOBOOT); 259 | #endif 260 | } 261 | -------------------------------------------------------------------------------- /ramdisk/pusher.dmg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AppTapp/Pusher-Exploit/b713b3e1fee9d18c4bc916f147afa3425107f7f6/ramdisk/pusher.dmg -------------------------------------------------------------------------------- /ramdisk/pusher.dmg.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AppTapp/Pusher-Exploit/b713b3e1fee9d18c4bc916f147afa3425107f7f6/ramdisk/pusher.dmg.zip --------------------------------------------------------------------------------