Changeset 135 for trunk/src


Ignore:
Timestamp:
01/21/09 05:27:32 (16 years ago)
Author:
tim
Message:

cleaned up regfi API

started adding debugging infrastructure, but currently broken

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/reglookup-recover.c

    r130 r135  
    6767
    6868
    69 void printKey(REGF_FILE* f, REGF_NK_REC* nk, const char* prefix)
     69void printKey(REGFI_FILE* f, REGFI_NK_REC* nk, const char* prefix)
    7070{
    7171  char mtime[20];
     
    102102
    103103
    104 void printValue(REGF_FILE* f, const REGF_VK_REC* vk, const char* prefix)
     104void printValue(REGFI_FILE* f, const REGFI_VK_REC* vk, const char* prefix)
    105105{
    106106  char* quoted_value = NULL;
     
    122122   *      stderr/stdout don't always sync nicely.
    123123   */
    124   if(size > VK_MAX_DATA_LENGTH)
     124  if(size > REGFI_VK_MAX_DATA_LENGTH)
    125125  {
    126126    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;
    129129  }
    130130 
     
    188188
    189189
    190 void printSK(REGF_FILE* f, REGF_SK_REC* sk)
     190void printSK(REGFI_FILE* f, REGFI_SK_REC* sk)
    191191{
    192192  char* quoted_raw = NULL;
     
    226226
    227227
    228 int printCell(REGF_FILE* f, uint32 offset)
     228int printCell(REGFI_FILE* f, uint32 offset)
    229229{
    230230  char* quoted_buf;
     
    254254 *      together is slow and redundant.
    255255 */
    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;
     256char* 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;
    261261  char* ret_val;
    262262  char* path_element;
     
    267267  /* The path_stack size limit should guarantee that we don't recurse forever. */
    268268  virt_offset = nk->parent_off;
    269   while(virt_offset != REGF_OFFSET_NONE)
     269  while(virt_offset != REGFI_OFFSET_NONE)
    270270  { 
    271271    hbin = regfi_lookup_hbin(f, virt_offset);
    272272    if(hbin == NULL)
    273       virt_offset = REGF_OFFSET_NONE;
     273      virt_offset = REGFI_OFFSET_NONE;
    274274    else
    275275    {
    276276      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,
    279279                                    max_length, true);
    280280      if(cur_ancestor == NULL)
    281         virt_offset = REGF_OFFSET_NONE;
     281        virt_offset = REGFI_OFFSET_NONE;
    282282      else
    283283      {
    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;
    287287        else
    288288          virt_offset = cur_ancestor->parent_off;
     
    415415
    416416/* NOTE: unalloc_keys should be an empty range_list. */
    417 int extractKeys(REGF_FILE* f,
     417int extractKeys(REGFI_FILE* f,
    418418                range_list* unalloc_cells,
    419419                range_list* unalloc_keys)
    420420{
    421421  const range_list_element* cur_elem;
    422   REGF_NK_REC* key;
     422  REGFI_NK_REC* key;
    423423  uint32 i, j;
    424424
     
    455455
    456456
    457 int extractValueLists(REGF_FILE* f,
     457int extractValueLists(REGFI_FILE* f,
    458458                      range_list* unalloc_cells,
    459459                      range_list* unalloc_keys)
    460460{
    461   REGF_NK_REC* nk;
    462   REGF_HBIN* hbin;
     461  REGFI_NK_REC* nk;
     462  REGFI_HBIN* hbin;
    463463  const range_list_element* cur_elem;
    464464  uint32 i, j, num_keys, off, values_length, max_length;
     
    472472    nk = cur_elem->data;
    473473
    474     if(nk->num_values && (nk->values_off!=REGF_OFFSET_NONE))
     474    if(nk->num_values && (nk->values_off!=REGFI_OFFSET_NONE))
    475475    {
    476476      hbin = regfi_lookup_hbin(f, nk->values_off);
     
    478478      if(hbin != NULL)
    479479      {
    480         off = nk->values_off + REGF_BLOCKSIZE;
     480        off = nk->values_off + REGFI_REGF_SIZE;
    481481        max_length = hbin->block_size + hbin->file_off - off;
    482482        /* XXX: This is a hack.  We parse all value-lists, VK records,
     
    546546                  if(nk->values[j]->data != NULL && !nk->values[j]->data_in_offset)
    547547                  {
    548                     off = nk->values[j]->data_off+REGF_BLOCKSIZE;
     548                    off = nk->values[j]->data_off+REGFI_REGF_SIZE;
    549549                    if(!range_list_has_range(unalloc_cells, off,
    550550                                             nk->values[j]->data_size))
     
    576576
    577577/* NOTE: unalloc_values should be an empty range_list. */
    578 int extractValues(REGF_FILE* f,
     578int extractValues(REGFI_FILE* f,
    579579                  range_list* unalloc_cells,
    580580                  range_list* unalloc_values)
    581581{
    582582  const range_list_element* cur_elem;
    583   REGF_VK_REC* vk;
     583  REGFI_VK_REC* vk;
    584584  uint32 i, j, off;
    585585
     
    616616  {
    617617    cur_elem = range_list_get(unalloc_values, i);
    618     vk = (REGF_VK_REC*)cur_elem->data;
     618    vk = (REGFI_VK_REC*)cur_elem->data;
    619619    if(vk == NULL)
    620620      return 40;
     
    622622    if(vk->data != NULL && !vk->data_in_offset)
    623623    {
    624       off = vk->data_off+REGF_BLOCKSIZE;
     624      off = vk->data_off+REGFI_REGF_SIZE;
    625625      if(!range_list_has_range(unalloc_cells, off, vk->data_size))
    626626      { /* We've parsed a data cell which isn't in the unallocated
     
    643643
    644644/* NOTE: unalloc_sks should be an empty range_list. */
    645 int extractSKs(REGF_FILE* f,
     645int extractSKs(REGFI_FILE* f,
    646646               range_list* unalloc_cells,
    647647               range_list* unalloc_sks)
    648648{
    649649  const range_list_element* cur_elem;
    650   REGF_SK_REC* sk;
     650  REGFI_SK_REC* sk;
    651651  uint32 i, j;
    652652
     
    684684int main(int argc, char** argv)
    685685{
    686   REGF_FILE* f;
     686  REGFI_FILE* f;
    687687  const range_list_element* cur_elem;
    688688  range_list* unalloc_cells;
     
    693693  char* tmp_name;
    694694  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;
    697697  uint32 argi, arge, i, j, ret, num_unalloc_keys;
    698698  /* uint32 test_offset;*/
     
    806806  {
    807807    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;
    809809
    810810    if(tmp_key == NULL)
     
    821821  {
    822822    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;
    824824
    825825    printKey(f, tmp_key, parent_paths[i]);
     
    848848  {
    849849    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;
    851851
    852852    printValue(f, tmp_value, "");
  • trunk/src/reglookup.c

    r126 r135  
    11/*
    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.
    43 *
    5  * Copyright (C) 2005-2008 Timothy D. Morgan
     4 * Copyright (C) 2005-2009 Timothy D. Morgan
    65 * Copyright (C) 2002 Richard Sharpe, rsharpe@richardsharpe.com
    76 *
     
    4342
    4443/* Other globals */
    45 REGF_FILE* f;
     44REGFI_FILE* f;
    4645
    4746
     
    5251
    5352
    54 void printValue(const REGF_VK_REC* vk, char* prefix)
     53void printValue(const REGFI_VK_REC* vk, char* prefix)
    5554{
    5655  char* quoted_value = NULL;
     
    6665   *   http://msdn2.microsoft.com/en-us/library/ms724872.aspx
    6766   */
    68   if(size > VK_MAX_DATA_LENGTH)
     67  if(size > REGFI_VK_MAX_DATA_LENGTH)
    6968  {
    7069    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;
    7372  }
    7473 
     
    143142  uint32 ret_cur = 0;
    144143
    145   ret_val = (char**)malloc((REGF_MAX_DEPTH+1+1)*sizeof(char**));
     144  ret_val = (char**)malloc((REGFI_MAX_DEPTH+1+1)*sizeof(char**));
    146145  if (ret_val == NULL)
    147146    return NULL;
     
    163162      copy[next-cur] = '\0';
    164163      ret_val[ret_cur++] = copy;
    165       if(ret_cur < (REGF_MAX_DEPTH+1+1))
     164      if(ret_cur < (REGFI_MAX_DEPTH+1+1))
    166165        ret_val[ret_cur] = NULL;
    167166      else
     
    176175    copy = strdup(cur);
    177176    ret_val[ret_cur++] = copy;
    178     if(ret_cur < (REGF_MAX_DEPTH+1+1))
     177    if(ret_cur < (REGFI_MAX_DEPTH+1+1))
    179178      ret_val[ret_cur] = NULL;
    180179    else
     
    275274void printValueList(REGFI_ITERATOR* i, char* prefix)
    276275{
    277   const REGF_VK_REC* value;
     276  const REGFI_VK_REC* value;
    278277
    279278  value = regfi_iterator_first_value(i);
     
    299298  time_t tmp_time[1];
    300299  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);
    303302
    304303  *tmp_time = nt_time_to_unix(&k->mtime);
     
    369368void printKeyTree(REGFI_ITERATOR* iter)
    370369{
    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;
    374373  char* path = NULL;
    375374  int key_type = regfi_type_str2val("KEY");
     
    441440int retrievePath(REGFI_ITERATOR* iter, char** path)
    442441{
    443   const REGF_VK_REC* value;
     442  const REGFI_VK_REC* value;
    444443  char* tmp_path_joined;
    445444  const char** tmp_path;
     
    450449
    451450  /* 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));
    453452  if(tmp_path == NULL)
    454453    return -2;
     
    457456  for(i=0;
    458457      (path[i] != NULL) && (path[i+1] != NULL)
    459         && (i < REGF_MAX_DEPTH+1+1);
     458        && (i < REGFI_MAX_DEPTH+1+1);
    460459      i++)
    461460    tmp_path[i] = path[i];
Note: See TracChangeset for help on using the changeset viewer.