Browse Source

[Project] Lua_magic: Support ole documents recognition

tags/2.0
Vsevolod Stakhov 4 years ago
parent
commit
0f4f770639
4 changed files with 36 additions and 1 deletions
  1. 1
    1
      lualib/lua_magic/init.lua
  2. 13
    0
      lualib/lua_magic/patterns.lua
  3. 21
    0
      lualib/lua_magic/types.lua
  4. 1
    0
      src/lua/lua_text.c

+ 1
- 1
lualib/lua_magic/init.lua View File

@@ -140,7 +140,7 @@ local function match_chunk(chunk, input, tlen, offset, trie, processed_tbl, log_
if not res[ext] then
res[ext] = 0
end
if match.weight then
if weight then
res[ext] = res[ext] + weight
else
res[ext] = res[ext] + 1

+ 13
- 0
lualib/lua_magic/patterns.lua View File

@@ -19,6 +19,8 @@ limitations under the License.
-- This module contains most common patterns
--]]

local heuristics = require "lua_magic/heuristics"

local patterns = {
pdf = {
-- These are alternatives
@@ -82,6 +84,17 @@ local patterns = {
}
}
},
-- MS Office format, needs heuristic
ole = {
matches = {
{
hex = [[d0cf11e0a1b11ae1]],
relative_position = 0,
weight = 60,
heuristic = heuristics.ole_format_heuristic
}
}
},
-- MS Exe file
exe = {
matches = {

+ 21
- 0
lualib/lua_magic/types.lua View File

@@ -130,6 +130,27 @@ local types = {
ct = 'application/x-shockwave-flash',
type = 'image',
},
-- Ole files
ole = {
ct = 'application/octet-stream',
type = 'msoffice'
},
doc = {
ct = 'application/msword',
type = 'msoffice'
},
xls = {
ct = 'application/vnd.ms-excel',
type = 'msoffice'
},
ppt = {
ct = 'application/vnd.ms-powerpoint',
type = 'msoffice'
},
msi = {
ct = 'application/x-msi',
type = 'executable'
},
-- other
pgp = {
ct = 'application/encrypted',

+ 1
- 0
src/lua/lua_text.c View File

@@ -98,6 +98,7 @@ static const struct luaL_reg textlib_m[] = {
LUA_INTERFACE_DEF (text, take_ownership),
LUA_INTERFACE_DEF (text, save_in_file),
LUA_INTERFACE_DEF (text, span),
LUA_INTERFACE_DEF (text, at),
{"write", lua_text_save_in_file},
{"__len", lua_text_len},
{"__tostring", lua_text_str},

Loading…
Cancel
Save