Code Protector Example source code after reverse engineering

Let's take a simple VBA function (taken from Northwind sample database) and look at the results of normal reverse engineering versus reverse engineering after protecting the file with our Code Protector.

  1. Original source code
  2. Normal reverse engineered source code
  3. Reverse engineered code after protecting the MDE with Code Protector

The original source code:

Function OpenStartup() As Boolean
Dim blnHideStartupForm As Boolean
On Error GoTo OpenStartup_Err
    If IsItAReplica() Then
         DoCmd.Close
    Else
        If (CurrentDb().Properties("StartupForm") = "Startup" Or _
            CurrentDb().Properties("StartupForm") = "Form.Startup") Then
            blnHideStartupForm = False
        Else
            blnHideStartupForm = True
        End If
        
        Forms!Startup!HideStartupForm = blnHideStartupForm    
    End If
  
OpenStartup_Exit:
    Exit Function
        
OpenStartup_Err:
    Const conPropertyNotFound = 3270
    If Err = conPropertyNotFound Then
        Forms!Startup!HideStartupForm = True
        Resume OpenStartup_Exit
    End If
End Function

Normal reverse engineered source code after being compiled to MDE format:

Function OpenStartup() As Boolean

    Dim blnHideStartupForm As Boolean
    Const conPropertyNotFound = 3270

    On Error GoTo ErrorHandler
    
    If IsItAReplica() Then
    
         DoCmd.Close
         
    Else
    
        If CurrentDb().Properties("StartupForm") = "Startup" Or _
            CurrentDb().Properties("StartupForm") = "Form.Startup" Then
            
            blnHideStartupForm = False
            
        Else
        
            blnHideStartupForm = True
            
        End If
        
        Forms("Startup").Controls("HideStartupForm") = blnHideStartupForm 
        
    End If
   
ExitRoutine:
    Exit Function
        
ErrorHandler:

    If Err = conPropertyNotFound Then
    
        Forms("Startup").Controls("HideStartupForm") = True
        Resume ExitRoutine
        
    End If
    
End Function

As you can see, by using standard reverse engineering on a compiled MDE version of Northwind, we can retrieve VBA source code that is very similar to the original.

However, after using the MDE Protector on the compiled MDE file, there are some major benefits that make the reverse engineering much less accurate.

  • Constants are removed

  • Variable names and datatypes are lost (see below - variable blnHideStartupForm:Boolean becomes Variable8:Variant)

  • After using the MDE Protector a decompiler cannot determine whether the variables that were defined by the compiler (implicit/temporary variables) are in fact real variables or not so it has to assume they are all real, explicit variables ***

*** Compilers (including the VBA compiler) make use of both explicit variables (declared by the developer) and implicit variables (declared by the compiler) in order to make everything work as it should.  By examining the "compiler junk", a decompiler can determine exactly which variables are implicit and which ones are explicit - using this information, the decompiler can then optimize the resultant source code by removing all implicit variables - this is key to making the resultant source code very accurate to the original.


Reverse engineered code after protecting the MDE with the Code Protector:

Function OpenStartup() As Boolean

    Dim Variable1 
    Dim Variable2 As Object
    Dim Variable3
    Dim Variable4
    Dim Variable5 As Object
    Dim Variable6
    Dim Variable7
    Dim Variable8
    Dim Variable9 As Object
    Dim Variable10 As Object
	
    On Error GoTo ErrorHandler
    
    Variable1 = IsItAReplica()
    
    If Variable1 = True Then
    
         DoCmd.Close
         
    Else
    
    	Set Variable2 = CurrentDb()
    	Variable3 = Variable2.Properties("StartupForm")
    	Variable4 = (Variable3 = "Startup")
    	Set Variable2 = Nothing
    	Set Variable5 = CurrentDb()
    	Variable6 = Variable5.Properties("StartupForm")
    	Variable7 = (Variable6 = "Form.Startup")
    	Set Variable5 = Nothing
    	
        If Variable4 = True Or _
            Variable7 = True Then
            
            Variable8 = False
            
        Else
        
            Variable8 = True
            
        End If
        
        Set Variable9 = Forms("Startup")
        Set Variable10 = Variable9.Controls("HideStartupForm")
        Variable10 = Variable8 
        Set Variable10 = Nothing
        Set Variable9 = Nothing
        
    End If
   
ExitRoutine:
    Exit Function
        
ErrorHandler:

    If Err = 3270 Then
    
        Set Variable9 = Forms("Startup")
        Set Variable10 = Variable9.Controls("HideStartupForm")
        Variable10 = True
        Set Variable10 = Nothing
        Set Variable9 = Nothing
        Resume ExitRoutine
        
    End If
    
End Function

As you can see, the result is much less understandable code.  A developer could then tidy this code up and optimize it but the point is that it makes the process much harder (particularly in projects of considerable size), and therefore reverse engineering/decompiling your project will become much less effective.

<< Back to main information page