- Timestamp:
- 02/18/09 23:46:37 (16 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/regfi.h
r145 r146 158 158 159 159 160 161 160 /* HBIN block */ 162 161 typedef struct _regfi_hbin … … 258 257 WINSEC_DESC* sec_desc; 259 258 uint32 hbin_off; /* offset from beginning of this hbin block */ 260 261 uint32 sk_off; /* offset parsed from NK record used as a key262 * to lookup reference to this SK record263 */264 259 265 260 uint32 prev_sk_off; … … 330 325 /* Metadata about hbins */ 331 326 range_list* hbins; 327 328 /* SK record cached since they're repeatedly reused */ 329 lru_cache* sk_cache; 332 330 333 331 /* Error/warning/info messages returned by lower layer functions */ … … 375 373 REGFI_FILE* f; 376 374 void_stack* key_positions; 377 lru_cache* sk_recs;378 375 REGFI_NK_REC* cur_key; 379 376 uint32 cur_subkey; … … 384 381 typedef struct 385 382 { 386 /* XXX: Should probably eliminate the storage of keys here387 * once key caching is implemented.388 */389 383 REGFI_NK_REC* nk; 390 384 uint32 cur_subkey; … … 437 431 438 432 /********************************************************/ 439 /* Middle-layer structure caching, loading, and linking */433 /* Middle-layer structure loading, linking, and caching */ 440 434 /********************************************************/ 441 REGFI_HBIN* regfi_lookup_hbin(REGFI_FILE* file, uint32 voffset);442 435 REGFI_NK_REC* regfi_load_key(REGFI_FILE* file, uint32 offset, 443 436 bool strict); 444 REGFI_SUBKEY_LIST* regfi_load_subkeylist(REGFI_FILE* file, uint32 offset,445 uint32 num_keys, uint32 max_size,446 bool strict);447 437 REGFI_VK_REC* regfi_load_value(REGFI_FILE* file, uint32 offset, 448 438 bool strict); 439 REGFI_SUBKEY_LIST* regfi_load_subkeylist(REGFI_FILE* file, uint32 offset, 440 uint32 num_keys, uint32 max_size, 441 bool strict); 449 442 REGFI_VALUE_LIST* regfi_load_valuelist(REGFI_FILE* file, uint32 offset, 450 uint32 num_values, uint32 max_size, 443 uint32 num_values, uint32 max_size, 451 444 bool strict); 445 446 /* These are cached so return values don't need to be freed. */ 447 const REGFI_SK_REC* regfi_load_sk(REGFI_FILE* file, uint32 offset, 448 bool strict); 449 const REGFI_HBIN* regfi_lookup_hbin(REGFI_FILE* file, uint32 voffset); 450 451 452 452 453 453 /************************************/ … … 522 522 void regfi_add_message(REGFI_FILE* file, uint16 msg_type, 523 523 const char* fmt, ...); 524 REGFI_NK_REC* regfi_copy_nk(const REGFI_NK_REC* nk); 525 REGFI_VK_REC* regfi_copy_vk(const REGFI_VK_REC* vk); 526 524 527 #endif /* _REGFI_H */ -
trunk/lib/lru_cache.c
r136 r146 106 106 107 107 if(max_keys == 0) 108 ret_val->num_buckets = 2048;108 ret_val->num_buckets = 1024; 109 109 else 110 110 { -
trunk/lib/regfi.c
r145 r146 475 475 * The offset is a virtual file offset. 476 476 *******************************************************************/ 477 static bool regfi_offset_in_hbin( REGFI_HBIN* hbin, uint32 voffset)477 static bool regfi_offset_in_hbin(const REGFI_HBIN* hbin, uint32 voffset) 478 478 { 479 479 if(!hbin) … … 493 493 * block for it. NULL if one doesn't exist. 494 494 *******************************************************************/ 495 REGFI_HBIN* regfi_lookup_hbin(REGFI_FILE* file, uint32 voffset) 496 { 497 return (REGFI_HBIN*)range_list_find_data(file->hbins, voffset+REGFI_REGF_SIZE); 495 const REGFI_HBIN* regfi_lookup_hbin(REGFI_FILE* file, uint32 voffset) 496 { 497 return (const REGFI_HBIN*)range_list_find_data(file->hbins, 498 voffset+REGFI_REGF_SIZE); 498 499 } 499 500 … … 541 542 REGFI_SUBKEY_LIST* ret_val; 542 543 REGFI_SUBKEY_LIST** sublists; 543 REGFI_HBIN* sublist_hbin;544 const REGFI_HBIN* sublist_hbin; 544 545 uint32 i, num_sublists, off, max_length; 545 546 … … 956 957 /****************************************************************************** 957 958 ******************************************************************************/ 958 REGFI_VK_REC* regfi_load_value(REGFI_FILE* file, uint32 offset, bool strict) 959 REGFI_VK_REC* regfi_load_value(REGFI_FILE* file, uint32 offset, 960 bool strict) 959 961 { 960 962 REGFI_VK_REC* ret_val = NULL; 961 REGFI_HBIN* hbin;963 const REGFI_HBIN* hbin; 962 964 uint32 data_offset, data_maxsize; 963 965 … … 1018 1020 ******************************************************************************/ 1019 1021 REGFI_VALUE_LIST* regfi_load_valuelist(REGFI_FILE* file, uint32 offset, 1020 uint32 num_values, uint32 max_size, 1022 uint32 num_values, uint32 max_size, 1021 1023 bool strict) 1022 1024 { … … 1041 1043 1042 1044 1043 /******************************************************************* 1044 * XXX: Need to add full key caching using a 1045 * custom cache structure. 1046 *******************************************************************/ 1045 /****************************************************************************** 1046 * 1047 ******************************************************************************/ 1047 1048 REGFI_NK_REC* regfi_load_key(REGFI_FILE* file, uint32 offset, bool strict) 1048 1049 { 1049 REGFI_HBIN* hbin;1050 REGFI_HBIN* sub_hbin;1050 const REGFI_HBIN* hbin; 1051 const REGFI_HBIN* sub_hbin; 1051 1052 REGFI_NK_REC* nk; 1052 1053 uint32 max_length, off; … … 1058 1059 /* get the initial nk record */ 1059 1060 max_length = hbin->block_size + hbin->file_off - offset; 1060 if 1061 if((nk = regfi_parse_nk(file, offset, max_length, true)) == NULL) 1061 1062 { 1062 1063 regfi_add_message(file, REGFI_MSG_ERROR, "Could not load NK record at" … … 1065 1066 } 1066 1067 1067 /* fill in values*/1068 /* get value list */ 1068 1069 if(nk->num_values && (nk->values_off!=REGFI_OFFSET_NONE)) 1069 1070 { … … 1102 1103 } 1103 1104 1104 /* now get subkey s*/1105 /* now get subkey list */ 1105 1106 if(nk->num_subkeys && (nk->subkeys_off != REGFI_OFFSET_NONE)) 1106 1107 { … … 1141 1142 /****************************************************************************** 1142 1143 ******************************************************************************/ 1143 static bool regfi_find_root_nk(REGFI_FILE* file, uint32 offset, uint32 hbin_size, 1144 const REGFI_SK_REC* regfi_load_sk(REGFI_FILE* file, uint32 offset, bool strict) 1145 { 1146 REGFI_SK_REC* ret_val = NULL; 1147 const REGFI_HBIN* hbin; 1148 uint32 max_length; 1149 1150 /* First look if we have already parsed it */ 1151 ret_val = (REGFI_SK_REC*)lru_cache_find(file->sk_cache, &offset, 4); 1152 1153 /* Bail out if we have previously cached a parse failure at this offset. */ 1154 if(ret_val == (void*)REGFI_OFFSET_NONE) 1155 return NULL; 1156 1157 if(ret_val == NULL) 1158 { 1159 hbin = regfi_lookup_hbin(file, offset - REGFI_REGF_SIZE); 1160 if(hbin == NULL) 1161 return NULL; 1162 1163 max_length = hbin->block_size + hbin->file_off - offset; 1164 ret_val = regfi_parse_sk(file, offset, max_length, strict); 1165 if(ret_val == NULL) 1166 { /* Cache the parse failure and bail out. */ 1167 lru_cache_update(file->sk_cache, &offset, 4, (void*)REGFI_OFFSET_NONE); 1168 return NULL; 1169 } 1170 1171 lru_cache_update(file->sk_cache, &offset, 4, ret_val); 1172 } 1173 1174 return ret_val; 1175 } 1176 1177 1178 1179 /****************************************************************************** 1180 ******************************************************************************/ 1181 static bool regfi_find_root_nk(REGFI_FILE* file, uint32 offset,uint32 hbin_size, 1144 1182 uint32* root_offset) 1145 1183 { … … 1192 1230 REGFI_FILE* rb; 1193 1231 REGFI_HBIN* hbin = NULL; 1194 uint32 hbin_off, file_length ;1232 uint32 hbin_off, file_length, cache_secret; 1195 1233 int fd; 1196 1234 bool rla; … … 1241 1279 } 1242 1280 1281 1282 /* This secret isn't very secret, but we don't need a good one. This 1283 * secret is just designed to prevent someone from trying to blow our 1284 * caching and make things slow. 1285 */ 1286 cache_secret = 0x15DEAD05^time(NULL)^(getpid()<<16); 1287 1288 /* Cache an unlimited number of SK records. Typically there are very few. */ 1289 rb->sk_cache = lru_cache_create(0, cache_secret, true); 1290 1243 1291 /* Default message mask */ 1244 1292 rb->msg_mask = REGFI_MSG_ERROR|REGFI_MSG_WARN; … … 1251 1299 /******************************************************************* 1252 1300 *******************************************************************/ 1253 int regfi_close( REGFI_FILE *file)1301 int regfi_close(REGFI_FILE *file) 1254 1302 { 1255 1303 int fd; … … 1266 1314 range_list_free(file->hbins); 1267 1315 1316 if(file->sk_cache != NULL) 1317 lru_cache_destroy(file->sk_cache); 1268 1318 free(file); 1269 1319 … … 1279 1329 { 1280 1330 REGFI_NK_REC* nk = NULL; 1281 REGFI_HBIN* 1282 uint32 1331 REGFI_HBIN* hbin; 1332 uint32 root_offset, i, num_hbins; 1283 1333 1284 1334 if(!file) … … 1286 1336 1287 1337 /* Scan through the file one HBIN block at a time looking 1288 for an NK record with a type == 0x002c.1289 Normally this is the first nk record in the first hbin1290 block (but I'm not assuming that for now) */1291 1338 * for an NK record with a root key type. 1339 * This is typically the first NK record in the first HBIN 1340 * block (but we're not assuming that generally). 1341 */ 1292 1342 num_hbins = range_list_size(file->hbins); 1293 1343 for(i=0; i < num_hbins; i++) … … 1361 1411 { 1362 1412 free(ret_val); 1363 free(root); 1364 return NULL; 1365 } 1366 1367 /* This secret isn't very secret, but we don't need a good one. This 1368 * secret is just designed to prevent someone from trying to blow our 1369 * caching and make things slow. 1370 */ 1371 ret_val->sk_recs = lru_cache_create(127, 0x15DEAD05^time(NULL)^(getpid()<<16), 1372 true); 1413 return NULL; 1414 } 1373 1415 1374 1416 ret_val->f = fh; … … 1396 1438 } 1397 1439 1398 lru_cache_destroy(i->sk_recs); 1399 1440 void_stack_free(i->key_positions); 1400 1441 free(i); 1401 1442 } … … 1543 1584 const REGFI_SK_REC* regfi_iterator_cur_sk(REGFI_ITERATOR* i) 1544 1585 { 1545 REGFI_SK_REC* ret_val = NULL; 1546 REGFI_HBIN* hbin; 1547 uint32 max_length, off; 1548 1549 if(i->cur_key == NULL) 1550 return NULL; 1551 1552 /* First look if we have already parsed it */ 1553 if((i->cur_key->sk_off!=REGFI_OFFSET_NONE) 1554 && !(ret_val =(REGFI_SK_REC*)lru_cache_find(i->sk_recs, 1555 &i->cur_key->sk_off, 4))) 1556 { 1557 hbin = regfi_lookup_hbin(i->f, i->cur_key->sk_off); 1558 1559 if(hbin == NULL) 1560 return NULL; 1561 1562 off = i->cur_key->sk_off + REGFI_REGF_SIZE; 1563 max_length = hbin->block_size + hbin->file_off - off; 1564 ret_val = regfi_parse_sk(i->f, off, max_length, true); 1565 if(ret_val == NULL) 1566 return NULL; 1567 1568 ret_val->sk_off = i->cur_key->sk_off; 1569 lru_cache_update(i->sk_recs, &i->cur_key->sk_off, 4, ret_val); 1570 } 1571 1572 return ret_val; 1573 } 1574 1586 if(i->cur_key == NULL || i->cur_key->sk_off == REGFI_OFFSET_NONE) 1587 return NULL; 1588 1589 return regfi_load_sk(i->f, i->cur_key->sk_off + REGFI_REGF_SIZE, true); 1590 } 1575 1591 1576 1592 … … 1658 1674 const REGFI_VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i) 1659 1675 { 1660 REGFI_VK_REC* ret_val = NULL;1676 const REGFI_VK_REC* ret_val = NULL; 1661 1677 uint32 voffset; 1662 1678 … … 1687 1703 return ret_val; 1688 1704 } 1689 1690 1705 1691 1706 … … 1852 1867 { 1853 1868 uint8 nk_header[REGFI_NK_MIN_LENGTH]; 1854 REGFI_HBIN *hbin;1869 const REGFI_HBIN *hbin; 1855 1870 REGFI_NK_REC* ret_val; 1856 1871 uint32 length,cell_length; -
trunk/src/reglookup-recover.c
r145 r146 257 257 { 258 258 void_stack* path_stack = void_stack_new(REGFI_MAX_DEPTH); 259 REGFI_HBIN* hbin;259 const REGFI_HBIN* hbin; 260 260 REGFI_NK_REC* cur_ancestor; 261 261 char* ret_val; … … 465 465 const range_list_element* cur_elem; 466 466 REGFI_VK_REC* vk; 467 REGFI_HBIN* hbin;467 const REGFI_HBIN* hbin; 468 468 uint32 i, off, data_offset, data_maxsize; 469 469 … … 570 570 REGFI_NK_REC* nk; 571 571 REGFI_VK_REC* vk; 572 REGFI_HBIN* hbin;572 const REGFI_HBIN* hbin; 573 573 const range_list_element* cur_elem; 574 574 uint32 i, j, num_keys, off, values_length, max_length;
Note: See TracChangeset
for help on using the changeset viewer.