# Path: utils/utils.py
# def look_for_outlook_dirs(paths_to_search):
#     """Takes a list of paths to search for Outlook, will return a list of valid Outlook paths
#         A good practice is to take the output from get_userprofiles_from_reg() function
#         Returns the path if it exists, None otherwise"""
#     valid_paths = []
#     if paths_to_search:
#         for path in paths_to_search:
#             path = check_outlook_d(path)
#             if path:
#                 valid_paths.append(path)
#     return valid_paths
# 
# def look_for_files(dir_to_look):
#     """Looks for windows in a given directory. Supports the * wildcard character"""
#     found_files = []
#     if "*" in dir_to_look:
#         found_files += glob.glob(dir_to_look)
#     elif os.path.exists(dir_to_look):
#         found_files.append(dir_to_look)
#     return found_files
# 
# def zip_archive(files_to_zip, zip_path, filename, logger, file_mode="w"):
#     """Uses the global variable to save the zip file. Creates a zip archive containing windows given in parameters.
#         The file mode is write by default. It can also be "a" for append."""
#     computer_name = os.environ["COMPUTERNAME"]
#     zip_fullname = zip_path + "\\" + computer_name + "_" + filename + ".zip"
#     with zipfile.ZipFile(zip_fullname, file_mode) as myzip:
#         zip_from_object(files_to_zip, myzip, logger)
# 
# def get_csv_writer(csvfile):
#     return UnicodeWriter(csvfile, quoting=csv.QUOTE_ALL)
# 
# def get_json_writer(json_file):
#     return UnicodeJsonDumper(json_file)
# 
# def write_to_csv(arr_data, csv_writer):
#     """Writes contents to a CSV file using UTF-8"""
#     csv_writer.writerow(arr_data)
# 
# def write_to_json(header, arr_data, json_writer):
#     """Write data in json files using UTF-8"""
#     try:
#         json_writer.dump_json({
#             h: arr_data[index] for index, h in enumerate(header)
#         })
#     except IndexError:
#         json_writer.dump_json({
#             header[index]: d for index, d in enumerate(arr_data)
#         })
# 
# def close_json_writer(json_writer):
#     json_writer.close_current()
# 
# def record_sha256_logs(fr, fw):
#     with open(fw, "a") as hash_file:
#         m = process_sha256(fr)
#         hash_file.write(fr + "," + m + "\n")
#         hash_file.close()
# 
# def process_hashes(path):
#     content = open(path, "rb").read()
#     return hashlib.md5(content).hexdigest(), hashlib.sha1(content).hexdigest(), hashlib.sha256(content).hexdigest()
# 
# Path: registry/registry_obj.py
# def get_userprofiles_from_reg():
#     """Retrieves and returns the userprofiles from the registry"""
#     # SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList contains a list of subkeys representing SIDs
#     list_profiles = []
#     users = get_registry_key(HKEY_LOCAL_MACHINE,
#                              r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList")
#     if users:
#         for i in xrange(users.get_number_of_sub_keys()):
#             user = users.get_sub_key(i)
#             list_profiles.append(user.get_value_by_name("ProfileImagePath").get_data())
#     return list_profiles


import datetime
import glob
import os
import sqlite3
import traceback
import ctypes
import struct
from utils.utils import look_for_outlook_dirs, look_for_files, zip_archive, get_csv_writer, get_json_writer, \
     write_to_csv, write_to_json, close_json_writer, record_sha256_logs, process_hashes
from registry.registry_obj import get_userprofiles_from_reg
from utils.utils_rawstring import sekoiamagic
from win32com.shell import shell, shellcon
            for time, url, user, profile in fhistory:
                write_to_json(header, [self.computer_name, 'firefox_history', time, url, user, profile], json_writer)
            close_json_writer(json_writer)
        record_sha256_logs(self.output_dir + self.computer_name + '_firefox_history' + self.rand_ext,
                           self.output_dir + self.computer_name + '_sha256.log')

    def _csv_chrome_history(self, chistory):
        with open(self.output_dir + self.computer_name + '_chrome_history' + self.rand_ext, 'wb') as output:
            csv_writer = get_csv_writer(output)
            write_to_csv(("COMPUTER_NAME", "TYPE", "TIME", "URL", "TITLE", "USER", "PROFILE"), csv_writer)
            for time, url, title, user, profile in chistory:
                write_to_csv([self.computer_name, 'chrome_history', time, url, title, user, profile], csv_writer)
        record_sha256_logs(self.output_dir + self.computer_name + '_chrome_history' + self.rand_ext,
                           self.output_dir + self.computer_name + '_sha256.log')

    def _json_chrome_history(self, chistory):
        if self.destination == 'local':
            with open(self.output_dir + self.computer_name + '_chrome_history' + self.rand_ext, 'wb') as output:
                json_writer = get_json_writer(output)
                header = ["COMPUTER_NAME", "TYPE", "TIME", "URL", "TITLE", "USER", "PROFILE"]
                for time, url, title, user, profile in chistory:
                    write_to_json(header, [self.computer_name, 'chrome_history',
                                           time, url, title, user, profile], json_writer)
                close_json_writer(json_writer)
        record_sha256_logs(self.output_dir + self.computer_name + '_chrome_history' + self.rand_ext,
                           self.output_dir + self.computer_name + '_sha256.log')

    def csv_recycle_bin(self):
        """Exports the filenames contained in the recycle bin"""
        with open(self.output_dir + self.computer_name + '_recycle_bin' + self.rand_ext, 'wb') as output:

