Add Original SDK

This commit is contained in:
2026-05-06 07:47:36 +02:00
parent 2915e04380
commit 0ed627517a
674 changed files with 89334 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,58 @@
using System.Reflection;
using System.Runtime.CompilerServices;
//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]
//
// In order to sign your assembly you must specify a key to use. Refer to the
// Microsoft .NET Framework documentation for more information on assembly signing.
//
// Use the attributes below to control which key is used for signing.
//
// Notes:
// (*) If no key is specified, the assembly is not signed.
// (*) KeyName refers to a key that has been installed in the Crypto Service
// Provider (CSP) on your machine. KeyFile refers to a file which contains
// a key.
// (*) If the KeyFile and the KeyName values are both specified, the
// following processing occurs:
// (1) If the KeyName can be found in the CSP, that key is used.
// (2) If the KeyName does not exist and the KeyFile does exist, the key
// in the KeyFile is installed into the CSP and used.
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
// When specifying the KeyFile, the location of the KeyFile should be
// relative to the project output directory which is
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
// located in the project directory, you would specify the AssemblyKeyFile
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
// documentation for more information on this.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]

View File

@@ -0,0 +1,548 @@
// !! We strongly recommend that you read the "readme.txt" file in the sample code folder.
// !! It contains important instructions on how to use the sample code
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices; // so we can marshal our structures in dapf.cs
namespace dapfTest
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox machineIDText;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox expdayText;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox expmonthText;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox expyearText;
private GroupBox groupBox2;
private Label label9;
private TextBox maxDaysText;
private Button demoSoftwareKey;
public string AppName = "dapfTest";
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.dapfFile = new System.Windows.Forms.TextBox();
this.programDongle = new System.Windows.Forms.Button();
this.programDongleMod = new System.Windows.Forms.Button();
this.lockSoftware = new System.Windows.Forms.Button();
this.tempSoftwareKey = new System.Windows.Forms.Button();
this.encryptShellData = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.expyearText = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.expmonthText = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.expdayText = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.machineIDText = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.label9 = new System.Windows.Forms.Label();
this.maxDaysText = new System.Windows.Forms.TextBox();
this.demoSoftwareKey = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(416, 16);
this.label1.TabIndex = 0;
this.label1.Text = "Full path of dapf file:";
//
// dapfFile
//
this.dapfFile.Location = new System.Drawing.Point(16, 40);
this.dapfFile.Name = "dapfFile";
this.dapfFile.Size = new System.Drawing.Size(344, 20);
this.dapfFile.TabIndex = 1;
//
// programDongle
//
this.programDongle.Location = new System.Drawing.Point(84, 88);
this.programDongle.Name = "programDongle";
this.programDongle.Size = new System.Drawing.Size(208, 23);
this.programDongle.TabIndex = 2;
this.programDongle.Text = "Program Dongle";
this.programDongle.Click += new System.EventHandler(this.programDongle_Click);
//
// programDongleMod
//
this.programDongleMod.Location = new System.Drawing.Point(84, 128);
this.programDongleMod.Name = "programDongleMod";
this.programDongleMod.Size = new System.Drawing.Size(208, 23);
this.programDongleMod.TabIndex = 3;
this.programDongleMod.Text = "Program Dongle with modification";
this.programDongleMod.Click += new System.EventHandler(this.programDongleMod_Click);
//
// lockSoftware
//
this.lockSoftware.Location = new System.Drawing.Point(84, 168);
this.lockSoftware.Name = "lockSoftware";
this.lockSoftware.Size = new System.Drawing.Size(208, 23);
this.lockSoftware.TabIndex = 4;
this.lockSoftware.Text = "Lock Software";
this.lockSoftware.Click += new System.EventHandler(this.lockSoftware_Click);
//
// tempSoftwareKey
//
this.tempSoftwareKey.Location = new System.Drawing.Point(64, 88);
this.tempSoftwareKey.Name = "tempSoftwareKey";
this.tempSoftwareKey.Size = new System.Drawing.Size(208, 23);
this.tempSoftwareKey.TabIndex = 5;
this.tempSoftwareKey.Text = "Create Software Key";
//
// encryptShellData
//
this.encryptShellData.Location = new System.Drawing.Point(84, 208);
this.encryptShellData.Name = "encryptShellData";
this.encryptShellData.Size = new System.Drawing.Size(208, 23);
this.encryptShellData.TabIndex = 6;
this.encryptShellData.Text = "Encrypt Shell Data Files";
this.encryptShellData.Click += new System.EventHandler(this.encryptShellData_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.expyearText);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.expmonthText);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.expdayText);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.machineIDText);
this.groupBox1.Controls.Add(this.tempSoftwareKey);
this.groupBox1.Location = new System.Drawing.Point(16, 256);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(336, 128);
this.groupBox1.TabIndex = 7;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Temporary Software Key";
//
// expyearText
//
this.expyearText.Location = new System.Drawing.Point(240, 56);
this.expyearText.Name = "expyearText";
this.expyearText.Size = new System.Drawing.Size(32, 20);
this.expyearText.TabIndex = 13;
this.expyearText.Text = "yyyy";
//
// label5
//
this.label5.Location = new System.Drawing.Point(224, 56);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(8, 20);
this.label5.TabIndex = 12;
this.label5.Text = "/";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// expmonthText
//
this.expmonthText.Location = new System.Drawing.Point(184, 56);
this.expmonthText.Name = "expmonthText";
this.expmonthText.Size = new System.Drawing.Size(32, 20);
this.expmonthText.TabIndex = 11;
this.expmonthText.Text = "mm";
//
// label4
//
this.label4.Location = new System.Drawing.Point(168, 56);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(8, 20);
this.label4.TabIndex = 10;
this.label4.Text = "/";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// expdayText
//
this.expdayText.Location = new System.Drawing.Point(128, 56);
this.expdayText.Name = "expdayText";
this.expdayText.Size = new System.Drawing.Size(32, 20);
this.expdayText.TabIndex = 9;
this.expdayText.Text = "dd";
//
// label3
//
this.label3.Location = new System.Drawing.Point(24, 56);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(100, 20);
this.label3.TabIndex = 8;
this.label3.Text = "Expiry Date:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label2
//
this.label2.Location = new System.Drawing.Point(24, 24);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(100, 20);
this.label2.TabIndex = 7;
this.label2.Text = "Machine ID:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// machineIDText
//
this.machineIDText.Location = new System.Drawing.Point(128, 24);
this.machineIDText.Name = "machineIDText";
this.machineIDText.Size = new System.Drawing.Size(184, 20);
this.machineIDText.TabIndex = 6;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.label9);
this.groupBox2.Controls.Add(this.maxDaysText);
this.groupBox2.Controls.Add(this.demoSoftwareKey);
this.groupBox2.Location = new System.Drawing.Point(19, 400);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(336, 99);
this.groupBox2.TabIndex = 14;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Demo Software Key";
//
// label9
//
this.label9.Location = new System.Drawing.Point(24, 24);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(100, 20);
this.label9.TabIndex = 7;
this.label9.Text = "Max Days:";
this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// maxDaysText
//
this.maxDaysText.Location = new System.Drawing.Point(128, 24);
this.maxDaysText.Name = "maxDaysText";
this.maxDaysText.Size = new System.Drawing.Size(184, 20);
this.maxDaysText.TabIndex = 6;
//
// demoSoftwareKey
//
this.demoSoftwareKey.Location = new System.Drawing.Point(61, 59);
this.demoSoftwareKey.Name = "demoSoftwareKey";
this.demoSoftwareKey.Size = new System.Drawing.Size(208, 23);
this.demoSoftwareKey.TabIndex = 5;
this.demoSoftwareKey.Text = "Create Demo Template";
this.demoSoftwareKey.Click += new System.EventHandler(this.demoSoftwareKey_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(376, 523);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.encryptShellData);
this.Controls.Add(this.lockSoftware);
this.Controls.Add(this.programDongleMod);
this.Controls.Add(this.programDongle);
this.Controls.Add(this.dapfFile);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox dapfFile;
private System.Windows.Forms.Button programDongle;
private System.Windows.Forms.Button programDongleMod;
private System.Windows.Forms.Button lockSoftware;
private System.Windows.Forms.Button tempSoftwareKey;
private System.Windows.Forms.Button encryptShellData;
/* The sample code contains 5 functions. You will not need to use all these functions in your code.
Just use which ever functions are most appropriate and customise in your own way. The sample code
is just a guide.
There are two methods to loading a DAPF file. These are shown in the first two functions
programDongle_Click and programDongleMod_Click:
programDongle_Click: we load the DAPF file from disk and get a handle and use it "as is" using the API
call LoadDAPFFromFile. You can make some limited changes to overwrite the default
behaviour by using API flags.
programDongleMod_Click: we load the DAPF file from disk and load into structures. We can then modify the
DAPF settings by modifying this structure. This method uses the API calls
ReadDAPFEx and LoadDAPF.
The other functions use the first method (as it is simpler) but you can use the second method instead if
you prefer.
Note - an alternative to using the programDongleMod_Click technique is to modify the DAPF file on disk
and then use the programDongle_Click technique. To modify a binary DAPF you would use the binary structures
that are defined in dapf.h. To modify JSON DAPF you would need to use a JSON parser.
lockSoftware_Click : locks software (protect it) to a dongle as specified by the DAPF file.
encryptShellData_Click: encrypts the shell data files specified in the DAPF file (this is used with encrypting
data file if you use the Shell Method with "Data File Encryption" enabled).
tempSoftwareKey_Click: creates a Temporary Software Key based on the DAPF file and settings the user has entered.
demoSoftwareKey_Click: creates a Demo Software Key Template based on the DAPF file and settings the user has entered.
*/
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
// load a DAPF file from disk and program the dongle as specified by the DAPF file
private void programDongle_Click(object sender, System.EventArgs e)
{
IntPtr dapfHandle;
int err_code;
uint dongle_number;
// load DAPF from File into memory
dapfHandle = DinkeyAdd.LoadDAPFFromFile(dapfFile.Text, out err_code);
if (dapfHandle == IntPtr.Zero)
{
MessageBox.Show(DinkeyAdd.GetLastMessage(), AppName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
// program dongle as specified by the DAPF file
err_code = DinkeyAdd.AddProtection(dapfHandle, DinkeyAdd.ACTION_PROGRAM_DONGLE, 0, 0, out dongle_number);
// Unload DAPF from memory
DinkeyAdd.UnloadDAPF(ref dapfHandle);
// display message (error or success)
MessageBox.Show(DinkeyAdd.GetLastMessage(), AppName, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
// load a DAPF file from disk, modify it in memory and then program the dongle
private void programDongleMod_Click(object sender, System.EventArgs e)
{
IntPtr dapfHandle;
int dummy1, dummy2, err_code;
uint dongle_number;
DINKEYINFO DinkeyInfo;
LICENCEINFO[] LicenceInfo;
FILEINFO[] FileInfo;
ALGORITHM[] Algorithms;
DATAFILEENC[] DataFileEnc;
// in this case we need to read the DAPF into our structures, so that the DAPF values can be modified
err_code = DinkeyAdd.ReadDAPFEx(dapfFile.Text, out DinkeyInfo, out LicenceInfo, out FileInfo, out Algorithms, out DataFileEnc, out dummy1, out dummy2);
if (err_code != 0)
{
MessageBox.Show(DinkeyAdd.GetLastMessage(), AppName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
// patch new values
LicenceInfo[0].Features = 12345;
LicenceInfo[0].Execs = 100;
LicenceInfo[0].LicenceName = "fred";
// get DAPF handle
dapfHandle = DinkeyAdd.LoadDAPF(DinkeyInfo, LicenceInfo, FileInfo, Algorithms, DataFileEnc, out err_code);
if (dapfHandle == IntPtr.Zero)
{
MessageBox.Show(DinkeyAdd.GetLastMessage(), AppName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
// program dongle
err_code = DinkeyAdd.AddProtection(dapfHandle, DinkeyAdd.ACTION_PROGRAM_DONGLE, 0, 0, out dongle_number);
// Unload DAPF from memory
DinkeyAdd.UnloadDAPF(ref dapfHandle);
// display message (error or success)
MessageBox.Show(DinkeyAdd.GetLastMessage(), AppName, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
// load a DAPF file from disk and protect the files specified
// (in practice it is better to protect the files one at a time and output messages as you go along, similar to DinkeyAdd.exe)
// In this example we specify the flag to overwrite any existing output file that might exist.
private void lockSoftware_Click(object sender, System.EventArgs e)
{
IntPtr dapfHandle;
int err_code;
uint dummy;
// load DAPF from File into memory
dapfHandle = DinkeyAdd.LoadDAPFFromFile(dapfFile.Text, out err_code);
if (dapfHandle == IntPtr.Zero)
{
MessageBox.Show(DinkeyAdd.GetLastMessage(), AppName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
// protect all the files listed in the DAPF file
err_code = DinkeyAdd.AddProtection(dapfHandle, DinkeyAdd.ACTION_PROTECT_SOFTWARE, -1, DinkeyAdd.FLAGS_OVERWRITE_OUTPUT, out dummy);
// Unload DAPF from memory
DinkeyAdd.UnloadDAPF(ref dapfHandle);
// display message (error or success)
MessageBox.Show(DinkeyAdd.GetLastMessage(), AppName, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
// load a DAPF file from disk and encrypt the shell data files specified
// (in practice it is better to encrypt the files one at a time and output messages as you go along, similar to DinkeyAdd.exe)
// In this example we specify the flag to overwrite any existing output file that might exist.
private void encryptShellData_Click(object sender, System.EventArgs e)
{
IntPtr dapfHandle;
int err_code;
// load DAPF from File into memory
dapfHandle = DinkeyAdd.LoadDAPFFromFile(dapfFile.Text, out err_code);
if (dapfHandle == IntPtr.Zero)
{
MessageBox.Show(DinkeyAdd.GetLastMessage(), AppName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
// encrypt all the shell data files listed in the DAPF file
err_code = DinkeyAdd.EncryptShellDataFiles(dapfHandle, -1, DinkeyAdd.FLAGS_OVERWRITE_OUTPUT);
// Unload DAPF from memory
DinkeyAdd.UnloadDAPF(ref dapfHandle);
// display message (error or success)
MessageBox.Show(DinkeyAdd.GetLastMessage(), AppName, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
// load a DAPF file from disk and create a Temporary Software Key using the info that the user entered
private void tempSoftwareKey_Click(object sender, System.EventArgs e)
{
IntPtr dapfHandle;
int err_code;
TEMP_SWKEY_INFO swkey_info = new TEMP_SWKEY_INFO();
// load DAPF from File into memory
dapfHandle = DinkeyAdd.LoadDAPFFromFile(dapfFile.Text, out err_code);
if (dapfHandle == IntPtr.Zero)
{
MessageBox.Show(DinkeyAdd.GetLastMessage(), AppName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
// fill out the SWKEY structure from the values the user entered
swkey_info.size = Marshal.SizeOf(typeof(TEMP_SWKEY_INFO));
swkey_info.machineID = Convert.ToUInt32(machineIDText.Text, 16);
swkey_info.expiry_day = Convert.ToInt32(expdayText.Text, 10);
swkey_info.expiry_month = Convert.ToInt32(expmonthText.Text, 10);
swkey_info.expiry_year = Convert.ToInt32(expyearText.Text, 10);
// !!!! in this case we just choose Pro Plus. You could load the DAPF file into structures and see which model is selected.
// If there is more than one model selected you can ask the customer to choose which model they want.
swkey_info.dongle_model = DinkeyAdd.SWKEY_MODEL_PRO_PLUS;
swkey_info.dongle_number = 0;
// attempt to create the Temporary Software Key
err_code = DinkeyAdd.CreateTempSoftwareKey(dapfHandle, swkey_info, 0);
// Unload DAPF from memory
DinkeyAdd.UnloadDAPF(ref dapfHandle);
// display message (error or success)
MessageBox.Show(DinkeyAdd.GetLastMessage(), AppName, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
private void demoSoftwareKey_Click(object sender, EventArgs e)
{
IntPtr dapfHandle;
int err_code;
DEMO_SWKEY_INFO swkey_info = new DEMO_SWKEY_INFO();
// load DAPF from File into memory
dapfHandle = DinkeyAdd.LoadDAPFFromFile(dapfFile.Text, out err_code);
if (dapfHandle == IntPtr.Zero)
{
MessageBox.Show(DinkeyAdd.GetLastMessage(), AppName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
// fill out the SWKEY structure from the values the user entered
swkey_info.size = Marshal.SizeOf(typeof(DEMO_SWKEY_INFO));
swkey_info.max_days = Convert.ToInt32(maxDaysText.Text, 10);
// !!!! in this case we just choose the default model (assuming you only selected one in the DAPF file).
// If you want to specify more than one model then OR the flags together. e.g. DinkeyAdd.SWKEY_BITMAP_PRO_LITE | DinkeyAdd.SWKEY_BITMAP_PRO_PLUS
swkey_info.models = DinkeyAdd.SWKEY_BITMAP_DEFAULT;
// attempt to create the Temporary Software Key
err_code = DinkeyAdd.CreateDemoSoftwareKeyTemplate(dapfHandle, swkey_info, 0);
// Unload DAPF from memory
DinkeyAdd.UnloadDAPF(ref dapfHandle);
// display message (error or success)
MessageBox.Show(DinkeyAdd.GetLastMessage(), AppName, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,50 @@
dapfTest - sample code to call DinkeyAdd Module in C#
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This project is written in Visual Studio 2002 but will work in more recent
versions of Visual Studio (they will upgrade the Project to the latest version.
If prompted you should also upgrade the .NET framework the project requires).
For users of Visual Studio 2005 or higher, the default setting to projects is to
compile for the Target Platform "Any". This means that on 32-bit Windows, your
code will run as 32-bit code (and needs to call DinkeyAdd32.dll) and under 64-bit
Windows your code will run as 64-bit code (and needs to call DinkeyAdd64.dll).
The sample code works this out automatically. If you select the target platform as "x86"
then it will always be 32-bit and so you only need to use DinkeyAdd32.dll. If you
select "x64" then your code will be 64-bit and you only need to use DinkeyAdd64.dll.
The main source files in the project are:
dapf.cs - the source file contains declarations of our API. We automatically
work out whether your code is running in 32-bit or 64-bit and load
the appropriate DinkeyAdd module.
Form1.cs - this is the sample code giving an example on how you can call our API.
It contains 5 functions. Just use which ever functions are most appropriate
and customise in your own way.
The best approach is to compile the sample code and see how it works and then to take
the appropriate code and apply it to your own project. You should include the dapf.cs
file in your project and use/modify which ever functions from Form1.cs you feel are
appropriate. The dapf.cs file should not be modified.
The sample code is just a guide. As none of the parameters are security sensitive then
there is no need to implement strong security in calling DinkeyAdd.
Make sure you remember to do the following when creating your own project:
1) Insert the following namespaces in your code file:
using System.Runtime.InteropServices;
2) Insert the dapf.cs file in your project.
3) You need to put DinkeyAdd32.dll and/or DinkeyAdd64.dll into the folder that
contains dapfTest. Otherwise the System.DllNotFoundException error will appear
when you run dapfTest.
Notes on Debugging 64-bit Code
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When you use the 64-bit module (DinkeyAdd64.dll) the anti-debug code is so strong
that if you are debugging your code, after calling our API then it will crash with
an SEH exception. There are no debug modules for DinkeyAdd so you will have to find
other ways of debugging your code (for example taking out the call altogether).

View File

@@ -0,0 +1,552 @@
// !! this file should not be modified
// DAPF file is in the following format:
// DINKEYINFO
// LICENCEINFO (however many are needed)
// FILEINFO (however many are needed)
// ALGORITHM (however many are needed)
// DATAFILEENC (however many are needed)
using System;
using System.Runtime.InteropServices; // so we can marshal the structures as a block of memory
using System.Text; // for StringBuilder class for GetLastMessage API
// *********** define structures that make up the DAPF file *******************
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi, Pack=1)]
public struct DINKEYINFO
{
public byte Header1; // should be set to "DAPF"
public byte Header2;
public byte Header3;
public byte Header4;
public int Version; // version of this structure. Currently 9.
public int SelectedModels; // BIT0 = Dinkey Pro Lite, BIT1 = Dinkey Pro Plus, BIT2 = Dinkey Pro Net etc...
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=12)]
public string ProdCode;
public int PerLicence; // 1 = per licence, 0 = per product (default)
public int MaxNetUsers; // product net users, unlimited = -1, no entry = -2
public int RangeSettings; // 0 = any number, 1 = dongle in computer, 2 = range
public uint RangeMin;
public uint RangeMax;
public int NumLicences; // number of LICENCEINFO structures in this DAPF file
public int NumProgs; // number of FILEINFO structures in this DAPF file
public int NumAlgs;
public int DataSizeType; // 1 = set the zero data size, 0 = use file to initialise data area
public int ZeroDataSize; // size of the data area area in bytes
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string DataFile; // path to data file (0 = no data file)
public int DataAreaSize; // file size in bytes, -1 = file not found
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string ShellSuccessMsg; // Shell Method messages...
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string ShellNoDongleMsg;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string ShellExpiryDateMsg;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string ShellExpiryExecsMsg;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string ShellWarnDateMsg;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string ShellWarnExecsMsg;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string ShellNetUserLimitMsg;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string ShellOtherErrorMsg;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string ShellBackgroundMsg;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string NetNoServerMsg;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=12)]
public byte[] rwalg; // coded form of rw algorithm (0 = no algorithm)
public int SecOptions; // BIT0: DRIS encryption, BIT1: Data encryption, BIT2: Data enc with alg, BIT3: only secure update codes
public byte SecDRISEncKey1; // DRIS encryption parameters
public byte SecDRISEncKey2;
public byte SecDRISEncKey3;
public byte Ignored1; // this byte is ignored
public byte SecDataEncKey1; // API Data encryption parameters
public byte SecDataEncKey2;
public byte SecDataEncKey3;
public byte Ignored2; // this byte is ignored
public int ProtectionType; // 0 = software + dongle, 1 = dongle only, 2 = program only
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=12)]
public string DataEncKeyProdCode; // Alternative Product Code used to generate internal encryption keys. Normally set to 0.
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string Notes; // user-defined notes
public int LockDongle; // 0 = don't lock (default), 1 = lock dongle to user's computer
public int Reserved1; // must be 0
public int Reserved2; // must be 0
public int AdvancedOptions; // BIT0 = do not allow usb-over-network for non-Net dongles, BIT1 = do not check for Software Key at Runtime.
public int NumDataFileEnc; // Number of data files in our encryption list
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi, Pack=1)]
public struct LICENCEINFO
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string LicenceName;
public int MaxDays; // -1 = no limit
public int ExpiryDay; // -1 = no limit, 0 = no change
public int ExpiryMonth;
public int ExpiryYear;
public int Execs; // -1 = no limit
public int ExecsWarn; // 0 = no warning (just for Shell method)
public int DaysWarn; // 0 = no warning (just for Shell method)
public uint Features;
public int LicenceNetUsers; // unlimited = -1 (-2 = not needed (this is for display only))
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi, Pack=1)]
public struct FILEINFO
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string InputName; // input file (full path)
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string OutputName; // output file/folder
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string CallingProg; // calling program name
public int LicenceIndex; // index (of licence) in the LicenceInfo structure (1-based index. 0 = no selection)
public int Method; // 0-api, 1-shell, 2-shell & api
public int ShellFlags; // same bit flag values as in dris. i.e. 1 = DEC_ONE_EXEC, 4 = START_NET_USER
public int BackGround; // 0=no background, 1=1min, 2=5min, 3=10min, 4=30min, 5=60min
public int OtherShellOptions; // BIT0 = Shell Data Encryption is enabled, BIT1: Extra Anti-Debug is disabled, BIT2: Extra Anti-Piracy is disabled
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string EncFileList; // files (or file types) that the Shell-protected program will treat as encrypted (separated by ':')
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string ExceptList; // files (or file types) that are exceptions to the above list (separated by ':')
public int ExtraAntiPiracy; // 0 = off, 1=min, 10=max
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi, Pack=1)]
public struct ALGORITHM
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=12)]
public byte[] alg;
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi, Pack=1)]
public struct DATAFILEENC
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string InputName; // file name, wild cards are allowed
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string OutputName; // file name (or folder name if input is a wildcard)
}
// this structure is used for creating temporary software keys
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi, Pack=1)]
public struct TEMP_SWKEY_INFO
{
public int size; // size of this structure (must be initialised)
public uint machineID; // machine ID in (hex) integer form
public int expiry_day; // expiry date of the Software Key
public int expiry_month;
public int expiry_year;
public int dongle_model; // model of the Software Key. See constant values below
public uint dongle_number; // dongle number of the Software Key. 0 = default (random)
}
// this structure is used for creating demo software key templates
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi, Pack=1)]
public struct DEMO_SWKEY_INFO
{
public int size; // size of this structure (must be initialised)
public int max_days; // max days demo swkey installation is valid (0-60)
public int models; // bitmap of valid dongle models. See constant values below. 0 = default (only use if only one model is selected in DINKEYINFO)
}
// ********************** API functions ************************
// we declare classes for all the API functions for each bitness
// Loads DAPF from disk and returns handle
class LoadDAPFFromFile32
{
[DllImport("DinkeyAdd32.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr LoadDAPFFromFile(string dapf_file, out int err_code);
}
class LoadDAPFFromFile64
{
[DllImport("DinkeyAdd64.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr LoadDAPFFromFile(string dapf_file, out int err_code);
}
// Loads DAPF from disk into structures supplied (so we can modify DAPF in memory)
class ReadDAPFEx32
{
[DllImport("DinkeyAdd32.dll", CharSet = CharSet.Ansi)]
public static extern int ReadDAPFEx(string dapf_file, out DINKEYINFO DinkeyInfo, byte[] licence_bytes, byte[] fileinfo_bytes, byte[] alg_bytes, byte[] datafile_bytes, out int dapf_version, out int dapf_format);
}
class ReadDAPFEx64
{
[DllImport("DinkeyAdd64.dll", CharSet = CharSet.Ansi)]
public static extern int ReadDAPFEx(string dapf_file, out DINKEYINFO DinkeyInfo, byte[] licence_bytes, byte[] fileinfo_bytes, byte[] alg_bytes, byte[] datafile_bytes, out int dapf_version, out int dapf_format);
}
// Loads DAPF from structures and returns a handle
class LoadDAPF32
{
[DllImport("DinkeyAdd32.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr LoadDAPF(ref DINKEYINFO DinkeyInfo, byte[] licence_bytes, byte[] fileinfo_bytes, byte[] alg_bytes, byte[] datafile_bytes, out int ret_code);
}
class LoadDAPF64
{
[DllImport("DinkeyAdd64.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr LoadDAPF(ref DINKEYINFO DinkeyInfo, byte[] licence_bytes, byte[] fileinfo_bytes, byte[] alg_bytes, byte[] datafile_bytes, out int ret_code);
}
// saves the DAPF file to disk
class WriteDAPFEx32
{
[DllImport("DinkeyAdd32.dll", CharSet = CharSet.Ansi)]
public static extern int WriteDAPFEx(IntPtr dapf_handle, string dapf_file, int dapf_format, int dapf_version, int flags);
}
class WriteDAPFEx64
{
[DllImport("DinkeyAdd64.dll", CharSet = CharSet.Ansi)]
public static extern int WriteDAPFEx(IntPtr dapf_handle, string dapf_file, int dapf_format, int dapf_version, int flags);
}
// unloads the DAPF file
class UnloadDAPF32
{
[DllImport("DinkeyAdd32.dll", CharSet = CharSet.Ansi)]
public static extern void UnloadDAPF(ref IntPtr dapf_handle);
}
class UnloadDAPF64
{
[DllImport("DinkeyAdd64.dll", CharSet = CharSet.Ansi)]
public static extern void UnloadDAPF(ref IntPtr dapf_handle);
}
class AddProtection32
{
[DllImport("DinkeyAdd32.dll", CharSet = CharSet.Ansi)]
public static extern int AddProtection(IntPtr dapf_handle, int action, int file_num, int flags, out uint dongle_number);
}
class AddProtection64
{
[DllImport("DinkeyAdd64.dll", CharSet = CharSet.Ansi)]
public static extern int AddProtection(IntPtr dapf_handle, int action, int file_num, int flags, out uint dongle_number);
}
class CreateTempSoftwareKey32
{
[DllImport("DinkeyAdd32.dll", CharSet = CharSet.Ansi)]
public static extern int CreateTempSoftwareKey(IntPtr dapf_handle, ref TEMP_SWKEY_INFO swkey_info, int flags);
}
class CreateTempSoftwareKey64
{
[DllImport("DinkeyAdd64.dll", CharSet = CharSet.Ansi)]
public static extern int CreateTempSoftwareKey(IntPtr dapf_handle, ref TEMP_SWKEY_INFO swkey_info, int flags);
}
class CreateDemoSoftwareKeyTemplate32
{
[DllImport("DinkeyAdd32.dll", CharSet = CharSet.Ansi)]
public static extern int CreateDemoSoftwareKeyTemplate(IntPtr dapf_handle, ref DEMO_SWKEY_INFO swkey_info, int flags);
}
class CreateDemoSoftwareKeyTemplate64
{
[DllImport("DinkeyAdd64.dll", CharSet = CharSet.Ansi)]
public static extern int CreateDemoSoftwareKeyTemplate(IntPtr dapf_handle, ref DEMO_SWKEY_INFO swkey_info, int flags);
}
class EncryptShellDataFiles32
{
[DllImport("DinkeyAdd32.dll", CharSet = CharSet.Ansi)]
public static extern int EncryptShellDataFiles(IntPtr dapf_handle, int file_num, int flags);
}
class EncryptShellDataFiles64
{
[DllImport("DinkeyAdd64.dll", CharSet = CharSet.Ansi)]
public static extern int EncryptShellDataFiles(IntPtr dapf_handle, int file_num, int flags);
}
class GetLastMessage32
{
[DllImport("DinkeyAdd32.dll", CharSet = CharSet.Ansi)]
public static extern void GetLastMessage(StringBuilder message, int buffer_size, out int message_length);
}
class GetLastMessage64
{
[DllImport("DinkeyAdd64.dll", CharSet = CharSet.Ansi)]
public static extern void GetLastMessage(StringBuilder message, int buffer_size, out int message_length);
}
class GetLastExtendedError32
{
[DllImport("DinkeyAdd32.dll", CharSet = CharSet.Ansi)]
public static extern int GetLastExtendedError();
}
class GetLastExtendedError64
{
[DllImport("DinkeyAdd64.dll", CharSet = CharSet.Ansi)]
public static extern int GetLastExtendedError();
}
// ********************* DinkeyAdd class **********************
class DinkeyAdd
{
// constants
public const int DAPF_VERSION = 9; // current DAPF version
// WriteDAPFEx API flags
public const int FLAGS_LOSE_FEATURES = 1; // means that you can save the DAPF file to an earlier version even if it means losing some new features that have been currently set
// AddProtection API action values
public const int ACTION_USE_DAPF_SETTINGS = 0; // means you just ignore the action value and use the default dapf settings
public const int ACTION_PROGRAM_DONGLE = 1; // program the dongle only
public const int ACTION_PROTECT_SOFTWARE = 2; // protect a software file (index indicated by separate parameter)
public const int ACTION_PROGRAM_AND_PROTECT = 3; // program the dongle and protect software
// AddProtection API flags values
public const int FLAGS_OVERWRITE_OUTPUT = 1; // overwrite the output file if it already exists (default is to give an error)
// SoftwareKey API flags
public const int FLAGS_OVERWRITE_SWKEY = 1; // overwrite an existing swkey with the new one
public const int FLAGS_EXPIRY_DONTCARE = 2; // create the Software Key even though the expiry date (or max days) is less than the expiry date of the key itself.
// constants for dapf_format in ReadDAPFEx and WriteDAPFEx functions
public const int DAPF_FORMAT_BINARY = 1;
public const int DAPF_FORMAT_JSON = 2;
public const int DAPF_FORMAT_JSON_MIN = 3; // this value is only used with WriteDAPEx. ReadDAPFEx cannot return this value.
// constants for values for model in the TEMP_SWKEY_INFO structure
public const int SWKEY_MODEL_PRO_LITE = 0;
public const int SWKEY_MODEL_PRO_PLUS = 1;
public const int SWKEY_MODEL_PRO_NET = 2;
public const int SWKEY_MODEL_FD_LITE = 3;
public const int SWKEY_MODEL_FD_PLUS = 4;
public const int SWKEY_MODEL_FD_NET = 5;
// constants for models bitmap in the DEMO_SWKEY_INFO structure
public const int SWKEY_BITMAP_DEFAULT = 0; // use default value set in DINKEYINFO.SelectedModels
public const int SWKEY_BITMAP_PRO_LITE = 1; // BIT0
public const int SWKEY_BITMAP_PRO_PLUS = 2; // BIT1
public const int SWKEY_BITMAP_PRO_NET = 4; // BIT2
public const int SWKEY_BITMAP_FD_LITE = 8; // BIT3
public const int SWKEY_BITMAP_FD_PLUS = 16; // BIT4
public const int SWKEY_BITMAP_FD_NET = 32; // BIT5
// private constants
private const int MAX_LICENCES = 255; // max number of licences in a DAPF file
private const int MAX_FILE_INFO = 1000; // theoretically unlimited but in practice it is easier if we limit it
private const int MAX_USER_ALGS = 20; // max number of user algs in DAPF file
private const int MAX_DATA_ENCS = 255; // max number of Shell data encryption files in DAPF file
// **** main API
// We only want to load the correct DLL for the bit-ness of the computer. The other DLL may not exist.
// if the appropriate DLL does not exist in the same directory as this test program you will receive a DllNotFoundException
public static IntPtr LoadDAPFFromFile(string dapf_file, out int err_code)
{
if (IntPtr.Size == 4)
return LoadDAPFFromFile32.LoadDAPFFromFile(dapf_file, out err_code);
return LoadDAPFFromFile64.LoadDAPFFromFile(dapf_file, out err_code);
}
// we have to do some marshalling of arrays of bytes into arrays of structures
public static int ReadDAPFEx(string dapf_file, out DINKEYINFO DinkeyInfo, out LICENCEINFO[] LicenceInfo, out FILEINFO[] FileInfo, out ALGORITHM[] Algorithms, out DATAFILEENC[] DataFileEnc, out int dapf_version, out int dapf_format)
{
int ret_code, i;
byte[] licence_bytes = new byte[MAX_LICENCES * Marshal.SizeOf(typeof(LICENCEINFO))];
byte[] licence_bytes_one_struct = new byte[Marshal.SizeOf(typeof(LICENCEINFO))];
byte[] fileinfo_bytes = new byte[MAX_FILE_INFO * Marshal.SizeOf(typeof(FILEINFO))];
byte[] fileinfo_bytes_one_struct = new byte[Marshal.SizeOf(typeof(FILEINFO))];
byte[] alg_bytes = new byte[MAX_USER_ALGS * Marshal.SizeOf(typeof(ALGORITHM))];
byte[] alg_bytes_one_struct = new byte[Marshal.SizeOf(typeof(ALGORITHM))];
byte[] datafile_bytes = new byte[MAX_DATA_ENCS * Marshal.SizeOf(typeof(DATAFILEENC))];
byte[] datafile_bytes_one_struct = new byte[Marshal.SizeOf(typeof(DATAFILEENC))];
GCHandle MyGC;
DinkeyInfo = new DINKEYINFO();
LicenceInfo = null;
FileInfo = null;
Algorithms = null;
DataFileEnc = null;
if (IntPtr.Size == 4)
ret_code = ReadDAPFEx32.ReadDAPFEx(dapf_file, out DinkeyInfo, licence_bytes, fileinfo_bytes, alg_bytes, datafile_bytes, out dapf_version, out dapf_format);
else
ret_code = ReadDAPFEx64.ReadDAPFEx(dapf_file, out DinkeyInfo, licence_bytes, fileinfo_bytes, alg_bytes, datafile_bytes, out dapf_version, out dapf_format);
if (ret_code != 0)
return ret_code;
// convert byte array to an array of structs
LicenceInfo = new LICENCEINFO[DinkeyInfo.NumLicences];
for (i=0; i<DinkeyInfo.NumLicences; i++)
{
Array.Copy(licence_bytes, i*Marshal.SizeOf(typeof(LICENCEINFO)), licence_bytes_one_struct, 0, Marshal.SizeOf(typeof(LICENCEINFO)));
MyGC = GCHandle.Alloc(licence_bytes_one_struct, GCHandleType.Pinned);
LicenceInfo[i] = (LICENCEINFO)Marshal.PtrToStructure(MyGC.AddrOfPinnedObject(), typeof(LICENCEINFO));
MyGC.Free();
}
FileInfo = new FILEINFO[DinkeyInfo.NumProgs];
for (i=0; i<DinkeyInfo.NumProgs; i++)
{
Array.Copy(fileinfo_bytes, i*Marshal.SizeOf(typeof(FILEINFO)), fileinfo_bytes_one_struct, 0, Marshal.SizeOf(typeof(FILEINFO)));
MyGC = GCHandle.Alloc(fileinfo_bytes_one_struct, GCHandleType.Pinned);
FileInfo[i] = (FILEINFO)Marshal.PtrToStructure(MyGC.AddrOfPinnedObject(), typeof(FILEINFO));
MyGC.Free();
}
Algorithms = new ALGORITHM[DinkeyInfo.NumAlgs];
for (i=0; i<DinkeyInfo.NumAlgs; i++)
{
Array.Copy(alg_bytes, i*Marshal.SizeOf(typeof(ALGORITHM)), alg_bytes_one_struct, 0, Marshal.SizeOf(typeof(ALGORITHM)));
MyGC = GCHandle.Alloc(alg_bytes_one_struct, GCHandleType.Pinned);
Algorithms[i] = (ALGORITHM)Marshal.PtrToStructure(MyGC.AddrOfPinnedObject(), typeof(ALGORITHM));
MyGC.Free();
}
DataFileEnc = new DATAFILEENC[DinkeyInfo.NumDataFileEnc];
for (i=0; i<DinkeyInfo.NumDataFileEnc; i++)
{
Array.Copy(datafile_bytes, i*Marshal.SizeOf(typeof(DATAFILEENC)), datafile_bytes_one_struct, 0, Marshal.SizeOf(typeof(DATAFILEENC)));
MyGC = GCHandle.Alloc(datafile_bytes_one_struct, GCHandleType.Pinned);
DataFileEnc[i] = (DATAFILEENC)Marshal.PtrToStructure(MyGC.AddrOfPinnedObject(), typeof(DATAFILEENC));
MyGC.Free();
}
return ret_code;
}
// we have to do some marshalling of an array of structures into an array of bytes
public static IntPtr LoadDAPF(DINKEYINFO DinkeyInfo, LICENCEINFO[] LicenceInfo, FILEINFO[] FileInfo, ALGORITHM[] Algorithms, DATAFILEENC[] DataFileEnc, out int ret_code)
{
int i;
byte[] licence_bytes = new byte[MAX_LICENCES * Marshal.SizeOf(typeof(LICENCEINFO))];
byte[] licence_bytes_one_struct = new byte[Marshal.SizeOf(typeof(LICENCEINFO))];
byte[] fileinfo_bytes = new byte[MAX_FILE_INFO * Marshal.SizeOf(typeof(FILEINFO))];
byte[] fileinfo_bytes_one_struct = new byte[Marshal.SizeOf(typeof(FILEINFO))];
byte[] alg_bytes = new byte[MAX_USER_ALGS * Marshal.SizeOf(typeof(ALGORITHM))];
byte[] alg_bytes_one_struct = new byte[Marshal.SizeOf(typeof(ALGORITHM))];
byte[] datafile_bytes = new byte[MAX_DATA_ENCS * Marshal.SizeOf(typeof(DATAFILEENC))];
byte[] datafile_bytes_one_struct = new byte[Marshal.SizeOf(typeof(DATAFILEENC))];
GCHandle MyGC;
// convert array of structs to a byte array
for (i=0; i<DinkeyInfo.NumLicences; i++)
{
MyGC = GCHandle.Alloc(licence_bytes_one_struct, GCHandleType.Pinned);
Marshal.StructureToPtr(LicenceInfo[i], MyGC.AddrOfPinnedObject(), false);
MyGC.Free();
Array.Copy(licence_bytes_one_struct, 0, licence_bytes, i*Marshal.SizeOf(typeof(LICENCEINFO)), Marshal.SizeOf(typeof(LICENCEINFO)));
}
for (i=0; i<DinkeyInfo.NumProgs; i++)
{
MyGC = GCHandle.Alloc(fileinfo_bytes_one_struct, GCHandleType.Pinned);
Marshal.StructureToPtr(FileInfo[i], MyGC.AddrOfPinnedObject(), false);
MyGC.Free();
Array.Copy(fileinfo_bytes_one_struct, 0, fileinfo_bytes, i*Marshal.SizeOf(typeof(FILEINFO)), Marshal.SizeOf(typeof(FILEINFO)));
}
for (i=0; i<DinkeyInfo.NumAlgs; i++)
{
MyGC = GCHandle.Alloc(alg_bytes_one_struct, GCHandleType.Pinned);
Marshal.StructureToPtr(Algorithms[i], MyGC.AddrOfPinnedObject(), false);
MyGC.Free();
Array.Copy(alg_bytes_one_struct, 0, alg_bytes, i*Marshal.SizeOf(typeof(ALGORITHM)), Marshal.SizeOf(typeof(ALGORITHM)));
}
for (i=0; i<DinkeyInfo.NumDataFileEnc; i++)
{
MyGC = GCHandle.Alloc(datafile_bytes_one_struct, GCHandleType.Pinned);
Marshal.StructureToPtr(DataFileEnc[i], MyGC.AddrOfPinnedObject(), false);
MyGC.Free();
Array.Copy(datafile_bytes_one_struct, 0, datafile_bytes, i*Marshal.SizeOf(typeof(DATAFILEENC)), Marshal.SizeOf(typeof(DATAFILEENC)));
}
if (IntPtr.Size == 4)
return LoadDAPF32.LoadDAPF(ref DinkeyInfo, licence_bytes, fileinfo_bytes, alg_bytes, datafile_bytes, out ret_code);
return LoadDAPF64.LoadDAPF(ref DinkeyInfo, licence_bytes, fileinfo_bytes, alg_bytes, datafile_bytes, out ret_code);
}
public static int WriteDAPFEx(IntPtr dapf_handle, string dapf_file, int dapf_format, int dapf_version, int flags)
{
if (IntPtr.Size == 4)
return WriteDAPFEx32.WriteDAPFEx(dapf_handle, dapf_file, dapf_format, dapf_version, flags);
return WriteDAPFEx64.WriteDAPFEx(dapf_handle, dapf_file, dapf_format, dapf_version, flags);
}
public static void UnloadDAPF(ref IntPtr dapf_handle)
{
if (IntPtr.Size == 4)
UnloadDAPF32.UnloadDAPF(ref dapf_handle);
else
UnloadDAPF64.UnloadDAPF(ref dapf_handle);
return;
}
public static int AddProtection(IntPtr dapf_handle, int action, int file_num, int flags, out uint dongle_number)
{
if (IntPtr.Size == 4)
return AddProtection32.AddProtection(dapf_handle, action, file_num, flags, out dongle_number);
return AddProtection64.AddProtection(dapf_handle, action, file_num, flags, out dongle_number);
}
public static int CreateTempSoftwareKey(IntPtr dapf_handle, TEMP_SWKEY_INFO swkey_info, int flags)
{
if (IntPtr.Size == 4)
return CreateTempSoftwareKey32.CreateTempSoftwareKey(dapf_handle, ref swkey_info, flags);
return CreateTempSoftwareKey64.CreateTempSoftwareKey(dapf_handle, ref swkey_info, flags);
}
public static int CreateDemoSoftwareKeyTemplate(IntPtr dapf_handle, DEMO_SWKEY_INFO swkey_info, int flags)
{
if (IntPtr.Size == 4)
return CreateDemoSoftwareKeyTemplate32.CreateDemoSoftwareKeyTemplate(dapf_handle, ref swkey_info, flags);
return CreateDemoSoftwareKeyTemplate64.CreateDemoSoftwareKeyTemplate(dapf_handle, ref swkey_info, flags);
}
public static int EncryptShellDataFiles(IntPtr dapf_handle, int file_num, int flags)
{
if (IntPtr.Size == 4)
return EncryptShellDataFiles32.EncryptShellDataFiles(dapf_handle, file_num, flags);
return EncryptShellDataFiles64.EncryptShellDataFiles(dapf_handle, file_num, flags);
}
// do a bit of work here to make the function easier to use for C#
public static string GetLastMessage()
{
int length, dummy;
StringBuilder message;
if (IntPtr.Size == 4)
{
GetLastMessage32.GetLastMessage(null, 0, out length);
message = new StringBuilder(length);
GetLastMessage32.GetLastMessage(message, length, out dummy);
}
else
{
GetLastMessage64.GetLastMessage(null, 0, out length);
message = new StringBuilder(length);
GetLastMessage64.GetLastMessage(message, length, out dummy);
}
return message.ToString();
}
public static int GetLastExtendedError()
{
if (IntPtr.Size == 4)
return GetLastExtendedError32.GetLastExtendedError();
return GetLastExtendedError64.GetLastExtendedError();
}
}

View File

@@ -0,0 +1,121 @@
<VisualStudioProject>
<CSHARP
ProjectType = "Local"
ProductVersion = "7.0.9466"
SchemaVersion = "1.0"
ProjectGuid = "{6535AF22-2AF4-4401-BFE2-889CD40C8F2F}"
>
<Build>
<Settings
ApplicationIcon = "App.ico"
AssemblyKeyContainerName = ""
AssemblyName = "dapfTest"
AssemblyOriginatorKeyFile = ""
DefaultClientScript = "JScript"
DefaultHTMLPageLayout = "Grid"
DefaultTargetSchema = "IE50"
DelaySign = "false"
OutputType = "WinExe"
RootNamespace = "dapfTest"
StartupObject = ""
>
<Config
Name = "Debug"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "DEBUG;TRACE"
DocumentationFile = ""
DebugSymbols = "true"
FileAlignment = "4096"
IncrementalBuild = "true"
Optimize = "false"
OutputPath = "bin\Debug\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
<Config
Name = "Release"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "TRACE"
DocumentationFile = ""
DebugSymbols = "false"
FileAlignment = "4096"
IncrementalBuild = "false"
Optimize = "true"
OutputPath = "bin\Release\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
</Settings>
<References>
<Reference
Name = "System"
AssemblyName = "System"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.dll"
/>
<Reference
Name = "System.Data"
AssemblyName = "System.Data"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Data.dll"
/>
<Reference
Name = "System.Drawing"
AssemblyName = "System.Drawing"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Drawing.dll"
/>
<Reference
Name = "System.Windows.Forms"
AssemblyName = "System.Windows.Forms"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Windows.Forms.dll"
/>
<Reference
Name = "System.XML"
AssemblyName = "System.Xml"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.XML.dll"
/>
</References>
</Build>
<Files>
<Include>
<File
RelPath = "App.ico"
BuildAction = "Content"
/>
<File
RelPath = "AssemblyInfo.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "dapf.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Form1.cs"
SubType = "Form"
BuildAction = "Compile"
/>
<File
RelPath = "Form1.resx"
DependentUpon = "Form1.cs"
BuildAction = "EmbeddedResource"
/>
<File
RelPath = "readme.txt"
BuildAction = "Content"
/>
</Include>
</Files>
</CSHARP>
</VisualStudioProject>

View File

@@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 7.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dapfTest", "dapfTest.csproj", "{6535AF22-2AF4-4401-BFE2-889CD40C8F2F}"
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
ConfigName.0 = Debug
ConfigName.1 = Release
EndGlobalSection
GlobalSection(ProjectDependencies) = postSolution
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{6535AF22-2AF4-4401-BFE2-889CD40C8F2F}.Debug.ActiveCfg = Debug|.NET
{6535AF22-2AF4-4401-BFE2-889CD40C8F2F}.Debug.Build.0 = Debug|.NET
{6535AF22-2AF4-4401-BFE2-889CD40C8F2F}.Release.ActiveCfg = Release|.NET
{6535AF22-2AF4-4401-BFE2-889CD40C8F2F}.Release.Build.0 = Release|.NET
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal