Sky Software Homepage LogicNP Software Knowledge Base And FAQ

 
Contact Product Support    SearchSearch      Subscribe to the RSS feed for this forum

HOWTO: Package the LogicNP.CryptoLicensing.dll file inside your host application

 
Subscribe to the RSS feed for this forum  Forum Index -> CryptoLicensing For .Net
View previous topic :: View next topic  
Author Message
Support



Joined: 18 Jul 2005
Posts: 731

Posted: Thu Aug 13, 2009 3:18 am    Post subject: HOWTO: Package the LogicNP.CryptoLicensing.dll file inside your host application

Deep Integration (Merging) Using Crypto Obfuscator

If you are using Crypto Obfuscator for the obfuscation and protection of your software, you can merge the LogicNP.CryptoLicensing.dll assembly in your own assembly. This enables deep integration of the licensing module by shifting all classes and code from LogicNP.CryptoLicensing.dll into your own assembly and removing references to the LogicNP.CryptoLicensing.dll assembly. This increases resistance against cracking and reverse-engineering by removing any explicit and obvious links between your software and its usage of CryptoLicensing.

When not using Crypto Obfuscator, to simplify deployment, you can add the LogicNP.CryptoLicensing.dll file as an 'Embedded Resource' in your host assembly and use the AssemblyResolve event to load the LogicNP.CryptoLicensing.dll assembly as shown in the code below:
[C#]
Code:
// Windows Forms:
// C#: The static contruction of the 'Program' class in Program.cs
// VB.Net: 'MyApplication' class in ApplicationEvents.vb (Project Settings-->Application Tab-->View Application Events)
// WPF:
// The 'App' class in WPF applications (app.xaml.cs/vb)

static Program() // Or MyApplication or App as mentioned above
{
    AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}

static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    if (args.Name.Contains("LogicNP.CryptoLicensing"))
    {
        // Looking for the LogicNP.CryptoLicensing.dll assembly, load it from our own embedded resource
        foreach (string res in Assembly.GetExecutingAssembly().GetManifestResourceNames())
        {
            if(res.EndsWith("LogicNP.CryptoLicensing.dll"))
            {
                Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(res);
                byte[] buff = new byte[s.Length];
                s.Read(buff, 0, buff.Length);
                return Assembly.Load(buff);
            }
        }
    }
    return null;
}

[VB.NET]
Code:
' Windows Forms:
' C#: The static construction of the 'Program' class in Program.cs
' VB.Net: 'MyApplication' class in ApplicationEvents.vb (Project Settings-->Application Tab-->View Application Events)
' WPF: The 'App' class in WPF applications (app.xaml.cs/vb)

Partial Friend Class MyApplication 'Or Program or App as mentioned above
  Shared Sub New()
      AddHandler AppDomain.CurrentDomain.AssemblyResolve, New ResolveEventHandler(AddressOf CurrentDomain_AssemblyResolve)
  End Sub

  Shared Function CurrentDomain_AssemblyResolve(ByVal sender As System.Object, ByVal args As ResolveEventArgs) As Assembly

      If (args.Name.Contains("LogicNP.CryptoLicensing")) Then
          ' Looking for the LogicNP.CryptoLicensing.dll assembly, load it from our own embedded resource
          Dim res As String

          For Each res In Assembly.GetExecutingAssembly().GetManifestResourceNames()
             
              If (res.EndsWith("LogicNP.CryptoLicensing.dll")) Then

                  Dim s As Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(res)
                  Dim buff As Byte() = New Byte(s.Length) {}
                  s.Read(buff, 0, buff.Length)
                  Return Assembly.Load(buff)
              End If
         
          Next

      End If

      Return Nothing
  End Function

End Class
Back to top
Display posts from previous:   
Forum Index -> CryptoLicensing For .Net All times are GMT
Page 1 of 1

 
Jump to:  


Powered by phpBB © 2001, 2005 phpBB Group