Created
February 16, 2011 02:07
-
-
Save jamesdaniels/828721 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'zip' | |
require 'zip/zipfilesystem' | |
require 'openssl' | |
require 'nokogiri' | |
class Ipa | |
attr_accessor :ipa_path, :package_name | |
def initialize(ipa_path) | |
@ipa_path = ipa_path | |
@package_name = Zip::ZipFile.open(ipa_path, 0) {|zip| zip.dir.entries('Payload') }.first | |
end | |
# ProvisioningFile | |
def devices | |
parse_plist( | |
provisioning_file.entries[1] | |
.value.entries[0] | |
.value.entries[2] | |
.value.entries[1] | |
.value.entries[0] | |
.value).xpath("//key[.='ProvisionedDevices']/following-sibling::array") | |
.first.content.split | |
end | |
def provisioning_file | |
@provisioning_file ||= OpenSSL::ASN1.decode read('embedded.mobileprovision') | |
end | |
# Plutil | |
def parse_plist(plist_data) | |
Nokogiri::XML( | |
begin | |
plist = Tempfile.new(package_name) | |
plist.write plist_data | |
plist.rewind | |
%x(plutil -convert xml1 #{plist.path} -o -).strip | |
ensure | |
plist.close | |
plist.unlink | |
end | |
) | |
end | |
# InfoPlist | |
def info_plist | |
@info_plist ||= parse_plist(read('Info.plist')) | |
end | |
def info_plist_key(key) | |
info_plist.xpath("//key[.='#{key}']/following-sibling::string").first.content | |
end | |
def icon_file | |
info_plist_key 'CFBundleIconFile' | |
end | |
def bundle_identifier | |
info_plist_key 'CFBundleIdentifier' | |
end | |
def bundle_display_name | |
info_plist_key 'CFBundleDisplayName' | |
end | |
# Helpers | |
def read(payload_path) | |
Zip::ZipFile.open(ipa_path, 0) {|zip| zip.read("Payload/#{package_name}/#{payload_path}") } | |
end | |
def icon | |
read icon_file | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment