Skip to content

Commit

Permalink
Bug fix for large blocks (closes #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
merces committed Dec 9, 2024
1 parent ba1b11a commit f075bf5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion Hashes/HiewModule.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
// HEM SDK required defs

#define HEM_MODULE_VERSION_MAJOR 1
#define HEM_MODULE_VERSION_MINOR 2
#define HEM_MODULE_VERSION_MINOR 3
#define HEM_MODULE_NAME "Hashes"
#define HEM_MODULE_FULL_NAME "Hashes: CRC-32, MD5, SHA-1, SHA-256"
#define HEM_MODULE_DESCRIPTION "Calculate common hashes of files and blocks"
#define HEM_MODULE_AUTHOR "Fernando Merces - github.com/merces"

enum opMode { HASHES_FILE, HASHES_BLOCK };

int HEM_API Hem_EntryPoint(HEMCALL_TAG* hemCall);
int HEM_API Hem_Unload(VOID);

Expand Down Expand Up @@ -143,14 +145,18 @@ int HEM_API Hem_EntryPoint(HEMCALL_TAG* HemCall) {
if (HiewGate_GetData(&HiewData) != HEM_OK)
return HEM_ERROR;

enum opMode mode;

// Check if there is an active block, if not use the whole file.
if (HiewData.sizeMark) {
mode = HASHES_BLOCK;
BaseAddr = HiewData.offsetMark1;
BufferEnd = HiewData.sizeMark;
// Use the smallest buffer if marked block size is smaller than BUFFER_SIZE
// Notice a marked block cannot exceed UINT_MAX
BufferSize = BufferEnd < BUFFER_SIZE ? (HEM_UINT)BufferEnd : BUFFER_SIZE;
} else {
mode = HASHES_FILE;
BaseAddr = 0;
BufferEnd = HiewData.filelength;
// Use a buffer to read the file contents using BUFFER_SIZE byte chunks
Expand Down Expand Up @@ -253,6 +259,14 @@ int HEM_API Hem_EntryPoint(HEMCALL_TAG* HemCall) {
HEM_QWORD totalRead = 0;

while (totalRead < BufferEnd) {

if (mode == HASHES_BLOCK) {
BufferSize = BufferEnd - totalRead;
if (BufferSize > BUFFER_SIZE) {
BufferSize = BUFFER_SIZE;
}
}

int read = HiewGate_FileRead(BaseAddr + totalRead, BufferSize, Buffer);

if (read == 0) {
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

## Installation

Download the `.hem` file and put it in your HIEW `hem` folder.
Download the `.hem` file and put it in your Hiew `hem` folder.

## Usage

After opening a file in Hiew, press `F11` to load a HIEW module and choose it from the menu.
After opening a file in Hiew, press `F11` to load a Hiew module and choose it from the menu.
It will calculate common hashes of the whole file. If you mark a block instead, Hashes will generate
the hashes of the block content. Press `F5` to copy a hash value to clipboard.

Expand Down

0 comments on commit f075bf5

Please sign in to comment.