├── README.md ├── prepare.rb └── sign.rb /README.md: -------------------------------------------------------------------------------- 1 | # Re-signing a built iOS app 2 | 3 | Investigating bugs that a client of your framework is experiencing can be significantly easier if you're able to 4 | reproduce the issue locally in a debugger. As many clients are rightfully reluctant to share their source code, 5 | debugging a prebuilt binary is the next best step. This repository contains a collection of scripts that can assist 6 | with re-signing a prebuilt iOS application using your own signing identity and provisioning profile. This allows 7 | you to install and run the application on your device, and even to replace your own framework in the app bundle 8 | with a your own copy containing debugging code. 9 | 10 | ## Usage 11 | 12 | Starting with Test.ipa, containing a prebuilt version of Test.app provided by a user: 13 | 14 | 1. `unzip Test.ipa && mv Payload Test` 15 | 2. `cd Test` 16 | 3. `prepare.rb Test.app 38F637AQG5 nz.net.bdash.Test.3P` 17 | 4. `sign.rb Test.app "iPhone Developer: Mark Rowe (RSYL4QFV9U)"` 18 | 19 | After modifying Test.app in any way (e.g., replacing a dynamic framework), re-run step 4. 20 | 21 | Be sure to replace the team ID, bundle ID and signing identity with ones that are valid for your iOS developer account. 22 | 23 | ## Installing or updating a signed app 24 | 25 | In Xcode's Devices window, select your attached iOS device. You can then drag and drop the signed .app into the 26 | Installed Apps section of the window. If an error occurs installing the app you can check the device's system log 27 | in the same window to see a more detailed error message. 28 | -------------------------------------------------------------------------------- /prepare.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'fileutils' 3 | 4 | if ARGV.size < 1 5 | STDERR.puts "usage: prepare.rb App.app [team-identifier] [bundle-id-prefix]" 6 | exit 1 7 | end 8 | 9 | app = ARGV[0] 10 | new_team_identifier = ARGV[1] || "38F637AQG5" 11 | bundle_id_prefix = ARGV[2] || "nz.net.bdash.Test.3P" 12 | 13 | print "Extracting entitlements..." 14 | FileUtils.remove_file "entitlements.plist", true 15 | system("codesign", "-d", "--entitlements=:entitlements.plist", app, :err => :close) or exit 1 16 | puts " Done!" 17 | 18 | print "Extracting team and app identifiers..." 19 | existing_team_identifier=`/usr/libexec/PlistBuddy -c "Print :com.apple.developer.team-identifier" entitlements.plist`.chomp 20 | existing_app_identifier=`/usr/libexec/PlistBuddy -c "Print :application-identifier" entitlements.plist`.chomp 21 | puts " Done!" 22 | 23 | if existing_team_identifier == new_team_identifier 24 | STDERR.puts "#{app} already appears to belong to team #{new_team_identifier}!" 25 | exit 1 26 | end 27 | 28 | existing_bundle_identifier = existing_app_identifier.gsub("#{existing_team_identifier}.", "") 29 | new_bundle_identifier = "#{bundle_id_prefix}.#{existing_bundle_identifier}" 30 | new_app_identifier = existing_app_identifier.gsub(existing_team_identifier, "#{new_team_identifier}.#{bundle_id_prefix}") 31 | 32 | system("plutil", "-convert", "xml1", "#{app}/Info.plist") or exit 1 33 | 34 | print "Updating entitlements to reflect new team identifier..." 35 | system("/usr/libexec/PlistBuddy", "-c", "Set :get-task-allow true", "-c", "Save", "entitlements.plist", :out => :close) or exit 1 36 | system("sed", "-i", "", "-e", "s/#{existing_app_identifier}/#{new_app_identifier}/g", "-e", "s/#{existing_team_identifier}/#{new_team_identifier}/g", "entitlements.plist") or exit 1 37 | puts " Done!" 38 | 39 | print "Updating Info.plist to reflect new bundle identifier..." 40 | system("sed", "-i", "", "-e", "s/>#{existing_bundle_identifier}#{new_bundle_identifier}