Changeset 206 for trunk


Ignore:
Timestamp:
08/25/10 11:20:32 (14 years ago)
Author:
tim
Message:

simplified part of regfi API to move string encoding to the REGFI_FILE object

additional pyregfi implementation

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/regfi.h

    r203 r206  
    359359typedef struct _regfi_value_list
    360360{
     361  /* Real offset of this record's cell in the file */
     362  uint32_t offset;
     363
     364  uint32_t cell_size;
     365
    361366  /* Actual number of values referenced by this list. 
    362367   * May differ from parent key's num_values if there were parsing errors.
     
    373378typedef struct _regfi_classname
    374379{
     380  /** Real offset of this record's cell in the file */
     381  uint32_t offset;
     382
    375383  /** As converted to requested REGFI_ENCODING */
    376384  char* interpreted;
     
    497505 * @ingroup regfiBase
    498506 */
    499 typedef struct
     507typedef struct _regfi_vk
    500508{
    501509  /** Real offset of this record's cell in the file */
     
    504512  /** ((start_offset - end_offset) & 0xfffffff8) */
    505513  uint32_t cell_size;
    506 
    507   /* XXX: deprecated */
    508   REGFI_DATA* data;
    509514
    510515  /** The name of this value converted to desired REGFI_ENCODING. 
     
    513518   * settings.  String is NUL terminated.
    514519   */
    515   char*    valuename;
     520  char* name;
    516521
    517522  /** The raw value name
     
    519524   * Length of the buffer is stored in name_length.
    520525   */
    521   uint8_t* valuename_raw;
    522 
    523   /** Length of valuename_raw */
     526  uint8_t* name_raw;
     527
     528  /** Length of name_raw */
    524529  uint16_t name_length;
    525530
     
    553558   */
    554559  bool     data_in_offset;
     560
     561  /* XXX: deprecated */
     562  REGFI_DATA* data;
     563
    555564} REGFI_VK;
    556565
    557566
    558567/* Key Security */
    559 struct _regfi_sk_rec;
     568struct _regfi_sk;
    560569
    561570/** Security structure
    562571 * @ingroup regfiBase
    563572 */
    564 typedef struct _regfi_sk_rec
     573typedef struct _regfi_sk
    565574{
    566575  /** Real file offset of this record */
     
    599608 * @ingroup regfiBase
    600609 */
    601 typedef struct _regfi_nk_rec
     610typedef struct _regfi_nk
    602611{
    603612  /** Real offset of this record's cell in the file */
     
    642651   * settings.  String is NUL terminated.
    643652   */
    644   char* keyname;
     653  char* name;
    645654
    646655  /** The raw key name
     
    648657   * Length of the buffer is stored in name_length.
    649658   */
    650   uint8_t* keyname_raw;
     659  uint8_t* name_raw;
    651660
    652661  /** Virutal offset of parent key */
     
    662671  uint32_t max_bytes_subkeyclassname;
    663672
    664   /* XXX: max valuename * 2 */
     673  /* XXX: max value name * 2 */
    665674  uint32_t max_bytes_valuename;
    666675
     
    772781  /* Run-time information */
    773782  /************************/
     783  /* For sanity checking (not part of the registry header) */
     784  uint32_t file_length;
     785
     786  /** The encoding that all strings are converted to during interpretation.
     787   */
     788  REGFI_ENCODING string_encoding;
     789
    774790  /* Functions for accessing the file */
    775791  REGFI_RAW_FILE* cb;
     
    780796  pthread_mutex_t cb_lock;
    781797
    782   /* For sanity checking (not part of the registry header) */
    783   uint32_t file_length;
    784 
    785798  /* Metadata about hbins */
    786799  range_list* hbins;
     
    811824  /** The current key */
    812825  REGFI_NK* cur_key;
    813 
    814   /** The encoding that all strings are converted to as set during iterator
    815    *  creation.
    816    */
    817   REGFI_ENCODING string_encoding;
    818826
    819827  /** Index of the current subkey */
     
    866874 */
    867875_EXPORT
    868 REGFI_FILE* regfi_alloc(int fd);
     876REGFI_FILE* regfi_alloc(int fd, REGFI_ENCODING output_encoding);
    869877
    870878
     
    882890 */
    883891_EXPORT
    884 REGFI_FILE* regfi_alloc_cb(REGFI_RAW_FILE* file_cb);
     892REGFI_FILE* regfi_alloc_cb(REGFI_RAW_FILE* file_cb,
     893                           REGFI_ENCODING output_encoding);
    885894
    886895
     
    952961_EXPORT
    953962void regfi_free_record(const void* record);
     963
     964
     965/** Retrieves classname for a given key.
     966 *
     967 * @param file the file from which key is derived
     968 * @param key the key whose classname is desired
     969 *
     970 * @return Returns a newly allocated classname structure, or NULL on failure.
     971 *         Classname structures must be freed with @ref regfi_free_record.
     972 *
     973 * @ingroup regfiBase
     974 */
     975_EXPORT
     976const REGFI_CLASSNAME* regfi_fetch_classname(REGFI_FILE* file,
     977                                             const REGFI_NK* key);
     978
     979
     980/** Returns the SK (security) record referenced by the supplied key.
     981 *
     982 * @param file the file from which key is derived
     983 * @param key  the key whose SK record is desired
     984 *
     985 * @return A read-only SK structure, or NULL on failure.
     986 *
     987 * @ingroup regfiBase
     988 */
     989_EXPORT
     990const REGFI_SK* regfi_fetch_sk(REGFI_FILE* file, const REGFI_NK* key);
     991
     992
     993/** Retrieves data for a given value.
     994 *
     995 * @param file the file from which value is derived
     996 * @param value the value whose data is desired
     997 *
     998 * @return Returns a newly allocated data structure, or NULL on failure.
     999 *         Data structures must be freed with @ref regfi_free_record.
     1000 *
     1001 * @ingroup regfiBase
     1002 */
     1003_EXPORT
     1004const REGFI_DATA* regfi_fetch_data(REGFI_FILE* file,
     1005                                   const REGFI_VK* value);
    9541006
    9551007
     
    9821034 */
    9831035_EXPORT
    984 REGFI_ITERATOR* regfi_iterator_new(REGFI_FILE* file,
    985                                          REGFI_ENCODING output_encoding);
     1036REGFI_ITERATOR* regfi_iterator_new(REGFI_FILE* file);
    9861037
    9871038
     
    10741125
    10751126
    1076 /** Returns the SK (security) record referenced by the current key.
    1077  *
    1078  * @param i the iterator
    1079  *
    1080  * @return A read-only SK structure, or NULL on failure.
    1081  *
    1082  * @ingroup regfiIteratorLayer
    1083  */
    1084 _EXPORT
    1085 const REGFI_SK* regfi_iterator_cur_sk(REGFI_ITERATOR* i);
    1086 
    1087 
    10881127/** Sets the internal subkey index to the first subkey referenced by the current
    10891128 *  key.
     
    11931232bool regfi_iterator_find_value(REGFI_ITERATOR* i,
    11941233                               const char* value_name);
    1195 
    1196 /** Retrieves classname for a given key.
    1197  *
    1198  * @param i   the iterator
    1199  * @param key the key whose classname is desired
    1200  *
    1201  * @return Returns a newly allocated classname structure, or NULL on failure.
    1202  *         Classname structures must be freed with @ref regfi_free_record.
    1203  *
    1204  * @ingroup regfiIteratorLayer
    1205  */
    1206 _EXPORT
    1207 const REGFI_CLASSNAME* regfi_iterator_fetch_classname(REGFI_ITERATOR* i,
    1208                                                       const REGFI_NK* key);
    1209 
    1210 
    1211 /** Retrieves data for a given value.
    1212  *
    1213  * @param i     the iterator
    1214  * @param value the value whose data is desired
    1215  *
    1216  * @return Returns a newly allocated data structure, or NULL on failure.
    1217  *         Data structures must be freed with @ref regfi_free_record.
    1218  *
    1219  * @ingroup regfiIteratorLayer
    1220  */
    1221 _EXPORT
    1222 const REGFI_DATA* regfi_iterator_fetch_data(REGFI_ITERATOR* i,
    1223                                             const REGFI_VK* value);
    1224 
    12251234
    12261235
     
    13301339const REGFI_SK* regfi_load_sk(REGFI_FILE* file, uint32_t offset,
    13311340                                  bool strict);
     1341
     1342
    13321343
    13331344
     
    14701481/*    Private Functions                                                       */
    14711482/******************************************************************************/
    1472 REGFI_NK*         regfi_rootkey(REGFI_FILE* file,
    1473                                     REGFI_ENCODING output_encoding);
     1483REGFI_NK*             regfi_rootkey(REGFI_FILE* file);
    14741484
    14751485off_t                 regfi_raw_seek(REGFI_RAW_FILE* self,
     
    15061516void                  regfi_add_message(REGFI_FILE* file, uint16_t msg_type,
    15071517                                        const char* fmt, ...);
    1508 REGFI_NK*         regfi_copy_nk(const REGFI_NK* nk);
    1509 REGFI_VK*         regfi_copy_vk(const REGFI_VK* vk);
     1518REGFI_NK*             regfi_copy_nk(const REGFI_NK* nk);
     1519REGFI_VK*             regfi_copy_vk(const REGFI_VK* vk);
    15101520_EXPORT
    15111521int32_t               regfi_calc_maxsize(REGFI_FILE* file, uint32_t offset);
  • trunk/lib/regfi.c

    r203 r206  
    11311131    goto fail_locked;
    11321132
     1133  ret_val->offset = offset;
     1134  ret_val->cell_size = cell_length;
    11331135  ret_val->num_values = num_values;
    11341136
     
    11751177}
    11761178
    1177 
     1179/* XXX: should give this boolean return type to indicate errors */
    11781180void regfi_interpret_valuename(REGFI_FILE* file, REGFI_VK* vk,
    11791181                               REGFI_ENCODING output_encoding, bool strict)
     
    11931195  if(from_encoding == output_encoding)
    11941196  {
    1195     vk->valuename_raw = talloc_realloc(vk, vk->valuename_raw,
    1196                                             uint8_t, vk->name_length+1);
    1197     vk->valuename_raw[vk->name_length] = '\0';
    1198     vk->valuename = (char*)vk->valuename_raw;
     1197    vk->name_raw[vk->name_length] = '\0';
     1198    vk->name = (char*)vk->name_raw;
    11991199  }
    12001200  else
    12011201  {
    1202     vk->valuename = talloc_array(vk, char, vk->name_length+1);
    1203     if(vk->valuename == NULL)
    1204     {
    1205       talloc_free(vk);
     1202    vk->name = talloc_array(vk, char, vk->name_length+1);
     1203    if(vk->name == NULL)
    12061204      return;
    1207     }
    12081205
    12091206    tmp_size = regfi_conv_charset(regfi_encoding_int2str(from_encoding),
    12101207                                  regfi_encoding_int2str(output_encoding),
    1211                                   vk->valuename_raw, vk->valuename,
     1208                                  vk->name_raw, vk->name,
    12121209                                  vk->name_length, vk->name_length+1);
    12131210    if(tmp_size < 0)
    12141211    {
    12151212      regfi_log_add(REGFI_LOG_WARN, "Error occurred while converting"
    1216                         " valuename to encoding %s.  Error message: %s",
     1213                        " value name to encoding %s.  Error message: %s",
    12171214                        regfi_encoding_int2str(output_encoding),
    12181215                        strerror(-tmp_size));
    1219       talloc_free(vk->valuename);
    1220       vk->valuename = NULL;
     1216      talloc_free(vk->name);
     1217      vk->name = NULL;
    12211218    }
    12221219  }
     
    12271224 ******************************************************************************/
    12281225REGFI_VK* regfi_load_value(REGFI_FILE* file, uint32_t offset,
    1229                                REGFI_ENCODING output_encoding, bool strict)
     1226                           REGFI_ENCODING output_encoding, bool strict)
    12301227{
    12311228  REGFI_VK* ret_val = NULL;
     
    12721269
    12731270
     1271/* XXX: should give this boolean return type to indicate errors */
    12741272void regfi_interpret_keyname(REGFI_FILE* file, REGFI_NK* nk,
    12751273                             REGFI_ENCODING output_encoding, bool strict)
     
    12881286  if(from_encoding == output_encoding)
    12891287  {
    1290     nk->keyname_raw = talloc_realloc(nk, nk->keyname_raw, uint8_t, nk->name_length+1);
    1291     nk->keyname_raw[nk->name_length] = '\0';
    1292     nk->keyname = (char*)nk->keyname_raw;
     1288    nk->name_raw[nk->name_length] = '\0';
     1289    nk->name = (char*)nk->name_raw;
    12931290  }
    12941291  else
    12951292  {
    1296     nk->keyname = talloc_array(nk, char, nk->name_length+1);
    1297     if(nk->keyname == NULL)
    1298     {
    1299       talloc_free(nk);
     1293    nk->name = talloc_array(nk, char, nk->name_length+1);
     1294    if(nk->name == NULL)
    13001295      return;
    1301     }
     1296
     1297    memset(nk->name,0,nk->name_length+1);
    13021298
    13031299    tmp_size = regfi_conv_charset(regfi_encoding_int2str(from_encoding),
    13041300                                  regfi_encoding_int2str(output_encoding),
    1305                                   nk->keyname_raw, nk->keyname,
     1301                                  nk->name_raw, nk->name,
    13061302                                  nk->name_length, nk->name_length+1);
    13071303    if(tmp_size < 0)
    13081304    {
    13091305      regfi_log_add(REGFI_LOG_WARN, "Error occurred while converting"
    1310                         " keyname to encoding %s.  Error message: %s",
     1306                        " key name to encoding %s.  Error message: %s",
    13111307                        regfi_encoding_int2str(output_encoding),
    13121308                        strerror(-tmp_size));
    1313       talloc_free(nk->keyname);
    1314       nk->keyname = NULL;
     1309      talloc_free(nk->name);
     1310      nk->name = NULL;
    13151311    }
    13161312  }
     
    13221318 ******************************************************************************/
    13231319REGFI_NK* regfi_load_key(REGFI_FILE* file, uint32_t offset,
    1324                              REGFI_ENCODING output_encoding, bool strict)
     1320                         REGFI_ENCODING output_encoding, bool strict)
    13251321{
    13261322  REGFI_NK* nk;
     
    14661462 ******************************************************************************/
    14671463REGFI_NK* regfi_find_root_nk(REGFI_FILE* file, const REGFI_HBIN* hbin,
    1468                                 REGFI_ENCODING output_encoding)
     1464                            REGFI_ENCODING output_encoding)
    14691465{
    14701466  REGFI_NK* nk = NULL;
     
    15101506/******************************************************************************
    15111507 ******************************************************************************/
    1512 REGFI_FILE* regfi_alloc(int fd)
     1508REGFI_FILE* regfi_alloc(int fd, REGFI_ENCODING output_encoding)
    15131509{
    15141510  REGFI_FILE* ret_val;
     
    15271523  file_cb->seek = &regfi_raw_seek;
    15281524 
    1529   ret_val = regfi_alloc_cb(file_cb);
     1525  ret_val = regfi_alloc_cb(file_cb, output_encoding);
    15301526  if(ret_val == NULL)
    15311527    goto fail;
     
    15571553/******************************************************************************
    15581554 ******************************************************************************/
    1559 REGFI_FILE* regfi_alloc_cb(REGFI_RAW_FILE* file_cb)
     1555REGFI_FILE* regfi_alloc_cb(REGFI_RAW_FILE* file_cb,
     1556                           REGFI_ENCODING output_encoding)
    15601557{
    15611558  REGFI_FILE* rb;
     
    15771574  file_cb->seek(file_cb, 0, SEEK_SET);
    15781575
     1576  if(output_encoding != REGFI_ENCODING_UTF8
     1577     && output_encoding != REGFI_ENCODING_ASCII)
     1578  {
     1579    regfi_log_add(REGFI_LOG_ERROR, "Invalid output_encoding supplied"
     1580                  " in creation of regfi iterator.");
     1581    return NULL;
     1582  }
     1583
    15791584  /* Read file header */
    15801585  if ((rb = regfi_parse_regf(file_cb, false)) == NULL)
     
    15851590  rb->file_length = file_length;
    15861591  rb->cb = file_cb;
     1592  rb->string_encoding = output_encoding;
    15871593
    15881594  if(pthread_mutex_init(&rb->cb_lock, NULL) != 0)
     
    16641670 * rest of the file if that fails.
    16651671 ******************************************************************************/
    1666 REGFI_NK* regfi_rootkey(REGFI_FILE* file, REGFI_ENCODING output_encoding)
     1672REGFI_NK* regfi_rootkey(REGFI_FILE* file)
    16671673{
    16681674  REGFI_NK* nk = NULL;
     
    16741680
    16751681  root_offset = file->root_cell+REGFI_REGF_SIZE;
    1676   nk = regfi_load_key(file, root_offset, output_encoding, true);
     1682  nk = regfi_load_key(file, root_offset, file->string_encoding, true);
    16771683  if(nk != NULL)
    16781684  {
     
    16961702  {
    16971703    hbin = (REGFI_HBIN*)range_list_get(file->hbins, i)->data;
    1698     nk = regfi_find_root_nk(file, hbin, output_encoding);
     1704    nk = regfi_find_root_nk(file, hbin, file->string_encoding);
    16991705  }
    17001706
     
    17171723/******************************************************************************
    17181724 *****************************************************************************/
    1719 REGFI_ITERATOR* regfi_iterator_new(REGFI_FILE* file,
    1720                                    REGFI_ENCODING output_encoding)
     1725REGFI_ITERATOR* regfi_iterator_new(REGFI_FILE* file)
    17211726{
    17221727  REGFI_NK* root;
    17231728  REGFI_ITERATOR* ret_val;
    17241729
    1725   if(output_encoding != REGFI_ENCODING_UTF8
    1726      && output_encoding != REGFI_ENCODING_ASCII)
    1727   {
    1728     regfi_log_add(REGFI_LOG_ERROR, "Invalid output_encoding supplied"
    1729                   " in creation of regfi iterator.");
    1730     return NULL;
    1731   }
    1732 
    17331730  ret_val = talloc(NULL, REGFI_ITERATOR);
    17341731  if(ret_val == NULL)
    17351732    return NULL;
    17361733
    1737   root = regfi_rootkey(file, output_encoding);
     1734  root = regfi_rootkey(file);
    17381735  if(root == NULL)
    17391736  {
     
    17551752  ret_val->cur_subkey = 0;
    17561753  ret_val->cur_value = 0;
    1757   ret_val->string_encoding = output_encoding;
    17581754   
    17591755  return ret_val;
     
    18531849  while((subkey = regfi_iterator_cur_subkey(i)) != NULL && (found == false))
    18541850  {
    1855     if(subkey->keyname != NULL
    1856        && strcasecmp(subkey->keyname, subkey_name) == 0)
     1851    if(subkey->name != NULL
     1852       && strcasecmp(subkey->name, subkey_name) == 0)
    18571853      found = true;
    18581854    else
     
    19031899const REGFI_NK* regfi_iterator_cur_key(REGFI_ITERATOR* i)
    19041900{
     1901  /* XXX: do we need to add a NULL talloc reference here? */
    19051902  return i->cur_key;
    19061903}
     
    19091906/******************************************************************************
    19101907 *****************************************************************************/
    1911 const REGFI_SK* regfi_iterator_cur_sk(REGFI_ITERATOR* i)
    1912 {
    1913   if(i->cur_key == NULL || i->cur_key->sk_off == REGFI_OFFSET_NONE)
    1914     return NULL;
    1915 
    1916   return regfi_load_sk(i->f, i->cur_key->sk_off + REGFI_REGF_SIZE, true);
     1908const REGFI_SK* regfi_fetch_sk(REGFI_FILE* file, const REGFI_NK* key)
     1909{
     1910  if(key == NULL || key->sk_off == REGFI_OFFSET_NONE)
     1911    return NULL;
     1912
     1913  return regfi_load_sk(file, key->sk_off + REGFI_REGF_SIZE, true);
    19171914}
    19181915
     
    19411938
    19421939    return regfi_load_key(i->f, nk_offset+REGFI_REGF_SIZE,
    1943                           i->string_encoding, true);
     1940                          i->f->string_encoding, true);
    19441941  }
    19451942
     
    19671964  uint32_t old_value = i->cur_value;
    19681965
    1969   /* XXX: cur->valuename can be NULL in the registry. 
     1966  /* XXX: cur->name can be NULL in the registry. 
    19701967   *      Should we allow for a way to search for that?
    19711968   */
     
    19761973  while((cur = regfi_iterator_cur_value(i)) != NULL && (found == false))
    19771974  {
    1978     if((cur->valuename != NULL)
    1979        && (strcasecmp(cur->valuename, value_name) == 0))
     1975    if((cur->name != NULL)
     1976       && (strcasecmp(cur->name, value_name) == 0))
    19801977      found = true;
    19811978    else
     
    20192016    voffset = i->cur_key->values->elements[i->cur_value];
    20202017    ret_val = regfi_load_value(i->f, voffset+REGFI_REGF_SIZE,
    2021                                i->string_encoding, true);
     2018                               i->f->string_encoding, true);
    20222019  }
    20232020
     
    20382035/******************************************************************************
    20392036 *****************************************************************************/
    2040 const REGFI_CLASSNAME* regfi_iterator_fetch_classname(REGFI_ITERATOR* i,
    2041                                                       const REGFI_NK* key)
     2037const REGFI_CLASSNAME* regfi_fetch_classname(REGFI_FILE* file,
     2038                                             const REGFI_NK* key)
    20422039{
    20432040  REGFI_CLASSNAME* ret_val;
     
    20522049
    20532050  offset = key->classname_off + REGFI_REGF_SIZE;
    2054   max_size = regfi_calc_maxsize(i->f, offset);
     2051  max_size = regfi_calc_maxsize(file, offset);
    20552052  if(max_size <= 0)
    20562053    return NULL;
    20572054
    20582055  parse_length = key->classname_length;
    2059   raw = regfi_parse_classname(i->f, offset, &parse_length, max_size, true);
     2056  raw = regfi_parse_classname(file, offset, &parse_length, max_size, true);
    20602057 
    20612058  if(raw == NULL)
     
    20712068    return NULL;
    20722069
     2070  ret_val->offset = offset;
    20732071  ret_val->raw = raw;
    20742072  ret_val->size = parse_length;
     
    20782076
    20792077  conv_size = regfi_conv_charset(regfi_encoding_int2str(REGFI_ENCODING_UTF16LE),
    2080                                  regfi_encoding_int2str(i->string_encoding),
     2078                                 regfi_encoding_int2str(file->string_encoding),
    20812079                                 raw, interpreted,
    20822080                                 parse_length, parse_length);
     
    20852083    regfi_log_add(REGFI_LOG_WARN, "Error occurred while"
    20862084                  " converting classname to charset %s.  Error message: %s",
    2087                   i->string_encoding, strerror(-conv_size));
     2085                  file->string_encoding, strerror(-conv_size));
    20882086    talloc_free(interpreted);
    20892087    ret_val->interpreted = NULL;
     
    21022100/******************************************************************************
    21032101 *****************************************************************************/
    2104 const REGFI_DATA* regfi_iterator_fetch_data(REGFI_ITERATOR* i,
    2105                                             const REGFI_VK* value)
     2102const REGFI_DATA* regfi_fetch_data(REGFI_FILE* file,
     2103                                   const REGFI_VK* value)
    21062104{
    21072105  REGFI_DATA* ret_val = NULL;
     
    21102108  if(value->data_size != 0)
    21112109  {
    2112     raw_data = regfi_load_data(i->f, value->data_off, value->data_size,
     2110    raw_data = regfi_load_data(file, value->data_off, value->data_size,
    21132111                              value->data_in_offset, true);
    21142112    if(raw_data.buf == NULL)
     
    21322130      }
    21332131
    2134       if(!regfi_interpret_data(i->f, i->string_encoding, value->type, ret_val))
     2132      if(!regfi_interpret_data(file, file->string_encoding,
     2133                               value->type, ret_val))
    21352134      {
    21362135        regfi_log_add(REGFI_LOG_INFO, "Error occurred while"
     
    23442343 *****************************************************************************/
    23452344int32_t regfi_conv_charset(const char* input_charset, const char* output_charset,
    2346                          uint8_t* input, char* output,
    2347                          uint32_t input_len, uint32_t output_max)
     2345                           uint8_t* input, char* output,
     2346                           uint32_t input_len, uint32_t output_max)
    23482347{
    23492348  iconv_t conv_desc;
     
    26572656  ret_val->name_length = SVAL(nk_header, 0x48);
    26582657  ret_val->classname_length = SVAL(nk_header, 0x4A);
    2659   ret_val->keyname = NULL;
     2658  ret_val->name = NULL;
    26602659
    26612660  if(ret_val->name_length + REGFI_NK_MIN_LENGTH > ret_val->cell_size)
     
    26822681  }
    26832682
    2684   ret_val->keyname_raw = talloc_array(ret_val, uint8_t, ret_val->name_length);
    2685   if(ret_val->keyname_raw == NULL)
     2683  /* +1 to length in case we decided to use this directly as a string later */
     2684  ret_val->name_raw = talloc_array(ret_val, uint8_t, ret_val->name_length+1);
     2685  if(ret_val->name_raw == NULL)
    26862686    goto fail_locked;
    26872687
    26882688  /* Don't need to seek, should be at the right offset */
    26892689  length = ret_val->name_length;
    2690   if((regfi_read(file->cb, (uint8_t*)ret_val->keyname_raw, &length) != 0)
     2690  if((regfi_read(file->cb, (uint8_t*)ret_val->name_raw, &length) != 0)
    26912691     || length != ret_val->name_length)
    26922692  {
     
    27102710
    27112711uint8_t* regfi_parse_classname(REGFI_FILE* file, uint32_t offset,
    2712                              uint16_t* name_length, uint32_t max_size, bool strict)
     2712                               uint16_t* name_length, uint32_t max_size, bool strict)
    27132713{
    27142714  uint8_t* ret_val = NULL;
     
    28112811  ret_val->offset = offset;
    28122812  ret_val->cell_size = cell_length;
    2813   ret_val->valuename = NULL;
    2814   ret_val->valuename_raw = NULL;
     2813  ret_val->name = NULL;
     2814  ret_val->name_raw = NULL;
    28152815 
    28162816  if(ret_val->cell_size > max_size)
     
    28672867      cell_length+=8;
    28682868
    2869     ret_val->valuename_raw = talloc_array(ret_val, uint8_t, ret_val->name_length);
    2870     if(ret_val->valuename_raw == NULL)
     2869    /* +1 to length in case we decided to use this directly as a string later */
     2870    ret_val->name_raw = talloc_array(ret_val, uint8_t, ret_val->name_length+1);
     2871    if(ret_val->name_raw == NULL)
    28712872      goto fail_locked;
    28722873
    28732874    length = ret_val->name_length;
    2874     if((regfi_read(file->cb, (uint8_t*)ret_val->valuename_raw, &length) != 0)
     2875    if((regfi_read(file->cb, (uint8_t*)ret_val->name_raw, &length) != 0)
    28752876       || length != ret_val->name_length)
    28762877    {
  • trunk/python/pyregfi/__init__.py

    r205 r206  
    2929regfi.regfi_free_record.restype = None
    3030
     31regfi.regfi_fetch_classname.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_NK)]
     32regfi.regfi_fetch_classname.restype = POINTER(REGFI_CLASSNAME)
     33
     34regfi.regfi_fetch_sk.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_NK)]
     35regfi.regfi_fetch_sk.restype = POINTER(REGFI_SK)
     36
     37regfi.regfi_fetch_data.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_VK)]
     38regfi.regfi_fetch_data.restype = POINTER(REGFI_DATA)
     39
    3140regfi.regfi_iterator_new.argtypes = [POINTER(REGFI_FILE), REGFI_ENCODING]
    3241regfi.regfi_iterator_new.restype = POINTER(REGFI_ITERATOR)
     
    5059regfi.regfi_iterator_cur_key.restype = POINTER(REGFI_NK)
    5160
    52 regfi.regfi_iterator_cur_sk.argtypes = [POINTER(REGFI_ITERATOR)]
    53 regfi.regfi_iterator_cur_sk.restype = POINTER(REGFI_SK)
    54 
    5561regfi.regfi_iterator_first_subkey.argtypes = [POINTER(REGFI_ITERATOR)]
    5662regfi.regfi_iterator_first_subkey.restype = c_bool
     
    7682regfi.regfi_iterator_find_value.argtypes = [POINTER(REGFI_ITERATOR), c_char_p]
    7783regfi.regfi_iterator_find_value.restype = c_bool
    78 
    79 # XXX: possibly move REGFI_ENCODING to file object and eliminate need for ITERATOR here.
    80 regfi.regfi_iterator_fetch_classname.argtypes = [POINTER(REGFI_ITERATOR), POINTER(REGFI_NK)]
    81 regfi.regfi_iterator_fetch_classname.restype = POINTER(REGFI_CLASSNAME)
    82 
    83 regfi.regfi_iterator_fetch_data.argtypes = [POINTER(REGFI_ITERATOR), POINTER(REGFI_VK)]
    84 regfi.regfi_iterator_fetch_data.restype = POINTER(REGFI_DATA)
    8584
    8685
     
    9190
    9291def GetLogMessages():
    93     return regfi.regfi_log_get_str()
    94 
     92    msgs = regfi.regfi_log_get_str()
     93    if msgs == None:
     94        return ''
     95    return msgs
     96
     97
     98class _StructureWrapper():
     99    "Handles memory management and proxies attribute access to base structures"
     100    base = None
     101
     102    def __init__(self, base):
     103        # XXX: check for NULL here, throw an exception if so.
     104        self.base = base
     105
     106    def __del__(self):
     107        regfi.regfi_free_record(self.base)
     108
     109    def __getattr__(self, name):
     110        return getattr(self.base.contents, name)
     111
     112    def __eq__(self, other):
     113        return (type(self) == type(other)) and (self.offset == other.offset)
     114
     115    def __ne__(self, other):
     116        return (not self.__eq__(other))
     117
     118
     119class Key(_StructureWrapper):
     120    pass
     121
     122class Value(_StructureWrapper):
     123    pass
     124
     125class Data(_StructureWrapper):
     126    pass
     127
     128class Security(_StructureWrapper):
     129    pass
    95130
    96131class Hive():   
     
    126161        return HiveIterator(self)
    127162
     163    def subtree(self, path):
     164        hi = HiveIterator(self)
     165        hi.descend(path)
     166        return hi
     167
    128168
    129169class HiveIterator():
    130170    hive = None
    131171    iter = None
    132     root_traversed = False
     172    iteration_root = None
    133173
    134174    def __init__(self, hive):
     
    147187
    148188    def __iter__(self):
     189        self.iteration_root = None
    149190        return self
    150191
    151192    def __next__(self):
    152         if self.root_traversed:
    153             self.root_traversed = True
    154            
     193        if self.iteration_root == None:
     194            self.iteration_root = self.current_key()           
    155195        elif not regfi.regfi_iterator_down(self.iter):
    156196            up_ret = regfi.regfi_iterator_up(self.iter)
    157             while up_ret and not regfi.regfi_iterator_next_subkey(self.iter):
     197            while (up_ret and
     198                   not regfi.regfi_iterator_next_subkey(self.iter)):
     199                if self.iteration_root == self.current_key():
     200                    self.iteration_root = None
     201                    raise StopIteration('')
    158202                up_ret = regfi.regfi_iterator_up(self.iter)
    159203
     
    166210
    167211        regfi.regfi_iterator_first_subkey(self.iter)
    168         print(regfi.regfi_iterator_cur_key(self.iter).contents.keyname)
    169         return regfi.regfi_iterator_cur_key(self.iter)
    170 
     212        return self.current_key()
     213
     214    def down(self):
     215        pass
     216
     217    def up(self):
     218        pass
     219
     220    def descend(self, path):
     221        #set up generator
     222        cpath = (bytes(p,'ascii') for p in path)
     223
     224        # evaluate generator and create char* array
     225        apath = (c_char_p*len(path))(*cpath)
     226
     227        if not regfi.regfi_iterator_walk_path(self.iter,apath):
     228            raise Exception('Could not locate path.\n'+GetLogMessages())
     229
     230    def current_key(self):
     231        return Key(regfi.regfi_iterator_cur_key(self.iter))
  • trunk/python/pyregfi/structures.py

    r205 r206  
    8383REGFI_VK._fields_ = [('offset', c_uint32),
    8484                     ('cell_size', c_uint32),
    85                      ('valuename', c_char_p),
    86                      ('valuename_raw', POINTER(c_char)),
     85                     ('name', c_char_p),
     86                     ('name_raw', POINTER(c_char)),
    8787                     ('name_length', c_uint16),
    8888                     ('hbin_off', c_uint32),
     
    119119                     ('name_length', c_uint16),
    120120                     ('classname_length', c_uint16),
    121                      ('keyname', c_char_p),
    122                      ('keyname_raw', POINTER(c_char)),
     121                     ('name', c_char_p),
     122                     ('name_raw', POINTER(c_char)),
    123123                     ('parent_off', c_uint32),
    124124                     ('classname_off', c_uint32),
  • trunk/src/common.c

    r203 r206  
    324324  char* ret_val;
    325325
    326   if(nk->keyname == NULL)
    327     ret_val = quote_buffer(nk->keyname_raw, nk->name_length, key_special_chars);
     326  if(nk->name == NULL)
     327    ret_val = quote_buffer(nk->name_raw, nk->name_length, key_special_chars);
    328328  else
    329     ret_val = quote_string(nk->keyname, key_special_chars);
     329    ret_val = quote_string(nk->name, key_special_chars);
    330330
    331331  return ret_val;
     
    337337  char* ret_val;
    338338
    339   if(vk->valuename == NULL)
    340     ret_val = quote_buffer(vk->valuename_raw, vk->name_length,
     339  if(vk->name == NULL)
     340    ret_val = quote_buffer(vk->name_raw, vk->name_length,
    341341                           key_special_chars);
    342342  else
    343     ret_val = quote_string(vk->valuename, key_special_chars);
     343    ret_val = quote_string(vk->name, key_special_chars);
    344344
    345345  return ret_val;
  • trunk/src/reglookup-recover.c

    r203 r206  
    832832    regfi_log_set_mask(REGFI_LOG_ERROR);
    833833
    834   f = regfi_alloc(fd);
     834  /* XXX: add command line option to choose output encoding */
     835  f = regfi_alloc(fd, REGFI_ENCODING_ASCII);
    835836  if(f == NULL)
    836837  {
  • trunk/src/reglookup.c

    r203 r206  
    7777  }
    7878 
    79   data = regfi_iterator_fetch_data(iter, vk);
     79  data = regfi_fetch_data(iter->f, vk);
    8080
    8181  printMsgs(iter->f);
     
    304304  formatTime(&key->mtime, mtime);
    305305
    306   if(print_security && (sk=regfi_iterator_cur_sk(iter)))
     306  if(print_security && (sk=regfi_fetch_sk(iter->f, key)))
    307307  {
    308308    owner = regfi_get_owner(sk->sec_desc);
     
    321321      dacl = empty_str;
    322322
    323     classname = regfi_iterator_fetch_classname(iter, key);
     323    classname = regfi_fetch_classname(iter->f, key);
    324324    printMsgs(iter->f);
    325325    if(classname != NULL)
     
    636636  }
    637637   
    638   f = regfi_alloc(fd);
     638  /* XXX: add command line option to choose output encoding */
     639  f = regfi_alloc(fd, REGFI_ENCODING_ASCII);
    639640  if(f == NULL)
    640641  {
     
    643644  }
    644645
    645 
    646   /* XXX: add command line option to choose output encoding */
    647   iter = regfi_iterator_new(f, REGFI_ENCODING_ASCII);
     646  iter = regfi_iterator_new(f);
    648647  if(iter == NULL)
    649648  {
Note: See TracChangeset for help on using the changeset viewer.