-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssdeep.pyx
53 lines (43 loc) · 1.58 KB
/
ssdeep.pyx
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
cdef extern from "stdio.h": pass
cdef extern from "stdlib.h": pass
cdef extern from "string.h": pass
cdef extern from "errno.h": pass
cdef extern from "limits.h": pass
cdef extern from "sys/stat.h": pass
cdef extern from "unistd.h": pass
cdef extern from "ctype.h": pass
cdef extern from "inttypes.h": pass
cdef extern from "fuzzy.h":
int fuzzy_compare(char *sig1, char *sig2)
cdef extern from *:
char * fuzzy_hash(char *filename)
char * fuzzy_hash_data(char *buf, int buf_len)
cdef extern from "Python.h":
void Py_INCREF(object o)
void Py_DECREF(object o)
class SsdeepException(Exception): pass
cdef class ssdeep:
def __init__(self):
pass
def hash_file(self, filename):
"""hash_file(self, filename)
compute the ssdeep fuzzy hash for the input filename.
returns a string with the hash value"""
res = fuzzy_hash(filename)
# Py_INCREF(res)
if ' oops' in res:
raise SsdeepException, res.replace(' oops', ' error')
else: return res
def hash_bytes(self, buf):
"""compute the ssdeep fuzzy hash for the data in the buffer"""
cdef char* utext
utext = buf
res = fuzzy_hash_data(utext,len(buf))
if ' oops' in res:
raise SsdeepException, res,replace(' oops',' error')
else: return res
def compare(self, hash1, hash2):
"""compare(self, hash1, hash2)
compare two ssdeep hashes to discover their similarities
returns an integer 1-100 on the strength of the match. 0 means no match"""
return fuzzy_compare(hash1, hash2)