Method: Android::Apk#initialize

Defined in:
lib/android/apk.rb

#initialize(filepath) ⇒ Apk

create new apk object

Parameters:

  • filepath (String)

    apk file path

Raises:



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
# File 'lib/android/apk.rb', line 39

def initialize(filepath)
  @path = filepath
  raise NotFoundError, "'#{filepath}'" unless File.exist? @path
  begin
    @zip = Zip::File.open(@path)
  rescue Zip::Error => e
    raise NotApkFileError, e.message 
  end

  @bindata = File.open(@path, 'rb') {|f| f.read }
  @bindata.force_encoding(Encoding::ASCII_8BIT)
  raise NotApkFileError, "manifest file is not found." if @zip.find_entry(MANIFEST).nil?
  begin
    @resource = Android::Resource.new(self.file(RESOURCE))
  rescue => e
    $stderr.puts "failed to parse resource:#{e}"
    #$stderr.puts e.backtrace
  end
  begin
    @manifest = Android::Manifest.new(self.file(MANIFEST), @resource)
  rescue => e
    $stderr.puts "failed to parse manifest:#{e}"
    #$stderr.puts e.backtrace
  end
  begin
    @dex = Android::Dex.new(self.file(DEX))
  rescue => e
    $stderr.puts "failed to parse dex:#{e}"
    #$stderr.puts e.backtrace
  end
end