apktools 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -316,6 +316,7 @@ class ApkResources
316
316
  #
317
317
  # If xml_format is true, return value will be @<type>/<key>
318
318
  # If xml_format is false or missing, return value will be R.<type>.<key>
319
+ # If the resource id does not exist, return value will be nil
319
320
 
320
321
  def get_resource_key(res_id, xml_format=false)
321
322
  if res_id.is_a? String
@@ -329,7 +330,7 @@ class ApkResources
329
330
 
330
331
  if res_package != @package_header.id
331
332
  # This is not a resource we can parse
332
- return res_id_to_s(res_id)
333
+ return nil
333
334
  end
334
335
 
335
336
  res_spec = @type_data[res_type-1]
@@ -337,7 +338,7 @@ class ApkResources
337
338
 
338
339
  if entry == nil
339
340
  # There is no entry in our table for this resource
340
- return res_id_to_s(res_id)
341
+ return nil
341
342
  end
342
343
 
343
344
  if xml_format
@@ -355,10 +356,18 @@ class ApkResources
355
356
  # Returns: The default ResTypeEntry to the given id, or nil if no default exists
356
357
 
357
358
  def get_default_resource_value(res_id)
358
- entries = get_resource_value(res_id)
359
- default = ResTypeConfig.new(0, 0, 0, 0, 0, 0, 0, 0)
359
+ if res_id.is_a? String
360
+ res_id = res_id.hex
361
+ end
360
362
 
361
- return entries[default]
363
+ entries = get_resource_value(res_id)
364
+ if entries != nil
365
+ default = ResTypeConfig.new(0, 0, 0, 0, 0, 0, 0, 0)
366
+ default_entry = entries[default]
367
+ return default_entry
368
+ else
369
+ return nil
370
+ end
362
371
  end
363
372
 
364
373
  ##
@@ -368,6 +377,7 @@ class ApkResources
368
377
  # res_id: ID value of a resource as a FixNum or String representation (i.e. 0x7F060001)
369
378
  #
370
379
  # Returns: Hash of all entries matching this id, keyed by their matching ResTypeConfig
380
+ # or nil if the resource id cannot be found.
371
381
 
372
382
  def get_resource_value(res_id)
373
383
  if res_id.is_a? String
@@ -381,7 +391,7 @@ class ApkResources
381
391
 
382
392
  if res_package != @package_header.id
383
393
  # This is not a resource we can parse
384
- return res_id_to_s(res_id)
394
+ return nil
385
395
  end
386
396
 
387
397
  res_spec = @type_data[res_type-1]
@@ -389,7 +399,7 @@ class ApkResources
389
399
  entries = res_spec.types.entries[res_index]
390
400
  if entries == nil
391
401
  puts "Could not find #{type_name} ResType chunk" if DEBUG
392
- return res_id_to_s(res_id)
402
+ return nil
393
403
  end
394
404
 
395
405
  return entries
@@ -436,6 +446,8 @@ class ApkResources
436
446
 
437
447
  #Flag Constants
438
448
  FLAG_UTF8 = 0x100 # :nodoc:
449
+ FLAG_COMPLEX = 0x0001 # :nodoc:
450
+ FLAG_PUBLIC = 0x0002 # :nodoc:
439
451
 
440
452
  OFFSET_NO_ENTRY = 0xFFFFFFFF # :nodoc:
441
453
  HEADER_START = 0 # :nodoc:
@@ -229,13 +229,21 @@ class ApkXml
229
229
  attr_value = nil
230
230
  if attr_raw != nil # Use raw value
231
231
  attr_value = attr_raw
232
- elsif entry.data_type == 1
232
+ elsif entry.data_type == 1 # Value is a references to a resource
233
233
  # Find the resource
234
234
  default_res = apk_resources.get_default_resource_value(entry.data)
235
235
  if resolve_resources && default_res != nil
236
+ # Use the default resource value
236
237
  attr_value = default_res.data
237
238
  else
238
- attr_value = apk_resources.get_resource_key(entry.data, true)
239
+ key_value = apk_resources.get_resource_key(entry.data, true)
240
+ if key_value != nil
241
+ # Use the key string
242
+ attr_value = key_value
243
+ else
244
+ #No key found, use raw id marked as a resource
245
+ attr_value = "res:0x#{entry.data.to_s(16)}"
246
+ end
239
247
  end
240
248
  else # Value is a constant
241
249
  attr_value = "0x#{entry.data.to_s(16)}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apktools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-12 00:00:00.000000000 Z
12
+ date: 2012-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubyzip
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  version: '0'
60
60
  requirements: []
61
61
  rubyforge_project:
62
- rubygems_version: 1.8.22
62
+ rubygems_version: 1.8.24
63
63
  signing_key:
64
64
  specification_version: 3
65
65
  summary: APKTools