summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2015-11-28 13:17:24 +0100
committerErich Eckner <git@eckner.net>2015-11-28 13:17:24 +0100
commit51a9ea9aa803c7d73b0385d5cb9a0d2e0c17daf9 (patch)
treea7941a46de21bf79d818e50951e110880230402e
downloadEmails-51a9ea9aa803c7d73b0385d5cb9a0d2e0c17daf9.tar.xz
Wichtiges aus dem Delphi-Projekt für Windows
-rw-r--r--.gitignore9
-rw-r--r--Email.icobin0 -> 318 bytes
-rw-r--r--Hashes.pas151
-rw-r--r--gotmail.wavbin0 -> 18164 bytes
-rw-r--r--nichts.icobin0 -> 318 bytes
5 files changed, 160 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0ec6f30
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,9 @@
+*.bak
+*.ppu
+*.o
+*.tar.gz
+*~
+Emails
+lib
+Log*
+socket
diff --git a/Email.ico b/Email.ico
new file mode 100644
index 0000000..2f1d2f1
--- /dev/null
+++ b/Email.ico
Binary files differ
diff --git a/Hashes.pas b/Hashes.pas
new file mode 100644
index 0000000..284212c
--- /dev/null
+++ b/Hashes.pas
@@ -0,0 +1,151 @@
+unit Hashes;
+
+interface
+
+uses Windows, SysUtils, Classes;
+
+type
+ THashAlgorithm = (haMD5, haSHA1);
+
+function CalcHash(Stream: TStream; Algorithm: THashAlgorithm): string; overload;
+function CalcHash(Archivo: string; Algorithm: THashAlgorithm): string; overload;
+function CalcHash2(Str: string; Algorithm: THashAlgorithm): string;
+
+implementation
+
+type
+ HCRYPTPROV = ULONG;
+ PHCRYPTPROV = ^HCRYPTPROV;
+ HCRYPTKEY = ULONG;
+ PHCRYPTKEY = ^HCRYPTKEY;
+ HCRYPTHASH = ULONG;
+ PHCRYPTHASH = ^HCRYPTHASH;
+ LPAWSTR = PAnsiChar;
+ ALG_ID = ULONG;
+
+const
+ CRYPT_NEWKEYSET = $00000008;
+ PROV_RSA_FULL = 1;
+ CALG_MD5 = $00008003;
+ CALG_SHA1 = $00008004;
+ HP_HASHVAL = $0002;
+
+function CryptAcquireContext(phProv: PHCRYPTPROV;
+ pszContainer: LPAWSTR;
+ pszProvider: LPAWSTR;
+ dwProvType: DWORD;
+ dwFlags: DWORD): BOOL; stdcall;
+ external ADVAPI32 name 'CryptAcquireContextA';
+
+function CryptCreateHash(hProv: HCRYPTPROV;
+ Algid: ALG_ID;
+ hKey: HCRYPTKEY;
+ dwFlags: DWORD;
+ phHash: PHCRYPTHASH): BOOL; stdcall;
+ external ADVAPI32 name 'CryptCreateHash';
+
+function CryptHashData(hHash: HCRYPTHASH;
+ const pbData: PBYTE;
+ dwDataLen: DWORD;
+ dwFlags: DWORD): BOOL; stdcall;
+ external ADVAPI32 name 'CryptHashData';
+
+function CryptGetHashParam(hHash: HCRYPTHASH;
+ dwParam: DWORD;
+ pbData: PBYTE;
+ pdwDataLen: PDWORD;
+ dwFlags: DWORD): BOOL; stdcall;
+ external ADVAPI32 name 'CryptGetHashParam';
+
+function CryptDestroyHash(hHash: HCRYPTHASH): BOOL; stdcall;
+ external ADVAPI32 name 'CryptDestroyHash';
+
+function CryptReleaseContext(hProv: HCRYPTPROV; dwFlags: DWORD): BOOL; stdcall;
+ external ADVAPI32 name 'CryptReleaseContext';
+
+function CalcHash(Stream: TStream; Algorithm: THashAlgorithm): string; overload;
+var
+ hProv: HCRYPTPROV;
+ hHash: HCRYPTHASH;
+ Buffer: PByte;
+ BytesRead: DWORD;
+ Algid: ALG_ID;
+ Data: array[1..20] of Byte;
+ DataLen: DWORD;
+ Success: BOOL;
+ i: integer;
+begin
+ Result:= EmptyStr;
+ Success := CryptAcquireContext(@hProv, nil, nil, PROV_RSA_FULL, 0);
+ if (not Success) then
+ if GetLastError() = DWORD(NTE_BAD_KEYSET) then
+ Success := CryptAcquireContext(@hProv, nil, nil, PROV_RSA_FULL,
+ CRYPT_NEWKEYSET);
+ if Success then
+ begin
+ if Algorithm = haMD5 then
+ begin
+ Algid:= CALG_MD5;
+ Datalen:= 16
+ end else
+ begin
+ Algid:= CALG_SHA1;
+ Datalen:= 20;
+ end;
+ if CryptCreateHash(hProv, Algid, 0, 0, @hHash) then
+ begin
+ GetMem(Buffer,10*1024);
+ try
+ while TRUE do
+ begin
+ BytesRead:= Stream.Read(Buffer^, 10*1024);
+ if (BytesRead = 0) then
+ begin
+ if (CryptGetHashParam(hHash, HP_HASHVAL, @Data, @DataLen, 0)) then
+ for i := 1 to DataLen do
+ Result := Result + LowerCase(IntToHex(Integer(Data[i]), 2));
+ break;
+ end;
+ if (not CryptHashData(hHash, Buffer, BytesRead, 0)) then
+ break;
+ end;
+ finally
+ FreeMem(Buffer);
+ end;
+ CryptDestroyHash(hHash);
+ end;
+ CryptReleaseContext(hProv, 0);
+ end;
+end;
+
+function CalcHash(Archivo: string; Algorithm: THashAlgorithm): string; overload;
+var
+ Stream: TFileStream;
+begin
+ Result:= EmptyStr;
+ if FileExists(Archivo) then
+ try
+ Stream:= TFileStream.Create(Archivo,fmOpenRead or fmShareDenyWrite);
+ try
+ Result:= CalcHash(Stream,Algorithm);
+ finally
+ Stream.Free;
+ end;
+ except end;
+end;
+
+function CalcHash2(Str: string; Algorithm: THashAlgorithm): string;
+var
+ Stream: TStringStream;
+begin
+ Result:= EmptyStr;
+ Stream:= TStringStream.Create(Str);
+ try
+ Result:= CalcHash(Stream,Algorithm);
+ finally
+ Stream.Free;
+ end;
+end;
+
+end.
+
diff --git a/gotmail.wav b/gotmail.wav
new file mode 100644
index 0000000..61e0efa
--- /dev/null
+++ b/gotmail.wav
Binary files differ
diff --git a/nichts.ico b/nichts.ico
new file mode 100644
index 0000000..808280d
--- /dev/null
+++ b/nichts.ico
Binary files differ