#1 01 May 2014 07:48

carlos
Member
From: Chile
Registered: 04 Nov 2008
Posts: 232
Website

Maybe for http://ss64.com/nt/makecab.html genchr.cmd create any byte

I have this code. I love this code because I thing combine many contributions for get the creation of any byte value.

Maybe it can appear in http://ss64.com/nt/makecab.html
It uses makecab for create any byte value.

This will works from windows 2000 to windows 8.

Usage:

genchr.cmd 0
rem this will create the 0 or nul character. file 0.chr
genchr.cmd 9
rem this will create the 9 or tab character. file 9.chr

The files will have the .chr extension.

genchr.cmd

REM This code creates one single byte. Parameter: <int>0-255
REM Teamwork of carlos, penpen, aGerman, dbenham
REM Tested under Win2000, XP, Win7, Win8

@echo off

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 "^">t.tmp)
>nul copy /y t.tmp /a %~1.chr /b
del t.tmp
) else (copy /y nul + nul /a 26.chr /a >nul)

Last edited by carlos (02 May 2014 21:19)

Offline

#2 01 May 2014 08:47

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 941

Re: Maybe for http://ss64.com/nt/makecab.html genchr.cmd create any byte

Nice code.

Minor change to validate input and also to allow concurrent runs, like if you want to generate multiple characters in one go with something like this:

D:\Documents\Scripts\ss64\p7665>for /l %a in (0,1,255) do start "" cmd /c genchr %a
@echo off
set "USAGE=echo:Usage: Supply an integer 0-255& goto :EOF"
if "%~1" equ ""      %USAGE%
set /a "val=%~1" 2>nul
if "%~1" neq "%val%" %USAGE%
if  %~1  lss 0       %USAGE%
if  %~1  gtr 255     %USAGE%

set tempfile=%1.tmp
set "options=/d compress=off /d reserveperdatablocksize=26"
if %~1 neq 26  (type nul >"%tempfile%"
makecab %options% /d reserveperfoldersize=%~1 "%tempfile%" %~1.chr >nul
type %~1.chr | (
(for /l %%N in (1 1 38) do pause)>nul&findstr "^">"%tempfile%")
>nul copy /y "%tempfile%" /a %~1.chr /b
del "%tempfile%"
) else (copy /y nul + nul /a 26.chr /a >nul)

Last edited by bluesxman (02 May 2014 11:02)


cmd | *sh  | KiX | AutoIT3 | PowerShell | Puppet

Offline

#3 01 May 2014 23:38

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 779
Website

Re: Maybe for http://ss64.com/nt/makecab.html genchr.cmd create any byte

Very nice!
I have put a copy of this here http://ss64.com/nt/syntax-genchr.html
with links from the makecab and Ascii table pages

Offline

#4 02 May 2014 00:19

carlos
Member
From: Chile
Registered: 04 Nov 2008
Posts: 232
Website

Re: Maybe for http://ss64.com/nt/makecab.html genchr.cmd create any byte

Thanks.
The bluexman code, need a little fix:

this

if "%~1" lss "0"     %USAGE%
if "%~1" gtr "255"   %USAGE%

need be:

if %~1 lss 0     %USAGE%
if %~1 gtr 255   %USAGE%

without quotes, else for example: genchr 3 print the usage text.

Offline

#5 02 May 2014 10:31

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 941

Re: Maybe for http://ss64.com/nt/makecab.html genchr.cmd create any byte

carlos wrote:

The bluexman code, need a little fix:

D'oh!  Thanks for exposing the flaw in my testing.  Fixed above.


cmd | *sh  | KiX | AutoIT3 | PowerShell | Puppet

Offline

#6 02 May 2014 13:56

carlos
Member
From: Chile
Registered: 04 Nov 2008
Posts: 232
Website

Re: Maybe for http://ss64.com/nt/makecab.html genchr.cmd create any byte

Thanks bluexmam. I tried send you a pm, but not found how.

Also. I want add a note about the tempfile.
It should be left as current is:
set tempfile=%1.tmp
or for avoid quote problem:
set tempfile=%~1.tmp

the decimal length of the ascii byte that you want ( %~1 ), plus ".tmp" or 4 characters.
This means, that if you create the 1 ascii, it should be: 1.tmp and if you create the 33 ascii, it should be 33.tmp
Is ok.
The tempfile name length is critical, because the filename is included in the cabinet file, and can affect the offset size, and cause that the code not generate correctly all the ascii bytes.
Actually, the code works ok: I test with a program all the ascii bytes generates, checking if the file generated is a 1 byte size and have in the content byte is the same that in the filename.

But, if you change the tempfile to other something like: _%1.temp it can cause that the generation of some bytes fail (It is only verified checking the .chr file generated, not because a warning of the batch).

Because all this explication, maybe a note about not change the tempfile name should be added, or not use a variable tempfile, for avoid the temptation of change it, that can cause corrupted .chr files.

Any change to the code, should be tested in all the 256 .chr files, having 1 byte and with the same ascii content.

I used this c code for test it: change.c
I run this in the same folder that have the .chr files.
First I delete all the .chr files, then I generate all using genchr
If you run this, and any message is printed, means that the generation is ok.

Actually, the code is ok, but because a variable is used for the temp filename, it is ok, but a note of change it can cause corrupted .chr files maybe should be added. The temp filename is relevant for the correct generation of .chr files.

Last edited by carlos (02 May 2014 13:58)

Offline

#7 02 May 2014 18:34

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 779
Website

Re: Maybe for http://ss64.com/nt/makecab.html genchr.cmd create any byte

from a brief test it looks like makecab is putting the filename at the end of the temporary file, so the filename length may not matter.

Offline

#8 02 May 2014 20:05

carlos
Member
From: Chile
Registered: 04 Nov 2008
Posts: 232
Website

Re: Maybe for http://ss64.com/nt/makecab.html genchr.cmd create any byte

Yes, Simon. I do more test and all my test works ok changing the filenames.
I not remember why, but in previous version, the temp filename was a problem for me.
Anyways, any change to the code, need verify the correct creation and content of the .chr files.

Please, update the code on the page with the fix.

Offline

#9 02 May 2014 20:55

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 779
Website

Re: Maybe for http://ss64.com/nt/makecab.html genchr.cmd create any byte

Does the version here look OK now
http://ss64.com/nt/syntax-genchr.html

Offline

#10 02 May 2014 21:19

carlos
Member
From: Chile
Registered: 04 Nov 2008
Posts: 232
Website

Re: Maybe for http://ss64.com/nt/makecab.html genchr.cmd create any byte

Thanks Simon, but current it left out the fix:
http://ss64.org/viewtopic.php?pid=7671#p7671

Offline

#11 02 May 2014 21:29

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 779
Website

Re: Maybe for http://ss64.com/nt/makecab.html genchr.cmd create any byte

You may need to do a shift-reload on the page to see the changes.

Offline

#12 03 May 2014 00:05

carlos
Member
From: Chile
Registered: 04 Nov 2008
Posts: 232
Website

Re: Maybe for http://ss64.com/nt/makecab.html genchr.cmd create any byte

Simon, it should have:

if  %~1  lss 0       %USAGE%
if  %~1  gtr 255     %USAGE%

Offline

#13 03 May 2014 00:31

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 779
Website

Re: Maybe for http://ss64.com/nt/makecab.html genchr.cmd create any byte

Of course, fixed now

Offline

Board footer

Powered by FluxBB