Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Looking for alternative methods for creating binary files

65 views
Skip to first unread message

JJ

unread,
Aug 9, 2016, 4:30:38 PM8/9/16
to
I have some tiny custom Win32 EXE programs that I "embedd" in batch files so
that they can be temporarily deployed in a system and then be used by those
batch files - keeping the whole task in a single file to prevent dependency
issue.

Previously I used DEBUG.EXE to generate the binary files by first deploying
a DEBUG script then use it as an input for DEBUG. This works in Windows XP
and Vista, but not Windows 7 and newer versions because DEBUG.EXE is no
longer included. So, I replaced DEBUG usage with VBScript.

Is there other alternative method?

Note that using PowerShell is not acceptable since it's not available in all
Windows installations. Using .NET to compile a VB.NET/JScript.NET script is
also not acceptable because .NET v2.x+ is not available in all Windows
installations.

Admin rights is not a problem because I will be the adminitrator of every
systems I manage.

Herbert Kleebauer

unread,
Aug 9, 2016, 6:05:43 PM8/9/16
to
On 09.08.2016 22:30, JJ wrote:

> longer included. So, I replaced DEBUG usage with VBScript.
>
> Is there other alternative method?

You can use certutil.exe:

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
:: swap left and right mouse button
certutil -f -decode %~f0 swap.exe>nul
swap.exe
del swap.exe
goto :eof

-----BEGIN CERTIFICATE-----
TVpgAQEAAAAEAAAA//8AAGABAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAoAAAAA4fug4AtAnNIbgBTM0hTmljZSB0byBtZWV0IHNvbWVi
b2R5IHdobyBpcyBzdGlsbCB1c2luZyBET1MsDQpidXQgdGhpcyBwcm9ncmFtIHJl
cXVpcmVzIFdpbjMyLg0KJFBFAABMAQEAUHmlNgAAAAAAAAAA4AAPAQsBBQwAAgAA
AAAAAAAAAACWEAAAABAAAAAgAAAAAEAAABAAAAACAAAEAAAAAAAAAAQAAAAAAAAA
ACAAAAACAAAAAAAAAgAAAAAAEAAAEAAAAAAQAAAQAAAA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certutil.exe to generate the bat file:


:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

@echo off
certutil -f -encode %~n1.exe %~n1.b64
echo @echo off>%~n1.bat
echo certutil -f -decode %%~f0 %~n1.exe^>nul>>%~n1.bat
echo.>>%~n1.bat
echo.>>%~n1.bat
echo.>>%~n1.bat
echo del %~n1.exe>>%~n1.bat
echo goto :eof>>%~n1.bat
echo.>>%~n1.bat
copy /b %~n1.bat+%~n1.b64
del %~n1.b64



foxidrive

unread,
Aug 9, 2016, 6:21:22 PM8/9/16
to
On 10/08/2016 08:03, Herbert Kleebauer wrote:
>
> You can use certutil.exe:
>
>
>
> You can also use certutil.exe to generate the bat file:
>
>
> :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
> :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
>
> @echo off
> certutil -f -encode %~n1.exe %~n1.b64
> echo @echo off>%~n1.bat
> echo certutil -f -decode %%~f0 %~n1.exe^>nul>>%~n1.bat
> echo.>>%~n1.bat
> echo.>>%~n1.bat
> echo.>>%~n1.bat
> echo del %~n1.exe>>%~n1.bat
> echo goto :eof>>%~n1.bat
> echo.>>%~n1.bat
> copy /b %~n1.bat+%~n1.b64
> del %~n1.b64
>


I cobbled this together a while ago for the same reason. It creates a
script that can be appended easily and only decodes the file if it doesn't
already exist.



