Documentation
¶
Overview ¶
Copyright (c) 2025 Stefano Scafiti
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2025 Stefano Scafiti ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2025 Stefano Scafiti ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright 2025 Stefano Scafiti. All rights reserved.
This file implements a GIF decoder derived from the one in the Go standard library. It has been modified and extended specifically for file carving.
Modifications are licensed under the MIT License; see the LICENSE file for details.
Copyright (c) 2025 Stefano Scafiti ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2025 Stefano Scafiti ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2025 Stefano Scafiti ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2025 Stefano Scafiti ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright 2025 Stefano Scafiti. All rights reserved.
This file implements a PNG decoder derived from the one in the Go standard library. It has been modified and extended specifically for file carving.
Modifications are licensed under the MIT License; see the LICENSE file for details.
Copyright (c) 2025 Stefano Scafiti ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2025 Stefano Scafiti ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2025 Stefano Scafiti ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2025 Stefano Scafiti ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2025 Stefano Scafiti ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2025 Stefano Scafiti ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2025 Stefano Scafiti ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2025 Stefano Scafiti ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2025 Stefano Scafiti ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Index ¶
- Constants
- Variables
- func SeekAt(r *Reader, sig []byte, n int) (bool, error)
- type BMPHeader
- type DIBHeader
- type FileHeader
- type FileInfo
- type FileRegistry
- type FileScanner
- type PCXHeader
- type Reader
- func (r *Reader) BufferSize() int
- func (r *Reader) BytesRead() uint64
- func (r *Reader) Discard(n int) (int, error)
- func (r *Reader) Peek(n int) ([]byte, error)
- func (r *Reader) Read(buf []byte) (int, error)
- func (r *Reader) ReadByte() (byte, error)
- func (r *Reader) Seek(offset int64, whence int) (int64, error)
- func (r *Reader) Unread(n int) error
- func (r *Reader) UnreadByte() error
- type ScanResult
- func ScanBMP(r *Reader) (*ScanResult, error)
- func ScanGIF(r *Reader) (*ScanResult, error)
- func ScanJPEG(r *Reader) (*ScanResult, error)
- func ScanMP3(r *Reader) (*ScanResult, error)
- func ScanPCX(r *Reader) (*ScanResult, error)
- func ScanPDF(r *Reader) (*ScanResult, error)
- func ScanPNG(r *Reader) (*ScanResult, error)
- func ScanRAR(r *Reader) (*ScanResult, error)
- func ScanSQLite(r *Reader) (*ScanResult, error)
- func ScanSunAudio(r *Reader) (*ScanResult, error)
- func ScanTIFF(r *Reader) (*ScanResult, error)
- func ScanWAV(r *Reader) (*ScanResult, error)
- func ScanWMA(r *Reader) (*ScanResult, error)
- func ScanZIP(r *Reader) (*ScanResult, error)
- type Scanner
- type ZipFileEntry
Constants ¶
const ( // AU_MAGIC is the magic number for .au files: ".snd" in big-endian. AU_MAGIC uint32 = 0x2e736e64 // MIN_AU_HEADER_SIZE is the minimum size of a valid AU header (6 * 4 bytes). MIN_AU_HEADER_SIZE = 24 // AU_DATA_SIZE_UNKNOWN is the value used in the data_size field to indicate // that the data extends to the end of the file. AU_DATA_SIZE_UNKNOWN uint32 = 0xFFFFFFFF )
const ( BI_RGB = 0 // No compression BI_RLE8 = 1 // RLE 8-bit/pixel BI_RLE4 = 2 // RLE 4-bit/pixel BI_BITFIELDS = 3 // RGB bit field masks (for 16bpp and 32bpp) BI_JPEG = 4 // JPEG compression (Windows 95/NT and later) BI_PNG = 5 // PNG compression (Windows 95/NT and later) BI_ALPHABITFIELDS = 6 // Alpha bit field masks (often overlaps with BI_BITFIELDS in usage) BI_CMYK = 11 // CMYK uncompressed BI_CMYKRLE8 = 12 // CMYK RLE 8-bit/pixel BI_CMYKRLE4 = 13 // CMYK RLE 4-bit/pixel )
BMP Compression Types
const ( // Maximum file size of a zip entry. MaxZipFileSize = math.MaxUint32 // ZipSignature4 represents the standard 4-byte signature for a local file header in a ZIP file. ZipSignature4 uint32 = 0x04034B50 // ['P', 'K', 0x03, 0x04] // ZipSignature8 represents the 8-byte signature for a WinZIPv8-compressed file, // which includes a repeating 'PK' signature. ZipSignature8 uint64 = 0x30304B5004034B50 // ['P', 'K', '0', '0', 'P', 'K', 0x03, 0x04] - WinZIPv8-compressed files // ZIP header signatures // ZipCentralDirHeader is the signature for a central directory file header. ZipCentralDirHeader uint32 = 0x02014B50 // ZipFileEntryHeader is the signature for a local file header. ZipFileEntryHeader uint32 = 0x04034B50 // ZipEndCentralDirHeader is the signature for the end of central directory record. ZipEndCentralDirHeader uint32 = 0x06054B50 // ZipCentralDir64Header is the signature for the ZIP64 central directory record. ZipCentralDir64Header uint32 = 0x06064B50 // ZipEndCentralDir64Header is the signature for the ZIP64 end of central directory locator. ZipEndCentralDir64Header uint32 = 0x07064B50 // ZipDataDescriptorHeader is the signature for a data descriptor, used when the CRC-32 // and sizes are not known at the time the local file header is written. ZipDataDescriptorHeader uint32 = 0x08074B50 // ZipFileEntrySize defines the fixed size of the ZipFileEntry struct in bytes. ZipFileEntrySize = int(unsafe.Sizeof(ZipFileEntry{})) )
const RarMHDPasswordFlag = 0x0080
const SQLiteSignature = "SQLite format 3\x00"
Variables ¶
var ( Rar15Signature = []byte{0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00} Rar50Signature = []byte{0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x01, 0x00} )
var ErrChunkOrderError = fmt.Errorf("invalid PNG chunk order")
var ErrInvalidZip = errors.New("invalid zip file")
Functions ¶
func SeekAt ¶
SeekAt efficiently searches for a byte signature (`sig`) within the Reader's stream, up to a maximum of `n` bytes from the current reader position. It uses a circular buffer to handle cases where the signature might span across internal read buffer boundaries. The function attempts to position the reader right at the beginning of the found signature.
Parameters:
r: The custom Reader interface to read from. sig: The byte slice representing the signature to search for. n: The maximum number of bytes to search from the current reader position.
Returns:
bool: True if the signature is found, false otherwise. error: An error if an I/O error occurs during reading, other than io.EOF.
Types ¶
type BMPHeader ¶
type BMPHeader struct {
Signature [2]byte // BM
FileSize uint32 // Size of the BMP file in bytes
Reserved1 uint16 // Must be 0
Reserved2 uint16 // Must be 0
DataOffset uint32 // Offset to the start of the bitmap data
}
BMPHeader represents the BITMAPFILEHEADER structure of a BMP file.
type DIBHeader ¶
type DIBHeader struct {
HeaderSize uint32 // Size of this header (should be 40 for BITMAPINFOHEADER)
Width int32 // Bitmap width in pixels
Height int32 // Bitmap height in pixels
Planes uint16 // Number of color planes (must be 1)
BitsPerPixel uint16 // Number of bits per pixel (e.g., 1, 4, 8, 16, 24, 32)
Compression uint32 // Compression method
ImageSize uint32 // Size of the raw bitmap data (can be 0 for BI_RGB)
XPixelsPerMeter int32
YPixelsPerMeter int32
ColorsUsed uint32 // Number of colors in the color palette
ColorsImportant uint32 // Number of important colors
}
DIBHeader (BITMAPINFOHEADER) is the most common DIB header. We'll use this for initial validation.
type FileHeader ¶
type FileRegistry ¶
type FileRegistry struct {
// contains filtered or unexported fields
}
func BuildFileRegistry ¶
func BuildFileRegistry(scanners ...FileScanner) *FileRegistry
func NewFileRegisty ¶
func NewFileRegisty() *FileRegistry
func (*FileRegistry) Add ¶
func (r *FileRegistry) Add(sc FileScanner)
func (*FileRegistry) Search ¶
func (r *FileRegistry) Search(data []byte, handleHeader func(sc FileScanner) bool)
Searches the registry for headers where the key matches a prefix of `data`. The search starts with `r.minKeyLen` and iteratively extends the key length as long as matching headers are found. Each found header is processed by `handleHeader`.
func (*FileRegistry) Signatures ¶
func (r *FileRegistry) Signatures() int
type FileScanner ¶
type FileScanner interface {
Ext() string
Description() string
Signatures() [][]byte
ScanFile(r *Reader) (*ScanResult, error)
}
func GetAllFileScanners ¶
func GetAllFileScanners() []FileScanner
func GetFileScanners ¶
func GetFileScanners(ext ...string) ([]FileScanner, error)
func LoadPlugins ¶
func LoadPlugins(pluginPaths ...string) ([]FileScanner, error)
type PCXHeader ¶
type PCXHeader struct {
Manufacturer byte // Manufacturer (0x0A for ZSoft .PCX)
Version byte // Version (0-5, e.g., 5 for PC Paintbrush Plus)
Encoding byte // Encoding (0 for uncompressed, 1 for RLE)
BitsPerPixel byte // Bits per pixel per plane (e.g., 1, 2, 4, 8)
XMin uint16 // Image dimensions (min/max X, Y)
YMin uint16
XMax uint16
YMax uint16
HRes uint16 // Horizontal resolution (DPI)
VRes uint16 // Vertical resolution (DPI)
ColorMap [48]byte // 16-color EGA palette (only if palette not separate)
Reserved byte // Must be 0
NumPlanes byte // Number of color planes (e.g., 1 for grayscale/indexed, 3 for RGB)
BytesPerLine uint16 // Bytes per scanline (uncompressed, for one plane)
PaletteType uint16 // Palette type (1 for color/grayscale, 2 for color only)
HScreenSize uint16 // Horizontal screen size (used for display, often 0)
VScreenSize uint16 // Vertical screen size (used for display, often 0)
Filler [54]byte // Filler (should be 0 for older versions, variable for newer)
}
PCXHeader represents the ZSoft PCX file header (128 bytes).
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
func (*Reader) BufferSize ¶
func (*Reader) UnreadByte ¶ added in v0.1.0
type ScanResult ¶
func ScanBMP ¶
func ScanBMP(r *Reader) (*ScanResult, error)
ScanBMP attempts to carve a BMP from the given Reader and returns its size. It performs more extensive checks to reduce false positives.
func ScanGIF ¶
func ScanGIF(r *Reader) (*ScanResult, error)
func ScanJPEG ¶
func ScanJPEG(r *Reader) (*ScanResult, error)
ScanJPEG attempts to validate a JPEG file from the beginning of the 'data' buffer and determine its total size. This function is adapted from the standard library's 'image/jpeg' package's internal scanning logic, specifically from the 'decode' function, but modified to exclusively focus on finding the End Of Image (EOI) marker to determine the file's boundaries for file carving purposes.
It deviates from 'image/jpeg.DecodeConfig' as that function is designed to read only enough of the header to extract configuration (like dimensions) and does not typically scan to the EOI marker. This 'ScanJPEG' implementation navigates JPEG segments, handles byte stuffing (0xFF00), extraneous data (0xFF fill bytes), and restart markers (RSTn) in a robust way, mimicking libjpeg's leniency, to reliably locate the file's end.
It returns the total size of the JPEG file (the offset of the EOI marker plus its 2-byte length) or the buffer's length if the file appears truncated. It returns an error if the file is malformed or doesn't start with an SOI marker.
func ScanMP3 ¶
func ScanMP3(r *Reader) (*ScanResult, error)
ScanMP3 scans the input byte slice, strictly from the beginning, for a contiguous MP3 stream. It returns the end offset (exclusive) of the detected stream within the buffer, or 0 and an error if no valid stream is found. An optional ID3v2 tag at the very beginning is allowed and skipped.
func ScanPCX ¶
func ScanPCX(r *Reader) (*ScanResult, error)
ScanPCX attempts to carve a PCX file from the given io.Reader and returns its size. It handles both uncompressed and RLE compressed PCX files.
func ScanPDF ¶
func ScanPDF(r *Reader) (*ScanResult, error)
ScanPDF reads a byte stream from an io.Reader, identifies a potential PDF file, and returns its carved size.
It searches for the first occurrence of the standard PDF header (%PDF-X.Y) and the last occurrence of the end-of-file marker (%%EOF). The carved size is determined by the position of the last %%EOF marker plus its length.
func ScanPNG ¶
func ScanPNG(r *Reader) (*ScanResult, error)
func ScanRAR ¶ added in v0.1.0
func ScanRAR(r *Reader) (*ScanResult, error)
func ScanSQLite ¶ added in v0.1.0
func ScanSQLite(r *Reader) (*ScanResult, error)
ScanSqlite tries to carve a single SQLite DB starting at offset 0 in the reader.
func ScanSunAudio ¶
func ScanSunAudio(r *Reader) (*ScanResult, error)
ScanSunAudio scans the input io.Reader strictly from the beginning for a valid AU file. It returns the total size of the detected AU data, or 0 and an error if no valid AU file is found at the beginning. The reader's position will be at the end of the AU data upon successful return.
func ScanTIFF ¶
func ScanTIFF(r *Reader) (*ScanResult, error)
func ScanWAV ¶
func ScanWAV(r *Reader) (*ScanResult, error)
ScanWAV scans the input io.Reader strictly from the beginning for a valid WAV file. It returns the total size of the detected WAV data, or 0 and an error if no valid WAV file is found at the beginning. The reader's position will be at the end of the WAV data upon successful return.
func ScanWMA ¶
func ScanWMA(r *Reader) (*ScanResult, error)
ScanWMA attempts to validate a WMA file in ASF format and return its total size. It strictly expects a valid ASF Header Object at the beginning of the buffer, then parses its internal objects to find the definitive file size from the ASF File Properties Object.
func ScanZIP ¶
func ScanZIP(r *Reader) (*ScanResult, error)
ScanZIP scans a byte slice for ZIP file content and estimates the total ZIP size. It reads the initial bytes to identify the ZIP signature (standard or WinZIPv8) and then iteratively parses file entries and central directory records to determine the total size of the ZIP archive.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
func NewScanner ¶
func (*Scanner) FoundSignatures ¶ added in v0.1.0
type ZipFileEntry ¶
type ZipFileEntry struct {
Version uint16 // Version made by (and minimum version needed to extract)
Flags uint16 // General purpose bit flag
Compression uint16 // Compression method
LastModTime uint16 // File last modification time
LastModDate uint16 // File last modification date
CRC32 uint32 // CRC-32 of uncompressed data
CompressedSize uint32 // Compressed size
UncompressedSize uint32 // Uncompressed size
FilenameLength uint16 // Length of filename
ExtraLength uint16 // Length of extra field
}
ZipFileEntry represents the structure of a local file header in a ZIP file. This struct is used for reading and parsing the fixed-size portion of a file entry.