self-modifying

What is a code cave, and is there any legitimate use for one?

試著忘記壹切 提交于 2019-12-20 09:23:11
问题 I encountered this word for the first time in the StackOverflow question "C# Theoretical: Write a JMP to a codecave in asm." I see that according to Wiktionary, a code cave is: an unused block of memory that someone, typically a software cracker, can use to inject custom programming code to modify the behavior of a program. Did I find the correct definition? If so, is there any legitimate use for a code cave? 回答1: I've used them, although I'd never heard the term code cave until today. The

How is x86 instruction cache synchronized?

旧时模样 提交于 2019-12-17 15:42:21
问题 I like examples, so I wrote a bit of self-modifying code in c... #include <stdio.h> #include <sys/mman.h> // linux int main(void) { unsigned char *c = mmap(NULL, 7, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE| MAP_ANONYMOUS, -1, 0); // get executable memory c[0] = 0b11000111; // mov (x86_64), immediate mode, full-sized (32 bits) c[1] = 0b11000000; // to register rax (000) which holds the return value // according to linux x86_64 calling convention c[6] = 0b11000011; // return for (c[2] = 0; c

Probable instruction Cache Synchronization issue in self modifying code?

余生颓废 提交于 2019-12-14 01:30:14
问题 A lot of related questions <How is x86 instruction cache synchronized? > mention x86 should properly handle i-cache synchronization in self modifying code. I wrote the following piece of code which toggles a function call on and off from different threads interleaved with its execution. I am using compare and swap operation as an additional guard so that the modification is atomic. But I am getting intermittent crashes (SIGSEGV, SIGILL) and analyzing the core dump makes me suspicious if the

How do I modify a filepath using the os.path module?

社会主义新天地 提交于 2019-12-13 20:47:02
问题 My code import os.path #gets the module beginning = input("Enter the file name/path you would like to upperify: ") inFile = open(beginning, "r") contents = inFile.read() moddedContents = contents.upper() #makes the contents of the file all caps head,tail = os.path.split(beginning) #supposed to split the path new_new_name = "UPPER" + tail #adds UPPER to the file name final_name = os.path.join(head + new_new_name) #rejoins the path and new file name outFile = open(final_name, "w") #creates new

C: How to change my own program in my program in runtime?

空扰寡人 提交于 2019-12-13 11:09:31
问题 At runtime, either the assembler or machine code (which is it?) should be somewhere in RAM. Can I somehow get access to it, and read or even write to it? This is just for educational purposes. So, I just could compile this code. Am I really reading myself here? #include <stdio.h> #include <sys/mman.h> int main() { void *p = (void *)main; mprotect(p, 4098, PROT_READ | PROT_WRITE | PROT_EXEC); printf("Main: %p\n Content: %i", p, *(int *)(p+2)); unsigned int size = 16; for (unsigned int i = 0; i

What are the possibilities for self-modification of Java code?

元气小坏坏 提交于 2019-12-13 09:04:48
问题 Could you list the possibilities for Java code to modify itself? The scenario in which this is going to be used is a learning program. In response to user input the program learns a new algorithm: it looks up the existing code base for a similar algorithm if no similar algorithm is in the code base, the program just adds a new algorithm if a similar algorithm exists, the program (perhaps with some help from the user) modifies the existing algorithm to be able to serve both the old purpose and

Android Self-modifying code - NDK

拥有回忆 提交于 2019-12-13 00:19:47
问题 I am trying to make a self-modifying code library and I have scowered all over and I have the follow code: typedef int (*FUNC) (void); int test(); JNIEXPORT int Java_com_example_untitled_MyActivity_decrypt( JNIEnv* env, jobject thiz) { void *code = mmap(NULL, 4, PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (code != MAP_FAILED) { memcpy(code, test, 4); return ( (FUNC)code)(); } return 0; } int test() { return 100; } Please help...I used Native self-modifying code on Android

Does mprotect flush the instruction cache on ARM Linux?

£可爱£侵袭症+ 提交于 2019-12-12 11:02:01
问题 I am writing a JIT on ARM Linux that executes an instruction set that contains self-modifying code. The instruction set does not have any cache flush instructions (similar to x86 in that respect). If I write out some code to a page and then call mprotect on that page, is that sufficient to invalidate the instruction cache? Or do I also need to use the cacheflush syscall on those pages? 回答1: You'd expect that the mmap/mprotect syscalls would establish mappings that are updated immediately, and

Self-Modifying MIPS Code

本小妞迷上赌 提交于 2019-12-12 04:56:30
问题 I'm trying to write a program in MIPS that continuously prompts for two integers and prints the sum until the sum is 0. The trick is that if the sum is 13, I need to call a method to change the assembled MIPS code so that add $t2, $t0, $t1 becomes and $t2, $t0, $t1 and all subsequent runs of the loop use the and instruction. I have the summation loop working so that when 13 is the sum the method instMod is called which I want to modify the instruction. Unfortunately, I have no idea where to

Self modifying code in node.js, would cluster work?

痞子三分冷 提交于 2019-12-11 09:48:12
问题 I am asking this since I don t have the tool or time to test this right now, but the idea is bothering me. I ll answer this myself when I ll have the time to play with it. In node.js, how does require() work? Does it keep the required function in memory? or doest it read the file anew? Exemple: launcher.js var cluster = require('cluster'); if (cluster.isMaster) { cluster.fork(); cluster.on('exit', function () { cluster.fork(); } } if (cluster.isWorker) { var self = require('self_modifying.js'