Skip to content

Commit

Permalink
ch architecture result field in report
Browse files Browse the repository at this point in the history
output to string
  • Loading branch information
BenediktMKuehne committed Nov 23, 2023
1 parent 5d8e3e8 commit 0f105ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
15 changes: 3 additions & 12 deletions embark/embark/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,15 @@ def zip_check(content_list):
return all(value_ in content_list for value_ in check_list)


def cleanup_charfield(charfield):
def cleanup_charfield(charfield) -> str:
# clean-up for linux extensive os-descriptions
if charfield.startswith("Linux"):
charfield = charfield.split("/", 2)[:2]
charfield = f"{charfield[0]}{charfield[1]}"
charfield = (charfield[:16] + '..') if len(charfield) > 18 else charfield
# clean-up for architecture descriptions
elif isinstance(charfield, dict):
for key_, value_ in charfield.items():
if value_.lower() == 'el':
charfield = f"{key_} - Little Endian"
elif value_.lower() == 'eb':
charfield = f"{key_} - Big Endian"
else:
charfield = key_
return charfield


if __name__ == '__main__':
print(rnd_rgb_color())
print(rnd_rgb_full())
test_string = 'Linux / v2.6.33.2'
print(cleanup_charfield(test_string))
25 changes: 19 additions & 6 deletions embark/reporter/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ def get_individual_report(request, analysis_id):
return_dict['version'] = analysis_object.version
return_dict['path_to_logs'] = analysis_object.path_to_logs
return_dict['strcpy_bin'] = json.loads(return_dict['strcpy_bin'])
# architecture
arch_ = json.loads(return_dict['architecture_verified'])
for key_, value_ in arch_.items():
return_dict['architecture_verified'] += f"{key_}-{value_} "

return JsonResponse(data=return_dict, status=HTTPStatus.OK)
except Result.DoesNotExist:
Expand All @@ -165,17 +169,28 @@ def get_accumulated_reports(request):
}
"""
results = Result.objects.all()
charfields = ['architecture_verified', 'os_verified']
charfields = ['os_verified', 'architecture_verified']
data = {}
strcpy_bins = {}
system_bin_dict = {}
for result in results:
result = model_to_dict(result)
# Pop firmware object_id
# Pop all unnecessary data
result.pop('vulnerability', None) # FIXME this is disabled for now
result.pop('firmware', None)
result.pop('emba_command', None)

# architecture
architecture = json.loads(result.pop('architecture_verified', '{}'))
# clean-up for architecture descriptions
for key_, value_ in architecture.items():
if value_.lower() == 'el':
charfields['architecture_verified'] += f"{key_}-Little Endian "
elif value_.lower() == 'eb':
charfields['architecture_verified'] += f"{key_}-Big Endian "
else:
charfields['architecture_verified'] += f"{key_}-{value_} "

# Get counts for all strcpy_bin and system_bin values
system_bin = json.loads(result.pop('system_bin', '{}'))
strcpy_bin = json.loads(result.pop('strcpy_bin', '{}'))
Expand All @@ -188,18 +203,16 @@ def get_accumulated_reports(request):
system_bin_dict[key] = 0
system_bin_dict[key] += int(system_bin[key])

# os_verified
for charfield in charfields:
charfield = cleanup_charfield(charfield)

if charfield not in data:
data[charfield] = {}

value = result.pop(charfield)

if value not in data[charfield]:
data[charfield][value] = 0

data[charfield][value] += 1

for field in result:
if field not in data:
data[field] = {'sum': 0, 'count': 0}
Expand Down

0 comments on commit 0f105ef

Please sign in to comment.