def __init__(self, dataset_name, query, format):
     self.dataset_name = dataset_name
     self.query = query
     self.format = format
     self.dpi = 72.
     self.size = '11x9'
     self.filetype, self.mime = utils.get_mimetype(format)
     self.filename = utils.get_filename(self.plottype, dataset_name,
                                        self.filetype)
Exemple #2
0
 def process_item(self, item, orig_item = None):
     if isinstance(item, dict) and "subpage" in item:
         item["subpage"] = self.process_item(item["subpage"])
     if type(item) in (str,unicode) and os.path.exists(item) and not os.path.isdir(item):
         if not orig_item: orig_item = {}
         newitem = {"type": get_file_type(item), "mime": get_mimetype(item)}
         if "width" in orig_item: newitem["width"] = orig_item["width"]
         if "height" in orig_item: newitem["height"] = orig_item["height"]
         if newitem["type"] == "image" and ("width" not in newitem or "height" not in newitem):
             content_type, width, height = getImageInfo(open(item).read())
             if content_type and width and height:
                 try:
                     if "width" not in newitem and "height" not in newitem:
                         newitem["width"] = width
                         newitem["height"] = height
                     elif "width" not in newitem:
                         newitem["width"] = width * newitem["height"] / height
                     else:
                         newitem["height"] = height * newitem["width"] / width
                 except TypeError:
                     pass
         newitem["rawpath"] = item
         if self.params["WEB_ROOT"] in item:
             newitem["url"] = item.replace(self.params["WEB_ROOT"],
                                           self.params["WEB_URL"])
         elif self.params["copy_images"]:
             new_name = item.replace(os.sep, "_")
             new_path = os.path.join(self.params["target_dir"], "imgs", new_name)
             if not DEBUG and (not os.path.exists(new_path) or (os.path.getmtime(item) > os.path.getmtime(new_path))): shutil.copy(item, new_path)
             newitem["rawpath"] = new_path
             newitem["url"] = os.path.join("imgs", new_name)
         else:
             newitem["url"] = item.replace(self.params["target_dir"], "")
         return newitem
     elif isinstance(item, dict) and "type" in item:
         if item["type"] in ("image", "video"):
             processed = self.process_item(item["url"], item)
             if isinstance(processed, dict):
                 item.update(processed)
             else:
                 item["url"] = processed
             if "popup" in item and "rawpath" in item:
                 item["fullurl"] = item["url"]
                 item["url"] = make_thumbnail(item)
                 item["type"] = "imagegallery" if item["popup"] == "gallery" else "imagepopup"
             return item
         elif item["type"] == "stack":
             item["stack"] = self.process_items(item["stack"])
             return item
         elif item["type"] in item_processors:
             return item_processors[item["type"]](item, self.params)
         else:
             return item
     elif isinstance(item, list):
         return self.process_items(item)
     else:
         return item
 def __init__(self, dataset_name, query, format):
     self.dataset_name = dataset_name
     self.query = query
     self.format = format
     self.dpi = 72.
     self.size = '11x9'
     self.filetype, self.mime = utils.get_mimetype(format)
     self.filename = utils.get_filename(
         self.plottype,
         dataset_name,
         self.filetype
     )
 def analyze(self, malware_sample):
     malware_definition = dict()
     malware_definition["source"] = malware_sample.meta_source if malware_sample.meta_source else ""
     malware_definition["tags"] = malware_sample.meta_tags   if malware_sample.meta_tags   else ""
     malware_definition["notes"] = malware_sample.meta_notes  if malware_sample.meta_notes  else ""
     
     # Parsing Automatically Generated Options
     malware_definition["name"] = malware_sample.filename if malware_sample.filename else ""
     malware_definition["datetime"] = str(datetime.datetime.now())
     malware_definition["size"] = os.stat(malware_sample.analysis_sample_location).st_size
     malware_definition["md5"] = malware_sample.hash_md5
     malware_definition["sha256"] = malware_sample.hash_sha256
     malware_definition["mimetype"] = utils.get_mimetype(malware_sample.analysis_sample_location)  
     malware_definition["sample_dir"] = malware_sample.analysis_sample_directory  
     malware_sample.malware_definition = malware_definition
     self.report = malware_sample.details()
     self.report_name = "analysis.rpt"
    def analyze(self, malware_sample):
        malware_definition = dict()
        malware_definition[
            "source"] = malware_sample.meta_source if malware_sample.meta_source else ""
        malware_definition[
            "tags"] = malware_sample.meta_tags if malware_sample.meta_tags else ""
        malware_definition[
            "notes"] = malware_sample.meta_notes if malware_sample.meta_notes else ""

        # Parsing Automatically Generated Options
        malware_definition[
            "name"] = malware_sample.filename if malware_sample.filename else ""
        malware_definition["datetime"] = str(datetime.datetime.now())
        malware_definition["size"] = os.stat(
            malware_sample.analysis_sample_location).st_size
        malware_definition["md5"] = malware_sample.hash_md5
        malware_definition["sha256"] = malware_sample.hash_sha256
        malware_definition["mimetype"] = utils.get_mimetype(
            malware_sample.analysis_sample_location)
        malware_definition[
            "sample_dir"] = malware_sample.analysis_sample_directory
        malware_sample.malware_definition = malware_definition
        self.report = malware_sample.details()
        self.report_name = "analysis.rpt"
