2415
|
1 #define _CRTDBG_MAP_ALLOC
|
|
2 #include <stdlib.h>
|
|
3 #include <crtdbg.h>
|
|
4
|
2342
|
5 #define _CRT_SECURE_NO_WARNINGS
|
|
6 #include <stdio.h>
|
|
7 #include <array>
|
|
8 #include <windows.h>
|
|
9
|
|
10 #include "Registry.h"
|
2427
|
11 #include "ErrorHandling.h"
|
2342
|
12
|
|
13 //----- (004649EF) --------------------------------------------------------
|
|
14 int __fastcall ReadWindowsRegistryInt(const char *pKey, int uDefValue)
|
|
15 {
|
|
16 DWORD cbData; // [sp+8h] [bp-20h]@1
|
|
17 LPCSTR lpValueName; // [sp+Ch] [bp-1Ch]@1
|
|
18 DWORD dwDisposition; // [sp+10h] [bp-18h]@2
|
|
19 BYTE Data[4]; // [sp+14h] [bp-14h]@5
|
|
20 HKEY hKey; // [sp+18h] [bp-10h]@1
|
|
21 HKEY phkResult; // [sp+1Ch] [bp-Ch]@1
|
|
22 HKEY v10; // [sp+20h] [bp-8h]@1
|
|
23 HKEY v11; // [sp+24h] [bp-4h]@1
|
|
24
|
|
25 lpValueName = pKey;
|
|
26 v11 = 0;
|
|
27 v10 = 0;
|
|
28 hKey = 0;
|
|
29 phkResult = 0;
|
|
30 cbData = 4;
|
|
31 if ( !RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ|KEY_WOW64_32KEY, &hKey) )// for 64 bit
|
|
32 {
|
|
33 if ( !RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, 0xF003Fu, 0, &phkResult, &dwDisposition) )
|
|
34 {
|
|
35 if ( !RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, 0xF003Fu, 0, &v10, &dwDisposition) )
|
|
36 {
|
|
37 if ( !RegCreateKeyExA(v10, "1.0", 0, "", 0, 0xF003Fu, 0, &v11, &dwDisposition) )
|
|
38 {
|
2427
|
39 LSTATUS status;
|
|
40 if ( status = RegQueryValueExA(v11, lpValueName, 0, 0, Data, &cbData) )
|
2342
|
41 {
|
2427
|
42 status;
|
|
43 GetLastError();
|
|
44
|
|
45 *(int *)Data = uDefValue;
|
2459
|
46 RegSetValueExA(v11, lpValueName, 0, 4, Data, 4);
|
2342
|
47 }
|
|
48 RegCloseKey(v11);
|
|
49 }
|
|
50 RegCloseKey(v10);
|
|
51 }
|
|
52 RegCloseKey(phkResult);
|
|
53 }
|
|
54 RegCloseKey(hKey);
|
|
55 }
|
|
56 return *(int *)Data;
|
|
57 }
|
|
58
|
|
59 //----- (00464B02) --------------------------------------------------------
|
|
60 void __fastcall WriteWindowsRegistryString(const char *pKey, const char *pString)
|
|
61 {
|
|
62 size_t v2; // eax@5
|
|
63 const char *lpValueName; // [sp+4h] [bp-1Ch]@1
|
|
64 const char *Str; // [sp+8h] [bp-18h]@1
|
|
65 DWORD dwDisposition; // [sp+Ch] [bp-14h]@2
|
|
66 HKEY hKey; // [sp+10h] [bp-10h]@1
|
|
67 HKEY phkResult; // [sp+14h] [bp-Ch]@1
|
|
68 HKEY v8; // [sp+18h] [bp-8h]@1
|
|
69 HKEY v9; // [sp+1Ch] [bp-4h]@1
|
|
70
|
|
71 Str = pString;
|
|
72 lpValueName = pKey;
|
|
73 v9 = 0;
|
|
74 v8 = 0;
|
|
75 hKey = 0;
|
|
76 phkResult = 0;
|
|
77 if ( !RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, 0x2001Fu, &hKey) )
|
|
78 {
|
|
79 if ( !RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, 0xF003Fu, 0, &phkResult, &dwDisposition) )
|
|
80 {
|
|
81 if ( !RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, 0xF003Fu, 0, &v8, &dwDisposition) )
|
|
82 {
|
|
83 if ( !RegCreateKeyExA(v8, "1.0", 0, "", 0, 0xF003Fu, 0, &v9, &dwDisposition) )
|
|
84 {
|
|
85 v2 = strlen(Str);
|
|
86 RegSetValueExA(v9, lpValueName, 0, 1u, (const BYTE *)Str, v2 + 1);
|
|
87 RegCloseKey(v9);
|
|
88 }
|
|
89 RegCloseKey(v8);
|
|
90 }
|
|
91 RegCloseKey(phkResult);
|
|
92 }
|
|
93 RegCloseKey(hKey);
|
|
94 }
|
|
95 }
|
|
96
|
|
97 //----- (00464BEF) --------------------------------------------------------
|
|
98 void __fastcall ReadWindowsRegistryString(const char *pKeyName, char *pOutString, int uBufLen, const char *pDefaultValue)
|
|
99 {
|
|
100 LSTATUS (__stdcall *v4)(HKEY); // esi@1
|
|
101 LSTATUS result; // eax@7
|
|
102 DWORD Type; // [sp+Ch] [bp-24h]@5
|
|
103 LPCSTR lpValueName; // [sp+10h] [bp-20h]@1
|
|
104 DWORD cbData; // [sp+14h] [bp-1Ch]@1
|
|
105 LPBYTE Dest; // [sp+18h] [bp-18h]@1
|
|
106 DWORD dwDisposition; // [sp+1Ch] [bp-14h]@2
|
|
107 HKEY phkResult; // [sp+20h] [bp-10h]@1
|
|
108 HKEY hKey; // [sp+24h] [bp-Ch]@1
|
|
109 HKEY v13; // [sp+28h] [bp-8h]@1
|
|
110 HKEY v14; // [sp+2Ch] [bp-4h]@1
|
|
111
|
|
112 cbData = uBufLen;
|
|
113 Dest = (LPBYTE)pOutString;
|
|
114 lpValueName = pKeyName;
|
|
115 v14 = 0;
|
|
116 v13 = 0;
|
|
117 hKey = 0;
|
|
118 phkResult = 0;
|
|
119 v4 = RegCloseKey;
|
|
120 if ( RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, 0x2001Fu, &hKey)
|
|
121 || RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, 0xF003Fu, 0, &phkResult, &dwDisposition)
|
|
122 || RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, 0xF003Fu, 0, &v13, &dwDisposition)
|
|
123 || RegCreateKeyExA(v13, "1.0", 0, "", 0, 0xF003Fu, 0, &v14, &dwDisposition) )
|
|
124 {
|
|
125 result = (LSTATUS)strncpy((char *)Dest, pDefaultValue, uBufLen);
|
|
126 }
|
|
127 else if ( RegQueryValueExA(v14, lpValueName, 0, &Type, Dest, &cbData) )
|
|
128 {
|
|
129 RegCloseKey(v14);
|
|
130 v14 = 0;
|
|
131 result = (LSTATUS)strncpy((char *)Dest, pDefaultValue, uBufLen);
|
|
132 }
|
|
133 else
|
|
134 {
|
|
135 v4 = RegCloseKey;
|
|
136 RegCloseKey(v14);
|
|
137 v14 = 0;
|
|
138 RegCloseKey(v13);
|
|
139 v13 = 0;
|
|
140 RegCloseKey(phkResult);
|
|
141 phkResult = 0;
|
|
142 result = RegCloseKey(hKey);
|
|
143 hKey = 0;
|
|
144 }
|
|
145 if ( v14 )
|
|
146 result = v4(v14);
|
|
147 if ( v13 )
|
|
148 result = v4(v13);
|
|
149 if ( hKey )
|
|
150 result = v4(hKey);
|
|
151 if ( phkResult )
|
|
152 result = v4(phkResult);
|
|
153 }
|
|
154
|
|
155 //----- (00464D32) --------------------------------------------------------
|
|
156 void __fastcall WriteWindowsRegistryInt(const char *pKey, int val)
|
|
157 {
|
|
158 const char *lpValueName; // [sp+4h] [bp-1Ch]@1
|
|
159 BYTE Data[4]; // [sp+8h] [bp-18h]@1
|
|
160 DWORD dwDisposition; // [sp+Ch] [bp-14h]@2
|
|
161 HKEY hKey; // [sp+10h] [bp-10h]@1
|
|
162 HKEY phkResult; // [sp+14h] [bp-Ch]@1
|
|
163 HKEY v7; // [sp+18h] [bp-8h]@1
|
|
164 HKEY v8; // [sp+1Ch] [bp-4h]@1
|
|
165
|
|
166 *(int *)Data = val;
|
|
167 lpValueName = pKey;
|
|
168 v8 = 0;
|
|
169 v7 = 0;
|
|
170 hKey = 0;
|
|
171 phkResult = 0;
|
|
172 if ( !RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, 0x2001Fu, &hKey) )
|
|
173 {
|
|
174 if ( !RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, 0xF003Fu, 0, &phkResult, &dwDisposition) )
|
|
175 {
|
|
176 if ( !RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, 0xF003Fu, 0, &v7, &dwDisposition) )
|
|
177 {
|
|
178 if ( !RegCreateKeyExA(v7, "1.0", 0, "", 0, 0xF003Fu, 0, &v8, &dwDisposition) )
|
|
179 {
|
|
180 RegSetValueExA(v8, lpValueName, 0, 4, Data, 4);
|
|
181 RegCloseKey(v8);
|
|
182 }
|
|
183 RegCloseKey(v7);
|
|
184 }
|
|
185 RegCloseKey(phkResult);
|
|
186 }
|
|
187 RegCloseKey(hKey);
|
|
188 }
|
|
189 } |