Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Firstly, I would like to state that I already understand the 'vx' applications for Metamorphic code. I am not here to ask a question related to any of those topics as that would be inappropriate in this context.

I would like to know if anyone has ever used 'Metamorphic' code in practice, for purposes other than those previously stated, if so, what was the reasoning for using said concept.

In essence I am trying to discover a purpose for this concept, if any, other than circumventing anti-virus scanners and the like.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

There are plenty of possible applications. For example, evolutionary and genetic programming methods are widely used in practice (and there is a lot of current research as well).

One of the most mundane (and thus practical) applications is generating stress-tests for compilers via mutating a piece of code with the known behaviour into a much larger but still equivalent code.

share|improve this answer

Optimisation can be done by metamorphism. You could, at least in theory, release a binary that would work on any x86 CPU. When running the program, you'd have a menu item "optimize code for current CPU", which would decompile methods and recompile them in a more efficient manner.

In fact, that's how a JIT compiler works*. Any JITted code could be considered metamorphic, since the code that actually runs isn't in the executable file; it is compiled with optimisations for the specific machine, when it's needed.

* Actually, a JIT compiler doesn't actually decompile a method and rewrites it; the original method is usually just a stub that says "please compile this method from this bytecode representation, then call it" - after the first time it is run the method is replaced with the compiled version.

share|improve this answer
1  
I agree with your first statement regarding optimizations, though the JIT statement, I do not. A JIT compiler reads in a file and produces and semi-binary file of some form (to be interpreted by a specific runtime environment). Metamorphic code would include, at least, a disassembler, mutator (for rewriting the code) and an assembler all within itself. So, after the initial compilation, a compiler is no longer needed as one is essentially built in. –  V_P Nov 15 '11 at 4:35
2  
It is somewhat correct to say that JIT performs a "decompilation". If your bytecode is for some kind of a stack-based machine, JIT have to decompile it first into a three-address form (or any other similar register-based representation), then into SSA (i.e., reconstructing expression trees), and this is anyway about a half of what decompilers are doing. A smart JIT may perform serious mutations of the original bytecode (or an intermediate representation), which may include global constant propagation, partial specialisation, inlining, etc. –  SK-logic Nov 15 '11 at 8:17
    
@V_P: On program start, the method is one thing (a stub that calls the JIT); after it is called the first time, the method is a different thing (a compiled method). Seems metamorphic to me. Does the mutation have to be algorithmically inferred of the original code? Why? –  configurator Nov 15 '11 at 15:14
    
@configurator: I see your point of view on how the JIT process can be argued as being Metamorphic. With regard to your second statement; Does the mutation have to be algorithmically inferred of the original code? Why? From the examples I have seen and write-ups I have studied on the concept, I would have to say yes. The actual application's of Metamorphism that I have seen contain what we will call the 'engine' internally. The issue with JITted code is that it relies on an external 'means', the JIT, in order to recompile; the logic is not built internally. –  V_P Nov 15 '11 at 15:31
    
@configurator: Continued >>>> Also, the mutation of the code must occur at runtime, we also need direct access to memory as it is the assembly level instructions themselves that we wish to re-write. I do not believe this is possible with a JITted language such as; Java, C#, Etc. The only working examples of this concept I have seen are written in Assembly. –  V_P Nov 15 '11 at 15:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.