forked from parsiya/golnk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringdata.go
More file actions
executable file
·87 lines (71 loc) · 2.35 KB
/
stringdata.go
File metadata and controls
executable file
·87 lines (71 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package lnk
import (
"io"
)
// Optional StringData - Section 2.4.
// StringDataSection represents section 2.4 of the lnk.
// Fields are mostly optional and present if certain flags are set.
type StringDataSection struct {
// On disk, all these fields have an uint16 size, followed by a string.
// The string is not null-terminated.
// The strings are Unicode if IsUnicode is set in header.
// NameString specifies a description of the shortcut that is displayed to
// end users to identify the purpose of the shell link.
// Present with HasName flag.
NameString string
// RelativePath specifies the location of the link target relative to the
// file that contains the shell link.
// Present with HasRelativePath flag.
RelativePath string
// WorkingDir specifies the file system path of the working directory to
// be used when activating the link target.
// Present with HasWorkingDir flag.
WorkingDir string
// CommandLineArguments stores the command-line arguments of the link target.
// Present with HasArguments flag.
CommandLineArguments string
// IconLocation specifies the location of the icon to be used.
// Present with HasIconLocation flag.
IconLocation string
}
// StringData parses the StringData portion of the lnk.
// flags is the ShellLinkHeader.LinkFlags.
func StringData(r io.Reader, linkFlags FlagMap) (st StringDataSection, err error) {
// Read Unicode strings if is Unicode flag is set.
isUnicode := linkFlags["IsUnicode"]
// Read NameString if HasName flag is set.
if linkFlags["HasName"] {
name, _ := readStringData(r, isUnicode)
// fmt.Println("Name", name)
st.NameString = name
}
// Read NameString if HasName flag is set.
if linkFlags["HasRelativePath"] {
st.RelativePath, err = readStringData(r, isUnicode)
if err != nil {
return st, err
}
}
// Read WorkingDir if HasWorkingDir flag is set.
if linkFlags["HasWorkingDir"] {
st.WorkingDir, err = readStringData(r, isUnicode)
if err != nil {
return st, err
}
}
// Read CommandLineArguments if HasArguments flag is set.
if linkFlags["HasArguments"] {
st.CommandLineArguments, err = readStringData(r, isUnicode)
if err != nil {
return st, err
}
}
// Read IconLocation if HasIconLocation flag is set.
if linkFlags["HasIconLocation"] {
st.IconLocation, err = readStringData(r, isUnicode)
if err != nil {
return st, err
}
}
return st, err
}