void MRP_PCMSource::GetSamples(PCM_source_transfer_t * block) { std::lock_guard<std::mutex> locker(m_mutex); // wasteful prezeroing if no problem, but meh for now... for (int i = 0; i < block->length*block->nch; ++i) block->samples[i] = 0.0; if (m_dsp != nullptr) { if (m_dsp->is_prepared() == true) { // Oddly enough, PCM_source doesn't have a Seek method that we could react to. // So a hack like this is needed to detect a seek happened... // This may not be completely correct but the fuzzy comparison should make it pretty close double t0 = m_lastpos + ((double)block->length / block->samplerate); if (fuzzy_compare(t0, block->time_s) == false) { // was probably seeked //char buf[256]; //sprintf(buf, "pcm_source seeked %f %f %f", m_lastpos, t0, block->time_s); //OutputDebugString(buf); m_dsp->seek(block->time_s); } m_dsp->process_audio(block->samples, block->nch, block->samplerate, block->length); } } block->samples_out = block->length; m_lastpos = block->time_s; }
static PyObject *__pyx_f_6ssdeep_6ssdeep_compare(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_hash1 = 0; PyObject *__pyx_v_hash2 = 0; PyObject *__pyx_r; char (*__pyx_1); char (*__pyx_2); PyObject *__pyx_3 = 0; static char *__pyx_argnames[] = {"hash1","hash2",0}; if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO", __pyx_argnames, &__pyx_v_hash1, &__pyx_v_hash2)) return 0; Py_INCREF(__pyx_v_self); Py_INCREF(__pyx_v_hash1); Py_INCREF(__pyx_v_hash2); /* "/home/jose/tmp/ssdeep-2.2/pyssdeep-read-only/ssdeep.pyx":53 */ __pyx_1 = PyString_AsString(__pyx_v_hash1); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; goto __pyx_L1;} __pyx_2 = PyString_AsString(__pyx_v_hash2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; goto __pyx_L1;} __pyx_3 = PyInt_FromLong(fuzzy_compare(__pyx_1,__pyx_2)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; goto __pyx_L1;} __pyx_r = __pyx_3; __pyx_3 = 0; goto __pyx_L0; __pyx_r = Py_None; Py_INCREF(__pyx_r); goto __pyx_L0; __pyx_L1:; Py_XDECREF(__pyx_3); __Pyx_AddTraceback("ssdeep.ssdeep.compare"); __pyx_r = 0; __pyx_L0:; Py_DECREF(__pyx_v_self); Py_DECREF(__pyx_v_hash1); Py_DECREF(__pyx_v_hash2); return __pyx_r; }
static PyObject * ssdeep_fuzzy_compare(PyObject *self, PyObject *args) { int distance; /* difference between hash signature one and two (return value)*/ char *sig1, *sig2; /* local storage for the two hash signatures */ if (!PyArg_ParseTuple(args, "ss", &sig1, &sig2)) { PyErr_SetObject(PyExc_ValueError, Py_BuildValue("s", "Unable to parse two string signatures from argument list")); return NULL; } distance = fuzzy_compare(sig1, sig2); return Py_BuildValue("i", distance); }
static PyObject * pydeep_compare(PyObject *self, PyObject *args){ char *ssdeepHash1= NULL; char *ssdeepHash2= NULL; int ret; if (!PyArg_ParseTuple(args, "ss", &ssdeepHash1, &ssdeepHash2)){ return NULL; } ret = fuzzy_compare(ssdeepHash1, ssdeepHash2); if (ret < 0){ PyErr_SetString(pydeepError, "Error in fuzzy compare"); return NULL; } return Py_BuildValue("i", ret); }
bool match_compare(state *s, Filedata * f) { if (NULL == s) fatal_error("%s: Null state passed into match_compare", __progname); bool status = false; size_t fn_len = _tcslen(f->get_filename()); std::vector<Filedata* >::const_iterator it; for (it = s->all_files.begin() ; it != s->all_files.end() ; ++it) { // When in pretty mode, we still want to avoid printing // A matches A (100). if (s->mode & mode_match_pretty) { if (!(_tcsncmp(f->get_filename(), (*it)->get_filename(), std::max(fn_len,_tcslen((*it)->get_filename())))) and (f->get_signature() == (*it)->get_signature())) { // Unless these results from different matching files (such as // what happens in sigcompare mode). That being said, we have to // be careful to avoid NULL values such as when working in // normal pretty print mode. if (not(f->has_match_file()) or f->get_match_file() == (*it)->get_match_file()) continue; } } int score = fuzzy_compare(f->get_signature().c_str(), (*it)->get_signature().c_str()); if (-1 == score) print_error(s, "%s: Bad hashes in comparison", __progname); else { if (score > s->threshold or MODE(mode_display_all)) { handle_match(s,f,(*it),score); status = true; } } } return status; }
static PyObject * _cffi_f_fuzzy_compare(PyObject *self, PyObject *args) { char const * x0; char const * x1; Py_ssize_t datasize; int result; PyObject *arg0; PyObject *arg1; if (!PyArg_ParseTuple(args, "OO:fuzzy_compare", &arg0, &arg1)) return NULL; datasize = _cffi_prepare_pointer_call_argument( _cffi_type(0), arg0, (char **)&x0); if (datasize != 0) { if (datasize < 0) return NULL; x0 = alloca(datasize); memset((void *)x0, 0, datasize); if (_cffi_convert_array_from_object((char *)x0, _cffi_type(0), arg0) < 0) return NULL; } datasize = _cffi_prepare_pointer_call_argument( _cffi_type(0), arg1, (char **)&x1); if (datasize != 0) { if (datasize < 0) return NULL; x1 = alloca(datasize); memset((void *)x1, 0, datasize); if (_cffi_convert_array_from_object((char *)x1, _cffi_type(0), arg1) < 0) return NULL; } Py_BEGIN_ALLOW_THREADS _cffi_restore_errno(); { result = fuzzy_compare(x0, x1); } _cffi_save_errno(); Py_END_ALLOW_THREADS return _cffi_from_c_int(result, int); }
int main(int argc, char **argv) { unsigned char * buf; char * result, * result2; FILE *handle; srand(1); buf = (unsigned char *)malloc(SIZE); result = (char *)malloc(FUZZY_MAX_RESULT); result2 = (char *)malloc(FUZZY_MAX_RESULT); if (NULL == result || NULL == buf || NULL == result2) { fprintf (stderr,"%s: Out of memory\n", argv[0]); return EXIT_FAILURE; } generate_random(buf,SIZE); if (write_data(buf,SIZE,FILENAME)) return EXIT_FAILURE; printf ("Hashing buffer\n"); int status = fuzzy_hash_buf(buf,SIZE,result); if (status) printf ("Error during buf hash\n"); else printf ("%s\n", result); handle = fopen(FILENAME,"rb"); if (NULL == handle) { perror(FILENAME); return EXIT_FAILURE; } printf ("Hashing file\n"); status = fuzzy_hash_file(handle,result); if (status) printf ("Error during file hash\n"); else printf ("%s\n", result); fclose(handle); printf ("Modifying buffer and comparing to file\n"); int i; for (i = 0x100 ; i < 0x110 ; ++i) buf[i] = 37; status = fuzzy_hash_buf(buf,SIZE,result2); if (status) printf ("Error during buffer hash\n"); else printf ("%s\n", result2); i = fuzzy_compare(result,result2); if (-1 == i) printf ("An error occured during matching\n"); else { if (i != 0) printf ("MATCH: score = %d\n", i); else printf ("did not match\n"); } return EXIT_SUCCESS; }
int fuzzy::similarity (fuzzy & f) { std::string result = f.calc_digest (); std::string myresult = calc_digest (); return fuzzy_compare (result.c_str (), myresult.c_str ()); }