mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-26 12:07:40 +00:00
Support new xml binary format
This commit is contained in:
parent
fdd700f3e5
commit
5f22d3e055
@ -43,13 +43,12 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
|
|||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean findAndPatch(byte xml[], String from, String to) {
|
private int findOffset(byte buf[], byte pattern[]) {
|
||||||
int offset = -1;
|
int offset = -1;
|
||||||
byte target[] = (from + '\0').getBytes();
|
for (int i = 0; i < buf.length - pattern.length; ++i) {
|
||||||
for (int i = 0; i < xml.length - target.length; ++i) {
|
|
||||||
boolean match = true;
|
boolean match = true;
|
||||||
for (int j = 0; j < target.length; ++j) {
|
for (int j = 0; j < pattern.length; ++j) {
|
||||||
if (xml[i + j] != target[j]) {
|
if (buf[i + j] != pattern[j]) {
|
||||||
match = false;
|
match = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -59,9 +58,32 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* It seems that AAPT sometimes generate another type of string format */
|
||||||
|
private boolean fallbackPatch(byte xml[], String from, String to) {
|
||||||
|
|
||||||
|
byte[] target = new byte[from.length() * 2 + 2];
|
||||||
|
for (int i = 0; i < from.length(); ++i) {
|
||||||
|
target[i * 2] = (byte) from.charAt(i);
|
||||||
|
}
|
||||||
|
int offset = findOffset(xml, target);
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
return false;
|
return false;
|
||||||
|
byte[] dest = new byte[target.length - 2];
|
||||||
|
for (int i = 0; i < to.length(); ++i) {
|
||||||
|
dest[i * 2] = (byte) to.charAt(i);
|
||||||
|
}
|
||||||
|
System.arraycopy(dest, 0, xml, offset, dest.length);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean findAndPatch(byte xml[], String from, String to) {
|
||||||
|
byte target[] = (from + '\0').getBytes();
|
||||||
|
int offset = findOffset(xml, target);
|
||||||
|
if (offset < 0)
|
||||||
|
return fallbackPatch(xml, from, to);
|
||||||
System.arraycopy(to.getBytes(), 0, xml, offset, to.length());
|
System.arraycopy(to.getBytes(), 0, xml, offset, to.length());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user