self-modifying

Dynamic relocation of code section

天涯浪子 提交于 2019-12-04 00:59:04
Just out of curiosity I wonder if it is possible to relocate a piece of code during the execution of a program. For instance, I have a function and this function should be replaced in memory each time after it has been executed. One idea that came up our mind is to use self-modifying code to do that. According to some online resources, self-modifying code can be executed on Linux, but still I am not sure if such a dynamic relocation is possible. Has anyone experience with that? Yes dynamic relocation is definitely possible. However, you have to make sure that the code is completely self

Self Modifying Code [C++]

倖福魔咒の 提交于 2019-12-03 16:56:58
I was reading a codebreakers journal article on self-modifying code and there was this code snippet: void Demo(int (*_printf) (const char *,...)) { _printf("Hello, OSIX!n"); return; } int main(int argc, char* argv[]) { char buff[1000]; int (*_printf) (const char *,...); int (*_main) (int, char **); void (*_Demo) (int (*) (const char *,...)); _printf=printf; int func_len = (unsigned int) _main ­- (unsigned int) _Demo; for (int a=0; a<func_len; a++) buff[a] = ((char *) _Demo)[a]; _Demo = (void (*) (int (*) (const char *,...))) &buff[0]; _Demo(_printf); return 0; } This code supposedly executed

Native self-modifying code on Android

旧巷老猫 提交于 2019-12-03 06:20:35
I am trying to make some self-modifing native code on Android and run it in the emulator. My sample is based on the HelloJNI sample from the android-ndk. It looks like this: #define NOPE_LENGTH 4 typedef void (*FUNC) (void); // 00000be4 <nope>: // be4: 46c0 nop (mov r8, r8) // be6: 4770 bx lr void nope(void) { __asm__ __volatile__ ("nop"); } void execute(void){ void *code = mmap(NULL, NOPE_LENGTH, PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (code != MAP_FAILED) { memcpy(code, nope, NOPE_LENGTH); ((FUNC)code)(); } } The problem is that this code is crashing. What is wrong?

How can I write self-modifying code that runs efficiently on modern x64 processors?

徘徊边缘 提交于 2019-12-02 19:24:43
I'm trying to speed up a variable-bitwidth integer compression scheme and I'm interested in generating and executing assembly code on-the-fly. Currently a lot of time is spent on mispredicted indirect branches, and generating code based on the series of bitwidths as found seems to be the only way avoid this penalty. The general technique is referred to as "subroutine threading" (or "call threading", although this has other definitions as well). The goal is to take advantage of the processors efficient call/ret prediction so as to avoid stalls. The approach is well described here: http:/

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

心不动则不痛 提交于 2019-12-02 18:06:28
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? I've used them, although I'd never heard the term code cave until today. The Wiktionary definition suggests that a code cave is something the cracker finds in the executable he or she

Self modifying html-JavaScript file

守給你的承諾、 提交于 2019-12-01 05:15:38
I would like to have a html file with JavaScript, which (file) is able to modify its context. In more details, I imagine it like that. I have a html file, which I open with a browser. I have a text area there where I type my text and press submit button. As a result of that, the context of the form saved somewhere in the html file. What is the easiest and stable way to do that? LarsH TiddlyWiki saves all its content to a new, local html-with-javascript file in browser-specific ways. This is because writing to the local hard drive is not normally allowed in javascript, for security reasons. If

Self modifying html-JavaScript file

喜你入骨 提交于 2019-12-01 02:34:54
问题 I would like to have a html file with JavaScript, which (file) is able to modify its context. In more details, I imagine it like that. I have a html file, which I open with a browser. I have a text area there where I type my text and press submit button. As a result of that, the context of the form saved somewhere in the html file. What is the easiest and stable way to do that? 回答1: TiddlyWiki saves all its content to a new, local html-with-javascript file in browser-specific ways. This is

Can a C program modify its executable file?

。_饼干妹妹 提交于 2019-11-30 03:08:30
I had a little too much time on my hands and started wondering if I could write a self-modifying program. To that end, I wrote a "Hello World" in C, then used a hex editor to find the location of the "Hello World" string in the compiled executable. Is it possible to modify this program to open itself and overwrite the "Hello World" string? char* str = "Hello World\n"; int main(int argc, char* argv) { printf(str); FILE * file = fopen(argv, "r+"); fseek(file, 0x1000, SEEK_SET); fputs("Goodbyewrld\n", file); fclose(file); return 0; } This doesn't work, I'm assuming there's something preventing it

Programming language for self-modifying code?

杀马特。学长 韩版系。学妹 提交于 2019-11-29 21:03:30
I am recently thinking about writing self-modifying programs , I think it may be powerful and fun. So I am currently looking for a language that allows modifying a program's own code easily. I read about C# (as a way around) and the ability to compile and execute code in runtime, but that is too hurting. I am also thinking about assembly . It is easier there to change running code but it is not very powerful (very raw). Can you suggest a powerful language or feature that supports modifying code in runtime? Example That what I mean by modifying code in runtime: Start: a=10,b=20,c=0; label1: c=a

Program that modifes string inside its exe

随声附和 提交于 2019-11-29 11:52:43
I looking for example of program, that modifies a string inside its exe. I work with C++, Visual Studio under Windows. I searched working examples in Windows, but I can't find any working code. I need simple code, that will ask user for string: string strTest = ""; (if strTest != "") { cout << "Modified: " << strTest << endl; } cin >> strText; And code should rewrite: string strTest = ""; To string that typed user: string strTest = "SomeStringFromUser"; How, in C++, do you modify a string (from string strTest = ""), to string, what a user typed? (for example to strTest = "foo")? When an EXE is