Using Google Protocol buffers to dump the obfuscating mapping
information of being used to deobfuscate items.
* shortened file path -> original file path
* resource id -> original resource name
This patch add a new option --save-obfuscating-map to deprecate
--resource-path-shortening-map. The option
--resource-path-shortening-map is kept until no one to use it.
Bug: 246489170
Bug: 228192695
b/228192695#comment2
Test: make WITH_TIDY=1 aapt2
Test: atest aapt2_test
Change-Id: I29733c4dbae9f6dd2f0e9b2c87b0d2046662fc59
There are 2 copy codes for handling the obfuscating resources names
between serializing to pb format file and writing to apks. The
obfuscator also needs to dump resources names. It means there are
3 places to handle the obfuscating resources names.
So, using C++ lambda to apply the callback mechanism refactors the
codes.
Obfuscator
* Initial a Obfuscator according to Optimizer's options
* Add Obfuscator.IsEnabled() function.
return true either shorten_resource_paths_ is true or
collapse_key_stringpool_ is true.
Bug: 228192695
Test: atest aapt2_test idmap2_test
Change-Id: Idd2442beecf41e9392620ff801a36fd1285e06f9
1. Report permissions declared only under <manifest>.
2. If the same feature reported multiple times: the last declaration
wins.
Bug: b/260704482
Test: manual runs
Change-Id: Ic9ff32573d2bf6550c3a01ed3019da83590eda2f
Bug: 237583012
Most offsets to the entries can be well encoded in 16-bit,
and given entries are 4-byte aligned, this gives us a range
of entry offsets from 0x00000 to 0xfffe * 4u, with 0xffffu
to represent ResTable_type::NO_ENTRY.
For now, 16-bit entry offset will be enabled only when:
* all the entry offsets can be represented in 16-bit
* --enable-compact-entries switch is turned on
Change-Id: I1c815c052aa5fba6eab2529434d31d7714c13694
Bug: 237583012
Given the large number of simple resources such as strings in
Android resources, their ResTable_entry and Res_value can be
encoded together in a compact way. This allows a significant
saving in both storage and memory footprint.
The basic observations for simple resources are:
* ResTable_entry.size will always be sizeof(ResTable_entry)
unless it's a complex entry
* ResTable_entry.key is unlikely to exceed 16-bit
* ResTable_entry.flags only uses 3 bits for now
* Res_value.size will always be sizeof(Res_value)
Given the above, we could well encode the information into
a compact/compatible structure.
struct compact {
uint16_t key;
uint16_t flags;
uint32_t data;
};
The layout of this structure will allow maximum backward
compatibility. e.g. the flags will be at the same offset,
and a
`dtohs((ResTable_entry *)entry->flags) & FLAG_COMPACT`
would tell if this entry is a compact one or not. For a
compact entry:
struct compact *entry;
entry_size == sizeof(*entry)
entry_key == static_cast<uint32_t>(dtohs(entry->key))
entry_flags == dtohs(entry->flags) & 0xff // low 8-bit
data_type == dtohs(entry->flags) >> 8 // high 8-bit
data_size == sizeof(Res_value)
data_value == dtohl(entry->data)
To allow minimum code change and backward compatibility,
we change 'struct ResTable_entry' to 'union ResTable_entry',
with an anonymous structure inside that's fully backward
compatible. Thus, any existing reference such as:
ResTable_entry *entry = ...
if (dtohs(entry->flags) & ResTable_entry::FLAG_COMPLEX) ...
would still work.
However, special care needs to be taken after an entry is
obtained, and when value needs to be extracted.
A compact entry will not encode a complex value, and hence
complex entries/values are handled the same way.
Change-Id: I15d97a4f5e85fab28c075496f7f0cf6b1fcd73e3
To achieve this ParseResourceConfig is extracted to Utils.cpp and tests
are moved from Optimize_test.cpp to Util_test.cpp.
Bug: b/249793372
Test: Util_test, Convert_test
Change-Id: I5a0458e3834d5ea62c96013abc14527285e895e0
This CL introduces DeduplicateItemsResEntryWriter which stores unique
pairs of entry and value and deduplicates a new pair based of this data
before writing it into the buffer.
Bug: b/249793372
Test: ResEntriesWriter_test, TableFlattener_test
Change-Id: I938a3425a87bfad9853e59193680de2050a95bd2
ResEntryWriter is responsible to write pairs of entry+value into binary
buffers and allows easy customization how and where entries are written.
This is no-op refactoring and all existing tests should pass.
Bug: b/249793372
Test: Existing tests
Change-Id: Ica98a25aeb49cc96cad28547c462b36316a8adb6
`android::util::Utf16ToUtf8()` actually returns a `std::string` due to
the actual conversion to Utf8. `ParseResourceNamedType()` operates on a
`StringPiece` of `converted` (the `std::string` returned from that
call), and stashes it away for later use. Of course, by the time we're
using the `StringPiece` in `parsed_type`, `converted` has already gone
out of scope and is invalid to access.
Bug: http://b/250827883
Test: ./art/test/testrunner/run_build_test_target.py -j80 art-asan
Change-Id: Iea71a5cc84b7dfa96e7dcb549435f8394770a4df
ResourcePathShortener is a part of Obfuscator. Obfuscator will not
only shorten the path but also handle obfuscating resource names.
Format C++ code by clang-format.
Bug: 228192695
Test: atest aapt2_test idmap2_test
Change-Id: I27b4b1af44061e3cd8a6717ffd46b8a187cdc41d
This helps solve three problems:
* obfuscation maps are now documented.
* obfuscation maps will not require hand-rolled parsers.
* no additional plumbing will be required for future
optimizations---plumbing individual mapping files in Bazel for
ProGuard, aapt2, etc. has been a pain.
Bug: 153201806
Test: make aapt2
Change-Id: Ie3829834527e8875d768ae28242d3aeca28c6db2
This allows to use sparse encoding for APKs that do not specify minSdk
version inside. This is common for split APKs generated by bundletool
when Android App Bundle (AAB) is split into multiple APKs.
Bug: b/223394605
Test: TableFlattener_test
Change-Id: I2a99a611f855cffbcea20018d869e1eb54d1b3d5
aapt2 disable sparse encoding when sdk < 32
Bug: 197642721
Test: Updated and verified affected atests pass
Change-Id: I839978207eb30f958f5d695cf8dea7f0dad1312f
aapt2 enable sparse encoding when sdk is not set.
Bug: 197642721
Test: Added new unit test and verified all tests pass
Change-Id: Ib58941d98eafe8e543d50054c9d36a51d7977c71
The text of CDATA in XML document should be escaped before the CDATA
text is printed.
Dump xmltree command use XmlPrinter inheriting from xml:ConstVisitor.
To fix issue, it only needs to modify
XmlPrinter::Visit(const xml::Text).
Bug: 140373430
Test: aapt2 dump xmltree --file res/xml/test.xml app_debug.apk
Change-Id: I4f43120b4fbc2ea7136fb51fdeb24e254b94c60f
At the moment aapt2 dumps information from the latest <uses-sdk> element
but uses all of them to detect target SDK which affects implied
permissions. Use only the latest one for detecting targetSdk as well.
Bug: b/243145989
Test: Dump_test
Change-Id: I70f828f1845ab070fa84c5297af12df24e7068dc
Logic is synchronised with 'aapt':
* use 'android.media.*' intents for 'camera' component detection;
* use only 'lib/' under root to parse supported archs.
Bug: b/243145989
Test: Dump_test.cpp
Change-Id: I90fbe802a97a4382e3021b344d0c5e9708563389
Once the build process finds one overlayable resource entry is not in
the list of collapse name exemption, the build process outputs the
resource name automatically and gives a warning message to notify the
developers.
Bug: 228192695
Test: atest aapt2_test
Change-Id: I989b75343d803b059c902baa088590fce7237211
Add the scaffolding for teaching the package parser to reject a package
if its manifest specifies a set of prefixes, and the device fingerprint
does not start with one of the prefixes.
Bug: b/232475788
Test: m
Change-Id: I9f3f3d3ad96332d2d65fbf6f58c7ce35992bcd7e
Leverage the existing mechanism for validating the locale format to verify whether the locale format of the compiled localeConfig file follows the BCP47 reqular expressions
Bug: 208943132
Test: 1. atest aapt2_tests
2. Build the app bundle with the local aapt2 in the Android Studio
a. Make sure the app can be built pass with AGP 7.3.0-alpha06.
b. Make sure the app can be built pass by using the local aapt2 with gradle: set the android.aapt2FromMavenOverride=<path> variable in gradle.properties.
c. Revove the property above in gradle.properties then apply AGP 7.3.0-alpha07. Make sure the appt2 shows error(AAPT: error: failed to load XML file: No such file or directory) when building the app.
d. Add the locale aapt2 with gradle: set the android.aapt2FromMavenOverride=<path> variable in gradle.properties. Make sure the app can be built pass.
Change-Id: Ifa4b9123d36f9c2d450fdf16e1f52963962d7d81