self-modifying

Can a C program modify its executable file?

纵饮孤独 提交于 2019-11-29 00:10:10
问题 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(

Programming language for self-modifying code?

青春壹個敷衍的年華 提交于 2019-11-28 16:29:12
问题 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

Self modifying code in Java [closed]

余生长醉 提交于 2019-11-28 09:16:32
Have you ever created or encountered a self modifying code in Java? If yes, then please post the link or simply post the code. Ignoring the world of grief you could be causing yourself via self-modifying code(!), it seems to me there are 3 options: use the inbuilt compiler support of Java 6 and write/recompile/reload classes use the Apache BCEL bytecode manipulation library to write your class directly make use of Java 6's inbuilt scripting support (or use Apache BSF ) to write methods in your JVM scripting language of choice, and execute these Of the three above, my initial choice (in the

Is there any self-improving compiler around?

喜你入骨 提交于 2019-11-28 08:25:33
I am not aware of any self-improving compiler, but then again I am not much of a compiler-guy. Is there ANY self-improving compiler out there? Please note that I am talking about a compiler that improves itself - not a compiler that improves the code it compiles . Any pointers appreciated! Side-note : in case you're wondering why I am asking have a look at this post . Even if I agree with most of the arguments I am not too sure about the following: We have programs that can improve their code without human input now — they’re called compilers. ... hence my question. While it is true that

Program that modifes string inside its exe

旧街凉风 提交于 2019-11-28 05:17:44
问题 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

What are the uses of self modifying code?

五迷三道 提交于 2019-11-28 03:27:30
Is there any real use for self modifying code ? I know that they can be used to build worms/viruses, but I was wondering whether there is some good reason that a programmer may have to use self modifying code. Any ideas? Hypothetical situations are welcome too. Turns out that the Wikipedia entry on " self-modifying code " has a great list: Semi-automatic optimization of a state dependent loop. Runtime code generation , or specialization of an algorithm in runtime or loadtime (which is popular, for example, in the domain of real-time graphics) such as a general sort utility preparing code to

How is x86 instruction cache synchronized?

心不动则不痛 提交于 2019-11-27 19:06:01
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[2] < 30; c[2]++) { // incr immediate data after every run // rest of immediate data (c[3:6]) are

Homoiconic and “unrestricted” self modifying code + Is lisp really self modifying?

空扰寡人 提交于 2019-11-27 10:00:30
问题 I will be forward in admiting that my knowledge of Lisp is extremely minimal. However I am extremely interested in the language and plan to begin seriously learning it in the near future. My understanding of these issues is no doubt flawed, so if I say anything which is blatently wrong, please comment and correct me rather than downvoting. Truly Homoiconic and Self-modifiable languages I'm looking for examples of programming languages which support both Homoiconicity (Code has the same

Self modifying code always segmentation faults on Linux

大憨熊 提交于 2019-11-27 07:54:36
i found an article about self modifying code and tried to do some examples, but i get always segmentation faults. As fas as i can understand, there is a violation in memory permissions. The code segment is (r)ead/e(x)ecute and so the attempt of writting results to this fault. Is there a way to test the program either by changing the memory permissions at runtime or before? I'm using linux and the example is written in GAS assembly. .extern memcpy .section .data string: .asciz "whatever" string_end: .section .bss .lcomm buf, string_end-string .section .text .globl main main: call changer mov

Self modifying code in Java [closed]

折月煮酒 提交于 2019-11-27 02:47:05
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . Have you ever created or encountered a self modifying code in Java? If yes, then please post the link or simply post the code. 回答1: Ignoring the world of grief you could be causing yourself via self-modifying code(!), it seems to me there are 3 options: use the inbuilt compiler