self-modifying

What are the uses of self modifying code?

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. ...

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

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 ...

Is it possible to write an assembly which dynamically generates a new class and patches itself with the new class?

Is it possible to write an assembly which dynamically generates/emits a new class and patches itself to include the new class? How? ...

Self modifying code in JAVA

Have you ever created or encountered a self modifying code in Java? If yes, then please post the link or simply post the code. ...

Is there any self-improving compiler around?

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 ...

Compiled dynamic language

Greetings, I search for a programming language for which a compiler exists and that supports self modifying code. I’ve heared that Lisp supports these features, but I was wondering if there is a more C/C++/D-Like language with these features. To clarify what I mean: I want to be able to have in some way access to the programms code at...

[C++] Program that modify string inside his exe

Hi I looking for example of program, that modify string inside his exe. I work with C++, Visual Studio under Windows. I searched in internet for working examples in Windows, but I doesn't find any working code. I need simple code, that will ask user for string: string strTest = ""; (if strTest != "") { cout << "Modified: " << str...

Dynamic relocation of code section

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, s...

Does mprotect flush the instruction cache on ARM Linux?

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 ...

Python - Code snippet not working on Python 2.5.6, using IDLE

Hello, everyone I am using a piece of self-modifying code for a college project. Here it is: import datetime import inspect import re import sys def main(): # print the time it is last run lastrun = 'Mon Jun 8 16:31:27 2009' print "This program was last run at ", print lastrun # read in the source code of itsel...

Self Modifying Code

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 allow modifying program 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 assembl...

Reading/Writing self heap

Could the own heap space be readed? could the software be self modified in memory? I write some code to show the subject, am I reading own code at memory? how (if possible) to write it and change instruction on runtime? #include<stdio.h> #include<stdint.h> volatile int addressBase; uint8_t read(int address); int main(void) { ...

copy and call function

I'd like to copy and call a function, but the code below segfaults when calling the buffer. What do I have to change? (Linux, x86) #include <string.h> #include <malloc.h> #include <stdio.h> int foo () { return 12; } void foo_end () {} int main () { int s = (unsigned long long) foo_end - (unsigned long long) foo; int (*f) () = (int...

A way to implement `String#split!`

Sometimes I need such method, which could change class of its own object. There are String#delete!, #downcase!, #encode!, #gsub!, #strip!, #slice!, etc. They are all trying to change string, but resulting class is anyway still String. And I want a method, which can convert String to Array. Some way to make this: irb(main):082:0> str = "...

Self modifying html-JavaScript file.

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 ...

Can a C program modify its executable file?

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" strin...