2

I use a dongle to protect my executable. The dongle protects the software in two ways:

  1. inside the code with calls to read/write the dongle memory (for example to store functional data), to encrypt/decrypt data with an algorithm resident in the dongle. The encryption key is writable only.
  2. Encrypting the EXE file and using a loader that decrypts it through the dongle. If any debugger like softice is running, the software either terminates or does not start.

It would work well and make cheaper to buy the license than to crack my software and this is my only goal.

The problem is that I cannot serialize anymore! If I try, I get the following exception:

SerializationException
Source = mscorlib
Message = Unable to find assembly 'MyApp, Version=1.0.0.3, Culture=neutral, PublicKeyToken=null'.
TargetSite = System.Reflection.Assembly GetAssembly()
Stack =
    System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
    System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
    System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
    System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
    System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)
    System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
    System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
    System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)

I must use Binary Serialization due to the nature of the data to be persistent.

How can a solve this problem?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
  • This is an issue with your dongle/encryption provider and is not something that we can help you with - not least without you telling us what system you're using. – Dai May 06 '15 at 09:31
  • 1
    Also note that most "black-box" EXE encryption systems (where you just pass-in the finished EXE, rather than those that use an API) are inherently incompatible with .NET programs owing to JIT compilation. – Dai May 06 '15 at 09:33
  • I don't think it's an issue with the dongle provider. If the EXE is encrypted and compressed and the loader "expand" it in memory, probably the assembly does not exist on the disk and probably this is the reason why System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly() throw an exception. Anyway, this is just a hypothesis of mine... I think that it should be possible to walk around this, but I don't know how! For sure, I'm not the first one that use this dongle to protect the software and to need serialization... – Angelo Mascaro May 06 '15 at 09:42

1 Answers1

0

I dedicate an enormous amount of time to this problem and I got to a workaround, more than a true solution.

I share what I learned. The serialization needs to load the assembly that generated the permanent stream in order to know exactly the structure of the saved data. With "black-box" EXE encryption systems, the assembly is not available. One possible solution could be to write a custom BynaryFormatter: for sure it's not worth the effort.

The workaround is to put the classes to be serialized in a DLL that is not encrypted and then decrypted in memory at run time by the dongle. This idea derive from the suggestions that I have found for a similar problem: one wants to deserialize in application A data written from application B.