求助大牛,该代码用c#写后无法运行
注册码生成代码如下
m_machineCode= GetMachineCode("RDH");
相关函数为
public string GetMachineCode(string seriesNum)
{
string s = this.GetDeviceID() + seriesNum;
MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
string src = BitConverter.ToString((Encoding.Default.GetBytes(s))).Replace("-", "");
return this.GetCode(src, 3);
}
public string GetDeviceID()
{
byte[] outputBuffer = new byte[0x100];
int length = outputBuffer.Length;
int bytesReturned = 0;
if (!KernelIoControl(IOCTL_HAL_GET_DEVICEID, IntPtr.Zero, 0, outputBuffer, length, ref bytesReturned))
{
return null;
}
int startIndex = BitConverter.ToInt32(outputBuffer, 4);
int num4 = BitConverter.ToInt32(outputBuffer, 12);
int num5 = BitConverter.ToInt32(outputBuffer, 0x10);
StringBuilder builder = new StringBuilder();
builder.Append(string.Format("{0:X8}-{1:X4}-{2:X4}-{3:X4}-", new object[] { BitConverter.ToInt32(outputBuffer, startIndex), BitConverter.ToInt16(outputBuffer, startIndex + 4), BitConverter.ToInt16(outputBuffer, startIndex + 6), BitConverter.ToInt16(outputBuffer, startIndex + 8) }));
for (int i = num4; i < (num4 + num5); i++)
{
builder.Append(string.Format("{0:X2}", outputBuffer[i]));
}
return builder.ToString();
}
编码生成函数为
GetRegHead2(m_machineCode);
public string GetRegHead2(string machineCode)
{
string s = machineCode;
MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
string src = BitConverter.ToString((Encoding.Default.GetBytes(s))).Replace("-", "");
return this.GetCode(src, 2);
}