Exemple #6
0
 def process_item(self, item, orig_item=None, in_media_item=False):
     if isinstance(item, dict) and "subpage" in item:
         item["subpage"] = self.process_item(item["subpage"])
     if type(item) in (str, unicode) and os.path.exists(item) and not os.path.isdir(item):
         if not orig_item:
             orig_item = {}
         newitem = {"type": get_file_type(item), "mime": get_mimetype(item)}
         if "width" in orig_item:
             newitem["width"] = orig_item["width"]
         if "height" in orig_item:
             newitem["height"] = orig_item["height"]
         if newitem["type"] == "image" and ("width" not in newitem or "height" not in newitem):
             width, height = get_image_size(item)
             if width and height:
                 try:
                     if "width" not in newitem and "height" not in newitem:
                         newitem["width"] = width
                         newitem["height"] = height
                     elif "width" not in newitem:
                         newitem["width"] = width * newitem["height"] / height
                     else:
                         newitem["height"] = height * newitem["width"] / width
                 except TypeError:
                     pass
         # Should all images should be converted to thumbnails?
         do_thumbnail = False
         if newitem["type"] == "image" and self.params["allthumbs"]:
             # If we are in a media item, do not make thumbnail now, it will
             # be done (if needed) in the media item
             if not in_media_item:
                 adjust_thumb_size(newitem, self.params)
                 do_thumbnail = True
         newitem["rawpath"] = item
         if self.params['WEB_ROOT'] and self.params['WEB_URL'] and self.params["WEB_ROOT"] in item:
             newitem["url"] = item.replace(self.params["WEB_ROOT"],
                                           self.params["WEB_URL"])
         elif self.params["copy_images"] or do_thumbnail:
             new_name = item.replace(os.sep, "_")
             new_path = os.path.join(self.params["target_dir"], "imgs", new_name)
             if not do_thumbnail and not orig_item.get("type") == "thumbnail":
                 if not DEBUG and (not os.path.exists(new_path) or (os.path.getmtime(item) > os.path.getmtime(new_path))):
                     shutil.copy(item, new_path)
             newitem["rawpath"] = new_path
             newitem["url"] = os.path.join("imgs", new_name)
             if do_thumbnail:
                 newitem["url"] = make_thumbnail(newitem, orig_path=item)
         else:
             newitem["url"] = item.replace(self.params["target_dir"], "")
         if "type" in orig_item:
             newitem["type"] = orig_item["type"]
         return newitem
     elif isinstance(item, dict) and "type" in item:
         if item["type"] in ("image", "video", "thumbnail"):
             original_item = dict(item)
             processed = self.process_item(item["url"], item, in_media_item=True)
             if isinstance(processed, dict):
                 item.update(processed)
             else:
                 item["url"] = processed
             if item["type"] == "image" and self.params["allthumbs"]:
                 item["type"] = "thumbnail"
                 if not original_item.get("width") and not original_item.get("height"):
                     adjust_thumb_size(item, self.params)
             if ("popup" in item or item["type"] == "thumbnail") and "rawpath" in item:
                 item["url"] = make_thumbnail(item, orig_path=original_item["url"])
                 if item["type"] != "thumbnail":
                     item["fullurl"] = item["url"]
                     item["type"] = "imagegallery" if item["popup"] == "gallery" else "imagepopup"
                 else:
                     item["type"] = "image"
             return item
         elif item["type"] == "stack":
             item["stack"] = self.process_items(item["stack"])
             return item
         elif item["type"] in item_processors:
             return item_processors[item["type"]](item, self.params)
         else:
             return item
     elif isinstance(item, list):
         return self.process_items(item)
     else:
         return item
