诊断0x27服务解密文件DLL制作与使用

2023-11-23 20:36

本文主要是介绍诊断0x27服务解密文件DLL制作与使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

DLL文件在CANoe的使用方法

DLL文件在诊断里面可以用在0x27秘钥服务里面,对解密有帮助,在下图位置加载。

DLL文件制作

vector公司本来就给了我们一个demo,先拷贝一份下来,别把原来的文件给改坏了。我这个是CANoe12,demo代码的路径在C:\Users\Public\Documents\Vector\CANoe\Sample Configurations 12.0.75\CAN\Diagnostics\UDSSystem\SecurityAccess\Sources,大家可以参考下,把里面这个KeyGenDll_GenerateKeyEx文件夹复制一份出来,当然你也可以用KeyGenDll_GenerateKeyExOpt,待会打开源代码看得到是差不多的。

打开Visual Studio 2019,将工程里面的工程文件GenerateKeyExImpl.vcproj拖进去,就能打开工程。展开工程,然后打开源文件GenerateKeyExImpl.cpp。

程序比较简单,还有注释,里面有很多空行,我删了几行放在这里大家看看,这个是工程KeyGenDll_GenerateKeyEx的源代码。

// KeyGeneration.cpp : Defines the entry point for the DLL application.
#include <windows.h>
#include "KeyGenAlgoInterfaceEx.h"BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{return TRUE;
}KEYGENALGO_API VKeyGenResultEx GenerateKeyEx(const unsigned char*  iSeedArray,     /* 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*           iVariant,       /* Name of the active variant [in] */unsigned char*        ioKeyArray,     /* Array for the key [in, out] */unsigned int          iKeyArraySize,  /* Maximum length of the array for the key [in] */unsigned int&         oSize           /* Length of the key [out] */)
{if (iSeedArraySize>iKeyArraySize)return KGRE_BufferToSmall;for (unsigned int i=0;i<iSeedArraySize;i++)ioKeyArray[i]=~iSeedArray[i];oSize=iSeedArraySize;return KGRE_Ok;
}

这个是KeyGenDll_GenerateKeyExOpt工程的源代码GenerateKeyExOpt.cpp,相对于KeyGenDll_GenerateKeyEx工程就是多了个选项作为入参,高级用法才会用到,我们一般都用不到,所以这里就用KeyGenDll_GenerateKeyEx工程。

//
/// Seed & Key DLL with extended interface and options argument
/// This is an example implementation for CANoe demo configuration "UDSsim"
//#include <windows.h>
#include "GenerateKeyExOpt.h"KEYGENALGO_API VKeyGenResultExOpt GenerateKeyExOpt(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]const char*           ipOptions,              // Optional parameter which might be used for OEM specific information [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]
{// Check the input argumentsif( iSecurityLevel == 0 || iSecurityLevel > 10)return KGREO_SecurityLevelInvalid;if( iMaxKeyArraySize < iSeedArraySize || 4 > iSeedArraySize)return KGREO_BufferToSmall;if( !ipSeedArray || !iopKeyArray || !ipOptions || strlen( ipOptions) < iSeedArraySize)return KGREO_UnspecifiedError;// Copy the input bytes to the output bytesmemcpy( iopKeyArray, ipSeedArray, iSeedArraySize);// As an example each byte in the options array will be added to each byte of the seed array securityLevel times.for( unsigned int l = 0; l < iSecurityLevel; ++l){for( unsigned int i = 0; i < iSeedArraySize; ++i)iopKeyArray[i] += ipOptions[i];}oActualKeyArraySize = iSeedArraySize;return KGREO_Ok;
}

修改KeyGenDll_GenerateKeyEx工程源代码GenerateKeyExImpl.cpp,里面做了注释。

KEYGENALGO_API VKeyGenResultEx GenerateKeyEx(unsigned char*  iSeedArray,     /* 种子数组 */unsigned int          iSeedArraySize, /* 种子长度 */const unsigned int    iSecurityLevel, /* 秘钥等级(调试打印) */const char*           iVariant,       /* 激活状态(调试打印) */unsigned char*        ioKeyArray,     /* 秘钥数组 */unsigned int          iKeyArraySize,  /* 秘钥长度 */unsigned int&         oSize           /* 秘钥长度(调试打印) */)
{if (iSeedArraySize>iKeyArraySize)//秘钥长度大于种子长度的话就是长度错误return KGRE_BufferToSmall;……(这里是我的算法,计算出来的秘钥放在iSeedArray[]数组)for (int i = 0; i < iKeyArraySize; i++) {ioKeyArray[i] = iSeedArray[i];}oSize = iSeedArraySize;//这个其实没啥用,长度是CDD里面定义的return KGRE_Ok;
}

对着工程右键,重新生成就行,输出信息会告诉你把DLL文件生成到了哪里。

DLL文件检查

如果你很有自信一次写对,那直接在CANoe里面直接加载就行。如果想谨慎点,想要检查写得对不对,就新建个控制台工程来调用DLL文件里面的函数进行验证。

把上面生成的DLL文件拷贝到控制台路径下。

调用代码如下

