strayge / pylnk

Python library for reading and writing Windows shortcut files (.lnk). Python 3 only.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

issue with Fax Recipient.lnk

micprz opened this issue · comments

One of LNK file under SendTo folder does not contain path in expected location.
I have found it only in Extra Data segment.

>>> lnk4 = pylnk3.Lnk(r'c:\Users\heznik\AppData\Roaming\Microsoft\Windows\SendTo\Fax Recipient.lnk')
>>> lnk4.path
>>> lnk4.link_info.path
>>> lnk4.relative_path
'..\\..\\..\\..\\..\\..\\..\\Windows\\System32\\WFS.exe'
>>> print(lnk4)
Target file:
{ 'archive': True,
  'compressed': False,
  'directory': False,
  'encrypted': False,
  'hidden': False,
  'normal': False,
  'not_content_indexed': False,
  'offline': False,
  'read_only': False,
  'reparse_point': False,
  'reserved1': False,
  'reserved2': False,
  'sparse_file': False,
  'system_file': False,
  'temporary': False}
Creation Time: 2009-07-14 02:36:26.369370
Modification Time: 2009-07-14 03:39:52.134001
Access Time: 2009-07-14 02:36:26.369370
File size: 974336
Window mode: Normal
Hotkey:
File Location Info: <not specified>
Description: @%windir%\system32\FXSRESM.dll,-121
Relative Path: ..\..\..\..\..\..\..\Windows\System32\WFS.exe
Commandline Arguments: /SendTo
Icon: %windir%\system32\WFSR.dll
Used Path: None
PropertyStoreDataBlock
 PropertyStore
  FormatID: {46588AE2-4CBC-4338-BBFC-139326986DCE}
EnvironmentVariableDataBlock
 TargetAnsi: %windir%\system32\WFS.exe
 TargetUnicode: %windir%\system32\WFS.exe
ExtraDataBlock
 signature 0xa0000003
 data: b'X\x00\x00\x00\x00\x00\x00\x00win-tj9qcsjkags\x00\xda\xcbLI\xe8\x98\xc8E\xb8\xca\xf6MFCf\xc7\xac\xe3n\x849p\xde\x11\x9d \x00\x1d\t\xfaZ\x1c\xda\xcbLI\xe8\x98\xc8E\xb8\xca\xf6MFCf\xc7\xac\xe3n\x849p\xde\x11\x9d \x00\x1d\t\xfaZ\x1c'

I was able to bypass it with following code:

            if not lnk.path:
                for bloc in lnk.extra_data.blocks:
                    if type(bloc) is pylnk3.ExtraData_EnvironmentVariableDataBlock:
                        # in my case it contains env var %windir%
                        fo.lnk_target = os.path.expandvars (bloc.target_unicode.replace ('\x00', ''))
            else:
                fo.lnk_target = os.path.expandvars (lnk.path)

you right, explorer shows path from EnvironmentVariableDataBlock -> TargetUnicode
thanks for report.
i'll fix this.

fixed: 24866d6

feel free to reopen if i missed something