![]() |
Benötige Hilfe bei einer Entschlüsselung bei altem Programm
Zum Entschlüsseln von Daten wurden in einem altem Pascal-Programm folgender Code verwendet. Kann mir jemand Helfen daraus eine Funktion zu basteln?
Es muss bei folgenden HEX String "82 6a 55 b0 3b 63" "THOMAS" raus kommen.
Code:
(*******************************************************************************
PROCEDURE Crypt (dataPtr: AdsMem; 8 [bp] --> es:di 4 Byte Pointer dataLen: WORD 6 [bp] --> cx 2 Byte Laenge ); EXTERN; *******************************************************************************) Crypt PROC FAR push bp mov bp, sp call near TestRandom push cx mov cx, 6 [bp] ; cx:= dataLen jcxz @crReturn push es push di les di, 8 [bp] ; es:di:= dataPtr shr cx, 1 ; immer 2 Bytes werden ver/entSchlüsselt @crLoop: call near NextRand; xor ax, Word Ptr es:[di] stosW ; es:[di]:= verschluesseltes Word dec cx jnz @crLoop pop di pop es @crReturn: pop cx mov sp, bp pop bp retf 6 ; dataPtr, dataLen wegwerfen Crypt ENDP |
AW: Benötige Hilfe bei einer Entschlüsselung bei altem Programm
Die eigentliche Funktion ist doch trivial:
Delphi-Quellcode:
Ohne die Funktionen testrandom und nextrand wird Dir das aber wahrscheinlich nicht viel weiterhelfen.:(
procedure crypt(var data: array of word; datalen: integer);
var i: integer; begin testrandom; for i:=0 to datalen div 2 do data[i] := data[i] xor nextrand; end; |
AW: Benötige Hilfe bei einer Entschlüsselung bei altem Programm
Ich hab mal nachgeschaut und folgendes noch gefunden. Ich hoffe es ist komplett.
Code:
bzw.
TestRandom PROC NEAR
push ds push si push es push di push cx push ds ; es:= ds pop es mov di, offSet @Gard1 ; di:= ofs @Gard1 mov si, offSet @Gard2 ; si:= ofs @Gard2 mov cx, 6 cld repe cmpsb ; @Gard1 = @Gard2 ? je @trReturn mov dx, offset @Gard1 mov ah, 9 int 21H mov dx, offset @msg mov ah, 9 int 21H call far EndXqq @trReturn: pop cx pop di pop es pop si pop ds ret near TestRandom ENDP
Code:
NextRand PROC NEAR ; result in ax
push bx push cx mov ax, Word ptr zz [0]; mov bx, Word ptr zz [2]; mov cx, Word ptr zz [4]; sub ax, bx; jnc @nrStore; add ax, p @nrStore: mov Word ptr zz [0], bx mov Word ptr zz [2], cx mov Word ptr zz [4], ax pop cx pop bx ret near NextRand ENDP |
AW: Benötige Hilfe bei einer Entschlüsselung bei altem Programm
Das is ja noch einfacher:
Delphi-Quellcode:
Gleich mit Teststub, liefert bei mir: 54350 35009 55073 19341 45514 35732 39405 9782 61905 29623.
var
zz: array[0..5] of byte; var p: word; {??? was ist das} function nextrand: word; begin asm push bx mov ax, Word ptr zz [0]; mov bx, Word ptr zz [2]; mov cx, Word ptr zz [4]; sub ax, bx; jnc @@nrStore; add ax, p @@nrStore: mov Word ptr zz [0], bx mov Word ptr zz [2], cx mov Word ptr zz [4], ax mov @result, ax pop bx end; end; var i: integer; begin randseed := 0; p := 42; for i:=0 to 5 do zz[i] := random(256); for i:=1 to 10 do writeln(nextrand); end. Bleiben die Fragen: wie wird zz initialisiert?, was ist p? und wozu das Gedöns in TestRandom?. |
AW: Benötige Hilfe bei einer Entschlüsselung bei altem Programm
Hallo Gammatester,
warum das geanze Gedöns weiß ich auch nicht. Ich habe dir per Mail den meiner Meinung nach den ganzen Source geschickt welche notwendig sein sollte. Wir müssen hier Daten aus einem alten Programm importieren. |
AW: Benötige Hilfe bei einer Entschlüsselung bei altem Programm
Hier der schnell zusammengehackte Proof-of-Concept:
Delphi-Quellcode:
Kompilieren und Ausgabe:
program fcrypt;
{$ifdef VER70} type ansichar = char; {$else} {$apptype console} {$endif} {----------------------------------------------------} var zz: array[0..5] of byte; const p = 65521; function nextrand: word; begin asm push bx mov ax, Word ptr zz [0]; mov bx, Word ptr zz [2]; mov cx, Word ptr zz [4]; sub ax, bx; jnc @@nrStore; add ax, p @@nrStore: mov Word ptr zz [0], bx mov Word ptr zz [2], cx mov Word ptr zz [4], ax mov @result, ax pop bx end; end; {----------------------------------------------------} procedure crypt(var bdata; datalen: integer); var i: integer; data: array[0..32000] of word absolute bdata; begin for i:=0 to datalen div 2 - 1 do data[i] := data[i] xor nextrand; end; {----------------------------------------------------} const Initkey: array[0..5] of ansichar = 'OsyPPS'; const test: array[0..5] of byte = ($82, $6a, $55, $b0, $3b, $63); var ct: array[0..sizeof(test)-1] of ansichar; i: integer; begin move(initkey, zz, 6); move(test,ct,sizeof(ct)); crypt(ct,6); write('Der entschlüsselte Text lautet: '); for i:=0 to 5 do write(ansichar(ct[i])); writeln; end.
Code:
Der Rest bleibt als Übungsaufgabe, hoffentlich hilft's weiter.
Y:\WORK\Dev>D:\DMX\M12\DCC32 -b fcrypt.pas
CodeGear Delphi for Win32 compiler version 20.0 Copyright (c) 1983,2008 CodeGear fcrypt.pas(67) 68 lines, 0.10 seconds, 14668 bytes code, 13068 bytes data. Y:\WORK\Dev>FCRYPT.EXE Der entschlüsselte Text lautet: THOMAS Gruß Gammatester |
AW: Benötige Hilfe bei einer Entschlüsselung bei altem Programm
Hallo Gammatester,
ja vorerst hilft es weiter. Was müsste ich machen dass es außerhalb einer Konsolenanwendung läuft? |
AW: Benötige Hilfe bei einer Entschlüsselung bei altem Programm
Zitat:
|
AW: Benötige Hilfe bei einer Entschlüsselung bei altem Programm
Ja danke jetzt funktioniert es. Hatte eine Zeile vergessen zu übernehmen. :oops:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:23 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz