Skip to content
Snippets Groups Projects

서버에 자동으로 제출하도록

Merged Eunhak Lee requested to merge feat/auto-submit into dev
1 file
+ 135
123
Compare changes
  • Side-by-side
  • Inline
@@ -266,6 +266,16 @@ bool validateCode(std::string code) {
return true;
}
IWbemLocator* pLoc = NULL;
IWbemServices* pSvc = NULL, * pSvcStorage = NULL;
int initWQLServices();
size_t crawlParts(const char *queries[], char *buffer, size_t bufferSize) {
size_t written = 0;
return written;
}
int main(int argc, char *argv[]) {
setlocale(LC_ALL, "en_US.UTF-8");
SetConsoleOutputCP(CP_UTF8);
@@ -280,117 +290,13 @@ int main(int argc, char *argv[]) {
bool result = validateCode(code);
curl_global_cleanup();
cout << "Result is " << result << '\n';
return 0;
HRESULT hres;
IWbemLocator* pLoc = NULL;
IWbemServices* pSvc = NULL;
IWbemServices* pSvcStorage = NULL;
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hres)) {
cout << "Failed to initialize COM library. Error code = 0x" << hex << hres << endl;
return 1; // Program has failed.
}
hres = CoInitializeSecurity(
NULL,
-1, // COM authentication
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL // Reserved
);
if (FAILED(hres)) {
cout << "Failed to initialize security."
<< " Error code = 0x" << hex << hres << endl;
CoUninitialize();
return 1; // Program has failed.
}
hres = CoCreateInstance(
CLSID_WbemLocator,
0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID*)&pLoc);
if (FAILED(hres)) {
cout << "Failed to create IWbemLocator object."
<< " Err code = 0x" << hex << hres << endl;
CoUninitialize();
return 1; // Program has failed.
}
hres = pLoc->ConnectServer(
_bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace
NULL, // User name. NULL = current user
NULL, // User password. NULL = current
0, // Locale. NULL indicates current
NULL, // Security flags.
0, // Authority (for example, Kerberos)
0, // Context object
&pSvc // pointer to IWbemServices proxy
);
if (FAILED(hres)) {
cout << "Could not connect. Error code = 0x"
<< hex << hres << endl;
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
hres = pLoc->ConnectServer(
_bstr_t(L"ROOT\\Microsoft\\Windows\\Storage"), // Object path of WMI namespace
NULL, // User name. NULL = current user
NULL, // User password. NULL = current
0, // Locale. NULL indicates current
NULL, // Security flags.
0, // Authority (for example, Kerberos)
0, // Context object
&pSvcStorage // pointer to IWbemServices proxy
);
if (FAILED(hres)) {
cout << "Could not connect. Error code = 0x"
<< hex << hres << endl;
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
int _initRes = initWQLServices();
if (_initRes != 0) {
wcout << L"WQL을 초기화하는데 실패했습니다. 문의를 남겨주시기 바랍니다.\n";
return _initRes;
}
hres = CoSetProxyBlanket(
pSvc, // Indicates the proxy to set
RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx
RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx
NULL, // Server principal name
RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx
RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
NULL, // client identity
EOAC_NONE // proxy capabilities
);
if (FAILED(hres)) {
cout << "Could not set proxy blanket. Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
CoSetProxyBlanket(pSvc, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE);
if (FAILED(hres)) {
cout << "Could not set proxy blanket. Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pSvcStorage->Release();
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
HRESULT hres;
/* const char* QUERIES[] = {
"SELECT Name, Manufacturer, SocketDesignation, NumberOfCores, ThreadCount FROM Win32_Processor",
@@ -418,12 +324,12 @@ int main(int argc, char *argv[]) {
return 1;
}
fprintf(out, "<meanspec version=\"%s\">\n<time>%s</time>\n", VERSION, getDateTimeString());
fprintf(out, "<meanspec version=\"%s\"><time>%s</time>", VERSION, getDateTimeString());
wcout << L"\n데이터를 수집하는 중\n";
for (const char* QUERY : QUERIES) {
fprintf(out, "<search>\n <query>%s</query>\n", QUERY);
fprintf(out, "<search><query>%s</query>", QUERY);
bool isMsft = string(QUERY).find("MSFT") != string::npos;
hres = (isMsft ? pSvcStorage : pSvc)->ExecQuery(bstr_t("WQL"), bstr_t(QUERY), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
@@ -440,13 +346,13 @@ int main(int argc, char *argv[]) {
BSTR* colName = NULL;
WCHAR BUFFER[1024] = { 0 };
fwprintf(out, L" <parts>\n");
fwprintf(out, L"<parts>");
while (pEnumerator) {
hres = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
if (0 == uReturn) break;
fwprintf(out, L" <part>\n");
fwprintf(out, L"<part>");
wstring _gpuNameCandidate = L"";
wstring _gpuDriverVersionCandidate = L"";
@@ -475,8 +381,7 @@ int main(int argc, char *argv[]) {
if (!isSkip && vtProp.bstrVal != nullptr) {
switch (vtProp.vt) {
case VT_BSTR: {
// std::wcout << vtProp.bstrVal << std::endl;
fwprintf(out, L" <%s>%s</%s>\n", bstrName, SafeXML(vtProp.bstrVal).c_str(), bstrName);
fwprintf(out, L"<%s>%s</%s>", bstrName, SafeXML(vtProp.bstrVal).c_str(), bstrName);
if (wcscmp(bstrName, L"Name") == 0) {
_gpuNameCandidate = vtProp.bstrVal;
@@ -488,19 +393,19 @@ int main(int argc, char *argv[]) {
break;
}
case VT_INT: {
fwprintf(out, L" <%s>%d</%s>\n", bstrName, vtProp.intVal, bstrName);
fwprintf(out, L"<%s>%d</%s>", bstrName, vtProp.intVal, bstrName);
break;
}
case VT_I4: {
fwprintf(out, L" <%s>%ld</%s>\n", bstrName, vtProp.lVal, bstrName);
fwprintf(out, L"<%s>%ld</%s>", bstrName, vtProp.lVal, bstrName);
break;
}
case VT_BOOL: {
fwprintf(out, L" <%s>%s</%s>\n", bstrName, ((vtProp.boolVal) ? (L"true") : (L"false")), bstrName);
fwprintf(out, L"<%s>%s</%s>", bstrName, ((vtProp.boolVal) ? (L"true") : (L"false")), bstrName);
break;
}
default: {
fwprintf(out, L" <%s>(Unsupported type=%d)</%s>\n", bstrName, (int)vtProp.vt, bstrName);
fwprintf(out, L"<%s>(Unsupported type=%d)</%s>", bstrName, (int)vtProp.vt, bstrName);
}
}
}
@@ -515,14 +420,13 @@ int main(int argc, char *argv[]) {
if (_gpuNameCandidate.size() > 0 && _gpuDriverVersionCandidate.size() > 0) {
ULONGLONG size = GetGpuMemorySizeByProperties(_gpuNameCandidate, _gpuDriverVersionCandidate);
if (size >= 0) {
fwprintf(out, L" <RegistryVRAMSize>%llu</RegistryVRAMSize>\n", size);
fwprintf(out, L"<RegistryVRAMSize>%llu</RegistryVRAMSize>", size);
}
}
fwprintf(out, L" </part>\n");
fwprintf(out, L"</part>");
}
fwprintf(out, L" </parts>\n</search>\n");
fwprintf(out, L"</parts></search>");
}
// Cleanup
@@ -561,3 +465,111 @@ int main(int argc, char *argv[]) {
return 0;
}
int initWQLServices() {
HRESULT hres;
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hres)) {
cout << "Failed to initialize COM library. Error code = 0x" << hex << hres << endl;
return 1; // Program has failed.
}
hres = CoInitializeSecurity(
NULL,
-1, // COM authentication
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL // Reserved
);
if (FAILED(hres)) {
cout << "Failed to initialize security."
<< " Error code = 0x" << hex << hres << endl;
CoUninitialize();
return 1; // Program has failed.
}
hres = CoCreateInstance(
CLSID_WbemLocator,
0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID*)&pLoc);
if (FAILED(hres)) {
cout << "Failed to create IWbemLocator object."
<< " Err code = 0x" << hex << hres << endl;
CoUninitialize();
return 1; // Program has failed.
}
hres = pLoc->ConnectServer(
_bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace
NULL, // User name. NULL = current user
NULL, // User password. NULL = current
0, // Locale. NULL indicates current
NULL, // Security flags.
0, // Authority (for example, Kerberos)
0, // Context object
&pSvc // pointer to IWbemServices proxy
);
if (FAILED(hres)) {
cout << "Could not connect. Error code = 0x"
<< hex << hres << endl;
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
hres = pLoc->ConnectServer(
_bstr_t(L"ROOT\\Microsoft\\Windows\\Storage"), // Object path of WMI namespace
NULL, // User name. NULL = current user
NULL, // User password. NULL = current
0, // Locale. NULL indicates current
NULL, // Security flags.
0, // Authority (for example, Kerberos)
0, // Context object
&pSvcStorage // pointer to IWbemServices proxy
);
if (FAILED(hres)) {
cout << "Could not connect. Error code = 0x"
<< hex << hres << endl;
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
hres = CoSetProxyBlanket(
pSvc, // Indicates the proxy to set
RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx
RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx
NULL, // Server principal name
RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx
RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
NULL, // client identity
EOAC_NONE // proxy capabilities
);
if (FAILED(hres)) {
cout << "Could not set proxy blanket. Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
CoSetProxyBlanket(pSvc, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE);
if (FAILED(hres)) {
cout << "Could not set proxy blanket. Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pSvcStorage->Release();
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
return 0;
}
Loading