Questions tagged [self-modifying]

Self-modifying code is a piece of software which achieves its goal by rewriting itself as it goes along. Use this tag for questions related to self-modifying code, such as the writing and running of such codes in different languages, use cases and its detection.

Self-modifying code is a piece of software which achieves its goal by rewriting itself as it goes along. Use this tag for questions related to self-modifying code, such as the writing and running of such codes in different languages, use cases and its detection.

156 questions
11
votes
4 answers

self modifying python script

I want to create python script which can modify code in that script itself using Python Language Services or using any other way. e.g. A script which keep track of its count of successfull execution import re COUNT = 0 def updateCount(): #…
Alok
  • 7,734
  • 8
  • 55
  • 100
10
votes
3 answers

Can compilers generate self modifying code?

It is commonly said that a static variable initialization is wrapped in an if to prevent it from being initialized multiple times. For this, and other one-off conditions, it would be more efficient to have the code remove the conditional after the…
janekb04
  • 4,304
  • 2
  • 20
  • 51
10
votes
1 answer

Native self-modifying code on Android

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 : //…
Иван
  • 434
  • 3
  • 16
10
votes
1 answer

Levels of Homoiconicity

This is a follow up to my previous question. I’m not convinced that Lisp code is as Homoiconic as machine code on a Von Neumann architecture. It seems obvious to me that in both cases code is represented as data, but it also seems apparent that you…
TheIronKnuckle
  • 7,224
  • 4
  • 33
  • 56
9
votes
4 answers

How can I make the contents of an #include-file a compile-time constant in a cpp-file?

I have a file module.hpp struct ModuleBase { virtual void run() = 0; }; and a main.cpp program int main() { cout << ...?...; // here should go the contents of module.hpp } What can I put at ...?... to let the contents of the header file…
towi
  • 21,587
  • 28
  • 106
  • 187
9
votes
7 answers

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.
Rakesh Juyal
  • 35,919
  • 68
  • 173
  • 214
9
votes
2 answers

Disassembling self-modifying code

I've been just wondering - how does one disassemble self-modifying binary? I guess you can't use olly or IDA because they are static disassemblers, correct? What happens with disassembler if you jump into middle of an instruction? And how does one…
Samuel
  • 2,430
  • 5
  • 31
  • 41
8
votes
2 answers

Self-modifying code on Darwin 10.15 resulting in "malformed mach-o image"?

I have a program that generates self-modifying code (see https://tigress.wtf/selfModify.html in case you're interested). It runs on x86 Darwin and Linux. On Darwin, I compile with gcc -g -segprot __TEXT rwx rwx self_modifying.c -o…
7
votes
1 answer

WinAPI: Is it needed to call FlushInstructionCache on an executable memory-mapped file?

I have written a short program to read a windows obj file and find the .text section and run the code in it. To do this I make the following Windows API function calls (Full code [gist.github.com], for those interested): HANDLE FileHandle =…
Fsmv
  • 1,106
  • 2
  • 12
  • 28
7
votes
1 answer

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…
Roman
  • 124,451
  • 167
  • 349
  • 456
7
votes
7 answers

Compiled dynamic language

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…
Marenz
  • 2,722
  • 3
  • 20
  • 19
6
votes
2 answers

Fixing file permissions after modifying in C++?

I'm saving my data in the executable file of the program. I copy it to a temporary file, overwrite a part starting at a 'magic string' and rename it to the original. I know this is a bad idea, but I'm doing it just for experimenting. I got…
RPFeltz
  • 1,049
  • 2
  • 12
  • 21
6
votes
3 answers

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…
Adam Goode
  • 7,380
  • 3
  • 29
  • 33
6
votes
1 answer

Self modifying code, copy/jump in the heap failed

First I am sorry about the length of this post, but I wanted to explain the problem clearly. I try to write a kind of small self modifying program in C but I have some troubles and I don't know exactly why. Plateform is : Ubuntu/Linux 2.6.32-40…
hodj
  • 73
  • 3
5
votes
2 answers

Use cases for self-modifying code?

On a Von Neumann architecture, program and data are both stored in memory, so a program can modify itself. Is this useful for a programmer? Could you give some examples?
gylns
  • 237
  • 3
  • 8
1
2
3
10 11