the whole code i am trying is below quoted.
I am trying to do , based on what you have done in recycle bin module
files = fileManager.findFiles(dataSource, “ntuser.dat”, “”)
First that is returning 0 files???
Then am writing it
lclDbPath = os.path.join(temp_dir, file.getName())
ContentUtils.writeToFile(file, File(lclDbPath))
And then searching for the key
samRegFile = RegistryHiveFile(File(lclDbPath))
currentKey = self.findRegistryKey(samRegFile, self.registryKeyToFind)
message3 = IngestMessage.createMessage(IngestMessage.MessageType.DATA, “Key Found” , str(currentKey), str(currentKey))
IngestServices.getInstance().postMessage(message3)
Posting the key found to messages. I will modify that to return the file .However the issue is i am getting 0 files for ntuser.dat ??? Also please check below for my logic. I want to find registry for key HKLM\System\MountedDevices ( currently only this key, but the list of keys will be 1000 …i am just trying one key for now).
class RecBin2IngestModuleFactory(IngestModuleFactoryAdapter):
def __init__(self):
self.settings = None
moduleName = "Recycle Bin Module"
def getModuleDisplayName(self):
return self.moduleName
def getModuleDescription(self):
return "Parse Recycle Bin Information for Vista and beyond"
def getModuleVersionNumber(self):
return "1.2"
def hasIngestJobSettingsPanel(self):
return False
def isDataSourceIngestModuleFactory(self):
return True
def createDataSourceIngestModule(self, ingestOptions):
return RecBin2IngestModule(self.settings)
class RecBin2IngestModule(DataSourceIngestModule):
_logger = Logger.getLogger(RecBin2IngestModuleFactory.moduleName)
def log(self, level, msg):
self._logger.logp(level, self.__class__.__name__, inspect.stack()[1][3], msg)
def __init__(self, settings):
self.context = None
def startUp(self, context):
self.context = context
self.registryKeyToFind = 'HKLM\System\MountedDevices'
def process(self, dataSource, progressBar):
progressBar.switchToIndeterminate()
skCase = Case.getCurrentCase().getSleuthkitCase();
fileManager = Case.getCurrentCase().getServices().getFileManager()
Temp_Dir = Case.getCurrentCase().getTempDirectory()
temp_dir = os.path.join(Temp_Dir, "recyclebin")
self.log(Level.INFO, "create Directory " + temp_dir)
try:
os.mkdir(temp_dir)
except:
self.log(Level.INFO, "recyclebin Directory already exists " + temp_dir)
systemAbsFile = []
files = fileManager.findFiles(dataSource, "ntuser.dat", "")
numFiles = len(files)
self.log(Level.INFO, "Number of Files found ==> " + str(numFiles))
message2 = IngestMessage.createMessage(IngestMessage.MessageType.DATA, "files found" , str(numFiles), str(numFiles))
IngestServices.getInstance().postMessage(message2)
for file in files:
if self.context.isJobCancelled():
return IngestModule.ProcessResult.OK
if true:
lclDbPath = os.path.join(temp_dir, file.getName())
ContentUtils.writeToFile(file, File(lclDbPath))
samRegFile = RegistryHiveFile(File(lclDbPath))
currentKey = self.findRegistryKey(samRegFile, self.registryKeyToFind)
message3 = IngestMessage.createMessage(IngestMessage.MessageType.DATA, "Key Found" , str(currentKey), str(currentKey))
IngestServices.getInstance().postMessage(message3)
else:
self.log(Level.INFO, "Skipping File " + file.getName() + " In Path " + file.getParentPath())
try:
shutil.rmtree(temp_dir)
except:
self.log(Level.INFO, "removal of directory tree failed " + temp_dir)
message = IngestMessage.createMessage(IngestMessage.MessageType.DATA,
"RecycleBin", " Recycle Bin Files Have Been Analyzed " )
IngestServices.getInstance().postMessage(message)
return IngestModule.ProcessResult.OK
def findRegistryKey(self, registryHiveFile, registryKey):
rootKey = registryHiveFile.getRoot()
regKeyList = registryKey.split('/')
currentKey = rootKey
for key in regKeyList:
self.log(Level.INFO, "Key value is ==> " + key)
self.log(Level.INFO, "Current Key is ==> " + str(currentKey))
currentKey = currentKey.getSubkey(key)
return currentKey
def utf16decode(self, bytes):
bytes = binascii.hexlify(bytes)
bytes = [bytes[i:i+2] for i in range(0, len(bytes), 2)]
bytes = (''.join(filter(lambda a: a !='00', bytes)))
bytes = codecs.decode(bytes, 'hex')
return(bytes)