feature: make files downloadable

This commit is contained in:
2023-06-22 09:57:12 +02:00
parent e4f8dd412a
commit 4db76a64be
4 changed files with 77 additions and 2 deletions
+7
View File
@@ -115,6 +115,13 @@ File is not detected by AV.
</tr>
{% endfor %}
</table>
{% if current_user.is_authenticated %}
<a href="{{request.path}}/downloadPatchMatch/">Download</a> with all matches overwritten</td>
<br>
{% endif %}
<br>
{% endif %}
{% if outcome.fileStructure != '' %}
+5 -1
View File
@@ -5,7 +5,11 @@
{% elif outcome.verification.matchConclusions.verifyStatus[index]|string == "VerifyStatus.IRRELEVANT" %}
<td style="background-color:rgb(157, 143, 143)">Probably not relevant. Check verifier</td>
{% elif outcome.verification.matchConclusions.verifyStatus[index]|string == "VerifyStatus.DOMINANT" %}
<td style="background-color:rgb(63, 179, 63)">Dominant. Modify this to make file undetected</td>
<td style="background-color:rgb(63, 179, 63)">Dominant. Modify this to make file undetected
{% if current_user.is_authenticated %}
(<a href="{{request.path}}/downloadPatchMatch/{{loop.index0}}">Download</a>)
{% endif %}
</td>
{% else %}
<td></td>
{% endif %}
+3 -1
View File
@@ -11,7 +11,9 @@
<td>
{% endif %}
<label style="color: grey">{{ outcome.matches[loop.index0].sectionType.value }}</label>
<label style="color: grey">
{{ outcome.matches[loop.index0].sectionType.value }}
</label>
</td>
{% endfor %}
{% endif %}
+62
View File
@@ -106,6 +106,68 @@ def fileDownloadOutflank(filename):
attachment_filename=filename
)
@views.route("/file/<filename>/downloadPatchMatch/<id>")
@login_required
def fileDownloadPatchMatch(filename, id):
id = int(id)
if filename != secure_filename(filename):
flash('Invalid filename')
return redirect('index.html')
filepath = os.path.join(current_app.config['UPLOAD_FOLDER'], filename)
outcome, logData, errStr = getFileData(filepath)
if errStr is not None or outcome is None or logData is None:
return "Error: " + errStr
if not os.path.isfile(filepath):
return "Error: File not found: " + filepath
with open(filepath, 'rb') as file:
fileData: bytearray = bytearray(file.read())
match: Match = outcome.matches[id]
len = match.size
offset = match.fileOffset
data = b"\x00" * len
fileData[offset:offset+len] = data
return send_file(
io.BytesIO(fileData),
mimetype='application/octet-stream',
as_attachment=True,
attachment_filename=filename
)
@views.route("/file/<filename>/downloadPatchMatch/")
@login_required
def fileDownloadPatchFull(filename):
if filename != secure_filename(filename):
flash('Invalid filename')
return redirect('index.html')
filepath = os.path.join(current_app.config['UPLOAD_FOLDER'], filename)
outcome, logData, errStr = getFileData(filepath)
if errStr is not None or outcome is None or logData is None:
return "Error: " + errStr
if not os.path.isfile(filepath):
return "Error: File not found: " + filepath
with open(filepath, 'rb') as file:
fileData: bytearray = bytearray(file.read())
for match in outcome.matches:
print("Patch: {} {} {}".format(match.idx, match.fileOffset, match.size))
len = match.size
offset = match.fileOffset
data = b"\x00" * len
fileData[offset:offset+len] = data
return send_file(
io.BytesIO(fileData),
mimetype='application/octet-stream',
as_attachment=True,
attachment_filename=filename
)
### Examples related