# Path: IApp.py
# class IApp(object):
#     '''
#     classdocs
#     '''
#     name = "Unknown"
#     cname = "Unknown"
#     databases = {}
#     known = False
#     dummyRE = type(re.compile("nfi"))
#     version = [-1]
#     
#     def get_versions(self):
#         return self.version
#     
#     def has_defaultversion(self):
#         if IDeviceVersion.DEFAULT_VERSION in self.version:
#             return True
#         return False
#     
#     def has_version(self,appversion):
#         if appversion in self.version:
#             return True
#         return False
#     
#     def get_packagename(self):
#         return self.name
#     
#     def get_canonicalname(self):
#         return self.cname
#     
#     def get_files(self):
#         return self.databases
#     
#     def get_file_info(self, dbname):
#         if len(self.databases) == 0:
#             return None
#         for thisdbname,defn in self.databases.iteritems():
#             if type(thisdbname) == type("str"):
#                 if thisdbname == dbname:
#                     return defn
#             elif type(thisdbname) == self.dummyRE:
#                 if thisdbname.match(dbname) != None:
#                     return defn
#         return None
#     
#     def set_packagename(self, name):
#         self.name = name
#     
#     def __init__(self):
#         return
# 
# Path: MiscUtils.py
# def genfilesig(filepath,hasher=DEFAULT_HASHER,bs=65536):
#         try:
#             f = open(filepath,"rb")
#             while True:
#                 buf = f.read(bs)
#                 if not buf:
#                     break
#                 hasher.update(buf)
#             f.close()
#             return hasher.hexdigest()
#         except:
#             print "Error opening file:" + filepath
#             return None
# 
# DEFAULT_HASHER = hashlib.sha256()
# 
# Path: ModuleImporter.py
# class Importer(object):
#     def __init__(self):
#         return
#     
#     def get_package_modules_dict(self, package_name, parent_obj, keyfield, 
#                                  args=None ):
#         return self._load_dict( [package_name], package_name + u".", parent_obj, 
#                                 keyfield, args)
#         
#     def get_package_modules(self, package_name, parent_obj, args=None ):
#         return self._load( [package_name], package_name + u".", parent_obj, 
#                            True, args )
#     
#     def get_package_modules_list(self, package_name, parent_obj ):
#         return self._load( [package_name], package_name + u".", parent_obj )
#     
#     def _load(self, path, prefix, parent_obj, instantiate=False, args=None ):
#         modules = []
#         for _, name, is_package in walk_packages( path, prefix=prefix ):
#             if is_package: continue
#             module = import_module( name )
#             for member in dir(module):
#                 if member == parent_obj.__class__.__name__: continue
#                 member_obj = getattr( module, member )
#                 if inspect.isclass( member_obj ) == False: continue
#                 if issubclass( member_obj, parent_obj.__class__ ):
#                     if instantiate:
#                         if args != None: obj = member_obj(*args)
#                         else: obj = member_obj()
#                         modules.append( obj )
#                     else:
#                         modules.append( member )
#         return modules
#     
#     def _load_dict(self, path, prefix, parent_obj, keyfield, args=None ):
#         modules = {}
#         for _, name, is_package in walk_packages( path, prefix=prefix ):
#             if is_package: continue
#             module = import_module( name )
#             for member in dir(module):
#                 if member == parent_obj.__class__.__name__: continue
#                 member_obj = getattr( module, member )
#                 if inspect.isclass( member_obj ) == False: continue
#                 if issubclass( member_obj, parent_obj.__class__ ):
#                     if args != None: tmpobj = member_obj(*args)
#                     else: tmpobj = member_obj()
#                     modules[getattr( tmpobj, keyfield )] = tmpobj
#         return modules


from IApp import IApp
from MimeGuesser import MimeGuesser
from os import listdir
from os.path import isfile, isdir, islink, join, basename, dirname
from MiscUtils import genfilesig, DEFAULT_HASHER
from ModuleImporter import Importer
import ExtractStore
import os
Copyright (C) 2014  George Nicolaou (george[at]silensec[dot]com)
                    Silensec Ltd.

This file is part of Nyuki Forensics Investigator (NFI).

NFI 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 3 of the License, or
(at your option) any later version.

NFI 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 General Public License
along with NFI.  If not, see <http://www.gnu.org/licenses/>.
'''

class ApplicationParser(object):
    
    parser_name = "Android Application Parser"
    appstore = {}
    exstore = None        
    def __init__(self, outqueue=None, extract_store=None, mountpoint=None, 
                 settings=None, versions=None ):
        self.mimguess = MimeGuesser()
        self.outqueue = outqueue
        self.settings = settings
        self.versions = versions

# Path: IApp.py
# class IApp(object):
#     '''
#     classdocs
#     '''
#     name = "Unknown"
#     cname = "Unknown"
#     databases = {}
#     known = False
#     dummyRE = type(re.compile("nfi"))
#     version = [-1]
#     
#     def get_versions(self):
#         return self.version
#     
#     def has_defaultversion(self):
#         if IDeviceVersion.DEFAULT_VERSION in self.version:
#             return True
#         return False
#     
#     def has_version(self,appversion):
#         if appversion in self.version:
#             return True
#         return False
#     
#     def get_packagename(self):
#         return self.name
#     
#     def get_canonicalname(self):
#         return self.cname
#     
#     def get_files(self):
#         return self.databases
#     
#     def get_file_info(self, dbname):
#         if len(self.databases) == 0:
#             return None
#         for thisdbname,defn in self.databases.iteritems():
#             if type(thisdbname) == type("str"):
#                 if thisdbname == dbname:
#                     return defn
#             elif type(thisdbname) == self.dummyRE:
#                 if thisdbname.match(dbname) != None:
#                     return defn
#         return None
#     
#     def set_packagename(self, name):
#         self.name = name
#     
#     def __init__(self):
#         return
# 
# Path: MiscUtils.py
# def genfilesig(filepath,hasher=DEFAULT_HASHER,bs=65536):
#         try:
#             f = open(filepath,"rb")
#             while True:
#                 buf = f.read(bs)
#                 if not buf:
#                     break
#                 hasher.update(buf)
#             f.close()
#             return hasher.hexdigest()
#         except:
#             print "Error opening file:" + filepath
#             return None
# 
# DEFAULT_HASHER = hashlib.sha256()
# 
# Path: ModuleImporter.py
# class Importer(object):
#     def __init__(self):
#         return
#     
#     def get_package_modules_dict(self, package_name, parent_obj, keyfield, 
#                                  args=None ):
#         return self._load_dict( [package_name], package_name + u".", parent_obj, 
#                                 keyfield, args)
#         
#     def get_package_modules(self, package_name, parent_obj, args=None ):
#         return self._load( [package_name], package_name + u".", parent_obj, 
#                            True, args )
#     
#     def get_package_modules_list(self, package_name, parent_obj ):
#         return self._load( [package_name], package_name + u".", parent_obj )
#     
#     def _load(self, path, prefix, parent_obj, instantiate=False, args=None ):
#         modules = []
#         for _, name, is_package in walk_packages( path, prefix=prefix ):
#             if is_package: continue
#             module = import_module( name )
#             for member in dir(module):
#                 if member == parent_obj.__class__.__name__: continue
#                 member_obj = getattr( module, member )
#                 if inspect.isclass( member_obj ) == False: continue
#                 if issubclass( member_obj, parent_obj.__class__ ):
#                     if instantiate:
#                         if args != None: obj = member_obj(*args)
#                         else: obj = member_obj()
#                         modules.append( obj )
#                     else:
#                         modules.append( member )
#         return modules
#     
#     def _load_dict(self, path, prefix, parent_obj, keyfield, args=None ):
#         modules = {}
#         for _, name, is_package in walk_packages( path, prefix=prefix ):
#             if is_package: continue
#             module = import_module( name )
#             for member in dir(module):
#                 if member == parent_obj.__class__.__name__: continue
#                 member_obj = getattr( module, member )
#                 if inspect.isclass( member_obj ) == False: continue
#                 if issubclass( member_obj, parent_obj.__class__ ):
#                     if args != None: tmpobj = member_obj(*args)
#                     else: tmpobj = member_obj()
#                     modules[getattr( tmpobj, keyfield )] = tmpobj
#         return modules


# Path: Android/ApplicationParser.py
from IApp import IApp
from MimeGuesser import MimeGuesser
from os import listdir
from os.path import isfile, isdir, islink, join, basename, dirname
from MiscUtils import genfilesig, DEFAULT_HASHER
from ModuleImporter import Importer
import ExtractStore
import os

Copyright (C) 2014  George Nicolaou (george[at]silensec[dot]com)
                    Silensec Ltd.

This file is part of Nyuki Forensics Investigator (NFI).

NFI 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 3 of the License, or
(at your option) any later version.

NFI 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 General Public License
along with NFI.  If not, see <http://www.gnu.org/licenses/>.
'''

class ApplicationParser(object):
    
    parser_name = "Android Application Parser"
    appstore = {}
    exstore = None        
    def __init__(self, outqueue=None, extract_store=None, mountpoint=None, 
                 settings=None, versions=None ):
        self.mimguess = MimeGuesser()
        self.outqueue = outqueue
        self.settings = settings
        self.versions = versions

        imp = Importer()