/** * File Signatures Database for Content-Based File Type Detection * * This module provides a comprehensive database of file signatures (magic numbers) * for detecting file types based on their binary content rather than just extensions. * * @module file-signatures */ /** * Represents a file signature entry with all metadata needed for detection */ export interface FileSignature { /** Unique identifier for the file type (e.g., 'PDF', 'JPEG') */ type: string; /** MIME type associated with this file format */ mimeType: string; /** Array of possible magic number signatures (Buffer objects) */ signatures: Buffer[]; /** Common file extensions (with dot) */ extensions: string[]; /** Category for grouping and security classification */ category: "Document" | "Image" | "Executable" | "Archive" | "Audio" | "Video" | "Code" | "Other"; /** Human-readable description of the file format */ description: string; /** Optional: offset where signature starts (default: 0) */ offset?: number; /** Optional: additional validation function for complex formats */ validator?: (buffer: Buffer) => boolean; } /** * Comprehensive database of file signatures for content-based type detection */ export declare const FILE_SIGNATURES: FileSignature[]; /** * Security-critical file types that should trigger warnings * These represent potentially executable content */ export declare const EXECUTABLE_SIGNATURES: string[]; /** * Map of file extensions to their expected signature types * Used for detecting extension/signature mismatches */ export declare const EXTENSION_TO_SIGNATURE: Record; /** * Get a file signature definition by its type identifier * @param type - The file type identifier (e.g., 'PDF', 'JPEG') * @returns The FileSignature definition or undefined if not found */ export declare function getSignatureByType(type: string): FileSignature | undefined; /** * Get all file signatures associated with a file extension * @param ext - The file extension (with or without leading dot) * @returns Array of matching FileSignature definitions */ export declare function getSignaturesByExtension(ext: string): FileSignature[]; /** * Check if a file type is considered security-critical (executable) * @param type - The file type identifier * @returns True if the type represents executable content */ export declare function isExecutableSignature(type: string): boolean; /** * Match a buffer against known file signatures * @param buffer - The buffer to analyze (first few bytes of a file) * @param options - Optional configuration for matching * @returns The matched FileSignature or null if no match */ export declare function matchSignature(buffer: Buffer, options?: { /** Maximum bytes to read from buffer (default: 8192) */ maxReadBytes?: number; /** Whether to run validators for complex formats (default: true) */ runValidators?: boolean; }): FileSignature | null; /** * Detect potential file type mismatches between extension and content * @param filePath - Path to the file * @param buffer - Buffer containing file content * @returns Object with mismatch information or null if no mismatch */ export declare function detectExtensionMismatch(filePath: string, buffer: Buffer): { detectedType: string; expectedTypes: string[]; } | null; /** * Get all signatures for a specific category * @param category - The category to filter by * @returns Array of FileSignature definitions in that category */ export declare function getSignaturesByCategory(category: FileSignature["category"]): FileSignature[]; /** * Check if a buffer contains executable content * Convenience function for security checks * @param buffer - The buffer to analyze * @returns True if the buffer matches an executable signature */ export declare function isExecutableContent(buffer: Buffer): boolean; //# sourceMappingURL=file-signatures.d.ts.map