-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdnw.cpp
More file actions
4804 lines (3689 loc) · 142 KB
/
Copy pathdnw.cpp
File metadata and controls
4804 lines (3689 loc) · 142 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ----------------------------
// dnw.cpp
// -------------------------------
#define STRICT
#define WIN32_LEAN_AND_MEAN
#include "resource.h"
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <tchar.h>
#include <string.h>
#include <process.h> /* For _beginthread() */
#include <stdlib.h>
#include <io.h> // _findfirsti64()
#include <wchar.h>
#include "def.h"
#include "dnw.h"
#include "engine.h"
#include "fileopen.h"
#include "d_box.h"
#include "usbtxrx.h"
#include <stdio.h>
#include <memory.h>
#include "regmgr.h"
#include <Tlhelp32.h> // CreateToolhelp32Snapshot(TH32CS_SNAPALL,NULL);
//NOTE: _beginthread()
// To use _beginenthread(),Activate "Project/Settings/C/C++/Categry/Code generation/
// Use Run-Time library/Multithreaded or Debug Multithreaded"
// If DDK2000 is used,
// 1. Project_Settings/CC++/Preprocessor/Additional_include_directories = C:\NTDDK\inc
// 2. Project_Settings/Link/Input/Additional_library_path=c:\NTDDK\libfre\i386
// If DDKXP is used,
// 1. Project_Settings/CC++/Preprocessor/Additional include directories = C:\WINDDK\2600\inc\w2k
// 2-1. Project_Settings/Link/Input/Additional_library_path=C:\WINDDK\2600\lib\w2k\i386
// This causes some warning about '.rdata' section attribute.
// 2-2. Project_Settings/Link/Input/Additional_library_path==C:\WINDDK\2600\lib\i386\free
// There's no warning.
/*
===================== REVISON HISTORY =====================
1. 2000. 3.30: V0.01
First release of DNW
2. 2000.10.11: V0.2
The edit control is used for scroll, copy&paste, smooth screen update
3. 2001.1.26: V0.3
a) The CPU usage will be less. Sleep() is inserted during TX.
b) The filesize and checksum are transmitted together with bin file.
c) WriteCommBlock() bug is fixed. The txEmpty flag should be changed in only DoRxTx().
4. 2001.2.24: V0.31
a) The size of edit buffer is changed by EM_LIMITTEXT message.
EDIT_BUF_SIZE(30000) -> MAX_EDIT_BUF_SIZE(65000)
b) If the edit box is greater than 50000,
the size of edit box is reduced by 10000.
c) The horizontal scroll bar is removed for better look.
d) In WaitCommEvent() loop,
the following condition is inserted to clear the overrun condition.
if((dwEvtMask & EV_ERR){...}
e) EB_Printf() have some error to process large string data.
5. 2001.3.8: V0.32
a) EDIT_BUF_SIZE is reduced 25000 because the EM_REPLACESEL message is done very slowly
if the size is over about 30000.
6. 2001.4.11: V0.32A
a) Experimentally, MAX_EDIT_BUF_SIZE is set to the default value(32767).
//SendMessage(_hwndEdit, EM_SETLIMITTEXT, MAX_EDIT_BUF_SIZE, 0L);
RESULT: MAX_EDIT_BUF_SIZE doesn't affect the display delay problem.
I think that the new method for deleting the contents should be applied
Let's do tonight
7. 2001.5.14: V0.34
a) I have known that the edit control isn't adequate for console program.
So, I would give up the development of DNW using the edit control
The last decision is as follows;
MAX_EDIT_BUF_SIZE (65000) //up to 65535
EDIT_BUF_SIZE (30000)
EDIT_BUF_DEC_SIZE (10000)
b) If the selected text is deleted, the edit control displays the first of the text.
In this case, to show the end of the text, dummy REPLACE_SEL is added.
8. 2001.11.23: V0.4
a) USB download function is added.
b) GetOverlappedResult() is used in TxFile() in order to save the cpu time more efficiently
c) Serial Configuration dialog box
d) In secbulk.sys is changed to support IRP_MN_QUERY_CAPABILITIES.
So, the surpriseRemoval is allowed. When the USB is yanked impolitely,
the warning dialog box won't appear in WIN2000.
9. 2001.11.24: v0.41alpha
a) WriteFile() supports overlapped I/O to check broken pipe.
b) progress bar is added for transmit operation.
c) USB,serial status is printed on the window title bar
10. 2001.12.5: v0.42a
a) In secbulk.sys, the maximum number of bulk packit in 1ms frame duration is changed to 16 from 4.
So, transfer rate is increased from 220KB/S to 405KB/S
b) Although the fileopen was failed(or canceled), the transmit wasn't canceled. This is fixed.
c) When the options menu is selected, a serial port will be reconnected.
d) The receive test menu is added.
11. 2001.12.6: v0.43
a) Fou USB tx operation, TX_SIZE is increased from 2KB to 16KB.
So, transfer rate is increased from 405KB/S to 490KB/S.
(2KB:405KB/S 4KB:450KB/S 8KB:470KB/S 16KB:490KB/S)
12. 2001.12.7: v0.44b
a) Although a serial port is not connected, the serial port is connected
after Configuration/Options menu -> fixed.
b) The name dnw.cfg for v 0.4x is changed to dnw.ini
in order not to confuse old dnw.cfg for ver 0.3x
12. 2002.01.2: v0.44c
a) The edit box size is changed to display 80x25 characters
13. 2002.02.22: v0.45
a) In windows95, DNW doesn't search USB stack.
b) When download, there should be a cancel button
c) Sometimes, the progress bar is not filled although download is doing.
I think it's because InitDownloadProgress() is executed
before than DownloadProgressProc().
So, I inserted the code to wait until DownloadProgressProc() is executed as follows;
while(_hDlgDownloadProgress==0); //wait until the progress dialog box is ready.
d) secbulk is optimized
14. 2002.04.01: v0.46
a) If DNW is start to transmit although the b/d is not ready, DNW will be hung.
It's only solution to turn off and on the b/d.
To solve this problem smoothly, the overlapped I/O will be used for USB transfer.
But, secbulk.sys may not support overlapped I/O.
Although I implemented the overlapped I/O, WriteFile() function didn't return before its completion.
b) Because the overlapped I/O doens't work as my wish,
and in order to quit the dnw.exe hung, modaless dialogue box is used for the progress bar.
c) *.nb0
15. 2002.04.10: v0.47
a) I reduce the edit box size as follows;
#define MAX_EDIT_BUF_SIZE (0x7FFE)
#define EDIT_BUF_SIZE (0x6000)
#define EDIT_BUF_DEC_SIZE (0x1000)
There is no good cause about why I change. I want to just reduce the edit box size.
b) Sometimes, when transmit, there is no transmit although the transmit progrss dialog box is shown.
I think that it's because the _enthread() fails.
To debug this problem, the _enthread result is checked.
16. 2002.04.19: v0.48
a) The bug of WIN2K WINAPI is found. ->It's not fixed perfectly.
Please let me know of the solution to avoid the memory problem of SetWindowText() API.
The SetWindowText()(also,WM_SETTEXT message) consumes 4KB system memory every times.
I think there is some bug in SetWindowText API.
In my case, because SetWindowText() is called every 1 seconds,
the system memory used by DNW.exe is increased by 4KB every 1 seconds.
For emergency fix, SetWindowText() will be called only when its content is changed.
NOTE. This memory problem is not memory leakage problem
because the memory is flushed when the window is shrinked.
17. 2002.05.03:v0.49
a) Sometimes, when transmit, there is no transmit although the transmit progrss dialog box is shown.
I have found the cause.
It's because _hDlgDownloadProgress.
If the TxFile thread is executed first than WM_INITDIALOG message,
while(_hDlgDownloadProgress==NULL); will not exited because _hDlgDownloadProgress
in CPU register will be checked. So, the volatile should have been used
because _hDlgDownloadProgress value is changed in another thread.
The solution is as follows;
volatile HWND _hDlgDownloadProgress=NULL;
b) Sometimes, the CPU usage will be always 100% if dnw.exe is being executed.
This is because of the just above problem.
If the problem 17-a) is occurred, the TxFile will be an obsolete thread.
while(_hDlgDownloadProgress==NULL); will use the CPU at 100%.
I think that this problem may be cleared because the problem 17-a) is cleared.
c) The small icon,DNW is displayed in the window shell task bar and the window title.
18. 2003.04.25:v0.50
a) In case that a USB2Serial cable is used when COMPAQ Presario 1700,
a few last character display is postponed until the next group is received.
-> MSDN recommends the while() for read operation, which has solved the problem.
b) In DoRxTx(), the EV_ERR is added to SetCommMask(); -> which is more correct, I think.
c) For overlapped WaitCommEvent,ReadFile,WriteFile, the return value should be checked.
For ReadFile,WriteFile cases, the operation has no change.
In previous version(V0.49), WaitCommEvent(,,NULL) should have not been used because OVERLAPPED I/O was being used.
The combination of WaitCommEvent(,,&os) and GetOverlappedResult() will fix this problem.
d) During developing the DNW v0.50, I had experienced some blue screen without any USB connection when I reset the SMDK2410.
This problem was occurred when WaitCommEvent(,,&os) without GetOverlappedResult().
This problem was not revived when is WaitCommEvent(,,NULL) although it's not correct.
From this phenomenon, I assume that the blue-screen, which is caused sometimes when resetting the SMDK2410,
may be caused by the mis-use of WaitCommEvent(,,NULL).
But, it's still truth that the abnormal USBD response may cause the windows blue-screen
,which I experienced many times during my secbulk.sys development.
19. 2003.04.29:v0.50A
a) If the break condition is detected, "[DBG:EV_ERR]" message is displayed.
So, the display of "[DBG:EV_ERR]" is removed.
*/
/*
Items to be enhanced.
- avoid SetWindowText() API problem.
- remove debug stuff in following functions.
void InitDownloadProgress(void);
void DisplayDownloadProgress(int percent);
- make status bar.
- malloc() uses too much memory for large file transfer.
- Enlarge the scroll buffer -> the edit box is not adequate.
- file logging function
- Ctrl+C should be work as copy function.
*/
/*
Edit Box Note:
- Check if the edit box is scrolled to show the text being deleted
when the selected text is deleted in Win2000. In windows98, It's scrolled to show the deleted portion unfortunately.
*/
#define IS_OVERLAPPED_IO (TRUE)
#define IS_OVERLAPPED_CHECK 1 /// 2014.03.04, if Long Time, disconneted UART...
#define IS_OVERLAPPED_WAIT (30*1000) /// 30sec <-- INFINITE
#if USE_RX_TX_QUEUE
#include "queue.h"
//------------------------------
// Queue
//------------------------------
ctQueue Rx2Tx;
#endif
int userBaudRate,idBaudRate, autoSendKey=0, msgSaveOnOff=0;
#if DISPLAY_PC_SYSTEM_TIME /*--- 2016.02.12 ------ */
int localTime=0; // NONE
int isTimeInfoOnce=0; // Time 정보를 맨 앞에 한번 표시한다.
#endif
int cmdCRLF=0; // 2019.12.21
int LogFileType=0; // 2020.04.07
#if DNW_2ND_WINDOWS_ENABLE // 2017.4.14
extern int isStatusBarEnable; // BAR_STATUS, BAR_COMMAND
extern int OKstatusBarInitial; // 2017.4.14
#endif
int userComPort;
int TotalROMfilenum, UmonFileNum=0;
int FontType = 0;
int CPUtype=1; // 2014.04.11, SMDK6410:0, SMDKC100:1, S3C2440A:2, Other:3
// #if HEXA_MODE_SUPPORT /* 2011.02.08 Hexa mode display */
int TextorHexaMode=0; // display Text mode or Hexa mode -> default Text mode(0)
// #endif
extern DWORD HexaEndChar; // 2016.04.12
__int64 iUARTTxFileSize=0L; // 2016.10.12 tx data in MENU
int isTxUARTDataExit=0;
int isMenuTxing = 0;
#if USE_TXDATA_TO_SERIAL
int isTxData2UART = 0; // Tx Data on/Off for UpdateWindowTitle()
int sendTxDataType=0, txDataMsgOnOff; // 2016.03.23
extern volatile HWND _hDlgTxData2UART;
extern unsigned int TxScriptCommandLines;
#endif
#if USE_FLOAT2HEX_VALUE // 2018.07.18
extern volatile HWND _hDlgFlt2Hexa;
int iChoiceFlt2Hex=0, iFlt2HexEndian=0; // F2H_LITTLE_ENDIAN
#endif
#if (RICHED_COLOR) || (TEXT_FIND_MARK) // 2016.09.23
int iColorText = 0; // 0:black, 1:Red, 2:Magenta, 3:Blue, 4:Green, 5:Yellow
int txtColorRed=0, txtColorMegenta=0, txtColorBlue=0, txtColorGreen=0, txtColorYellow=0;
int txtFindRed=0, txtFindMegenta=0, txtFindBlue=0, txtFindGreen=0, txtFindYellow=0;
#endif
#if (TEXT_FIND_MARK) // 2016.09.23
int isTxtMark=0;
#endif
#if USE_HEX2BIN_CONVERT // 2016.03.04
int userHexType=0, userHex2BinLogOnOff=0;
int userCRCtype=2; // CRC8
int userEndian=0; // little
int userHexAddrZeroForced=0; // default : read hex address
int userCRCverify=1; // ON
int userSizeUnit=0; // Unit : KByte or Byte
int userSwapWordwise=0; // Off
int userAddrAlignWord=0;
int userPadByteOnOff=1; // 2018.07.13
#endif
#if defined(COLOR_DISP2) /// 2010.05.14
int ColorType=0; // 0:Default(Gray), 1:Black, Gray1:2, Gray2:3
#endif
#ifdef ENGINEER_MODE /// 개발자용은 필요없음.
int RetryUSB = 0; /// defauilt
#else
int RetryUSB = 1; /// 20 times
#endif
#if COM_SETTINGS /// 2012.07.11
int userCOMparity=0, userCOMstop=0, userCOMdataIdx=1;
int userFlowControl=0; // 2017.08.03 None FlowControl
int userFlowCtrlVal=0; // 2017.08.04 None FlowControl
int userHexaDispVal=0; // 2018.03.22 None Hexa Display
#define LEN_COMPARITY 6
#define LEN_COMSTOP 4
#define LEN_COMDATABIT 2
const TCHAR* szCOMParity[LEN_COMPARITY] = {
TEXT("N"), // NOPARITY
TEXT("O"), // ODDPARITY
TEXT("E"), // EVENPARITY
TEXT("M"), // MARKPARITY
TEXT("S"), // SPACEPARITY
TEXT("*"), // unknown
};
const TCHAR* szCOMStop[LEN_COMSTOP] = {
TEXT("1S"), // ONESTOPBIT
TEXT("1.5S"), // ONE5STOPBITS
TEXT("2S"), // TWOSTOPBITS
TEXT("*S") // Unknown
};
const int COMportDatabit[LEN_COMDATABIT] = {
7, /// index 0 : 7bit
8 /// index 1 : 8bit
};
#endif
#if USER_SCREEN_BUF_SIZE // 2016.02.14
// 0: Huge(100MB), 1:Latge, 2:Middle, 3:Small(2MB), 4:Smallest(1MB)
int userScrBufSizIndex=0; // huge
#endif
#if 1 /// 2015.0516 ---
#define MAX_IN_BLOCK_SIZE (4*1024) // 2020.09.10 /// 2015.05.16 ---
#define MAX_OU_BLOCK_SIZE (4*1024) // 2020.09.10
#else
#define MAX_BLOCK_SIZE (4096)
#endif
#define RX_BUF_SIZE (MAX_IN_BLOCK_SIZE+20)
HANDLE idComDev = NULL;
OVERLAPPED osWrite, osRead;
volatile int isConnected=0; // 0:Disconnect, 1:Connected, 2:Try to connect
TCHAR rxBuf[RX_BUF_SIZE] = {0,};
volatile char *SerialTxBuf = NULL;
volatile DWORD idxTxBuf = 0;
DWORD TxBufSize;
volatile BOOL txEmpty=TRUE; /* int -> BOOL */
extern TCHAR szDownloadAddress[ADDR_LENGTH];
extern TCHAR szColumnNumber[16];
extern TCHAR szSerialTxCharData[TX_DATA_LENGTH]; // 2016.03.23
extern TCHAR szSerialTxHexaData[TX_DATA_LENGTH]; // 2016.03.23
extern TCHAR szSerialTxFileData[TX_DATA_LENGTH]; // 2016.03.28
extern TCHAR szSerialTxFileTitl[TX_DATA_LENGTH]; // 2016.03.28
extern TCHAR szFileNameOnPopUP[FILENAMELEN];
extern void BeepSound(int beeptype);
#if USE_WIN_OUTOF_AREA_TO_ZERO // 2016.03.31 LCD size
extern DWORD myLCDwidth, myLCDheight;
extern DWORD WIN_XBgn, WIN_YBgn;
extern DWORD MainWidth, MainHeight;
extern DWORD WIN_XSIZE, WIN_YSIZE;
extern DWORD myVirWidth, myVirHeight; // 2017.04.20 VirtualLCD size
#endif
#if HEXA_MODE_SUPPORT /* 2011.02.08 Hexa mode display */
extern DWORD ColumnNumber;
#endif
extern HWND _EditHwnd, _MainHwnd;
extern WORD DownloadedBin;
extern int BinFileIndex;
extern char *os_name(void);
extern TCHAR *GetProcessorName();
//extern TCHAR *GetIPaddress(void);
// get memory info...
extern int getTotalRAM(void);
extern int getAvailRAM(void);
extern int getTotalMemory(void);
extern int getAvailMemory(void);
extern __int64 XfGetTime(void);
extern int ProcessorType(void);
extern void GetComPortRegistry(void);
#if DISPLAY_MAX_EDIT_BUF_SIZE // 2016.02.12
extern unsigned int iEditCount, iLineDeleted;
#endif
void GMTTime2LocalTime(SYSTEMTIME gmtTime, SYSTEMTIME *local)
{
// Converting UTCTime to LocalTime.
FILETIME FileTime, LocalFileTime;
SYSTEMTIME LocalTime;
SystemTimeToFileTime(&gmtTime, &FileTime);
FileTimeToLocalFileTime(&FileTime, &LocalFileTime); // to Local Time
FileTimeToSystemTime(&LocalFileTime, &LocalTime);
memcpy( (void*)local, &LocalTime, sizeof(SYSTEMTIME) );
}
void LocalTime2GMTTime(SYSTEMTIME locTime, SYSTEMTIME *gmt)
{
FILETIME FileTime, GMTFileTime;
SYSTEMTIME LocalTime;
SystemTimeToFileTime(&locTime, &FileTime);
LocalFileTimeToFileTime(&FileTime, &GMTFileTime); // to GMT Time
FileTimeToSystemTime(&GMTFileTime, &LocalTime);
memcpy( (void*)gmt, &LocalTime, sizeof(SYSTEMTIME) );
}
int SearchProcess()
{
DWORD dwSize = 250;
HANDLE hSnapShot=NULL;
PROCESSENTRY32 pEntry;
BOOL bCrrent=FALSE, hRes=FALSE;
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL,NULL);
if( hSnapShot )
{
pEntry.dwSize = sizeof(pEntry);
if( Process32First (hSnapShot,&pEntry) )
{
do {
EB_Printf(TEXT("[dnw] Run -----: [%s] [%d] [0x%x, 0x%x, 0x%x, 0x%x] \r\n"),
pEntry.szExeFile, pEntry.cntUsage,
pEntry.th32ProcessID, pEntry.th32ModuleID, pEntry.cntThreads, pEntry.th32ParentProcessID );
if(!strncmp(pEntry.szExeFile,"EXC1212EL.EXE",15))
{
bCrrent = TRUE;
}
if(bCrrent)
{
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pEntry.th32ProcessID);
bCrrent = FALSE;
if(hProcess)
{
if(TerminateProcess(hProcess, 0))
{
unsigned long nCode; //프로세스 종료 상태
GetExitCodeProcess(hProcess, &nCode);
EB_Printf(TEXT("[dnw] Kill -----: [%s] [%d] \r\n"), pEntry.szExeFile, pEntry.cntUsage );
}
CloseHandle(hProcess);
}
//break;
}
} while( hRes = Process32Next (hSnapShot,&pEntry) );
}
CloseHandle(hSnapShot);
}
return 0;
}
extern TCHAR Cpu_info[MAX_PATH];
extern TCHAR Cpu_ID[MAX_PATH];
extern TCHAR ProductName[MAX_PATH];
extern TCHAR Manufacture[MAX_PATH];
extern TCHAR BIOSRelease[MAX_PATH]; // 2020.03.27,
extern TCHAR BIOSVersion[MAX_PATH];
extern TCHAR BIOSVendor_[MAX_PATH];
extern TCHAR SWProductName[MAX_PATH];
extern TCHAR SWEditionID[MAX_PATH];
extern TCHAR SWReleaseId[MAX_PATH];
extern TCHAR SWCurrentBuildNumber[MAX_PATH];
extern unsigned __int64 SWInstallDate;
//extern unsigned __int64 SWInstallTime;
#if CIPHER_RSA2048 // 2018.02.20
//#include <Windows.h>
//#include <stdio.h>
#include ".\RSA2048\common.h"
#include ".\RSA2048\rsa2048.h"
//int main(void)
int RSA2048(void)
{
HCRYPTPROV hCryptProv = 0; // CSP handle
HCRYPTKEY key = 0; // Signature key pair handle
unsigned long cLen = 0;
char *cipherText = NULL;
char *plainText = "PLAIN_TEXT_PLAIN_TEXT\0";
//char *plainText = "ABC\0";
unsigned char *decrypted = NULL;
unsigned char *publicKey = NULL;
unsigned char *privateKey = NULL;
if (!CryptoInit(&key, &hCryptProv, &publicKey, &privateKey))
{
//printf("Crypto initializing failed\n");
EB_Printf(TEXT("[dnw] Crypto initializing failed\n") );
return EXIT_FAILURE;
}
EB_Printf(TEXT("[dnw] RSA2048 key : [%I64u] %I64x \n"), key, key);
//EB_Printf(TEXT("[dnw] publicKey : [%s] \n"), publicKey );
//EB_Printf(TEXT("[dnw] privateKey : [%s] \n"), privateKey );
EB_Printf(TEXT("[dnw] Original plain text: [%s] \n"), plainText );
if (!Encrypt(key, &cipherText, &cLen, (unsigned char *)plainText, strlen(plainText)))
{
//printf("Encryption failed\n");
EB_Printf(TEXT("[dnw] Encryption failed\n") );
if (hCryptProv) CryptReleaseContext(hCryptProv, 0);
return EXIT_FAILURE;
}
//printf("Encrypted string: %s\n", cipherText);
EB_Printf(TEXT("[dnw] Encrypted string : ]%s[ \n"), cipherText );
if (!Decrypt(key, &decrypted, cipherText, cLen))
{
//printf("Decryption failed\n");
EB_Printf(TEXT("[dnw] Decryption failed \n") );
SAFE_FREE(cipherText);
if (hCryptProv) CryptReleaseContext(hCryptProv, 0);
return EXIT_FAILURE;
}
SAFE_FREE(cipherText);
//printf("Decrypted string: %s\n", decrypted);
EB_Printf(TEXT("[dnw] Decrypted string : [%s] \n"), decrypted );
SAFE_FREE(decrypted);
CryptoUninit(key, hCryptProv);
SAFE_FREE(publicKey);
SAFE_FREE(privateKey);
return EXIT_SUCCESS;
}
#endif // CIPHER_RSA2048
#if 0
#define SQR1(x) ((x)*(x))
#define SQR2(x) (x*x)
int MISRA_test(void)
{
int a=0, b=3;
int bCheck = 1;
int i, j;
char szSrc[10] = "abcd";
char szDes[10] = "ABCD";
if( bCheck && ++a )
{
EB_Printf(TEXT("in if ++++++++++++ a(%d)\r\n"), a);
}
EB_Printf(TEXT(" outsider ... a(%d) \r\n"), a);
EB_Printf(TEXT("===SQR=== %d %d \r\n"), SQR1(a+b), SQR2(a+b) );
j = strcmp( szSrc, szDes );
if( !j ) EB_Printf(TEXT("------------ \r\n"));
EB_Printf(TEXT("strcmp == %d %d \r\n"), j, !j);
j = strcmp( szDes, szSrc );
if( !j ) EB_Printf(TEXT("------------ \r\n"));
EB_Printf(TEXT("strcmp == %d %d \r\n"), j, !j);
j = -21;
EB_Printf(TEXT("-----00------- (%d %d) \r\n"), j, !j);
j = 0x16;
EB_Printf(TEXT("-----00------- (%d %d) \r\n"), j, !j);
return 0;
}
#endif
#if 0
static const char *GetExceptionString(DWORD exception)
{
#define EXCEPTION(x) case EXCEPTION_##x: return (#x);
static char buf[16];
switch (exception)
{
EXCEPTION(ACCESS_VIOLATION)
EXCEPTION(DATATYPE_MISALIGNMENT)
EXCEPTION(BREAKPOINT)
EXCEPTION(SINGLE_STEP)
EXCEPTION(ARRAY_BOUNDS_EXCEEDED)
EXCEPTION(FLT_DENORMAL_OPERAND)
EXCEPTION(FLT_DIVIDE_BY_ZERO)
EXCEPTION(FLT_INEXACT_RESULT)
EXCEPTION(FLT_INVALID_OPERATION)
EXCEPTION(FLT_OVERFLOW)
EXCEPTION(FLT_STACK_CHECK)
EXCEPTION(FLT_UNDERFLOW)
EXCEPTION(INT_DIVIDE_BY_ZERO)
EXCEPTION(INT_OVERFLOW)
EXCEPTION(PRIV_INSTRUCTION)
EXCEPTION(IN_PAGE_ERROR)
EXCEPTION(ILLEGAL_INSTRUCTION)
EXCEPTION(NONCONTINUABLE_EXCEPTION)
EXCEPTION(STACK_OVERFLOW)
EXCEPTION(INVALID_DISPOSITION)
EXCEPTION(GUARD_PAGE)
EXCEPTION(INVALID_HANDLE)
default:
_snprintf_s(buf, sizeof(buf), _TRUNCATE, "0x%x", exception);
return buf;
//return "UNKNOWN_ERROR";
}
#undef EXCEPTION
}
#endif
/* --------------------------------------------------------------
%% % 자체를 표시한다.
%a 요일이름을 표시한다. (일..토)
%A 완전한요일이름을 표시한다. (일요일..토요일)
%b 월이름을 표시한다. (1월..12월)
%B 완전한월 이름을 표시한다. (1월..12월)
%c 날짜와 시간을 표시한다. (2007년 11월 14일 (수) 오전 12시 50분 16초)
%C 세기를 나타낸다. (년을 100으로 나눈 몫)
%d 월일 (01..31)
%D 월일 (mm/dd/yy)
%e 월일 (1..31)
%F %Y-%m-%d 와 같다.
%g 년도로 마지막 두자리만 표시
%G 년도로 모든자리 표시
%h %b 와 같다.
%H 시간 (00..23)
%I 시간 (01..12)
%j 년일(001..366)
%k 시간 (0..23)
%l 시간 (1..12)
%m 월 (01..12)
%M 분 (00..59)
%n 개행문자
%N 나노초 (000000000..999999999)
%P 오전 오후
%p 오전 오후
%r 시간 (오전/오후 hh시 mm분 ss초)
%R 시간 (hh시 mm분)
%s UTC 기준 1970-01-01 부터 지금까지 흐른 초
%t 탭문자
%T 24시간 (hh:mm:ss)
%u 주중 요일 (1..7), 1이 월요일이다
%U 1년중 몇번째 주인지, 일요일 기준 (00..53)
%V 1년중 몇번째 주인지, 월요일 기준 (00..53)
%w 주중 요일 (0..6), 0은 일요일
%x mm/dd/yy
%X %H:%M:%S 와 동일
%Y 년도 (1970..)
------------------------------------------------------ */
extern UINT str2hex(TCHAR *str);
extern ULONG hex2dec(TCHAR *str);
/* ------------------------------------------------------
01 : Linux_Year = 1970 -> fSUM = 31536000 -> Acc = 31536000UL
02 : Linux_Year = 1971 -> fSUM = 31536000 -> Acc = 63072000UL
03 : Linux_Year = 1972 -> fSUM = 31622400 -> Acc = 94694400UL <- YOON
04 : Linux_Year = 1973 -> fSUM = 31536000 -> Acc = 126230400UL
05 : Linux_Year = 1974 -> fSUM = 31536000 -> Acc = 157766400UL
06 : Linux_Year = 1975 -> fSUM = 31536000 -> Acc = 189302400UL
07 : Linux_Year = 1976 -> fSUM = 31622400 -> Acc = 220924800UL <- YOON
08 : Linux_Year = 1977 -> fSUM = 31536000 -> Acc = 252460800UL
09 : Linux_Year = 1978 -> fSUM = 31536000 -> Acc = 283996800UL
10 : Linux_Year = 1979 -> fSUM = 31536000 -> Acc = 315532800UL
11 : Linux_Year = 1980 -> fSUM = 31622400 -> Acc = 347155200UL <- YOON
12 : Linux_Year = 1981 -> fSUM = 31536000 -> Acc = 378691200UL
13 : Linux_Year = 1982 -> fSUM = 31536000 -> Acc = 410227200UL
14 : Linux_Year = 1983 -> fSUM = 31536000 -> Acc = 441763200UL
15 : Linux_Year = 1984 -> fSUM = 31622400 -> Acc = 473385600UL <- YOON
16 : Linux_Year = 1985 -> fSUM = 31536000 -> Acc = 504921600UL
17 : Linux_Year = 1986 -> fSUM = 31536000 -> Acc = 536457600UL
18 : Linux_Year = 1987 -> fSUM = 31536000 -> Acc = 567993600UL
19 : Linux_Year = 1988 -> fSUM = 31622400 -> Acc = 599616000UL <- YOON
20 : Linux_Year = 1989 -> fSUM = 31536000 -> Acc = 631152000UL
21 : Linux_Year = 1990 -> fSUM = 31536000 -> Acc = 662688000UL
22 : Linux_Year = 1991 -> fSUM = 31536000 -> Acc = 694224000UL
23 : Linux_Year = 1992 -> fSUM = 31622400 -> Acc = 725846400UL <- YOON
24 : Linux_Year = 1993 -> fSUM = 31536000 -> Acc = 757382400UL
25 : Linux_Year = 1994 -> fSUM = 31536000 -> Acc = 788918400UL
26 : Linux_Year = 1995 -> fSUM = 31536000 -> Acc = 820454400UL
27 : Linux_Year = 1996 -> fSUM = 31622400 -> Acc = 852076800UL <- YOON
28 : Linux_Year = 1997 -> fSUM = 31536000 -> Acc = 883612800UL
29 : Linux_Year = 1998 -> fSUM = 31536000 -> Acc = 915148800UL
30 : Linux_Year = 1999 -> fSUM = 31536000 -> Acc = 946684800UL
31 : Linux_Year = 2000 -> fSUM = 31622400 -> Acc = 978307200UL <- YOON
32 : Linux_Year = 2001 -> fSUM = 31536000 -> Acc = 1009843200UL
33 : Linux_Year = 2002 -> fSUM = 31536000 -> Acc = 1041379200UL
34 : Linux_Year = 2003 -> fSUM = 31536000 -> Acc = 1072915200UL
35 : Linux_Year = 2004 -> fSUM = 31622400 -> Acc = 1104537600UL <- YOON
36 : Linux_Year = 2005 -> fSUM = 31536000 -> Acc = 1136073600UL
37 : Linux_Year = 2006 -> fSUM = 31536000 -> Acc = 1167609600UL
38 : Linux_Year = 2007 -> fSUM = 31536000 -> Acc = 1199145600UL
39 : Linux_Year = 2008 -> fSUM = 31622400 -> Acc = 1230768000UL <- YOON
40 : Linux_Year = 2009 -> fSUM = 31536000 -> Acc = 1262304000UL
41 : Linux_Year = 2010 -> fSUM = 31536000 -> Acc = 1293840000UL
42 : Linux_Year = 2011 -> fSUM = 31536000 -> Acc = 1325376000UL
43 : Linux_Year = 2012 -> fSUM = 31622400 -> Acc = 1356998400UL <- YOON
44 : Linux_Year = 2013 -> fSUM = 31536000 -> Acc = 1388534400UL
45 : Linux_Year = 2014 -> fSUM = 31536000 -> Acc = 1420070400UL
46 : Linux_Year = 2015 -> fSUM = 31536000 -> Acc = 1451606400UL
47 : Linux_Year = 2016 -> fSUM = 31622400 -> Acc = 1483228800UL <- YOON
48 : Linux_Year = 2017 -> fSUM = 31536000 -> Acc = 1514764800UL
49 : Linux_Year = 2018 -> fSUM = 31536000 -> Acc = 1546300800UL
50 : Linux_Year = 2019 -> fSUM = 31536000 -> Acc = 1577836800UL
51 : Linux_Year = 2020 -> fSUM = 31622400 -> Acc = 1609459200UL <- YOON
52 : Linux_Year = 2021 -> fSUM = 31536000 -> Acc = 1640995200UL
53 : Linux_Year = 2022 -> fSUM = 31536000 -> Acc = 1672531200UL
54 : Linux_Year = 2023 -> fSUM = 31536000 -> Acc = 1704067200UL
55 : Linux_Year = 2024 -> fSUM = 31622400 -> Acc = 1735689600UL <- YOON
56 : Linux_Year = 2025 -> fSUM = 31536000 -> Acc = 1767225600UL
57 : Linux_Year = 2026 -> fSUM = 31536000 -> Acc = 1798761600UL
58 : Linux_Year = 2027 -> fSUM = 31536000 -> Acc = 1830297600UL
59 : Linux_Year = 2028 -> fSUM = 31622400 -> Acc = 1861920000UL <- YOON
60 : Linux_Year = 2029 -> fSUM = 31536000 -> Acc = 1893456000UL
61 : Linux_Year = 2030 -> fSUM = 31536000 -> Acc = 1924992000UL
----------------------------------------------------------- */
#define YOON_YEAR (60*60*24*366) /* aDay[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; */
#define NORM_YEAR (60*60*24*365) /* aDay[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; */
#define LINUX_START_YEAR 1970 /* reference year 1970.1.1 0:0:0 */
#define LINUX_ACC_COUNT_UNTIL_2018 1546300800UL /* = 1970 + 1971 + ... 2018 */
int isYearOnce=1;
int isMonthOnce=1;
static unsigned int Linux_Year = 2019; // LINUX_START_YEAR;
static unsigned __int64 LinuxCnt = LINUX_ACC_COUNT_UNTIL_2018; /* = 1970 + 1971 + ... 2018 */
static unsigned int Linux_Month = 0;
static unsigned __int64 dwYear=0UL, dwMonth=0UL, dwDay=0UL;
enum {
YEAR_ERROR = 0,
YEAR_NORMAL = 1,
YEAR_YOON = 2,
};
int isYOONyear(unsigned int year)
{
int isYOON = 0; // 0:Abnormal, 1:Normal year, 2:YOON year
unsigned __int64 linuxAcc = 0UL;
unsigned __int64 oneYearCnt = 0UL;
// ++++++++++++++++++++++++++++++++++++++++
if( (year)%400 == 0 ) { isYOON=YEAR_YOON; linuxAcc += YOON_YEAR; oneYearCnt = YOON_YEAR; }
else if( (year)%4 == 0 )
{
if( (year)%100 == 0 ) { isYOON=YEAR_NORMAL; linuxAcc += NORM_YEAR; oneYearCnt = NORM_YEAR; }
else { isYOON=YEAR_YOON; linuxAcc += YOON_YEAR; oneYearCnt = YOON_YEAR; }
}
else { isYOON=YEAR_NORMAL; linuxAcc += NORM_YEAR; oneYearCnt = NORM_YEAR; }
// ----------------------------------------------
return isYOON;
}
unsigned __int64 LinuxDate2Number( mjd_timestamp LTime )
{
/* 1 2 3 4 5 6 7 8 9 10 11 12 */
const unsigned short yDay[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
const unsigned short aDay[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
unsigned int dwHour=0, dwMin=0, dwSec=0;
int ii=0;
unsigned int iCheck = 0;
unsigned int fSUM = 0;
/* ---------------------------------------------------
2. 년도 계산 (평년과 윤년 확인하여야 한다)
15026/365 = 41
기준일이 1970년 1월 1일 00:00:00 로 (UNIX 또는 Linux)
1970 + 41 = 2011년을 위미
3. 일자계산
15026 - (41*365) = 61일
날짜를 계산하면
1월이 31일, 2월이 28일로
61일째 날은 3월 2일임을 계산할 수 있음
즉 변경일은 2011년 3월 2일임.
1593565932 -> 2020-7-1 10:12:12
------------------------------------------------------ */
// ++ Year ++++++++++++++++++++++++++++++++++++++
//LinuxCnt = 1546300800UL; /* = 1970 + 1971 + ... 2018 */
//Linux_Year = 2019;
if( !dwYear || (LTime.m_year != Linux_Year) ) isYearOnce=1;
if( isYearOnce )
{
isYearOnce = 0;
do {
iCheck = 0;
// ++++++++++++++++++++++++++++++++++++++++
if( (Linux_Year)%400 == 0 ) { LinuxCnt += YOON_YEAR; fSUM = YOON_YEAR; iCheck = 2; }
else if( (Linux_Year)%4 == 0 )
{
if( (Linux_Year)%100 == 0 ) { LinuxCnt += NORM_YEAR; fSUM = NORM_YEAR; iCheck = 1; }
else { LinuxCnt += YOON_YEAR; fSUM = YOON_YEAR; iCheck = 2; }
}
else { LinuxCnt += NORM_YEAR; fSUM = NORM_YEAR; iCheck = 1; }
// ----------------------------------------
dwYear++;
Linux_Year++;
} while( Linux_Year < LTime.m_year );
//EB_Printf(TEXT("[dnw] %u %u\r\n"), LTime.m_year , Linux_Year);
dwYear = LinuxCnt;
//EB_Printf(TEXT("[dnw] %04d/%02d/%02d %02d:%02d:%02d \r\n"), LTime.m_year, LTime.m_month, LTime.m_day, LTime.m_hour, LTime.m_mins, LTime.m_secs);
//EB_Printf(TEXT("[dnw] %I64u \r\n"), dwYear);
//EB_Printf(TEXT("[dnw] %lu \r\n"), dwYear);
}
// ++ Month ++++++++++++++++++++++++++++++++++++++
if( !dwMonth || (Linux_Month != LTime.m_month) ) isMonthOnce=1;
if( isMonthOnce )
{
Linux_Month = LTime.m_month;
dwMonth = 0UL;
isMonthOnce = 0;
#if 0
if( (LTime.m_year)%400 == 0 ) { iCheck = 2; } // YOON_YEAR
else if( (LTime.m_year)%4 == 0 )
{
if( (LTime.m_year)%100 == 0 ) { iCheck = 1; } // NORMAL_YEAR
else { iCheck = 2; } // YOON_YEAR
}
else { iCheck = 1; } // NORMAL_YEAR
#else
iCheck = isYOONyear(LTime.m_year);
#endif
if( YEAR_YOON==iCheck ) // YOON_DAL
{
for(ii=0; ii<LTime.m_month-1; ii++)
dwMonth += yDay[ii]*24*60*60;
}
else if( YEAR_NORMAL==iCheck ) // NORMAL_DAL
{
for(ii=0; ii<LTime.m_month-1; ii++)
dwMonth += aDay[ii]*24*60*60;
}
else
{
//EB_Printf(TEXT("[dnw] LINUX Time -> Min ERROR iCheck=(%d) \r\n"), iCheck );
// Error
}
}
//EB_Printf(TEXT("[dnw] dwMonth %ul \r\n"), dwMonth );
// ++ Day ++++++++++++++++++++++++++++++++++++++++
dwDay = (LTime.m_day)*24*60*60;
// ++ Hour ++++++++++++++++++++++++++++++++++++++++
dwHour = (LTime.m_hour)*60*60;
// ++ Minute ++++++++++++++++++++++++++++++++++++++
dwMin = (LTime.m_mins)*60;
// ++ Second ++++++++++++++++++++++++++++++++++++++
dwSec = LTime.m_secs;
// ++++++++++ SUM +++++++++++++++++++++++++++++++++
LinuxCnt = dwYear + dwMonth + dwDay + dwHour + dwMin + dwSec;
LinuxCnt -= (24*60*60); // -1Day because of Reference
LinuxCnt -= (9*60*60); // -9Hour because of Korean TimeZone
//EB_Printf(TEXT("[dnw] LinuxCnt = %lld \r\n"), LinuxCnt );
return LinuxCnt;
}
void LinuxCount2Date(unsigned __int64 linuxCount, unsigned int *year, unsigned int *month, unsigned int *day, unsigned int *hour, unsigned int *min, unsigned int *sec)
{
/* 1 2 3 4 5 6 7 8 9 10 11 12 */
const unsigned short yDay[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // YOON-year
const unsigned short aDay[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // Normal year
unsigned int dwyear=0, dwmonth=0, dwday=0;
unsigned int dwhour=0, dwmin=0, dwsec=0;
unsigned int accDay=0;
unsigned int iMonCnt = 0;
unsigned int Linux_Year = LINUX_START_YEAR;
unsigned __int64 linuxCnt = 0UL;
unsigned int iCheck = 0;