Changeset 111 for trunk/lib


Ignore:
Timestamp:
05/01/08 00:06:22 (16 years ago)
Author:
tim
Message:

Switched license to GPLv3

Added early version of new tool, reglookup-recover

Many library changes made to support this new tool

Location:
trunk/lib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/lru_cache.c

    r108 r111  
    101101  lru_cache* ret_val;
    102102
    103   if(max_keys < 2)
    104     return NULL;
    105 
    106103  ret_val = (lru_cache*)malloc(sizeof(lru_cache));
    107104  if(ret_val == NULL)
    108105    return NULL;
    109106
    110   ret_val->num_buckets = max_keys/lru_cache_floor_log2(max_keys);
    111   if(ret_val->num_buckets < 1)
    112     ret_val->num_buckets = 1;
    113  
     107  if(max_keys == 0)
     108    ret_val->num_buckets = 2048;
     109  else
     110  {
     111    ret_val->num_buckets = max_keys/lru_cache_floor_log2(max_keys);
     112    if(ret_val->num_buckets < 1)
     113      ret_val->num_buckets = 1;
     114  }
     115
    114116  ret_val->table
    115117    = (lru_cache_element**)malloc(sizeof(lru_cache_element*)
     
    193195  { /* We didn't find an identical index. */
    194196   
    195     if(ht->num_keys >= ht->max_keys)
     197    if((ht->max_keys != 0) && (ht->num_keys >= ht->max_keys))
    196198    { /* Eliminate the least recently used item, but reuse the element
    197199       * structure to minimize reallocation.
  • trunk/lib/range_list.c

    r106 r111  
    2828#define RANGE_LIST_ALLOC_SIZE 256
    2929
    30 
     30#if 0
    3131static void range_list_print(const range_list* rl)
    3232{
     
    3838  fprintf(stderr, "\n");
    3939}
    40 
     40#endif
    4141
    4242/*
  • trunk/lib/regfi.c

    r110 r111  
    1111 * This program is free software; you can redistribute it and/or modify
    1212 * it under the terms of the GNU General Public License as published by
    13  * the Free Software Foundation; version 2 of the License.
     13 * the Free Software Foundation; version 3 of the License.
    1414 *
    1515 * This program is distributed in the hope that it will be useful,
     
    372372 *
    373373 *****************************************************************************/
    374 static bool regfi_parse_cell(int fd, uint32 offset, uint8* hdr, uint32 hdr_len,
    375                              uint32* cell_length, bool* unalloc)
     374bool regfi_parse_cell(int fd, uint32 offset, uint8* hdr, uint32 hdr_len,
     375                      uint32* cell_length, bool* unalloc)
    376376{
    377377  uint32 length;
     
    434434 * block for it.  NULL if one doesn't exist.
    435435 *******************************************************************/
    436 static REGF_HBIN* regfi_lookup_hbin(REGF_FILE* file, uint32 offset)
     436REGF_HBIN* regfi_lookup_hbin(REGF_FILE* file, uint32 offset)
    437437{
    438438  return (REGF_HBIN*)range_list_find_data(file->hbins, offset+REGF_BLOCKSIZE);
     
    565565
    566566  ret_val->offset = offset;
     567  /* TODO: is there a way to be more conservative (shorter) with
     568   *       cell length when cell is unallocated?
     569   */
    567570  ret_val->cell_size = cell_length;
    568571
     
    576579  }
    577580
    578 
    579581  ret_val->magic[0] = sk_header[0];
    580582  ret_val->magic[1] = sk_header[1];
    581583
     584  /* TODO: can additional validation be added here? */
    582585  ret_val->unknown_tag = SVAL(sk_header, 0x2);
    583586  ret_val->prev_sk_off = IVAL(sk_header, 0x4);
     
    621624
    622625
    623 
    624 /******************************************************************************
    625  TODO: not currently validating against max_size.
     626uint32* regfi_parse_valuelist(REGF_FILE* file, uint32 offset,
     627                              uint32 num_values, bool strict)
     628{
     629  uint32* ret_val;
     630  uint32 i, cell_length, length, read_len;
     631  bool unalloc;
     632
     633  if(!regfi_parse_cell(file->fd, offset, NULL, 0, &cell_length, &unalloc))
     634    return NULL;
     635
     636  if(cell_length != (cell_length & 0xFFFFFFF8))
     637  {
     638    if(strict)
     639      return NULL;
     640    cell_length = cell_length & 0xFFFFFFF8;
     641  }
     642  if((num_values * sizeof(uint32)) > cell_length-sizeof(uint32))
     643    return NULL;
     644
     645  read_len = num_values*sizeof(uint32);
     646  ret_val = (uint32*)malloc(read_len);
     647  if(ret_val == NULL)
     648    return NULL;
     649
     650  length = read_len;
     651  if((regfi_read(file->fd, (uint8*)ret_val, &length) != 0) || length != read_len)
     652  {
     653    free(ret_val);
     654    return NULL;
     655  }
     656 
     657  for(i=0; i < num_values; i++)
     658  {
     659    /* Fix endianness */
     660    ret_val[i] = IVAL(&ret_val[i], 0);
     661
     662    /* Validate the first num_values values to ensure they make sense */
     663    if(strict)
     664    {
     665      if((ret_val[i] + REGF_BLOCKSIZE > file->file_length)
     666         || ((ret_val[i] & 0xFFFFFFF8) != ret_val[i]))
     667      {
     668        free(ret_val);
     669        return NULL;
     670      }
     671    }
     672  }
     673
     674  return ret_val;
     675}
     676
     677
     678
     679/******************************************************************************
     680 * If !strict, the list may contain NULLs and VK records may point to NULL data.
    626681 ******************************************************************************/
    627682REGF_VK_REC** regfi_load_valuelist(REGF_FILE* file, uint32 offset,
     
    630685{
    631686  REGF_VK_REC** ret_val;
    632   REGF_HBIN* sub_hbin;
    633   uint8* buf;
    634   uint32 i, cell_length, vk_raw_offset, vk_offset, vk_max_length, buf_len;
    635   bool unalloc;
    636 
    637   buf_len = sizeof(uint8) * 4 * num_values;
    638   buf = (uint8*)zalloc(buf_len);
    639   if(buf == NULL)
    640     return NULL;
    641 
    642   if(!regfi_parse_cell(file->fd, offset, buf, buf_len, &cell_length, &unalloc))
    643   {
    644     free(buf);
    645     return NULL;
    646   }
     687  REGF_HBIN* hbin;
     688  uint32 i, vk_offset, vk_max_length;
     689  uint32* voffsets;
     690
     691  if((num_values+1) * sizeof(uint32) > max_size)
     692    return NULL;
     693
     694  /* TODO: For now, everything strict seems to make sense on this call.
     695   *       Maybe remove the parameter or use it for other things.
     696   */
     697  voffsets = regfi_parse_valuelist(file, offset, num_values, true);
     698  if(voffsets == NULL)
     699    return NULL;
    647700
    648701  ret_val = (REGF_VK_REC**)zalloc(sizeof(REGF_VK_REC*) * num_values);
    649702  if(ret_val == NULL)
    650703  {
    651     free(buf);
    652     return NULL;
    653   }
    654  
    655   for (i=0; i < num_values; i++)
    656   {
    657     vk_raw_offset = IVAL(buf, i*4);
    658    
    659     sub_hbin = regfi_lookup_hbin(file, vk_raw_offset);
    660     if (!sub_hbin)
    661     {
    662       free(buf);
     704    free(voffsets);
     705    return NULL;
     706  }
     707 
     708  for(i=0; i < num_values; i++)
     709  {
     710    hbin = regfi_lookup_hbin(file, voffsets[i]);
     711    if(!hbin)
     712    {
     713      free(voffsets);
    663714      free(ret_val);
    664715      return NULL;
    665716    }
    666717   
    667     vk_offset =  vk_raw_offset + REGF_BLOCKSIZE;
    668     vk_max_length = sub_hbin->block_size - vk_offset + sizeof(uint32);
    669     ret_val[i] = regfi_parse_vk(file, vk_offset, vk_max_length, true);
     718    vk_offset =  voffsets[i] + REGF_BLOCKSIZE;
     719    vk_max_length = hbin->block_size - vk_offset + sizeof(uint32);
     720    ret_val[i] = regfi_parse_vk(file, vk_offset, vk_max_length, strict);
    670721    if(ret_val[i] == NULL)
    671     {
    672       free(buf);
    673       free(ret_val);
    674       return NULL;     
    675     }
    676   }
    677 
    678   free(buf);
     722    { /* If we're being strict, throw out the whole list.
     723       * Otherwise, let it be NULL.
     724       */
     725      if(strict)
     726      {
     727        free(voffsets);
     728        free(ret_val);
     729        return NULL;
     730      }
     731    }
     732  }
     733
     734  free(voffsets);
    679735  return ret_val;
    680736}
     
    14601516  {
    14611517    /* TODO: deal with subkey-lists that reference other subkey-lists. */
    1462 printf("DEBUG: magic check failed! \"%c%c\"\n", nk_header[0x0], nk_header[0x1]);
    14631518    return NULL;
    14641519  }
     
    15741629                       &cell_length, &unalloc))
    15751630    return NULL;
    1576    
     1631
    15771632  ret_val = (REGF_VK_REC*)zalloc(sizeof(REGF_VK_REC));
    15781633  if(ret_val == NULL)
     
    15851640    ret_val->cell_size = max_size & 0xFFFFFFF8;
    15861641  if((ret_val->cell_size < REGFI_VK_MIN_LENGTH)
    1587      || (strict && ret_val->cell_size != (ret_val->cell_size & 0xFFFFFFF8)))
     1642     || ret_val->cell_size != (ret_val->cell_size & 0xFFFFFFF8))
    15881643  {
    15891644    free(ret_val);
     
    16021657  raw_data_size = IVAL(vk_header, 0x4);
    16031658  ret_val->data_size = raw_data_size & ~VK_DATA_IN_OFFSET;
     1659  ret_val->data_in_offset = (bool)(raw_data_size & VK_DATA_IN_OFFSET);
    16041660  ret_val->data_off = IVAL(vk_header, 0x8);
    16051661  ret_val->type = IVAL(vk_header, 0xC);
     
    16971753                         &cell_length, &unalloc))
    16981754      return NULL;
    1699    
    1700     if(cell_length < 8 || ((cell_length & 0xFFFFFFF8) != cell_length))
     1755
     1756    if((cell_length & 0xFFFFFFF8) != cell_length)
    17011757      return NULL;
    17021758
    17031759    if(cell_length - 4 < length)
    17041760    {
     1761      /* TODO: This strict condition has been triggered in multiple registries.
     1762       *       Not sure the cause, but the data length values are very large,
     1763       *       such as 53392.
     1764       */
    17051765      if(strict)
    17061766        return NULL;
  • trunk/lib/smb_deps.c

    r84 r111  
    1010 * This program is free software; you can redistribute it and/or modify
    1111 * it under the terms of the GNU General Public License as published by
    12  * the Free Software Foundation; version 2 of the License.
     12 * the Free Software Foundation; version 3 of the License.
    1313 *
    1414 * This program is distributed in the hope that it will be useful,
  • trunk/lib/void_stack.c

    r89 r111  
    88 * This program is free software; you can redistribute it and/or modify
    99 * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; version 2 of the License.
     10 * the Free Software Foundation; version 3 of the License.
    1111 *
    1212 * This program is distributed in the hope that it will be useful,
Note: See TracChangeset for help on using the changeset viewer.