weixin_48338861
Dawn_Dew
采纳率0%
2021-06-11 01:32 阅读 22

如何在代码中(C++)跳过dongle实现 compile code

问题:如何通过修改代码跳过dongle 实现compile code

已使用的方法: comment out 源代码中使用smart dongle 部分,出现了一下窗口。

 

软件版本: Microsoft visual studio 2019.

 

以下是包括smartdongle的代码 (App.cpp):

#include "smartdongle.h"

/*
....
....
*/

App::App()
{
	unsigned __int64 P1, P2;
	int error;
	//char errorString[QTS_ERROR_STRING_LENGTH_MAX];


   //SmartDongle  Demo Keys
   P1 = /* 没有展示的一串数字符*/;
   P2 = /* 没有展示的一串数字符*/;  


   while (1)
   {
	   error = SmartDongleRead(P1, P2, 0, NULL, 0);
	   if (error)
	   {
			
			int userchoice = AfxMessageBox("A valid Dongle is not present\n", MB_RETRYCANCEL);
			if(userchoice == IDCANCEL)
			{
				PostQuitMessage(0);
				break;
			}
		 
		//  SmartDongleGetErrorString(errorString, error);
		//  AfxMessageBox(errorString);

	   }
	   else
	   {
		   break;
	   }
   }


}

以下是部分 smartdongle.h

/*
   smartdongle.h for SmartDongle API version 3.2


   www.smartdongle.com

   MicroWorks, Inc.
   2808 North Cole Road
   Boise, ID 83704
*/

#ifndef _DEFINED_2A39393E_C414_4F94_B623_3FBCE5A8190F
#define _DEFINED_2A39393E_C414_4F94_B623_3FBCE5A8190F

#ifndef _WINDOWS_
   #include <Windows.h>
#endif

/*
   Maximum string length returned from GetErrorString()
*/
#define QTS_ERROR_STRING_LENGTH_MAX 128

#if defined(__cplusplus) || defined(__cplusplus__)
extern "C" {
#endif

	unsigned __int64 SmartDongleGetKeylessChallenge();
	int SmartDongleSendKeylessResponse(unsigned __int64 response);
	int SmartDongleKeylessRead(
	  unsigned int address,
	  unsigned char *buffer,
	  int size);
	int SmartDongleKeylessWrite(
	  unsigned int address,
	  unsigned char *buffer,
	  int size);

/*
   Given the correct keys, P1 and P2, will place the dongle into
   the enabled state and read EEPROM into buffer.

   Valid address is 0 to 32431

   Note: Refer to sd_uskerr.h for returned errors.
*/
   int SmartDongleRead (
      unsigned __int64 P1,
      unsigned __int64 P2,
      unsigned int address,
      unsigned char *buffer,
      int size);

以下是部分smartdongle.c

/*
   Given the correct keys, P1 and P2, will place the dongle into
   the enabled state and read EEPROM into buffer.
   Number of bytes read returned in size parameter.

   Note: Refer to uskerr.h for returned errors.
*/
int SmartDongleRead(
   unsigned __int64 P1,
   unsigned __int64 P2,
   unsigned int address,
   unsigned char *buffer,
   int size)
{
   int status;
   int bufferSize = size;
   HANDLE m_UsbHandle = INVALID_HANDLE_VALUE;


   status = OpenUsbDev(&m_UsbHandle);
   if (status != USK_OK)
   {
      return status;
   }

   /*
      Attempt to read user EEPROM space.
      On failure, attempt to disable dongle and return error.
      Number of bytes read returned in size parameter.
   */
   status = ReadEepromUserSpace(
      P1, P2, (unsigned short)address, buffer, &bufferSize, &m_UsbHandle);
   if (status != USK_OK)
   {
      DisableUsk(&m_UsbHandle);
      goto SD_ERROR;
   }

   /*
      Lock SmartDongle.
   */
   status = DisableUsk(&m_UsbHandle);

SD_ERROR:
   if (m_UsbHandle != INVALID_HANDLE_VALUE)
   {
      CloseHandle(m_UsbHandle);
   }

   return status;
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • QA_Assistant 有问必答小助手 2021-06-16 16:49

    你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答

    本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。

    ​​​​因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。

    点赞 评论 复制链接分享

相关推荐