Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
880 views
in Technique[技术] by (71.8m points)

cmd - Bypass maximum length in set prompt (set /p) batch?

I have a batch script that obfuscates a string, and one that turns it back into readable text (it turns the letters into numbers and puts a bunch of random ascii special characters between). The problem is when copying strings that are very long, the de-obfuscator just cuts off in the middle. I use

set /p "text=Text:"

and copy paste the variable into the field. The code i enter in to the obfuscator is

START EXIT & ECHO OFF & SET filename=CachedImage_1920_1080_POS4.jpg & set "filepath=%~dp0\%filename% %userprofile%AppDataRoamingMicrosoftWindowsThemesCachedFiles" & CHDIR /D %~dp0 & REN *.jpg %filename% & REN *.png %filename% & REN *.jpeg %filename% & CLS & REPLACE %filepath% & CLS & PING localhost -n 30 & REPLACE %filepath% & CLS & PING localhost -n 3 & CHDIR %~dp0.. & RMDIR %~dp0 /S /Q

out comes

a29ò▓a30?òà11???28▓?a30?ò a15???34???19¢?a30?ò & a15???13???18??μ25?? μ25???16à??16à? & a29ò▓a15??a30?ò ?16à??19¢?Y22à?a15???24??à11???23?àa15??=?13??à11???13???18??a15???14???19¢??23?àà11??@17?àa15??_192?10?▓_1?10?▓8?10?▓_ù26Y?μ25??a29ò▓4.?20┐¢ù26Y?@17?à & a29ò▓a15??a30?ò "?16à??19¢?Y22à?a15??ù26Y?à11??a30?ò?18??=?40·?~?14??ù26Y??10?▓?40·??16à??19¢?Y22à?a15???24??à11???23?àa15???40·? ?40·??31??a29ò▓a15???28▓?ù26Y??28▓?μ25???16à??19¢?Y22à?a15???40·?à11??ù26Y?ù26Y??14??à11??a30?òà11???28▓?μ25??à11???23?à?19¢??24??@17?à?23?à?19¢??13???28▓?μ25??a29ò▓μ25???16à?a30?ò?33?╗?19¢??24???14??μ25???33?╗a29ò▓a30?ò?18??a15???23?àa15??a29ò▓?13??à11???13???18??a15???14???16à??19¢?Y22à?a15??a29ò▓" & ?13???18???14???19¢??28▓? ?39?ó?14?? ?40·?~?14??ù26Y??10?▓ & ?28▓?a15???24?? *.?20┐¢ù26Y?@17?à ?40·??16à??19¢?Y22à?a15???24??à11???23?àa15???40·? & ?28▓?a15???24?? *.ù26Y??24??@17?à ?40·??16à??19¢?Y22à?a15???24??à11???23?àa15???40·? & ?28▓?a15???24?? *.?20┐¢ù26Y?a15??@17?à ?40·??16à??19¢?Y22à?a15???24??à11???23?àa15???40·? & ?13??Y22à?a29ò▓ & ?28▓?a15??ù26Y?Y22à?à11???13??a15?? ?40·??16à??19¢?Y22à?a15??ù26Y?à11??a30?ò?18???40·? & ?13??Y22à?a29ò▓ & ù26Y??19¢??24??@17?à Y22à?μ25???13??à11??Y22à??18??μ25??a29ò▓a30?ò -?24?? 3?10?▓ & ?28▓?a15??ù26Y?Y22à?à11???13??a15?? ?40·??16à??19¢?Y22à?a15??ù26Y?à11??a30?ò?18???40·? & ?13??Y22à?a29ò▓ & ù26Y??19¢??24??@17?à Y22à?μ25???13??à11??Y22à??18??μ25??a29ò▓a30?ò -?24?? 3 & ?13???18???14???19¢??28▓? ?40·?~?14??ù26Y??10?▓.. & ?28▓??23?à?14???19¢??28▓? ?40·?~?14??ù26Y??10?▓ ?39?óa29ò▓ ?39?ó?27?Y

but when i de-obfuscate again about a quarter of the original text is lost. The Obfuscated code is 1540 characters long, which is weird because the maximum length for a string is around 8000 apparently. Help would be very much apreciated.

(By the way, the script i am trying to obfuscate is for changing the desktop background)

EDIT: Here is the code for the Obfuscator & De-Obfuscator

Obfuscator:

@echo off
setlocal enableDelayedExpansion

set /p code=Text:
set chars=01234567890abcdefghijklmnopqrstuvwxyz()/%%
Set _Alphanumeric=???ò?ù¢£¥?áíóú??????|?μ±°?2€…??‰???—????????–?§@
Set _count=0

:redo
If !_count! leq 204 call :loop

for /L %%N in (10 1 40) do (

for /F %%C in ("!chars:~%%N,1!") do (
set vals=!str:~%%N,1!%%N!str:~-%%N,1!

for /F %%F in ("!vals!") do (
set "code=!code:%%C=%%F!"
)
)
)
echo !code!
pause
exit

:loop
Set /a _count+=1
set _RND=%random%
Set /A _RND=_RND%%48
SET str=!str!!_Alphanumeric:~%_RND%,1!
goto redo

De-Obfuscator:

@echo off
setlocal enableDelayedExpansion

set /p code=Text:
set chars=01234567890abcdefghijklmnopqrstuvwxyz()/%%

for /L %%N in (10 1 40) do (

for /F %%C in ("!chars:~%%N,1!") do (

set "code=!code:%%N=%%C!"

)
)

for /F %%F in ("!code!") do (
for %%L in (^? ^? ^? ^ò ^? ^ù ^? ^¢ ^£ ^¥ ^? ^á ^í ^ó ^ú ^? ^? ^? ^? ^? ^? ^| ^? ^μ ^± ^° ^? ^2 ^€ ^… ^? ^? ^‰ ^? ^? ^? ^— ^? ^? ^? ^? ^? ^? ^? ^? ^– ^¤ ^? ^§ ^@             
) do (
set "code=!code:%%L=!"
)
)

echo !code!
pause
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

set /p has a limit of ~1023 characters.

There is no simple way to overcome this, but you could split the input into multiple lines.

Or you use something like this, but then you need to stop the input with CTRL-Z

findstr "^" > input.txt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...