Add generation of SHA-256 hash feature

This commit is contained in:
Don HO 2018-12-16 20:14:30 +01:00
parent e7b04a6a1a
commit 647651b7ee
9 changed files with 249 additions and 93 deletions

View File

@ -16,13 +16,15 @@
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "md5.h" #include "md5.h"
#include <stdint.h>
#include "sha-256.h"
#include "md5Dlgs.h" #include "md5Dlgs.h"
#include "md5Dlgs_rc.h" #include "md5Dlgs_rc.h"
#include "FileDialog.h" #include "FileDialog.h"
#include "Parameters.h" #include "Parameters.h"
#include <shlwapi.h> #include <shlwapi.h>
INT_PTR CALLBACK MD5FromFilesDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM /*lParam*/) INT_PTR CALLBACK HashFromFilesDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM /*lParam*/)
{ {
switch (message) switch (message)
{ {
@ -32,8 +34,8 @@ INT_PTR CALLBACK MD5FromFilesDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
HFONT hFont = ::CreateFontA(fontDpiDynamicalHeight, 0, 0, 0, 0, FALSE, FALSE, FALSE, ANSI_CHARSET, HFONT hFont = ::CreateFontA(fontDpiDynamicalHeight, 0, 0, 0, 0, FALSE, FALSE, FALSE, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, "Courier New"); DEFAULT_PITCH | FF_DONTCARE, "Courier New");
::SendMessage(::GetDlgItem(_hSelf, IDC_MD5_PATH_EDIT), WM_SETFONT, reinterpret_cast<WPARAM>(hFont), TRUE); ::SendMessage(::GetDlgItem(_hSelf, IDC_HASH_PATH_EDIT), WM_SETFONT, reinterpret_cast<WPARAM>(hFont), TRUE);
::SendMessage(::GetDlgItem(_hSelf, IDC_MD5_RESULT_EDIT), WM_SETFONT, reinterpret_cast<WPARAM>(hFont), TRUE); ::SendMessage(::GetDlgItem(_hSelf, IDC_HASH_RESULT_EDIT), WM_SETFONT, reinterpret_cast<WPARAM>(hFont), TRUE);
} }
return TRUE; return TRUE;
@ -50,51 +52,78 @@ INT_PTR CALLBACK MD5FromFilesDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
return TRUE; return TRUE;
} }
case IDC_MD5_FILEBROWSER_BUTTON: case IDC_HASH_FILEBROWSER_BUTTON:
{ {
FileDialog fDlg(_hSelf, ::GetModuleHandle(NULL)); FileDialog fDlg(_hSelf, ::GetModuleHandle(NULL));
fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL);
if (stringVector *pfns = fDlg.doOpenMultiFilesDlg()) if (stringVector *pfns = fDlg.doOpenMultiFilesDlg())
{ {
std::wstring files2check, md5resultStr; std::wstring files2check, hashResultStr;
for (const auto& it : *pfns) for (const auto& it : *pfns)
{ {
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); if (_ht == hashType::hash_md5)
const char *path = wmc->wchar2char(it.c_str(), CP_ACP);
MD5 md5;
char *md5Result = md5.digestFile(path);
if (md5Result)
{ {
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
const char *path = wmc->wchar2char(it.c_str(), CP_ACP);
MD5 md5;
char *md5Result = md5.digestFile(path);
if (md5Result)
{
files2check += it;
files2check += TEXT("\r\n");
wchar_t* fileName = ::PathFindFileName(it.c_str());
hashResultStr += wmc->char2wchar(md5Result, CP_ACP);
hashResultStr += TEXT(" ");
hashResultStr += fileName;
hashResultStr += TEXT("\r\n");
}
}
else if (_ht == hashType::hash_sha256)
{
std::string content = getFileContent(it.c_str());
uint8_t sha2hash[32];
calc_sha_256(sha2hash, reinterpret_cast<const uint8_t*>(content.c_str()), content.length());
wchar_t sha2hashStr[65] = { '\0' };
for (size_t i = 0; i < 32; i++)
wsprintf(sha2hashStr + i * 2, TEXT("%02x"), sha2hash[i]);
files2check += it; files2check += it;
files2check += TEXT("\r\n"); files2check += TEXT("\r\n");
wchar_t* fileName = ::PathFindFileName(it.c_str()); wchar_t* fileName = ::PathFindFileName(it.c_str());
md5resultStr += wmc->char2wchar(md5Result, CP_ACP); hashResultStr += sha2hashStr;
md5resultStr += TEXT(" "); hashResultStr += TEXT(" ");
md5resultStr += fileName; hashResultStr += fileName;
md5resultStr += TEXT("\r\n"); hashResultStr += TEXT("\r\n");
}
else
{
// unknown
} }
} }
if (not files2check.empty() && not md5resultStr.empty()) if (!files2check.empty() && !hashResultStr.empty())
{ {
::SetDlgItemText(_hSelf, IDC_MD5_PATH_EDIT, files2check.c_str()); ::SetDlgItemText(_hSelf, IDC_HASH_PATH_EDIT, files2check.c_str());
::SetDlgItemText(_hSelf, IDC_MD5_RESULT_EDIT, md5resultStr.c_str()); ::SetDlgItemText(_hSelf, IDC_HASH_RESULT_EDIT, hashResultStr.c_str());
} }
} }
} }
return TRUE; return TRUE;
case IDC_MD5_TOCLIPBOARD_BUTTON: case IDC_HASH_TOCLIPBOARD_BUTTON:
{ {
int len = static_cast<int>(::SendMessage(::GetDlgItem(_hSelf, IDC_MD5_RESULT_EDIT), WM_GETTEXTLENGTH, 0, 0)); int len = static_cast<int>(::SendMessage(::GetDlgItem(_hSelf, IDC_HASH_RESULT_EDIT), WM_GETTEXTLENGTH, 0, 0));
if (len) if (len)
{ {
wchar_t *rStr = new wchar_t[len+1]; wchar_t *rStr = new wchar_t[len+1];
::GetDlgItemText(_hSelf, IDC_MD5_RESULT_EDIT, rStr, len + 1); ::GetDlgItemText(_hSelf, IDC_HASH_RESULT_EDIT, rStr, len + 1);
str2Clipboard(rStr, _hSelf); str2Clipboard(rStr, _hSelf);
delete[] rStr; delete[] rStr;
} }
@ -109,45 +138,75 @@ INT_PTR CALLBACK MD5FromFilesDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
return FALSE; return FALSE;
} }
void MD5FromFilesDlg::doDialog(bool isRTL) void HashFromFilesDlg::setHashType(hashType hashType2set)
{
_ht = hashType2set;
}
void HashFromFilesDlg::doDialog(bool isRTL)
{ {
if (!isCreated()) if (!isCreated())
create(IDD_MD5FROMFILES_DLG, isRTL); create(IDD_HASHFROMFILES_DLG, isRTL);
if (_ht == hash_sha256)
{
generic_string title = TEXT("Generate SHA-256 digest from files");
::SetWindowText(_hSelf, title.c_str());
generic_string buttonText = TEXT("Choose files to generate SHA-256...");
::SetDlgItemText(_hSelf, IDC_HASH_FILEBROWSER_BUTTON, buttonText.c_str());
}
// Adjust the position in the center // Adjust the position in the center
goToCenter(); goToCenter();
//::SetFocus(::GetDlgItem(_hSelf, IDC_COMBO_RUN_PATH));
}; };
void MD5FromTextDlg::generateMD5() void HashFromTextDlg::generateHash()
{ {
int len = static_cast<int>(::SendMessage(::GetDlgItem(_hSelf, IDC_MD5_TEXT_EDIT), WM_GETTEXTLENGTH, 0, 0)); if (_ht != hash_md5 && _ht != hash_sha256)
return;
int len = static_cast<int>(::SendMessage(::GetDlgItem(_hSelf, IDC_HASH_TEXT_EDIT), WM_GETTEXTLENGTH, 0, 0));
if (len) if (len)
{ {
// it's important to get text from UNICODE then convert it to UTF8
// So we get the result of UTF8 text (tested with Chinese).
wchar_t *text = new wchar_t[len + 1]; wchar_t *text = new wchar_t[len + 1];
::GetDlgItemText(_hSelf, IDC_MD5_TEXT_EDIT, text, len + 1); ::GetDlgItemText(_hSelf, IDC_HASH_TEXT_EDIT, text, len + 1);
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
const char *newText = wmc->wchar2char(text, SC_CP_UTF8); const char *newText = wmc->wchar2char(text, SC_CP_UTF8);
if (_ht == hash_md5)
{
MD5 md5;
char* md5Result = md5.digestString(newText);
::SetDlgItemTextA(_hSelf, IDC_HASH_RESULT_FOMTEXT_EDIT, md5Result);
}
else if (_ht == hash_sha256)
{
uint8_t sha2hash[32];
calc_sha_256(sha2hash, reinterpret_cast<const uint8_t*>(newText), strlen(newText));
MD5 md5; wchar_t sha2hashStr[65] = { '\0' };
char* md5Result = md5.digestString(newText); for (size_t i = 0; i < 32; i++)
::SetDlgItemTextA(_hSelf, IDC_MD5_RESULT_FOMTEXT_EDIT, md5Result); wsprintf(sha2hashStr + i * 2, TEXT("%02x"), sha2hash[i]);
::SetDlgItemText(_hSelf, IDC_HASH_RESULT_FOMTEXT_EDIT, sha2hashStr);
}
delete[] text; delete[] text;
} }
else else
{ {
::SetDlgItemTextA(_hSelf, IDC_MD5_RESULT_FOMTEXT_EDIT, ""); ::SetDlgItemTextA(_hSelf, IDC_HASH_RESULT_FOMTEXT_EDIT, "");
} }
} }
void MD5FromTextDlg::generateMD5PerLine() void HashFromTextDlg::generateHashPerLine()
{ {
int len = static_cast<int>(::SendMessage(::GetDlgItem(_hSelf, IDC_MD5_TEXT_EDIT), WM_GETTEXTLENGTH, 0, 0)); int len = static_cast<int>(::SendMessage(::GetDlgItem(_hSelf, IDC_HASH_TEXT_EDIT), WM_GETTEXTLENGTH, 0, 0));
if (len) if (len)
{ {
wchar_t *text = new wchar_t[len + 1]; wchar_t *text = new wchar_t[len + 1];
::GetDlgItemText(_hSelf, IDC_MD5_TEXT_EDIT, text, len + 1); ::GetDlgItemText(_hSelf, IDC_HASH_TEXT_EDIT, text, len + 1);
std::wstringstream ss(text); std::wstringstream ss(text);
std::wstring aLine; std::wstring aLine;
@ -166,21 +225,37 @@ void MD5FromTextDlg::generateMD5PerLine()
else else
{ {
const char *newText = wmc->wchar2char(aLine.c_str(), SC_CP_UTF8); const char *newText = wmc->wchar2char(aLine.c_str(), SC_CP_UTF8);
char* md5Result = md5.digestString(newText);
result += md5Result; if (_ht == hash_md5)
result += "\r\n"; {
char* md5Result = md5.digestString(newText);
result += md5Result;
result += "\r\n";
}
else if (_ht == hash_sha256)
{
uint8_t sha2hash[32];
calc_sha_256(sha2hash, reinterpret_cast<const uint8_t*>(newText), strlen(newText));
char sha2hashStr[65] = { '\0' };
for (size_t i = 0; i < 32; i++)
sprintf(sha2hashStr + i * 2, "%02x", sha2hash[i]);
result += sha2hashStr;
result += "\r\n";
}
} }
} }
delete[] text; delete[] text;
::SetDlgItemTextA(_hSelf, IDC_MD5_RESULT_FOMTEXT_EDIT, result.c_str()); ::SetDlgItemTextA(_hSelf, IDC_HASH_RESULT_FOMTEXT_EDIT, result.c_str());
} }
else else
{ {
::SetDlgItemTextA(_hSelf, IDC_MD5_RESULT_FOMTEXT_EDIT, ""); ::SetDlgItemTextA(_hSelf, IDC_HASH_RESULT_FOMTEXT_EDIT, "");
} }
} }
INT_PTR CALLBACK MD5FromTextDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM /*lParam*/) INT_PTR CALLBACK HashFromTextDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM /*lParam*/)
{ {
switch (message) switch (message)
{ {
@ -190,22 +265,22 @@ INT_PTR CALLBACK MD5FromTextDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
HFONT hFont = ::CreateFontA(fontDpiDynamicalHeight, 0, 0, 0, 0, FALSE, FALSE, FALSE, ANSI_CHARSET, HFONT hFont = ::CreateFontA(fontDpiDynamicalHeight, 0, 0, 0, 0, FALSE, FALSE, FALSE, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, "Courier New"); DEFAULT_PITCH | FF_DONTCARE, "Courier New");
::SendMessage(::GetDlgItem(_hSelf, IDC_MD5_TEXT_EDIT), WM_SETFONT, reinterpret_cast<WPARAM>(hFont), TRUE); ::SendMessage(::GetDlgItem(_hSelf, IDC_HASH_TEXT_EDIT), WM_SETFONT, reinterpret_cast<WPARAM>(hFont), TRUE);
::SendMessage(::GetDlgItem(_hSelf, IDC_MD5_RESULT_FOMTEXT_EDIT), WM_SETFONT, reinterpret_cast<WPARAM>(hFont), TRUE); ::SendMessage(::GetDlgItem(_hSelf, IDC_HASH_RESULT_FOMTEXT_EDIT), WM_SETFONT, reinterpret_cast<WPARAM>(hFont), TRUE);
} }
return TRUE; return TRUE;
case WM_COMMAND : case WM_COMMAND :
{ {
if (HIWORD(wParam) == EN_CHANGE && LOWORD(wParam) == IDC_MD5_TEXT_EDIT) if (HIWORD(wParam) == EN_CHANGE && LOWORD(wParam) == IDC_HASH_TEXT_EDIT)
{ {
if (isCheckedOrNot(IDC_MD5_EACHLINE_CHECK)) if (isCheckedOrNot(IDC_HASH_EACHLINE_CHECK))
{ {
generateMD5PerLine(); generateHashPerLine();
} }
else else
{ {
generateMD5(); generateHash();
} }
} }
@ -220,27 +295,26 @@ INT_PTR CALLBACK MD5FromTextDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
return TRUE; return TRUE;
} }
case IDC_MD5_EACHLINE_CHECK: case IDC_HASH_EACHLINE_CHECK:
{ {
if (isCheckedOrNot(IDC_MD5_EACHLINE_CHECK)) if (isCheckedOrNot(IDC_HASH_EACHLINE_CHECK))
{ {
generateMD5PerLine(); generateHashPerLine();
} }
else else
{ {
generateMD5(); generateHash();
} }
} }
return TRUE; return TRUE;
case IDC_MD5_FROMTEXT_TOCLIPBOARD_BUTTON: case IDC_HASH_FROMTEXT_TOCLIPBOARD_BUTTON:
{ {
int len = static_cast<int>(::SendMessage(::GetDlgItem(_hSelf, IDC_MD5_RESULT_FOMTEXT_EDIT), WM_GETTEXTLENGTH, 0, 0)); int len = static_cast<int>(::SendMessage(::GetDlgItem(_hSelf, IDC_HASH_RESULT_FOMTEXT_EDIT), WM_GETTEXTLENGTH, 0, 0));
if (len) if (len)
{ {
wchar_t *rStr = new wchar_t[len+1]; wchar_t *rStr = new wchar_t[len+1];
::GetDlgItemText(_hSelf, IDC_MD5_RESULT_FOMTEXT_EDIT, rStr, len + 1); ::GetDlgItemText(_hSelf, IDC_HASH_RESULT_FOMTEXT_EDIT, rStr, len + 1);
str2Clipboard(rStr, _hSelf); str2Clipboard(rStr, _hSelf);
delete[] rStr; delete[] rStr;
} }
@ -255,12 +329,22 @@ INT_PTR CALLBACK MD5FromTextDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
return FALSE; return FALSE;
} }
void MD5FromTextDlg::doDialog(bool isRTL) void HashFromTextDlg::setHashType(hashType hashType2set)
{
_ht = hashType2set;
}
void HashFromTextDlg::doDialog(bool isRTL)
{ {
if (!isCreated()) if (!isCreated())
create(IDD_MD5FROMTEXT_DLG, isRTL); create(IDD_HASHFROMTEXT_DLG, isRTL);
if (_ht == hash_sha256)
{
generic_string title = TEXT("Generate SHA-256 digest");
::SetWindowText(_hSelf, title.c_str());
}
// Adjust the position in the center // Adjust the position in the center
goToCenter(); goToCenter();
//::SetFocus(::GetDlgItem(_hSelf, IDC_COMBO_RUN_PATH));
}; };

View File

@ -19,30 +19,35 @@
#include "StaticDialog.h" #include "StaticDialog.h"
enum hashType {hash_md5, hash_sha256};
class MD5FromFilesDlg : public StaticDialog class HashFromFilesDlg : public StaticDialog
{ {
public : public :
MD5FromFilesDlg() : StaticDialog() {}; HashFromFilesDlg() : StaticDialog() {};
void doDialog(bool isRTL = false); void doDialog(bool isRTL = false);
virtual void destroy() {}; virtual void destroy() {};
void setHashType(hashType hashType2set);
protected : protected :
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
hashType _ht = hash_md5;
}; };
class MD5FromTextDlg : public StaticDialog class HashFromTextDlg : public StaticDialog
{ {
public : public :
MD5FromTextDlg() : StaticDialog() {}; HashFromTextDlg() : StaticDialog() {};
void doDialog(bool isRTL = false); void doDialog(bool isRTL = false);
virtual void destroy() {}; virtual void destroy() {};
void generateMD5(); void generateHash();
void generateMD5PerLine(); void generateHashPerLine();
void setHashType(hashType hashType2set);
protected : protected :
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
hashType _ht = hash_md5;
}; };

View File

@ -20,28 +20,30 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <windows.h> #include <windows.h>
#include "md5Dlgs_rc.h" #include "md5Dlgs_rc.h"
IDD_MD5FROMFILES_DLG DIALOGEX 0, 0, 357, 213 IDD_HASHFROMFILES_DLG DIALOGEX 0, 0, 357, 213
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_TOOLWINDOW EXSTYLE WS_EX_TOOLWINDOW
CAPTION "Generate MD5 digest from files" CAPTION "Generate MD5 digest from files"
FONT 8, "MS Shell Dlg", 400, 0, 0x1 FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN BEGIN
EDITTEXT IDC_MD5_PATH_EDIT, 9,21,263,64, ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | NOT WS_BORDER | WS_VSCROLL | WS_HSCROLL, WS_EX_CLIENTEDGE PUSHBUTTON "Choose files to generate MD5...",IDC_HASH_FILEBROWSER_BUTTON,9,4,131,14
PUSHBUTTON "Choose files to generate MD5...",IDC_MD5_FILEBROWSER_BUTTON,278,21,76,28, BS_MULTILINE EDITTEXT IDC_HASH_PATH_EDIT,9,21,340,64,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | NOT WS_BORDER | WS_VSCROLL | WS_HSCROLL,WS_EX_CLIENTEDGE
EDITTEXT IDC_MD5_RESULT_EDIT,9,105,262,64,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | NOT WS_BORDER | WS_VSCROLL | WS_HSCROLL, WS_EX_CLIENTEDGE EDITTEXT IDC_HASH_RESULT_EDIT,9,105,340,64,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | NOT WS_BORDER | WS_VSCROLL | WS_HSCROLL,WS_EX_CLIENTEDGE
PUSHBUTTON "Copy to Clipboard",IDC_MD5_TOCLIPBOARD_BUTTON,278,105,76,28,BS_MULTILINE PUSHBUTTON "Copy to Clipboard",IDC_HASH_TOCLIPBOARD_BUTTON,259,172,90,14
PUSHBUTTON "Close",IDCANCEL,148,188,60,14 PUSHBUTTON "Close",IDCANCEL,148,190,60,14
END END
IDD_MD5FROMTEXT_DLG DIALOGEX 0, 0, 357, 213 IDD_HASHFROMTEXT_DLG DIALOGEX 0, 0, 357, 213
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_TOOLWINDOW EXSTYLE WS_EX_TOOLWINDOW
CAPTION "Generate MD5 digest" CAPTION "Generate MD5 digest"
FONT 8, "MS Shell Dlg", 400, 0, 0x1 FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN BEGIN
EDITTEXT IDC_MD5_TEXT_EDIT, 9,21,263,64, ES_MULTILINE | ES_AUTOVSCROLL | NOT WS_BORDER | WS_VSCROLL | WS_HSCROLL, WS_EX_CLIENTEDGE CONTROL "Treat each line as a separate string",IDC_HASH_EACHLINE_CHECK,
CONTROL "Treat each line as a separate string", IDC_MD5_EACHLINE_CHECK, "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP, 278,21,76,28 EDITTEXT IDC_HASH_TEXT_EDIT,9,21,340,64,ES_MULTILINE | ES_AUTOVSCROLL | NOT WS_BORDER | WS_VSCROLL | WS_HSCROLL,WS_EX_CLIENTEDGE
EDITTEXT IDC_MD5_RESULT_FOMTEXT_EDIT,9,105,262,64,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | NOT WS_BORDER | WS_VSCROLL | WS_HSCROLL, WS_EX_CLIENTEDGE "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,9,3,179,16
PUSHBUTTON "Copy to Clipboard",IDC_MD5_FROMTEXT_TOCLIPBOARD_BUTTON,278,105,76,28,BS_MULTILINE EDITTEXT IDC_HASH_RESULT_FOMTEXT_EDIT,9,105,340,64,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | NOT WS_BORDER | WS_VSCROLL | WS_HSCROLL,WS_EX_CLIENTEDGE
PUSHBUTTON "Close",IDCANCEL,148,188,60,14 PUSHBUTTON "Copy to Clipboard",IDC_HASH_FROMTEXT_TOCLIPBOARD_BUTTON,259,172,90,14
PUSHBUTTON "Close",IDCANCEL,148,190,60,14
END END

View File

@ -17,14 +17,14 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#define IDD_MD5FROMFILES_DLG 1920 #define IDD_HASHFROMFILES_DLG 1920
#define IDC_MD5_PATH_EDIT (IDD_MD5FROMFILES_DLG + 1) #define IDC_HASH_PATH_EDIT (IDD_HASHFROMFILES_DLG + 1)
#define IDC_MD5_FILEBROWSER_BUTTON (IDD_MD5FROMFILES_DLG + 2) #define IDC_HASH_FILEBROWSER_BUTTON (IDD_HASHFROMFILES_DLG + 2)
#define IDC_MD5_RESULT_EDIT (IDD_MD5FROMFILES_DLG + 3) #define IDC_HASH_RESULT_EDIT (IDD_HASHFROMFILES_DLG + 3)
#define IDC_MD5_TOCLIPBOARD_BUTTON (IDD_MD5FROMFILES_DLG + 4) #define IDC_HASH_TOCLIPBOARD_BUTTON (IDD_HASHFROMFILES_DLG + 4)
#define IDD_MD5FROMTEXT_DLG 1930 #define IDD_HASHFROMTEXT_DLG 1930
#define IDC_MD5_TEXT_EDIT (IDD_MD5FROMTEXT_DLG + 1) #define IDC_HASH_TEXT_EDIT (IDD_HASHFROMTEXT_DLG + 1)
#define IDC_MD5_EACHLINE_CHECK (IDD_MD5FROMTEXT_DLG + 2) #define IDC_HASH_EACHLINE_CHECK (IDD_HASHFROMTEXT_DLG + 2)
#define IDC_MD5_RESULT_FOMTEXT_EDIT (IDD_MD5FROMTEXT_DLG + 3) #define IDC_HASH_RESULT_FOMTEXT_EDIT (IDD_HASHFROMTEXT_DLG + 3)
#define IDC_MD5_FROMTEXT_TOCLIPBOARD_BUTTON (IDD_MD5FROMTEXT_DLG + 4) #define IDC_HASH_FROMTEXT_TOCLIPBOARD_BUTTON (IDD_HASHFROMTEXT_DLG + 4)

View File

@ -623,11 +623,19 @@ LRESULT Notepad_plus::init(HWND hwnd)
_aboutDlg.init(_pPublicInterface->getHinst(), hwnd); _aboutDlg.init(_pPublicInterface->getHinst(), hwnd);
_debugInfoDlg.init(_pPublicInterface->getHinst(), hwnd, _isAdministrator, _pluginsManager.getLoadedPluginNames()); _debugInfoDlg.init(_pPublicInterface->getHinst(), hwnd, _isAdministrator, _pluginsManager.getLoadedPluginNames());
_runDlg.init(_pPublicInterface->getHinst(), hwnd); _runDlg.init(_pPublicInterface->getHinst(), hwnd);
_md5FromFilesDlg.init(_pPublicInterface->getHinst(), hwnd);
_md5FromTextDlg.init(_pPublicInterface->getHinst(), hwnd);
_runMacroDlg.init(_pPublicInterface->getHinst(), hwnd); _runMacroDlg.init(_pPublicInterface->getHinst(), hwnd);
_documentPeeker.init(_pPublicInterface->getHinst(), hwnd); _documentPeeker.init(_pPublicInterface->getHinst(), hwnd);
_md5FromFilesDlg.init(_pPublicInterface->getHinst(), hwnd);
_md5FromFilesDlg.setHashType(hash_md5);
_md5FromTextDlg.init(_pPublicInterface->getHinst(), hwnd);
_md5FromTextDlg.setHashType(hash_md5);
_sha2FromFilesDlg.init(_pPublicInterface->getHinst(), hwnd);
_sha2FromFilesDlg.setHashType(hash_sha256);
_sha2FromTextDlg.init(_pPublicInterface->getHinst(), hwnd);
_sha2FromTextDlg.setHashType(hash_sha256);
//--User Define Dialog Section--// //--User Define Dialog Section--//
int uddStatus = nppGUI._userDefineDlgStatus; int uddStatus = nppGUI._userDefineDlgStatus;
UserDefineDialog *udd = _pEditView->getUserDefineDlg(); UserDefineDialog *udd = _pEditView->getUserDefineDlg();
@ -5687,7 +5695,7 @@ bool Notepad_plus::reloadLang()
if (_md5FromFilesDlg.isCreated()) if (_md5FromFilesDlg.isCreated())
{ {
_nativeLangSpeaker.changeDlgLang(_md5FromFilesDlg.getHSelf(), "MD5FromFilesDlg"); _nativeLangSpeaker.changeDlgLang(_md5FromFilesDlg.getHSelf(), "HashFromFilesDlg");
} }
if (_md5FromTextDlg.isCreated()) if (_md5FromTextDlg.isCreated())

View File

@ -301,8 +301,10 @@ private:
AboutDlg _aboutDlg; AboutDlg _aboutDlg;
DebugInfoDlg _debugInfoDlg; DebugInfoDlg _debugInfoDlg;
RunDlg _runDlg; RunDlg _runDlg;
MD5FromFilesDlg _md5FromFilesDlg; HashFromFilesDlg _md5FromFilesDlg;
MD5FromTextDlg _md5FromTextDlg; HashFromTextDlg _md5FromTextDlg;
HashFromFilesDlg _sha2FromFilesDlg;
HashFromTextDlg _sha2FromTextDlg;
GoToLineDlg _goToLineDlg; GoToLineDlg _goToLineDlg;
ColumnEditorDlg _colEditorDlg; ColumnEditorDlg _colEditorDlg;
WordStyleDlg _configStyleDlg; WordStyleDlg _configStyleDlg;

View File

@ -932,6 +932,12 @@ BEGIN
MENUITEM "Generate from files...", IDM_TOOL_MD5_GENERATEFROMFILE MENUITEM "Generate from files...", IDM_TOOL_MD5_GENERATEFROMFILE
MENUITEM "Generate from selection into clipboard", IDM_TOOL_MD5_GENERATEINTOCLIPBOARD MENUITEM "Generate from selection into clipboard", IDM_TOOL_MD5_GENERATEINTOCLIPBOARD
END END
POPUP "SHA-256"
BEGIN
MENUITEM "Generate...", IDM_TOOL_SHA256_GENERATE
MENUITEM "Generate from files...", IDM_TOOL_SHA256_GENERATEFROMFILE
MENUITEM "Generate from selection into clipboard", IDM_TOOL_SHA256_GENERATEINTOCLIPBOARD
END
END END
POPUP "&Macro" POPUP "&Macro"

View File

@ -2572,7 +2572,7 @@ void Notepad_plus::command(int id)
bool isFirstTime = !_md5FromFilesDlg.isCreated(); bool isFirstTime = !_md5FromFilesDlg.isCreated();
_md5FromFilesDlg.doDialog(_nativeLangSpeaker.isRTL()); _md5FromFilesDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime) if (isFirstTime)
_nativeLangSpeaker.changeDlgLang(_md5FromFilesDlg.getHSelf(), "MD5FromFilesDlg"); _nativeLangSpeaker.changeDlgLang(_md5FromFilesDlg.getHSelf(), "HashFromFilesDlg");
} }
break; break;
@ -2601,6 +2601,53 @@ void Notepad_plus::command(int id)
} }
break; break;
case IDM_TOOL_SHA256_GENERATE:
{
bool isFirstTime = !_sha2FromTextDlg.isCreated();
_sha2FromTextDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
_nativeLangSpeaker.changeDlgLang(_sha2FromTextDlg.getHSelf(), "SHA256FromTextDlg");
}
break;
case IDM_TOOL_SHA256_GENERATEFROMFILE:
{
bool isFirstTime = !_sha2FromFilesDlg.isCreated();
_sha2FromFilesDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
_nativeLangSpeaker.changeDlgLang(_sha2FromFilesDlg.getHSelf(), "SHA256FromFilesDlg");
}
break;
case IDM_TOOL_SHA256_GENERATEINTOCLIPBOARD:
{
if (_pEditView->execute(SCI_GETSELECTIONS) == 1)
{
size_t selectionStart = _pEditView->execute(SCI_GETSELECTIONSTART);
size_t selectionEnd = _pEditView->execute(SCI_GETSELECTIONEND);
int32_t strLen = static_cast<int32_t>(selectionEnd - selectionStart);
if (strLen)
{
int strSize = strLen + 1;
char *selectedStr = new char[strSize];
_pEditView->execute(SCI_GETSELTEXT, 0, reinterpret_cast<LPARAM>(selectedStr));
uint8_t sha2hash[32];
calc_sha_256(sha2hash, reinterpret_cast<const uint8_t*>(selectedStr), strlen(selectedStr));
wchar_t sha2hashStr[65] = { '\0' };
for (size_t i = 0; i < 32; i++)
wsprintf(sha2hashStr + i * 2, TEXT("%02x"), sha2hash[i]);
str2Clipboard(sha2hashStr, _pPublicInterface->getHSelf());
delete[] selectedStr;
}
}
}
break;
case IDM_DEBUGINFO: case IDM_DEBUGINFO:
{ {
_debugInfoDlg.doDialog(); _debugInfoDlg.doDialog();

View File

@ -556,7 +556,9 @@
#define IDM_TOOL_MD5_GENERATE (IDM_TOOL + 1) #define IDM_TOOL_MD5_GENERATE (IDM_TOOL + 1)
#define IDM_TOOL_MD5_GENERATEFROMFILE (IDM_TOOL + 2) #define IDM_TOOL_MD5_GENERATEFROMFILE (IDM_TOOL + 2)
#define IDM_TOOL_MD5_GENERATEINTOCLIPBOARD (IDM_TOOL + 3) #define IDM_TOOL_MD5_GENERATEINTOCLIPBOARD (IDM_TOOL + 3)
#define IDM_TOOL_SHA256_GENERATE (IDM_TOOL + 4)
#define IDM_TOOL_SHA256_GENERATEFROMFILE (IDM_TOOL + 5)
#define IDM_TOOL_SHA256_GENERATEINTOCLIPBOARD (IDM_TOOL + 6)
#define IDM_EXECUTE (IDM + 9000) #define IDM_EXECUTE (IDM + 9000)