Looking to encrypt batch scripts but need to edit in-between

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
pditty8811
Posts: 184
Joined: 21 Feb 2013 15:54

Looking to encrypt batch scripts but need to edit in-between

#1 Post by pditty8811 » 05 Apr 2013 13:49

I am looking to encrypt my batch scripts to exe to protect the code I've, and some here, have put together.
I will then be giving my work to others en masse.

But here's the problem. Within the script I have file and directory paths that are specific to my computer. These will have to be changed for each person. (I know how to do this part, as I can ask for user input and they can type the file paths and I can find and replace them within my batch script).

BUT, how do I do that but keeping my files encrypted at the same time. In essence, I'd like people to download my work, protected or encrypted, and then they can launch the install batch that asks for the user input for the file paths, which will then replace the file paths within my script. But how do I do the find and replace if my scripts are encrypted?

Is there a way to unencrypt, then find and replace file paths in the script, then encrypt again?
Or put them in a safe place until the find and replace then encrypt them? What would you suggest?

pditty8811
Posts: 184
Joined: 21 Feb 2013 15:54

Re: Looking to encrypt batch scripts but need to edit in-bet

#2 Post by pditty8811 » 05 Apr 2013 15:00

Could I possible package the scripts in a password protected .rar archive then unrar it to edit the file paths, then encrypt it?

Will a batch unrar an archive that is password protected?

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Looking to encrypt batch scripts but need to edit in-bet

#3 Post by Endoro » 05 Apr 2013 15:35

You can't protect your code by "encrypting" them with BAT2EXE converters. It's impossible! Forget it.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Looking to encrypt batch scripts but need to edit in-bet

#4 Post by Squashman » 05 Apr 2013 16:15

I agree. All those bat2exe programs are just wrappers. When you execute them they unpack them to the current working directory or to the TEMP directory. All you are doing is obscuring your code.

What is wrong with people seeing the code?

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Looking to encrypt batch scripts but need to edit in-bet

#5 Post by abc0502 » 05 Apr 2013 16:57

have a look at "Quick Batch File Compiler", it's not free unfortunately but it does what you need.

pditty8811
Posts: 184
Joined: 21 Feb 2013 15:54

Re: Looking to encrypt batch scripts but need to edit in-bet

#6 Post by pditty8811 » 05 Apr 2013 17:03

How do software companies encrypt their code? Knowing that they aren't writing in batch script.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Looking to encrypt batch scripts but need to edit in-bet

#7 Post by abc0502 » 05 Apr 2013 17:07

software are written in other language like C/C++ when they compile the source they just convert it from a readable language to machine language that you don't understand.

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: Looking to encrypt batch scripts but need to edit in-bet

#8 Post by carlos » 05 Apr 2013 17:48

about protect code with compiled batch, is impossible because cmd.exe execute source files ("compilers" encode the code itself and extract the plain code to a temp folder), about this i remember that a batch file can be encoded with Big Endian, when you look the code with notepad it show garbage characters, but you can execute it with cmd /u /c Anyways the file can be reencoded and the source file can be catched. Other tool can be ofuscate the code (this slow the execution).
I think that you can hide the code mounting a telnet server (kpym), configuring and connecting to the telnet server with telnet.exe (In the past I do this with a batch that launch some dos games), then you play remote dos games, and the batch code that launch the games was hidden.

About change the value of a variable.

Remember that children windows of cmd.exe inherits a copy of the variables of father windows. Then you can use this:

launch.bat

Code: Select all

Set /P "myvalue=Enter value:"
Call other.bat


other.bat

Code: Select all

If Not Defined myvalue Set myvalue=DEFAULT


other.bat will use the content of myvalue setted in launch.bat because launch.bat is launching other.bat and giving a copy of the variables.

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: Looking to encrypt batch scripts but need to edit in-bet

#9 Post by Dos_Probie » 05 Apr 2013 18:19

