find

package
v0.0.0-...-473980d Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cli.Cmd[findArgs]{
	Name:        "find",
	Usage:       "find [IMAGE PATH]",
	Description: "find data hidden inside an image",
	Examples: []cli.Example{
		{
			Description: "find hidden data from inside 'img.png'",
			Args:        []string{"img.png"},
			Output:      "Here's the hidden data",
		},
		{
			Description: "searching for hidden data in 'img.png' fails",
			Args:        []string{"img.png"},
			Error:       errors.New("magic number does not match"),
		},
	},
	ParseArgs: func(args []string) (findArgs, error) {
		if len(args) != 1 {
			return findArgs{}, errors.New("invalid argument count")
		}

		if !strings.HasSuffix(args[0], ".png") {
			return findArgs{}, errors.New("only png images are supported")
		}

		return findArgs{
			imagePath: args[0],
		}, nil
	},
	Fn: func(args findArgs) error {
		f, err := os.Open(args.imagePath)
		if err != nil {
			return fmt.Errorf("failed to read in an image file: %w", err)
		}
		defer f.Close()

		inImage, err := png.Decode(f)
		if err != nil {
			return fmt.Errorf("failed to decode png file: %w", err)
		}

		img, ok := inImage.(*image.NRGBA)
		if !ok {
			return fmt.Errorf("invalid image format: %T", img)
		}

		got, err := findData(img)
		if err != nil {
			return fmt.Errorf("failed to get hidden data: %w", err)
		}

		fmt.Print(string(got))
		return nil
	},
}

Cmd is the find command that searches the given image for data hidden using the hide command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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