A method of protecting a software program from unauthorized modification,
and a system for practicing the method. The method utilizes
self-protecting software code. Armed internally with self-defensive
mechanisms, a self-protecting software program is tamper-resistant.
Whenever its integrity is compromised, a self-protecting software program
may become unusable due to software program crashes or other errors, or
may generate subtle errors that do not immediately result render the
program unusable but still result in incorrect software program
execution. A self-protecting software program also may be able to repair
itself to restore the integrity of its damaged code. The system comprises
a computer program for automatically adding self-protection features to a
software program.