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

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

#31 Post by pditty8811 » 14 Apr 2013 04:39

carlos,

I think we came to an understanding that encrypting a batch file can't be done?

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

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

#32 Post by Aacini » 14 Apr 2013 16:07

@pditty8811:

  1. There is no way to protect the source code of a Batch file by encryption of any type. Even if the Batch code is converted into an .exe file with a compiler, the original Batch program must be recovered to its Ascii version in order to be executed by cmd.exe processor. An expert may break the encrypted code in minutes (ask Liviu or carlos!), but this largely depends on the knowledge base of each person.
  2. There are less sophisticated ways to protect Batch source code via several levels of encoding. How easily these schemes can be broken depends on each individual again. If you think this means that don't cares to encrypt or not, you must realize that unencoded code will be seen by everyone, but an encoded program will remain hidden for a certain number of people.
  3. I understood that your concern is not "how to encrypt/encode a source Batch program", but...
    pditty8811 wrote:... 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.

    Is there a way to unencrypt, then find and replace file paths in the script, then encrypt again?
    There is no way to do that even if you give a compiler to the users because they will have access to the original source code at some point.

Did you reviewed my solution? It achieve precisely what you had asked for: the people may download an encoded program, they launch it, the installer ask the user for the file paths and generate an encoded Batch application. If you are not comfortable with the series of numbers I posted in my solution, I can post it in its original source version (the same published by carlos in his first reply!)

Antonio

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

#33 Post by carlos » 14 Apr 2013 20:14

Please wait my software utility.
It uses a new technique.

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

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

#34 Post by pditty8811 » 14 Apr 2013 21:58

carlos wrote:Please wait my software utility.
It uses a new technique.


Is your software free or paid?

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

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

#35 Post by pditty8811 » 14 Apr 2013 22:12

Aacini wrote:@pditty8811:

  1. There is no way to protect the source code of a Batch file by encryption of any type. Even if the Batch code is converted into an .exe file with a compiler, the original Batch program must be recovered to its Ascii version in order to be executed by cmd.exe processor. An expert may break the encrypted code in minutes (ask Liviu or carlos!), but this largely depends on the knowledge base of each person.
  2. There are less sophisticated ways to protect Batch source code via several levels of encoding. How easily these schemes can be broken depends on each individual again. If you think this means that don't cares to encrypt or not, you must realize that unencoded code will be seen by everyone, but an encoded program will remain hidden for a certain number of people.
  3. I understood that your concern is not "how to encrypt/encode a source Batch program", but...
    pditty8811 wrote:... 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.

    Is there a way to unencrypt, then find and replace file paths in the script, then encrypt again?
    There is no way to do that even if you give a compiler to the users because they will have access to the original source code at some point.

Did you reviewed my solution? It achieve precisely what you had asked for: the people may download an encoded program, they launch it, the installer ask the user for the file paths and generate an encoded Batch application. If you are not comfortable with the series of numbers I posted in my solution, I can post it in its original source version (the same published by carlos in his first reply!)

Antonio


I'm sorry I don't understand your code. It's a bit complicated for me to grasp.

Will I have to change the batch files I've created in any way? I have my batch files for the install and user input questions all created, with variables. Will I have to change this?

I can't follow what you say in your post about your program. I'm still learning.

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

#36 Post by carlos » 15 Apr 2013 09:33

pditty8811 wrote:
carlos wrote:Please wait my software utility.
It uses a new technique.


Is your software free or paid?


It will be available in a free demo version and full version for a us$1.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

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

#37 Post by Aacini » 15 Apr 2013 19:29

pditty8811 wrote:I'm sorry I don't understand your code. It's a bit complicated for me to grasp.

Will I have to change the batch files I've created in any way? I have my batch files for the install and user input questions all created, with variables. Will I have to change this?

I can't follow what you say in your post about your program. I'm still learning.

Excuse me, I am a little confused by your reply. In my first reply in this topic I posted a solution to your problem that consist in BatchEncoder.bat program; this is the beginning of such program:

Code: Select all

@if (@CodeSection == @Batch) @then

@echo off

REM BatchEncoder.bat: Create an installer for an encoded Batch file
REM Antonio Perez Ayala

if not exist "%~1" echo File not found: %1 & goto :EOF
Cscript //nologo //E:JScript.Encode "%~F0" %1
goto :EOF

@end

// Create an Installation program for a Batch file with initialized variables
// and Encode the source code in a non-readable way
//**Start Encode**#@~^sxAAAA==@#@&@#@&Jz,rwx,OtPdW!D^n,0k^nPmxN,.nl9PDtnPWrM/OPD4D+~sbx+d@#@&\CD,WbVn:WAxmKN~',jmMk2OcbDT;:xYk ix   ls+[R(O:c!*I@#@&\C.,0ksnAx^W9n9Px,B'--'JE~_,?ODbxL 6DWs/tmDZK
several encoded lines follows...
You just need to use this program as it is, you don't need to modify or copy it in any way. To use this program just execute it with the name of your Batch file in the parameter this way:

Code: Select all

BATCHENCODER YOURPROGRAM.BAT
The result of previous step is a Batch file called INSTALLYOURPROGRAM.BAT that is the installer for your application.

The only requirement for BatchEncoder program is that the install and user input questions be made via SET /P "VARIABLE=USER INPUT QUESTION" commands placed from third line on in your program. An example of all these steps is shown in my first reply above.

