File: database_types.c

package info (click to toggle)
libesedb 20181229-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 15,672 kB
  • sloc: ansic: 246,874; sh: 6,096; makefile: 1,680; python: 309; sed: 16
file content (203 lines) | stat: -rw-r--r-- 6,046 bytes parent folder | download | duplicates (2)
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
/*
 * Database types
 *
 * Copyright (C) 2009-2018, Joachim Metz <joachim.metz@gmail.com>
 *
 * Refer to AUTHORS for acknowledgements.
 *
 * This software is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This software 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 Lesser General Public License
 * along with this software.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <common.h>
#include <narrow_string.h>
#include <system_string.h>
#include <types.h>
#include <wide_string.h>

#include "database_types.h"
#include "esedbtools_libcdata.h"
#include "esedbtools_libcerror.h"

const system_character_t *database_type_descriptions[ ] = {
	_SYSTEM_STRING( "Unknown" ),
	_SYSTEM_STRING( "Exchange" ),
	_SYSTEM_STRING( "System Resource Usage Monitor (SRUM)" ),
	_SYSTEM_STRING( "MSIE WebCache" ),
	_SYSTEM_STRING( "Windows Search" ),
	_SYSTEM_STRING( "Windows Security" ),
};

database_type_descriptor_t database_type_descriptors[ ] = {
	{ DATABASE_TYPE_EXCHANGE, {
		_SYSTEM_STRING( "Folders" ),
		_SYSTEM_STRING( "Global" ),
		_SYSTEM_STRING( "Mailbox" ),
		_SYSTEM_STRING( "Msg" ),
		_SYSTEM_STRING( "PerUserRead" ),
		 NULL } },
	{ DATABASE_TYPE_SRUM, {
		_SYSTEM_STRING( "SruDbIdMapTable" ),
		_SYSTEM_STRING( "{D10CA2FE-6FCF-4F6D-848E-B2E99266FA86}" ),
		_SYSTEM_STRING( "{D10CA2FE-6FCF-4F6D-848E-B2E99266FA89}" ),
		_SYSTEM_STRING( "{FEE4E14F-02A9-4550-B5CE-5FA2DA202E37}" ),
		_SYSTEM_STRING( "{973F5D5C-1D90-4944-BE8E-24B94231A174}" ),
		_SYSTEM_STRING( "{FEE4E14F-02A9-4550-B5CE-5FA2DA202E37}LT" ),
		_SYSTEM_STRING( "{DD6636C4-8929-4683-974E-22C046A43763}" ),
		NULL } },
	{ DATABASE_TYPE_WEBCACHE, {
		_SYSTEM_STRING( "Containers" ),
		_SYSTEM_STRING( "LeakFiles" ),
		_SYSTEM_STRING( "Partitions" ),
		NULL } },
	{ DATABASE_TYPE_WINDOWS_SEARCH, {
		_SYSTEM_STRING( "SystemIndex_0A" ),
		_SYSTEM_STRING( "SystemIndex_Gthr" ),
		NULL } },
	{ DATABASE_TYPE_WINDOWS_SECURITY, {
		_SYSTEM_STRING( "SmTblSection" ),
		_SYSTEM_STRING( "SmTblVersion" ),
		 NULL } },
	{ DATABASE_TYPE_UNKNOWN, {
		 NULL } }
};

/* Determines the database type
 * Returns 1 if successful or -1 on error
 */
int database_type_determine(
     int *database_type,
     libcdata_array_t *table_names,
     libcerror_error_t **error )
{
	int database_types[ NUMBER_OF_DATABASE_TYPES ];

	database_type_descriptor_t *database_type_descriptor = NULL;
	const system_character_t *known_table_name           = NULL;
	system_character_t *table_name                       = NULL;
	static char *function                                = "export_handle_determine_database_type";
	size_t known_table_name_length                       = 0;
	size_t table_name_length                             = 0;
	int database_type_index                              = 0;
	int known_table_name_index                           = 0;
	int number_of_tables                                 = 0;
	int table_index                                      = 0;

	if( database_type == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid database type.",
		 function );

		return( -1 );
	}
	for( database_type_index = 0;
	     database_type_index < NUMBER_OF_DATABASE_TYPES;
	     database_type_index++ )
	{
		database_types[ database_type_index ] = 0;
	}
	if( libcdata_array_get_number_of_entries(
	     table_names,
	     &number_of_tables,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve number of tables.",
		 function );

		return( -1 );
	}
	for( table_index = 0;
	     table_index < number_of_tables;
	     table_index++ )
	{
		if( libcdata_array_get_entry_by_index(
		     table_names,
		     table_index,
		     (intptr_t **) &table_name,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve the name of table: %d from array.",
			 function,
			 table_index );

			return( -1 );
		}
		if( table_name == NULL )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
			 "%s: missing name of table: %d.",
			 function,
			 table_index );

			return( -1 );
		}
		table_name_length = system_string_length(
		                     table_name );

		database_type_index = 0;

		database_type_descriptor = &( database_type_descriptors[ database_type_index++ ] );

		while( database_type_descriptor->database_type != DATABASE_TYPE_UNKNOWN )
		{
			known_table_name_index = 0;

			known_table_name = database_type_descriptor->known_table_names[ known_table_name_index++ ];

			while( known_table_name != NULL )
			{
				known_table_name_length = system_string_length(
				                           known_table_name );

				if( ( known_table_name_length == table_name_length )
				 && ( system_string_compare(
				       known_table_name,
				       table_name,
				       known_table_name_length ) == 0 ) )
				{
					database_types[ database_type_descriptor->database_type ] += 1;
				}
				known_table_name = database_type_descriptor->known_table_names[ known_table_name_index++ ];
			}
			database_type_descriptor = &( database_type_descriptors[ database_type_index++ ] );
		}
	}
	*database_type = DATABASE_TYPE_UNKNOWN;

	for( database_type_index = 0;
	     database_type_index < NUMBER_OF_DATABASE_TYPES;
	     database_type_index++ )
	{
		if( database_types[ *database_type ] < database_types[ database_type_index ] )
		{
			*database_type = database_type_index;
		}
	}
	return( 1 );
}