auch ich bin auf die USB-Dongle von SG-Lock gestoßen und versuche mich gerade am Demo-Gerät, um mit AHK zu kommunizieren. Als Grundlage dienten die Infos aus dem Forum:https://www.autohotkey.com/boards/viewtopic.php?f=10&t=4130&hilit=sg+lock
Folgende Sachen habe ich unternommen:
- USB Dongle ID auf 1001 gesetzt
- AuthentCode an Dongle angepasst
- Datei "SglW32.dll" in C:\Windows\System32 gespeichert
- SglAuth.ahk im Quellordner gemäß Info Forum angelegt, Inhalt:
Code: Select all
; ======================================================================================================================
; Functions to use the SG-Lock (http://www.sg-lock.com/de/index.php) with AutoHotkey (http://www.autohotkey.com).
; This script must be included in the beginning inside the auto-execute-section of the programscript.
; It automatically detects to use the 32 or 64 bit SG-Lock Dll.
; The following routines are written by just me (2014/07)
;======================================================================================================================
Global SGL_SUCCESS := 0x0000 ; Error messages
, SGL_DGL_NOT_FOUND := 0x0001
, SGL_LPT_BUSY := 0x0002
, SGL_LPT_OPEN_ERROR := 0x0003
, SGL_NO_LPT_PORT_FOUND := 0x0004
, SGL_AUTHENTICATION_REQUIRED := 0x0005
, SGL_AUTHENTICATION_FAILED := 0x0006
, SGL_FUNCTION_NOT_SUPPORTED := 0x0007
, SGL_PARAMETER_INVALID := 0x0008
, SGL_SIGNATURE_INVALID := 0x0009
, SGL_USB_BUSY := 0x000A
, SGLDLL := A_PtrSize = 8 ? "SGLW64.DLL" : "SGLW32.DLL" ; Don´t change this!
; ======================================================================================================================
; Function: Load dll
; Return values:
; On success: Handle of loaded dll file
; On bad success: Errormessage and exit the program
; ======================================================================================================================
SGL_Init()
{
Static HMOD := 0
If (HMOD = 0) && !(HMOD := DllCall("Kernel32.dll\LoadLibrary", "Str", SGLDLL, "UPtr"))
{
MsgBox, 16, ERROR!, `n'%SGLDLL%' not loaded!`nProgram will be terminated.
ExitApp
}
Return HMOD
}
; ======================================================================================================================
; Function: Authentification between the script and the SglDLL.
; Parameters:
; AuthentCode Array with twelve 32 bit integers
; Return values:
; On success: 0x0000 (SGL_SUCCESS)
; On bad success: 0x0006 (SGL_AUTHENTICATION_FAILED)
; ======================================================================================================================
SGL_Authent(AuthentCode)
{
DllCall("msvcrt.dll\srand", "UInt", SGL_Rand()) ; Init MSVCRT Random generator
RandNumLo := SGL_Rand() ; Generate two random numbers
RandNumHi := SGL_Rand()
VarSetCapacity(RandNum, 8, 0) ; Generate and fill Randnum
NumPut(RandNumLo, RandNum, 0, "UInt")
NumPut(RandNumHi, RandNum, 4, "UInt")
VarSetCapacity(AppRandNum, 8, 0) ; Generate AppRandNum and fill with 0
NumPut(RandNumLo, AppRandNum, 0, "UInt")
NumPut(RandNumHi, AppRandNum, 4, "UInt")
VarSetCapacity(LibRandNum, 8, 0) ; Generate LibRandNum and initialize it with 0
VarSetCapacity(AuthentLocal, 32, 0) ; Generate AuthentLocal and fill it with the first 8 values of the AuthentCode
Addr := &AuthentLocal
Loop, 8 ;Generate TeaKey and fill it with the last 4 values of the AuthentCode
Addr := NumPut(AuthentCode[A_Index], Addr + 0, "UInt")
TeaKey := [AuthentCode[9], AuthentCode[10], AuthentCode[11], AuthentCode[12]]
RetCode := DllCall(SGLDLL . "\SglAuthentA", "Ptr", &AuthentLocal, "Ptr", &AppRandNum, "Ptr", &LibRandNum, "UInt") ; Call 'SglAuthentAÄ from Dll file
If (RetCode <> SGL_SUCCESS) ; Check result and exit on error.
Return SGL_AUTHENTICATION_FAILED . ": SglAuthentA"
SGL_TeaEncipher(RandNum, RandNum, TeaKey) ; Encrypt RandNum with TeaKey
If (NumGet(RandNum, 0, "UInt") <> NumGet(AppRandNum, 0, "UInt")) ; Check if the result conciders eith AppRandNum.
|| (NumGet(RandNum, 4, "UInt") <> NumGet(AppRandNum, 4, "UInt")) ; If not, exit.
Return SGL_AUTHENTICATION_FAILED . ": Sgl_TeaEncipher 1"
SGL_TeaEncipher(LibRandNum, LibRandNum, TeaKey) ; Encrypt LibRandNum with TeaKey
RetCode := DllCall(SGLDLL . "\SglAuthentB", "Ptr", &LibRandNum, "UInt") ; Call DLL function 'SglAuthentB'
If (RetCode <> SGL_SUCCESS) ; Check relult and exit on error
Return SGL_AUTHENTICATION_FAILED . " - " . RetCode . " - " . ErrorLevel . " - SglAuthentB"
Return SGL_SUCCESS ; Anything is all right
}
; ======================================================================================================================
; Internal functions
; ======================================================================================================================
SGL_TeaEncipher(ByRef InData, ByRef OutData, ByRef Key)
{
Static Delta := 0x9E3779B9
Y := NumGet(InData, 0, "UInt") ; Initialize local vaiables
Z := NumGet(InData, 4, "UInt")
A := Key[1]
B := Key[2]
C := Key[3]
D := Key[4]
Sum := 0
N := 32
Loop, % N
{ ; Encrypt
Sum := SGL_UINT(Sum + Delta)
Y := SGL_UINT(Y + (((Z << 4) + A) ^ (Z + Sum) ^ ((Z >> 5) + B)))
Z := SGL_UINT(Z + (((Y << 4) + C) ^ (Y + Sum) ^ ((Y >> 5) + D)))
}
NumPut(Y, OutData, 0, "UInt") ; Write result to OutData
NumPut(Z, OutData, 4, "UInt")
}
; ----------------------------------------------------------------------------------------------------------------------
SGL_Rand()
{
Return ((DllCall("msvcrt.dll\rand", "Int") << 16) | DllCall("msvcrt.dll\rand", "Int")) & 0xFFFFFFFF
}
; ----------------------------------------------------------------------------------------------------------------------
SGL_UINT(Value)
{
Return (Value & 0xFFFFFFFF)
}
; ======================================================================================================================
Code: Select all
; 2014/07 by Gucky
; This program shows how to use the SG-Lock together with AutoHotKey
; IMPORTANT NOTE:
; With the Demo Authent Key it´s impossible to read/write data from/to
; the memory or counter and/or to encrypt/decrypt data, because the
; demo locks (U2 type) don´t have any memory to store data.
#NoEnv
#Include SglAuth.AHK
SetBatchlines -1
; This is the DEMO authentication code, every regular SG-Lock user gets its own unique authentication code.
AuthentCode := [0xF574D17B, 0xA94628EE, 0xF2857A8F, 0x69346B4A
,0x4136E8F2, 0x89ADC688, 0x80C2C1D4, 0xA8C6327C
,0x1A72699A, 0x574B7CA0, 0x1E8D3E98, 0xD7DEFDC5]
SGL_Init()
; Search for a SG-Lock with a specified product id
ProductID := 1001
If SGL_Authent(AuthentCode) = 0
{
If SGL_SearchLock(ProductID) = 0
MsgBox, 0, SGL_SearchLock(), Found SG-Lock with the`nproduct id: %ProductID%
else
MsgBox, 0, SGL_SearchLock(), Unable to find SG-Lock`nwithproduct id: %ProductID%
}
Else
MsgBox, 0, SGL_Authent(), % "ERROR!`nDLL Authentification failed."
ExitApp
SGL_SearchLock(SGL_ProductID)
{
Result := Return DllCall(SGLDLL . "\SglSearchLock", "UInt", SGL_ProductID)
If Result = 0
Return 0
else
Return -%Result%
}
Diese Funktion sollte nun den Dongle suchen.
Egal wie ich an die Geschichte herangehe (AHK A32, AHK U32, AHKU64, diverse Skriptversuche...),
ich komme immer bei dem folgenden Fehler heraus:
Scheinbar ist die Kommunikation zur SGLW32.dll fehlerhaft und ich weiß nicht wie ich dieses Thema beheben kann.
Kann jemand hier weiterhelfen oder weiß noch Rat. Ich weiß das verhergehende Thema ist sehr sehr alt Umso mehr freue ich mich über euer Feedback...