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
5
votes
1 answer

Is it guaranteed that x86 instruction fetch is atomic, so that rewriting an instruction with a short jump is safe for concurrent thread execution?

I thought hot-patching assumed that overwriting any instruction that is 2 or more bytes long with a 2 byte jump is safe for concurrent execution of the same code. So instruction fetch is assumed to be atomic. Is it indeed atomic, taking into account…
Alex Guteniev
  • 12,039
  • 2
  • 34
  • 79
5
votes
2 answers

Does the C Standard Allow for Self-Modifying Code?

Is self-modifying code possible in a portable manner in C? The reason I ask is that, in a way, OOP relies on self-modifying code (because the code that executes at run-time is actually generated as data, e.g. in a v-table), and yet, it seems that,…
user541686
  • 205,094
  • 128
  • 528
  • 886
5
votes
2 answers

Self Modifying Code [C++]

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…
Gogeta70
  • 881
  • 1
  • 9
  • 23
5
votes
1 answer

Kotlin: Possible to modify functions during compile time through metaprogramming?

In dynamic languages like JavaScript/Python, it's possible to overwrite or "modify" functions during run-time. For example, in order to modify the alert function in JS, one could do: const _prev_alert = window.alert; window.alert = function() { …
Griffort
  • 1,174
  • 1
  • 10
  • 26
5
votes
1 answer

How to synchronize on ARM when one thread is writing code which the other thread may be executing concurrently?

Consider a multi-core ARM processor. One thread is modifying a machine code block which is maybe being executed concurrently by another thread. The modifying thread does the following kinds of changes: Mark the machine code block for skipping: it…
Serge Rogatch
  • 13,865
  • 7
  • 86
  • 158
5
votes
1 answer

Self-modifying code sees a 0xCC byte but the debugger doesn't show it?

I'm trying to write self modifying asm code. At some point, I try the following : (NASM compiler) start_of_code: ; ... snip ... cmp byte [rax], 0x66 jae above_label add byte[rax], 0x20 ; ... snip ... above_label: inc rax loop start_of_code gdb…
Eric
  • 19,525
  • 19
  • 84
  • 147
5
votes
1 answer

Can I use Self-Modification in Android?

When I read Google play policy, I have a question in this sentence. An app downloaded from Google Play may not modify, replace or update its own APK binary code using any method other than Google Play's update mechanism. This means developsers can't…
maekchi
  • 55
  • 2
4
votes
2 answers

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?
Triynko
  • 18,766
  • 21
  • 107
  • 173
4
votes
1 answer

self-modifying code algorithm

some programs generates the executable code at run-time. i.e computer virus, packed binary. this makes static analysis very difficult. aside from packing algorithms, is there any general algorithm for self-modifying code generation? or compiler…
daehee
  • 5,047
  • 7
  • 44
  • 70
3
votes
1 answer

does the processor switch data from 'L1 code' to 'L1 data' cache?

I would like to know, how does the microprocessor (lets say on SandyBridge architecture in long mode) switches data from 'L1 code' to 'L1 data' cache and vice versa ? Lets say a page was used for data storage, so it is cached in L1 cache. Then ,…
Nulik
  • 6,748
  • 10
  • 60
  • 129
3
votes
1 answer

Is it safe to write unaligned to an immediate operand in machine code while that code is executing?

Let's say I have x86-64 code that looks like this (though this question applies more generally to all code): mov rbx,7F0140E5247Dh jmp rbx Is it safe to overwrite the target constant if that target value is not aligned, while that code could be…
PiRocks
  • 1,708
  • 2
  • 18
  • 29
3
votes
1 answer

Synchronizing caches for JIT/self-modifying code on ARM

The general, more abstract procedure for writing and later executing JIT or self-modifying code is, to my understanding, something like the following. Write the generated code, make sure it's flushed and globally0 visible, and then make sure that…
Mona the Monad
  • 2,265
  • 3
  • 19
  • 30
3
votes
5 answers

C++ Boolean Variables Changing

I have a C++ class; this class is as follows: First, the header: class PageTableEntry { public: PageTableEntry(bool modified = true); virtual ~PageTableEntry(); bool modified(); void setModified(bool modified); private: …
jstm88
  • 3,335
  • 4
  • 38
  • 55
3
votes
1 answer

Modifying region of memory - returns 0xCC VC++

I am modifying some sections of an executable code compiled in a dll. But a single byte at a fixed address from the entire segment that I am modifying can't be changed, not even read. The code is very simple: SEGMENT_DATA segInfo =…
sergiu reznicencu
  • 1,039
  • 1
  • 11
  • 31
3
votes
4 answers

Self-modifying code for trace hooks?

I'm looking for the least-overhead way of inserting trace/logging hooks into some very performance-sensitive driver code. This logging stuff has to always be compiled in, but most of the time do nothing (but do nothing very fast). There isn't…
kdt
  • 27,905
  • 33
  • 92
  • 139
1 2
3
10 11