Skip to content

Commit 737ff9b

Browse files
committed
Add README example.
1 parent c12f747 commit 737ff9b

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

README.md

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ APK Resource Toolkit
22
====================
33
[![Gem Version](https://badge.fury.io/rb/apktools.png)](http://badge.fury.io/rb/apktools)
44

5-
This repository contains the source code for the 'apktools' ruby gem, a set of utilities for parsing resource data out of Android APK files.
5+
This repository contains the source code for the `apktools` ruby gem, a set of utilities for parsing resource data out of Android APK files.
66

77
This library only contains utility code to read XML and resource data from an APK. It does not contain utilities to de-dex or otherwise decompile the sources.
88

99
Its intended purpose is to assist web applications that need to read basic resource information from APKs that are uploaded in order to manage them (like a private app store).
1010

11-
**This library is in early beta, feedback is greatly appreciated. Please submit issues or pull requests for anything you'd like to see added or changed to make this library more useful.**
11+
**This library is not feature complete, feedback is greatly appreciated. Please submit issues or pull requests for anything you'd like to see added or changed to make this library more useful.**
1212

1313
Installing/Building
1414
========
@@ -168,6 +168,53 @@ end
168168

169169
**For more information on the capabilities of the library, take a look at the RDoc posted in the `doc/` directory of the repository.**
170170

171+
Resource References
172+
-------------------
173+
`apktools` does not automatically follow references links found in resources. Instead, the library will return the resource id of the reference, allowing you to manually follow the reference as far as you like. The following example script recursively traces resource references until a value is found:
174+
```ruby
175+
require 'apktools/apkresources'
176+
177+
## Resolve a resource value, tracing references when necessary
178+
def resolve_resource(resources, res_id)
179+
res_value = resources.get_default_resource_value(res_id)
180+
if res_value == nil
181+
return nil
182+
elsif res_value.data_type == ApkResources::TYPE_REFERENCE
183+
#This is a reference, trace it down
184+
return resolve_resource(resources, res_value.data)
185+
else
186+
return [res_value.key,res_value.data]
187+
end
188+
end
189+
190+
# Read resource information out of the given APK
191+
# Returns the initial resource key, and final resource key/value pair
192+
# The above will be different if the initial resource contains a reference
193+
194+
if ARGV.length != 2
195+
puts "usage: ref_test <APKFile> <ResId>"
196+
exit(1)
197+
end
198+
199+
apk_file = ARGV[0]
200+
res_id = ARGV[1]
201+
202+
# Load the XML data
203+
# Initialize with an APK file
204+
resources = ApkResources.new(apk_file)
205+
206+
# Get Resource key
207+
res_key = resources.get_resource_key(res_id)
208+
209+
# Get Resource value (ResTypeEntry struct)
210+
res_value = resolve_resource(resources, res_id)
211+
if res_value == nil
212+
puts "No resource found for #{res_id}"
213+
else
214+
puts [res_key,res_value]
215+
end
216+
```
217+
171218
Utilities
172219
=========
173220

0 commit comments

Comments
 (0)