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



104
105
106
# File 'lib/read_ipa.rb', line 104

def bundle_identifier
  plist["CFBundleIdentifier"]
end

#executable_fileObject



96
97
98
# File 'lib/read_ipa.rb', line 96

def executable_file
  read_file(executable_file_name)
end

#executable_file_nameObject



92
93
94
# File 'lib/read_ipa.rb', line 92

def executable_file_name
  plist["CFBundleExecutable"]
end

#for_ipad?Boolean

Returns:

  • (Boolean)


112
113
114
115
116
# File 'lib/read_ipa.rb', line 112

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)


118
119
120
121
122
123
# File 'lib/read_ipa.rb', line 118

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_array) ⇒ Object



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

def get_highest_res_icon(icons_array)
  highest_res_icon = icons_array
    .map{ |icon_path| icon_path.downcase.end_with?('.png') ? icon_path : icon_path + '.png' }
    .map{ |icon_path| read_file(icon_path) }
    .max_by{|data| read_png(data).width }

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

#icon_fileObject



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

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



108
109
110
# File 'lib/read_ipa.rb', line 108

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



100
101
102
# File 'lib/read_ipa.rb', line 100

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(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