fiedka / fiedka

a visual toolkit for exploring and editing firmware images, running on web platforms
https://fiedka.app/
MIT License
100 stars 8 forks source link

render IFR on the web #20

Open orangecms opened 3 years ago

orangecms commented 3 years ago

UEFI defines a protocol for data to render the menu that allows for changing settings from, named HII, or Human Interface Infrastructure. The binary format is called IFR, Intermediate Forms Representation, while the source format is called VFR, Visual Forms Representation, and can be compiled with https://edk2-docs.gitbook.io/edk-ii-basetools-user-guides/vfrcompiler. Tools like https://github.com/LongSoft/Universal-IFR-Extractor and https://github.com/topeterk/IfrViewer allow for parsing and viewing it already, but the output is not JSON. See if we can hack on something to get JSON output that we can load as a fixture into utk-web again. The web browser is a neat environment for rendering, so it can simulate a firmware image's menu.

Short script for UEFITool + Universal-IFR-Extractor:

#!/bin/sh
# cat all the IFRs
uefiextract-ng "$1"
for f in $(find $1.dump/ -name '*1 PE32 image section*'); do
  ifrextract "$f/body.bin" "$f/ifr"
done
for f in $(find $1.dump/ -name ifr); do
  cat "$f"
done

Excerpts as examples:

0x576F          Checkbox: , VarStoreInfo (VarOffset/VarName): 0x39, VarStore: 0x8020, QuestionId: 0x119 {06 8E 03 00 04 00 19 01 20 80 39 00 00 00}
0x577D          End {29 02}
0x577F          Checkbox: , VarStoreInfo (VarOffset/VarName): 0x3A, VarStore: 0x8020, QuestionId: 0x11A {06 8E 03 00 04 00 1A 01 20 80 3A 00 00 00}
0x578D          End {29 02}
0x578F          Checkbox: , VarStoreInfo (VarOffset/VarName): 0x3B, VarStore: 0x8020, QuestionId: 0x11B {06 8E 03 00 04 00 1B 01 20 80 3B 00 00 00}
0x579D          End {29 02}
0x579F          Checkbox: , VarStoreInfo (VarOffset/VarName): 0x3C, VarStore: 0x8020, QuestionId: 0x11C {06 8E 03 00 04 00 1C 01 20 80 3C 00 00 00}
0x57AD          End {29 02}
0x57AF          Checkbox: , VarStoreInfo (VarOffset/VarName): 0x3D, VarStore: 0x8020, QuestionId: 0x11D {06 8E 03 00 04 00 1D 01 20 80 3D 00 00 00}
0x57BD          End {29 02}
0x57BF          Checkbox: , VarStoreInfo (VarOffset/VarName): 0x3E, VarStore: 0x8020, QuestionId: 0x11E {06 8E 03 00 04 00 1E 01 20 80 3E 00 00 00}
0x57CD          End {29 02}
0x4B6D  Form: Select Physical Disk Operations, FormId: 0x321 {01 86 21 03 EE 00}
0x4B73          Text: Statement.Prompt: , TextTwo:  {03 08 05 00 04 00 05 00}
0x4B7B          Text: Statement.Prompt: You are about to unassign a Hot Spare. Doing so may leave your data at risk in the event of a disk failure. Are you sure you want to do this?, TextTwo:  {03 08 0B 01 04 00 03 00}
0x4B83          Text: Statement.Prompt: , TextTwo:  {03 08 05 00 04 00 05 00}
0x4B8B          Ref: Yes, VarStoreInfo (VarOffset/VarName): 0xFFFF, VarStore: 0x0, QuestionId: 0x3825, FormId: 0x320 {0F 0F 3E 00 09 01 25 38 00 00 FF FF 04 20 03}
0x4B9A          Text: Statement.Prompt: , TextTwo:  {03 08 05 00 04 00 05 00}
0x4BA2          Ref: No, VarStoreInfo (VarOffset/VarName): 0xFFFF, VarStore: 0x0, QuestionId: 0x3826, FormId: 0x320 {0F 0F 46 00 0A 01 26 38 00 00 FF FF 04 20 03}
0x4BB1  End Form {29 02}
0x69D1  Form: PCI Express GEN 1 Settings, FormId: 0x3 {01 86 03 00 19 00}
0x69D7          Subtitle: Statement.Prompt: PCI Express GEN 1 Settings, Flags: 0x0 {02 87 19 00 00 00 00}
0x69DE          End {29 02}
0x69E0          Subtitle: Statement.Prompt: , Flags: 0x0 {02 87 02 00 00 00 00}
0x69E7          End {29 02}
0x69E9          Guid: [0F0B1735-87A0-4193-B266-538C38AF48CE] {5F 15 35 17 0B 0F A0 87 93 41 B2 66 53 8C 38 AF 48 CE 00 01 03}
0x69FE          Guid: [0F0B1735-87A0-4193-B266-538C38AF48CE] {5F 15 35 17 0B 0F A0 87 93 41 B2 66 53 8C 38 AF 48 CE 00 02 03}
0x6A13  End Form {29 02}
0x6A15  Form: PCI Express GEN 2 Settings, FormId: 0x4 {01 86 04 00 1A 00}
0x6A1B          Subtitle: Statement.Prompt: PCI Express GEN 2 Settings, Flags: 0x0 {02 87 1A 00 00 00 00}
0x6A22          End {29 02}
0x6A24          Subtitle: Statement.Prompt: , Flags: 0x0 {02 87 02 00 00 00 00}
0x6A2B          End {29 02}
0x6A2D          Guid: [0F0B1735-87A0-4193-B266-538C38AF48CE] {5F 15 35 17 0B 0F A0 87 93 41 B2 66 53 8C 38 AF 48 CE 00 01 04}
0x6A42          Guid: [0F0B1735-87A0-4193-B266-538C38AF48CE] {5F 15 35 17 0B 0F A0 87 93 41 B2 66 53 8C 38 AF 48 CE 00 02 04}
0x6A57  End Form {29 02}
JohnAZoidberg commented 3 years ago

The code of https://github.com/LongSoft/IFRExtractor-RS looks cleaner and would probably be easier to modify to output JSON.

I wonder if IFR loses information compared to VFR or if it's only a human-readable to binary conversion. If it's the same amount of information we can convert back and forth and possible use the result of this issue to visualize VFR as well.

orangecms commented 3 years ago

Another tool: https://github.com/JohnAZoidberg/LangAppUEFIBIOS/tree/master/vfr

orangecms commented 3 years ago

Original work: https://github.com/WilliamLeara/LangAppUEFIBIOS

orangecms commented 2 years ago

see also https://github.com/tianocore/edk2/tree/master/MdeModulePkg/Universal/DisplayEngineDxe

orangecms commented 2 years ago

Nice info on HII: https://github.com/lzeng14/tianocore/wiki/HII

orangecms commented 2 years ago

The code of https://github.com/LongSoft/IFRExtractor-RS looks cleaner and would probably be easier to modify to output JSON.

I wonder if IFR loses information compared to VFR or if it's only a human-readable to binary conversion. If it's the same amount of information we can convert back and forth and possible use the result of this issue to visualize VFR as well.

forked and WIP to get JSON output: https://github.com/orangecms/IFRExtractor-RS/tree/json

orangecms commented 2 years ago

Lenovo has put a renderer for all their devices' menus on the web: https://download.lenovo.com/bsco/index.html