mirror of
https://github.com/pbatard/rufus.git
synced 2024-09-19 19:18:51 -04:00
[misc] move hash definitions to rufus.h
* Also always add an extra NUL to read_file(), some additional macros in missing.h and fix some warnings in process.c.
This commit is contained in:
parent
d3f78c4e01
commit
a59389e1e1
6 changed files with 67 additions and 54 deletions
27
src/hash.c
27
src/hash.c
|
@ -97,20 +97,6 @@
|
||||||
#define BUFFER_SIZE (64*KB)
|
#define BUFFER_SIZE (64*KB)
|
||||||
#define WAIT_TIME 5000
|
#define WAIT_TIME 5000
|
||||||
|
|
||||||
/* Blocksize for each algorithm - Must be a power of 2 */
|
|
||||||
#define MD5_BLOCKSIZE 64
|
|
||||||
#define SHA1_BLOCKSIZE 64
|
|
||||||
#define SHA256_BLOCKSIZE 64
|
|
||||||
#define SHA512_BLOCKSIZE 128
|
|
||||||
#define MAX_BLOCKSIZE SHA512_BLOCKSIZE
|
|
||||||
|
|
||||||
/* Hashsize for each algorithm */
|
|
||||||
#define MD5_HASHSIZE 16
|
|
||||||
#define SHA1_HASHSIZE 20
|
|
||||||
#define SHA256_HASHSIZE 32
|
|
||||||
#define SHA512_HASHSIZE 64
|
|
||||||
#define MAX_HASHSIZE SHA512_HASHSIZE
|
|
||||||
|
|
||||||
/* Number of buffers we work with */
|
/* Number of buffers we work with */
|
||||||
#define NUM_BUFFERS 3 // 2 + 1 as a mere double buffered async I/O
|
#define NUM_BUFFERS 3 // 2 + 1 as a mere double buffered async I/O
|
||||||
// would modify the buffer being processed.
|
// would modify the buffer being processed.
|
||||||
|
@ -178,16 +164,6 @@ static const uint64_t K512[80] = {
|
||||||
0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL
|
0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
* For convenience, we use a common context for all the hash algorithms,
|
|
||||||
* which means some elements may be unused...
|
|
||||||
*/
|
|
||||||
typedef struct ALIGNED(64) {
|
|
||||||
uint8_t buf[MAX_BLOCKSIZE];
|
|
||||||
uint64_t state[8];
|
|
||||||
uint64_t bytecount;
|
|
||||||
} HASH_CONTEXT;
|
|
||||||
|
|
||||||
static void md5_init(HASH_CONTEXT *ctx)
|
static void md5_init(HASH_CONTEXT *ctx)
|
||||||
{
|
{
|
||||||
memset(ctx, 0, sizeof(*ctx));
|
memset(ctx, 0, sizeof(*ctx));
|
||||||
|
@ -1467,9 +1443,6 @@ static void null_write(HASH_CONTEXT *ctx, const uint8_t *buf, size_t len) { }
|
||||||
static void null_final(HASH_CONTEXT *ctx) { }
|
static void null_final(HASH_CONTEXT *ctx) { }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef void hash_init_t(HASH_CONTEXT *ctx);
|
|
||||||
typedef void hash_write_t(HASH_CONTEXT *ctx, const uint8_t *buf, size_t len);
|
|
||||||
typedef void hash_final_t(HASH_CONTEXT *ctx);
|
|
||||||
hash_init_t *hash_init[HASH_MAX] = { md5_init, sha1_init , sha256_init, sha512_init };
|
hash_init_t *hash_init[HASH_MAX] = { md5_init, sha1_init , sha256_init, sha512_init };
|
||||||
hash_write_t *hash_write[HASH_MAX] = { md5_write, sha1_write , sha256_write, sha512_write };
|
hash_write_t *hash_write[HASH_MAX] = { md5_write, sha1_write , sha256_write, sha512_write };
|
||||||
hash_final_t *hash_final[HASH_MAX] = { md5_final, sha1_final , sha256_final, sha512_final };
|
hash_final_t *hash_final[HASH_MAX] = { md5_final, sha1_final , sha256_final, sha512_final };
|
||||||
|
|
|
@ -31,14 +31,14 @@
|
||||||
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAX
|
||||||
|
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
#define LO_ALIGN_X_TO_Y(x, y) (((x) / (y)) * (y))
|
#define LO_ALIGN_X_TO_Y(x, y) (((x) / (y)) * (y))
|
||||||
#define HI_ALIGN_X_TO_Y(x, y) ((((x) + (y) - 1) / (y)) * (y))
|
#define HI_ALIGN_X_TO_Y(x, y) ((((x) + (y) - 1) / (y)) * (y))
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#define IS_HEXASCII(c) (((c) >= '0' && (c) <= '9') || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f'))
|
||||||
#define ALIGNED(m) __attribute__ ((__aligned__(m)))
|
|
||||||
#elif defined(_MSC_VER)
|
|
||||||
#define ALIGNED(m) __declspec(align(m))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prefetch 64 bytes at address m, for read-only operation
|
* Prefetch 64 bytes at address m, for read-only operation
|
||||||
|
|
|
@ -499,8 +499,8 @@ static DWORD WINAPI SearchProcessThread(LPVOID param)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (wHandleName != NULL) {
|
if (wHandleName != NULL) {
|
||||||
for (i = 0; i < nHandles; i++)
|
for (j = 0; j < nHandles; j++)
|
||||||
free(wHandleName[i]);
|
free(wHandleName[j]);
|
||||||
free(wHandleName);
|
free(wHandleName);
|
||||||
}
|
}
|
||||||
safe_free(wHandleNameLen);
|
safe_free(wHandleNameLen);
|
||||||
|
@ -515,10 +515,10 @@ static DWORD WINAPI SearchProcessThread(LPVOID param)
|
||||||
ReleaseMutex(hLock);
|
ReleaseMutex(hLock);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
for (i = 0; i < nHandles; i++) {
|
for (j = 0; j < nHandles; j++) {
|
||||||
wHandleName[i] = wcsdup(blocking_process.wHandleName[i]);
|
wHandleName[j] = wcsdup(blocking_process.wHandleName[j]);
|
||||||
wHandleNameLen[i] = (USHORT)wcslen(blocking_process.wHandleName[i]);
|
wHandleNameLen[j] = (USHORT)wcslen(blocking_process.wHandleName[j]);
|
||||||
if (wHandleName[i] == NULL) {
|
if (wHandleName[j] == NULL) {
|
||||||
ReleaseMutex(hLock);
|
ReleaseMutex(hLock);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -741,8 +741,8 @@ out:
|
||||||
uprintf("Warning: Could not start process handle enumerator!");
|
uprintf("Warning: Could not start process handle enumerator!");
|
||||||
|
|
||||||
if (wHandleName != NULL) {
|
if (wHandleName != NULL) {
|
||||||
for (i = 0; i < nHandles; i++)
|
for (j = 0; j < nHandles; j++)
|
||||||
free(wHandleName[i]);
|
free(wHandleName[j]);
|
||||||
free(wHandleName);
|
free(wHandleName);
|
||||||
}
|
}
|
||||||
safe_free(wHandleNameLen);
|
safe_free(wHandleNameLen);
|
||||||
|
|
53
src/rufus.h
53
src/rufus.h
|
@ -311,14 +311,6 @@ enum image_option_type {
|
||||||
IMOP_MAX
|
IMOP_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
enum hash_type {
|
|
||||||
HASH_MD5 = 0,
|
|
||||||
HASH_SHA1,
|
|
||||||
HASH_SHA256,
|
|
||||||
HASH_SHA512,
|
|
||||||
HASH_MAX
|
|
||||||
};
|
|
||||||
|
|
||||||
enum file_io_type {
|
enum file_io_type {
|
||||||
FILE_IO_READ = 0,
|
FILE_IO_READ = 0,
|
||||||
FILE_IO_WRITE,
|
FILE_IO_WRITE,
|
||||||
|
@ -484,6 +476,51 @@ typedef struct {
|
||||||
uint32_t* address; // 32-bit will do, as we're not dealing with >4GB DLLs...
|
uint32_t* address; // 32-bit will do, as we're not dealing with >4GB DLLs...
|
||||||
} dll_resolver_t;
|
} dll_resolver_t;
|
||||||
|
|
||||||
|
/* Alignment macro */
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#define ALIGNED(m) __attribute__ ((__aligned__(m)))
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
#define ALIGNED(m) __declspec(align(m))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Hash definitions */
|
||||||
|
enum hash_type {
|
||||||
|
HASH_MD5 = 0,
|
||||||
|
HASH_SHA1,
|
||||||
|
HASH_SHA256,
|
||||||
|
HASH_SHA512,
|
||||||
|
HASH_MAX
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Blocksize for each hash algorithm - Must be a power of 2 */
|
||||||
|
#define MD5_BLOCKSIZE 64
|
||||||
|
#define SHA1_BLOCKSIZE 64
|
||||||
|
#define SHA256_BLOCKSIZE 64
|
||||||
|
#define SHA512_BLOCKSIZE 128
|
||||||
|
#define MAX_BLOCKSIZE SHA512_BLOCKSIZE
|
||||||
|
|
||||||
|
/* Hashsize for each hash algorithm */
|
||||||
|
#define MD5_HASHSIZE 16
|
||||||
|
#define SHA1_HASHSIZE 20
|
||||||
|
#define SHA256_HASHSIZE 32
|
||||||
|
#define SHA512_HASHSIZE 64
|
||||||
|
#define MAX_HASHSIZE SHA512_HASHSIZE
|
||||||
|
|
||||||
|
/* Context for the hash algorithms */
|
||||||
|
typedef struct ALIGNED(64) {
|
||||||
|
uint8_t buf[MAX_BLOCKSIZE];
|
||||||
|
uint64_t state[8];
|
||||||
|
uint64_t bytecount;
|
||||||
|
} HASH_CONTEXT;
|
||||||
|
|
||||||
|
/* Hash functions */
|
||||||
|
typedef void hash_init_t(HASH_CONTEXT* ctx);
|
||||||
|
typedef void hash_write_t(HASH_CONTEXT* ctx, const uint8_t* buf, size_t len);
|
||||||
|
typedef void hash_final_t(HASH_CONTEXT* ctx);
|
||||||
|
extern hash_init_t* hash_init[HASH_MAX];
|
||||||
|
extern hash_write_t* hash_write[HASH_MAX];
|
||||||
|
extern hash_final_t* hash_final[HASH_MAX];
|
||||||
|
|
||||||
#ifndef __VA_GROUP__
|
#ifndef __VA_GROUP__
|
||||||
#define __VA_GROUP__(...) __VA_ARGS__
|
#define __VA_GROUP__(...) __VA_ARGS__
|
||||||
#endif
|
#endif
|
||||||
|
|
10
src/rufus.rc
10
src/rufus.rc
|
@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
|
||||||
IDD_DIALOG DIALOGEX 12, 12, 232, 326
|
IDD_DIALOG DIALOGEX 12, 12, 232, 326
|
||||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||||
EXSTYLE WS_EX_ACCEPTFILES
|
EXSTYLE WS_EX_ACCEPTFILES
|
||||||
CAPTION "Rufus 4.5.2117"
|
CAPTION "Rufus 4.5.2118"
|
||||||
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
|
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
|
||||||
BEGIN
|
BEGIN
|
||||||
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
|
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
|
||||||
|
@ -392,8 +392,8 @@ END
|
||||||
//
|
//
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 4,5,2117,0
|
FILEVERSION 4,5,2118,0
|
||||||
PRODUCTVERSION 4,5,2117,0
|
PRODUCTVERSION 4,5,2118,0
|
||||||
FILEFLAGSMASK 0x3fL
|
FILEFLAGSMASK 0x3fL
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
|
@ -411,13 +411,13 @@ BEGIN
|
||||||
VALUE "Comments", "https://rufus.ie"
|
VALUE "Comments", "https://rufus.ie"
|
||||||
VALUE "CompanyName", "Akeo Consulting"
|
VALUE "CompanyName", "Akeo Consulting"
|
||||||
VALUE "FileDescription", "Rufus"
|
VALUE "FileDescription", "Rufus"
|
||||||
VALUE "FileVersion", "4.5.2117"
|
VALUE "FileVersion", "4.5.2118"
|
||||||
VALUE "InternalName", "Rufus"
|
VALUE "InternalName", "Rufus"
|
||||||
VALUE "LegalCopyright", "© 2011-2024 Pete Batard (GPL v3)"
|
VALUE "LegalCopyright", "© 2011-2024 Pete Batard (GPL v3)"
|
||||||
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
|
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
|
||||||
VALUE "OriginalFilename", "rufus-4.5.exe"
|
VALUE "OriginalFilename", "rufus-4.5.exe"
|
||||||
VALUE "ProductName", "Rufus"
|
VALUE "ProductName", "Rufus"
|
||||||
VALUE "ProductVersion", "4.5.2117"
|
VALUE "ProductVersion", "4.5.2118"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
|
|
@ -125,7 +125,8 @@ uint32_t read_file(const char* path, uint8_t** buf)
|
||||||
uint32_t size = (uint32_t)ftell(fd);
|
uint32_t size = (uint32_t)ftell(fd);
|
||||||
fseek(fd, 0L, SEEK_SET);
|
fseek(fd, 0L, SEEK_SET);
|
||||||
|
|
||||||
*buf = malloc(size);
|
// +1 so we can add an extra NUL
|
||||||
|
*buf = malloc(size + 1);
|
||||||
if (*buf == NULL) {
|
if (*buf == NULL) {
|
||||||
uprintf("Error: Can't allocate %d bytes buffer for file '%s'", size, path);
|
uprintf("Error: Can't allocate %d bytes buffer for file '%s'", size, path);
|
||||||
size = 0;
|
size = 0;
|
||||||
|
@ -135,6 +136,8 @@ uint32_t read_file(const char* path, uint8_t** buf)
|
||||||
uprintf("Error: Can't read '%s'", path);
|
uprintf("Error: Can't read '%s'", path);
|
||||||
size = 0;
|
size = 0;
|
||||||
}
|
}
|
||||||
|
// Always NUL terminate the file
|
||||||
|
(*buf)[size] = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
|
|
Loading…
Reference in a new issue