Class: AppPermissionStatistics::Extracter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Helper::Archive, Helper::Sigflat, Helper::Utils
Defined in:
lib/app_permission_statistics/extracter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper::Utils

#defalut_store_path, #entitlements_yaml_name, #report_file_name, #versions_yaml_name

Methods included from Helper::Sigflat

#createsig

Methods included from Helper::Archive

#tempdir, #unarchive

Constructor Details

#initialize(file, store_path = nil) ⇒ Extracter

Returns a new instance of Extracter.



21
22
23
24
# File 'lib/app_permission_statistics/extracter.rb', line 21

def initialize(file, store_path = nil)
    @file = file
    @store_path = store_path
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



18
19
20
# File 'lib/app_permission_statistics/extracter.rb', line 18

def file
  @file
end

#store_pathObject (readonly)

Returns the value of attribute store_path.



19
20
21
# File 'lib/app_permission_statistics/extracter.rb', line 19

def store_path
  @store_path
end

Instance Method Details

#app_pathObject



118
119
120
# File 'lib/app_permission_statistics/extracter.rb', line 118

def app_path
    @app_path ||= Dir.glob(File.join(contents, 'Payload', '*.app')).first
end

#clear!Object



122
123
124
125
126
127
128
129
130
131
132
# File 'lib/app_permission_statistics/extracter.rb', line 122

def clear!
    return unless @contents

    FileUtils.rm_rf(@contents)

    @contents = nil
    @app_path = nil
    @info_path = nil
    @info = nil
    @pre_version = nil
end

#contentsObject



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

def contents
    @contents ||= unarchive(@file, path: 'ios')
end

#entitlements_pathObject



114
115
116
# File 'lib/app_permission_statistics/extracter.rb', line 114

def entitlements_path
    @entitlements_path ||= File.join(app_path, 'Runner.entitlements')
end

#entitlementsInfoObject



86
87
88
# File 'lib/app_permission_statistics/extracter.rb', line 86

def entitlementsInfo
    @entitlementsInfo ||= EntitlementsPlist.new(entitlements_path)
end

#extract_capabilities_infoObject



67
68
69
70
71
72
73
74
# File 'lib/app_permission_statistics/extracter.rb', line 67

def extract_capabilities_info 
    capabilities_info = {}
    capabilities_info["In-App Purchase"] = true
    capabilities_info = capabilities_info.merge(entitlementsInfo.enabled_capabilities)
    capabilities_info = capabilities_info.merge(plistInfo.backgroundModes)
    capabilities_info = capabilities_info.merge(plistInfo.enabled_capabilities)
    capabilities_info
end

#extract_updateObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/app_permission_statistics/extracter.rb', line 26

def extract_update            
    capabilities_summary = Hash.new
    capabilities = extract_capabilities_info
    capabilities.each do |key,value|
        capabilities_summary[key] = createsig(value)
    end
    
    usage_desc_summary = Hash.new
    usage_desc = plistInfo.permis_usagedescription
    usage_desc.each do |key,value|
        usage_desc_summary[key] = createsig(value)
    end
    
    yaml_content = {
        'Capabilities_Summary' => capabilities_summary,
        'Capabilities' => capabilities,
        'PermissionsUsageDescription_Summary' => usage_desc_summary,
        'PermissionsUsageDescription' => usage_desc
    }
    yaml_name = entitlements_yaml_name(plistInfo.version, plistInfo.identifier, path: @store_path)

    File.open(yaml_name, "w") { |file| file.write(yaml_content.to_yaml) }
    update_versions
    yaml_content
end

#info_pathObject



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

def info_path
    @info_path ||= File.join(app_path, 'Info.plist')
end

#mobileprovisionObject



76
77
78
79
80
# File 'lib/app_permission_statistics/extracter.rb', line 76

def mobileprovision
    return unless mobileprovision?
    return @mobileprovision if @mobileprovision
    @mobileprovision = MobileProvision.new(mobileprovision_path)
end

#mobileprovision?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/app_permission_statistics/extracter.rb', line 91

def mobileprovision?
    File.exist?(mobileprovision_path)
end

#mobileprovision_pathObject



95
96
97
98
99
100
101
102
103
# File 'lib/app_permission_statistics/extracter.rb', line 95

def mobileprovision_path
    filename = 'embedded.mobileprovision'
    @mobileprovision_path ||= File.join(@file, filename)
    unless File.exist?(@mobileprovision_path)
        @mobileprovision_path = File.join(app_path, filename)
    end

    @mobileprovision_path
end

#plistInfoObject



82
83
84
# File 'lib/app_permission_statistics/extracter.rb', line 82

def plistInfo
    @plistInfo ||= InfoPlist.new(info_path)
end

#update_versionsObject



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/app_permission_statistics/extracter.rb', line 53

def update_versions
    yaml_name = versions_yaml_name(plistInfo.identifier, path: @store_path)
    yaml_content = [ ]
    if File.exist?(yaml_name) 
        yaml_content = YAML.load_file(yaml_name)
    end
    version = plistInfo.version
    if !yaml_content.include?(version)
        yaml_content.push(version)
        yaml_content.sort{|x,y| y<=>x } unless yaml_content.size < 2
        File.open(yaml_name, "w") { |file| file.write(yaml_content.to_yaml) }  
    end
end