-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.cpp
More file actions
128 lines (106 loc) · 3.02 KB
/
Main.cpp
File metadata and controls
128 lines (106 loc) · 3.02 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
/*
gpo2sql
Copyright (c) 2019 aurel26
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <Windows.h>
#include <tchar.h>
#include "gpo2sql.h"
HANDLE g_hHeap;
HANDLE g_hLogFile = NULL;
BOOL g_bSupportsAnsi = FALSE;
GLOBAL_CONFIG g_GlobalConfig = { 0 };
#pragma comment(lib, "msxml6.lib")
#pragma comment(lib, "rpcrt4.lib")
int
wmain (
int argc,
wchar_t *argv[])
{
BOOL bResult;
BOOL bReturn = EXIT_FAILURE;
HRESULT hr;
WCHAR szFindPattern[MAX_PATH];
WIN32_FIND_DATA FindFileData;
HANDLE hFind, hStdOut;
DWORD dwConsoleMode;
LONG lGpoId = 1;
g_hHeap = HeapCreate(0, 0, 0);
if (g_hHeap == NULL)
return EXIT_FAILURE;
hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (hr != S_OK)
return EXIT_FAILURE;
//
// Initialize console
//
hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
// Set console output to 'ISO 8859-1 Latin 1; Western European (ISO)'
SetConsoleOutputCP(28591);
GetConsoleMode(hStdOut, &dwConsoleMode);
g_bSupportsAnsi = SetConsoleMode(hStdOut, dwConsoleMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
SetConsoleTitle(L"gpo2sql");
//
// Read parameters
//
if (argc != 4)
{
Log(
0, LOG_LEVEL_CRITICAL,
L"[!] Wrong number of arguments"
);
Log(
0, LOG_LEVEL_INFORMATION,
L"[.] Usage: gpo2sql <input dir> <output dir> <database name>"
);
goto Fail;
}
else
{
g_GlobalConfig.szDatabaseName = argv[3];
g_GlobalConfig.szInputDirectory = argv[1];
g_GlobalConfig.szOutputDirectory = argv[2];
}
//
// Process
//
bResult = OutputInitialize();
if (bResult == FALSE)
goto End;
swprintf_s(szFindPattern, MAX_PATH, L"%s\\*.xml", g_GlobalConfig.szInputDirectory);
hFind = FindFirstFile(szFindPattern, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
//printf("FindFirstFile failed (%d)\n", GetLastError());
}
else
{
do
{
if ((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
{
TCHAR szFullPath[MAX_PATH];
_stprintf_s(szFullPath, MAX_PATH, TEXT("%s\\%s"), g_GlobalConfig.szInputDirectory, FindFileData.cFileName);
XmlParseFile(&lGpoId, szFullPath);
lGpoId++;
}
} while (FindNextFile(hFind, &FindFileData) != 0);
FindClose(hFind);
}
bReturn = EXIT_SUCCESS;
End:
OutputClose();
Fail:
CoUninitialize();
HeapDestroy(g_hHeap);
return bReturn;
}