// CallDLL.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include <Windows.h>
#include <tchar.h>using namespace std;
#define iSeedArraySize 16
const unsigned char SeedArray[iSeedArraySize] = {0xD1,0x28,0xD2,0x7B,0x25,0xCE,0x78,0x22,0xCB,0x75,0x1E,0xC8,0x71,0x1B,0xC5,0x6E }; const unsigned int    iSecurityLevel = 1;
const char iVariant = 0;#define iKeyArraySize 16
unsigned char ioKeyArray[iSeedArraySize] = { 0x0 };unsigned int oSize = 0;int main()
{HINSTANCE handle = LoadLibrary(_T("SeednKey.dll"));//加载dll ,需要加上头文件tchar.h并在调用时加上_T 由句柄指向dll文件cout << "Dll Adddr:" << handle << endl;if (handle){typedef int(*GenerateKeyExOpt_API_Type)(const unsigned char*,unsigned int,const unsigned int,const char*,unsigned char*,unsigned int,unsigned int &);GenerateKeyExOpt_API_Type GenerateKeyExOpt_API_Point = (GenerateKeyExOpt_API_Type)GetProcAddress(handle, "GenerateKeyEx"); //GetProcAddress获取dll中的Add_Func函数,用add_API_Point指向函数它cout << "dll 函数的句柄返回值:" << GenerateKeyExOpt_API_Point << endl;//打印dll的函数句柄地址值,不为0就说明调用成功printf("\n");if (GenerateKeyExOpt_API_Point){int result = (*GenerateKeyExOpt_API_Point)(SeedArray,iSeedArraySize, iSecurityLevel,&iVariant, ioKeyArray, iKeyArraySize, oSize);for (int i = 0; i < iSeedArraySize; i++) {/*打印种子*/printf("SeedArray[%d]: %2X\n", i, SeedArray[i]);}printf("\n");for (int j = 0; j < iKeyArraySize; j++) {/*打印秘钥*/printf("ioKeyArray[%d]: %2X\n", j, ioKeyArray[j]);}cout << "oSize = " << oSize << endl;/*调试打印*/FreeLibrary(handle); //释放句柄}}return 0;
}// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

对一下打印出来的结果,是对的话就是验证通过。

CDD文件配置

0x27服务的长度是在CDD文件里面配置的,单纯改代码是改不动的。

用CANdelaStudio打开CDD文件,勾选这个,把0x27服务带出来。

长度,解密等级都在这里设置。

DLL文件使用

按照本文最上面的使用方法加载进去,双击能发送。

这篇关于诊断0x27服务解密文件DLL制作与使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/420575

相关文章

鸿蒙中@State的原理使用详解(HarmonyOS 5)

《鸿蒙中@State的原理使用详解(HarmonyOS5)》@State是HarmonyOSArkTS框架中用于管理组件状态的核心装饰器,其核心作用是实现数据驱动UI的响应式编程模式,本文给大家介绍... 目录一、@State在鸿蒙中是做什么的?二、@Spythontate的基本原理1. 依赖关系的收集2.

Python基础语法中defaultdict的使用小结

《Python基础语法中defaultdict的使用小结》Python的defaultdict是collections模块中提供的一种特殊的字典类型,它与普通的字典(dict)有着相似的功能,本文主要... 目录示例1示例2python的defaultdict是collections模块中提供的一种特殊的字

C++ Sort函数使用场景分析

《C++Sort函数使用场景分析》sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变,如果某些场景需要保持相同元素间的相对顺序,可使... 目录C++ Sort函数详解一、sort函数调用的两种方式二、sort函数使用场景三、sort函数排序

Java String字符串的常用使用方法

《JavaString字符串的常用使用方法》String是JDK提供的一个类,是引用类型,并不是基本的数据类型,String用于字符串操作,在之前学习c语言的时候,对于一些字符串,会初始化字符数组表... 目录一、什么是String二、如何定义一个String1. 用双引号定义2. 通过构造函数定义三、St

Pydantic中Optional 和Union类型的使用

《Pydantic中Optional和Union类型的使用》本文主要介绍了Pydantic中Optional和Union类型的使用,这两者在处理可选字段和多类型字段时尤为重要,文中通过示例代码介绍的... 目录简介Optional 类型Union 类型Optional 和 Union 的组合总结简介Pyd

Vue3使用router,params传参为空问题

《Vue3使用router,params传参为空问题》:本文主要介绍Vue3使用router,params传参为空问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录vue3使用China编程router,params传参为空1.使用query方式传参2.使用 Histo

使用Python自建轻量级的HTTP调试工具

《使用Python自建轻量级的HTTP调试工具》这篇文章主要为大家详细介绍了如何使用Python自建一个轻量级的HTTP调试工具,文中的示例代码讲解详细,感兴趣的小伙伴可以参考一下... 目录一、为什么需要自建工具二、核心功能设计三、技术选型四、分步实现五、进阶优化技巧六、使用示例七、性能对比八、扩展方向建

使用Python实现一键隐藏屏幕并锁定输入

《使用Python实现一键隐藏屏幕并锁定输入》本文主要介绍了使用Python编写一个一键隐藏屏幕并锁定输入的黑科技程序,能够在指定热键触发后立即遮挡屏幕,并禁止一切键盘鼠标输入,这样就再也不用担心自己... 目录1. 概述2. 功能亮点3.代码实现4.使用方法5. 展示效果6. 代码优化与拓展7. 总结1.

使用Python开发一个简单的本地图片服务器

《使用Python开发一个简单的本地图片服务器》本文介绍了如何结合wxPython构建的图形用户界面GUI和Python内建的Web服务器功能,在本地网络中搭建一个私人的,即开即用的网页相册,文中的示... 目录项目目标核心技术栈代码深度解析完整代码工作流程主要功能与优势潜在改进与思考运行结果总结你是否曾经

Linux中的计划任务(crontab)使用方式

《Linux中的计划任务(crontab)使用方式》:本文主要介绍Linux中的计划任务(crontab)使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、前言1、linux的起源与发展2、什么是计划任务(crontab)二、crontab基础1、cro