def bc_generate_feature_xlsx(PdfReport, data, feature_file): #wb = Workbook(optimized_write = True) wb = Workbook() dest_filename = PdfReport.featuredir + '/' + ( filename_from_path(feature_file))[10:-3] + "xlsx" row_idx = [2] ws = wb.worksheets[0] #ws = wb.create_sheet() ws.title = "File Feature Information" ws.cell('%s%s' % ('A', '1')).value = '%s' % "Filename" ws.cell('%s%s' % ('B', '1')).value = '%s' % "Feature" ws.cell('%s%s' % ('C', '1')).value = '%s' % "Position" linenum = 0 for row in data: # Skip the lines with known text lines to be eliminated if (re.match("Total features", str(row))): continue filename = "Unknown" feature = "Unknown" position = "Unknown" # Some lines in the annotated_xxx.txt have less than three # columns where filename or feature may be missing. if len(row) > 3: filename = row[3] else: filename = "Unknown" if len(row) > 1: feature = row[1] else: feature = "Unknown" position = row[0] # If it is a special file, check if the user wants it to # be repoted. If not, exclude this from the table. if (PdfReport.bc_config_report_special_files == False) and \ (is_special_file(filename)): ## print("D: File %s is special. So skipping" %(filename)) continue ws.cell('%s%s' % ('A', row_idx[0])).value = '%s' % filename ws.cell('%s%s' % ('B', row_idx[0])).value = '%s' % feature ws.cell('%s%s' % ('C', row_idx[0])).value = '%s' % position row_idx[0] += 1 wb.save(filename=dest_filename)
def bc_generate_feature_xlsx(PdfReport, data, feature_file): #wb = Workbook(optimized_write = True) wb = Workbook() dest_filename = PdfReport.featuredir +'/'+ (filename_from_path(feature_file))[10:-3] + "xlsx" row_idx = [2] ws = wb.worksheets[0] #ws = wb.create_sheet() ws.title = "File Feature Information" ws.cell('%s%s'%('A', '1')).value = '%s' % "Filename" ws.cell('%s%s'%('B', '1')).value = '%s' % "Feature" ws.cell('%s%s'%('C', '1')).value = '%s' % "Position" linenum=0 for row in data: # Skip the lines with known text lines to be eliminated if (re.match("Total features",str(row))): continue filename = "Unknown" feature = "Unknown" position = "Unknown" # Some lines in the annotated_xxx.txt have less than three # columns where filename or feature may be missing. if len(row) > 3: filename = row[3] else: filename = "Unknown" if len(row) > 1: feature = row[1] else: feature = "Unknown" position = row[0] # If it is a special file, check if the user wants it to # be repoted. If not, exclude this from the table. if (PdfReport.bc_config_report_special_files == False) and \ (is_special_file(filename)): ## print("D: File %s is special. So skipping" %(filename)) continue ws.cell('%s%s'%('A', row_idx[0])).value = '%s' % filename ws.cell('%s%s'%('B', row_idx[0])).value = '%s' % feature ws.cell('%s%s'%('C', row_idx[0])).value = '%s' % position row_idx[0] += 1 wb.save(filename=dest_filename)
def make_table(self, header): self.set_text_color(10) self.set_font('Times','I',10) self.underline = 0 self.set_x(-80) self.cell(0, 6, "Note: ", border=0, ln=1) self.set_x(-80) self.cell(0, 5, "DIR: Directory:d; Regular file:r", border=0, ln=1) self.set_x(-80) self.cell(0, 5, "Size: Size of the file in bytes", border=0, ln=1) self.set_x(-80) self.cell(0, 5, "Deleted: If the file is Deleted ", border=0, ln=1) #Header w=[60,20,10,15,12,80] #Colors, line width and bold font self.set_table_hdr_attributes(w, header) #Color and font restoration self.set_table_body_attributes() fill=0 # Warn the user if the length of a feature file is > max lines if PdfReport.bc_max_lines_to_report and \ FiwalkReport.array_ind > PdfReport.bc_config_report_lines['FiwalkReport']: print("### WARNING ### Feature Report file has exceeded "\ "%d lines limit###" \ %(PdfReport.bc_config_report_lines['FiwalkReport'])) self.set_font('Times','',8) linenum = 0 for i in range(0, FiwalkReport.array_ind-1): column = 6 cell_text = FiwalkReport.fiDictList[i]['filename'] # Check if config file is set to not report special files if (PdfReport.bc_config_report_special_files == False) \ and (bc_utils.is_special_file(cell_text)): ## print("D: File %s is special. Skipping" %(cell_text)) continue # Config file sets the maxlines to 0 to report all the lines # or a specific number to limit the reporting lines. if (PdfReport.bc_config_report_lines['FiwalkReport'] != 0): if (linenum >= PdfReport.bc_config_report_lines['FiwalkReport']): # Lines reached max: Breaking print("FiwalkReport: Exceeded Maxlines: ", linenum) break linenum += 1 # Just print the filename if the path exceeds cell width if (len(cell_text) > w[0]/2): cell_text = filename_from_path(cell_text) text = bc_pdf.bc_adjust_text(cell_text, w[0]) self.cell(w[0],6,text,'LR',0,'L',fill) self.cell(w[1],column,FiwalkReport.fiDictList[i]['partition'],'LR',0,'L',fill) self.cell(w[2],column,FiwalkReport.fiDictList[i]['name_type'],'LR',0,'L',fill) self.cell(w[3],column,FiwalkReport.fiDictList[i]['filesize'],'LR',0,'L',fill) if FiwalkReport.fiDictList[i]['unalloc']: self.cell(w[4],column,'YES','LR',0,'C',fill) elif FiwalkReport.fiDictList[i]['alloc']: self.cell(w[4],column,'NO','LR',0,'C',fill) cell_text = str(FiwalkReport.fiDictList[i]['libmagic']) trimmed_text = bc_pdf.bc_adjust_text(cell_text, w[5]) self.cell(w[5],column,trimmed_text,'LR',0,'L',fill) self.ln() fill=not fill # Start from a new page with header names once # reached max_entries allowed per page. bc_pdf.bc_table_end_page(self, FiwalkReport, i, header, w) # Closure line self.cell(sum(w),0,'','T')
def bc_generate_feature_reports_in_pdf(self, PdfReport, data, feature_file): header = ['Filename', 'Position','Feature '] self.set_text_color(1) self.set_font('Times','B',12) fill=0 self.cell(40, 7, 'Feature File: ' + \ filename_from_path(feature_file), border=0, ln=1) self.set_font('Times','',8) self.underline = 0 self.set_fill_color(224,235,255) self.set_text_color(0) self.set_draw_color(128,0,0) self.set_line_width(.3) # Filename; position; feature w=[65,50,75] for i in range(0,len(header)): self.cell(w[i],7,header[i],1,0,'C',1) self.ln() linenum = 0 for row in data: # Skip the lines with known text lines to be eliminated if (re.match("Total features",str(row))): continue filename = "Unknown" feature = "Unknown" position = "Unknown" # Some lines in the annotated_xxx.txt have less than three # columns where filename or feature may be missing. if len(row) > 3: filename = row[3] else: filename = "Unkown" if len(row) > 1: feature = row[1] else: feature = "Unkown" position = row[0] # If it is a special file, check if the user wants it to # be repoted. If not, exclude this from the table. if (PdfReport.bc_config_report_special_files == False) and \ (bc_utils.is_special_file(filename)): ## print("D: File %s is special. So skipping" %(filename)) continue self.bc_write_column(w[0],6,filename,fill) self.bc_write_column(w[1],6,position,fill) self.bc_write_column(w[2],6,feature,fill) self.ln() fill=not fill # Start from a new page with header names once # reached max_entries allowed per page. if ((linenum >= FiwalkReport.max_entries_per_page) & (linenum%FiwalkReport.max_entries_per_page == 0)): bc_pdf.bc_table_end_page(self, FiwalkReport, linenum, header, w) linenum+=1 #Closure line self.cell(sum(w),0,'','T') return