Last active
September 8, 2020 13:56
-
-
Save nijave/f323eb1756933b968b70f0cb951ea619 to your computer and use it in GitHub Desktop.
Read Hyper-V key-value pair data on Linux guest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Inspired by https://github.com/ejsiron/hvkvp | |
# explanation of format https://www.altaro.com/hyper-v/key-value-pair-data-exchange-3-linux/ | |
# pool_3 host->guest (read-only) | |
with open("/var/lib/hyperv/.kvp_pool_3", "r") as f: | |
data = f.read() | |
# Each k, v is a nul terminated string. k is 512 bytes, v 2048 bytes | |
# so 2560 bytes is a single item | |
n = 2560 | |
pairs = { | |
# It looks like the nul terminated strings may have non nul data so stop reading when | |
# first nul byte is found after the data | |
c[0:c[0:512].find("\x00")].replace("\x00",""): c[512:512+c[512:].find("\x00")].replace("\x00","") | |
for c in [data[i:i+n] for i in range(0, len(data), n)] | |
} | |
print(pairs) |
Author
nijave
commented
Sep 8, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment