Read Goal Target Using Go

I am trying to read the target file / shortcut file (.lnk) file using Go.

I already have a loop for all the files in the directory, and I can successfully determine if it is a dir with IsDir()or if it is a file IsRegular(). Now I need a way to read if this is a link, and if so .lnk, the path to it so that I can print it.

I could not find a way to do this, and I was looking for SO, but nothing comes. Any idea?

+4
source share
1 answer

You need to read lnk binary format defined by Microsoft

In Go, its structure will be translated (as used in exponential-decay/shortcuts)

//structs that make up the shortcut specification [76 bytes] 
type ShellLinkHeader struct {
   HeaderSize  [4]byte           //HeaderSize
   ClassID     [16]byte          //LinkCLSID
   LinkFlags   uint32            //LinkFlags      [4]byte
   FileAttr    uint32            //FileAttributes [4]byte
   Creation    [8]byte           //CreationTime
   Access      [8]byte           //AccessTime
   Write       [8]byte           //WriteTime
   FileSz      [4]byte           //FileSize
   IconIndex   [4]byte           //IconIndex
   ShowCmd     [4]byte           //ShowCommand

   //[2]byte HotKey values for shortcut shortcuts
   HotKeyLow   byte              //HotKeyLow
   HotKeyHigh  byte              //HotKeyHigh

   Reserved1   [2]byte           //Reserved1
   Reserved2   [4]byte           //Reserved2
   Reserved3   [4]byte           //Reserved3
}

, .

+4

Source: https://habr.com/ru/post/1677877/