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