Jump to content

Self-modifying code

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Smaffy (talk | contribs) at 22:47, 27 April 2003. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Selfmodifying code is simply code that modifies itself. This is impossible to do without the use of assembly language as high level langugages (HLL's) simply cannot describe how to do such an advaced operation.

example algorithm (theoretic!)

Start:
GOTO Decryption_Code
Encrypted:
    ...
    lots of encrypted code!!!
    ...
Decryption_Code:
    A = Encrypted
Loop:
    B = *A
    XOR B, CryptoKey
    *A = B
    *A = *A + 1
    GOTO Loop IFNOT A = (Decryption_Code - Encrypted)
    GOTO Encrypted
 CryptoKey:
    some_random_number

This "program" will decrypt a part of itself and then jump to it. (*A means "the location to wich A points")