Add unprotect_addr to util.c
This commit is contained in:
parent
44f00ace13
commit
fee20bb1ec
|
@ -35,5 +35,6 @@ float angle_delta_rad(float a, float b);
|
|||
bool world_to_screen(vec3_t vec, vec2_t screen);
|
||||
void gl_drawbox(int x, int y, int w, int h, rgb_t c);
|
||||
void gl_drawline(int x0, int y0, int x1, int y1, float w, rgb_t col);
|
||||
bool unprotect_addr(void* ptr);
|
||||
|
||||
#endif /* UTIL_H_ */
|
||||
|
|
24
src/util.c
24
src/util.c
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include <math.h>
|
||||
#include <GL/gl.h>
|
||||
#include <unistd.h> /* getpagesize */
|
||||
#include <sys/mman.h> /* mprotect */
|
||||
|
||||
cl_entity_t* get_entity(int ent_idx) {
|
||||
if (ent_idx < 0 || ent_idx > 32)
|
||||
|
@ -125,3 +127,25 @@ void gl_drawline(int x0, int y0, int x1, int y1, float w, rgb_t col) {
|
|||
glEnable(GL_TEXTURE_2D);
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
/*
|
||||
* Credits:
|
||||
* https://github.com/UnkwUsr/hlhax/blob/26491984996c8389efec977ed940c5a67a0ecca4/src/utils/mem/mem.cpp
|
||||
* Linux kernel, tools/virtio/linux/kernel.h
|
||||
*/
|
||||
#define PAGE_SIZE getpagesize()
|
||||
#define PAGE_MASK (~(PAGE_SIZE - 1))
|
||||
#define PAGE_ALIGN(x) ((x + PAGE_SIZE - 1) & PAGE_MASK)
|
||||
#define PAGE_ALIGN_DOWN(x) (PAGE_ALIGN(x) - PAGE_SIZE)
|
||||
|
||||
bool unprotect_addr(void* ptr) {
|
||||
void* p = (void*)PAGE_ALIGN_DOWN((int)ptr);
|
||||
int pgsz = getpagesize();
|
||||
|
||||
if (mprotect(p, pgsz, PROT_READ | PROT_WRITE) == -1) {
|
||||
printf("hl-cheat: error unprotecting %p\n", ptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue