-
Notifications
You must be signed in to change notification settings - Fork 5
/
tsk3.h
275 lines (207 loc) · 7.32 KB
/
tsk3.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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/* SleuthKit functions.
*
* Copyright 2010, Michael Cohen <[email protected]>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if !defined( TSK3_H_ )
#define TSK3_H_
#if defined( HAVE_TSK3_LIBTSK_H )
#include <tsk3/libtsk.h>
#elif defined( HAVE_TSK_LIBTSK_H )
#include <tsk/libtsk.h>
#else
#error Missing libtsk header
#endif
#include "class.h"
#include "aff4_errors.h"
typedef struct {
TSK_IMG_INFO base;
struct Img_Info_t *container;
} Extended_TSK_IMG_INFO;
BIND_STRUCT(Extended_TSK_IMG_INFO);
/** Bind the following structs */
BIND_STRUCT(TSK_FS_INFO);
BIND_STRUCT(TSK_FS_NAME);
BIND_STRUCT(TSK_FS_META);
BIND_STRUCT(TSK_FS_DIR);
BIND_STRUCT(TSK_FS_FILE);
BIND_STRUCT(TSK_FS_BLOCK);
BIND_STRUCT(TSK_FS_ATTR);
BIND_STRUCT(TSK_FS_ATTR_RUN);
BIND_STRUCT(TSK_VS_PART_INFO);
BIND_STRUCT(TSK_VS_INFO);
/** This is a normal IMG_INFO which takes a filename and passes it
to TSK. It just uses the standard TSK image handling code to
support EWF, AFF etc.
This is usually the first object you would instantiate in order to
use the TSK library:
img = Img_Info(filename)
you would then pass it to an FS_Info object:
fs = FS_Info(img)
Then open an inode or path
f = fs.open_dir(inode = 2)
*/
CLASS(Img_Info, Object)
PRIVATE Extended_TSK_IMG_INFO *img;
/* Value to indicate if img is managed internally
*/
PRIVATE int img_is_internal;
/* Value to indicate if img is open
*/
PRIVATE int img_is_open;
/* Open an image using the Sleuthkit.
*
* DEFAULT(type) = TSK_IMG_TYPE_DETECT;
* DEFAULT(url) = "";
*/
Img_Info METHOD(Img_Info, Con, ZString url, TSK_IMG_TYPE_ENUM type);
/* Read a random buffer from the image */
uint64_t METHOD(Img_Info, read, TSK_OFF_T off, OUT char *buf, size_t len);
/* Retrieve the size of the image */
uint64_t METHOD(Img_Info, get_size);
/* Closes the image */
void METHOD(Img_Info, close);
END_CLASS
/** This object handles volumes.
*/
CLASS(Volume_Info, Object)
FOREIGN TSK_VS_INFO *info;
int current;
/** Open a volume using the Sleuthkit.
DEFAULT(offset) = 0;
DEFAULT(type) = TSK_VS_TYPE_DETECT;
*/
Volume_Info METHOD(Volume_Info, Con, Img_Info img,
TSK_VS_TYPE_ENUM type, TSK_OFF_T offset);
void METHOD(Volume_Info, __iter__);
TSK_VS_PART_INFO *METHOD(Volume_Info, iternext);
END_CLASS
// Forward declerations
struct FS_Info_t;
struct Directory_t;
/** An attribute is associated with a file. In some filesystem
(e.g. NTFS) a file may contain many attributes.
Attributes can be iterated over to obtain the attribute runs
(e.g. to recover block allocation information).
*/
CLASS(Attribute, Object)
FOREIGN TSK_FS_ATTR *info;
FOREIGN TSK_FS_ATTR_RUN *current;
Attribute METHOD(Attribute, Con, TSK_FS_ATTR *info);
void METHOD(Attribute, __iter__);
TSK_FS_ATTR_RUN *METHOD(Attribute, iternext);
END_CLASS
/** This represents a file object. A file has both metadata and
data streams.
Its usually not useful to instantiate this class by itself -
you need to call FS_Info.open() or iterate over a Directory()
object.
This object may be used to read the content of the file using
read_random().
Iterating over this object will return all the attributes for
this file.
*/
CLASS(File, Object)
FOREIGN TSK_FS_FILE *info;
/* Value to indicate if info is managed internally
*/
PRIVATE int info_is_internal;
PRIVATE struct FS_Info_t *fs;
int max_attr;
int current_attr;
File METHOD(File, Con, struct FS_Info_t *fs, TSK_FS_FILE *info);
/** Read a buffer from a random location in the file.
DEFAULT(flags) = 0;
DEFAULT(type) = TSK_FS_ATTR_TYPE_DEFAULT;
DEFAULT(id) = -1;
*/
uint64_t METHOD(File, read_random, TSK_OFF_T offset,
OUT char *buff, int len,
TSK_FS_ATTR_TYPE_ENUM type, int id,
TSK_FS_FILE_READ_FLAG_ENUM flags);
/* Obtain a directory object that represents this inode. This may
be useful if the file is actually a directory and we want to
iterate over its contents.
*/
struct Directory_t *METHOD(File, as_directory);
void METHOD(File, __iter__);
Attribute METHOD(File, iternext);
END_CLASS
/** This represents a Directory within the filesystem. You can
iterate over this object to obtain all the File objects
contained within this directory:
for f in d:
print f.info.name.name
*/
CLASS(Directory, Object)
TSK_FS_DIR *info;
PRIVATE struct FS_Info_t *fs;
/* Total number of files in this directory */
size_t size;
/* Current file returned in the next iteration */
int current;
/* We can open the directory using a path, its inode number.
DEFAULT(path) = NULL;
DEFAULT(inode) = 0;
*/
Directory METHOD(Directory, Con, struct FS_Info_t *fs, \
ZString path, TSK_INUM_T inode);
/** An iterator of all files in the present directory. */
void METHOD(Directory, __iter__);
File METHOD(Directory, iternext);
END_CLASS
/** This is used to obtain a filesystem object from an Img_Info object.
From this FS_Info we can open files or directories by inode, or
path.
*/
CLASS(FS_Info, Object)
FOREIGN TSK_FS_INFO *info;
PRIVATE Extended_TSK_IMG_INFO *extended_img_info;
/** Open the filesystem stored on image.
DEFAULT(type) = TSK_FS_TYPE_DETECT;
DEFAULT(offset) = 0;
*/
FS_Info METHOD(FS_Info, Con, Img_Info img, TSK_OFF_T offset,
TSK_FS_TYPE_ENUM type);
/** A convenience function to open a directory in this image.
DEFAULT(path) = NULL;
DEFAULT(inode) = 2;
*/
Directory METHOD(FS_Info, open_dir, ZString path, TSK_INUM_T inode);
/** A convenience function to open a file in this image. */
File METHOD(FS_Info, open, ZString path);
// Open a file by inode number
File METHOD(FS_Info, open_meta, TSK_INUM_T inode);
/**
* Walk a range of file system blocks and call the callback function
* with the contents and allocation status of each.
* See tsk_fs_block_walk() for details.
* @param a_start_blk Block address to start walking from
* @param a_end_blk Block address to walk to
* @param a_flags Flags used during walk to determine which blocks to call callback with
* @param a_action Callback function
* @param a_ptr Pointer that will be passed to callback
* @returns 1 on error and 0 on success
*/
uint8_t METHOD(FS_Info, blockstat, TSK_DADDR_T blk_addr);
void METHOD(FS_Info, exit);
END_CLASS
// To Do : BLOCK INFO CLASS
/**
CLASS(BLCOK_INFO, Object)
END_CLASS
*/
int *tsk_get_current_error(char **buff);
void tsk_init(void);
#endif /* !TSK3_H_ */