Add new_flags parameter to protect_addr
This commit is contained in:
parent
d2d1f55d22
commit
4b7cdc86b9
|
@ -2,6 +2,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
#include <sys/mman.h> /* PROT_* */
|
||||||
|
|
||||||
#include "include/globals.h"
|
#include "include/globals.h"
|
||||||
#include "include/sdk.h"
|
#include "include/sdk.h"
|
||||||
|
@ -54,7 +55,7 @@ bool globals_init(void) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!unprotect_addr(i_studiomodelrenderer)) {
|
if (!protect_addr(i_studiomodelrenderer, PROT_READ | PROT_WRITE)) {
|
||||||
printf("hl-cheat: globals_init: couldn't unprotect address of SMR\n");
|
printf("hl-cheat: globals_init: couldn't unprotect address of SMR\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,6 @@ float angle_delta_rad(float a, float b);
|
||||||
bool world_to_screen(vec3_t vec, vec2_t screen);
|
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_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);
|
void gl_drawline(int x0, int y0, int x1, int y1, float w, rgb_t col);
|
||||||
bool unprotect_addr(void* ptr);
|
bool protect_addr(void* ptr, int new_flags);
|
||||||
|
|
||||||
#endif /* UTIL_H_ */
|
#endif /* UTIL_H_ */
|
||||||
|
|
|
@ -139,12 +139,12 @@ void gl_drawline(int x0, int y0, int x1, int y1, float w, rgb_t col) {
|
||||||
#define PAGE_ALIGN(x) ((x + PAGE_SIZE - 1) & PAGE_MASK)
|
#define PAGE_ALIGN(x) ((x + PAGE_SIZE - 1) & PAGE_MASK)
|
||||||
#define PAGE_ALIGN_DOWN(x) (PAGE_ALIGN(x) - PAGE_SIZE)
|
#define PAGE_ALIGN_DOWN(x) (PAGE_ALIGN(x) - PAGE_SIZE)
|
||||||
|
|
||||||
bool unprotect_addr(void* ptr) {
|
bool protect_addr(void* ptr, int new_flags) {
|
||||||
void* p = (void*)PAGE_ALIGN_DOWN((int)ptr);
|
void* p = (void*)PAGE_ALIGN_DOWN((int)ptr);
|
||||||
int pgsz = getpagesize();
|
int pgsz = getpagesize();
|
||||||
|
|
||||||
if (mprotect(p, pgsz, PROT_READ | PROT_WRITE) == -1) {
|
if (mprotect(p, pgsz, new_flags) == -1) {
|
||||||
printf("hl-cheat: error unprotecting %p\n", ptr);
|
printf("hl-cheat: error protecting %p\n", ptr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue