mirror of
https://github.com/revanced/smali.git
synced 2025-05-05 00:54:25 +02:00
Change ByteArrayInput.readNullTerminatedBytes() to ByteArrayInput.readNullTerminatedUtf8String()
git-svn-id: https://smali.googlecode.com/svn/trunk@685 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
parent
89325d96cc
commit
1f29ee7351
@ -78,12 +78,12 @@ public class StringDataItem extends Item<StringDataItem> {
|
|||||||
public static StringDataItem lookupStringDataItem(DexFile dexFile, String value) {
|
public static StringDataItem lookupStringDataItem(DexFile dexFile, String value) {
|
||||||
StringDataItem StringDataItem = new StringDataItem(dexFile, value);
|
StringDataItem StringDataItem = new StringDataItem(dexFile, value);
|
||||||
return dexFile.StringDataSection.getInternedItem(StringDataItem);
|
return dexFile.StringDataSection.getInternedItem(StringDataItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
protected void readItem(Input in, ReadContext readContext) {
|
protected void readItem(Input in, ReadContext readContext) {
|
||||||
in.readUnsignedLeb128(); //string length
|
in.readUnsignedLeb128(); //string length
|
||||||
stringValue = Utf8Utils.utf8BytesToString(in.readNullTerminatedBytes());
|
stringValue = in.realNullTerminatedUtf8String();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
@ -296,7 +296,7 @@ public class ByteArrayInput
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public byte[] readNullTerminatedBytes() {
|
public String realNullTerminatedUtf8String() {
|
||||||
int startPosition = cursor;
|
int startPosition = cursor;
|
||||||
while (data[cursor] != 0) {
|
while (data[cursor] != 0) {
|
||||||
cursor++;
|
cursor++;
|
||||||
@ -305,12 +305,11 @@ public class ByteArrayInput
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
int byteCount = cursor - startPosition;
|
int byteCount = cursor - startPosition;
|
||||||
|
|
||||||
//skip the terminating null
|
//skip the terminating null
|
||||||
cursor++;
|
cursor++;
|
||||||
|
|
||||||
byte[] result = new byte[byteCount];
|
return Utf8Utils.utf8BytesToString(data, startPosition, byteCount);
|
||||||
System.arraycopy(data, startPosition, result, 0, byteCount);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
@ -132,11 +132,13 @@ public interface Input {
|
|||||||
public byte[] readBytes(int length);
|
public byte[] readBytes(int length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reads a <code>byte[]</code> from this instance, from the current cursor up to but not including
|
* reads and decodes a null terminated utf8 string from the current cursor up to but not including
|
||||||
* the next null (0) byte. The terminating null byte is read and discarded, so that after the read,
|
* the next null (0) byte. The terminating null byte is read and discarded, so that after the read,
|
||||||
* the cursor is positioned at the byte immediately after the terminating null
|
* the cursor is positioned at the byte immediately after the terminating null
|
||||||
|
*
|
||||||
|
* @return a string representing the decoded value
|
||||||
*/
|
*/
|
||||||
public byte[] readNullTerminatedBytes();
|
public String realNullTerminatedUtf8String();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Skips the given number of bytes.
|
* Skips the given number of bytes.
|
||||||
|
@ -68,17 +68,18 @@ public final class Utf8Utils {
|
|||||||
* This method uses a global buffer to avoid having to allocate one every time, so it is *not* thread-safe
|
* This method uses a global buffer to avoid having to allocate one every time, so it is *not* thread-safe
|
||||||
*
|
*
|
||||||
* @param bytes non-null; the bytes to convert
|
* @param bytes non-null; the bytes to convert
|
||||||
|
* @param start the start index of the utf8 string to convert
|
||||||
|
* @param length the length of the utf8 string to convert, not including any null-terminator that might be present
|
||||||
* @return non-null; the converted string
|
* @return non-null; the converted string
|
||||||
*/
|
*/
|
||||||
public static String utf8BytesToString(byte[] bytes) {
|
public static String utf8BytesToString(byte[] bytes, int start, int length) {
|
||||||
int length = bytes.length;
|
|
||||||
if (tempBuffer == null || tempBuffer.length < length) {
|
if (tempBuffer == null || tempBuffer.length < length) {
|
||||||
tempBuffer = new char[length];
|
tempBuffer = new char[length];
|
||||||
}
|
}
|
||||||
char[] chars = tempBuffer;
|
char[] chars = tempBuffer;
|
||||||
int outAt = 0;
|
int outAt = 0;
|
||||||
|
|
||||||
for (int at = 0; length > 0; /*at*/) {
|
for (int at = start; length > 0; /*at*/) {
|
||||||
int v0 = bytes[at] & 0xFF;
|
int v0 = bytes[at] & 0xFF;
|
||||||
char out;
|
char out;
|
||||||
switch (v0 >> 4) {
|
switch (v0 >> 4) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user