本文整理汇总了Python中viper.core.database.Database.edit_note方法的典型用法代码示例。如果您正苦于以下问题:Python Database.edit_note方法的具体用法?Python Database.edit_note怎么用?Python Database.edit_note使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类viper.core.database.Database
的用法示例。
在下文中一共展示了Database.edit_note方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: file_notes
# 需要导入模块: from viper.core.database import Database [as 别名]
# 或者: from viper.core.database.Database import edit_note [as 别名]
def file_notes():
db = Database()
update = request.forms.get('update')
new = request.forms.get('new')
delete = request.forms.get('delete')
note_title = request.forms.get('noteTitle')
note_body = request.forms.get('noteBody')
note_id = request.forms.get('id')
note_sha = request.forms.get('sha256')
project = request.forms.get('project')
# Delete Note
if delete and note_id:
db.delete_note(note_id)
# Update an existing note
if update and note_id:
db.edit_note(note_id, note_body)
if new and note_sha and note_title and note_body:
db.add_note(note_sha, note_title, note_body)
redirect('/file/{0}/{1}#notes'.format(project, note_sha))
示例2: file_notes
# 需要导入模块: from viper.core.database import Database [as 别名]
# 或者: from viper.core.database.Database import edit_note [as 别名]
def file_notes():
db = Database()
update = request.forms.get("update")
new = request.forms.get("new")
delete = request.forms.get("delete")
note_title = request.forms.get("noteTitle")
note_body = request.forms.get("noteBody")
note_id = request.forms.get("id")
note_sha = request.forms.get("sha256")
project = request.forms.get("project")
# Delete Note
if delete and note_id:
db.delete_note(note_id)
# Update an existing note
if update and note_id:
db.edit_note(note_id, note_body)
if new and note_sha and note_title and note_body:
db.add_note(note_sha, note_title, note_body)
redirect("/file/{0}/{1}#notes".format(project, note_sha))
示例3: run
# 需要导入模块: from viper.core.database import Database [as 别名]
# 或者: from viper.core.database.Database import edit_note [as 别名]
def run(self, *args):
try:
args = self.parser.parse_args(args)
except SystemExit:
return
if not __sessions__.is_set():
self.log('error', "No open session. This command expects a file to be open.")
return
db = Database()
# check if the file is already stores, otherwise exit as no notes command will work if the file is not stored in the database
malware = db.find(key='sha256', value=__sessions__.current.file.sha256)
if not malware:
self.log('error', "The opened file doesn't appear to be in the database, have you stored it yet?")
return
if args.list:
# Retrieve all notes for the currently opened file.
notes = malware[0].note
if not notes:
self.log('info', "No notes available for this file yet")
return
# Populate table rows.
rows = [[note.id, note.title] for note in notes]
# Display list of existing notes.
self.log('table', dict(header=['ID', 'Title'], rows=rows))
elif args.add:
title = input("Enter a title for the new note: ")
# Create a new temporary file.
with tempfile.NamedTemporaryFile(mode='w+') as tmp:
# Open the temporary file with the default editor, or with nano.
os.system('"${EDITOR:-nano}" ' + tmp.name)
# Once the user is done editing, we need to read the content and
# store it in the database.
body = tmp.read()
db.add_note(__sessions__.current.file.sha256, title, body)
self.log('info', 'New note with title "{0}" added to the current file'.format(bold(title)))
elif args.view:
# Retrieve note wth the specified ID and print it.
note = db.get_note(args.view)
if note:
self.log('info', bold('Title: ') + note.title)
if isinstance(note.body, bytes):
# OLD: Old style, the content is stored as bytes
# This is fixed when the user edits the old note.
body = note.body.decode()
else:
body = note.body
self.log('info', '{}\n{}'.format(bold('Body:'), body))
else:
self.log('info', "There is no note with ID {0}".format(args.view))
elif args.edit:
# Retrieve note with the specified ID.
note = db.get_note(args.edit)
if note:
# Create a new temporary file.
with tempfile.NamedTemporaryFile(mode='w+') as tmp:
# Write the old body to the temporary file.
if isinstance(note.body, bytes):
# OLD: Old style, the content is stored as bytes
body = note.body.decode()
else:
body = note.body
tmp.write(body)
tmp.flush()
tmp.seek(0)
# Open the old body with the text editor.
os.system('"${EDITOR:-nano}" ' + tmp.name)
# Read the new body from the temporary file.
body = tmp.read()
# Update the note entry with the new body.
db.edit_note(args.edit, body)
self.log('info', "Updated note with ID {0}".format(args.edit))
elif args.delete:
# Delete the note with the specified ID.
db.delete_note(args.delete)
else:
self.parser.print_usage()