1+ import asyncio
12import csv
3+ import os
24import json
5+ import sqlite3
36import xml .etree .ElementTree as ET
4- import asyncio
57from typing import List , Dict , Any
68from .mft_record import MftRecord
79from .constants import *
@@ -86,4 +88,69 @@ async def write_l2t(records: List[MftRecord], output_file: str) -> None:
8688 date_str , time_str , 'UTC' , macb , 'MFT' , 'FILESYSTEM' , time_type , '' , '' , '' ,
8789 f"{ record .filename } { time_type } " , '' , record .filename , record .recordnum , '' , '' , ''
8890 ])
91+ await asyncio .sleep (0 )
92+
93+
94+ @staticmethod
95+ async def write_sqlite (records : List [MftRecord ], output_file : str ) -> None :
96+ conn = sqlite3 .connect (output_file )
97+ cursor = conn .cursor ()
98+
99+ # Create and populate static tables
100+ sql_dir = os .path .join (os .path .dirname (__file__ ), 'sql' )
101+ for sql_file in os .listdir (sql_dir ):
102+ with open (os .path .join (sql_dir , sql_file ), 'r' ) as f :
103+ cursor .executescript (f .read ())
104+
105+ # Create MFT records table
106+ cursor .execute ('''
107+ CREATE TABLE mft_records (
108+ record_number INTEGER PRIMARY KEY,
109+ filename TEXT,
110+ parent_record_number INTEGER,
111+ file_size INTEGER,
112+ is_directory INTEGER,
113+ creation_time TEXT,
114+ modification_time TEXT,
115+ access_time TEXT,
116+ entry_time TEXT,
117+ attribute_types TEXT
118+ )
119+ ''' )
120+
121+ # Insert MFT records
122+ for record in records :
123+ cursor .execute ('''
124+ INSERT INTO mft_records (
125+ record_number, filename, parent_record_number, file_size,
126+ is_directory, creation_time, modification_time, access_time,
127+ entry_time, attribute_types
128+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
129+ ''' , (
130+ record .recordnum ,
131+ record .filename ,
132+ record .get_parent_record_num (),
133+ record .filesize ,
134+ 1 if record .flags & FILE_RECORD_IS_DIRECTORY else 0 ,
135+ record .fn_times ['crtime' ].dtstr ,
136+ record .fn_times ['mtime' ].dtstr ,
137+ record .fn_times ['atime' ].dtstr ,
138+ record .fn_times ['ctime' ].dtstr ,
139+ ',' .join (map (str , record .attribute_types ))
140+ ))
141+
142+ conn .commit ()
143+ conn .close ()
144+ await asyncio .sleep (0 )
145+
146+ @staticmethod
147+ async def write_tsk (records : List [MftRecord ], output_file : str ) -> None :
148+ with open (output_file , 'w' , newline = '' , encoding = 'utf-8' ) as tskfile :
149+ for record in records :
150+ # TSK body file format:
151+ # MD5|name|inode|mode_as_string|UID|GID|size|atime|mtime|ctime|crtime
152+ tskfile .write (f"0|{ record .filename } |{ record .recordnum } |{ record .flags :04o} |0|0|"
153+ f"{ record .filesize } |{ record .fn_times ['atime' ].unixtime } |"
154+ f"{ record .fn_times ['mtime' ].unixtime } |{ record .fn_times ['ctime' ].unixtime } |"
155+ f"{ record .fn_times ['crtime' ].unixtime } \n " )
89156 await asyncio .sleep (0 )
0 commit comments