0%

install and use Superdog to encrypt program on windows 10

Guide

Superdog soft

2个dog:

  • 开发狗:Superdog公司给客户公司(kezunlin)提供的开发狗,包含公司的vendor_code,相当于管理员。不要遗失。
  • 超级狗:可以通过软件写入feature_id交付用户。可以有多个超级狗。

如何给超级狗写入特征id?

提示:写入特征之前,必须确保开发狗+超级狗都连接在电脑。

(1)安装windows版本加密狗软件到C:\Program Files (x86)\SafeNet\SuperDog\2.3\
(2)在线下载开发商代码。
(3)打开授权管理工具,添加特征。例如feature_id=101,然后编程到超级狗。

开发商代码会写入vendor_code到C:\Program Files (x86)\SafeNet\SuperDog\2.3\VendorCodes\BYAUY.hvc

Superdog sample

参见 C:\Program Files (x86)\SafeNet\SuperDog\2.3\Samples\Licensing\C

Superdog C SDK

从API中整理出C版本的SDK,供后面使用。

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        2014/6/30      8:43           9521 dog_api.h
-a----       2016/11/10     19:10        3297280 dog_windows_3150436.dll
-a----       2016/11/10     19:10           5668 dog_windows_3150436.lib
-a----       2016/11/10     19:10        3632128 dog_windows_x64_3150436.dll
-a----       2016/11/10     19:10           5530 dog_windows_x64_3150436.lib

superdog-config.cmake

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
set(SUPERDOG_FOUND TRUE) # auto 
set(SUPERDOG_VERSION 2.3.0)
set(SUPERDOG_ROOT_DIR "C:/car_libs/superdog-c-2.3")

find_path(SUPERDOG_INCLUDE_DIR NAMES superdog/dog_api.h PATHS "${SUPERDOG_ROOT_DIR}/include")
mark_as_advanced(SUPERDOG_INCLUDE_DIR) # show entry in cmake-gui

find_library(SUPERDOG_LIBRARY NAMES dog_windows_x64_3150436.lib PATHS "${SUPERDOG_ROOT_DIR}/lib")
mark_as_advanced(SUPERDOG_LIBRARY) # show entry in cmake-gui

# use xxx_INCLUDE_DIRS and xxx_LIBRARIES in CMakeLists.txt
set(SUPERDOG_INCLUDE_DIRS ${SUPERDOG_INCLUDE_DIR} )
set(SUPERDOG_LIBRARIES ${SUPERDOG_LIBRARY} )

message( "superdog-config.cmake " ${SUPERDOG_ROOT_DIR})

Code Example

code

MyDogApiImpl.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#pragma once
#include <iostream>
#include <string>

#include <superdog/dog_api.h>

#include "errorprinter.h"

class MyDogApiImpl
{
public:
MyDogApiImpl(int feature_id, const std::string& vendor_code);

int login();

int logout();

private:
dog_handle_t handle;
int m_feature_id;
std::string m_vendor_code;

ErrorPrinter err;
};

MyDogApiImpl.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "mydog_api_impi.h"

MyDogApiImpl::MyDogApiImpl(int feature_id, const std::string& vendor_code)
{
m_feature_id = feature_id;
m_vendor_code = vendor_code;
}

int MyDogApiImpl::login()
{
dog_status_t status = dog_login(
m_feature_id,
(dog_vendor_code_t *)m_vendor_code.c_str(),
&handle
);
err.printError(status);
return (int)status;
}

int MyDogApiImpl::logout()
{
dog_status_t status = dog_logout(handle);
err.printError(status);
return (int)status;
}

test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <string>

#include <gtest/gtest.h>
#include <glog/logging.h>

#include "mydog/mydog.h"

using namespace std;

int test_api()
{
int feature_id = 111;
std::string vendor_code = "xxx"; // from `VendorCodes\BYAUY.hvc`

MyDogApi dog(feature_id, vendor_code);
int status = dog.login(); // 0 OK, other failed (feature id error, vendor_code error, NO SuperDog)

std::cout << "status = " << status << std::endl;

int status2 = dog.logout();
std::cout << "status2 = " << status2 << std::endl;
return 0;
}

TEST(test, test_api) {
test_api();
}

Python version supported

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "mydog_api.h"

#define BUILD_PYTHON_MYDOG

#ifdef BUILD_PYTHON_MYDOG

#include <pybind11/pybind11.h>

namespace py = pybind11;

int add(int i, int j) {
return i + j;
}

struct Pet {
Pet(const std::string &name) : name(name) { }
void setName(const std::string &name_) { name = name_; }
const std::string &getName() const { return name; }

std::string name;
};

PYBIND11_MODULE(mydog, m)
{
// optional module docstring
m.doc() = "mydog plugin for python ";

// FUNCTIONS
// expose add function, and add keyword arguments and default arguments
m.def("add", &add, "A function which adds two numbers", py::arg("i") = 1, py::arg("j") = 2);

// DATA
// exporting variables
m.attr("the_answer") = 42;
py::object world = py::cast("World");
m.attr("what") = world;


// CLASSES
/*
py::class_<Pet>(m, "Pet")
.def(py::init<const std::string &>())
.def("setName", &Pet::setName)
.def("getName", &Pet::getName);
*/

// MyDog
py::class_<MyDogApi>(m, "MyDogApi")
.def(py::init<int, const std::string &>())
.def("login", &MyDogApi::login)
.def("logout", &MyDogApi::logout);
}


/*
// =====================1
pybind11_add_module(${PYMYDOG_TARGET}
${HEADER_FILES}
${SOURCE_FILES}

# supder dog (dog_login,dog_logout)
${SUPERDOG_LIBRARIES}
)

// =====================2
add_library(${PYMYDOG_TARGET} MODULE
${HEADER_FILES}
${SOURCE_FILES}
)

target_link_libraries(${PYMYDOG_TARGET}
pybind11::module
${SUPERDOG_LIBRARIES}
)
*/

#endif // BUILD_PYTHON_MYDOG

cmake for C++ version

1
2
3
4
5
6
7
8
9
10
11
find_package(SUPERDOG REQUIRED) # user-defined supderdog 2.3
include_directories(${SUPERDOG_INCLUDE_DIRS})

add_library(${MYDOG_TARGET}
${HEADER_FILES}
${SOURCE_FILES}
)

target_link_libraries (${MYDOG_TARGET}
${SUPERDOG_LIBRARIES}
)

cmake for Python version

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
find_package(SUPERDOG REQUIRED) # user-defined supderdog 2.3
include_directories(${SUPERDOG_INCLUDE_DIRS})

find_package(pybind11 CONFIG REQUIRED)
include_directories(${pybind11_INCLUDE_DIRS})

add_library(${MYDOG_TARGET}
${HEADER_FILES}
${SOURCE_FILES}
)

target_link_libraries (${MYDOG_TARGET}
pybind11::module
${SUPERDOG_LIBRARIES}
)

rename mydog.dll to mydog.pyd

test pymydog

1
2
3
4
5
6
7
8
import mydog # mydog.pyd

feature_id = 111
vendor_code = "xxx"

dog = mydog.MyDogApi(feature_id,vendor_code)
print(dog.login())
print(dog.logout())

with files

dog_windows_x64_3150436.dll
mydog.py
mydog.pyd

Reference

History

  • 20181022: created.