Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Samples

DC LockToKey

A community discussion post from the original code:zIRON forum.

Colin admin
Posts
928
Threads
49
Location
Bulgaria

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

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria

updated to use repeat and added an inline macro to shorten the code.

note that repeat requires compiler version 1.1.15.7

//
// 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;
  
	xinc ecx;
	repeat {
		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++;		
	} until (char*[esi+ecx] == ord(' Pk='));
	
	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
 
	inline op procedure stosDCN(s) {
		ebx = $s;
		eax = char*[ebx];
		stosd
		eax = char*[ebx+4];
		stosd
		eax = char*[ebx+8];
		stosw
	}
 
	edx = xor;
	repeat {
		lodsb
		if (al == 0) { 
			stosDCN '/%DCN000%/..';
		} elseif (al == 5) {
			stosDCN '/%DCN005%/..';
		} elseif (al == 36) {
			stosDCN '/%DCN036%/..';
		} elseif (al == 96) {
			stosDCN '/%DCN096%/..';
		} elseif (al == 124) {
			stosDCN '/%DCN124%/..';
		} elseif (al == 126) {
			stosDCN '/%DCN126%/..';
		} else {
			stosb
		}
		edx++;
	} while (edx < ecx);
	eax = xor;
	stosb
  
	return true;  
}