I am new to this world, and I have tried to learn through reading, and the few questions that I have asked in this forum. Through which and with your help I have been able to crystallize my ideas.
The point is that, in my work there are some colleagues who may not be very happy with my eagerness to learn to script, and they constantly seek to put their noses in the code. Come on, it is not a code from the other world, but they strive to snoop, and I do not let them look.
So I'm looking for a way to obfuscate the code so it's not visible (when my little project is done), or at least make it as difficult as possible for it.
I tried the following code, from this link:viewtopic.php?f=3&t=7990&hilit=obfuscate
Code: Select all
@ECHO OFF
GOTO:CODE
Drag .bat or .cmd file onto this batch file
It will be encoded and name___.bat will be created which will function as normal
To decode name__.bat file drag onto this file as well
encoded file will be deleted and name.DC.bat created
https://www.dostips.com/forum/viewtopic.php?t=7990
substring manipulation https://ss64.com/nt/syntax-substring.html
:CODE
:: if no perameter exit
if "%~1"=="" exit /b
:: if not .bat or .cmd exit
if /i "%~x1" neq ".bat" if /i "%~x1" neq ".cmd" exit /b
:: check to see if last 3 letter in filename are ___, if so decode
set _name=%~n1
if %_name:~-3% equ ___ goto :DECODE
:ENCODE
for /f %%i in ("certutil.exe") do if not exist "%%~$path:i" (
echo CertUtil.exe not found.
pause
exit /b
)
>"temp.~b64" echo(//4mY2xzDQo=
certutil.exe -f -decode "temp.~b64" "%~n1___%~x1"
del "temp.~b64"
copy "%~n1___%~x1" /b + "%~1" /b
GOTO:EOF
:DECODE
:: _result everything but last 3 characters
SET _result=%_name:~0,-3%
:: del old decoded file
if exist "%_result%.DC%~x1" del "%_result%.DC%~x1"
:: save decoded file to file.DC.ext
for /f "skip=1 delims=" %%L in ('CMD /U /C Type "%~1"') do (
echo %%L
echo %%L >>"%_result%.DC%~x1"
)
:: del original encoded file
del %~n1%~x1
1- It certainly masks the code, the bad thing is that with a Hexadecimal editor you can see and copy the code, which is precisely what I try to avoid.
2- My code runs fine almost to the end, where it sadly fails.
3- The failure is given because at the beginning of my code I have "<#: batch portion", so the final code is not executed. Error that would still give if it was removed and executed.
The question is, what can I do to prevent access to the code, either through other code like the one above, or through a program.
If there is no other way, how can I solve the problem that the use of the code described above presents?
Thankful as always for the help you can give me.
Please excuse my English, I use a translator.