- Timestamp:
- 01/21/09 05:27:32 (16 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/regfi.h
r134 r135 72 72 #define REG_KEY 0x7FFFFFFF 73 73 74 #define REGF_BLOCKSIZE 0x1000 75 #define REGF_ALLOC_BLOCK 0x1000 /* Minimum allocation unit for HBINs */ 76 #define REGF_MAX_DEPTH 512 77 78 /* header sizes for various records */ 79 #define REGF_MAGIC_SIZE 4 80 #define HBIN_MAGIC_SIZE 4 81 #define HBIN_HEADER_REC_SIZE 0x20 82 #define REC_HDR_SIZE 2 83 84 #define REGF_OFFSET_NONE 0xffffffff 74 #define REGFI_REGF_SIZE 0x1000 /* "regf" header block size */ 75 #define REGFI_HBIN_ALLOC 0x1000 /* Minimum allocation unit for HBINs */ 76 #define REGFI_MAX_DEPTH 512 77 #define REGFI_OFFSET_NONE 0xffffffff 78 79 /* Header sizes and magic number lengths for various records */ 80 #define REGFI_REGF_MAGIC_SIZE 4 81 #define REGFI_HBIN_MAGIC_SIZE 4 82 #define REGFI_CELL_MAGIC_SIZE 2 83 #define REGFI_HBIN_HEADER_SIZE 0x20 85 84 #define REGFI_NK_MIN_LENGTH 0x4C 86 85 #define REGFI_VK_MIN_LENGTH 0x14 87 86 #define REGFI_SK_MIN_LENGTH 0x14 88 87 #define REGFI_SUBKEY_LIST_MIN_LEN 0x4 88 89 89 90 90 /* Constants used for validation */ … … 106 106 107 107 /* Flags for the vk records */ 108 #define VK_FLAG_NAME_PRESENT0x0001109 #define VK_DATA_IN_OFFSET0x80000000110 #define VK_MAX_DATA_LENGTH1024*1024108 #define REGFI_VK_FLAG_NAME_PRESENT 0x0001 109 #define REGFI_VK_DATA_IN_OFFSET 0x80000000 110 #define REGFI_VK_MAX_DATA_LENGTH 1024*1024 111 111 112 112 /* NK record types */ 113 #define NK_TYPE_LINKKEY 0x0010 114 #define NK_TYPE_NORMALKEY 0x0020 115 #define NK_TYPE_ROOTKEY1 0x002c 116 #define NK_TYPE_ROOTKEY2 0x00ac 117 /* XXX: Unknown type that shows up in Vista registries */ 118 #define NK_TYPE_UNKNOWN1 0x1020 113 #define REGFI_NK_TYPE_LINKKEY 0x0010 114 #define REGFI_NK_TYPE_NORMALKEY 0x0020 115 /* XXX: Unknown key type that shows up in Vista registries */ 116 #define REGFI_NK_TYPE_UNKNOWN1 0x1020 117 #define REGFI_NK_TYPE_ROOTKEY1 0x002c 118 /* XXX: Unknown root key type that shows up in Vista registries */ 119 #define REGFI_NK_TYPE_ROOTKEY2 0x00ac 119 120 120 121 121 122 /* HBIN block */ 122 typedef struct regf_hbin123 typedef struct _regfi_hbin 123 124 { 124 125 uint32 file_off; /* my offset in the registry file */ … … 135 136 */ 136 137 137 uint8 magic[ HBIN_MAGIC_SIZE]; /* "hbin" */138 } REGF _HBIN;138 uint8 magic[REGFI_HBIN_MAGIC_SIZE]; /* "hbin" */ 139 } REGFI_HBIN; 139 140 140 141 … … 144 145 uint32 nk_off; 145 146 uint32 hash; 146 } REGF _SUBKEY_LIST_ELEM;147 } REGFI_SUBKEY_LIST_ELEM; 147 148 148 149 … … 152 153 uint32 cell_size; /* ((start_offset - end_offset) & 0xfffffff8) */ 153 154 uint32 num_keys; 154 REGF _SUBKEY_LIST_ELEM* elements;155 156 uint8 magic[RE C_HDR_SIZE];157 } REGF _SUBKEY_LIST;155 REGFI_SUBKEY_LIST_ELEM* elements; 156 157 uint8 magic[REGFI_CELL_MAGIC_SIZE]; 158 } REGFI_SUBKEY_LIST; 158 159 159 160 … … 164 165 uint32 cell_size; /* ((start_offset - end_offset) & 0xfffffff8) */ 165 166 166 REGF _HBIN* hbin; /* pointer to HBIN record (in memory) containing167 REGFI_HBIN* hbin; /* pointer to HBIN record (in memory) containing 167 168 * this nk record 168 169 */ … … 175 176 uint32 data_off; /* offset of data cell (virtual) */ 176 177 uint32 type; 177 uint8 magic[RE C_HDR_SIZE];178 uint8 magic[REGFI_CELL_MAGIC_SIZE]; 178 179 uint16 flag; 179 180 uint16 unknown1; 180 181 bool data_in_offset; 181 } REGF _VK_REC;182 } REGFI_VK_REC; 182 183 183 184 184 185 /* Key Security */ 185 struct _regf _sk_rec;186 187 typedef struct _regf _sk_rec186 struct _regfi_sk_rec; 187 188 typedef struct _regfi_sk_rec 188 189 { 189 190 uint32 offset; /* Real file offset of this record */ … … 202 203 uint32 desc_size; /* size of security descriptor */ 203 204 uint16 unknown_tag; 204 uint8 magic[RE C_HDR_SIZE];205 } REGF _SK_REC;205 uint8 magic[REGFI_CELL_MAGIC_SIZE]; 206 } REGFI_SK_REC; 206 207 207 208 … … 215 216 216 217 /* link in the other records here */ 217 REGF _VK_REC** values;218 REGF _SUBKEY_LIST* subkeys;218 REGFI_VK_REC** values; 219 REGFI_SUBKEY_LIST* subkeys; 219 220 220 221 /* header information */ 221 222 uint16 key_type; 222 uint8 magic[RE C_HDR_SIZE];223 uint8 magic[REGFI_CELL_MAGIC_SIZE]; 223 224 NTTIME mtime; 224 225 uint16 name_length; … … 247 248 uint32 values_off; /* value lists which point to VK records */ 248 249 uint32 sk_off; /* offset to SK record */ 249 } REGF _NK_REC;250 } REGFI_NK_REC; 250 251 251 252 … … 254 255 typedef struct 255 256 { 256 /* run time information */ 257 /* Run-time information */ 258 /************************/ 257 259 int fd; /* file descriptor */ 260 261 /* Experimental hbin lists */ 262 range_list* hbins; 263 264 /* Error/warning/info messages returned by lower layer functions */ 265 char* last_message; 266 258 267 /* For sanity checking (not part of the registry header) */ 259 268 uint32 file_length; 260 void* mem_ctx; /* memory context for run-time file access information */ 261 262 /* Experimental hbin lists */ 263 range_list* hbins; 264 265 /* file format information */ 266 uint8 magic[REGF_MAGIC_SIZE];/* "regf" */ 269 270 271 /* Data parsed from file header */ 272 /********************************/ 273 uint8 magic[REGFI_REGF_MAGIC_SIZE];/* "regf" */ 267 274 NTTIME mtime; 268 275 uint32 data_offset; /* offset to record in the first (or any?) … … 284 291 uint32 unknown6; 285 292 uint32 unknown7; 286 } REGF _FILE;287 288 289 290 typedef struct 291 { 292 REGF _FILE* f;293 } REGFI_FILE; 294 295 296 297 typedef struct 298 { 299 REGFI_FILE* f; 293 300 void_stack* key_positions; 294 301 lru_cache* sk_recs; 295 REGF _NK_REC* cur_key;302 REGFI_NK_REC* cur_key; 296 303 uint32 cur_subkey; 297 304 uint32 cur_value; … … 301 308 typedef struct 302 309 { 303 REGF_NK_REC* nk; 310 /* XXX: Should probably eliminate the storage of keys here 311 * once key caching is implemented. 312 */ 313 REGFI_NK_REC* nk; 304 314 uint32 cur_subkey; 305 315 /* We could store a cur_value here as well, but didn't see … … 310 320 311 321 /******************************************************************************/ 312 /* Function Declarations */ 313 /* Main API */ 314 const char* regfi_type_val2str(unsigned int val); 315 int regfi_type_str2val(const char* str); 316 317 char* regfi_get_sacl(WINSEC_DESC* sec_desc); 318 char* regfi_get_dacl(WINSEC_DESC* sec_desc); 319 char* regfi_get_owner(WINSEC_DESC* sec_desc); 320 char* regfi_get_group(WINSEC_DESC* sec_desc); 321 322 REGF_FILE* regfi_open(const char* filename); 323 int regfi_close(REGF_FILE* r); 324 325 REGFI_ITERATOR* regfi_iterator_new(REGF_FILE* fh); 322 /* Main iterator API */ 323 /******************************************************************************/ 324 REGFI_FILE* regfi_open(const char* filename); 325 int regfi_close(REGFI_FILE* r); 326 327 /* regfi_get_message: Get errors, warnings, and/or verbose information 328 * relating to processing of the given registry file. 329 * 330 * Arguments: 331 * file -- the structure for the registry file 332 * 333 * Returns: 334 * A newly allocated char* which must be free()d by the caller. 335 */ 336 char* regfi_get_message(REGFI_FILE* file); 337 338 REGFI_ITERATOR* regfi_iterator_new(REGFI_FILE* fh); 326 339 void regfi_iterator_free(REGFI_ITERATOR* i); 327 340 bool regfi_iterator_down(REGFI_ITERATOR* i); … … 333 346 bool regfi_iterator_walk_path(REGFI_ITERATOR* i, 334 347 const char** path); 335 const REGF _NK_REC*regfi_iterator_cur_key(REGFI_ITERATOR* i);336 const REGF _SK_REC*regfi_iterator_cur_sk(REGFI_ITERATOR* i);337 const REGF _NK_REC*regfi_iterator_first_subkey(REGFI_ITERATOR* i);338 const REGF _NK_REC*regfi_iterator_cur_subkey(REGFI_ITERATOR* i);339 const REGF _NK_REC*regfi_iterator_next_subkey(REGFI_ITERATOR* i);348 const REGFI_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i); 349 const REGFI_SK_REC* regfi_iterator_cur_sk(REGFI_ITERATOR* i); 350 const REGFI_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i); 351 const REGFI_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i); 352 const REGFI_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i); 340 353 341 354 bool regfi_iterator_find_value(REGFI_ITERATOR* i, 342 355 const char* value_name); 343 const REGF _VK_REC*regfi_iterator_first_value(REGFI_ITERATOR* i);344 const REGF _VK_REC*regfi_iterator_cur_value(REGFI_ITERATOR* i);345 const REGF _VK_REC*regfi_iterator_next_value(REGFI_ITERATOR* i);356 const REGFI_VK_REC* regfi_iterator_first_value(REGFI_ITERATOR* i); 357 const REGFI_VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i); 358 const REGFI_VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i); 346 359 347 360 … … 349 362 /* Middle-layer structure caching, loading, and linking */ 350 363 /********************************************************/ 351 REGF_HBIN* regfi_lookup_hbin(REGF_FILE* file, uint32 offset); 352 353 REGF_NK_REC* regfi_load_key(REGF_FILE* file, uint32 offset, bool strict); 354 355 REGF_SUBKEY_LIST* regfi_load_subkeylist(REGF_FILE* file, uint32 offset, 356 uint32 num_keys, uint32 max_size, 357 bool strict); 358 359 REGF_VK_REC** regfi_load_valuelist(REGF_FILE* file, uint32 offset, 360 uint32 num_values, uint32 max_size, 361 bool strict); 362 363 REGF_SUBKEY_LIST* regfi_merge_subkeylists(uint16 num_lists, 364 REGF_SUBKEY_LIST** lists, 365 bool strict); 364 REGFI_HBIN* regfi_lookup_hbin(REGFI_FILE* file, uint32 offset); 365 REGFI_NK_REC* regfi_load_key(REGFI_FILE* file, uint32 offset, 366 bool strict); 367 REGFI_SUBKEY_LIST* regfi_load_subkeylist(REGFI_FILE* file, uint32 offset, 368 uint32 num_keys, uint32 max_size, 369 bool strict); 370 REGFI_VK_REC** regfi_load_valuelist(REGFI_FILE* file, uint32 offset, 371 uint32 num_values, uint32 max_size, 372 bool strict); 366 373 367 374 /************************************/ 368 375 /* Low-layer data structure access */ 369 376 /************************************/ 370 REGF _FILE*regfi_parse_regf(int fd, bool strict);371 REGF _HBIN* regfi_parse_hbin(REGF_FILE* file, uint32 offset,377 REGFI_FILE* regfi_parse_regf(int fd, bool strict); 378 REGFI_HBIN* regfi_parse_hbin(REGFI_FILE* file, uint32 offset, 372 379 bool strict); 373 380 … … 384 391 * A newly allocated NK record structure, or NULL on failure. 385 392 */ 386 REGF _NK_REC* regfi_parse_nk(REGF_FILE* file, uint32 offset,393 REGFI_NK_REC* regfi_parse_nk(REGFI_FILE* file, uint32 offset, 387 394 uint32 max_size, bool strict); 388 395 389 REGF_VK_REC* regfi_parse_vk(REGF_FILE* file, uint32 offset, 390 uint32 max_size, bool strict); 391 392 uint8* regfi_parse_data(REGF_FILE* file, uint32 offset, 393 uint32 length, uint32 max_size, bool strict); 394 395 REGF_SK_REC* regfi_parse_sk(REGF_FILE* file, uint32 offset, uint32 max_size, bool strict); 396 397 range_list* regfi_parse_unalloc_cells(REGF_FILE* file); 398 399 bool regfi_parse_cell(int fd, uint32 offset, uint8* hdr, uint32 hdr_len, 400 uint32* cell_length, bool* unalloc); 401 402 char* regfi_parse_classname(REGF_FILE* file, uint32 offset, 403 uint16* name_length, uint32 max_size, bool strict); 404 405 406 /* Private Functions */ 407 REGF_NK_REC* regfi_rootkey(REGF_FILE* file); 408 void regfi_key_free(REGF_NK_REC* nk); 409 void regfi_subkeylist_free(REGF_SUBKEY_LIST* list); 396 REGFI_VK_REC* regfi_parse_vk(REGFI_FILE* file, uint32 offset, 397 uint32 max_size, bool strict); 398 399 uint8* regfi_parse_data(REGFI_FILE* file, uint32 offset, 400 uint32 length, uint32 max_size, 401 bool strict); 402 403 REGFI_SK_REC* regfi_parse_sk(REGFI_FILE* file, uint32 offset, 404 uint32 max_size, bool strict); 405 406 range_list* regfi_parse_unalloc_cells(REGFI_FILE* file); 407 408 bool regfi_parse_cell(int fd, uint32 offset, 409 uint8* hdr, uint32 hdr_len, 410 uint32* cell_length, bool* unalloc); 411 412 char* regfi_parse_classname(REGFI_FILE* file, uint32 offset, 413 uint16* name_length, 414 uint32 max_size, bool strict); 415 416 417 /************************************/ 418 /* Private Functions */ 419 /************************************/ 420 REGFI_NK_REC* regfi_rootkey(REGFI_FILE* file); 421 void regfi_key_free(REGFI_NK_REC* nk); 422 void regfi_subkeylist_free(REGFI_SUBKEY_LIST* list); 410 423 uint32 regfi_read(int fd, uint8* buf, uint32* length); 411 424 412 425 const char* regfi_type_val2str(unsigned int val); 426 int regfi_type_str2val(const char* str); 427 428 char* regfi_get_sacl(WINSEC_DESC* sec_desc); 429 char* regfi_get_dacl(WINSEC_DESC* sec_desc); 430 char* regfi_get_owner(WINSEC_DESC* sec_desc); 431 char* regfi_get_group(WINSEC_DESC* sec_desc); 432 433 REGFI_SUBKEY_LIST* regfi_merge_subkeylists(uint16 num_lists, 434 REGFI_SUBKEY_LIST** lists, 435 bool strict); 436 void regfi_add_message(REGFI_FILE* file, const char* error); 413 437 #endif /* _REGFI_H */ -
trunk/lib/regfi.c
r134 r135 34 34 35 35 36 37 /****************************************************************************** 38 ******************************************************************************/ 39 void regfi_add_message(REGFI_FILE* file, const char* error) 40 { 41 /* XXX: This function is not particularly efficient, 42 * but then it is mostly used during errors. 43 */ 44 uint32 length; 45 char* tmp; 46 47 if(file->last_message == NULL) 48 length = 0; 49 else 50 length = strlen(error); 51 52 tmp = realloc(file->last_message, length+strlen(file->last_message)+2); 53 if(tmp == NULL) 54 /* XXX: should we do something else here? */ 55 return; 56 57 if(length > 0) 58 strcat(tmp, "\n"); 59 strcat(tmp, error); 60 } 61 62 63 /****************************************************************************** 64 ******************************************************************************/ 65 char* regfi_get_message(REGFI_FILE* file) 66 { 67 char* ret_val = file->last_message; 68 file->last_message = NULL; 69 70 return ret_val; 71 } 72 73 36 74 /* Returns NULL on error */ 37 75 const char* regfi_type_val2str(unsigned int val) … … 66 104 67 105 68 /* Security descriptor parsing functions */106 /* Security descriptor formatting functions */ 69 107 70 108 const char* regfi_ace_type2str(uint8 type) … … 415 453 * The offset is a virtual file offset. 416 454 *******************************************************************/ 417 static bool regfi_offset_in_hbin(REGF _HBIN* hbin, uint32 offset)455 static bool regfi_offset_in_hbin(REGFI_HBIN* hbin, uint32 offset) 418 456 { 419 457 if(!hbin) … … 430 468 431 469 /******************************************************************* 432 * Given a virtual offset,and receive the correpsonding HBIN470 * Provide a virtual offset and receive the correpsonding HBIN 433 471 * block for it. NULL if one doesn't exist. 434 472 *******************************************************************/ 435 REGF _HBIN* regfi_lookup_hbin(REGF_FILE* file, uint32 offset)436 { 437 return (REGF _HBIN*)range_list_find_data(file->hbins, offset+REGF_BLOCKSIZE);473 REGFI_HBIN* regfi_lookup_hbin(REGFI_FILE* file, uint32 offset) 474 { 475 return (REGFI_HBIN*)range_list_find_data(file->hbins, offset+REGFI_REGF_SIZE); 438 476 } 439 477 … … 441 479 /******************************************************************* 442 480 *******************************************************************/ 443 REGF _SUBKEY_LIST* regfi_merge_subkeylists(uint16 num_lists,444 REGF _SUBKEY_LIST** lists,481 REGFI_SUBKEY_LIST* regfi_merge_subkeylists(uint16 num_lists, 482 REGFI_SUBKEY_LIST** lists, 445 483 bool strict) 446 484 { 447 485 uint32 i,j,k; 448 REGF _SUBKEY_LIST* ret_val;486 REGFI_SUBKEY_LIST* ret_val; 449 487 450 488 if(lists == NULL) 451 489 return NULL; 452 ret_val = (REGF _SUBKEY_LIST*)zalloc(sizeof(REGF_SUBKEY_LIST));490 ret_val = (REGFI_SUBKEY_LIST*)zalloc(sizeof(REGFI_SUBKEY_LIST)); 453 491 454 492 if(ret_val == NULL) … … 471 509 { 472 510 ret_val->elements = 473 (REGF _SUBKEY_LIST_ELEM*)zalloc(sizeof(REGF_SUBKEY_LIST_ELEM)511 (REGFI_SUBKEY_LIST_ELEM*)zalloc(sizeof(REGFI_SUBKEY_LIST_ELEM) 474 512 * ret_val->num_keys); 475 513 k=0; … … 497 535 /******************************************************************* 498 536 *******************************************************************/ 499 REGF _SUBKEY_LIST* regfi_load_subkeylist(REGF_FILE* file, uint32 offset,537 REGFI_SUBKEY_LIST* regfi_load_subkeylist(REGFI_FILE* file, uint32 offset, 500 538 uint32 num_keys, uint32 max_size, 501 539 bool strict) 502 540 { 503 REGF _SUBKEY_LIST* ret_val;504 REGF _SUBKEY_LIST** sublists;505 REGF _HBIN* sublist_hbin;541 REGFI_SUBKEY_LIST* ret_val; 542 REGFI_SUBKEY_LIST** sublists; 543 REGFI_HBIN* sublist_hbin; 506 544 uint32 i, cell_length, length, num_sublists, off, max_length, elem_size; 507 545 uint8* hashes; … … 537 575 } 538 576 539 sublists = (REGF _SUBKEY_LIST**)zalloc(num_sublists*sizeof(REGF_SUBKEY_LIST*));577 sublists = (REGFI_SUBKEY_LIST**)zalloc(num_sublists*sizeof(REGFI_SUBKEY_LIST*)); 540 578 for(i=0; i < num_sublists; i++) 541 579 { 542 off = IVAL(hashes, i*4)+REGF _BLOCKSIZE;580 off = IVAL(hashes, i*4)+REGFI_REGF_SIZE; 543 581 sublist_hbin = regfi_lookup_hbin(file, IVAL(hashes, i*4)); 544 582 max_length = sublist_hbin->block_size + sublist_hbin->file_off - off; … … 555 593 elem_size = sizeof(uint32); 556 594 else if((buf[0] == 'l') && (buf[1] == 'f' || buf[1] == 'h')) 557 elem_size = sizeof(REGF _SUBKEY_LIST_ELEM);595 elem_size = sizeof(REGFI_SUBKEY_LIST_ELEM); 558 596 else 559 597 { … … 562 600 } 563 601 564 ret_val = (REGF _SUBKEY_LIST*)zalloc(sizeof(REGF_SUBKEY_LIST));602 ret_val = (REGFI_SUBKEY_LIST*)zalloc(sizeof(REGFI_SUBKEY_LIST)); 565 603 if(ret_val == NULL) 566 604 return NULL; … … 596 634 length = elem_size*ret_val->num_keys; 597 635 ret_val->elements 598 = (REGF _SUBKEY_LIST_ELEM*)zalloc(ret_val->num_keys599 * sizeof(REGF _SUBKEY_LIST_ELEM));636 = (REGFI_SUBKEY_LIST_ELEM*)zalloc(ret_val->num_keys 637 * sizeof(REGFI_SUBKEY_LIST_ELEM)); 600 638 if(ret_val->elements == NULL) 601 639 { … … 645 683 /******************************************************************* 646 684 *******************************************************************/ 647 REGF _SK_REC* regfi_parse_sk(REGF_FILE* file, uint32 offset, uint32 max_size, bool strict)648 { 649 REGF _SK_REC* ret_val;685 REGFI_SK_REC* regfi_parse_sk(REGFI_FILE* file, uint32 offset, uint32 max_size, bool strict) 686 { 687 REGFI_SK_REC* ret_val; 650 688 uint8* sec_desc_buf; 651 689 uint32 cell_length, length; … … 661 699 return NULL; 662 700 663 ret_val = (REGF _SK_REC*)zalloc(sizeof(REGF_SK_REC));701 ret_val = (REGFI_SK_REC*)zalloc(sizeof(REGFI_SK_REC)); 664 702 if(ret_val == NULL) 665 703 return NULL; … … 696 734 } 697 735 698 /* XXX: need to get rid of this, but currently the security descriptor699 * code depends on the ps structure.700 */701 /*702 if(!prs_init(&ps, ret_val->desc_size, NULL, UNMARSHALL))703 {704 free(ret_val);705 return NULL;706 }707 708 length = ret_val->desc_size;709 if(regfi_read(file->fd, (uint8*)ps.data_p, &length) != 0710 || length != ret_val->desc_size)711 {712 free(ret_val);713 return NULL;714 }715 */716 717 736 sec_desc_buf = (uint8*)zalloc(ret_val->desc_size); 718 737 if(ret_val == NULL) … … 738 757 free(sec_desc_buf); 739 758 740 /* free(ps.data_p);*/741 759 742 760 return ret_val; … … 744 762 745 763 746 uint32* regfi_parse_valuelist(REGF _FILE* file, uint32 offset,764 uint32* regfi_parse_valuelist(REGFI_FILE* file, uint32 offset, 747 765 uint32 num_values, bool strict) 748 766 { … … 783 801 if(strict) 784 802 { 785 if((ret_val[i] + REGF _BLOCKSIZE > file->file_length)803 if((ret_val[i] + REGFI_REGF_SIZE > file->file_length) 786 804 || ((ret_val[i] & 0xFFFFFFF8) != ret_val[i])) 787 805 { … … 800 818 * If !strict, the list may contain NULLs, VK records may point to NULL. 801 819 ******************************************************************************/ 802 REGF _VK_REC** regfi_load_valuelist(REGF_FILE* file, uint32 offset,820 REGFI_VK_REC** regfi_load_valuelist(REGFI_FILE* file, uint32 offset, 803 821 uint32 num_values, uint32 max_size, 804 822 bool strict) 805 823 { 806 REGF _VK_REC** ret_val;807 REGF _HBIN* hbin;824 REGFI_VK_REC** ret_val; 825 REGFI_HBIN* hbin; 808 826 uint32 i, vk_offset, vk_max_length, usable_num_values; 809 827 uint32* voffsets; … … 822 840 return NULL; 823 841 824 ret_val = (REGF _VK_REC**)zalloc(sizeof(REGF_VK_REC*) * num_values);842 ret_val = (REGFI_VK_REC**)zalloc(sizeof(REGFI_VK_REC*) * num_values); 825 843 if(ret_val == NULL) 826 844 { … … 839 857 } 840 858 841 vk_offset = voffsets[i] + REGF _BLOCKSIZE;859 vk_offset = voffsets[i] + REGFI_REGF_SIZE; 842 860 vk_max_length = hbin->block_size + hbin->file_off - vk_offset; 843 861 ret_val[i] = regfi_parse_vk(file, vk_offset, vk_max_length, strict); … … 865 883 * custom cache structure. 866 884 *******************************************************************/ 867 REGF _NK_REC* regfi_load_key(REGF_FILE* file, uint32 offset, bool strict)868 { 869 REGF _HBIN* hbin;870 REGF _HBIN* sub_hbin;871 REGF _NK_REC* nk;885 REGFI_NK_REC* regfi_load_key(REGFI_FILE* file, uint32 offset, bool strict) 886 { 887 REGFI_HBIN* hbin; 888 REGFI_HBIN* sub_hbin; 889 REGFI_NK_REC* nk; 872 890 uint32 max_length, off; 873 891 874 hbin = regfi_lookup_hbin(file, offset-REGF _BLOCKSIZE);892 hbin = regfi_lookup_hbin(file, offset-REGFI_REGF_SIZE); 875 893 if (hbin == NULL) 876 894 return NULL; … … 879 897 max_length = hbin->block_size + hbin->file_off - offset; 880 898 if ((nk = regfi_parse_nk(file, offset, max_length, true)) == NULL) 881 return NULL; 899 { 900 regfi_add_message(file, "ERROR: Could not load NK record at" 901 " offset 0x%.8X.\n", offset); 902 return NULL; 903 } 882 904 883 905 /* fill in values */ 884 if(nk->num_values && (nk->values_off!=REGF _OFFSET_NONE))906 if(nk->num_values && (nk->values_off!=REGFI_OFFSET_NONE)) 885 907 { 886 908 sub_hbin = hbin; … … 901 923 else 902 924 { 903 off = nk->values_off + REGF _BLOCKSIZE;925 off = nk->values_off + REGFI_REGF_SIZE; 904 926 max_length = sub_hbin->block_size + sub_hbin->file_off - off; 905 927 nk->values = regfi_load_valuelist(file, off, nk->num_values, max_length, … … 907 929 if(strict && nk->values == NULL) 908 930 { 931 regfi_add_message(file, "ERROR: Could not load value list" 932 " for NK record at offset 0x%.8X.\n", 933 offset); 909 934 free(nk); 910 935 return NULL; … … 915 940 916 941 /* now get subkeys */ 917 if(nk->num_subkeys && (nk->subkeys_off != REGF _OFFSET_NONE))942 if(nk->num_subkeys && (nk->subkeys_off != REGFI_OFFSET_NONE)) 918 943 { 919 944 sub_hbin = hbin; … … 933 958 else 934 959 { 935 off = nk->subkeys_off + REGF _BLOCKSIZE;960 off = nk->subkeys_off + REGFI_REGF_SIZE; 936 961 max_length = sub_hbin->block_size + sub_hbin->file_off - off; 937 962 nk->subkeys = regfi_load_subkeylist(file, off, nk->num_subkeys, … … 953 978 954 979 /****************************************************************************** 955 956 980 ******************************************************************************/ 957 static bool regfi_find_root_nk(REGF _FILE* file, uint32 offset, uint32 hbin_size,981 static bool regfi_find_root_nk(REGFI_FILE* file, uint32 offset, uint32 hbin_size, 958 982 uint32* root_offset) 959 983 { … … 961 985 int32 record_size; 962 986 uint32 length, hbin_offset = 0; 963 REGF _NK_REC* nk = NULL;987 REGFI_NK_REC* nk = NULL; 964 988 bool found = false; 965 989 … … 980 1004 if(nk != NULL) 981 1005 { 982 if((nk->key_type == NK_TYPE_ROOTKEY1)983 || (nk->key_type == NK_TYPE_ROOTKEY2))1006 if((nk->key_type == REGFI_NK_TYPE_ROOTKEY1) 1007 || (nk->key_type == REGFI_NK_TYPE_ROOTKEY2)) 984 1008 { 985 1009 found = true; … … 1001 1025 * first hbin offset. 1002 1026 *******************************************************************/ 1003 REGF _FILE* regfi_open(const char* filename)1004 { 1005 REGF _FILE* rb;1006 REGF _HBIN* hbin = NULL;1027 REGFI_FILE* regfi_open(const char* filename) 1028 { 1029 REGFI_FILE* rb; 1030 REGFI_HBIN* hbin = NULL; 1007 1031 uint32 hbin_off; 1008 1032 int fd; … … 1034 1058 1035 1059 rla = true; 1036 hbin_off = REGF _BLOCKSIZE;1060 hbin_off = REGFI_REGF_SIZE; 1037 1061 hbin = regfi_parse_hbin(rb, hbin_off, true); 1038 1062 while(hbin && rla) … … 1050 1074 /******************************************************************* 1051 1075 *******************************************************************/ 1052 int regfi_close( REGF _FILE *file )1076 int regfi_close( REGFI_FILE *file ) 1053 1077 { 1054 1078 int fd; … … 1075 1099 * on my experience. --jerry 1076 1100 *****************************************************************************/ 1077 REGF _NK_REC* regfi_rootkey(REGF_FILE *file)1078 { 1079 REGF _NK_REC* nk = NULL;1080 REGF _HBIN* hbin;1101 REGFI_NK_REC* regfi_rootkey(REGFI_FILE *file) 1102 { 1103 REGFI_NK_REC* nk = NULL; 1104 REGFI_HBIN* hbin; 1081 1105 uint32 root_offset, i, num_hbins; 1082 1106 … … 1092 1116 for(i=0; i < num_hbins; i++) 1093 1117 { 1094 hbin = (REGF _HBIN*)range_list_get(file->hbins, i)->data;1095 if(regfi_find_root_nk(file, hbin->file_off+ HBIN_HEADER_REC_SIZE,1096 hbin->block_size- HBIN_HEADER_REC_SIZE, &root_offset))1118 hbin = (REGFI_HBIN*)range_list_get(file->hbins, i)->data; 1119 if(regfi_find_root_nk(file, hbin->file_off+REGFI_HBIN_HEADER_SIZE, 1120 hbin->block_size-REGFI_HBIN_HEADER_SIZE, &root_offset)) 1097 1121 { 1098 1122 nk = regfi_load_key(file, root_offset, true); … … 1107 1131 /****************************************************************************** 1108 1132 *****************************************************************************/ 1109 void regfi_key_free(REGF _NK_REC* nk)1133 void regfi_key_free(REGFI_NK_REC* nk) 1110 1134 { 1111 1135 uint32 i; 1112 1136 1113 if((nk->values != NULL) && (nk->values_off!=REGF _OFFSET_NONE))1137 if((nk->values != NULL) && (nk->values_off!=REGFI_OFFSET_NONE)) 1114 1138 { 1115 1139 for(i=0; i < nk->num_values; i++) … … 1131 1155 free(nk->classname); 1132 1156 1133 /* XXX: not freeing hbin because these are cached. This needs to be reviewed. */1134 1157 /* XXX: not freeing sec_desc because these are cached. This needs to be reviewed. */ 1135 1158 free(nk); … … 1139 1162 /****************************************************************************** 1140 1163 *****************************************************************************/ 1141 void regfi_subkeylist_free(REGF _SUBKEY_LIST* list)1164 void regfi_subkeylist_free(REGFI_SUBKEY_LIST* list) 1142 1165 { 1143 1166 if(list != NULL) … … 1151 1174 /****************************************************************************** 1152 1175 *****************************************************************************/ 1153 REGFI_ITERATOR* regfi_iterator_new(REGF _FILE* fh)1154 { 1155 REGF _NK_REC* root;1176 REGFI_ITERATOR* regfi_iterator_new(REGFI_FILE* fh) 1177 { 1178 REGFI_NK_REC* root; 1156 1179 REGFI_ITERATOR* ret_val = (REGFI_ITERATOR*)malloc(sizeof(REGFI_ITERATOR)); 1157 1180 if(ret_val == NULL) … … 1165 1188 } 1166 1189 1167 ret_val->key_positions = void_stack_new(REGF _MAX_DEPTH);1190 ret_val->key_positions = void_stack_new(REGFI_MAX_DEPTH); 1168 1191 if(ret_val->key_positions == NULL) 1169 1192 { … … 1217 1240 bool regfi_iterator_down(REGFI_ITERATOR* i) 1218 1241 { 1219 REGF _NK_REC* subkey;1242 REGFI_NK_REC* subkey; 1220 1243 REGFI_ITER_POSITION* pos; 1221 1244 … … 1224 1247 return false; 1225 1248 1226 subkey = (REGF _NK_REC*)regfi_iterator_cur_subkey(i);1249 subkey = (REGFI_NK_REC*)regfi_iterator_cur_subkey(i); 1227 1250 if(subkey == NULL) 1228 1251 { … … 1283 1306 bool regfi_iterator_find_subkey(REGFI_ITERATOR* i, const char* subkey_name) 1284 1307 { 1285 REGF _NK_REC* subkey;1308 REGFI_NK_REC* subkey; 1286 1309 bool found = false; 1287 1310 uint32 old_subkey = i->cur_subkey; … … 1291 1314 1292 1315 /* XXX: this alloc/free of each sub key might be a bit excessive */ 1293 subkey = (REGF _NK_REC*)regfi_iterator_first_subkey(i);1316 subkey = (REGFI_NK_REC*)regfi_iterator_first_subkey(i); 1294 1317 while((subkey != NULL) && (found == false)) 1295 1318 { … … 1300 1323 { 1301 1324 regfi_key_free(subkey); 1302 subkey = (REGF _NK_REC*)regfi_iterator_next_subkey(i);1325 subkey = (REGFI_NK_REC*)regfi_iterator_next_subkey(i); 1303 1326 } 1304 1327 } … … 1342 1365 /****************************************************************************** 1343 1366 *****************************************************************************/ 1344 const REGF _NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i)1367 const REGFI_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i) 1345 1368 { 1346 1369 return i->cur_key; … … 1350 1373 /****************************************************************************** 1351 1374 *****************************************************************************/ 1352 const REGF _SK_REC* regfi_iterator_cur_sk(REGFI_ITERATOR* i)1353 { 1354 REGF _SK_REC* ret_val;1355 REGF _HBIN* hbin;1375 const REGFI_SK_REC* regfi_iterator_cur_sk(REGFI_ITERATOR* i) 1376 { 1377 REGFI_SK_REC* ret_val; 1378 REGFI_HBIN* hbin; 1356 1379 uint32 max_length, off; 1357 1380 … … 1360 1383 1361 1384 /* First look if we have already parsed it */ 1362 if((i->cur_key->sk_off!=REGF _OFFSET_NONE)1363 && !(ret_val =(REGF _SK_REC*)lru_cache_find(i->sk_recs,1385 if((i->cur_key->sk_off!=REGFI_OFFSET_NONE) 1386 && !(ret_val =(REGFI_SK_REC*)lru_cache_find(i->sk_recs, 1364 1387 &i->cur_key->sk_off, 4))) 1365 1388 { … … 1369 1392 return NULL; 1370 1393 1371 off = i->cur_key->sk_off + REGF _BLOCKSIZE;1394 off = i->cur_key->sk_off + REGFI_REGF_SIZE; 1372 1395 max_length = hbin->block_size + hbin->file_off - off; 1373 1396 ret_val = regfi_parse_sk(i->f, off, max_length, true); … … 1386 1409 /****************************************************************************** 1387 1410 *****************************************************************************/ 1388 const REGF _NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i)1411 const REGFI_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i) 1389 1412 { 1390 1413 i->cur_subkey = 0; … … 1395 1418 /****************************************************************************** 1396 1419 *****************************************************************************/ 1397 const REGF _NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i)1420 const REGFI_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i) 1398 1421 { 1399 1422 uint32 nk_offset; 1400 1423 1401 1424 /* see if there is anything left to report */ 1402 if (!(i->cur_key) || (i->cur_key->subkeys_off==REGF _OFFSET_NONE)1425 if (!(i->cur_key) || (i->cur_key->subkeys_off==REGFI_OFFSET_NONE) 1403 1426 || (i->cur_subkey >= i->cur_key->num_subkeys)) 1404 1427 return NULL; … … 1406 1429 nk_offset = i->cur_key->subkeys->elements[i->cur_subkey].nk_off; 1407 1430 1408 return regfi_load_key(i->f, nk_offset+REGF _BLOCKSIZE, true);1431 return regfi_load_key(i->f, nk_offset+REGFI_REGF_SIZE, true); 1409 1432 } 1410 1433 … … 1413 1436 *****************************************************************************/ 1414 1437 /* XXX: some way of indicating reason for failure should be added. */ 1415 const REGF _NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i)1416 { 1417 const REGF _NK_REC* subkey;1438 const REGFI_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i) 1439 { 1440 const REGFI_NK_REC* subkey; 1418 1441 1419 1442 i->cur_subkey++; … … 1431 1454 bool regfi_iterator_find_value(REGFI_ITERATOR* i, const char* value_name) 1432 1455 { 1433 const REGF _VK_REC* cur;1456 const REGFI_VK_REC* cur; 1434 1457 bool found = false; 1435 1458 … … 1456 1479 /****************************************************************************** 1457 1480 *****************************************************************************/ 1458 const REGF _VK_REC* regfi_iterator_first_value(REGFI_ITERATOR* i)1481 const REGFI_VK_REC* regfi_iterator_first_value(REGFI_ITERATOR* i) 1459 1482 { 1460 1483 i->cur_value = 0; … … 1465 1488 /****************************************************************************** 1466 1489 *****************************************************************************/ 1467 const REGF _VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i)1468 { 1469 REGF _VK_REC* ret_val = NULL;1490 const REGFI_VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i) 1491 { 1492 REGFI_VK_REC* ret_val = NULL; 1470 1493 if(i->cur_value < i->cur_key->num_values) 1471 1494 ret_val = i->cur_key->values[i->cur_value]; … … 1477 1500 /****************************************************************************** 1478 1501 *****************************************************************************/ 1479 const REGF _VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i)1480 { 1481 const REGF _VK_REC* ret_val;1502 const REGFI_VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i) 1503 { 1504 const REGFI_VK_REC* ret_val; 1482 1505 1483 1506 i->cur_value++; … … 1516 1539 * XXX: Add way to return more detailed error information. 1517 1540 *******************************************************************/ 1518 REGF _FILE* regfi_parse_regf(int fd, bool strict)1519 { 1520 uint8 file_header[REGF _BLOCKSIZE];1541 REGFI_FILE* regfi_parse_regf(int fd, bool strict) 1542 { 1543 uint8 file_header[REGFI_REGF_SIZE]; 1521 1544 uint32 length; 1522 1545 uint32 file_length; 1523 1546 struct stat sbuf; 1524 REGF _FILE* ret_val;1547 REGFI_FILE* ret_val; 1525 1548 1526 1549 /* Determine file length. Must be at least big enough … … 1530 1553 return NULL; 1531 1554 file_length = sbuf.st_size; 1532 if(file_length < REGF _BLOCKSIZE+REGF_ALLOC_BLOCK)1533 return NULL; 1534 1535 ret_val = (REGF _FILE*)zalloc(sizeof(REGF_FILE));1555 if(file_length < REGFI_REGF_SIZE+REGFI_HBIN_ALLOC) 1556 return NULL; 1557 1558 ret_val = (REGFI_FILE*)zalloc(sizeof(REGFI_FILE)); 1536 1559 if(ret_val == NULL) 1537 1560 return NULL; … … 1540 1563 ret_val->file_length = file_length; 1541 1564 1542 length = REGF _BLOCKSIZE;1565 length = REGFI_REGF_SIZE; 1543 1566 if((regfi_read(fd, file_header, &length)) != 0 1544 || length != REGF _BLOCKSIZE)1567 || length != REGFI_REGF_SIZE) 1545 1568 { 1546 1569 free(ret_val); … … 1556 1579 } 1557 1580 1558 memcpy(ret_val->magic, file_header, 4);1559 if(strict && (memcmp(ret_val->magic, "regf", 4) != 0))1581 memcpy(ret_val->magic, file_header, REGFI_REGF_MAGIC_SIZE); 1582 if(strict && (memcmp(ret_val->magic, "regf", REGFI_REGF_MAGIC_SIZE) != 0)) 1560 1583 { 1561 1584 free(ret_val); … … 1590 1613 /* XXX: Need a way to return types of errors. 1591 1614 */ 1592 REGF _HBIN* regfi_parse_hbin(REGF_FILE* file, uint32 offset, bool strict)1593 { 1594 REGF _HBIN *hbin;1595 uint8 hbin_header[ HBIN_HEADER_REC_SIZE];1615 REGFI_HBIN* regfi_parse_hbin(REGFI_FILE* file, uint32 offset, bool strict) 1616 { 1617 REGFI_HBIN *hbin; 1618 uint8 hbin_header[REGFI_HBIN_HEADER_SIZE]; 1596 1619 uint32 length; 1597 1620 … … 1602 1625 return NULL; 1603 1626 1604 length = HBIN_HEADER_REC_SIZE;1627 length = REGFI_HBIN_HEADER_SIZE; 1605 1628 if((regfi_read(file->fd, hbin_header, &length) != 0) 1606 || length != HBIN_HEADER_REC_SIZE)1629 || length != REGFI_HBIN_HEADER_SIZE) 1607 1630 return NULL; 1608 1631 … … 1611 1634 return NULL; 1612 1635 1613 if(!(hbin = (REGF _HBIN*)zalloc(sizeof(REGF_HBIN))))1636 if(!(hbin = (REGFI_HBIN*)zalloc(sizeof(REGFI_HBIN)))) 1614 1637 return NULL; 1615 1638 hbin->file_off = offset; … … 1647 1670 /******************************************************************* 1648 1671 *******************************************************************/ 1649 REGF _NK_REC* regfi_parse_nk(REGF_FILE* file, uint32 offset,1672 REGFI_NK_REC* regfi_parse_nk(REGFI_FILE* file, uint32 offset, 1650 1673 uint32 max_size, bool strict) 1651 1674 { 1652 1675 uint8 nk_header[REGFI_NK_MIN_LENGTH]; 1653 REGF _HBIN *hbin;1654 REGF _NK_REC* ret_val;1676 REGFI_HBIN *hbin; 1677 REGFI_NK_REC* ret_val; 1655 1678 uint32 length,cell_length; 1656 1679 uint32 class_offset, class_maxsize; … … 1663 1686 /* A bit of validation before bothering to allocate memory */ 1664 1687 if((nk_header[0x0] != 'n') || (nk_header[0x1] != 'k')) 1665 return NULL; 1666 1667 ret_val = (REGF_NK_REC*)zalloc(sizeof(REGF_NK_REC)); 1688 { 1689 regfi_add_message(file, "ERROR: Magic number mismatch in parsing NK record" 1690 " at offset 0x%.8X.\n", offset); 1691 return NULL; 1692 } 1693 1694 ret_val = (REGFI_NK_REC*)zalloc(sizeof(REGFI_NK_REC)); 1668 1695 if(ret_val == NULL) 1669 return NULL; 1696 { 1697 regfi_add_message(file, "ERROR: Failed to allocate memory while" 1698 " parsing NK record at offset 0x%.8X.\n", offset); 1699 return NULL; 1700 } 1670 1701 1671 1702 ret_val->offset = offset; … … 1677 1708 || (strict && ret_val->cell_size != (ret_val->cell_size & 0xFFFFFFF8))) 1678 1709 { 1710 regfi_add_message(file, "ERROR: A length check failed while parsing" 1711 " NK record at offset 0x%.8X.\n", offset); 1679 1712 free(ret_val); 1680 1713 return NULL; … … 1684 1717 ret_val->magic[1] = nk_header[0x1]; 1685 1718 ret_val->key_type = SVAL(nk_header, 0x2); 1686 if((ret_val->key_type != NK_TYPE_NORMALKEY) 1687 && (ret_val->key_type != NK_TYPE_ROOTKEY1) 1688 && (ret_val->key_type != NK_TYPE_ROOTKEY2) 1689 && (ret_val->key_type != NK_TYPE_LINKKEY) 1690 && (ret_val->key_type != NK_TYPE_UNKNOWN1)) 1691 { 1719 if((ret_val->key_type != REGFI_NK_TYPE_NORMALKEY) 1720 && (ret_val->key_type != REGFI_NK_TYPE_ROOTKEY1) 1721 && (ret_val->key_type != REGFI_NK_TYPE_ROOTKEY2) 1722 && (ret_val->key_type != REGFI_NK_TYPE_LINKKEY) 1723 && (ret_val->key_type != REGFI_NK_TYPE_UNKNOWN1)) 1724 { 1725 regfi_add_message(file, "ERROR: Unknown key type (0x%.4X) while parsing" 1726 " NK record at offset 0x%.8X.\n", ret_val->key_type, 1727 offset); 1692 1728 free(ret_val); 1693 1729 return NULL; … … 1768 1804 ret_val->keyname[ret_val->name_length] = '\0'; 1769 1805 1770 if(ret_val->classname_off != REGF _OFFSET_NONE)1806 if(ret_val->classname_off != REGFI_OFFSET_NONE) 1771 1807 { 1772 1808 hbin = regfi_lookup_hbin(file, ret_val->classname_off); 1773 1809 if(hbin) 1774 1810 { 1775 class_offset = ret_val->classname_off+REGF _BLOCKSIZE;1811 class_offset = ret_val->classname_off+REGFI_REGF_SIZE; 1776 1812 class_maxsize = hbin->block_size + hbin->file_off - class_offset; 1777 1813 ret_val->classname … … 1791 1827 1792 1828 1793 char* regfi_parse_classname(REGF _FILE* file, uint32 offset,1829 char* regfi_parse_classname(REGFI_FILE* file, uint32 offset, 1794 1830 uint16* name_length, uint32 max_size, bool strict) 1795 1831 { … … 1799 1835 bool unalloc = false; 1800 1836 1801 if(*name_length > 0 && offset != REGF _OFFSET_NONE1837 if(*name_length > 0 && offset != REGFI_OFFSET_NONE 1802 1838 && offset == (offset & 0xFFFFFFF8)) 1803 1839 { … … 1843 1879 /******************************************************************* 1844 1880 *******************************************************************/ 1845 REGF _VK_REC* regfi_parse_vk(REGF_FILE* file, uint32 offset,1881 REGFI_VK_REC* regfi_parse_vk(REGFI_FILE* file, uint32 offset, 1846 1882 uint32 max_size, bool strict) 1847 1883 { 1848 REGF _VK_REC* ret_val;1849 REGF _HBIN *hbin;1884 REGFI_VK_REC* ret_val; 1885 REGFI_HBIN *hbin; 1850 1886 uint8 vk_header[REGFI_VK_MIN_LENGTH]; 1851 1887 uint32 raw_data_size, length, cell_length; … … 1857 1893 return NULL; 1858 1894 1859 ret_val = (REGF _VK_REC*)zalloc(sizeof(REGF_VK_REC));1895 ret_val = (REGFI_VK_REC*)zalloc(sizeof(REGFI_VK_REC)); 1860 1896 if(ret_val == NULL) 1861 1897 return NULL; … … 1887 1923 ret_val->name_length = SVAL(vk_header, 0x2); 1888 1924 raw_data_size = IVAL(vk_header, 0x4); 1889 ret_val->data_size = raw_data_size & ~ VK_DATA_IN_OFFSET;1890 ret_val->data_in_offset = (bool)(raw_data_size & VK_DATA_IN_OFFSET);1925 ret_val->data_size = raw_data_size & ~REGFI_VK_DATA_IN_OFFSET; 1926 ret_val->data_in_offset = (bool)(raw_data_size & REGFI_VK_DATA_IN_OFFSET); 1891 1927 ret_val->data_off = IVAL(vk_header, 0x8); 1892 1928 ret_val->type = IVAL(vk_header, 0xC); … … 1894 1930 ret_val->unknown1 = SVAL(vk_header, 0x12); 1895 1931 1896 if(ret_val->flag & VK_FLAG_NAME_PRESENT)1932 if(ret_val->flag & REGFI_VK_FLAG_NAME_PRESENT) 1897 1933 { 1898 1934 if(ret_val->name_length + REGFI_VK_MIN_LENGTH + 4 > ret_val->cell_size) … … 1954 1990 if(hbin) 1955 1991 { 1956 data_offset = ret_val->data_off+REGF _BLOCKSIZE;1992 data_offset = ret_val->data_off+REGFI_REGF_SIZE; 1957 1993 data_maxsize = hbin->block_size + hbin->file_off - data_offset; 1958 1994 ret_val->data = regfi_parse_data(file, data_offset, raw_data_size, … … 1976 2012 1977 2013 1978 uint8* regfi_parse_data(REGF _FILE* file, uint32 offset, uint32 length,2014 uint8* regfi_parse_data(REGFI_FILE* file, uint32 offset, uint32 length, 1979 2015 uint32 max_size, bool strict) 1980 2016 { … … 1985 2021 1986 2022 /* The data is stored in the offset if the size <= 4 */ 1987 if (length & VK_DATA_IN_OFFSET)1988 { 1989 length = length & ~ VK_DATA_IN_OFFSET;2023 if (length & REGFI_VK_DATA_IN_OFFSET) 2024 { 2025 length = length & ~REGFI_VK_DATA_IN_OFFSET; 1990 2026 if(length > 4) 1991 2027 return NULL; … … 1994 2030 return NULL; 1995 2031 1996 offset = offset - REGF _BLOCKSIZE;2032 offset = offset - REGFI_REGF_SIZE; 1997 2033 for(i = 0; i < length; i++) 1998 2034 ret_val[i] = (uint8)((offset >> i*8) & 0xFF); … … 2043 2079 2044 2080 2045 range_list* regfi_parse_unalloc_cells(REGF _FILE* file)2081 range_list* regfi_parse_unalloc_cells(REGFI_FILE* file) 2046 2082 { 2047 2083 range_list* ret_val; 2048 REGF _HBIN* hbin;2084 REGFI_HBIN* hbin; 2049 2085 const range_list_element* hbins_elem; 2050 2086 uint32 i, num_hbins, curr_off, cell_len; … … 2061 2097 if(hbins_elem == NULL) 2062 2098 break; 2063 hbin = (REGF _HBIN*)hbins_elem->data;2064 2065 curr_off = HBIN_HEADER_REC_SIZE;2099 hbin = (REGFI_HBIN*)hbins_elem->data; 2100 2101 curr_off = REGFI_HBIN_HEADER_SIZE; 2066 2102 while(curr_off < hbin->block_size) 2067 2103 { -
trunk/src/reglookup-recover.c
r130 r135 67 67 68 68 69 void printKey(REGF _FILE* f, REGF_NK_REC* nk, const char* prefix)69 void printKey(REGFI_FILE* f, REGFI_NK_REC* nk, const char* prefix) 70 70 { 71 71 char mtime[20]; … … 102 102 103 103 104 void printValue(REGF _FILE* f, const REGF_VK_REC* vk, const char* prefix)104 void printValue(REGFI_FILE* f, const REGFI_VK_REC* vk, const char* prefix) 105 105 { 106 106 char* quoted_value = NULL; … … 122 122 * stderr/stdout don't always sync nicely. 123 123 */ 124 if(size > VK_MAX_DATA_LENGTH)124 if(size > REGFI_VK_MAX_DATA_LENGTH) 125 125 { 126 126 fprintf(stderr, "WARNING: value data size %d larger than " 127 "%d, truncating...\n", size, VK_MAX_DATA_LENGTH);128 size = VK_MAX_DATA_LENGTH;127 "%d, truncating...\n", size, REGFI_VK_MAX_DATA_LENGTH); 128 size = REGFI_VK_MAX_DATA_LENGTH; 129 129 } 130 130 … … 188 188 189 189 190 void printSK(REGF _FILE* f, REGF_SK_REC* sk)190 void printSK(REGFI_FILE* f, REGFI_SK_REC* sk) 191 191 { 192 192 char* quoted_raw = NULL; … … 226 226 227 227 228 int printCell(REGF _FILE* f, uint32 offset)228 int printCell(REGFI_FILE* f, uint32 offset) 229 229 { 230 230 char* quoted_buf; … … 254 254 * together is slow and redundant. 255 255 */ 256 char* getParentPath(REGF _FILE* f, REGF_NK_REC* nk)257 { 258 void_stack* path_stack = void_stack_new(REGF _MAX_DEPTH);259 REGF _HBIN* hbin;260 REGF _NK_REC* cur_ancestor;256 char* getParentPath(REGFI_FILE* f, REGFI_NK_REC* nk) 257 { 258 void_stack* path_stack = void_stack_new(REGFI_MAX_DEPTH); 259 REGFI_HBIN* hbin; 260 REGFI_NK_REC* cur_ancestor; 261 261 char* ret_val; 262 262 char* path_element; … … 267 267 /* The path_stack size limit should guarantee that we don't recurse forever. */ 268 268 virt_offset = nk->parent_off; 269 while(virt_offset != REGF _OFFSET_NONE)269 while(virt_offset != REGFI_OFFSET_NONE) 270 270 { 271 271 hbin = regfi_lookup_hbin(f, virt_offset); 272 272 if(hbin == NULL) 273 virt_offset = REGF _OFFSET_NONE;273 virt_offset = REGFI_OFFSET_NONE; 274 274 else 275 275 { 276 276 max_length = hbin->block_size + hbin->file_off 277 - (virt_offset+REGF _BLOCKSIZE);278 cur_ancestor = regfi_parse_nk(f, virt_offset+REGF _BLOCKSIZE,277 - (virt_offset+REGFI_REGF_SIZE); 278 cur_ancestor = regfi_parse_nk(f, virt_offset+REGFI_REGF_SIZE, 279 279 max_length, true); 280 280 if(cur_ancestor == NULL) 281 virt_offset = REGF _OFFSET_NONE;281 virt_offset = REGFI_OFFSET_NONE; 282 282 else 283 283 { 284 if((cur_ancestor->key_type == NK_TYPE_ROOTKEY1)285 || (cur_ancestor->key_type == NK_TYPE_ROOTKEY2))286 virt_offset = REGF _OFFSET_NONE;284 if((cur_ancestor->key_type == REGFI_NK_TYPE_ROOTKEY1) 285 || (cur_ancestor->key_type == REGFI_NK_TYPE_ROOTKEY2)) 286 virt_offset = REGFI_OFFSET_NONE; 287 287 else 288 288 virt_offset = cur_ancestor->parent_off; … … 415 415 416 416 /* NOTE: unalloc_keys should be an empty range_list. */ 417 int extractKeys(REGF _FILE* f,417 int extractKeys(REGFI_FILE* f, 418 418 range_list* unalloc_cells, 419 419 range_list* unalloc_keys) 420 420 { 421 421 const range_list_element* cur_elem; 422 REGF _NK_REC* key;422 REGFI_NK_REC* key; 423 423 uint32 i, j; 424 424 … … 455 455 456 456 457 int extractValueLists(REGF _FILE* f,457 int extractValueLists(REGFI_FILE* f, 458 458 range_list* unalloc_cells, 459 459 range_list* unalloc_keys) 460 460 { 461 REGF _NK_REC* nk;462 REGF _HBIN* hbin;461 REGFI_NK_REC* nk; 462 REGFI_HBIN* hbin; 463 463 const range_list_element* cur_elem; 464 464 uint32 i, j, num_keys, off, values_length, max_length; … … 472 472 nk = cur_elem->data; 473 473 474 if(nk->num_values && (nk->values_off!=REGF _OFFSET_NONE))474 if(nk->num_values && (nk->values_off!=REGFI_OFFSET_NONE)) 475 475 { 476 476 hbin = regfi_lookup_hbin(f, nk->values_off); … … 478 478 if(hbin != NULL) 479 479 { 480 off = nk->values_off + REGF _BLOCKSIZE;480 off = nk->values_off + REGFI_REGF_SIZE; 481 481 max_length = hbin->block_size + hbin->file_off - off; 482 482 /* XXX: This is a hack. We parse all value-lists, VK records, … … 546 546 if(nk->values[j]->data != NULL && !nk->values[j]->data_in_offset) 547 547 { 548 off = nk->values[j]->data_off+REGF _BLOCKSIZE;548 off = nk->values[j]->data_off+REGFI_REGF_SIZE; 549 549 if(!range_list_has_range(unalloc_cells, off, 550 550 nk->values[j]->data_size)) … … 576 576 577 577 /* NOTE: unalloc_values should be an empty range_list. */ 578 int extractValues(REGF _FILE* f,578 int extractValues(REGFI_FILE* f, 579 579 range_list* unalloc_cells, 580 580 range_list* unalloc_values) 581 581 { 582 582 const range_list_element* cur_elem; 583 REGF _VK_REC* vk;583 REGFI_VK_REC* vk; 584 584 uint32 i, j, off; 585 585 … … 616 616 { 617 617 cur_elem = range_list_get(unalloc_values, i); 618 vk = (REGF _VK_REC*)cur_elem->data;618 vk = (REGFI_VK_REC*)cur_elem->data; 619 619 if(vk == NULL) 620 620 return 40; … … 622 622 if(vk->data != NULL && !vk->data_in_offset) 623 623 { 624 off = vk->data_off+REGF _BLOCKSIZE;624 off = vk->data_off+REGFI_REGF_SIZE; 625 625 if(!range_list_has_range(unalloc_cells, off, vk->data_size)) 626 626 { /* We've parsed a data cell which isn't in the unallocated … … 643 643 644 644 /* NOTE: unalloc_sks should be an empty range_list. */ 645 int extractSKs(REGF _FILE* f,645 int extractSKs(REGFI_FILE* f, 646 646 range_list* unalloc_cells, 647 647 range_list* unalloc_sks) 648 648 { 649 649 const range_list_element* cur_elem; 650 REGF _SK_REC* sk;650 REGFI_SK_REC* sk; 651 651 uint32 i, j; 652 652 … … 684 684 int main(int argc, char** argv) 685 685 { 686 REGF _FILE* f;686 REGFI_FILE* f; 687 687 const range_list_element* cur_elem; 688 688 range_list* unalloc_cells; … … 693 693 char* tmp_name; 694 694 char* tmp_path; 695 REGF _NK_REC* tmp_key;696 REGF _VK_REC* tmp_value;695 REGFI_NK_REC* tmp_key; 696 REGFI_VK_REC* tmp_value; 697 697 uint32 argi, arge, i, j, ret, num_unalloc_keys; 698 698 /* uint32 test_offset;*/ … … 806 806 { 807 807 cur_elem = range_list_get(unalloc_keys, i); 808 tmp_key = (REGF _NK_REC*)cur_elem->data;808 tmp_key = (REGFI_NK_REC*)cur_elem->data; 809 809 810 810 if(tmp_key == NULL) … … 821 821 { 822 822 cur_elem = range_list_get(unalloc_keys, i); 823 tmp_key = (REGF _NK_REC*)cur_elem->data;823 tmp_key = (REGFI_NK_REC*)cur_elem->data; 824 824 825 825 printKey(f, tmp_key, parent_paths[i]); … … 848 848 { 849 849 cur_elem = range_list_get(unalloc_values, i); 850 tmp_value = (REGF _VK_REC*)cur_elem->data;850 tmp_value = (REGFI_VK_REC*)cur_elem->data; 851 851 852 852 printValue(f, tmp_value, ""); -
trunk/src/reglookup.c
r126 r135 1 1 /* 2 * A utility to read a Windows NT/2K/XP/2K3 registry file, using 3 * Gerald Carter''s regfio interface. 2 * A utility to read a Windows NT and later registry files. 4 3 * 5 * Copyright (C) 2005-200 8Timothy D. Morgan4 * Copyright (C) 2005-2009 Timothy D. Morgan 6 5 * Copyright (C) 2002 Richard Sharpe, rsharpe@richardsharpe.com 7 6 * … … 43 42 44 43 /* Other globals */ 45 REGF _FILE* f;44 REGFI_FILE* f; 46 45 47 46 … … 52 51 53 52 54 void printValue(const REGF _VK_REC* vk, char* prefix)53 void printValue(const REGFI_VK_REC* vk, char* prefix) 55 54 { 56 55 char* quoted_value = NULL; … … 66 65 * http://msdn2.microsoft.com/en-us/library/ms724872.aspx 67 66 */ 68 if(size > VK_MAX_DATA_LENGTH)67 if(size > REGFI_VK_MAX_DATA_LENGTH) 69 68 { 70 69 fprintf(stderr, "WARNING: value data size %d larger than " 71 "%d, truncating...\n", size, VK_MAX_DATA_LENGTH);72 size = VK_MAX_DATA_LENGTH;70 "%d, truncating...\n", size, REGFI_VK_MAX_DATA_LENGTH); 71 size = REGFI_VK_MAX_DATA_LENGTH; 73 72 } 74 73 … … 143 142 uint32 ret_cur = 0; 144 143 145 ret_val = (char**)malloc((REGF _MAX_DEPTH+1+1)*sizeof(char**));144 ret_val = (char**)malloc((REGFI_MAX_DEPTH+1+1)*sizeof(char**)); 146 145 if (ret_val == NULL) 147 146 return NULL; … … 163 162 copy[next-cur] = '\0'; 164 163 ret_val[ret_cur++] = copy; 165 if(ret_cur < (REGF _MAX_DEPTH+1+1))164 if(ret_cur < (REGFI_MAX_DEPTH+1+1)) 166 165 ret_val[ret_cur] = NULL; 167 166 else … … 176 175 copy = strdup(cur); 177 176 ret_val[ret_cur++] = copy; 178 if(ret_cur < (REGF _MAX_DEPTH+1+1))177 if(ret_cur < (REGFI_MAX_DEPTH+1+1)) 179 178 ret_val[ret_cur] = NULL; 180 179 else … … 275 274 void printValueList(REGFI_ITERATOR* i, char* prefix) 276 275 { 277 const REGF _VK_REC* value;276 const REGFI_VK_REC* value; 278 277 279 278 value = regfi_iterator_first_value(i); … … 299 298 time_t tmp_time[1]; 300 299 struct tm* tmp_time_s = NULL; 301 const REGF _SK_REC* sk;302 const REGF _NK_REC* k = regfi_iterator_cur_key(i);300 const REGFI_SK_REC* sk; 301 const REGFI_NK_REC* k = regfi_iterator_cur_key(i); 303 302 304 303 *tmp_time = nt_time_to_unix(&k->mtime); … … 369 368 void printKeyTree(REGFI_ITERATOR* iter) 370 369 { 371 const REGF _NK_REC* root = NULL;372 const REGF _NK_REC* cur = NULL;373 const REGF _NK_REC* sub = NULL;370 const REGFI_NK_REC* root = NULL; 371 const REGFI_NK_REC* cur = NULL; 372 const REGFI_NK_REC* sub = NULL; 374 373 char* path = NULL; 375 374 int key_type = regfi_type_str2val("KEY"); … … 441 440 int retrievePath(REGFI_ITERATOR* iter, char** path) 442 441 { 443 const REGF _VK_REC* value;442 const REGFI_VK_REC* value; 444 443 char* tmp_path_joined; 445 444 const char** tmp_path; … … 450 449 451 450 /* One extra for any value at the end, and one more for NULL */ 452 tmp_path = (const char**)malloc(sizeof(const char**)*(REGF _MAX_DEPTH+1+1));451 tmp_path = (const char**)malloc(sizeof(const char**)*(REGFI_MAX_DEPTH+1+1)); 453 452 if(tmp_path == NULL) 454 453 return -2; … … 457 456 for(i=0; 458 457 (path[i] != NULL) && (path[i+1] != NULL) 459 && (i < REGF _MAX_DEPTH+1+1);458 && (i < REGFI_MAX_DEPTH+1+1); 460 459 i++) 461 460 tmp_path[i] = path[i];
Note: See TracChangeset
for help on using the changeset viewer.