-
Notifications
You must be signed in to change notification settings - Fork 6
/
uclhasp.c
119 lines (111 loc) · 2.46 KB
/
uclhasp.c
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* UCLHasp Emulator for plugin HASPVDD driver
*
* (c) [email protected] 2022
*
* This module implements an interface with the well-known UCLHASP HASP-
* emulator, in order to create a userspace-only HASP emulation facility
* which is targeted at DOS programs running in NTVDM
*
*/
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include "registry.h"
VOID __stdcall Buffer0x28(VOID);
VOID __stdcall Buffer0x48(VOID);
VOID __stdcall Buffer0x54(VOID);
/* Main dispatch routine for the call emulation
*
* Parameters:
* Buffer - [IN ] Buffer to process, gets read and filled by underlying
* UCLhasp function
* Length - [IN ] Length of Buffer
* ReadBytes - [OUT] Number of bytes read
* Returns:
* TRUE - Operation successful
* FALSE - Failed
*/
__declspec(dllexport) BOOL __stdcall
CallHardlock(HaspBufferInStruc* HaspBuffer, ULONG HaspBufferLength, PDWORD ReadBytes)
{
switch (HaspBufferLength) {
case 0x48:
{
__asm
{
push ebp
mov ebp, HaspBuffer
call Buffer0x48
pop ebp
}
break;
}
case 0x54:
{
__asm {
push ebp
mov ebp, HaspBuffer
call Buffer0x54
pop ebp
}
break;
}
case 0x28:
{
__asm
{
push ebp
mov ebp, HaspBuffer
call Buffer0x28
pop ebp
};
break;
}
default:
{
OutputDebugStringA("Buffer Length is not supported");
return FALSE;
}
}
if (ReadBytes) *ReadBytes = HaspBufferLength;
return TRUE;
}
/* Loads dongle dumps from potential locations of well-known Dongle Emulators
*
* Returns:
* TRUE - Some dumps were found and loaded
* FALSE - No dumps were found
*/
BOOL LoadDumps(void)
{
t_Supported = 0;
heapSupported = NULL;
heapMemory = NULL;
LoadDumpKey("SYSTEM\\CurrentControlSet\\Services\\Emulator\\Hasp\\Dump");
LoadDumpKey("SYSTEM\\CurrentControlSet\\MultiKey\\Dumps");
LoadDumpKey("SYSTEM\\CurrentControlSet\\Mkbus");
if (!t_Supported) return FALSE;
return TRUE;
}
/* DLL entry point */
#ifdef _DEBUG
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
#else
BOOL WINAPI _DllMainCRTStartup(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
#endif
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hinstDLL);
if (!LoadDumps())
{
MessageBoxA(NULL, "No dumps of dongle keys found!\n", "UCLHASP Error", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
break;
case DLL_PROCESS_DETACH:
FreeDumpMemory();
break;
}
return TRUE;
}