-
Notifications
You must be signed in to change notification settings - Fork 5
/
wildchar.asm
164 lines (159 loc) · 2.66 KB
/
wildchar.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
COMMON_SETTING equ 530043h;汉字、标点和常用符号
CJK_WORD EQU 570043h;包括所有汉字与日语当用汉字
JAPANESE_KANA equ 4b004ah;日语平假名与片假名
FULL_ANGLE EQU 410046h;全角字符
HALF_ANGLE EQU 410048h;半角字符
GENERAL_SYMBOL EQU 530047h;通用符号,包括所有标点和各种符号(只含全角)
DIGITS_HA EQU 480044h;半角数字
.code
;
_WildcharMatchW proc uses esi edi ebx _lpszPattern,_lpszStr
mov edi,_lpszPattern
mov esi,_lpszStr
.if !word ptr [esi]
xor eax,eax
ret
.endif
.while word ptr [edi]
mov ax,[edi]
.if ax=='*'
add edi,2
cmp word ptr [edi],0
je matchSuccess
mov ebx,edi
.repeat
add edi,2
mov ax,[edi]
.until ax=='*' || ax=='?' || ax=='%' || !ax
sub edi,ebx
shr edi,1
inc edi
mov ecx,edi
mov edi,ebx
mov eax,ecx
.repeat
push esi
push edi
mov ecx,eax
repe cmpsw
.if !ecx
add esp,8
sub edi,2
sub esi,2
jmp nextMatch
.endif
pop edi
pop esi
add esi,2
.until !word ptr [esi]
jmp matchFail
.elseif ax=='\'
add edi,2
mov ax,[edi]
cmp ax,'*'
je singleComp
cmp ax,'%'
je singleComp
cmp ax,'?'
je singleComp
cmp ax,'\'
je singleComp
.if ax=='t'
add edi,2
lodsw
cmp ax,9
jne matchFail
.continue
.endif
.elseif ax=='?'
add esi,2
add edi,2
.elseif ax=='%'
mov eax,[edi+2]
mov cx,[esi]
invoke _CharMatchW
or eax,eax
je matchFail
add edi,6
add esi,2
.else
singleComp:
cmpsw
jne matchFail
.endif
nextMatch:
.endw
cmp word ptr [esi],0
jne matchFail
matchSuccess:
mov eax,1
ret
matchFail:
xor eax,eax
ret
_WildcharMatchW endp
;
_CharMatchW proc
.if eax==COMMON_SETTING
cmp cx,2000h
jb charNo
cmp cx,22ffh
jbe charYes
cmp cx,3000h
jb charNo
cmp cx,303fh
jbe charYes
cmp cx,4e00h
jb charNo
cmp cx,9fbfh
jbe charYes
cmp cx,0ff00h
jb charNo
cmp cx,0ff65h
jbe charYes
jmp charNo
.elseif eax==JAPANESE_KANA
cmp cx,3040h
jb charNo
cmp cx,30ffh
ja charNo
.elseif eax==CJK_WORD
cmp cx,4e00h
jb charNo
cmp cx,9fbfh
ja charNo
.elseif eax==FULL_ANGLE
or ch,ch
je charNo
jne charYes
.elseif eax==HALF_ANGLE
or ch,ch
je charYes
jne charNo
.elseif eax==GENERAL_SYMBOL
cmp cx,2000h
jb charNo
cmp cx,22ffh
jbe charYes
cmp cx,3000h
jb charNo
cmp cx,303fh
jbe charYes
cmp cx,0ff00h
jb charNo
cmp cx,0ff65h
jbe charYes
jmp charNo
.elseif eax==DIGITS_HA
cmp cx,30h
jb charNo
cmp cx,39h
ja charNo
.endif
charYes:
mov eax,1
ret
charNo:
xor eax,eax
ret
_CharMatchW endp