-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathch.cmd
414 lines (373 loc) · 8.1 KB
/
ch.cmd
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
@echo off
setlocal enabledelayedexpansion
set "i=0"
for %%i in (%*) do set /a "i+=1"
if !i! neq 1 goto:man
set "map=ASM;AU3;C;CMD;CS;JS;JSN;HTA;KIX;LUA;PHP;PL;PS1;PY;RB;SH;TCL;VBN;VBS;WSF"
call:toUpper %1
for %%i in (!map!) do if /i "!$!" equ "%%i" set "#=%%i"
if /i "!#!" equ "" goto:man
set "i=0"
for /f "tokens=1 delims=:" %%i in (
'findstr /bn ":!#! :eof_!#!" "%~f0"'
) do set "arr.!i!=%%i"&set /a "i+=1"
set /a "arr.0=arr.0+1", "arr.1=arr.1-1"
3<"%~f0" (
for /l %%i in (1, 1, !arr.1!) do (
set /p s=<&3
if %%i geq !arr.0! echo:!s!
set "s="
)
)>source.cmd
endlocal
exit /b
:toUpper
for /f "tokens=2 delims=." %%i in (
'2^>^&1 find /v "" .%1'
) do set "$=%%i"
exit /b
:man
for %%i in (
"Usage: %~n0 [extension]"
""
"Where 'extension' is one of the follow:"
" asm - CMD\Assembler example (not template)"
" au3 - CMD\AutoIt template"
" cmd - pure cmd template"
" c - CMD\C template"
" cs - CMD\CSharp template"
" js - CMD\JavaScript (MS JScript or NodeJS)"
" jsn - CMD\JScript.NET template"
" hta - CMD\HTA template"
" kix - CMD\Kixtart template"
" lua - CMD\Lua template"
" php - CMD\PHP template"
" pl - CMD\Perl template"
" ps1 - CMD\PowerShell template"
" py - CMD\Python template"
" rb - CMD\Ruby template"
" sh - CMD\Bash template"
" tcl - CMD\Tcl template"
" vbn - CMD\VB.NET template"
" vbs - CMD\VBscript template"
" wsf - CMD\WSF template"
""
"Note that 'asm' requires NASM (tested version 2.12.02) and"
"link.exe (included into MS toolkit of code compilation)."
"In fact, you can also use GCC."
) do echo:%%~i
exit /b
:ASM
;@echo off
; setlocal
; set "obj="%~dpn0.obj""
; set "lnk=link.exe /nologo /subsystem:console"
; set "lnk=%lnk% %obj% /out:app.exe msvcrt.lib"
; set "app="%~dp0app.exe""
; nasm -fwin32 "%~f0"
; %lnk%
; app.exe
; for %%i in (%obj% %app%) do (
; if exist %%i del /f /q %%i
; )
; endlocal
;exit /b
global _main
extern _printf
section .data
str: db 'Sample code', 0xA, 0
section .text
_main:
sub esp, 4
lea eax, [str]
mov [esp], eax
call _printf
add esp, 4
ret
:eof_ASM
:AU3
;@echo off
; setlocal
; 2>nul AutoIt3.exe "%~f0" %*
; endlocal
;exit /b
; place your code here
:eof_AU3
:C
/* 2>nul
@echo off
cl /nologo /MD /O2 /Feapp.exe /Tc "%~f0">nul
app.exe
del /f /q app.exe "%~dpn0.obj
exit /b
*/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void StdOutClear(void) {
COORD coord;
SHORT width;
PCHAR space;
HANDLE hndl;
CONSOLE_SCREEN_BUFFER_INFO csbi;
if (INVALID_HANDLE_VALUE != (
hndl = GetStdHandle(STD_OUTPUT_HANDLE
))) {
if (GetConsoleScreenBufferInfo(hndl, &csbi)) {
coord.X = csbi.dwCursorPosition.X;
coord.Y = csbi.dwCursorPosition.Y - 1;
if (SetConsoleCursorPosition(hndl, coord)) {
width = csbi.dwSize.X - 1;
space = malloc(width);
memset(space, ' ', width);
space[width] = '\0';
printf("%s", space);
free(space);
coord.Y = csbi.dwCursorPosition.Y - 2;
SetConsoleCursorPosition(hndl, coord);
}
}
}
}
int main(void) {
StdOutClear();
// place your code here
return 0;
}
:eof_C
:CMD
@echo off
setlocal enabledelayedexpansion
endlocal
exit /b
:eof_CMD
:CS
/* 2>nul
@echo off
setlocal enabledelayedexpansion
set "key=HKLM\SOFTWARE\Microsoft\.NETFramework"
for /f "tokens=3" %%i in (
'2^>nul reg query %key% /v InstallRoot'
) do set "root=%%i"
if /i "%root%" equ "" echo:Could not find .NET root.
for /f %%i in ('dir /ad /b "%root%v*"') do (
set "path=%root%%%i;!path!"
)
for %%i in (csc.exe) do (
if exist "%%~$PATH:i" set "csc=%%~$PATH:i"
)
set "arg=/nologo /t:exe /out:app.exe /optimize+"
set "arg=%arg% /debug:pdbonly /define:CODE_ANALYSIS"
%csc% %arg% "%~f0"
app.exe
endlocal
exit /b
*/
using System;
internal sealed class Program {
static void Clear() {
Console.CursorTop = Console.CursorTop - 1;
Console.Write(new String(' ', Console.BufferWidth));
Console.CursorTop = Console.CursorTop - 2;
}
static void Main() {
Clear();
/* place your code here */
}
}
:eof_CS
:JS
0</* :
@echo off
setlocal
rem 2>nul node "%~f0" %*
cscript /nologo /e:jscript "%~f0" %*
endlocal
exit /b */0;
// place your code here
:eof_JS
:JSN
@set @js=0 /*
@echo off
set @js=
setlocal enabledelayedexpansion
set "key=HKLM\SOFTWARE\Microsoft\.NETFramework"
for /f "tokens=3" %%i in (
'2^>nul reg query %key% /v InstallRoot'
) do set "root=%%i"
if /i "%root%" equ "" echo:Could not find .NET root.
for /f %%i in ('dir /ad /b "%root%v*"') do (
set "path=%root%%%i;!path!"
)
for %%i in (jsc.exe) do (
if exist "%%~$PATH:i" set "jsc=%%~$PATH:i"
)
set "arg=/nologo /t:exe /out:app.exe /debug+ "%~f0""
%jsc% %arg%
app.exe
endlocal
exit /b
*/
// place your code here
:eof_JSN
:HTA
<!-- :
@start mshta "%~f0"&exit /b
-->
<html>
<head>
<title></title>
<meta name="author" content="" />
<hta:application id=""
applicationname=""
border="thin"
contextmenu="no"
maximizebutton="no"
minimizebutton="no"
scroll="no"
singleinstance="yes"
sysmenu="yes"
version="1.0" />
</head>
<body>
</body>
</html>
:eof_HTA
:KIX
;@echo off
; setlocal
; 2>nul Kix32.exe "%~f0" %*
; endlocal
;exit /b
; place your code here
:eof_KIX
:LUA
:: --[[
@echo off
setlocal
2>nul lua "%~f0" %*
endlocal
exit /b
--]]
_____ ::
-- place your code here
:eof_LUA
:PHP
:<?php /*
@echo off
setlocal
2>nul php "%~f0" %*
endlocal
exit /b
*/
echo "\r";
/* place your code here */
?>
:eof_PHP
:PL
@echo off
setlocal
2>nul perl -x "%~f0" %*
endlocal
exit /b
#!perl
# place your code here
:eof_PL
:PS1
<# :
@echo off
setlocal
powershell /noprofile /executionpolicy bypass^
"&{[ScriptBlock]::Create((Get-Content '%~f0') -join [Char]10).Invoke(@(&{$args}%*))}"
endlocal
exit /b
#>
# place your code here
:eof_PS1
:PY
1>2# : ^
'''
@echo off
setlocal
2>nul python "%~f0" %*
endlocal
exit /b
'''
# place your code here
:eof_PY
:RB
@echo off
setlocal
2>nul ruby -x "%~f0" %*
endlocal
exit /b
#!ruby
# place your code here
:eof_RB
:SH
:<<EOF
@echo off
setlocal
2>nul bash "%~f0" %*
ebdlocal
exit /b
EOF
# place your code here
:eof_SH
:TCL
::set comment {
@echo off
setlocal
2>nul tclsh86t "%~f0" %*
endlocal
exit /b
}
# place your code here
:eof_TCL
:VBN
rem^ & @echo off
rem^ & setlocal enabledelayedexpansion
rem^ & set "key=HKLM\SOFTWARE\Microsoft\.NETFramework"
rem^ & for /f "tokens=3" %%i in ('2^>nul reg query %key% /v InstallRoot') do set "root=%%i"
rem^ & if /i "%root%" equ "" echo:Could not find .NET root.
rem^ & for /f %%i in ('dir /ad /b "%root%v*"') do set "path=%root%%%i;!path!"
rem^ & for %%i in (vbc.exe) do if exist "%%~$PATH:i" set "vbc=%%~$PATH:i"
rem^ & set "arg=/nologo /t:exe /out:app.exe /optimize+"
rem^ & set "arg=%arg% /debug:pdbonly /define:CODE_ANALYSYS"
rem^ & %vbc% %arg% "%~f0"
rem^ & app.exe
rem^ & endlocal
rem^ & exit /b
Imports System
Friend NotInheritable Class Program
Private Shared Sub Clear
Console.CursorTop = Console.CursorTop - 1
Console.Write(New String(" ", Console.BufferWidth))
Console.CursorTop = Console.CursorTop - 2
End Sub
Shared Sub Main
Clear
' place your code here
End Sub
End Class
:eof_VBN
:VBS
::'@cscript /nologo /e:vbscript "%~f0" %*&exit /b
' place your code here
:eof_VBS
:WSF
<?xml : version="1.0" encoding="utf-8"?> ^<!-- :
@cscript /nologo "%~f0?.wsf" //job:JS //job:VBS&exit /b
-->
<package>
<job id="JS">
<script language="JScript"><![CDATA[
]]></script>
</job>
<job id="VBS">
<script language="VBScript"><![CDATA[
]]></script>
</job>
</package>
:eof_WSF