-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRipper.h
More file actions
124 lines (98 loc) · 3.11 KB
/
Ripper.h
File metadata and controls
124 lines (98 loc) · 3.11 KB
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
/***********************************************************************
* Copyright 2007-2010 Michael Drueing <michael@drueing.de>
*
* 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) version 3 or any later version
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************/
#ifndef RIPPER_H
#define RIPPER_H
#define FROM_BIG_ENDIAN(a) ((((a)>>24)&0xFF) | (((a)>>8)&0xFF00) | (((a)<<8)&0xFF0000) | (((a)<<24)&0xFF000000))
enum FoundCriterium
{
CRIT_NONE = 0x00,
CRIT_WEAK = 0x01, // not sure if file is really of expected type; flag it accordingly
CRIT_STRONG = 0x02 // file is almost certainly correct
};
#define HS_END \
{0, 0, 0, 0},
#define HS(h, l) \
{h, l, 0, 0},
#define HS_U(h, l, u) \
{h, l, 0, u},
#define HS_X(h, l, e) \
{h, l, e, 0},
#define HS_F(h, l, e, u) \
{h, l, e, u},
// defines one header to search for
struct HeaderStruct
{
// the pattern to look for
const char *header;
// the length of the pattern
int length;
// number of bytes in the file _before_ the pattern
// (normally this is 0, see MODRipper for an example where it's not)
int extra_len_before;
// even more user data
void *user_data;
};
struct FoundStruct
{
// the start offset where the file begins
unsigned char *startoffset;
// the total length of the file
unsigned long length;
// how sure are we that we have the expected file?
FoundCriterium criterium;
// proposed extension for this file
char extension[10];
};
class Ripper
{
protected:
unsigned char *m_start;
unsigned long m_length;
public:
// returns a list of headers to look out for
virtual const HeaderStruct *getHeaders() const = 0;
// return the name of this module
virtual const char *getName() const = 0;
// prepare for scanning a file
virtual void setupFile(unsigned char *start, unsigned long length)
{
m_start = start;
m_length = length;
}
// check if this offset really contains a valid file
virtual bool checkLocation(unsigned char *pos, const HeaderStruct *header, FoundStruct *found) = 0;
// this can be used to check the size of some structs, to see whether compilation bugs arise
// the default just returns true, subclasses should overload this and return false if something went
// wrong. The main program will then abort and print a message
virtual bool checkCompileAssertions()
{
return true;
}
};
// for smaller .h files implementing ripper modules:
#define IMPLEMENT_DEFAULT_RIPPER_INTERFACE \
public: \
virtual const HeaderStruct *getHeaders() const \
{ \
return &s_headers[0]; \
} \
\
virtual const char *getName() const \
{ \
return s_name; \
}
#endif