How to write serial number to executable file?

I am trying to protect the application only from a specific USB drive. I have a code to get the serial number from the device, but the only way to do this work the way I want is to manually encode the serial number in binary format. Is there a way to make a stub application that modifies an existing binary to insert a serial number into it after compiling it? I have seen this in C ++ in the past, but it was a long time ago, and I cannot remember how we did it then.

+7
security c # usb
source share
4 answers

Keeping it in an assembly is a bad idea. Here is what I would do (and have done similar in the past):

  • Be sure to sign your builds.
  • Create an XML document containing your licensing information - in your case, the serial number of the USB device.
  • Use the SignedXml library in .NET (implements XMLDSIG) to sign the licensing XML document containing the serial number. You will use the same private key that is used to sign the assembly.
  • When the application starts, it checks that the signature of the XML file is valid using the public key with which it was signed (and built into the assembly).

Obviously, you are not sending your private key, so if the application should generate the XML configuration file itself (and not the file that you send to the user), you will need to implement a web service.

+8
source share

I do not know, but that did not stop me from answering earlier.

Maybe find out where you want to save the SN in the executable (it should be only one place, right?) And just consider the executable as a giant binary, and use the stub to paste it where it needs to go?

0
source share

You might want to get a separate USB license key, such as these:

http://www.bhphotovideo.com/c/buy/USB-License-Keys/ci/12454/N/4294550039

???

0
source share

Why does someone want to save something inside an executable file. If you plan to sign the executable file for the distribution, changing the executable file would somehow violate the signing and saving something in the binary file to the executable file, this will not prevent someone from extracting the value from the executable file.

The best you can do is save the serial number in a file, registry, or other place, and then encrypt it so that it cannot be changed without breaking it. I use the library that comes with the Licensed Safe from a fairly new company called SpearmanTech. You can use your library to store encrypted values ​​in the .NET machine.config file in encrypted form, so it cannot be faked. This way you can extract information from the .config file at application startup.

You are writing a .NET application in C ++ or native C ++, and in any case, you must be able to communicate with the .NET platform for this solution to work.

I would look at their product at http://www.spearmantech.com . Hope this works for you.

0
source share

All Articles