Advertisement
XaskeL

[MTA] Theory of the hooking api MTA/Lua

May 30th, 2018
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.68 KB | None | 0 0
  1. -- Remark: Since, my themes on the official site of the MTA have been deleted, I am writing here.
  2. -- Theme: Removing protection from any compiled Lua script
  3.  
  4. -- Introduction: Method concluding is to re-create the MTA-API functions, but with your answer, which is necessary for you. After testing such interceptions, I wondered if it was possible to defend against this. As it turned out, this is simply not possible.
  5.  
  6. -- Example code and protect by server name:
  7. -- This Code on your server file and write in meta.xml above protected script
  8.  
  9. -- Example:
  10.  
  11. -- <meta>
  12. -- <script src="hook.lua" type="server"/>
  13. -- <script src="server.lua" type="server"/>
  14. -- </meta>
  15.  
  16. -- in hook.lua:
  17.  
  18. function getServerName()
  19.     return "server name on protected script" -- Example: "Big World RPG"
  20. end
  21.  
  22. -- Remark: You can save the original function in this way:
  23.  
  24. local _getServerName = getServerName; -- saved original function
  25. outputDebugString("server name: "..tostring(_getServerName)) -- get original server name, easy :)
  26.  
  27. -- Example code and protect by ip/port, strong hook:
  28.  
  29. local _getServerConfigSetting = getServerConfigSetting; -- save original function
  30. function getServerConfigSetting(name) -- Completely working function and does not break the receipt of other data
  31.     if name == "serverip" then
  32.         return "ip on protected script"
  33.     elseif name == "serverport" then
  34.         return "port on protected script"
  35.     end
  36.     return _getServerConfigSetting(name)
  37. end
  38.  
  39. function getServerPort()
  40.     return 22003
  41. end
  42.  
  43. -- Remark: Important save returning type values! (if function return STRING then "value" or function return INT then 123456)
  44. -- Author: XaskeL (Vladimir K.) vk.com/ixaskel
  45. -- Thank you for attention!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement