Harnessing Dynamic Loading

Resourceful Code Reuse — by Dmitry Zinoviev (18 / 20)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Chapter 3 Reuse Code at Runtime (C and Python) | TOC | Getting a Taste of Remote Procedure Calls 👉

Dynamic loading is a technique of changing the code executed by a process (a running program) on the fly as the process runs. External code may be added to or removed from the process as necessary.

At first glance, dynamic loading looks like an example of self-modifying code (SMC). Self-modifying code was hyped in the 1980s as a means to implement adaptable machine learning systems that would learn by reconfiguring their data and algorithms. Another fancy application of SMC was in computer viruses that would disguise themselves to hide their presence from signature-matching antivirus software.

It was soon concluded that SMC was more of a problem than a solution. In the first place, it makes a program in memory different from the same program in a disk file, essentially inhibiting symbolic debugging. Secondly, SMC permits malicious exploits that normally modify only data buffers to alter program code as well, potentially disabling security mechanisms.

At this point, you may feel lost. Is dynamic loading a kind of self-modifying code? If it’s, is it evil? If it’s evil, would you be better off not knowing how to use it?

Sharing code is risky, but the risk is often justified.

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.