better hex conversion

This commit is contained in:
REAndroid 2023-05-04 15:01:57 +02:00
parent 1b240b2281
commit f5ec1381a4
40 changed files with 1459 additions and 1320 deletions

View File

@ -16,6 +16,7 @@
package com.reandroid.apk; package com.reandroid.apk;
import com.reandroid.archive.InputSource; import com.reandroid.archive.InputSource;
import com.reandroid.arsc.util.HexUtil;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
@ -148,7 +149,7 @@ public class PathSanitizer {
} }
private static String createUniqueName(String name){ private static String createUniqueName(String name){
int hash = name.hashCode(); int hash = name.hashCode();
return String.format("alias_%08x", hash).toLowerCase(); return "alias_" + HexUtil.toHexNoPrefix8(hash);
} }
private static boolean isGoodSimpleName(String name){ private static boolean isGoodSimpleName(String name){
if(name==null){ if(name==null){

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -19,6 +19,7 @@ import com.reandroid.arsc.chunk.PackageBlock;
import com.reandroid.arsc.chunk.TableBlock; import com.reandroid.arsc.chunk.TableBlock;
import com.reandroid.arsc.group.EntryGroup; import com.reandroid.arsc.group.EntryGroup;
import com.reandroid.arsc.pool.SpecStringPool; import com.reandroid.arsc.pool.SpecStringPool;
import com.reandroid.arsc.util.HexUtil;
import com.reandroid.arsc.util.ResNameMap; import com.reandroid.arsc.util.ResNameMap;
import com.reandroid.json.JSONArray; import com.reandroid.json.JSONArray;
import com.reandroid.json.JSONObject; import com.reandroid.json.JSONObject;
@ -379,7 +380,7 @@ import java.util.*;
type.add(entry); type.add(entry);
} }
public String getHexId(){ public String getHexId(){
return String.format("0x%02x", id); return HexUtil.toHex2(id);
} }
public JSONObject toJson(){ public JSONObject toJson(){
JSONObject jsonObject=new JSONObject(); JSONObject jsonObject=new JSONObject();
@ -575,7 +576,7 @@ import java.util.*;
return entryMap.get(entryId); return entryMap.get(entryId);
} }
public String getHexId(){ public String getHexId(){
return String.format("0x%02x", id); return HexUtil.toHex2(id);
} }
public void add(Entry entry){ public void add(Entry entry){
if(entry==null){ if(entry==null){
@ -733,7 +734,7 @@ import java.util.*;
| (getEntryId() & 0xffff); | (getEntryId() & 0xffff);
} }
public String getHexId(){ public String getHexId(){
return String.format("0x%08x", getResourceId()); return HexUtil.toHex8(getResourceId());
} }
public void writeXml(String indent, Writer writer) throws IOException{ public void writeXml(String indent, Writer writer) throws IOException{

View File

@ -21,6 +21,7 @@ import com.reandroid.arsc.chunk.StagedAlias;
import com.reandroid.arsc.chunk.TableBlock; import com.reandroid.arsc.chunk.TableBlock;
import com.reandroid.arsc.chunk.TypeBlock; import com.reandroid.arsc.chunk.TypeBlock;
import com.reandroid.arsc.container.SpecTypePair; import com.reandroid.arsc.container.SpecTypePair;
import com.reandroid.arsc.util.HexUtil;
import com.reandroid.json.JSONObject; import com.reandroid.json.JSONObject;
import java.io.File; import java.io.File;
@ -73,7 +74,7 @@ public class TableBlockJson {
private String getFileName(TypeBlock typeBlock){ private String getFileName(TypeBlock typeBlock){
StringBuilder builder=new StringBuilder(); StringBuilder builder=new StringBuilder();
builder.append(String.format("%03d-", typeBlock.getIndex())); builder.append(String.format("%03d-", typeBlock.getIndex()));
builder.append(String.format("0x%02x", typeBlock.getTypeId())); builder.append(HexUtil.toHex2(typeBlock.getTypeId()));
String name= typeBlock.getTypeName(); String name= typeBlock.getTypeName();
builder.append('-').append(name); builder.append('-').append(name);
builder.append(typeBlock.getResConfig().getQualifiers()); builder.append(typeBlock.getResConfig().getQualifiers());
@ -81,7 +82,7 @@ public class TableBlockJson {
} }
private String getDirName(PackageBlock packageBlock){ private String getDirName(PackageBlock packageBlock){
StringBuilder builder=new StringBuilder(); StringBuilder builder=new StringBuilder();
builder.append(String.format("0x%02x", packageBlock.getId())); builder.append(HexUtil.toHex2((byte) packageBlock.getId()));
builder.append("-"); builder.append("-");
builder.append(packageBlock.getIndex()); builder.append(packageBlock.getIndex());
String name= ApkUtil.sanitizeForFileName(packageBlock.getName()); String name= ApkUtil.sanitizeForFileName(packageBlock.getName());

View File

@ -16,6 +16,7 @@
package com.reandroid.apk.xmldecoder; package com.reandroid.apk.xmldecoder;
import com.reandroid.apk.XmlHelper; import com.reandroid.apk.XmlHelper;
import com.reandroid.arsc.util.HexUtil;
import com.reandroid.arsc.value.Entry; import com.reandroid.arsc.value.Entry;
import com.reandroid.arsc.value.ResTableMapEntry; import com.reandroid.arsc.value.ResTableMapEntry;
import com.reandroid.arsc.value.ValueType; import com.reandroid.arsc.value.ValueType;
@ -58,7 +59,7 @@ class BagDecoderAttr<OUTPUT> extends BagDecoder<OUTPUT>{
int rawVal = item.getData(); int rawVal = item.getData();
String value; String value;
if(item.getBagItem().getValueType() == ValueType.INT_HEX){ if(item.getBagItem().getValueType() == ValueType.INT_HEX){
value = String.format("0x%08x", rawVal); value = HexUtil.toHex8(rawVal);
}else { }else {
value = String.valueOf(rawVal); value = String.valueOf(rawVal);
} }

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -13,28 +13,29 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.reandroid.apk.xmlencoder; package com.reandroid.apk.xmlencoder;
import com.reandroid.apk.APKLogger; import com.reandroid.apk.APKLogger;
import com.reandroid.apk.FrameworkApk; import com.reandroid.apk.FrameworkApk;
import com.reandroid.apk.ResourceIds; import com.reandroid.apk.ResourceIds;
import com.reandroid.arsc.chunk.PackageBlock; import com.reandroid.arsc.chunk.PackageBlock;
import com.reandroid.arsc.chunk.TableBlock; import com.reandroid.arsc.chunk.TableBlock;
import com.reandroid.arsc.chunk.TypeBlock; import com.reandroid.arsc.chunk.TypeBlock;
import com.reandroid.arsc.container.SpecTypePair; import com.reandroid.arsc.container.SpecTypePair;
import com.reandroid.arsc.decoder.ValueDecoder; import com.reandroid.arsc.decoder.ValueDecoder;
import com.reandroid.arsc.group.EntryGroup; import com.reandroid.arsc.group.EntryGroup;
import com.reandroid.arsc.item.SpecString; import com.reandroid.arsc.item.SpecString;
import com.reandroid.arsc.util.FrameworkTable; import com.reandroid.arsc.util.FrameworkTable;
import com.reandroid.arsc.util.ResNameMap; import com.reandroid.arsc.util.HexUtil;
import com.reandroid.arsc.value.Entry; import com.reandroid.arsc.util.ResNameMap;
import com.reandroid.common.Frameworks; import com.reandroid.arsc.value.Entry;
import com.reandroid.common.Frameworks;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
public class EncodeMaterials { public class EncodeMaterials {
private final Set<ResourceIds.Table.Package> packageIdSet = new HashSet<>(); private final Set<ResourceIds.Table.Package> packageIdSet = new HashSet<>();
private PackageBlock currentPackage; private PackageBlock currentPackage;
private final Set<FrameworkTable> frameworkTables = new HashSet<>(); private final Set<FrameworkTable> frameworkTables = new HashSet<>();
@ -136,7 +137,7 @@
return entry.getResourceId(); return entry.getResourceId();
} }
throw new EncodeException("Framework entry not found: " + throw new EncodeException("Framework entry not found: " +
"packageId="+String.format("0x%02x", packageId)+ "packageId=" + HexUtil.toHex2((byte) packageId)+
", type="+type+ ", type="+type+
", name="+name); ", name="+name);
} }
@ -356,4 +357,4 @@
return encodeMaterials; return encodeMaterials;
} }
} }

View File

@ -17,6 +17,7 @@ package com.reandroid.archive2;
import com.reandroid.archive2.block.CentralEntryHeader; import com.reandroid.archive2.block.CentralEntryHeader;
import com.reandroid.archive2.block.LocalFileHeader; import com.reandroid.archive2.block.LocalFileHeader;
import com.reandroid.arsc.util.HexUtil;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
@ -116,6 +117,7 @@ public class ArchiveEntry extends ZipEntry {
@Override @Override
public String toString(){ public String toString(){
return "["+ getFileOffset()+"] "+getName()+getComment()+String.format(" 0x%08x", getCrc()); return "["+ getFileOffset()+"] " + getName() + getComment()
+ HexUtil.toHex(" 0x", getCrc(), 8);
} }
} }

View File

@ -16,6 +16,7 @@
package com.reandroid.archive2.block; package com.reandroid.archive2.block;
import com.reandroid.archive2.ZipSignature; import com.reandroid.archive2.ZipSignature;
import com.reandroid.arsc.util.HexUtil;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -134,12 +135,12 @@ public class CentralEntryHeader extends CommonHeader {
builder.append(", "); builder.append(", ");
} }
builder.append("SIG=").append(getSignature()); builder.append("SIG=").append(getSignature());
builder.append(", versionMadeBy=").append(String.format("0x%04x", getVersionMadeBy())); builder.append(", versionMadeBy=").append(HexUtil.toHex4((short) getVersionMadeBy()));
builder.append(", versionExtract=").append(String.format("0x%04x", getVersionExtract())); builder.append(", versionExtract=").append(HexUtil.toHex4((short) getVersionExtract()));
builder.append(", GP={").append(getGeneralPurposeFlag()).append("}"); builder.append(", GP={").append(getGeneralPurposeFlag()).append("}");
builder.append(", method=").append(getMethod()); builder.append(", method=").append(getMethod());
builder.append(", date=").append(getDate()); builder.append(", date=").append(getDate());
builder.append(", crc=").append(String.format("0x%08x", getCrc())); builder.append(", crc=").append(HexUtil.toHex8(getCrc()));
builder.append(", cSize=").append(getCompressedSize()); builder.append(", cSize=").append(getCompressedSize());
builder.append(", size=").append(getSize()); builder.append(", size=").append(getSize());
builder.append(", fileNameLength=").append(getFileNameLength()); builder.append(", fileNameLength=").append(getFileNameLength());

View File

@ -16,6 +16,7 @@
package com.reandroid.archive2.block; package com.reandroid.archive2.block;
import com.reandroid.archive2.ZipSignature; import com.reandroid.archive2.ZipSignature;
import com.reandroid.arsc.util.HexUtil;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -287,12 +288,12 @@ public abstract class CommonHeader extends ZipHeader {
builder.append(", "); builder.append(", ");
} }
builder.append("SIG=").append(getSignature()); builder.append("SIG=").append(getSignature());
builder.append(", versionMadeBy=").append(String.format("0x%04x", getVersionMadeBy())); builder.append(", versionMadeBy=").append(HexUtil.toHex4((short) getVersionMadeBy()));
builder.append(", platform=").append(String.format("0x%02x", getPlatform())); builder.append(", platform=").append(HexUtil.toHex2((byte) getPlatform()));
builder.append(", GP={").append(getGeneralPurposeFlag()).append("}"); builder.append(", GP={").append(getGeneralPurposeFlag()).append("}");
builder.append(", method=").append(getMethod()); builder.append(", method=").append(getMethod());
builder.append(", date=").append(getDate()); builder.append(", date=").append(getDate());
builder.append(", crc=").append(String.format("0x%08x", getCrc())); builder.append(", crc=").append(HexUtil.toHex8(getCrc()));
builder.append(", cSize=").append(getCompressedSize()); builder.append(", cSize=").append(getCompressedSize());
builder.append(", size=").append(getSize()); builder.append(", size=").append(getSize());
builder.append(", fileNameLength=").append(getFileNameLength()); builder.append(", fileNameLength=").append(getFileNameLength());

View File

@ -16,6 +16,7 @@
package com.reandroid.archive2.block; package com.reandroid.archive2.block;
import com.reandroid.archive2.ZipSignature; import com.reandroid.archive2.ZipSignature;
import com.reandroid.arsc.util.HexUtil;
public class DataDescriptor extends ZipHeader{ public class DataDescriptor extends ZipHeader{
public DataDescriptor() { public DataDescriptor() {
@ -44,7 +45,7 @@ public class DataDescriptor extends ZipHeader{
public String toString(){ public String toString(){
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append(getSignature()); builder.append(getSignature());
builder.append(", crc=").append(String.format("0x%08x", getCrc())); builder.append(", crc=").append(HexUtil.toHex8(getCrc()));
builder.append(", compressed=").append(getCompressedSize()); builder.append(", compressed=").append(getCompressedSize());
builder.append(", size=").append(getSize()); builder.append(", size=").append(getSize());
return builder.toString(); return builder.toString();

View File

@ -16,6 +16,7 @@
package com.reandroid.archive2.block; package com.reandroid.archive2.block;
import com.reandroid.archive2.ZipSignature; import com.reandroid.archive2.ZipSignature;
import com.reandroid.arsc.util.HexUtil;
public class EndRecord extends ZipHeader{ public class EndRecord extends ZipHeader{
public EndRecord() { public EndRecord() {
@ -78,7 +79,7 @@ public class EndRecord extends ZipHeader{
builder.append(", total dirs=").append(getTotalNumberOfDirectories()); builder.append(", total dirs=").append(getTotalNumberOfDirectories());
builder.append(", length=").append(getLengthOfCentralDirectory()); builder.append(", length=").append(getLengthOfCentralDirectory());
builder.append(", offset=").append(getOffsetOfCentralDirectory()); builder.append(", offset=").append(getOffsetOfCentralDirectory());
builder.append(", last=").append(String.format("0x%08x", getLastShort())); builder.append(", last=").append(HexUtil.toHex8(getLastShort()));
return builder.toString(); return builder.toString();
} }

View File

@ -16,6 +16,7 @@
package com.reandroid.archive2.block; package com.reandroid.archive2.block;
import com.reandroid.arsc.decoder.ValueDecoder; import com.reandroid.arsc.decoder.ValueDecoder;
import com.reandroid.arsc.util.HexUtil;
import java.util.Objects; import java.util.Objects;
@ -39,7 +40,7 @@ public class SignatureId implements Comparable<SignatureId>{
if (this.name != null) { if (this.name != null) {
return name + FILE_EXT_RAW; return name + FILE_EXT_RAW;
} }
return String.format("0x%08x", id) + FILE_EXT_RAW; return HexUtil.toHex8(id) + FILE_EXT_RAW;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
@ -66,7 +67,7 @@ public class SignatureId implements Comparable<SignatureId>{
if (name != null) { if (name != null) {
return name; return name;
} }
return "UNKNOWN(" + String.format("0x%08x", id) + ")"; return "UNKNOWN(" + HexUtil.toHex8(id) + ")";
} }
public static SignatureId valueOf(String name) { public static SignatureId valueOf(String name) {
if (name == null) { if (name == null) {

View File

@ -15,6 +15,8 @@
*/ */
package com.reandroid.archive2.io; package com.reandroid.archive2.io;
import com.reandroid.arsc.util.HexUtil;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.zip.CRC32; import java.util.zip.CRC32;
@ -124,6 +126,6 @@ public class CountingInputStream<T extends InputStream> extends InputStream {
if(!mFinished || crc==null){ if(!mFinished || crc==null){
return "[" + size + "]: " + inputStream.getClass().getSimpleName(); return "[" + size + "]: " + inputStream.getClass().getSimpleName();
} }
return "[size=" + size +", crc=" + String.format("0x%08x", mCheckSum) + "]: " + inputStream.getClass().getSimpleName(); return "[size=" + size +", crc=" + HexUtil.toHex8(mCheckSum) + "]: " + inputStream.getClass().getSimpleName();
} }
} }

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -15,6 +15,8 @@
*/ */
package com.reandroid.arsc.chunk; package com.reandroid.arsc.chunk;
import com.reandroid.arsc.util.HexUtil;
public enum ChunkType { public enum ChunkType {
NULL((short)0x0000), NULL((short)0x0000),
@ -45,7 +47,7 @@ public enum ChunkType {
@Override @Override
public String toString(){ public String toString(){
return name()+String.format("(0x%04x)", ((int) ID)); return name() + "(" + HexUtil.toHex4(ID) + ")";
} }
public static ChunkType get(short id){ public static ChunkType get(short id){

View File

@ -29,6 +29,7 @@ import com.reandroid.arsc.list.StagedAliasList;
import com.reandroid.arsc.pool.SpecStringPool; import com.reandroid.arsc.pool.SpecStringPool;
import com.reandroid.arsc.pool.TableStringPool; import com.reandroid.arsc.pool.TableStringPool;
import com.reandroid.arsc.pool.TypeStringPool; import com.reandroid.arsc.pool.TypeStringPool;
import com.reandroid.arsc.util.HexUtil;
import com.reandroid.arsc.value.Entry; import com.reandroid.arsc.value.Entry;
import com.reandroid.arsc.value.LibraryInfo; import com.reandroid.arsc.value.LibraryInfo;
import com.reandroid.arsc.value.ResConfig; import com.reandroid.arsc.value.ResConfig;
@ -466,7 +467,7 @@ public class PackageBlock extends Chunk<PackageHeader>
StringBuilder builder=new StringBuilder(); StringBuilder builder=new StringBuilder();
builder.append(super.toString()); builder.append(super.toString());
builder.append(", id="); builder.append(", id=");
builder.append(String.format("0x%02x", getId())); builder.append(HexUtil.toHex2((byte) getId()));
builder.append(", name="); builder.append(", name=");
builder.append(getName()); builder.append(getName());
int libCount=getLibraryBlock().getLibraryCount(); int libCount=getLibraryBlock().getLibraryCount();

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -13,18 +13,19 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.reandroid.arsc.chunk; package com.reandroid.arsc.chunk;
import com.reandroid.arsc.array.TypeBlockArray; import com.reandroid.arsc.array.TypeBlockArray;
import com.reandroid.arsc.container.SpecTypePair; import com.reandroid.arsc.container.SpecTypePair;
import com.reandroid.arsc.header.SpecHeader; import com.reandroid.arsc.header.SpecHeader;
import com.reandroid.arsc.item.*; import com.reandroid.arsc.item.*;
import com.reandroid.json.JSONConvert; import com.reandroid.arsc.util.HexUtil;
import com.reandroid.json.JSONObject; import com.reandroid.json.JSONConvert;
import com.reandroid.json.JSONObject;
import java.util.List; import java.util.List;
public class SpecBlock extends Chunk<SpecHeader> implements JSONConvert<JSONObject> { public class SpecBlock extends Chunk<SpecHeader> implements JSONConvert<JSONObject> {
private final SpecFlagsArray specFlagsArray; private final SpecFlagsArray specFlagsArray;
public SpecBlock() { public SpecBlock() {
super(new SpecHeader(), 1); super(new SpecHeader(), 1);
@ -150,7 +151,7 @@
if(appendOnce){ if(appendOnce){
builder.append('|'); builder.append('|');
} }
builder.append(String.format("0x%02x", flagValueInt)); builder.append(HexUtil.toHex2((byte) flagValueInt));
} }
return builder.toString(); return builder.toString();
} }
@ -159,4 +160,4 @@
public static final String NAME_spec = "spec"; public static final String NAME_spec = "spec";
public static final String NAME_spec_flags = "spec_flags"; public static final String NAME_spec_flags = "spec_flags";
public static final String NAME_flag = "flag"; public static final String NAME_flag = "flag";
} }

View File

@ -21,6 +21,7 @@ import com.reandroid.arsc.io.BlockReader;
import com.reandroid.arsc.item.*; import com.reandroid.arsc.item.*;
import com.reandroid.arsc.pool.ResXmlStringPool; import com.reandroid.arsc.pool.ResXmlStringPool;
import com.reandroid.arsc.pool.StringPool; import com.reandroid.arsc.pool.StringPool;
import com.reandroid.arsc.util.HexUtil;
import com.reandroid.arsc.value.AttributeValue; import com.reandroid.arsc.value.AttributeValue;
import com.reandroid.arsc.value.ValueItem; import com.reandroid.arsc.value.ValueItem;
import com.reandroid.arsc.value.ValueType; import com.reandroid.arsc.value.ValueType;
@ -419,10 +420,10 @@ public class ResXmlAttribute extends ValueItem implements AttributeValue, Compar
if(group==null){ if(group==null){
//Lets ignore such error until XML encoder implemented //Lets ignore such error until XML encoder implemented
//throw new XMLException("Failed to decode attribute name: " //throw new XMLException("Failed to decode attribute name: "
//+ String.format("@0x%08x", resourceId)); //HexUtil.toHex8("@0x", resourceId));
name=String.format("@0x%08x", resourceId); name = HexUtil.toHex8("@0x", resourceId);
}else { }else {
name=group.getSpecName(); name = group.getSpecName();
} }
} }
String prefix = getNamePrefix(); String prefix = getNamePrefix();
@ -445,7 +446,7 @@ public class ResXmlAttribute extends ValueItem implements AttributeValue, Compar
if(fullName!=null ){ if(fullName!=null ){
int id=getNameResourceID(); int id=getNameResourceID();
if(id!=0){ if(id!=0){
fullName=fullName+"(@"+String.format("0x%08x",id)+")"; fullName=fullName+"(@"+ HexUtil.toHex8(id)+")";
} }
String valStr; String valStr;
ValueType valueType=getValueType(); ValueType valueType=getValueType();
@ -456,7 +457,7 @@ public class ResXmlAttribute extends ValueItem implements AttributeValue, Compar
}else if (valueType==ValueType.INT_DEC){ }else if (valueType==ValueType.INT_DEC){
valStr = String.valueOf(getData()); valStr = String.valueOf(getData());
}else { }else {
valStr = "["+valueType+"] " + String.format("0x%08x",getData()); valStr = "["+valueType+"] " + HexUtil.toHex8(getData());
} }
if(valStr!=null){ if(valStr!=null){
return fullName+"=\""+valStr+"\""; return fullName+"=\""+valStr+"\"";

View File

@ -27,6 +27,7 @@ import com.reandroid.arsc.io.BlockReader;
import com.reandroid.arsc.item.TypeString; import com.reandroid.arsc.item.TypeString;
import com.reandroid.arsc.pool.SpecStringPool; import com.reandroid.arsc.pool.SpecStringPool;
import com.reandroid.arsc.pool.TableStringPool; import com.reandroid.arsc.pool.TableStringPool;
import com.reandroid.arsc.util.HexUtil;
import com.reandroid.arsc.value.Entry; import com.reandroid.arsc.value.Entry;
import com.reandroid.arsc.value.ResConfig; import com.reandroid.arsc.value.ResConfig;
import com.reandroid.json.JSONConvert; import com.reandroid.json.JSONConvert;
@ -338,7 +339,7 @@ public class SpecTypePair extends BlockContainer<Block>
@Override @Override
public String toString(){ public String toString(){
StringBuilder builder=new StringBuilder(); StringBuilder builder=new StringBuilder();
builder.append(String.format("0x%02x", getTypeId())); builder.append(HexUtil.toHex2(getTypeId()));
builder.append(" ("); builder.append(" (");
TypeString ts = getTypeString(); TypeString ts = getTypeString();
if(ts!=null){ if(ts!=null){

View File

@ -15,6 +15,7 @@
*/ */
package com.reandroid.arsc.decoder; package com.reandroid.arsc.decoder;
import com.reandroid.arsc.util.HexUtil;
import com.reandroid.arsc.value.ValueType; import com.reandroid.arsc.value.ValueType;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -43,7 +44,7 @@ public class ColorUtil {
default: default:
return null; return null;
} }
String hex = String.format("%08x", data); String hex = HexUtil.toHexNoPrefix8(data);
return "#" + hex.substring(index); return "#" + hex.substring(index);
} }
public static ValueDecoder.EncodeResult encode(String hexColor){ public static ValueDecoder.EncodeResult encode(String hexColor){

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -25,6 +25,7 @@ import com.reandroid.arsc.chunk.xml.AndroidManifestBlock;
import com.reandroid.arsc.chunk.xml.ResXmlDocument; import com.reandroid.arsc.chunk.xml.ResXmlDocument;
import com.reandroid.arsc.group.EntryGroup; import com.reandroid.arsc.group.EntryGroup;
import com.reandroid.arsc.util.FrameworkTable; import com.reandroid.arsc.util.FrameworkTable;
import com.reandroid.arsc.util.HexUtil;
import com.reandroid.arsc.value.AttributeValue; import com.reandroid.arsc.value.AttributeValue;
import com.reandroid.arsc.value.Value; import com.reandroid.arsc.value.Value;
import com.reandroid.arsc.value.ValueType; import com.reandroid.arsc.value.ValueType;
@ -57,7 +58,7 @@ public class Decoder {
return null; return null;
} }
private String hexResourceName(int resourceId){ private String hexResourceName(int resourceId){
return String.format("@0x%08x", resourceId); return HexUtil.toHex8("@0x", resourceId);
} }
public String decodeValue(Value value){ public String decodeValue(Value value){
if(value==null){ if(value==null){

View File

@ -20,6 +20,7 @@ import com.reandroid.arsc.chunk.TableBlock;
import com.reandroid.arsc.group.EntryGroup; import com.reandroid.arsc.group.EntryGroup;
import com.reandroid.arsc.item.TableString; import com.reandroid.arsc.item.TableString;
import com.reandroid.arsc.pool.TableStringPool; import com.reandroid.arsc.pool.TableStringPool;
import com.reandroid.arsc.util.HexUtil;
import com.reandroid.arsc.value.*; import com.reandroid.arsc.value.*;
import com.reandroid.arsc.value.attribute.AttributeBag; import com.reandroid.arsc.value.attribute.AttributeBag;
import com.reandroid.common.EntryStore; import com.reandroid.common.EntryStore;
@ -265,11 +266,11 @@ public class ValueDecoder {
public static String decodeAttributeName(EntryStore store, PackageBlock currentPackage, int resourceId){ public static String decodeAttributeName(EntryStore store, PackageBlock currentPackage, int resourceId){
EntryGroup entryGroup=searchEntryGroup(store, currentPackage, resourceId); EntryGroup entryGroup=searchEntryGroup(store, currentPackage, resourceId);
if(entryGroup==null){ if(entryGroup==null){
return String.format("@0x%08x", resourceId); return HexUtil.toHex8("@0x", resourceId);
} }
Entry entry =entryGroup.pickOne(); Entry entry = entryGroup.pickOne();
if(entry ==null){ if(entry == null){
return String.format("@0x%08x", resourceId); return HexUtil.toHex8("@0x", resourceId);
} }
String prefix=null; String prefix=null;
if(currentPackage!=null){ if(currentPackage!=null){
@ -705,7 +706,7 @@ public class ValueDecoder {
} }
private static String decodeHex(int rawVal){ private static String decodeHex(int rawVal){
return String.format("0x%x", rawVal); return HexUtil.toHex(rawVal, 1);
} }
private static String decodeInt(int rawVal){ private static String decodeInt(int rawVal){
return String.valueOf(rawVal); return String.valueOf(rawVal);
@ -786,7 +787,7 @@ public class ValueDecoder {
return entry1; return entry1;
} }
private static String toHexResourceId(int resourceId){ private static String toHexResourceId(int resourceId){
return String.format("0x%08x", resourceId); return HexUtil.toHex8(resourceId);
} }
private static boolean isEqualString(String str1, String str2){ private static boolean isEqualString(String str1, String str2){
if(isEmpty(str1)){ if(isEmpty(str1)){
@ -810,7 +811,7 @@ public class ValueDecoder {
} }
@Override @Override
public String toString(){ public String toString(){
return valueType+": "+String.format("0x%08x", value); return valueType+": "+HexUtil.toHex8(value);
} }
} }

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -27,11 +27,12 @@ import com.reandroid.arsc.item.ByteArray;
import com.reandroid.arsc.item.IntegerItem; import com.reandroid.arsc.item.IntegerItem;
import com.reandroid.arsc.item.ShortItem; import com.reandroid.arsc.item.ShortItem;
import com.reandroid.arsc.util.HexBytesWriter; import com.reandroid.arsc.util.HexBytesWriter;
import com.reandroid.arsc.util.HexUtil;
import java.io.*; import java.io.*;
import java.util.List; import java.util.List;
public class HeaderBlock extends ExpandableBlockContainer implements BlockLoad { public class HeaderBlock extends ExpandableBlockContainer implements BlockLoad {
private final ShortItem mType; private final ShortItem mType;
private final ShortItem mHeaderSize; private final ShortItem mHeaderSize;
private final IntegerItem mChunkSize; private final IntegerItem mChunkSize;
@ -218,7 +219,7 @@ import java.util.List;
builder.append(type.toString()); builder.append(type.toString());
}else { }else {
builder.append("Unknown type="); builder.append("Unknown type=");
builder.append(String.format("0x%02x", (0xffff & t))); builder.append(HexUtil.toHex4(t));
} }
builder.append("{ValueHeader="); builder.append("{ValueHeader=");
builder.append(getHeaderSize()); builder.append(getHeaderSize());

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -16,7 +16,9 @@
package com.reandroid.arsc.item; package com.reandroid.arsc.item;
public class ByteItem extends BlockItem { import com.reandroid.arsc.util.HexUtil;
public class ByteItem extends BlockItem {
public ByteItem() { public ByteItem() {
super(1); super(1);
} }
@ -47,7 +49,7 @@ public class ByteItem extends BlockItem {
return 0xff & get(); return 0xff & get();
} }
public String toHex(){ public String toHex(){
return String.format("0x%02x", unsignedInt()); return HexUtil.toHex2(get());
} }
@Override @Override
public String toString(){ public String toString(){

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -15,13 +15,13 @@
*/ */
package com.reandroid.arsc.item; package com.reandroid.arsc.item;
import com.reandroid.arsc.io.BlockReader;
import com.reandroid.arsc.util.HexUtil;
import com.reandroid.arsc.io.BlockReader; import java.io.IOException;
import java.io.InputStream;
import java.io.IOException; public class IntegerItem extends BlockItem implements ReferenceItem{
import java.io.InputStream;
public class IntegerItem extends BlockItem implements ReferenceItem{
private int mCache; private int mCache;
public IntegerItem(){ public IntegerItem(){
super(4); super(4);
@ -50,7 +50,7 @@ package com.reandroid.arsc.item;
return get() & 0x00000000ffffffffL; return get() & 0x00000000ffffffffL;
} }
public String toHex(){ public String toHex(){
return String.format("0x%08x", get()); return HexUtil.toHex8(get());
} }
@Override @Override
protected void onBytesChanged() { protected void onBytesChanged() {

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -15,6 +15,8 @@
*/ */
package com.reandroid.arsc.item; package com.reandroid.arsc.item;
import com.reandroid.arsc.util.HexUtil;
public class LongItem extends BlockItem{ public class LongItem extends BlockItem{
private long mCache; private long mCache;
public LongItem() { public LongItem() {
@ -31,7 +33,7 @@ public class LongItem extends BlockItem{
return mCache; return mCache;
} }
public String toHex(){ public String toHex(){
return String.format("0x%016x", get()); return HexUtil.toHex(get(), 16);
} }
@Override @Override

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -17,6 +17,7 @@ package com.reandroid.arsc.item;
import com.reandroid.arsc.chunk.xml.ResXmlDocument; import com.reandroid.arsc.chunk.xml.ResXmlDocument;
import com.reandroid.arsc.pool.ResXmlStringPool; import com.reandroid.arsc.pool.ResXmlStringPool;
import com.reandroid.arsc.util.HexUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -90,7 +91,7 @@ public class ResXmlID extends IntegerItem {
builder.append(getIndex()); builder.append(getIndex());
} }
builder.append(':'); builder.append(':');
builder.append(String.format("0x%08x", get())); builder.append(HexUtil.toHex8(get()));
builder.append('}'); builder.append('}');
return builder.toString(); return builder.toString();
} }

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -15,12 +15,13 @@
*/ */
package com.reandroid.arsc.item; package com.reandroid.arsc.item;
import com.reandroid.arsc.io.BlockReader; import com.reandroid.arsc.io.BlockReader;
import com.reandroid.arsc.util.HexUtil;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
public class ShortItem extends BlockItem { public class ShortItem extends BlockItem {
private short mCache; private short mCache;
public ShortItem(){ public ShortItem(){
@ -46,7 +47,7 @@ package com.reandroid.arsc.item;
return 0xffff & get(); return 0xffff & get();
} }
public String toHex(){ public String toHex(){
return String.format("0x%04x", unsignedInt()); return HexUtil.toHex4(get());
} }
@Override @Override
protected void onBytesChanged() { protected void onBytesChanged() {

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -16,6 +16,7 @@
package com.reandroid.arsc.item; package com.reandroid.arsc.item;
import com.reandroid.arsc.chunk.SpecBlock; import com.reandroid.arsc.chunk.SpecBlock;
import com.reandroid.arsc.util.HexUtil;
public class SpecFlag extends IndirectItem<SpecFlagsArray> { public class SpecFlag extends IndirectItem<SpecFlagsArray> {
public SpecFlag(SpecFlagsArray specFlagsArray, int offset) { public SpecFlag(SpecFlagsArray specFlagsArray, int offset) {
@ -58,7 +59,7 @@ public class SpecFlag extends IndirectItem<SpecFlagsArray> {
} }
int val = getInteger(); int val = getInteger();
if(val != 0){ if(val != 0){
return String.format("0x%08x", val); return HexUtil.toHex8(val);
} }
return ""; return "";
} }

View File

@ -17,6 +17,7 @@ package com.reandroid.arsc.item;
import com.reandroid.arsc.pool.TypeStringPool; import com.reandroid.arsc.pool.TypeStringPool;
import com.reandroid.arsc.util.HexUtil;
public class TypeString extends StringItem { public class TypeString extends StringItem {
public TypeString(boolean utf8) { public TypeString(boolean utf8) {
@ -40,6 +41,6 @@ public class TypeString extends StringItem {
} }
@Override @Override
public String toString(){ public String toString(){
return String.format("0x%02x", getId())+':'+get(); return HexUtil.toHex2((byte) getId())+':'+get();
} }
} }

View File

@ -106,7 +106,7 @@ public class HexBytesWriter {
} }
} }
private void writeHex(Writer writer, byte b) throws IOException { private void writeHex(Writer writer, byte b) throws IOException {
String hex = String.format("%02x", (0xff & b)).toUpperCase(); String hex = HexUtil.toHex(null, (0xff & b), 2).toUpperCase();
writer.write(hex); writer.write(hex);
} }
private void writeString(Writer writer, int width, int position) throws IOException { private void writeString(Writer writer, int width, int position) throws IOException {

View File

@ -0,0 +1,84 @@
/*
* Copyright (C) 2022 github.com/REAndroid
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.reandroid.arsc.util;
public class HexUtil {
public static String toHex2(byte num){
return toHex((long)(num & 0x00000000000000ffL), 2);
}
public static String toHex4(short num){
return toHex((long)(num & 0x000000000000ffffL), 4);
}
public static String toHex8(int num){
return toHex(num, 8);
}
public static String toHex8(long num){
return toHex(num, 8);
}
public static String toHex(int num, int minLength){
return toHex((0x00000000ffffffffL & num), minLength);
}
public static String toHex(long num, int minLength){
String hex = Long.toHexString(num);
StringBuilder builder = new StringBuilder();
builder.append('0');
builder.append('x');
int rem = minLength - hex.length();
for(int i=0; i < rem; i++){
builder.append('0');
}
builder.append(hex);
return builder.toString();
}
public static String toHexNoPrefix8(int num){
return toHex(null, (0x00000000ffffffffL & num), 8);
}
public static String toHexNoPrefix(int num, int minLength){
return toHex(null, (0x00000000ffffffffL & num), minLength);
}
public static String toHex8(String prefix, int num){
return toHex(prefix, (0x00000000ffffffffL & num), 8);
}
public static String toHex(String prefix, int num, int minLength){
return toHex(prefix, (0x00000000ffffffffL & num), minLength);
}
public static String toHex(String prefix, long num, int minLength){
String hex = Long.toHexString(num);
StringBuilder builder = new StringBuilder();
if(prefix != null){
builder.append(prefix);
}
int rem = minLength - hex.length();
for(int i=0; i < rem; i++){
builder.append('0');
}
builder.append(hex);
return builder.toString();
}
public static int parseHex(String hexString){
hexString = trim0x(hexString);
return (int) Long.parseLong(hexString, 16);
}
private static String trim0x(String hexString){
if(hexString == null || hexString.length() < 3){
return hexString;
}
if(hexString.charAt(0) == '0' && hexString.charAt(1) == 'x'){
hexString = hexString.substring(2);
}
return hexString;
}
}

View File

@ -29,6 +29,7 @@ import com.reandroid.arsc.io.BlockReader;
import com.reandroid.arsc.item.*; import com.reandroid.arsc.item.*;
import com.reandroid.arsc.pool.SpecStringPool; import com.reandroid.arsc.pool.SpecStringPool;
import com.reandroid.arsc.pool.TableStringPool; import com.reandroid.arsc.pool.TableStringPool;
import com.reandroid.arsc.util.HexUtil;
import com.reandroid.json.JSONConvert; import com.reandroid.json.JSONConvert;
import com.reandroid.json.JSONObject; import com.reandroid.json.JSONObject;
@ -429,7 +430,7 @@ public class Entry extends Block implements JSONConvert<JSONObject> {
@Override @Override
public String toString(){ public String toString(){
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append(String.format("0x%08x", getResourceId())); builder.append(HexUtil.toHex8(getResourceId()));
builder.append(' '); builder.append(' ');
ResConfig resConfig = getResConfig(); ResConfig resConfig = getResConfig();
if(resConfig!=null){ if(resConfig!=null){

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -15,6 +15,7 @@
*/ */
package com.reandroid.arsc.value; package com.reandroid.arsc.value;
import com.reandroid.arsc.util.HexUtil;
import com.reandroid.json.JSONObject; import com.reandroid.json.JSONObject;
public class EntryHeaderMap extends ValueHeader { public class EntryHeaderMap extends ValueHeader {
@ -92,7 +93,7 @@ public class EntryHeaderMap extends ValueHeader {
int parentId = getParentId(); int parentId = getParentId();
if(parentId!=0){ if(parentId!=0){
builder.append(", parentId="); builder.append(", parentId=");
builder.append(String.format("0x%08x", getParentId())); builder.append(HexUtil.toHex8(getParentId()));
} }
builder.append(", count=").append(getValuesCount()); builder.append(", count=").append(getValuesCount());
return builder.toString(); return builder.toString();

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -20,6 +20,7 @@ import com.reandroid.arsc.base.BlockCounter;
import com.reandroid.arsc.io.BlockReader; import com.reandroid.arsc.io.BlockReader;
import com.reandroid.arsc.item.FixedLengthString; import com.reandroid.arsc.item.FixedLengthString;
import com.reandroid.arsc.item.IntegerItem; import com.reandroid.arsc.item.IntegerItem;
import com.reandroid.arsc.util.HexUtil;
import com.reandroid.json.JSONConvert; import com.reandroid.json.JSONConvert;
import com.reandroid.json.JSONObject; import com.reandroid.json.JSONObject;
@ -117,7 +118,7 @@ public class LibraryInfo extends Block implements JSONConvert<JSONObject> {
public String toString(){ public String toString(){
StringBuilder builder=new StringBuilder(); StringBuilder builder=new StringBuilder();
builder.append("LIBRARY{"); builder.append("LIBRARY{");
builder.append(String.format("0x%02x", getPackageId())); builder.append(HexUtil.toHex2((byte) getPackageId()));
builder.append(':'); builder.append(':');
String name=getPackageName(); String name=getPackageName();
if(name==null){ if(name==null){

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -17,6 +17,7 @@ package com.reandroid.arsc.value;
import com.reandroid.arsc.base.Block; import com.reandroid.arsc.base.Block;
import com.reandroid.arsc.chunk.PackageBlock; import com.reandroid.arsc.chunk.PackageBlock;
import com.reandroid.arsc.util.HexUtil;
import com.reandroid.json.JSONObject; import com.reandroid.json.JSONObject;
public class ResValueMap extends ValueItem implements AttributeValue{ public class ResValueMap extends ValueItem implements AttributeValue{
@ -110,7 +111,7 @@ public class ResValueMap extends ValueItem implements AttributeValue{
} }
@Override @Override
public String toString(){ public String toString(){
return "name="+String.format("0x%08x", getName()) return "name=" + HexUtil.toHex8(getName())
+", "+super.toString(); +", "+super.toString();
} }

View File

@ -1,6 +1,22 @@
/*
* Copyright (C) 2022 github.com/REAndroid
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.reandroid.arsc.value; package com.reandroid.arsc.value;
import com.reandroid.arsc.item.ByteArray; import com.reandroid.arsc.item.ByteArray;
import com.reandroid.arsc.util.HexUtil;
import com.reandroid.json.JSONConvert; import com.reandroid.json.JSONConvert;
import com.reandroid.json.JSONObject; import com.reandroid.json.JSONObject;
@ -32,8 +48,8 @@ public class StagedAliasEntry extends ByteArray implements JSONConvert<JSONObjec
} }
@Override @Override
public String toString(){ public String toString(){
return "stagedResId="+String.format("0x%08x",getStagedResId()) return "stagedResId=" + HexUtil.toHex8(getStagedResId())
+", finalizedResId="+String.format("0x%08x",getFinalizedResId()); +", finalizedResId=" + HexUtil.toHex8(getFinalizedResId());
} }
@Override @Override
public JSONObject toJson() { public JSONObject toJson() {

View File

@ -24,13 +24,14 @@ import com.reandroid.arsc.item.ReferenceItem;
import com.reandroid.arsc.item.StringItem; import com.reandroid.arsc.item.StringItem;
import com.reandroid.arsc.pool.StringPool; import com.reandroid.arsc.pool.StringPool;
import com.reandroid.arsc.pool.TableStringPool; import com.reandroid.arsc.pool.TableStringPool;
import com.reandroid.arsc.util.HexUtil;
import com.reandroid.json.JSONConvert; import com.reandroid.json.JSONConvert;
import com.reandroid.json.JSONObject; import com.reandroid.json.JSONObject;
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;
public abstract class ValueItem extends BlockItem implements Value, public abstract class ValueItem extends BlockItem implements Value,
JSONConvert<JSONObject>{ JSONConvert<JSONObject>{
private ReferenceItem mStringReference; private ReferenceItem mStringReference;
private final int sizeOffset; private final int sizeOffset;
@ -303,7 +304,7 @@ import java.util.Objects;
if(valueType!=null){ if(valueType!=null){
builder.append(valueType); builder.append(valueType);
}else { }else {
builder.append(String.format("0x%02x", (0xff & getType()))); builder.append(HexUtil.toHex2(getType()));
} }
builder.append(", data="); builder.append(", data=");
int data = getData(); int data = getData();
@ -312,10 +313,10 @@ import java.util.Objects;
if(tableString!=null){ if(tableString!=null){
builder.append(tableString.getHtml()); builder.append(tableString.getHtml());
}else { }else {
builder.append(String.format("0x%08x", data)); builder.append(HexUtil.toHex8(data));
} }
}else { }else {
builder.append(String.format("0x%08x", data)); builder.append(HexUtil.toHex8(data));
} }
return builder.toString(); return builder.toString();
} }
@ -328,4 +329,4 @@ import java.util.Objects;
public static final String NAME_data = "data"; public static final String NAME_data = "data";
public static final String NAME_value_type = "value_type"; public static final String NAME_value_type = "value_type";
} }

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -13,16 +13,17 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.reandroid.arsc.value.array; package com.reandroid.arsc.value.array;
import com.reandroid.arsc.decoder.ValueDecoder; import com.reandroid.arsc.decoder.ValueDecoder;
import com.reandroid.arsc.item.StringItem; import com.reandroid.arsc.item.StringItem;
import com.reandroid.arsc.item.TableString; import com.reandroid.arsc.item.TableString;
import com.reandroid.arsc.value.ValueType; import com.reandroid.arsc.util.HexUtil;
import com.reandroid.arsc.value.bag.BagItem; import com.reandroid.arsc.value.ValueType;
import com.reandroid.arsc.value.ResValueMap; import com.reandroid.arsc.value.bag.BagItem;
import com.reandroid.arsc.value.ResValueMap;
public class ArrayBagItem extends BagItem { public class ArrayBagItem extends BagItem {
private ArrayBagItem(ResValueMap valueMap) { private ArrayBagItem(ResValueMap valueMap) {
super(valueMap); super(valueMap);
} }
@ -42,7 +43,7 @@
if (hasStringValue()) { if (hasStringValue()) {
builder.append(getStringValue()); builder.append(getStringValue());
} else { } else {
builder.append(String.format("0x%08x", getValue())); builder.append(HexUtil.toHex8(getValue()));
} }
builder.append("</item>"); builder.append("</item>");
return builder.toString(); return builder.toString();
@ -92,4 +93,4 @@
public static ArrayBagItem reference(int resourceId) { public static ArrayBagItem reference(int resourceId) {
return create(ValueType.REFERENCE, resourceId); return create(ValueType.REFERENCE, resourceId);
} }
} }

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -17,6 +17,7 @@ package com.reandroid.arsc.value.attribute;
import com.reandroid.arsc.chunk.PackageBlock; import com.reandroid.arsc.chunk.PackageBlock;
import com.reandroid.arsc.group.EntryGroup; import com.reandroid.arsc.group.EntryGroup;
import com.reandroid.arsc.util.HexUtil;
import com.reandroid.arsc.value.Entry; import com.reandroid.arsc.value.Entry;
import com.reandroid.arsc.value.ResValueMap; import com.reandroid.arsc.value.ResValueMap;
import com.reandroid.common.EntryStore; import com.reandroid.common.EntryStore;
@ -36,7 +37,7 @@ public class AttributeBagItem {
public String getNameOrHex(EntryStore entryStore){ public String getNameOrHex(EntryStore entryStore){
String name=getName(entryStore); String name=getName(entryStore);
if(name==null){ if(name==null){
name=String.format("@0x%08x", getBagItem().getName()); name=HexUtil.toHex8("@0x", getBagItem().getName());
} }
return name; return name;
} }
@ -162,7 +163,7 @@ public class AttributeBagItem {
} }
ResValueMap item=getBagItem(); ResValueMap item=getBagItem();
builder.append(getNameOrHex()); builder.append(getNameOrHex());
builder.append("=").append(String.format("0x%x", item.getData())); builder.append("=").append(HexUtil.toHex8(item.getData()));
return builder.toString(); return builder.toString();
} }
@ -214,6 +215,4 @@ public class AttributeBagItem {
} }
return null; return null;
} }
} }

View File

@ -18,6 +18,7 @@
import com.reandroid.arsc.chunk.TableBlock; import com.reandroid.arsc.chunk.TableBlock;
import com.reandroid.arsc.item.StringItem; import com.reandroid.arsc.item.StringItem;
import com.reandroid.arsc.item.TableString; import com.reandroid.arsc.item.TableString;
import com.reandroid.arsc.util.HexUtil;
import com.reandroid.arsc.value.*; import com.reandroid.arsc.value.*;
import com.reandroid.arsc.value.bag.BagItem; import com.reandroid.arsc.value.bag.BagItem;
@ -83,7 +84,7 @@
} }
private String formattedRefValue() { private String formattedRefValue() {
return String.format("@0x%08x", getValue()); return HexUtil.toHex8("@0x", getValue());
} }
@Override @Override

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2022 github.com/REAndroid * Copyright (C) 2022 github.com/REAndroid
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -13,20 +13,21 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.reandroid.arsc.value.style; package com.reandroid.arsc.value.style;
import com.reandroid.arsc.decoder.ValueDecoder; import com.reandroid.arsc.decoder.ValueDecoder;
import com.reandroid.arsc.item.StringItem; import com.reandroid.arsc.item.StringItem;
import com.reandroid.arsc.item.TableString; import com.reandroid.arsc.item.TableString;
import com.reandroid.arsc.value.attribute.AttributeBag; import com.reandroid.arsc.util.HexUtil;
import com.reandroid.arsc.value.attribute.AttributeBagItem; import com.reandroid.arsc.value.attribute.AttributeBag;
import com.reandroid.arsc.value.bag.BagItem; import com.reandroid.arsc.value.attribute.AttributeBagItem;
import com.reandroid.arsc.value.Entry; import com.reandroid.arsc.value.bag.BagItem;
import com.reandroid.arsc.value.ResValueMap; import com.reandroid.arsc.value.Entry;
import com.reandroid.arsc.value.ValueType; import com.reandroid.arsc.value.ResValueMap;
import com.reandroid.common.EntryStore; import com.reandroid.arsc.value.ValueType;
import com.reandroid.common.EntryStore;
public class StyleBagItem extends BagItem { public class StyleBagItem extends BagItem {
private StyleBagItem(ResValueMap bagItem) { private StyleBagItem(ResValueMap bagItem) {
super(bagItem); super(bagItem);
} }
@ -109,7 +110,7 @@
builder.append("<item name=\""); builder.append("<item name=\"");
String name = getName(); String name = getName();
if (name == null) { if (name == null) {
name = String.format("@0x%08x", getNameId()); name = HexUtil.toHex8("@0x", getNameId());
} }
builder.append(name); builder.append(name);
builder.append("\">"); builder.append("\">");
@ -121,7 +122,7 @@
val = getValueAsReference(); val = getValueAsReference();
} }
if (val == null) { if (val == null) {
val = String.format("0x%08x", getValue()); val = HexUtil.toHex8(getValue());
} }
builder.append(val); builder.append(val);
builder.append("</item>"); builder.append("</item>");
@ -186,4 +187,4 @@
public static StyleBagItem enumOrFlag(AttributeBag attr, String valueString) { public static StyleBagItem enumOrFlag(AttributeBag attr, String valueString) {
return encoded(attr.encodeEnumOrFlagValue(valueString)); return encoded(attr.encodeEnumOrFlagValue(valueString));
} }
} }