-
Notifications
You must be signed in to change notification settings - Fork 3
/
Intellisense.asm
1061 lines (970 loc) · 27.9 KB
/
Intellisense.asm
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
.CODE
FindFromStructureMembersListAndSelect Proc Uses ESI EDI lpText:DWORD
Local lvfi:LV_FINDINFO
Local Buffer[256]:BYTE
Invoke ShowListAutoPosAndHeight,hListStructureMembers
XOR EDI,EDI
MOV ESI,lpText
.If BYTE PTR [ESI]!=0
Invoke RtlZeroMemory,ADDR lvfi,SizeOf LV_FINDINFO
MOV lvfi.flags,LVFI_STRING or LVFI_PARTIAL; or LVFI_WRAP or LVFI_PARTIAL; Or
MOV lvfi.psz,ESI
Invoke SendMessage,hListStructureMembers,LVM_FINDITEM,-1,ADDR lvfi
.If EAX!=-1 ;i.e if there is such text in the list
MOV EDI,EAX
Invoke GetItemText,hListStructureMembers, EDI, 0, ADDR Buffer
Invoke lstrlen,ESI
MOV Buffer[EAX],0
Invoke lstrcmpi,ESI,ADDR Buffer
.If EAX
XOR EDI,EDI
.EndIf
.EndIf
.EndIf
Invoke SelectListItem,hListStructureMembers, EDI;,0
Invoke ScrollListItemToTop,hListStructureMembers,EDI
RET
FindFromStructureMembersListAndSelect EndP
FindFromListAndSelect Proc Uses EDI ESI EBX lpText:DWORD, hList:DWORD
Local lvfi:LV_FINDINFO
Local Buffer[256]:BYTE
MOV ESI,lpText
;.If BYTE PTR [ESI]!=0
Invoke RtlZeroMemory,ADDR lvfi,SizeOf LV_FINDINFO
MOV lvfi.flags,LVFI_STRING or LVFI_PARTIAL; or LVFI_WRAP or LVFI_PARTIAL; Or
MOV lvfi.psz,ESI
Invoke SendMessage,hList,LVM_FINDITEM,-1,ADDR lvfi
.If EAX!=-1 ;i.e if there is such text in the list
.If BYTE PTR[ESI]==0
MOV EDI,-1
.Else
MOV EDI,EAX
.EndIf
Invoke GetItemText, hList, EDI, 0, ADDR Buffer
Invoke lstrlen,ESI
MOV Buffer[EAX],0
Invoke lstrcmpi,ESI,ADDR Buffer
.If EAX==0
Invoke ShowListAutoPosAndHeight,hList
Invoke SelectListItem, hList, EDI
Invoke ScrollListItemToTop,hList,EDI
MOV EAX,TRUE
.Else
Invoke ShowWindow,hList,SW_HIDE
MOV EAX,FALSE
.EndIf
.Else
Invoke ShowWindow,hList,SW_HIDE
Invoke ShowWindow,hListConstants,SW_HIDE
MOV EAX,FALSE
.EndIf
;.Else
; Invoke ShowWindow,hListConstants,SW_HIDE
;.EndIf
RET
FindFromListAndSelect EndP
InsertVariableAndType Proc Uses EDI ESI EBX lpText:DWORD,nImage:DWORD
Local lvi:LVITEM
MOV EDI,lpText
MOV lvi.imask,LVIF_TEXT OR LVIF_IMAGE
M2M lvi.iImage,nImage
PUSH EDI
NextOne:
XOR EBX,EBX
XOR ESI,ESI
@@:
.If BYTE PTR [EDI]==":"
MOV BYTE PTR [EDI],0
INC EDI
MOV EBX,EDI
JMP @B
;JMP NextOne
.ElseIf BYTE PTR [EDI]==","
MOV BYTE PTR [EDI],0
MOV ESI,EDI
INC ESI
.Else
.If BYTE PTR [EDI]!=0
INC EDI
JMP @B;NextOne
.EndIf
.EndIf
POP EDI
MOV lvi.pszText,EDI
MOV lvi.iItem,0
MOV lvi.iSubItem, 0
Invoke SendMessage,hListVariables,LVM_INSERTITEM,0,ADDR lvi
.If EBX ;i.e this structure member is a structure
MOV lvi.iItem,EAX
MOV lvi.iSubItem, 1
MOV lvi.pszText,EBX
;PrintStringByAddr EBX
Invoke SendMessage,hListVariables,LVM_SETITEM,0,ADDR lvi
.EndIf
.If ESI
MOV EDI,ESI
PUSH EDI
JMP NextOne
.EndIf
RET
InsertVariableAndType EndP
;=======================================================================
; by shoorick
;=======================================================================
fasm_proc_parser proc ; uses edi<-o_buff,esi<-i_buff
;-----------------------------------------------------------------------
; string has to be trimmed from spaces left and right,
; has no comments, cr, lf or "\"
; case sensitive! (lowcase as in the fasm definitions)
;-----------------------------------------------------------------------
xor edx,edx
mov eax,[esi]
mov [edi],edx
add esi,4
cmp eax,"corp";"proc"
jne done
cmp byte ptr [esi],0
je done
cmp byte ptr [esi],20h
je search_name
cmp byte ptr [esi],9
jne done
search_name:
call skip_spaces
search_name_end:
lodsb
stosb
cmp al,0
je done
cmp al,20h
je @F
cmp al,9
je @F
cmp al,","
jne search_name_end
@@:
mov byte ptr [edi - 1],0
call skip_spaces_noinc
;-----------------------------------------------------------------------
fasm_params_only label near
;-----------------------------------------------------------------------
mov ecx,2
cmp word ptr [esi]," c"
je check_uses
cmp word ptr [esi],"c" or 900h
je check_uses
xor ecx,ecx
cmp dword ptr [esi],"cdts";"stdc"
jne check_uses
mov ecx,8
cmp dword ptr [esi + 4]," lla";"all "
je check_uses
cmp dword ptr [esi + 4],"lla" or 9000000h
jne search_params
check_uses:
add esi,ecx
call skip_spaces_noinc
cmp dword ptr [esi],"sesu";"uses"
jne search_params
cmp byte ptr [esi + 4],20h
je @f
cmp byte ptr [esi + 4],9
jne search_params
@@:
lodsb
or al,al
jz done
cmp al,","
jne @B
call skip_spaces_noinc
search_params:
; inc edi
mov edx,edi
copy_params:
lodsb
or al,al
jz done
cmp al,9
je @F
cmp al,20h
je @F
stosb
jmp copy_params
@@:
call skip_spaces_noinc
jmp copy_params
;-----------------------------------------------------------------------
done:
mov eax,edx
mov byte ptr [edi],0
ret
;-----------------------------------------------------------------------
skip_spaces:
inc esi
skip_spaces_noinc:
cmp byte ptr [esi],0
je done
cmp byte ptr [esi],20h
je skip_spaces
cmp byte ptr [esi],9
je skip_spaces
retn
;-----------------------------------------------------------------------
fasm_proc_parser endp
;=======================================================================
InsertProcParameters Proc Uses EDI ESI nProcLine:DWORD
Invoke GetLineText,hEditor,nProcLine,Offset LineTxt
;Returns in EAX the length of the line text
LEA ESI,LineTxt
;Trim out any comments
Invoke TrimComment,ESI
;-----------------------------------------------------------
;Is Procedure Declaration multiline?->Get All Lines
@@:
Invoke lstrlen,ESI
ADD EAX,ESI
DEC EAX
;Check whether procedure declaration is multiline
.If BYTE PTR [EAX]=="\"
mov byte ptr [eax],0
jmp Multy
.EndIf
.If BYTE PTR [EAX]==","
;i.e. last char of line is comma or backward slash
;We need to get next line as well
Multy:
Invoke lstrcpy,Offset tmpLineTxt,ESI
INC nProcLine
Invoke GetLineText,hEditor,nProcLine,Offset LineTxt
Invoke TrimComment,Offset LineTxt
Invoke lstrcat,Offset tmpLineTxt, Offset LineTxt
Invoke lstrcpy,ESI,Offset tmpLineTxt
JMP @B
.EndIf
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
cmp FasmProcStyle,0
jne FasmParams
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;-----------------------------------------------------------
;Find first parameter that we know its type e.g. DWORD
.While BYTE PTR [ESI]!=0
.If BYTE PTR [ESI]==":"
;In case there are spaces or tabs just before ":"
AvoidSpacesAndTabs:
DEC ESI
.If BYTE PTR [ESI]==" " || BYTE PTR [ESI]==VK_TAB
JMP AvoidSpacesAndTabs
.EndIf
@@:
DEC ESI
.If BYTE PTR [ESI]=="," || BYTE PTR [ESI]==" " || BYTE PTR [ESI]==VK_TAB
;This is the first letter of the parameter
MOV BYTE PTR [ESI], ","
JMP RawParameters
.EndIf
JMP @B
.EndIf
INC ESI
.EndW
RawParameters:
;Now remove all tabs and spaces
LEA EDI, tmpLineTxt
PUSH EDI
.While BYTE PTR [ESI]!=0
.If BYTE PTR [ESI]!=" " && BYTE PTR [ESI]!=VK_TAB
MOV CL, BYTE PTR [ESI]
MOV BYTE PTR [EDI],CL
INC EDI
.EndIf
INC ESI
.EndW
MOV BYTE PTR [EDI],0 ;Insert NULL terminator
POP EDI
.If BYTE PTR [EDI]=="," ;i.e. there are parameters for this procedure
INC EDI ;To leave first comma behind
Invoke InsertVariableAndType,EDI,4
.EndIf
MOV EAX,nProcLine ;this is to return the last procedure declaration line
RET
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
FasmParams:
mov edi,esi
call fasm_proc_parser
or eax,eax
jz @F
invoke InsertVariableAndType,eax,4
@@:
mov eax,nProcLine
ret
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
InsertProcParameters EndP
InsertConstantsInVariableList Proc Uses EBX EDI
Local lvi :LVITEM
Local lvfi :LV_FINDINFO
MOV lvfi.flags,LVFI_STRING
MOV lvi.iSubItem, 0
MOV lvi.imask,LVIF_TEXT OR LVIF_IMAGE
MOV lvi.iImage,2
MOV lvi.iItem,0
MOV EBX,pLinkedList
.If EBX!=0
@@:
MOV EDI,[EBX].APICONSTANTS.pText
.While BYTE PTR [EDI]!=0
.If BYTE PTR [EDI]== "="
INC EDI
MOV lvi.pszText,EDI
MOV lvfi.psz,EDI
.While BYTE PTR [EDI]!=0
.If BYTE PTR [EDI]==" "
MOV BYTE PTR [EDI],0
;Check if not aready in the list
Invoke SendMessage,hListVariables,LVM_FINDITEM,-1,ADDR lvfi
.If EAX==-1 ;i.e if there is NOT such text in the list
Invoke SendMessage,hListVariables,LVM_INSERTITEM,0,ADDR lvi
.EndIf
MOV BYTE PTR [EDI]," "
INC EDI
MOV lvi.pszText,EDI
MOV lvfi.psz,EDI
.EndIf
INC EDI
.EndW
;Check if not aready in the list
Invoke SendMessage,hListVariables,LVM_FINDITEM,-1,ADDR lvfi
.If EAX==-1 ;i.e if there is NOT such text in the list
Invoke SendMessage,hListVariables,LVM_INSERTITEM,0,ADDR lvi
.EndIf
.Break
.EndIf
INC EDI
.EndW
.If [EBX].APICONSTANTS.pNext!=0 ;This is NOT last Entry
MOV EBX,[EBX].APICONSTANTS.pNext
JMP @B
.EndIf
.EndIf
RET
InsertConstantsInVariableList EndP
FillVariablesList Proc Uses EDI ESI fInsertConstantsToo:DWORD
Local chrg:CHARRANGE
Local ftxt:FINDTEXTEX
Local LineNo:DWORD
.If fInsertConstantsToo
Invoke GetWindowLong,hListVariables,GWL_USERDATA
.If EAX
;I need SPEEEEEEEEEEEED
MOV fInsertConstantsToo,FALSE ;i,e. do NOT add constans again;they are already there
;Delete all except constants
Invoke DeleteAllItemsByImage,hListVariables,4 ;i.e. procedure parameters
Invoke DeleteAllItemsByImage,hListVariables,5 ;i.e. local variables
.Else
Invoke SetWindowLong,hListVariables,GWL_USERDATA,TRUE
Invoke SendMessage,hListVariables,LVM_DELETEALLITEMS,0,0
.EndIf
.Else
Invoke SetWindowLong,hListVariables,GWL_USERDATA,0
Invoke SendMessage,hListVariables,LVM_DELETEALLITEMS,0,0
.EndIf
Invoke SendMessage,hEditor,EM_EXGETSEL,0,ADDR chrg
Invoke SendMessage,hEditor,EM_EXLINEFROMCHAR,0,chrg.cpMin
Invoke InProcedure,hEditor,EAX
.If EAX
;EAX is a pointer to Procedure Name
MOV ftxt.lpstrText,EAX
MOV ftxt.chrg.cpMin,0
MOV ftxt.chrg.cpMax,-1
@@:
Invoke SendMessage,hEditor,EM_FINDTEXTEX,FR_MATCHCASE or FR_WHOLEWORD or FR_DOWN,ADDR ftxt
.If EAX!=-1
Invoke SendMessage,hEditor,EM_EXLINEFROMCHAR,0,ftxt.chrgText.cpMin
MOV LineNo,EAX
Invoke SendMessage,hEditor,CHM_GETBOOKMARK,EAX,0
.If EAX==1 || EAX==2
;---------------------------------------------------------------
;First Of all get Procedure Parameters
Invoke InsertProcParameters,LineNo
MOV LineNo,EAX ;i.e. Procdure declaration last line
;---------------------------------------------------------------
;Now Get Locals
NextLine:
INC LineNo
Invoke SendMessage,hEditor,CHM_ISLINE,LineNo,Offset szLocal
.If EAX==0 ;i.e this is a 'Local' line
Invoke GetLineText,hEditor,LineNo,Offset tmpLineTxt
LEA EDI,tmpLineTxt
Invoke LTrim,EDI,EDI
NextChar:
.If BYTE PTR [EDI] !=" " && BYTE PTR [EDI] !=VK_TAB
.If BYTE PTR [EDI]!=0
INC EDI
JMP NextChar
.EndIf
.Else
Invoke LTrim,EDI,EDI
Invoke TrimComment,EDI
;Remove any tabs and spaces
LEA ESI, LineTxt
.While BYTE PTR [EDI]!=0
.If BYTE PTR [EDI]!=" " && BYTE PTR [EDI]!=VK_TAB
MOV CL,BYTE PTR [EDI]
MOV BYTE PTR [ESI],CL
INC ESI
.EndIf
INC EDI
.EndW
MOV BYTE PTR [ESI],0 ;Insert NULL terminator
Invoke InsertVariableAndType,Offset LineTxt,5
.EndIf
JMP NextLine
.Else
Invoke GetLineText,hEditor,LineNo,Offset tmpLineTxt
LEA EDI,tmpLineTxt
Invoke LTrim,EDI,EDI
;in case this line is empty or commented check the next one.
.If BYTE PTR [EDI]==0 || BYTE PTR [EDI]==";"
JMP NextLine
.EndIf
.EndIf
.Else
MOV EAX,ftxt.chrgText.cpMin
INC EAX
MOV ftxt.chrg.cpMin,EAX
JMP @B
.EndIf
;.Else ;Such a procedure name was not found
.EndIf
.EndIf
.If fInsertConstantsToo==TRUE
;PrintText "Hooray!!!!"
Invoke InsertConstantsInVariableList
.EndIf
;Now Get Global Variables
;Invoke EnumProjectItems,Offset InsertGlobals
RET
FillVariablesList EndP
FillStructureMembersList Proc Uses ESI EDI EBX lpText:DWORD
Local lvi:LVITEM
Invoke SendMessage,hListStructureMembers,LVM_DELETEALLITEMS,0,0
MOV lvi.imask, LVIF_TEXT OR LVIF_IMAGE; OR LVIF_STATE
MOV lvi.iImage,2
MOV ESI,lpText
INC ESI ;i.e do NOT need first comma
MOV EDI,ESI
.While BYTE PTR [ESI]!=0
.If BYTE PTR [ESI]==","
MOV BYTE PTR [ESI],0
CALL Insert
MOV EDI,ESI
INC EDI
.EndIf
INC ESI
.EndW
CALL Insert
RET
;-----------------------------------------------------------------------
Insert:
PUSH EDI
XOR EBX,EBX
@@:
.If BYTE PTR [EDI]==":"
MOV BYTE PTR [EDI],0
MOV EBX,EDI
INC EBX
.Else
.If BYTE PTR [EDI]!=0
INC EDI
JMP @B
.EndIf
.EndIf
POP EDI
MOV lvi.pszText,EDI
MOV lvi.iItem,0
MOV lvi.iSubItem, 0
Invoke SendMessage,hListStructureMembers,LVM_INSERTITEM,0,ADDR lvi
.If EBX ;i.e this structure member is a structure
MOV lvi.iItem,EAX
MOV lvi.iSubItem, 1
MOV lvi.pszText,EBX
Invoke SendMessage,hListStructureMembers,LVM_SETITEM,0,ADDR lvi
.EndIf
RETN
FillStructureMembersList EndP
;Returns -1 if not Structure or variable defined as structure
IsWordAPIStructure Proc Uses ESI EBX lpWord:DWORD
Local lvfi:LV_FINDINFO
Local Buffer[256]:BYTE
MOV ESI,lpWord
MOV lvfi.flags,LVFI_STRING
MOV lvfi.psz,ESI
;Check if lpWord is a STRUCTURE NAME
Invoke SendMessage,hListStructures,LVM_FINDITEM,-1,ADDR lvfi
.If EAX!=-1 ;i.e if there is such text in the list
MOV EBX,EAX
Invoke GetItemText,hListStructures,EBX,0,ADDR Buffer
Invoke lstrcmp,ESI,ADDR Buffer ;we need case sensitive comparison
.If EAX !=0 ;i.e. if NOT eaxctly the same
JMP IsItVariable ;test this may be a variable such as rect (case difference with a structure name RECT)
.EndIf
MOV EAX,EBX
.Else ;Check if lpWord is a variable defined as structure
IsItVariable:
;Fill list with variables
Invoke FillVariablesList,FALSE
;Is this word a variable that is defined as structure ?
Invoke SendMessage,hListVariables,LVM_FINDITEM,-1,ADDR lvfi
.If EAX!=-1 ;i.e if there is such text in the list
;-----Let us check if they are case sensitive same strings--------
MOV EBX,EAX
Invoke GetItemText,hListVariables,EBX,0,ADDR Buffer
Invoke lstrcmp,ESI,ADDR Buffer ;we need case sensitive comparison
.If EAX !=0 ;i.e. if NOT eaxctly the same
;XOR EAX,EAX
MOV EAX,-1
JMP Done
.EndIf
;-----------------------------------------------------------------
Invoke GetItemText, hListVariables, EBX, 1, ADDR Buffer
.If Buffer[0]!=0
LEA EAX,Buffer
MOV lvfi.psz,EAX
Invoke SendMessage,hListStructures,LVM_FINDITEM,-1,ADDR lvfi
.If EAX!=-1 ;i.e such structure found
.Else
;XOR EAX,EAX
MOV EAX,-1
.EndIf
.Else
;XOR EAX,EAX
MOV EAX,-1
.EndIf
.Else
;XOR EAX,EAX
MOV EAX,-1
.EndIf
.EndIf
Done:
RET
IsWordAPIStructure EndP
AutoVariableAndStructureMembersList Proc Uses EBX fInsertConstantsToo:DWORD
Local chrg :CHARRANGE
Local txtrange :TEXTRANGE
Local Buffer[256] :BYTE
Local nCurLine :DWORD
Local BracketFound :DWORD
Invoke SendMessage,hEditor,EM_EXGETSEL,0,ADDR chrg
Invoke SendMessage,hEditor,EM_FINDWORDBREAK,WB_MOVEWORDLEFT,chrg.cpMin
MOV EBX,EAX
Invoke SendMessage,hEditor,EM_EXLINEFROMCHAR,0,chrg.cpMin
;Now EAX is the currentline number
MOV nCurLine,EAX
Invoke GetLineText,hEditor,EAX,Offset tmpLineTxt
Invoke SendMessage,hEditor,EM_LINEINDEX,nCurLine,0
;Now EAX is the first line character
SUB EBX,EAX
DEC EBX
;Now EBX is the position of the start of CURRENT word in the Line Text
.If tmpLineTxt[EBX]==" " || tmpLineTxt[EBX]==VK_TAB || tmpLineTxt[EBX]=="," || tmpLineTxt[EBX]=="[" || tmpLineTxt[EBX]=="=" || tmpLineTxt[EBX]=="<" || tmpLineTxt[EBX]==">"
;New
Invoke ShowWindow,hListStructureMembers,SW_HIDE
.If EBX!=-1 && EBX!=0
MOV tmpLineTxt[EBX],0
LEA EBX,tmpLineTxt
XOR EAX,EAX
@@:
.If BYTE PTR [EBX]==0
.If !EAX
Invoke ShowWindow,hListVariables,SW_HIDE
JMP Finished
.EndIf
.Else
.If (BYTE PTR [EBX]>='a' && BYTE PTR [EBX]<='z') || (BYTE PTR [EBX]>='A' && BYTE PTR [EBX]<='Z')
.If !EAX
MOV EAX,1
.ElseIf EAX==2
MOV EAX,3
.EndIf
.ElseIf BYTE PTR [EBX]==":"
;There is a label-->start looking from this point onwards
XOR EAX,EAX
.ElseIf BYTE PTR [EBX]==" " || BYTE PTR [EBX]==" "
.If EAX==1
MOV EAX,2
.EndIf
;.ElseIf BYTE PTR [EBX] == "," || BYTE PTR [EBX] == "="
; .If EAX==3
; MOV EAX,4
; .EndIf
.EndIf
INC EBX
JMP @B
.EndIf
;PrintDec EAX
;.If fInsertConstantsToo
.If EAX!=3
MOV fInsertConstantsToo,FALSE
.EndIf
;.EndIf
Invoke IsWindowVisible,hListVariables
.If !EAX
Invoke FillVariablesList,fInsertConstantsToo
.EndIf
;Now Get CURRENT WORD
Invoke SendMessage,hEditor,CHM_GETWORD,SizeOf tmpLineTxt,ADDR tmpLineTxt
.If tmpLineTxt[0]!=0
Invoke FindFromListAndSelect,Offset tmpLineTxt,hListVariables
.Else
Invoke ShowWindow,hListVariables,SW_HIDE
.EndIf
.Else
Invoke ShowWindow,hListVariables,SW_HIDE
.EndIf
.ElseIf tmpLineTxt[EBX]=="."
Invoke ShowWindow,hListVariables,SW_HIDE
MOV BracketFound,FALSE
@@:
.If EBX
DEC EBX
.If tmpLineTxt[EBX]==" " || tmpLineTxt[EBX]==" " ;i.e. space or tab
JMP @B
.ElseIf tmpLineTxt[EBX]=="]" && !BracketFound
MOV BracketFound,TRUE
JMP @B
.EndIf
.EndIf
MOV tmpLineTxt[EBX+1],0
@@:
.If EBX
.If tmpLineTxt[EBX]!=" " && tmpLineTxt[EBX]!=" " && tmpLineTxt[EBX]!="," && tmpLineTxt[EBX]!="=" && tmpLineTxt[EBX]!=">" && tmpLineTxt[EBX]!="<" && tmpLineTxt[EBX]!="."
DEC EBX
JMP @B
.EndIf
INC EBX
.EndIf
;Here we have [esi if MOV [ESI].xxxx
;and we have esi if MOV [ ESI].xxxxxx
MOV EAX,EBX
.If BracketFound
.If tmpLineTxt[EBX]!="["
@@:
.If EBX
DEC EBX
.If (tmpLineTxt[EBX]==" " || tmpLineTxt[EBX] == " "); || tmpLineTxt[EBX]=="["
JMP @B
.EndIf
.EndIf
.Else
INC EAX
.EndIf
.If tmpLineTxt[EBX]!="["
;MOV BracketFound,FALSE
JMP HideBoth
.EndIf
.EndIf
MOV EBX,EAX
Invoke lstrcpy,ADDR Buffer,ADDR tmpLineTxt[EBX]
.If BracketFound
Invoke lstrcmpi,ADDR Buffer,Offset szEAX
.If EAX
Invoke lstrcmpi,ADDR Buffer,Offset szEBX
.If EAX
Invoke lstrcmpi,ADDR Buffer,Offset szECX
.If EAX
Invoke lstrcmpi,ADDR Buffer,Offset szEDX
.If EAX
Invoke lstrcmpi,ADDR Buffer,Offset szESI
.If EAX
Invoke lstrcmpi,ADDR Buffer,Offset szEDI
.If EAX
Invoke ShowWindow,hListStructureMembers,SW_HIDE
JMP Finished
.EndIf
.EndIf
.EndIf
.EndIf
.EndIf
.EndIf
CALL IsAnAssumedRegister
.Else
Invoke IsWordAPIStructure,ADDR Buffer
.EndIf
.If EAX!=-1
MOV ECX,EAX
Invoke GetItemText,hListStructures,ECX,1,Offset tmpLineTxt
.If tmpLineTxt[0]!=0 ;If not a variable
Invoke IsWindowVisible,hListStructureMembers
.If !EAX ;i.e not visible
Invoke FillStructureMembersList,Offset tmpLineTxt
.EndIf
;Now Get CURRENT WORD
Invoke SendMessage,hEditor,CHM_GETWORD,SizeOf tmpLineTxt,Offset tmpLineTxt
Invoke FindFromStructureMembersListAndSelect,Offset tmpLineTxt
.EndIf
.Else
Invoke ShowWindow,hListStructureMembers,SW_HIDE
.EndIf
.Else
HideBoth:
Invoke ShowWindow,hListVariables,SW_HIDE
Invoke ShowWindow,hListStructureMembers,SW_HIDE
.EndIf
Finished:
RET
;Returns -1 if not
IsAnAssumedRegister:
;--------------------
.While nCurLine
DEC nCurLine
Invoke SendMessage,hEditor,CHM_ISLINE,nCurLine,ADDR szAssume
.If EAX==0 ;This is an assume line
Invoke GetLineText,hEditor,nCurLine,Offset tmpLineTxt
Invoke LTrim,Offset tmpLineTxt,Offset tmpLineTxt
LEA EBX,tmpLineTxt
ADD EBX,7
Invoke LTrim,EBX,EBX
MOV CL,BYTE PTR [EBX+3]
PUSH ECX
MOV BYTE PTR [EBX+3],0
Invoke lstrcmpi,EBX,ADDR Buffer
POP ECX
.If EAX ;i.e. not the same register
JMP PreviousLine
.EndIf
MOV BYTE PTR [EBX+3],CL
@@:
.If BYTE PTR [EBX]!=0DH
.If BYTE PTR [EBX]==":"
SkipBlanks:
INC EBX
.If (BYTE PTR [EBX]==" " || BYTE PTR [EBX]==" ")
JMP SkipBlanks
.EndIf
MOV BYTE PTR [EBX+3],0
Invoke lstrcmpi,EBX,CTEXT("ptr")
.If !EAX ; :ptr found
ADD EBX,3
SkipMoreBlanks:
INC EBX
.If BYTE PTR [EBX]==" " || BYTE PTR [EBX]==" "; || BYTE PTR [EBX]==0dh
JMP SkipMoreBlanks
.EndIf
PUSH EBX
FindEndOfWord:
INC EBX
.If BYTE PTR [EBX]!=" " && BYTE PTR [EBX]!=" " && BYTE PTR [EBX]!=0dh
JMP FindEndOfWord
.EndIf
MOV BYTE PTR [EBX],0
POP EBX
Invoke IsWordAPIStructure,EBX
.Break
.EndIf
.Else
INC EBX
JMP @B
.EndIf
.EndIf
MOV EAX,-1
.Break
.Else
Invoke SendMessage,hEditor,CHM_ISLINE,nCurLine,ADDR szProc ;Stop searching if we are in proc and reached its top
.If EAX==0
Invoke SendMessage,hEditor,CHM_ISLINE,nCurLine,ADDR szOption
.If EAX!=0
MOV EAX,-1
.Break
.EndIf
.EndIf
.EndIf
PreviousLine:
MOV EAX,-1
.EndW
RETN
AutoVariableAndStructureMembersList EndP
AutoStructuresList Proc
Local chrg:CHARRANGE
Local Buffer[256]:BYTE
Local txtrange:TEXTRANGE
Invoke SendMessage,hEditor,EM_EXGETSEL,0,ADDR chrg
;Go see whether we are after ":"
Invoke SendMessage,hEditor,EM_FINDWORDBREAK,WB_MOVEWORDLEFT,chrg.cpMin
.If EAX ;Manos bug-deleting all before first procedure causes WinAsm Studio to hang
MOV txtrange.chrg.cpMax,EAX
DEC EAX
MOV txtrange.chrg.cpMin,EAX
LEA EAX,Buffer
MOV txtrange.lpstrText,EAX
@@:
Invoke SendMessage,hEditor,EM_GETTEXTRANGE,0 ,ADDR txtrange
.If Buffer[0]==" " || Buffer[0]==VK_TAB
DEC txtrange.chrg.cpMax
DEC txtrange.chrg.cpMin
.If txtrange.chrg.cpMax && txtrange.chrg.cpMin ;Manos bug-deleting all before first procedure causes WinAsm Studio to hang
JMP @B
.Else
RET
.EndIf
.EndIf
.If Buffer[0]==":" ;OK We are after ":"
Invoke SendMessage,hEditor,CHM_GETWORD,SizeOf Buffer,ADDR Buffer
.If Buffer[0]!=0
Invoke FindFromListAndSelect,ADDR Buffer,hListStructures
.Else
Invoke ShowWindow,hListStructures,SW_HIDE
.EndIf
.Else
Invoke ShowWindow,hListStructures,SW_HIDE
.EndIf
.EndIf
RET
AutoStructuresList EndP
AsmAndIncFiles Proc Uses EBX hChild:DWORD
Local lvi:LVITEM
Local tvi:TVITEM
Local Buffer[MAX_PATH]:BYTE
Invoke GetWindowLong,hChild,0
MOV EBX, EAX
.If CHILDWINDOWDATA.dwTypeOfFile[EBX]==1 || CHILDWINDOWDATA.dwTypeOfFile[EBX]==2; NOOOOOOOOOOOO Modules || CHILDWINDOWDATA.dwTypeOfFile[EBX]==51
Invoke GetFilePath,ADDR CHILDWINDOWDATA.szFileName[EBX],ADDR Buffer
Invoke lstrcmpi,ADDR Buffer,Offset ProjectPath
.If EAX==0 ;This file is in the project directory so get only the fileaname+ext
MOV tvi._mask,TVIF_TEXT
LEA EAX, Buffer
MOV tvi.pszText,EAX
MOV tvi.cchTextMax,256
PUSH CHILDWINDOWDATA.hTreeItem[EBX]
POP tvi.hItem
Invoke SendMessage,WinAsmHandles.hProjTree,TVM_GETITEM,0,ADDR tvi
LEA EAX,Buffer
.Else ;This file is in some other directory so get fullpath name+ext
LEA EAX,CHILDWINDOWDATA.szFileName[EBX]
.EndIf
;---------------------------------------------------------
MOV lvi.pszText,EAX
MOV lvi.imask, LVIF_TEXT OR LVIF_IMAGE
MOV lvi.iImage,0
MOV lvi.iSubItem, 0
Invoke SendMessage,hListIncludes,LVM_INSERTITEM,0,ADDR lvi
.EndIf
RET
AsmAndIncFiles EndP
AutoIncludesList Proc Uses EBX nType:DWORD
Local Buffer[2*MAX_PATH] :BYTE ;in case we have a long comment
Local FindFileData :WIN32_FIND_DATA
Local hFindFile :HANDLE
Local lvi :LVITEM
Local chrg :CHARRANGE
Local nLine :DWORD
Local nLineStart :DWORD
Local ftxt :FINDTEXTEX
Local txtrng :TEXTRANGE
Local dwTrials :DWORD
MOV EBX,Offset tmpBuffer
Invoke SendMessage,hEditor,CHM_GETWORD,16383,EBX
.If BYTE PTR [EBX]==0
Invoke ShowWindow,hListIncludes,SW_HIDE
RET
.EndIf
Invoke IsWindowVisible,hListIncludes
.If !EAX ;i.e not visible
Invoke SendMessage,hListIncludes,LVM_DELETEALLITEMS,0,0
.If nType==1 ;i.e. include files
Invoke EnumProjectItems,Offset AsmAndIncFiles
Invoke lstrcpy,ADDR Buffer,pIncludePath
Invoke lstrcat,ADDR Buffer,Offset szSlash
Invoke lstrcat,ADDR Buffer,Offset szAllInc
.Else
Invoke lstrcpy, ADDR Buffer,Offset LibraryPath
Invoke lstrcat, ADDR Buffer,Offset szSlash
Invoke lstrcat, ADDR Buffer,Offset szAllLib
.EndIf
Invoke FindFirstFile,ADDR Buffer,ADDR FindFileData
MOV hFindFile, EAX
.If hFindFile!=INVALID_HANDLE_VALUE
MOV lvi.imask, LVIF_TEXT OR LVIF_IMAGE
MOV lvi.iImage,1
MOV lvi.iSubItem, 0
LEA EAX,FindFileData.cFileName
MOV lvi.pszText,EAX
Invoke SendMessage,hListIncludes,LVM_INSERTITEM,0,ADDR lvi
@@:
Invoke FindNextFile, hFindFile, ADDR FindFileData
.If EAX!=0
Invoke SendMessage,hListIncludes,LVM_INSERTITEM,0,ADDR lvi
JMP @B
.EndIf
.EndIf
Invoke FindClose, hFindFile
.EndIf
Invoke SendMessage,hEditor,EM_EXGETSEL,0,ADDR chrg
;chrg.cpMin is the position of the first character of the selection.
;chrg.cpMax is the position of the last character of the selection.
Invoke SendMessage,hEditor,EM_EXLINEFROMCHAR,0,chrg.cpMin
MOV nLine,EAX
Invoke SendMessage,hEditor,EM_LINEINDEX,nLine,0
;Now eax is the begining of line
MOV nLineStart,EAX
MOV ftxt.chrg.cpMin,EAX
MOV EAX,chrg.cpMin
MOV ftxt.chrg.cpMax,EAX
MOV dwTrials,1
TryAgain:
.If nType==1
.If dwTrials==1
MOV ftxt.lpstrText,CTEXT("include ")
.Else