Add option to remove existing permissions
parent
b88a560ddb
commit
19356cfabf
|
@ -13,3 +13,7 @@
|
||||||
/captures
|
/captures
|
||||||
.externalNativeBuild
|
.externalNativeBuild
|
||||||
.cxx
|
.cxx
|
||||||
|
/.project
|
||||||
|
/.classpath
|
||||||
|
/.settings
|
||||||
|
/bin
|
|
@ -1,4 +1,9 @@
|
||||||
# **ManifestEditor**
|
# **ManifestEditor**
|
||||||
|
|
||||||
|
Fork from [WindySha/ManifestEditor](https://github.com/WindySha/ManifestEditor) with additional feature to remove previously defined permissions in android Manifest file.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
This is a tool used to modify Android Manifest binary file.
|
This is a tool used to modify Android Manifest binary file.
|
||||||
此工具用于修改AndroidManifest二进制文件。比如,更改Manifest文件中的app包名,版本号,更改或新增app入口Application的类名,更改或新增debuggable的属性,增加usesPermission标签,增加meta-data标签等。
|
此工具用于修改AndroidManifest二进制文件。比如,更改Manifest文件中的app包名,版本号,更改或新增app入口Application的类名,更改或新增debuggable的属性,增加usesPermission标签,增加meta-data标签等。
|
||||||
同时,为了更方便使用,提供了直接修改Apk包中的Manifest文件,并对修改后的Apk进行签名的功能。
|
同时,为了更方便使用,提供了直接修改Apk包中的Manifest文件,并对修改后的Apk进行签名的功能。
|
||||||
|
|
3
run.sh
3
run.sh
|
@ -2,4 +2,5 @@
|
||||||
./gradlew build
|
./gradlew build
|
||||||
|
|
||||||
# Run the app (add your options here)
|
# Run the app (add your options here)
|
||||||
java -jar build/dist/ManifestEditor.jar --help
|
java -jar build/dist/ManifestEditor.jar /mnt/entwicklung/git/RPdb/client/android/app/build/outputs/apk/debug/AndroidManifest.xml --deleteUsesPermission "android.permission.REQUEST_INSTALL_PACKAGES" --output \
|
||||||
|
/mnt/entwicklung/git/RPdb/client/android/app/build/outputs/apk/debug/AndroidManifest2.xml --force
|
|
@ -60,6 +60,10 @@ public class ManifestEditorMain extends BaseCommand {
|
||||||
"name to the manifest file, multi option is supported", argName = "uses-permission-name")
|
"name to the manifest file, multi option is supported", argName = "uses-permission-name")
|
||||||
private List<String> usesPermissionList = new ArrayList<>();
|
private List<String> usesPermissionList = new ArrayList<>();
|
||||||
|
|
||||||
|
@Opt(opt = "dup", longOpt = "deleteUsesPermission", description = "delete the app uses permission " +
|
||||||
|
"name to the manifest file, multi option is supported", argName = "delete-uses-permission-name")
|
||||||
|
private List<String> deletePermissionList = new ArrayList<>();
|
||||||
|
|
||||||
@Opt(opt = "ma", longOpt = "manifestAttribute", description = "set the app manifest attribute, " +
|
@Opt(opt = "ma", longOpt = "manifestAttribute", description = "set the app manifest attribute, " +
|
||||||
" name and value should be separated by " + MULTI_NAME_SEPERATER +
|
" name and value should be separated by " + MULTI_NAME_SEPERATER +
|
||||||
" , if name is in android namespace, prefix \"" + ANDROID_NAMESPACE + "\" should be set" +
|
" , if name is in android namespace, prefix \"" + ANDROID_NAMESPACE + "\" should be set" +
|
||||||
|
@ -226,6 +230,10 @@ public class ManifestEditorMain extends BaseCommand {
|
||||||
property.addUsesPermission(permission);
|
property.addUsesPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (String permission: deletePermissionList ) {
|
||||||
|
property.deleteAddUsesPermission(permission);
|
||||||
|
}
|
||||||
|
|
||||||
for (String manfestAttr : manifestAttributeList) {
|
for (String manfestAttr : manifestAttributeList) {
|
||||||
String[] nameValue = manfestAttr.split(MULTI_NAME_SEPERATER);
|
String[] nameValue = manfestAttr.split(MULTI_NAME_SEPERATER);
|
||||||
if (nameValue.length == 2) {
|
if (nameValue.length == 2) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class ModificationProperty {
|
public class ModificationProperty {
|
||||||
|
|
||||||
|
private List<String> deleteUsesPermissionList = new ArrayList<>();
|
||||||
private List<String> usesPermissionList = new ArrayList<>();
|
private List<String> usesPermissionList = new ArrayList<>();
|
||||||
private List<MetaData> metaDataList = new ArrayList<>();
|
private List<MetaData> metaDataList = new ArrayList<>();
|
||||||
private List<MetaData> deleteMetaDataList = new ArrayList<>();
|
private List<MetaData> deleteMetaDataList = new ArrayList<>();
|
||||||
|
@ -22,11 +23,21 @@ public class ModificationProperty {
|
||||||
return usesPermissionList;
|
return usesPermissionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getDeleteUsesPermissionList() {
|
||||||
|
return deleteUsesPermissionList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public ModificationProperty addUsesPermission(String permissionName) {
|
public ModificationProperty addUsesPermission(String permissionName) {
|
||||||
usesPermissionList.add(permissionName);
|
usesPermissionList.add(permissionName);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ModificationProperty deleteAddUsesPermission(String permissionName) {
|
||||||
|
deleteUsesPermissionList.add(permissionName);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public List<AttributeItem> getApplicationAttributeList() {
|
public List<AttributeItem> getApplicationAttributeList() {
|
||||||
return applicationAttributeList;
|
return applicationAttributeList;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,9 @@ import java.util.List;
|
||||||
|
|
||||||
import pxb.android.axml.NodeVisitor;
|
import pxb.android.axml.NodeVisitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class where all manifest tags are processed and delegated
|
||||||
|
*/
|
||||||
public class ManifestTagVisitor extends ModifyAttributeVisitor {
|
public class ManifestTagVisitor extends ModifyAttributeVisitor {
|
||||||
|
|
||||||
private ModificationProperty properties;
|
private ModificationProperty properties;
|
||||||
|
@ -24,11 +27,9 @@ public class ManifestTagVisitor extends ModifyAttributeVisitor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeVisitor child(String ns, String name) {
|
public NodeVisitor child(String ns, String name) {
|
||||||
Log.d(" ManifestTagVisitor child --> ns = " + ns + " name = " + name);
|
|
||||||
|
|
||||||
if (ns != null && (NodeValue.UsesPermission.TAG_NAME).equals(name)) {
|
if (ns != null && (NodeValue.UsesPermission.TAG_NAME).equals(name)) {
|
||||||
NodeVisitor child = super.child(null, NodeValue.UsesPermission.TAG_NAME);
|
NodeVisitor child = super.child(null, NodeValue.UsesPermission.TAG_NAME);
|
||||||
return new UserPermissionTagVisitor(child, null, ns);
|
return new UserPermissionTagVisitor(child, null, ns, properties.getDeleteUsesPermissionList());
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeVisitor child = super.child(ns, name);
|
NodeVisitor child = super.child(ns, name);
|
||||||
|
@ -42,7 +43,7 @@ public class ManifestTagVisitor extends ModifyAttributeVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NodeValue.UsesPermission.TAG_NAME.equals(name)) {
|
if (NodeValue.UsesPermission.TAG_NAME.equals(name)) {
|
||||||
return new UserPermissionTagVisitor(child, getUsesPermissionGetter(), null);
|
return new UserPermissionTagVisitor(child, getUsesPermissionGetter(), null, properties.getDeleteUsesPermissionList());
|
||||||
}
|
}
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
@ -51,6 +52,7 @@ public class ManifestTagVisitor extends ModifyAttributeVisitor {
|
||||||
public void attr(String ns, String name, int resourceId, int type, Object obj) {
|
public void attr(String ns, String name, int resourceId, int type, Object obj) {
|
||||||
Log.d(" ManifestTagVisitor attr --> ns = " + ns + " name = " +
|
Log.d(" ManifestTagVisitor attr --> ns = " + ns + " name = " +
|
||||||
name + " resourceId=" + resourceId + " obj = " + obj);
|
name + " resourceId=" + resourceId + " obj = " + obj);
|
||||||
|
|
||||||
super.attr(ns, name, resourceId, type, obj);
|
super.attr(ns, name, resourceId, type, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.wind.meditor.visitor;
|
package com.wind.meditor.visitor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.wind.meditor.property.AttributeItem;
|
import com.wind.meditor.property.AttributeItem;
|
||||||
import com.wind.meditor.utils.NodeValue;
|
import com.wind.meditor.utils.NodeValue;
|
||||||
import com.wind.meditor.utils.Utils;
|
import com.wind.meditor.utils.Utils;
|
||||||
|
@ -9,10 +11,12 @@ import pxb.android.axml.NodeVisitor;
|
||||||
class UserPermissionTagVisitor extends NodeVisitor {
|
class UserPermissionTagVisitor extends NodeVisitor {
|
||||||
|
|
||||||
private IUsesPermissionGetter permissionGetter;
|
private IUsesPermissionGetter permissionGetter;
|
||||||
|
private List<String> deletedPermissions;
|
||||||
|
|
||||||
UserPermissionTagVisitor(NodeVisitor nv, IUsesPermissionGetter permissionGetter, String permissionTobeAdded) {
|
UserPermissionTagVisitor(NodeVisitor nv, IUsesPermissionGetter permissionGetter, String permissionTobeAdded, List<String> deletedPermission) {
|
||||||
super(nv);
|
super(nv);
|
||||||
this.permissionGetter = permissionGetter;
|
this.permissionGetter = permissionGetter;
|
||||||
|
this.deletedPermissions = deletedPermission;
|
||||||
|
|
||||||
if (!Utils.isNullOrEmpty(permissionTobeAdded)) {
|
if (!Utils.isNullOrEmpty(permissionTobeAdded)) {
|
||||||
AttributeItem attributeItem = new AttributeItem(NodeValue.UsesPermission.NAME, permissionTobeAdded);
|
AttributeItem attributeItem = new AttributeItem(NodeValue.UsesPermission.NAME, permissionTobeAdded);
|
||||||
|
@ -26,13 +30,32 @@ class UserPermissionTagVisitor extends NodeVisitor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void attr(String ns, String name, int resourceId, int type, Object obj) {
|
public void attr(String ns, String name, int resourceId, int type, Object obj) {
|
||||||
if (obj instanceof String && permissionGetter != null) {
|
if (obj instanceof String) {
|
||||||
permissionGetter.onPermissionGetted((String) obj);
|
// Check if the permission is contained in the list of permission to delete
|
||||||
|
if (deletedPermissions != null && !deletedPermissions.isEmpty()) {
|
||||||
|
if (deletedPermissions.stream().filter( p -> p.equals((String) obj)).map(p -> true).findFirst().orElse(false) ) {
|
||||||
|
// Return out of this function without calling super function
|
||||||
|
System.out.println("Removing permission " + obj.toString());
|
||||||
|
super.nv.shouldChildBeWritten = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(permissionGetter != null) permissionGetter.onPermissionGetted((String) obj);
|
||||||
|
}
|
||||||
|
super.nv.end();
|
||||||
super.attr(ns, name, resourceId, type, obj);
|
super.attr(ns, name, resourceId, type, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IUsesPermissionGetter {
|
public interface IUsesPermissionGetter {
|
||||||
void onPermissionGetted(String permissionName);
|
void onPermissionGetted(String permissionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeVisitor child(String ns, String name) {
|
||||||
|
if (nv != null) {
|
||||||
|
return nv.child(ns, name);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,8 +197,10 @@ public class AxmlWriter extends AxmlVisitor {
|
||||||
int size = 24 + 36 + attrs.size() * 20;// 24 for end tag,36+x*20 for
|
int size = 24 + 36 + attrs.size() * 20;// 24 for end tag,36+x*20 for
|
||||||
// start tag
|
// start tag
|
||||||
for (NodeImpl child : children) {
|
for (NodeImpl child : children) {
|
||||||
|
if (child.shouldChildBeWritten) {
|
||||||
size += child.prepare(axmlWriter);
|
size += child.prepare(axmlWriter);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (text != null) {
|
if (text != null) {
|
||||||
size += 28;
|
size += 28;
|
||||||
}
|
}
|
||||||
|
@ -265,8 +267,10 @@ public class AxmlWriter extends AxmlVisitor {
|
||||||
|
|
||||||
// children
|
// children
|
||||||
for (NodeImpl child : children) {
|
for (NodeImpl child : children) {
|
||||||
|
if (child.shouldChildBeWritten) {
|
||||||
child.write(out);
|
child.write(out);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// end tag
|
// end tag
|
||||||
out.putInt(RES_XML_END_ELEMENT_TYPE | (0x0010 << 16));
|
out.putInt(RES_XML_END_ELEMENT_TYPE | (0x0010 << 16));
|
||||||
|
@ -328,8 +332,10 @@ public class AxmlWriter extends AxmlVisitor {
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
for (NodeImpl first : firsts) {
|
for (NodeImpl first : firsts) {
|
||||||
|
if (first.shouldChildBeWritten) {
|
||||||
size += first.prepare(this);
|
size += first.prepare(this);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
{
|
{
|
||||||
int a = 0;
|
int a = 0;
|
||||||
for (Map.Entry<String, Ns> e : nses.entrySet()) {
|
for (Map.Entry<String, Ns> e : nses.entrySet()) {
|
||||||
|
@ -399,8 +405,10 @@ public class AxmlWriter extends AxmlVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (NodeImpl first : firsts) {
|
for (NodeImpl first : firsts) {
|
||||||
|
if (first.shouldChildBeWritten) {
|
||||||
first.write(out);
|
first.write(out);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (stack.size() > 0) {
|
while (stack.size() > 0) {
|
||||||
Ns ns = stack.pop();
|
Ns ns = stack.pop();
|
||||||
|
|
|
@ -24,6 +24,8 @@ public abstract class NodeVisitor {
|
||||||
public static final int TYPE_STRING = 0x03;
|
public static final int TYPE_STRING = 0x03;
|
||||||
protected NodeVisitor nv;
|
protected NodeVisitor nv;
|
||||||
|
|
||||||
|
public boolean shouldChildBeWritten = true;
|
||||||
|
|
||||||
public NodeVisitor() {
|
public NodeVisitor() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue