<s> import os <EOL> import hashlib <EOL> import binascii <EOL> import ConfigParser <EOL> try : <EOL> import magic <EOL> except ImportError : <EOL> pass <EOL> try : <EOL> import pydeep <EOL> HAVE_SSDEEP = True <EOL> except ImportError : <EOL> HAVE_SSDEEP = False <EOL> class Dictionary ( dict ) : <EOL> def __getattr__ ( self , key ) : <EOL> return self . get ( key , None ) <EOL> __setattr__ = dict . __setitem__ <EOL> __delattr__ = dict . __delitem__ <EOL> class File : <EOL> def __init__ ( self , file_path = None , file_data = None ) : <EOL> self . file_path = file_path <EOL> if file_path : <EOL> self . file_data = open ( self . file_path , "<STR_LIT:rb>" ) . read ( ) <EOL> else : <EOL> self . file_data = file_data <EOL> def get_name ( self ) : <EOL> file_name = os . path . basename ( self . file_path ) <EOL> return file_name <EOL> def get_data ( self ) : <EOL> return self . file_data <EOL> def get_size ( self ) : <EOL> return os . path . getsize ( self . file_path ) <EOL> def get_crc32 ( self ) : <EOL> res = '<STR_LIT>' <EOL> crc = binascii . crc32 ( self . file_data ) <EOL> for i in range ( <NUM_LIT:4> ) : <EOL> t = crc & <NUM_LIT> <EOL> crc >>= <NUM_LIT:8> <EOL> res = '<STR_LIT>' % ( t , res ) <EOL> return res <EOL> def get_md5 ( self ) : <EOL> return hashlib . md5 ( self . file_data ) . hexdigest ( ) <EOL> def get_sha1 ( self ) : <EOL> return hashlib . sha1 ( self . file_data ) . hexdigest ( ) <EOL> def get_sha256 ( self ) : <EOL> return hashlib . sha256 ( self . file_data ) . hexdigest ( ) <EOL> def get_sha512 ( self ) : <EOL> return hashlib . sha512 ( self . file_data ) . hexdigest ( ) <EOL> def get_ssdeep ( self ) : <EOL> if not HAVE_SSDEEP : <EOL> return None <EOL> try : <EOL> return pydeep . hash_file ( self . file_path ) <EOL> except Exception : <EOL> return None <EOL> def get_type ( self ) : <EOL> try : <EOL> ms = magic . open ( magic . MAGIC_NONE ) <EOL> ms . load ( ) <EOL> file_type = ms . buffer ( self . file_data ) <EOL> except : <EOL> try : <EOL> file_type = magic . from_buffer ( self . file_data ) <EOL> except : <EOL> try : <EOL> import subprocess <EOL> file_process = subprocess . Popen ( [ '<STR_LIT:file>' , '<STR_LIT>' , self . file_path ] , stdout = subprocess . PIPE ) <EOL> file_type = file_process . stdout . read ( ) . strip ( ) <EOL> except : <EOL> return None <EOL> return file_type <EOL> class Config : <EOL> def __init__ ( self , cfg = "<STR_LIT>" ) : <EOL> config = ConfigParser . ConfigParser ( ) <EOL> config . read ( cfg ) <EOL> for section in config . sections ( ) : <EOL> setattr ( self , section , Dictionary ( ) ) <EOL> for name , raw_value in config . items ( section ) : <EOL> try : <EOL> value = config . getboolean ( section , name ) <EOL> except ValueError : <EOL> try : <EOL> value = config . getint ( section , name ) <EOL> except ValueError : <EOL> value = config . get ( section , name ) <EOL> setattr ( getattr ( self , section ) , name , value ) <EOL> def get ( self , section ) : <EOL> try : <EOL> return getattr ( self , section ) <EOL> except AttributeError as e : <EOL> return None </s>