Exemple #7
0
 def process_item(self, item, orig_item=None, in_media_item=False):
     if isinstance(item, dict) and "subpage" in item:
         item["subpage"] = self.process_item(item["subpage"])
     if type(item) in (
             str,
             unicode) and os.path.exists(item) and not os.path.isdir(item):
         if not orig_item:
             orig_item = {}
         newitem = {"type": get_file_type(item), "mime": get_mimetype(item)}
         if "width" in orig_item:
             newitem["width"] = orig_item["width"]
         if "height" in orig_item:
             newitem["height"] = orig_item["height"]
         if newitem["type"] == "image" and ("width" not in newitem
                                            or "height" not in newitem):
             width, height = get_image_size(item)
             if width and height:
                 try:
                     if "width" not in newitem and "height" not in newitem:
                         newitem["width"] = width
                         newitem["height"] = height
                     elif "width" not in newitem:
                         newitem[
                             "width"] = width * newitem["height"] / height
                     else:
                         newitem[
                             "height"] = height * newitem["width"] / width
                 except TypeError:
                     pass
         # Should all images should be converted to thumbnails?
         do_thumbnail = False
         if newitem["type"] == "image" and self.params["allthumbs"]:
             # If we are in a media item, do not make thumbnail now, it will
             # be done (if needed) in the media item
             if not in_media_item:
                 adjust_thumb_size(newitem, self.params)
                 do_thumbnail = True
         newitem["rawpath"] = item
         if self.params['WEB_ROOT'] and self.params[
                 'WEB_URL'] and self.params["WEB_ROOT"] in item:
             newitem["url"] = item.replace(self.params["WEB_ROOT"],
                                           self.params["WEB_URL"])
         elif self.params["copy_images"] or do_thumbnail:
             new_name = item.replace(os.sep, "_")
             new_path = os.path.join(self.params["target_dir"], "imgs",
                                     new_name)
             if not do_thumbnail and not orig_item.get(
                     "type") == "thumbnail":
                 if not DEBUG and (
                         not os.path.exists(new_path) or
                     (os.path.getmtime(item) > os.path.getmtime(new_path))):
                     shutil.copy(item, new_path)
             newitem["rawpath"] = new_path
             newitem["url"] = os.path.join("imgs", new_name)
             if do_thumbnail:
                 newitem["url"] = make_thumbnail(newitem, orig_path=item)
         else:
             newitem["url"] = item.replace(self.params["target_dir"], "")
         if "type" in orig_item:
             newitem["type"] = orig_item["type"]
         return newitem
     elif isinstance(item, dict) and "type" in item:
         if item["type"] in ("image", "video", "thumbnail"):
             original_item = dict(item)
             processed = self.process_item(item["url"],
                                           item,
                                           in_media_item=True)
             if isinstance(processed, dict):
                 item.update(processed)
             else:
                 item["url"] = processed
             if item["type"] == "image" and self.params["allthumbs"]:
                 item["type"] = "thumbnail"
                 if not original_item.get(
                         "width") and not original_item.get("height"):
                     adjust_thumb_size(item, self.params)
             if ("popup" in item
                     or item["type"] == "thumbnail") and "rawpath" in item:
                 item["url"] = make_thumbnail(
                     item, orig_path=original_item["url"])
                 if item["type"] != "thumbnail":
                     item["fullurl"] = item["url"]
                     item["type"] = "imagegallery" if item[
                         "popup"] == "gallery" else "imagepopup"
                 else:
                     item["type"] = "image"
             return item
         elif item["type"] == "stack":
             item["stack"] = self.process_items(item["stack"])
             return item
         elif item["type"] in item_processors:
             return item_processors[item["type"]](item, self.params)
         else:
             return item
     elif isinstance(item, list):
         return self.process_items(item)
     else:
         return item