amx.inc 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (C) 2012 Zeex
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a
  4. // copy of this software and associated documentation files (the "Software"),
  5. // to deal in the Software without restriction, including without limitation
  6. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  7. // and/or sell copies of the Software, and to permit persons to whom the
  8. // Software is furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  14. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  18. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  19. // DEALINGS IN THE SOFTWARE.
  20. #if defined AMX_INC
  21. #endinput
  22. #endif
  23. #define AMX_INC
  24. #include "phys_memory"
  25. #include "shellcode"
  26. const AMX_OFFSET_BASE = 0;
  27. const AMX_OFFSET_DATA = 4;
  28. const AMX_OFFSET_CALLBACK = 8;
  29. const AMX_OFFSET_DEBUG = 12;
  30. const AMX_OFFSET_CIP = 16;
  31. const AMX_OFFSET_FRM = 20;
  32. const AMX_OFFSET_HEA = 24;
  33. const AMX_OFFSET_HLW = 28;
  34. const AMX_OFFSET_STK = 32;
  35. const AMX_OFFSET_STP = 36;
  36. const AMX_OFFSET_FLAGS = 40;
  37. const AMX_OFFSET_USERTAGS = 44;
  38. const AMX_OFFSET_USERDATA = 60;
  39. const AMX_OFFSET_ERROR = 76;
  40. const AMX_OFFSET_PARAMCOUNT = 80;
  41. const AMX_OFFSET_PRI = 84;
  42. const AMX_OFFSET_ALT = 88;
  43. const AMX_OFFSET_RESET_STK = 92;
  44. const AMX_OFFSET_RESET_HEA = 96;
  45. const AMX_OFFSET_SYSREQ_D = 100;
  46. // Returns the address of the AMX struct instance in memory that corresponds
  47. // to this script. This function works only on Windows!
  48. stock GetAmxAddress() {
  49. static address = 0;
  50. if (address == 0) {
  51. static const code[] = {
  52. 0x90909090, 0x90909090, 0x90909090, 0x90909090, // for alignment
  53. 0x0424448b, 0xC3C3C3C3
  54. // 8B 44 24 04 - MOV eax, [esp + arg_0]
  55. // C3 - RETN
  56. };
  57. address = RunShellcode(refabs(code));
  58. }
  59. return address;
  60. }
  61. // Reads a cell from the AMX struct.
  62. stock ReadAmxCell(offset) {
  63. new amx = GetAmxAddress();
  64. return ReadPhysMemoryCell(amx + offset);
  65. }
  66. // Writes a cell to the AMX struct.
  67. stock WriteAmxCell(offset, value) {
  68. new amx = GetAmxAddress();
  69. WritePhysMemoryCell(amx + offset, value);
  70. }