Beispiel #1
0
def bc_generate_bar_graph(PdfReport, image_info, outfile, item_dict):
    fig = Figure()
    canvas = FigureCanvas(fig)
    ax = fig.add_subplot(1, 1, 1)

    y = []
    group_labels = []

    ## print("D: Generate_bar_graph: Dict:Length: %d, %s"
    ## % (len(item_dict), item_dict.items()))

    # Simple lambda expression to sort the items in ascending order (then reverse it)
    sorted_items = sorted(item_dict.items(), key=lambda x: x[1])
    sorted_items.reverse()
    num_items = 0
    for i in sorted_items:
        y.append(i[1])
        group_labels.append(i[0])
        num_items += 1
        if num_items >= PdfReport.bc_max_formats_in_bar_graph:
            ## print("D: Reporting only %d formats in the bargraph" %num_items)
            break

    # calculate the number of bars required
    N = len(y)
    # generate a range of numbers (just a placeholder before we relabel)
    ind = range(N)

    # Make the font small and the xticks vertical
    for label in ax.yaxis.get_ticklabels():
        # label is a Text instance
        label.set_fontsize(6)

    for label in ax.xaxis.get_ticklabels():
        label.set_fontsize(7)
    # set up the actual graphing
    ax.bar(ind, y, width=0.1, facecolor='#888888', ecolor='black')
    ax.set_ylabel('Counts')
    imgname = 'image_filename: ' + str(image_info['image_filename'])
    imgname = 'Disk Image: ' + filename_from_path(imgname)
    ax.set_title(imgname + ' File counts (by format)')
    rects = ax.bar(ind, y, width=0.3, facecolor='#888888', ecolor='black')

    # Write the frequency on top of each bar
    for rect in rects:
        height = rect.get_height()
        ax.text(rect.get_x() + rect.get_width() / 2.,
                height + 1.0,
                '%d' % int(height),
                ha='center',
                va='bottom')

    ax.set_xticks(ind)
    ax.set_xticklabels(group_labels)
    fig.autofmt_xdate()

    #pp = PdfPages(outfile)
    canvas.print_figure(outfile)

    bc_addToReportFileList(outfile, PdfReport)
Beispiel #2
0
def bc_generate_bar_graph(PdfReport, image_info, outfile, item_dict):
    fig = Figure()
    canvas = FigureCanvas(fig)
    ax = fig.add_subplot(1,1,1)

    y = []
    group_labels = []

    ## print("D: Generate_bar_graph: Dict:Length: %d, %s"
                       ## % (len(item_dict), item_dict.items())) 

    # Simple lambda expression to sort the items in ascending order (then reverse it)
    sorted_items = sorted(item_dict.items(), key=lambda x: x[1])
    sorted_items.reverse()
    num_items = 0
    for i in sorted_items:
       y.append(i[1])
       group_labels.append(i[0])
       num_items += 1
       if num_items >= PdfReport.bc_max_formats_in_bar_graph:
           ## print("D: Reporting only %d formats in the bargraph" %num_items)
           break
 
    # calculate the number of bars required
    N = len(y)
    # generate a range of numbers (just a placeholder before we relabel)
    ind = range(N)

    # Make the font small and the xticks vertical
    for label in ax.yaxis.get_ticklabels():
        # label is a Text instance
        label.set_fontsize(6)

    for label in ax.xaxis.get_ticklabels():
        label.set_fontsize(7)
    # set up the actual graphing
    ax.bar(ind,y,width=0.1,facecolor = '#888888',ecolor = 'black')
    ax.set_ylabel('Counts')
    imgname = 'image_filename: ' + str(image_info['image_filename'])
    imgname='Disk Image: '+filename_from_path(imgname)
    ax.set_title(imgname + ' File counts (by format)')
    rects = ax.bar(ind,y,width=0.3,facecolor = '#888888',ecolor = 'black')

    # Write the frequency on top of each bar
    for rect in rects:
        height = rect.get_height()
        ax.text(rect.get_x()+rect.get_width()/2., height+1.0, '%d'%int(height), ha='center', va='bottom')

    ax.set_xticks(ind)
    ax.set_xticklabels(group_labels)
    fig.autofmt_xdate()
 
    #pp = PdfPages(outfile)
    canvas.print_figure(outfile)

    bc_addToReportFileList(outfile, PdfReport)
Beispiel #3
0
def be_create_pdf_report_file(input_file, annotated_file):
    # Table column headers
    tab_header_feat = ['Filename', 'Position','Feature ']

    pdf = PDF_BE()
    pdf.compress = False
    pdf.add_page()
    pdf.make_table_feat_pdf(input_file,tab_header_feat)

    # Name the pdf file: Remove the first 10 characters: "annotated_"
    # and the last 4 characters: ".txt" and add :.pdf" in the suffix.
    # First create a new directory
    pdf_file = PdfReport.featuredir +'/' + annotated_file[10:-3] + 'pdf'
    pdf.output(pdf_file,'F')
    bc_utils.bc_addToReportFileList(pdf_file, PdfReport)
    return(pdf_file)
