magic

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package magic works out what a blob of data might be.

A Runner looks at data, asks which operations claim to be able to decode something of that shape, runs them from the registry it is given, and looks at what comes out — recursively, to a given depth — then ranks the recipes it found by how much like ordinary text or a known file the result became. Ported from CyberChef's lib/Magic.mjs; the Magic operation renders what Runner.Speculate returns.

Index

Constants

View Source
const BruteForceLen = 100

BruteForceLen is how much of the data brute forcing works on, since trying every byte over a large input is slow and rarely more informative.

Variables

This section is empty.

Functions

func LanguageName

func LanguageName(code string) string

LanguageName gives a language's name, falling back to its code.

Types

type LangScore

type LangScore struct {
	Lang        string
	Score       float64
	Probability float64
}

LangScore is how well the data's byte frequencies fit one language.

type Option

type Option struct {
	Recipe      core.Recipe
	Data        string
	LangScores  []LangScore
	FileType    *filesig.Sig
	IsUTF8      bool
	Entropy     float64
	MatchingOps []magicCheck
	Useful      bool
	MatchesCrib bool
}

Option is one candidate recipe and what its result looks like.

type Runner

type Runner struct {
	Extensive bool
	Intensive bool
	Crib      *regexp.Regexp
	Registry  *core.Registry
}

Runner carries the settings for one invocation, so the recursion does not have to pass them all down.

func (*Runner) Speculate

func (m *Runner) Speculate(data []byte, depth int, recipe core.Recipe, useful bool) []Option

Speculate is the recursion: record what this data looks like, then run each operation that claims to decode it and look at the result the same way.

Jump to

Keyboard shortcuts

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