Skip to content

Commit

Permalink
Print string pool in all formats.
Browse files Browse the repository at this point in the history
Co-authored-by: REAndroid <[email protected]>
Co-authored-by: kikfox <[email protected]>
  • Loading branch information
REAndroid and kikfox committed Sep 28, 2024
1 parent 86b88dc commit d783603
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/reandroid/apkeditor/info/Info.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ private void printXmlStrings(ApkModule apkModule) throws IOException {
ResXmlDocument document = apkModule.loadResXmlDocument(xmlStrings);
document.setApkFile(null);
document.setPackageBlock(null);
infoWriter.writeStringPool(document.getStringPool());
infoWriter.writeStringPool(xmlStrings, document.getStringPool());
}
private void printXmlTree(ApkModule apkModule) throws IOException {
InfoOptions options = getOptions();
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/reandroid/apkeditor/info/InfoWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ public void writeDexInfo(DexDirectory dexDirectory) throws IOException {
}
}

public void writeStringPool(StringPool<?> stringPool) throws IOException {

}
public abstract void writeStringPool(String source, StringPool<?> stringPool) throws IOException;
public abstract void writeXmlDocument(String sourcePath, ResXmlDocument xmlDocument) throws IOException;
public abstract void writeCertificates(List<CertificateBlock> certificateList, boolean base64) throws IOException;
public abstract void writeDexInfo(DexFile dexFile, boolean writeSectionInfo) throws IOException;
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/reandroid/apkeditor/info/InfoWriterJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import com.reandroid.arsc.chunk.PackageBlock;
import com.reandroid.arsc.chunk.xml.ResXmlDocument;
import com.reandroid.arsc.container.SpecTypePair;
import com.reandroid.arsc.item.StringItem;
import com.reandroid.arsc.model.ResourceEntry;
import com.reandroid.arsc.pool.StringPool;
import com.reandroid.arsc.value.Entry;
import com.reandroid.arsc.value.ResTableMapEntry;
import com.reandroid.arsc.value.ResValue;
Expand All @@ -47,6 +49,24 @@ public InfoWriterJson(Writer writer) {
this.mJsonWriter = jsonWriter;
}

@Override
public void writeStringPool(String source, StringPool<?> stringPool) throws IOException {
JSONWriter jsonWriter = mJsonWriter.object()
.key("string_pool").object()
.key("source").value(source)
.key("count").value(stringPool.size())
.key("styles").value(stringPool.countStyles())
.key("sorted").value(stringPool.getHeaderBlock().isSorted())
.key("utf8").value(stringPool.isUtf8())
.key("bytes").value(stringPool.getHeaderBlock().getChunkSize())
.key("strings").array();
int size = stringPool.size();
for (int i = 0; i < size; i++ ) {
StringItem item = stringPool.get(i);
jsonWriter.value(item.get());
}
jsonWriter.endArray().endObject().endObject();
}
@Override
public void writeXmlDocument(String sourcePath, ResXmlDocument xmlDocument) throws IOException {
JSONWriter jsonWriter = mJsonWriter.object();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ public InfoWriterText(Writer writer) {
}

@Override
public void writeStringPool(StringPool<?> stringPool) throws IOException {
public void writeStringPool(String source, StringPool<?> stringPool) throws IOException {
Writer writer = getWriter();
writer.write(source);
writer.write("\n");
writer.write("String pool of ");
writer.write(Integer.toString(stringPool.size()));
writer.write(" unique ");
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/reandroid/apkeditor/info/InfoWriterXml.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.reandroid.archive.block.CertificateBlock;
import com.reandroid.arsc.chunk.xml.ResXmlDocument;
import com.reandroid.arsc.chunk.xml.ResXmlNode;
import com.reandroid.arsc.item.StringItem;
import com.reandroid.arsc.pool.StringPool;
import com.reandroid.dex.model.DexFile;
import com.reandroid.dex.sections.MapItem;
import com.reandroid.dex.sections.MapList;
Expand Down Expand Up @@ -52,6 +54,36 @@ public InfoWriterXml(Writer writer) {
super(writer);
}

@Override
public void writeStringPool(String source, StringPool<?> stringPool) throws IOException {
KXmlSerializer serializer = getSerializer();
int indent = mIndent + 2;
mIndent = indent;
writeIndent(serializer, indent);
indent = mIndent + 2;
mIndent = indent;
serializer.startTag(null, "string-pool");
serializer.attribute(null, "source", source);
serializer.attribute(null, "count", Integer.toString(stringPool.size()));
serializer.attribute(null, "styles", Integer.toString(stringPool.countStyles()));
serializer.attribute(null, "sorted", String.valueOf(stringPool.getHeaderBlock().isSorted()));
serializer.attribute(null, "utf8", String.valueOf(stringPool.isUtf8()));
serializer.attribute(null, "bytes", String.valueOf(stringPool.getHeaderBlock().getChunkSize()));

int size = stringPool.size();
for (int i = 0; i < size; i++ ) {
StringItem item = stringPool.get(i);
writeIndent(serializer, indent);
serializer.startTag(null, "item");
serializer.text(item.get());
serializer.endTag(null, "item");
}

indent = indent - 2;
writeIndent(serializer, indent);
serializer.endTag(null, "string-pool");
serializer.flush();
}
@Override
public void writeXmlDocument(String sourcePath, ResXmlDocument xmlDocument) throws IOException {
KXmlSerializer serializer = getSerializer();
Expand Down

0 comments on commit d783603

Please sign in to comment.