iOS 提取IPA中的图片

脚本代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
pngcrush = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/pngcrush'
destination = File.join(ENV['HOME'], 'Desktop')
ARGV.each do |ipa|
if File.extname(ipa) == '.ipa'
# Get the app name by stripping out the extension from the file name
app_name = File.basename(ipa, ".*")
# Get the expanded dir by stripping out the extension from the file path
expanded_dir = ipa.sub(File.extname(ipa), '')
# In case the dir is already there, try and remove it
system "rm -drf '#{expanded_dir}'"
# Extract .ipa zip file
system "unzip -q '#{ipa}' -d '#{expanded_dir}'"
images_dir_path = File.join(destination, "#{app_name} Images")
# In case the destination directory is already there, try and remove it
system "rm -drf '#{images_dir_path}'"
# Create the destination directory
Dir.mkdir(images_dir_path)
# Iterate through all png images
Dir.glob(File.join(expanded_dir, 'Payload', "*.app", '*.png')).each do |png_file|
# and revert the iphone optimizations
system "#{pngcrush} -q -revert-iphone-optimizations -d '#{images_dir_path}' '#{png_file}'"
end
# Iterate through all jpg images
Dir.glob(File.join(expanded_dir, 'Payload', "*.app", '*.jpg')).each do |jpg_file|
# and move each to the destination directory
system "mv '#{jpg_file}' '#{images_dir_path}'"
end
# Cleanup. Delete the expanded dir
system "rm -drf '#{expanded_dir}'"
end