Add generation of SHA-256 hash feature
This commit is contained in:
parent
e7b04a6a1a
commit
647651b7ee
@ -16,13 +16,15 @@
|
||||
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
#include "md5.h"
|
||||
#include <stdint.h>
|
||||
#include "sha-256.h"
|
||||
#include "md5Dlgs.h"
|
||||
#include "md5Dlgs_rc.h"
|
||||
#include "FileDialog.h"
|
||||
#include "Parameters.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)
|
||||
{
|
||||
@ -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,
|
||||
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
|
||||
DEFAULT_PITCH | FF_DONTCARE, "Courier New");
|
||||
::SendMessage(::GetDlgItem(_hSelf, IDC_MD5_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_PATH_EDIT), WM_SETFONT, reinterpret_cast<WPARAM>(hFont), TRUE);
|
||||
::SendMessage(::GetDlgItem(_hSelf, IDC_HASH_RESULT_EDIT), WM_SETFONT, reinterpret_cast<WPARAM>(hFont), TRUE);
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
@ -50,15 +52,17 @@ INT_PTR CALLBACK MD5FromFilesDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
case IDC_MD5_FILEBROWSER_BUTTON:
|
||||
case IDC_HASH_FILEBROWSER_BUTTON:
|
||||
{
|
||||
FileDialog fDlg(_hSelf, ::GetModuleHandle(NULL));
|
||||
fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL);
|
||||
|
||||
if (stringVector *pfns = fDlg.doOpenMultiFilesDlg())
|
||||
{
|
||||
std::wstring files2check, md5resultStr;
|
||||
std::wstring files2check, hashResultStr;
|
||||
for (const auto& it : *pfns)
|
||||
{
|
||||
if (_ht == hashType::hash_md5)
|
||||
{
|
||||
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
|
||||
const char *path = wmc->wchar2char(it.c_str(), CP_ACP);
|
||||
@ -72,29 +76,54 @@ INT_PTR CALLBACK MD5FromFilesDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
|
||||
files2check += TEXT("\r\n");
|
||||
|
||||
wchar_t* fileName = ::PathFindFileName(it.c_str());
|
||||
md5resultStr += wmc->char2wchar(md5Result, CP_ACP);
|
||||
md5resultStr += TEXT(" ");
|
||||
md5resultStr += fileName;
|
||||
md5resultStr += TEXT("\r\n");
|
||||
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 += TEXT("\r\n");
|
||||
|
||||
wchar_t* fileName = ::PathFindFileName(it.c_str());
|
||||
hashResultStr += sha2hashStr;
|
||||
hashResultStr += TEXT(" ");
|
||||
hashResultStr += fileName;
|
||||
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_MD5_RESULT_EDIT, md5resultStr.c_str());
|
||||
::SetDlgItemText(_hSelf, IDC_HASH_PATH_EDIT, files2check.c_str());
|
||||
::SetDlgItemText(_hSelf, IDC_HASH_RESULT_EDIT, hashResultStr.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
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);
|
||||
delete[] rStr;
|
||||
}
|
||||
@ -109,45 +138,75 @@ INT_PTR CALLBACK MD5FromFilesDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void MD5FromFilesDlg::doDialog(bool isRTL)
|
||||
void HashFromFilesDlg::setHashType(hashType hashType2set)
|
||||
{
|
||||
_ht = hashType2set;
|
||||
}
|
||||
|
||||
void HashFromFilesDlg::doDialog(bool isRTL)
|
||||
{
|
||||
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
|
||||
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)
|
||||
{
|
||||
// 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];
|
||||
::GetDlgItemText(_hSelf, IDC_MD5_TEXT_EDIT, text, len + 1);
|
||||
::GetDlgItemText(_hSelf, IDC_HASH_TEXT_EDIT, text, len + 1);
|
||||
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
|
||||
const char *newText = wmc->wchar2char(text, SC_CP_UTF8);
|
||||
|
||||
if (_ht == hash_md5)
|
||||
{
|
||||
MD5 md5;
|
||||
char* md5Result = md5.digestString(newText);
|
||||
::SetDlgItemTextA(_hSelf, IDC_MD5_RESULT_FOMTEXT_EDIT, md5Result);
|
||||
::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));
|
||||
|
||||
wchar_t sha2hashStr[65] = { '\0' };
|
||||
for (size_t i = 0; i < 32; i++)
|
||||
wsprintf(sha2hashStr + i * 2, TEXT("%02x"), sha2hash[i]);
|
||||
|
||||
::SetDlgItemText(_hSelf, IDC_HASH_RESULT_FOMTEXT_EDIT, sha2hashStr);
|
||||
}
|
||||
delete[] text;
|
||||
}
|
||||
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)
|
||||
{
|
||||
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::wstring aLine;
|
||||
@ -166,21 +225,37 @@ void MD5FromTextDlg::generateMD5PerLine()
|
||||
else
|
||||
{
|
||||
const char *newText = wmc->wchar2char(aLine.c_str(), SC_CP_UTF8);
|
||||
|
||||
if (_ht == hash_md5)
|
||||
{
|
||||
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;
|
||||
::SetDlgItemTextA(_hSelf, IDC_MD5_RESULT_FOMTEXT_EDIT, result.c_str());
|
||||
::SetDlgItemTextA(_hSelf, IDC_HASH_RESULT_FOMTEXT_EDIT, result.c_str());
|
||||
}
|
||||
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)
|
||||
{
|
||||
@ -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,
|
||||
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
|
||||
DEFAULT_PITCH | FF_DONTCARE, "Courier New");
|
||||
::SendMessage(::GetDlgItem(_hSelf, IDC_MD5_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_TEXT_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;
|
||||
|
||||
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
|
||||
{
|
||||
generateMD5();
|
||||
generateHash();
|
||||
}
|
||||
}
|
||||
|
||||
@ -220,27 +295,26 @@ INT_PTR CALLBACK MD5FromTextDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
|
||||
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
|
||||
{
|
||||
generateMD5();
|
||||
generateHash();
|
||||
}
|
||||
|
||||
}
|
||||
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)
|
||||
{
|
||||
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);
|
||||
delete[] rStr;
|
||||
}
|
||||
@ -255,12 +329,22 @@ INT_PTR CALLBACK MD5FromTextDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void MD5FromTextDlg::doDialog(bool isRTL)
|
||||
void HashFromTextDlg::setHashType(hashType hashType2set)
|
||||
{
|
||||
_ht = hashType2set;
|
||||
}
|
||||
|
||||
void HashFromTextDlg::doDialog(bool isRTL)
|
||||
{
|
||||
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
|
||||
goToCenter();
|
||||
//::SetFocus(::GetDlgItem(_hSelf, IDC_COMBO_RUN_PATH));
|
||||
};
|
||||
|
@ -19,30 +19,35 @@
|
||||
|
||||
#include "StaticDialog.h"
|
||||
|
||||
enum hashType {hash_md5, hash_sha256};
|
||||
|
||||
class MD5FromFilesDlg : public StaticDialog
|
||||
class HashFromFilesDlg : public StaticDialog
|
||||
{
|
||||
public :
|
||||
MD5FromFilesDlg() : StaticDialog() {};
|
||||
HashFromFilesDlg() : StaticDialog() {};
|
||||
|
||||
void doDialog(bool isRTL = false);
|
||||
virtual void destroy() {};
|
||||
void setHashType(hashType hashType2set);
|
||||
|
||||
protected :
|
||||
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 :
|
||||
MD5FromTextDlg() : StaticDialog() {};
|
||||
HashFromTextDlg() : StaticDialog() {};
|
||||
|
||||
void doDialog(bool isRTL = false);
|
||||
virtual void destroy() {};
|
||||
void generateMD5();
|
||||
void generateMD5PerLine();
|
||||
void generateHash();
|
||||
void generateHashPerLine();
|
||||
void setHashType(hashType hashType2set);
|
||||
|
||||
protected :
|
||||
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
|
||||
hashType _ht = hash_md5;
|
||||
};
|
||||
|
||||
|
@ -20,28 +20,30 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#include <windows.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
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
CAPTION "Generate MD5 digest from files"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
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_MD5_FILEBROWSER_BUTTON,278,21,76,28, BS_MULTILINE
|
||||
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
|
||||
PUSHBUTTON "Copy to Clipboard",IDC_MD5_TOCLIPBOARD_BUTTON,278,105,76,28,BS_MULTILINE
|
||||
PUSHBUTTON "Close",IDCANCEL,148,188,60,14
|
||||
PUSHBUTTON "Choose files to generate MD5...",IDC_HASH_FILEBROWSER_BUTTON,9,4,131,14
|
||||
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_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_HASH_TOCLIPBOARD_BUTTON,259,172,90,14
|
||||
PUSHBUTTON "Close",IDCANCEL,148,190,60,14
|
||||
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
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
CAPTION "Generate MD5 digest"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
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_MD5_EACHLINE_CHECK, "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP, 278,21,76,28
|
||||
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
|
||||
PUSHBUTTON "Copy to Clipboard",IDC_MD5_FROMTEXT_TOCLIPBOARD_BUTTON,278,105,76,28,BS_MULTILINE
|
||||
PUSHBUTTON "Close",IDCANCEL,148,188,60,14
|
||||
CONTROL "Treat each line as a separate string",IDC_HASH_EACHLINE_CHECK,
|
||||
EDITTEXT IDC_HASH_TEXT_EDIT,9,21,340,64,ES_MULTILINE | ES_AUTOVSCROLL | NOT WS_BORDER | WS_VSCROLL | WS_HSCROLL,WS_EX_CLIENTEDGE
|
||||
"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,9,3,179,16
|
||||
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 "Copy to Clipboard",IDC_HASH_FROMTEXT_TOCLIPBOARD_BUTTON,259,172,90,14
|
||||
PUSHBUTTON "Close",IDCANCEL,148,190,60,14
|
||||
END
|
||||
|
||||
|
@ -17,14 +17,14 @@ along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#define IDD_MD5FROMFILES_DLG 1920
|
||||
#define IDC_MD5_PATH_EDIT (IDD_MD5FROMFILES_DLG + 1)
|
||||
#define IDC_MD5_FILEBROWSER_BUTTON (IDD_MD5FROMFILES_DLG + 2)
|
||||
#define IDC_MD5_RESULT_EDIT (IDD_MD5FROMFILES_DLG + 3)
|
||||
#define IDC_MD5_TOCLIPBOARD_BUTTON (IDD_MD5FROMFILES_DLG + 4)
|
||||
#define IDD_HASHFROMFILES_DLG 1920
|
||||
#define IDC_HASH_PATH_EDIT (IDD_HASHFROMFILES_DLG + 1)
|
||||
#define IDC_HASH_FILEBROWSER_BUTTON (IDD_HASHFROMFILES_DLG + 2)
|
||||
#define IDC_HASH_RESULT_EDIT (IDD_HASHFROMFILES_DLG + 3)
|
||||
#define IDC_HASH_TOCLIPBOARD_BUTTON (IDD_HASHFROMFILES_DLG + 4)
|
||||
|
||||
#define IDD_MD5FROMTEXT_DLG 1930
|
||||
#define IDC_MD5_TEXT_EDIT (IDD_MD5FROMTEXT_DLG + 1)
|
||||
#define IDC_MD5_EACHLINE_CHECK (IDD_MD5FROMTEXT_DLG + 2)
|
||||
#define IDC_MD5_RESULT_FOMTEXT_EDIT (IDD_MD5FROMTEXT_DLG + 3)
|
||||
#define IDC_MD5_FROMTEXT_TOCLIPBOARD_BUTTON (IDD_MD5FROMTEXT_DLG + 4)
|
||||
#define IDD_HASHFROMTEXT_DLG 1930
|
||||
#define IDC_HASH_TEXT_EDIT (IDD_HASHFROMTEXT_DLG + 1)
|
||||
#define IDC_HASH_EACHLINE_CHECK (IDD_HASHFROMTEXT_DLG + 2)
|
||||
#define IDC_HASH_RESULT_FOMTEXT_EDIT (IDD_HASHFROMTEXT_DLG + 3)
|
||||
#define IDC_HASH_FROMTEXT_TOCLIPBOARD_BUTTON (IDD_HASHFROMTEXT_DLG + 4)
|
||||
|
@ -623,11 +623,19 @@ LRESULT Notepad_plus::init(HWND hwnd)
|
||||
_aboutDlg.init(_pPublicInterface->getHinst(), hwnd);
|
||||
_debugInfoDlg.init(_pPublicInterface->getHinst(), hwnd, _isAdministrator, _pluginsManager.getLoadedPluginNames());
|
||||
_runDlg.init(_pPublicInterface->getHinst(), hwnd);
|
||||
_md5FromFilesDlg.init(_pPublicInterface->getHinst(), hwnd);
|
||||
_md5FromTextDlg.init(_pPublicInterface->getHinst(), hwnd);
|
||||
_runMacroDlg.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--//
|
||||
int uddStatus = nppGUI._userDefineDlgStatus;
|
||||
UserDefineDialog *udd = _pEditView->getUserDefineDlg();
|
||||
@ -5687,7 +5695,7 @@ bool Notepad_plus::reloadLang()
|
||||
|
||||
if (_md5FromFilesDlg.isCreated())
|
||||
{
|
||||
_nativeLangSpeaker.changeDlgLang(_md5FromFilesDlg.getHSelf(), "MD5FromFilesDlg");
|
||||
_nativeLangSpeaker.changeDlgLang(_md5FromFilesDlg.getHSelf(), "HashFromFilesDlg");
|
||||
}
|
||||
|
||||
if (_md5FromTextDlg.isCreated())
|
||||
|
@ -301,8 +301,10 @@ private:
|
||||
AboutDlg _aboutDlg;
|
||||
DebugInfoDlg _debugInfoDlg;
|
||||
RunDlg _runDlg;
|
||||
MD5FromFilesDlg _md5FromFilesDlg;
|
||||
MD5FromTextDlg _md5FromTextDlg;
|
||||
HashFromFilesDlg _md5FromFilesDlg;
|
||||
HashFromTextDlg _md5FromTextDlg;
|
||||
HashFromFilesDlg _sha2FromFilesDlg;
|
||||
HashFromTextDlg _sha2FromTextDlg;
|
||||
GoToLineDlg _goToLineDlg;
|
||||
ColumnEditorDlg _colEditorDlg;
|
||||
WordStyleDlg _configStyleDlg;
|
||||
|
@ -932,6 +932,12 @@ BEGIN
|
||||
MENUITEM "Generate from files...", IDM_TOOL_MD5_GENERATEFROMFILE
|
||||
MENUITEM "Generate from selection into clipboard", IDM_TOOL_MD5_GENERATEINTOCLIPBOARD
|
||||
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
|
||||
|
||||
POPUP "&Macro"
|
||||
|
@ -2572,7 +2572,7 @@ void Notepad_plus::command(int id)
|
||||
bool isFirstTime = !_md5FromFilesDlg.isCreated();
|
||||
_md5FromFilesDlg.doDialog(_nativeLangSpeaker.isRTL());
|
||||
if (isFirstTime)
|
||||
_nativeLangSpeaker.changeDlgLang(_md5FromFilesDlg.getHSelf(), "MD5FromFilesDlg");
|
||||
_nativeLangSpeaker.changeDlgLang(_md5FromFilesDlg.getHSelf(), "HashFromFilesDlg");
|
||||
}
|
||||
break;
|
||||
|
||||
@ -2601,6 +2601,53 @@ void Notepad_plus::command(int id)
|
||||
}
|
||||
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:
|
||||
{
|
||||
_debugInfoDlg.doDialog();
|
||||
|
@ -556,7 +556,9 @@
|
||||
#define IDM_TOOL_MD5_GENERATE (IDM_TOOL + 1)
|
||||
#define IDM_TOOL_MD5_GENERATEFROMFILE (IDM_TOOL + 2)
|
||||
#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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user