summaryrefslogtreecommitdiff
path: root/server/src/matcher
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/matcher')
-rw-r--r--server/src/matcher/compile.lua71
-rw-r--r--server/src/matcher/find_lib.lua20
2 files changed, 74 insertions, 17 deletions
diff --git a/server/src/matcher/compile.lua b/server/src/matcher/compile.lua
index 5ed3e97a..2c53f618 100644
--- a/server/src/matcher/compile.lua
+++ b/server/src/matcher/compile.lua
@@ -56,6 +56,14 @@ function mt:createDots()
return dots
end
+function mt:createLib(name)
+ local lib = {
+ name = name,
+ type = 'lib',
+ }
+ return lib
+end
+
function mt:createLocal(key, source, var)
if key == nil then
return nil
@@ -132,6 +140,34 @@ function mt:checkDots(source)
self:addInfo(dots, 'get', source)
end
+function mt:fixCallAsSetMetaTable(results)
+ local obj = results[1]
+ local metatable = results[2]
+ if metatable then
+ local index = self:getField(metatable, '__index')
+ if obj then
+ self:setMeta(obj, index)
+ return obj
+ else
+ return index
+ end
+ else
+ return obj
+ end
+end
+
+function mt:fixCallAsRequire(results)
+ local libname = results[1]
+ if not libname then
+ return
+ end
+ libname = libname.value or libname
+ if libname.type ~= 'string' then
+ return
+ end
+ return self:createLib(libname.string)
+end
+
function mt:searchCall(call, func)
local results = {}
for i, exp in ipairs(call) do
@@ -141,20 +177,13 @@ function mt:searchCall(call, func)
local api = self:getApi(func)
if api == 'setmetatable' then
- local obj = results[1]
- local metatable = results[2]
- if metatable then
- local index = self:getField(metatable, '__index')
- if obj then
- self:setMeta(obj, index)
- return obj
- else
- return index
- end
- else
- return obj
- end
+ return self:fixCallAsSetMetaTable(results)
end
+
+ if api == 'require' then
+ return self:fixCallAsRequire(results)
+ end
+
return nil
end
@@ -220,10 +249,18 @@ function mt:searchTable(exp)
return tbl
end
+function mt:getString(exp)
+ return {
+ type = 'string',
+ string = exp[1],
+ }
+end
+
function mt:searchExp(exp)
local tp = exp.type
if tp == 'nil' then
elseif tp == 'string' then
+ return self:getString(exp)
elseif tp == 'boolean' then
elseif tp == 'number' then
elseif tp == 'name' then
@@ -254,10 +291,12 @@ function mt:setValue(var, value)
if not var or not value then
return
end
- var.childs = value.childs
var.value = value.value or value
- for _, child in pairs(value.childs) do
- child.parent = var
+ if value.childs then
+ var.childs = value.childs
+ for _, child in pairs(value.childs) do
+ child.parent = var
+ end
end
end
diff --git a/server/src/matcher/find_lib.lua b/server/src/matcher/find_lib.lua
index 84cf44c5..7001117e 100644
--- a/server/src/matcher/find_lib.lua
+++ b/server/src/matcher/find_lib.lua
@@ -110,7 +110,6 @@ local function isGlobal(var)
end
local function checkLibAsGlobal(var, name)
- -- 检查是否是全局变量
local value = var.value or var
if value.key == name and isGlobal(value) then
return name
@@ -118,6 +117,20 @@ local function checkLibAsGlobal(var, name)
return nil
end
+local function checkLibAsLibrary(var, name)
+ local value = var.value
+ if not value then
+ return nil
+ end
+ if value.type ~= 'lib' then
+ return nil
+ end
+ if value.name == name then
+ return name
+ end
+ return nil
+end
+
local function checkLib(var, name, lib)
if not lib.source then
return checkLibAsGlobal(var, name)
@@ -128,6 +141,11 @@ local function checkLib(var, name, lib)
if fullkey then
return fullkey
end
+ elseif source.type == 'library' then
+ local fullkey = checkLibAsLibrary(var, name)
+ if fullkey then
+ return fullkey
+ end
end
end
return nil