Jump to content











Photo
- - - - -

Is it possible to map ptn3:\uefi-ntfs.img to ptn3 of USB Drive using .cmd batch

uefi-ntfs.img rufus cmd .imgptn partimg

  • Please log in to reply
44 replies to this topic

#1 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 11 November 2021 - 03:35 PM

@Wonko, @Akeo, @Steve Si

 

Is it possible to map ptn3:\uefi-ntfs.img to ptn3 of MBR Partition Table of Multi-Partitioned USB Drive using .cmd batch ?

 

Please help ??



#2 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 11 November 2021 - 05:57 PM

If the question is general. i.e.

Can I map a disk extent to a partition table entry?

The answer is "yes".

 

If the question is more specific, i.e.:

Can I do the above in .cmd batch, the answer is (obviously) yes as long as you use a command line program capable of writing to disk like -say - dsfo/dsfi or similar and something like hexalter or similar to write the actual hex partition table somewhere, temporary file or similar (or -seen the other way - no it is not possible in pure batch).

 

No idea what (the heck) is the "ptn3:\uefi-ntfs.img" you are talking about, if it is or can be accessed as a contiguous extent on disk, then the answer is yes, see above.

 

As always if you could explain in a DETAILED manner what the issue (or idea) you have (the actual goal as opposed to the means you think suited to obtain it) it would be easier to avoid the possibility of slipping on a chocolate covered banana:

http://jdebp.info/FGA/

http://jdebp.info/FG...red-banana.html

 

:duff:

Wonko

 

P.S. as a side note, it would be like three or four commands/lines in grub4dos batch, if it can be used


  • devdevadev likes this

#3 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 11 November 2021 - 06:36 PM

Thanks for quick reply and reminding dsfo/dsfi tool .....

As you said it is already done using g4d/Grub2 commands in E2B+agFM partition image approach (PTN3:/_ISO/uefi-ntfs.imgptnrep3). But I want to map Rufus/Akeo uefi-ntfs.img partition image (Contiguous) to partition 3 of USB Drive using dsfo/dsfi or any other command line tools that will be suitable and easy to use within a .cmd batch file.

#4 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 11 November 2021 - 07:31 PM

Essentially you have most of the batch code in mbrbatch/mkimg:

 

http://reboot.pro/in...pic=3191&page=1

 

or in one of the mods:

http://reboot.pro/in...showtopic=20213

http://reboot.pro/in...?showtopic=9033

 

:duff:

Wonko


  • devdevadev likes this

#5 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 12 November 2021 - 03:31 PM

@echo off
set DD=1
set FILE="G:\_ISO\UEFI_NTFS.imgPTNrep3"
set FILESTART= ?
set FILELENGTH= ?

How to get FILESTART and FILELENGH of %FILE% in Decimal (LBA/Sectors) instead of Hex value ?
Does MBRBatch.cmd accept StartLBA and SectorsLBA in hex ?

AFAICU, I should use codes as follows ?
mbrbatch.cmd VIEW %DD%
pause
mbrbatch.cmd COPY %DD% my_MBR.mbr
mbrbatch.cmd VIEW my_MBR.mbr
pause
mbrbatch.cmd CHANGE my_MBR.mbr 255/63 3 0E 0 LBA %FILESTART% %FILELENGTH%
mbrbatch.cmd VIEW my_MBR.mbr
pause & pause
mbrbatch.cmd WRITE my_MBR.mbr %DD%
pause


Does MBRBatch.cmd also do any changes in Reserved Sectors of PBR ?


Thanks & Regards...

#6 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 12 November 2021 - 07:35 PM

How to get FILESTART and FILELENGH of %FILE% in Decimal (LBA/Sectors) instead of Hex value ?

How to get them in hex value?

Once you have them (how?[1]) in hex you convert them to decimal if needed.

 

Does MBRBatch.cmd also do any changes in Reserved Sectors of PBR ?

 

No, it is meant to only deal with the MBR.

 

To clarify, what I meant by:

 

 

Essentially you have most of the batch code in mbrbatch/mkimg:

 

 

was that those batches contain code/formulas that can be of inspiration to write your own batch script.

 

The functions in mbrbatch cmd "as is" can - at the most - prepare the mbr partition entry.

 

:duff:

Wonko

 

[1] basically you want to write a script (and you will need to find a suitable program to be used combined with it) capable of replacing the blocklist command in grub4dos.



#7 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 13 November 2021 - 01:33 PM

Most probably the easiest tool to integrate into the batch setup is fsutil

fsutil file queryextents

but the queryextents is not in all windows versions AFAICR, and parsing its output may be tricky.

 

Another possibility is myfragmenter (part of mydefrag).

 

But we have "our own" (in the sense of in-house) tool, extents:

http://reboot.pro/in...ic=18570&page=1

 

That directly outputs LBA's (as opposed to VCN's that would need to be translated depending on the filesystem) in decimal.

 

The little batch here:

http://reboot.pro/in...=18570&p=210184

should be checked on the output of the most recent version, 1.4 if I recall correctly, but should as well give you inspiration.

 

:duff:

Wonko 


  • devdevadev likes this

#8 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 13 November 2021 - 07:59 PM

AFAIK, Both Grub4dos and Grub2 uses partnew command in order to map partition image into USB Drive Partitions.

Can you please explain what exact modification partnew command do in MBR and PBR of USB Drive ?

Can you please provide a PartImg.cmd / Partnew.cmd that will allow us to map a partition image into USB Drive partition using .cmd batch file !

 

UE FI_NTFS.cmd

@echo off
pushd "%~dp0"
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
set DD=1
set PTN3=G:
if exist "G:\_ISO\uefi-ntfs.imgptnrep3" call :GETFILEEXTENTS "%PTN3%\_ISO\uefi-ntfs.imgptnrep3"
pause
if exist "G:\_ISO\uefi-ntfs.imgptnrep3" call :UEFI_NTFS "%PTN3%\_ISO\uefi-ntfs.imgptnrep3"
pause


:UEFI_NTFS
FOR /F "tokens=1,2,3,4,5,6 delims=:-" %%A IN ('extents-win32.exe "%~1"') DO (
SET ThisToken1=%%A
SET ThisToken1=!ThisToken1: =_!
SET my!ThisToken1!=%%B
IF !ThisToken1!==extents_[0]_ CALL :get_LBA Start_LBA %%E&&CALL :get_LBA Length_LBA %%F
)
SET Filename="%~1"

IF %myExtents_count_%==1 (
ECHO File is contiguous
) ELSE (
ECHO File is NOT contiguous
ECHO A suffusion of yellow ...
GOTO :EOF
)
ECHO Filename=%Filename%
ECHO Start_LBA=%Start_LBA%
ECHO Length_LBA=%Length_LBA%
pause
pause
mbrbatch.cmd VIEW %DD%
mbrbatch.cmd COPY %DD% my_MBR.mbr
mbrbatch.cmd VIEW my_MBR.mbr
mbrbatch.cmd CHANGE my_MBR.mbr 255/63 3 0E 0 LBA %Start_LBA% %Length_LBA%
mbrbatch.cmd VIEW my_MBR.mbr
pause
pause
pause
mbrbatch.cmd WRITE my_MBR.mbr %DD%
pause
GOTO :EOF

:get_LBA
SET %1=%2
GOTO :EOF



:GETFILEEXTENTS
for /f "tokens=5,7 delims=: " %%A in ('getfileextents "%~1"') do (set START=%%A & set LENGTH=%%B)
for /f "tokens=3" %%A in ('hex2dec.exe -nobanner 0x%START%') do set STARTLBA=%%A
for /f "tokens=3" %%A in ('hex2dec.exe -nobanner 0x%LENGTH%') do set LENGTHLBA=%%A
set FILE="%~1"
echo FILE=%FILE%
echo STARTLBA=%STARTLBA%
echo LENGTHLBA=%LENGTHLBA%
goto :EOF

This is what I can understood so far. Maybe modification in PBR will also be required ? Don't know what exactly and how ?

Am I using correct codes in above UEFI_NTFS.cmd batch file ? Any Suggestions Please.....

 

Thanks & Regards....



#9 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 13 November 2021 - 11:15 PM

It seems to me like you are on the right track.

in grub4dos the partnew command writes the partition entry in the MBR:
Active/non active
partition tape
chs start
chs end
lba start
lba length
then it checks the PBR and writes to it:
lba start (sectors before or hidden sectors)
lba length (volume size)
[1]

These two fields are at different offsets in the BPB of the PBR depending on filesystem.

In your specific case you need not to check the filesystem as the image is fixed (I presume FAT 32).

So it is just a matter of copying the LBA fields from the partition entry in the MBR to the right offset in the PBR sector.

:duff: 

Wonko
 
