Now can download .pack.xz file for Forge library.
This commit is contained in:
50
HMCLAPI/src/main/java/org/tukaani/xz/simple/ARM.java
Normal file
50
HMCLAPI/src/main/java/org/tukaani/xz/simple/ARM.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* BCJ filter for little endian ARM instructions
|
||||
*
|
||||
* Authors: Lasse Collin <lasse.collin@tukaani.org>
|
||||
* Igor Pavlov <http://7-zip.org/>
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
package org.tukaani.xz.simple;
|
||||
|
||||
public final class ARM implements SimpleFilter {
|
||||
private final boolean isEncoder;
|
||||
private int pos;
|
||||
|
||||
public ARM(boolean isEncoder, int startPos) {
|
||||
this.isEncoder = isEncoder;
|
||||
pos = startPos + 8;
|
||||
}
|
||||
|
||||
public int code(byte[] buf, int off, int len) {
|
||||
int end = off + len - 4;
|
||||
int i;
|
||||
|
||||
for (i = off; i <= end; i += 4) {
|
||||
if ((buf[i + 3] & 0xFF) == 0xEB) {
|
||||
int src = ((buf[i + 2] & 0xFF) << 16)
|
||||
| ((buf[i + 1] & 0xFF) << 8)
|
||||
| (buf[i] & 0xFF);
|
||||
src <<= 2;
|
||||
|
||||
int dest;
|
||||
if (isEncoder)
|
||||
dest = src + (pos + i - off);
|
||||
else
|
||||
dest = src - (pos + i - off);
|
||||
|
||||
dest >>>= 2;
|
||||
buf[i + 2] = (byte)(dest >>> 16);
|
||||
buf[i + 1] = (byte)(dest >>> 8);
|
||||
buf[i] = (byte)dest;
|
||||
}
|
||||
}
|
||||
|
||||
i -= off;
|
||||
pos += i;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
53
HMCLAPI/src/main/java/org/tukaani/xz/simple/ARMThumb.java
Normal file
53
HMCLAPI/src/main/java/org/tukaani/xz/simple/ARMThumb.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* BCJ filter for little endian ARM-Thumb instructions
|
||||
*
|
||||
* Authors: Lasse Collin <lasse.collin@tukaani.org>
|
||||
* Igor Pavlov <http://7-zip.org/>
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
package org.tukaani.xz.simple;
|
||||
|
||||
public final class ARMThumb implements SimpleFilter {
|
||||
private final boolean isEncoder;
|
||||
private int pos;
|
||||
|
||||
public ARMThumb(boolean isEncoder, int startPos) {
|
||||
this.isEncoder = isEncoder;
|
||||
pos = startPos + 4;
|
||||
}
|
||||
|
||||
public int code(byte[] buf, int off, int len) {
|
||||
int end = off + len - 4;
|
||||
int i;
|
||||
|
||||
for (i = off; i <= end; i += 2) {
|
||||
if ((buf[i + 1] & 0xF8) == 0xF0 && (buf[i + 3] & 0xF8) == 0xF8) {
|
||||
int src = ((buf[i + 1] & 0x07) << 19)
|
||||
| ((buf[i] & 0xFF) << 11)
|
||||
| ((buf[i + 3] & 0x07) << 8)
|
||||
| (buf[i + 2] & 0xFF);
|
||||
src <<= 1;
|
||||
|
||||
int dest;
|
||||
if (isEncoder)
|
||||
dest = src + (pos + i - off);
|
||||
else
|
||||
dest = src - (pos + i - off);
|
||||
|
||||
dest >>>= 1;
|
||||
buf[i + 1] = (byte)(0xF0 | ((dest >>> 19) & 0x07));
|
||||
buf[i] = (byte)(dest >>> 11);
|
||||
buf[i + 3] = (byte)(0xF8 | ((dest >>> 8) & 0x07));
|
||||
buf[i + 2] = (byte)dest;
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
i -= off;
|
||||
pos += i;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
81
HMCLAPI/src/main/java/org/tukaani/xz/simple/IA64.java
Normal file
81
HMCLAPI/src/main/java/org/tukaani/xz/simple/IA64.java
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* BCJ filter for Itanium (IA-64) instructions
|
||||
*
|
||||
* Authors: Lasse Collin <lasse.collin@tukaani.org>
|
||||
* Igor Pavlov <http://7-zip.org/>
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
package org.tukaani.xz.simple;
|
||||
|
||||
public final class IA64 implements SimpleFilter {
|
||||
private static final int[] BRANCH_TABLE = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
4, 4, 6, 6, 0, 0, 7, 7,
|
||||
4, 4, 0, 0, 4, 4, 0, 0 };
|
||||
|
||||
private final boolean isEncoder;
|
||||
private int pos;
|
||||
|
||||
public IA64(boolean isEncoder, int startPos) {
|
||||
this.isEncoder = isEncoder;
|
||||
pos = startPos;
|
||||
}
|
||||
|
||||
public int code(byte[] buf, int off, int len) {
|
||||
int end = off + len - 16;
|
||||
int i;
|
||||
|
||||
for (i = off; i <= end; i += 16) {
|
||||
int instrTemplate = buf[i] & 0x1F;
|
||||
int mask = BRANCH_TABLE[instrTemplate];
|
||||
|
||||
for (int slot = 0, bitPos = 5; slot < 3; ++slot, bitPos += 41) {
|
||||
if (((mask >>> slot) & 1) == 0)
|
||||
continue;
|
||||
|
||||
int bytePos = bitPos >>> 3;
|
||||
int bitRes = bitPos & 7;
|
||||
|
||||
long instr = 0;
|
||||
for (int j = 0; j < 6; ++j)
|
||||
instr |= (buf[i + bytePos + j] & 0xFFL) << (8 * j);
|
||||
|
||||
long instrNorm = instr >>> bitRes;
|
||||
|
||||
if (((instrNorm >>> 37) & 0x0F) != 0x05
|
||||
|| ((instrNorm >>> 9) & 0x07) != 0x00)
|
||||
continue;
|
||||
|
||||
int src = (int)((instrNorm >>> 13) & 0x0FFFFF);
|
||||
src |= ((int)(instrNorm >>> 36) & 1) << 20;
|
||||
src <<= 4;
|
||||
|
||||
int dest;
|
||||
if (isEncoder)
|
||||
dest = src + (pos + i - off);
|
||||
else
|
||||
dest = src - (pos + i - off);
|
||||
|
||||
dest >>>= 4;
|
||||
|
||||
instrNorm &= ~(0x8FFFFFL << 13);
|
||||
instrNorm |= (dest & 0x0FFFFFL) << 13;
|
||||
instrNorm |= (dest & 0x100000L) << (36 - 20);
|
||||
|
||||
instr &= (1 << bitRes) - 1;
|
||||
instr |= instrNorm << bitRes;
|
||||
|
||||
for (int j = 0; j < 6; ++j)
|
||||
buf[i + bytePos + j] = (byte)(instr >>> (8 * j));
|
||||
}
|
||||
}
|
||||
|
||||
i -= off;
|
||||
pos += i;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
50
HMCLAPI/src/main/java/org/tukaani/xz/simple/PowerPC.java
Normal file
50
HMCLAPI/src/main/java/org/tukaani/xz/simple/PowerPC.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* BCJ filter for big endian PowerPC instructions
|
||||
*
|
||||
* Authors: Lasse Collin <lasse.collin@tukaani.org>
|
||||
* Igor Pavlov <http://7-zip.org/>
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
package org.tukaani.xz.simple;
|
||||
|
||||
public final class PowerPC implements SimpleFilter {
|
||||
private final boolean isEncoder;
|
||||
private int pos;
|
||||
|
||||
public PowerPC(boolean isEncoder, int startPos) {
|
||||
this.isEncoder = isEncoder;
|
||||
pos = startPos;
|
||||
}
|
||||
|
||||
public int code(byte[] buf, int off, int len) {
|
||||
int end = off + len - 4;
|
||||
int i;
|
||||
|
||||
for (i = off; i <= end; i += 4) {
|
||||
if ((buf[i] & 0xFC) == 0x48 && (buf[i + 3] & 0x03) == 0x01) {
|
||||
int src = ((buf[i] & 0x03) << 24)
|
||||
| ((buf[i + 1] & 0xFF) << 16)
|
||||
| ((buf[i + 2] & 0xFF) << 8)
|
||||
| (buf[i + 3] & 0xFC);
|
||||
|
||||
int dest;
|
||||
if (isEncoder)
|
||||
dest = src + (pos + i - off);
|
||||
else
|
||||
dest = src - (pos + i - off);
|
||||
|
||||
buf[i] = (byte)(0x48 | ((dest >>> 24) & 0x03));
|
||||
buf[i + 1] = (byte)(dest >>> 16);
|
||||
buf[i + 2] = (byte)(dest >>> 8);
|
||||
buf[i + 3] = (byte)((buf[i + 3] & 0x03) | dest);
|
||||
}
|
||||
}
|
||||
|
||||
i -= off;
|
||||
pos += i;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
56
HMCLAPI/src/main/java/org/tukaani/xz/simple/SPARC.java
Normal file
56
HMCLAPI/src/main/java/org/tukaani/xz/simple/SPARC.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* BCJ filter for SPARC instructions
|
||||
*
|
||||
* Authors: Lasse Collin <lasse.collin@tukaani.org>
|
||||
* Igor Pavlov <http://7-zip.org/>
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
package org.tukaani.xz.simple;
|
||||
|
||||
public final class SPARC implements SimpleFilter {
|
||||
private final boolean isEncoder;
|
||||
private int pos;
|
||||
|
||||
public SPARC(boolean isEncoder, int startPos) {
|
||||
this.isEncoder = isEncoder;
|
||||
pos = startPos;
|
||||
}
|
||||
|
||||
public int code(byte[] buf, int off, int len) {
|
||||
int end = off + len - 4;
|
||||
int i;
|
||||
|
||||
for (i = off; i <= end; i += 4) {
|
||||
if ((buf[i] == 0x40 && (buf[i + 1] & 0xC0) == 0x00)
|
||||
|| (buf[i] == 0x7F && (buf[i + 1] & 0xC0) == 0xC0)) {
|
||||
int src = ((buf[i] & 0xFF) << 24)
|
||||
| ((buf[i + 1] & 0xFF) << 16)
|
||||
| ((buf[i + 2] & 0xFF) << 8)
|
||||
| (buf[i + 3] & 0xFF);
|
||||
src <<= 2;
|
||||
|
||||
int dest;
|
||||
if (isEncoder)
|
||||
dest = src + (pos + i - off);
|
||||
else
|
||||
dest = src - (pos + i - off);
|
||||
|
||||
dest >>>= 2;
|
||||
dest = (((0 - ((dest >>> 22) & 1)) << 22) & 0x3FFFFFFF)
|
||||
| (dest & 0x3FFFFF) | 0x40000000;
|
||||
|
||||
buf[i] = (byte)(dest >>> 24);
|
||||
buf[i + 1] = (byte)(dest >>> 16);
|
||||
buf[i + 2] = (byte)(dest >>> 8);
|
||||
buf[i + 3] = (byte)dest;
|
||||
}
|
||||
}
|
||||
|
||||
i -= off;
|
||||
pos += i;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* BCJ filter for little endian ARM instructions
|
||||
*
|
||||
* Author: Lasse Collin <lasse.collin@tukaani.org>
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
package org.tukaani.xz.simple;
|
||||
|
||||
public interface SimpleFilter {
|
||||
int code(byte[] buf, int off, int len);
|
||||
}
|
||||
98
HMCLAPI/src/main/java/org/tukaani/xz/simple/X86.java
Normal file
98
HMCLAPI/src/main/java/org/tukaani/xz/simple/X86.java
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* BCJ filter for x86 instructions
|
||||
*
|
||||
* Authors: Lasse Collin <lasse.collin@tukaani.org>
|
||||
* Igor Pavlov <http://7-zip.org/>
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
package org.tukaani.xz.simple;
|
||||
|
||||
public final class X86 implements SimpleFilter {
|
||||
private static final boolean[] MASK_TO_ALLOWED_STATUS
|
||||
= {true, true, true, false, true, false, false, false};
|
||||
|
||||
private static final int[] MASK_TO_BIT_NUMBER = {0, 1, 2, 2, 3, 3, 3, 3};
|
||||
|
||||
private final boolean isEncoder;
|
||||
private int pos;
|
||||
private int prevMask = 0;
|
||||
|
||||
private static boolean test86MSByte(byte b) {
|
||||
int i = b & 0xFF;
|
||||
return i == 0x00 || i == 0xFF;
|
||||
}
|
||||
|
||||
public X86(boolean isEncoder, int startPos) {
|
||||
this.isEncoder = isEncoder;
|
||||
pos = startPos + 5;
|
||||
}
|
||||
|
||||
public int code(byte[] buf, int off, int len) {
|
||||
int prevPos = off - 1;
|
||||
int end = off + len - 5;
|
||||
int i;
|
||||
|
||||
for (i = off; i <= end; ++i) {
|
||||
if ((buf[i] & 0xFE) != 0xE8)
|
||||
continue;
|
||||
|
||||
prevPos = i - prevPos;
|
||||
if ((prevPos & ~3) != 0) { // (unsigned)prevPos > 3
|
||||
prevMask = 0;
|
||||
} else {
|
||||
prevMask = (prevMask << (prevPos - 1)) & 7;
|
||||
if (prevMask != 0) {
|
||||
if (!MASK_TO_ALLOWED_STATUS[prevMask] || test86MSByte(
|
||||
buf[i + 4 - MASK_TO_BIT_NUMBER[prevMask]])) {
|
||||
prevPos = i;
|
||||
prevMask = (prevMask << 1) | 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prevPos = i;
|
||||
|
||||
if (test86MSByte(buf[i + 4])) {
|
||||
int src = (buf[i + 1] & 0xFF)
|
||||
| ((buf[i + 2] & 0xFF) << 8)
|
||||
| ((buf[i + 3] & 0xFF) << 16)
|
||||
| ((buf[i + 4] & 0xFF) << 24);
|
||||
int dest;
|
||||
while (true) {
|
||||
if (isEncoder)
|
||||
dest = src + (pos + i - off);
|
||||
else
|
||||
dest = src - (pos + i - off);
|
||||
|
||||
if (prevMask == 0)
|
||||
break;
|
||||
|
||||
int index = MASK_TO_BIT_NUMBER[prevMask] * 8;
|
||||
if (!test86MSByte((byte)(dest >>> (24 - index))))
|
||||
break;
|
||||
|
||||
src = dest ^ ((1 << (32 - index)) - 1);
|
||||
}
|
||||
|
||||
buf[i + 1] = (byte)dest;
|
||||
buf[i + 2] = (byte)(dest >>> 8);
|
||||
buf[i + 3] = (byte)(dest >>> 16);
|
||||
buf[i + 4] = (byte)(~(((dest >>> 24) & 1) - 1));
|
||||
i += 4;
|
||||
} else {
|
||||
prevMask = (prevMask << 1) | 1;
|
||||
}
|
||||
}
|
||||
|
||||
prevPos = i - prevPos;
|
||||
prevMask = ((prevPos & ~3) != 0) ? 0 : prevMask << (prevPos - 1);
|
||||
|
||||
i -= off;
|
||||
pos += i;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user