modern reply.exe created using only batch
Posted: 30 Jan 2014 01:13
Edit: minor changes to the batch code, and to my comments in this post.
Hello.
The title of this topic is for celebrate the creation of technique for write binary data using only batch developed in this topic:
http://www.dostips.com/forum/viewtopic.php?f=3&t=5326
For this I write a little tool reply.exe (1536 bytes) as replacement of old reply.com found here: http://support.microsoft.com/kb/77457
because 16 bits programs are not supported on 64 bit window system.
the source code of it is at the end of this post.
The program accept a keyboard input and return a numeric code. If the input is a extended key, example a arrow key, it sum 256 to the numeric code.
I'm interesed on creation of binary data using batch since 2010 and I read many things about this. I use succesfully utilities that generates .com files using only ascii files from authors like herbert kleebauer, laura fairhead, jim tucker, creation using debug, all it for 16 bits, and for 32 bits creation using vbscript (cscript, mshta), certutil. Also I wasted many time writing a utility called bhx that combine many techniques of it with focus on give support to windows 2000 and above systems of 64 bits, also combining the usage of cabinet files for reduce the file size.
But, now, finally is posible using only batch. (I think add this as module to bhx for a easy script generation). I celebrate this advance in the batch posting the creation of reply.exe using only batch. This method is good because not create a debug or vbs script. It write directly to the file using batch, not interpretation of a script is involved.
This generation of the executable using the function :genchr in this script is a prototype, but can serve as a guide for creation a binary using only batch, you only need change the hex data and the filenames. Note: I optimized for support only hex data with length of 60 characters. I choose this length in bhx and in this code because in the past I remember post some hex data on alt.msdos.batch.nt and get the script spoiled because large line length.
create_reply.cmd
reply.c
// Compiled with tiny c for get a small executable
Hello.
The title of this topic is for celebrate the creation of technique for write binary data using only batch developed in this topic:
http://www.dostips.com/forum/viewtopic.php?f=3&t=5326
For this I write a little tool reply.exe (1536 bytes) as replacement of old reply.com found here: http://support.microsoft.com/kb/77457
because 16 bits programs are not supported on 64 bit window system.
the source code of it is at the end of this post.
The program accept a keyboard input and return a numeric code. If the input is a extended key, example a arrow key, it sum 256 to the numeric code.
I'm interesed on creation of binary data using batch since 2010 and I read many things about this. I use succesfully utilities that generates .com files using only ascii files from authors like herbert kleebauer, laura fairhead, jim tucker, creation using debug, all it for 16 bits, and for 32 bits creation using vbscript (cscript, mshta), certutil. Also I wasted many time writing a utility called bhx that combine many techniques of it with focus on give support to windows 2000 and above systems of 64 bits, also combining the usage of cabinet files for reduce the file size.
But, now, finally is posible using only batch. (I think add this as module to bhx for a easy script generation). I celebrate this advance in the batch posting the creation of reply.exe using only batch. This method is good because not create a debug or vbs script. It write directly to the file using batch, not interpretation of a script is involved.
This generation of the executable using the function :genchr in this script is a prototype, but can serve as a guide for creation a binary using only batch, you only need change the hex data and the filenames. Note: I optimized for support only hex data with length of 60 characters. I choose this length in bhx and in this code because in the past I remember post some hex data on alt.msdos.batch.nt and get the script spoiled because large line length.
create_reply.cmd
Code: Select all
@echo off
REM creation of reply.exe a utility for get a user input key and know the value of it
setlocal enabledelayedexpansion
set "out=reply.cab"
>"!out!" type nul
echo creating reply.exe ...
call :w "4D53434600000000B8010000000000002C00000000000000030101000100"
call :w "0000000000004600000001000100000600000000000000003E44B31C2000"
call :w "7265706C792E65786500F8C5FE566A010006434BF38D9AC0C0CCC0C0C002"
call :w "C4FFFF3330EC6080000706C2A00188F9E477F1316CE13CABB883D1E7AC62"
call :w "484666B14241517E7A5162AE4272625E5E7E894252AA4251699E42669E82"
call :w "8B7FB0426E7E4AAA1E2F2F970AD48C005706061F462614731F30F0337333"
call :w "B2A15A2600C50A50D781D84C10773330206806038878395009334CA30032"
call :w "0DA72000689E0D117E2515D800CD15C123AF57925A51020D43985F185083"
call :w "01E4B404BD94C49244207B015400AC8605551DD0AB07C8756768E7D3C637"
call :w "20F326BC8804929DAE7FBA5DFFB41EE06F1105F2763C0012DDBE7F2C4FF0"
call :w "B7B002992FF980C40B4320D178808111A63AE0853A50A4F908CBC9C360D3"
call :w "40C64E00A7A3801720534E1E06A52D551B050730ED00A53D14884963A380"
call :w "B6204001C14E5180A4DB1824B17A20DB4301BBDE7CA0780554AE4701B758"
call :w "6E71597251895E4A4E0E90139F9E5A929C0164A45664963064A716E5A5E6"
call :w "181B41255D81620145F9C9A9C5C5A35143170000"
del *.chr
expand "!out!" reply.exe >nul
del "!out!"
echo Press a key ...
reply.exe
echo Key pressed: %errorlevel%
pause
goto :eof
:genchr
REM This code creates one single byte. Parameter: int
REM Teamwork of carlos, penpen, aGerman, dbenham
REM Tested under Win2000, XP, Win7, Win8
set "options=/d compress=off /d reserveperdatablocksize=26"
if %~1 neq 26 (type nul >t.tmp
makecab %options% /d reserveperfoldersize=%~1 t.tmp %~1.chr >nul
type %~1.chr | (
(for /l %%N in (1 1 38) do pause)>nul&findstr "^">temp.tmp)
>nul copy /y temp.tmp /a %~1.chr /b
del t.tmp temp.tmp
) else (copy /y nul + nul /a 26.chr /a >nul)
goto :eof
:w
set "line=%~1"
::get length upto 60 characters
::Function for get the length originally writted by jeb. Modified.
(set "z=0" &set "s=a!line!" &for %%a in (
64 32 16 8 4 2 1) do (set /a "z|=%%a"
for %%b in (!z!) do if "!s:~%%b,1!"=="" set /a "z&=~%%a"))
set /a "limit=z-2"
for /l %%# in (0,2,%limit%) do (
set /a "chr=0x!line:~%%#,2!"
if not exist !chr!.chr call :genchr !chr!
copy /y "!out!" /b + !chr!.chr /b "!out!" >nul
)
goto :eof
reply.c
// Compiled with tiny c for get a small executable
Code: Select all
#include <windows.h>
#include <conio.h>
void _start(void)
{
int ret = getch();
if (!ret || 0xE0 == ret) {
ret = 256 + getch();
}
exit(ret);
}
void avoid_false_positive() {
/* avira can detect a false positive on executables files with less bytes */
/* this fix it */
ExitProcess(0);
}