[1] maybe it also checks the CHS data, but nowadays, given their size, *any* device should be 255/63 anyway, and the CHS values in the boot sector are AFAICR only used by some boot sector code (which - if needed - can be patched:
http://reboot.pro/to...sector/?p=73205
 
P.S.: maybe useful, maybe not, there is also this other small batch (intended for FAT12/16 boot sectors, but the general idea is the same):
https://msfn.org/boa...comment=1001712



#10 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 17 November 2021 - 01:33 PM

:DOEDIT
................
.............................
if "%PROCESSOR_ARCHITECTURE%" == "AMD64" goto echooox64bypass
if not exist echoo.com (
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6
echo ?@xAyJHmH@=a?}VjuN?_LEkS?`w`s_{OCIvJDGEHtc{OCIKGMgELCI?GGg
echo EL?s?WL`LRBcx=k_K?AxVD?fCo?Cd?BLDs0
)>>echoo.com 
echoo.com %DataString% >TMPDATA.$$$
goto echooobpatbypass
:echooox64bypass
echo 0123456789ABCD>TMPDATA.$$$
bpatcher.exe TMPDATA.$$$ 00 %Active%
bpatcher.exe TMPDATA.$$$ 01 %BHd%
bpatcher.exe TMPDATA.$$$ 02 %BSec%
bpatcher.exe TMPDATA.$$$ 03 %BCyl%
bpatcher.exe TMPDATA.$$$ 04 %Parttype%
bpatcher.exe TMPDATA.$$$ 05 %EHd%
bpatcher.exe TMPDATA.$$$ 06 %ESec%
bpatcher.exe TMPDATA.$$$ 07 %ECyl%
bpatcher.exe TMPDATA.$$$ 08 %StartLBA:~0,2%
bpatcher.exe TMPDATA.$$$ 09 %StartLBA:~2,2%
bpatcher.exe TMPDATA.$$$ 0A %StartLBA:~4,2%
bpatcher.exe TMPDATA.$$$ 0B %StartLBA:~6,2%
bpatcher.exe TMPDATA.$$$ 0C %SectorsLBA:~0,2%
bpatcher.exe TMPDATA.$$$ 0D %SectorsLBA:~2,2%
bpatcher.exe TMPDATA.$$$ 0E %SectorsLBA:~4,2%
bpatcher.exe TMPDATA.$$$ 0F %SectorsLBA:~6,2%
:echooobpatbypass
dsfi %source% %Offset% %Length% TMPDATA.$$$>nul
GOTO :EOF

Can you please explain why different approach is used in order to create TMPDATA.$$$ file for AMD64 processor ?

echoo.com %DataString% >TMPDATA.$echoo.com %DataString% >TMPDATA.$$$ nbsp; 

What function is done by echoo.com in above command ?

echo 0123456789ABCD>TMPDATA.$$ 

Why you just used 0123456789ABCD instead of 0123456789ABCDEF in above command ?

 

 

Please explain functioning of :doedit function a bit details so we can grasp it easily....

 

Thanks & Regards...



#11 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 17 November 2021 - 02:12 PM

echoo.com is a small (pure assembler) program that won't run on 64 bit (and probably also not on some post - XP Windows versions :unsure:).

 

Some history/reference:

http://reboot.pro/in...ic=2681&p=21795

 

The echo command in batch will append a CR+LF to the string, so to have 16 bytes you need a 14 bytes string.

 

bpatcher modifies the file you create with "plain" echo before, as it is a patcher and doesn't create the file.

 

You could use alternatively hexalter:

https://web.archive..../hexalter.shtml

but it is as well a patcher, that can modify an existing file.

 

Since you will have anyway dsfi/dsfo handy, you can use fsz (same dsfok package) to create the file.

 

:duff:

Wonko



#12 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 21 November 2021 - 03:36 PM

It's very tough for me to grasp how exactly MBRTEMP.$$$ will be created from following variables ?

00 %Active%
01 %BHd%
02 %BSec%
03 %BCyl%
04 %Parttype%
05 %EHd%
06 %ESec%
07 %ECyl%
08 %StartLBA:~0,2%
09 %StartLBA:~2,2%
0A %StartLBA:~4,2%
0B %StartLBA:~6,2%
0C %SectorsLBA:~0,2%
0D %SectorsLBA:~2,2%
0E %SectorsLBA:~4,2%
0F %SectorsLBA:~6,2%

Maybe I also have to create PBRTEMP.$$$ file which will be written over reserved bytes of PBR ??

00 %StartLBA:~0,2%
01 %StartLBA:~2,2%
02 %StartLBA:~4,2%
03 %StartLBA:~6,2%

How exactly I can create 16 Bytes MBRTEMP.$$$ and 4 Byte PBRTEMP.$$$ from above variables ? Which tool will be best to use for this purpose ?
Please provide a PartImg.cmd which will modify both MBR and PBR ???
Your batch files codes are a bit tricky and beyond my head...I am still stuck within :doedit function of MBRBatch.cmd
Please simlify :doedit section if you have some free time ??

Thanks & Regards...

#13 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 21 November 2021 - 06:04 PM

You don't need to create a PBRTEMP.$$$ at all you can use bpatcher to directly patch the copy (gathered with dsfi) of the PBR.

 

In case you would need an 8 byte file, as StartLBA is 4 bytes and SectorsLBA is another 4 bytes, 4+4=8.

 

bpatcher writes single bytes with syntax

bpatcher.exe <target> <(hex)offset> <(hex) value>

 

When you run (example):

bpatcher.exe TMPDATA.$$$ 0F %SectorsLBA:~6,2%

it means:

go into (already existing file) TMPDATA.$$$ at offset 15 and replace whatever byte is there with the byte corresponding to the (hex value) of the last two characters of variable %SectorsLBA%.

 

The original MBRbatch uses echoo.com that writes in a single pass the 16 bytes to a new file, the workaround using bpatcher is to first create a 16 bytes file, then replace bytes in it one at the time.

 

What is not understandable?

 

Nowadays it may be simpler to use the Win32 port of xxd (but you need anyway the temporary file):

https://sourceforge....xd-for-windows/

 

Example:





@ECHO OFF
SET hexstring=000102030405060708090A0B0C0D0E0F
ECHO %hexstring% > test.hex

xxd -l 32 -ps -r test.hex test.bin
xxd test.bin
ECHO.
TYPE test.hex
xxd -ps -u test.bin

Or - even easier - the bytepatch tool here:

http://bytepointer.c...x.htm#bytepatch

which - like hexalter and unlike bpatcher can write multiple bytes in one pass, but needs not the comma separator or the 0x prefix.

 

:duff:

Wonko



#14 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 22 November 2021 - 01:16 PM

echo 0123456789ABCD>TMPDATA.$$$

The echo command in batch will append a CR+LF to the string, so to have 16 bytes you need a 14 bytes string.

echo command create TMPDATA.$$$ file in plain text. How echo command add CR+LF to the string and where ? What is CR+LF ? Is this feature or bug of echo command ?

Can we not put hex values directly within TEMPDATA.$$$ using echo command ?

SET DataString=$%Active%$%BHd%$%BSec%$%BCyl%$%PartType%$%EHd%$%ESec%$%ECyl%$%StartLBA:~0,2%$%StartLBA:~2,2%$%StartLBA:~4,2%$%StartLBA:~6,2%$%SectorsLBA:~0,2%$%SectorsLBA:~2,2%$%SectorsLBA:~4,2%$%SectorsLBA:~6,2%

Why $ is added in betwwen of string ?



#15 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 22 November 2021 - 01:50 PM

Echo (the built in command) is intended to "print to screen".

It is intended for printable characters.

It appends to the text provided a CR+LF (Carriage Return+Line Feed) which is the standard "new line" in DOS and Windows, hex 0x0D and 0x0A.

 

No bugs, it is designed that way.

 

The $ is added to the string for use with the echoo.com, as it is designed to "recognize" a hex value by having a $ pre-pended to it, echoo.com can be used with normal text as well.

 

i.e.

echoo.com This_is_20$2020

will output

This_is_20[SPACE]20

 

 

 

Can we not put hex values directly within TEMPDATA.$$$ using echo command ?

 

Think a bit about it, IF "we" could, do you really think "we" would use a self-generating com file or use external programs like bpatcher, hexalter, xxd or bytepatch? :dubbio:

 

:duff:

Wonko


  • devdevadev likes this

#16 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 02 December 2021 - 02:58 PM

It's looking Pmode variable is not properly described/defined in MBRBatch ?
Why you use CHANGE command in :MBRHELPEDIT instead of EDIT command ?
While CHANGE command is not used within MBRBatch.cmd ??
Is something is wrongly described within :MBRHELPEDIT ??
 
:MBRHELPEDIT
CLS
ECHO EDIT   [source] [MBRparams]	Edits one partition entry in MBR file
ECHO.
ECHO Source can be ONLY a MBR file (CREATEd or COPYed).
ECHO.
ECHO [MBRparams] are a bit complex:
ECHO Geometry Part PartType Active PMode [More_parameters]
ECHO.
ECHO Geometry = Drive Geometry, Heads/Sectors, under 2K/XP/2003 255/63,
ECHO            but values accepted are 255/63, 128/63, 16/63, 
ECHO.
ECHO Part     = number of partition entry - can be 1, 2, 3 or 4
ECHO.
ECHO PartType = Partition type - can be:
ECHO		01 FAT12
ECHO		04 FAT16 <32 Mb (obsolete)
ECHO 		06 FAT16 CHS mapped ³
ECHO 		07 NTFS             ³
ECHO 		0B FAT32 CHS mapped ³ NO support for extended partitions
ECHO 		0C FAT32 LBA mapped ³
ECHO 		0E FAT16 LBA mapped ³
ECHO.
ECHO Active =   Active flag for entry - can be 0 (NOT Active) or 80 (Active)
ECHO.
ECHO PMode  =   Program Mode - can be either CHS or LBA
ECHO.
PAUSE
CLS
ECHO PMode  =   Program Mode - can be either CHS or LBA
ECHO.
ECHO If Pmode = CHS, six more parameters are needed:
ECHO.
ECHO CHANGE [source] Geometry Part PartType Active CHS BCyl BHd BSec ECyl EHd ESec
ECHO.
ECHO BCyl = Beginning Cylinder
ECHO BHd  = Beginning Head
ECHO BSec = Beginning Sector 
ECHO ECyl = Ending Cylinder
ECHO EHd  = Ending Head
ECHO ESec = Ending Sector
ECHO.
ECHO If Pmode = LBA, only two more parameters are needed:
ECHO.
ECHO CHANGE [source] Geometry Part PartType Active LBA StartLBA SectorsLBA
ECHO.
ECHO StartLBA   = LBA address of first sector
ECHO SectorsLBA = Number of sectors in partition
ECHO.
ECHO The batch in CHS mode will calculate LBA values, whilst in LBA mode it
ECHO will calculate CHS ones.
ECHO.
PAUSE
CLS
REM and the preceding CHS ones are calculated by the batch
ECHO Due to number and complexity of parameters, this batch is better suited to be
ECHO either called from within another batch or in interactive mode.
ECHO.
ECHO Please use some common sense for filenames:
ECHO NO spaces in name, extension or path, the batch has been tested
ECHO ONLY with "pure" DOS 8.3 names
ECHO.
ECHO EXAMPLES:
ECHO %~nx0 CHANGE my_MBR.mbr 255/63 1 0B 80 CHS 0 1 1 127 254 63
ECHO %~nx0 CHANGE my_MBR.mbr 255/63 1 0B 80 LBA 63 2056257
PAUSE
GOTO :EOF
:MBREDIT
:parseparams
REM Needed parameters are:
REM 1) Source (and Target, they are the same) file
REM 2) Geometry= Drive Geometry, Heads/Sectors, under 2K/XP/2003 255/63, but values accepted are 255/63, 128/63, 16/63, 64/32
REM 3) PMode= Program Mode - can be either CHS or LBA
REM 4) Partnum=number of partition entry - can be 1, 2, 3 or 4
REM 5) PartType= Partition type - can be:
REM 01 FAT12
REM 04 FAT16 <32Mb (obsolete)
REM 06 FAT16 CHS mapped
REM 07 NTFS
REM 0B FAT32 CHS mapped
REM 0C FAT32 LBA mapped
REM 0E FAT16 LBA mapped
REM NO support for extended partitions of any kind!
REM 6) Active= whether the partition is Active or not - can be 0 (NOT Active) or 80 (Active)
REM
REM If Pmode=CHS following parameters are needed:
REM 7) BCyl= Beginning Cylinder
REM 8) BHd= Beginning Head
REM 9) BSec= Beginning Sector 
REM 10) ECyl= Ending Cylinder
REM 11) EHd= Ending Head
REM 12) ESec= Ending Sector
REM 13) (Optional) /S to make the batch operate silently
REM and following ones are calculated by the batch
REM 
REM If Pmode=LBA following parameters are needed:
REM 7) StartLBA= LBA address of first sector
REM 8) SectorsLBA= Number of sectors in partition
REM 9) (Optional) /S to make the batch operate silently
REM and the preceding CHS ones are calculated by the batch
REM Due to number and complexity of parameters, this batch is better suited to be
REM either called from within another batch or in interactive mode
SET OK=0
SHIFT
Set Source=%1
IF DEFINED Source IF EXIST %Source% SET /A OK+=1 
Set Geometry=%2
Set Pmode=%3
Set Partnum=%4
Set Parttype=%5
Set Active=%6
SHIFT
SHIFT
SHIFT
SHIFT
IF %Pmode%.==LBA. (
Set StartLBA=%3
Set SectorsLBA=%4
Set Silent=%5
FOR %%A IN (StartLBA SectorsLBA) DO IF NOT DEFINED %%A SET DATA=0
)
IF %Pmode%.==CHS. (
Set BCyl=%3
Set BHd=%4
Set BSec=%5
Set ECyl=%6
Set EHd=%7
Set ESec=%8
Set Silent=%9
FOR %%A IN (BCyl BHd BSec ECyl EHd ESec) DO IF NOT DEFINED %%A  SET DATA=0
)
FOR %%A IN (255/63 128/63 16/63 64/32) DO IF /I %Geometry%.==%%A. SET Geometry=%%A&SET /A OK+=10
FOR %%A IN (CHS LBA) DO IF /I %PMode%.==%%A. SET PMode=%%A&SET /A OK+=100
FOR %%A IN (1 2 3 4) DO IF %Partnum%.==%%A. SET Partnum=%%A&SET /A OK+=1000
FOR %%A IN (01 04 06 07 0B 0C 0E) DO IF /I %PartType%.==%%A. SET PartType=%%A&SET /A OK+=10000
FOR %%A IN (00 80) DO IF %Active%.==%%A. SET Active=%%A&SET /A OK+=100000
IF %OK% lss 111111 GOTO :MBREDITI
IF %DATA%.==0. GOTO :MBREDITI
GOTO :is%Pmode%


#17 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 03 December 2021 - 09:44 AM

Pmode is either CHS or LBA.

 

Its value determines the number and order of following parameters.

 

For *some reasons* the help text mixed together EDIT and CHANGE, diddy noticed it, read starting here

http://reboot.pro/in...ge=2#entry70483

and the glitch was corrected.

 

WHICH version of MBRBATCH.CMD are you using?

 

It was fixed in 0.03:

http://reboot.pro/in...ic=3191&p=70584

 

Anyway, CHANGE does nothing, use EDIT, from 0.03:



:MBRHELPEDIT
CLS
ECHO EDIT   [source] [MBRparams]	Edits one partition entry in MBR file
ECHO.
ECHO Source can be ONLY a MBR file (CREATEd or COPYed).
ECHO.
ECHO [MBRparams] are a bit complex:
ECHO Geometry PMode Part PartType Active [More_parameters]
ECHO.
ECHO Geometry = Drive Geometry, Heads/Sectors, under 2K/XP/2003 255/63,
ECHO            but values accepted are 255/63, 128/63, 16/63, 
ECHO.
ECHO PMode    = Program Mode - can be either CHS or LBA
ECHO.
ECHO Partnum  = number of partition entry - can be 1, 2, 3 or 4
ECHO.
ECHO PartType = Partition type - can be:
ECHO			01 FAT12			³
ECHO			04 FAT16 ^<32 Mb (obsolete)	³
ECHO 		06 FAT16 CHS mapped 		³ NO support for
ECHO 		07 NTFS             		³
ECHO 		0B FAT32 CHS mapped 		³ extended partitions
ECHO 		0C FAT32 LBA mapped 		³
ECHO 		0E FAT16 LBA mapped 		³
ECHO.
ECHO Active =   Active flag for entry - can be 0 (NOT Active) or 80 (Active)

PAUSE
CLS
ECHO PMode  =   Program Mode - can be either CHS or LBA
ECHO.
ECHO If Pmode = CHS, six more parameters are needed:
ECHO.
ECHO EDIT [source] Geometry CHS Part PartType Active BCyl BHd BSec ECyl EHd ESec
ECHO.
ECHO BCyl = Beginning Cylinder
ECHO BHd  = Beginning Head
ECHO BSec = Beginning Sector 
ECHO ECyl = Ending Cylinder
ECHO EHd  = Ending Head
ECHO ESec = Ending Sector
ECHO.
ECHO If Pmode = LBA, only two more parameters are needed:
ECHO.
ECHO EDIT [source] Geometry LBA Part PartType Active StartLBA SectorsLBA
ECHO.
ECHO StartLBA   = LBA address of first sector
ECHO SectorsLBA = Number of sectors in partition
ECHO.
ECHO The batch in CHS mode will calculate LBA values, whilst in LBA mode it
ECHO will calculate CHS ones.
ECHO.
PAUSE
CLS
REM and the preceding CHS ones are calculated by the batch
ECHO Due to number and complexity of parameters, this batch is better suited to be
ECHO either called from within another batch or in interactive mode.
ECHO.
ECHO Please use some common sense for filenames:
ECHO NO spaces in name, extension or path, the batch has been tested
ECHO ONLY with "pure" DOS 8.3 names
ECHO.
ECHO EXAMPLES:
ECHO %~nx0 EDIT my_MBR.mbr 255/63 CHS 1 0B 80 0 1 1 127 254 63
ECHO %~nx0 EDIT my_MBR.mbr 255/63 LBA 1 0B 80 63 2056257
PAUSE
GOTO :EOF

:duff:

Wonko



#18 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 03 December 2021 - 03:20 PM

In MBRBatch 0.03 you have used only echoo.com. Will echoo.com work for all operating Systems (Both 32-bit and 64-bit Windows 7/8.1/10) ?

if not exist echoo.com (
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6
echo ?@xAyJHmH@=a?}VjuN?_LEkS?`w`s_{OCIvJDGEHtc{OCIKGMgELCI?GGg
echo EL?s?WL`LRBcx=k_K?AxVD?fCo?Cd?BLDs0
)>>echoo.com 
echoo.com %DataString% >TMPDATA.$$$
dsfi my_MBR.mbr %Offset% %Length% TMPDATA.$$$>nul

while you have use both echoo.com and bpatcher.exe in MBRBatch 0.02 as follows 

if "%PROCESSOR_ARCHITECTURE%" == "AMD64" goto echooox64bypass
if not exist echoo.com (
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6
echo ?@xAyJHmH@=a?}VjuN?_LEkS?`w`s_{OCIvJDGEHtc{OCIKGMgELCI?GGg
echo EL?s?WL`LRBcx=k_K?AxVD?fCo?Cd?BLDs0
)>>echoo.com 
echoo.com %DataString% >TMPDATA.$$$
goto echooobpatbypass
:echooox64bypass
echo 0123456789ABCD>TMPDATA.$$$
bpatcher.exe TMPDATA.$$$ 00 %Active%
bpatcher.exe TMPDATA.$$$ 01 %BHd%
bpatcher.exe TMPDATA.$$$ 02 %BSec%
bpatcher.exe TMPDATA.$$$ 03 %BCyl%
bpatcher.exe TMPDATA.$$$ 04 %Parttype%
bpatcher.exe TMPDATA.$$$ 05 %EHd%
bpatcher.exe TMPDATA.$$$ 06 %ESec%
bpatcher.exe TMPDATA.$$$ 07 %ECyl%
bpatcher.exe TMPDATA.$$$ 08 %StartLBA:~0,2%
bpatcher.exe TMPDATA.$$$ 09 %StartLBA:~2,2%
bpatcher.exe TMPDATA.$$$ 0A %StartLBA:~4,2%
bpatcher.exe TMPDATA.$$$ 0B %StartLBA:~6,2%
bpatcher.exe TMPDATA.$$$ 0C %SectorsLBA:~0,2%
bpatcher.exe TMPDATA.$$$ 0D %SectorsLBA:~2,2%
bpatcher.exe TMPDATA.$$$ 0E %SectorsLBA:~4,2%
bpatcher.exe TMPDATA.$$$ 0F %SectorsLBA:~6,2%
:echooobpatbypass
dsfi my_MBR.mbr %Offset% %Length% TMPDATA.$$$>nul

Should I use codes of MBRBatch 0.02 (both echoo.com and bpatcher.exe ) so that it will work for all operating Systems ??

What are the hex location of Reserve Bytes in PBR ?

 

Regards...



#19 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 03 December 2021 - 07:00 PM

In MBRBatch 0.03 you have used only echoo.com. 

Not really.

 

Jaclaz wrote (writes?) batches that run (and are tested) on good ol' XP.

 

Lancelot adapted that batch to run on newer systems (and - I believe - on 64 bit) - essentially using bpatcher as a replacement for echoo.com.

 

It is well possible that he used as base the 0.02 and did not update his batch, it has to be checked but from what I recall (and re-read on the given reference) the "CHANGE" was only a leftover in the "help" part, i.e. "EDIT" worked also in version 0.02 but the "help" part was not correct (and only that part was corrected in 0.03).

 

So I believe that you can take the 

:MBRHELPEDIT

 

from "my " version 0.03 and replace it into Lancelot's version.

http://reboot.pro/in...ic=5000&p=45422

 

 

 

Will echoo.com work for all operating Systems (Both 32-bit and 64-bit Windows 7/8.1/10) ?

Definitely not, this is why Lancelot made his modified version.

 

As said earlier the echoo.com is a (pure assembler) 16 bit program.

 

The possibility of running 16 bit (.com) programs has been removed from Windows 64 bit, but I seem to remember :unsure: that were also some issues in the NTVDM in some later than XP version, even on 32 bit::

https://en.wikipedia...latform_support

 

 

 

Should I use codes of MBRBatch 0.02 (both echoo.com and bpatcher.exe ) so that it will work for all operating Systems ??

What are the hex location of Reserve Bytes in PBR ?

 

Yes, though, as said, probably nowadays it would make more sense to forget about echoo.com and also use instead of bpatcher one of the other suggested programs.

 

You DO NOT want to touch "reserve bytes" (nor "reserved sectors" that are part of the filesystem).

 

You may want to touch "Hidden sectors" ( that are often referred to as "Sectors Before") it may depend on the filesystem for which the PBR is made, for the "common" ones it is at the same offset:

FAT16 offset 0x01C

FAT32 offset 0x01C

NTFS offset  0x01C 

 

https://www.ntfs.com...tion-sector.htm

https://www.ntfs.com...-boot-modif.htm

https://www.ntfs.com...boot-sector.htm

 

:duff:

Wonko



#20 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 04 December 2021 - 03:09 PM

Don't know what exactly following ImgPart.cmd will do ? Will it serve my purpose ?

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SETLOCAL ENABLEEXTENSIONS
SET /A comline=0
FOR %%A IN (MAP HELP) DO IF /I %%A.==%1. SET /A comline=!comline!+1
IF NOT %comline%==1 GOTO :Syntax
GOTO :PARTIMG%1

:Syntax
ECHO.
ECHO %~nx0 batch file to map Partition Image to a Partition entry of USB Drive
ECHO by jaclaz, this file is licensed under my "CAREWARE" license:
ECHO http://home.graffiti.net/jaclaz:graffiti.net/careware.html
ECHO.
ECHO General syntax is %~nx0 COMMAND [parameters], commands are:
ECHO.
ECHO MAP [Disk] [parameters]   - Map Partition Image to a partition of USB Drive
ECHO HELP                      - Displays help for the given command
ECHO.
GOTO :EOF

:DEC2BIN
SET BINnum=
SET DECnum=%1
SET /A Val32768=%DECnum% / 32768
SET /A Mod32768=%DECnum% %% 32768
FOR %%A in (%Powers%) DO CALL:BINcalc %%A
FOR %%A in (%Powers%) DO SET BINnum=!BINnum!!Val%%A!
GOTO :EOF

:BINcalc
IF %1==1 GOTO :EOF
SET /A Div=%1 /2
SET /A Val%Div%=!Mod%1! / %Div%
SET /A Mod%Div%=!Mod%1! %% %Div%
GOTO :EOF

:BIN2DEC
SET DECnum=
SET BINnum=%1
SET BINLength=%2
Set Counter=0
FOR %%A IN (%Powers%) DO (
CALL :DECcalc %%A
SET /A Counter=!Counter!+1
)
FOR %%A IN (%Powers%) DO SET /A DECnum=!DECnum!+!Digit%%A!*%%A
GOTO :EOF

:DECcalc
SET digit%1=!BINNum:~%Counter%,1!
IF %Counter%==%BINLength% GOTO :EOF
GOTO :EOF

:DEC2hex
SET DECnum=%1
SET Numdig=%2
SET HEXnum=
SET Powers=268435456 16777216 1048576 65536 4096 256 16 1
::=======================================================
::| WARNING! Limit is 2147483647 i.e. 7FFFFFF  WARNING! |
::=======================================================
SET /A Limit=%DECnum%/16
IF %Limit% LSS 0 ECHO Out of Range &GOTO :EOF
SET /A Val268435456=%DECnum% / 268435456
SET /A Mod268435456=%DECnum% %% 268435456
FOR %%A in (%Powers%) DO CALL:HEXcalc %%A
FOR %%A in (%Powers%) DO CALL:HEXchar %%A
FOR %%A in (%Powers%) DO SET Hexnum=!Hexnum!!Val%%A!

SET /A Length=8
SET HexnumF=%Hexnum%
CALL :RemoveLead

GOTO :EOF

:RemoveLead
Set/A Length=%Length%-2
IF %HexnumF:~0,2%==00 set HEXnumF=!HexnumF:~-%Length%!&GOTO :RemoveLead
SET HexnumF=!Hexnum:~-%NumDig%!
SET Hexnum=%HexnumF:~6,2%%HexnumF:~4,2%%HexnumF:~2,2%%HexnumF:~0,2%
GOTO :EOF

:HEXcalc
IF %1==1 GOTO :EOF
SET /A Div=%1 /16
SET /A Val%Div%=!Mod%1! / %Div%
SET /A Mod%Div%=!Mod%1! %% %Div%
GOTO :EOF

:HEXchar
IF !Val%1!==10 SET Val%1=A
IF !Val%1!==11 SET Val%1=B
IF !Val%1!==12 SET Val%1=C
IF !Val%1!==13 SET Val%1=D
IF !Val%1!==14 SET Val%1=E
IF !Val%1!==15 SET Val%1=F
GOTO :EOF

:PARTIMGMAP
:parseparams
REM Needed parameters are:
REM 1) Disk= Disk Number
REM 2) Geometry= Drive Geometry, Heads/Sectors, under 2K/XP/2003 255/63, but values accepted are 255/63, 128/63, 16/63, 64/32
REM 3) Partnum=number of partition entry - can be 1, 2, 3 or 4
REM 4) PartType= Partition type - can be:
REM    01 FAT12
REM    04 FAT16 <32Mb (obsolete)
REM    06 FAT16 CHS mapped
REM    07 NTFS
REM    0B FAT32 CHS mapped
REM    0C FAT32 LBA mapped
REM    0E FAT16 LBA mapped
REM    NO support for extended partitions of any kind!
REM 5) Active= whether the partition is Active or not - can be 0 (NOT Active) or 80 (Active)
REM 6) StartLBA= LBA address of first sector
REM 7) SectorsLBA= Number of sectors in partition
REM 8) (Optional) /S to make the batch operate silently
REM and the preceding CHS ones are calculated by the batch
REM Due to number and complexity of parameters, this batch is better suited to be
REM either called from within another batch or in interactive mode
SET neededfiles=gsar.exe dsfo.exe dsfi.exe dumphex.exe
FOR %%A IN (%neededfiles%) DO IF NOT EXIST %%A ECHO Missing file: %%A& GOTO :ERROR1
SHIFT
SET OK=0
Set Disk=%1 
Set Geometry=%2
Set Partnum=%3
Set Parttype=%4
Set Active=%5
Set StartLBA=%6
Set SectorsLBA=%7
Set Silent=%8
FOR %%A IN (1 2 3 4 5 6 7 8 9) DO IF %Disk%.==%%A. SET Disk=%%A&SET /A OK+=1
FOR %%A IN (255/63 128/63 16/63 64/32) DO IF /I %Geometry%.==%%A. SET Geometry=%%A&SET /A OK+=10
FOR %%A IN (1 2 3 4) DO IF %Partnum%.==%%A. SET Partnum=%%A&SET /A OK+=100
FOR %%A IN (01 04 06 07 0B 0C 0E) DO IF /I %PartType%.==%%A. SET PartType=%%A&SET /A OK+=1000
FOR %%A IN (00 80) DO IF %Active%.==%%A. SET Active=%%A&SET /A OK+=10000
FOR %%A IN (StartLBA SectorsLBA) DO IF NOT DEFINED %%A SET DATA=0
IF %OK% lss 11111 GOTO :PARTIMGHELP
IF %DATA%.==0. GOTO :PARTIMGHELP
IF EXIST my_MBR.mbr DEL my_MBR.mbr
IF EXIST my_PBR.pbr DEL my_PBR.pbr
dsfo \\.\PHYSICALDRIVE%Disk% 0 512 my_MBR.mbr
dsfo \\.\PHYSICALDRIVE%Disk% %6 512 my_PBR.pbr
GOTO :isLBA

:isLBA
CALL :LBAtoCHS Start %StartLBA% %Geometry%
FOR /F "tokens=1,2,3 delims=/" %%A in ("%StartCHS%") DO SET /A BCyl=%%A&SET /A BHd=%%B&SET /A BSec=%%C
SET /A EndLBA=%StartLBA%+%SectorsLBA%-1
CALL :LBAtoCHS End %EndLBA% %Geometry%
FOR /F "tokens=1,2,3 delims=/" %%A in ("%EndCHS%") DO SET /A ECyl=%%A&SET /A EHd=%%B&SET /A ESec=%%C

:ConfirmParams
IF %BCyl% gtr 1023 SET /A BCyl=1023
IF %ECyl% gtr 1023 SET /A ECyl=1023
IF /I %Silent%.==/S. GOTO :DoSilent
ECHO Parameters are as follows:
:display
SET partline=³
FOR %%A IN ( 
Partnum.6
Parttype.11
Active.16
BCyl.23
BHd.27
BSec.32
ECyl.39
EHd.43
ESec.48
StartLBA.60
SectorsLBA.74
) DO (
CALL :adddata partline %%~nA %%~xA
)
CALL :display3 NOOLD
ECHO %partline%
IF %BCyl% gtr 1023 SET /A WBCyl=1023
IF %ECyl% gtr 1023 SET /A WECyl=1023
IF DEFINED WBCyl ECHO (The Beginning Cylinder will be written as %WBCyl%)
IF DEFINED WECyl ECHO (The Ending Cylinder will be written as %WECyl%)
GOTO :DoEdit

:DoEdit
ECHO Are you sure you want to write the above values to file %source%?
SET Confirm=NO
SET /P Confirm=Type YES to confirm: 
IF /I NOT %Confirm%.==YES. goto :EOF
ECHO Writing data....
:DoSilent
SET Powers=32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1
CALL :DEC2BIN %BCyl%
SET BCyl=%BINNUM:~-10,10%
CALL :DEC2BIN %BSec%
SET BSec=%BINNUM:~-6,6%
SET BSec=%BCyl:~0,2%%BSec%
SET BCyl=%BCyl:~-8,8%

CALL :DEC2BIN %ECyl%
SET ECyl=%BINNUM:~-10,10%
CALL :DEC2BIN %ESec%
SET ESec=%BINNUM:~-6,6%
SET ESec=%ECyl:~0,2%%ESec%
SET ECyl=%ECyl:~-8,8%
SET Powers=128 64 32 16 8 4 2 1

FOR %%A IN (BCyl BSec ECyl ESec) DO (
CALL :BIN2DEC !%%A! 8
SET %%A=!DECnum!
)

FOR %%A IN (BCyl BHd BSec ECyl EHd ESec) DO (
CALL :DEC2hex !%%A! 2
SET %%A=!HEXnum!
)
FOR %%A IN (StartLBA SectorsLBA) DO (
CALL :DEC2hex !%%A! 8
SET %%A=!HEXnum!
)
IF /I NOT %Silent%.==/S. FOR %%A IN ( PartType Active BCyl BHd BSec ECyl EHd ESec StartLBA SectorsLBA) DO SET %%A
SET DataString=$%Active%$%BHd%$%BSec%$%BCyl%$%PartType%$%EHd%$%ESec%$%ECyl%$%StartLBA:~0,2%$%StartLBA:~2,2%$%StartLBA:~4,2%$%StartLBA:~6,2%$%SectorsLBA:~0,2%$%SectorsLBA:~2,2%$%SectorsLBA:~4,2%$%SectorsLBA:~6,2%

REM Partition Data offset: 1=446 2=462 3=478 4=494
Set /A Offset=430+%Partnum%*16
Set /A Length=16

if "%PROCESSOR_ARCHITECTURE%" == "AMD64" goto echooox64bypass
if not exist echoo.com (
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6
echo ?@xAyJHmH@=a?}VjuN?_LEkS?`w`s_{OCIvJDGEHtc{OCIKGMgELCI?GGg
echo EL?s?WL`LRBcx=k_K?AxVD?fCo?Cd?BLDs0
)>>echoo.com 
echoo.com %DataString% >TMPDATA.$$$
goto echooobpatbypass
:echooox64bypass
echo 0123456789ABCD>TMPDATA.$$$
bpatcher.exe TMPDATA.$$$ 00 %Active%
bpatcher.exe TMPDATA.$$$ 01 %BHd%
bpatcher.exe TMPDATA.$$$ 02 %BSec%
bpatcher.exe TMPDATA.$$$ 03 %BCyl%
bpatcher.exe TMPDATA.$$$ 04 %Parttype%
bpatcher.exe TMPDATA.$$$ 05 %EHd%
bpatcher.exe TMPDATA.$$$ 06 %ESec%
bpatcher.exe TMPDATA.$$$ 07 %ECyl%
bpatcher.exe TMPDATA.$$$ 08 %StartLBA:~0,2%
bpatcher.exe TMPDATA.$$$ 09 %StartLBA:~2,2%
bpatcher.exe TMPDATA.$$$ 0A %StartLBA:~4,2%
bpatcher.exe TMPDATA.$$$ 0B %StartLBA:~6,2%
bpatcher.exe TMPDATA.$$$ 0C %SectorsLBA:~0,2%
bpatcher.exe TMPDATA.$$$ 0D %SectorsLBA:~2,2%
bpatcher.exe TMPDATA.$$$ 0E %SectorsLBA:~4,2%
bpatcher.exe TMPDATA.$$$ 0F %SectorsLBA:~6,2%
:echooobpatbypass
dsfi my_MBR.mbr %Offset% %Length% TMPDATA.$$$>nul
bpatcher.exe my_PBR.pbr 1C %StartLBA:~0,2%
bpatcher.exe my_PBR.pbr 1D %StartLBA:~2,2%
bpatcher.exe my_PBR.pbr 1E %StartLBA:~4,2%
bpatcher.exe my_PBR.pbr 1F %StartLBA:~6,2%
dsfi \\.\PHYSICALDRIVE%Disk% 0 512 my_MBR.mbr
dsfi \\.\PHYSICALDRIVE%Disk% %6 512 my_PBR.pbr
pause
IF EXIST my_MBR.mbr DEL my_MBR.mbr
IF EXIST my_PBR.pbr DEL my_PBR.pbr
GOTO :EOF

:LBAtoCHS
REM %1 is Variable name
REM %2 is the LBA value to convert
REM %3 is the disk geometry like 255/63
REM To get CHS from LBA:
REM CYL = LBA / (THds * TSec)
REM TEMPVAL = LBA % (THds * TSec)
REM HEAD = TEMP / TSec
REM SECT = TEMP % TSec + 1
REM Where:
REM LBA: linear base address of the block
REM CYL: value of the cylinder CHS coordinate
REM THds: Total number of heads per cylinder for the disk
REM HEAD: value of the head CHS coordinate
REM TSec: Total number of sectors per head for the disk
REM SECT: value of the sector CHS coordinate
REM TEMPVAL: buffer to hold a temporary value
SET /A LBA=%2
FOR /F "tokens=1,2 delims=/" %%A in ("%3") DO SET THds=%%A&SET TSec=%%B
SET /A TEMPVAL = THds * TSec
SET /A CYL = LBA/TEMPVAL
SET /A TEMPVAL = "%LBA% %% %TEMPVAL%"
SET /A HEAD = TEMPVAL/TSec
SET /A SECT = "%TEMPVAL% %% %TSec% + 1"
SET %1CHS=%CYL%/%HEAD%/%SECT%
GOTO :EOF

:checklength
SET /A Counter=0
SET data=!%1!
:LoopLength
SET /A Counter=%Counter%+1
IF NOT "%data%"=="!data:~0,%Counter%!" GOTO :LoopLength
SET /A %1Length=Counter
GOTO :EOF

:Padzeroes
SET /A sCounter=%sCounter%+1
SET String=%String%$00
IF NOT %sCounter%==%1 goto :Padzeroes
IF %2.==MagSig. SET String=%String%$55$AA
ECHoo.com %String%>> test.mbr
GOTO :EOF

:checkstrings
REM Parameters are:
REM Variable Goodnumber Goodvalue Sep_offset
FOR %%A IN (%Range%) DO IF /I !%1!.==%%A. SET /A Goodparam=%Goodparam%+%2
IF NOT %Goodparam%==%3 GOTO :EOF
CALL :adddata partline %1 %4
CLS&CALL :display3
ECHO %partline%
GOTO :EOF

:checkvalues
REM Parameters are:
REM Variable Goodnumber Goodvalue Sep_offset min max 
IF !%1! Geq %5 IF !%1! Leq %6 SET /A Goodparam=%Goodparam%+%2
IF NOT %Goodparam%==%3 GOTO :EOF
CALL :adddata partline %1 %4
CLS&CALL :display3
ECHO %partline%
GOTO :EOF

:display3
IF %1.==NOOLD. goto :NOOLD
For %%A IN (a b c d e 1 f 2 f 3 f 4 g) DO ECHO !Line%%A!
:NOOLD
ECHO.
ECHO Drive geometry: %Geometry% Program Mode: %PMode%
ECHO ÚÄÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
ECHO ³Part ³Type³Boot³  Begin   CHS  ³   End   CHS   ³ LBA Start ³ LBA Sectors ³
ECHO ³  #  ³    ³    ³ BCyl ³BHd³BSec³ ECyl ³EHd³ESec³           ³             ³
ECHO ÃÄÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÅÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÅÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
GOTO :EOF

:adddata
if %3.==. GOTO :EOF
set templine=%1
set thisline=!%templine%!
set pad=%2
set pad=!%pad%!³
set sepoffset=%3
set sepoffset=%sepoffset:.=%
:dataloop
SET templine=%thisline%%pad%
set pad= %pad%
IF NOT "!templine:~%sepoffset%,1!"=="³" goto :dataloop
SET %1=%templine%
GOTO :EOF

:PARTIMGHELP
ECHO.
ECHO Syntax :
ECHO.
ECHO %~nx0 MAP [Disk] [Geometry] [Partnum] [PartType] [Active] [StartLBA] [SectorsLBA] [/S]
ECHO.
ECHO Disk       = Disk Number
ECHO.
ECHO Geometry   = Drive Geometry, Heads/Sectors, under 2K/XP/2003 255/63,
ECHO              but values accepted are 255/63, 128/63, 16/63, 
ECHO.
ECHO Partnum    = number of partition entry - can be 1, 2, 3 or 4
ECHO.
ECHO PartType   = Partition type - can be:
ECHO 		  01 FAT12			³
ECHO 		  04 FAT16 ^<32 Mb (obsolete)	³
ECHO 		  06 FAT16 CHS mapped 		³ NO support for
ECHO 		  07 NTFS             		³
ECHO 		  0B FAT32 CHS mapped 		³ extended partitions
ECHO 		  0C FAT32 LBA mapped 		³
ECHO 		  0E FAT16 LBA mapped 		³
ECHO.
ECHO Active     = Active flag for entry - can be 0 (NOT Active) or 80 (Active)
ECHO.
ECHO StartLBA   = LBA address of first sector
ECHO.
ECHO SectorsLBA = Number of sectors in partition
ECHO.
ECHO EXAMPLES:
ECHO %~nx0 1 255/63 1 0B 80 63 2056257 /S
PAUSE
GOTO :EOF


:error
ECHO An error has occurred
GOTO :EOF

:error1
ECHO Please add the missing file in the same directory where %~nx0 is
GOTO :EOF

:Temporary_Code
if not exist echoo.com (
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6
echo ?@xAyJHmH@=a?}VjuN?_LEkS?`w`s_{OCIvJDGEHtc{OCIKGMgELCI?GGg
echo EL?s?WL`LRBcx=k_K?AxVD?fCo?Cd?BLDs0
)>>echoo.com 

Set /A Length=512
SET /A sCOUNTER=0
SET /A BCOUNTER=0
SET String=
FOR /F "tokens=2 delims=: " %%A IN ('dumphex /s%Offset% /L%Length% /w1 /nc %SystemRoot%\System32\dmadmin.exe') DO (
SET /A sCOUNTER=!sCOUNTER!+1
SET String=!String!$%%A
IF !sCOUNTER!==32 (
ECHoo.com !String!>> %2
SET sCOUNTER=0
SET /A BCOUNTER=!BCOUNTER!+1
SET STRING=
)
IF !BCOUNTER!==13 IF !sCOUNTER!==30 GOTO :PartData
)

:PartData
SET Active=80
SET PartType=0E
SET EHd=0F
SET ESec=3F
SET ECyl=24
SET SecBef=3F000000
SET TotSec=71910000
SET String=%String%$%Active%$01
ECHoo.com !String!>> test.mbr
SET String=$01$00$%PartType%$%EHd%$%ESec%$%ECyl%$%SecBef:~0,2%$%SecBef:~2,2%$%SecBef:~4,2%$%SecBef:~6,2%$%TotSec:~0,2%$%TotSec:~2,2%$%TotSec:~4,2%$%TotSec:~6,2%
SET /A sCounter=14
CALL :Padzeroes 32
SET /A sCounter=0
SET String=
CALL :Padzeroes 30 MagSig
GOTO :EOF

It's looking Bytepatch.exe will be best and simple tool to use in ImgPart.cmd ?

What exact Bytepatch.exe commands I should use in order to directly patch Hex Bytes of my_MBR.mbr and my_PBR.pbr ?

 

Regards...

Attached Files



#21 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 04 December 2021 - 05:00 PM

Yes, bytepatch is (imho) the easiest one.

 

How difficult can it be to use it? :dubbio:

 

Output of running bytepatch (without arguments):

Byte Patcher (bytepatch) v1.3 build 1809180 - simple binary and PE patch tool
copyright (c) bytepointer.com 2016-2018

syntax:
  bytepatch [options] <input_file> [data_bytes]

[data_bytes]
  patch data may be specified directly as 0-padded hex digits, where two hex
  digits delineate each byte - spaces optional; e.g.: 33 C0 83 C4 04

[options]
  -f <file> - load binary data from file instead of command-line
  -a <uint> - specify patch start address; by default this value designates
              the base-0 file offset for which to beging patching specified
              data.
  -p        - this option designates that address argument (-a) is a pointer
              into specified input file rather than a file offset; the
              input file must specify a valid Windows PE image (EXE/DLL); when
              this option is used and no address argument is specified, general
              PE and section information is displayed for the input file.
  -b <uint> - in pe pointer mode, overrides preferred load address (base) of
              image for address calculations.
  -l <uint> - loglevel number (0=quiet, 1=normal/default, 2=verbose/debug)
  -t        - trial-run; execute normally, but patch is not written to file
  -?        - this help

NOTE: numbers given for the options above default to base-10; to specify hex or
binary values, please prefix with "0x" or "0b" respectively.

bytepatch <targetfile> -a <offset> <byte> <byte> ... <byte>

 

SInce you can add the -t options, it provides an easy way to test the behaviour.

 

:duff:

Wonko



#22 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 08 December 2021 - 01:23 PM

Can you please check if something is wrongly used in following .cmd file ? Please suggest any betterment if required ?

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SETLOCAL ENABLEEXTENSIONS
SET /A comline=0
FOR %%A IN (MAP HELP) DO IF /I %%A.==%1. SET /A comline=!comline!+1
IF NOT %comline%==1 GOTO :Syntax
GOTO :PARTIMG%1

:Syntax
ECHO.
ECHO %~nx0 batch file to map Partition Image to a Partition entry of USB Drive
ECHO by jaclaz, this file is licensed under my "CAREWARE" license:
ECHO http://home.graffiti.net/jaclaz:graffiti.net/careware.html
ECHO.
ECHO General syntax is %~nx0 COMMAND [parameters], commands are:
ECHO.
ECHO MAP [Disk] [parameters]   - Map Partition Image to a partition of USB Drive
ECHO HELP                      - Displays help for the given command
ECHO.
GOTO :EOF

:DEC2BIN
SET BINnum=
SET DECnum=%1
SET /A Val32768=%DECnum% / 32768
SET /A Mod32768=%DECnum% %% 32768
FOR %%A in (%Powers%) DO CALL:BINcalc %%A
FOR %%A in (%Powers%) DO SET BINnum=!BINnum!!Val%%A!
GOTO :EOF

:BINcalc
IF %1==1 GOTO :EOF
SET /A Div=%1 /2
SET /A Val%Div%=!Mod%1! / %Div%
SET /A Mod%Div%=!Mod%1! %% %Div%
GOTO :EOF

:BIN2DEC
SET DECnum=
SET BINnum=%1
SET BINLength=%2
Set Counter=0
FOR %%A IN (%Powers%) DO (
CALL :DECcalc %%A
SET /A Counter=!Counter!+1
)
FOR %%A IN (%Powers%) DO SET /A DECnum=!DECnum!+!Digit%%A!*%%A
GOTO :EOF

:DECcalc
SET digit%1=!BINNum:~%Counter%,1!
IF %Counter%==%BINLength% GOTO :EOF
GOTO :EOF

:DEC2hex
SET DECnum=%1
SET Numdig=%2
SET HEXnum=
SET Powers=268435456 16777216 1048576 65536 4096 256 16 1
::=======================================================
::| WARNING! Limit is 2147483647 i.e. 7FFFFFF  WARNING! |
::=======================================================
SET /A Limit=%DECnum%/16
IF %Limit% LSS 0 ECHO Out of Range &GOTO :EOF
SET /A Val268435456=%DECnum% / 268435456
SET /A Mod268435456=%DECnum% %% 268435456
FOR %%A in (%Powers%) DO CALL:HEXcalc %%A
FOR %%A in (%Powers%) DO CALL:HEXchar %%A
FOR %%A in (%Powers%) DO SET Hexnum=!Hexnum!!Val%%A!

SET /A Length=8
SET HexnumF=%Hexnum%
CALL :RemoveLead

GOTO :EOF

:RemoveLead
Set/A Length=%Length%-2
IF %HexnumF:~0,2%==00 set HEXnumF=!HexnumF:~-%Length%!&GOTO :RemoveLead
SET HexnumF=!Hexnum:~-%NumDig%!
SET Hexnum=%HexnumF:~6,2%%HexnumF:~4,2%%HexnumF:~2,2%%HexnumF:~0,2%
GOTO :EOF

:HEXcalc
IF %1==1 GOTO :EOF
SET /A Div=%1 /16
SET /A Val%Div%=!Mod%1! / %Div%
SET /A Mod%Div%=!Mod%1! %% %Div%
GOTO :EOF

:HEXchar
IF !Val%1!==10 SET Val%1=A
IF !Val%1!==11 SET Val%1=B
IF !Val%1!==12 SET Val%1=C
IF !Val%1!==13 SET Val%1=D
IF !Val%1!==14 SET Val%1=E
IF !Val%1!==15 SET Val%1=F
GOTO :EOF

:PARTIMGMAP
:parseparams
REM Needed parameters are:
REM 1) Disk= Disk Number
REM 2) Geometry= Drive Geometry, Heads/Sectors, under 2K/XP/2003 255/63, but values accepted are 255/63, 128/63, 16/63, 64/32
REM 3) Partnum=number of partition entry - can be 1, 2, 3 or 4
REM 4) PartType= Partition type - can be:
REM    01 FAT12
REM    04 FAT16 <32Mb (obsolete)
REM    06 FAT16 CHS mapped
REM    07 NTFS
REM    0B FAT32 CHS mapped
REM    0C FAT32 LBA mapped
REM    0E FAT16 LBA mapped
REM    NO support for extended partitions of any kind!
REM 5) Active= whether the partition is Active or not - can be 0 (NOT Active) or 80 (Active)
REM 6) StartLBA= LBA address of first sector
REM 7) SectorsLBA= Number of sectors in partition
REM 8) (Optional) /S to make the batch operate silently
REM and the preceding CHS ones are calculated by the batch
REM Due to number and complexity of parameters, this batch is better suited to be
REM either called from within another batch or in interactive mode
SET neededfiles=gsar.exe dsfo.exe dsfi.exe dumphex.exe
FOR %%A IN (%neededfiles%) DO IF NOT EXIST %%A ECHO Missing file: %%A& GOTO :ERROR1
SHIFT
SET OK=0
Set Disk=%1 
Set Geometry=%2
Set Partnum=%3
Set Parttype=%4
Set Active=%5
Set StartLBA=%6
Set SectorsLBA=%7
Set Silent=%8
FOR %%A IN (1 2 3 4 5 6 7 8 9) DO IF %Disk%.==%%A. SET Disk=%%A&SET /A OK+=1
FOR %%A IN (255/63 128/63 16/63 64/32) DO IF /I %Geometry%.==%%A. SET Geometry=%%A&SET /A OK+=10
FOR %%A IN (1 2 3 4) DO IF %Partnum%.==%%A. SET Partnum=%%A&SET /A OK+=100
FOR %%A IN (01 04 06 07 0B 0C 0E) DO IF /I %PartType%.==%%A. SET PartType=%%A&SET /A OK+=1000
FOR %%A IN (00 80) DO IF %Active%.==%%A. SET Active=%%A&SET /A OK+=10000
FOR %%A IN (StartLBA SectorsLBA) DO IF NOT DEFINED %%A SET DATA=0
IF %OK% lss 11111 GOTO :PARTIMGHELP
IF %DATA%.==0. GOTO :PARTIMGHELP
IF EXIST my_MBR.mbr DEL my_MBR.mbr
IF EXIST my_PBR.pbr DEL my_PBR.pbr
dsfo \\.\PHYSICALDRIVE%Disk% 0 512 my_MBR.mbr
dsfo \\.\PHYSICALDRIVE%Disk% %6 512 my_PBR.pbr
GOTO :isLBA

:isLBA
CALL :LBAtoCHS Start %StartLBA% %Geometry%
FOR /F "tokens=1,2,3 delims=/" %%A in ("%StartCHS%") DO SET /A BCyl=%%A&SET /A BHd=%%B&SET /A BSec=%%C
SET /A EndLBA=%StartLBA%+%SectorsLBA%-1
CALL :LBAtoCHS End %EndLBA% %Geometry%
FOR /F "tokens=1,2,3 delims=/" %%A in ("%EndCHS%") DO SET /A ECyl=%%A&SET /A EHd=%%B&SET /A ESec=%%C

:ConfirmParams
IF %BCyl% gtr 1023 SET /A BCyl=1023
IF %ECyl% gtr 1023 SET /A ECyl=1023
IF /I %Silent%.==/S. GOTO :DoSilent
ECHO Parameters are as follows:
:display
SET partline=³
FOR %%A IN ( 
Partnum.6
Parttype.11
Active.16
BCyl.23
BHd.27
BSec.32
ECyl.39
EHd.43
ESec.48
StartLBA.60
SectorsLBA.74
) DO (
CALL :adddata partline %%~nA %%~xA
)
CALL :display3 NOOLD
ECHO %partline%
IF %BCyl% gtr 1023 SET /A WBCyl=1023
IF %ECyl% gtr 1023 SET /A WECyl=1023
IF DEFINED WBCyl ECHO (The Beginning Cylinder will be written as %WBCyl%)
IF DEFINED WECyl ECHO (The Ending Cylinder will be written as %WECyl%)
GOTO :DoEdit

:DoEdit
ECHO Are you sure you want to write the above values to file %source%?
SET Confirm=NO
SET /P Confirm=Type YES to confirm: 
IF /I NOT %Confirm%.==YES. goto :EOF
ECHO Writing data....
:DoSilent
SET Powers=32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1
CALL :DEC2BIN %BCyl%
SET BCyl=%BINNUM:~-10,10%
CALL :DEC2BIN %BSec%
SET BSec=%BINNUM:~-6,6%
SET BSec=%BCyl:~0,2%%BSec%
SET BCyl=%BCyl:~-8,8%

CALL :DEC2BIN %ECyl%
SET ECyl=%BINNUM:~-10,10%
CALL :DEC2BIN %ESec%
SET ESec=%BINNUM:~-6,6%
SET ESec=%ECyl:~0,2%%ESec%
SET ECyl=%ECyl:~-8,8%
SET Powers=128 64 32 16 8 4 2 1

FOR %%A IN (BCyl BSec ECyl ESec) DO (
CALL :BIN2DEC !%%A! 8
SET %%A=!DECnum!
)

FOR %%A IN (BCyl BHd BSec ECyl EHd ESec) DO (
CALL :DEC2hex !%%A! 2
SET %%A=!HEXnum!
)
FOR %%A IN (StartLBA SectorsLBA) DO (
CALL :DEC2hex !%%A! 8
SET %%A=!HEXnum!
)
IF /I NOT %Silent%.==/S. FOR %%A IN ( PartType Active BCyl BHd BSec ECyl EHd ESec StartLBA SectorsLBA) DO SET %%A
SET DataString=$%Active%$%BHd%$%BSec%$%BCyl%$%PartType%$%EHd%$%ESec%$%ECyl%$%StartLBA:~0,2%$%StartLBA:~2,2%$%StartLBA:~4,2%$%StartLBA:~6,2%$%SectorsLBA:~0,2%$%SectorsLBA:~2,2%$%SectorsLBA:~4,2%$%SectorsLBA:~6,2%

REM Partition Data offset: 1=446 2=462 3=478 4=494
Set /A Offset=430+%Partnum%*16
Set /A Length=16

bytepatch.exe my_MBR.mbr -a %Offset% %Active% %BHd% %BSec% %BCyl% %Parttype% %EHd% %ESec% %ECyl% %StartLBA:~0,2% %StartLBA:~2,2% %StartLBA:~4,2% %StartLBA:~6,2% %SectorsLBA:~0,2% %SectorsLBA:~2,2% %SectorsLBA:~4,2% %SectorsLBA:~6,2%
bytepatch.exe my_PBR.pbr -a 0x01C %StartLBA:~0,2% %StartLBA:~2,2% %StartLBA:~4,2% %StartLBA:~6,2%

dsfi \\.\PHYSICALDRIVE%Disk% 0 512 my_MBR.mbr
dsfi \\.\PHYSICALDRIVE%Disk% %6 512 my_PBR.pbr
IF EXIST my_MBR.mbr DEL my_MBR.mbr
IF EXIST my_PBR.pbr DEL my_PBR.pbr
GOTO :EOF

:LBAtoCHS
REM %1 is Variable name
REM %2 is the LBA value to convert
REM %3 is the disk geometry like 255/63
REM To get CHS from LBA:
REM CYL = LBA / (THds * TSec)
REM TEMPVAL = LBA % (THds * TSec)
REM HEAD = TEMP / TSec
REM SECT = TEMP % TSec + 1
REM Where:
REM LBA: linear base address of the block
REM CYL: value of the cylinder CHS coordinate
REM THds: Total number of heads per cylinder for the disk
REM HEAD: value of the head CHS coordinate
REM TSec: Total number of sectors per head for the disk
REM SECT: value of the sector CHS coordinate
REM TEMPVAL: buffer to hold a temporary value
SET /A LBA=%2
FOR /F "tokens=1,2 delims=/" %%A in ("%3") DO SET THds=%%A&SET TSec=%%B
SET /A TEMPVAL = THds * TSec
SET /A CYL = LBA/TEMPVAL
SET /A TEMPVAL = "%LBA% %% %TEMPVAL%"
SET /A HEAD = TEMPVAL/TSec
SET /A SECT = "%TEMPVAL% %% %TSec% + 1"
SET %1CHS=%CYL%/%HEAD%/%SECT%
GOTO :EOF

:checklength
SET /A Counter=0
SET data=!%1!
:LoopLength
SET /A Counter=%Counter%+1
IF NOT "%data%"=="!data:~0,%Counter%!" GOTO :LoopLength
SET /A %1Length=Counter
GOTO :EOF

:Padzeroes
SET /A sCounter=%sCounter%+1
SET String=%String%$00
IF NOT %sCounter%==%1 goto :Padzeroes
IF %2.==MagSig. SET String=%String%$55$AA
ECHoo.com %String%>> test.mbr
GOTO :EOF

:checkstrings
REM Parameters are:
REM Variable Goodnumber Goodvalue Sep_offset
FOR %%A IN (%Range%) DO IF /I !%1!.==%%A. SET /A Goodparam=%Goodparam%+%2
IF NOT %Goodparam%==%3 GOTO :EOF
CALL :adddata partline %1 %4
CLS&CALL :display3
ECHO %partline%
GOTO :EOF

:checkvalues
REM Parameters are:
REM Variable Goodnumber Goodvalue Sep_offset min max 
IF !%1! Geq %5 IF !%1! Leq %6 SET /A Goodparam=%Goodparam%+%2
IF NOT %Goodparam%==%3 GOTO :EOF
CALL :adddata partline %1 %4
CLS&CALL :display3
ECHO %partline%
GOTO :EOF

:display3
IF %1.==NOOLD. goto :NOOLD
For %%A IN (a b c d e 1 f 2 f 3 f 4 g) DO ECHO !Line%%A!
:NOOLD
ECHO.
ECHO Drive geometry: %Geometry% Program Mode: %PMode%
ECHO ÚÄÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
ECHO ³Part ³Type³Boot³  Begin   CHS  ³   End   CHS   ³ LBA Start ³ LBA Sectors ³
ECHO ³  #  ³    ³    ³ BCyl ³BHd³BSec³ ECyl ³EHd³ESec³           ³             ³
ECHO ÃÄÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÅÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÅÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
GOTO :EOF

:adddata
if %3.==. GOTO :EOF
set templine=%1
set thisline=!%templine%!
set pad=%2
set pad=!%pad%!³
set sepoffset=%3
set sepoffset=%sepoffset:.=%
:dataloop
SET templine=%thisline%%pad%
set pad= %pad%
IF NOT "!templine:~%sepoffset%,1!"=="³" goto :dataloop
SET %1=%templine%
GOTO :EOF

:PARTIMGHELP
ECHO.
ECHO Syntax :
ECHO.
ECHO %~nx0 MAP [Disk] [Geometry] [Partnum] [PartType] [Active] [StartLBA] [SectorsLBA] [/S]
ECHO.
ECHO Disk       = Disk Number
ECHO.
ECHO Geometry   = Drive Geometry, Heads/Sectors, under 2K/XP/2003 255/63,
ECHO              but values accepted are 255/63, 128/63, 16/63, 
ECHO.
ECHO Partnum    = number of partition entry - can be 1, 2, 3 or 4
ECHO.
ECHO PartType   = Partition type - can be:
ECHO 		  01 FAT12			³
ECHO 		  04 FAT16 ^<32 Mb (obsolete)	³
ECHO 		  06 FAT16 CHS mapped 		³ NO support for
ECHO 		  07 NTFS             		³
ECHO 		  0B FAT32 CHS mapped 		³ extended partitions
ECHO 		  0C FAT32 LBA mapped 		³
ECHO 		  0E FAT16 LBA mapped 		³
ECHO.
ECHO Active     = Active flag for entry - can be 0 (NOT Active) or 80 (Active)
ECHO.
ECHO StartLBA   = LBA address of first sector
ECHO.
ECHO SectorsLBA = Number of sectors in partition
ECHO.
ECHO EXAMPLES:
ECHO %~nx0 1 255/63 1 0B 80 63 2056257 /S
PAUSE
GOTO :EOF


:error
ECHO An error has occurred
GOTO :EOF

:error1
ECHO Please add the missing file in the same directory where %~nx0 is
GOTO :EOF

:Temporary_Code
if not exist echoo.com (
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6
echo ?@xAyJHmH@=a?}VjuN?_LEkS?`w`s_{OCIvJDGEHtc{OCIKGMgELCI?GGg
echo EL?s?WL`LRBcx=k_K?AxVD?fCo?Cd?BLDs0
)>>echoo.com 

Set /A Length=512
SET /A sCOUNTER=0
SET /A BCOUNTER=0
SET String=
FOR /F "tokens=2 delims=: " %%A IN ('dumphex /s%Offset% /L%Length% /w1 /nc %SystemRoot%\System32\dmadmin.exe') DO (
SET /A sCOUNTER=!sCOUNTER!+1
SET String=!String!$%%A
IF !sCOUNTER!==32 (
ECHoo.com !String!>> %2
SET sCOUNTER=0
SET /A BCOUNTER=!BCOUNTER!+1
SET STRING=
)
IF !BCOUNTER!==13 IF !sCOUNTER!==30 GOTO :PartData
)

:PartData
SET Active=80
SET PartType=0E
SET EHd=0F
SET ESec=3F
SET ECyl=24
SET SecBef=3F000000
SET TotSec=71910000
SET String=%String%$%Active%$01
ECHoo.com !String!>> test.mbr
SET String=$01$00$%PartType%$%EHd%$%ESec%$%ECyl%$%SecBef:~0,2%$%SecBef:~2,2%$%SecBef:~4,2%$%SecBef:~6,2%$%TotSec:~0,2%$%TotSec:~2,2%$%TotSec:~4,2%$%TotSec:~6,2%
SET /A sCounter=14
CALL :Padzeroes 32
SET /A sCounter=0
SET String=
CALL :Padzeroes 30 MagSig
GOTO :EOF

Am I using Offset correctly in Bytepatch command ? Can I use above .cmd in my MAIN .cmd for mapping UEFI_NTFS.img to Partition 3 of USB Drive now ?

 

Regards...

Attached Files



#23 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 08 December 2021 - 04:40 PM

It looks fine (but it needs to be tested).

 

Surely this part:

ECHO %~nx0 batch file to map Partition Image to a Partition entry of USB Drive
ECHO by jaclaz, this file is licensed under my "CAREWARE" license:
ECHO http://home.graffiti.net/jaclaz:graffiti.net/careware.html

must be removed/modified, you can use "inspired by" or "derived from" (only if you want to), and if you want to mantain the Careware license (there is actually no obligation to, that is the whole point of that particular license)  it is (since some ten years or more) here:

http://jaclaz.alterv...s/careware.html

 

:duff:

Wonko



#24 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 16 December 2021 - 06:10 PM

C:\Users\Krishna\Desktop\SMART BOOT ALTOY\aLTOy\BIN>dsfo \\.\PHYSICALDRIVE1 0 512 my_MBR.mbr
OK, 512 bytes, 0.000s, MD5 = 3a2f74201824e5bae4c78af0cc65b11f

C:\Users\Krishna\Desktop\SMART BOOT ALTOY\aLTOy\BIN>dsfo \\.\PHYSICALDRIVE1 62416512 512 my_PBR.pbr
\\.\PHYSICALDRIVE1 - The parameter is incorrect.
This error can probably be ignored.
my_PBR.pbr - No more data is available.

It's looking offset must be 0 in case of dsfo/dsfi ??

Which tool I should use in order to read PBR of USB Drive as my_PBR.pbr and then write my_PBR.pbr to USB Drive after patching ? I need a suitable tool that will work in both 32-bit and 64-bit Windows OS/WinPE Platforms for read/write PBR of USB Drives.

 

Regards...



#25 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 17 December 2021 - 12:17 PM

Both the offset and the amount/length parameters in dsfo/dsfi may be non-zero, BUT if the source of target are a block device, both need to be either 0 or a multiple of the device block size.

Said in another way, the offset must fall on a block/sector boundary, and then you can only have one or more exact whole amount of blocks/sectors.

Assuming your device has "normal" 512 bytes blocks, the offset seems like not valid:

62416512/512=121907,25 :w00t:

Alternatively to accessing the \\.\PHYSICALDRIVE1 device and have the correct offset to the PBR, you can try accessing the logical volume, i.e. something like \\.\G: (but of course you need to know the drive letter assigned to the volume, or alternatively, the Volume ID, in practice (example of my drive D:, Drive 1, offset 63 sectors or 32256 bytes):
C:\Downloaded\dsfok>dsfo \\.\Volume{b0b284c4-8a33-11dd-8781-806d6172696f} 0 512 $
OK, 512 bytes, 0.016s, MD5 = bb494e68e7c8dddf1f80c1ceb48e72f5
C:\Downloaded\dsfok>dsfo \\.\d: 0 512 $
OK, 512 bytes, 0.016s, MD5 = bb494e68e7c8dddf1f80c1ceb48e72f5
C:\Downloaded\dsfok>dsfo \\.\physicaldrive1 32256 512 $
OK, 512 bytes, 0.000s, MD5 = bb494e68e7c8dddf1f80c1ceb48e72f5
C:\Downloaded\dsfok>
:duff:
Wonko





Also tagged with one or more of these keywords: uefi-ntfs.img, rufus, cmd, .imgptn, partimg

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users