Ignore:
Timestamp:
03/13/10 12:56:36 (14 years ago)
Author:
tim
Message:

reworked I/O to use callback functions

fixed a bug in mtime validation and consolidated time formatting code

File:
1 edited

Legend:

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

    r173 r178  
    4040
    4141
    42 char* getQuotedData(int fd, uint32_t offset, uint32_t length)
     42char* getQuotedData(REGFI_RAW_FILE* file_cb, uint32_t offset, uint32_t length)
    4343{
    4444  uint8_t* buf;
     
    4646  uint32_t len;
    4747
    48   if((lseek(fd, offset, SEEK_SET)) == -1)
     48  if((regfi_seek(file_cb, offset, SEEK_SET)) == -1)
    4949    return NULL;
    5050
     
    5454
    5555  len = length;
    56   if((regfi_read(fd, buf, &length) != 0) || length != len)
     56  if((regfi_read(file_cb, buf, &length) != 0) || length != len)
    5757  {
    5858    free(buf);
     
    6969void printKey(REGFI_FILE* f, REGFI_NK_REC* nk, const char* prefix)
    7070{
    71   char mtime[20];
    72   time_t tmp_time[1];
    73   struct tm* tmp_time_s = NULL;
     71  char mtime[24];
    7472  char* quoted_name = NULL;
    7573  char* quoted_raw = "";
    7674
    77   *tmp_time = regfi_nt2unix_time(&nk->mtime);
    78   tmp_time_s = gmtime(tmp_time);
    79   strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", tmp_time_s);
    80 
     75  formatTime(&nk->mtime, mtime);
     76 
    8177  /* XXX: Add command line option to choose output encoding */
    8278  regfi_interpret_keyname(f, nk, REGFI_ENCODING_ASCII, true);
     
    9692
    9793  if(print_parsedraw)
    98     quoted_raw = getQuotedData(f->fd, nk->offset, nk->cell_size);
     94    quoted_raw = getQuotedData(f->cb, nk->offset, nk->cell_size);
    9995
    10096  printf("%.8X,%.8X,KEY,%s,%s,%s,%d,,,,,,,,%s\n", nk->offset, nk->cell_size,
     
    162158
    163159  if(print_parsedraw)
    164     quoted_raw = getQuotedData(f->fd, vk->offset, vk->cell_size);
     160    quoted_raw = getQuotedData(f->cb, vk->offset, vk->cell_size);
    165161
    166162  str_type = regfi_type_val2str(vk->type);
     
    195191
    196192  if(print_parsedraw)
    197     quoted_raw = getQuotedData(f->fd, sk->offset, sk->cell_size);
     193    quoted_raw = getQuotedData(f->cb, sk->offset, sk->cell_size);
    198194
    199195  if(owner == NULL)
     
    229225  bool unalloc;
    230226
    231   if(!regfi_parse_cell(f->fd, offset, NULL, 0, &cell_length, &unalloc))
     227  if(!regfi_parse_cell(f->cb, offset, NULL, 0, &cell_length, &unalloc))
    232228    return 1;
    233229
    234   quoted_buf = getQuotedData(f->fd, offset, cell_length);
     230  quoted_buf = getQuotedData(f->cb, offset, cell_length);
    235231  if(quoted_buf == NULL)
    236232    return 2;
     
    490486        max_size = regfi_calc_maxsize(file, offset);
    491487        if(max_size >= 0
    492            && regfi_parse_cell(file->fd, offset, NULL, 0,
     488           && regfi_parse_cell(file->cb, offset, NULL, 0,
    493489                               &cell_length, &unalloc)
    494490           && (cell_length & 0x00000007) == 0
     
    789785  REGFI_VK_REC* tmp_value;
    790786  uint32_t argi, arge, i, j, ret, num_unalloc_keys;
    791  
     787  int fd;
     788
    792789  /* Process command line arguments */
    793790  if(argc < 2)
     
    826823    bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Memory allocation problem.\n");
    827824
    828   f = regfi_open(registry_file);
    829   if(f == NULL)
     825  fd = openHive(registry_file);
     826  if(fd < 0)
    830827  {
    831828    fprintf(stderr, "ERROR: Couldn't open registry file: %s\n", registry_file);
    832829    bailOut(REGLOOKUP_EXIT_NOINPUT, "");
    833830  }
     831
     832  f = regfi_alloc(fd);
     833  if(f == NULL)
     834  {
     835    close(fd);
     836    bailOut(REGLOOKUP_EXIT_NOINPUT, "ERROR: Failed to create REGFI_FILE structure.\n");
     837  }
     838
    834839  if(print_verbose)
    835840    regfi_set_message_mask(f, REGFI_MSG_ERROR|REGFI_MSG_WARN|REGFI_MSG_INFO);
     
    991996  range_list_free(unalloc_sks);
    992997
     998  regfi_free(f);
     999  close(fd);
     1000
    9931001  return 0;
    9941002}
Note: See TracChangeset for help on using the changeset viewer.