Process elf correctly
This commit is contained in:
+5
-50
@@ -5,7 +5,6 @@ import org.apache.tools.zip.ZipEntry
|
||||
import javax.annotation.Nonnull
|
||||
import org.apache.tools.zip.ZipOutputStream
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
plugins {
|
||||
id "java"
|
||||
@@ -320,21 +319,10 @@ subprojects { p ->
|
||||
// Sqlite Database
|
||||
relocate("org.xerial", "dh_sqlite.org.xerial")
|
||||
relocate("org.sqlite", "dh_sqlite") {
|
||||
// this is the exact list of classes referenced by native code
|
||||
// exclude("org.sqlite.core.NativeDB")
|
||||
// exclude("org.sqlite.Function")
|
||||
// exclude("org.sqlite.Collation")
|
||||
// exclude("org.sqlite.Function$Aggregate")
|
||||
// exclude("org.sqlite.Function$Window")
|
||||
// exclude("org.sqlite.core.DB$ProgressObserver")
|
||||
// exclude("org.sqlite.ProgressHandler")
|
||||
// exclude("org.sqlite.BusyHandlerh")
|
||||
|
||||
exclude("org/sqlite/native/**")
|
||||
}
|
||||
relocate("jdbc:sqlite", "jdbc:dh_sqlite")
|
||||
|
||||
// "dh_sqlite" leaves just enough room for rewriting "org_sqlite" to "dh_1sqlite" in export tables
|
||||
// https://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/design.html
|
||||
// Should be pretty much enough for Linux & Windows
|
||||
// Probably won't work for Mac, because it requires signing native libs
|
||||
transform(new Transformer() {
|
||||
@@ -342,40 +330,6 @@ subprojects { p ->
|
||||
|
||||
private HashMap<String, byte[]> rewrittenFiles = new HashMap()
|
||||
|
||||
// region thank you chatgpt
|
||||
private static void replaceInByteArray(byte[] byteArray, String target, String replacement) {
|
||||
if (target.length() < replacement.length()) {
|
||||
throw new IllegalArgumentException("Replacement must be the same length or shorter than the target.")
|
||||
}
|
||||
|
||||
byte[] targetBytes = target.getBytes(StandardCharsets.US_ASCII)
|
||||
byte[] replacementBytes = replacement.getBytes(StandardCharsets.US_ASCII)
|
||||
|
||||
int nullByte = 0
|
||||
|
||||
for (int endPos = 0; endPos < byteArray.length - targetBytes.length - 1; endPos++) {
|
||||
int startPos = endPos
|
||||
int targetPos = 0
|
||||
while (targetPos < targetBytes.length && byteArray[endPos] == targetBytes[targetPos]) {
|
||||
targetPos++
|
||||
endPos++
|
||||
}
|
||||
|
||||
if (targetPos == targetBytes.length) {
|
||||
System.arraycopy(replacementBytes, 0, byteArray, startPos, replacementBytes.length)
|
||||
|
||||
startPos = startPos + replacementBytes.length
|
||||
while (byteArray[endPos] != nullByte) {
|
||||
byteArray[startPos] = byteArray[endPos]
|
||||
endPos++
|
||||
startPos++
|
||||
}
|
||||
byteArray[startPos] = nullByte
|
||||
}
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
|
||||
@Override
|
||||
boolean canTransformResource(@Nonnull FileTreeElement element) {
|
||||
System.out.println("canTransformResource " + element.name)
|
||||
@@ -386,10 +340,11 @@ subprojects { p ->
|
||||
void transform(@Nonnull TransformerContext context) {
|
||||
System.out.println("transform " + context.path)
|
||||
|
||||
String path = context.path.replace("org/sqlite", "dh_sqlite")
|
||||
byte[] content = context.is.readAllBytes()
|
||||
replaceInByteArray(content, "org_sqlite", "dh_1sqlite")
|
||||
replaceInByteArray(content, "org/sqlite", "dh_sqlite")
|
||||
rewrittenFiles.put(context.path.replace("org/sqlite", "dh_sqlite"), content)
|
||||
|
||||
content = RelocateNatives.processNative(path, content)
|
||||
rewrittenFiles.put(path, content)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user