diff --git a/src/main/java/com/reandroid/apk/ApkModuleXmlDecoder.java b/src/main/java/com/reandroid/apk/ApkModuleXmlDecoder.java index 4915da3cb..9fd162204 100644 --- a/src/main/java/com/reandroid/apk/ApkModuleXmlDecoder.java +++ b/src/main/java/com/reandroid/apk/ApkModuleXmlDecoder.java @@ -241,7 +241,7 @@ private void decodeValues(EntryStore entryStore, File outDir, TypeBlock typeBloc xmlDocument.save(file, false); } private XMLElement decodeValue(EntryStore entryStore, Entry entry){ - XMLElement element=new XMLElement(entry.getTypeName()); + XMLElement element=new XMLElement(XmlHelper.toXMLTagName(entry.getTypeName())); int resourceId= entry.getResourceId(); XMLAttribute attribute=new XMLAttribute("name", entry.getName()); element.addAttribute(attribute); diff --git a/src/main/java/com/reandroid/apk/XmlHelper.java b/src/main/java/com/reandroid/apk/XmlHelper.java index bf38694a2..c519da20d 100644 --- a/src/main/java/com/reandroid/apk/XmlHelper.java +++ b/src/main/java/com/reandroid/apk/XmlHelper.java @@ -30,4 +30,11 @@ public static void setTextContent(XMLElement element, StringItem stringItem){ element.setSpannableText(stringItem.getXml()); } } + public static String toXMLTagName(String typeName){ + // e.g ^attr-private + if(typeName.length()>0 && typeName.charAt(0)=='^'){ + typeName = typeName.substring(1); + } + return typeName; + } } diff --git a/src/main/java/com/reandroid/apk/xmlencoder/EncodeMaterials.java b/src/main/java/com/reandroid/apk/xmlencoder/EncodeMaterials.java index e13152db4..d92794e1a 100644 --- a/src/main/java/com/reandroid/apk/xmlencoder/EncodeMaterials.java +++ b/src/main/java/com/reandroid/apk/xmlencoder/EncodeMaterials.java @@ -50,8 +50,16 @@ public SpecString getSpecString(String name){ .get(0); } public Entry getAttributeBlock(String refString){ - String packageName = null; String type = "attr"; + Entry entry = getAttributeBlock(type, refString); + if(entry == null){ + type = "^attr-private"; + entry = getAttributeBlock(type, refString); + } + return entry; + } + private Entry getAttributeBlock(String type, String refString){ + String packageName = null; String name = refString; int i=refString.lastIndexOf(':'); if(i>=0){ diff --git a/src/main/java/com/reandroid/apk/xmlencoder/EncodeUtil.java b/src/main/java/com/reandroid/apk/xmlencoder/EncodeUtil.java index b6b3e0a23..278a3a33d 100644 --- a/src/main/java/com/reandroid/apk/xmlencoder/EncodeUtil.java +++ b/src/main/java/com/reandroid/apk/xmlencoder/EncodeUtil.java @@ -128,6 +128,9 @@ public static String getTypeNameFromValuesXml(File valuesXml){ return name; } public static String sanitizeType(String type){ + if(type.startsWith("^attr")){ + return type; + } Matcher matcher=PATTERN_TYPE.matcher(type); if(!matcher.find()){ return ""; diff --git a/src/main/java/com/reandroid/apk/xmlencoder/ValuesEncoder.java b/src/main/java/com/reandroid/apk/xmlencoder/ValuesEncoder.java index dc522517b..3d8612bc4 100644 --- a/src/main/java/com/reandroid/apk/xmlencoder/ValuesEncoder.java +++ b/src/main/java/com/reandroid/apk/xmlencoder/ValuesEncoder.java @@ -44,7 +44,9 @@ public ValuesEncoder(EncodeMaterials materials){ this.commonEncoder=new XMLValuesEncoderCommon(materials); Map mapBag=new HashMap<>(); - mapBag.put("attr", new XMLValuesEncoderAttr(materials)); + XMLValuesEncoderAttr encoderAttr = new XMLValuesEncoderAttr(materials); + mapBag.put("attr", encoderAttr); + mapBag.put("^attr-private", encoderAttr); mapBag.put("plurals", new XMLValuesEncoderPlurals(materials)); mapBag.put("array", new XMLValuesEncoderArray(materials)); mapBag.put("style", new XMLValuesEncoderStyle(materials)); @@ -79,6 +81,9 @@ private boolean isBag(XMLDocument xmlDocument, String type){ if(type.startsWith("attr")){ return true; } + if(type.startsWith("^attr")){ + return true; + } if(type.startsWith("style")){ return true; } @@ -117,6 +122,9 @@ private String getType(XMLDocument xmlDocument, String def){ if(type.endsWith("-array")){ return "array"; } + if(type.startsWith("attr-private")){ + return "^attr-private"; + } if(type.equals("item")){ return def; } diff --git a/src/main/java/com/reandroid/apk/xmlencoder/XMLValuesEncoderAttr.java b/src/main/java/com/reandroid/apk/xmlencoder/XMLValuesEncoderAttr.java index 5aafd451c..66b803ca5 100644 --- a/src/main/java/com/reandroid/apk/xmlencoder/XMLValuesEncoderAttr.java +++ b/src/main/java/com/reandroid/apk/xmlencoder/XMLValuesEncoderAttr.java @@ -17,6 +17,7 @@ import com.reandroid.arsc.array.ResValueMapArray; import com.reandroid.arsc.decoder.ValueDecoder; +import com.reandroid.arsc.value.EntryHeaderMap; import com.reandroid.arsc.value.ResTableMapEntry; import com.reandroid.arsc.value.ResValueMap; import com.reandroid.arsc.value.ValueType; @@ -42,8 +43,10 @@ int getChildesCount(XMLElement element){ void encodeChildes(XMLElement parentElement, ResTableMapEntry mapEntry){ encodeAttributes(parentElement, mapEntry); encodeEnumOrFlag(parentElement, mapEntry); - // TODO: re-check if this is necessary - mapEntry.getHeader().setPublic(true); + EntryHeaderMap header = mapEntry.getHeader(); + boolean is_public = !mapEntry.getParentEntry() + .getTypeName().contains("private"); + header.setPublic(is_public); } private void encodeAttributes(XMLElement parentElement, ResTableMapEntry mapEntry){ ResValueMapArray mapArray = mapEntry.getValue();