Updating memory drawer to allow both files and pd dataframes
This commit is contained in:
parent
2e7700c54c
commit
2f300eebe7
11
debug.py
Normal file → Executable file
11
debug.py
Normal file → Executable file
@ -1,3 +1,9 @@
|
||||
"""
|
||||
Sample file for debugging purposes and examples
|
||||
"""
|
||||
|
||||
import pandas as pd
|
||||
|
||||
#from herrewebpy.bioinformatics import sequence_alignment
|
||||
#sequence_alignment.SequenceAlignment(['aa', 'bb', 'cc'],['bb','aa','cc'], ['1','2','3'], ['1','2','3'])
|
||||
|
||||
@ -7,5 +13,6 @@
|
||||
# from herrewebpy.christianity import readplan_generator
|
||||
# readplan_generator.generate_readplan()
|
||||
|
||||
from herrewebpy.firmware_forensics import memory_drawer
|
||||
memory_drawer.MemoryDrawer('sample_data/csv/stack_and_functions.csv')
|
||||
from herrewebpy.firmware_forensics.memory_drawer import MemoryDrawer
|
||||
df = pd.read_csv('sample_data/csv/stack_and_functions.csv')
|
||||
MemoryDrawer(df)
|
||||
|
0
docs/conf.py
Normal file → Executable file
0
docs/conf.py
Normal file → Executable file
0
examples/bioinformatics.ipynb
Normal file → Executable file
0
examples/bioinformatics.ipynb
Normal file → Executable file
0
herrewebpy/__init__.py
Normal file → Executable file
0
herrewebpy/__init__.py
Normal file → Executable file
0
herrewebpy/bioinformatics/__init__.py
Normal file → Executable file
0
herrewebpy/bioinformatics/__init__.py
Normal file → Executable file
0
herrewebpy/bioinformatics/sequence_alignment.py
Normal file → Executable file
0
herrewebpy/bioinformatics/sequence_alignment.py
Normal file → Executable file
0
herrewebpy/christianity/__init__.py
Normal file → Executable file
0
herrewebpy/christianity/__init__.py
Normal file → Executable file
7
herrewebpy/christianity/readplan_generator.py
Normal file → Executable file
7
herrewebpy/christianity/readplan_generator.py
Normal file → Executable file
@ -30,7 +30,12 @@ def generate_readplan(start_date):
|
||||
total_chapters = sum([bible.get_number_of_chapters(reading_list[i]) for i in range(len(reading_list))])
|
||||
chapters_per_day = total_chapters // 365 + 1
|
||||
|
||||
df = pd.DataFrame(columns=['Book', 'Chapters'])
|
||||
# Create a dataframe with each book, each chapter, and number of verses
|
||||
df = pd.DataFrame(columns=['Book', 'Chapters', 'Verses'])
|
||||
for book in reading_list:
|
||||
df = pd.concat([df, pd.DataFrame({'Book': [book.title], 'Chapters': [bible.get_number_of_chapters(book)]})])
|
||||
|
||||
df = pd.DataFrame(columns=['Book', 'Chapters', 'Verses'])
|
||||
for book in reading_list:
|
||||
df = pd.concat([df, pd.DataFrame({'Book': [book.title], 'Chapters': [bible.get_number_of_chapters(book)]})])
|
||||
|
||||
|
0
herrewebpy/config/trains/credentials.json
Normal file → Executable file
0
herrewebpy/config/trains/credentials.json
Normal file → Executable file
0
herrewebpy/firmware_forensics/__init__.py
Normal file → Executable file
0
herrewebpy/firmware_forensics/__init__.py
Normal file → Executable file
0
herrewebpy/firmware_forensics/function_extractor.py
Normal file → Executable file
0
herrewebpy/firmware_forensics/function_extractor.py
Normal file → Executable file
49
herrewebpy/firmware_forensics/memory_drawer.py
Normal file → Executable file
49
herrewebpy/firmware_forensics/memory_drawer.py
Normal file → Executable file
@ -1,7 +1,6 @@
|
||||
# Using plotly
|
||||
import plotly.graph_objects as go
|
||||
import random, argparse
|
||||
import numpy as np
|
||||
import random, argparse, os, datetime
|
||||
import pandas as pd
|
||||
|
||||
"""
|
||||
@ -14,10 +13,37 @@ This script reads a CSV file with the following columns: start,end,name,order,co
|
||||
Then it generates a memory map of the regions, and outputs an HTML file with the memory map.
|
||||
"""
|
||||
|
||||
def read_data(input_file):
|
||||
data = pd.read_csv(input_file)
|
||||
class MemoryDrawer():
|
||||
|
||||
def convert_to_int(value):
|
||||
def __init__(self, input):
|
||||
"""
|
||||
If this file is run manually, will take an input .csv path and output a memory map in .html format.
|
||||
|
||||
Args:
|
||||
(Required) input (str): Path to the input .csv file
|
||||
(Optional) output (str): Path to the output .html file
|
||||
"""
|
||||
if isinstance(input, str):
|
||||
if os.path.isfile(input):
|
||||
output = f'{os.path.splitext(os.path.basename(input))[0]}_memory_drawer'
|
||||
data = MemoryDrawer.read_data(pd.read_csv(input))
|
||||
else:
|
||||
raise ValueError('Input string must be a path to a .csv file')
|
||||
elif isinstance(input, pd.DataFrame):
|
||||
now = datetime.datetime.now()
|
||||
output = f'{now.strftime("%Y-%m-%d_%H-%M-%S")}_memory_drawer'
|
||||
data = MemoryDrawer.read_data(input)
|
||||
else:
|
||||
raise ValueError('Input must be a path to a .csv file or a pandas DataFrame')
|
||||
|
||||
|
||||
fig = MemoryDrawer.draw_diagram(data)
|
||||
MemoryDrawer.write_output(fig, output)
|
||||
|
||||
|
||||
def read_data(data):
|
||||
|
||||
def _convert_to_int(value):
|
||||
try:
|
||||
if isinstance(value, str) and value.startswith('0x'):
|
||||
return int(value, 16)
|
||||
@ -26,8 +52,8 @@ def read_data(input_file):
|
||||
except ValueError:
|
||||
return value
|
||||
|
||||
data['start'] = data['start'].apply(convert_to_int)
|
||||
data['end'] = data['end'].apply(convert_to_int)
|
||||
data['start'] = data['start'].apply(_convert_to_int)
|
||||
data['end'] = data['end'].apply(_convert_to_int)
|
||||
data['size'] = data['end'] - data['start']
|
||||
|
||||
#data.sort_values(by=['size'], inplace=True, ascending=False)
|
||||
@ -260,15 +286,10 @@ def draw_diagram(data, vertical_gap_percentage=0.08, horizontal_gap=0.1):
|
||||
def write_output(fig, output_file):
|
||||
fig.write_html(f'{output_file}.html')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
argparser = argparse.ArgumentParser()
|
||||
argparser.add_argument('--input', help='Input CSV file path', required=True, type=str)
|
||||
argparser.add_argument('--output', help='Output HTML filename', required=False, type=str)
|
||||
args = argparser.parse_args()
|
||||
|
||||
if not args.output:
|
||||
args.output = 'memory_drawer'
|
||||
|
||||
data = read_data(args.input)
|
||||
fig = draw_diagram(data)
|
||||
write_output(fig, args.output)
|
||||
MemoryDrawer(args.input)
|
0
herrewebpy/mlops/__init__.py
Normal file → Executable file
0
herrewebpy/mlops/__init__.py
Normal file → Executable file
0
herrewebpy/mlops/anomaly_scoring.py
Normal file → Executable file
0
herrewebpy/mlops/anomaly_scoring.py
Normal file → Executable file
0
herrewebpy/trains/__init__.py
Normal file → Executable file
0
herrewebpy/trains/__init__.py
Normal file → Executable file
0
herrewebpy/trains/ns_api.py
Normal file → Executable file
0
herrewebpy/trains/ns_api.py
Normal file → Executable file
0
readthedocs.yml
Normal file → Executable file
0
readthedocs.yml
Normal file → Executable file
0
requirements.txt
Normal file → Executable file
0
requirements.txt
Normal file → Executable file
0
sample_data/csv/logdata.csv
Normal file → Executable file
0
sample_data/csv/logdata.csv
Normal file → Executable file
Can't render this file because it is too large.
|
0
sample_data/csv/stack_and_functions.csv
Normal file → Executable file
0
sample_data/csv/stack_and_functions.csv
Normal file → Executable file
0
sample_data/firmwares/S7_BL31.bin
Normal file → Executable file
0
sample_data/firmwares/S7_BL31.bin
Normal file → Executable file
Loading…
x
Reference in New Issue
Block a user