forked from ssdeep-project/ssdeep
-
Notifications
You must be signed in to change notification settings - Fork 1
/
filedata.h
82 lines (61 loc) · 2.58 KB
/
filedata.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef __FILEDATA_H
#define __FILEDATA_H
/// @file filedata.h
// Copyright (C) 2012 Kyrus. See COPYING for details
// $Id$
#include <set>
#include <string>
#include <iostream>
#include <stdlib.h>
#include <assert.h>
#include "tchar-local.h"
/// Contains a fuzzy hash and associated metadata for file
class Filedata
{
public:
Filedata() : m_has_match_file(false) {}
/// Creates a new Filedata object with the given filename and signature
///
/// If sig is not valid, throws std::bad_alloc
Filedata(const TCHAR * fn, const char * sig, const char * match_file = NULL);
/// Creates a new Filedata object with the given filename and signature
///
/// If sig is not valid, throws std::bad_alloc
Filedata(const std::string& sig, const char * match_file = NULL);
/// Returns the file's fuzzy hash without a filename.
/// std::string("[blocksize]:[sig1]:[sig2]")
std::string get_signature(void) const { return m_signature; }
/// Returns the file's name
/// RBF - Should this be a std::wstring?
TCHAR * get_filename(void) const { return m_filename; }
/// Returns true if this file came from a file of known files on the disk
bool has_match_file(void) const { return m_has_match_file; }
/// Returns the name of the file on the disk from which this file came
/// RBF - Should this be a std::wstring?
std::string get_match_file(void) const { return m_match_file; }
/// Returns true if this file belongs to a cluster of similar files
bool has_cluster(void) const { return (m_cluster != NULL); }
void set_cluster(std::set<Filedata *> *c) { m_cluster = c; }
std::set<Filedata* >* get_cluster(void) const { return m_cluster; }
void clear_cluster(void);
~Filedata() { if (m_filename) { free(m_filename); } }
private:
Filedata(const Filedata &other) { (void) other; assert(false); /* never copy */ }
std::set<Filedata *> * m_cluster;
/// Original signature in the form [blocksize]:[sig1]:[sig2]
/// It may also contain the filename, but there is no guarantee of that
/// one way or the other.
std::string m_signature;
/// RBF - Should this be a std::wstring?
TCHAR * m_filename;
/// File of hashes where we got this known file from, if any
std::string m_match_file;
bool m_has_match_file;
/// Returns true if the m_signature field contains a valid fuzzy hash
bool valid(void) const;
};
/// Display [blocksize]:[sig1]:[sig2],"filename"
std::ostream& operator<<(std::ostream& o, const Filedata& f);
/// RBF - We can use this IF AND ONLY IF get_filename() returns a std::wstring
//bool operator==(const Filedata& a, const Filedata& b);
#endif // ifndef __FILEDATA_H