Documentation ¶
Index ¶
- type MagicNumbers
- func (m *MagicNumbers) AddMagicNumber(ext, mime string, isText bool, signaturesList ...MagicNumbersSignature) (err error)
- func (m *MagicNumbers) CheckBytes(data []byte, basename ...string) (outInf *[]outInfos, err error)
- func (m *MagicNumbers) CheckFile(filename string) (out *[]outInfos, err error)
- func (m *MagicNumbers) ImportFromFile(filename string) (err error)
- func (m *MagicNumbers) Read(filename string) (err error)
- func (m *MagicNumbers) ReadFromBytes(textFileBytes []byte) (err error)
- func (m *MagicNumbers) Rebuild() (err error)
- func (m *MagicNumbers) Write(filename string) (err error)
- type MagicNumbersSignature
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MagicNumbers ¶
type MagicNumbers struct { // Will be a saved file (read/write). List []signatures // whether there is no signature that match, output display "Displen" // byte from the start of the input data. DispLen int // contains filtered or unexported fields }
MagicNumbers:
func (*MagicNumbers) AddMagicNumber ¶
func (m *MagicNumbers) AddMagicNumber(ext, mime string, isText bool, signaturesList ...MagicNumbersSignature) (err error)
TODO Thing to add multi-patterns matching in a specific range ... AddMagicNumber: Use MagicNumbersNewSig() to create a new signature before adding. i.e: notice, error not hendled here ... Rebuild() must be used to finalize operation !
1- Add 2 signatures for .woff type "application/font-woff", not a txt file mns := MagicNumbersSignatureNew(0, "774F464600010000") mns1 := MagicNumbersSignatureNew(0, "774F46464F54544F") signs.AddMagicNumber("woff", "application/font-woff", false, mns, mns1) 2- Add 1 signature start at offset 22 for .eot type "application/vnd.ms-fontobject", not a txt file mns = MagicNumbersSignatureNew(22, "4C500000000000000000000000000000000001") signs.AddMagicNumber("eot", "application/vnd.ms-fontobject", false, mns) 3- Add only extension .js and his mime type "application/javascript", is a txt file signs.AddMagicNumber("js", "application/javascript", true) 4- Add 1 signature start at offset 0, to offset 512 (pattern if searched in this range), Another search is done from the end of the file with a range of 7 to match "3C2F7376673E" (</svg>). This signature is for the .svg type "image/svg+xml", is a txt file. mns = MagicNumbersSignatureNew(0, "3C73766720786D6C6E73", "3C2F7376673E") mns.Range=512 // Range to search from start offset mns.RangeEnd=7 // Range from end, by default that contain length +1 of "ValueEnd" signs.AddMagicNumber("svg", "image/svg+xml", true, mns) signs.Rebuild()
func (*MagicNumbers) CheckBytes ¶
func (m *MagicNumbers) CheckBytes(data []byte, basename ...string) (outInf *[]outInfos, err error)
CheckBytes:
func (*MagicNumbers) CheckFile ¶
func (m *MagicNumbers) CheckFile(filename string) (out *[]outInfos, err error)
CheckFile: TODO find a way to seek only needed bytes to be analysed
func (*MagicNumbers) ImportFromFile ¶
func (m *MagicNumbers) ImportFromFile(filename string) (err error)
ImportFromFile: Import base data containing signatures information.
func (*MagicNumbers) Read ¶
func (m *MagicNumbers) Read(filename string) (err error)
Read: main structure containing whole signatures
func (*MagicNumbers) ReadFromBytes ¶
func (m *MagicNumbers) ReadFromBytes(textFileBytes []byte) (err error)
ReadFromBytes:
func (*MagicNumbers) Rebuild ¶
func (m *MagicNumbers) Rebuild() (err error)
Rebuild: using new added signature and the original json signatures files.
func (*MagicNumbers) Write ¶
func (m *MagicNumbers) Write(filename string) (err error)
Write: main structure containing whole signatures
type MagicNumbersSignature ¶
type MagicNumbersSignature struct { Offset, Range, RangeEnd int Value, ValueEnd string Bytes, BytesEnd []byte }
MagicNumbersSignature:
func MagicNumbersSignatureNew ¶
func MagicNumbersSignatureNew(offset int, valueStart string, valueEnd ...string) MagicNumbersSignature
MagicNumbersSignatureNew: