Key von Syncfusion wird aus der Dongle nun gelesen

This commit is contained in:
HuskyTeufel
2022-03-25 15:47:46 +01:00
parent d96c618a21
commit d350791acc
10 changed files with 145 additions and 42 deletions

166
SanShared/Dongle.cs Normal file
View File

@@ -0,0 +1,166 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CodeMeter;
namespace SanShared
{
//4e 6a 41 77 4e 6a 51 7a 51 44 4d 78 4d 7a 6b 79 5a 54 4d 30 4d 6d 55 7a 4d 47 35 4c 61 32 55 7a 51 31 46 30 52 33 64 46 5a 45 68 35 56 57 74 47 61 7a 5a 30 61 48 70 55 57 69 39 58 64 6b 78 4a 54 32 78 43 62 6b 74 58 52 58 46 57 63 30 5a 73 64 7a 41 39
public class Dongle : IDisposable
{
uint FirmCode;
uint ProductCode;
public string SyncfusionKey = "";
Api cmApi;
CmCredential cmCred;
CmAccess2 cmAcc;
HCMSysEntry hcmse;
CmBoxInfo cmBoxInfo;
CmBoxEntry2 BoxContent;
public Dongle(uint ProductCode)
{
#if !DEBUG
this.FirmCode = 103086;
this.ProductCode = ProductCode;
#else
this.FirmCode = 10;
this.ProductCode = 1;
#endif
cmApi = new Api();
cmCred = new CmCredential();
cmAcc = new CmAccess2();
cmAcc.Credential = cmCred;
cmAcc.Ctrl |= CmAccess.Option.UserLimit;
cmAcc.FirmCode = this.FirmCode;
cmAcc.ProductCode = this.ProductCode;
hcmse = cmApi.CmAccess2(CmAccessOption.Local, cmAcc);
if (hcmse == null)
{
ErrorCodes2 code = cmApi.CmGetLastErrorCode2();
string output = string.Format("{0}", code);
}
if (!CheckDongleVorhanden())
throw new Exception("Dongle not connected");
cmBoxInfo = new CmBoxInfo();
CmGetBoxContentsOption boxOptions = new CmGetBoxContentsOption();
boxOptions = CmGetBoxContentsOption.AllEntries;
CmBoxEntry2[] tmpBoxContent;
tmpBoxContent = cmApi.CmGetBoxContents2(hcmse, boxOptions, this.FirmCode, cmBoxInfo);
CmEntryData[] pCmBoxEntry = (CmEntryData[])cmApi.CmGetInfo(hcmse, CmGetInfoOption.EntryData);
for (int i = 0; i < pCmBoxEntry.Length; i++)
{
switch (pCmBoxEntry[i].Ctrl & 0x0ffff)
{
case (uint)CodeMeter.GlobalEntryOption.ProtectedData:
// Transfer to transformed byte
uint length = pCmBoxEntry[i].DataLen;
byte[] datas = new byte[length];
for(uint f = 0; f < length; f++)
{
datas[f] = pCmBoxEntry[i].Data[f];
}
SyncfusionKey = Encoding.ASCII.GetString(datas);
break;
}
}
foreach (CmBoxEntry2 boxes in tmpBoxContent)
{
if (boxes.ProductCode == this.ProductCode)
{
this.BoxContent = boxes;
}
}
}
~Dongle()
{
CleanDongle();
}
public void CleanDongle()
{
cmApi.CmRelease(hcmse);
}
public bool CheckDongleVorhanden()
{
#if LAPTOP
return true;
#else
if (hcmse == null)
return false;
else
return true;
#endif
}
public string GetDongleSerial()
{
CmBoxInfo res = (CmBoxInfo)cmApi.CmGetInfo(hcmse, CmGetInfoOption.BoxInfo);
if (null != res)
{
return res.SerialNumber.ToString();
}
else
{
throw new Exception("Fehler beim aufrufen der Seriennummer");
}
}
public uint GetFeatureMap()
{
return BoxContent.FeatureMap;
}
public string GetName()
{
return "";
}
public bool IsLicensed(byte neededMask)
{
#if LAPTOP
return true;
#else
uint DongleFeature = GetFeatureMap();
//Trace.WriteLine("DongleFeature: " + DongleFeature);
byte DongleFeatureB = (byte)DongleFeature;
if ((DongleFeatureB & neededMask) == neededMask)
return true;
return false;
#endif
}
public void Dispose()
{
CleanDongle();
}
}
}

View File

@@ -41,6 +41,18 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="WibuCmNET, Version=7.40.4997.501, Culture=neutral, PublicKeyToken=01d86e1eb0c69c23, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\3rdPackage\WibuCmNET.dll</HintPath>
</Reference>
<Reference Include="wupi.net, Version=9.20.8.500, Culture=neutral, PublicKeyToken=5f399135ee0c35d4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\3rdPackage\wupi.net.dll</HintPath>
</Reference>
<Reference Include="WupiEngineNet, Version=11.0.4997.501, Culture=neutral, PublicKeyToken=8d0bd6872db0b9bb, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\3rdPackage\WupiEngineNet.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="BerichtWorker.cs" />
@@ -55,6 +67,7 @@
<Compile Include="IReadCSVData.cs" />
<Compile Include="ITemperature.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Dongle.cs" />
<Compile Include="UVcsvStrukture.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />