Changeset 135


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
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/regfi.h

    r134 r135  
    7272#define REG_KEY                        0x7FFFFFFF
    7373
    74 #define REGF_BLOCKSIZE             0x1000
    75 #define REGF_ALLOC_BLOCK           0x1000 /* Minimum allocation unit for HBINs */
    76 #define REGF_MAX_DEPTH             512
    77 
    78 /* header sizes for various records */
    79 #define REGF_MAGIC_SIZE            4
    80 #define HBIN_MAGIC_SIZE            4
    81 #define HBIN_HEADER_REC_SIZE       0x20
    82 #define REC_HDR_SIZE               2
    83 
    84 #define REGF_OFFSET_NONE           0xffffffff
     74#define REGFI_REGF_SIZE            0x1000 /* "regf" header block size */
     75#define REGFI_HBIN_ALLOC           0x1000 /* Minimum allocation unit for HBINs */
     76#define REGFI_MAX_DEPTH            512
     77#define REGFI_OFFSET_NONE          0xffffffff
     78
     79/* Header sizes and magic number lengths for various records */
     80#define REGFI_REGF_MAGIC_SIZE      4
     81#define REGFI_HBIN_MAGIC_SIZE      4
     82#define REGFI_CELL_MAGIC_SIZE      2
     83#define REGFI_HBIN_HEADER_SIZE     0x20
    8584#define REGFI_NK_MIN_LENGTH        0x4C
    8685#define REGFI_VK_MIN_LENGTH        0x14
    8786#define REGFI_SK_MIN_LENGTH        0x14
    8887#define REGFI_SUBKEY_LIST_MIN_LEN  0x4
     88
    8989
    9090/* Constants used for validation */
     
    106106
    107107/* Flags for the vk records */
    108 #define VK_FLAG_NAME_PRESENT      0x0001
    109 #define VK_DATA_IN_OFFSET          0x80000000
    110 #define VK_MAX_DATA_LENGTH         1024*1024
     108#define REGFI_VK_FLAG_NAME_PRESENT 0x0001
     109#define REGFI_VK_DATA_IN_OFFSET    0x80000000
     110#define REGFI_VK_MAX_DATA_LENGTH   1024*1024
    111111
    112112/* NK record types */
    113 #define NK_TYPE_LINKKEY            0x0010
    114 #define NK_TYPE_NORMALKEY          0x0020
    115 #define NK_TYPE_ROOTKEY1           0x002c
    116 #define NK_TYPE_ROOTKEY2           0x00ac
    117  /* XXX: Unknown type that shows up in Vista registries */
    118 #define NK_TYPE_UNKNOWN1           0x1020
     113#define REGFI_NK_TYPE_LINKKEY      0x0010
     114#define REGFI_NK_TYPE_NORMALKEY    0x0020
     115 /* XXX: Unknown key type that shows up in Vista registries */
     116#define REGFI_NK_TYPE_UNKNOWN1     0x1020
     117#define REGFI_NK_TYPE_ROOTKEY1     0x002c
     118 /* XXX: Unknown root key type that shows up in Vista registries */
     119#define REGFI_NK_TYPE_ROOTKEY2     0x00ac
    119120
    120121
    121122/* HBIN block */
    122 typedef struct regf_hbin
     123typedef struct _regfi_hbin
    123124{
    124125  uint32 file_off;       /* my offset in the registry file */
     
    135136                          */
    136137
    137   uint8 magic[HBIN_MAGIC_SIZE]; /* "hbin" */
    138 } REGF_HBIN;
     138  uint8 magic[REGFI_HBIN_MAGIC_SIZE]; /* "hbin" */
     139} REGFI_HBIN;
    139140
    140141
     
    144145  uint32 nk_off;
    145146  uint32 hash;
    146 } REGF_SUBKEY_LIST_ELEM;
     147} REGFI_SUBKEY_LIST_ELEM;
    147148
    148149
     
    152153  uint32 cell_size;      /* ((start_offset - end_offset) & 0xfffffff8) */
    153154  uint32 num_keys;
    154   REGF_SUBKEY_LIST_ELEM* elements;
    155  
    156   uint8 magic[REC_HDR_SIZE];
    157 } REGF_SUBKEY_LIST;
     155  REGFI_SUBKEY_LIST_ELEM* elements;
     156 
     157  uint8 magic[REGFI_CELL_MAGIC_SIZE];
     158} REGFI_SUBKEY_LIST;
    158159
    159160
     
    164165  uint32 cell_size;     /* ((start_offset - end_offset) & 0xfffffff8) */
    165166
    166   REGF_HBIN* hbin;      /* pointer to HBIN record (in memory) containing
     167  REGFI_HBIN* hbin;     /* pointer to HBIN record (in memory) containing
    167168                         * this nk record
    168169                         */
     
    175176  uint32 data_off;      /* offset of data cell (virtual) */
    176177  uint32 type;
    177   uint8  magic[REC_HDR_SIZE];
     178  uint8  magic[REGFI_CELL_MAGIC_SIZE];
    178179  uint16 flag;
    179180  uint16 unknown1;
    180181  bool data_in_offset;
    181 } REGF_VK_REC;
     182} REGFI_VK_REC;
    182183
    183184
    184185/* Key Security */
    185 struct _regf_sk_rec;
    186 
    187 typedef struct _regf_sk_rec
     186struct _regfi_sk_rec;
     187
     188typedef struct _regfi_sk_rec
    188189{
    189190  uint32 offset;        /* Real file offset of this record */
     
    202203  uint32 desc_size;     /* size of security descriptor */
    203204  uint16 unknown_tag;
    204   uint8  magic[REC_HDR_SIZE];
    205 } REGF_SK_REC;
     205  uint8  magic[REGFI_CELL_MAGIC_SIZE];
     206} REGFI_SK_REC;
    206207
    207208
     
    215216
    216217  /* link in the other records here */
    217   REGF_VK_REC** values;
    218   REGF_SUBKEY_LIST* subkeys;
     218  REGFI_VK_REC** values;
     219  REGFI_SUBKEY_LIST* subkeys;
    219220 
    220221  /* header information */
    221222  uint16 key_type;
    222   uint8  magic[REC_HDR_SIZE];
     223  uint8  magic[REGFI_CELL_MAGIC_SIZE];
    223224  NTTIME mtime;
    224225  uint16 name_length;
     
    247248  uint32 values_off;    /* value lists which point to VK records */
    248249  uint32 sk_off;        /* offset to SK record */
    249 } REGF_NK_REC;
     250} REGFI_NK_REC;
    250251
    251252
     
    254255typedef struct
    255256{
    256   /* run time information */
     257  /* Run-time information */
     258  /************************/
    257259  int fd;         /* file descriptor */
     260
     261  /* Experimental hbin lists */
     262  range_list* hbins;
     263
     264  /* Error/warning/info messages returned by lower layer functions */
     265  char* last_message;
     266
    258267  /* For sanity checking (not part of the registry header) */
    259268  uint32 file_length;
    260   void* mem_ctx;  /* memory context for run-time file access information */
    261 
    262   /* Experimental hbin lists */
    263   range_list* hbins;
    264 
    265   /* file format information */ 
    266   uint8  magic[REGF_MAGIC_SIZE];/* "regf" */
     269
     270
     271  /* Data parsed from file header */
     272  /********************************/
     273  uint8  magic[REGFI_REGF_MAGIC_SIZE];/* "regf" */
    267274  NTTIME mtime;
    268275  uint32 data_offset;           /* offset to record in the first (or any?)
     
    284291  uint32 unknown6;
    285292  uint32 unknown7;
    286 } REGF_FILE;
    287 
    288 
    289 
    290 typedef struct
    291 {
    292   REGF_FILE* f;
     293} REGFI_FILE;
     294
     295
     296
     297typedef struct
     298{
     299  REGFI_FILE* f;
    293300  void_stack* key_positions;
    294301  lru_cache* sk_recs;
    295   REGF_NK_REC* cur_key;
     302  REGFI_NK_REC* cur_key;
    296303  uint32 cur_subkey;
    297304  uint32 cur_value;
     
    301308typedef struct
    302309{
    303   REGF_NK_REC* nk;
     310  /* XXX: Should probably eliminate the storage of keys here
     311   *      once key caching is implemented.
     312   */
     313  REGFI_NK_REC* nk;
    304314  uint32 cur_subkey;
    305315  /* We could store a cur_value here as well, but didn't see
     
    310320
    311321/******************************************************************************/
    312 /* Function Declarations */
    313 /*  Main API */
    314 const char*           regfi_type_val2str(unsigned int val);
    315 int                   regfi_type_str2val(const char* str);
    316 
    317 char*                 regfi_get_sacl(WINSEC_DESC* sec_desc);
    318 char*                 regfi_get_dacl(WINSEC_DESC* sec_desc);
    319 char*                 regfi_get_owner(WINSEC_DESC* sec_desc);
    320 char*                 regfi_get_group(WINSEC_DESC* sec_desc);
    321 
    322 REGF_FILE*            regfi_open(const char* filename);
    323 int                   regfi_close(REGF_FILE* r);
    324 
    325 REGFI_ITERATOR*       regfi_iterator_new(REGF_FILE* fh);
     322/*                         Main iterator API                                  */
     323/******************************************************************************/
     324REGFI_FILE*           regfi_open(const char* filename);
     325int                   regfi_close(REGFI_FILE* r);
     326
     327/* regfi_get_message: Get errors, warnings, and/or verbose information
     328 *                    relating to processing of the given registry file.
     329 *
     330 * Arguments:
     331 *   file     -- the structure for the registry file
     332 *
     333 * Returns:
     334 *   A newly allocated char* which must be free()d by the caller.
     335 */
     336char*                 regfi_get_message(REGFI_FILE* file);
     337
     338REGFI_ITERATOR*       regfi_iterator_new(REGFI_FILE* fh);
    326339void                  regfi_iterator_free(REGFI_ITERATOR* i);
    327340bool                  regfi_iterator_down(REGFI_ITERATOR* i);
     
    333346bool                  regfi_iterator_walk_path(REGFI_ITERATOR* i,
    334347                                               const char** path);
    335 const REGF_NK_REC*    regfi_iterator_cur_key(REGFI_ITERATOR* i);
    336 const REGF_SK_REC*    regfi_iterator_cur_sk(REGFI_ITERATOR* i);
    337 const REGF_NK_REC*    regfi_iterator_first_subkey(REGFI_ITERATOR* i);
    338 const REGF_NK_REC*    regfi_iterator_cur_subkey(REGFI_ITERATOR* i);
    339 const REGF_NK_REC*    regfi_iterator_next_subkey(REGFI_ITERATOR* i);
     348const REGFI_NK_REC*   regfi_iterator_cur_key(REGFI_ITERATOR* i);
     349const REGFI_SK_REC*   regfi_iterator_cur_sk(REGFI_ITERATOR* i);
     350const REGFI_NK_REC*   regfi_iterator_first_subkey(REGFI_ITERATOR* i);
     351const REGFI_NK_REC*   regfi_iterator_cur_subkey(REGFI_ITERATOR* i);
     352const REGFI_NK_REC*   regfi_iterator_next_subkey(REGFI_ITERATOR* i);
    340353
    341354bool                  regfi_iterator_find_value(REGFI_ITERATOR* i,
    342355                                                const char* value_name);
    343 const REGF_VK_REC*    regfi_iterator_first_value(REGFI_ITERATOR* i);
    344 const REGF_VK_REC*    regfi_iterator_cur_value(REGFI_ITERATOR* i);
    345 const REGF_VK_REC*    regfi_iterator_next_value(REGFI_ITERATOR* i);
     356const REGFI_VK_REC*   regfi_iterator_first_value(REGFI_ITERATOR* i);
     357const REGFI_VK_REC*   regfi_iterator_cur_value(REGFI_ITERATOR* i);
     358const REGFI_VK_REC*   regfi_iterator_next_value(REGFI_ITERATOR* i);
    346359
    347360
     
    349362/* Middle-layer structure caching, loading, and linking */
    350363/********************************************************/
    351 REGF_HBIN* regfi_lookup_hbin(REGF_FILE* file, uint32 offset);
    352 
    353 REGF_NK_REC* regfi_load_key(REGF_FILE* file, uint32 offset, bool strict);
    354 
    355 REGF_SUBKEY_LIST* regfi_load_subkeylist(REGF_FILE* file, uint32 offset,
    356                                         uint32 num_keys, uint32 max_size,
    357                                         bool strict);
    358 
    359 REGF_VK_REC** regfi_load_valuelist(REGF_FILE* file, uint32 offset,
    360                                    uint32 num_values, uint32 max_size,
    361                                    bool strict);
    362 
    363 REGF_SUBKEY_LIST* regfi_merge_subkeylists(uint16 num_lists,
    364                                           REGF_SUBKEY_LIST** lists,
    365                                           bool strict);
     364REGFI_HBIN*           regfi_lookup_hbin(REGFI_FILE* file, uint32 offset);
     365REGFI_NK_REC*         regfi_load_key(REGFI_FILE* file, uint32 offset,
     366                                     bool strict);
     367REGFI_SUBKEY_LIST*    regfi_load_subkeylist(REGFI_FILE* file, uint32 offset,
     368                                            uint32 num_keys, uint32 max_size,
     369                                            bool strict);
     370REGFI_VK_REC**        regfi_load_valuelist(REGFI_FILE* file, uint32 offset,
     371                                           uint32 num_values, uint32 max_size,
     372                                           bool strict);
    366373
    367374/************************************/
    368375/*  Low-layer data structure access */
    369376/************************************/
    370 REGF_FILE*            regfi_parse_regf(int fd, bool strict);
    371 REGF_HBIN*            regfi_parse_hbin(REGF_FILE* file, uint32 offset,
     377REGFI_FILE*           regfi_parse_regf(int fd, bool strict);
     378REGFI_HBIN*           regfi_parse_hbin(REGFI_FILE* file, uint32 offset,
    372379                                       bool strict);
    373380
     
    384391 *   A newly allocated NK record structure, or NULL on failure.
    385392 */
    386 REGF_NK_REC*          regfi_parse_nk(REGF_FILE* file, uint32 offset,
     393REGFI_NK_REC*         regfi_parse_nk(REGFI_FILE* file, uint32 offset,
    387394                                     uint32 max_size, bool strict);
    388395
    389 REGF_VK_REC* regfi_parse_vk(REGF_FILE* file, uint32 offset,
    390                             uint32 max_size, bool strict);
    391 
    392 uint8* regfi_parse_data(REGF_FILE* file, uint32 offset,
    393                         uint32 length, uint32 max_size, bool strict);
    394 
    395 REGF_SK_REC* regfi_parse_sk(REGF_FILE* file, uint32 offset, uint32 max_size, bool strict);
    396 
    397 range_list* regfi_parse_unalloc_cells(REGF_FILE* file);
    398 
    399 bool regfi_parse_cell(int fd, uint32 offset, uint8* hdr, uint32 hdr_len,
    400                       uint32* cell_length, bool* unalloc);
    401 
    402 char* regfi_parse_classname(REGF_FILE* file, uint32 offset,
    403                             uint16* name_length, uint32 max_size, bool strict);
    404 
    405 
    406 /* Private Functions */
    407 REGF_NK_REC*          regfi_rootkey(REGF_FILE* file);
    408 void                  regfi_key_free(REGF_NK_REC* nk);
    409 void                  regfi_subkeylist_free(REGF_SUBKEY_LIST* list);
     396REGFI_VK_REC*         regfi_parse_vk(REGFI_FILE* file, uint32 offset,
     397                                     uint32 max_size, bool strict);
     398
     399uint8*                regfi_parse_data(REGFI_FILE* file, uint32 offset,
     400                                       uint32 length, uint32 max_size,
     401                                       bool strict);
     402
     403REGFI_SK_REC*         regfi_parse_sk(REGFI_FILE* file, uint32 offset,
     404                                     uint32 max_size, bool strict);
     405
     406range_list*           regfi_parse_unalloc_cells(REGFI_FILE* file);
     407
     408bool                  regfi_parse_cell(int fd, uint32 offset,
     409                                       uint8* hdr, uint32 hdr_len,
     410                                       uint32* cell_length, bool* unalloc);
     411
     412char*                 regfi_parse_classname(REGFI_FILE* file, uint32 offset,
     413                                            uint16* name_length,
     414                                            uint32 max_size, bool strict);
     415
     416
     417/************************************/
     418/*    Private Functions             */
     419/************************************/
     420REGFI_NK_REC*         regfi_rootkey(REGFI_FILE* file);
     421void                  regfi_key_free(REGFI_NK_REC* nk);
     422void                  regfi_subkeylist_free(REGFI_SUBKEY_LIST* list);
    410423uint32                regfi_read(int fd, uint8* buf, uint32* length);
    411424
    412 
     425const char*           regfi_type_val2str(unsigned int val);
     426int                   regfi_type_str2val(const char* str);
     427
     428char*                 regfi_get_sacl(WINSEC_DESC* sec_desc);
     429char*                 regfi_get_dacl(WINSEC_DESC* sec_desc);
     430char*                 regfi_get_owner(WINSEC_DESC* sec_desc);
     431char*                 regfi_get_group(WINSEC_DESC* sec_desc);
     432
     433REGFI_SUBKEY_LIST*    regfi_merge_subkeylists(uint16 num_lists,
     434                                              REGFI_SUBKEY_LIST** lists,
     435                                              bool strict);
     436void                  regfi_add_message(REGFI_FILE* file, const char* error);
    413437#endif  /* _REGFI_H */
  • 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    {
  • 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.