I am trying to read the LNK file not the target of the shortcut. The following PowerShell code reads the target of the shortcut into the variable rather than the shortcut file itself.
Here is the code that I used to create the LNK:
New-Item -ItemType SymbolicLink -Path $env:USERPROFILE\Desktop -Name "test.lnk" -Value "C:\Windows\System32\alg.exe"
Here is the code to read the LNK:
$file_data = Get-Content -Encoding Byte $env:USERPROFILE\Desktop\test.lnk
$encoded = [System.Convert]::ToBase64String($file_data)
Here is the contents of the variable $encoded
PS C:\Users\Administrator> $encoded
TVqQAAMAAAA
I have truncated the content here, but TVqQAAMAAAA
is base64 for the first bytes of a Windows PE file: MZ.....
.
Here is the contents of the variable $file_data
:
PS C:\Users\Administrator> $file_data
77
90
144
I have truncated this, but 77 90
is enough to see that this is MZ
which is the magic bytes for a PE executable that is the target of the LNK not the LNK itself.
The first characters of the resulting data should be TAAAAAEUA
in base64 or 76 0 0 0 1 20 2 0
in integers if this has read what I need. These are the magic bytes for a LNK file.
How do I read the bytes of the shortcut itself into the variable?