mirror of
https://github.com/revanced/Apktool.git
synced 2025-02-01 06:37:34 +01:00
StringBlock.getString(): decoding strings using CharsetDecoder.
This commit is contained in:
parent
a7fd5fd70a
commit
4ea40577bf
@ -18,6 +18,10 @@ package brut.androlib.res.decoder;
|
|||||||
|
|
||||||
import brut.util.ExtDataInput;
|
import brut.util.ExtDataInput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.*;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
|
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||||
@ -88,12 +92,7 @@ public class StringBlock {
|
|||||||
}
|
}
|
||||||
int offset = m_stringOffsets[index];
|
int offset = m_stringOffsets[index];
|
||||||
int length = getShort(m_strings, offset);
|
int length = getShort(m_strings, offset);
|
||||||
StringBuilder result = new StringBuilder(length);
|
return decodeString(offset + 2, length * 2);
|
||||||
for (; length != 0; length -= 1) {
|
|
||||||
offset += 2;
|
|
||||||
result.append((char) getShort(m_strings, offset));
|
|
||||||
}
|
|
||||||
return result.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -228,6 +227,16 @@ public class StringBlock {
|
|||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String decodeString(int offset, int length) {
|
||||||
|
try {
|
||||||
|
return UTF16LE_DECODER.decode(
|
||||||
|
ByteBuffer.wrap(m_strings, offset, length)).toString();
|
||||||
|
} catch (CharacterCodingException ex) {
|
||||||
|
LOGGER.log(Level.WARNING, null, ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final int getShort(byte[] array, int offset) {
|
private static final int getShort(byte[] array, int offset) {
|
||||||
return (array[offset + 1] & 0xff) << 8 | array[offset] & 0xff;
|
return (array[offset + 1] & 0xff) << 8 | array[offset] & 0xff;
|
||||||
}
|
}
|
||||||
@ -244,5 +253,9 @@ public class StringBlock {
|
|||||||
private byte[] m_strings;
|
private byte[] m_strings;
|
||||||
private int[] m_styleOffsets;
|
private int[] m_styleOffsets;
|
||||||
private int[] m_styles;
|
private int[] m_styles;
|
||||||
|
private static final CharsetDecoder UTF16LE_DECODER =
|
||||||
|
Charset.forName("UTF-16LE").newDecoder();
|
||||||
|
private static final Logger LOGGER =
|
||||||
|
Logger.getLogger(StringBlock.class.getName());
|
||||||
private static final int CHUNK_TYPE = 0x001C0001;
|
private static final int CHUNK_TYPE = 0x001C0001;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user