-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathBaseliner.EnScript
110 lines (102 loc) · 3.42 KB
/
Baseliner.EnScript
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
/*
* Author: Jamie Levy (Gleeda) jamie.levy@gmail.com
*
* Baseliner.EnScript
*
* Creates a SQLite database of Path, Hash and Size of all DLL files
* in disk images from a created case.
*
* 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.
*/
include "GSI_LogLib"
include "GSI_Basic"
class MainClass {
long RecordsAdded,
RecordsFailed;
String TableCreateQuery,
InsertQuery,
OutputPath;
MainClass():
TableCreateQuery
(
"CREATE TABLE entries(id INTEGER PRIMARY KEY ASC AUTOINCREMENT, path TEXT, hash TEXT, size INTEGER)"
),
InsertQuery
(
"INSERT INTO entries(path, hash, size) VALUES ('{0}', '{1}', '{2}')"
)
{
}
void Main(CaseClass c) {
LocalFileClass SQLiteFile();
SQLiteClass SQLiteData();
SystemClass::ClearConsole(SystemClass::SHOWCONSOLE);
if (c)
{
NameListClass devices();
SearchClass search();
forall (DeviceClass d in c.DeviceRoot()) {
Console.WriteLine("Device Name = "+d.Name());
Console.WriteLine("Device FullPath = "+d.FullPath());
new NameListClass (devices, d.FullPath());
}
if (SystemClass::PathDialog(OutputPath,
"Choose SQLite output file",
"sqlite",
"SQLite Files\t*.sqlite",
SystemClass::CREATE))
{
LocalFileClass SQLiteFile();
if (SQLiteFile.Open(OutputPath, FileClass::APPEND))
{
if (SQLiteData.Open(SQLiteFile, SQLiteClass::SQLITE_OPEN_READWRITE))
{
SQLiteClass::CommandClass command();
if (SQLiteData.CreateCommand(command))
{
if (command.ExecuteNonQuery(TableCreateQuery))
Console.WriteLine("Table Created");
forall (EntryClass e in c.EntryRoot())
{
if (e.Extension().Compare("dll") == 0)
{
String path = e.FullPath();
foreach (NameListClass d in devices){
path.Replace(c.Name() + "\\" + d.Name() + "\\", "");
}
HashClass hash = search.ComputeHash(e);
if(!hash.IsValid())
hash = "none";
if (command.ExecuteNonQuery(String::Format(InsertQuery, escapeQuotes(path),
hash,
e.LogicalSize())))
{
Console.WriteLine(String::Format("Record added to database for '{0}'", e.Name()));
++RecordsAdded;
}
else
{
Console.WriteLine(String::Format("Couldn't add record: {0}", SystemClass::LastError()));
++RecordsFailed;
}
}
}
Console.WriteLine(String::Format("Records added: {0}", RecordsAdded));
Console.WriteLine(String::Format("Records that couldn't be added: {0}", RecordsFailed));
Console.WriteLine("Script finished");
}
}
}
}
}
}
String escapeQuotes(const String &input)
{
String retval = input;
retval.Replace("'", "''");
return retval;
}
}