Skip to content

Commit

Permalink
[Project] Lua_magic: Moar patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Sep 6, 2019
1 parent c9af91f commit 0d5d24b
Show file tree
Hide file tree
Showing 2 changed files with 202 additions and 7 deletions.
151 changes: 149 additions & 2 deletions lualib/lua_magic/patterns.lua
Expand Up @@ -98,6 +98,36 @@ local patterns = {
}
}
},
elf = {
matches = {
{
hex = [[7f454c46]],
relative_position = 0,
weight = 60,
},
}
},
lnk = {
matches = {
{
hex = [[4C0000000114020000000000C000000000000046]],
relative_position = 0,
weight = 60,
},
}
},
class = {
-- Technically, this also matches MachO files, but I don't care about
-- Apple and their mental health problems here: just consider Java files,
-- Mach object files and all other cafe babes as bad and block them!
matches = {
{
hex = [[cafebabe]],
relative_position = 0,
weight = 60,
},
}
},
-- Archives
arj = {
matches = {
Expand All @@ -120,7 +150,82 @@ local patterns = {
cab = {
matches = {
{
string = [[MSCF]],
hex = [[4d53434600000000]], -- Can be anywhere for SFX :(
position = {'>=', 8},
weight = 60,
},
}
},
tar = {
matches = {
{
string = [[ustar]],
relative_position = 257,
weight = 60,
},
}
},
bz2 = {
matches = {
{
string = "BZ[h0]",
position = 3,
weight = 60,
},
}
},
lz4 = {
matches = {
{
hex = "184d2204",
relative_position = 0,
weight = 60,
},
{
hex = "184c2103",
relative_position = 0,
weight = 60,
},
{
hex = "184c2102",
relative_position = 0,
weight = 60,
},
}
},
zst = {
matches = {
{
string = [[\x{FD}\x{2F}\x{B5}[\x{22}-\x{40}].]],
position = 5, -- includes last .
weight = 60,
},
}
},
-- Apple is a 'special' child: this needs to be matched at the data tail...
dmg = {
matches = {
{
string = [[koly]],
position = -512 + 4,
weight = 61,
tail = 512,
},
}
},
szdd = {
matches = {
{
hex = [[535a4444]],
relative_position = 0,
weight = 60,
},
}
},
xz = {
matches = {
{
hex = [[FD377A585A00]],
relative_position = 0,
weight = 60,
},
Expand Down Expand Up @@ -163,6 +268,39 @@ local patterns = {
},
}
},
swf = {
matches = {
{
hex = [[5a5753]], -- LZMA
relative_position = 0,
weight = 60,
},
{
hex = [[435753]], -- Zlib
relative_position = 0,
weight = 60,
},
{
hex = [[465753]], -- Uncompressed
relative_position = 0,
weight = 60,
},
}
},
tiff = {
matches = {
{
hex = [[49492a00]], -- LE encoded
relative_position = 0,
weight = 60,
},
{
hex = [[4d4d]], -- BE tiff
relative_position = 0,
weight = 60,
},
}
},
-- Other
pgp = {
matches = {
Expand All @@ -177,7 +315,16 @@ local patterns = {
weight = 60,
},
}
}
},
uue = {
matches = {
{
hex = [[626567696e20]],
relative_position = 0,
weight = 60,
},
}
},
}
return patterns
58 changes: 53 additions & 5 deletions lualib/lua_magic/types.lua
Expand Up @@ -27,6 +27,18 @@ local types = {
ct = 'application/x-ms-application',
type = 'executable',
},
elf = {
ct = 'application/x-elf-executable',
type = 'executable',
},
lnk = {
ct = 'application/x-ms-application',
type = 'executable',
},
class = {
ct = 'application/x-java-applet',
type = 'executable',
},
-- text
rtf = {
ct = "application/rtf",
Expand All @@ -41,23 +53,51 @@ local types = {
type = 'binary',
},
chm = {
ct = 'application/chm',
ct = 'application/x-chm',
type = 'binary',
},
djvu = {
ct = 'application/djvu',
ct = 'application/x-djvu',
type = 'binary',
},
-- archives
arj = {
ct = 'application/x-compressed',
ct = 'application/x-arj',
type = 'archive',
},
cab = {
ct = 'application/x-compressed',
ct = 'application/x-cab',
type = 'archive',
},
ace = {
ct = 'application/x-ace',
type = 'archive',
},
tar = {
ct = 'application/x-tar',
type = 'archive',
},
bz2 = {
ct = 'application/x-bzip',
type = 'archive',
},
xz = {
ct = 'application/x-xz',
type = 'archive',
},
lz4 = {
ct = 'application/x-lz4',
type = 'archive',
},
zst = {
ct = 'application/x-zstandard',
type = 'archive',
},
dmg = {
ct = 'application/x-dmg',
type = 'archive',
},
szdd = { -- in fact, their MSDOS extension is like FOO.TX_ or FOO.TX$
ct = 'application/x-compressed',
type = 'archive',
},
Expand All @@ -82,11 +122,19 @@ local types = {
ct = 'image/ico',
type = 'image',
},
swf = {
ct = 'application/x-shockwave-flash',
type = 'image',
},
-- other
pgp = {
ct = 'application/encrypted',
type = 'encrypted'
}
},
uue = {
ct = 'application/x-uuencoded',
type = 'binary',
},
}
return types

0 comments on commit 0d5d24b

Please sign in to comment.