如何制作用于27服务的dll

1、简介

在利用CANOE 进行测试时,需要用到dll库用于生成27服务需要的Key。因此本文主要介绍如何识别Vector 默认的dll接口,并根据自己需要生成dll

2、找到CANOE提供的Demo工程

安装CANOD时,会提供生成符合CANOE接口的Demo工程,路径如下
在这里插入图片描述

3、打开VS工程,修改代码

示例代码如下

//
///Example for a SeedKey.Dll used in CANoe.DiVa
///See also CANoe.DiVa help==>Proceedings/Entry masks/"General" entry mask
//


#include <windows.h>
#include "GenerateKeyEx.h"


// KeyGeneration.cpp : Defines the entry point for the DLL application.
BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    return TRUE;
}



const unsigned char APP_MASK[4] = { 0xD6, 0xD7, 0x98, 0xFA };


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

  //begin calculate key from seed------------------------------------------------------------
  //for security access with Services 0x27 01 ->0x27 02
  unsigned char tmpKey[4];

  for (int i = 0; i<4; i++)
  {
	  tmpKey[i] = ipSeedArray[i] ^ APP_MASK[i];
  }
  
  //end calculate key from seed------------------------------------------------------------

  //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[0] = ((tmpKey[0] & 0x0F) << 4) | (tmpKey[1] & 0xF0);
  iopKeyArray[1] = ((tmpKey[1] & 0x0F) << 4) | ((tmpKey[2] & 0xF0) >> 4);
  iopKeyArray[2] = (tmpKey[2] & 0xF0) | ((tmpKey[3] & 0xF0) >> 4);
  iopKeyArray[3] = ((tmpKey[3] & 0x0F) << 4) | (tmpKey[0] & 0xF0);
  //setting length of key
  oActualKeyArraySize = 4;     
  return KGRE_Ok;
}

4、 支持多个Level

为了便于在一个dll 中支持多个level, 可以使用接口参数 iSecurityLevel,如下代码

if (iSecurityLevel == 0x1)
{
	/* calc seed key */
}
else if (iSecurityLevel  == 0x09)
{
	/*  calc seed key*/
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值