WoW:API issecurevariable: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
m (I played around with this a little bit and this is what I got. :)) |
||
| Line 2: | Line 2: | ||
Determines if given variable or table is [[secure]] or "[[Tainted (Addons)|tainted]]." Any usage of a "[[Tainted (Addons)|tainted]]" (= non-secure) variable, be it a function or simply data, will break [[secure]] state and prevent further access to Protected functions. | Determines if given variable or table is [[secure]] or "[[Tainted (Addons)|tainted]]." Any usage of a "[[Tainted (Addons)|tainted]]" (= non-secure) variable, be it a function or simply data, will break [[secure]] state and prevent further access to Protected functions. | ||
issecurevariable() | isSecure, unknown = issecurevariable([table], variable) | ||
==Parameters== | ==Parameters== | ||
| Line 9: | Line 9: | ||
===Return=== | ===Return=== | ||
:; | :;isSecure - 1 (secure) or nil (not secure) | ||
:;unknown - always nil. If isSecure is nil, this is not returned (implied nil). | |||
==Example 1== | ==Example 1== | ||
local secure = issecurevariable( "JumpOrAscendStart" ); | local secure = issecurevariable( "JumpOrAscendStart" ); | ||
if | if secure then | ||
DEFAULT_CHAT_FRAME:AddMessage("OK! Given variable is secure!"); | DEFAULT_CHAT_FRAME:AddMessage("OK! Given variable is secure!"); | ||
else | else | ||
DEFAULT_CHAT_FRAME:AddMessage("Given variable | DEFAULT_CHAT_FRAME:AddMessage("Given variable tainted. :s"); | ||
end | end | ||
===Result=== | ===Result=== | ||
| Line 23: | Line 24: | ||
==Example 2== | ==Example 2== | ||
local Old_UnitName = UnitName | |||
local secure = issecurevariable( " | function UnitName(unit) | ||
if | return Old_UnitName(unit or "player") | ||
end | |||
local secure = issecurevariable( "UnitName" ); | |||
if secure then | |||
DEFAULT_CHAT_FRAME:AddMessage("OK! Given variable is secure!"); | DEFAULT_CHAT_FRAME:AddMessage("OK! Given variable is secure!"); | ||
else | else | ||
DEFAULT_CHAT_FRAME:AddMessage("Given variable | DEFAULT_CHAT_FRAME:AddMessage("Given variable tainted. :s"); | ||
end | end | ||
===Result=== | ===Result=== | ||
*Message "Given variable | *[[API_UnitName|UnitName]] is not a protected Blizzard-defined function, but will still become tainted when hooked. | ||
*Message "Given variable tainted. :s" will get displayed in your chat frame. | |||
==Notes== | ==Notes== | ||
* | * Returns <code>1, nil</code> for undefined variables. This is because an undefined variable is secure since you have not tainted it. | ||
* Returns <code>1, nil</code> for all untainted variables (i.e. Blizzard variables). | |||
* Returns <code>nil</code> for '''any''' global variable that is hooked insecurely (tainted), even unprotected ones like [[API UnitName|UnitName()]]. | |||
* Returns <code>nil</code> for all user defined global variables. | |||
* If a table is passed first, it checks table.variable (e.g. <code>issecurevariable(PlayerFrame, "Show")</code> checks PlayerFrame["Show"] or PlayerFrame.Show (they are the same thing)). | |||
* Does not work for local variables. | |||
Revision as of 06:24, 30 January 2009
Determines if given variable or table is secure or "tainted." Any usage of a "tainted" (= non-secure) variable, be it a function or simply data, will break secure state and prevent further access to Protected functions.
isSecure, unknown = issecurevariable([table], variable)
Parameters
Arguments
- [table], variable
Return
- isSecure - 1 (secure) or nil (not secure)
- unknown - always nil. If isSecure is nil, this is not returned (implied nil).
Example 1
local secure = issecurevariable( "JumpOrAscendStart" );
if secure then
DEFAULT_CHAT_FRAME:AddMessage("OK! Given variable is secure!");
else
DEFAULT_CHAT_FRAME:AddMessage("Given variable tainted. :s");
end
Result
- JumpOrAscendStart is a protected Blizzard-defined function, thus secure. Calling it will not break secure status.
- Message "OK! Given variable is secure!" will get displayed in your chat frame.
Example 2
local Old_UnitName = UnitName
function UnitName(unit)
return Old_UnitName(unit or "player")
end
local secure = issecurevariable( "UnitName" );
if secure then
DEFAULT_CHAT_FRAME:AddMessage("OK! Given variable is secure!");
else
DEFAULT_CHAT_FRAME:AddMessage("Given variable tainted. :s");
end
Result
- UnitName is not a protected Blizzard-defined function, but will still become tainted when hooked.
- Message "Given variable tainted. :s" will get displayed in your chat frame.
Notes
- Returns
1, nilfor undefined variables. This is because an undefined variable is secure since you have not tainted it. - Returns
1, nilfor all untainted variables (i.e. Blizzard variables). - Returns
nilfor any global variable that is hooked insecurely (tainted), even unprotected ones like UnitName(). - Returns
nilfor 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)). - Does not work for local variables.