Skip to content

Commit 98675e1

Browse files
committed
codecaves: allow specifying the memory protection of the codecaves
1 parent 1b81acb commit 98675e1

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

thcrap/src/binhack.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ int codecaves_apply(json_t *codecaves) {
325325
size_t codecave_count = 0, codecaves_total_size = 0;
326326

327327
json_object_foreach(codecaves, codecave_name, hack) {
328+
if (strcmp(codecave_name, "protection") == 0) {
329+
continue;
330+
}
328331
const char* code = json_string_value(hack);
329332
if (!code) {
330333
continue;
@@ -340,6 +343,10 @@ int codecaves_apply(json_t *codecaves) {
340343
BYTE *current_cave = codecave_buf;
341344

342345
json_object_foreach(codecaves, codecave_name, hack) {
346+
if (strcmp(codecave_name, "protection") == 0) {
347+
continue;
348+
}
349+
343350
const char *code = json_string_value(hack);
344351
if (!code) {
345352
continue;
@@ -358,7 +365,14 @@ int codecaves_apply(json_t *codecaves) {
358365
// Second pass: Write all of the code
359366
current_cave = codecave_buf;
360367

368+
DWORD codecave_protection = 0;
369+
361370
json_object_foreach(codecaves, codecave_name, hack) {
371+
if (strcmp(codecave_name, "protection") == 0) {
372+
codecave_protection = json_object_get_hex(codecaves, codecave_name);
373+
continue;
374+
}
375+
362376
const char* code = json_string_value(hack);
363377
if (!code) {
364378
continue;
@@ -372,7 +386,11 @@ int codecaves_apply(json_t *codecaves) {
372386
}
373387

374388
DWORD old_prot;
375-
VirtualProtect(codecave_buf, codecaves_total_size, PAGE_EXECUTE_READ, &old_prot);
389+
if (codecave_protection == 0) {
390+
codecave_protection = PAGE_EXECUTE_READ;
391+
}
392+
393+
VirtualProtect(codecave_buf, codecaves_total_size, codecave_protection, &old_prot);
376394

377395
return 0;
378396
}

0 commit comments

Comments
 (0)