Skip to content

Instantly share code, notes, and snippets.

@marpie
Forked from 0x1F9F1/clean_bndb.py
Created January 31, 2019 10:55
Show Gist options
  • Save marpie/caa6c5fd3540cf96e09e19c47a8ac336 to your computer and use it in GitHub Desktop.
Save marpie/caa6c5fd3540cf96e09e19c47a8ac336 to your computer and use it in GitHub Desktop.
import sqlite3
import contextlib
import os
import sys
def clean_binja_snapshots(conn, limit = 1):
with conn as cur:
for section in [ 'snapshot', 'file_data' ]:
cur.execute(f'DELETE FROM {section} WHERE id NOT IN (SELECT id FROM {section} ORDER BY id DESC LIMIT ?)', (limit,))
with conn as cur:
cur.execute('VACUUM')
if __name__ == '__main__':
if len(sys.argv) > 1:
db_file = sys.argv[1]
else:
db_file = input('Enter *.bndn name: ')
if os.path.isfile(db_file):
with contextlib.closing(sqlite3.connect(db_file)) as conn:
conn.set_trace_callback(print)
clean_binja_snapshots(conn, 1)
else:
print('%s does not exist' % db_file)
input('Press any key to continue...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment