Author Topic: gkb.trid.xml for GRUB keyboard *.GKB  (Read 913 times)

jenderek

  • Sr. Member
  • ****
  • Posts: 375
gkb.trid.xml for GRUB keyboard *.GKB
« on: November 23, 2023, 07:26:21 PM »
Hello trid users,

some days ago i installed a new Linux system on my PC.  For security reasons i
wanted some complicated password with special characters. Unfortunately this
does not work out of the box for my system with German keyboard. After a
nightmare session i find that i myself must create keyboard modules (*.GKB)
for GRUB boot loader and insert instruction inside configuration grub.cfg to
use this.

GRUB is the GRand Unified Boot loader of/for GNU found on their website. That
is expressed by line like:

   <RefURL>https://www.gnu.org/software/grub</RefURL>

When i run TrID on such examples these are described wrong like
"PrintFox/Pagefox bitmap (640x400" by definition bitmap-printfox-g.trid.xml
(see appended output/trid-v-old.txt).

For comparison reason i also run the file utility (version 5.42). This
describes the examples as data" (see appended output/file-5.42.txt). I also
run a file command (version 5.42). Now my samples are described as "GRUB
Keyboard" with some additional information about keys like q and z which are
different on non English keyboards like German and french (see appended
output/file-5.45). Now as file name suffix gkb is shown (see appended
output/file-ext-5.45.txt). As mime type now application/x-grub-keyboard is
shown (see appended output/file-i-5.45.txt).

So i run tridscan on my examples to generate gkb.trid.xml for GRUB Keyboard
(*.GKB )

In source of GRUB there exist header file keyboard_layouts.h and c-source
keylayouts.c with needed information about file format.  So it is possible to
interpret first XML construct. This looks like:

   <Bytes>475255424C41594F0A00000000000000000000000000000000000000</Bytes>
   <ASCII> G R U B L A Y O</ASCII>
   <Pos>0</Pos>

According to that documentation samples start with 8 byte magic string named
GRUB_KEYBOARD_LAYOUTS_FILEMAGIC. Afterward the version is stored as 4 byte
integer, which is in current version value 10.

I am not a c programmer, but if i under stand source right afterwards comes
four keyboard layout with 160 elements, where every element has a size of 32
bit. First comes the normal keyboard. This is followed by the "shift" variant
and so on. So with 4 such structures i get file size 2572 { 8 (magic) + 4
(version) + 4*160*4 (keyboard structures) }.

By lucky circumstances my few keyboard layouts look similar. So the structures
grub_keyboard_layout look the same.

Assuming that other more exotic keyboard layouts exist the first XML construct
now becomes like:
   <Pattern>
      <Bytes>475255424C41594F0A0000000</Bytes>
      <ASCII> G R U B L A Y O</ASCII>
      <Pos>0</Pos>
   </Pattern>

In the structure an element is stored as 32 bit type. If something like pure
letter q press is stored in map then 3 byte are unused. This situation happen
many times. So this give many short nil sequences like:
   <Pattern>
      <Bytes>000000</Bytes>
      <Pos>29</Pos>
   </Pattern>
   <Pattern>
      <Bytes>000000</Bytes>
      <Pos>33</Pos>
   </Pattern>
But it may be possible to store exotic characters in the map. So i delete such
patterns.

There exist also some longer non nil patterns like:
   <Pattern>
      <Bytes>0000000A0000001B0000000800000009000000</Bytes>
      <Pos>169</Pos>
   </Pattern>
I assume that this also triggered by lucky circumstances (often same keys on
European keyboards). So i also delete such constructs.

With the new definition now all my GRUB keyboards are described more precisely
( see appended output/trid-v-new.txt). TrID definition and output are stored
in archive gkb-2.zip. I hope that the XML file can be used in future version
of triddefs.

With best wishes
Jörg Jenderek

Mark0

  • Administrator
  • Hero Member
  • *****
  • Posts: 2743
    • Mark0's Home Page
Re: gkb.trid.xml for GRUB keyboard *.GKB
« Reply #1 on: November 26, 2023, 05:45:47 PM »
Thanks!