Score:2

How to use hexadecimal code as a magic value in mime-type file

cn flag

I know to add a mimetype I must use a code like that:

<mime-type type="audio/x-gtp">
    <comment>GuitarPro file</comment>
    <glob pattern="*.gp5"/>
</mime-type>

I know to add a mimetype whose file extension is used for other mimetype I can use magic like that:

<mime-type type="audio/x-gtp">
    <magic priority="50">
        <match value="BCFZ" type="string" offset="0" />
    </magic>
    <glob pattern="*.gpx"/>
</mime-type>

This, taking into account that the first 4 characters of the file are printable. I obtained this pattern using xxd. I show you the first four lines of xxd output:

xxd '/home/cactus/Descargas/Billie Eilish - Everything I Wanted.gpx'  | head -n 4 
00000000: 4243 465a 0420 0500 6848 68cd 4c00 0180  BCFZ. ..hHh.L...
00000010: 0000 4ed7 fdff feff ffff e76d 156a 52d8  ..N........m.jR.
00000020: 516e 142e 0141 7201 00e4 0201 c804 0390  Qn...Ar.........
00000030: 0807 2010 0e40 201c 8040 3900 8072 0100  .. ..@ ..@9..r..

So far, everything works fine.

The problem with this other filetype .gp, whose first characters are not imprimible, I show you the output of the first four xdd lines:

xxd /home/cactus/Descargas/arpeggio.gp   | head -n 4                                                                                                                                                      
00000000: 504b 0304 1400 0000 0000 0000 0000 0000  PK..............
00000010: 0000 0000 0000 0000 0000 0800 0000 436f  ..............Co
00000020: 6e74 656e 742f 504b 0304 1400 0800 0800  ntent/PK........
00000030: 0000 0000 0000 0000 0000 0000 0000 0000  ................

So I don't know how use magic with that type of files, I think the best way would be using hexadecimal code in value, but I don't know how use it.

Thanks for your time.

Score:1
cn flag

I was able to solve the problem.

In that page https://specifications.freedesktop.org/shared-mime-info-spec/latest/ar01s02.html#idm45785599133248 I found the following definition:

value: The value to compare the file contents with, in the format indicated by the type attribute. The string type supports the C character escapes (\0, \t, \n, \r, \xAB for hex, \777 for octal).

So that indicates what I needed, so you can use hexadecimal values in the string type using the C character escapes.

Remembering the hexadecimal output of my file:

hexdump -C /home/cactus/Descargas/arpeggio.gp  | head -4                                                                                                                                                                    
00000000  50 4b 03 04 14 00 00 00  00 00 00 00 00 00 00 00  |PK..............|
00000010  00 00 00 00 00 00 00 00  00 00 08 00 00 00 43 6f  |..............Co|
00000020  6e 74 65 6e 74 2f 50 4b  03 04 14 00 08 00 08 00  |ntent/PK........|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

The pattern would look like this: \x40\x4b\x03\x04. This did not work. But I change the priority value to 100 an this finally works. The final code looks like this:

<mime-type type="audio/x-gtp">
    <magic priority="100">
        <match value="\x50\x4b\x03\x04" type="string" offset="0"  />
    </magic>
    <comment>GuitarPro file</comment>
    <comment xml:lang="es">Archivo de GuitarPro</comment>
    <glob pattern="*.gp"/>
</mime-type>

And it's finally works!

enter image description here

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.