-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextwords.spf
430 lines (369 loc) · 13.7 KB
/
extwords.spf
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
\ Ôàéë: extwords.spf
\ Àâòîð: VoidVolker
\ Äàòà: 10:39 16/08/2015
\ Âåðñèÿ: 1.72
\ Îïèñàíèå: Ñáîðíèê ðàçëè÷íûõ ïîëåçíûõ ñëîâ
\ SEARCH Fix (èñïðàâëÿåò áàã ïîèñêà â ñòðîêàõ áîëåå 65535 áàéò)
0x90 ' SEARCH 29 + C! \ 0x67 (prefix) -> NOP
\ ### Êîíñòàíòû
2 CELLS CONSTANT DCELL
\ ### Èñïðàâëåíèå áàãîâ
WARNING @ WARNING OFF
\ # Çàïèñü íóëÿ â êîíåö ñòðîêè ñëîâîì PLACE
: PLACE
DUP >R PLACE
0 R> COUNT + C!
;
WARNING !
\ ### Õàêè
\ # Âåòâëåíèå, öèêëû
: IFNOT \ ( flag -- )
?COMP
[COMPILE] IF
0x85 HERE 5 - C! \ Õàê: ïîäìåíÿåì ñêîìïèëèðîâàííóþ ðàíåå èíñòðóêöèþ JE(0x84) íà JNE(0x85)
\ Âûñîêîóðîâíåâûé âàðèàíò:
\ POSTPONE 0= [COMPILE] IF
; IMMEDIATE
: WHILENOT
?COMP
[COMPILE] WHILE
0x85 HERE 5 - C! \ Õàê: ïîäìåíÿåì ñêîìïèëèðîâàííóþ ðàíåå èíñòðóêöèþ JE(0x84) íà JNE(0x85)
\ Âûñîêîóðîâíåâûé âàðèàíò:
\ POSTPONE 0= [COMPILE] WHILE
; IMMEDIATE
: UNTILNOT
?COMP
[COMPILE] UNTIL
0x85 HERE 5 - C! \ Õàê: ïîäìåíÿåì ñêîìïèëèðîâàííóþ ðàíåå èíñòðóêöèþ JE(0x84) íà JNE(0x85)
\ Âûñîêîóðîâíåâûé âàðèàíò:
\ POSTPONE 0= [COMPILE] UNTIL
; IMMEDIATE
\ # Ñíÿòèå îãðàíè÷åíèÿ íà ìàêñèìàëüíóþ äëèíó ïóòè äëÿ öèêëà FOR-FILES
\ : ffHackMaxPath \ ( num -- )
\ DUP ffMask DUP ['] ffPath 5 + ! + ['] /FF-BUF 5 + !
\ ;
\ 1000 ffHackMaxPath \ 1000 - ìîæíî çàìåíèòü íà ëþáîå íóæíîå ÷èñëî
\ Äëÿ íòôñ ìàêñèìàëüíàÿ äëèíà ïóòè ñîñòàâëÿåò 32 767 ñèìâîëîâ Þíèêîäà, ïðè ýòîì ìàêñèìàëüíàÿ äëèíà èìåíè ôàéëà 255 áàéò
: A@XT \ ( addr -- xt ) \ Èçâëå÷ü âûçûâàåìûé òîêåí èç àäðåñà. Âûçîâ(call) -> E8...... <- ñìåùåíèå, îòíîñèòåëüíî òåêóùåãî àäðåñà â ñòåêå âîçâðàòîâ (ôàêòè÷åñêè ñëåäóþùèé âûçîâ, ïîñëå ýòîãî)
DUP 1+ @ 5 + +
;
\ ### Óìíîæèòåëè Êèëî- Ìåãà- Ãèãà-
: Kb 10 LSHIFT ;
: Mb 20 LSHIFT ;
: Gb 30 LSHIFT ;
\ ### Ñòåê
: -ROT ROT ROT ;
\ # Ìàòåìàòè÷åñêèå îïåðàöèè
: D>0 \ ( ud -- ? )
0 0 D>
;
\ ### Ïåðåìåííûå è ìàññèâû
: 0ALLOT \ ( len -- ) \ Âûäåëåíèå ïàìÿòè c î÷èñòêîé
HERE SWAP
DUP ALLOT
ERASE
;
: QUAN 0 VALUE ;
: ARRAY \ ( size -- ) ( " name" -> ) \ Ñîçäàòü ìàññèâ ðàçìåðîì size áàéò è èíèöèðîâàòü âñå åãî ÿ÷åéêè íóëåì.
CREATE 0ALLOT ;
: USER-ARRAY USER-CREATE USER-ALLOT ;
\ ### Ñòðîêè
: BACK-SEARCH { a u a1 u1 \ a2 u2 -- a2 u2 ? } \ Ïîèñê ñ êîíöà
0
a TO a2 u TO u2
a u +
u 0 DO
DUP I -
u1 a1 u1 COMPARE
IF ELSE
DUP I - TO a2
I TO u2
NIP -1 SWAP
LEAVE
THEN
LOOP DROP
a2 u2 ROT
;
: StringGetPos { a1 u1 a2 u2 -- pos }
a1 u1 a2 u2 SEARCH IF DROP a1 - 1+ ELSE 2DROP 0 THEN ;
: CropFromString \ ( a1 u1 a2 u2 -- a3 u3 ) \ Îáðåçàòü ñòðîêó 1 íà÷èíàÿ ñî ñòðîêè 2
3 PICK >R SEARCH IF DROP R@ - R> SWAP THEN ;
: CropAfterString \ ( a u a1 u1 -- a2 u2 ) \ Îáðåçàòü ñòðîêó 1 ïîñëå ñòðîêè 2
DUP >R 3 PICK >R SEARCH IF DROP R@ - R> SWAP R> + THEN ;
: CharReplace \ ( a u char1 char2 -- a u ) \ Çàìåíèòü â ñòðîêå ñèìâîë 1 íà ñèìâîë 2 è îñòàâèòü ñòðîêó íà ñòåêå
2OVER OVER + SWAP DO \ a u char1 char2
OVER I C@ = IF DUP I C! THEN
LOOP
2DROP
;
: CropFromStringEnd \ ( a1 u1 a2 u2 -- a3 u3 ) \ Îáðåçàòü ñòðîêó 1 íà÷èíàÿ ñî ñòðîêè 2 äëÿ ïåðâîãî ñîâïàäåíèÿ ñ êîíöà ñòðîêè
3 PICK >R BACK-SEARCH IF DROP R@ - R> SWAP THEN
;
: CropAfterStringEnd \ ( a u a1 u1 -- a2 u2 ) \ Îáðåçàòü ñòðîêó 1 ïîñëå ñòðîêè 2 äëÿ ïåðâîãî ñîâïàäåíèÿ ñ êîíöà ñòðîêè
DUP >R 3 PICK >R BACK-SEARCH IF DROP R@ - R> SWAP R> + THEN
;
: StringSplit { a u a1 u1 -- a2 u2 a3 u3 TRUE | a u a1 u1 FALSE }
a u a1 u1 SEARCH IF
OVER a - a SWAP \ a4 u4 a2 u2
2SWAP \ a2 u2 a4 u4
u1 - SWAP u1 + SWAP \ a2 u2 a3 u3
TRUE
ELSE
2DROP
a u a1 u1
FALSE
THEN
;
: GET-SUBST { a0 u0 a1 u1 a2 u2 -- a3 u3 | a0 u0 } \ Ïîëó÷èòü ïîäñòðîêó a3 u3 èç ñòðîêè a0 u0, îãðàíè÷åííóþ a1 u1 è a2 u2. Åñëè ïîäñòðîêà íå íàéäåíà - âåðíóòü ïóñòóþ ñòðîêó.
a0 u0 a1 u1 SEARCH
IF
u1 u1 NEGATE D+ 2DUP
a2 u2 SEARCH
IF
NIP OVER - ABS NIP
ELSE
2DROP 2DROP S" "
THEN
ELSE
2DROP S" "
THEN
;
: GET-SUBST-ANY { a0 u0 a1 u1 a2 u2 -- a3 u3 | a0 u0 } \ Ïîëó÷èòü ïîäñòðîêó a3 u3 èç ñòðîêè a0 u0, îãðàíè÷åííóþ a1 u1 è a2 u2 èëè îãðàíè÷åííóþ a2 u2 è a1 u1 - ò.å. ïîðÿäîê ñòðîê-îãðàíè÷èòåëåé íå âàæåí. Åñëè ïîäñòðîêà íå íàéäåíà - âåðíóòü ïóñòóþ ñòðîêó.
a0 u0 a1 u1 SEARCH IF
a0 u0 a2 u2 SEARCH IF
ROT - ABS >R MIN R>
u1 u2 MAX DUP NEGATE D+
ELSE
2DROP 2DROP S" "
THEN
ELSE
2DROP S" "
THEN
;
: REL-PATH { a u -- a1 u1 } \ Ïîëó÷èòü îòíîñèòåëüíûé ïóòü C:\any\path\file.txt -> C:\any\path\
a
a u +
BEGIN
1-
DUP C@ [CHAR] \ =
OVER C@ [CHAR] / = OR
OVER a = OR
UNTIL
a - 1+
;
: SPLACE \ ( a u buf -- )
>R
DUP R@ ! \ Ñîõðàíÿåì ñ÷åò÷èê ñòðîêè
R@ CELL+ \ Ïðîïóñêàåì ñ÷åò÷èê
SWAP CMOVE \ Ïåðåìåùàåì ñòðîêó
0 R@ @ R> CELL+ + ! \ Çàïèñûâàåì â êîíåö ñòðîêè íîëü (îïöèîíàëüíî)
;
: SCOUNT \ ( buf -- a u )
DUP CELL+ SWAP @
;
: +SPLACE \ ( a u buf -- )
DUP >R \ a u buf R: buf
SCOUNT + \ a u bufEnd R: buf
OVER R@ +! \ a u bufEnd
SWAP CMOVE
0 R> SCOUNT + !
;
: SCONSTANT \ ( " èìÿ" " ëþáîé òåêñò äî êîíöà ñòðîêè" -> ) ( -- a u ) \ Ñòðîêîâàÿ êîíñòàíòà
: 0 PARSE [COMPILE] SLITERAL POSTPONE ; \ ]
;
\ # Ñòðîêîâûé CASE
: SCASE ( -> )
!CSP
; IMMEDIATE
: SOF
POSTPONE 2OVER POSTPONE COMPARE
[COMPILE] IFNOT POSTPONE 2DROP
; IMMEDIATE
: ENDSOF
[COMPILE] ELSE
; IMMEDIATE
: ENDSCASE
POSTPONE 2DROP BEGIN SP@ CSP@ <>
WHILE [COMPILE] THEN REPEAT -CSP
; IMMEDIATE
\ ### Ïàðî÷êà ñëîâ äëÿ ðàáîòû ñ VALUE è âåêòîðàìè
: USES \ ( " word_name" " name_vect" -> ) \ Çàïèñàòü âûïîëíèìûé òîêåí ñëåäóþùåãî ñëîâà â âåêòîð. Çàìåíà êîíñòðóêöèè ['] ... TO ... Ïðèìåð: ['] any_word TO any_vect_or_value --> USES any_word any_vect_or_value
STATE @
IF
POSTPONE ['] POSTPONE TO
ELSE
' [COMPILE] TO
THEN
; IMMEDIATE
: FROM \ ( " name" -> xt ) \ Ïîëó÷èòü çíà÷åíèå âåêòîðà.
' 5 +
STATE @ IF LIT, POSTPONE @ ELSE @ THEN
; IMMEDIATE
: +TO \ ( n -- ) ( "name" -> ) \ Ïðèáàâèòü çíà÷åíèå ê VALUE èëè USER-VALUE ïåðåìåííîé
' DUP >R A@XT ['] _USER-VALUE-CODE = \ ? \ äëÿ user value
STATE @ IF
IF
R@ COMPILE,
POSTPONE +
R> 9 + COMPILE,
ELSE
R> >BODY
POSTPONE LITERAL
POSTPONE +!
THEN
ELSE
IF
R@ EXECUTE +
R> 9 + EXECUTE
ELSE
R> >BODY +!
THEN
THEN
; IMMEDIATE
\ ### Ïå÷àòü â êîíñîëè
: .B \ ( num -- ) \ Ðàñïå÷àòàòü ÷èñëî ñî ñòåêà â áèíàðíîé ñèñòåìå ñ÷èñëåíèÿ
BASE @ SWAP 2 BASE ! . BASE ! ;
: .D \ ( num -- ) \ Ðàñïå÷àòàòü ÷èñëî ñî ñòåêà â äåñÿòè÷íîé ñèñòåìå ñ÷èñëåíèÿ
BASE @ SWAP DECIMAL . BASE ! ;
: .H \ ( num -- ) \ Ðàñïå÷àòàòü ÷èñëî ñî ñòåêà â øåñòíàäöàòèðè÷íîé ñèñòåìå ñ÷èñëåíèÿ
BASE @ SWAP HEX . BASE !
;
: PRINT \ ( az -- ) \ Ðàñïå÷àòàòü az ñòðîêó
BEGIN DUP C@ DUP WHILE
EMIT 1+
REPEAT
2DROP
;
\ ### Ïå÷àòü ñòåêà
\ Ñëîâî .SN åñòü â disasm.f
: .SN \ ( n -- ) \ Ðàñïå÷àòàòü n âåðõíèõ ýëåìåíòîâ ñòåêà
>R BEGIN
R@
WHILE
SP@ R@ 1- CELLS + @ DUP 0<
IF DUP U>D <# #S #> TYPE
." (" ABS 0 <# #S [CHAR] - HOLD #> TYPE ." ) " ELSE . THEN
R> 1- >R
REPEAT RDROP
;
:NONAME
STATE @ 0=
IF
DEPTH 10 < IF
DEPTH IF
." Ok ( " DEPTH .SN ." )" CR
ELSE
." Ok" CR
THEN
ELSE
." Ok ( [" DEPTH 0 <# #S #> TYPE ." ].. "
5 .SN ." )" CR
THEN
THEN
; TO OK
\ ### Îêíà
WINAPI: WindowFromPoint user32.dll
: WIN-FROM-POINT \ ( -- hwnd ) \ Ïîëó÷èòü õýíäë îêíà ïîä êóðñîðîì
MOUSE-POS SWAP WindowFromPoint
;
: GET-WTEXT \ ( hwnd -- a u ) \ Ïîëó÷èòü òåêñò îêíà ïî åãî õýíäëó. Ðàáîòàåò è äëÿ äî÷åðíèõ îêîí. Ìàêñèìàëüíûé ðàçìåð òåêñòà - 256 áàéò.
PAD 256 ROT 13 SWAP SendMessageA PAD SWAP
;
WINAPI: GetParent USER32.DLL
WINAPI: GetClassNameA User32.dll
: GET-WCLASS \ ( hwnd -- a u ) \ Ïîëó÷èòü êëàññ îêíà ïî åãî õýíäëó. Ðàáîòàåò è äëÿ äî÷åðíèõ îêîí
256 PAD ROT GetClassNameA PAD SWAP
;
WINAPI: GetParent USER32.DLL
: TOP-PARENT-WINDOW \ ( hwnd-child -- hwnd-parent ) \ Ïîëó÷èòü ðîäèòåëüñêîå îêíî âåðõíåãî óðîâíÿ ïî õýíäëó äî÷åðíåãî îêíà
BEGIN DUP GetParent DUP WHILE
NIP
REPEAT
DROP
;
: WinActivate ( hwnd -- )
DUP PUSH-WINDOW DROP \ TO active-window#
DUP IsIconic
IF 9 SWAP ShowWindow DROP ELSE DROP THEN \ #define SW_RESTORE 9
;
\ ### Ïîòîêè
: STOP-THEARD \ ( tid -- ) \ Îñòàíîâèòü ïîòîê ñ èäåíòèôèêàòîðîì tid
?DUP IF
0 1 OpenThread ?DUP
IF STOP THEN
THEN
;
\ ### Ôàéëû
: FILE-MD5 \ ( a u -- a1 u1 ) \ Ïîëó÷èòü MD5 õýø äëÿ ôàéëà a u
PAD 256 ERASE
PAD ROT ROT MD5File DROP
PAD MD5String
;
: FILE-BLOCK { offset size \ h buf -- } \ ( a0 u0 offset size -- a1 u1 ) \ Çàãðóçèòü â ïàìÿòü áëîê ôàéëà íà÷èíàÿ ñ offset è äëèíîé size, îòðèöàòåëüíîå ñìåùåíèå ñ÷èòàåòñÿ ñìåùåíèåì ñ êîíöà ôàéëà
R/O OPEN-FILE-SHARED THROW TO h
h FILE-SIZE THROW \ ud
offset size + S>D \ ud ud1
2OVER \ ud ud1 ud
D< IF \ ud \ Ïðîâåðÿåì ðàçìåð ôàéëà è ñìåùåíèå - èíà÷å âûõîäèì
offset 0< IF \ ud \ Åñëè ñìåùåíèå îòðèöàòåëüíîå - òî îòñ÷èòûâàåì ñ êîíöà ôàéëà
offset S>D D+ \ ud1 \ Ïðèáàâëÿåì îòðèöàòåëüíîå ñìåùåíèå ê äëèíå ôàéëà - ïîëó÷àåì ñìåùåíèå îò êîíöà ôàéëà
ELSE
2DROP offset S>D \ ud2 \ Âûêèäûâàåì ðàçìåð ôàéëà - îí áîëüøå íå íóæåí, âìåñòî íåãî èñïîëüçóåì ñìåùåíèå êàê ñìåùåíèå îò íà÷àëà ôàéëà
THEN
h REPOSITION-FILE THROW \ Ñìåùàåì ïîçèöèþ â ôàéëå
size CELL+ ALLOCATE THROW TO buf \ Âûäåëÿåì ïàìÿòü äëÿ ÷òåíèÿ áëîêà ôàéëà
buf size h
READ-FILE THROW \ u1 \ ×èòàåì íóæíûé áëîê. Íà ñòåêå - ðàçìåð ïðî÷èòàííîãî áëîêà èç ôàéëà
buf SWAP \ a1 u1
ELSE
2DROP
S" "
THEN
h CLOSE-FILE THROW
;
: FILE-REST { offset \ h buf -- } \ ( a0 u0 offset -- a1 u1 ) \ Çàãðóçèòü â ïàìÿòü áëîê ôàéëà íà÷èíàÿ ñ offset è äî êîíöà ôàéëà, îòðèöàòåëüíîå ñìåùåíèå ñ÷èòàåòñÿ ñìåùåíèåì ñ êîíöà ôàéëà
R/O OPEN-FILE-SHARED THROW TO h
h FILE-SIZE THROW \ ud
offset S>D \ ud ud1
2OVER \ ud ud1 ud
D< IF \ ud \ Ïðîâåðÿåì ðàçìåð ôàéëà è ñìåùåíèå - èíà÷å âûõîäèì
2DUP \ ud ud
offset 0< IF \ ud ud \ Åñëè ñìåùåíèå îòðèöàòåëüíîå - òî îòñ÷èòûâàåì ñ êîíöà ôàéëà
offset S>D D+ \ ud ud1 \ Ïðèáàâëÿåì îòðèöàòåëüíîå ñìåùåíèå ê äëèíå ôàéëà - ïîëó÷àåì ñìåùåíèå îò êîíöà ôàéëà
ELSE
2DROP offset S>D \ ud ud1 \ Âûêèäûâàåì ðàçìåð ôàéëà - îí áîëüøå íå íóæåí, âìåñòî íåãî èñïîëüçóåì ñìåùåíèå êàê ñìåùåíèå îò íà÷àëà ôàéëà
THEN
2SWAP \ ud1 ud
2OVER D- D>S -ROT \ u1 ud1
h REPOSITION-FILE THROW \ u1 \ Ñìåùàåì ïîçèöèþ â ôàéëå
DUP CELL+ ALLOCATE THROW TO buf \ u1 \ Âûäåëÿåì ïàìÿòü äëÿ ÷òåíèÿ áëîêà ôàéëà
buf SWAP h \ a1 u1 h
READ-FILE THROW \ u1 \ ×èòàåì íóæíûé áëîê. Íà ñòåêå - ðàçìåð ïðî÷èòàííîãî áëîêà èç ôàéëà
buf SWAP \ a1 u1
ELSE
2DROP
S" "
THEN
h CLOSE-FILE THROW
;
\ ### Âðåìÿ èñïîëíåíèÿ
\ Âçÿòî èç disasm.f èç äèñòðèáóòèâà ñïô
\ Ruvim Pinka additions:
: [DEFINED] ( -- f ) \ "name"
NextWord SFIND IF DROP TRUE ELSE 2DROP FALSE THEN
; IMMEDIATE
: [UNDEFINED] ( -- f ) \ "name"
POSTPONE [DEFINED] 0=
; IMMEDIATE
\ ### Ðàçíîå
\ # Êëàâèàòóðà è ïîëüçîâàòåëüñêèé ââîä
[DEFINED] KEY-PRESSED? [IF] \ Âêëþ÷àåòñÿ ïðè ïîäêëþ÷åíèè ïëàãèíà keystate.spf
: WAIT-KUP \ ( VK -- ) \ Æäàòü ïîäíÿòèÿ êíîïêè ñ êîäîì VK
BEGIN DUP KEY-PRESSED? WHILE
50 PAUSE
REPEAT DROP
;
[THEN]
WINAPI: BlockInput USER32.DLL
: BlockTheInput TRUE BlockInput DROP ;
: UnblockTheInput FALSE BlockInput DROP ;