Class: IpaAnalyzer::Analyzer

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

Instance Method Summary collapse

Constructor Details

#initialize(ipa_path) ⇒ Analyzer

Returns a new instance of Analyzer.



8
9
10
11
12
# File 'lib/ipa_analyzer/analyzer.rb', line 8

def initialize(ipa_path)
	@ipa_path = ipa_path
	@ipa_zipfile = nil
	@app_folder_path = nil
end

Instance Method Details

#closeObject



24
25
26
27
28
# File 'lib/ipa_analyzer/analyzer.rb', line 24

def close
	if self.open?
		@ipa_zipfile.close()
	end
end

#collect_info_plist_infoObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/ipa_analyzer/analyzer.rb', line 73

def collect_info_plist_info
	raise "IPA is not open" unless self.open?

	result = {
		path_in_ipa: nil,
		content: {}
	}
	info_plist_entry = @ipa_zipfile.find_entry("#{@app_folder_path}/Info.plist")

	raise "File 'Info.plist' not found in #{@ipa_path}" unless info_plist_entry
	result[:path_in_ipa] = "#{info_plist_entry}"

	tempfile = Tempfile.new(::File.basename(info_plist_entry.name))
	begin
		@ipa_zipfile.extract(info_plist_entry, tempfile.path){ override = true }
		# convert from binary Plist to XML Plist
		unless system("plutil -convert xml1 '#{tempfile.path}'")
			raise "Failed to convert binary Plist to XML"
		end
		plist = Plist::parse_xml(tempfile.path)

		plist.each do |key, value|
			parse_value = nil
			case value
			when Hash
				parse_value = value
			when Array
				parse_value = value
			else
				parse_value = value.to_s
			end

			result[:content][key] = parse_value
		end

	rescue => e
		puts e.message
		result = nil
	ensure
		tempfile.close and tempfile.unlink
	end
	return result
end

#collect_provision_infoObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ipa_analyzer/analyzer.rb', line 30

def collect_provision_info
	raise "IPA is not open" unless self.open?

	result = {
		path_in_ipa: nil,
		content: {}
	}
	mobileprovision_path = "#{@app_folder_path}/embedded.mobileprovision"
	mobileprovision_entry = @ipa_zipfile.find_entry(mobileprovision_path)

	raise "Embedded mobile provisioning file not found in (#{@ipa_path}) at path (#{mobileprovision_path})" unless mobileprovision_entry
	result[:path_in_ipa] = "#{mobileprovision_entry}"

	tempfile = Tempfile.new(::File.basename(mobileprovision_entry.name))
	begin
		@ipa_zipfile.extract(mobileprovision_entry, tempfile.path){ override = true }
		plist = Plist::parse_xml(`security cms -D -i #{tempfile.path}`)

		plist.each do |key, value|
			next if key == "DeveloperCertificates"

			parse_value = nil
			case value
			when Hash
				parse_value = value
			when Array
				parse_value = value
			else
				parse_value = value.to_s
			end

			result[:content][key] = parse_value
		end

	rescue => e
		puts e.message
		result = nil
	ensure
		tempfile.close and tempfile.unlink
	end
	return result
end

#open!Object



14
15
16
17
18
# File 'lib/ipa_analyzer/analyzer.rb', line 14

def open!
	@ipa_zipfile = Zip::File.open(@ipa_path)
	@app_folder_path = find_app_folder_in_ipa()
	raise "No app folder found in the IPA" if @app_folder_path.nil?
end

#open?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/ipa_analyzer/analyzer.rb', line 20

def open?
	return !@ipa_zipfile.nil?
end