self-modifying

Native self-modifying code on Android

感情迁移 提交于 2019-12-09 05:55:42
问题 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 <nope>: // be4: 46c0 nop (mov r8, r8) // be6: 4770 bx lr void nope(void) { __asm__ __volatile__ ("nop"); } void execute(void){ void *code = mmap(NULL, NOPE_LENGTH, PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (code != MAP_FAILED) { memcpy

x86_64 - Self-modifying code performance

醉酒当歌 提交于 2019-12-08 00:32:48
问题 I am reading the Intel architecture documentation, vol3, section 8.1.3 ; Self-modifying code will execute at a lower level of performance than non-self-modifying or normal code. The degree of the performance deterioration will depend upon the frequency of modification and specific characteristics of the code. So, if I respect the rules: (* OPTION 1 *) Store modified code (as data) into code segment; Jump to new code or an intermediate location; Execute new code; (* OPTION 2 ) Store modified

Fixing file permissions after modifying in C++?

和自甴很熟 提交于 2019-12-07 10:23:07
问题 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 everything to work so far, except for that I have to re-enable "Allow running as an executable" each time the file is replaced. What ways are there to solve this? Additional information: I use linux. 回答1: If you want to avoid using system(), you can use

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

a 夏天 提交于 2019-12-07 05:56:59
问题 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() { _prev_alert.apply(this, arguments); console.log("Alert function was called!"); } This would output "Alert function was called!" to the console every time the alert function is called. Now, obviously something like this would be impossible during

Does the C Standard Allow for Self-Modifying Code?

妖精的绣舞 提交于 2019-12-07 04:21:04
问题 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, if this is taken too far, it would prevent most optimizations in a compiler. For example: void add(char *restrict p, char *restrict pAddend, int len) { for (int i = 0; i < len; i++) p[i] += *pAddend; } An optimizing compiler could hoist the *pAddend

x86_64 - Self-modifying code performance

社会主义新天地 提交于 2019-12-06 05:56:02
I am reading the Intel architecture documentation, vol3, section 8.1.3 ; Self-modifying code will execute at a lower level of performance than non-self-modifying or normal code. The degree of the performance deterioration will depend upon the frequency of modification and specific characteristics of the code. So, if I respect the rules: (* OPTION 1 *) Store modified code (as data) into code segment; Jump to new code or an intermediate location; Execute new code; (* OPTION 2 ) Store modified code (as data) into code segment; Execute a serializing instruction; ( For example, CPUID instruction *)

Levels of Homoiconicity [closed]

不打扰是莪最后的温柔 提交于 2019-12-05 18:34:01
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . 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 can exploit this property much more freely in machine code than

Use cases for self-modifying code?

安稳与你 提交于 2019-12-05 11:56:47
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? Metamorphism One (questionable) use case that comes to my mind is metamorphic computer viruses . These are malicious pieces of software that conceal themselves from signature based detection by rewriting their own machine code to an semantically equivalent representation that looks different. Trampolining Another (more complex, but also more common) use case is trampolining , a technique based on dynamic code generation to

Does the C Standard Allow for Self-Modifying Code?

落爺英雄遲暮 提交于 2019-12-05 09:55:11
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, if this is taken too far, it would prevent most optimizations in a compiler. For example: void add(char *restrict p, char *restrict pAddend, int len) { for (int i = 0; i < len; i++) p[i] += *pAddend; } An optimizing compiler could hoist the *pAddend out of the loop, because it wouldn't interfere with p . However, this is no longer a valid

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

限于喜欢 提交于 2019-12-05 09:13:49
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() { _prev_alert.apply(this, arguments); console.log("Alert function was called!"); } This would output "Alert function was called!" to the console every time the alert function is called. Now, obviously something like this would be impossible during runtime in Kotlin-JVM or Kotlin-Native due to their static nature. However, in regards to those same