Dump the deobfuscate data using Protocol buffers
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
diff --git a/tools/aapt2/cmd/Optimize.cpp b/tools/aapt2/cmd/Optimize.cpp
index f7f2f22..d7a39bf 100644
--- a/tools/aapt2/cmd/Optimize.cpp
+++ b/tools/aapt2/cmd/Optimize.cpp
@@ -161,6 +161,15 @@
<< "failed shortening resource paths");
return 1;
}
+
+ if (options_.obfuscation_map_path &&
+ !obfuscator.WriteObfuscationMap(options_.obfuscation_map_path.value())) {
+ context_->GetDiagnostics()->Error(android::DiagMessage()
+ << "failed to write the obfuscation map to file");
+ return 1;
+ }
+
+ // TODO(b/246489170): keep the old option and format until transform to the new one
if (options_.shortened_paths_map_path
&& !WriteShortenedPathsMap(options_.table_flattener_options.shortened_path_map,
options_.shortened_paths_map_path.value())) {
@@ -292,6 +301,7 @@
ArchiveEntry::kAlign, writer);
}
+ // TODO(b/246489170): keep the old option and format until transform to the new one
bool WriteShortenedPathsMap(const std::map<std::string, std::string> &path_map,
const std::string &file_path) {
std::stringstream ss;
diff --git a/tools/aapt2/cmd/Optimize.h b/tools/aapt2/cmd/Optimize.h
index 794a87b..1879f25 100644
--- a/tools/aapt2/cmd/Optimize.h
+++ b/tools/aapt2/cmd/Optimize.h
@@ -58,6 +58,7 @@
bool shorten_resource_paths = false;
// Path to the output map of original resource paths to shortened paths.
+ // TODO(b/246489170): keep the old option and format until transform to the new one
std::optional<std::string> shortened_paths_map_path;
// Whether sparse encoding should be used for O+ resources.
@@ -65,6 +66,9 @@
// Whether sparse encoding should be used for all resources.
bool force_sparse_encoding = false;
+
+ // Path to the output map of original resource paths/names to obfuscated paths/names.
+ std::optional<std::string> obfuscation_map_path;
};
class OptimizeCommand : public Command {
@@ -120,9 +124,13 @@
AddOptionalSwitch("--shorten-resource-paths",
"Shortens the paths of resources inside the APK.",
&options_.shorten_resource_paths);
+ // TODO(b/246489170): keep the old option and format until transform to the new one
AddOptionalFlag("--resource-path-shortening-map",
- "Path to output the map of old resource paths to shortened paths.",
- &options_.shortened_paths_map_path);
+ "[Deprecated]Path to output the map of old resource paths to shortened paths.",
+ &options_.shortened_paths_map_path);
+ AddOptionalFlag("--save-obfuscation-map",
+ "Path to output the map of original paths/names to obfuscated paths/names.",
+ &options_.obfuscation_map_path);
AddOptionalSwitch(
"--deduplicate-entry-values",
"Whether to deduplicate pairs of resource entry and value for simple resources.\n"