生成Security解锁算法的dll文件

Vector Diva文件的模板路径
在这里插入图片描述
代码例子

KEYGENALGO_API VKeyGenResultEx GenerateKeyEx(
  const unsigned char* ipSeedArray,          /* Array for the seed [in] */
  unsigned int iSeedArraySize,               /* Length of the array for the seed [in] */
  const unsigned int iSecurityLevel,         /* Security level [in] */
  const char* ipVariant,                     /* Name of the active variant [in] */  
  unsigned char* iopKeyArray,                /* Array for the key [in, out] */
  unsigned int iMaxKeyArraySize,             /* Maximum length of the array for the key [in] */
  unsigned int& oActualKeyArraySize)         /* Length of the key [out] */
{
  //Copy seed from parameter to a integer 
  //Note: The byte order in the seed array is equal to the byte order in the bus message
  unsigned int seed=0;
  seed=ipSeedArray[3];
  seed=seed | (ipSeedArray[2]<<8);
  seed=seed | (ipSeedArray[1]<<16);
  seed=seed | (ipSeedArray[0]<<24);
  unsigned int delta = 0x9E3779B9;
  unsigned int key=0;  

  unsigned int notseed = ~seed;
  int constant[4] = { 0x33,0x5a,0xb7,0x98 };//22F18C后四位,是个常量,对结果有有影响的

  //if ((iSeedArraySize > iMaxKeyArraySize) | (ipSeedArray[1] << 16) | (ipSeedArray[0] << 24))
      //return KGREO_BufferToSmall;
  // 
  //begin calculate key from seed------------------------------------------------------------
  //for security access with Services 0x27 01 ->0x27 02
  int round = 2;//几级解锁
  int sum = 0;

  if (iSecurityLevel == 0x01)
  {
      for (int i = 0; i < round; i++)
      {
          seed += (((notseed << 4) ^ (notseed >> 5)) + notseed) ^ (sum + constant[sum & 3]);
          sum += delta;
          notseed += (((seed << 4) ^ (seed >> 5)) + seed) ^ (sum + constant[(sum >> 11) & 3]);
      }

      key = seed;

  }

  //for security access with Services 0x27 03 -> 0x27 04
  if (iSecurityLevel==0x03) 
  {  
    key=seed/2;   
  }  

  //for security access with Services 0x27 05 -> 0x27 06
  if (iSecurityLevel==0x09) 
  {  
      constant[0] = ((constant[0] >> 3) | (constant[0] << 5)) & 0x000000FF;
      constant[1] = ((constant[1] >> 3) | (constant[1] << 5)) & 0x000000FF;
      constant[2] = ((constant[2] >> 3) | (constant[2] << 5)) & 0x000000FF;
      constant[3] = ((constant[3] >> 3) | (constant[3] << 5)) & 0x000000FF;
      for (int i = 0; i < round; i++)
      {
          seed += (((notseed << 4) ^ (notseed >> 5)) + notseed) ^ (sum + constant[sum & 3]);
          sum += delta;
          notseed += (((seed << 4) ^ (seed >> 5)) + seed) ^ (sum + constant[(sum >> 11) & 3]);
      }

      key = seed;
  }  
  //end calculate key from seed------------------------------------------------------------
  //key = 0x9E3779B9;
  //Copy key to the output buffer 
  //Note: The first byte of the key array will be the first key byte of the bus message
 // iopKeyArray[3] = key & 0xff;
  //iopKeyArray[2] = (key>>8)& 0xff;
  //iopKeyArray[1] = (key>>16)& 0xff;
 // iopKeyArray[0] = (key>>24)& 0xff;

  iopKeyArray[3] = key & 0x000000ff;
  iopKeyArray[2] = (key & 0x0000ff00)>>8;
  iopKeyArray[1] = (key & 0x00ff0000)>>16;
  iopKeyArray[0] = (key & 0xff000000)>>24;
  //setting length of key
  oActualKeyArraySize = 4;     
  return KGRE_Ok;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值