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

LinkTargetIDList

parent 8d35eb97
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ public class ByteReader extends InputStream {
private InputStream stream;
private Endianness end = Endianness.LITTLE_ENDIAN;
private int pos = 0;
public ByteReader(InputStream in) {
......@@ -39,8 +40,13 @@ public class ByteReader extends InputStream {
return end == Endianness.LITTLE_ENDIAN;
}
public int getPosition() {
return pos;
}
@Override
public int read() throws IOException {
pos++;
return stream.read();
}
......
package mslinks;
import java.io.IOException;
import java.util.LinkedList;
public class LinkTargetIDList {
private LinkedList<byte[]> list = new LinkedList<>();
public LinkTargetIDList(ByteReader data) throws IOException, ShellLinkException {
int size = (int)data.read2bytes();
int check = data.getPosition();
int s = (int)data.read2bytes();
while (s != 0) {
s -= 2;
byte[] b = new byte[s];
for (int i=0; i<s; i++)
b[i] = (byte)data.read();
list.add(b);
s = (int)data.read2bytes();
}
check = data.getPosition() - check;
if (check != size)
throw new ShellLinkException();
}
public void serialize(ByteWriter bw) throws IOException {
int size = 2;
for (byte[] i : list)
size += i.length + 2;
bw.write2bytes(size);
for (byte[] i : list) {
bw.write2bytes(i.length + 2);
for (byte j : i)
bw.write(j);
}
bw.write2bytes(0);
}
}
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;
......
......@@ -7,7 +7,9 @@ import java.nio.file.Paths;
public class ShellLink {
private ShellLinkHeader header;
private boolean le;
private ShellLinkHeader header;
private LinkTargetIDList idlist;
public ShellLink(String file) throws IOException, ShellLinkException {
this(Paths.get(file));
......@@ -27,17 +29,17 @@ public class ShellLink {
private ShellLink(ByteReader data) throws ShellLinkException, IOException {
header = new ShellLinkHeader(data);
if (header.getLinkFlags().hasLinkTargetIDList())
idlist = new LinkTargetIDList(data);
le = data.isLitteEndian();
}
public void serialize(OutputStream out) throws IOException {
serialize(out, true);
}
public void serialize(OutputStream out, boolean littleendian) throws IOException {
ByteWriter bw = new ByteWriter(out);
if (littleendian) bw.setLittleEndian();
if (le) bw.setLittleEndian();
else bw.setBigEndian();
header.serialize(bw);
header.serialize(bw);
idlist.serialize(bw);
}
/* to header */
......
package mslinks;
public class ShellLinkException extends Exception {
public ShellLinkException() {
super();
}
public ShellLinkException(String msg) {
super(msg);
}
}
test.lnk 0 → 100644
File added
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