2021-10-18 12:51:36 +03:00
|
|
|
package format
|
|
|
|
|
2022-06-01 17:55:55 +03:00
|
|
|
// TODO: do before-format somehow and topology sort?
|
|
|
|
const (
|
|
|
|
ProbeOrderBinUnique = 0 // binary with unlikely overlap
|
2022-08-15 13:12:37 +03:00
|
|
|
ProbeOrderBinFuzzy = 100 // binary with possible overlap
|
|
|
|
ProbeOrderTextJSON = 200 // text json has prio as yaml overlap
|
|
|
|
ProbeOrderTextFuzzy = 300 // text with possible overlap
|
2022-06-01 17:55:55 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// TODO: change to CamelCase?
|
2022-08-05 01:20:14 +03:00
|
|
|
//
|
2021-10-18 12:51:36 +03:00
|
|
|
//nolint:revive
|
|
|
|
const (
|
|
|
|
ALL = "all"
|
|
|
|
|
2021-11-24 23:20:46 +03:00
|
|
|
IMAGE = "image"
|
2022-01-12 20:35:28 +03:00
|
|
|
PROBE = "probe"
|
2022-04-01 17:31:55 +03:00
|
|
|
LINK_FRAME = "link_frame" // ex: ethernet
|
|
|
|
INET_PACKET = "inet_packet" // ex: ipv4
|
|
|
|
IP_PACKET = "ip_packet" // ex: tcp
|
|
|
|
TCP_STREAM = "tcp_stream" // ex: http
|
|
|
|
UDP_PAYLOAD = "udp_payload" // ex: dns
|
2021-11-24 23:20:46 +03:00
|
|
|
|
2022-11-20 21:22:16 +03:00
|
|
|
BYTES = "bytes"
|
|
|
|
BITS = "bits"
|
|
|
|
|
2021-10-18 12:51:36 +03:00
|
|
|
AAC_FRAME = "aac_frame"
|
|
|
|
ADTS = "adts"
|
|
|
|
ADTS_FRAME = "adts_frame"
|
2022-03-29 23:41:11 +03:00
|
|
|
AMF0 = "amf0"
|
2021-10-18 12:51:36 +03:00
|
|
|
APEV2 = "apev2"
|
2022-01-12 20:35:28 +03:00
|
|
|
AR = "ar"
|
2022-01-13 20:34:59 +03:00
|
|
|
ASN1_BER = "asn1_ber"
|
2021-10-18 12:51:36 +03:00
|
|
|
AV1_CCR = "av1_ccr"
|
|
|
|
AV1_FRAME = "av1_frame"
|
|
|
|
AV1_OBU = "av1_obu"
|
2022-01-12 20:35:28 +03:00
|
|
|
AVC_ANNEXB = "avc_annexb"
|
|
|
|
AVC_AU = "avc_au"
|
|
|
|
AVC_DCR = "avc_dcr"
|
|
|
|
AVC_NALU = "avc_nalu"
|
|
|
|
AVC_PPS = "avc_pps"
|
|
|
|
AVC_SEI = "avc_sei"
|
|
|
|
AVC_SPS = "avc_sps"
|
2022-10-29 20:23:50 +03:00
|
|
|
AVI = "avi"
|
2021-12-28 22:05:10 +03:00
|
|
|
AVRO_OCF = "avro_ocf"
|
2022-01-09 18:27:40 +03:00
|
|
|
BENCODE = "bencode"
|
2022-04-17 11:33:01 +03:00
|
|
|
BITCOIN_BLKDAT = "bitcoin_blkdat"
|
|
|
|
BITCOIN_BLOCK = "bitcoin_block"
|
|
|
|
BITCOIN_SCRIPT = "bitcoin_script"
|
|
|
|
BITCOIN_TRANSACTION = "bitcoin_transaction"
|
2022-09-15 06:37:39 +03:00
|
|
|
BPLIST = "bplist"
|
2022-01-12 20:35:28 +03:00
|
|
|
BSD_LOOPBACK_FRAME = "bsd_loopback_frame"
|
|
|
|
BSON = "bson"
|
2021-10-18 12:51:36 +03:00
|
|
|
BZIP2 = "bzip2"
|
2022-01-12 20:35:28 +03:00
|
|
|
CBOR = "cbor"
|
2022-06-01 17:55:55 +03:00
|
|
|
CSV = "csv"
|
2022-01-12 20:35:28 +03:00
|
|
|
DNS = "dns"
|
|
|
|
DNS_TCP = "dns_tcp"
|
2021-10-18 12:51:36 +03:00
|
|
|
ELF = "elf"
|
2022-01-12 20:35:28 +03:00
|
|
|
ETHER8023_FRAME = "ether8023_frame"
|
2021-10-18 12:51:36 +03:00
|
|
|
EXIF = "exif"
|
2022-07-07 18:00:25 +03:00
|
|
|
FAIRPLAY_SPC = "fairplay_spc"
|
2021-10-18 12:51:36 +03:00
|
|
|
FLAC = "flac"
|
|
|
|
FLAC_FRAME = "flac_frame"
|
2021-10-28 02:44:09 +03:00
|
|
|
FLAC_METADATABLOCK = "flac_metadatablock"
|
2021-10-18 12:51:36 +03:00
|
|
|
FLAC_METADATABLOCKS = "flac_metadatablocks"
|
|
|
|
FLAC_PICTURE = "flac_picture"
|
2022-01-12 20:35:28 +03:00
|
|
|
FLAC_STREAMINFO = "flac_streaminfo"
|
2021-10-18 12:51:36 +03:00
|
|
|
FLV = "flv" // TODO:
|
|
|
|
GIF = "gif"
|
|
|
|
GZIP = "gzip"
|
2022-01-12 20:35:28 +03:00
|
|
|
HEVC_ANNEXB = "hevc_annexb"
|
|
|
|
HEVC_AU = "hevc_au"
|
|
|
|
HEVC_DCR = "hevc_dcr"
|
|
|
|
HEVC_NALU = "hevc_nalu"
|
2022-03-21 19:21:58 +03:00
|
|
|
HEVC_PPS = "hevc_pps"
|
|
|
|
HEVC_SPS = "hevc_sps"
|
|
|
|
HEVC_VPS = "hevc_vps"
|
2022-06-01 17:55:55 +03:00
|
|
|
HTML = "html"
|
2021-10-18 12:51:36 +03:00
|
|
|
ICC_PROFILE = "icc_profile"
|
2022-01-12 20:35:28 +03:00
|
|
|
ICMP = "icmp"
|
2022-04-01 17:31:55 +03:00
|
|
|
ICMPV6 = "icmpv6"
|
2021-10-18 12:51:36 +03:00
|
|
|
ID3V1 = "id3v1"
|
|
|
|
ID3V11 = "id3v11"
|
|
|
|
ID3V2 = "id3v2"
|
2022-01-12 20:35:28 +03:00
|
|
|
IPV4_PACKET = "ipv4_packet"
|
2022-04-01 17:31:55 +03:00
|
|
|
IPV6_PACKET = "ipv6_packet"
|
2021-10-18 12:51:36 +03:00
|
|
|
JPEG = "jpeg"
|
2022-01-12 20:35:28 +03:00
|
|
|
JSON = "json"
|
2022-08-15 13:57:02 +03:00
|
|
|
JSONL = "jsonl"
|
2022-01-04 01:12:15 +03:00
|
|
|
MACHO = "macho"
|
2022-08-01 19:42:24 +03:00
|
|
|
MACHO_FAT = "macho_fat"
|
2022-09-10 19:09:36 +03:00
|
|
|
MARKDOWN = "markdown"
|
2021-10-18 12:51:36 +03:00
|
|
|
MATROSKA = "matroska"
|
|
|
|
MP3 = "mp3"
|
|
|
|
MP3_FRAME = "mp3_frame"
|
2022-11-16 15:04:16 +03:00
|
|
|
MP3_FRAME_TAGS = "mp3_frame_tags"
|
2021-10-18 12:51:36 +03:00
|
|
|
MP4 = "mp4"
|
|
|
|
MPEG_ASC = "mpeg_asc"
|
|
|
|
MPEG_ES = "mpeg_es"
|
|
|
|
MPEG_PES = "mpeg_pes"
|
|
|
|
MPEG_PES_PACKET = "mpeg_pes_packet"
|
|
|
|
MPEG_SPU = "mpeg_spu"
|
|
|
|
MPEG_TS = "mpeg_ts"
|
2022-01-10 14:18:10 +03:00
|
|
|
MSGPACK = "msgpack"
|
2021-10-18 12:51:36 +03:00
|
|
|
OGG = "ogg"
|
|
|
|
OGG_PAGE = "ogg_page"
|
|
|
|
OPUS_PACKET = "opus_packet"
|
2021-11-23 00:08:36 +03:00
|
|
|
PCAP = "pcap"
|
|
|
|
PCAPNG = "pcapng"
|
2022-09-19 15:45:54 +03:00
|
|
|
PG_BTREE = "pg_btree"
|
2022-07-19 08:58:31 +03:00
|
|
|
PG_CONTROL = "pg_control"
|
2022-09-02 16:14:24 +03:00
|
|
|
PG_HEAP = "pg_heap"
|
2021-10-18 12:51:36 +03:00
|
|
|
PNG = "png"
|
2022-08-24 20:08:41 +03:00
|
|
|
PRORES_FRAME = "prores_frame"
|
2021-10-18 12:51:36 +03:00
|
|
|
PROTOBUF = "protobuf"
|
|
|
|
PROTOBUF_WIDEVINE = "protobuf_widevine"
|
|
|
|
PSSH_PLAYREADY = "pssh_playready"
|
2022-03-29 23:41:11 +03:00
|
|
|
RTMP = "rtmp"
|
2022-01-12 20:35:28 +03:00
|
|
|
SLL_PACKET = "sll_packet"
|
|
|
|
SLL2_PACKET = "sll2_packet"
|
2021-10-18 12:51:36 +03:00
|
|
|
TAR = "tar"
|
2022-01-12 20:35:28 +03:00
|
|
|
TCP_SEGMENT = "tcp_segment"
|
2021-10-18 12:51:36 +03:00
|
|
|
TIFF = "tiff"
|
2022-06-01 17:55:55 +03:00
|
|
|
TOML = "toml"
|
2022-01-12 20:35:28 +03:00
|
|
|
UDP_DATAGRAM = "udp_datagram"
|
2021-10-18 12:51:36 +03:00
|
|
|
VORBIS_COMMENT = "vorbis_comment"
|
|
|
|
VORBIS_PACKET = "vorbis_packet"
|
|
|
|
VP8_FRAME = "vp8_frame"
|
|
|
|
VP9_CFM = "vp9_cfm"
|
2022-01-12 20:35:28 +03:00
|
|
|
VP9_FRAME = "vp9_frame"
|
2021-10-18 12:51:36 +03:00
|
|
|
VPX_CCR = "vpx_ccr"
|
2022-08-18 15:40:30 +03:00
|
|
|
WASM = "wasm"
|
2021-10-18 12:51:36 +03:00
|
|
|
WAV = "wav"
|
|
|
|
WEBP = "webp"
|
2022-06-01 17:55:55 +03:00
|
|
|
XML = "xml"
|
|
|
|
YAML = "yaml"
|
2021-11-01 15:08:52 +03:00
|
|
|
ZIP = "zip"
|
2021-10-18 12:51:36 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// below are data types used to communicate between formats <FormatName>In/Out
|
|
|
|
|
2021-10-28 02:44:09 +03:00
|
|
|
type FlacStreamInfo struct {
|
|
|
|
SampleRate uint64
|
2021-12-09 19:15:21 +03:00
|
|
|
BitsPerSample uint64
|
2021-10-28 02:44:09 +03:00
|
|
|
TotalSamplesInStream uint64
|
2021-11-05 17:04:26 +03:00
|
|
|
MD5 []byte
|
2021-10-28 02:44:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type FlacStreaminfoOut struct {
|
|
|
|
StreamInfo FlacStreamInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
type FlacMetadatablockOut struct {
|
|
|
|
IsLastBlock bool
|
|
|
|
HasStreamInfo bool
|
|
|
|
StreamInfo FlacStreamInfo
|
2021-10-18 12:51:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type FlacMetadatablocksOut struct {
|
|
|
|
HasStreamInfo bool
|
2021-10-28 02:44:09 +03:00
|
|
|
StreamInfo FlacStreamInfo
|
2021-10-18 12:51:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type FlacFrameIn struct {
|
2021-12-09 19:15:21 +03:00
|
|
|
SamplesBuf []byte
|
|
|
|
BitsPerSample int `doc:"Bits per sample"`
|
2021-10-18 12:51:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type FlacFrameOut struct {
|
|
|
|
SamplesBuf []byte
|
|
|
|
Samples uint64
|
|
|
|
Channels int
|
|
|
|
BitsPerSample int
|
|
|
|
}
|
|
|
|
|
|
|
|
type OggPageOut struct {
|
|
|
|
IsLastPage bool
|
|
|
|
IsFirstPage bool
|
|
|
|
IsContinuedPacket bool
|
|
|
|
StreamSerialNumber uint32
|
|
|
|
SequenceNo uint32
|
2021-11-30 15:12:14 +03:00
|
|
|
Segments [][]byte
|
2021-10-18 12:51:36 +03:00
|
|
|
}
|
|
|
|
|
2021-12-09 19:15:21 +03:00
|
|
|
type AvcAuIn struct {
|
|
|
|
LengthSize uint64 `doc:"Length value size"`
|
2021-10-18 12:51:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type AvcDcrOut struct {
|
|
|
|
LengthSize uint64
|
|
|
|
}
|
|
|
|
|
2021-12-09 19:15:21 +03:00
|
|
|
type HevcAuIn struct {
|
|
|
|
LengthSize uint64 `doc:"Length value size"`
|
2021-10-18 12:51:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type HevcDcrOut struct {
|
|
|
|
LengthSize uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProtoBufIn struct {
|
|
|
|
Message ProtoBufMessage
|
|
|
|
}
|
|
|
|
|
2021-11-28 18:59:45 +03:00
|
|
|
type MpegDecoderConfig struct {
|
|
|
|
ObjectType int
|
|
|
|
ASCObjectType int
|
|
|
|
}
|
|
|
|
|
2021-10-18 12:51:36 +03:00
|
|
|
type MpegEsOut struct {
|
|
|
|
DecoderConfigs []MpegDecoderConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
type MPEGASCOut struct {
|
|
|
|
ObjectType int
|
|
|
|
}
|
|
|
|
|
|
|
|
type AACFrameIn struct {
|
2021-12-09 19:15:21 +03:00
|
|
|
ObjectType int `doc:"Audio object type"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Mp3In struct {
|
|
|
|
MaxUniqueHeaderConfigs int `doc:"Max number of unique frame header configs allowed"`
|
|
|
|
MaxSyncSeek int `doc:"Max byte distance to next sync"`
|
2021-10-18 12:51:36 +03:00
|
|
|
}
|
2021-11-19 13:55:45 +03:00
|
|
|
|
|
|
|
type MP3FrameOut struct {
|
|
|
|
MPEGVersion int
|
|
|
|
ProtectionAbsent bool
|
|
|
|
BitRate int
|
|
|
|
SampleRate int
|
|
|
|
ChannelsIndex int
|
|
|
|
ChannelModeIndex int
|
|
|
|
}
|
2021-11-24 23:20:46 +03:00
|
|
|
|
2022-04-01 17:31:55 +03:00
|
|
|
type LinkFrameIn struct {
|
|
|
|
Type int
|
|
|
|
IsLittleEndian bool // pcap endian etc
|
2022-01-03 22:17:01 +03:00
|
|
|
}
|
|
|
|
|
2022-04-01 17:31:55 +03:00
|
|
|
type InetPacketIn struct {
|
|
|
|
EtherType int
|
|
|
|
}
|
|
|
|
|
|
|
|
type IPPacketIn struct {
|
|
|
|
Protocol int
|
2022-01-03 22:17:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type UDPPayloadIn struct {
|
2021-11-24 23:20:46 +03:00
|
|
|
SourcePort int
|
|
|
|
DestinationPort int
|
|
|
|
}
|
|
|
|
|
2022-04-08 16:03:47 +03:00
|
|
|
func (u UDPPayloadIn) IsPort(ports ...int) bool {
|
|
|
|
for _, p := range ports {
|
|
|
|
if u.DestinationPort == p || u.SourcePort == p {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-05-20 16:10:41 +03:00
|
|
|
func (u UDPPayloadIn) MustIsPort(fn func(format string, a ...any), ports ...int) {
|
2022-04-08 16:03:47 +03:00
|
|
|
if !u.IsPort(ports...) {
|
|
|
|
fn("incorrect udp port %t src:%d dst:%d", u.DestinationPort, u.SourcePort)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-24 23:20:46 +03:00
|
|
|
type TCPStreamIn struct {
|
2022-03-29 23:41:11 +03:00
|
|
|
IsClient bool
|
2022-04-08 16:03:47 +03:00
|
|
|
HasStart bool
|
|
|
|
HasEnd bool
|
2022-05-06 17:45:59 +03:00
|
|
|
SkippedBytes uint64
|
2021-11-24 23:20:46 +03:00
|
|
|
SourcePort int
|
|
|
|
DestinationPort int
|
|
|
|
}
|
2021-12-06 21:33:17 +03:00
|
|
|
|
2022-04-08 16:03:47 +03:00
|
|
|
func (t TCPStreamIn) IsPort(ports ...int) bool {
|
|
|
|
for _, p := range ports {
|
|
|
|
if (t.IsClient && t.DestinationPort == p) ||
|
|
|
|
(!t.IsClient && t.SourcePort == p) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-05-20 16:10:41 +03:00
|
|
|
func (t TCPStreamIn) MustIsPort(fn func(format string, a ...any), ports ...int) {
|
2022-04-08 16:03:47 +03:00
|
|
|
if !t.IsPort(ports...) {
|
|
|
|
fn("incorrect tcp port client %t src:%d dst:%d", t.IsClient, t.DestinationPort, t.SourcePort)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-09 19:15:21 +03:00
|
|
|
type Mp4In struct {
|
|
|
|
DecodeSamples bool `doc:"Decode supported media samples"`
|
|
|
|
AllowTruncated bool `doc:"Allow box to be truncated"`
|
2021-12-06 21:33:17 +03:00
|
|
|
}
|
2022-05-26 13:39:14 +03:00
|
|
|
|
2022-10-29 20:23:50 +03:00
|
|
|
type AviIn struct {
|
|
|
|
DecodeSamples bool `doc:"Decode supported media samples"`
|
|
|
|
}
|
|
|
|
|
2022-05-26 13:39:14 +03:00
|
|
|
type ZipIn struct {
|
2022-05-26 20:27:17 +03:00
|
|
|
Uncompress bool `doc:"Uncompress and probe files"`
|
2022-05-26 13:39:14 +03:00
|
|
|
}
|
2022-07-20 08:43:24 +03:00
|
|
|
|
2022-06-01 17:55:55 +03:00
|
|
|
type XMLIn struct {
|
2022-08-25 17:06:25 +03:00
|
|
|
Seq bool `doc:"Use seq attribute to preserve element order"`
|
|
|
|
Array bool `doc:"Decode as nested arrays"`
|
|
|
|
AttributePrefix string `doc:"Prefix for attribute keys"`
|
2022-06-01 17:55:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type HTMLIn struct {
|
2022-08-25 17:06:25 +03:00
|
|
|
Seq bool `doc:"Use seq attribute to preserve element order"`
|
|
|
|
Array bool `doc:"Decode as nested arrays"`
|
|
|
|
AttributePrefix string `doc:"Prefix for attribute keys"`
|
2022-06-01 17:55:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type CSVLIn struct {
|
|
|
|
Comma string `doc:"Separator character"`
|
|
|
|
Comment string `doc:"Comment line character"`
|
|
|
|
}
|
2022-08-25 09:55:48 +03:00
|
|
|
|
2022-08-26 13:07:29 +03:00
|
|
|
type BitCoinBlockIn struct {
|
|
|
|
HasHeader bool `doc:"Has blkdat header"`
|
|
|
|
}
|
2022-08-31 12:17:14 +03:00
|
|
|
|
2022-07-20 08:43:24 +03:00
|
|
|
type PostgresIn struct {
|
2022-09-23 13:50:54 +03:00
|
|
|
Flavour string `doc:"PostgreSQL flavour: postgres14, pgproee14.., postgres10"`
|
|
|
|
}
|
|
|
|
|
2022-10-07 12:58:36 +03:00
|
|
|
type PostgresHeapIn struct {
|
2022-12-22 11:22:02 +03:00
|
|
|
Flavour string `doc:"PostgreSQL flavour: postgres14, pgproee14.., postgres10"`
|
|
|
|
Page int `doc:"First page number in file, default is 0"`
|
|
|
|
Segment int `doc:"Segment file number (16790.1 is 1), default is 0"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type PostgresBTreeIn struct {
|
|
|
|
Page int `doc:"First page number in file, default is 0"`
|
2022-10-07 12:58:36 +03:00
|
|
|
}
|