Jump to content











Photo
- - - - -

[RELEASE] mbrview.g4b a BAT! tool for grub4dos


  • Please log in to reply
61 replies to this topic

#51 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 31 October 2013 - 08:09 AM

Very good. :)

Can you post it as and attachment (inside a .zip file)?

There are known issue with copy/paste through different browsers :w00t: and there is always the risk of yet another big CODE box corruption at the next board software update.   :ph34r:

 

:cheers:

Wonko



#52 nando4

nando4

    Frequent Member

  • Advanced user
  • 112 posts
  •  
    Australia

Posted 31 October 2013 - 02:38 PM

Very good. :)

Can you post it as and attachment (inside a .zip file)?

There are known issue with copy/paste through different browsers :w00t: and there is always the risk of yet another big CODE box corruption at the next board software update.   :ph34r:

 

:cheers:

Wonko

 

You are welcome to post it on the first post, replacing or supplementing the version there. I just removed the wenv calls and replaced them with grub4dos native calls. The body of work is primarily of your creation.

 

You can see there was plenty of discussion about wenv and it's performance. Given the grub4dos improvements since this script was released,  I felt wenv just added an extra layer of complication that was no longer necessary.



#53 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 31 October 2013 - 07:46 PM

You are welcome to post it on the first post, replacing or supplementing the version there. I just removed the wenv calls and replaced them with grub4dos native calls. The body of work is primarily of your creation.

 

You can see there was plenty of discussion about wenv and it's performance. Given the grub4dos improvements since this script was released,  I felt wenv just added an extra layer of complication that was no longer necessary.

I will gladly do, but if you could post it in the form of a .zip archive, I would be sure that it is the actual version that you tested, and not a copy/paste of the code.

Believe me when I tell you that anything (and the contrary of everything can happen), JFYI:

http://reboot.pro/to...st-and-ddlistw/

Please note how the original misadventures described happened long before (and caused by browsers like Internet Explorer/firefox/whatever ) the good IPB board guys decided to botch each and every codebox on any board in the world through one of their updates, and please note how that particular thread's code boxes were affected by two subsequent "botching updates" by them, the first one failing to interpret parse a number of characters and the second one removing newline/linefeeds).

 

:cheers:

Wonko



#54 nando4

nando4

    Frequent Member

  • Advanced user
  • 112 posts
  •  
    Australia

Posted 01 November 2013 - 03:23 AM

Wonko, find the modified mbrview.g4b in attached ZIP file.

Attached Files



#55 Gerolf

Gerolf

    Newbie

  • Members
  • 13 posts
  •  
    Germany

Posted 28 April 2018 - 04:19 PM

Since the result is going to be displayed as a hex number I think the four bytes of the MBR's disk signature

cat --hex --skip=440 --length=4 %target% | set disksig=
set disksig=%disksig:~10,2%%%disksig:~13,2%%%disksig:~16,2%%%disksig:~19,2%
echo Drive=%target:~0,5%, Signature=%disksig%

should be interpreted as little endian and thus be concatenated in reversed order like this:

set disksig=%disksig:~19,2%%%disksig:~16,2%%%disksig:~13,2%%%disksig:~10,2%

Compare the following construction:

dd if=%target% of=(md)0x300+1 > nul ;; :: 0x300 x 512 = 0x60000
set /A disksig=*0x601b8&0xffffffff > nul ;; :: +0x1b8 = +440: disk signature in MBR
echo Drive=%target:~0,5%, Signature=%disksig:~2,8% ;; :: remove leading "0x"

Then you get the same result that e.g. Minitool Partition Wizard shows for the corresponding device.

https://en.wikipedia...d#Sector_layout



#56 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 28 April 2018 - 05:08 PM

Since the result is going to be displayed as a hex number I think the four bytes of the MBR's disk signature

cat --hex --skip=440 --length=4 %target% | set disksig=set disksig=%disksig:~10,2%%%disksig:~13,2%%%disksig:~16,2%%%disksig:~19,2%echo Drive=%target:~0,5%, Signature=%disksig%
should be interpreted as little endian and thus be concatenated in reversed order like this:
set disksig=%disksig:~19,2%%%disksig:~16,2%%%disksig:~13,2%%%disksig:~10,2%
Compare the following construction:
dd if=%target% of=(md)0x300+1 > nul ;; :: 0x300 x 512 = 0x60000set /A disksig=*0x601b8&0xffffffff > nul ;; :: +0x1b8 = +440: disk signature in MBRecho Drive=%target:~0,5%, Signature=%disksig:~2,8% ;; :: remove leading "0x"
Then you get the same result that e.g. Minitool Partition Wizard shows for the corresponding device.
https://en.wikipedia...d#Sector_layout
Yes and No. :dubbio:

Meaning that not necessarily Minitool Partition Wizard has *any* authority on how to display or interpret 4 bytes, a Disk Signature is either a Signature or a number, compare with the known issue about "Magic Bytes":
http://starman.vertc.../mbr/AA55H.html

Try running WMIC as follows:
wmic diskdrive get name, signature

very likely you will find decimal negative numbers as a result. :w00t:

On the other hand in MountedDevices in the Registry you will find the 4 byte sequence EXACTLY as it is written in the MBR at offset 440 as you can check with a hex editor. (i.e. as MBRview shows it)

And if you run Diskpart (Select disk #, detail disk) you will get as Disk ID: again the 4 bytes sequence "inverted". (i.e. as you propose)

So, three different ways (the WMI/WMIC clearly completely wrong) to display a 4 byte sequence.

If you want to mimic the hypothetically "right" way (Minitool and Diskpart) you are welcome, but if you want to look for a drive letter in the Registry to understand to which disk it belongs, the "plain" way is more handy.

Exception made for the stupid conversion to signed decimal that WMIC performs, it is just a matter of preferences IMHO.

Not so casually (shameless plug ;)) in my MBRview script/structure viewer for Tiny Hexer:

