DC LockToKey
this function can be used to decode the lock sent from a Direct Connect hub
//
// Copyright (c) CodeZiron.com
//
function DC_LockToKey(char* src; char* buf) {
uses ecx edx edi esi ebx;
esi = src;
edi = buf;
//remove lock if passed also
if (char*[esi] == ord('$Loc')) {
add esi, 6
}
//add space for $Key
add edi, 5
al = byte[esi];
xor al, 5
ah = al;
shr ax, 4
and ax, 0x0ff0
or al, ah
byte[edi] = al;
ecx = xor;
ecx++;
while (char*[esi+ecx] <> ord(' Pk=')) {
al = byte[esi+ecx];
if (!al) {
break;
}
xor al, [esi+ecx-1];
ah = al;
shr ax, 4
and ax, 0x0ff0
or al, ah
byte[edi+ecx] = al;
ecx++;
}
if (ecx < 3) {
return false;
}
al = byte[edi];
xor al, [edi+ecx-1]
byte[edi] = al;
esi = edi;
edi = buf;
char*[edi] = ord('$Key');
char[edi+4] = ord(' ');
add edi, 5
edx = xor;
while (edx < ecx) {
lodsb
if (al == 0) {
ebx = '/%DCN000%/..';
eax = char*[ebx];
stosd
eax = char*[ebx+4];
stosd
eax = char*[ebx+8];
stosw
} elseif (al == 5) {
ebx = '/%DCN005%/..';
eax = char*[ebx];
stosd
eax = char*[ebx+4];
stosd
eax = char*[ebx+8];
stosw
} elseif (al == 36) {
ebx = '/%DCN036%/..';
eax = char*[ebx];
stosd
eax = char*[ebx+4];
stosd
eax = char*[ebx+8];
stosw
} elseif (al == 96) {
ebx = '/%DCN096%/..';
eax = char*[ebx];
stosd
eax = char*[ebx+4];
stosd
eax = char*[ebx+8];
stosw
} elseif (al == 124) {
ebx = '/%DCN124%/..';
eax = char*[ebx];
stosd
eax = char*[ebx+4];
stosd
eax = char*[ebx+8];
stosw
} elseif (al == 126) {
ebx = '/%DCN126%/..';
eax = char*[ebx];
stosd
eax = char*[ebx+4];
stosd
eax = char*[ebx+8];
stosw
} else {
stosb
}
edx++;
}
eax = xor;
stosb
return true;
}
a quick sample using the function
//a buffer
char sKey[512];
DC_LockToKey('$Lock EXTENDEDPROTOCOL_HeXHub_TE_mzkfahwycyeq Pk=versiunea5.04', @sKey);
//source can also be without $Lock
DC_LockToKey('EXTENDEDPROTOCOL_HeXHub_TE_mzkfahwycyeq Pk=versiunea5.04', @sKey);
//write key
WriteLn(@sKey);
stats:
1,000,000 iterations breaking the above lock takes 407ms exactly, timed on a Core 2 Quad 2.4GHz with 2048MB DDR2 800