Skip to content

Commit

Permalink
use strrchr and strcpy, rename name_from_path function
Browse files Browse the repository at this point in the history
  • Loading branch information
dickfickling committed May 9, 2012
1 parent d8f129a commit 4a5aff1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 23 deletions.
4 changes: 3 additions & 1 deletion tsk3/hashdb/encase_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ encase_name(TSK_HDB_INFO * hdb_info)
UTF16 *utf16;
UTF8 *utf8;
size_t ilen;
hdb_info->db_name[0] = '\0';
if(!hFile)
return;

memset(buf, '\0', 40);

fseeko(hFile, 1032, SEEK_SET);
if (39 != fread(buf, sizeof(wchar_t), 39, hFile))
return;

ilen = wcslen(buf);
buf[ilen++] = '\0';

utf8 = (UTF8 *) ret8;
utf16 = (UTF16 *) buf;
Expand Down
2 changes: 1 addition & 1 deletion tsk3/hashdb/hk_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ hk_test(FILE * hFile)
void
hk_name(TSK_HDB_INFO * hdb_info)
{
tsk_name_from_path(hdb_info);
tsk_hdb_name_from_path(hdb_info);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tsk3/hashdb/md5sum_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ md5sum_test(FILE * hFile)
void
md5sum_name(TSK_HDB_INFO * hdb_info)
{
tsk_name_from_path(hdb_info);
tsk_hdb_name_from_path(hdb_info);
}


Expand Down
2 changes: 1 addition & 1 deletion tsk3/hashdb/nsrl_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ nsrl_test(FILE * hFile)
void
nsrl_name(TSK_HDB_INFO * hdb_info)
{
tsk_name_from_path(hdb_info);
tsk_hdb_name_from_path(hdb_info);
}

/**
Expand Down
28 changes: 10 additions & 18 deletions tsk3/hashdb/tm_lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1321,32 +1321,24 @@ tsk_hdb_nameinit(TSK_HDB_INFO * hdb_info)
* @param hdb_info the hash database object
*/
void
tsk_name_from_path(TSK_HDB_INFO * hdb_info)
tsk_hdb_name_from_path(TSK_HDB_INFO * hdb_info)
{
size_t lastSeparatorIndex = 0;
size_t lastPeriodIndex = 0;
size_t len = TSTRLEN(hdb_info->db_fname);
size_t i = 0;
#ifdef TSK_WIN32
char path_char = '\\';
#else
char path_char = '/';
#endif
char * begin = strrchr(hdb_info->db_fname, path_char);
char * end = strrchr(hdb_info->db_fname, '.');
int i;

for (i = len-1; i > 0; --i)
{
if (hdb_info->db_fname[i] == '.' && !lastPeriodIndex)
lastPeriodIndex = i;
if (hdb_info->db_fname[i] == path_char)
{
lastSeparatorIndex = ++i;
break;
}
}
for(i = 0; i < (len-lastSeparatorIndex) && i < (lastPeriodIndex-lastSeparatorIndex); i++)
if(!end)
end = begin + strlen(begin);

for(i = 0; i < (end-begin); i++)
{
hdb_info->db_name[i] = (char) hdb_info->db_fname[lastSeparatorIndex+i];
hdb_info->db_name[i] = begin[i];
}

hdb_info->db_name[i] = '\0';
hdb_info->db_name[i+1] = '\0';
}
2 changes: 1 addition & 1 deletion tsk3/hashdb/tsk_hashdb_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extern "C" {
unsigned char *hvalue, int hlen,
TSK_OFF_T offset);
extern uint8_t tsk_hdb_idxfinalize(TSK_HDB_INFO *);
extern void tsk_name_from_path(TSK_HDB_INFO *);
extern void tsk_hdb_name_from_path(TSK_HDB_INFO *);
extern void tsk_hdb_nameinit(TSK_HDB_INFO *);

/* Functions */
Expand Down

0 comments on commit 4a5aff1

Please sign in to comment.