Changeset 135 for trunk/lib


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/regfi.c

    r134 r135  
    3434
    3535
     36
     37/******************************************************************************
     38 ******************************************************************************/
     39void 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 ******************************************************************************/
     65char* 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
    3674/* Returns NULL on error */
    3775const char* regfi_type_val2str(unsigned int val)
     
    66104
    67105
    68 /* Security descriptor parsing functions  */
     106/* Security descriptor formatting functions  */
    69107
    70108const char* regfi_ace_type2str(uint8 type)
     
    415453 * The offset is a virtual file offset.
    416454 *******************************************************************/
    417 static bool regfi_offset_in_hbin(REGF_HBIN* hbin, uint32 offset)
     455static bool regfi_offset_in_hbin(REGFI_HBIN* hbin, uint32 offset)
    418456{
    419457  if(!hbin)
     
    430468
    431469/*******************************************************************
    432  * Given a virtual offset, and receive the correpsonding HBIN
     470 * Provide a virtual offset and receive the correpsonding HBIN
    433471 * block for it.  NULL if one doesn't exist.
    434472 *******************************************************************/
    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);
     473REGFI_HBIN* regfi_lookup_hbin(REGFI_FILE* file, uint32 offset)
     474{
     475  return (REGFI_HBIN*)range_list_find_data(file->hbins, offset+REGFI_REGF_SIZE);
    438476}
    439477
     
    441479/*******************************************************************
    442480 *******************************************************************/
    443 REGF_SUBKEY_LIST* regfi_merge_subkeylists(uint16 num_lists,
    444                                           REGF_SUBKEY_LIST** lists,
     481REGFI_SUBKEY_LIST* regfi_merge_subkeylists(uint16 num_lists,
     482                                          REGFI_SUBKEY_LIST** lists,
    445483                                          bool strict)
    446484{
    447485  uint32 i,j,k;
    448   REGF_SUBKEY_LIST* ret_val;
     486  REGFI_SUBKEY_LIST* ret_val;
    449487
    450488  if(lists == NULL)
    451489    return NULL;
    452   ret_val = (REGF_SUBKEY_LIST*)zalloc(sizeof(REGF_SUBKEY_LIST));
     490  ret_val = (REGFI_SUBKEY_LIST*)zalloc(sizeof(REGFI_SUBKEY_LIST));
    453491
    454492  if(ret_val == NULL)
     
    471509  {
    472510    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)
    474512                                     * ret_val->num_keys);
    475513    k=0;
     
    497535/*******************************************************************
    498536 *******************************************************************/
    499 REGF_SUBKEY_LIST* regfi_load_subkeylist(REGF_FILE* file, uint32 offset,
     537REGFI_SUBKEY_LIST* regfi_load_subkeylist(REGFI_FILE* file, uint32 offset,
    500538                                        uint32 num_keys, uint32 max_size,
    501539                                        bool strict)
    502540{
    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;
    506544  uint32 i, cell_length, length, num_sublists, off, max_length, elem_size;
    507545  uint8* hashes;
     
    537575    }
    538576
    539     sublists = (REGF_SUBKEY_LIST**)zalloc(num_sublists*sizeof(REGF_SUBKEY_LIST*));   
     577    sublists = (REGFI_SUBKEY_LIST**)zalloc(num_sublists*sizeof(REGFI_SUBKEY_LIST*));   
    540578    for(i=0; i < num_sublists; i++)
    541579    {
    542       off = IVAL(hashes, i*4)+REGF_BLOCKSIZE;
     580      off = IVAL(hashes, i*4)+REGFI_REGF_SIZE;
    543581      sublist_hbin = regfi_lookup_hbin(file, IVAL(hashes, i*4));
    544582      max_length = sublist_hbin->block_size + sublist_hbin->file_off - off;
     
    555593    elem_size = sizeof(uint32);
    556594  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);
    558596  else
    559597  {
     
    562600  }
    563601
    564   ret_val = (REGF_SUBKEY_LIST*)zalloc(sizeof(REGF_SUBKEY_LIST));
     602  ret_val = (REGFI_SUBKEY_LIST*)zalloc(sizeof(REGFI_SUBKEY_LIST));
    565603  if(ret_val == NULL)
    566604    return NULL;
     
    596634  length = elem_size*ret_val->num_keys;
    597635  ret_val->elements
    598     = (REGF_SUBKEY_LIST_ELEM*)zalloc(ret_val->num_keys
    599                                      * sizeof(REGF_SUBKEY_LIST_ELEM));
     636    = (REGFI_SUBKEY_LIST_ELEM*)zalloc(ret_val->num_keys
     637                                     * sizeof(REGFI_SUBKEY_LIST_ELEM));
    600638  if(ret_val->elements == NULL)
    601639  {
     
    645683/*******************************************************************
    646684 *******************************************************************/
    647 REGF_SK_REC* regfi_parse_sk(REGF_FILE* file, uint32 offset, uint32 max_size, bool strict)
    648 {
    649   REGF_SK_REC* ret_val;
     685REGFI_SK_REC* regfi_parse_sk(REGFI_FILE* file, uint32 offset, uint32 max_size, bool strict)
     686{
     687  REGFI_SK_REC* ret_val;
    650688  uint8* sec_desc_buf;
    651689  uint32 cell_length, length;
     
    661699    return NULL;
    662700 
    663   ret_val = (REGF_SK_REC*)zalloc(sizeof(REGF_SK_REC));
     701  ret_val = (REGFI_SK_REC*)zalloc(sizeof(REGFI_SK_REC));
    664702  if(ret_val == NULL)
    665703    return NULL;
     
    696734  }
    697735
    698   /* XXX: need to get rid of this, but currently the security descriptor
    699    * 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) != 0
    710      || length != ret_val->desc_size)
    711   {
    712     free(ret_val);
    713     return NULL;
    714   }
    715   */
    716 
    717736  sec_desc_buf = (uint8*)zalloc(ret_val->desc_size);
    718737  if(ret_val == NULL)
     
    738757  free(sec_desc_buf);
    739758
    740   /*  free(ps.data_p);*/
    741759
    742760  return ret_val;
     
    744762
    745763
    746 uint32* regfi_parse_valuelist(REGF_FILE* file, uint32 offset,
     764uint32* regfi_parse_valuelist(REGFI_FILE* file, uint32 offset,
    747765                              uint32 num_values, bool strict)
    748766{
     
    783801    if(strict)
    784802    {
    785       if((ret_val[i] + REGF_BLOCKSIZE > file->file_length)
     803      if((ret_val[i] + REGFI_REGF_SIZE > file->file_length)
    786804         || ((ret_val[i] & 0xFFFFFFF8) != ret_val[i]))
    787805      {
     
    800818 * If !strict, the list may contain NULLs, VK records may point to NULL.
    801819 ******************************************************************************/
    802 REGF_VK_REC** regfi_load_valuelist(REGF_FILE* file, uint32 offset,
     820REGFI_VK_REC** regfi_load_valuelist(REGFI_FILE* file, uint32 offset,
    803821                                   uint32 num_values, uint32 max_size,
    804822                                   bool strict)
    805823{
    806   REGF_VK_REC** ret_val;
    807   REGF_HBIN* hbin;
     824  REGFI_VK_REC** ret_val;
     825  REGFI_HBIN* hbin;
    808826  uint32 i, vk_offset, vk_max_length, usable_num_values;
    809827  uint32* voffsets;
     
    822840    return NULL;
    823841
    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);
    825843  if(ret_val == NULL)
    826844  {
     
    839857    }
    840858
    841     vk_offset =  voffsets[i] + REGF_BLOCKSIZE;
     859    vk_offset =  voffsets[i] + REGFI_REGF_SIZE;
    842860    vk_max_length = hbin->block_size + hbin->file_off - vk_offset;
    843861    ret_val[i] = regfi_parse_vk(file, vk_offset, vk_max_length, strict);
     
    865883 *      custom cache structure.
    866884 *******************************************************************/
    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;
     885REGFI_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;
    872890  uint32 max_length, off;
    873891
    874   hbin = regfi_lookup_hbin(file, offset-REGF_BLOCKSIZE);
     892  hbin = regfi_lookup_hbin(file, offset-REGFI_REGF_SIZE);
    875893  if (hbin == NULL)
    876894    return NULL;
     
    879897  max_length = hbin->block_size + hbin->file_off - offset;
    880898  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  }
    882904
    883905  /* 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))
    885907  {
    886908    sub_hbin = hbin;
     
    901923    else
    902924    {
    903       off = nk->values_off + REGF_BLOCKSIZE;
     925      off = nk->values_off + REGFI_REGF_SIZE;
    904926      max_length = sub_hbin->block_size + sub_hbin->file_off - off;
    905927      nk->values = regfi_load_valuelist(file, off, nk->num_values, max_length,
     
    907929      if(strict && nk->values == NULL)
    908930      {
     931        regfi_add_message(file, "ERROR: Could not load value list"
     932                          " for NK record at offset 0x%.8X.\n",
     933                          offset);
    909934        free(nk);
    910935        return NULL;
     
    915940
    916941  /* 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))
    918943  {
    919944    sub_hbin = hbin;
     
    933958    else
    934959    {
    935       off = nk->subkeys_off + REGF_BLOCKSIZE;
     960      off = nk->subkeys_off + REGFI_REGF_SIZE;
    936961      max_length = sub_hbin->block_size + sub_hbin->file_off - off;
    937962      nk->subkeys = regfi_load_subkeylist(file, off, nk->num_subkeys,
     
    953978
    954979/******************************************************************************
    955 
    956980 ******************************************************************************/
    957 static bool regfi_find_root_nk(REGF_FILE* file, uint32 offset, uint32 hbin_size,
     981static bool regfi_find_root_nk(REGFI_FILE* file, uint32 offset, uint32 hbin_size,
    958982                               uint32* root_offset)
    959983{
     
    961985  int32 record_size;
    962986  uint32 length, hbin_offset = 0;
    963   REGF_NK_REC* nk = NULL;
     987  REGFI_NK_REC* nk = NULL;
    964988  bool found = false;
    965989
     
    9801004      if(nk != NULL)
    9811005      {
    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))
    9841008        {
    9851009          found = true;
     
    10011025 * first hbin offset.
    10021026 *******************************************************************/
    1003 REGF_FILE* regfi_open(const char* filename)
    1004 {
    1005   REGF_FILE* rb;
    1006   REGF_HBIN* hbin = NULL;
     1027REGFI_FILE* regfi_open(const char* filename)
     1028{
     1029  REGFI_FILE* rb;
     1030  REGFI_HBIN* hbin = NULL;
    10071031  uint32 hbin_off;
    10081032  int fd;
     
    10341058 
    10351059  rla = true;
    1036   hbin_off = REGF_BLOCKSIZE;
     1060  hbin_off = REGFI_REGF_SIZE;
    10371061  hbin = regfi_parse_hbin(rb, hbin_off, true);
    10381062  while(hbin && rla)
     
    10501074/*******************************************************************
    10511075 *******************************************************************/
    1052 int regfi_close( REGF_FILE *file )
     1076int regfi_close( REGFI_FILE *file )
    10531077{
    10541078  int fd;
     
    10751099 * on my experience.  --jerry
    10761100 *****************************************************************************/
    1077 REGF_NK_REC* regfi_rootkey(REGF_FILE *file)
    1078 {
    1079   REGF_NK_REC* nk = NULL;
    1080   REGF_HBIN*   hbin;
     1101REGFI_NK_REC* regfi_rootkey(REGFI_FILE *file)
     1102{
     1103  REGFI_NK_REC* nk = NULL;
     1104  REGFI_HBIN*   hbin;
    10811105  uint32       root_offset, i, num_hbins;
    10821106 
     
    10921116  for(i=0; i < num_hbins; i++)
    10931117  {
    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))
    10971121    {
    10981122      nk = regfi_load_key(file, root_offset, true);
     
    11071131/******************************************************************************
    11081132 *****************************************************************************/
    1109 void regfi_key_free(REGF_NK_REC* nk)
     1133void regfi_key_free(REGFI_NK_REC* nk)
    11101134{
    11111135  uint32 i;
    11121136 
    1113   if((nk->values != NULL) && (nk->values_off!=REGF_OFFSET_NONE))
     1137  if((nk->values != NULL) && (nk->values_off!=REGFI_OFFSET_NONE))
    11141138  {
    11151139    for(i=0; i < nk->num_values; i++)
     
    11311155    free(nk->classname);
    11321156
    1133   /* XXX: not freeing hbin because these are cached.  This needs to be reviewed. */
    11341157  /* XXX: not freeing sec_desc because these are cached.  This needs to be reviewed. */
    11351158  free(nk);
     
    11391162/******************************************************************************
    11401163 *****************************************************************************/
    1141 void regfi_subkeylist_free(REGF_SUBKEY_LIST* list)
     1164void regfi_subkeylist_free(REGFI_SUBKEY_LIST* list)
    11421165{
    11431166  if(list != NULL)
     
    11511174/******************************************************************************
    11521175 *****************************************************************************/
    1153 REGFI_ITERATOR* regfi_iterator_new(REGF_FILE* fh)
    1154 {
    1155   REGF_NK_REC* root;
     1176REGFI_ITERATOR* regfi_iterator_new(REGFI_FILE* fh)
     1177{
     1178  REGFI_NK_REC* root;
    11561179  REGFI_ITERATOR* ret_val = (REGFI_ITERATOR*)malloc(sizeof(REGFI_ITERATOR));
    11571180  if(ret_val == NULL)
     
    11651188  }
    11661189
    1167   ret_val->key_positions = void_stack_new(REGF_MAX_DEPTH);
     1190  ret_val->key_positions = void_stack_new(REGFI_MAX_DEPTH);
    11681191  if(ret_val->key_positions == NULL)
    11691192  {
     
    12171240bool regfi_iterator_down(REGFI_ITERATOR* i)
    12181241{
    1219   REGF_NK_REC* subkey;
     1242  REGFI_NK_REC* subkey;
    12201243  REGFI_ITER_POSITION* pos;
    12211244
     
    12241247    return false;
    12251248
    1226   subkey = (REGF_NK_REC*)regfi_iterator_cur_subkey(i);
     1249  subkey = (REGFI_NK_REC*)regfi_iterator_cur_subkey(i);
    12271250  if(subkey == NULL)
    12281251  {
     
    12831306bool regfi_iterator_find_subkey(REGFI_ITERATOR* i, const char* subkey_name)
    12841307{
    1285   REGF_NK_REC* subkey;
     1308  REGFI_NK_REC* subkey;
    12861309  bool found = false;
    12871310  uint32 old_subkey = i->cur_subkey;
     
    12911314
    12921315  /* 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);
    12941317  while((subkey != NULL) && (found == false))
    12951318  {
     
    13001323    {
    13011324      regfi_key_free(subkey);
    1302       subkey = (REGF_NK_REC*)regfi_iterator_next_subkey(i);
     1325      subkey = (REGFI_NK_REC*)regfi_iterator_next_subkey(i);
    13031326    }
    13041327  }
     
    13421365/******************************************************************************
    13431366 *****************************************************************************/
    1344 const REGF_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i)
     1367const REGFI_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i)
    13451368{
    13461369  return i->cur_key;
     
    13501373/******************************************************************************
    13511374 *****************************************************************************/
    1352 const REGF_SK_REC* regfi_iterator_cur_sk(REGFI_ITERATOR* i)
    1353 {
    1354   REGF_SK_REC* ret_val;
    1355   REGF_HBIN* hbin;
     1375const REGFI_SK_REC* regfi_iterator_cur_sk(REGFI_ITERATOR* i)
     1376{
     1377  REGFI_SK_REC* ret_val;
     1378  REGFI_HBIN* hbin;
    13561379  uint32 max_length, off;
    13571380
     
    13601383 
    13611384  /* 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,
    13641387                                                &i->cur_key->sk_off, 4)))
    13651388  {
     
    13691392      return NULL;
    13701393
    1371     off = i->cur_key->sk_off + REGF_BLOCKSIZE;
     1394    off = i->cur_key->sk_off + REGFI_REGF_SIZE;
    13721395    max_length = hbin->block_size + hbin->file_off - off;
    13731396    ret_val = regfi_parse_sk(i->f, off, max_length, true);
     
    13861409/******************************************************************************
    13871410 *****************************************************************************/
    1388 const REGF_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i)
     1411const REGFI_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i)
    13891412{
    13901413  i->cur_subkey = 0;
     
    13951418/******************************************************************************
    13961419 *****************************************************************************/
    1397 const REGF_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i)
     1420const REGFI_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i)
    13981421{
    13991422  uint32 nk_offset;
    14001423
    14011424  /* 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)
    14031426      || (i->cur_subkey >= i->cur_key->num_subkeys))
    14041427    return NULL;
     
    14061429  nk_offset = i->cur_key->subkeys->elements[i->cur_subkey].nk_off;
    14071430
    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);
    14091432}
    14101433
     
    14131436 *****************************************************************************/
    14141437/* 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;
     1438const REGFI_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i)
     1439{
     1440  const REGFI_NK_REC* subkey;
    14181441
    14191442  i->cur_subkey++;
     
    14311454bool regfi_iterator_find_value(REGFI_ITERATOR* i, const char* value_name)
    14321455{
    1433   const REGF_VK_REC* cur;
     1456  const REGFI_VK_REC* cur;
    14341457  bool found = false;
    14351458
     
    14561479/******************************************************************************
    14571480 *****************************************************************************/
    1458 const REGF_VK_REC* regfi_iterator_first_value(REGFI_ITERATOR* i)
     1481const REGFI_VK_REC* regfi_iterator_first_value(REGFI_ITERATOR* i)
    14591482{
    14601483  i->cur_value = 0;
     
    14651488/******************************************************************************
    14661489 *****************************************************************************/
    1467 const REGF_VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i)
    1468 {
    1469   REGF_VK_REC* ret_val = NULL;
     1490const REGFI_VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i)
     1491{
     1492  REGFI_VK_REC* ret_val = NULL;
    14701493  if(i->cur_value < i->cur_key->num_values)
    14711494    ret_val = i->cur_key->values[i->cur_value];
     
    14771500/******************************************************************************
    14781501 *****************************************************************************/
    1479 const REGF_VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i)
    1480 {
    1481   const REGF_VK_REC* ret_val;
     1502const REGFI_VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i)
     1503{
     1504  const REGFI_VK_REC* ret_val;
    14821505
    14831506  i->cur_value++;
     
    15161539 * XXX: Add way to return more detailed error information.
    15171540 *******************************************************************/
    1518 REGF_FILE* regfi_parse_regf(int fd, bool strict)
    1519 {
    1520   uint8 file_header[REGF_BLOCKSIZE];
     1541REGFI_FILE* regfi_parse_regf(int fd, bool strict)
     1542{
     1543  uint8 file_header[REGFI_REGF_SIZE];
    15211544  uint32 length;
    15221545  uint32 file_length;
    15231546  struct stat sbuf;
    1524   REGF_FILE* ret_val;
     1547  REGFI_FILE* ret_val;
    15251548
    15261549  /* Determine file length.  Must be at least big enough
     
    15301553    return NULL;
    15311554  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));
    15361559  if(ret_val == NULL)
    15371560    return NULL;
     
    15401563  ret_val->file_length = file_length;
    15411564
    1542   length = REGF_BLOCKSIZE;
     1565  length = REGFI_REGF_SIZE;
    15431566  if((regfi_read(fd, file_header, &length)) != 0
    1544      || length != REGF_BLOCKSIZE)
     1567     || length != REGFI_REGF_SIZE)
    15451568  {
    15461569    free(ret_val);
     
    15561579  }
    15571580
    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))
    15601583  {
    15611584    free(ret_val);
     
    15901613/* XXX: Need a way to return types of errors.
    15911614 */
    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];
     1615REGFI_HBIN* regfi_parse_hbin(REGFI_FILE* file, uint32 offset, bool strict)
     1616{
     1617  REGFI_HBIN *hbin;
     1618  uint8 hbin_header[REGFI_HBIN_HEADER_SIZE];
    15961619  uint32 length;
    15971620 
     
    16021625    return NULL;
    16031626
    1604   length = HBIN_HEADER_REC_SIZE;
     1627  length = REGFI_HBIN_HEADER_SIZE;
    16051628  if((regfi_read(file->fd, hbin_header, &length) != 0)
    1606      || length != HBIN_HEADER_REC_SIZE)
     1629     || length != REGFI_HBIN_HEADER_SIZE)
    16071630    return NULL;
    16081631
     
    16111634    return NULL;
    16121635
    1613   if(!(hbin = (REGF_HBIN*)zalloc(sizeof(REGF_HBIN))))
     1636  if(!(hbin = (REGFI_HBIN*)zalloc(sizeof(REGFI_HBIN))))
    16141637    return NULL;
    16151638  hbin->file_off = offset;
     
    16471670/*******************************************************************
    16481671 *******************************************************************/
    1649 REGF_NK_REC* regfi_parse_nk(REGF_FILE* file, uint32 offset,
     1672REGFI_NK_REC* regfi_parse_nk(REGFI_FILE* file, uint32 offset,
    16501673                            uint32 max_size, bool strict)
    16511674{
    16521675  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;
    16551678  uint32 length,cell_length;
    16561679  uint32 class_offset, class_maxsize;
     
    16631686  /* A bit of validation before bothering to allocate memory */
    16641687  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));
    16681695  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  }
    16701701
    16711702  ret_val->offset = offset;
     
    16771708     || (strict && ret_val->cell_size != (ret_val->cell_size & 0xFFFFFFF8)))
    16781709  {
     1710    regfi_add_message(file, "ERROR: A length check failed while parsing"
     1711                      " NK record at offset 0x%.8X.\n", offset);
    16791712    free(ret_val);
    16801713    return NULL;
     
    16841717  ret_val->magic[1] = nk_header[0x1];
    16851718  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);
    16921728    free(ret_val);
    16931729    return NULL;
     
    17681804  ret_val->keyname[ret_val->name_length] = '\0';
    17691805
    1770   if(ret_val->classname_off != REGF_OFFSET_NONE)
     1806  if(ret_val->classname_off != REGFI_OFFSET_NONE)
    17711807  {
    17721808    hbin = regfi_lookup_hbin(file, ret_val->classname_off);
    17731809    if(hbin)
    17741810    {
    1775       class_offset = ret_val->classname_off+REGF_BLOCKSIZE;
     1811      class_offset = ret_val->classname_off+REGFI_REGF_SIZE;
    17761812      class_maxsize = hbin->block_size + hbin->file_off - class_offset;
    17771813      ret_val->classname
     
    17911827
    17921828
    1793 char* regfi_parse_classname(REGF_FILE* file, uint32 offset,
     1829char* regfi_parse_classname(REGFI_FILE* file, uint32 offset,
    17941830                            uint16* name_length, uint32 max_size, bool strict)
    17951831{
     
    17991835  bool unalloc = false;
    18001836
    1801   if(*name_length > 0 && offset != REGF_OFFSET_NONE
     1837  if(*name_length > 0 && offset != REGFI_OFFSET_NONE
    18021838     && offset == (offset & 0xFFFFFFF8))
    18031839  {
     
    18431879/*******************************************************************
    18441880 *******************************************************************/
    1845 REGF_VK_REC* regfi_parse_vk(REGF_FILE* file, uint32 offset,
     1881REGFI_VK_REC* regfi_parse_vk(REGFI_FILE* file, uint32 offset,
    18461882                            uint32 max_size, bool strict)
    18471883{
    1848   REGF_VK_REC* ret_val;
    1849   REGF_HBIN *hbin;
     1884  REGFI_VK_REC* ret_val;
     1885  REGFI_HBIN *hbin;
    18501886  uint8 vk_header[REGFI_VK_MIN_LENGTH];
    18511887  uint32 raw_data_size, length, cell_length;
     
    18571893    return NULL;
    18581894
    1859   ret_val = (REGF_VK_REC*)zalloc(sizeof(REGF_VK_REC));
     1895  ret_val = (REGFI_VK_REC*)zalloc(sizeof(REGFI_VK_REC));
    18601896  if(ret_val == NULL)
    18611897    return NULL;
     
    18871923  ret_val->name_length = SVAL(vk_header, 0x2);
    18881924  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);
    18911927  ret_val->data_off = IVAL(vk_header, 0x8);
    18921928  ret_val->type = IVAL(vk_header, 0xC);
     
    18941930  ret_val->unknown1 = SVAL(vk_header, 0x12);
    18951931
    1896   if(ret_val->flag & VK_FLAG_NAME_PRESENT)
     1932  if(ret_val->flag & REGFI_VK_FLAG_NAME_PRESENT)
    18971933  {
    18981934    if(ret_val->name_length + REGFI_VK_MIN_LENGTH + 4 > ret_val->cell_size)
     
    19541990      if(hbin)
    19551991      {
    1956         data_offset = ret_val->data_off+REGF_BLOCKSIZE;
     1992        data_offset = ret_val->data_off+REGFI_REGF_SIZE;
    19571993        data_maxsize = hbin->block_size + hbin->file_off - data_offset;
    19581994        ret_val->data = regfi_parse_data(file, data_offset, raw_data_size,
     
    19762012
    19772013
    1978 uint8* regfi_parse_data(REGF_FILE* file, uint32 offset, uint32 length,
     2014uint8* regfi_parse_data(REGFI_FILE* file, uint32 offset, uint32 length,
    19792015                        uint32 max_size, bool strict)
    19802016{
     
    19852021
    19862022  /* 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;
    19902026    if(length > 4)
    19912027      return NULL;
     
    19942030      return NULL;
    19952031
    1996     offset = offset - REGF_BLOCKSIZE;
     2032    offset = offset - REGFI_REGF_SIZE;
    19972033    for(i = 0; i < length; i++)
    19982034      ret_val[i] = (uint8)((offset >> i*8) & 0xFF);
     
    20432079
    20442080
    2045 range_list* regfi_parse_unalloc_cells(REGF_FILE* file)
     2081range_list* regfi_parse_unalloc_cells(REGFI_FILE* file)
    20462082{
    20472083  range_list* ret_val;
    2048   REGF_HBIN* hbin;
     2084  REGFI_HBIN* hbin;
    20492085  const range_list_element* hbins_elem;
    20502086  uint32 i, num_hbins, curr_off, cell_len;
     
    20612097    if(hbins_elem == NULL)
    20622098      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;
    20662102    while(curr_off < hbin->block_size)
    20672103    {
Note: See TracChangeset for help on using the changeset viewer.