MCPcopy Create free account
hub / github.com/BeneficialCode/WinArk / ExportKey

Method ExportKey

WinArk/RegExportImport.cpp:33–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31}
32
33bool RegExportImport::ExportKey(HKEY hKey, HANDLE hFile, PCWSTR section) const {
34 WriteString(hFile, CString(L"[") + section + L"]\n");
35
36 RegistryKey key(hKey, false);
37 Registry::EnumKeyValues(hKey, [&](auto type, auto name, auto size) {
38 CString sname(name);
39 if (sname.IsEmpty())
40 sname = L"@";
41 else
42 sname = L"\"" + sname + L"\"";
43
44 auto data = std::make_unique<BYTE[]>(size + 3);
45 auto count{ size };
46 if (ERROR_SUCCESS != key.QueryValue(name, nullptr, data.get(), &count))
47 return true;
48
49 switch (type)
50 {
51 case REG_DWORD:
52 // c++20 https://www.modernescpp.com/index.php/std-format-in-c-20
53 WriteString(hFile, sname + (L"=dword:" + std::format(L"{:08x}\n", *(DWORD*)data.get())).c_str());
54 break;
55
56 case REG_SZ: {
57 CString text(data.get());
58 text.Replace(L"\"", L"\\\"");
59 WriteString(hFile, sname + L"=\"" + text + L"\"\n");
60 break;
61 }
62
63 case REG_BINARY:
64 WriteString(hFile, sname + L"=hex:" + BytesToString(data.get(), count) + L"\n");
65 break;
66
67 default:
68 WriteString(hFile, sname + std::format(L"=hex({:x}):", type).c_str() +
69 BytesToString(data.get(), count) + L"\n");
70 break;
71 }
72
73 return true;
74 });
75 WriteString(hFile, L"\n");
76 return true;
77}
78
79CString RegExportImport::BytesToString(BYTE const* data, DWORD count) {
80 CString text, chars;

Callers

nothing calls this directly

Calls 3

IsEmptyMethod · 0.80
QueryValueMethod · 0.80
ReplaceMethod · 0.80

Tested by

no test coverage detected