Skip to content

Commit bd27d48

Browse files
committed
improve the encoding a little bit (in case of repeat)
1 parent 0906d50 commit bd27d48

File tree

1 file changed

+76
-20
lines changed

1 file changed

+76
-20
lines changed

Cheat Engine/feces.pas

Lines changed: 76 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
interface
77

88
uses
9-
Classes, SysUtils, bcrypt, DOM, xmlutils, XmlRead, XMLWrite, dialogs, windows, graphics;
9+
Classes, SysUtils, bcrypt, DOM, xmlutils, XmlRead, XMLWrite, dialogs, windows,
10+
graphics, math;
1011

1112
function canSignTables: boolean;
1213
procedure signTable(cheattable: TDOMElement);
@@ -395,7 +396,7 @@ procedure signTableFile(f: string);
395396
WriteXMLFile(d,f);
396397
end;
397398

398-
procedure getPasswordHash(password: string; var hashbuffer: pointer; var hashlength: integer);
399+
procedure generateHash(password: pointer; passwordsize: integer; var hash: pointer; var hashsize: integer);
399400
var
400401
s: ntstatus;
401402
hashAlgoritm: BCRYPT_ALG_HANDLE;
@@ -405,12 +406,11 @@ procedure getPasswordHash(password: string; var hashbuffer: pointer; var hashlen
405406

406407
size: ulong;
407408
i,j: integer;
409+
secondaryvalue: byte;
408410
begin
409-
if password='' then
410-
begin
411-
hashbuffer:=nil;
412-
exit;
413-
end;
411+
hash:=nil;
412+
hashsize:=0;
413+
if passwordsize=0 then exit;
414414

415415
s:=BCryptOpenAlgorithmProvider(hashAlgoritm, 'SHA512', nil, 0);
416416
if succeeded(s) then
@@ -425,37 +425,93 @@ procedure getPasswordHash(password: string; var hashbuffer: pointer; var hashlen
425425
s:=BCryptCreateHash(hashAlgoritm, hHash, bHashObject, objectlength, nil, 0, 0);
426426
if succeeded(s) then
427427
begin
428-
s:=BCryptHashData(hHash, @password[1], length(password), 0);
428+
s:=BCryptHashData(hHash, password, passwordsize, 0);
429429
if succeeded(s) then
430430
begin
431-
s:=BCryptGetProperty(hashAlgoritm, BCRYPT_HASH_LENGTH, @hashlength, sizeof(DWORD), size, 0);
431+
s:=BCryptGetProperty(hashAlgoritm, BCRYPT_HASH_LENGTH, @hashsize, sizeof(DWORD), size, 0);
432432
if succeeded(s) then
433433
begin
434-
getmem(hashbuffer, hashlength);
435-
s:=BCryptFinishHash(hHash, hashbuffer, hashlength, 0);
434+
getmem(hash, hashsize);
435+
s:=BCryptFinishHash(hHash, hash, hashsize, 0);
436+
436437
end;
437438
end;
438439
BCryptDestroyHash(hashAlgoritm);
439440
end;
440441
freemem(bHashObject);
441442
BCryptCloseAlgorithmProvider(hashAlgoritm,0);
442443
end;
443-
444444
end;
445445
end;
446446

447-
procedure hashDecode(buffer: pbyte; buffersize: integer; hash: pbyte; hashsize: integer);
448-
var i,j: integer;
447+
procedure getPasswordHash(password: string; out pwhash: pointer; out pwhashlength: integer; wantedsize: integer);
448+
var
449+
hash: array of byte;
450+
451+
initialHash: pbyte;
452+
initialhashsize: integer;
453+
454+
partialhash: pbyte;
455+
partialhashsize: integer;
456+
457+
hashpos: integer;
458+
copysize: integer;
459+
i,j: integer;
449460
begin
450-
j:=0;
451-
for i:=0 to buffersize-1 do
461+
pwhash:=nil;
462+
if password='' then exit;
463+
464+
setlength(hash,wantedsize);
465+
466+
467+
//generate hashes until it's the size of the buffer
468+
hashpos:=0;
469+
470+
generateHash(@password[1],length(password),initialhash,initialhashsize);
471+
472+
j:=1;
473+
for i:=0 to initialhashsize-1 do
452474
begin
453-
buffer[i]:=buffer[i] xor hash[j];
475+
initialhash[i]:=initialhash[i] xor ord(password[j]);
454476
inc(j);
455-
if j>=hashsize then j:=0;
477+
if j>length(password) then j:=1;
456478
end;
479+
480+
generateHash(initialhash,initialhashsize,partialhash,partialhashsize);
481+
freemem(initialhash);
482+
483+
copysize:=ifthen(partialhashsize>wantedsize, wantedsize, partialhashsize);
484+
copymemory(@hash[0],partialhash, copysize);
485+
freemem(partialhash);
486+
487+
inc(hashpos, copysize);
488+
489+
while hashpos<wantedsize do
490+
begin
491+
generateHash(@hash[hashpos-copysize],copysize,partialhash, partialhashsize);
492+
493+
copysize:=ifthen(partialhashsize+hashpos>wantedsize, wantedsize-hashpos, partialhashsize);
494+
copymemory(@hash[hashpos],partialhash, copysize);
495+
freemem(partialhash);
496+
inc(hashpos,copysize);
497+
end;
498+
499+
getmem(pwhash, wantedsize);
500+
copymemory(pwhash, @hash[0],wantedsize);
501+
502+
setlength(hash,0);
503+
end;
504+
505+
506+
procedure passwordDecode(buffer: pbyte; buffersize: integer; pwhash: pbyte);
507+
var
508+
i: integer;
509+
begin
510+
for i:=0 to buffersize-1 do
511+
buffer[i]:=buffer[i] xor pwhash[i];
457512
end;
458513

514+
459515
procedure signTable(cheattable: TDOMElement);
460516
var
461517
f: tfilestream;
@@ -546,7 +602,7 @@ procedure signTable(cheattable: TDOMElement);
546602
end;
547603

548604
if InputQuery('CE Signature', 'Enter your password', true, password)=false then exit;
549-
getPasswordHash(password, pwhash, pwhashlength);
605+
getPasswordHash(password, pwhash, pwhashlength, m.size-m.position);
550606
end
551607
else
552608
begin
@@ -556,7 +612,7 @@ procedure signTable(cheattable: TDOMElement);
556612
passwordhash:=nil; //in case it's wrong/changed
557613

558614
if pwhash<>nil then
559-
HashDecode(pointer(ptruint(m.memory)+m.position), m.size-m.position, pwhash, pwhashlength);
615+
passwordDecode(pointer(ptruint(m.memory)+m.position), m.size-m.position, pwhash);
560616
end;
561617

562618
try

0 commit comments

Comments
 (0)