| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/linux/registry.cpp $ |
| 21 | * $Revision: 1.4 $ |
| 22 | * $Date: 2004/02/25 00:04:06 $ |
| 23 | * $Author: ryan $ |
| 24 | * |
| 25 | * Linux registry routines |
| 26 | * |
| 27 | * $Log: registry.cpp,v $ |
| 28 | * Revision 1.4 2004/02/25 00:04:06 ryan |
| 29 | * Removed loki_utils dependency and ported to MacOS X (runs, but incomplete). |
| 30 | * |
| 31 | * Revision 1.3 2000/06/24 01:15:15 icculus |
| 32 | * patched to compile. |
| 33 | * |
| 34 | * Revision 1.2 2000/04/28 20:19:29 icculus |
| 35 | * Minor mprintf update |
| 36 | * |
| 37 | * Revision 1.1.1.1 2000/04/18 00:00:39 icculus |
| 38 | * initial checkin |
| 39 | * |
| 40 | * |
| 41 | * 8 8/20/99 1:59p Jeff |
| 42 | * removed mprintfs... |
| 43 | * |
| 44 | * 7 7/14/99 9:09p Jeff |
| 45 | * added comment header |
| 46 | * |
| 47 | * $NoKeywords: $ |
| 48 | */ |
| 49 | |
| 50 | #include <stdio.h> |
| 51 | #include <stdlib.h> |
| 52 | #include <string.h> |
| 53 | #include <ctype.h> |
| 54 | // #include "local_malloc.h" |
| 55 | #include "registry.h"cxx . . $ `<file>/linux/registry.h`/ |
| 56 | #include "mono.h"cxx . . $ `<file>/ddebug/mono.h`/ |
| 57 | |
| 58 | #if defined(_WIN32) |
| 59 | #define strcasecmp stricmp |
| 60 | #endif |
| 61 | |
| 62 | // Convert a string that represents a hex value into an int |
| 63 | int hextoicxx . . $ hextoi(1ef8e6ec083aabb9).(char *p) { |
| 64 | int value = 0; |
| 65 | while ((p) && (*p) && isalnum(*p)) { |
| 66 | *p = toupper(*p); |
| 67 | if ((*p >= '0') && (*p <= '9')) |
| 68 | value = (value * 16) + ((*p) - '0'); |
| 69 | else if ((*p >= 'A') && (*p <= 'F')) |
| 70 | value = (value * 16) + ((*p) - 'A'); |
| 71 | else |
| 72 | return value; |
| 73 | |
| 74 | p++; |
| 75 | } |
| 76 | return value; |
| 77 | } |
| 78 | |
| 79 | // Removes whitespace from the start of the given string. |
| 80 | // Returns a pointer to the first non-white character |
| 81 | char *SkipWhitecxx . . $ SkipWhite(7a9722d75b371431).(char *p) { |
| 82 | while (isspace(*p)) |
| 83 | p++; |
| 84 | return p; |
| 85 | } |
| 86 | |
| 87 | // Parses a quoted string |
| 88 | // Returns true if got string ok, else false |
| 89 | char *ParseStringcxx . . $ ParseString(16cab7bd68b2d8b0).(char *p, char *buf, int bufsize, char sdelim, char edelim) { |
| 90 | char *save_p; |
| 91 | |
| 92 | p = SkipWhitecxx . . $ SkipWhite(7a9722d75b371431).(p); |
| 93 | |
| 94 | save_p = p; |
| 95 | |
| 96 | if (*p != sdelim) { |
| 97 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 98 | } else |
| 99 | p++; // skip initial quote |
| 100 | |
| 101 | // Copy chars until endquote or out of space |
| 102 | while (*p && (*p != edelim) && --bufsize) |
| 103 | *buf++ = *p++; |
| 104 | |
| 105 | // Check for buffer overflow |
| 106 | if (bufsize <= 0) { |
| 107 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 108 | } |
| 109 | |
| 110 | // Check for missing endquote |
| 111 | if (!*p) { |
| 112 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 113 | } |
| 114 | |
| 115 | // Write terminator |
| 116 | *buf = 0; |
| 117 | |
| 118 | // Return new pointer (move over a char for end quote) |
| 119 | return p + 1; |
| 120 | } |
| 121 | |
| 122 | // Parses a sequence of non-space characters |
| 123 | char *ParseTokencxx . . $ ParseToken(4b1661a75e253f1d).(char *p, char *buf, int bufsize) { |
| 124 | char *save_p; |
| 125 | p = SkipWhitecxx . . $ SkipWhite(7a9722d75b371431).(p); |
| 126 | save_p = p; |
| 127 | |
| 128 | while (!isspace(*p) && (*p != ',') && *p && --bufsize) |
| 129 | *buf++ = *p++; |
| 130 | |
| 131 | *buf = 0; |
| 132 | |
| 133 | // Check for buffer overflow |
| 134 | if (bufsize <= 0) { |
| 135 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 136 | } |
| 137 | |
| 138 | return p; |
| 139 | } |
| 140 | #define PARSE_KEYcxx . . $ `linux/registry.cpp:140:9`!(buf) \ |
| 141 | do { \ |
| 142 | ptr = ParseString(ptr, buf, sizeof(buf), '[', ']'); \ |
| 143 | } while (0) |
| 144 | #define PARSE_STRINGcxx . . $ `linux/registry.cpp:144:9`!(buf) \ |
| 145 | do { \ |
| 146 | ptr = ParseString(ptr, buf, sizeof(buf), '"', '"'); \ |
| 147 | } while (0) |
| 148 | #define PARSE_TOKENcxx . . $ `linux/registry.cpp:148:9`!(buf) \ |
| 149 | do { \ |
| 150 | ptr = ParseToken(ptr, buf, sizeof(buf)); \ |
| 151 | } while (0) |
| 152 | |
| 153 | CRegistrycxx . . $ CRegistry#::CRegistrycxx . . $ CRegistry#CRegistry(85c52e162fed56f9).(const char *str) { |
| 154 | currentkeycxx . . $ CRegistry#currentkey. = rootcxx . . $ CRegistry#root. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 155 | strcpy(namecxx . . $ CRegistry#name., str); |
| 156 | } |
| 157 | |
| 158 | CRegistrycxx . . $ CRegistry#::~cxx . . $ CRegistry#`~CRegistry`(ced63f7c635d850d).CRegistrycxx . . $ CRegistry#() { Destroycxx . . $ CRegistry#Destroy(49f6e7a06ebc5aa8).(); } |
| 159 | |
| 160 | void CRegistrycxx . . $ CRegistry#::GetSystemNamecxx . . $ CRegistry#GetSystemName(fda57c8427c60377).(char *n) { strcpy(n, namecxx . . $ CRegistry#name.); } |
| 161 | |
| 162 | void CRegistrycxx . . $ CRegistry#::SetSystemNamecxx . . $ CRegistry#SetSystemName(85c52e162fed56f9).(const char *n) { strcpy(namecxx . . $ CRegistry#name., n); } |
| 163 | |
| 164 | void CRegistrycxx . . $ CRegistry#::Destroycxx . . $ CRegistry#Destroy(49f6e7a06ebc5aa8).(void) { |
| 165 | tKeycxx . . $ tKey# *curr, *next; |
| 166 | curr = next = rootcxx . . $ CRegistry#root.; |
| 167 | while (curr) { |
| 168 | next = curr->nextcxx . . $ tKey#next.; |
| 169 | DestroyKeycxx . . $ CRegistry#DestroyKey(75fb02095f21236d).(curr); |
| 170 | curr = next; |
| 171 | } |
| 172 | rootcxx . . $ CRegistry#root. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 173 | } |
| 174 | |
| 175 | void CRegistrycxx . . $ CRegistry#::DestroyKeycxx . . $ CRegistry#DestroyKey(75fb02095f21236d).(tKeycxx . . $ tKey# *key) { |
| 176 | tRecordcxx . . $ tRecord# *curr, *next; |
| 177 | curr = next = key->recordscxx . . $ tKey#records.; |
| 178 | while (curr) { |
| 179 | next = curr->nextcxx . . $ tRecord#next.; |
| 180 | DestroyRecordcxx . . $ CRegistry#DestroyRecord(a197468c659cdcd8).(curr); |
| 181 | curr = next; |
| 182 | } |
| 183 | freecxx . . $ free(bd21765a0afc8e3c).(key); |
| 184 | } |
| 185 | |
| 186 | void CRegistrycxx . . $ CRegistry#::DestroyRecordcxx . . $ CRegistry#DestroyRecord(a197468c659cdcd8).(tRecordcxx . . $ tRecord# *record) { |
| 187 | if (record->datacxx . . $ tRecord#data.) { |
| 188 | freecxx . . $ free(bd21765a0afc8e3c).(record->datacxx . . $ tRecord#data.); |
| 189 | record->datacxx . . $ tRecord#data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 190 | } |
| 191 | freecxx . . $ free(bd21765a0afc8e3c).(record); |
| 192 | } |
| 193 | |
| 194 | void CRegistrycxx . . $ CRegistry#::Exportcxx . . $ CRegistry#Export(49f6e7a06ebc5aa8).() { |
| 195 | tKeycxx . . $ tKey# *curr, *next; |
| 196 | curr = next = rootcxx . . $ CRegistry#root.; |
| 197 | FILE *file; |
| 198 | file = fopen(namecxx . . $ CRegistry#name., "wt"); |
| 199 | if (!file) |
| 200 | return; |
| 201 | while (curr) { |
| 202 | next = curr->nextcxx . . $ tKey#next.; |
| 203 | ExportKeycxx . . $ CRegistry#ExportKey(214d306f1bc4ef48).(curr, file); |
| 204 | curr = next; |
| 205 | } |
| 206 | fclose(file); |
| 207 | } |
| 208 | |
| 209 | void CRegistrycxx . . $ CRegistry#::ExportKeycxx . . $ CRegistry#ExportKey(214d306f1bc4ef48).(tKeycxx . . $ tKey# *key, FILE *file) { |
| 210 | tRecordcxx . . $ tRecord# *curr, *next; |
| 211 | curr = next = key->recordscxx . . $ tKey#records.; |
| 212 | // write out name |
| 213 | char buffer[256+16]; |
| 214 | snprintf(buffer, sizeof(buffer), "[%s]\n", key->namecxx . . $ tKey#name.); |
| 215 | fputs(buffer, file); |
| 216 | while (curr) { |
| 217 | next = curr->nextcxx . . $ tRecord#next.; |
| 218 | ExportRecordcxx . . $ CRegistry#ExportRecord(77dbf6824b5a97f6).(curr, file); |
| 219 | curr = next; |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | void CRegistrycxx . . $ CRegistry#::ExportRecordcxx . . $ CRegistry#ExportRecord(77dbf6824b5a97f6).(tRecordcxx . . $ tRecord# *record, FILE *file) { |
| 224 | int *dw; |
| 225 | char *st; |
| 226 | char buffer[512]; |
| 227 | switch (record->typecxx . . $ tRecord#type.) { |
| 228 | case REGT_STRINGcxx . . $ `linux/registry.h:49:9`!: { |
| 229 | st = (char *)record->datacxx . . $ tRecord#data.; |
| 230 | snprintf(buffer, sizeof(buffer), "\"%s\"=\"%s\"\n", record->namecxx . . $ tRecord#name., st); |
| 231 | } break; |
| 232 | case REGT_DWORDcxx . . $ `linux/registry.h:50:9`!: { |
| 233 | dw = (int *)record->datacxx . . $ tRecord#data.; |
| 234 | snprintf(buffer, sizeof(buffer), "\"%s\"=dword:%X\n", record->namecxx . . $ tRecord#name., *dw); |
| 235 | } break; |
| 236 | }; |
| 237 | fputs(buffer, file); |
| 238 | } |
| 239 | |
| 240 | bool CRegistrycxx . . $ CRegistry#::Importcxx . . $ CRegistry#Import(c9857a73d68e59ba).() { |
| 241 | char buffer[500]; |
| 242 | char newbuff[500]; |
| 243 | FILE *file; |
| 244 | char *ptr; |
| 245 | file = fopen(namecxx . . $ CRegistry#name., "rt"); |
| 246 | if (!file) { |
| 247 | mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "REGISTRY: Unable to import %s\n", name); |
| 248 | return false; |
| 249 | } |
| 250 | mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "REGISTRY: Importing %s\n", name); |
| 251 | Destroycxx . . $ CRegistry#Destroy(49f6e7a06ebc5aa8).(); |
| 252 | |
| 253 | bool oktocreate; |
| 254 | // loop till we are done |
| 255 | while (!feof(file)) { |
| 256 | oktocreate = true; |
| 257 | char type = REGT_STRINGcxx . . $ `linux/registry.h:49:9`!; |
| 258 | |
| 259 | // read in the string |
| 260 | fgets(buffer, 500, file); |
| 261 | ptr = buffer; |
| 262 | if (feof(file)) // we are at the end of the file so there isn't data to continue |
| 263 | oktocreate = false; |
| 264 | // see what we read, a key or record, if the first character is a [ than a key " is record |
| 265 | if (oktocreate) { |
| 266 | if (buffer[0] == '[') { |
| 267 | // Create a key! |
| 268 | PARSE_KEYcxx . . $ `linux/registry.cpp:140:9`!(newbuff); |
| 269 | // mprintf(0,"Found Key: |%s|\n",newbuff); |
| 270 | CreateKeycxx . . $ CRegistry#CreateKey(85c52e162fed56f9).(newbuff); |
| 271 | } else if (buffer[0] == '\"') { |
| 272 | // Create a record |
| 273 | // see what type of record by looking at whats after the = |
| 274 | char *p; |
| 275 | p = buffer; |
| 276 | bool done = false; |
| 277 | type = REGT_STRINGcxx . . $ `linux/registry.h:49:9`!; |
| 278 | while (!done) { |
| 279 | if ((!p) || (!*p)) |
| 280 | done = true; |
| 281 | if ((p) && (*p == '=')) { |
| 282 | if (*(p + 1) == 'd') |
| 283 | type = REGT_DWORDcxx . . $ `linux/registry.h:50:9`!; |
| 284 | else |
| 285 | type = REGT_STRINGcxx . . $ `linux/registry.h:49:9`!; |
| 286 | done = true; |
| 287 | } |
| 288 | p++; |
| 289 | } |
| 290 | // now we "SHOULD" know the type, parse the info |
| 291 | char data[300]; |
| 292 | int idata; |
| 293 | switch (type) { |
| 294 | case REGT_STRINGcxx . . $ `linux/registry.h:49:9`!: |
| 295 | PARSE_STRINGcxx . . $ `linux/registry.cpp:144:9`!(newbuff); |
| 296 | |
| 297 | // rcg06212000 getting a NULL ptr in here...added a check. |
| 298 | if (ptr == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 299 | continue; |
| 300 | |
| 301 | ptr++; // blow by = |
| 302 | PARSE_STRINGcxx . . $ `linux/registry.cpp:144:9`!(data); |
| 303 | if (!CreateRecordcxx . . $ CRegistry#CreateRecord(5438c15cf96d2f9c).(newbuff, REGT_STRINGcxx . . $ `linux/registry.h:49:9`!, data)) { |
| 304 | // mprintf(0,"Unable to create String record: %s\n",newbuff); |
| 305 | } else { |
| 306 | // mprintf(0,"Created String record %s = %s\n",newbuff,data); |
| 307 | } |
| 308 | break; |
| 309 | case REGT_DWORDcxx . . $ `linux/registry.h:50:9`!: |
| 310 | PARSE_STRINGcxx . . $ `linux/registry.cpp:144:9`!(newbuff); |
| 311 | ptr += 7; // blow by =dword: |
| 312 | PARSE_TOKENcxx . . $ `linux/registry.cpp:148:9`!(data); |
| 313 | idata = hextoicxx . . $ hextoi(1ef8e6ec083aabb9).(data); |
| 314 | if (!CreateRecordcxx . . $ CRegistry#CreateRecord(5438c15cf96d2f9c).(newbuff, REGT_DWORDcxx . . $ `linux/registry.h:50:9`!, &idata)) { |
| 315 | // mprintf(0,"Unable to create dword record: %s\n",newbuff); |
| 316 | } else { |
| 317 | // mprintf(0,"Created dword record %s = %X\n",newbuff,idata); |
| 318 | } |
| 319 | break; |
| 320 | }; |
| 321 | } else { |
| 322 | // mprintf(0,"Expected [ or \"\n"); |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | fclose(file); |
| 327 | return true; |
| 328 | } |
| 329 | |
| 330 | void CRegistrycxx . . $ CRegistry#::CreateKeycxx . . $ CRegistry#CreateKey(85c52e162fed56f9).(const char *name) { |
| 331 | tKeycxx . . $ tKey# *curr; |
| 332 | if (LookupKeycxx . . $ CRegistry#LookupKey(c5f7da30cbc0f4e9).(name)) { |
| 333 | // mprintf(0,"Key: %s already exists\n",name); |
| 334 | return; |
| 335 | } |
| 336 | if (!rootcxx . . $ CRegistry#root.) { |
| 337 | rootcxx . . $ CRegistry#root. = (tKeycxx . . $ tKey# *)malloccxx . . $ malloc(9f008b2a9698428b).(sizeof(tKeycxx . . $ tKey#)); |
| 338 | if (!rootcxx . . $ CRegistry#root.) |
| 339 | return; |
| 340 | curr = rootcxx . . $ CRegistry#root.; |
| 341 | } else { |
| 342 | curr = rootcxx . . $ CRegistry#root.; |
| 343 | while (curr->nextcxx . . $ tKey#next.) { |
| 344 | curr = curr->nextcxx . . $ tKey#next.; |
| 345 | } |
| 346 | curr->nextcxx . . $ tKey#next. = (tKeycxx . . $ tKey# *)malloccxx . . $ malloc(9f008b2a9698428b).(sizeof(tKeycxx . . $ tKey#)); |
| 347 | if (!curr->nextcxx . . $ tKey#next.) |
| 348 | return; |
| 349 | curr = curr->nextcxx . . $ tKey#next.; |
| 350 | } |
| 351 | curr->nextcxx . . $ tKey#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 352 | strcpy(curr->namecxx . . $ tKey#name., name); |
| 353 | curr->recordscxx . . $ tKey#records. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 354 | currentkeycxx . . $ CRegistry#currentkey. = curr; |
| 355 | } |
| 356 | |
| 357 | bool CRegistrycxx . . $ CRegistry#::LookupKeycxx . . $ CRegistry#LookupKey(c5f7da30cbc0f4e9).(const char *name) { |
| 358 | tKeycxx . . $ tKey# *curr; |
| 359 | curr = rootcxx . . $ CRegistry#root.; |
| 360 | while (curr) { |
| 361 | if (!strcasecmp(name, curr->namecxx . . $ tKey#name.)) { |
| 362 | // found a match |
| 363 | currentkeycxx . . $ CRegistry#currentkey. = curr; |
| 364 | return true; |
| 365 | } |
| 366 | curr = curr->nextcxx . . $ tKey#next.; |
| 367 | } |
| 368 | return false; |
| 369 | } |
| 370 | |
| 371 | tRecordcxx . . $ tRecord# *CRegistrycxx . . $ CRegistry#::LookupRecordcxx . . $ CRegistry#LookupRecord(f758117682a82874).(const char *record, void *data) { |
| 372 | if (!currentkeycxx . . $ CRegistry#currentkey.) |
| 373 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 374 | |
| 375 | tRecordcxx . . $ tRecord# *curr; |
| 376 | curr = currentkeycxx . . $ CRegistry#currentkey.->recordscxx . . $ tKey#records.; |
| 377 | while (curr) { |
| 378 | if (!strcasecmp(record, curr->namecxx . . $ tRecord#name.)) { |
| 379 | // found the record |
| 380 | switch (curr->typecxx . . $ tRecord#type.) { |
| 381 | case REGT_STRINGcxx . . $ `linux/registry.h:49:9`!: |
| 382 | char *st; |
| 383 | st = (char *)curr->datacxx . . $ tRecord#data.; |
| 384 | strcpy((char *)data, st); |
| 385 | break; |
| 386 | case REGT_DWORDcxx . . $ `linux/registry.h:50:9`!: |
| 387 | int *dw; |
| 388 | dw = (int *)curr->datacxx . . $ tRecord#data.; |
| 389 | *((int *)data) = *dw; |
| 390 | break; |
| 391 | }; |
| 392 | return curr; |
| 393 | } |
| 394 | curr = curr->nextcxx . . $ tRecord#next.; |
| 395 | } |
| 396 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 397 | } |
| 398 | |
| 399 | int CRegistrycxx . . $ CRegistry#::GetDataSizecxx . . $ CRegistry#GetDataSize(5c4306d8553b3696).(const char *record) { |
| 400 | if (!currentkeycxx . . $ CRegistry#currentkey.) |
| 401 | return false; |
| 402 | tRecordcxx . . $ tRecord# *curr; |
| 403 | curr = currentkeycxx . . $ CRegistry#currentkey.->recordscxx . . $ tKey#records.; |
| 404 | while (curr) { |
| 405 | if (!strcasecmp(record, curr->namecxx . . $ tRecord#name.)) { |
| 406 | // found the record |
| 407 | switch (curr->typecxx . . $ tRecord#type.) { |
| 408 | case REGT_STRINGcxx . . $ `linux/registry.h:49:9`!: |
| 409 | return strlen((char *)curr->datacxx . . $ tRecord#data.) + 1; |
| 410 | break; |
| 411 | case REGT_DWORDcxx . . $ `linux/registry.h:50:9`!: |
| 412 | return sizeof(int); |
| 413 | break; |
| 414 | }; |
| 415 | return 0; |
| 416 | } |
| 417 | curr = curr->nextcxx . . $ tRecord#next.; |
| 418 | } |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | bool CRegistrycxx . . $ CRegistry#::CreateRecordcxx . . $ CRegistry#CreateRecord(5438c15cf96d2f9c).(const char *name, char type, void *data) { |
| 423 | if (!currentkeycxx . . $ CRegistry#currentkey.) |
| 424 | return false; |
| 425 | tRecordcxx . . $ tRecord# *curr; |
| 426 | // first see if the record exists under this key |
| 427 | int datasize = GetDataSizecxx . . $ CRegistry#GetDataSize(5c4306d8553b3696).(name); |
| 428 | if (datasize) { |
| 429 | char *olddata = (char *)malloccxx . . $ malloc(9f008b2a9698428b).(datasize); |
| 430 | if (olddata) { |
| 431 | curr = LookupRecordcxx . . $ CRegistry#LookupRecord(f758117682a82874).(name, olddata); |
| 432 | if (curr) { |
| 433 | // ok we have an old value, replace it! |
| 434 | // mprintf(0,"Replacing %s\n",name); |
| 435 | if (curr->datacxx . . $ tRecord#data.) |
| 436 | freecxx . . $ free(bd21765a0afc8e3c).(curr->datacxx . . $ tRecord#data.); |
| 437 | freecxx . . $ free(bd21765a0afc8e3c).(olddata); |
| 438 | curr->typecxx . . $ tRecord#type. = type; |
| 439 | switch (type) { |
| 440 | case REGT_STRINGcxx . . $ `linux/registry.h:49:9`!: |
| 441 | curr->datacxx . . $ tRecord#data. = malloccxx . . $ malloc(9f008b2a9698428b).(strlen((char *)data) + 1); |
| 442 | strcpy((char *)curr->datacxx . . $ tRecord#data., (char *)data); |
| 443 | break; |
| 444 | case REGT_DWORDcxx . . $ `linux/registry.h:50:9`!: |
| 445 | curr->datacxx . . $ tRecord#data. = malloccxx . . $ malloc(9f008b2a9698428b).(sizeof(int)); |
| 446 | *((int *)curr->datacxx . . $ tRecord#data.) = *((int *)data); |
| 447 | break; |
| 448 | } |
| 449 | return true; |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | // it is a new record |
| 455 | if (currentkeycxx . . $ CRegistry#currentkey.->recordscxx . . $ tKey#records.) { |
| 456 | curr = currentkeycxx . . $ CRegistry#currentkey.->recordscxx . . $ tKey#records.; |
| 457 | while (curr->nextcxx . . $ tRecord#next.) |
| 458 | curr = curr->nextcxx . . $ tRecord#next.; |
| 459 | curr->nextcxx . . $ tRecord#next. = (tRecordcxx . . $ tRecord# *)malloccxx . . $ malloc(9f008b2a9698428b).(sizeof(tRecordcxx . . $ tRecord#)); |
| 460 | if (!curr->nextcxx . . $ tRecord#next.) |
| 461 | return false; |
| 462 | curr = curr->nextcxx . . $ tRecord#next.; |
| 463 | } else { |
| 464 | currentkeycxx . . $ CRegistry#currentkey.->recordscxx . . $ tKey#records. = (tRecordcxx . . $ tRecord# *)malloccxx . . $ malloc(9f008b2a9698428b).(sizeof(tRecordcxx . . $ tRecord#)); |
| 465 | if (!currentkeycxx . . $ CRegistry#currentkey.->recordscxx . . $ tKey#records.) |
| 466 | return false; |
| 467 | curr = currentkeycxx . . $ CRegistry#currentkey.->recordscxx . . $ tKey#records.; |
| 468 | } |
| 469 | curr->nextcxx . . $ tRecord#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 470 | strcpy(curr->namecxx . . $ tRecord#name., name); |
| 471 | switch (type) { |
| 472 | case REGT_STRINGcxx . . $ `linux/registry.h:49:9`!: |
| 473 | curr->datacxx . . $ tRecord#data. = malloccxx . . $ malloc(9f008b2a9698428b).(strlen((char *)data) + 1); |
| 474 | curr->typecxx . . $ tRecord#type. = REGT_STRINGcxx . . $ `linux/registry.h:49:9`!; |
| 475 | strcpy((char *)curr->datacxx . . $ tRecord#data., (char *)data); |
| 476 | break; |
| 477 | case REGT_DWORDcxx . . $ `linux/registry.h:50:9`!: |
| 478 | curr->datacxx . . $ tRecord#data. = malloccxx . . $ malloc(9f008b2a9698428b).(sizeof(int)); |
| 479 | curr->typecxx . . $ tRecord#type. = REGT_DWORDcxx . . $ `linux/registry.h:50:9`!; |
| 480 | *((int *)curr->datacxx . . $ tRecord#data.) = *((int *)data); |
| 481 | break; |
| 482 | }; |
| 483 | return true; |
| 484 | } |