- Timestamp:
- 01/21/09 05:27:32 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 {
Note: See TracChangeset
for help on using the changeset viewer.