Why do you need to encrypt your code do you work for the DoD? , Seriously most of the compilers that I have used extract to the tmp folder during execution so anyone with any basic puter knowledge can still get your code easily..Plus you have to backup all your batch files if you want
to make future revisions..I usually just pack my batch in a sfx .exe file with icon then run it without any user action, still you can upzip it but you can easily revise when needed. :P

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Looking to encrypt batch scripts but need to edit in-bet

#10 Post by foxidrive » 05 Apr 2013 19:04

+1 to the suggestion that encryption is stoopid.

But you could include a variable name in all the locations for paths in the batch file, and then use the correct paths that have been typed in by the user.

Example: (It seems obvious to me)

:: "encrypted batch file.exe"

Code: Select all

@echo off
set /p "path1=enter path to widget A "
set /p "path2=enter path to widget B "
set /p "path3=enter path to widget C "
set /p "path4=enter path to widget D "

copy /b "%path1%\backup folder" "%path2%\working folder"
findstr "Text to find" "%path4\business.file" > "%path3\outputfile.txt"


You'll have to include code to test that the locations are valid.

pditty8811
Posts: 184
Joined: 21 Feb 2013 15:54

Re: Looking to encrypt batch scripts but need to edit in-bet

#11 Post by pditty8811 » 05 Apr 2013 19:27

carlos wrote:about protect code with compiled batch, is impossible because cmd.exe execute source files ("compilers" encode the code itself and extract the plain code to a temp folder), about this i remember that a batch file can be encoded with Big Endian, when you look the code with notepad it show garbage characters, but you can execute it with cmd /u /c Anyways the file can be reencoded and the source file can be catched. Other tool can be ofuscate the code (this slow the execution).
I think that you can hide the code mounting a telnet server (kpym), configuring and connecting to the telnet server with telnet.exe (In the past I do this with a batch that launch some dos games), then you play remote dos games, and the batch code that launch the games was hidden.

About change the value of a variable.

Remember that children windows of cmd.exe inherits a copy of the variables of father windows. Then you can use this:

launch.bat

Code: Select all

Set /P "myvalue=Enter value:"
Call other.bat


other.bat

Code: Select all

If Not Defined myvalue Set myvalue=DEFAULT


other.bat will use the content of myvalue setted in launch.bat because launch.bat is launching other.bat and giving a copy of the variables.

I don't understand this Big Endian thing.

Although your variable tactics I did not realize, I cannot use that method because it would then require everyone to input the filepaths everytime my scripts run, instead of just making the find and replace permanent.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Looking to encrypt batch scripts but need to edit in-bet

#12 Post by foxidrive » 05 Apr 2013 19:44

pditty8811 wrote:Although your variable tactics I did not realize, I cannot use that method because it would then require everyone to input the filepaths everytime my scripts run, instead of just making the find and replace permanent.


Make your batch file read a text file with the info - and use another batch file to get the info just once from the user.

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: Looking to encrypt batch scripts but need to edit in-bet

#13 Post by Liviu » 05 Apr 2013 20:44

carlos wrote: i remember that a batch file can be encoded with Big Endian, when you look the code with notepad it show garbage characters, but you can execute it with cmd /u /c

I am not aware of any Windows version where cmd/u can execute unicode-encoded batch files, neither big nor little endian nor utf-8. I'd be more than happy to be proven wrong, though ;-) if you had a pointer to an actual working case.

Liviu

pditty8811
Posts: 184
Joined: 21 Feb 2013 15:54

Re: Looking to encrypt batch scripts but need to edit in-bet

#14 Post by pditty8811 » 06 Apr 2013 00:36

So if there is no program that encrypts batch scripts in existance, or there is no way to encrypt batch, then this whole thread is a waste of time?

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Looking to encrypt batch scripts but need to edit in-bet

#15 Post by abc0502 » 06 Apr 2013 02:29

if you still insist on encryption i remembered now carlos made a tool called BHX it is used to put exe files or other files inside a batch, if you look at that batch you will see many numbers and won't understand what is in from the first look.

you can use the same method, create your batch and make sure it delete itself after it's done.
then use the BHX tool to (compile it) and add a line at the end of the resulted batch to run your batch after it's done.

your original batch will be safe inside the batch that was created using the BHX

Post Reply