示例#1
0
filesizeM = 10
Mb = 1024 * 1024

os.system("dd if=/dev/urandom of=%s bs=%d count=%d" % (TARGET, Mb, filesizeM))
random.seed(open(TARGET, 'rb').read(1024))

set_min_block_size(1024)
set_max_block_size(2048)
set_average_block_size(1024)

r = Rabin()

before = get_file_fingerprints(TARGET)
f = open(TARGET, 'rb+')
data = f.read(int(filesizeM / 2 * Mb))
r.update(data)
r.update(b'x')
data = f.read()
r.update(data)
after = r.fingerprints()

assert len(before) <= len(after)

diffcount = 0
for i in range(len(before)):
    try:
        bs, bl, bp = before[i]
        As, al, ap = after[i]
        # assert bs == As
        assert bl == al
        assert bp == ap
示例#2
0
reached = []
def block_reached(start, length, fingerprint):
    # print('(%s, %s, %s)' % (start, length, fingerprint))
    reached.append((start, length, fingerprint))

r = Rabin()
r.register(block_reached)

with open(TARGET, 'rb') as f:
    while True:
        size = random.randint(1,os.path.getsize(TARGET))
        data = f.read(size)
        if len(data) == 0:
            break
        r.update(data)

partial = r.fingerprints()
gold = get_file_fingerprints(TARGET)

assert len(gold) == len(partial) == len(reached)

for i in range(len(gold)):
    try:
        gs,gl,gp = gold[i]
        ps,pl,pp = partial[i]
        rs,rl,rp = reached[i]
        assert gs == ps == rs
        assert gl == pl == rl
        assert gp == pp == rp
    except:
示例#3
0
filesizeM = 10
Mb = 1024 * 1024

os.system("dd if=/dev/urandom of=%s bs=%d count=%d" % (TARGET, Mb, filesizeM))
random.seed(open(TARGET, 'r').read(1024))

set_min_block_size(1024)
set_max_block_size(2048)
set_average_block_size(1024)

r = Rabin()

before = get_file_fingerprints(TARGET)
f = open(TARGET, 'r+')
data = f.read(filesizeM / 2 * Mb)
r.update(data)
r.update('x')
data = f.read()
r.update(data)
after = r.fingerprints()

assert len(before) <= len(after)

diffcount = 0
for i in range(len(before)):
    try:
        bs, bl, bp = before[i]
        As, al, ap = after[i]
        # assert bs == As
        assert bl == al
        assert bp == ap
示例#4
0
Mb = 1024*1024

os.system("dd if=/dev/urandom of=%s bs=%d count=%d" % (
    TARGET, Mb, filesizeM))
random.seed(open(TARGET, 'r').read(1024))

set_min_block_size(1024)
set_max_block_size(2048)
set_average_block_size(1024)

r = Rabin()

before = get_file_fingerprints(TARGET)
f = open(TARGET, 'r+')
data = f.read(filesizeM/2 * Mb)
r.update(data)
r.update('x')
data = f.read()
r.update(data)
after = r.fingerprints()

assert len(before) <= len(after) 

diffcount = 0
for i in range(len(before)):
    try:
        bs,bl,bp = before[i]
        As,al,ap = after[i]
        # assert bs == As
        assert bl == al
        assert bp == ap
示例#5
0
#!/usr/bin/env python

from rabin import Rabin, get_file_fingerprints, set_min_block_size, set_max_block_size, set_average_block_size

TARGET = 'test.bin'

set_min_block_size(1024)
set_max_block_size(2048)
set_average_block_size(1024)

def block_reached(start, length, fingerprint):
    print '(%s, %s, %s)' % (start, length, fingerprint)

r = Rabin()
r.register(block_reached)

with open(TARGET, 'r') as f:
    data = f.read()
    half = len(data) / 2
    r.update(data[:half])
    r.update(data[half:])

partial = r.fingerprints()
gold = get_file_fingerprints(TARGET)

print gold
print partial == gold