Class: ReadIpa::IpaFile

Inherits:
Object
  • Object
show all
Defined in:
lib/read_ipa.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ IpaFile

Returns a new instance of IpaFile.



15
16
17
18
19
20
21
22
# File 'lib/read_ipa.rb', line 15

def initialize(file_path)
  self.file_path = file_path
  @app_folder = Zip::ZipFile.foreach(file_path).find { |e| /.*\.app\/Info\.plist$/ =~ e.to_s }.to_s.gsub(/Info\.plist$/, '')
  @zipfile = Zip::ZipFile.open(file_path)

  cf_plist = CFPropertyList::List.new(data: @zipfile.read(@app_folder + "Info.plist"), format: CFPropertyList::List::FORMAT_AUTO)
  self.plist = cf_plist.value.to_rb
end

Instance Attribute Details

#file_pathObject

Returns the value of attribute file_path.



14
15
16
# File 'lib/read_ipa.rb', line 14

def file_path
  @file_path
end

#plistObject

Returns the value of attribute plist.



14
15
16
# File 'lib/read_ipa.rb', line 14

def plist
  @plist
end

Instance Method Details

#bundle_identifierObject



106
107
108
# File 'lib/read_ipa.rb', line 106

def bundle_identifier
  plist["CFBundleIdentifier"]
end

#executable_fileObject



98
99
100
# File 'lib/read_ipa.rb', line 98

def executable_file
  read_file(executable_file_name)
end

#executable_file_nameObject



94
95
96
# File 'lib/read_ipa.rb', line 94

def executable_file_name
  plist["CFBundleExecutable"]
end

#find_existing_path(icon_path) ⇒ Object



127
128
129
130
131
# File 'lib/read_ipa.rb', line 127

def find_existing_path(icon_path)
  without_extension = icon_path.gsub(/\.png$/i, '')
  regex = /#{Regexp.quote(@app_folder)}#{Regexp.quote(without_extension)}[(\.png)@~]/
  @zipfile.entries.find{|e| e.name =~ regex}
end

#for_ipad?Boolean

Returns:

  • (Boolean)


114
115
116
117
118
# File 'lib/read_ipa.rb', line 114

def for_ipad?
  return true if plist["UIDeviceFamily"] && (plist["UIDeviceFamily"] == 2 || plist["UIDeviceFamily"].include?(2))
  return true if plist["UIDeviceFamily"] && (plist["UIDeviceFamily"] == "2" || plist["UIDeviceFamily"].include?("2"))
  return false
end

#for_iphone?Boolean

Returns:

  • (Boolean)


120
121
122
123
124
125
# File 'lib/read_ipa.rb', line 120

def for_iphone?
  return true if !plist["UIDeviceFamily"]
  return true if plist["UIDeviceFamily"] == 1 || plist["UIDeviceFamily"].include?(1)
  return true if plist["UIDeviceFamily"] == "1" || plist["UIDeviceFamily"].include?("1")
  return false
end

#get_highest_res_icon(icons_file_names) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/read_ipa.rb', line 60

def get_highest_res_icon(icons_file_names)
  highest_res_icon = icons_file_names
    .map{ |icon_path| find_existing_path(icon_path) }
    .compact
    .uniq(&:name)
    .map{|entry| entry.get_input_stream.read}
    .max_by{|data| read_png(data).width }

  begin
    return ApplePng.new(highest_res_icon).data
  rescue NotValidApplePngError
    highest_res_icon
  end
end

#icon_fileObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/read_ipa.rb', line 75

def icon_file
  if plist["CFBundleIconFiles"]
    get_highest_res_icon(plist["CFBundleIconFiles"])
  elsif plist["CFBundleIcons"]
    dict = plist["CFBundleIcons"]
    primary_icons = dict["CFBundlePrimaryIcon"]
    return nil unless primary_icons
    icons = primary_icons.to_rb["CFBundleIconFiles"]
    return nil unless icons
    get_highest_res_icon(icons)
  elsif plist["CFBundleIconFile"]
    data = read_file(plist["CFBundleIconFile"])
    png = ApplePng.new(data)
    png.data
  else
    nil
  end
end

#icon_prerenderedObject



110
111
112
# File 'lib/read_ipa.rb', line 110

def icon_prerendered
  plist["UIPrerenderedIcon"] == true
end

#minimum_os_versionObject



40
41
42
# File 'lib/read_ipa.rb', line 40

def minimum_os_version
  plist["MinimumOSVersion"].match(/[\d\.]*/)[0]
end

#mobile_provision_fileObject



102
103
104
# File 'lib/read_ipa.rb', line 102

def mobile_provision_file
  read_file("embedded.mobileprovision")
end

#nameObject



32
33
34
# File 'lib/read_ipa.rb', line 32

def name
  plist["CFBundleDisplayName"]
end

#read_png(data) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/read_ipa.rb', line 52

def read_png(data)
  begin
    return ApplePng.new(data)
  rescue NotValidApplePngError
    return ChunkyPng::Image.from_datastream(ChunkyPNG::Datastream.from_blob(data))
  end
end

#short_versionObject



28
29
30
# File 'lib/read_ipa.rb', line 28

def short_version
  plist["CFBundleShortVersionString"]
end

#target_os_versionObject



36
37
38
# File 'lib/read_ipa.rb', line 36

def target_os_version
  plist["DTPlatformVersion"].match(/[\d\.]*/)[0]
end

#url_schemesObject



44
45
46
47
48
49
50
# File 'lib/read_ipa.rb', line 44

def url_schemes
  if plist["CFBundleURLTypes"] && plist["CFBundleURLTypes"][0] && plist["CFBundleURLTypes"][0]["CFBundleURLSchemes"]
    plist["CFBundleURLTypes"][0]["CFBundleURLSchemes"]
  else
    []
  end
end

#versionObject



24
25
26
# File 'lib/read_ipa.rb', line 24

def version
  plist["CFBundleVersion"]
end