offsets2.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #include <errno.h>
  2. #include <string.h> // strcmp, strerror
  3. #include <sys/utsname.h> // uname
  4. #include <sys/sysctl.h>
  5. #include "common2.h" // LOG, kptr_t
  6. #include "offsets2.h"
  7. static offsets_t *offsets[] =
  8. {
  9. // XXX: A few offsets are still in v0rtex.m because they're used in structs,
  10. // so moving them here will require rewriting of those parts.
  11. #ifdef __LP64__
  12. &(offsets_t){
  13. .version = "Darwin Kernel Version 16.7.0: Thu Jun 15 18:33:36 PDT 2017; root:xnu-3789.70.16~4/RELEASE_ARM64_T7000",
  14. .base = 0xfffffff007004000,
  15. .sizeof_task = 0x550,
  16. .task_itk_self = 0xd8,
  17. .task_itk_registered = 0x2e8,
  18. .task_bsd_info = 0x360,
  19. .proc_ucred = 0x100,
  20. .vm_map_hdr = 0x10,
  21. .ipc_space_is_task = 0x28,
  22. .realhost_special = 0x10,
  23. .iouserclient_ipc = 0x9c,
  24. .vtab_get_retain_count = 0x3,
  25. .vtab_get_external_trap_for_index = 0xb7,
  26. .zone_map = 0xfffffff007558478,
  27. .kernel_map = 0xfffffff0075b4050,
  28. .kernel_task = 0xfffffff0075b4048,
  29. .realhost = 0xfffffff00753aba0,
  30. .copyin = 0xfffffff00718d028,
  31. .copyout = 0xfffffff00718d21c,
  32. .chgproccnt = 0xfffffff00739aa04,
  33. .kauth_cred_ref = 0xfffffff007374d90,
  34. .ipc_port_alloc_special = 0xfffffff0070a60b4,
  35. .ipc_kobject_set = 0xfffffff0070b938c,
  36. .ipc_port_make_send = 0xfffffff0070a5bd8,
  37. .osserializer_serialize = 0xfffffff00744db90,
  38. .rop_ldr_x0_x0_0x10 = 0xfffffff00722a41c,
  39. .root_user_surface_vtab = 0xfffffff000000000, //replace
  40. /*
  41. OFFSET_ZONE_MAP = 0xfffffff007558478;
  42. OFFSET_KERNEL_MAP = 0xfffffff0075b4050;
  43. OFFSET_KERNEL_TASK = 0xfffffff0075b4048;
  44. OFFSET_REALHOST = 0xfffffff00753aba0;
  45. OFFSET_BZERO = 0xfffffff00708df80;
  46. OFFSET_BCOPY = 0xfffffff00708ddc0;
  47. OFFSET_COPYIN = 0xfffffff00718d028;
  48. OFFSET_COPYOUT = 0xfffffff00718d21c;
  49. OFFSET_ROOT_MOUNT_V_NODE = 0xfffffff0075b40b0;
  50. //OFFSET_CHGPROCCNT = 0xfffffff00739aa04;
  51. //OFFSET_KAUTH_CRED_REF = 0xfffffff007374d90;
  52. OFFSET_IPC_PORT_ALLOC_SPECIAL = 0xfffffff0070a60b4;
  53. OFFSET_IPC_KOBJECT_SET = 0xfffffff0070b938c;
  54. OFFSET_IPC_PORT_MAKE_SEND = 0xfffffff0070a5bd8;
  55. OFFSET_IOSURFACEROOTUSERCLIENT_VTAB = 0xfffffff006f11678;
  56. OFFSET_ROP_ADD_X0_X0_0x10 = 0xfffffff006935398;
  57. OFFSET_OSSERIALIZER_SERIALIZE = 0xfffffff00744db90;
  58. //OFFSET_ROP_LDR_X0_X0_0x10 = 0xfffffff00666a09c;
  59. */
  60. },
  61. #else
  62. &(offsets_t){
  63. .version = "Darwin Kernel Version 16.7.0: Thu Jun 15 18:33:36 PDT 2017; root:xnu-3789.70.16~4/RELEASE_ARM_S5L8950X",
  64. .base = 0x80001000,
  65. .sizeof_task = 0x3b0,
  66. .task_itk_self = 0x9c,
  67. .task_itk_registered = 0x1dc,
  68. .task_bsd_info = 0x22c,
  69. .proc_ucred = 0x98,
  70. .ipc_space_is_task = 0x18,
  71. .realhost_special = 0x8,
  72. .iouserclient_ipc = 0x5c,
  73. .vtab_get_retain_count = 0x3,
  74. .vtab_get_external_trap_for_index = 0xe1,
  75. .zone_map = 0x804188e0,
  76. .kernel_map = 0x80456034,
  77. .kernel_task = 0x80456030,
  78. .realhost = 0x80404150,
  79. .copyin = 0x80007b9c,
  80. .copyout = 0x80007c74,
  81. .chgproccnt = 0x8027cc17,
  82. .kauth_cred_ref = 0x8025e78b,
  83. .ipc_port_alloc_special = 0x80019035,
  84. .ipc_kobject_set = 0x800290b7,
  85. .ipc_port_make_send = 0x80018c55,
  86. .osserializer_serialize = 0x8030687d,
  87. .rop_ldr_r0_r0_0xc = 0x802d1d45,
  88. .root_user_surface_vtab = 0xfffffff000000000, //replace
  89. },
  90. #endif
  91. NULL,
  92. };
  93. offsets_t* get_offsets(void)
  94. {
  95. kern_return_t error = KERN_SUCCESS;
  96. //read device id
  97. int d_prop[2] = {CTL_HW, HW_MACHINE};
  98. char device[20];
  99. size_t d_prop_len = sizeof(device);
  100. //sysctl(d_prop, 2, NULL, &d_prop_len, NULL, 0);
  101. sysctl(d_prop, 2, device, &d_prop_len, NULL, 0);
  102. LOG("device: %s", device);
  103. int version_prop[2] = {CTL_KERN, KERN_OSVERSION};
  104. char osversion[20];
  105. size_t version_prop_len = sizeof(osversion);
  106. //sysctl(version_prop, 2, NULL, &version_prop_len, NULL, 0);
  107. sysctl(version_prop, 2, osversion, &version_prop_len, NULL, 0);
  108. LOG("version: %s", osversion);
  109. struct utsname u;
  110. if(uname(&u) != 0)
  111. {
  112. LOG("uname: %s", strerror(errno));
  113. return 0;
  114. }
  115. // TODO: load from file
  116. for(size_t i = 0; offsets[i] != 0; ++i)
  117. {
  118. // if(strcmp(u.version, offsets[i]->version) == 0)
  119. // {
  120. return offsets[i];
  121. //}
  122. }
  123. LOG("Failed to get offsets for kernel version: %s", u.version);
  124. return NULL;
  125. }