diff --git a/tsk/hashdb/hdb_index.cpp b/tsk/hashdb/hdb_index.cpp index 6827c1223a5549504f6ef388f219c064249bd318..b96c2a33ffa9c0c2d058640df35635faef378e69 100644 --- a/tsk/hashdb/hdb_index.cpp +++ b/tsk/hashdb/hdb_index.cpp @@ -81,6 +81,30 @@ tsk_idx_close_file(FILE * idx) } } +/** + * Update the hash type. New indices can handle multiple hash types, so hash + * type is now dependent on what the client is doing (e.g. lookup md5). + * @return 1 on error, 0 on success + */ +static int +hdb_update_htype(TSK_HDB_INFO * hdb_info, uint8_t htype) +{ + /* Get hash type specific information */ + switch (htype) { + case TSK_HDB_HTYPE_MD5_ID: + hdb_info->hash_type = static_cast<TSK_HDB_HTYPE_ENUM>(htype); + hdb_info->hash_len = TSK_HDB_HTYPE_MD5_LEN; + break; + case TSK_HDB_HTYPE_SHA1_ID: + hdb_info->hash_type = static_cast<TSK_HDB_HTYPE_ENUM>(htype); + hdb_info->hash_len = TSK_HDB_HTYPE_SHA1_LEN; + break; + default: + return 1; + } + return 0; +} + /** * Open an index for the given hash db * We only create kdb (SQLite) files, but can open old indexes. @@ -117,27 +141,16 @@ tsk_idx_open(TSK_HDB_INFO * hdb_info, uint8_t htype, uint8_t create) return NULL; } - /* Get hash type specific information */ - switch (htype) { - case TSK_HDB_HTYPE_MD5_ID: - hdb_info->hash_type = static_cast<TSK_HDB_HTYPE_ENUM>(htype); - hdb_info->hash_len = TSK_HDB_HTYPE_MD5_LEN; - break; - case TSK_HDB_HTYPE_SHA1_ID: - hdb_info->hash_type = static_cast<TSK_HDB_HTYPE_ENUM>(htype); - hdb_info->hash_len = TSK_HDB_HTYPE_SHA1_LEN; - break; - default: - free(idx_info); - tsk_error_reset(); - tsk_error_set_errno(TSK_ERR_HDB_MISSING); - tsk_error_set_errstr( - "tsk_idx_open: Unknown hash type: %d\n", - (int)htype); - return NULL; + if (hdb_update_htype(hdb_info, htype) == 1) { + free(idx_info); + tsk_error_reset(); + tsk_error_set_errno(TSK_ERR_HDB_MISSING); + tsk_error_set_errstr( + "tsk_idx_open: Unknown hash type: %d\n", + (int)htype); + return NULL; } - // Verify the new SQLite index exists, get its size, and open it for header reading // Set SQLite index filename @@ -308,6 +321,9 @@ hdb_setupindex(TSK_HDB_INFO * hdb_info, uint8_t htype, uint8_t create) // already opened if (hdb_info->idx_info != NULL) { + // update htype + hdb_update_htype(hdb_info, htype); + tsk_release_lock(&hdb_info->lock); return 0; } diff --git a/tsk/hashdb/sqlite_index.cpp b/tsk/hashdb/sqlite_index.cpp index 67e6a8c5e4e4de73c3321f17d80794f8d800f7c5..3ff82422c68c75cae943811cc02d6c88e3b1e744 100644 --- a/tsk/hashdb/sqlite_index.cpp +++ b/tsk/hashdb/sqlite_index.cpp @@ -506,7 +506,7 @@ sqlite_v1_lookup_raw(TSK_HDB_INFO * hdb_info, uint8_t * hvalue, uint8_t len, tsk_error_reset(); tsk_error_set_errno(TSK_ERR_HDB_ARG); tsk_error_set_errstr("hdb_lookup: Hash passed is different size than expected: %d vs %d", - hdb_info->hash_len, len); + hdb_info->hash_len, (len * 2)); ret = -1; } else {