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
3
votes
4 answers

Memcpy with function pointers leads to a segfault

I know I can just copy the function by reference, but I want to understand what's going on in the following code that produces a segfault. #include #include #include int return0() { return 0; } int main() { …
A.S
  • 175
  • 1
  • 6
3
votes
3 answers

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…
Nakilon
  • 34,866
  • 14
  • 107
  • 142
3
votes
1 answer

Android self-modifying code in ART

I'm trying to implement self-modifying code in my Android application using JNI. I have the following method in MainActivity class of my application: public int methodToModify() { return 42; } And this is a bytecode of this…
floyd
  • 692
  • 8
  • 23
3
votes
0 answers

Seg fault in Self Modifying Code

This is related to Probable instruction Cache Synchronization issue in self modifying code? I had asked sometime back. Even though the accepted solution solved the related issue I came across a new intermittent failure mode where the CPU tries to…
chamibuddhika
  • 1,419
  • 2
  • 20
  • 36
3
votes
2 answers

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

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…
F. P.
  • 5,018
  • 10
  • 55
  • 80
3
votes
0 answers

C++ self erasing code

I want to create self erasing code - function to erase others. I tried to do it - but sometimes (most of times) I run it - it isn't working as it's suposed to work. I want to do something like this: int func(int a) { return a+1; } int…
mlgpro
  • 161
  • 1
  • 1
  • 8
3
votes
2 answers

Probable instruction Cache Synchronization issue in self modifying code?

A lot of related questions mention x86 should properly handle i-cache synchronization in self modifying code. I wrote the following piece of code which toggles a function call on and off from different…
chamibuddhika
  • 1,419
  • 2
  • 20
  • 36
3
votes
3 answers

Program that modifes string inside its exe

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…
Jasmin25
  • 177
  • 1
  • 7
3
votes
2 answers

Is there a way to decorate/perform operations on every line of a function in Python?

Say I have a function or method that does something repetitive, like checking a value, before performing every operation it does, like so: def myfunc(): if mybool: do_operation_1() else: return if mybool: …
Zac B
  • 3,796
  • 3
  • 35
  • 52
3
votes
1 answer

Find a minimal self-modifiying code example for educational purpose in x86 assembler?

I am looking for a few lines long example demonstrating a self-modifying code in x86 assembler for educational purpose (does not need to do something meaningful but needs to clearly write his own code and then execute it when you read the code…
perror
  • 7,071
  • 16
  • 58
  • 85
2
votes
0 answers

modify the NDK and generate new experimental release packages

I am trying to modify the NDK and generate new experimental release packages with the doc 'android-ndk-r6\docs\DEVELOPMENT.html',but getting the following error after execute script $NDK/build/tools/rebuild-all-prebuilt.sh --toolchain-pkg=: ERROR:…
霄 冯
  • 21
  • 2
2
votes
2 answers

A self modifying code?

I would like to do the following . I have declared a structure in my program and in run time when the program is being executed, if there is a user input, I should be able to create another new structure/edit that structure in my code. How can we do…
Niranjan Sonachalam
  • 1,545
  • 1
  • 20
  • 29
2
votes
1 answer

Can I execute the number stored in a register as an instruction in MIPS?

If I take an instruction and break it down into the binary representation of its op code, rs, rt etc... could I then put this binary number into a register and get MIPS to treat it as an instruction? For example: The instruction: add $t0, $s0, $t0…
wfbarksdale
  • 7,498
  • 15
  • 65
  • 88
2
votes
0 answers

Avoiding self-modifying code (SMC) machine clears when writing to executable memory

I have run into a weird issue, where the CPU believes that I am modifying currently executed code, and repeatedly triggers self-modifying code (SMC) machine clears. My (simplified) program does the following: Allocate an executable buffer. Copy a…
janw
  • 8,758
  • 11
  • 40
  • 62
2
votes
2 answers

Is it possible to write self-modifying PowerShell scripts?

Is it possible to write self-modifying PowerShell scripts? Suppose I have a script named foo.ps1: "Write-Host `"Goodbye world`"" | Set-Content "foo.ps1" Write-Host "Hello world" This script prints out Hello world. What techniques could I use to get…
sourcenouveau
  • 29,356
  • 35
  • 146
  • 243