func TestWriteCompose(t *testing.T) { buf := new(bytes.Buffer) genbin.Compose(buf, []uint8{0x4C, 0x00, 0x00, 0x00, 0x01, 0x14, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x9B, 0x00, 0x08, 0x00, 0x20, 0x00, 0x00, 0x00, 0xD0, 0xE9, 0xEE, 0xF2, 0x15, 0x15, 0xC9, 0x01, 0xD0, 0xE9, 0xEE, 0xF2, 0x15, 0x15, 0xC9, 0x01, 0xD0, 0xE9, 0xEE, 0xF2, 0x15, 0x15, 0xC9, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBD, 0x00, 0x14, 0x00, 0x1F, 0x50, 0xE0, 0x4F, 0xD0, 0x20, 0xEA, 0x3A, 0x69, 0x10, 0xA2, 0xD8, 0x08, 0x00, 0x2B, 0x30, 0x30, 0x9D, 0x19, 0x00, 0x2F, 0x43, 0x3A, 0x5C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x39, 0x69, 0xA3, 0x10, 0x00, 0x74, 0x65, 0x73, 0x74, 0x00, 0x00, 0x32, 0x00, 0x07, 0x00, 0x04, 0x00, 0xEF, 0xBE, 0x2C, 0x39, 0x65, 0xA3, 0x2C, 0x39, 0x69, 0xA3, 0x26, 0x00, 0x00, 0x00, 0x03, 0x1E, 0x00, 0x00, 0x00, 0x00, 0xF5, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x00, 0x65, 0x00, 0x73, 0x00, 0x74, 0x00, 0x00, 0x00, 0x14, 0x00, 0x48, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x39, 0x69, 0xA3, 0x20, 0x00, 0x61, 0x2E, 0x74, 0x78, 0x74, 0x00, 0x34, 0x00, 0x07, 0x00, 0x04, 0x00, 0xEF, 0xBE, 0x2C, 0x39, 0x69, 0xA3, 0x2C, 0x39, 0x69, 0xA3, 0x26, 0x00, 0x00, 0x00, 0x2D, 0x6E, 0x00, 0x00, 0x00, 0x00, 0x96, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x00, 0x2E, 0x00, 0x74, 0x00, 0x78, 0x00, 0x74, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x2D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3B, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x81, 0x8A, 0x7A, 0x30, 0x10, 0x00, 0x00, 0x00, 0x00, 0x43, 0x3A, 0x5C, 0x74, 0x65, 0x73, 0x74, 0x5C, 0x61, 0x2E, 0x74, 0x78, 0x74, 0x00, 0x00, 0x07, 0x00, 0x2E, 0x00, 0x5C, 0x00, 0x61, 0x00, 0x2E, 0x00, 0x74, 0x00, 0x78, 0x00, 0x74, 0x00, 0x07, 0x00, 0x43, 0x00, 0x3A, 0x00, 0x5C, 0x00, 0x74, 0x00, 0x65, 0x00, 0x73, 0x00, 0x74, 0x00, 0x60, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0xA0, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x68, 0x72, 0x69, 0x73, 0x2D, 0x78, 0x70, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x78, 0xC7, 0x94, 0x47, 0xFA, 0xC7, 0x46, 0xB3, 0x56, 0x5C, 0x2D, 0xC6, 0xB6, 0xD1, 0x15, 0xEC, 0x46, 0xCD, 0x7B, 0x22, 0x7F, 0xDD, 0x11, 0x94, 0x99, 0x00, 0x13, 0x72, 0x16, 0x87, 0x4A, 0x40, 0x78, 0xC7, 0x94, 0x47, 0xFA, 0xC7, 0x46, 0xB3, 0x56, 0x5C, 0x2D, 0xC6, 0xB6, 0xD1, 0x15, 0xEC, 0x46, 0xCD, 0x7B, 0x22, 0x7F, 0xDD, 0x11, 0x94, 0x99, 0x00, 0x13, 0x72, 0x16, 0x87, 0x4A, 0x00, 0x00, 0x00, 0x00}) ioutil.WriteFile("testGenbinCompose.lnk", buf.Bytes(), 0777) }
// Algorithm can be found on Windows site : https://support.microsoft.com/en-us/kb/167296 func nowTimeUTCWindows() (result []byte) { seconds := time.Now().Second() longlong := uint64(seconds)*10000000 + 116444736000000000 buf := new(bytes.Buffer) genbin.Compose(buf, longlong) result = buf.Bytes() return }
func Header(head LnkHeader_t) { buf := new(bytes.Buffer) // This is ALWAYS this, don't allow user to change dangerous values nowTime := nowTimeUTCWindows() HeaderSize := [1]uint8{0x4C} LinkCLSID := [16]uint8{00, 02, 0x14, 01, 00, 00, 00, 00, 0xC0, 00, 00, 00, 00, 00, 00, 0x46} Reserved := [10]uint8{0, 0, 0, 0, 0, 0, 0, 0, 0, 0} genbin.Compose(buf, HeaderSize, LinkCLSID, linkFlags(head.LinkFlags), fileAttribute(head.FileAttributes), nowTime, nowTime, nowTime, fileSize(head.Target), head.IconIndex, head.ShowCommand, head.HotKey, Reserved) }