mirror of
https://github.com/revanced/Apktool.git
synced 2025-05-09 18:24:26 +02:00
StringBlock, AXmlResourceParser: reformat.
This commit is contained in:
parent
843768aad0
commit
4ced4222f9
@ -14,7 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package brut.androlib.res.decoder;
|
package brut.androlib.res.decoder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -66,7 +65,6 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////// iteration
|
/////////////////////////////////// iteration
|
||||||
|
|
||||||
public int next() throws XmlPullParserException, IOException {
|
public int next() throws XmlPullParserException, IOException {
|
||||||
if (m_reader == null) {
|
if (m_reader == null) {
|
||||||
throw new XmlPullParserException("Parser is not opened.", this, null);
|
throw new XmlPullParserException("Parser is not opened.", this, null);
|
||||||
@ -74,8 +72,7 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
try {
|
try {
|
||||||
doNext();
|
doNext();
|
||||||
return m_event;
|
return m_event;
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e) {
|
|
||||||
close();
|
close();
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
@ -116,10 +113,9 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void require(int type, String namespace, String name) throws XmlPullParserException, IOException {
|
public void require(int type, String namespace, String name) throws XmlPullParserException, IOException {
|
||||||
if (type!=getEventType() ||
|
if (type != getEventType()
|
||||||
(namespace!=null && !namespace.equals(getNamespace())) ||
|
|| (namespace != null && !namespace.equals(getNamespace()))
|
||||||
(name!=null && !name.equals(getName())))
|
|| (name != null && !name.equals(getName()))) {
|
||||||
{
|
|
||||||
throw new XmlPullParserException(TYPES[type] + " is expected.", this, null);
|
throw new XmlPullParserException(TYPES[type] + " is expected.", this, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,7 +186,6 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////// attributes
|
/////////////////////////////////// attributes
|
||||||
|
|
||||||
public String getClassAttribute() {
|
public String getClassAttribute() {
|
||||||
if (m_classAttribute == -1) {
|
if (m_classAttribute == -1) {
|
||||||
return null;
|
return null;
|
||||||
@ -267,9 +262,8 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
public int getAttributeNameResource(int index) {
|
public int getAttributeNameResource(int index) {
|
||||||
int offset = getAttributeOffset(index);
|
int offset = getAttributeOffset(index);
|
||||||
int name = m_attributes[offset + ATTRIBUTE_IX_NAME];
|
int name = m_attributes[offset + ATTRIBUTE_IX_NAME];
|
||||||
if (m_resourceIDs==null ||
|
if (m_resourceIDs == null
|
||||||
name<0 || name>=m_resourceIDs.length)
|
|| name < 0 || name >= m_resourceIDs.length) {
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return m_resourceIDs[name];
|
return m_resourceIDs[name];
|
||||||
@ -313,9 +307,8 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
public int getAttributeIntValue(int index, int defaultValue) {
|
public int getAttributeIntValue(int index, int defaultValue) {
|
||||||
int offset = getAttributeOffset(index);
|
int offset = getAttributeOffset(index);
|
||||||
int valueType = m_attributes[offset + ATTRIBUTE_IX_VALUE_TYPE];
|
int valueType = m_attributes[offset + ATTRIBUTE_IX_VALUE_TYPE];
|
||||||
if (valueType>=TypedValue.TYPE_FIRST_INT &&
|
if (valueType >= TypedValue.TYPE_FIRST_INT
|
||||||
valueType<=TypedValue.TYPE_LAST_INT)
|
&& valueType <= TypedValue.TYPE_LAST_INT) {
|
||||||
{
|
|
||||||
return m_attributes[offset + ATTRIBUTE_IX_VALUE_DATA];
|
return m_attributes[offset + ATTRIBUTE_IX_VALUE_DATA];
|
||||||
}
|
}
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
@ -401,10 +394,10 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////// dummies
|
/////////////////////////////////// dummies
|
||||||
|
|
||||||
public void setInput(InputStream stream, String inputEncoding) throws XmlPullParserException {
|
public void setInput(InputStream stream, String inputEncoding) throws XmlPullParserException {
|
||||||
throw new XmlPullParserException(E_NOT_SUPPORTED);
|
throw new XmlPullParserException(E_NOT_SUPPORTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInput(Reader reader) throws XmlPullParserException {
|
public void setInput(Reader reader) throws XmlPullParserException {
|
||||||
throw new XmlPullParserException(E_NOT_SUPPORTED);
|
throw new XmlPullParserException(E_NOT_SUPPORTED);
|
||||||
}
|
}
|
||||||
@ -436,6 +429,7 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
public Object getProperty(String name) {
|
public Object getProperty(String name) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProperty(String name, Object value) throws XmlPullParserException {
|
public void setProperty(String name, Object value) throws XmlPullParserException {
|
||||||
throw new XmlPullParserException(E_NOT_SUPPORTED);
|
throw new XmlPullParserException(E_NOT_SUPPORTED);
|
||||||
}
|
}
|
||||||
@ -443,12 +437,12 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
public boolean getFeature(String feature) {
|
public boolean getFeature(String feature) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFeature(String name, boolean value) throws XmlPullParserException {
|
public void setFeature(String name, boolean value) throws XmlPullParserException {
|
||||||
throw new XmlPullParserException(E_NOT_SUPPORTED);
|
throw new XmlPullParserException(E_NOT_SUPPORTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////// implementation
|
///////////////////////////////////////////// implementation
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Namespace stack, holds prefix+uri pairs, as well as
|
* Namespace stack, holds prefix+uri pairs, as well as
|
||||||
* depth information.
|
* depth information.
|
||||||
@ -469,6 +463,7 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final class NamespaceStack {
|
private static final class NamespaceStack {
|
||||||
|
|
||||||
public NamespaceStack() {
|
public NamespaceStack() {
|
||||||
m_data = new int[32];
|
m_data = new int[32];
|
||||||
}
|
}
|
||||||
@ -601,6 +596,7 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
m_dataLength += 2;
|
m_dataLength += 2;
|
||||||
m_depth += 1;
|
m_depth += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void decreaseDepth() {
|
public final void decreaseDepth() {
|
||||||
if (m_dataLength == 0) {
|
if (m_dataLength == 0) {
|
||||||
return;
|
return;
|
||||||
@ -670,7 +666,6 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int[] m_data;
|
private int[] m_data;
|
||||||
private int m_dataLength;
|
private int m_dataLength;
|
||||||
private int m_count;
|
private int m_count;
|
||||||
@ -678,7 +673,6 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////// package-visible
|
/////////////////////////////////// package-visible
|
||||||
|
|
||||||
// final void fetchAttributes(int[] styleableIDs,TypedArray result) {
|
// final void fetchAttributes(int[] styleableIDs,TypedArray result) {
|
||||||
// result.resetIndices();
|
// result.resetIndices();
|
||||||
// if (m_attributes==null || m_resourceIDs==null) {
|
// if (m_attributes==null || m_resourceIDs==null) {
|
||||||
@ -712,13 +706,11 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
// result.setStrings(m_strings);
|
// result.setStrings(m_strings);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
final StringBlock getStrings() {
|
final StringBlock getStrings() {
|
||||||
return m_strings;
|
return m_strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////
|
///////////////////////////////////
|
||||||
|
|
||||||
private final int getAttributeOffset(int index) {
|
private final int getAttributeOffset(int index) {
|
||||||
if (m_event != START_TAG) {
|
if (m_event != START_TAG) {
|
||||||
throw new IndexOutOfBoundsException("Current event is not START_TAG.");
|
throw new IndexOutOfBoundsException("Current event is not START_TAG.");
|
||||||
@ -738,13 +730,12 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
if (name == -1) {
|
if (name == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int uri=(namespace!=null)?
|
int uri = (namespace != null)
|
||||||
m_strings.find(namespace):
|
? m_strings.find(namespace)
|
||||||
-1;
|
: -1;
|
||||||
for (int o = 0; o != m_attributes.length; ++o) {
|
for (int o = 0; o != m_attributes.length; ++o) {
|
||||||
if (name==m_attributes[o+ATTRIBUTE_IX_NAME] &&
|
if (name == m_attributes[o + ATTRIBUTE_IX_NAME]
|
||||||
(uri==-1 || uri==m_attributes[o+ATTRIBUTE_IX_NAMESPACE_URI]))
|
&& (uri == -1 || uri == m_attributes[o + ATTRIBUTE_IX_NAMESPACE_URI])) {
|
||||||
{
|
|
||||||
return o / ATTRIBUTE_LENGHT;
|
return o / ATTRIBUTE_LENGHT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -786,10 +777,9 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fake END_DOCUMENT event.
|
// Fake END_DOCUMENT event.
|
||||||
if (event==END_TAG &&
|
if (event == END_TAG
|
||||||
m_namespaces.getDepth()==1 &&
|
&& m_namespaces.getDepth() == 1
|
||||||
m_namespaces.getCurrentCount()==0)
|
&& m_namespaces.getCurrentCount() == 0) {
|
||||||
{
|
|
||||||
m_event = END_DOCUMENT;
|
m_event = END_DOCUMENT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -826,9 +816,8 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
int lineNumber = m_reader.readInt();
|
int lineNumber = m_reader.readInt();
|
||||||
/*0xFFFFFFFF*/ m_reader.skipInt();
|
/*0xFFFFFFFF*/ m_reader.skipInt();
|
||||||
|
|
||||||
if (chunkType==CHUNK_XML_START_NAMESPACE ||
|
if (chunkType == CHUNK_XML_START_NAMESPACE
|
||||||
chunkType==CHUNK_XML_END_NAMESPACE)
|
|| chunkType == CHUNK_XML_END_NAMESPACE) {
|
||||||
{
|
|
||||||
if (chunkType == CHUNK_XML_START_NAMESPACE) {
|
if (chunkType == CHUNK_XML_START_NAMESPACE) {
|
||||||
int prefix = m_reader.readInt();
|
int prefix = m_reader.readInt();
|
||||||
int uri = m_reader.readInt();
|
int uri = m_reader.readInt();
|
||||||
@ -880,23 +869,17 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////// data
|
/////////////////////////////////// data
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* All values are essentially indices, e.g. m_name is
|
* All values are essentially indices, e.g. m_name is
|
||||||
* an index of name in m_strings.
|
* an index of name in m_strings.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private IntReader m_reader;
|
private IntReader m_reader;
|
||||||
private boolean m_operational = false;
|
private boolean m_operational = false;
|
||||||
|
|
||||||
private StringBlock m_strings;
|
private StringBlock m_strings;
|
||||||
private int[] m_resourceIDs;
|
private int[] m_resourceIDs;
|
||||||
private NamespaceStack m_namespaces = new NamespaceStack();
|
private NamespaceStack m_namespaces = new NamespaceStack();
|
||||||
|
|
||||||
private boolean m_decreaseDepth;
|
private boolean m_decreaseDepth;
|
||||||
|
|
||||||
private int m_event;
|
private int m_event;
|
||||||
private int m_lineNumber;
|
private int m_lineNumber;
|
||||||
private int m_name;
|
private int m_name;
|
||||||
@ -905,20 +888,14 @@ public class AXmlResourceParser implements XmlResourceParser {
|
|||||||
private int m_idAttribute;
|
private int m_idAttribute;
|
||||||
private int m_classAttribute;
|
private int m_classAttribute;
|
||||||
private int m_styleAttribute;
|
private int m_styleAttribute;
|
||||||
|
private static final String E_NOT_SUPPORTED = "Method is not supported.";
|
||||||
private static final String
|
private static final int ATTRIBUTE_IX_NAMESPACE_URI = 0,
|
||||||
E_NOT_SUPPORTED ="Method is not supported.";
|
|
||||||
|
|
||||||
private static final int
|
|
||||||
ATTRIBUTE_IX_NAMESPACE_URI =0,
|
|
||||||
ATTRIBUTE_IX_NAME = 1,
|
ATTRIBUTE_IX_NAME = 1,
|
||||||
ATTRIBUTE_IX_VALUE_STRING = 2,
|
ATTRIBUTE_IX_VALUE_STRING = 2,
|
||||||
ATTRIBUTE_IX_VALUE_TYPE = 3,
|
ATTRIBUTE_IX_VALUE_TYPE = 3,
|
||||||
ATTRIBUTE_IX_VALUE_DATA = 4,
|
ATTRIBUTE_IX_VALUE_DATA = 4,
|
||||||
ATTRIBUTE_LENGHT = 5;
|
ATTRIBUTE_LENGHT = 5;
|
||||||
|
private static final int CHUNK_AXML_FILE = 0x00080003,
|
||||||
private static final int
|
|
||||||
CHUNK_AXML_FILE =0x00080003,
|
|
||||||
CHUNK_RESOURCEIDS = 0x00080180,
|
CHUNK_RESOURCEIDS = 0x00080180,
|
||||||
CHUNK_XML_FIRST = 0x00100100,
|
CHUNK_XML_FIRST = 0x00100100,
|
||||||
CHUNK_XML_START_NAMESPACE = 0x00100100,
|
CHUNK_XML_START_NAMESPACE = 0x00100100,
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package brut.androlib.res.decoder;
|
package brut.androlib.res.decoder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -71,19 +70,18 @@ public class StringBlock {
|
|||||||
* Returns number of strings in block.
|
* Returns number of strings in block.
|
||||||
*/
|
*/
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return m_stringOffsets!=null?
|
return m_stringOffsets != null
|
||||||
m_stringOffsets.length:
|
? m_stringOffsets.length
|
||||||
0;
|
: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns raw string (without any styling information) at specified index.
|
* Returns raw string (without any styling information) at specified index.
|
||||||
*/
|
*/
|
||||||
public String getString(int index) {
|
public String getString(int index) {
|
||||||
if (index<0 ||
|
if (index < 0
|
||||||
m_stringOffsets==null ||
|
|| m_stringOffsets == null
|
||||||
index>=m_stringOffsets.length)
|
|| index >= m_stringOffsets.length) {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int offset = m_stringOffsets[index];
|
int offset = m_stringOffsets[index];
|
||||||
@ -189,7 +187,6 @@ public class StringBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////// implementation
|
///////////////////////////////////////////// implementation
|
||||||
|
|
||||||
private StringBlock() {
|
private StringBlock() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,9 +198,8 @@ public class StringBlock {
|
|||||||
* * third int is tag end index in string
|
* * third int is tag end index in string
|
||||||
*/
|
*/
|
||||||
private int[] getStyle(int index) {
|
private int[] getStyle(int index) {
|
||||||
if (m_styleOffsets==null || m_styles==null ||
|
if (m_styleOffsets == null || m_styles == null
|
||||||
index>=m_styleOffsets.length)
|
|| index >= m_styleOffsets.length) {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int offset = m_styleOffsets[index] / 4;
|
int offset = m_styleOffsets[index] / 4;
|
||||||
@ -238,11 +234,9 @@ public class StringBlock {
|
|||||||
return (value >>> 16);
|
return (value >>> 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int[] m_stringOffsets;
|
private int[] m_stringOffsets;
|
||||||
private int[] m_strings;
|
private int[] m_strings;
|
||||||
private int[] m_styleOffsets;
|
private int[] m_styleOffsets;
|
||||||
private int[] m_styles;
|
private int[] m_styles;
|
||||||
|
|
||||||
private static final int CHUNK_TYPE = 0x001C0001;
|
private static final int CHUNK_TYPE = 0x001C0001;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user