File: changefile.py

package info (click to toggle)
ori 0.8.1%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,204 kB
  • ctags: 2,659
  • sloc: cpp: 22,383; ansic: 5,870; sh: 451; python: 205; makefile: 21
file content (29 lines) | stat: -rw-r--r-- 711 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
import sys
import os.path
import random

CHANGE_SIZE = 30

size = os.path.getsize(sys.argv[1])
changes = [0]
for i in range(3):
    changes.append(random.randint(0,size-1-CHANGE_SIZE))
changes.sort()

newbuf = b''

with open(sys.argv[1], 'rb') as f:
    for i,c in enumerate(changes):
        if c == 0: continue
        rsize = max(0, c-changes[i-1])
        newbuf += f.read(rsize)
        for j in range(random.randint(CHANGE_SIZE-5, CHANGE_SIZE+5)):
            newbuf += chr(random.randint(60,80))
        changes[i] += CHANGE_SIZE
        f.seek(CHANGE_SIZE, os.SEEK_CUR)
    rsize = max(0, size - changes[-1])
    newbuf += f.read(rsize)

with open(sys.argv[1], 'wb') as f:
    f.write(newbuf)