Page 1 of 1
Lizenzfile entschlüsseln
Posted: Mon Feb 03, 2020 1:37 pm
by lagraf
Hallo,
um das Raubkopieren zu erschweren, habe ich in meinen VO Apps seit 1.0 eine Routine, welche einen OEM String aus einer Lizenzdatei wie folgt decodiert:
Code: Select all
FUNCTION GetLicense(cStr AS STRING, cKey AS STRING) AS STRING PASCAL
LOCAL x, y, z AS DWORD
x := y := 1
DO WHILE x <= Len(cStr)
z := 256 + Asc(SubStr(cStr,x,1)) - Asc(SubStr(cKey,y,1)) - x - y
z -= iif(z>=256, 256, 0)
cStr := Stuff(cStr, x, 1, Chr(z))
x += 1
y := iif(y >= Len(cKey), 1, y+1)
ENDDO
RETURN cStr
In X# kommt jedoch nur Blödsinn heraus, hängt wahrscheinlich mit irgendwelchen internen Zeichensätzen zusammen. Wie muß die Routine umgeschrieben werden, damit sie wieder einen korrekten Returnwert liefert?
Lizenzfile entschlüsseln
Posted: Mon Feb 03, 2020 2:27 pm
by Chris
Hi Franz,
That's because Asc() and Chr() are designed to work with unicode strings (that are used in .Net), while you are assuming 8-bit strings (as in VO). Try using AscW() and ChrW() instead, which do not do any ansi/unicode translation, does it work now as you'd expect?
If not, please give as some sample contents of the key and value strings, so we can propose an alternative way of writing this code.
Lizenzfile entschlüsseln
Posted: Mon Feb 03, 2020 2:53 pm
by lagraf
Hi Chris,
AscW / ChrW does not bring the correct output. I've attached one license file and for this the output should be
Code: Select all
WIN_RBKASSA_9999_01_Gärtnerei Rachbauer (01)_31.12.2999_J_XXXXXXXXXXXXXXXX_201326w
The _ is a visual filler for HT chr(9)
The cKey param is CORAONLY in uppercases
Read the file simply with cStr := MemoRead("01RBKASSA.WIN")
Lizenzfile entschlüsseln
Posted: Mon Feb 03, 2020 3:48 pm
by robert
Franz,
If you read the file with MemoRead then the characters are converted from bytes to unicode.
If you want to work directly with the bytes then I would advise to not use MemoRead() but use MemoReadBinary().
This returns the contents of the file as a byte[]. Inside GetLicense you can then walk the array of bytes and instead of Substr(cStr,x,1) you can then simply use aBytes[x] (assuming you have named the parameter aBytes).
Of course Len(cStr) must then also be replaced with aBytes:Length.
Afterwards you can convert the bytes to a unicode string with System.Text.Encoding.GetEncoding(1252).GetString(aBytes)
You can replace 1252 with another codepage number when needed.
Robert
Lizenzfile entschlüsseln
Posted: Mon Feb 03, 2020 4:39 pm
by lagraf
Hi Robert,
thank you for your infos!
Now the funktion looks like
Code: Select all
FUNCTION GetLicense(aStr AS BYTE[], cKey AS STRING) AS STRING PASCAL
// aStr is read with MemoReadBinary
LOCAL nCode, x, y, z AS DWORD
LOCAL cStr := AS STRING
y := 1
FOR x := 1 TO aStr:length
z := 256 + aStr[x] - AscW(SubStr(cKey,y,1)) - x - y
z -= iif(z>=256, 256, 0)
cStr += ChrW(z)
y := iif(y >= Len(cKey), 1, y+1)
NEXT
RETURN cStr
The output looks good, but the ä in Gärtnerei is not correct decoded!
Lizenzfile entschlüsseln
Posted: Mon Feb 03, 2020 4:44 pm
by Chris
Hi Franz,
All the characters in strings that are "standard" Latin have the same code in both ansi/oem and unicode. So "A" is always 65, "C" is 67 etc, so for this case it is easy to convert "CORAONLY" to 8-bit. The issue is with non-standard chars, for example "ä" has a unicode value of 228 and "α" is 391.
Lizenzfile entschlüsseln
Posted: Mon Feb 03, 2020 4:47 pm
by wriedmann
Hallo Franz,
vielleicht hilft das beim Verständnis ein bisschen weiter:
https://docs.xsharp.it/doku.php?id=string_char_byte
Wolfgang
Lizenzfile entschlüsseln
Posted: Mon Feb 03, 2020 4:52 pm
by Karl-Heinz
Hi Franz,
When i try:
Code: Select all
SetAnsi ( true )
? GetLicense ( MemoRead ( "d:test1RBKASSA.WIN" ) , "CORAONLY" )
the word [Gärtnerei] is shown as [G"rtnerei]. But after a additional Oem2Ansi() the "ä" appears.
Code: Select all
? Oem2Ansi(GetLicense ( MemoRead ( "d:test1RBKASSA.WIN" ) , "CORAONLY" ) )
Code: Select all
WIN RBKASSA 9999 01 Gärtnerei Rachbauer (01) 31.12.2999
J XXXXXXXXXXXXXXXX 201326w
Is this the correct result ?
BTW. The GetLicense() func i´m using still uses Chr()/Asc() and not ChrW()/AscW()
regards
Karl-Heinz
Lizenzfile entschlüsseln
Posted: Mon Feb 03, 2020 5:21 pm
by lagraf
Hallo Karl-Heinz,
das funktioniert so, die Lizenz kommt aus einem Harbour (DOS) Programm, daher ist Oem2Ansi notwendig!
Danke!