如何使用python程序中的安全dll执行UDS会话解锁?

2024-09-27 18:03:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我想自动化一些需要安全解锁的WDBI服务。 我有一个可以从CANoe调用的dll,但我不想使用CANoe硬件,也不知道dll中的函数调用。 是否有任何方法可以从python程序调用dll来执行会话解锁


Tags: 方法程序硬件dll函数调用canoewdbi
1条回答
网友
1楼 · 发布于 2024-09-27 18:03:11

有了DLL,您可以使用类似DependencyWalker的工具查看DLL的导出符号。但是如果您已经知道您的DLL在CANoe中工作,那么它将遵循指定的API by Vector Informatik在CANoe的安全访问DLL中实现:GenerateKeyx&;GenerateKeyXopt

GenerateKeyx:

int VKeyGenResult ExGenerateKeyEx (
  const unsigned char* ipSeedArray,
  unsigned int iSeedArraySize,
  const unsigned int iSecurityLevel,
  const char* ipVariant,
  unsigned char* iopKeyArray,
  unsigned int iMaxKeyArraySize,
  unsigned int& oActualKeyArraySize );

GenerateKeyXOpt:

VKeyGenResult ExOptGenerateKeyExOpt (
  const unsigned char* ipSeedArray,
  unsigned int iSeedArraySize,
  const unsigned int iSecurityLevel,
  const char* ipVariant,
  const char* ipOptions,
  unsigned char* iopKeyArray,
  unsigned int iMaxKeyArraySize,
  unsigned int& oActualKeyArraySize );

然后,只需从python调用此Dll,即使用ctypes

import ctypes

mylib = ctypes.WinDLL("./GenerateKeyExImpl.dll")
seed = (ctypes.c_byte * 4)(0xff, 0xfe, 0xfd, 0xfc) # these bytes you should get from the ECU i.e.
# Tx 27 01
# Rx 67 01 ff fe fd fc
key = (ctypes.c_byte * 4)() # this will contain the secret key after Dll call
keylength = ctypes.c_int(4) # this will contain the secret key length after Dll call
mylib.ExGenerateKeyEx(
     ctypes.pointer(seed), # Seed from the ECU
     ctypes.c_int(4), # Example: Seed length = 4 bytes
     ctypes.c_int(1), # Example: Security Level 1
     POINTER(c_int)(), # Example: NULL = No variant string
     ctypes.pointer(key), # Key to send back to the ECU
     ctypes.c_int(4), # Example: Key Max length = 4 bytes
     ctypes.pointer(keylength), # Example: Seed length = 4 bytes
)
# TODO: Send "key" back to the ECU i.e.
# Tx 27 02 XX XX XX XX
# Rx 67 02   

相关问题 更多 >

    热门问题