@echo off
set suffix=create.bat
if "%~1"=="" (
echo( Syntax: "%~0" "filename.mp3"
echo( to encode the filename.mp3 into a filename.%suffix% batch script
echo( - any filetype can be encoded into a batch script.
echo(
pause & goto :EOF
)
echo(creating "%~n1.%suffix%"
certutil /encode /f "%~1" "encode.tmp"
find /v /i "CERTIFICATE---" <"encode.tmp" >"encode.tm"
(
echo @echo off
echo if not exist "%~nx1" (
echo echo creating "%~nx1"
echo (
for /f "usebackq delims=" %%a in ("encode.tm") do echo echo %%a
echo ^)^>"decode.tmp"
echo certutil /decode /f "decode.tmp" "%~nx1" ^>nul
echo del "decode.tmp"
echo ^)
)>"%~n1.%suffix%"
del "encode.tm*"



JJ

unread,
Aug 10, 2016, 12:22:32 PM8/10/16
to
On Wed, 10 Aug 2016 00:03:12 +0200, Herbert Kleebauer wrote:
>
> You can use certutil.exe:
[snip]

Unfortunately, CERTUTIL is not guaranteed to be available in all Windows
installations. For Windows XP, CERTUTIL is only available from Windows
Server 2003 Administration Pack. CERTUTIL is absent in the Windows XP Pro
SP3 CD (non upgrade version).

<http://support.microsoft.com/kb/934576>

The oldest OS I manage is Windows XP, BTW.
Sorry to forgot mentioning that.

Herbert Kleebauer

unread,
Aug 10, 2016, 4:57:04 PM8/10/16
to
On 10.08.2016 18:22, JJ wrote:

> Unfortunately, CERTUTIL is not guaranteed to be available in all Windows
> installations. For Windows XP, CERTUTIL is only available from Windows
> Server 2003 Administration Pack. CERTUTIL is absent in the Windows XP Pro
> SP3 CD (non upgrade version).

But nearly all XP installations are 32 bit versions so you
can use 16 bit code. Here an example for a combined cerutil/16 bit
batch file:

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

@echo off

for %%i in (%PATH%) do if exist %%i\certutil.exe goto :cert
goto :nocert

:cert
certutil -f -decode %~f0 base64d.exe>nul
goto :eof
-----BEGIN CERTIFICATE-----
TVpgAQEAAAAEAAAA//8AAGABAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAoAAAAA4fug4AtAnNIbgBTM0hTmljZSB0byBtZWV0IHNvbWVi
b2R5IHdobyBpcyBzdGlsbCB1c2luZyBET1MsDQpidXQgaGlzIHByb2dyYW0gcmVx
dWlyZXMgV2luMzIuDQokAFBFAABMAQEAUHmlNgAAAAAAAAAA4AAPAQsBBQwAAgAA
AAAAAAAAAACUEAAAABAAAAAgAAAAAEAAABAAAAACAAAEAAAAAAAAAAQAAAAAAAAA
ACAAAAACAAAAAAAAAwAAAAAAEAAAEAAAAAAQAAAQAAAAAAAAEAAAAAAAAAAAAAAA
FBAAACgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAUAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALnRleHQAAAD/AQAAABAAAAACAAAAAgAA
AAAAAAAAAAAAAAAAIAAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABeEAAAbBAAAHwQAACIEAAA
AAAAAEoQAAAAAAAAAAAAADwQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAABLRVJO
RUwzMi5kbGwAAF4QAABsEAAAfBAAAIgQAAAAAAAAAABFeGl0UHJvY2VzcwAAAEdl
dFN0ZEhhbmRsZQAAAABSZWFkRmlsZQAAAABXcml0ZUZpbGUAu+AQQAAx0rkgAAAA
6AMBAACD+P90GTw9dBUIwHju1wjAeOmD6QbT4AHCgPkId92SgPkacw3BwAjojwAA
AIPBCOvuCNJ0v+gZAQAAAP//////////////////////////////////////////
//////////////8+////PzQ1Njc4OTo7PD3/////////AAECAwQFBgcICQoLDA0O
DxAREhMUFRYXGBn///////8aGxwdHh8gISIjJCUmJygpKissLS4vMDEyMwAAAAAA
YDHAAwWkEUAAdQ1q9f8VBBBAAKOkEUAAagCNVCQQUmoBg8IQUlD/FQwQQAAJwHUI
agD/FQAQQACDfCQMAXXxYZDDAAAAAAAAMcBgAwX0EUAAdQ1q9v8VBBBAAKP0EUAA
agCNVCQQUmoBg8IQUlD/FQgQQAAJwHUIagD/FQAQQACDfCQMAXQIx0QkHP////9h
kMMAAAAAAABQ/xUAEEAAAA==
-----END CERTIFICATE-----


:nocert
echo hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>base64d.com
echo hhpbbnpljhoxolnhaigidpllnbkdnhlkfhlflefblffahfUebdfahhfkokh>>base64d.com
echo wvPp0wvL3k9C5/R/pN0d0uzL37bwo1YiTFEWtbGov5//B6mkuMEo0IL0l/w>>base64d.com
echo ef2iC57R/pNEA/jeefHhC5AR/pNEA/juefXgC5ER/phCfDM@m042knfuur5>>base64d.com
echo YE2ZIIBd4M03kE3Aozz@3M03J0/4Z7UCY2Tcf2/EP1B61i0kInVsIOXJ57o>>base64d.com
echo x57hJKNo0mQjpKNWx5Nt0mRcx57dB67nFLOgl57pBLOiR573xoIgoU1WJ6R>>base64d.com
echo UUKOn01QmxqNm4KPU7LNlJLOmJqQUQJOiBXAioU1Y//I483H03//EZLdq3p>>base64d.com
echo 0U2k20gE/4k//13J1I1lEEA3780YEEAY/1FEI5EEI6/mE13J02340E73380>>base64d.com
echo VEE3J0E3Z1I/VEc3pIE734FdV@oJ5SoBoz0A3328kE13J2U73sFxXLE73PE>>base64d.com
echo 73TE73WE3J090FI8k2320FIJgIFGtIFABXAiE5Pg8YLE73PE73TE73WE3p0>>base64d.com
echo 4VLOo0ZQjBKNnBrE6J5RHF6N74aPYlKN88JNVFaFdlKN8RZQdFLN5Z5PZ0k>>base64d.com
echo iU20E/3Xot1mEcDE/1B7yzHL5wo2RJU/kstyp7/ASdDMu5ABs07AUtXkRR@>>base64d.com
echo 8UtflQB3Ak7UyX2BMk7giv77BRzWS50Aozzzzzzzzzzzzzzzzzzzzzzzzzz>>base64d.com
echo zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzywzzzz2BpMnBsYXCvkHDzzzzzzzz>>base64d.com
echo z2E/1A/04Mk07YU1@kE2Cw/3F7l3IIV4LUF5zzzzzzzzOg06Rsl6U3W7XEG>>base64d.com
echo 8aQ19dcm9goW@j/HAmAHI3/KA/DE0Y50E/IL2eJzzJE/3/0kcY50E/c5/BG>>base64d.com
echo 48E7ZO0AckE74IzL02E/3/8/QR7c5/zL0/E/3/2m68A3ERl65Y26J0l/AM2>>base64d.com
echo I/xF/3/ppUOqzT43/0E/A9xF/3/e0EXIF13GdK/29A3G0pzJU/3/0E1/L61>>base64d.com
echo e0kzJ//3/0kUwF120E616H38QwzzzzTMECQI4/pzJ//3/833.>>base64d.com
base64d.com>base64.exe
del base64d.com

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

You can do the same with your binaries or you use the above
code to generate the base64 decoder "base64d.exe" and then use
this program to decode your binary:

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


@echo off
:: swap left and right mouse button
findstr /b /c:"::$" %~f0 |base64d.exe >swap.exe
swap.exe
del swap.exe
goto :eof

::$ TVpgAQEAAAAEAAAA//8AAGABAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
::$ AAAAAAAAAAAAAAAAoAAAAA4fug4AtAnNIbgBTM0hTmljZSB0byBtZWV0IHNvbWVi
::$ b2R5IHdobyBpcyBzdGlsbCB1c2luZyBET1MsDQpidXQgdGhpcyBwcm9ncmFtIHJl
::$ cXVpcmVzIFdpbjMyLg0KJFBFAABMAQEAUHmlNgAAAAAAAAAA4AAPAQsBBQwAAgAA
::$ AAAAAAAAAACWEAAAABAAAAAgAAAAAEAAABAAAAACAAAEAAAAAAAAAAQAAAAAAAAA
::$ ACAAAAACAAAAAAAAAgAAAAAAEAAAEAAAAAAQAAAQAAAAAAAAEAAAAAAAAAAAAAAA
::$ EBAAADwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
::$ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAQAAAA
::$ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALnRleHQAAACyAAAAABAAAAACAAAAAgAA
::$ AAAAAAAAAAAAAAAAIAAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
::$ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgEAAAAAAAAIgQAAAAAAAA
::$ WBAAAAAAAAAAAAAATBAAAAAQAACAEAAAAAAAAAAAAAByEAAACBAAAAAAAAAAAAAA
::$ AAAAAAAAAAAAAAAAVVNFUjMyLmRsbAAAYBAAAAAAAAAAAFN3YXBNb3VzZUJ1dHRv
::$ bgBLRVJORUwzMi5kbGwAAIgQAAAAAAAAAABFeGl0UHJvY2VzcwBqAP8VABBAAIPw
::$ AXQHUP8VABBAAGoA/xUIEEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
::$ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
::$ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
::$ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
::$ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
::$ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
::$ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
::$ AAAAAAAAAAAAAAAAAAAAAA==





Batchman

unread,
Aug 15, 2016, 6:30:25 AM8/15/16
to
JJ wrote:

>
> Is there other alternative method?
>
There's an old (dos) variation of Basic called P.D.Q...

http://ethanwiner.com/p_pdq.htm

...actually it's a 3rd party library designed to be used with the Microsoft
Quick Basic (dos) compiler. It has the ability to create truly tiny
executables which are also VERY fast.

I'm guessing that it makes a good substitute to using assembler.

It's an ideal way to create tiny executables to be used in batch files.

The `language' is very close to the original Quick Basic syntax, with some
useful extentions. One of those you'll enjoy is you can arrange for an
executable to set the errorlevel to be returned to the OS or batch.

It does include the ability to Call dos interrupts.

Another possibility is a Dos Basic compiler which went by the handle of
`ASIC' because the author reckoned that it was `almost BASIC'.

It also produced very small/efficient executables but the features it
contained were not nearly as good as P.D.Q.

Batchman


--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

Petr Laznovsky

unread,
Aug 18, 2016, 2:48:15 AM8/18/16
to JJ
Dne 9.8.2016 v 22:30 JJ napsal(a):
http://consolesoft.com/p/bhx/

0 new messages