The invention discloses a method and apparatus for protecting
application security based on a
virtual machine. The method comprises the following steps: obtaining a code of an application, and judging whether each function in the code contains a preset protection identifier; if the function contains the preset protection identifier, compiling the function into an
assembly instruction that is executed on the basis of the
virtual machine; and linking execution logic of the
virtual machine with the
assembly instruction that is executed on the basis of the virtual
machine to generate a target program of the application. In the scheme, the code in the function containing the preset protection identifier is virtually compiled through an operation environment of the
assembly instruction corresponding to the application self-defined by the virtual
machine, the entire virtual compilation process is irreversible and cannot be restored, therefore even if decompilation is performed on the virtualized assembly instruction, the obtained code is not the original code of the application, and thus the security of the code of the application is protected.