This commit is contained in:
REAndroid 2022-12-20 05:34:24 -05:00
parent 54133957f9
commit fe6b86197f
2 changed files with 27 additions and 27 deletions

View File

@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier same "printed page" as the copyright notice for easier
identification within third-party archives. identification within third-party archives.
Copyright [yyyy] [name of copyright owner] Copyright [2023] [github.com/REAndroid]
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@ -1,10 +1,10 @@
# ARSCLib # ARSCLib
## Android binary resources read/write java library ## Android binary resources read/write java library
This library is developed based on AOSP structure of androidfw/ResourceTypes.h , to totally replace aapt/aapt2 This library is developed based on AOSP structure of androidfw/ResourceTypes.h , to totally replace aapt/aapt2
### Read, write, modify and create #### Read, write, modify and create
* Resource table (resources.arsc) * Resource table (resources.arsc)
* Binary xml files (AndroidManifest.xml & resource xml) * Binary xml files (AndroidManifest.xml & resource xml)
### Convert from/to json string #### Convert from/to json string
* Decompiling resources to readable XML using traditional techniques is now becoming very challenging due to resource obfuscation (like Proguard & ResGuard) * Decompiling resources to readable XML using traditional techniques is now becoming very challenging due to resource obfuscation (like Proguard & ResGuard)
* Just like SMALI coding this library brings unbeatable coding style * Just like SMALI coding this library brings unbeatable coding style
@ -13,20 +13,20 @@ This library is developed based on AOSP structure of androidfw/ResourceTypes.h ,
``` ```
can be represented in json as can be represented in json as
```json ```json
{ {
"entry_name": "app_name", "entry_name": "app_name",
"id": 16, "id": 16,
"value": { "value": {
"value_type": "STRING", "value_type": "STRING",
"data": "My Application" "data": "My Application"
} }
``` ```
### Works on all java supported platforms (Android, Linux, Windows) #### Works on all java supported platforms (Android, Linux, Windows)
* Use the jar file as dependency * Use the jar file as dependency
### Check this tool developed using this library #### Check this tool developed using this library
[https://github.com/REAndroid/APKEditor](https://github.com/REAndroid/APKEditor) [https://github.com/REAndroid/APKEditor](https://github.com/REAndroid/APKEditor)
<details><summary> <b>See java example</b></summary> <details><summary> <code><b>See java example</b></code></summary>
```java ```java
import com.reandroid.lib.arsc.chunk.TableBlock; import com.reandroid.lib.arsc.chunk.TableBlock;
@ -35,7 +35,7 @@ import com.reandroid.lib.arsc.chunk.xml.AndroidManifestBlock;
import com.reandroid.lib.arsc.chunk.xml.ResXmlElement; import com.reandroid.lib.arsc.chunk.xml.ResXmlElement;
import com.reandroid.lib.arsc.chunk.xml.ResXmlAttribute; import com.reandroid.lib.arsc.chunk.xml.ResXmlAttribute;
public static void exampleManifest() throws IOException{ public static void exampleManifest() throws IOException{
File inFile=new File("AndroidManifest.xml"); File inFile=new File("AndroidManifest.xml");
// *** Loading AndroidManifest *** // *** Loading AndroidManifest ***
@ -45,7 +45,7 @@ import com.reandroid.lib.arsc.chunk.xml.ResXmlAttribute;
List<String> usesPermissionList = manifestBlock.getUsesPermissions(); List<String> usesPermissionList = manifestBlock.getUsesPermissions();
for(String usesPermission:usesPermissionList){ for(String usesPermission:usesPermissionList){
System.out.println("Uses permission: "+usesPermission); System.out.println("Uses permission: "+usesPermission);
} }
// *** Modifying AndroidManifest *** // *** Modifying AndroidManifest ***
@ -61,11 +61,11 @@ import com.reandroid.lib.arsc.chunk.xml.ResXmlAttribute;
// Modify xml attribute // Modify xml attribute
List<ResXmlElement> activityList = manifestBlock.listActivities(); List<ResXmlElement> activityList = manifestBlock.listActivities();
for(ResXmlElement activityElement:activityList){ for(ResXmlElement activityElement:activityList){
ResXmlAttribute attributeName = activityElement.searchAttributeByResourceId(AndroidManifestBlock.ID_name); ResXmlAttribute attributeName = activityElement.searchAttributeByResourceId(AndroidManifestBlock.ID_name);
System.out.println("Old activity name: "+attributeName.getValueAsString()); System.out.println("Old activity name: "+attributeName.getValueAsString());
attributeName.setValueAsString("com.app.MyActivity"); attributeName.setValueAsString("com.app.MyActivity");
System.out.println("New activity name: "+attributeName.getValueAsString()); System.out.println("New activity name: "+attributeName.getValueAsString());
break; break;
} }
// Refresh to re-calculate offsets // Refresh to re-calculate offsets
@ -75,7 +75,7 @@ import com.reandroid.lib.arsc.chunk.xml.ResXmlAttribute;
manifestBlock.writeBytes(outFile); manifestBlock.writeBytes(outFile);
System.out.println("Saved: "+outFile); System.out.println("Saved: "+outFile);
} }
``` ```
@ -91,16 +91,16 @@ import com.reandroid.lib.arsc.chunk.xml.ResXmlAttribute;
Collection<PackageBlock> packageBlockList=tableBlock.listPackages(); Collection<PackageBlock> packageBlockList=tableBlock.listPackages();
System.out.println("Packages count = "+packageBlockList.size()); System.out.println("Packages count = "+packageBlockList.size());
for(PackageBlock packageBlock:packageBlockList){ for(PackageBlock packageBlock:packageBlockList){
System.out.println("Package id = "+packageBlock.getId() System.out.println("Package id = "+packageBlock.getId()
+", name = "+packageBlock.getName()); +", name = "+packageBlock.getName());
} }
// *** Modify resource table // *** Modify resource table
// Change package name // Change package name
for(PackageBlock packageBlock:packageBlockList){ for(PackageBlock packageBlock:packageBlockList){
String name = packageBlock.getName(); String name = packageBlock.getName();
String newName = name + ".new-name"; String newName = name + ".new-name";
packageBlock.setName(newName); packageBlock.setName(newName);
} }
// Refresh to re-calculate offsets // Refresh to re-calculate offsets
@ -110,7 +110,7 @@ import com.reandroid.lib.arsc.chunk.xml.ResXmlAttribute;
tableBlock.writeBytes(outFile); tableBlock.writeBytes(outFile);
System.out.println("Saved: "+outFile); System.out.println("Saved: "+outFile);
} }
``` ```