-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_test.cpp
1676 lines (1523 loc) · 53.3 KB
/
run_test.cpp
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
/*-----------------------------------------------------------------------------
Run Susie plug-in Copyright (c) TORO
----------------------------------------------------------------------------*/
#include <windows.h>
#include "torowin.h"
#include "susie.h"
#include "run.h"
int CommentCount = 0;
BOOL CallbackError = FALSE;
BOOL type_extract = FALSE;
char *SourceImage = NULL, *CompareSourceImage = NULL;
DWORD SourceSize, SourceAllocSize;
int testmem = -1;
int testdisk = -1;
// 展開プラグイン用
BOOL type_extract_mem = FALSE;
HLOCAL ArchiveInfo = NULL;
HLOCAL ArchiveInfoW = NULL;
SUSIE_FINFO *finfo_file = NULL, *finfo_mem = NULL;
SUSIE_FINFOW *finfo_fileW = NULL, *finfo_memW = NULL;
UINT infosize_file, infosize_mem;
#define MAX_TEST_ON_MEMORY (50 * 1024 * 1024) // ソースがメモリの時の最大可能値
#define PrintAPIname(name) printoutfColor(COLOR_APINAME, L"\r\n" UNICODESTR(name) L"\r\n")
void ShowComment(const WCHAR *message, ...)
{
WCHAR buf[0x800];
va_list argptr;
SetColor(COLOR_COMMENT);
va_start(argptr, message);
wvsprintfW(buf, message, argptr);
printout(buf);
ResetColor();
CommentCount++;
}
const WCHAR *errortext[] = {
L"Not Support",
L"no error",
L"User cancel",
L"Unknown format",
L"Broken DATA",
L"Empty memory",
L"Fault memory",
L"Fault read",
L"Window error",
L"Internal",
L"File write",
L"End of file"
};
void PluginResult(int result)
{
const WCHAR *text;
if ( (result >= SUSIEERROR_NOTSUPPORT) && (result <= SUSIEERROR_EOF) ){
text = errortext[result - SUSIEERROR_NOTSUPPORT];
}else if ( result == -101 ){
text = errortext[0];
}else if ( (result >= 101) && (result <= 110) ){
text = errortext[result - 99];
}else{
text = L" ● 未定義コード";
CommentCount++;
}
printoutf(L" return code: %d (%s)\r\n", result, text);
}
void LoadSourceImage(void)
{
HANDLE hFile;
if ( testmem == testmem_zerosize ){
SourceSize = 0;
SourceAllocSize = 0;
SourceImage = (char *)malloc(0);
CompareSourceImage = (char *)malloc(0);
strcpy(sourcenameA, "NUL");
strcpyW(sourcename, L"NUL");
return;
}
if ( sourcename[0] == '\0' ){
testmem = 0;
return;
}
hFile = CreateFileW(sourcename, GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if ( hFile != INVALID_HANDLE_VALUE ){
LARGE_INTEGER filesize;
DWORD size;
GetFileSizeEx(hFile, &filesize);
SourceSize = filesize.u.LowPart;
SourceAllocSize = filesize.u.LowPart + 256;
if ( testmem < 0 ){
testmem = filesize.QuadPart <= MAX_TEST_ON_MEMORY;
}
if ( testmem ){
SourceImage = (char *)malloc(SourceAllocSize);
CompareSourceImage = (char *)malloc(SourceAllocSize);
memset(SourceImage, WRITECHECK_BYTE, SourceAllocSize);
ReadFile(hFile, SourceImage, filesize.u.LowPart, &size, NULL);
memcpy(CompareSourceImage, SourceImage, SourceAllocSize);
}else{
printout(L"*ソースファイルが大きいためチェックできない\r\n");
}
CloseHandle(hFile);
}else{
printoutf(L"%s open error.\r\n", sourcename);
testmem = 0;
}
}
int __stdcall SusieProgressCallbackCheck(int nNum, int nDenom, LONG_PTR lData)
{
if ( CallbackError == FALSE ){
if ( lData != (LONG_PTR)sourcenameA ){
#ifdef _WIN64
if ( lData == (DWORD)(DWORD_PTR)sourcenameA ){
ShowComment(L" ● SUSIE_PROGRESS の lData が LONG_PTR でなく、long のため、上位 32bit が渡されていない((lData(%p) != %p)、今後のチェックをスキップ\r\n", lData, sourcename);
}else
#endif
ShowComment(L" ● SUSIE_PROGRESS(nNum = %d, nDenom = %d, lData = %p) 異常(!= %p)、今後のチェックをスキップ\r\n", nNum, nDenom, lData, sourcenameA);
CallbackError = TRUE;
}
}
return 0;
}
const WCHAR *Compressions[] = {
L"BI_RGB", L"BI_RLE8", L"BI_RLE4", L"BI_BITFIELDS",
L"BI_JPEG", L"BI_PNG", L"BI_ALPHABITFIELDS"
};
#ifndef BI_ALPHABITFIELDS
#define BI_ALPHABITFIELDS 6
#endif
typedef struct {
DWORD bV5Size;
LONG bV5Width;
LONG bV5Height;
WORD bV5Planes;
WORD bV5BitCount;
DWORD bV5Compression;
DWORD bV5SizeImage;
LONG bV5XPelsPerMeter;
LONG bV5YPelsPerMeter;
DWORD bV5ClrUsed;
DWORD bV5ClrImportant;
DWORD bV5RedMask;
DWORD bV5GreenMask;
DWORD bV5BlueMask;
DWORD bV5AlphaMask;
DWORD bV5CSType;
CIEXYZTRIPLE bV5Endpoints;
DWORD bV5GammaRed;
DWORD bV5GammaGreen;
DWORD bV5GammaBlue;
DWORD bV5Intent;
DWORD bV5ProfileData;
DWORD bV5ProfileSize;
DWORD bV5Reserved;
} BITMAPV5HEADER;
void ShowPictureInfo(HLOCAL HBInfo, HLOCAL HBm)
{
BITMAPV5HEADER *bmpinfo;
DWORD size, bmpsize, linesize, calc_bmpsize;
if ( HBInfo == NULL ){
ShowComment(L" ● pHBInfo == NULL\r\n");
}
if ( HBm == NULL ){
ShowComment(L" ● pHBm == NULL\r\n");
}
bmpinfo = (BITMAPV5HEADER *)LocalLock(HBInfo);
size = LocalSize(HBInfo);
bmpsize = LocalSize(HBm);
if ( size < 40 ){
ShowComment(L" ● HBInfo の大きさが小さい %d < 40\r\n", size );
}else{
const WCHAR *wptr;
if ( bmpinfo->bV5Size == 40 ){
printout(L" BITMAPINFO\r\n");
}else if ( bmpinfo->bV5Size == sizeof(BITMAPV5HEADER) ){
printout(L" BITMAPV5HEADER\r\n");
}else if ( bmpinfo->bV5Size < sizeof(BITMAPINFO) ){
ShowComment(L" ● BITMAPINFO biSize が小さい %d < 40\r\n", bmpinfo->bV5Size );
}else if ( bmpinfo->bV5Size < sizeof(BITMAPINFO) ){
ShowComment(L" ● BITMAPINFO biSize 不明サイズ %d != %d\r\n", bmpinfo->bV5Size, sizeof(BITMAPINFO) );
}
printoutf(L" biWidth: %d pix biHeight: %d pix\r\n", bmpinfo->bV5Width, bmpinfo->bV5Height );
if ( (bmpinfo->bV5Width <= 0) || (bmpinfo->bV5Width >= 0x20000) ){
ShowComment(L" ● biWidth が異常値\r\n");
}
if ( (bmpinfo->bV5Height < 0) ){
ShowComment(L" ● トップダウンDIB\r\n");
}
if ( (bmpinfo->bV5Height <= -0x20000) || (bmpinfo->bV5Height >= 0x20000) ){
ShowComment(L" ● biHeight が異常値\r\n");
}
if ( bmpinfo->bV5Planes != 1 ){
ShowComment(L" ● biPlanes が 1 以外(%d)\r\n", bmpinfo->bV5Planes);
}
printoutf(L" biBitCount: %d bit (%d colors)\r\n", bmpinfo->bV5BitCount, 1 << bmpinfo->bV5BitCount );
if ( !( (bmpinfo->bV5BitCount <= 1) || (bmpinfo->bV5BitCount == 4) ||
(bmpinfo->bV5BitCount == 8) || (bmpinfo->bV5BitCount == 16) ||
(bmpinfo->bV5BitCount == 24) || (bmpinfo->bV5BitCount == 32))){
ShowComment(L" ● biBitCount が異常値\r\n");
}
if ( (bmpinfo->bV5BitCount == 16) || (bmpinfo->bV5BitCount == 32) ){
ShowComment(L" ● %d bit 色は対応していないアプリケーションあり\r\n", bmpinfo->bV5BitCount);
}
if ( bmpinfo->bV5Compression > BI_ALPHABITFIELDS ){
wptr = L"?";
}else{
wptr = Compressions[bmpinfo->bV5Compression];
}
printoutf(L" biCompression: %d (%s)\r\n", bmpinfo->bV5Compression, wptr);
if ( bmpinfo->bV5Compression != BI_RGB ){
ShowComment(L" ● BI_RGB 以外は対応していないアプリケーションあり\r\n");
}
linesize = DwordBitSize(bmpinfo->bV5Width * bmpinfo->bV5BitCount);
calc_bmpsize = linesize * ((bmpinfo->bV5Height >= 0) ? bmpinfo->bV5Height : -bmpinfo->bV5Height);
printoutf(L" biSizeImage: %d bytes (HBm: %d bytes. calculated: %d bytes)\r\n", bmpinfo->bV5SizeImage, bmpsize, calc_bmpsize);
if ( ((bmpinfo->bV5Compression != BI_RGB) && (bmpinfo->bV5SizeImage == 0)) ||
(bmpinfo->bV5SizeImage > bmpsize) ){
ShowComment(L" ● biSizeImage が異常値\r\n");
}
if ( ((bmpinfo->bV5Compression == BI_RGB) || (bmpinfo->bV5Compression == BI_BITFIELDS)) ){
if ( (bmpinfo->bV5SizeImage != 0) && (bmpinfo->bV5SizeImage != calc_bmpsize) ){
ShowComment(L" ● biSizeImage が calculated と一致しない\r\n");
}
if ( bmpsize < calc_bmpsize ){
ShowComment(L" ● ビットマップが calculated より少ない\r\n");
}
}
printoutf(L" biXPelsPerMeter: %d (%d ppi) biYPelsPerMeter %d (%d ppi)\r\n",
bmpinfo->bV5XPelsPerMeter, bmpinfo->bV5XPelsPerMeter / 39,
bmpinfo->bV5YPelsPerMeter, bmpinfo->bV5YPelsPerMeter / 39);
if ( bmpinfo->bV5XPelsPerMeter != bmpinfo->bV5YPelsPerMeter ){
ShowComment(L" ● アスペクト比が 1 以外\r\n");
}
printoutf(L" biClrUsed: %d biClrImportant %d\r\n\r\n",
bmpinfo->bV5ClrUsed , bmpinfo->bV5ClrImportant);
if ( bmpinfo->bV5Compression == BI_BITFIELDS ){
printoutf(L" Bit mask R:%x G:%x B:%x Alpha:%x\r\n",
bmpinfo->bV5RedMask , bmpinfo->bV5GreenMask,
bmpinfo->bV5BlueMask, bmpinfo->bV5AlphaMask);
}
}
LocalUnlock(HBInfo);
LocalUnlock(HBm);
}
void TestGetPicture_check(HLOCAL HBInfo, HLOCAL HBm)
{
ShowPictureInfo(HBInfo, HBm);
LocalFree(HBInfo);
LocalFree(HBm);
}
void CheckInvaildFilename(int result)
{
PluginResult(result);
if ( result == SUSIEERROR_NOERROR ){
ShowComment(L" ● ソースファイルが無いのに正常終了\r\n");
}
}
void TestGetPictureMain(GETPICTURE TestApi)
{
int result;
char buf[MAX_PATH];
HLOCAL HBInfo, HBm;
if ( testdisk ){
printout(L"SOURCE_DISK(non-existence)");
strcpy(buf, "dummy_file_name");
HBInfo = HBm = INVALID_HANDLE_VALUE;
result = TestApi(buf, 0, SUSIE_SOURCE_DISK, &HBInfo, &HBm, (FARPROC)SusieProgressCallbackCheck, (LONG_PTR)sourcenameA);
CheckInvaildFilename(result);
printout(L"SOURCE_DISK");
strcpy(buf, sourcenameA);
HBInfo = HBm = INVALID_HANDLE_VALUE;
result = TestApi(buf, 0, SUSIE_SOURCE_DISK, &HBInfo, &HBm, (FARPROC)SusieProgressCallbackCheck, (LONG_PTR)sourcenameA);
PluginResult(result);
if ( strcmp(buf, sourcenameA) != 0 ){
ShowComment(L" ● filename 破損\r\n");
}
if ( result == SUSIEERROR_NOERROR ){
TestGetPicture_check(HBInfo, HBm);
}
}
if ( testmem ){
printout(L"SOURCE_MEM");
HBInfo = HBm = INVALID_HANDLE_VALUE;
result = TestApi(SourceImage, SourceSize, SUSIE_SOURCE_MEM, &HBInfo, &HBm, (FARPROC)SusieProgressCallbackCheck, (LONG_PTR)sourcenameA);
PluginResult(result);
if ( memcmp(SourceImage, CompareSourceImage, SourceAllocSize) != 0 ){
ShowComment(L" ● buf 破損\r\n");
}
if ( result == SUSIEERROR_NOERROR ){
TestGetPicture_check(HBInfo, HBm);
}
}
}
void TestGetPictureWMain(GETPICTUREW TestApiW)
{
int result;
WCHAR buf[MAX_PATH];
HLOCAL HBInfo, HBm;
printout(L"SOURCE_DISK(non-existence)");
strcpyW(buf, L"dummy_file_name");
HBInfo = HBm = INVALID_HANDLE_VALUE;
result = TestApiW(buf, 0, SUSIE_SOURCE_DISK, &HBInfo, &HBm, (FARPROC)SusieProgressCallbackCheck, (LONG_PTR)sourcenameA);
CheckInvaildFilename(result);
if ( testdisk ){
printout(L"SOURCE_DISK");
strcpyW(buf, sourcename);
HBInfo = HBm = INVALID_HANDLE_VALUE;
result = TestApiW(buf, 0, SUSIE_SOURCE_DISK, &HBInfo, &HBm, (FARPROC)SusieProgressCallbackCheck, (LONG_PTR)sourcenameA);
PluginResult(result);
if ( strcmpW(buf, sourcename) != 0 ){
ShowComment(L" ● filename が破損\r\n");
}
if ( result == SUSIEERROR_NOERROR ){
TestGetPicture_check(HBInfo, HBm);
}
}
if ( testmem ){
printout(L"SOURCE_MEM");
HBInfo = HBm = INVALID_HANDLE_VALUE;
result = TestApiW((WCHAR *)SourceImage, SourceSize, SUSIE_SOURCE_MEM, &HBInfo, &HBm, (FARPROC)SusieProgressCallbackCheck, (LONG_PTR)sourcenameA);
PluginResult(result);
if ( memcmp(SourceImage, CompareSourceImage, SourceAllocSize) != 0 ){
ShowComment(L" ● buf が破損\r\n");
}
if ( result == SUSIEERROR_NOERROR ){
TestGetPicture_check(HBInfo, HBm);
}
}
}
void TestGetPicture(void)
{
if ( GetPicture != NULL ){
PrintAPIname("GetPicture(LPCSTR buf, LONG_PTR len, unsigned int flag, HLOCAL *pHBInfo, HLOCAL *pHBm, SUSIE_PROGRESS lpPrgressCallback, LONG_PTR lData)");
TestGetPictureMain(GetPicture);
}else if ( type_extract == FALSE ){
ShowComment(L" ● GetPicture がない\r\n");
}
if ( UseUNICODE && (GetPictureW != NULL) ){
PrintAPIname("GetPictureW(LPCWSTR buf, LONG_PTR len, unsigned int flag, HLOCAL *pHBInfo, HLOCAL *pHBm, SUSIE_PROGRESS lpPrgressCallback, LONG_PTR lData)");
TestGetPictureWMain(GetPictureW);
}
}
void TestGetPreview(void)
{
if ( GetPreview != NULL ){
PrintAPIname("GetPreview(LPCSTR buf, LONG_PTR len, unsigned int flag, HLOCAL *pHBInfo, HLOCAL *pHBm, SUSIE_PROGRESS lpPrgressCallback, LONG_PTR lData)");
TestGetPictureMain(GetPreview);
}else if ( type_extract == FALSE ){
ShowComment(L" ● GetPreview がない\r\n");
}
if ( UseUNICODE && (GetPreviewW != NULL) ){
PrintAPIname("GetPreviewW(LPCWSTR buf, LONG_PTR len, unsigned int flag, HLOCAL *pHBInfo, HLOCAL *pHBm, SUSIE_PROGRESS lpPrgressCallback, LONG_PTR lData)");
TestGetPictureWMain(GetPreviewW);
}
}
void TestGetPictureInfo_check(struct PictureInfo *pinfo)
{
printoutf(L" (left, top) = (%d, %d)\r\n", pinfo->left, pinfo->top);
printoutf(L" (width, height) = (%d, %d)\r\n", pinfo->width, pinfo->height);
printoutf(L" x_density: %d ppi y_density %d ppi\r\n",
pinfo->x_density, pinfo->y_density);
printoutf(L" colorDepth: %d bit (%d colors)\r\n", pinfo->colorDepth, 1 << pinfo->colorDepth );
if ( pinfo->left == WRITECHECK_DWORD ){
ShowComment(L" ● left が変更されていない\r\n");
}
if ( pinfo->top == WRITECHECK_DWORD ){
ShowComment(L" ● top が変更されていない\r\n");
}
if ( pinfo->width == WRITECHECK_DWORD ){
ShowComment(L" ● width が変更されていない\r\n");
}
if ( pinfo->height == WRITECHECK_DWORD ){
ShowComment(L" ● height が変更されていない\r\n");
}
if ( pinfo->x_density == WRITECHECK_DWORD ){
ShowComment(L" ● x_density が変更されていない\r\n");
}
if ( pinfo->y_density == WRITECHECK_DWORD ){
ShowComment(L" ● y_density が変更されていない\r\n");
}
if ( pinfo->colorDepth == WRITECHECK_DWORD ){
ShowComment(L" ● colorDepth が変更されていない\r\n");
}
#ifdef _WIN64
if ( ((LONG_PTR)pinfo->hInfo & WRITECHECK_QMASK) == ((LONG_PTR)WRITECHECK_QTOP) ){
ShowComment(L" ● hInfo のアラインメントがずれている(hInfo = %p)\r\n", pinfo->hInfo);
}else if ( pinfo->hInfo == (HANDLE)WRITECHECK_QWORD )
#else
if ( pinfo->hInfo == (HANDLE)WRITECHECK_DWORD )
#endif
{
ShowComment(L" ● hInfo が変更されていない(hInfo = %p)\r\n", pinfo->hInfo);
}else if ( pinfo->hInfo == NULL ){
printout(L" hInfo: NULL\r\n");
}else{
char *info, *infolast;
DWORD size;
info = (char *)LocalLock(pinfo->hInfo);
size = LocalSize(pinfo->hInfo);
printoutf(L" hInfo: %d bytes\r\n", size);
if ( size == 0 ){
ShowComment(L" ● hInfo の大きさが 0 \r\n");
}else{
WCHAR *infoW;
DWORD sizeW;
UINT codepage;
infolast = (char *)memchr(info, 0, size);
if ( infolast == NULL ){
ShowComment(L" ● hInfo が \0 終端でない \r\n");
info[size - 1] = '\0';
}
if ( (size >= 4) && (memcmp(info, UTF8HEADER, UTF8HEADERSIZE) == 0) ){
info += UTF8HEADERSIZE;
size -= UTF8HEADERSIZE;
printout(L" (utf-8): ");
codepage = CP_UTF8;
}else{
printout(L" (ShiftJIS): ");
codepage = CP_ACP;
}
sizeW = MultiByteToWideChar(codepage, 0, info, size, NULL, 0);
infoW = (WCHAR *)malloc(sizeW);
if ( infoW != NULL ){
MultiByteToWideChar(codepage, 0, info, size, infoW, sizeW);
printout(infoW);
free(infoW);
}else{
printout(L"memory error");
}
}
LocalUnlock(pinfo->hInfo);
LocalFree(pinfo->hInfo);
}
}
void TestGetPictureInfo(void)
{
struct PictureInfo pinfo;
if ( GetPictureInfo != NULL ){
int result;
char buf[MAX_PATH];
PrintAPIname("GetPictureInfo(LPCSTR buf, LONG_PTR len, unsigned int flag, struct PictureInfo *lpInfo)");
if ( testdisk ){
printout(L"SOURCE_DISK(non-existence)");
strcpy(buf, "dummy_file_name");
result = GetPictureInfo(buf, 0, SUSIE_SOURCE_DISK, &pinfo);
CheckInvaildFilename(result);
printout(L"SOURCE_DISK");
strcpy(buf, sourcenameA);
memset(&pinfo, WRITECHECK_BYTE, sizeof(pinfo));
result = GetPictureInfo(buf, 0, SUSIE_SOURCE_DISK, &pinfo);
if ( strcmp(buf, sourcenameA) != 0 ){
ShowComment(L" ● filename 破損\r\n");
}
if ( result == SUSIEERROR_NOERROR ){
TestGetPictureInfo_check(&pinfo);
}
}
if ( testmem ){
printout(L"SOURCE_MEM");
result = GetPictureInfo(SourceImage, SourceSize, SUSIE_SOURCE_MEM, &pinfo);
PluginResult(result);
if ( memcmp(SourceImage, CompareSourceImage, SourceAllocSize) != 0 ){
ShowComment(L" ● buf 破損\r\n");
}
if ( result == SUSIEERROR_NOERROR ){
TestGetPictureInfo_check(&pinfo);
}
}
}
if ( UseUNICODE && (GetPictureInfoW != NULL) ){
int result;
WCHAR buf[MAX_PATH];
PrintAPIname("GetPictureInfoW(LPCWSTR buf, LONG_PTR len, unsigned int flag, struct PictureInfo *lpInfo)");
if ( testdisk ){
printout(L"SOURCE_DISK(non-existence)");
strcpyW(buf, L"dummy_file_name");
result = GetPictureInfoW(buf, 0, SUSIE_SOURCE_DISK, &pinfo);
CheckInvaildFilename(result);
printout(L"SOURCE_DISK");
strcpyW(buf, sourcename);
memset(&pinfo, WRITECHECK_BYTE, sizeof(pinfo));
result = GetPictureInfoW(buf, 0, SUSIE_SOURCE_DISK, &pinfo);
PluginResult(result);
if ( strcmpW(buf, sourcename) != 0 ){
ShowComment(L" ● filename 破損\r\n");
}
if ( result == SUSIEERROR_NOERROR ){
TestGetPictureInfo_check(&pinfo);
}
}
if ( testmem ){
printout(L"SOURCE_MEM");
result = GetPictureInfoW((WCHAR *)SourceImage, SourceSize, SUSIE_SOURCE_MEM, &pinfo);
PluginResult(result);
if ( memcmp(SourceImage, CompareSourceImage, SourceAllocSize) != 0 ){
ShowComment(L" ● buf 破損\r\n");
}
if ( result == SUSIEERROR_NOERROR ){
TestGetPictureInfo_check(&pinfo);
}
}
}
}
void TestGetPluginInfo_noinfo(int infono)
{
if ( infono < 4 ){
ShowComment(L" ● infono=%d: infono は 0-3 まで必須\r\n", infono);
}
if ( (infono > 2) && (infono & 1) ){
ShowComment(L" ● infono=%d: 2n+1 があるのに 2n+2 がない\r\n", infono);
}
}
void TestGetPluginInfo(void)
{
BOOL unicode = FALSE;
int infono;
for (;; unicode = TRUE){
if ( unicode == FALSE ){ // ansi
if ( GetPluginInfo == NULL ){
ShowComment(L" ● GetPluginInfo がない\r\n");
continue;
}
PrintAPIname("GetPluginInfo(int infono, LPSTR buf, int buflen)");
}else{ // unicode
if ( !UseUNICODE || (GetPluginInfoW == NULL) ) break;
PrintAPIname("GetPluginInfoW(int infono, LPWSTR buf, int buflen)");
}
for ( infono = 0; ; infono++ ){
#define INFOBUFLEN 512
#define INFOBUFCHECKLEN 500
char bufA[INFOBUFLEN];
WCHAR bufW[INFOBUFLEN], cbuf[32], *memo;
int result, result_checklen, result_susielen;
if ( infono >= 2 ){
result_susielen = 255;
}else if ( infono == 1 ){
result_susielen = 128;
}else{
result_susielen = 8;
}
if ( unicode == FALSE ){
if ( infono >= 1 ){
memset(bufA, WRITECHECK_BYTE, sizeof(bufA));
result = GetPluginInfo(infono, bufA, 4);
bufA[5] = '\0';
if ( result != 0 ){
if ( bufA[4] != WRITECHECK_BYTE ){
ShowComment(L" ● infono=%d: buflen = 4 のとき、buf[4] を越えて書き込み\r\n", infono);
}else if ( strlen(bufA) > 4 ){
ShowComment(L" ● infono=%d: 切り捨て時、末尾が \\0 でない\r\n", infono);
}
}
}
memset(bufA, WRITECHECK_BYTE, sizeof(bufA));
result = GetPluginInfo(infono, bufA, INFOBUFCHECKLEN);
if ( result == 0 ){
TestGetPluginInfo_noinfo(infono);
break;
}
bufA[INFOBUFLEN - 1] = '\0';
result_checklen = strlen(bufA);
AnsiToUnicode(bufA, bufW, INFOBUFCHECKLEN);
}else{
if ( infono >= 1 ){
memset(bufW, WRITECHECK_BYTE, sizeof(bufW));
result = GetPluginInfoW(infono, bufW, 4);
bufW[5] = '\0';
if ( result != 0 ){
if ( bufW[4] != WRITECHECK_WCHAR ){
ShowComment(L" ● infono=%d: buflen = 4 のとき、buf[4] を越えて書き込み\r\n", infono);
}else if ( strlenW(bufW) > 4 ){
ShowComment(L" ● infono=%d: 切り捨て時、末尾が \\0 でない\r\n", infono);
}
}
}
memset(bufW, WRITECHECK_BYTE, sizeof(bufW));
bufW[0] = '\0';
result = GetPluginInfoW(infono, bufW, INFOBUFCHECKLEN);
if ( result == 0 ){
TestGetPluginInfo_noinfo(infono);
break;
}
bufW[INFOBUFLEN - 1] = '\0';
result_checklen = strlenW(bufW);
}
if ( result > INFOBUFCHECKLEN ){
ShowComment(L" ● infono=%d: 戻り値(%d)が指定最大値(%d)超\r\n", infono, result, INFOBUFCHECKLEN);
result = INFOBUFCHECKLEN - 1;
}
if ( result_checklen > result ){
ShowComment(L" ● infono=%d: buf の末尾が \\0 でない\r\n", infono);
}
if ( result_checklen >= result_susielen ){
ShowComment(L" ● infono=%d: Susie(%d)では扱えない長さ\r\n", infono, result_susielen);
}
memo = L"";
if ( infono == 0 ){
if ( strcmpW(bufW, L"00AM") == 0 ){
type_extract = TRUE;
memo = L" (Export filter)";
}else if ( strcmpW(bufW, L"00IN") == 0 ){
memo = L" (Import filter)";
}else if ( strcmpW(bufW, L"T0XN") == 0 ){
memo = L" (AtoB Converter export Plug-in)";
}else{
ShowComment(L" ● 不明プラグインバージョン\r\n");
}
strcpyW(cbuf, L"type");
}else if ( infono == 1 ){
strcpyW(cbuf, L"name");
}else if ( infono & 1 ){
wsprintfW(cbuf, L"name #%d", infono / 2);
}else{
wsprintfW(cbuf, L"ext #%d", infono / 2);
}
printoutf(L" %d(%s): %s%s\r\n", infono, cbuf, bufW, memo);
if ( result != result_checklen ){
ShowComment(L" ● infono=%d: 戻り値:%d != 文字列長:%d\r\n", infono, result, result_checklen);
}
if ( (infono >= 2) && ((infono & 1) == 0) ){
if ( (bufW[0] == '.') || (strstrW(bufW, L";.") != NULL) ){
ShowComment(L" ● infono=%d: 対応拡張子が「*.ext」形式で無い\r\n", infono);
}
}
}
if ( unicode ) break;
}
}
#define IsSupportedT(unicode, nameA, nameW, dw) (!unicode ? IsSupported(nameA, dw) : IsSupportedW(nameW, dw))
int PrintSupport(int result)
{
printoutf(L" %d (%s)\r\n", result, result ? L"support" : L"not support");
return result;
}
void TestIsSupported(void)
{
char header[SUSIE_CHECK_SIZE + 16], backup_header[SUSIE_CHECK_SIZE + 16];
char dummy_header[SUSIE_CHECK_SIZE + 16];
HANDLE hFile;
BOOL unicode = FALSE;
int result;
char bufA[MAX_PATH];
WCHAR bufW[MAX_PATH];
if ( sourcename[0] == '\0' ) return;
hFile = OpenFileHeader(header);
if ( hFile == INVALID_HANDLE_VALUE ) return;
memcpy(backup_header, header, sizeof(backup_header));
memset(dummy_header, WRITECHECK_BYTE, sizeof(dummy_header));
for (;; unicode = TRUE){
if ( unicode == FALSE ){ // ansi
if ( IsSupported == NULL ){
ShowComment(L" ● IsSupported が存在しない\r\n");
continue;
}
PrintAPIname("IsSupported(LPCSTR filename, void *dw)");
strcpy(bufA, "non-existence");
}else{ // unicode
if ( !UseUNICODE || (IsSupportedW == NULL) ) break;
PrintAPIname("IsSupportedW(LPCSTR filename, void *dw)");
strcpyW(bufW, L"non-existence");
}
printout(L" dw is memory(dummy data):");
result = PrintSupport(IsSupportedT(unicode, bufA, bufW, dummy_header));
if ( result ) ShowComment(L" ● 存在しないファイルでも対応扱い\r\n");
printoutf(L" dw is file handle(bad handle):");
result = PrintSupport(IsSupportedT(unicode, bufA, bufW, (void *)WRITECHECK_BYTE));
if ( result ) ShowComment(L" ● 存在しないハンドルでも対応扱い\r\n");
if ( unicode == FALSE ){ // ansi
strcpy(bufA, sourcenameA);
}else{ // unicode
strcpyW(bufW, sourcename);
}
printout(L" dw is memory: ");
PrintSupport(IsSupportedT(unicode, bufA, bufW, header));
if ( (!unicode ? strcmp(bufA, sourcenameA) : strcmpW(bufW, sourcename)) != 0 ){
ShowComment(L" ● filename 破損\r\n");
}
if ( memcmp(header, backup_header, sizeof(header)) != 0 ){
ShowComment(L" ● dw 破損\r\n");
}
{
hFile = CreateFileW(sourcename, GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if ( hFile != INVALID_HANDLE_VALUE ){
if ( (LONG_PTR)hFile < 0x10000 ){
printout(L" dw is file handle:");
PrintSupport(IsSupportedT(unicode, bufA, bufW, hFile));
}else{
printout(L"* ファイルハンドルのテストができない(over 16bit).\r\n");
}
CloseHandle(hFile);
}
}
if ( unicode ) break;
}
}
void TestGetArchiveInfo_SUSIE_FINFO(SUSIE_FINFO *finfo, UINT infosize)
{
UINT maxcount;
UINT count = 0;
WCHAR timebuf[32];
maxcount = (infosize + sizeof(SUSIE_FINFO) - 1) / sizeof(SUSIE_FINFO);
if ( infosize < 1 ){
ShowComment(L" ● lphInf の大きさが小さいため、ファイル情報の終了を検出できない\r\n");
}
for ( ; count < maxcount ;){
if ( finfo->method[0] == '\0' ){
if ( (count + 1) != maxcount ){
printoutf(L"※ 確保したメモリ(%d)よりファイル情報の数(%dx%d=%d)が少ない\r\n", infosize, count, sizeof(SUSIE_FINFO), count * sizeof(SUSIE_FINFO));
}
break;
}
printoutf(L"-#%d-method: %hs\r\n", count, finfo->method);
printoutf(L" #%d position: %lu\r\n", count, finfo->position);
printoutf(L" #%d compsize: %lu\r\n", count, finfo->compsize);
printoutf(L" #%d filesize: %lu\r\n", count, finfo->filesize);
printoutf(L" #%d timestamp: %s\r\n", count, GetTimeStrings(timebuf, finfo->timestamp));
printoutf(L" #%d path: '%hs'\r\n", count, finfo->path);
printoutf(L" #%d filename: '%hs'\r\n", count, finfo->filename);
printoutf(L" #%d crc: %u\r\n", count, finfo->crc);
finfo++;
count++;
if ( count == maxcount ){
ShowComment(L" ● 最後のファイル情報が method[0] == '\\0' でない\r\n");
}
}
printoutf(L" %d Entries\r\n", count);
}
void Compare_SUSIE_FINFO_one(SUSIE_FINFO *finfo1, SUSIE_FINFO *finfo2, int count)
{
if ( strcmp((const char *)finfo1->method, (const char *)finfo2->method) != 0 ){
ShowComment(L" ● #%d method 不一致(%hs != %hs)\r\n", count, finfo1->method, finfo2->method);
}
if ( finfo1->position != finfo2->position ){
ShowComment(L" ● #%d position 不一致(%d != %d)\r\n", count, finfo1->position, finfo2->position);
}
if ( finfo1->compsize != finfo2->compsize ){
ShowComment(L" ● #%d compsize 不一致\r\n", count);
}
if ( finfo1->filesize != finfo2->filesize ){
ShowComment(L" ● #%d filesize 不一致(%d != %d)\r\n", count, finfo1->filesize, finfo2->filesize);
}
if ( finfo1->timestamp != finfo2->timestamp ){
ShowComment(L" ● #%d timestamp 不一致\r\n", count);
}
if ( strcmp(finfo1->path, finfo2->path) != 0 ){
ShowComment(L" ● #%d path 不一致\r\n", count);
}
if ( strcmp(finfo1->filename, finfo2->filename) != 0 ){
ShowComment(L" ● #%d filename 不一致(%hs != %hs)\r\n", count, finfo1->filename, finfo2->filename);
}
if ( finfo1->crc != finfo2->crc ){
ShowComment(L" ● #%d crc 不一致\r\n", count);
}
}
void Compare_SUSIE_FINFO(SUSIE_FINFO *finfo1, SUSIE_FINFO *finfo2, UINT infosize)
{
UINT maxcount;
UINT count = 0;
int OldCommentCount = CommentCount;
printout(L" Compare SUSIE_FINFO file <-> mem\r\n");
maxcount = (infosize + sizeof(SUSIE_FINFO) - 1) / sizeof(SUSIE_FINFO);
for ( ; count < maxcount ; finfo1++, finfo2++, count++ ){
if ( (finfo1->method[0] == '\0') || (finfo2->method[0] == '\0') ){
if ( (finfo1->method[0] != '\0') || (finfo2->method[0] != '\0') ){
printout(L"X\r\n");
ShowComment(L" ● ソースが memory と file で情報数が異なる\r\n");
}else{
printout(L".");
}
break;
}
Compare_SUSIE_FINFO_one(finfo1, finfo2, count);
}
printout(L"\r\n");
if ( CommentCount == OldCommentCount ) printout(L" -> All match\r\n");
}
void TestGetArchiveInfo_SUSIE_FINFOW(SUSIE_FINFOW *finfo, UINT infosize)
{
UINT maxcount;
UINT count = 0;
WCHAR timebuf[32];
maxcount = (infosize + sizeof(SUSIE_FINFOW) - 1) / sizeof(SUSIE_FINFOW);
if ( infosize < 1 ){
ShowComment(L" ● lphInf の大きさが小さいため、ファイル情報の終了を検出できない\r\n");
}
for ( ; count < maxcount ;){
if ( finfo->method[0] == '\0' ){
if ( (count + 1) != maxcount ){
ShowComment(L"● 確保したメモリ(%d)よりファイル情報の数(%dx%d=%d)が少ない\r\n", infosize, count, sizeof(SUSIE_FINFO), count * sizeof(SUSIE_FINFO));
}
break;
}
printoutf(L"-#%d-method: %hs\r\n", count, finfo->method);
printoutf(L" #%d position: %lu\r\n", count, finfo->position);
printoutf(L" #%d compsize: %lu\r\n", count, finfo->compsize);
printoutf(L" #%d filesize: %lu\r\n", count, finfo->filesize);
printoutf(L" #%d timestamp: %s\r\n", count, GetTimeStrings(timebuf, finfo->timestamp));
printoutf(L" #%d path: '%s'\r\n", count, finfo->path);
printoutf(L" #%d filename: '%s'\r\n", count, finfo->filename);
printoutf(L" #%d crc: %u\r\n", count, finfo->crc);
finfo++;
count++;
if ( count == maxcount ){
ShowComment(L" ● 最後のファイル情報が method[0] == '\\0' でない\r\n");
}
}
printoutf(L" %d Entries\r\n", count);
}
void Compare_SUSIE_FINFOW_one(SUSIE_FINFOW *finfo1, SUSIE_FINFOW *finfo2, int count)
{
if ( strcmp((const char *)finfo1->method, (const char *)finfo2->method) != 0 ){
ShowComment(L" ● #%d method 不一致(%S != %S)\r\n", count, finfo1->method, finfo2->method);
}
if ( finfo1->position != finfo2->position ){
ShowComment(L" ● #%d position 不一致(%d != %d)\r\n", count, finfo1->position, finfo2->position);
}
if ( finfo1->compsize != finfo2->compsize ){
ShowComment(L" ● #%d compsize 不一致(%d != %d)\r\n", count, finfo1->compsize, finfo2->compsize);
}
if ( finfo1->filesize != finfo2->filesize ){
ShowComment(L" ● #%d filesize 不一致(%d != %d)\r\n", count, finfo1->filesize, finfo2->filesize);
}
if ( finfo1->timestamp != finfo2->timestamp ){
ShowComment(L" ● #%d timestamp 不一致\r\n", count);
}
if ( strcmpW(finfo1->path, finfo2->path) != 0 ){
ShowComment(L" ● #%d path 不一致(%s != %s)\r\n", count, finfo1->path, finfo2->path);
}
if ( strcmpW(finfo1->filename, finfo2->filename) != 0 ){
ShowComment(L" ● #%d filename 不一致(%s != %s)\r\n", count, finfo1->filename, finfo2->filename);
}
if ( finfo1->crc != finfo2->crc ){
ShowComment(L" ● #%d crc 不一致\r\n", count);
}
}
void Compare_SUSIE_FINFOW(SUSIE_FINFOW *finfo1, SUSIE_FINFOW *finfo2, UINT infosize)
{
UINT maxcount;
UINT count = 0;
int OldCommentCount = CommentCount;
printout(L" Compare SUSIE_FINFOW file <-> mem\r\n");
maxcount = (infosize + sizeof(SUSIE_FINFOW) - 1) / sizeof(SUSIE_FINFOW);
for ( ; count < maxcount ; finfo1++, finfo2++, count++ ){
if ( finfo1->method[0] == '\0' ){
if ( finfo2->method[0] != '\0' ){
ShowComment(L" ● ソースが memory と file で情報数が異なる\r\n");
}
break;
}
Compare_SUSIE_FINFOW_one(finfo1, finfo2, count);
}
if ( CommentCount == OldCommentCount ) printout(L" -> All match\r\n");
}
void Compare_SUSIE_FINFO_AW(SUSIE_FINFO *finfo1, SUSIE_FINFOW *finfo2, UINT info1size)
{
UINT maxcount;
UINT count = 0;
int OldCommentCount = CommentCount;
WCHAR text[SUSIE_PATH_MAX];
printout(L" Compare SUSIE_FINFO with SUSIE_FINFOW\r\n");
maxcount = (info1size + sizeof(SUSIE_FINFO) - 1) / sizeof(SUSIE_FINFO);
for ( ; count < maxcount ; finfo1++, finfo2++, count++ ){
printout(L".");
if ( finfo1->method[0] == '\0' ){
if ( finfo2->method[0] != '\0' ){
ShowComment(L" ● ソースが memory と file で情報数が異なる\r\n");
}
break;
}
if ( finfo1->position != finfo2->position ){
ShowComment(L" ● #%d position 不一致(%d != %d)\r\n", count, finfo1->position, finfo2->position);
}
if ( finfo1->compsize != finfo2->compsize ){
ShowComment(L" ● #%d compsize 不一致(%d != %d)\r\n", count, finfo1->compsize, finfo2->compsize);
}
if ( finfo1->filesize != finfo2->filesize ){
ShowComment(L" ● #%d filesize 不一致(%d != %d)\r\n", count, finfo1->filesize, finfo2->filesize);
}
if ( finfo1->timestamp != finfo2->timestamp ){
ShowComment(L" ● #%d timestamp 不一致(%d != %d)\r\n", count, finfo1->timestamp, finfo2->timestamp);
}
AnsiToUnicode(finfo1->path, text, SUSIE_PATH_MAX);
if ( strcmpW(text, finfo2->path) != 0 ){
ShowComment(L" ● #%d path 不一致(%s != %s)\r\n", count, text, finfo2->path);
}
AnsiToUnicode(finfo1->filename, text, SUSIE_PATH_MAX);
if ( strcmpW(text, finfo2->filename) != 0 ){
ShowComment(L" ● #%d filename 不一致(%s != %s)\r\n", count, text, finfo2->filename);
}
if ( finfo1->crc != finfo2->crc ){
ShowComment(L" ● #%d crc 不一致(%d, %d)\r\n", count, finfo1->crc, finfo2->crc);
}
}
printout(L"X\r\n");
if ( CommentCount == OldCommentCount ) printout(L" -> All match\r\n");
}
void TestGetArchiveInfo(void)
{
if ( sourcename[0] == '\0' ) return;
if ( GetArchiveInfo != NULL ){
int result;
char buf[MAX_PATH];
HLOCAL hInfFile, hInfMem;