]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Lua_magic: Support hex patterns
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 6 Sep 2019 11:39:21 +0000 (12:39 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 6 Sep 2019 11:39:21 +0000 (12:39 +0100)
lualib/lua_magic/init.lua

index e8629eedad96652fb67a0c9527e5a295c3a5c33e..1ba899b0698c944366348510b29c115654b58de7 100644 (file)
@@ -42,6 +42,16 @@ local function process_patterns()
           processed_patterns[#processed_patterns + 1] = {
             match.string, match, pattern
           }
+        elseif match.hex then
+          local hex_table = {}
+
+          for i=1,#match.hex,2 do
+            local subc = match.hex:sub(i, i + 1)
+            hex_table[#hex_table + 1] = string.format('\\x{%s}', subc)
+          end
+          processed_patterns[#processed_patterns + 1] = {
+            table.concat(hex_table), match, pattern
+          }
         end
       end
     end