diff --git a/libs/ARSCLib.jar b/libs/ARSCLib.jar index 5bfed9ae..e788bd4e 100644 Binary files a/libs/ARSCLib.jar and b/libs/ARSCLib.jar differ diff --git a/libs/smali.jar b/libs/smali.jar index f97b773e..23f4962e 100644 Binary files a/libs/smali.jar and b/libs/smali.jar differ diff --git a/src/main/java/com/reandroid/apkeditor/common/AndroidManifestHelper.java b/src/main/java/com/reandroid/apkeditor/common/AndroidManifestHelper.java index 1c16636f..ac550753 100644 --- a/src/main/java/com/reandroid/apkeditor/common/AndroidManifestHelper.java +++ b/src/main/java/com/reandroid/apkeditor/common/AndroidManifestHelper.java @@ -16,6 +16,7 @@ package com.reandroid.apkeditor.common; import com.reandroid.apk.APKLogger; +import com.reandroid.app.AndroidManifest; import com.reandroid.arsc.chunk.xml.AndroidManifestBlock; import com.reandroid.arsc.chunk.xml.ResXmlAttribute; import com.reandroid.arsc.chunk.xml.ResXmlElement; @@ -34,7 +35,7 @@ public static List listSplitRequired(ResXmlElement parentElement) return EmptyList.of(); } return CollectionUtil.toList(parentElement.getElements(element -> { - if(!element.equalsName(AndroidManifestBlock.TAG_meta_data)){ + if(!element.equalsName(AndroidManifest.TAG_meta_data)){ return false; } ResXmlAttribute nameAttribute = CollectionUtil.getFirst(element @@ -65,7 +66,7 @@ public static void removeAttributeFromManifestAndApplication(AndroidManifestBloc } int removed = manifestElement.removeAttributesWithId(resourceId); ResXmlElement applicationElement = manifestElement.getElementByTagName( - AndroidManifestBlock.TAG_application); + AndroidManifest.TAG_application); if(removed > 1){ if(logger != null){ logger.logMessage("Duplicate attributes on removed: " @@ -109,8 +110,8 @@ public static String getNamedValue(ResXmlElement element) { return attribute.decodeValue(); } static boolean isNameResourceId(ResXmlAttribute attribute){ - int resourceId = attribute.getNameResourceID(); - return resourceId == AndroidManifestBlock.ID_name; + int resourceId = attribute.getNameId(); + return resourceId == AndroidManifest.ID_name; } static final Predicate NAME_FILTER = attribute -> { if(!isNameResourceId(attribute)){ diff --git a/src/main/java/com/reandroid/apkeditor/compile/Builder.java b/src/main/java/com/reandroid/apkeditor/compile/Builder.java index 7a74c203..8f0ecd93 100644 --- a/src/main/java/com/reandroid/apkeditor/compile/Builder.java +++ b/src/main/java/com/reandroid/apkeditor/compile/Builder.java @@ -19,13 +19,13 @@ import com.reandroid.apkeditor.BaseCommand; import com.reandroid.apkeditor.Util; import com.reandroid.apkeditor.smali.SmaliCompiler; +import com.reandroid.app.AndroidManifest; import com.reandroid.archive.ArchiveFile; import com.reandroid.archive.block.ApkSignatureBlock; import com.reandroid.archive.writer.ApkFileWriter; import com.reandroid.arsc.chunk.TableBlock; import com.reandroid.arsc.coder.xml.XmlCoder; import com.reandroid.commons.command.ARGException; -import com.reandroid.arsc.chunk.xml.AndroidManifestBlock; import java.io.File; import java.io.IOException; @@ -176,14 +176,14 @@ public static void execute(String[] args) throws ARGException, IOException { builder.run(); } private static boolean isRawInDir(File dir){ - File file=new File(dir, AndroidManifestBlock.FILE_NAME_BIN); + File file=new File(dir, AndroidManifest.FILE_NAME_BIN); if(!file.isFile()){ file = new File(dir, TableBlock.FILE_NAME); } return file.isFile(); } private static boolean isXmlInDir(File dir){ - File manifest = new File(dir, AndroidManifestBlock.FILE_NAME); + File manifest = new File(dir, AndroidManifest.FILE_NAME); return manifest.isFile(); } private static boolean isJsonInDir(File dir) { @@ -220,11 +220,7 @@ private static boolean isModuleDir(File dir){ if(!dir.isDirectory()){ return false; } - File manifest=new File(dir,AndroidManifestBlock.FILE_NAME+".json"); - if(manifest.isFile()){ - return true; - } - File file=new File(dir, "AndroidManifest.xml.json"); + File file = new File(dir, AndroidManifest.FILE_NAME_JSON); return file.isFile(); } public static boolean isCommand(String command){ diff --git a/src/main/java/com/reandroid/apkeditor/info/Info.java b/src/main/java/com/reandroid/apkeditor/info/Info.java index 0c233326..4d590763 100644 --- a/src/main/java/com/reandroid/apkeditor/info/Info.java +++ b/src/main/java/com/reandroid/apkeditor/info/Info.java @@ -27,6 +27,7 @@ import com.reandroid.arsc.coder.ReferenceString; import com.reandroid.arsc.coder.ValueCoder; import com.reandroid.arsc.model.ResourceEntry; +import com.reandroid.dex.model.DexDirectory; import com.reandroid.utils.HexUtil; import com.reandroid.arsc.value.AttributeDataFormat; import com.reandroid.arsc.value.Entry; @@ -72,7 +73,7 @@ private void print(ApkModule apkModule) throws IOException { printSourceFile(); printPackage(apkModule); - AndroidManifestBlock manifest = apkModule.getAndroidManifestBlock(); + AndroidManifestBlock manifest = apkModule.getAndroidManifest(); printVersionCode(manifest); printVersionName(manifest); printMinSdkVersion(manifest); @@ -88,6 +89,7 @@ private void print(ApkModule apkModule) throws IOException { printResList(apkModule); printResources(apkModule); + printDex(apkModule); } private void printSourceFile() throws IOException { InfoOptions options = getOptions(); @@ -114,6 +116,15 @@ private void printResources(ApkModule apkModule) throws IOException { infoWriter.writeResources(packageBlock, options.typeFilterList, writeEntries); } } + private void printDex(ApkModule apkModule) throws IOException { + InfoOptions options = getOptions(); + if(!options.dex){ + return; + } + InfoWriter infoWriter = getInfoWriter(); + DexDirectory dexDirectory = DexDirectory.readStrings(apkModule.getZipEntryMap()); + infoWriter.writeDexInfo(dexDirectory); + } private void printResList(ApkModule apkModule) throws IOException { InfoOptions options = getOptions(); if(options.resList.size() == 0){ @@ -160,7 +171,7 @@ private void printPackage(ApkModule apkModule) throws IOException { if(!options.packageName){ return; } - AndroidManifestBlock manifest = apkModule.getAndroidManifestBlock(); + AndroidManifestBlock manifest = apkModule.getAndroidManifest(); if(manifest != null){ getInfoWriter().writeNameValue("package" , manifest.getPackageName()); } @@ -204,7 +215,7 @@ private void printAppName(ApkModule apkModule) throws IOException { if(!options.appName){ return; } - AndroidManifestBlock manifest = apkModule.getAndroidManifestBlock(); + AndroidManifestBlock manifest = apkModule.getAndroidManifest(); ResXmlElement application = manifest.getApplicationElement(); ResXmlAttribute attributeLabel = application .searchAttributeByResourceId(AndroidManifestBlock.ID_label); @@ -223,7 +234,7 @@ private void printAppIcon(ApkModule apkModule) throws IOException { if(!options.appIcon){ return; } - AndroidManifestBlock manifest = apkModule.getAndroidManifestBlock(); + AndroidManifestBlock manifest = apkModule.getAndroidManifest(); ResXmlElement application = manifest.getApplicationElement(); ResXmlAttribute attribute = application .searchAttributeByResourceId(AndroidManifestBlock.ID_icon); @@ -242,7 +253,7 @@ private void printAppRoundIcon(ApkModule apkModule) throws IOException { if(!options.appRoundIcon){ return; } - AndroidManifestBlock manifest = apkModule.getAndroidManifestBlock(); + AndroidManifestBlock manifest = apkModule.getAndroidManifest(); ResXmlElement application = manifest.getApplicationElement(); int id_roundIcon = 0x0101052c; ResXmlAttribute attribute = application @@ -262,7 +273,7 @@ private void printUsesPermissions(ApkModule apkModule) throws IOException { if(!options.permissions || !options.verbose){ return; } - AndroidManifestBlock manifest = apkModule.getAndroidManifestBlock(); + AndroidManifestBlock manifest = apkModule.getAndroidManifest(); if(manifest == null){ return; } @@ -280,7 +291,7 @@ private void printActivities(ApkModule apkModule) throws IOException { if(!options.activities){ return; } - AndroidManifestBlock manifest = apkModule.getAndroidManifestBlock(); + AndroidManifestBlock manifest = apkModule.getAndroidManifest(); if(manifest == null){ return; } @@ -309,7 +320,7 @@ private void printAppClass(ApkModule apkModule) throws IOException { if(!options.appClass){ return; } - AndroidManifestBlock manifest = apkModule.getAndroidManifestBlock(); + AndroidManifestBlock manifest = apkModule.getAndroidManifest(); if(manifest == null){ return; } diff --git a/src/main/java/com/reandroid/apkeditor/info/InfoOptions.java b/src/main/java/com/reandroid/apkeditor/info/InfoOptions.java index 820e7ffa..2011514b 100644 --- a/src/main/java/com/reandroid/apkeditor/info/InfoOptions.java +++ b/src/main/java/com/reandroid/apkeditor/info/InfoOptions.java @@ -41,6 +41,7 @@ public class InfoOptions extends Options { public final List resList; public boolean resources = false; public final List typeFilterList; + public boolean dex = false; public InfoOptions(){ super(); this.resList = new ArrayList<>(); @@ -75,6 +76,7 @@ public void parse(String[] args) throws ARGException { appClass = containsArg(ARG_app_class, args, appClass); activities = containsArg(ARG_activities, args, activities); resources = containsArg(ARG_resources, args, false); + dex = containsArg(ARG_dex, args, false); @@ -132,6 +134,7 @@ private void initializeDefaults(String[] args){ permissions = false; activities = false; appClass = false; + dex = false; } } private void parseInput(String[] args) throws ARGException { @@ -180,6 +183,8 @@ public static String getHelp(){ new String[]{ARG_activities, ARG_DESC_activities}, new String[]{ARG_resources, ARG_DESC_resources}, new String[]{" ", " "}, + new String[]{ARG_dex, ARG_DESC_dex}, + new String[]{" ", " "}, new String[]{ARG_ALL_help, ARG_DESC_help} }; StringHelper.printTwoColumns(builder, " ", PRINT_WIDTH, table); @@ -266,6 +271,9 @@ public static String getHelp(){ "\n *This applies only when flag '-resources' used." + "\n *Can be multiple"; + private static final String ARG_dex = "-dex"; + private static final String ARG_DESC_dex = "Prints dex information"; + private static final String[] availableTypes = new String[]{TYPE_TEXT, TYPE_JSON, TYPE_XML}; } diff --git a/src/main/java/com/reandroid/apkeditor/info/InfoWriter.java b/src/main/java/com/reandroid/apkeditor/info/InfoWriter.java index 93b6551d..996ea0ad 100644 --- a/src/main/java/com/reandroid/apkeditor/info/InfoWriter.java +++ b/src/main/java/com/reandroid/apkeditor/info/InfoWriter.java @@ -19,6 +19,8 @@ import com.reandroid.arsc.coder.ValueCoder; import com.reandroid.arsc.container.SpecTypePair; import com.reandroid.arsc.model.ResourceEntry; +import com.reandroid.dex.model.DexDirectory; +import com.reandroid.dex.model.DexFile; import com.reandroid.utils.HexUtil; import com.reandroid.arsc.value.*; @@ -40,6 +42,12 @@ public void writeResources(PackageBlock packageBlock, List typeFilters, writeResources(resourceEntry, writeEntries); } } + public void writeDexInfo(DexDirectory dexDirectory) throws IOException { + for(DexFile dexFile : dexDirectory){ + writeDexInfo(dexFile, true); + } + } + public abstract void writeDexInfo(DexFile dexFile, boolean writeSectionInfo) throws IOException; public abstract void writeResources(ResourceEntry resourceEntry, boolean writeEntries) throws IOException; public abstract void writePackageNames(Collection packageBlocks) throws IOException; public abstract void writeEntries(String name, List entryList) throws IOException; diff --git a/src/main/java/com/reandroid/apkeditor/info/InfoWriterJson.java b/src/main/java/com/reandroid/apkeditor/info/InfoWriterJson.java index d2401f78..586af744 100644 --- a/src/main/java/com/reandroid/apkeditor/info/InfoWriterJson.java +++ b/src/main/java/com/reandroid/apkeditor/info/InfoWriterJson.java @@ -23,6 +23,8 @@ import com.reandroid.arsc.value.ResTableMapEntry; import com.reandroid.arsc.value.ResValue; import com.reandroid.arsc.value.ResValueMap; +import com.reandroid.dex.model.DexFile; +import com.reandroid.dex.sections.Marker; import com.reandroid.json.JSONWriter; import java.io.IOException; @@ -33,6 +35,7 @@ public class InfoWriterJson extends InfoWriter{ private final JSONWriter mJsonWriter; + public InfoWriterJson(Writer writer) { super(writer); JSONWriter jsonWriter = new JSONWriter(writer); @@ -40,6 +43,18 @@ public InfoWriterJson(Writer writer) { this.mJsonWriter = jsonWriter; } + @Override + public void writeDexInfo(DexFile dexFile, boolean writeSectionInfo) throws IOException { + JSONWriter jsonWriter = mJsonWriter.object() + .key("name").value(dexFile.getFileName()) + .key("version").value(dexFile.getVersion()) + .key("markers").array(); + List markersList = dexFile.getMarkers(); + for(Marker marker : markersList){ + jsonWriter.value(marker.getJsonObject()); + } + jsonWriter.endArray().endObject(); + } @Override public void writeResources(PackageBlock packageBlock, List typeFilters, boolean writeEntries) throws IOException { packageBlock.sortTypes(); @@ -126,7 +141,7 @@ private void writeBagEntry(Entry entry) { private void writeValueMap(ResValueMap resValueMap){ mJsonWriter.object() .key("name").value(resValueMap.decodeName()) - .key("id").value(resValueMap.getNameResourceID()) + .key("id").value(resValueMap.getNameId()) .key("value").value(getValueAsString(resValueMap)) .endObject(); } diff --git a/src/main/java/com/reandroid/apkeditor/info/InfoWriterText.java b/src/main/java/com/reandroid/apkeditor/info/InfoWriterText.java index 8a491200..40ac629f 100644 --- a/src/main/java/com/reandroid/apkeditor/info/InfoWriterText.java +++ b/src/main/java/com/reandroid/apkeditor/info/InfoWriterText.java @@ -23,6 +23,10 @@ import com.reandroid.arsc.value.ResTableMapEntry; import com.reandroid.arsc.value.ResValue; import com.reandroid.arsc.value.ResValueMap; +import com.reandroid.dex.model.DexFile; +import com.reandroid.dex.sections.MapItem; +import com.reandroid.dex.sections.MapList; +import com.reandroid.dex.sections.Marker; import com.reandroid.utils.HexUtil; import java.io.IOException; @@ -36,6 +40,33 @@ public InfoWriterText(Writer writer) { super(writer); } + + @Override + public void writeDexInfo(DexFile dexFile, boolean writeSectionInfo) throws IOException { + Writer writer = getWriter(); + writer.write("\n"); + writeNameValue("Name", dexFile.getFileName()); + writeNameValue("Version", dexFile.getVersion()); + List markersList = dexFile.getMarkers(); + if(markersList.size() != 0){ + writer.write("Markers:"); + for(Marker marker : markersList){ + writer.write("\n"); + writer.write(ARRAY_TAB); + writer.write(marker.toString()); + } + } + writer.write("\n"); + MapList mapList = dexFile.getDexLayout().getMapList(); + writer.write("Sections:"); + for(MapItem mapItem : mapList){ + writer.write("\n"); + writer.write(ARRAY_TAB); + writer.write(mapItem.toString()); + } + writer.write("\n"); + writer.flush(); + } @Override public void writeResources(PackageBlock packageBlock, List typeFilters, boolean writeEntries) throws IOException { Writer writer = getWriter(); @@ -138,7 +169,7 @@ private void writeValueMap(ResValueMap resValueMap) throws IOException { writer.write(name); writer.write("("); } - writer.write(HexUtil.toHex8(resValueMap.getNameResourceID())); + writer.write(HexUtil.toHex8(resValueMap.getNameId())); if(name != null){ writer.write(")"); } diff --git a/src/main/java/com/reandroid/apkeditor/info/InfoWriterXml.java b/src/main/java/com/reandroid/apkeditor/info/InfoWriterXml.java index 11c6a05f..437854c5 100644 --- a/src/main/java/com/reandroid/apkeditor/info/InfoWriterXml.java +++ b/src/main/java/com/reandroid/apkeditor/info/InfoWriterXml.java @@ -15,7 +15,11 @@ */ package com.reandroid.apkeditor.info; -import com.android.org.kxml2.io.KXmlSerializer; +import com.reandroid.dex.model.DexFile; +import com.reandroid.dex.sections.MapItem; +import com.reandroid.dex.sections.MapList; +import com.reandroid.dex.sections.Marker; +import com.reandroid.xml.kxml2.KXmlSerializer; import com.reandroid.arsc.array.ResValueMapArray; import com.reandroid.arsc.chunk.PackageBlock; import com.reandroid.arsc.container.SpecTypePair; @@ -33,11 +37,50 @@ import java.util.List; public class InfoWriterXml extends InfoWriter{ + private KXmlSerializer mSerializer; private int mIndent; + public InfoWriterXml(Writer writer) { super(writer); } + + @Override + public void writeDexInfo(DexFile dexFile, boolean writeSectionInfo) throws IOException { + KXmlSerializer serializer = getSerializer(); + int indent = mIndent + 2; + mIndent = indent; + writeIndent(serializer, indent); + indent = mIndent + 2; + mIndent = indent; + serializer.startTag(null, "dex"); + serializer.attribute(null, "name", dexFile.getFileName()); + serializer.attribute(null, "version", Integer.toString(dexFile.getVersion())); + List markersList = dexFile.getMarkers(); + writeArray("markers", markersList.toArray()); + + MapList mapList = dexFile.getDexLayout().getMapList(); + writeIndent(serializer, indent); + serializer.startTag(null, "dex-sections"); + indent = mIndent + 2; + mIndent = indent; + for(MapItem mapItem : mapList){ + writeIndent(serializer, indent); + serializer.startTag(null, "section"); + serializer.attribute(null, "name", mapItem.getSectionType().getName()); + serializer.attribute(null, "count", Integer.toString(mapItem.getCountValue())); + serializer.attribute(null, "offset", Integer.toString(mapItem.getOffsetValue())); + serializer.endTag(null, "section"); + } + indent = mIndent - 2; + mIndent = indent; + writeIndent(serializer, indent); + serializer.endTag(null, "dex-sections"); + indent = mIndent - 2; + mIndent = indent; + writeIndent(serializer, indent); + serializer.endTag(null, "dex"); + } @Override public void writeResources(PackageBlock packageBlock, List typeFilters, boolean writeEntries) throws IOException { KXmlSerializer serializer = getSerializer(); @@ -177,7 +220,7 @@ private void writeValueMap(ResValueMap resValueMap) throws IOException { writeIndent(serializer, indent); serializer.startTag(null, TAG_VALUE); serializer.attribute(null, "name", - HexUtil.toHex8(resValueMap.getNameResourceID())); + HexUtil.toHex8(resValueMap.getNameId())); serializer.attribute(null, "type", resValueMap.getValueType().name()); serializer.text(getValueAsString(resValueMap)); serializer.endTag(null, TAG_VALUE); @@ -238,7 +281,10 @@ public void writeArray(String name, Object[] values) throws IOException { if(values == null){ return; } - int level = INDENT; + int level = mIndent; + if(level == 0){ + level = INDENT; + } KXmlSerializer serializer = getSerializer(); writeIndent(serializer, level); serializer.startTag(null, name); diff --git a/src/main/java/com/reandroid/apkeditor/merge/Merger.java b/src/main/java/com/reandroid/apkeditor/merge/Merger.java index f5d1d1b4..f242fcda 100644 --- a/src/main/java/com/reandroid/apkeditor/merge/Merger.java +++ b/src/main/java/com/reandroid/apkeditor/merge/Merger.java @@ -18,6 +18,7 @@ import com.reandroid.apkeditor.BaseCommand; import com.reandroid.apkeditor.Util; import com.reandroid.apkeditor.common.AndroidManifestHelper; +import com.reandroid.app.AndroidManifest; import com.reandroid.archive.ZipEntryMap; import com.reandroid.archive.ArchiveEntry; import com.reandroid.archive.ArchiveFile; @@ -130,17 +131,17 @@ private File toTmpDir(File file){ return tmp; } private void sanitizeManifest(ApkModule apkModule) { - if(!apkModule.hasAndroidManifestBlock()){ + if(!apkModule.hasAndroidManifest()){ return; } - AndroidManifestBlock manifest = apkModule.getAndroidManifestBlock(); + AndroidManifestBlock manifest = apkModule.getAndroidManifest(); logMessage("Sanitizing manifest ..."); AndroidManifestHelper.removeAttributeFromManifestAndApplication(manifest, - AndroidManifestBlock.ID_extractNativeLibs, - this, AndroidManifestBlock.NAME_extractNativeLibs); + AndroidManifest.ID_extractNativeLibs, + this, AndroidManifest.NAME_extractNativeLibs); AndroidManifestHelper.removeAttributeFromManifestAndApplication(manifest, - AndroidManifestBlock.ID_isSplitRequired, - this, AndroidManifestBlock.NAME_isSplitRequired); + AndroidManifest.ID_isSplitRequired, + this, AndroidManifest.NAME_isSplitRequired); ResXmlElement application = manifest.getApplicationElement(); List splitMetaDataElements = AndroidManifestHelper.listSplitRequired(application); @@ -156,7 +157,7 @@ private void sanitizeManifest(ApkModule apkModule) { manifest.refresh(); } private boolean removeSplitsTableEntry(ResXmlElement metaElement, ApkModule apkModule) { - ResXmlAttribute nameAttribute = metaElement.searchAttributeByResourceId(AndroidManifestBlock.ID_name); + ResXmlAttribute nameAttribute = metaElement.searchAttributeByResourceId(AndroidManifest.ID_name); if(nameAttribute == null){ return false; } @@ -164,10 +165,10 @@ private boolean removeSplitsTableEntry(ResXmlElement metaElement, ApkModule apkM return false; } ResXmlAttribute valueAttribute=metaElement.searchAttributeByResourceId( - AndroidManifestBlock.ID_value); + AndroidManifest.ID_value); if(valueAttribute==null){ valueAttribute=metaElement.searchAttributeByResourceId( - AndroidManifestBlock.ID_resource); + AndroidManifest.ID_resource); } if(valueAttribute == null || valueAttribute.getValueType() != ValueType.REFERENCE){ diff --git a/src/main/java/com/reandroid/apkeditor/protect/Protector.java b/src/main/java/com/reandroid/apkeditor/protect/Protector.java index 50bd8b2a..c8c6f8db 100644 --- a/src/main/java/com/reandroid/apkeditor/protect/Protector.java +++ b/src/main/java/com/reandroid/apkeditor/protect/Protector.java @@ -72,7 +72,7 @@ private void confuseAndroidManifest(ApkModule apkModule) { return; } logMessage("Confusing AndroidManifest ..."); - AndroidManifestBlock manifestBlock = apkModule.getAndroidManifestBlock(); + AndroidManifestBlock manifestBlock = apkModule.getAndroidManifest(); manifestBlock.setAttributesUnitSize(24, true); manifestBlock.refresh(); } diff --git a/src/main/java/com/reandroid/apkeditor/refactor/TypeNameRefactor.java b/src/main/java/com/reandroid/apkeditor/refactor/TypeNameRefactor.java index 2099f3fc..5ec96124 100644 --- a/src/main/java/com/reandroid/apkeditor/refactor/TypeNameRefactor.java +++ b/src/main/java/com/reandroid/apkeditor/refactor/TypeNameRefactor.java @@ -54,7 +54,7 @@ public void refactor() throws IOException { logMessage("Refactoring types ..."); loadTypeStrings(apkModule.getTableBlock()); logMessage("Refactoring from AndroidManifest ..."); - AndroidManifestBlock manifestBlock=apkModule.getAndroidManifestBlock(); + AndroidManifestBlock manifestBlock=apkModule.getAndroidManifest(); scanXml(manifestBlock, 0); scanResFiles(); if(!isFinished()){ @@ -71,7 +71,7 @@ private void logFinished(){ XMLElement element=refactoredTypeMap.toXMLDocument().getDocumentElement(); element.setName("renamed"); element.setAttribute("count", String.valueOf(refactoredTypeMap.count())); - log.append(element.toText()); + log.append(element.getDebugText()); } TypeNameMap remain=new TypeNameMap(); for(Map.Entry entry:mTypeStrings.entrySet()){ @@ -82,7 +82,7 @@ private void logFinished(){ XMLDocument xmlDocument=remain.toXMLDocument(); XMLElement element=xmlDocument.getDocumentElement(); element.setName("remain"); - log.append(xmlDocument.toText()); + log.append(xmlDocument.getDebugText()); } logMessage(log.toString()); } @@ -393,7 +393,7 @@ private boolean checkAttr(ResXmlAttribute attribute){ if(hasRefactoredName(name)){ return false; } - return rename(attribute.getNameResourceID(), name); + return rename(attribute.getNameId(), name); } private boolean checkColor(ResXmlAttribute attribute){ String name="color"; @@ -404,7 +404,7 @@ private boolean checkColor(ResXmlAttribute attribute){ return false; } int textColor=0x01010098; - int nameId=attribute.getNameResourceID(); + int nameId=attribute.getNameId(); if(nameId!=textColor){ return false; } @@ -428,7 +428,7 @@ private boolean checkWithAndroidAttribute(String name, if(hasRefactoredName(name)){ return false; } - int nameId=attribute.getNameResourceID(); + int nameId=attribute.getNameId(); if(nameId == 0){ return false; } @@ -448,7 +448,7 @@ private boolean checkDimen(ResXmlAttribute attribute){ } int layout_width=0x010100f4; int layout_height=0x010100f5; - int nameId=attribute.getNameResourceID(); + int nameId=attribute.getNameId(); if(nameId!=layout_width && nameId!=layout_height){ return false; } @@ -463,7 +463,7 @@ private boolean checkId(ResXmlAttribute attribute){ if(hasRefactoredName(name)){ return false; } - if(attribute.getNameResourceID()!=AndroidManifestBlock.ID_id){ + if(attribute.getNameId()!=AndroidManifestBlock.ID_id){ return false; } if(attribute.getValueType() != ValueType.REFERENCE){ @@ -477,7 +477,7 @@ private boolean checkStyle(ResXmlAttribute attribute){ if(hasRefactoredName(name)){ return false; } - if(attribute.getNameResourceID()!=AndroidManifestBlock.ID_theme){ + if(attribute.getNameId()!=AndroidManifestBlock.ID_theme){ return false; } if(attribute.getValueType() != ValueType.REFERENCE){ @@ -491,7 +491,7 @@ private boolean checkString(ResXmlAttribute attribute){ if(hasRefactoredName(name)){ return false; } - if(attribute.getNameResourceID()!=AndroidManifestBlock.ID_label){ + if(attribute.getNameId()!=AndroidManifestBlock.ID_label){ return false; } if(attribute.getValueType() != ValueType.REFERENCE){ diff --git a/src/main/java/com/reandroid/apkeditor/smali/SmaliCompiler.java b/src/main/java/com/reandroid/apkeditor/smali/SmaliCompiler.java index 3e6c5339..32770c10 100644 --- a/src/main/java/com/reandroid/apkeditor/smali/SmaliCompiler.java +++ b/src/main/java/com/reandroid/apkeditor/smali/SmaliCompiler.java @@ -43,10 +43,13 @@ public List buildDexFiles(ApkModuleEncoder apkModuleEncoder, File m if(!smaliDir.isDirectory()){ return null; } - AndroidManifestBlock manifestBlock = apkModuleEncoder.getApkModule().getAndroidManifestBlock(); + AndroidManifestBlock manifestBlock = apkModuleEncoder.getApkModule().getAndroidManifest(); if (manifestBlock != null) { this.minSdkVersion = manifestBlock.getMinSdkVersion(); } + if(minSdkVersion == null){ + minSdkVersion = 30; + } List results = new ArrayList<>(); List classesDirList = listClassesDirectories(smaliDir); int i = 0;