2021-01-23 09:26:37 +01:00
|
|
|
|
/* Copyright (C) 2019-2021 Logaev Maxim (turbocat2001), GPLv2 */
|
2020-12-16 21:10:09 +01:00
|
|
|
|
|
2021-05-01 00:28:05 +02:00
|
|
|
|
#include <sys/ksys.h>
|
2020-09-21 19:37:22 +02:00
|
|
|
|
#include <stdio.h>
|
2020-12-16 21:10:09 +01:00
|
|
|
|
#include <stdbool.h>
|
2020-09-21 19:37:22 +02:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2020-12-11 21:34:18 +01:00
|
|
|
|
#include <cryptal/md5.h>
|
|
|
|
|
#include <cryptal/sha1.h>
|
|
|
|
|
#include <cryptal/sha256.h>
|
2020-12-16 21:10:09 +01:00
|
|
|
|
#include <clayer/dialog.h>
|
2020-12-21 19:42:34 +01:00
|
|
|
|
#include <clayer/boxlib.h>
|
2020-09-21 19:37:22 +02:00
|
|
|
|
|
|
|
|
|
#define TRUE 1;
|
|
|
|
|
#define FALSE 0;
|
|
|
|
|
#define MAX_HASH_LEN 65 // <20><><EFBFBD>ᨬ<EFBFBD><E1A8AC>쭠<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><>ப<EFBFBD>
|
|
|
|
|
#define WINDOW_W 665
|
2021-02-02 09:08:17 +01:00
|
|
|
|
#define VERSION "%s - thashview 2.6.1"
|
2020-12-21 19:42:34 +01:00
|
|
|
|
#define EDIT_TEXT_SIZE 0x10000000
|
2021-05-01 00:28:05 +02:00
|
|
|
|
#define DATA(type, addr, offset) *((type*)((uint8_t*)addr+offset))
|
2020-09-21 19:37:22 +02:00
|
|
|
|
|
2021-05-01 00:28:05 +02:00
|
|
|
|
ksys_colors_table_t sys_color_table;
|
2020-09-21 19:37:22 +02:00
|
|
|
|
|
2021-02-02 09:08:17 +01:00
|
|
|
|
char hash_str_md5[MAX_HASH_LEN]= "Click the 'MD5:' button to show the md5-checksum!"; //<2F>뢮<EFBFBD> MD5
|
|
|
|
|
char hash_str_sha1[MAX_HASH_LEN]= "Click the 'SHA1:' button to show the sha1-checksum!"; //<2F>뢮<EFBFBD> SHA1
|
2020-09-21 19:37:22 +02:00
|
|
|
|
char hash_str_sha256[MAX_HASH_LEN]="Click the 'SHA256:' button to show the sha256-checksum!"; //<2F>뢮<EFBFBD> SHA256
|
|
|
|
|
char edit_box_buff[MAX_HASH_LEN]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
char *filename; // <20><><EFBFBD> <20><>ࠡ<EFBFBD><E0A0A1>뢠<EFBFBD><EBA2A0><EFBFBD><EFBFBD><EFBFBD> 䠩<><E4A0A9>
|
|
|
|
|
char *title; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
enum MYCOLORS // <20><><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
2020-12-21 19:42:34 +01:00
|
|
|
|
GREEN = 0x067D06 | EDIT_TEXT_SIZE,
|
|
|
|
|
RED = 0xFF0000 | EDIT_TEXT_SIZE,
|
|
|
|
|
BLACK = 0x000000 | EDIT_TEXT_SIZE,
|
|
|
|
|
WHITE = 0xFFFFFF,
|
|
|
|
|
GREY = 0x919191
|
2020-09-21 19:37:22 +02:00
|
|
|
|
};
|
|
|
|
|
|
2020-12-21 19:42:34 +01:00
|
|
|
|
edit_box hash_edit_box={WINDOW_W-140,10,121,WHITE,0,0,GREY,EDIT_TEXT_SIZE, MAX_HASH_LEN-1, edit_box_buff,NULL,ed_focus}; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> edit_box
|
2020-09-21 19:37:22 +02:00
|
|
|
|
int md5_flag=0, sha1_flag=0, sha256_flag=0; // <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>뢠<EFBFBD>騥 <20>뫠 <20><> 㦥 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⠭<EFBFBD> <20><><EFBFBD>쭠<E0AEAB> <20>㬬<EFBFBD> <20> <20>㭪樨 check_sum()
|
|
|
|
|
|
|
|
|
|
enum BUTTONS // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD>䥩<EFBFBD><E4A5A9>
|
|
|
|
|
{
|
|
|
|
|
BTN_QUIT=1, //<2F><>室
|
|
|
|
|
BTN_MD5 = 10, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> md5-<2D><><EFBFBD><EFBFBD><EFBFBD><E0AEAB><EFBFBD><EFBFBD> <20>㬬<EFBFBD>
|
|
|
|
|
BTN_SHA1 = 20, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> sha1-<2D><><EFBFBD><EFBFBD><EFBFBD><E0AEAB><EFBFBD><EFBFBD> <20>㬬<EFBFBD>
|
|
|
|
|
BTN_SHA256 = 30, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> sha256-<2D><><EFBFBD><EFBFBD><EFBFBD><E0AEAB><EFBFBD><EFBFBD> <20>㬬<EFBFBD>
|
|
|
|
|
BTN_COPY_MD5= 11, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E0AEA2><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
BTN_COPY_SHA1= 21,
|
|
|
|
|
BTN_COPY_SHA256=31,
|
|
|
|
|
BTN_CMP=40, //<2F>ࠢ<EFBFBD><E0A0A2><EFBFBD><EFBFBD> edit_box <20> <20><><EFBFBD><EFBFBD><EFBFBD><E0AEAB><EFBFBD><EFBFBD> <20>㬬<EFBFBD>
|
|
|
|
|
BTN_PASTE=50 //<2F><>⠢<EFBFBD><E2A0A2><EFBFBD> <20> edit_box(<28><><EFBFBD><EFBFBD> <20> ࠧࠡ<E0A0A7>⪥)
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-11 21:34:18 +01:00
|
|
|
|
void notify_show(char *text)
|
|
|
|
|
{
|
2021-05-01 00:28:05 +02:00
|
|
|
|
_ksys_exec("/sys/@notify", text);
|
2020-12-11 21:34:18 +01:00
|
|
|
|
}
|
2020-09-21 19:37:22 +02:00
|
|
|
|
|
|
|
|
|
void* safe_malloc(size_t size) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> malloc. <20><><EFBFBD><EFBFBD><EFBFBD>뢠<EFBFBD><EBA2A0> 㢥<><E3A2A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20>訡<EFBFBD><E8A8A1> <20> <20><><EFBFBD><EFBFBD>뢠<EFBFBD><EBA2A0> <20>ணࠬ<E0AEA3><E0A0AC> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20>뫠 <20>뤥<EFBFBD><EBA4A5><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
void *p=malloc(size);
|
2021-02-02 09:08:17 +01:00
|
|
|
|
if(p==NULL){
|
2020-09-21 19:37:22 +02:00
|
|
|
|
notify_show("'Memory allocation error!' -E");
|
|
|
|
|
exit(0);
|
2021-02-02 09:08:17 +01:00
|
|
|
|
}else{
|
2020-09-21 19:37:22 +02:00
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void global_var_init(unsigned int size) // <20><><EFBFBD>樠<EFBFBD><E6A8A0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ᨢ<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
filename=safe_malloc(size);
|
|
|
|
|
title=safe_malloc(size+20);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20>㭪樨 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>樨 <20><><EFBFBD><EFBFBD><EFBFBD><E0AEAB><EFBFBD><EFBFBD> <20>㬬 */
|
|
|
|
|
void md5_hash(FILE* input, BYTE* hash )
|
|
|
|
|
{
|
|
|
|
|
int input_size;
|
|
|
|
|
BYTE *temp_buffer;
|
|
|
|
|
temp_buffer=safe_malloc(1024);
|
|
|
|
|
MD5_CTX ctx;
|
|
|
|
|
md5_init(&ctx);
|
|
|
|
|
while((input_size = fread(temp_buffer, 1, 1024, input)) > 0){
|
|
|
|
|
md5_update(&ctx, temp_buffer, input_size);
|
|
|
|
|
}
|
|
|
|
|
md5_final(&ctx, hash);
|
|
|
|
|
free(temp_buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sha1_hash(FILE* input, BYTE* hash )
|
|
|
|
|
{
|
|
|
|
|
int input_size;
|
|
|
|
|
BYTE *buffer;
|
|
|
|
|
buffer=safe_malloc(1024);
|
|
|
|
|
SHA1_CTX ctx;
|
|
|
|
|
sha1_init(&ctx);
|
|
|
|
|
while((input_size = fread(buffer, 1, 1024, input)) > 0){
|
|
|
|
|
sha1_update(&ctx, buffer, input_size);
|
|
|
|
|
}
|
|
|
|
|
sha1_final(&ctx, hash);
|
|
|
|
|
free(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sha256_hash(FILE* input, BYTE* hash )
|
|
|
|
|
{
|
|
|
|
|
int input_size;
|
|
|
|
|
BYTE *buffer;
|
|
|
|
|
buffer=safe_malloc(1024);
|
|
|
|
|
SHA256_CTX ctx;
|
|
|
|
|
sha256_init(&ctx);
|
|
|
|
|
while((input_size = fread(buffer, 1, 1024, input)) > 0){
|
|
|
|
|
sha256_update(&ctx, buffer, input_size);
|
|
|
|
|
}
|
|
|
|
|
sha256_final(&ctx, hash);
|
|
|
|
|
free(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BYTE* check_sum(int alg) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㥬 <20><><EFBFBD><EFBFBD><EFBFBD><E0AEAB><EFBFBD><EFBFBD> <20>㬬<EFBFBD> <20>ᯮ<EFBFBD><E1AFAE><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⬮<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
FILE* input_file;
|
|
|
|
|
BYTE *hash;
|
|
|
|
|
input_file=fopen(filename,"rb");
|
|
|
|
|
hash = safe_malloc(alg);
|
|
|
|
|
switch (alg)
|
|
|
|
|
{
|
|
|
|
|
case MD5_BLOCK_SIZE :
|
|
|
|
|
md5_hash(input_file, hash);
|
|
|
|
|
md5_flag=1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SHA1_BLOCK_SIZE :
|
|
|
|
|
sha1_hash(input_file, hash);
|
|
|
|
|
sha1_flag=1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SHA256_BLOCK_SIZE :
|
|
|
|
|
sha256_hash(input_file, hash);
|
|
|
|
|
sha256_flag=1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
fclose(input_file);
|
|
|
|
|
return hash;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sprint_hash(BYTE *hash, char* hash_str, int hash_size) //<2F>८<EFBFBD><E0A5AE><EFBFBD>㥬 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> hash <20> <20><>ப<EFBFBD> hash_str
|
|
|
|
|
{
|
|
|
|
|
char block[3];
|
|
|
|
|
memset(hash_str, 0, MAX_HASH_LEN); // <20><><EFBFBD>頥<EFBFBD> <20><>ப<EFBFBD> <20><><EFBFBD> strcat
|
|
|
|
|
for(int i=0; i<hash_size; i++)
|
|
|
|
|
{
|
|
|
|
|
sprintf(block,"%02x", hash[i]);
|
|
|
|
|
strcat(hash_str,block);
|
|
|
|
|
}
|
|
|
|
|
free(hash);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void redraw_window() //<2F><><EFBFBD>㥬 <20><><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
sprintf(title,VERSION, filename); // <20><>⠭<EFBFBD><E2A0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
2021-05-01 00:28:05 +02:00
|
|
|
|
ksys_pos_t win_pos = _ksys_get_mouse_pos(KSYS_MOUSE_SCREEN_POS); // <20><><EFBFBD><EFBFBD>砥<EFBFBD> <20><><EFBFBD>न<EFBFBD><E0A4A8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
_ksys_start_draw(); //<2F><>稭<EFBFBD><E7A8AD><EFBFBD> <20><>ᮢ<EFBFBD><E1AEA2><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>䥩<EFBFBD><E4A5A9> )
|
|
|
|
|
_ksys_create_window(win_pos.x, win_pos.y, WINDOW_W, 150, title, sys_color_table.work_area, 0x14); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
|
2020-12-21 19:42:34 +01:00
|
|
|
|
edit_box_draw(&hash_edit_box); // <20><><EFBFBD>㥬 edit_box
|
2020-09-21 19:37:22 +02:00
|
|
|
|
|
2021-05-01 00:28:05 +02:00
|
|
|
|
_ksys_define_button(10, 30, 60, 20, BTN_MD5, GREEN); // <20><>।<EFBFBD><E0A5A4>塞 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> md5
|
|
|
|
|
_ksys_define_button(10, 60, 60, 20, BTN_SHA1, GREEN);// <20><>।<EFBFBD><E0A5A4>塞 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> sha1
|
|
|
|
|
_ksys_define_button(10, 90, 60, 20, BTN_SHA256, GREEN);// <20><>।<EFBFBD><E0A5A4>塞 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> sha256
|
2020-09-21 19:37:22 +02:00
|
|
|
|
|
2021-05-01 00:28:05 +02:00
|
|
|
|
_ksys_draw_text("MD5:", 15, 34, 0, 0x90000000 | sys_color_table.work_button_text); // <20><>饬 ⥪<><E2A5AA> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
_ksys_draw_text("SHA1:", 15, 64, 0, 0x90000000 | sys_color_table.work_button_text);
|
|
|
|
|
_ksys_draw_text("SHA256:", 15,94, 0, 0x90000000 | sys_color_table.work_button_text);
|
2020-09-21 19:37:22 +02:00
|
|
|
|
|
2021-05-01 00:28:05 +02:00
|
|
|
|
_ksys_draw_text(hash_str_md5, 80, 34, 0, 0x90000000 | sys_color_table.work_text); // <20>뢮<EFBFBD><EBA2AE><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><E0AEAB><EFBFBD><EFBFBD> <20>㬬<EFBFBD> <20> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
_ksys_draw_text(hash_str_sha1, 80, 64, 0, 0x90000000 | sys_color_table.work_text);
|
|
|
|
|
_ksys_draw_text(hash_str_sha256, 80, 94, 0, 0x90000000| sys_color_table.work_text);
|
2020-09-21 19:37:22 +02:00
|
|
|
|
|
2021-05-01 00:28:05 +02:00
|
|
|
|
|
|
|
|
|
_ksys_define_button(610, 30, 42, 20, BTN_COPY_MD5, sys_color_table.work_button); // <20><>।<EFBFBD><E0A5A4>塞 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><E0AEA2><EFBFBD><EFBFBD>
|
|
|
|
|
_ksys_define_button(610, 60, 42, 20, BTN_COPY_MD5, sys_color_table.work_button);
|
|
|
|
|
_ksys_define_button(610, 90, 42, 20, BTN_COPY_MD5, sys_color_table.work_button);
|
2020-09-21 19:37:22 +02:00
|
|
|
|
|
2021-05-01 00:28:05 +02:00
|
|
|
|
_ksys_draw_text("Copy", 615, 34, 0, 0x90000000 | sys_color_table.work_button_text); // <20><>襬 copy <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><E0AEA2><EFBFBD><EFBFBD>
|
|
|
|
|
_ksys_draw_text("Copy", 615, 64, 0, 0x90000000 | sys_color_table.work_button_text);
|
|
|
|
|
_ksys_draw_text("Copy", 615, 94, 0, 0x90000000 | sys_color_table.work_button_text);
|
2020-09-21 19:37:22 +02:00
|
|
|
|
|
2021-05-01 00:28:05 +02:00
|
|
|
|
_ksys_define_button(592, 120, 60, 20, BTN_CMP, GREEN); // <20><>।<EFBFBD><E0A5A4>塞 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20>ࠢ<EFBFBD><E0A0A2><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>⮫<EFBFBD><E2AEAB><EFBFBD><EFBFBD> <20>㬬
|
|
|
|
|
_ksys_draw_text("Compare", 595, 124 , 0,0x90000000 | sys_color_table.work_button_text); // <20><>襬 ⥪<> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|
|
|
|
_ksys_define_button(540, 120, 45, 20, BTN_PASTE, sys_color_table.work_button); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><>⠢<EFBFBD><E2A0A2> (<28><>ࠡ<EFBFBD>⠥<EFBFBD>)
|
|
|
|
|
_ksys_draw_text("Paste", 543, 124 , 0,0x90000000 | sys_color_table.work_button_text); // <20><><EFBFBD><EFBFBD><EFBFBD> paste <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
_ksys_end_draw();
|
2020-09-21 19:37:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void paste_to_edit_buffer() // <20><>⠢<EFBFBD><E2A0A2><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
2020-11-24 15:40:29 +01:00
|
|
|
|
char *temp_buff=NULL;
|
2021-05-01 00:28:05 +02:00
|
|
|
|
if(_ksys_clip_num()>0){
|
|
|
|
|
temp_buff=_ksys_clip_get(_ksys_clip_num()-1);
|
2020-11-24 15:40:29 +01:00
|
|
|
|
memset(edit_box_buff,0,MAX_HASH_LEN);
|
2021-05-01 00:28:05 +02:00
|
|
|
|
if(DATA(int, temp_buff,0)>0 && DATA(int,temp_buff,4)==KSYS_CLIP_TEXT && DATA(int,temp_buff,8)==KSYS_CLIP_CP866){
|
2020-11-24 15:40:29 +01:00
|
|
|
|
strncpy(edit_box_buff,temp_buff+12, MAX_HASH_LEN-1);
|
2020-12-21 19:42:34 +01:00
|
|
|
|
edit_box_set_text(&hash_edit_box,edit_box_buff);
|
2020-11-24 15:40:29 +01:00
|
|
|
|
notify_show("'Pasted from clipboard!' -I");
|
2020-12-21 19:42:34 +01:00
|
|
|
|
hash_edit_box.text_color = BLACK;
|
2021-05-01 00:28:05 +02:00
|
|
|
|
free(temp_buff);
|
2020-11-24 15:40:29 +01:00
|
|
|
|
}
|
2020-09-21 19:37:22 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-02 09:08:17 +01:00
|
|
|
|
void copy_to_clipboard(char *text) // <20><><EFBFBD><EFBFBD><EFBFBD><E0AEA2><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2020-09-21 19:37:22 +02:00
|
|
|
|
{
|
2021-02-02 09:08:17 +01:00
|
|
|
|
int text_hash_len = strlen(text)/2;
|
|
|
|
|
if(text_hash_len==MD5_BLOCK_SIZE ||
|
|
|
|
|
text_hash_len==SHA1_BLOCK_SIZE ||
|
|
|
|
|
text_hash_len==SHA256_BLOCK_SIZE) // <20> ⥪<><E2A5AA> <><EFA2AB><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>-<2D><>ப<EFBFBD><E0AEAA>
|
2020-09-21 19:37:22 +02:00
|
|
|
|
{
|
2021-02-02 09:08:17 +01:00
|
|
|
|
char *temp_buffer=safe_malloc(MAX_HASH_LEN+12); // <20>뤥<EFBFBD>塞 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20>६<EFBFBD><E0A5AC><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
memset(temp_buffer, 0, MAX_HASH_LEN); // <20><><EFBFBD><EFBFBD><EFBFBD>塞 <20><><EFBFBD><EFBFBD><EFBFBD>
|
2021-05-01 00:28:05 +02:00
|
|
|
|
DATA(char,temp_buffer,4)=KSYS_CLIP_TEXT; // <20><>⠭<EFBFBD><E2A0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> TEXT <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD>饭<EFBFBD><E9A5AD> 4 <20><><EFBFBD><EFBFBD><EFBFBD>)
|
|
|
|
|
DATA(char,temp_buffer,8)=KSYS_CLIP_CP866; // <20><>⠭<EFBFBD><E2A0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><E0AEA2> CP866(<28><><EFBFBD>饭<EFBFBD><E9A5AD> 8 <20><><EFBFBD><EFBFBD>)
|
2021-02-02 09:08:17 +01:00
|
|
|
|
strncpy(temp_buffer+12, text, MAX_HASH_LEN-1); // <20><><EFBFBD><EFBFBD><EFBFBD>㥬 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> text <20><> <20>६<EFBFBD><E0A5AC><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD>饭<EFBFBD><E9A5AD> 12 <20><><EFBFBD><EFBFBD>)
|
2021-05-01 00:28:05 +02:00
|
|
|
|
_ksys_clip_set(strlen(text)+12, temp_buffer); // <20>믮<EFBFBD><EBAFAE>塞 <20><><EFBFBD>⥬<EFBFBD><E2A5AC><EFBFBD> <20>맮<EFBFBD> <20> <20><>६<EFBFBD>頥<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20>६<EFBFBD><E0A5AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2021-02-02 09:08:17 +01:00
|
|
|
|
notify_show("'Copied to clipboard!' -I");
|
|
|
|
|
free(temp_buffer); // <20><EFBFBD><E1A2AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>६<EFBFBD><E0A5AC><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>.
|
2020-09-21 19:37:22 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void print_pending_calc(char *str) // <20>뢮<EFBFBD><EBA2AE><EFBFBD> ᮮ<>饭<EFBFBD><E9A5AD> <20> ⮬ <20><><EFBFBD> <20><><EFBFBD><EFBFBD>쭠<E0AEAB> <20>㬬<EFBFBD><E3ACAC> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|
|
|
|
{
|
2021-02-02 09:08:17 +01:00
|
|
|
|
strcpy(str, "Please wait! Calculating checksum...");
|
2020-09-21 19:37:22 +02:00
|
|
|
|
redraw_window();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool calc_and_cmp(char *hash_str_universal,int alg) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>塞 <20><><EFBFBD><EFBFBD><EFBFBD><E0AEAB><EFBFBD><EFBFBD> <20>㬬<EFBFBD> <20> <20>ࠢ<EFBFBD><E0A0A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> edit_box_buff.
|
|
|
|
|
{
|
|
|
|
|
print_pending_calc(hash_str_universal);
|
|
|
|
|
sprint_hash(check_sum(alg),hash_str_universal, alg);
|
|
|
|
|
return !strcmp(edit_box_buff, hash_str_universal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool hash_compare() // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>㭪<EFBFBD><E3ADAA><EFBFBD> <20><><EFBFBD> <20>ࠢ<EFBFBD><E0A0A2><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
int alg=strlen(edit_box_buff)/2;
|
2021-02-02 09:08:17 +01:00
|
|
|
|
switch (alg){ // <20> <20><><EFBFBD><EFBFBD><EFBFBD><E1ABA5><EFBFBD> <20><><EFBFBD> <20><><EFBFBD>뫮
|
2020-09-21 19:37:22 +02:00
|
|
|
|
case MD5_BLOCK_SIZE:
|
2020-12-21 19:42:34 +01:00
|
|
|
|
if(md5_flag){
|
2020-09-21 19:37:22 +02:00
|
|
|
|
return !strcmp(edit_box_buff,hash_str_md5);
|
2020-12-21 19:42:34 +01:00
|
|
|
|
}else{
|
2020-09-21 19:37:22 +02:00
|
|
|
|
return calc_and_cmp(hash_str_md5,alg);
|
|
|
|
|
}
|
2021-02-02 09:08:17 +01:00
|
|
|
|
break;
|
2020-09-21 19:37:22 +02:00
|
|
|
|
case SHA1_BLOCK_SIZE:
|
2020-12-21 19:42:34 +01:00
|
|
|
|
if(sha1_flag){
|
2020-09-21 19:37:22 +02:00
|
|
|
|
return !strcmp(edit_box_buff,hash_str_sha1);
|
2020-12-21 19:42:34 +01:00
|
|
|
|
}else{
|
2020-09-21 19:37:22 +02:00
|
|
|
|
return calc_and_cmp(hash_str_sha1,alg);
|
|
|
|
|
}
|
2021-02-02 09:08:17 +01:00
|
|
|
|
break;
|
2020-09-21 19:37:22 +02:00
|
|
|
|
case SHA256_BLOCK_SIZE:
|
2020-12-21 19:42:34 +01:00
|
|
|
|
if(sha256_flag){
|
2020-09-21 19:37:22 +02:00
|
|
|
|
return !strcmp(edit_box_buff,hash_str_sha256);
|
2020-12-21 19:42:34 +01:00
|
|
|
|
}else{
|
2020-09-21 19:37:22 +02:00
|
|
|
|
return calc_and_cmp(hash_str_sha256,alg);
|
|
|
|
|
}
|
2021-02-02 09:08:17 +01:00
|
|
|
|
break;
|
2020-09-21 19:37:22 +02:00
|
|
|
|
default:
|
|
|
|
|
return FALSE;
|
2021-02-02 09:08:17 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2020-09-21 19:37:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
|
{
|
2020-12-21 19:42:34 +01:00
|
|
|
|
kolibri_boxlib_init(); // <20><><EFBFBD><EFBFBD>㦠<EFBFBD><E3A6A0> boxlib
|
2021-02-02 09:08:17 +01:00
|
|
|
|
if(argc<2){ // <20> <20><><EFBFBD>㬥<EFBFBD>⮢ <20><><EFBFBD>, <20><> <20><><EFBFBD><EFBFBD>᪠<EFBFBD><E1AAA0> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>롮<EFBFBD><EBA1AE> <20><>
|
2020-12-21 19:42:34 +01:00
|
|
|
|
kolibri_dialog_init(); // <20><><EFBFBD><EFBFBD>㦠<EFBFBD><E3A6A0> proc_lib(libdialog)
|
2020-12-16 21:10:09 +01:00
|
|
|
|
open_dialog* dialog = kolibri_new_open_dialog(OPEN,0, 0, 420, 320);
|
|
|
|
|
OpenDialog_init(dialog);
|
|
|
|
|
OpenDialog_start(dialog);
|
2021-02-02 09:08:17 +01:00
|
|
|
|
if(dialog->status==SUCCESS){ // <20> 䠩<> <20><><EFBFBD>࠭
|
2020-12-16 21:10:09 +01:00
|
|
|
|
global_var_init(strlen(dialog->openfile_path));
|
|
|
|
|
strcpy(filename, dialog->openfile_path);
|
2021-02-02 09:08:17 +01:00
|
|
|
|
}else{ // <20> 䠩<> <20><> <20><><EFBFBD>࠭
|
2020-12-16 21:10:09 +01:00
|
|
|
|
notify_show("'No file selected!' -E");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
free(dialog);
|
2021-02-02 09:08:17 +01:00
|
|
|
|
}else{
|
2020-12-16 21:10:09 +01:00
|
|
|
|
global_var_init(strlen(argv[1]));
|
|
|
|
|
strcpy(filename, argv[1]);
|
2020-09-21 19:37:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-02 09:08:17 +01:00
|
|
|
|
if(NULL==fopen(filename,"rb")){ // <20> 䠩<><E4A0A9> <20><><EFBFBD> <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>뢠<EFBFBD><EBA2A0><EFBFBD><EFBFBD>
|
2020-09-21 19:37:22 +02:00
|
|
|
|
notify_show("'File not found!' -E");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
2021-05-01 00:28:05 +02:00
|
|
|
|
if(_ksys_screen_size().x<WINDOW_W){
|
2020-09-21 19:37:22 +02:00
|
|
|
|
notify_show("'Low screen resolution! Program will not display correctrly!' -W");
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-16 21:10:09 +01:00
|
|
|
|
int gui_event; // <20><>६<EFBFBD><E0A5AC><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20>࠭<EFBFBD><E0A0AD><EFBFBD><EFBFBD> ᮡ<><E1AEA1><EFBFBD><EFBFBD>
|
2020-09-21 19:37:22 +02:00
|
|
|
|
uint32_t pressed_button = 0; // <20><><EFBFBD> <20><><EFBFBD><EFBFBD>⮩ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
2021-05-01 00:28:05 +02:00
|
|
|
|
_ksys_get_system_colors(&sys_color_table);
|
2020-12-21 19:42:34 +01:00
|
|
|
|
hash_edit_box.shift_color=sys_color_table.work_button;
|
|
|
|
|
|
2021-05-01 00:28:05 +02:00
|
|
|
|
_ksys_set_event_mask(0xC0000027);// <20><>⠭<EFBFBD><E2A0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> ᮡ<>⨩
|
2020-09-21 19:37:22 +02:00
|
|
|
|
do // <20><><EFBFBD><EFBFBD> <20><>ࠡ<EFBFBD>⪨ ᮡ<>⨩
|
|
|
|
|
{
|
2021-05-01 00:28:05 +02:00
|
|
|
|
gui_event = _ksys_get_event(); // <20><><EFBFBD><EFBFBD>砥<EFBFBD> ᮡ<>⨥
|
2021-02-02 09:08:17 +01:00
|
|
|
|
switch(gui_event){ // <20><>ࠡ<EFBFBD><E0A0A1>뢠<EFBFBD><EBA2A0> ᮡ<><E1AEA1><EFBFBD><EFBFBD>
|
2021-05-01 00:28:05 +02:00
|
|
|
|
case KSYS_EVENT_NONE:
|
2020-09-21 19:37:22 +02:00
|
|
|
|
break;
|
2021-05-01 00:28:05 +02:00
|
|
|
|
case KSYS_EVENT_REDRAW:
|
2021-02-02 09:08:17 +01:00
|
|
|
|
redraw_window();
|
2020-09-21 19:37:22 +02:00
|
|
|
|
break;
|
2021-05-01 00:28:05 +02:00
|
|
|
|
case KSYS_EVENT_MOUSE:
|
2021-02-02 09:08:17 +01:00
|
|
|
|
edit_box_mouse(&hash_edit_box);
|
|
|
|
|
break;
|
2021-05-01 00:28:05 +02:00
|
|
|
|
case KSYS_EVENT_KEY:
|
2021-02-02 09:08:17 +01:00
|
|
|
|
hash_edit_box.text_color = BLACK;
|
2021-05-01 00:28:05 +02:00
|
|
|
|
edit_box_key(&hash_edit_box, _ksys_get_key().val);
|
2020-09-21 19:37:22 +02:00
|
|
|
|
break;
|
2021-05-01 00:28:05 +02:00
|
|
|
|
case KSYS_EVENT_BUTTON: // <20><><EFBFBD><EFBFBD>⨥ <20><>ࠡ<EFBFBD>⪨ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
pressed_button = _ksys_get_button(); // <20><><EFBFBD><EFBFBD>祭<EFBFBD><E7A5AD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>⮩ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
2021-02-02 09:08:17 +01:00
|
|
|
|
switch (pressed_button){ // <20><EFBFBD>ઠ <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>뫠 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
case BTN_MD5:
|
|
|
|
|
print_pending_calc(hash_str_md5);
|
|
|
|
|
sprint_hash(check_sum(MD5_BLOCK_SIZE),hash_str_md5, MD5_BLOCK_SIZE);
|
|
|
|
|
break;
|
|
|
|
|
case BTN_SHA1:
|
|
|
|
|
print_pending_calc(hash_str_sha1);
|
|
|
|
|
sprint_hash(check_sum(SHA1_BLOCK_SIZE),hash_str_sha1, SHA1_BLOCK_SIZE);
|
|
|
|
|
break;
|
|
|
|
|
case BTN_SHA256:
|
|
|
|
|
print_pending_calc(hash_str_sha256);
|
|
|
|
|
sprint_hash(check_sum(SHA256_BLOCK_SIZE),hash_str_sha256, SHA256_BLOCK_SIZE);
|
|
|
|
|
break;
|
|
|
|
|
case BTN_COPY_MD5:
|
|
|
|
|
copy_to_clipboard(hash_str_md5);
|
|
|
|
|
break;
|
|
|
|
|
case BTN_COPY_SHA1:
|
|
|
|
|
copy_to_clipboard(hash_str_sha1);
|
|
|
|
|
break;
|
|
|
|
|
case BTN_COPY_SHA256:
|
|
|
|
|
copy_to_clipboard(hash_str_sha256);
|
|
|
|
|
break;
|
|
|
|
|
case BTN_PASTE:
|
|
|
|
|
paste_to_edit_buffer();
|
|
|
|
|
break;
|
|
|
|
|
case BTN_CMP:
|
|
|
|
|
if(hash_compare()){
|
|
|
|
|
notify_show("'The checksum matches :)' -OK");
|
|
|
|
|
hash_edit_box.text_color = GREEN; // <20><>⠭<EFBFBD><E2A0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ⥪<><E2A5AA> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD>쭠<E0AEAB> <20>㬬<EFBFBD> ᮢ<><E1AEA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
}else{
|
|
|
|
|
notify_show("'The checksum does not match! :(' -W");
|
|
|
|
|
hash_edit_box.text_color = RED; // <20><>⠭<EFBFBD><E2A0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ⥪<><E2A5AA> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD>쭠<E0AEAB> <20>㬬<EFBFBD> <20><> ᮢ<><E1AEA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case BTN_QUIT:
|
|
|
|
|
exit(0);
|
|
|
|
|
break;
|
2020-09-21 19:37:22 +02:00
|
|
|
|
}
|
|
|
|
|
redraw_window();
|
2021-02-02 09:08:17 +01:00
|
|
|
|
break;
|
2020-09-21 19:37:22 +02:00
|
|
|
|
}
|
|
|
|
|
}while(1);
|
2020-12-16 21:10:09 +01:00
|
|
|
|
exit(0);
|
2020-09-21 19:37:22 +02:00
|
|
|
|
}
|