forked from cchd0012/___l__r___e____r
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLM_Script_LSB.cpp
More file actions
3254 lines (2740 loc) · 110 KB
/
LM_Script_LSB.cpp
File metadata and controls
3254 lines (2740 loc) · 110 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
#include "LM_Script.h"
#include "LM_Functions.h"
#pragma warning (disable:6031)
#pragma warning (disable:4996)
//*** lsb 스크립트 분석 및 적용 함수들을 서술하는 파일
LSB_INST_BASE* getInstClass(LSB_INST_TYPES _type, unsigned int _script_ver, LSB_HEADER* _header);
//*** 경우별로 타입에 맞춰 할당 후 반환하는 함수
//---------------------------- 스크립트 클래스 관련 함수 ----------------------------//
bool LSB_SCRIPT::Script_Analysis(wchar_t* LsbFile, unsigned int code)
{
_setmode(_fileno(stdout), _O_U16TEXT);
wprintf(TEXT("Analysis: Lsb File: %s\n"), LsbFile);
HANDLE hLsb = CreateFileW(LsbFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hLsb == INVALID_HANDLE_VALUE) {
wprintf(TEXT("%s: There's not LSB File\n"), LsbFile);
_setmode(_fileno(stdout), _O_TEXT);
return false;
}
unsigned int lsb_size = GetFileSize(hLsb, NULL);
unsigned char* lsb_buffer = (unsigned char*)malloc(lsb_size);
ReadFile(hLsb, lsb_buffer, lsb_size, NULL, NULL);
CloseHandle(hLsb);
//*lsb 파일 읽어들이기 (파일 경로 언어코드도 고려할 필요 있음)
unsigned char* lsb_buffer_pnt = lsb_buffer;
//*필요한 변수들
if (!LSB_Header_Analysis(LsbFile, lsb_buffer, &lsb_buffer_pnt)) {
_setmode(_fileno(stdout), _O_U16TEXT);
wprintf(TEXT("%s: Error occured while analysing header\n"), LsbFile);
free(lsb_buffer);
_setmode(_fileno(stdout), _O_TEXT);
return false;
}
//*헤더 분석
if (!LSB_Body_Analysis(LsbFile, lsb_buffer, &lsb_buffer_pnt, code)) {
_setmode(_fileno(stdout), _O_U16TEXT);
wprintf(TEXT("%s: Error occured while analysing body\n"), LsbFile);
free(lsb_buffer);
_setmode(_fileno(stdout), _O_TEXT);
return false;
}
//*몸통 분석
wprintf(TEXT("Script Analysis Complete!\n"));
free(lsb_buffer);
_setmode(_fileno(stdout), _O_TEXT);
return true;
//*정리
}
//*** lsb 스크립트 파일 분석 함수
bool LSB_SCRIPT::LSB_Header_Analysis(wchar_t* LsbFile, unsigned char* _org_pnt, unsigned char** _lsb_buffer_pnt)
{
_setmode(_fileno(stdout), _O_TEXT);
if (_lsb_buffer_pnt == NULL) { return false; }
//*필수조건
unsigned char* lsb_buffer_pnt = (*_lsb_buffer_pnt);
lm_version = *(unsigned int*)(lsb_buffer_pnt);
lsb_buffer_pnt += sizeof(int);
if (lm_version != LM_VERSION_1) { printf("Lm script version : 1\n"); }
else if (lm_version != LM_VERSION_2) { printf("Lm script version : 2\n"); }
else if (lm_version != LM_VERSION_3) { printf("Lm script version : 3\n"); }
else {
_setmode(_fileno(stdout), _O_U16TEXT);
wprintf(TEXT("%s: Not supported LSB script file\n"), LsbFile);
_setmode(_fileno(stdout), _O_TEXT);
return false;
}
//*버전 세팅 후 매직 바이트 분석
flag = (*lsb_buffer_pnt); lsb_buffer_pnt++;
//*첫 1바이트
_header = new LSB_HEADER(lm_version);
_header->Header_Read(_org_pnt, &lsb_buffer_pnt);
//*헤더 데이터 읽어들이기
(*_lsb_buffer_pnt) = lsb_buffer_pnt;
return true;
//*위치 변경 반영
}
//*** 헤더 분석 함수
bool LSB_SCRIPT::LSB_Body_Analysis(wchar_t* LsbFile, unsigned char* _org_pnt, unsigned char** _lsb_buffer_pnt, unsigned int code)
{
_setmode(_fileno(stdout), _O_TEXT);
if (_lsb_buffer_pnt == NULL) { return false; }
//*필수조건
unsigned char* lsb_buffer_pnt = (*_lsb_buffer_pnt);
_body = new LSB_BODY(lm_version, _header);
_body->Body_Read(_org_pnt, &lsb_buffer_pnt, code);
//*헤더 세팅 후 몸체 데이터 읽어들이기
(*_lsb_buffer_pnt) = lsb_buffer_pnt;
return true;
//*위치 변경 반영
}
//*** 몸통 분석 함수
void LSB_SCRIPT::Decompile_To_Code(wchar_t* TxtFile, unsigned int code)
{
_setmode(_fileno(stdout), _O_U16TEXT);
wprintf(TEXT("Decompiling to Code: Lsb File: To %s\n"), TxtFile);
HANDLE hWrite = CreateFileW(TxtFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
//*핸들 생성
UINT16 BOM = 0xFEFF;
WriteFile(hWrite, &BOM, 2, NULL, NULL);
//*유니코드 형식 추출 준비 (BOM)
memset(_txt_buf, 0, sizeof(wchar_t) * TXT_BUFF_LEN);
//*맨 처음은 반드시 0으로 초기화함
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("Livemaker Script Version_0x%02X%s%s"), lm_version, _enter_raw_, separation_line);
//*버전 기록
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("[HEADER]%s"), _enter_raw_);
if (_header != NULL) { _header->_decompile_code(hWrite); }
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("%s"), separation_line);
WriteFile(hWrite, _txt_buf, (sizeof(wchar_t) * wcslen(_txt_buf)), NULL, NULL);
//*헤더 클래스에 추출 명령
memset(_txt_buf, 0, sizeof(wchar_t) * wcslen(_txt_buf));
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("[BODY]%s"), _enter_raw_);
WriteFile(hWrite, _txt_buf, (sizeof(wchar_t) * wcslen(_txt_buf)), NULL, NULL);
memset(_txt_buf, 0, sizeof(wchar_t) * wcslen(_txt_buf));
if (_body != NULL) { _body->_decompile_code (hWrite, code); }
memset(_txt_buf, 0, sizeof(wchar_t) * wcslen(_txt_buf));
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("%s"), separation_line);
WriteFile(hWrite, _txt_buf, (sizeof(wchar_t) * wcslen(_txt_buf)), NULL, NULL);
//*몸통 클래스에 추출 명령
CloseHandle(hWrite);
//*핸들 해제
wprintf(TEXT("Decompiling Complete!\n"));
_setmode(_fileno(stdout), _O_TEXT);
}
//*스크립트 클래스 : 디컴파일 함수
void LSB_SCRIPT::Make_To_Script(wchar_t* newLsbFile, unsigned int code)
{
_setmode(_fileno(stdout), _O_U16TEXT);
wprintf(TEXT("Writing: Lsb File: %s\n"), newLsbFile);
HANDLE hNewLsb = CreateFileW(newLsbFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
//*핸들 생성
WriteFile(hNewLsb, &lm_version, sizeof(int), NULL, NULL);
WriteFile(hNewLsb, &flag, sizeof(char), NULL, NULL);
//* 버전 / 플래그 기록
if (_header != NULL) { _header->_write_as_lsb(hNewLsb); }
//* 헤더 기록
if (_body != NULL) { _body->_write_as_lsb(hNewLsb, code); }
//* 몸통 기록
CloseHandle(hNewLsb);
//*핸들 해제
wprintf(TEXT("Writing Complete!\n"));
_setmode(_fileno(stdout), _O_TEXT);
//*정리
}
//*스크립트 클래스 : lsb 파일로 기록하는 함수 (내부 언어코드 및 문자열 변환은 다른 함수에서)
void LSB_SCRIPT::Extract_Text_Data(wchar_t* DstTxtFile)
{
_setmode(_fileno(stdout), _O_U16TEXT);
wprintf(TEXT("Extracting: Text File: %s\n"), DstTxtFile);
HANDLE hTxt = CreateFileW(DstTxtFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
//*핸들 생성
UINT16 BOM = 0xFEFF;
WriteFile(hTxt, &BOM, 2, NULL, NULL);
//*유니코드 형식 추출 준비 (BOM)
_body->_extract_text(hTxt);
//*텍스트 추출 함수 호출
CloseHandle(hTxt);
//*핸들 해제
wprintf(TEXT("Extracting Text Complete!\n"));
_setmode(_fileno(stdout), _O_TEXT);
//*정리
}
//*텍스트 추출 함수
void LSB_SCRIPT::Replace_Text_Data(wchar_t* SrcTxtFile, unsigned int code)
{
_setmode(_fileno(stdout), _O_U16TEXT);
wprintf(TEXT("Replacing: Text File: %s\n"), SrcTxtFile);
HANDLE hTxt = CreateFileW(SrcTxtFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hTxt == INVALID_HANDLE_VALUE) {
wprintf(TEXT("%s: Can't Open File\n"), SrcTxtFile);
_setmode(_fileno(stdout), _O_TEXT);
return;
}
//*핸들 생성
UINT16 _chk = 0;
ReadFile(hTxt, &_chk, 2, NULL, NULL);
if (_chk != 0xFEFF) {
wprintf(TEXT("%s: This File Isn't Unicode File\n"), SrcTxtFile);
_setmode(_fileno(stdout), _O_TEXT);
CloseHandle(hTxt);
return;
}
//*유니코드 텍스트인지 체크
unsigned int txt_size = GetFileSize(hTxt, NULL);
unsigned int total_txt_count = (txt_size / sizeof(wchar_t)) - 1;
wchar_t* txt_buffer = (wchar_t*)malloc((txt_size));
ReadFile(hTxt, txt_buffer, (txt_size - sizeof(wchar_t)), NULL, NULL);
txt_buffer[total_txt_count] = 0;
CloseHandle(hTxt);
//*텍스트 파일 읽어들이기 / 핸들 해제
unsigned int line_count = Get_Txt_Count (txt_buffer, line_prefix, total_txt_count);
//*텍스트가 있는 라인 수 확인
LSB_TEXTS_PER_INST* _txt_list = (LSB_TEXTS_PER_INST*)malloc(sizeof(LSB_TEXTS_PER_INST) * line_count);
memset(_txt_list, 0, (sizeof(LSB_TEXTS_PER_INST) * line_count));
//*라인당 소유 텍스트 구조체 할당
wchar_t* _line_pnt = txt_buffer, * _line_pnt_bak = txt_buffer;
wchar_t line_num[9]; line_num[8] = 0x00;
for (unsigned int i = 0; i < line_count;i++) {
_line_pnt = wcsstr(_line_pnt_bak, line_prefix);
_line_pnt += (wcslen(line_prefix) + 1);
memcpy(line_num, _line_pnt, (sizeof(wchar_t) * 8));
_txt_list[i]._line = wcstol(line_num, NULL, 10);
//*_line_pnt : 라인 문자열 시작 지점
//*라인 문자열 + ':' 만큼 길이를 더한 후 길이를 얻어낸다
if (i != (line_count - 1)) {
_line_pnt_bak = wcsstr(_line_pnt, line_prefix);
}
else {
_line_pnt_bak = (txt_buffer + total_txt_count);
}
//*_line_pnt_bak : 해당 라인이 끝나는 지점
//*만일 마지막 카운트면 위치를 못 찾기 때문에 수동으로 마무리를 지정한다
unsigned int _tp_buf_size = _line_pnt_bak - _line_pnt;
wchar_t* _tp_buf = (wchar_t*)malloc(sizeof(wchar_t) * (_tp_buf_size + 1));
_tp_buf[_tp_buf_size] = 0;
memcpy(_tp_buf, _line_pnt, (sizeof(wchar_t) * _tp_buf_size));
//*해당 영역만 따로 카피를 떠서 진행함
_txt_list[i]._txt_count = Get_Txt_Count(_tp_buf, text_data_prefix, _tp_buf_size);
//*해당 명령어 내 텍스트 수 파악
if (_txt_list[i]._txt_count != 0) {
_txt_list[i]._txt_list_per_inst = (wchar_t**)malloc(sizeof(wchar_t*) * _txt_list[i]._txt_count);
memset(_txt_list[i]._txt_list_per_inst, 0, (sizeof(wchar_t*) * _txt_list[i]._txt_count));
//*공간 할당
wchar_t* _txt_pnt = _tp_buf, * _txt_pnt_bak = _tp_buf;
for (unsigned int j = 0; j < _txt_list[i]._txt_count;j++) {
_txt_pnt = wcsstr(_txt_pnt_bak, text_data_prefix);
_txt_pnt += wcslen(text_data_prefix);
_txt_pnt_bak = wcsstr(_txt_pnt, text_prefix);
_txt_pnt_bak += wcslen(text_prefix);
//*_txt_pnt_bak : 텍스트 시작 지점
_txt_pnt = wcsstr(_txt_pnt_bak, text_prefix);
//*_txt_pnt : 텍스트 끝나는 지점
wchar_t* _tmp = (wchar_t*)malloc(sizeof(wchar_t) * (_txt_pnt - _txt_pnt_bak + 1));
memcpy(_tmp, _txt_pnt_bak, (sizeof(wchar_t) * (_txt_pnt - _txt_pnt_bak)));
_tmp[(_txt_pnt - _txt_pnt_bak)] = 0;
_txt_list[i]._txt_list_per_inst[j] = _tmp;
//*데이터 할당 / 카피 후 붙여넣기 / 리스트에 세팅
_txt_pnt_bak = _txt_pnt + wcslen(text_prefix);
//*_txt_pnt_bak은 이 다음 지점에 세팅한다
}
//*텍스트 수만큼 루프 돌림
}
//*텍스트 수가 0이 아닐 때만 진행
else if (wcsstr (_tp_buf, _inst_type_list[TYPE_INST_TEXT_INST]) != NULL) {
_txt_list[i]._txt_count = 1;
_txt_list[i]._txt_list_per_inst = (wchar_t**)malloc(sizeof(wchar_t*));
_txt_list[i]._txt_list_per_inst[0] = (wchar_t*)malloc(sizeof(wchar_t) * (wcslen(_tp_buf) + 1));
memset(_txt_list[i]._txt_list_per_inst[0], 0, (sizeof(wchar_t) * (wcslen(_tp_buf) + 1)));
memcpy(_txt_list[i]._txt_list_per_inst[0], _tp_buf, (sizeof(wchar_t) * wcslen(_tp_buf)));
}
//*텍스트 수가 0일 때는 _TEXT_INST인지 확인해보고 만일 그렇다면 그대로 복사해서 추가해 준다
free(_tp_buf);
//*다 진행했으면 임시 버퍼 해제
}
//*읽어들인 파일로 텍스트 세팅
_body->_replace_text(_txt_list, line_count, code);
//*텍스트 교체 함수 호출
for (unsigned int i = 0; i < line_count; i++) {
for (unsigned int j = 0; j < _txt_list[i]._txt_count; j++) { free(_txt_list[i]._txt_list_per_inst[j]); }
if (_txt_list[i]._txt_list_per_inst != NULL) { free(_txt_list[i]._txt_list_per_inst); }
}
free (txt_buffer);
//*버퍼 해제
wprintf(TEXT("Replacing Complete!\n"));
_setmode(_fileno(stdout), _O_TEXT);
//*정리
}
//*텍스트 교체 함수
void LSB_SCRIPT::Convert_Codepage_J2K()
{
_setmode(_fileno(stdout), _O_U16TEXT);
wprintf(TEXT("Changing Text Language Code(Jap -> Kor)...\n"));
_body->_change_code_J2K();
wprintf(TEXT("Complete!\n"));
_setmode(_fileno(stdout), _O_TEXT);
}
//*텍스트 언어코드를 일본어에서 한글로 바꾸는 함수
//---------------------------- 스크립트 클래스 관련 함수 ----------------------------//
//---------------------------- 헤더 클래스 관련 함수 ----------------------------//
bool LSB_HEADER::Header_Read(unsigned char* _org_pnt, unsigned char** _lsb_buffer_pnt)
{
unsigned char* lsb_buffer_pnt = (*_lsb_buffer_pnt);
opcode_count = *(unsigned int*)(lsb_buffer_pnt);
lsb_buffer_pnt += sizeof(int);
opcode_property_count = *(unsigned int*)(lsb_buffer_pnt);
lsb_buffer_pnt += sizeof(int);
//*헤더 영역 : 오브젝트 수 / 오브젝트 크기 분석
opcode_property_table = (unsigned char**)malloc(sizeof(unsigned char*) * opcode_count);
for (unsigned int i = 0; i < opcode_count; i++) {
opcode_property_table[i] = (unsigned char*)malloc(opcode_property_count);
memcpy(opcode_property_table[i], lsb_buffer_pnt, opcode_property_count);
lsb_buffer_pnt += opcode_property_count;
}
//*각 크기에 맞추어 할당 후 복제
opcode_property_boolean_table = (bool**)malloc(sizeof(bool*) * opcode_count);
for (unsigned int i = 0; i < opcode_count; i++) {
opcode_property_boolean_table[i] = (bool*)malloc(opcode_property_count * 8);
for (unsigned int j = 0; j < opcode_property_count; j++) {
for (unsigned int k = 0; k < 8; k++) {
opcode_property_boolean_table[i][(j * 8) + k] = (opcode_property_table[i][j] & (1 << k)) != 0;
}
}
}
//*각 크기에 맞추어 할당 (bool이므로 8배 늘리기)
//*아마 각 스크립트 버전에 따라 ver2는 0xA5개, ver3은 0xAC개로 제한된 듯 한데
//*크게 신경 쓸 필요는 없을 듯 하다
(*_lsb_buffer_pnt) = lsb_buffer_pnt;
return true;
//*위치 변경 반영
}
//*헤더 클래스 : 버퍼에서 데이터 받아오기
void LSB_HEADER::_decompile_code(HANDLE hWrite)
{
if (opcode_property_table != NULL) {
for (unsigned int i = 0; i < opcode_count; i++) {
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("%s"), _indent_);
//*들여쓰기 출력
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("[%s%02d]::"), property_array_prefix, i);
//*속성 헤더 기록
for (unsigned int j = 0; j < opcode_property_count; j++) {
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("[0x%02X]"), opcode_property_table[i][j]);
}
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("%s"), _enter_raw_);
//*모든 원소 기록
}
}
//*opcode 배열 기록
}
//*헤더 클래스 : 디컴파일 함수
void LSB_HEADER::_write_as_lsb(HANDLE hNewLsb)
{
WriteFile(hNewLsb, &opcode_count, sizeof(int), NULL, NULL);
WriteFile(hNewLsb, &opcode_property_count, sizeof(int), NULL, NULL);
//*명령어 수 / 각 명령어당 속성 수 기록
for (unsigned int i = 0; i < opcode_count; i++) {
WriteFile(hNewLsb, opcode_property_table[i], opcode_property_count, NULL, NULL);
}
//*속성 정보 배열 기록
wprintf(TEXT("Header Writing Complete...\n"));
}
//*헤더 클래스 : lsb 파일로 기록하는 함수
//---------------------------- 헤더 클래스 관련 함수 ----------------------------//
//---------------------------- 몸체 클래스 관련 함수 ----------------------------//
bool LSB_BODY::Body_Read(unsigned char* _org_pnt, unsigned char** _lsb_buffer_pnt, unsigned int code)
{
unsigned char* lsb_buffer_pnt = (*_lsb_buffer_pnt);
inst_list_count = *(unsigned int*)(lsb_buffer_pnt);
lsb_buffer_pnt += sizeof(int);
inst_list_arr = (LSB_INST_BASE**)malloc(sizeof(LSB_INST_BASE*) * inst_list_count);
memset(inst_list_arr, 0, sizeof(LSB_INST_BASE*) * inst_list_count);
//*총 명령어 덩어리 수 파악 / 할당
for (unsigned int i = 0; i < inst_list_count; i++) {
unsigned char _opcode = *(lsb_buffer_pnt++);
inst_list_arr[i] = getInstClass((LSB_INST_TYPES)_opcode, _script_ver, _header);
if (inst_list_arr[i] == NULL) {
printf("Illegal command : 0x%02X at [0x%08X]\n", _opcode, ((lsb_buffer_pnt - 1) - _org_pnt));
return false;
}
//*opcode 읽기, ver2에서는 0x3C까지만 지원하는 듯 한데 그거까지 신경쓰고 싶진 않다
//*사실상 read_function_prologue가 모든 명령어에 적용되는 듯 하다
inst_list_arr[i]->_read_inst_data(&lsb_buffer_pnt, code);
//*각 명령어에 걸맞게 데이터 읽어들이기
}
//*스크립트에 기술된 명령어대로 돌아가며 읽어들이기
(*_lsb_buffer_pnt) = lsb_buffer_pnt;
return true;
//*위치 변경 반영
}
//*몸체 클래스 : 버퍼에서 데이터 받아오기
void LSB_BODY::_decompile_code(HANDLE hWrite, unsigned int code)
{
if (inst_list_arr != NULL) {
for (unsigned int i = 0; i < inst_list_count; i++) {
inst_list_arr[i]->_decompile_code(hWrite, i, code, 1);
}
}
//*들여쓰기 추가
}
//*몸체 클래스 : 디컴파일 함수
void LSB_BODY::_write_as_lsb(HANDLE hNewLsb, unsigned int code)
{
WriteFile(hNewLsb, &inst_list_count, sizeof(int), NULL, NULL);
//*총 명령어 수 기록
for (unsigned int i = 0; i < inst_list_count; i++) {
inst_list_arr[i]->_write_as_lsb(hNewLsb, code);
}
//*명령어만큼 돌아가며 기록
wprintf(TEXT("Body Writing Complete...\n"));
}
//*몸통 클래스 : lsb 파일로 기록하는 함수
void LSB_BODY::_extract_text(HANDLE hTxt)
{
for (unsigned int i = 0; i < inst_list_count; i++) {
inst_list_arr[i]->_extract_text(hTxt);
}
//*명령어만큼 돌아가며 추출
wprintf(TEXT("Text Extracting Complete...\n"));
}
//*몸통 클래스 : 텍스트 추출 함수
void LSB_BODY::_replace_text(LSB_TEXTS_PER_INST* txt_list, unsigned int txt_list_count, unsigned int code)
{
for (unsigned int i = 0; i < txt_list_count; i++) {
LSB_INST_BASE* _pnt = NULL;
for (unsigned int j = 0; j < inst_list_count; j++) {
if (inst_list_arr[j]->_line == txt_list[i]._line) {
_pnt = inst_list_arr[j]; break;
}
}
//*라인으로 등록된 명령어 찾기
if (_pnt != NULL) {
_pnt->_replace_text (&txt_list[i], code);
}
//*null이면 그냥 안함, 찾아내면 수행함
}
//*라인이 등록되어 있는 명령어만큼 돌아가며 대치
wprintf(TEXT("Text Replacing Complete...\n"));
}
//*몸통 클래스 : 텍스트 교체 함수
void LSB_BODY::_change_code_J2K()
{
for (unsigned int i = 0; i < inst_list_count; i++) {
inst_list_arr[i]->_change_code_J2K();
}
//*루프 돌면서 바꿔치기
}
//*몸통 클래스 : 텍스트 코드 변경 함수
//---------------------------- 몸체 클래스 관련 함수 ----------------------------//
//---------------------------- 기본 클래스 함수 ----------------------------//
void LSB_INST_BASE::_decompile_code(HANDLE hWrite, unsigned int offset, unsigned int code, unsigned int _indent)
{
//----------- 텍스트 버퍼에 모으기 -----------//
memset(_txt_buf, 0, sizeof(wchar_t) * wcslen(_txt_buf));
for (unsigned int i = 0; i < _indent; i++) { swprintf(_txt_buf + wcslen(_txt_buf), TEXT("%s"), _indent_); }
WriteFile(hWrite, _txt_buf, (sizeof(wchar_t) * wcslen(_txt_buf)), NULL, NULL);
//*들여쓰기 출력 (텍스트 파일로)
//----------- 텍스트 버퍼에 모으기 -----------//
//----------- 텍스트 버퍼에 모으기 -----------//
memset(_txt_buf, 0, sizeof(wchar_t) * wcslen(_txt_buf));
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("[%s:%08d][%s:%08d][%08X][%02X][%02X][%s:%s]%s"),
line_prefix, _line, offset_prefix, offset, this->_indent, _mute, _not_update, inst_type_prefix, _inst_type_list[_op_type], _enter_raw_);
//*명령어 종류 출력
unsigned int _param_c = 0, _addi = 0;
for (unsigned int i = 0; i < _data_chunks_count; i++) {
if (_param_c != 0) { _addi = 1; _param_c--; }
else { _addi = 0; }
//*함수 인자 수만큼 들여쓰기 반영
for (unsigned int j = 0; j < (_indent + _addi + 1); j++) {
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("%s"), _indent_);
}
//*들여쓰기 출력, 함수 인자 출력시 한칸 더 붙여 출력해야 함
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("%s%s"), text_prefix, (wchar_t*)_data_chunks[i]._str);
//*타입명 일부분만 먼저 출력
//* ([◆]타입명)
if (wcscmp(_data_chunks[i]._str, TEXT("Target_Label_Offset")) == 0)
{
unsigned int _val = *(unsigned int*)_data_chunks[i]._data;
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("%s%08d%s%s"), text_prefix, _val, text_prefix, _enter_raw_);
}
else if ((wcscmp(_data_chunks[i]._str, TEXT("Parameter_Count")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("Var_Type")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("Var_Scope")) == 0))
{
unsigned int _val = *(unsigned int*)_data_chunks[i]._data;
if (wcscmp(_data_chunks[i]._str, TEXT("Parameter_Count")) == 0) { _param_c = _val; }
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("%s0x%08X%s%s"), text_prefix, _val, text_prefix, _enter_raw_);
}
//*단순 정수, 함수 인자 수라면 값을 새로 갱신한다
//* ([◆]0x%08X[◆]\r\n)
else if ((wcscmp(_data_chunks[i]._str, TEXT("Var_Scope_Byte")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("All_Clear_Byte")) == 0))
{
unsigned char _val = *(unsigned char*)_data_chunks[i]._data;
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("%s0x%02X%s%s"), text_prefix, _val, text_prefix, _enter_raw_);
}
//*단순 바이트
//* ([◆]0x%02X[◆]\r\n)
else if ((wcscmp(_data_chunks[i]._str, TEXT("Result")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("Script_Page")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("Label")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("Var_Name")) == 0))
{
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("%s%s%s%s"), text_prefix, (wchar_t*)_data_chunks[i]._data, text_prefix, _enter_raw_);
}
//*단순 문자열 (코드값에 따라 적용)
//* ([◆]문자열[◆]\r\n)
else if ((wcscmp(_data_chunks[i]._str, TEXT("Event_Block")) == 0))
{
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("%s%s"), text_prefix, _enter_raw_);
//*개행 처리
LSB_EVENT* _evb = (LSB_EVENT*)_data_chunks[i]._data;
_evb->_decompile_code(hWrite, code, (_indent + _addi + 2));
//*데이터 출력
}
//*이벤트 블럭
else {
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("%s%s"), text_prefix, _enter_raw_);
//*개행 처리
LSB_PARAMETERS* _pnt = (LSB_PARAMETERS*)_data_chunks[i]._data;
_pnt->_decompile_code(hWrite, code, (_indent + _addi + 2));
}
//*이외는 전부 패러미터 리스트
}
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("%s"), _enter_raw_);
//----------- 텍스트 버퍼에 모으기 -----------//
WriteFile(hWrite, _txt_buf, (sizeof(wchar_t) * wcslen(_txt_buf)), NULL, NULL);
//*개행 한 번 더 하고 출력
}
//*** 전부 디컴파일해 출력하는 함수
void LSB_INST_BASE::_write_as_lsb(HANDLE hNewLsb, unsigned int code)
{
WriteFile(hNewLsb, &_op_type, sizeof(char), NULL, NULL);
//*맨 앞에 이 명령어의 속성(1바이트) 기록
WriteFile(hNewLsb, &_indent, sizeof(int), NULL, NULL);
WriteFile(hNewLsb, &_mute, sizeof(char), NULL, NULL);
WriteFile(hNewLsb, &_not_update, sizeof(char), NULL, NULL);
WriteFile(hNewLsb, &_line, sizeof(int), NULL, NULL);
//*들여쓰기(indent) / mute / _not_update_(static?) / 라인 위치 기록
for (unsigned int i = 0; i < _data_chunks_count; i++) {
if ((wcscmp(_data_chunks[i]._str, TEXT("Target_Label_Offset")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("Parameter_Count")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("Var_Scope")) == 0))
{
_write_int(hNewLsb, *(unsigned int*)_data_chunks[i]._data);
}
//*단순 정수
else if ((wcscmp(_data_chunks[i]._str, TEXT("Var_Type")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("Var_Scope_Byte")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("All_Clear_Byte")) == 0))
{
_write_byte(hNewLsb, *(unsigned char*)_data_chunks[i]._data);
}
//*단순 바이트
else if ((wcscmp(_data_chunks[i]._str, TEXT("Result")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("Script_Page")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("Label")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("Var_Name")) == 0))
{
wchar_t* _w1 = Replace_Text((wchar_t*)_data_chunks[i]._data, hex_1_plained, hex_1_raw);
free(_data_chunks[i]._data);
_data_chunks[i]._data = Replace_Text(_w1, _enter_plained_, _enter_raw_);
free(_w1);
char* _ansi = GetAnsiStr((wchar_t*)_data_chunks[i]._data, code);
_write_str(hNewLsb, _ansi);
free(_ansi);
//*대치 필요, ansi 문자열로 바꾸고 기록
}
//*단순 문자열
else if ((wcscmp(_data_chunks[i]._str, TEXT("Event_Block")) == 0))
{
LSB_EVENT* _t = (LSB_EVENT*)_data_chunks[i]._data;
_t->_write_as_lsb(hNewLsb, code);
}
//*이벤트 블럭
else {
LSB_PARAMETERS *_t = (LSB_PARAMETERS*)_data_chunks[i]._data;
_t->_write_as_lsb(hNewLsb, code);
}
//*패러미터 리스트
//*각 속성에 따라 기록함 (정수 / 문자열 / 이벤트 블럭 / 패러미터 리스트)
}
//*데이터 덩어리 수만큼 돌아가며 기록, 데이터 덩어리 수는 기록하지 않음
//*그냥 순서대로 기록하면 됨
}
//*기본 클래스 : lsb 파일로 기록하는 함수
void LSB_INST_BASE::_extract_text(HANDLE hTxt)
{
//----------- 텍스트 버퍼에 모으기 -----------//
memset(_txt_buf, 0, sizeof(wchar_t) * wcslen(_txt_buf));
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("[%s:%08d][%s:%s]%s"),
line_prefix, _line, inst_type_prefix, _inst_type_list[_op_type], _enter_raw_);
WriteFile(hTxt, _txt_buf, (sizeof(wchar_t) * wcslen(_txt_buf)), NULL, NULL);
//*라인 넘버 먼저 출력
//----------- 텍스트 버퍼에 모으기 -----------//
//----------- 텍스트 버퍼에 모으기 -----------//
memset(_txt_buf, 0, sizeof(wchar_t) * wcslen(_txt_buf));
_extract_text_each_inst(hTxt);
//*각 명령어별로 추출 실시
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("%s"), _enter_raw_);
//*가독성이 안좋으니 개행 추가
WriteFile(hTxt, _txt_buf, (sizeof(wchar_t) * wcslen(_txt_buf)), NULL, NULL);
//----------- 텍스트 버퍼에 모으기 -----------//
}
//*기본 클래스 : 텍스트 추출 함수
void LSB_INST_BASE::_replace_text(LSB_TEXTS_PER_INST* txt_list_elem, unsigned int code)
{
_replace_text_each_inst(txt_list_elem, code);
//* 각 명령어별로 교체 실시
}
//*기본 클래스 : 텍스트 교체 함수
void LSB_INST_BASE::_change_code_J2K()
{
if (_data_chunks != NULL) {
for (unsigned int i = 0; i < _data_chunks_count; i++) {
if ((wcscmp(_data_chunks[i]._str, TEXT("Result")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("Script_Page")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("Label")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("Var_Name")) == 0))
{
JPHan_2_KRHan((wchar_t*)_data_chunks[i]._data);
}
//*문자열은 직접 바꿔치기
else if (wcscmp(_data_chunks[i]._str, TEXT("Event_Block")) == 0)
{
LSB_EVENT* _t = (LSB_EVENT*)_data_chunks[i]._data;
_t->_change_code_J2K();
}
//*이벤트 클래스는 다시 호출
else if ((wcscmp(_data_chunks[i]._str, TEXT("Parameter_Count")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("Target_Label_Offset")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("Var_Type")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("Var_Scope")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("Var_Scope_Byte")) == 0)
|| (wcscmp(_data_chunks[i]._str, TEXT("All_Clear_Byte")) == 0))
{;}
//*나머지는 그냥 무시한다
else {
LSB_PARAMETERS* _t = (LSB_PARAMETERS*)_data_chunks[i]._data;
_t->_change_code_J2K();
}
//*패러미터 클래스는 다시 호출
}
}
//*루프돌면서 수행
}
//*기본 클래스 : 텍스트 코드 변경 함수
LSB_INST_BASE* getInstClass(LSB_INST_TYPES _type, unsigned int _script_ver, LSB_HEADER* _header)
{
switch (_type)
{
case TYPE_INST_IF: { return new LSB_INST_IF(_type, _script_ver, _header); }
case TYPE_INST_ELIF: { return new LSB_INST_ELIF(_type, _script_ver, _header); }
case TYPE_INST_ELSE: { return new LSB_INST_ELSE(_type, _script_ver, _header); }
case TYPE_INST_LABEL: { return new LSB_INST_LABEL(_type, _script_ver, _header); }
case TYPE_INST_JUMP: { return new LSB_INST_JUMP(_type, _script_ver, _header); }
case TYPE_INST_CALL: { return new LSB_INST_CALL(_type, _script_ver, _header); }
case TYPE_INST_EXIT: { return new LSB_INST_EXIT(_type, _script_ver, _header); }
case TYPE_INST_WAIT: { return new LSB_INST_WAIT(_type, _script_ver, _header); }
case TYPE_INST_TIMER: { return new LSB_INST_TIMER(_type, _script_ver, _header); }
case TYPE_INST_CALC_FUNC: { return new LSB_INST_CALC_FUNC(_type, _script_ver, _header); }
case TYPE_INST_BOX_NEW: { return new LSB_INST_BOX_NEW(_type, _script_ver, _header); }
case TYPE_INST_IMAGE_NEW: { return new LSB_INST_IMAGE_NEW(_type, _script_ver, _header); }
case TYPE_INST_MESSAGE_NEW: { return new LSB_INST_MESSAGE_NEW(_type, _script_ver, _header); }
case TYPE_INST_PARTICLE_NEW: { return new LSB_INST_PARTICLE_NEW(_type, _script_ver, _header); }
case TYPE_INST_FIRE_NEW: { return new LSB_INST_FIRE_NEW(_type, _script_ver, _header); }
case TYPE_INST_EDIT_NEW: { return new LSB_INST_EDIT_NEW(_type, _script_ver, _header); }
case TYPE_INST_MEMO_NEW: { return new LSB_INST_MEMO_NEW(_type, _script_ver, _header); }
case TYPE_INST_MAP_IMAGE_NEW: { return new LSB_INST_MAP_IMAGE_NEW(_type, _script_ver, _header); }
case TYPE_INST_WAVE_NEW: { return new LSB_INST_WAVE_NEW(_type, _script_ver, _header); }
case TYPE_INST_TILE_NEW: { return new LSB_INST_TILE_NEW(_type, _script_ver, _header); }
case TYPE_INST_SLIDER_NEW: { return new LSB_INST_SLIDER_NEW(_type, _script_ver, _header); }
case TYPE_INST_SCROLL_BAR_NEW: { return new LSB_INST_SCROLL_BAR_NEW(_type, _script_ver, _header); }
case TYPE_INST_GAUGE_NEW: { return new LSB_INST_GAUGE_NEW(_type, _script_ver, _header); }
case TYPE_INST_PREV_MENU_NEW: { return new LSB_INST_PREV_MENU_NEW(_type, _script_ver, _header); }
case TYPE_INST_VAR_NEW: { return new LSB_INST_VAR_NEW(_type, _script_ver, _header); }
case TYPE_INST_VAR_DELETE: { return new LSB_INST_VAR_DELETE(_type, _script_ver, _header); }
case TYPE_INST_MOVIE: { return new LSB_INST_MOVIE(_type, _script_ver, _header); }
case TYPE_INST_FLIP: { return new LSB_INST_FLIP(_type, _script_ver, _header); }
case TYPE_INST_MOVIE_STOP: { return new LSB_INST_MOVIE_STOP(_type, _script_ver, _header); }
case TYPE_INST_CINEMA: { return new LSB_INST_CINEMA(_type, _script_ver, _header); }
case TYPE_INST_GET_PROPERTY: { return new LSB_INST_GET_PROPERTY(_type, _script_ver, _header); }
case TYPE_INST_SET_PROPERTY: { return new LSB_INST_SET_PROPERTY(_type, _script_ver, _header); }
case TYPE_INST_OBJECT_DELETE: { return new LSB_INST_OBJECT_DELETE(_type, _script_ver, _header); }
case TYPE_INST_TEXT_INST: { return new LSB_INST_TEXT_INST(_type, _script_ver, _header); }
case TYPE_INST_TEXT_CLEAR: { return new LSB_INST_TEXT_CLEAR(_type, _script_ver, _header); }
case TYPE_INST_CLEAR_HISTORY: { return new LSB_INST_CLEAR_HISTORY(_type, _script_ver, _header); }
case TYPE_INST_CALL_HISTORY: { return new LSB_INST_CALL_HISTORY(_type, _script_ver, _header); }
case TYPE_INST_FORMAT_HISTORY: { return new LSB_INST_FORMAT_HISTORY(_type, _script_ver, _header); }
case TYPE_INST_CAPTION: { return new LSB_INST_CAPTION(_type, _script_ver, _header); }
case TYPE_INST_CG_CAPTION: { return new LSB_INST_CG_CAPTION(_type, _script_ver, _header); }
case TYPE_INST_MENU: { return new LSB_INST_MENU(_type, _script_ver, _header); }
case TYPE_INST_MENU_CLOSE: { return new LSB_INST_MENU_CLOSE(_type, _script_ver, _header); }
case TYPE_INST_BUTTON: { return new LSB_INST_BUTTON(_type, _script_ver, _header); }
case TYPE_INST_COMMENT: { return new LSB_INST_COMMENT(_type, _script_ver, _header); }
case TYPE_INST_WHILE: { return new LSB_INST_WHILE(_type, _script_ver, _header); }
case TYPE_INST_WHILE_INIT: { return new LSB_INST_WHILE_INIT(_type, _script_ver, _header); }
case TYPE_INST_WHILE_LOOP: { return new LSB_INST_WHILE_LOOP(_type, _script_ver, _header); }
case TYPE_INST_BREAK: { return new LSB_INST_BREAK(_type, _script_ver, _header); }
case TYPE_INST_CONTINUE: { return new LSB_INST_CONTINUE(_type, _script_ver, _header); }
case TYPE_INST_GAME_SAVE: { return new LSB_INST_GAME_SAVE(_type, _script_ver, _header); }
case TYPE_INST_GAME_LOAD: { return new LSB_INST_GAME_LOAD(_type, _script_ver, _header); }
case TYPE_INST_CLEAR_LOAD: { return new LSB_INST_CLEAR_LOAD(_type, _script_ver, _header); }
case TYPE_INST_PC_RESET: { return new LSB_INST_PC_RESET(_type, _script_ver, _header); }
case TYPE_INST_RESET: { return new LSB_INST_RESET(_type, _script_ver, _header); }
case TYPE_INST_SOUND: { return new LSB_INST_SOUND(_type, _script_ver, _header); }
case TYPE_INST_MEDIA_PLAY: { return new LSB_INST_MEDIA_PLAY(_type, _script_ver, _header); }
case TYPE_INST_TERMINATE: { return new LSB_INST_TERMINATE(_type, _script_ver, _header); }
case TYPE_INST_DO_EVENT: { return new LSB_INST_DO_EVENT(_type, _script_ver, _header); }
case TYPE_INST_PROPERTY_MOTION: { return new LSB_INST_PROPERTY_MOTION(_type, _script_ver, _header); }
case TYPE_INST_SAVE_CABINET: { return new LSB_INST_SAVE_CABINET(_type, _script_ver, _header); }
case TYPE_INST_LOAD_CABINET: { return new LSB_INST_LOAD_CABINET(_type, _script_ver, _header); }
case TYPE_INST_MACRO_IFDEF: { return new LSB_INST_MACRO_IFDEF(_type, _script_ver, _header); }
case TYPE_INST_MACRO_IFNDEF: { return new LSB_INST_MACRO_IFNDEF(_type, _script_ver, _header); }
case TYPE_INST_MACRO_ENDIF: { return new LSB_INST_MACRO_ENDIF(_type, _script_ver, _header); }
default: { return NULL; }
}
}
//*** 경우별로 타입에 맞춰 할당 후 반환하는 함수
//---------------------------- 기본 클래스 함수 ----------------------------//
//---------------------------- 패러미터 리스트 클래스 ----------------------------//
void LSB_PARAMETERS::_read_parameter_list(unsigned char** _lsb_buffer_pnt, unsigned int code)
{
unsigned char* lsb_buffer_pnt = (*_lsb_buffer_pnt);
_count = *(unsigned int*)lsb_buffer_pnt;
lsb_buffer_pnt += sizeof(int);
if (_count == 0) {
(*_lsb_buffer_pnt) = lsb_buffer_pnt;
return;
}
_list = (LSB_PARAMETER*)malloc(sizeof(LSB_PARAMETER) * _count);
memset(_list, 0, (sizeof(LSB_PARAMETER) * _count));
//*패러미터 수 파악 후 그만큼 할당
//*만일 패러미터 수가 0이면 그냥 리턴한다
char* _s;
for (unsigned int i = 0; i < _count; i++) {
_list[i]._type = (LSB_OPER_TYPES) * (lsb_buffer_pnt++); //*** 패러미터 타입
_s = _get_str(&lsb_buffer_pnt);
_list[i]._name = GetUniStr (_s, code); //*** 패러미터 이름
free(_s);
_list[i].arg_count = *(unsigned int*)lsb_buffer_pnt; //*** 패러미터가 가진 인자의 수
lsb_buffer_pnt += sizeof(int);
_list[i].arg_list = (LM_SCR_ARG*)malloc(sizeof(LM_SCR_ARG) * _list[i].arg_count);
memset(_list[i].arg_list, 0, (sizeof(LM_SCR_ARG) * _list[i].arg_count));
//*인자 수만큼 읽어들이고 할당
if (_list[i]._type == TYPE_ARG_CALC_FUNC) {
_list[i]._calc_func = (LSB_CALC_FUNC_TYPES)(*lsb_buffer_pnt++);
}
else {
_list[i]._calc_func = TYPE_CF_UNKNOWN;
}
//*패러미터 타입이 calc_func이라면 따로 읽어들인다
//*일단은 기호가 잘못되면 안되는 처리는 할 수 있는데 그냥 진행
for (unsigned int j = 0; j < _list[i].arg_count; j++) {
_list[i].arg_list[j]._type = (LM_SCR_TYPES) * (lsb_buffer_pnt++);
switch (_list[i].arg_list[j]._type)
{
case TYPE_ARG_INT:
{
_list[i].arg_list[j]._data = _get_int(&lsb_buffer_pnt);
break;
//*** 정수 처리
}
case TYPE_ARG_FLOAT:
{
_list[i].arg_list[j]._data = _get_data(&lsb_buffer_pnt, 0xA);
break;
//*** 소수 처리, 공간을 0xA 크기만큼 잡아먹는다
}
case TYPE_ARG_BOOL:
{
_list[i].arg_list[j]._data = _get_data(&lsb_buffer_pnt, 0x1);
break;
//*** 논리형 처리, 공간을 0x1 크기만큼 잡아먹는다
}
case TYPE_ARG_STR:
{
_s = _get_str(&lsb_buffer_pnt);
_list[i].arg_list[j]._data = GetUniStr (_s, code);
free(_s);
break;
//*** 문자열 처리
}
default:
{
_s = _get_str(&lsb_buffer_pnt);
_list[i].arg_list[j]._data = GetUniStr(_s, code);
free(_s);
break;
//*** 이외의 경우(VAR 등)는 그냥 문자열 처리한다
}
}
//*타입에 따라 처리를 나눈다
}
//*인자 수만큼 수행하기
}
//*패러미터 수만큼 읽어들이기
(*_lsb_buffer_pnt) = lsb_buffer_pnt;
}
//*패러미터를 읽어들이는 함수
void LSB_PARAMETERS::_decompile_code(HANDLE hWrite, unsigned int code, unsigned int _indent)
{
for (unsigned int i = 0; i < _count; i++) {
for (unsigned int j = 0; j < (_indent); j++) {
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("%s"), _indent_);
}
//*들여쓰기 출력
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("[%s:%s][_TYPE_:%s]"),
arg_name_prefix, (wchar_t*)_list[i]._name, _op_list[_list[i]._type]);
//*인자 이름 출력
if (_list[i]._type == TYPE_ARG_CALC_FUNC) {
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("[_CF_:%s]"), (wchar_t*)_cf_list[_list[i]._calc_func]);
}
//*CALC_FUNC일 경우 추가 출력
swprintf(_txt_buf + wcslen(_txt_buf), TEXT("%s"), _enter_raw_);
//*개행 마무리
for (unsigned int j = 0; j < _list[i].arg_count; j++) {