ssdeep

package module
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2022 License: BSD-3-Clause, MIT Imports: 9 Imported by: 0

README

Build Status Coverage Status Go Report Card GoDoc

SSDEEP

Golang implementation based on the paper and implementation by Jesse Kornblum.

See the example in the app directory for the usage.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyHash is returned when no hash string is provided for scoring.
	ErrEmptyHash = errors.New("empty string")

	// ErrInvalidFormat is returned when a hash string is malformed.
	ErrInvalidFormat = errors.New("invalid ssdeep format")
)
View Source
var (
	// ErrFileTooSmall is returned when a file contains too few bytes.
	ErrFileTooSmall = errors.New("did not process files large enough to produce meaningful results")
	// ErrBlockSizeTooSmall is returned when a file can't produce a large enough block size.
	ErrBlockSizeTooSmall = errors.New("unable to establish a sufficient block size")
	// ErrZeroBlockSize is returned if we fail to establish a non-zero block size.
	ErrZeroBlockSize = errors.New("Reached zero block size, unable to compute hash")
)
View Source
var (

	// Force calculates the hash on invalid input
	Force = false
)

Functions

func Distance

func Distance(hash1, hash2 string) (score int, err error)

Distance computes the match score between two fuzzy hash signatures. Returns a value from zero to 100 indicating the match score of the two signatures. A match score of zero indicates the signatures did not match. Returns an error when one of the inputs are not valid signatures.

func Distance2 added in v0.3.2

func Distance2(hash1String1, hash1String2, hash2String1, hash2String2 string, hash1BlockSize, hash2BlockSize int) (score int, err error)

Distance2 computes the match score between two fuzzy hash signatures. Returns a value from zero to 100 indicating the match score of the two signatures. A match score of zero indicates the signatures did not match. Returns an error when one of the inputs are not valid signatures.

func FuzzyBytes added in v0.3.2

func FuzzyBytes(buffer []byte) (string, error)

FuzzyBytes computes the fuzzy hash of a slice of byte. It is the caller's responsibility to append the filename, if any, to result after computation. Returns an error when ssdeep could not be computed on the buffer.

Example
package main

import (
	"fmt"
	"github.com/DanielPels/ssdeep"
	"log"
	"math/rand"
)

func main() {
	buffer := make([]byte, 4097)
	rand.Read(buffer)
	h, err := ssdeep.FuzzyBytes(buffer)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(h)
}
Output:

func FuzzyFile added in v0.3.2

func FuzzyFile(f *os.File) (string, error)

FuzzyFile computes the fuzzy hash of a file using os.File pointer. FuzzyFile will computes the fuzzy hash of the contents of the open file, starting at the beginning of the file. When finished, the file pointer is returned to its original position. If an error occurs, the file pointer's value is undefined. It is the callers's responsibility to append the filename to the result after computation. Returns an error when ssdeep could not be computed on the file.

func FuzzyFilename added in v0.3.2

func FuzzyFilename(filename string) (string, error)

FuzzyFilename computes the fuzzy hash of a file. FuzzyFilename will opens, reads, and hashes the contents of the file 'filename'. It is the caller's responsibility to append the filename to the result after computation. Returns an error when the file doesn't exist or ssdeep could not be computed on the file.

Example
package main

import (
	"fmt"
	"github.com/DanielPels/ssdeep"
	"log"
	"os"
)

func main() {
	f, err := os.Open("file.txt")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	h, err := ssdeep.FuzzyFile(f)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(h)
}
Output:

func FuzzyReader added in v0.3.2

func FuzzyReader(f Reader, fileSize int) (string, error)

FuzzyReader computes the fuzzy hash of a Reader interface with a given input size. It is the caller's responsibility to append the filename, if any, to result after computation. Returns an error when ssdeep could not be computed on the Reader.

Types

type Reader added in v0.3.2

type Reader interface {
	io.Seeker
	io.Reader
}

Reader is the minimum interface that ssdeep needs in order to calculate the fuzzy hash. Reader groups io.Seeker and io.Reader.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL