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