From 6292c256a3603f14c0af57c627d28ef7a688ba56 Mon Sep 17 00:00:00 2001 From: Pinya <800pin.ru@gmail.com> Date: Thu, 14 Dec 2017 20:48:19 +0300 Subject: [PATCH] add replacement for hooksecurefunc, issecurevariable --- !Compatibility/api/wowAPI.lua | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/!Compatibility/api/wowAPI.lua b/!Compatibility/api/wowAPI.lua index 31198fa..dfb2992 100644 --- a/!Compatibility/api/wowAPI.lua +++ b/!Compatibility/api/wowAPI.lua @@ -1,9 +1,11 @@ --Cache global variables +local _G = _G local assert = assert local date = date local pairs = pairs local tonumber = tonumber local type = type +local unpack = unpack local format, gsub, lower, match, upper = string.format, string.gsub, string.lower, string.match, string.upper local getn = table.getn --WoW API @@ -58,6 +60,36 @@ QuestDifficultyColors = { ["header"] = {r = 0.70, g = 0.70, b = 0.70} } +function hooksecurefunc(arg1, arg2, arg3) + local isMethod = type(arg1) == "table" and type(arg2) == "string" and type(arg1[arg2]) == "function" and type(arg3) == "function" + assert(isMethod or (type(arg1) == "string" and type(_G[arg1]) == "function" and type(arg2) == "function"), "Usage: hooksecurefunc([table,] \"functionName\", hookfunc)") + + if not isMethod then + arg1, arg2, arg3 = _G, arg1, arg2 + end + + local original_func = arg1[arg2] + + arg1[arg2] = function(...) + local original_return = {original_func(unpack(arg))} + arg3(unpack(arg)) + + return unpack(original_return) + end +end + +--[[ issecurevariable([table], variable) + Returns 1, nil for undefined variables. This is because an undefined variable is secure since you have not tainted it. + Returns 1, nil for all untainted variables (i.e. Blizzard variables). + Returns nil for any global variable that is hooked insecurely (tainted), even unprotected ones like UnitName(). + Returns nil for all user defined global variables. + If a table is passed first, it checks table.variable (e.g. issecurevariable(PlayerFrame, "Show") checks PlayerFrame["Show"] or PlayerFrame.Show (they are the same thing)). +]] +function issecurevariable(t, var) +-- assert(type(t) == "table" and type(var) == "string", "Usage: issecurevariable([table,] \"variable\")") + return +end + function UnitAura(unit, i, filter) assert((type(unit) == "string" or type(unit) == "number") and (type(i) == "string" or type(i) == "number"), "Usage: UnitAura(\"unit\", index [, filter])")