Three ways in which creators of digital works may protect their code from functional-purpose copying are trade secret, patent, and copyright doctrines. Trade secret law protects hidden parts of a work from unauthorized access, provided that the owner of the work takes reasonable measures to protect it. In the case of software, taking reasonable measures to protect the underlying source code means transforming the source code into binary code before distributing the product in the market. Reverse-engineering an unpatented work that one has legitimately acquired, as through purchase, in order to uncover its trade secret, is perfectly legal under trade secret doctrine. If the creator of a work is able to obtain a patent on some part of the code, the effect of the patent will be to make reverse engineering of the patented part illegal.
Patent law seeks to promote and protect functional innovation.
Because source code essentially functions as a machine built of verbal and numerical instructions rather than moving parts, it's possible to obtain a patent on a set of source code instructions that meet the patentability requirements of novelty, non-obviousness, and utility. However, even if the copyright owner cannot obtain a patent, he can still protect himself from certain effects of reverse engineering by means of copyright law. Copyright law serves to protect a work from unauthorized duplication with the goal of preventing usurpation of the copyright owner's market by those who would compete with him in the distribution of his work. Both source code and object code are protected by copyright doctrine. Because it's impossible to reverse engineer object code without first creating a copy of it on a computer, one cannot technically reverse engineer software without infringing its copyright.