http://reboot.pro/to...-hexer-scripts/

I provide both the "inverted" and "plain" Disk Signature, marking the first one as 0x (as it should be IF it is a hex number) and without the 0x the latter (as it should be being a plain sequence of bytes).

:duff:
Wonko

#57 Gerolf

Gerolf

    Newbie

  • Members
  • 13 posts
  •  
    Germany

Posted 28 April 2018 - 06:35 PM

Thank you! Now, if both ways do make sense, I simply suggest to separate the consecutive bytes with spaces

set disksig=%disksig:~10,2% %disksig:~13,2% %disksig:~16,2% %disksig:~19,2%

to make it more intuitive that this is not one single hex number.



#58 Gerolf

Gerolf

    Newbie

  • Members
  • 13 posts
  •  
    Germany

Posted 28 April 2018 - 08:26 PM

 Shorter, leaving intact the hex editor's formatting:

set disksig=%disksig:~10,11%


#59 Gerolf

Gerolf

    Newbie

  • Members
  • 13 posts
  •  
    Germany

Posted 28 April 2018 - 10:55 PM

Your linked document says in its headline that "55AAH is the Wrong Way to represent the Byte Sequence 55h followed by AAh on a PC". Marked as "Bytes", the "wrong" expression "0x55AA" can be found in this code fragment:

cat --hex --skip=510 --length=2 %target% | set magic=
set magic=0x%magic:~10,2%%%magic:~13,2%
if "%magic%"=="0x55AA" goto :mbOK
echo No valid Magic Bytes: %magic% instead of 0x55AA
:mbOK
:: echo Valid Magic Bytes %magic%

The following equivalent uses the "correct" hex Word "0xAA55" as proposed by The Starman:

cat --hex --skip=510 --length=2 %target% | set magic=
set magic=0x%magic:~13,2%%%magic:~10,2%
if "%magic%"=="0xAA55" goto :mbOK
echo No valid Magic Word: %magic% instead of 0xAA55
:mbOK
:: echo Valid Magic Word %magic%


#60 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 29 April 2018 - 01:28 PM

 

Your linked document says in its headline that "55AAH is the Wrong Way to represent the Byte Sequence 55h followed by AAh on a PC". Marked as "Bytes", the "wrong" expression "0x55AA" can be found in this code fragment:



cat --hex --skip=510 --length=2 %target% | set magic=
set magic=0x%magic:~10,2%%%magic:~13,2%
if "%magic%"=="0x55AA" goto :mbOK
echo No valid Magic Bytes: %magic% instead of 0x55AA
:mbOK
:: echo Valid Magic Bytes %magic%

The following equivalent uses the "correct" hex Word "0xAA55" as proposed by The Starman:



cat --hex --skip=510 --length=2 %target% | set magic=
set magic=0x%magic:~13,2%%%magic:~10,2%
if "%magic%"=="0xAA55" goto :mbOK
echo No valid Magic Word: %magic% instead of 0xAA55
:mbOK
:: echo Valid Magic Word %magic%

I know :smiling9: , I pointed you to it.

 

But I really don't get your point.

 

You want to sue me or Nando4 for the way the check is scripted? :w00t:

Do you believe that to be a bug? :unsure:

Is it really so important to need to be corrected? :dubbio:

 

IF it is, then the correction is (should be):

cat --hex --skip=510 --length=2 %target% | set magic=
set magic=%magic:~10,2%%%magic:~13,2%
if "%magic%"=="55AA" goto :mbOK
echo No valid Magic Bytes: %magic% instead of 55AA
:mbOK
:: echo Valid Magic Bytes %magic%

With all the affection and respect I have for Daniel B.Sedory (the Starman) :worship: I pointed you to that page only to show you how opinions may be different on the way a sequence of bytes is interpreted, and while all in all I believe he is actually right::

http://starman.vertc.../mbr/AA55H.html

 

Therefore, we'd advise any authors who need to describe a signature (apart from books on assembly language), to list each byte as it's found on some media or in memory, rather than attempting to use a hexadecimal number comprised of more than a single byte.

 

(this is the way I used for the Disk Signature), you got me :ph34r: on the 0x prepended to the "Magic Bytes", though I have to disagree with the notion of a sequence of two bytes (a signature or "Magic Bytes") constituting a "Word".

 

:duff:

Wonko



#61 Gerolf

Gerolf

    Newbie

  • Members
  • 13 posts
  •  
    Germany

Posted 29 April 2018 - 01:51 PM

Not suing, Wonko! I think your mbrview.g4b is such an instructive little piece of code that it's worth to be discussed in detail even for "educational" purposes.



#62 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 29 April 2018 - 03:24 PM

Not suing, Wonko! I think your mbrview.g4b is such an instructive little piece of code that it's worth to be discussed in detail even for "educational" purposes.

Is it?  :blush: Thanks for the compliment. :)

 

I consider it only one of the several - as usual - half-@ssed batches that I put together just to show both real programmers and common users how simple problems can be solved by simple tools, hoping to spur them into making more and better simple tools (and usually failing miserably :( , though from time to time a young padawan does learn something and actually produces something of use).

 

JFYI, it is only a simplified (and adapted to grub4dos syntax, later amended/simplified by nando4) re-using parts of the MBRbatch here:

http://reboot.pro/to...atch-001-alpha/

 

(that could actually have some "educational" purpose :unsure: )

 

:duff:

Wonko






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users