Skip to content
Snippets Groups Projects
Commit ccc5b706 authored by Dmitry Shamrikov's avatar Dmitry Shamrikov
Browse files

refactoring

parent 0dcbb4ba
No related branches found
No related tags found
No related merge requests found
package mslinks;
package io;
import java.io.IOException;
import java.io.InputStream;
......@@ -133,51 +133,6 @@ public class ByteReader extends InputStream {
else
return b7 | (b6 << 8) | (b5 << 16) | (b4 << 24) | (b3 << 32) | (b2 << 40) | (b1 << 48) | (b0 << 56);
}
public static short reverse(short n) {
return (short)(((n & 0xff) << 8) | ((n & 0xff00) >> 8));
}
public static int reverse(int n) {
return ((n & 0xff) << 24) | ((n & 0xff00) << 8) | ((n & 0xff0000) >> 8) | ((n & 0xff000000) >>> 24);
}
public static long reverse(long n) {
return ((n & 0xff) << 56) | ((n & 0xff00) << 40) | ((n & 0xff0000) << 24) | ((n & 0xff000000) << 8) |
((n & 0xff00000000L) >> 8) | ((n & 0xff0000000000L) >> 24) | ((n & 0xff000000000000L) >> 40) | ((n & 0xff00000000000000L) >>> 56);
}
public static short makeShortB(byte b0, byte b1) {
return (short)((i(b0) << 8) | i(b1));
}
public static int makeIntB(byte b0, byte b1, byte b2, byte b3) {
return (i(b0) << 24) | (i(b1) << 16) | (i(b2) << 8) | i(b3);
}
public static long makeLongB(byte b0, byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7) {
return (l(b0) << 56) | (l(b1) << 48) | (l(b2) << 40) | (l(b3) << 32) | (l(b4) << 24) | (l(b5) << 16) | (l(b6) << 8) | l(b7);
}
public static short makeShortL(byte b0, byte b1) {
return (short)((i(b1) << 8) | i(b0));
}
public static int makeIntL(byte b0, byte b1, byte b2, byte b3) {
return (i(b3) << 24) | (i(b2) << 16) | (i(b1) << 8) | i(b0);
}
public static long makeLongL(byte b0, byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7) {
return (l(b7) << 56) | (l(b6) << 48) | (l(b5) << 40) | (l(b4) << 32) | (l(b3) << 24) | (l(b2) << 16) | (l(b1) << 8) | l(b0);
}
private static int i(byte b) {
return b & 0xff;
}
private static long l(byte b) {
return b & 0xffL;
}
}
enum Endianness {
......
package mslinks;
package io;
import java.io.IOException;
import java.io.OutputStream;
......
package io;
public class Bytes {
public static short reverse(short n) {
return (short)(((n & 0xff) << 8) | ((n & 0xff00) >> 8));
}
public static int reverse(int n) {
return ((n & 0xff) << 24) | ((n & 0xff00) << 8) | ((n & 0xff0000) >> 8) | ((n & 0xff000000) >>> 24);
}
public static long reverse(long n) {
return ((n & 0xff) << 56) | ((n & 0xff00) << 40) | ((n & 0xff0000) << 24) | ((n & 0xff000000) << 8) |
((n & 0xff00000000L) >> 8) | ((n & 0xff0000000000L) >> 24) | ((n & 0xff000000000000L) >> 40) | ((n & 0xff00000000000000L) >>> 56);
}
public static short makeShortB(byte b0, byte b1) {
return (short)((Bytes.i(b0) << 8) | Bytes.i(b1));
}
public static int makeIntB(byte b0, byte b1, byte b2, byte b3) {
return (Bytes.i(b0) << 24) | (Bytes.i(b1) << 16) | (Bytes.i(b2) << 8) | Bytes.i(b3);
}
public static long makeLongB(byte b0, byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7) {
return (Bytes.l(b0) << 56) | (Bytes.l(b1) << 48) | (Bytes.l(b2) << 40) | (Bytes.l(b3) << 32) | (Bytes.l(b4) << 24) | (Bytes.l(b5) << 16) | (Bytes.l(b6) << 8) | Bytes.l(b7);
}
public static short makeShortL(byte b0, byte b1) {
return (short)((Bytes.i(b1) << 8) | Bytes.i(b0));
}
public static int makeIntL(byte b0, byte b1, byte b2, byte b3) {
return (Bytes.i(b3) << 24) | (Bytes.i(b2) << 16) | (Bytes.i(b1) << 8) | Bytes.i(b0);
}
public static long makeLongL(byte b0, byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7) {
return (Bytes.l(b7) << 56) | (Bytes.l(b6) << 48) | (Bytes.l(b5) << 40) | (Bytes.l(b4) << 32) | (Bytes.l(b3) << 24) | (Bytes.l(b2) << 16) | (Bytes.l(b1) << 8) | Bytes.l(b0);
}
static int i(byte b) {
return b & 0xff;
}
static long l(byte b) {
return b & 0xffL;
}
}
package mslinks;
import io.ByteReader;
import io.ByteWriter;
import java.io.IOException;
import java.util.LinkedList;
......
package mslinks;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.GregorianCalendar;
import mslinks.data.Filetime;
public class Main {
public static void main(String[] args) throws IOException, ShellLinkException {
ShellLink link = new ShellLink("testlink.lnk");
......
package mslinks;
import io.ByteReader;
import io.ByteWriter;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import mslinks.data.FileAttributesFlags;
import mslinks.data.Filetime;
import mslinks.data.HotKeyFlags;
import mslinks.data.LinkFlags;
public class ShellLink {
private boolean le;
......
package mslinks;
import io.ByteReader;
import io.ByteWriter;
import io.Bytes;
import java.io.IOException;
import mslinks.data.FileAttributesFlags;
import mslinks.data.Filetime;
import mslinks.data.GUID;
import mslinks.data.HotKeyFlags;
import mslinks.data.LinkFlags;
public class ShellLinkHeader {
private static byte b(int i) { return (byte)i; }
private static int headerSize = 0x0000004C;
......@@ -27,7 +37,7 @@ public class ShellLinkHeader {
public ShellLinkHeader(ByteReader data) throws ShellLinkException, IOException {
int size = (int)data.read4bytes();
if (size != headerSize) {
size = ByteReader.reverse(size);
size = Bytes.reverse(size);
if (size != headerSize)
throw new ShellLinkException();
data.changeEndiannes();
......
package mslinks;
package mslinks.data;
import io.ByteReader;
import io.ByteWriter;
import java.io.IOException;
......
package mslinks;
package mslinks.data;
import io.ByteReader;
import java.io.IOException;
......
package mslinks;
package mslinks.data;
import io.ByteReader;
import io.ByteWriter;
import java.io.IOException;
import java.util.GregorianCalendar;
......
package mslinks;
package mslinks.data;
import io.ByteReader;
import io.ByteWriter;
import io.Bytes;
import java.io.IOException;
......@@ -8,11 +12,11 @@ public class GUID {
private long d5;
public GUID(byte[] d) {
d1 = ByteReader.makeIntL(d[0], d[1], d[2], d[3]);
d2 = ByteReader.makeShortL(d[4], d[5]);
d3 = ByteReader.makeShortL(d[6], d[7]);
d4 = ByteReader.makeShortB(d[8], d[9]);
d5 = ByteReader.makeLongB((byte)0, (byte)0, d[10], d[11], d[12], d[13], d[14], d[15]);
d1 = Bytes.makeIntL(d[0], d[1], d[2], d[3]);
d2 = Bytes.makeShortL(d[4], d[5]);
d3 = Bytes.makeShortL(d[6], d[7]);
d4 = Bytes.makeShortB(d[8], d[9]);
d5 = Bytes.makeLongB((byte)0, (byte)0, d[10], d[11], d[12], d[13], d[14], d[15]);
}
public GUID(ByteReader data) throws IOException {
......
package mslinks;
package mslinks.data;
import io.ByteReader;
import io.ByteWriter;
import java.io.IOException;
import java.util.HashMap;
......
package mslinks;
package mslinks.data;
import io.ByteReader;
import java.io.IOException;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment