C# Keygen Error

Post here messages if you have any problems with working of Enigma Protector
samsonite131
Posts: 30
Joined: Tue Oct 15, 2013 10:35 pm

C# Keygen Error

Post by samsonite131 »

I'm having a problem getting the C# keygen to work.

I'm using this project:
\The Enigma Protector\Examples\KeyGen\C# (.NET)\

When KG_GenerateRegistrationKey is called, I get an exception error:
System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at Enigma_KeyGen_IDE.KG_GenerateRegistrationKey(TKeyGenParams& kg)
at Test.frmMain.btnGenerate_Click(Object sender, EventArgs e) in C:\The Enigma Protector\Examples\KeyGen\C# (.NET)\frmMain.cs:line 1102
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
BTW, I'm Using Visual C# 2010 Express.

And Enigma's keygen.dll is located in the same directory as the executable.
Enigma
Site Admin
Posts: 2945
Joined: Wed Aug 20, 2008 2:24 pm

Re: C# Keygen Error

Post by Enigma »

Hi, just set the CPU type to x86 when you compile the keygen.exe in Visual Studio.
samsonite131
Posts: 30
Joined: Tue Oct 15, 2013 10:35 pm

Re: C# Keygen Error

Post by samsonite131 »

Enigma wrote:Hi, just set the CPU type to x86 when you compile the keygen.exe in Visual Studio.
Thanks, that worked. But, now, I get a new error message after clicking on Generate button:

EP_ERROR_PRIVATEKEYISNOTSET

But, this can't be true. I can print out the private key, and it's not empty.

Code: Select all

 // debug
 MessageBox.Show( kg.PrivateKey, "kg.PrivateKey", MessageBoxButtons.OK, MessageBoxIcon.Information );

 // Generate reg. key
 uint dwResult = Enigma_KeyGen_IDE.KG_GenerateRegistrationKey(ref kg);
samsonite131
Posts: 30
Joined: Tue Oct 15, 2013 10:35 pm

Re: C# Keygen Error

Post by samsonite131 »

Oops, sorry, that was for NET Framework 4.0.


I must use C# keygen for NET Framework 3.5. This is the important one for me. (although, it would be nice to see both working for future webserver upgrades)

Now, when I re-compile and call GenerateRegistrationKey, I get a new exception error:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Enigma_KeyGen_IDE.KG_GenerateRegistrationKey(TKeyGenParams& kg)
at Test.frmMain.btnGenerate_Click(Object sender, EventArgs e) in C:\The Enigma Protector\Examples\KeyGen\C# (.NET)\frmMain.cs:line 1130
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
samsonite131
Posts: 30
Joined: Tue Oct 15, 2013 10:35 pm

Re: C# Keygen Error

Post by samsonite131 »

I have compiled C# Keygen for all given NET frameworks. They all crash or give invalid results:

NET Framework 2.0 -> crash
NET Framework 3.0 -> crash
NET Framework 3.5 -> crash
NET Framework 3.5 Client Profile -> crash
NET Framework 4.0 -> EP_ERROR_PRIVATEKEYISNOTSET
NET Framework 4.0 Client Profile -> EP_ERROR_PRIVATEKEYISNOTSET

Platform: x86
keygen.dll in same directory as executable

Using Visual C# 2010 Express.
Running Windows 7 Pro SP1, 64-bit.
The Enigma Protector x64 4.00
Alec
Posts: 82
Joined: Thu Feb 20, 2014 9:35 am

Re: C# Keygen Error

Post by Alec »

Hi. If you are using The Enigma Protector x64 then platform must be set to x64 as well in your Visual Studio project settings.
samsonite131
Posts: 30
Joined: Tue Oct 15, 2013 10:35 pm

Re: C# Keygen Error

Post by samsonite131 »

Alec wrote:Hi. If you are using The Enigma Protector x64 then platform must be set to x64 as well in your Visual Studio project settings.
I understand, but I don't think that's my problem. The SDK provides two keygen dlls, one 32-bit, the other 64-bit.
I have tried to compile both 32-bit and 64-bit projects. Neither project works for me.

Can you test to see if any C# Keygen project compiles, runs, and generates a valid regkey using Visual C# 2010 Express?

Project: \KeyGen\C# (.NET)
Platform: x86
DLL: keygen.dll
Result: crash for all NET frameworks

Project: \KeyGen\C# x64 (.NET)
Platform: x64
DLL: keygen64.dll
Result: all return EP_ERROR_PRIVATEKEYISNOTSET.
samsonite131
Posts: 30
Joined: Tue Oct 15, 2013 10:35 pm

Re: C# Keygen Error

Post by samsonite131 »

Well, I hope someone can fix this, because this is what I call a show stopper.
If the C# Keygen crashes on my computer, then it will crash on my webserver.
And if it crashes on my webserver, then I cannot use your product.
My webserver specifically uses compiled C# assembly DLLs.
Enigma
Site Admin
Posts: 2945
Joined: Wed Aug 20, 2008 2:24 pm

Re: C# Keygen Error

Post by Enigma »

Hi, we have finally investigated this issue. There are really problems with the keys generator API declarations for C#.
Everything you need is to change the declaration of EncryptedSections from

Code: Select all

public byte[] EncryptedSections;
to

Code: Select all

public bool[] EncryptedSections;
Fixed versions are in the post attachment.
Attachments
keygen_api.zip
(9.3 KiB) Downloaded 679 times
Alec
Posts: 82
Joined: Thu Feb 20, 2014 9:35 am

Re: C# Keygen Error

Post by Alec »

Also we have found another problem regarding the keygen sample in C#, fixed *.cs are in the attached file

the reason was here

Code: Select all

char[] keybuffer = new char[2048];
keybuffer.Initialize();
kg.Key = keybuffer.ToString();
kg.KeyLen = keybuffer.Length;
it must be the string

Code: Select all

kg.Key = new string('\0', 2048);
kg.KeyLen = kg.Key.Length;
Attachments
KeyGen_net_fix.zip
(39.82 KiB) Downloaded 771 times
Post Reply