Beispiel #4
0
    def bc_generate_fiwalk_reports(self, fn):
        # Output text file created using bulk-extractor output
        # We will use this text file to populate the pdf report
        ofn_be = fn.outdir + ".txt"
        FiwalkReport.outdir = fn.outdir
        prtn = FiwalkReport.numPartitions

        # Table headers
        header_be = ['Bulk Extractor Report Files','Feature Instances','FLTF','FUTF','FIER']
        header_files = ['Filename','Partition','DIR','Size','Deleted','Filetype']
        
        tab_header_delfiles = [' Partition ', 'Deleted File']
        tab_header_file_fmts = ['Partition', 'File']
        tab_header_statistics = ['Feature', 'Value']
        tab_header_bargraph = ['Format', 'Short Form', 'Files']

        # Data for Histogram
        # The frequency of each file-format type is mapped into a histogram/plot.
        # We calculate the number of files in each file format here.

        num_fmt_files = 0
        if (PdfReport.bc_max_fmtfiles_to_report):
            for x in self.bcFmtDict:
              file_format = x
              short_fmt_name = self.bcFmtDict[x]
              pdf=PDF()
              pdf.compress = False
              pdf.set_font('Arial','',10)
              pdf.add_page()
              pdf.make_table_fmtfiles(tab_header_file_fmts, file_format)
              pdf_file = fn.outdir + '/format_' + short_fmt_name + '.pdf'
                  
              pdf.output(pdf_file,'F')
              bc_utils.bc_addToReportFileList(pdf_file, PdfReport)
          
              num_fmt_files += 1
  
              # if the configured value for max fmtfiles is 0, it reports all.
              # else it uses the number specified in the config file.
              # If the number not configured, it uses the hardcoded default:20
              if PdfReport.bc_max_fmtfiles_to_report and \
                   num_fmt_files >= PdfReport.bc_max_fmtfiles_to_report:
                  ## print("D: FMT files exceeded max limit of %d" %(num_fmt_files))
                  break

        ## Report the bargraph only if the configuration file says so
        outfile = FiwalkReport.outdir + '/bc_format_bargraph.pdf'
        if PdfReport.bc_config_report_files['bc_format_bargraph']:
            bc_graph.bc_draw_histogram_fileformat(PdfReport, image_info, \
                                                  outfile, self.dictFileFmtVal)
  
            # Also make a table of the same information
            pdf=PDF()
            pdf.compress = False
            pdf.set_font('Arial','',10)
            pdf.add_page()
            pdf.bc_make_table_fileformat(tab_header_bargraph, \
                        self.dictFileFmtVal, self.bcFmtDict)
            pdf_file = fn.outdir + '/format_table.pdf'
            pdf.output(pdf_file,'F')
            bc_utils.bc_addToReportFileList(pdf_file, PdfReport)
  
  
        ## Report the Fiwalk Report file only if the config file says so
        if PdfReport.bc_config_report_files['FiwalkReport'] == 1:
            pdf=PDF()
            pdf.compress = False
            pdf.set_title("Bitcurator Report")
 
            # Print the statistics first
            pdf.set_font('Arial','',10)
            pdf.add_page()

            pdf.make_table_stat(tab_header_statistics)
  
            '''
            # If configured as -1, the table of files is not generated.
            if (PdfReport.bc_config_report_lines['FiwalkReport'] != -1):
                pdf.set_font('Arial','',10)
                pdf.add_page()
                pdf.make_table(header_files)
            '''
            pdf_file = fn.outdir + '/FiwalkReport.pdf'
            pdf.output(pdf_file,'F')
            bc_utils.bc_addToReportFileList(pdf_file, PdfReport)
          
        # Generate the Report of deleted files
  
        ## Report the Deleted Files only if the config file says so
        if PdfReport.bc_config_report_files['FiwalkDeletedFiles'] == 1:
            ## print("D: Generating Deleted Files Report")
            pdf=PDF()
            pdf.compress = False
            pdf.set_font('Arial','B',10)
            pdf.add_page()
            y = pdf.get_y()
            pdf.set_y(y+10)
            pdf.make_table_delfiles(tab_header_delfiles)
            pdf_file = fn.outdir + '/FiwalkDeletedFiles.pdf'
            print("Generating ", pdf_file)
            pdf.output(pdf_file, 'F')
            bc_utils.bc_addToReportFileList(pdf_file, PdfReport)
  
        ## Now add the info from bulk-extractor output (be_ofn)
        ## Report the BE Report file only if the config file says so
        if PdfReport.bc_config_report_files['BeReport'] == 1:
              pdf=PDF_BE()
              pdf.compress = False
  
              pdf.set_font('Arial','B',10)
              pdf.add_page()
              y = pdf.get_y()
              pdf.set_y(y+10)
              pdf.set_text_color(128)
              pdf.make_table_be(header_be, ofn_be)
  
              pdf_file = fn.outdir + '/BeReport.pdf'
              pdf.output(pdf_file,'F')
              bc_utils.bc_addToReportFileList(pdf_file, PdfReport)

        ## print("Printing the Generated PDF files ")
        bc_utils.bc_printReportFileList(PdfReport, FiwalkReport)