I suggest you to download BatchEncoder.bat program and do a couple tests with simple .bat files and then with your application, just be sure that those SET /P installation commands are placed from line number 3 and up in your program.

IMPORTANT! Be sure to test the INSTALLER in a different folder! Remember that the installer create an encoded Batch file with the same name as the original, so the original Batch file would be deleted.

Antonio

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

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

#38 Post by pditty8811 » 18 Apr 2013 12:11

Aacini, could you post the full code for BatchEncoder.bat please. I understand now. Your previous posts are in hex.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

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

#39 Post by Aacini » 19 Apr 2013 03:13

@pditty8811: To get the full code of BatchEncoder.bat, just follow these steps:

  • Go to my first reply and download BatchEncoder.bat.hex file comprised of hex digits.
  • Go to this post and download both HexToBin.bat and HexChar.vbs files.
  • Execute:

    Code: Select all

    C:> HEXTOBIN BATCHENCODER.BAT.HEX

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

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

#40 Post by pditty8811 » 19 Apr 2013 07:44

I tried it and it creates a file called HEXTOBIN and its an empty file. What am I doing wrong?

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

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

#41 Post by pditty8811 » 19 Apr 2013 07:51

Hi Aacini,

I got it working. I had to remove the C:> option at the begining.

So it encrypts, but my delimma is that I have 3 batch files, not including the install batch file that will edit the file paths in the 3 batch files. I'd like to have the batches encrypted, then unecrypt them make edits via install bat, then encrypt them again.

Can I do this with your program? Can I reverse the encrypting? Dencrypt.


Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

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

#43 Post by Aacini » 20 Apr 2013 05:56

pditty8811 wrote:Hi Aacini,

I got it working. I had to remove the C:> option at the begining.

So it encrypts, but my delimma is that I have 3 batch files, not including the install batch file that will edit the file paths in the 3 batch files. I'd like to have the batches encrypted, then unecrypt them make edits via install bat, then encrypt them again.

Can I do this with your program? Can I reverse the encrypting? Dencrypt.


This is not a good idea. "Remember that your program will be protected as long as the user have not chance to review its code". If the installation steps unencrypt the code, then the users "could see the Batch source code before the modifications, isn't it?". This is the reason because "I don't see how a batch compiler may help to solve your request".

"Did you reviewed my solution? It achieve precisely what you had asked for: the people may download an encoded program, they launch it, the installer ask the user for the file paths and generate an encoded Batch application". "Batch Encoder allows to install a Batch program via the modification of certain variables, but keep both the installer and the installed program code in unreadable form". "The Install Variables must be placed in the Batch file from the third line on with this format:

Code: Select all

set /p "varName=prompt"
For example:

Code: Select all

@echo off
setlocal EnableDelayedExpansion
set /P "source=Source directory:      "
set /P "destination=Destination directory: "
echo The installed source directory is: %source%
echo The installed destination directory is: %destination%
". When the installer created by BatchEncoder "run, it ask the user for the value of the Install Variables and create an installed version of the program..." "with this installed code:

Code: Select all

@echo off
setlocal EnableDelayedExpansion
set "source=C:\MY FOLDER\MY SOURCE"
set "destination=C:\MY FOLDER\MY DESTINATION"
echo The installed source directory is: %source%
echo The installed destination directory is: %destination%

". This means that your 'install batch file that will edit the file paths in the 3 batch files' is no longer needed! The installation steps are included in my program. You only need to "be sure that those SET /P installation commands are placed from line number 3 and up in your program". "Only consecutive SET /P commands placed in the Batch file from the line number 3 on will be processed this way".

I designed my program this way because "I understood that your concern is not how to encrypt/encode a source Batch program". If I would thought that your problem could be solved by unencrypt/modify/encrypt steps, I would suggest you to use a compiler. My program is a "complete solution for your specific needs" that keep the original code, "the installer and the installed program code in unreadable form", so it does not allow to unencrypt any code.

Antonio

PS - I taken all parts in quotes from previous posts! :?

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

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

#44 Post by pditty8811 » 21 Apr 2013 03:51

Hi Aacini,

I don't think your solution works for my agenda.

I have 3 batch files and they have filepaths in them of 3 different types. That's 3 batch files, and they all use 3 different variables that I'd like to change. I need these 3 batch files to be permanently edited because they will be ran continously over and over again after the three variables have been changed. So a permanent edit to the files is necessary.

I don't need user input every time these batch files are ran, just the first time in order to permanently edit the 3 variables. You've only listed 2 variables, source and directory.

Perhaps I don't understand what your code does, but it doesn't seem like it will work for my needs.

Keep in mind, I am not editing the variables in these batch files to install them in a source directory, I am editing them so they can find the files they need in order to work,in the directories I say they are in.

I just need to edit the 3 filepaths in these 3 batch files, but make it based on user input so the user gets to decide what these variables are.

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

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

#45 Post by pditty8811 » 21 Apr 2013 04:08

I know how I could do this.

I could encrypt all my batch files, the 3 plus the installer, with your program of encryption.

Then I could echo the 3 user input variables to 3 different text files, then have the other 3 batch files read from the text files to get the variables. Everything would be encrypted too.

Wont this work?

Post Reply