1+ import os
12import logging
23from collections import Counter
34from tempfile import NamedTemporaryFile
78from django .contrib import messages
89from django .core .cache import cache
910from django .core .files .storage import default_storage
10- from django .http import HttpResponse , JsonResponse , HttpResponseNotAllowed
11+ from django .http import HttpResponse , JsonResponse , HttpResponseNotAllowed , Http404 , FileResponse
1112from django .http .response import HttpResponseBadRequest
1213from django .shortcuts import redirect , render
1314from django .utils import timezone
@@ -146,6 +147,12 @@ def get(self, request, *args, **kwargs):
146147 else :
147148 is_bookmarked = False
148149
150+ # Check if binwalk found data to extract
151+ _ , extracted_files = default_storage .listdir (os .path .join (sha , "extracted" ))
152+ hidden_files = {}
153+ for fname in extracted_files :
154+ hidden_files [fname ] = os .path .join (sha , "extracted" , fname )
155+
149156 return render (request , 'front/report.html' , {
150157 'result' : result ,
151158 'status' : status ,
@@ -155,12 +162,28 @@ def get(self, request, *args, **kwargs):
155162 'hunting_matches' : hunting_matches ,
156163 'similar_samples' : similar_samples ,
157164 'cache_retention_time' : cache_retention_time ,
158- 'is_bookmarked' : is_bookmarked })
165+ 'is_bookmarked' : is_bookmarked ,
166+ 'hidden_files' : hidden_files ,
167+ })
159168 except Exception as e :
160169 logging .exception (e )
161170 return redirect (reverse_lazy ('front:home' ))
162171
163172
173+ def dl_hidden (request , sha256 , filename ):
174+ fpath = os .path .join (sha256 , "extracted" , filename )
175+ if not default_storage .exists (fpath ):
176+ raise Http404 ("File not found" )
177+
178+ file = default_storage .open (fpath , "rb" )
179+
180+ return FileResponse (
181+ file ,
182+ as_attachment = True ,
183+ filename = filename .split ("/" )[- 1 ],
184+ )
185+
186+
164187def report_status_view (request , sha256 ):
165188 try :
166189 report_status = ReportService .get_status (sha256 )
0 commit comments