This file is indexed.

/usr/include/dclib-0.3/dclib/cfilehasher.h is in libdc-dev 0.3.24~svn3121-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/***************************************************************************
        cfilehasher.h  -  Calculate the TTH root and leaves for a file
                             -------------------
    begin                : Fri May 16 2008
    copyright            : (C) 2008 by Edward Sheldrake
    email                : ejs1920@yahoo.co.uk
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef CFILEHASHER_H
#define CFILEHASHER_H

/**
 * @author Edward Sheldrake
 *
 * It's a wrapper for the tiger tree hashing functions, which currently
 * come from the DC++ source.
 *
 * However it was designed to hash files, and was never used. Much more
 * useful is to hash the data as it is received to verify it, dclib doesn't
 * do that either. Only the ValidateHashLeaves() function is used for hash
 * database verification plus maybe HashSize() is used in valknut, since
 * the DC++ headers are not installed.
 */

#include <dclib/dcos.h>
#include <dclib/core/cthread.h>
#include <dclib/core/cstring.h>
#include <dclib/core/cfile.h>

#include <dclib/core/clist.h>

/* The DC++ sources use different types than dclib: int64_t vs ulonglong */
#include <stdint.h>

class CByteArray;

/** */
enum eFileHasherStatus {
	efhsNotStarted=0,
	efhsReady,
	efhsWorking,
	efhsFinished,
	efhsError
};

class CHashedSegment {

public:
	/** Constructor */
	CHashedSegment() {
		start = 0;
		size  = 0;
	};
	/** Destructor */
	~CHashedSegment() { };
	
	/** start position */
	ulonglong start;
	/** chunk size */
	ulonglong size;
	/** expected hash, base32 encoded */
	CString expected;
	/** actual hash, base32 encoded */
	CString actual;
};

class CTreeVerificationReport {

public:
	/** Constructor */
	CTreeVerificationReport() {
		filesize = 0;
		allgood  = false;
		segments = new CList<CHashedSegment>;
	};
	
	/** Copy constructor */
	CTreeVerificationReport( const CTreeVerificationReport & other );
	
	/** Destructor */
	~CTreeVerificationReport() {
		delete segments;
		segments = 0;
	};
	
	/** Returns a nice string of the data that you can print out. */
	CString ToString() const;
	
	/** full name of file */
	CString filename;
	/** actual TTH root */
	CString tthRoot;
	/** file size */
	ulonglong filesize;
	/** true if all hashes matched */
	bool allgood;
	/** the list of file segments and their hashes */
	CList<CHashedSegment> * segments;
};
class CFileHasher {

public:
	/** Constructor */
	CFileHasher( const CString filename, CByteArray * workmem = 0 );
	/** Destructor */
	virtual ~CFileHasher();
	
	/** 
	 * Calculate the hash.
	 * Sets status to the given value when finished.
	 */
	void ComputeHash( const eFileHasherStatus doneStatus = efhsFinished );
	/** Stop the hashing */
	void StopHashing();
	/** */
	bool IsStop() const { return m_bStop; };
	/** Get status */
	eFileHasherStatus GetStatus() const { return status; };
	/** Get progress as number of bytes hashed */
	ulonglong GetProgress() const { return m_nProgress; };
	/** Get the filesize */
	ulonglong GetFileSize() const { return filesize; };
	/** Get the TTH root as a base32 encoded cstring */
	CString GetHashRoot();
	/** Returns a newly allocated copy of the hash root data */
	CByteArray * GetHashRootRaw();
	/** Returns a newly allocated copy of the hash leaf data */
	CByteArray * GetLeafData();
	/** Returns a pointer to the hash root data, so be careful with it.*/
	CByteArray * HashRootDirect() { return m_pRootData; };
	/** Returns a pointer to the hash leaf data, so be careful with it.*/
	CByteArray * HashLeavesDirect() { return m_pLeafData; };
	
	/** Returns true if the base32 encoded TTH root matches the TTH leaf data */
	static bool ValidateHashLeaves( const CString tth, CByteArray * leaves, const ulonglong filesize );
	/** The same, but with the raw TTH root not the base32 encoded string */
	static bool ValidateHashLeaves( CByteArray * root, CByteArray * leaves, const ulonglong filesize );
	/** */
	static int64_t GetBlockSize( const unsigned long leavesSize, const int64_t filesize );
	/** Get the root TTH of a bytearray as raw */
	static CByteArray * HashByteArray( CByteArray * data, unsigned long size );
	/** Get the size in bytes of the unencoded TTH value */
	static unsigned long HashSize();

protected:
	/** The file to hash */
	CFile file;
	/** The size of the file */
	ulonglong filesize;	
	/** Number of bytes hashed so far */
	ulonglong m_nProgress;
	/** Memory area to read file data to */
	CByteArray * m_pWorkMem;
	/** True if we allocated our own */
	bool usingOwnMem;
	/** Store the final TTH root data */
	CByteArray * m_pRootData;
	/** Store the final leaf data */
	CByteArray * m_pLeafData;
	/** Status */
	eFileHasherStatus status;
	/** Set to true to stop the hashing */
	bool m_bStop;
};

class CFileHasherThread : public CFileHasher, public CThread {

public:
	/** Constructor */
	CFileHasherThread ( const CString filename, CByteArray * workmem = 0 ) : CFileHasher( filename, workmem ) { };
	/** Destructor */
	virtual ~CFileHasherThread() { };
	
	/** Thread callback function */
	virtual void Thread();
};

class CFileTreeVerifier: public CFileHasher, public CThread {

public:
	/** Constructor */
	CFileTreeVerifier( const CString filename, CByteArray * leaves, CByteArray * workmem = 0 );
	/** Destructor */
	virtual ~CFileTreeVerifier();
	
	/**
	 * Gets the results of the verification.
	 * If finished, Returns the pointer to our report and sets m_pReport=0
	 * so we won't delete it when we're deleted.
	 * Whoever gets it must delete it when done with it.
	 * Otherwise returns 0 (and returns 0 the second time if you call it twice).
	 */
	CTreeVerificationReport * GetReport();
	
	/** Thread callback function */
	virtual void Thread();
	/** */
	int GetPass() const { return m_nPass; };

private:
	/** The hash leaves we are going to compare the file with */
	CByteArray * m_pLeaves;
	/** The output of the verification */
	CTreeVerificationReport * m_pReport;
	/** Set to 1 when hashing file or 2 when checking segments */
	int m_nPass;
};

#endif // CFILEHASHER_H