-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlooklink.cpp
More file actions
184 lines (178 loc) · 6.08 KB
/
Copy pathlooklink.cpp
File metadata and controls
184 lines (178 loc) · 6.08 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
///////////////////////////////////////////////////////////////////////////////
///
/// Written 2009-2013, Oliver Schneider (assarbad.net) - PUBLIC DOMAIN/CC0
///
/// Original filename: looklink.cpp
/// Project : looklink
/// Date of creation : 2009-02-03
/// Author(s) : Oliver Schneider
///
/// Purpose : Program to investigate all kinds of reparse points on
/// Windows 2000 and later.
///
///////////////////////////////////////////////////////////////////////////////
#include <cstdio>
#ifdef _DEBUG
# include <crtdbg.h>
#endif // _DEBUG
#include <tchar.h>
#include "looklink.h"
#include "VersionInfo.hpp"
namespace
{
BOOL isCommandLineSwitch(_TCHAR* arg, const _TCHAR* switchName = NULL)
{
if (arg && wcslen(arg) > 2 && arg[0] == L'-' && arg[1] == L'-')
{
if (!switchName)
{
return TRUE;
}
if (0 == wcscmp(&arg[2], switchName))
{
return TRUE;
}
}
return FALSE;
}
HMODULE GetInstanceHandle()
{
MEMORY_BASIC_INFORMATION mbi;
static int iDummy;
::VirtualQuery(&iDummy, &mbi, sizeof(mbi));
return HMODULE(mbi.AllocationBase);
}
} // namespace
LPCTSTR getReparseType(const CReparsePoint& rp)
{
if (!rp.isReparsePoint())
return _T("");
switch (rp.ReparseTag())
{
case IO_REPARSE_TAG_MOUNT_POINT:
return _T("volume mount point");
case IO_REPARSE_TAG_HSM:
return _T("HSM reparse point");
case IO_REPARSE_TAG_HSM2:
return _T("HSM2 reparse point");
case IO_REPARSE_TAG_SIS:
return _T("SIS reparse point");
case IO_REPARSE_TAG_WIM:
return _T("WIM reparse point");
case IO_REPARSE_TAG_CSV:
return _T("CSV reparse point");
case IO_REPARSE_TAG_DFS:
return _T("DFS reparse point");
case IO_REPARSE_TAG_SYMLINK:
return _T("symbolic link");
case IO_REPARSE_TAG_DFSR:
return _T("DFSR reparse point");
case IO_REPARSE_TAG_DEDUP:
return _T("DEDUP reparse point");
case IO_REPARSE_TAG_NFS:
return _T("NFS reparse point");
case IO_REPARSE_TAG_FILE_PLACEHOLDER:
return _T("placeholder file");
default:
return _T("reparse point");
}
}
int __cdecl _tmain(int argc, _TCHAR* argv[])
{
#ifdef _DEBUG
_CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_ALLOC_MEM_DF);
#endif // _DEBUG
if (2 <= argc)
{
bool show_logo = true, be_verbose = false, noerror = false;
int fname_arg = 1;
while (isCommandLineSwitch(argv[fname_arg]))
{
if (isCommandLineSwitch(argv[fname_arg], L"nologo"))
show_logo = false;
else if (isCommandLineSwitch(argv[fname_arg], L"verbose"))
be_verbose = true;
else if (isCommandLineSwitch(argv[fname_arg], L"noerror"))
noerror = true;
fname_arg++;
}
if (show_logo)
{
CVersionInfo verinfo(GetInstanceHandle());
_tprintf(_T("%s %s written by %s\n"), verinfo[_T("OriginalFilename")], verinfo[_T("FileVersion")], verinfo[_T("CompanyName")]);
#ifdef HG_REV_ID
_tprintf(_T("\tRevision: %s\n"), verinfo[_T("Mercurial revision")]);
#endif
_tprintf(_T("\n"));
}
CReparsePoint rp(argv[fname_arg]);
if (ERROR_SUCCESS != rp.LastError())
{
_ftprintf(stderr, _T("ERROR: Win32 error code %d. Probably file (2) or path (3) not found or access issue (5)?!\n"), rp.LastError());
return 3;
}
if (rp.isReparsePoint())
{
_tprintf(
_T("'%ws' is a %sMicrosoft %s (virt == %d)\n"), rp.Path(), ((rp.isMicrosoftTag()) ? _T("") : _T("non-")), getReparseType(rp), rp.isVirtual());
if (be_verbose)
{
#ifdef RP_QUERY_FILE_ID
if (-1 != rp.FileIndex())
{
_tprintf(_T("\tFile Index: %I64u (%08X%08X)\n"), rp.FileIndex(), rp.FileIndexHigh(), rp.FileIndexLow());
}
#endif // RP_QUERY_FILE_ID
}
if (rp.isNameSurrogate())
{
_tprintf(_T("\tPrint name: %ws\n"), rp.PrintName());
_tprintf(_T("\tSubst name: %ws\n"), rp.SubstName());
_tprintf(_T("\tSubst name: %ws (w32)\n"), rp.CanonicalSubstName());
}
if (!rp.isMicrosoftTag() || be_verbose)
{
if (be_verbose)
{
_tprintf(_T("\tTag : %08X\n"), rp.ReparseTag());
}
GUID const& rpguid = rp.ReparseGuid();
_tprintf(_T("\tGUID : {%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n"),
rpguid.Data1,
rpguid.Data2,
rpguid.Data3,
rpguid.Data4[0],
rpguid.Data4[1],
rpguid.Data4[2],
rpguid.Data4[3],
rpguid.Data4[4],
rpguid.Data4[5],
rpguid.Data4[6],
rpguid.Data4[7]);
}
}
else
{
if (!noerror) // show no errors if asked not to
{
_ftprintf(stderr, _T("ERROR: '%ws' is not a reparse point\n"), rp.Path());
}
if (be_verbose)
{
#ifdef RP_QUERY_FILE_ID
if (-1 != rp.FileIndex())
{
_ftprintf(stderr, _T("\tFile Index: %I64u (%08X%08X)\n"), rp.FileIndex(), rp.FileIndexHigh(), rp.FileIndexLow());
}
#endif // RP_QUERY_FILE_ID
}
return 2;
}
return 0;
}
else
{
_ftprintf(stderr, _T("Syntax:\n\tlooklink [--nologo] [--verbose] [--noerror] <path>\n"));
}
return 1;
}