Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi sequence of byte -> komischer Datentyp (https://www.delphipraxis.net/116011-sequence-byte-komischer-datentyp.html)

BUG 21. Jun 2008 19:55


sequence of byte -> komischer Datentyp
 
Moin moin,

ich versuche die MD5 Proceduren aus der Microsoft Cryptdll.dll zu benutzen,
leider tritt dabei beim Ausführen folgendes Codes eine AccessViolation bzw. Priviligierte Instruktion auf.

Ich nehme an das mit den Aufrufen der Funktionen etwas schief läuft ... die Aufrufkonventionen müsste aber stimmen, ist ja aus der Windows API

Delphi-Quellcode:
// ...

uses classes;

// Windows Cript API imports

type MD5_CTX = packed record
  i: packed array[0..1] of longint;      // ULONG[2]
  buf: packed array[0..3] of longint;    // ULONG[4]
  _in: packed array[0..63] of byte;      // unsigned char[64]
  digest: packed array[0..15] of byte;   // unsigned char[16]
end;

procedure MD5Init(var MD5_CTX); stdcall; external 'Cryptdll.dll' name 'MD5Init';
procedure MD5Update(var MD5_CTX; const input; inputLength: longint); stdcall; external 'Cryptdll.dll' name 'MD5Init';
procedure MD5Final(var MD5_CTX); stdcall; external 'Cryptdll.dll' name 'MD5Init';

function StreamToMD5String(x: TStream): string; // suboptimaler Funktionsname

implementation

function StreamToMD5String(x: TStream): string;
var context: MD5_CTX;
    buffer: packed array[0..511] of byte;
    length: integer;
begin
     MD5Init(context);
     x.Position := 0;
     repeat
           length := x.Read(buffer, 512);
           MD5Update(context, buffer, length);
     until length <= 0;
     MD5Final(context);
end;

// ...
Problematisch bei der Übersetzung/Einbindung ist folgendes:
Code:
 procedure MD5Update(
  var context: MD5_CTX,
  input: sequence of BYTE,
  inputLen: integer)
[Quelle]

Was ist "sequence of BYTE"?

Pointer hab ich schon probiert (s.o.)...

Ich freue mich über sachdienliche Hinweise :)


MfG,
Bug

Olli 21. Jun 2008 19:58

Re: sequence of byte -> komischer Datentyp
 
Zitat:

Zitat von BUG
Was ist "sequence of BYTE"?

Array[0..x] of Byte?

Ich denke, daß es in der Protokollbeschreibung nur "symbolisch" so steht. Es ist kein eigentlicher Typ. Im Notfall kann ich mal mit IDA in die DLL gucken.

BUG 21. Jun 2008 20:12

Re: sequence of byte -> komischer Datentyp
 
Zitat:

Zitat von Olli
Array[0..x] of Byte?

Glaub ich nicht, erstens unterstützt stdcall AFAIK keine Parameter variabler Länge und zweitens müsste dann folgendes funktionieren:
Delphi-Quellcode:
type TInput = packed array[0..511] of byte;

procedure MD5Update(var MD5_CTX; input: TInput; inputLength: longint); stdcall; external 'Cryptdll.dll' name 'MD5Init';

// ...

var buffer: TInput;
// ...
     MD5Init(context);
// ...
           MD5Update(context, buffer, 512);
// ...
     MD5Final(context);
// ...
Zitat:

Zitat von Olli
Im Notfall kann ich mal mit IDA in die DLL gucken.

Das wär nett ... aber eigentlich sollte sich doch bei sowas eine Lösung finden lassen, ohne sich an den Seziertisch zu begeben :?

MfG,
Bug

Olli 21. Jun 2008 20:15

Re: sequence of byte -> komischer Datentyp
 
Zitat:

Zitat von BUG
Zitat:

Zitat von Olli
Array[0..x] of Byte?

Glaub ich nicht, erstens unterstützt stdcall AFAIK keine Parameter variabler Länge und zweitens müsste dann folgendes funktionieren

Ja, das sollte identisch sein. Allerdings würde ein Array ohnehin als Pointer übergeben. Aber vielleicht ist es Pointer auf Pointer.

Ich schau mal schnell rein.

Olli 21. Jun 2008 20:57

Re: sequence of byte -> komischer Datentyp
 
Da schau ich so rein und da fällt mir auf, daß ich das doch schon kenne. Ist doch dokumentiert ;)

http://msdn.microsoft.com/en-us/library/bb432359(VS.85).aspx

Ich würde dir aber mal empfehlen nochmal hier nachzulesen.

BUG 21. Jun 2008 21:27

Re: sequence of byte -> komischer Datentyp
 
Aber dann müßte das:
Delphi-Quellcode:
procedure MD5Update(var context: MD5_CTX; const input; inputLength: word); stdcall; external 'Cryptdll.dll' name 'MD5Init';
doch funktionieren, oder? Macht es leider nicht ... irgendwas mach ich falsch :wall:

Zitat:

Zitat von Olli
Ich würde dir aber mal empfehlen nochmal hier nachzulesen.

Soll nichts werden, was mutwillig manipuliert wird. Trotzdem danke für die Warnung.

EDIT: :wall: hat geholfen, natürlich muss da
Delphi-Quellcode:
procedure MD5Update(var context: MD5_CTX; const input; inputLength: word); stdcall; external 'Cryptdll.dll' name 'MD5Update';
stehen ... Problem gelöst!

Trotzdem vielen Dank!

MfG,
Bug

Olli 21. Jun 2008 21:30

Re: sequence of byte -> komischer Datentyp
 
Könntest du mir einfach mal das kompilierte Programm anhängen? Ich würde es einfach mal im IDA Debgger durchlaufen lassen und mir die C-Variante vergleichend anschauen.


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:02 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz