ReactOS 0.4.16-dev-927-g467dec4
precomp.h File Reference
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <strsafe.h>
#include <conutils.h>
Include dependency graph for precomp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

BOOL hash_file (LPCWSTR Filename)
 
BOOL asn_dump (LPCWSTR Filename)
 

Function Documentation

◆ asn_dump()

BOOL asn_dump ( LPCWSTR  Filename)

Definition at line 456 of file asn.cpp.

457{
460
462 {
463 ConPrintf(StdOut, L"CertUtil: -asn command failed to open: %d\n", GetLastError());
464 return FALSE;
465 }
466
469 {
470 ConPrintf(StdOut, L"CertUtil: -asn command failed to get file size: %d\n", GetLastError());
472 return FALSE;
473 }
474
475 if (dwSize == 0)
476 {
477 ConPrintf(StdOut, L"CertUtil: -asn command got an empty file\n");
479 return FALSE;
480 }
481
483 if (!pData)
484 {
485 ConPrintf(StdOut, L"CertUtil: -asn command failed to allocate: %d\n", GetLastError());
487 return FALSE;
488 }
489
490 DWORD cbRead;
491 BOOL fRead = ReadFile(hFile, pData, dwSize, &cbRead, NULL);
494
495 if (!fRead || cbRead != dwSize)
496 {
497 ConPrintf(StdOut, L"CertUtil: -asn command failed to read: %d\n", dwErr);
499 return FALSE;
500 }
501
502 WCHAR Buffer[MAX_PATH] = {0};
503 BOOL fSucceeded = ParseAsn(pData, pData, dwSize, Buffer, TRUE);
504
506 return fSucceeded;
507}
BOOL ParseAsn(PBYTE pRoot, PBYTE pData, DWORD dwSize, PWSTR wszPrefix, BOOL fPrint)
Definition: asn.cpp:339
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdOut
Definition: fc.c:14
DWORD dwErr
Definition: service.c:36
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define FILE_SHARE_READ
Definition: compat.h:136
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
IN PVCB IN PBCB OUT PDIRENT IN USHORT IN POEM_STRING Filename
Definition: fatprocs.h:940
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define FILE_FLAG_SEQUENTIAL_SCAN
Definition: disk.h:43
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
_In_ HANDLE hFile
Definition: mswsock.h:90
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define INVALID_FILE_SIZE
Definition: winbase.h:574
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ hash_file()

BOOL hash_file ( LPCWSTR  Filename)

Definition at line 13 of file hashfile.cpp.

14{
16 BOOL bSuccess = FALSE;
17
20
22 {
23 ConPrintf(StdOut, L"CertUtil: -hashfile command failed: %d\n", GetLastError());
24 return bSuccess;
25 }
26
28 {
30
32 {
33 BYTE Buffer[2048];
34 DWORD cbRead;
35
36 while ((bSuccess = ReadFile(hFile, Buffer, sizeof(Buffer), &cbRead, NULL)))
37 {
38 if (cbRead == 0)
39 break;
40
41 if (!CryptHashData(hHash, Buffer, cbRead, 0))
42 {
43 bSuccess = FALSE;
44 ConPrintf(StdOut, L"CertUtil: -hashfile command failed to hash: %d\n", GetLastError());
45 break;
46 }
47 }
48
49 if (bSuccess)
50 {
51 BYTE rgbHash[20];
52 DWORD cbHash, n;
53
54 if (CryptGetHashParam(hHash, HP_HASHVAL, rgbHash, &cbHash, 0))
55 {
56 ConPrintf(StdOut, L"SHA1 hash of %s:\n", Filename);
57 for (n = 0; n < cbHash; ++n)
58 {
59 ConPrintf(StdOut, L"%02x", rgbHash[n]);
60 }
61 ConPuts(StdOut, L"\n");
62 }
63 else
64 {
65 ConPrintf(StdOut, L"CertUtil: -hashfile command failed to extract hash: %d\n", GetLastError());
66 bSuccess = FALSE;
67 }
68 }
69
71 }
72 else
73 {
74 ConPrintf(StdOut, L"CertUtil: -hashfile command no algorithm: %d\n", GetLastError());
75 }
76
78 }
79 else
80 {
81 ConPrintf(StdOut, L"CertUtil: -hashfile command no context: %d\n", GetLastError());
82 }
83
85 return bSuccess;
86}
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
BOOL WINAPI CryptCreateHash(HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey, DWORD dwFlags, HCRYPTHASH *phHash)
Definition: crypt.c:740
BOOL WINAPI CryptGetHashParam(HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
Definition: crypt.c:1610
BOOL WINAPI CryptDestroyHash(HCRYPTHASH hHash)
Definition: crypt.c:890
BOOL WINAPI CryptReleaseContext(HCRYPTPROV hProv, DWORD dwFlags)
Definition: crypt.c:648
BOOL WINAPI CryptHashData(HCRYPTHASH hHash, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
Definition: crypt.c:1771
BOOL WINAPI CryptAcquireContextW(HCRYPTPROV *phProv, LPCWSTR pszContainer, LPCWSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
Definition: crypt.c:358
GLdouble n
Definition: glext.h:7729
static HCRYPTPROV hProv
Definition: rsaenh.c:32
#define PROV_RSA_FULL
Definition: wincrypt.h:2039
#define CRYPT_VERIFYCONTEXT
Definition: wincrypt.h:2069
#define CALG_SHA1
Definition: wincrypt.h:1807
ULONG_PTR HCRYPTPROV
Definition: wincrypt.h:46
ULONG_PTR HCRYPTHASH
Definition: wincrypt.h:50
_In_ HCRYPTHASH hHash
Definition: wincrypt.h:4198
#define HP_HASHVAL
Definition: wincrypt.h:2183
unsigned char BYTE
Definition: xxhash.c:193