~ Office Supplies ~~ Buy Posters ~~ A-Z Products ~~ Website Advertising


Self-modifying code - Wikipedia

<<Up     Contents

Self-modifying code

Redirected from Self modifying code

In computer programming, self-modifying code is code that modifies itself. This is straightforward to write when using assembly language and is also supported by some high level language interpreters such as SNOBOL4 or the Lisp programming language. It is more difficult to implement on compilers but compilers such as Clipper and Spitbol[?] make a fair attempt at it. Batch programming scripts often involve self modifying code as well. Use of self-modifying code is not recommended where alternatives exist. This is because such code can be difficult to understand and maintain.

Self-modifying code was used in the early days of computers in order to save memory space in computers with very small main memory sizes. It was also used to implement subroutine calls and returns when the instruction set only provided simple branching or skipping instructions to vary the flow of control (this is still relevant in certain ultra-RISC architectures, at least theoretically, e.g. one such system has a single instruction with three operands: subtract-and-branch-if-negative).

Self-modifying code was used to hide copy protection instructions in 1980s MS DOS based games. The floppy disk drive access instruction 'int 0x13' would not appear in the executable program's image but it would be written into the executable's memory image after the program started executing. It is also sometimes used by programs that does not want to reveal their presence; computer viruses and some shellcodes use this technique.

example algorithm (theoretical!)

 
 Start:
 GOTO Decryption_Code
 Encrypted:
     ...
     lots of encrypted code!!!
     ...
 Decryption_Code:
     *A = Encrypted
 Loop:
     B = *A
     B = B XOR CryptoKey
     *A = B
     A = A + 1
     GOTO Loop IF NOT 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 which A points")

wikipedia.org dumped 2003-03-17 with terodump




 
 
13 ct pink red gemmy banded RHODOCHROSITE Gorgeous gemstone tongue freeform 14 mm Single gem piece
 13 ct pink red my banded RHODOCHROSITE Gorgeous tongue freeform 14 mm Single piece 
 
7 carat RARE yellow orange CLINOHUMITE gem stone crystal cabbing lapidary cabochon rough 1 gram C
 7 carat RARE yellow orange CLINOHUMITE crystal cabbing lapidary cabochon 1 gram C 
 
14 gram red blue gold PIETERSITE gem stone Tumbled cab cabbing rough raw gemstone 73 carat PRETTY
 14 gram red blue gold PIETERSITE Tumbled cab cabbing raw 73 carat PRETTY 
 
50 cts Neon Blue Green APATITES gem stones Jewelry rough tumbled polished gemstones lots 10 grams
 50 cts Neon Blue Green APATITES Jewelry tumbled polished lots 10 grams 
 
25 carats CHRYSOBERYL gems stones Facet uncut raw rough gemstones crystals lot 1 to 2 ct jewels Nice
 25 carats CHRYSOBERYL uncut raw crystals lot 1 to 2 ct jewels Nice