@@ -81,6 +81,30 @@ tsk_idx_close_file(FILE * idx)
81
81
}
82
82
}
83
83
84
+ /* *
85
+ * Update the hash type. New indices can handle multiple hash types, so hash
86
+ * type is now dependent on what the client is doing (e.g. lookup md5).
87
+ * @return 1 on error, 0 on success
88
+ */
89
+ static int
90
+ hdb_update_htype (TSK_HDB_INFO * hdb_info, uint8_t htype)
91
+ {
92
+ /* Get hash type specific information */
93
+ switch (htype) {
94
+ case TSK_HDB_HTYPE_MD5_ID:
95
+ hdb_info->hash_type = static_cast <TSK_HDB_HTYPE_ENUM>(htype);
96
+ hdb_info->hash_len = TSK_HDB_HTYPE_MD5_LEN;
97
+ break ;
98
+ case TSK_HDB_HTYPE_SHA1_ID:
99
+ hdb_info->hash_type = static_cast <TSK_HDB_HTYPE_ENUM>(htype);
100
+ hdb_info->hash_len = TSK_HDB_HTYPE_SHA1_LEN;
101
+ break ;
102
+ default :
103
+ return 1 ;
104
+ }
105
+ return 0 ;
106
+ }
107
+
84
108
/* *
85
109
* Open an index for the given hash db
86
110
* 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)
117
141
return NULL ;
118
142
}
119
143
120
- /* Get hash type specific information */
121
- switch (htype) {
122
- case TSK_HDB_HTYPE_MD5_ID:
123
- hdb_info->hash_type = static_cast <TSK_HDB_HTYPE_ENUM>(htype);
124
- hdb_info->hash_len = TSK_HDB_HTYPE_MD5_LEN;
125
- break ;
126
- case TSK_HDB_HTYPE_SHA1_ID:
127
- hdb_info->hash_type = static_cast <TSK_HDB_HTYPE_ENUM>(htype);
128
- hdb_info->hash_len = TSK_HDB_HTYPE_SHA1_LEN;
129
- break ;
130
- default :
131
- free (idx_info);
132
- tsk_error_reset ();
133
- tsk_error_set_errno (TSK_ERR_HDB_MISSING);
134
- tsk_error_set_errstr (
135
- " tsk_idx_open: Unknown hash type: %d\n " ,
136
- (int )htype);
137
- return NULL ;
144
+ if (hdb_update_htype (hdb_info, htype) == 1 ) {
145
+ free (idx_info);
146
+ tsk_error_reset ();
147
+ tsk_error_set_errno (TSK_ERR_HDB_MISSING);
148
+ tsk_error_set_errstr (
149
+ " tsk_idx_open: Unknown hash type: %d\n " ,
150
+ (int )htype);
151
+ return NULL ;
138
152
}
139
153
140
-
141
154
// Verify the new SQLite index exists, get its size, and open it for header reading
142
155
143
156
// Set SQLite index filename
@@ -308,6 +321,9 @@ hdb_setupindex(TSK_HDB_INFO * hdb_info, uint8_t htype, uint8_t create)
308
321
309
322
// already opened
310
323
if (hdb_info->idx_info != NULL ) {
324
+ // update htype
325
+ hdb_update_htype (hdb_info, htype);
326
+
311
327
tsk_release_lock (&hdb_info->lock );
312
328
return 0 ;
313
329
}
0 commit comments