Page 1 of 1
Writing an exe via batch
Posted: 21 Dec 2012 01:58
by keyboard1333
Greetings all!
I have some exe files, and I'd like to make an installer for them, from batch. (Not from the language they're programmed in)
Can I write these exe's using batch somehow? (Instead of just packaging the exe's with the installer)
Re: Writing an exe via batch
Posted: 21 Dec 2012 02:08
by foxidrive
You can encode them into a batch file - but if they are more than a couple of kb then they will take up a lot more space in the batch file due to overheads in encoding.
Re: Writing an exe via batch
Posted: 21 Dec 2012 02:09
by foxidrive
What is your aim? Do you want only one file, and not use an archive file like zip or 7z?
Re: Writing an exe via batch
Posted: 21 Dec 2012 03:55
by keyboard1333
Just one file, not using an archiving format...
All the files are around the 11 kb mark... But even so, I'd still like to try this
Re: Writing an exe via batch
Posted: 21 Dec 2012 07:08
by foxidrive
Carlos just posted his BHX.EXE file here in a batch file. It creates another batch file when you give it your target file as a parameter.
Do that once for each file and copy all the files together.
Re: Writing an exe via batch
Posted: 21 Dec 2012 16:00
by keyboard1333
I was kind of hoping that someone could actually show me how to do it, not just use a tool...
I'm interested in how it works too
Re: Writing an exe via batch
Posted: 21 Dec 2012 17:12
by foxidrive
Read things in google that tell you how XXencoding and UUencoding works. That's the principle of changing a file to be transmitted by text.
I think carlos' program converts each byte to a hex number and creates a string of them.
When it comes to decoding it the reverse is done, to get the 8 bit characters again.
Re: Writing an exe via batch
Posted: 22 Dec 2012 12:57
by Aacini
In the topic precisely called
Creating .EXE auxiliary programs in Batch files (placed 7 topics below this one, before I replied), the method to do such thing is described. It includes the source programs for the conversion of .exe file to .txt equivalent and the opposite one, and additional links to posts that describe the particular method to achieve each part.
After converting your .exe to text, just insert it in the text-to-exe conversion method as a series of strings enclosed in quotes in a long FOR command, like in
this carlos' example, to create an auxiliary file that will be converted by the original method. If all your lines does not fit in one FOR command, split they in several smaller FOR's.
I hope it helps...
Antonio
Re: Writing an exe via batch
Posted: 22 Dec 2012 15:24
by keyboard1333
Thanks for that link!!!
I'm a bit busy at the moment, but I'll have a look at it later
Thanks again everyone for all your help!
keebs
Re: Writing an exe via batch
Posted: 22 Dec 2012 22:45
by carlos
The advantage of use the scripts generated by BHX is that it use vbscript, then you can rebuild the binary in windows systems of 32 and 64 bits. But, if you only want that the make of the binary file be in a windows of 32 bits also you can do it whith debug.exe. Before BHX I build binary data with debug.exe, but because it not works in windows 64 bits I write BHX.exe.
If you have debug.exe you can understand the scripts of bhx, and also rebuild binary data using it.
Re: Writing an exe via batch
Posted: 22 Dec 2012 23:01
by carlos
For example. Read and run this batch:
Code: Select all
@Echo OFF
Rem Creating a file
Echo This is a text file>file.txt
Rem Getting the size of the file
For %%# in (file.txt) do set "size=%%~z#"
Rem Debug begin in offset 256 (0x100) ,
Rem then plus it to size to get a offset max
Rem also minus 1
Set /a "max_offset=%size%+0x100-1"
Rem Converting the max_offset to hexadecimal notation
Call :Dec2Hex %max_offset% max_offset
Rem Sending instructions to debug that open file.txt
Rem d = debug
Rem q = quit
Rem d number number debug from offset to offset
(Echo d 100 %max_offset%&Echo q) | debug file.txt
Pause
Goto :Eof
:Dec2Hex
:: Usage: Call :Dec2Hex number variableWhereSave
:: Only works fine with numbers from 0 to 2147483647
"%ComSpec%" /d /c Exit /b %~1 >Nul
For /f "eol=0 delims=0 tokens=*" %%# In (
"%=ExitCode%") Do If Not "%%#"=="" (Set %~2=%%#) Else (Set %~2=0)
Goto:Eof
This print:
Code: Select all
-d 100 114
139F:0100 54 68 69 73 20 69 73 20-61 20 74 65 78 74 20 66 This is a text f
139F:0110 69 6C 65 0D 0A ile..
-q
This teach you that every byte in a binary file have a value in hexadecimal from 00 to FF, this is in decimal from 0 to 255, for example the T letter is 0x54, h letter is 0x68 ... you can google a ascii table for more understand of this.
I have a script and a program that generate debug script for rebuild binary data, but is more practical use BHX or other tools that use vbscript, because it support windows of 64 bits.
Re: Writing an exe via batch
Posted: 25 Dec 2012 19:32
by keyboard1333
Thank you everyone so much for you input!
In the end, after fiddling with bhx, I programmed my own little hex converter in vb.net (hehe vb.net
).
Thankyou again for all the help!!!
I couldn't've figured it out without you
Re: Writing an exe via batch
Posted: 04 Jan 2013 06:36
by skat3444
follow this steps:
1. write your .bat file
2. compile it
3. edit the .exe file (open in editor)
4. copy code
5. in the .bat code, who must write the code, type this:
Code: Select all
echo ##exampel## > exampel.exe
echo ##exampel## >> exampel.exe
echo ##exampel## >> exampel.exe
...
only write one line of code in oneecho ##exampel## >> exampel.exe
!!its my way.. i think it not work 100% but try it.
Good luck!
Re: Writing an exe via batch
Posted: 05 Jan 2013 00:04
by keyboard1333
Skat, what're you compiling the .bat with?
And umm... what?