GithubHelp home page GithubHelp logo

rhydon1337 / firmware-variables Goto Github PK

View Code? Open in Web Editor NEW

This project forked from netaneld122/firmware-variables

0.0 0.0 0.0 50 KB

Python library for controlling UEFI variables in Windows.

License: MIT License

Python 100.00%

firmware-variables's Introduction

firmware_variables

Language grade: Python

Python library for controlling UEFI variables in Windows.

Requirements

  • Windows ≥ 8
  • Python ≥ 3.7 (might work on Python >= 2.7 but not formally supported)
  • UEFI Firmware (required for most APIs)
  • Administrative privileges (required for most APIs)

Installation

pip install firmware_variables

Usage

Run as Administrator

Read variables

from firmware_variables import *

# Acquire privileges to read the firmware state in your process
with privileges():
    # Read the current boot id 
    data, attr = get_variable("BootCurrent")
    print(data)
    print(attr)

Output:

b'\x00\x00'
Attributes.RUNTIME_ACCESS|BOOT_SERVICE_ACCESS

Display the boot order

from firmware_variables import *

with privileges():
    for entry_id in get_boot_order():
        load_option = get_parsed_boot_entry(entry_id)
        print(f"{entry_id} {load_option}")

Output:

0 <Windows Boot Manager \EFI\MICROSOFT\BOOT\BOOTMGFW.EFI [LoadOptionAttributes.LOAD_OPTION_ACTIVE]>
2 <Hard Drive <Custom Location> [LoadOptionAttributes.LOAD_OPTION_ACTIVE]>

Manipulate system state

Caution: The following commands will modify your system state.
Do not run it on your host machine unless you know what you're doing.

from firmware_variables import *

with privileges():

    # Create a new variable
    set_variable("Test", b"\x00",
    namespace="{f29e2c32-8cca-44ff-93d7-87195ace38b9}", 
    attributes= Attributes.NON_VOLATILE | 
                Attributes.BOOT_SERVICE_ACCESS |
                Attributes.RUNTIME_ACCESS)
    
    # Delete it
    delete_variable("Test", namespace="{f29e2c32-8cca-44ff-93d7-87195ace38b9}")
    
    # Add a new entry id to your boot order
    order = get_boot_order()
    new_id = max(order) + 1
    set_boot_order(order + [new_id])
    
    # Read the first boot entry
    load_option = get_parsed_boot_entry(order[0])
    load_option.description = "My Boot Entry"
    load_option.file_path_list.set_file_path(r"\EFI\Boot\myfile.efi")
    
    # Create our new boot entry based on the first entry
    set_parsed_boot_entry(new_id, load_option)

firmware-variables's People

Contributors

netaneld122 avatar guye1296 avatar ilayrosenberg avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.