mirror of
https://github.com/dobin/avred
synced 2026-06-08 13:54:13 +00:00
feature: make files downloadable
This commit is contained in:
@@ -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,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 %}
|
||||
|
||||
@@ -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 %}
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user