diff --git a/brachyura/pom.xml b/brachyura/pom.xml
index bf339be99..70ea5c9f7 100644
--- a/brachyura/pom.xml
+++ b/brachyura/pom.xml
@@ -60,7 +60,7 @@
io.github.coolcrabs
cfr
- 0.3
+ 0.4
io.github.coolcrabs
diff --git a/cfr/pom.xml b/cfr/pom.xml
index 8afcfd7c5..db5d584b5 100644
--- a/cfr/pom.xml
+++ b/cfr/pom.xml
@@ -6,7 +6,7 @@
io.github.coolcrabs
cfr
- 0.3
+ 0.4
cfr
CFR Java decompiler
diff --git a/cfr/src/org/benf/cfr/reader/util/bytestream/AbstractBackedByteData.java b/cfr/src/org/benf/cfr/reader/util/bytestream/AbstractBackedByteData.java
index 02961d6c9..f651d4e24 100644
--- a/cfr/src/org/benf/cfr/reader/util/bytestream/AbstractBackedByteData.java
+++ b/cfr/src/org/benf/cfr/reader/util/bytestream/AbstractBackedByteData.java
@@ -2,83 +2,100 @@
import org.benf.cfr.reader.util.ConfusedCFRException;
-import java.io.DataInputStream;
-
+/**
+ * {@link java.io.DataInputStream}
+ */
public abstract class AbstractBackedByteData implements ByteData {
+ protected final byte[] d;
+
+ protected AbstractBackedByteData(byte[] data) {
+ this.d = data;
+ }
- abstract DataInputStream rawDataAsStream(int offset, int length);
+ abstract int getRealOffset(int offset);
@Override
public int getS4At(long o) throws ConfusedCFRException {
- // Let's find an EFFICIENT way to do this later!
- DataInputStream dis = rawDataAsStream((int) o, 4);
+ int a = getRealOffset((int) o);
try {
- return dis.readInt();
- } catch (Exception e) {
+ return (((d[a] & 0xFF) << 24) | ((d[a + 1] & 0xFF) << 16) | ((d[a + 2] & 0xFF) << 8) | (d[a + 3] & 0xFF));
+ } catch (IndexOutOfBoundsException e) {
throw new ConfusedCFRException(e);
}
}
@Override
public double getDoubleAt(long o) throws ConfusedCFRException {
- DataInputStream dis = rawDataAsStream((int) o, 8);
- try {
- return dis.readDouble();
- } catch (Exception e) {
- throw new ConfusedCFRException(e);
- }
+ return Double.longBitsToDouble(getLongAt(o));
}
@Override
public float getFloatAt(long o) throws ConfusedCFRException {
- DataInputStream dis = rawDataAsStream((int) o, 8);
- try {
- return dis.readFloat();
- } catch (Exception e) {
- throw new ConfusedCFRException(e);
- }
+ return Float.intBitsToFloat(getS4At(o));
}
@Override
public long getLongAt(long o) throws ConfusedCFRException {
- DataInputStream dis = rawDataAsStream((int) o, 8);
+ int a = getRealOffset((int) o);
try {
- return dis.readLong();
- } catch (Exception e) {
+ return (((long)(d[a + 0] & 255) << 56) +
+ ((long)(d[a + 1] & 255) << 48) +
+ ((long)(d[a + 2] & 255) << 40) +
+ ((long)(d[a + 3] & 255) << 32) +
+ ((long)(d[a + 4] & 255) << 24) +
+ ((d[a + 5] & 255) << 16) +
+ ((d[a + 6] & 255) << 8) +
+ ((d[a + 7] & 255) << 0));
+ } catch (IndexOutOfBoundsException e) {
throw new ConfusedCFRException(e);
}
}
@Override
public short getS2At(long o) throws ConfusedCFRException {
- // Let's find an EFFICIENT way to do this later!
- DataInputStream dis = rawDataAsStream((int) o, 2);
+ int a = getRealOffset((int) o);
try {
- return dis.readShort();
- } catch (Exception e) {
+ return (short)(((d[a] & 0xFF) << 8) | (d[a + 1] & 0xFF));
+ } catch (IndexOutOfBoundsException e) {
throw new ConfusedCFRException(e);
}
}
@Override
public int getU2At(long o) throws ConfusedCFRException {
- // Let's find an EFFICIENT way to do this later!
- DataInputStream dis = rawDataAsStream((int) o, 2);
+ int a = getRealOffset((int) o);
try {
- return dis.readUnsignedShort();
- } catch (Exception e) {
+ return (((d[a] & 0xFF) << 8) | (d[a + 1] & 0xFF));
+ } catch (IndexOutOfBoundsException e) {
throw new ConfusedCFRException(e);
}
}
@Override
public short getU1At(long o) throws ConfusedCFRException {
- // Let's find an EFFICIENT way to do this later!
- DataInputStream dis = rawDataAsStream((int) o, 1);
+ int a = getRealOffset((int) o);
try {
- return (short) dis.readUnsignedByte();
- } catch (Exception e) {
+ return (short)(d[a] & 0xff);
+ } catch (IndexOutOfBoundsException e) {
throw new ConfusedCFRException(e);
}
}
+
+ @Override
+ public byte getS1At(long o) {
+ int a = getRealOffset((int) o);
+ try {
+ return d[a];
+ } catch (IndexOutOfBoundsException e) {
+ throw new ConfusedCFRException(e);
+ }
+ }
+
+ @Override
+ public byte[] getBytesAt(int count, long offset) {
+ int a = getRealOffset((int) offset);
+ byte[] res = new byte[count];
+ System.arraycopy(d, a, res, 0, count);
+ return res;
+ }
}
diff --git a/cfr/src/org/benf/cfr/reader/util/bytestream/BaseByteData.java b/cfr/src/org/benf/cfr/reader/util/bytestream/BaseByteData.java
index 0336e32f2..bbbcec174 100644
--- a/cfr/src/org/benf/cfr/reader/util/bytestream/BaseByteData.java
+++ b/cfr/src/org/benf/cfr/reader/util/bytestream/BaseByteData.java
@@ -1,39 +1,23 @@
package org.benf.cfr.reader.util.bytestream;
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-
public class BaseByteData extends AbstractBackedByteData {
- private final byte[] data;
-
public BaseByteData(byte[] data) {
- this.data = data;
- }
-
- @Override
- public DataInputStream rawDataAsStream(int start, int len) {
- return new DataInputStream(new ByteArrayInputStream(data, start, len));
+ super(data);
}
@Override
public ByteData getOffsetData(long offset) {
- return new OffsetBackedByteData(data, offset);
+ return new OffsetBackedByteData(d, offset);
}
@Override
public OffsettingByteData getOffsettingOffsetData(long offset) {
- return new OffsettingBackedByteData(data, offset);
- }
-
- @Override
- public byte[] getBytesAt(int count, long offset) {
- byte[] res = new byte[count];
- System.arraycopy(data, (int) offset, res, 0, count);
- return res;
+ return new OffsettingBackedByteData(d, offset);
}
@Override
- public byte getS1At(long o) {
- return data[(int) o];
+ int getRealOffset(int offset) {
+ return offset;
}
+
}
diff --git a/cfr/src/org/benf/cfr/reader/util/bytestream/OffsetBackedByteData.java b/cfr/src/org/benf/cfr/reader/util/bytestream/OffsetBackedByteData.java
index 84351a542..428e895cc 100644
--- a/cfr/src/org/benf/cfr/reader/util/bytestream/OffsetBackedByteData.java
+++ b/cfr/src/org/benf/cfr/reader/util/bytestream/OffsetBackedByteData.java
@@ -1,41 +1,25 @@
package org.benf.cfr.reader.util.bytestream;
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-
public class OffsetBackedByteData extends AbstractBackedByteData {
private final int offset;
- private final byte[] data;
OffsetBackedByteData(byte[] data, long offset) {
+ super(data);
this.offset = (int) offset;
- this.data = data;
- }
-
- @Override
- public DataInputStream rawDataAsStream(int start, int len) {
- return new DataInputStream(new ByteArrayInputStream(data, start + offset, len));
}
@Override
public ByteData getOffsetData(long offset) {
- return new OffsetBackedByteData(data, this.offset + offset);
+ return new OffsetBackedByteData(d, this.offset + offset);
}
@Override
public OffsettingByteData getOffsettingOffsetData(long offset) {
- return new OffsettingBackedByteData(data, this.offset + offset);
- }
-
- @Override
- public byte getS1At(long o) {
- return data[(int) (offset + o)];
+ return new OffsettingBackedByteData(d, this.offset + offset);
}
@Override
- public byte[] getBytesAt(int count, long offset) {
- byte[] res = new byte[count];
- System.arraycopy(data, (int) (this.offset + offset), res, 0, count);
- return res;
+ int getRealOffset(int o) {
+ return o + offset;
}
}
diff --git a/cfr/src/org/benf/cfr/reader/util/bytestream/OffsettingBackedByteData.java b/cfr/src/org/benf/cfr/reader/util/bytestream/OffsettingBackedByteData.java
index b52188fcd..8376f46ad 100644
--- a/cfr/src/org/benf/cfr/reader/util/bytestream/OffsettingBackedByteData.java
+++ b/cfr/src/org/benf/cfr/reader/util/bytestream/OffsettingBackedByteData.java
@@ -1,15 +1,11 @@
package org.benf.cfr.reader.util.bytestream;
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-
public class OffsettingBackedByteData extends AbstractBackedByteData implements OffsettingByteData {
- private final byte[] data;
private final int originalOffset;
private int mutableOffset;
OffsettingBackedByteData(byte[] data, long offset) {
- this.data = data;
+ super(data);
this.originalOffset = (int) offset;
this.mutableOffset = 0;
}
@@ -24,30 +20,18 @@ public long getOffset() {
return mutableOffset;
}
- @Override
- public DataInputStream rawDataAsStream(int start, int len) {
- return new DataInputStream(new ByteArrayInputStream(data, start + originalOffset + mutableOffset, len));
- }
-
@Override
public ByteData getOffsetData(long offset) {
- return new OffsetBackedByteData(data, originalOffset + mutableOffset + offset);
+ return new OffsetBackedByteData(d, originalOffset + mutableOffset + offset);
}
@Override
public OffsettingByteData getOffsettingOffsetData(long offset) {
- return new OffsettingBackedByteData(data, originalOffset + mutableOffset + offset);
- }
-
- @Override
- public byte getS1At(long o) {
- return data[(int) (originalOffset + mutableOffset + o)];
+ return new OffsettingBackedByteData(d, originalOffset + mutableOffset + offset);
}
@Override
- public byte[] getBytesAt(int count, long offset) {
- byte[] res = new byte[count];
- System.arraycopy(data, (int) (this.originalOffset + this.mutableOffset + offset), res, 0, count);
- return res;
+ int getRealOffset(int offset) {
+ return originalOffset + mutableOffset + offset;
}
}