# Path: utils/utils.py
# def look_for_outlook_dirs(paths_to_search):
#     """Takes a list of paths to search for Outlook, will return a list of valid Outlook paths
#         A good practice is to take the output from get_userprofiles_from_reg() function
#         Returns the path if it exists, None otherwise"""
#     valid_paths = []
#     if paths_to_search:
#         for path in paths_to_search:
#             path = check_outlook_d(path)
#             if path:
#                 valid_paths.append(path)
#     return valid_paths
# 
# def look_for_files(dir_to_look):
#     """Looks for windows in a given directory. Supports the * wildcard character"""
#     found_files = []
#     if "*" in dir_to_look:
#         found_files += glob.glob(dir_to_look)
#     elif os.path.exists(dir_to_look):
#         found_files.append(dir_to_look)
#     return found_files
# 
# def zip_archive(files_to_zip, zip_path, filename, logger, file_mode="w"):
#     """Uses the global variable to save the zip file. Creates a zip archive containing windows given in parameters.
#         The file mode is write by default. It can also be "a" for append."""
#     computer_name = os.environ["COMPUTERNAME"]
#     zip_fullname = zip_path + "\\" + computer_name + "_" + filename + ".zip"
#     with zipfile.ZipFile(zip_fullname, file_mode) as myzip:
#         zip_from_object(files_to_zip, myzip, logger)
# 
# def get_csv_writer(csvfile):
#     return UnicodeWriter(csvfile, quoting=csv.QUOTE_ALL)
# 
# def get_json_writer(json_file):
#     return UnicodeJsonDumper(json_file)
# 
# def write_to_csv(arr_data, csv_writer):
#     """Writes contents to a CSV file using UTF-8"""
#     csv_writer.writerow(arr_data)
# 
# def write_to_json(header, arr_data, json_writer):
#     """Write data in json files using UTF-8"""
#     try:
#         json_writer.dump_json({
#             h: arr_data[index] for index, h in enumerate(header)
#         })
#     except IndexError:
#         json_writer.dump_json({
#             header[index]: d for index, d in enumerate(arr_data)
#         })
# 
# def close_json_writer(json_writer):
#     json_writer.close_current()
# 
# def record_sha256_logs(fr, fw):
#     with open(fw, "a") as hash_file:
#         m = process_sha256(fr)
#         hash_file.write(fr + "," + m + "\n")
#         hash_file.close()
# 
# def process_hashes(path):
#     content = open(path, "rb").read()
#     return hashlib.md5(content).hexdigest(), hashlib.sha1(content).hexdigest(), hashlib.sha256(content).hexdigest()
# 
# Path: registry/registry_obj.py
# def get_userprofiles_from_reg():
#     """Retrieves and returns the userprofiles from the registry"""
#     # SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList contains a list of subkeys representing SIDs
#     list_profiles = []
#     users = get_registry_key(HKEY_LOCAL_MACHINE,
#                              r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList")
#     if users:
#         for i in xrange(users.get_number_of_sub_keys()):
#             user = users.get_sub_key(i)
#             list_profiles.append(user.get_value_by_name("ProfileImagePath").get_data())
#     return list_profiles


# Path: fs/fs.py
import datetime
import glob
import os
import sqlite3
import traceback
import ctypes
import struct
from utils.utils import look_for_outlook_dirs, look_for_files, zip_archive, get_csv_writer, get_json_writer, \
     write_to_csv, write_to_json, close_json_writer, record_sha256_logs, process_hashes
from registry.registry_obj import get_userprofiles_from_reg
from utils.utils_rawstring import sekoiamagic
from win32com.shell import shell, shellcon

            for time, url, user, profile in fhistory:
                write_to_json(header, [self.computer_name, 'firefox_history', time, url, user, profile], json_writer)
            close_json_writer(json_writer)
        record_sha256_logs(self.output_dir + self.computer_name + '_firefox_history' + self.rand_ext,
                           self.output_dir + self.computer_name + '_sha256.log')

    def _csv_chrome_history(self, chistory):
        with open(self.output_dir + self.computer_name + '_chrome_history' + self.rand_ext, 'wb') as output:
            csv_writer = get_csv_writer(output)
            write_to_csv(("COMPUTER_NAME", "TYPE", "TIME", "URL", "TITLE", "USER", "PROFILE"), csv_writer)
            for time, url, title, user, profile in chistory:
                write_to_csv([self.computer_name, 'chrome_history', time, url, title, user, profile], csv_writer)
        record_sha256_logs(self.output_dir + self.computer_name + '_chrome_history' + self.rand_ext,
                           self.output_dir + self.computer_name + '_sha256.log')

    def _json_chrome_history(self, chistory):
        if self.destination == 'local':
            with open(self.output_dir + self.computer_name + '_chrome_history' + self.rand_ext, 'wb') as output:
                json_writer = get_json_writer(output)
                header = ["COMPUTER_NAME", "TYPE", "TIME", "URL", "TITLE", "USER", "PROFILE"]
                for time, url, title, user, profile in chistory:
                    write_to_json(header, [self.computer_name, 'chrome_history',
                                           time, url, title, user, profile], json_writer)
                close_json_writer(json_writer)
        record_sha256_logs(self.output_dir + self.computer_name + '_chrome_history' + self.rand_ext,
                           self.output_dir + self.computer_name + '_sha256.log')

    def csv_recycle_bin(self):
        """Exports the filenames contained in the recycle bin"""
        with open(self.output_dir + self.computer_name + '_recycle_bin' + self.rand_ext, 'wb') as output:

            csv_writer = get_csv_writer(output)