datasone / setup_var.efi

UEFI command-line tool for read/write access of variables
Apache License 2.0
221 stars 8 forks source link

[BUG] First argument is skipped #7

Closed dreamwhite closed 1 year ago

dreamwhite commented 1 year ago

Good morning and thank you so much for writing this tool. I'm using it and despite it serves the same purpose as modGRUBShell.efi it's way more portable (especially when having ESPs with low space issues).

Anyway, I'm experiencing a weird bug while trying to execute the tool via OpenCore. I don't know if you ever had any Hackintoshing experience in the past or not, but basically it's a bootloader and for what concerns us, it can be used also for creating custom tools entries (e.g. CFG Lock unlock entry which runs .\setup_var.efi CFG_LOCK_OFFSET 0x00 -n VarStoreId).

What basically happens is that after adding the tool in the bootloader configuration file, it skips the first argument.

Below the code that I added to the bootloader configuration file:

<dict>
    <key>Arguments</key>
    <string>0x527 0x00 -n Setup</string>
    <key>Auxiliary</key>
    <true/>
    <key>Comment</key>
    <string>UEFI command-line tool for read/write access of variables - CFG Lock unlock</string>
    <key>Enabled</key>
    <true/>
    <key>Flavour</key>
    <string>Auto</string>
    <key>FullNvramAccess</key>
    <true/>
    <key>Name</key>
    <string>setup_var - CFG Unlock</string>
    <key>Path</key>
    <string>setup_var.efi</string>
    <key>RealPath</key>
    <true/>
    <key>TextMode</key>
    <true/>
</dict>

What concerns us is the Arguments key with the value 0x527 0x00 -n Setup. If I run that custom entry, it doesn't write in the offset but rather reads the value of 0x00 under Setup VarStoreName, so it skips the first argument.

I already discussed this with the devs of the bootloader (you can read more here), and they pointed out this line which may be the reason of the bug.

The only way I could find to temporarily fix it is adding .\setup_var.efi (potentially can be literally any string, as it doesn't need to be any particular value) so the tool correctly parses the argument.

Do you think this can be fixed? Thank you so much and have a great day

-- dreamwhite

dreamwhite commented 1 year ago

I temporarily commented line 172 and the tool works using OpenCore, but if I try running it from a UEFI shell (such as OpenShell.efi) then it raises the following error:

image

I'm definitely not a RUST nor a UEFI developer, but I think the right thing to do is:

datasone commented 1 year ago

I've added some checks to mitigate this problem in 0.2.0. In short, if the program detects the first arg as a named argument (i.e. starts with '-'), or as a valid number, it will not drop it. Though it's a simple check, I think it could cover most common cases.