-
Notifications
You must be signed in to change notification settings - Fork 0
/
refguid.cpp
823 lines (694 loc) · 19.2 KB
/
refguid.cpp
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
// refguid - Generating/Converting/Searching GUIDs
// License: MIT
#include <windows.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <initguid.h>
#include <string>
#include <vector>
#include <cstdio>
#include <cassert>
#include <cctype>
#include <cwchar>
#include <strsafe.h>
BOOL g_bSearch = FALSE;
BOOL g_bList = FALSE;
INT g_nGenerate = 0;
void show_version(void)
{
std::puts("refguid version 1.9.1 by katahiromz");
}
void usage(void)
{
std::printf(
"Usage:\n"
" refguid --search \"STRING\"\n"
" refguid IID_IDeskBand\n"
" refguid \"{EB0FE172-1A3A-11D0-89B3-00A0C90A90AC}\"\n"
" refguid \"72 E1 0F EB 3A 1A D0 11 89 B3 00 A0 C9 0A 90 AC\"\n"
" refguid \"{ 0xEB0FE172, 0x1A3A, 0x11D0, { 0x89, 0xB3, 0x00, 0xA0, 0xC9, 0x0A,\n"
" 0x90, 0xAC } }\"\n"
" refguid \"DEFINE_GUID(IID_IDeskBand, 0xEB0FE172, 0x1A3A, 0x11D0, 0x89, 0xB3,\n"
" 0x00, 0xA0, 0xC9, 0x0A, 0x90, 0xAC);\"\n"
" refguid --list\n"
" refguid --generate NUMBER\n"
" refguid --help\n"
" refguid --version\n"
"\n"
"You can specify multiple GUIDs.\n");
}
typedef enum RET
{
RET_DONE = 0,
RET_FAILED = -1,
RET_SUCCESS = +1,
} RET;
typedef struct tagENTRY
{
std::wstring name;
GUID guid;
} ENTRY, *PENTRY;
typedef std::vector<ENTRY> ENTRIES;
template <typename T_CHAR>
inline void mstr_trim(std::basic_string<T_CHAR>& str, const T_CHAR* spaces)
{
typedef std::basic_string<T_CHAR> string_type;
size_t i = str.find_first_not_of(spaces);
size_t j = str.find_last_not_of(spaces);
if ((i == string_type::npos) || (j == string_type::npos))
{
str.clear();
}
else
{
str = str.substr(i, j - i + 1);
}
}
template <typename T_STR>
inline bool
mstr_replace_all(T_STR& str, const T_STR& from, const T_STR& to)
{
bool ret = false;
size_t i = 0;
for (;;) {
i = str.find(from, i);
if (i == T_STR::npos)
break;
ret = true;
str.replace(i, from.size(), to);
i += to.size();
}
return ret;
}
template <typename T_STR>
inline bool
mstr_replace_all(T_STR& str,
const typename T_STR::value_type *from,
const typename T_STR::value_type *to)
{
return mstr_replace_all(str, T_STR(from), T_STR(to));
}
template <typename T_STR_CONTAINER>
inline void
mstr_split(T_STR_CONTAINER& container,
const typename T_STR_CONTAINER::value_type& str,
const typename T_STR_CONTAINER::value_type& chars)
{
container.clear();
size_t i = 0, k = str.find_first_of(chars);
while (k != T_STR_CONTAINER::value_type::npos)
{
container.push_back(str.substr(i, k - i));
i = k + 1;
k = str.find_first_of(chars, i);
}
container.push_back(str.substr(i));
}
std::wstring getBytesTextFromGUID(REFCLSID clsid)
{
std::wstring ret;
const BYTE *pb = (LPBYTE)&clsid;
for (size_t ib = 0; ib < sizeof(clsid); ++ib)
{
if (ib)
ret += L' ';
WCHAR sz[3];
StringCchPrintfW(sz, _countof(sz), L"%02X", pb[ib]);
ret += sz;
}
return ret;
}
BOOL getGUIDFromStructStr(GUID& guid, std::wstring str)
{
mstr_trim(str, L" \t\r\n");
if (str.size() && str[str.size() - 1] == L';')
str.erase(str.size() - 1, 1);
mstr_trim(str, L" \t\r\n");
if (str.size() && str[0] == L'{')
str.erase(0, 1);
else
return FALSE;
mstr_trim(str, L" \t\r\n");
if (str.size() && str[str.size() - 1] == L'}')
str.erase(str.size() - 1, 1);
else
return FALSE;
mstr_trim(str, L" \t\r\n");
if (str.size() && str[str.size() - 1] == L'}')
str.erase(str.size() - 1, 1);
else
return FALSE;
mstr_replace_all(str, L" ", L"");
mstr_replace_all(str, L"\t", L"");
auto ich0 = str.find(L',');
if (ich0 != str.npos)
{
auto ich1 = str.find(L',', ich0 + 1);
if (ich1 != str.npos)
{
auto ich2 = str.find(L',', ich1 + 1);
if (ich2 == str.npos || str[ich2 + 1] != L'{')
return FALSE;
str.erase(ich2 + 1, 1);
}
else
{
return FALSE;
}
}
else
{
return FALSE;
}
std::vector<std::wstring> items;
mstr_split(items, str, L",");
if (items.size() != 11)
return FALSE;
for (auto& item : items)
{
mstr_trim(item, L" \t");
}
guid.Data1 = wcstoul(items[0].c_str(), NULL, 0);
guid.Data2 = (USHORT)wcstoul(items[1].c_str(), NULL, 0);
guid.Data3 = (USHORT)wcstoul(items[2].c_str(), NULL, 0);
guid.Data4[0] = (BYTE)wcstoul(items[3].c_str(), NULL, 0);
guid.Data4[1] = (BYTE)wcstoul(items[4].c_str(), NULL, 0);
guid.Data4[2] = (BYTE)wcstoul(items[5].c_str(), NULL, 0);
guid.Data4[3] = (BYTE)wcstoul(items[6].c_str(), NULL, 0);
guid.Data4[4] = (BYTE)wcstoul(items[7].c_str(), NULL, 0);
guid.Data4[5] = (BYTE)wcstoul(items[8].c_str(), NULL, 0);
guid.Data4[6] = (BYTE)wcstoul(items[9].c_str(), NULL, 0);
guid.Data4[7] = (BYTE)wcstoul(items[10].c_str(), NULL, 0);
return TRUE;
}
BOOL getGUIDFromDefineGUID(GUID& guid, std::wstring str, std::wstring *pstrName = NULL)
{
mstr_trim(str, L" \t\r\n");
if (str.find(L"DEFINE_GUID") == 0)
str.erase(0, 11);
else
return FALSE;
mstr_trim(str, L" \t\r\n");
if (str.size() && str[0] == L'(')
str.erase(0, 1);
else
return FALSE;
mstr_trim(str, L" \t\r\n");
if (str.size() && str[str.size() - 1] == L';')
str.erase(str.size() - 1, 1);
mstr_trim(str, L" \t\r\n");
if (str.size() && str[str.size() - 1] == L')')
str.erase(str.size() - 1, 1);
else
return FALSE;
mstr_trim(str, L" \t\r\n");
mstr_replace_all(str, L" ", L"");
mstr_replace_all(str, L"\t", L"");
std::vector<std::wstring> items;
mstr_split(items, str, L",");
if (items.size() != 12)
return FALSE;
for (auto& item : items)
{
mstr_trim(item, L" \t");
}
if (pstrName)
*pstrName = items[0];
guid.Data1 = wcstoul(items[1].c_str(), NULL, 0);
guid.Data2 = (USHORT)wcstoul(items[2].c_str(), NULL, 0);
guid.Data3 = (USHORT)wcstoul(items[3].c_str(), NULL, 0);
guid.Data4[0] = (BYTE)wcstoul(items[4].c_str(), NULL, 0);
guid.Data4[1] = (BYTE)wcstoul(items[5].c_str(), NULL, 0);
guid.Data4[2] = (BYTE)wcstoul(items[6].c_str(), NULL, 0);
guid.Data4[3] = (BYTE)wcstoul(items[7].c_str(), NULL, 0);
guid.Data4[4] = (BYTE)wcstoul(items[8].c_str(), NULL, 0);
guid.Data4[5] = (BYTE)wcstoul(items[9].c_str(), NULL, 0);
guid.Data4[6] = (BYTE)wcstoul(items[10].c_str(), NULL, 0);
guid.Data4[7] = (BYTE)wcstoul(items[11].c_str(), NULL, 0);
return TRUE;
}
BOOL getGUIDFromBytesText(GUID& guid, std::wstring str)
{
mstr_replace_all(str, L"0x", L"");
CLSID ret;
std::vector<BYTE> bytes;
WCHAR sz[3];
size_t ich = 0, ib = 0;
for (auto ch : str)
{
if (!iswxdigit(ch))
continue;
if ((ich % 2) == 0)
{
sz[0] = ch;
}
else
{
sz[1] = ch;
sz[2] = 0;
BYTE byte = (BYTE)wcstoul(sz, NULL, 16);
bytes.push_back(byte);
ib++;
}
ich++;
}
if (ib != sizeof(CLSID))
return FALSE;
CopyMemory(&guid, bytes.data(), sizeof(ret));
return TRUE;
}
std::wstring getDefineGUIDFromGUID(REFGUID guid, LPCWSTR name)
{
WCHAR sz[256];
StringCchPrintfW(sz, _countof(sz),
L"DEFINE_GUID(%ls, 0x%08X, 0x%04X, 0x%04X, 0x%02X, 0x%02X, 0x%02X, "
L"0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X);", (name && name[0] ? name : L"<Name>"),
guid.Data1, guid.Data2, guid.Data3,
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
return sz;
}
std::wstring getStructFromGUID(REFGUID guid)
{
WCHAR sz[256];
StringCchPrintfW(sz, _countof(sz),
L"{ 0x%08X, 0x%04X, 0x%04X, { 0x%02X, 0x%02X, 0x%02X, "
L"0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X } }",
guid.Data1, guid.Data2, guid.Data3,
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
return sz;
}
std::wstring getDumpFromGUID(REFGUID guid, LPCWSTR name)
{
if (name && name[0] == 0)
name = NULL;
std::wstring ret;
auto define_guid = getDefineGUIDFromGUID(guid, name);
ret += define_guid;
ret += L"\n\n";
WCHAR szGUID[40];
StringFromGUID2(guid, szGUID, _countof(szGUID));
ret += L"GUID: ";
ret += szGUID;
ret += L"\n\n";
auto strBytes = getBytesTextFromGUID(guid);
ret += L"Bytes: ";
ret += strBytes;
ret += L"\n\n";
auto struct_str = getStructFromGUID(guid);
ret += L"Struct: ";
ret += struct_str;
ret += L"\n";
return ret;
}
template <typename T_DATA>
void RandomData(T_DATA& data)
{
std::srand(::GetTickCount());
LPBYTE pb = (LPBYTE)&data;
for (size_t ib = 0; ib < sizeof(data); ++ib)
{
pb[ib] = BYTE(std::rand());
}
}
BOOL readGUIDs(ENTRIES& entries)
{
WCHAR szPath[MAX_PATH];
GetModuleFileNameW(NULL, szPath, _countof(szPath));
PathRemoveFileSpecW(szPath);
PathAppendW(szPath, L"refguid.dat");
FILE *fp = _wfopen(szPath, L"r");
if (!fp)
{
fprintf(stderr, "WARNING: Cannot read file %ls\n", szPath);
return FALSE;
}
CHAR buf[1024];
WCHAR szLine[1024];
while (fgets(buf, sizeof(buf), fp))
{
std::string str = buf;
mstr_trim(str, " \t\r\n");
MultiByteToWideChar(CP_ACP, 0, buf, -1, szLine, _countof(szLine));
szLine[_countof(szLine) - 1] = 0;
GUID guid;
std::wstring name;
if (getGUIDFromDefineGUID(guid, szLine, &name))
{
ENTRY entry = { name, guid };
entries.push_back(entry);
}
}
fclose(fp);
return TRUE;
}
BOOL getEntryByName(ENTRY& found, const ENTRIES& entries, std::wstring name)
{
::CharUpperW(&name[0]);
for (auto& entry : entries)
{
std::wstring entry_name = entry.name;
::CharUpperW(&entry_name[0]);
if (lstrcmpiW(entry_name.c_str(), name.c_str()) == 0)
{
found = entry;
return TRUE;
}
}
return FALSE;
}
BOOL getEntriesByGuid(ENTRIES& got, const ENTRIES& entries, const GUID& guid)
{
for (auto& entry : entries)
{
if (IsEqualGUID(entry.guid, guid))
{
got.push_back(entry);
}
}
return !got.empty();
}
BOOL getEntriesByString(ENTRIES& found, const ENTRIES& entries, std::wstring text)
{
::CharUpperW(&text[0]);
for (auto& entry : entries)
{
auto str = getDefineGUIDFromGUID(entry.guid, entry.name.c_str());
::CharUpperW(&str[0]);
if (str.find(text) != str.npos)
{
found.push_back(entry);
continue;
}
str = getBytesTextFromGUID(entry.guid);
::CharUpperW(&str[0]);
if (str.find(text) != str.npos)
{
found.push_back(entry);
continue;
}
}
return !found.empty();
}
BOOL isHexGuid(std::wstring str)
{
mstr_trim(str, L" \t\r\n");
mstr_replace_all(str, L"0x", L"");
mstr_replace_all(str, L",", L"");
mstr_replace_all(str, L" ", L"");
mstr_replace_all(str, L"\t", L"");
if (str.size() != 32)
return FALSE;
for (auto& ch : str)
{
if (!iswxdigit(ch))
return FALSE;
}
return TRUE;
}
BOOL isGUIDString(LPCWSTR pszGUID)
{
GUID guid;
return CLSIDFromString(pszGUID, &guid) == S_OK;
}
BOOL isGUIDStruct(LPCWSTR pszGUID)
{
GUID guid;
return getGUIDFromStructStr(guid, pszGUID);
}
BOOL isDefineGUID(LPCWSTR pszGUID)
{
GUID guid;
return getGUIDFromDefineGUID(guid, pszGUID, NULL);
}
void refguid_unittest(void)
{
#ifndef NDEBUG
GUID guid = IID_IShellLinkW;
ENTRIES entries;
assert(readGUIDs(entries));
ENTRY entry;
assert(getEntryByName(entry, entries, L"IID_IShellLinkW"));
assert(entry.name == L"IID_IShellLinkW");
assert(IsEqualGUID(entry.guid, IID_IShellLinkW));
ENTRIES got;
assert(getEntriesByGuid(got, entries, guid));
assert(got.size() > 1);
assert(got[0].name == L"IID_IShellLinkW");
assert(IsEqualGUID(got[0].guid, IID_IShellLinkW));
auto define_guid = getDefineGUIDFromGUID(guid, NULL);
assert(define_guid ==
L"DEFINE_GUID(<Name>, 0x000214F9, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);");
assert(isDefineGUID(define_guid.c_str()));
WCHAR szGUID[40];
StringFromGUID2(guid, szGUID, _countof(szGUID));
std::wstring str = L"{000214F9-0000-0000-C000-000000000046}";
assert(str == szGUID);
assert(isGUIDString(str.c_str());
auto strBytes = getBytesTextFromGUID(guid);
assert(strBytes == L"F9 14 02 00 00 00 00 00 C0 00 00 00 00 00 00 46");
assert(isHexGuid(str.c_str());
auto struct_str = getStructFromGUID(guid);
assert(struct_str == L"{ 0x000214F9, 0x0000, 0x0000, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } }");
assert(isGUIDStruct(str.c_str());
std::fprintf(stderr, "refguid_unittest: Success!\n\n");
#endif
}
RET refguid_do_guid(const ENTRIES& entries, REFGUID guid, std::wstring *pstrName = NULL)
{
std::printf("\n--------------------\n");
std::wstring name;
if (pstrName == NULL)
{
BOOL found = FALSE;
for (auto& entry : entries)
{
if (IsEqualGUID(guid, entry.guid))
{
found = TRUE;
name = entry.name;
std::printf("Name: %ls\n", name.c_str());
}
}
if (found)
{
std::printf("\n");
pstrName = &name;
}
}
auto str = getDumpFromGUID(guid, (pstrName ? pstrName->c_str() : NULL));
std::printf("%ls", str.c_str());
name = name;
return RET_SUCCESS;
}
RET refguid_do_arg(const ENTRIES& entries, std::wstring str)
{
mstr_trim(str, L" \t\r\n");
if (isGUIDString(str.c_str()))
{
GUID guid;
if (CLSIDFromString(str.c_str(), &guid) == S_OK)
return refguid_do_guid(entries, guid);
return RET_FAILED;
}
if (isGUIDStruct(str.c_str()))
{
GUID guid;
if (getGUIDFromStructStr(guid, str))
return refguid_do_guid(entries, guid);
return RET_FAILED;
}
if (isDefineGUID(str.c_str()))
{
GUID guid;
std::wstring name;
if (getGUIDFromDefineGUID(guid, str, &name))
return refguid_do_guid(entries, guid, &name);
return RET_FAILED;
}
if (isHexGuid(str))
{
GUID guid;
if (getGUIDFromBytesText(guid, str))
return refguid_do_guid(entries, guid);
return RET_FAILED;
}
if (!g_bSearch)
{
ENTRY entry;
if (getEntryByName(entry, entries, str))
return refguid_do_guid(entries, entry.guid, &entry.name);
}
ENTRIES found;
if (getEntriesByString(found, entries, str))
{
if (found.size() == 1)
return refguid_do_guid(entries, found[0].guid, &found[0].name);
}
else
{
std::printf("Not found\n");
return RET_FAILED;
}
if (found.size() > 1)
{
std::printf("Found %d entries.\n", (int)found.size());
}
for (auto& item : found)
{
refguid_do_guid(entries, item.guid, &item.name);
}
return RET_SUCCESS;
}
RET parse_option(std::wstring str)
{
if (str == L"--help")
{
usage();
return RET_DONE;
}
if (str == L"--version")
{
show_version();
return RET_DONE;
}
if (str == L"--list")
{
g_bList = TRUE;
return RET_SUCCESS;
}
if (str == L"--search")
{
g_bSearch = TRUE;
return RET_SUCCESS;
}
fprintf(stderr, "Invalid option: %ls\n", str.c_str());
return RET_FAILED;
}
BOOL IsIdentifier(LPCWSTR pszParam)
{
if (pszParam[0] == 0)
return FALSE;
for (size_t ich = 0; pszParam[ich]; ++ich)
{
WCHAR ch = pszParam[ich];
if (ich == 0 && !iswalpha(ch) && ch != L'_')
return FALSE;
if (ich > 0 && !iswalnum(ch) && ch != L'_')
return FALSE;
}
return TRUE;
}
RET parse_cmd_line(std::vector<std::wstring>& args, int argc, wchar_t **argv)
{
if (argc <= 1)
{
usage();
return RET_FAILED;
}
std::wstring param;
for (int iarg = 1; iarg < argc; ++iarg)
{
std::wstring str = argv[iarg];
if (str[0] == L'-')
{
if (str == L"--generate")
{
if (argc <= iarg + 1)
g_nGenerate = 1;
else
g_nGenerate = _wtoi(argv[iarg + 1]);
if (g_nGenerate <= 0)
{
fprintf(stderr, "ERROR: Zero or negative value specified for '--generate'\n");
return RET_FAILED;
}
param.clear();
args.clear();
return RET_SUCCESS;
}
switch (parse_option(str))
{
case RET_FAILED:
return RET_FAILED;
case RET_DONE:
return RET_DONE;
case RET_SUCCESS:
continue;
}
}
if (param.size())
param += L' ';
param += str;
if (isGUIDString(param.c_str()) || isGUIDStruct(param.c_str()) ||
isDefineGUID(param.c_str()) || isHexGuid(param.c_str()))
{
args.push_back(param);
param.clear();
continue;
}
if (IsIdentifier(param.c_str()) && param != L"DEFINE_GUID")
{
args.push_back(param);
param.clear();
continue;
}
}
if (param.size())
args.push_back(param);
return RET_SUCCESS;
}
int _wmain(int argc, wchar_t **argv)
{
#ifndef NDEBUG
refguid_unittest();
#endif
std::vector<std::wstring> args;
RET ret = parse_cmd_line(args, argc, argv);
if (ret == RET_DONE)
return 0;
if (ret == RET_FAILED)
return -1;
ENTRIES entries;
if (!readGUIDs(entries))
return -2;
if (entries.empty() && !g_bList && g_nGenerate == 0)
{
std::printf("ERROR: File refguid.dat was empty\n");
return -3;
}
if (g_bList)
{
for (auto& entry : entries)
{
auto define_guid = getDefineGUIDFromGUID(entry.guid, entry.name.c_str());
std::printf("%ls\n", define_guid.c_str());
}
return 0;
}
if (g_nGenerate > 0)
{
for (INT i = 0; i < g_nGenerate; ++i)
{
GUID guid;
RandomData(guid);
refguid_do_guid(entries, guid);
}
return 0;
}
for (auto& item : args)
{
if (refguid_do_arg(entries, item) == RET_FAILED)
return -4;
}
return 0;
}
int main(void)
{
INT argc;
LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc);
INT ret = _wmain(argc, argv);
LocalFree(argv);
return ret;
}