18 | */
19 | public class DataBlock {
20 |
21 | private long offset;
22 | private long length;
23 |
24 | public long offset() {
25 | return offset;
26 | }
27 |
28 | public void offset(long offset) {
29 | this.offset = offset;
30 | }
31 |
32 | public long length() {
33 | return length;
34 | }
35 |
36 | public void length(long length) {
37 | this.length = length;
38 | }
39 |
40 | public void endOffset(long endOffset) {
41 | this.length = endOffset - offset;
42 | }
43 |
44 | public long endOffset() {
45 | return offset + length;
46 | }
47 |
48 | public boolean isIntersecting(DataBlock that) {
49 | return this.endOffset() > that.offset() && that.endOffset() > this.offset();
50 | }
51 |
52 | public boolean isInside(DataBlock that) {
53 | return this.offset() >= that.offset() && this.endOffset() <= that.endOffset();
54 | }
55 |
56 | public void markBegin(Positionable p) throws IOException {
57 | offset(p.position());
58 | }
59 |
60 | public void markEnd(Positionable p) throws IOException {
61 | DataBlock.this.endOffset(p.position());
62 | }
63 |
64 | @Override
65 | public String toString() {
66 | return DataBlock.this.offset() + " - " + endOffset() + " (" + DataBlock.this.length() + ")";
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/disunity-core/src/main/java/info/ata4/util/lz4/ByteBufferUtils.java:
--------------------------------------------------------------------------------
1 | /* Partial import of https://github.com/jpountz/lz4-java, Apache 2.0 licensed. */
2 |
3 | package info.ata4.util.lz4;
4 |
5 | import java.nio.ByteBuffer;
6 | import java.nio.ByteOrder;
7 | import java.nio.ReadOnlyBufferException;
8 |
9 | public enum ByteBufferUtils {
10 | ;
11 |
12 | public static void checkRange(ByteBuffer buf, int off, int len) {
13 | SafeUtils.checkLength(len);
14 | if (len > 0) {
15 | checkRange(buf, off);
16 | checkRange(buf, off + len - 1);
17 | }
18 | }
19 |
20 | public static void checkRange(ByteBuffer buf, int off) {
21 | if (off < 0 || off >= buf.capacity()) {
22 | throw new ArrayIndexOutOfBoundsException(off);
23 | }
24 | }
25 |
26 | public static ByteBuffer inLittleEndianOrder(ByteBuffer buf) {
27 | if (buf.order().equals(ByteOrder.LITTLE_ENDIAN)) {
28 | return buf;
29 | } else {
30 | return buf.duplicate().order(ByteOrder.LITTLE_ENDIAN);
31 | }
32 | }
33 |
34 | public static ByteBuffer inNativeByteOrder(ByteBuffer buf) {
35 | if (buf.order().equals(Utils.NATIVE_BYTE_ORDER)) {
36 | return buf;
37 | } else {
38 | return buf.duplicate().order(Utils.NATIVE_BYTE_ORDER);
39 | }
40 | }
41 |
42 | public static byte readByte(ByteBuffer buf, int i) {
43 | return buf.get(i);
44 | }
45 |
46 | public static void writeInt(ByteBuffer buf, int i, int v) {
47 | assert buf.order() == Utils.NATIVE_BYTE_ORDER;
48 | buf.putInt(i, v);
49 | }
50 |
51 | public static int readInt(ByteBuffer buf, int i) {
52 | assert buf.order() == Utils.NATIVE_BYTE_ORDER;
53 | return buf.getInt(i);
54 | }
55 |
56 | public static int readIntLE(ByteBuffer buf, int i) {
57 | assert buf.order() == ByteOrder.LITTLE_ENDIAN;
58 | return buf.getInt(i);
59 | }
60 |
61 | public static void writeLong(ByteBuffer buf, int i, long v) {
62 | assert buf.order() == Utils.NATIVE_BYTE_ORDER;
63 | buf.putLong(i, v);
64 | }
65 |
66 | public static long readLong(ByteBuffer buf, int i) {
67 | assert buf.order() == Utils.NATIVE_BYTE_ORDER;
68 | return buf.getLong(i);
69 | }
70 |
71 | public static long readLongLE(ByteBuffer buf, int i) {
72 | assert buf.order() == ByteOrder.LITTLE_ENDIAN;
73 | return buf.getLong(i);
74 | }
75 |
76 | public static void writeByte(ByteBuffer dest, int off, int i) {
77 | dest.put(off, (byte) i);
78 | }
79 |
80 | public static void writeShortLE(ByteBuffer dest, int off, int i) {
81 | dest.put(off, (byte) i);
82 | dest.put(off + 1, (byte) (i >>> 8));
83 | }
84 |
85 | public static void checkNotReadOnly(ByteBuffer buffer) {
86 | if (buffer.isReadOnly()) {
87 | throw new ReadOnlyBufferException();
88 | }
89 | }
90 |
91 | public static int readShortLE(ByteBuffer buf, int i) {
92 | return (buf.get(i) & 0xFF) | ((buf.get(i+1) & 0xFF) << 8);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/disunity-core/src/main/java/info/ata4/util/lz4/LZ4Constants.java:
--------------------------------------------------------------------------------
1 | /* Partial import of https://github.com/jpountz/lz4-java, Apache 2.0 licensed. */
2 |
3 | package info.ata4.util.lz4;
4 |
5 | /*
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 |
20 | enum LZ4Constants {
21 | ;
22 |
23 | static final int DEFAULT_COMPRESSION_LEVEL = 8+1;
24 | static final int MAX_COMPRESSION_LEVEL = 16+1;
25 |
26 | static final int MEMORY_USAGE = 14;
27 | static final int NOT_COMPRESSIBLE_DETECTION_LEVEL = 6;
28 |
29 | static final int MIN_MATCH = 4;
30 |
31 | static final int HASH_LOG = MEMORY_USAGE - 2;
32 | static final int HASH_TABLE_SIZE = 1 << HASH_LOG;
33 |
34 | static final int SKIP_STRENGTH = Math.max(NOT_COMPRESSIBLE_DETECTION_LEVEL, 2);
35 | static final int COPY_LENGTH = 8;
36 | static final int LAST_LITERALS = 5;
37 | static final int MF_LIMIT = COPY_LENGTH + MIN_MATCH;
38 | static final int MIN_LENGTH = MF_LIMIT + 1;
39 |
40 | static final int MAX_DISTANCE = 1 << 16;
41 |
42 | static final int ML_BITS = 4;
43 | static final int ML_MASK = (1 << ML_BITS) - 1;
44 | static final int RUN_BITS = 8 - ML_BITS;
45 | static final int RUN_MASK = (1 << RUN_BITS) - 1;
46 |
47 | static final int LZ4_64K_LIMIT = (1 << 16) + (MF_LIMIT - 1);
48 | static final int HASH_LOG_64K = HASH_LOG + 1;
49 | static final int HASH_TABLE_SIZE_64K = 1 << HASH_LOG_64K;
50 |
51 | static final int HASH_LOG_HC = 15;
52 | static final int HASH_TABLE_SIZE_HC = 1 << HASH_LOG_HC;
53 | static final int OPTIMAL_ML = ML_MASK - 1 + MIN_MATCH;
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/disunity-core/src/main/java/info/ata4/util/lz4/LZ4Exception.java:
--------------------------------------------------------------------------------
1 | /* Partial import of https://github.com/jpountz/lz4-java, Apache 2.0 licensed. */
2 |
3 | package info.ata4.util.lz4;
4 |
5 | /*
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | /**
20 | * LZ4 compression or decompression error.
21 | */
22 | public class LZ4Exception extends RuntimeException {
23 |
24 | private static final long serialVersionUID = 1L;
25 |
26 | public LZ4Exception(String msg, Throwable t) {
27 | super(msg, t);
28 | }
29 |
30 | public LZ4Exception(String msg) {
31 | super(msg);
32 | }
33 |
34 | public LZ4Exception() {
35 | super();
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/disunity-core/src/main/java/info/ata4/util/lz4/LZ4FastDecompressor.java:
--------------------------------------------------------------------------------
1 | package info.ata4.util.lz4;
2 |
3 | /* Partial import of https://github.com/jpountz/lz4-java, Apache 2.0 licensed. */
4 |
5 | import java.nio.ByteBuffer;
6 |
7 | /*
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 |
21 | /**
22 | * LZ4 decompressor that requires the size of the original input to be known.
23 | * Use LZ4SafeDecompressor if you only know the size of the
24 | * compressed stream.
25 | *
26 | * Instances of this class are thread-safe.
27 | */
28 | public abstract class LZ4FastDecompressor {
29 |
30 | /** Decompress src[srcOff:]
into dest[destOff:destOff+destLen]
31 | * and return the number of bytes read from src
.
32 | * destLen
must be exactly the size of the decompressed data.
33 | *
34 | * @param destLen the exact size of the original input
35 | * @return the number of bytes read to restore the original input
36 | */
37 | public abstract int decompress(byte[] src, int srcOff, byte[] dest, int destOff, int destLen);
38 |
39 | /** Decompress src[srcOff:]
into dest[destOff:destOff+destLen]
40 | * and return the number of bytes read from src
.
41 | * destLen
must be exactly the size of the decompressed data.
42 | * The positions and limits of the {@link ByteBuffer}s remain unchanged.
43 | *
44 | * @param destLen the exact size of the original input
45 | * @return the number of bytes read to restore the original input
46 | */
47 | public abstract int decompress(ByteBuffer src, int srcOff, ByteBuffer dest, int destOff, int destLen);
48 |
49 | /**
50 | * Convenience method, equivalent to calling
51 | * {@link #decompress(byte[], int, byte[], int, int) decompress(src, 0, dest, 0, destLen)}.
52 | */
53 | public final int decompress(byte[] src, byte[] dest, int destLen) {
54 | return decompress(src, 0, dest, 0, destLen);
55 | }
56 |
57 | /**
58 | * Convenience method, equivalent to calling
59 | * {@link #decompress(byte[], byte[], int) decompress(src, dest, dest.length)}.
60 | */
61 | public final int decompress(byte[] src, byte[] dest) {
62 | return decompress(src, dest, dest.length);
63 | }
64 |
65 | /**
66 | * Convenience method which returns src[srcOff:?]
67 | * decompressed.
68 | *
Warning: this method has an
69 | * important overhead due to the fact that it needs to allocate a buffer to
70 | * decompress into.
71 | * Here is how this method is implemented:
72 | *
73 | * final byte[] decompressed = new byte[destLen];
74 | * decompress(src, srcOff, decompressed, 0, destLen);
75 | * return decompressed;
76 | *
77 | */
78 | public final byte[] decompress(byte[] src, int srcOff, int destLen) {
79 | final byte[] decompressed = new byte[destLen];
80 | decompress(src, srcOff, decompressed, 0, destLen);
81 | return decompressed;
82 | }
83 |
84 | /**
85 | * Convenience method, equivalent to calling
86 | * {@link #decompress(byte[], int, int) decompress(src, 0, destLen)}.
87 | */
88 | public final byte[] decompress(byte[] src, int destLen) {
89 | return decompress(src, 0, destLen);
90 | }
91 |
92 | /**
93 | * Decompress src
into dest
. dest
's
94 | * {@link ByteBuffer#remaining()} must be exactly the size of the decompressed
95 | * data. This method moves the positions of the buffers.
96 | */
97 | public final void decompress(ByteBuffer src, ByteBuffer dest) {
98 | final int read = decompress(src, src.position(), dest, dest.position(), dest.remaining());
99 | dest.position(dest.limit());
100 | src.position(src.position() + read);
101 | }
102 |
103 | @Override
104 | public String toString() {
105 | return getClass().getSimpleName();
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/disunity-core/src/main/java/info/ata4/util/lz4/LZ4SafeUtils.java:
--------------------------------------------------------------------------------
1 | /* Partial import of https://github.com/jpountz/lz4-java, Apache 2.0 licensed. */
2 |
3 | package info.ata4.util.lz4;
4 |
5 | /*
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import static info.ata4.util.lz4.LZ4Constants.LAST_LITERALS;
20 | import static info.ata4.util.lz4.LZ4Constants.ML_BITS;
21 | import static info.ata4.util.lz4.LZ4Constants.ML_MASK;
22 | import static info.ata4.util.lz4.LZ4Constants.RUN_MASK;
23 |
24 | enum LZ4SafeUtils {
25 | ;
26 |
27 | static int hash(byte[] buf, int i) {
28 | return LZ4Utils.hash(SafeUtils.readInt(buf, i));
29 | }
30 |
31 | static int hash64k(byte[] buf, int i) {
32 | return LZ4Utils.hash64k(SafeUtils.readInt(buf, i));
33 | }
34 |
35 | static boolean readIntEquals(byte[] buf, int i, int j) {
36 | return buf[i] == buf[j] && buf[i+1] == buf[j+1] && buf[i+2] == buf[j+2] && buf[i+3] == buf[j+3];
37 | }
38 |
39 | static void safeIncrementalCopy(byte[] dest, int matchOff, int dOff, int matchLen) {
40 | for (int i = 0; i < matchLen; ++i) {
41 | dest[dOff + i] = dest[matchOff + i];
42 | }
43 | }
44 |
45 | static void wildIncrementalCopy(byte[] dest, int matchOff, int dOff, int matchCopyEnd) {
46 | do {
47 | copy8Bytes(dest, matchOff, dest, dOff);
48 | matchOff += 8;
49 | dOff += 8;
50 | } while (dOff < matchCopyEnd);
51 | }
52 |
53 | static void copy8Bytes(byte[] src, int sOff, byte[] dest, int dOff) {
54 | for (int i = 0; i < 8; ++i) {
55 | dest[dOff + i] = src[sOff + i];
56 | }
57 | }
58 |
59 | static int commonBytes(byte[] b, int o1, int o2, int limit) {
60 | int count = 0;
61 | while (o2 < limit && b[o1++] == b[o2++]) {
62 | ++count;
63 | }
64 | return count;
65 | }
66 |
67 | static int commonBytesBackward(byte[] b, int o1, int o2, int l1, int l2) {
68 | int count = 0;
69 | while (o1 > l1 && o2 > l2 && b[--o1] == b[--o2]) {
70 | ++count;
71 | }
72 | return count;
73 | }
74 |
75 | static void safeArraycopy(byte[] src, int sOff, byte[] dest, int dOff, int len) {
76 | System.arraycopy(src, sOff, dest, dOff, len);
77 | }
78 |
79 | static void wildArraycopy(byte[] src, int sOff, byte[] dest, int dOff, int len) {
80 | try {
81 | for (int i = 0; i < len; i += 8) {
82 | copy8Bytes(src, sOff + i, dest, dOff + i);
83 | }
84 | } catch (ArrayIndexOutOfBoundsException e) {
85 | throw new LZ4Exception("Malformed input at offset " + sOff);
86 | }
87 | }
88 |
89 | static int encodeSequence(byte[] src, int anchor, int matchOff, int matchRef, int matchLen, byte[] dest, int dOff, int destEnd) {
90 | final int runLen = matchOff - anchor;
91 | final int tokenOff = dOff++;
92 |
93 | if (dOff + runLen + (2 + 1 + LAST_LITERALS) + (runLen >>> 8) > destEnd) {
94 | throw new LZ4Exception("maxDestLen is too small");
95 | }
96 |
97 | int token;
98 | if (runLen >= RUN_MASK) {
99 | token = (byte) (RUN_MASK << ML_BITS);
100 | dOff = writeLen(runLen - RUN_MASK, dest, dOff);
101 | } else {
102 | token = runLen << ML_BITS;
103 | }
104 |
105 | // copy literals
106 | wildArraycopy(src, anchor, dest, dOff, runLen);
107 | dOff += runLen;
108 |
109 | // encode offset
110 | final int matchDec = matchOff - matchRef;
111 | dest[dOff++] = (byte) matchDec;
112 | dest[dOff++] = (byte) (matchDec >>> 8);
113 |
114 | // encode match len
115 | matchLen -= 4;
116 | if (dOff + (1 + LAST_LITERALS) + (matchLen >>> 8) > destEnd) {
117 | throw new LZ4Exception("maxDestLen is too small");
118 | }
119 | if (matchLen >= ML_MASK) {
120 | token |= ML_MASK;
121 | dOff = writeLen(matchLen - RUN_MASK, dest, dOff);
122 | } else {
123 | token |= matchLen;
124 | }
125 |
126 | dest[tokenOff] = (byte) token;
127 |
128 | return dOff;
129 | }
130 |
131 | static int lastLiterals(byte[] src, int sOff, int srcLen, byte[] dest, int dOff, int destEnd) {
132 | final int runLen = srcLen;
133 |
134 | if (dOff + runLen + 1 + (runLen + 255 - RUN_MASK) / 255 > destEnd) {
135 | throw new LZ4Exception();
136 | }
137 |
138 | if (runLen >= RUN_MASK) {
139 | dest[dOff++] = (byte) (RUN_MASK << ML_BITS);
140 | dOff = writeLen(runLen - RUN_MASK, dest, dOff);
141 | } else {
142 | dest[dOff++] = (byte) (runLen << ML_BITS);
143 | }
144 | // copy literals
145 | System.arraycopy(src, sOff, dest, dOff, runLen);
146 | dOff += runLen;
147 |
148 | return dOff;
149 | }
150 |
151 | static int writeLen(int len, byte[] dest, int dOff) {
152 | while (len >= 0xFF) {
153 | dest[dOff++] = (byte) 0xFF;
154 | len -= 0xFF;
155 | }
156 | dest[dOff++] = (byte) len;
157 | return dOff;
158 | }
159 |
160 | static class Match {
161 | int start, ref, len;
162 |
163 | void fix(int correction) {
164 | start += correction;
165 | ref += correction;
166 | len -= correction;
167 | }
168 |
169 | int end() {
170 | return start + len;
171 | }
172 | }
173 |
174 | static void copyTo(Match m1, Match m2) {
175 | m2.len = m1.len;
176 | m2.start = m1.start;
177 | m2.ref = m1.ref;
178 | }
179 |
180 | }
181 |
--------------------------------------------------------------------------------
/disunity-core/src/main/java/info/ata4/util/lz4/LZ4Utils.java:
--------------------------------------------------------------------------------
1 | /* Partial import of https://github.com/jpountz/lz4-java, Apache 2.0 licensed. */
2 |
3 | package info.ata4.util.lz4;
4 |
5 | /*
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import static info.ata4.util.lz4.LZ4Constants.HASH_LOG;
20 | import static info.ata4.util.lz4.LZ4Constants.HASH_LOG_64K;
21 | import static info.ata4.util.lz4.LZ4Constants.HASH_LOG_HC;
22 | import static info.ata4.util.lz4.LZ4Constants.LAST_LITERALS;
23 | import static info.ata4.util.lz4.LZ4Constants.MIN_MATCH;
24 | import static info.ata4.util.lz4.LZ4Constants.ML_BITS;
25 | import static info.ata4.util.lz4.LZ4Constants.ML_MASK;
26 | import static info.ata4.util.lz4.LZ4Constants.RUN_MASK;
27 |
28 | enum LZ4Utils {
29 | ;
30 |
31 | private static final int MAX_INPUT_SIZE = 0x7E000000;
32 |
33 | static int maxCompressedLength(int length) {
34 | if (length < 0) {
35 | throw new IllegalArgumentException("length must be >= 0, got " + length);
36 | } else if (length >= MAX_INPUT_SIZE) {
37 | throw new IllegalArgumentException("length must be < " + MAX_INPUT_SIZE);
38 | }
39 | return length + length / 255 + 16;
40 | }
41 |
42 | static int hash(int i) {
43 | return (i * -1640531535) >>> ((MIN_MATCH * 8) - HASH_LOG);
44 | }
45 |
46 | static int hash64k(int i) {
47 | return (i * -1640531535) >>> ((MIN_MATCH * 8) - HASH_LOG_64K);
48 | }
49 |
50 | static int hashHC(int i) {
51 | return (i * -1640531535) >>> ((MIN_MATCH * 8) - HASH_LOG_HC);
52 | }
53 |
54 | static class Match {
55 | int start, ref, len;
56 |
57 | void fix(int correction) {
58 | start += correction;
59 | ref += correction;
60 | len -= correction;
61 | }
62 |
63 | int end() {
64 | return start + len;
65 | }
66 | }
67 |
68 | static void copyTo(Match m1, Match m2) {
69 | m2.len = m1.len;
70 | m2.start = m1.start;
71 | m2.ref = m1.ref;
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/disunity-core/src/main/java/info/ata4/util/lz4/SafeUtils.java:
--------------------------------------------------------------------------------
1 | /* Partial import of https://github.com/jpountz/lz4-java, Apache 2.0 licensed. */
2 |
3 | package info.ata4.util.lz4;
4 |
5 | /*
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import java.nio.ByteOrder;
20 |
21 | public enum SafeUtils {
22 | ;
23 |
24 | public static void checkRange(byte[] buf, int off) {
25 | if (off < 0 || off >= buf.length) {
26 | throw new ArrayIndexOutOfBoundsException(off);
27 | }
28 | }
29 |
30 | public static void checkRange(byte[] buf, int off, int len) {
31 | checkLength(len);
32 | if (len > 0) {
33 | checkRange(buf, off);
34 | checkRange(buf, off + len - 1);
35 | }
36 | }
37 |
38 | public static void checkLength(int len) {
39 | if (len < 0) {
40 | throw new IllegalArgumentException("lengths must be >= 0");
41 | }
42 | }
43 |
44 | public static byte readByte(byte[] buf, int i) {
45 | return buf[i];
46 | }
47 |
48 | public static int readIntBE(byte[] buf, int i) {
49 | return ((buf[i] & 0xFF) << 24) | ((buf[i+1] & 0xFF) << 16) | ((buf[i+2] & 0xFF) << 8) | (buf[i+3] & 0xFF);
50 | }
51 |
52 | public static int readIntLE(byte[] buf, int i) {
53 | return (buf[i] & 0xFF) | ((buf[i+1] & 0xFF) << 8) | ((buf[i+2] & 0xFF) << 16) | ((buf[i+3] & 0xFF) << 24);
54 | }
55 |
56 | public static int readInt(byte[] buf, int i) {
57 | if (Utils.NATIVE_BYTE_ORDER == ByteOrder.BIG_ENDIAN) {
58 | return readIntBE(buf, i);
59 | } else {
60 | return readIntLE(buf, i);
61 | }
62 | }
63 |
64 | public static long readLongLE(byte[] buf, int i) {
65 | return (buf[i] & 0xFFL) | ((buf[i+1] & 0xFFL) << 8) | ((buf[i+2] & 0xFFL) << 16) | ((buf[i+3] & 0xFFL) << 24)
66 | | ((buf[i+4] & 0xFFL) << 32) | ((buf[i+5] & 0xFFL) << 40) | ((buf[i+6] & 0xFFL) << 48) | ((buf[i+7] & 0xFFL) << 56);
67 | }
68 |
69 | public static void writeShortLE(byte[] buf, int off, int v) {
70 | buf[off++] = (byte) v;
71 | buf[off++] = (byte) (v >>> 8);
72 | }
73 |
74 | public static void writeInt(int[] buf, int off, int v) {
75 | buf[off] = v;
76 | }
77 |
78 | public static int readInt(int[] buf, int off) {
79 | return buf[off];
80 | }
81 |
82 | public static void writeByte(byte[] dest, int off, int i) {
83 | dest[off] = (byte) i;
84 | }
85 |
86 | public static void writeShort(short[] buf, int off, int v) {
87 | buf[off] = (short) v;
88 | }
89 |
90 | public static int readShortLE(byte[] buf, int i) {
91 | return (buf[i] & 0xFF) | ((buf[i+1] & 0xFF) << 8);
92 | }
93 |
94 | public static int readShort(short[] buf, int off) {
95 | return buf[off] & 0xFFFF;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/disunity-core/src/main/java/info/ata4/util/lz4/Utils.java:
--------------------------------------------------------------------------------
1 | /* Partial import of https://github.com/jpountz/lz4-java, Apache 2.0 licensed. */
2 |
3 | package info.ata4.util.lz4;
4 |
5 | /*
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import java.nio.ByteOrder;
20 |
21 | public enum Utils {
22 | ;
23 |
24 | public static final ByteOrder NATIVE_BYTE_ORDER = ByteOrder.nativeOrder();
25 |
26 | private static final boolean unalignedAccessAllowed;
27 | static {
28 | String arch = System.getProperty("os.arch");
29 | unalignedAccessAllowed = arch.equals("i386") || arch.equals("x86")
30 | || arch.equals("amd64") || arch.equals("x86_64");
31 | }
32 |
33 | public static boolean isUnalignedAccessAllowed() {
34 | return unalignedAccessAllowed;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/disunity-core/src/main/resources/strings/5.x.txt:
--------------------------------------------------------------------------------
1 | AABB
2 | AnimationClip
3 | AnimationCurve
4 | AnimationState
5 | Array
6 | Base
7 | BitField
8 | bitset
9 | bool
10 | char
11 | ColorRGBA
12 | Component
13 | data
14 | deque
15 | double
16 | dynamic_array
17 | FastPropertyName
18 | first
19 | float
20 | Font
21 | GameObject
22 | Generic Mono
23 | GradientNEW
24 | GUID
25 | GUIStyle
26 | int
27 | list
28 | long long
29 | map
30 | Matrix4x4f
31 | MdFour
32 | MonoBehaviour
33 | MonoScript
34 | m_ByteSize
35 | m_Curve
36 | m_EditorClassIdentifier
37 | m_EditorHideFlags
38 | m_Enabled
39 | m_ExtensionPtr
40 | m_GameObject
41 | m_Index
42 | m_IsArray
43 | m_IsStatic
44 | m_MetaFlag
45 | m_Name
46 | m_ObjectHideFlags
47 | m_PrefabInternal
48 | m_PrefabParentObject
49 | m_Script
50 | m_StaticEditorFlags
51 | m_Type
52 | m_Version
53 | Object
54 | pair
55 | PPtr
56 | PPtr
57 | PPtr
58 | PPtr
59 | PPtr
60 | PPtr