From Glitchdata
Jump to: navigation, search


In computer programming, a self-relocating program is a program that relocates its own address-dependent instructions and data when run, and is therefore capable of being loaded into memory at any address.[1] In most cases, self-relocating code is also a form of self-modifying code.


Self-relocation is similar to the relocation process employed by the linker-loader when a program is copied from external storage into main memory; the difference is that it is the loaded program itself rather than the loader in the operating system or shell that performs the relocation. As an example, self-relocation is often employed in the early stages of bootstrapping operating systems on architectures like IBM PC compatibles, where lower-level chain boot loaders (like the Master Bootstrap Record, Volume Boot Record and initial boot stages of operating systems such as DOS) move themselves out of place in order to load the next stage into memory. Under DOS, self-relocation was sometimes also used by more advanced drivers and TSRs loading themselves "high" more effectively than possible for the operating system's built-in loaders in order to maximize the memory available for applications.

Self-relocation typically happens at load-time, sometimes also when changing the program's configuration at a later stage during runtime.[2][3]

As an extreme example of self-relocation it is possible to construct a computer program so that it does not stay at a fixed address in memory, even as it executes. The Apple Worm[4] is a dynamic self-relocator.

See also


  1. Template:Cite book
  2. Template:Citation (NB. FreeKEYB is a Unicode-based dynamically configurable driver supporting most keyboard layouts, code pages, and country codes. Utilizing an off-the-shelf macro assembler as well as a framework of automatic pre- and post-processing analysis tools to generate dependency and code morphing meta data to be embedded into the executable file alongside the binary code and a self-discarding, relaxing and relocating loader, the driver supports to be variously loaded and install itself as TSR or device driver and it implements advanced self-relocation techniques (including into normal DOS memory, UMBs, unused video memory, or raw memory also utilizing program segment prefix overloading and environment segment recombination) and byte-level granular dynamic dead code elimination at load-time as well as self-modifying code and reconfigurability at run-time to minimize its memory footprint depending on the hardware, operating system and driver configuration as well as the selected feature set and locale.)
  3. Template:Citation
  4. Template:Cite journal