INF files parser for python
wininfparser Python module that can open, save, edit Windows INF files (Driver Files)
Note
pip install wininfparserpip install wininfparser --upgradefromwininfparserimportWinINF, INFsectionInfFile=WinINF()
#Open Intel.infInfFile.ParseFile("./Intel.inf")
#Save Intel.inf on th same placeInfFile.Save()fromwininfparserimportWinINF, INFsectionInfFile=WinINF()
h="""########################## Header data 07/11/2023 Other data Some very important information##########################"""# Creates a header and sets an indent of 3 after it n=INFsection()
n.SetHeader(h)
n.SetIndent(3)
# Add header to the inf fileInfFile.AddSection(n)
n=INFsection()
# Enable key alignment# set indent after key 1# set indent before value 1# set indent before comment 4n.SetKeyAutoSize(True,1,1,4)
## also n.SetIndents(1,1,4) can be used#Add key/value/comment data to the sectionn.SetName("New_Section")
n.AddData("Path","./somepath")
n.AddData("Version","2.34.57","megatest")
n["TestKey"]="TestValue"#Add commentn.AddComment(" some comment")
#Add two empty linesn.AddComment()
n.AddComment()
#Add commentn.AddComment(" some comment 2")
#Add section to the end of the inf fileInfFile.AddSection(n)
#Save inf fileInfFile.Save(./new_file.inf);##########################;; Header data 07/11/2023; Other data; Some very important information;;##########################[New_Section]Path = ./somepath
Version = 2.34.57 ;megatestTestKey = TestValue
; some comment; some comment 2InfFile=WinINF()
InfFile.ParseFile("./Intel.inf")
# print section namesprint(InfFile.Sections())
# iterate over sectionsforsinInfFile:
print(s.GetName())
#Find section by names=InfFile['Manufacturer']
ifsisnotNone:
print(s.GetName())
#Sets number of white spaces to the last sectionInfFile.Last().SetIndent(3)
#Create new section, and set section name n=INFsection()
n.SetName("New_Section")
# Enable key alignment# set indent after key 1# set indent before value 1n.SetKeyAutoSize(True,1,1)
#Add key/value data to the sectionn.AddData("Path","./somepath")
n.AddData("Version","2.34.57")
n["TestKey"]="TestValue"#Add section to the end of the inf fileInfFile.AddSection(n)
#Save Intel.inf on th same placeInfFile.Save()InfFile=WinINF()
InfFile.ParseFile("./Intel.inf")
#Find and remove New_Sections=InfFile['New_Section']
ifsisnotNone:
InfFile.RemoveSection(s)
#Save Intel.inf on th same placeInfFile.Save()InfFile=WinINF()
InfFile.ParseFile("./Intel.inf")
# Get "Intel.Mfg" sections=InfFile['Intel.Mfg']
ifsisNone:
print("Error: section not found!")
sys.exit(-10)
#Get key with index 2Key=s[2]
print(Key)
# Finds the first key containing "iBKDG" and return its valueValue=s.Find("iBKDG")
print(Value)
# Finds the first key exactly matching "%iBKDG%" and return its valueValue=s["%iBKDG%"]
print(Value)
#Searches for keys that contain "i830M" and returns their valuesfork,v,cins.SearchKeyIter("i830M"):
print(v)
#Print all section contentfork,v,cins:
print(v);=============================================================================;; Copyright (c) Intel Corporation (2002).;; INTEL MAKES NO WARRANTY OF ANY KIND REGARDING THE CODE. THIS CODE IS; LICENSED ON AN "AS IS" BASIS AND INTEL WILL NOT PROVIDE ANY SUPPORT,; ASSISTANCE, INSTALLATION, TRAINING OR OTHER SERVICES. INTEL DOES NOT; PROVIDE ANY UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY; DISCLAIMS ANY WARRANTY OF MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR ANY; PARTICULAR PURPOSE, OR ANY OTHER WARRANTY. Intel disclaims all liability,; including liability for infringement of any proprietary rights, relating to; use of the code. No license, express or implied, by estoppel or otherwise,; to any intellectual property rights is granted herein.;;=============================================================================; Installation inf for the Intel Corporation graphics adapter.[Version]Signature="$WINDOWS NT$"Provider=%Intel%
ClassGUID={4D36E968-E325-11CE-BFC1-08002BE10318}
Class=Display
CatalogFile=i830mnt5.cat
DriverVer=08/20/2004,6.14.10.3889
[DestinationDirs]DefaultDestDir = 11
ialm.Miniport = 12 ; driversialm.Display = 11 ; system32Help.Copy = 11
CUI.Copy = 11
Uninstall_Copy = 11
OpenGL.Copy = 11 ; OpenGL Drivers in System32;; Driver information;[Manufacturer]
%Intel% = Intel.Mfg
[Intel.Mfg];830;%i830M% = i830M, PCI\VEN_8086&DEV_3577
%i830M% = i830M, PCI\VEN_8086&DEV_3577&SUBSYS_00C81028
%i830M% = i830M, PCI\VEN_8086&DEV_3577&SUBSYS_01221028
%i830M% = i830M, PCI\VEN_8086&DEV_3577&SUBSYS_00B81028
%i830M% = i830M, PCI\VEN_8086&DEV_3577&SUBSYS_00B91028
%i830M% = i830M, PCI\VEN_8086&DEV_3577&SUBSYS_00F51028
;845;%iBKDG% = i845G, PCI\VEN_8086&DEV_2562
%iBKDG% = i845G, PCI\VEN_8086&DEV_2562&SUBSYS_013D1028
%iBKDG% = i845G, PCI\VEN_8086&DEV_2562&SUBSYS_01471028
%iBKDG% = i845G, PCI\VEN_8086&DEV_2562&SUBSYS_03011028
%iBKDG% = i845G, PCI\VEN_8086&DEV_2562&SUBSYS_013A1028
%iBKDG% = i845G, PCI\VEN_8086&DEV_2562&SUBSYS_01481028
%iBKDG% = i845G, PCI\VEN_8086&DEV_2562&SUBSYS_01381028
%iBKDG% = i845G, PCI\VEN_8086&DEV_2562&SUBSYS_01261028
%iBKDG% = i845G, PCI\VEN_8086&DEV_2562&SUBSYS_01271028
%iBKDG% = i845G, PCI\VEN_8086&DEV_2562&SUBSYS_01331028
%iBKDG% = i845G, PCI\VEN_8086&DEV_2562&SUBSYS_014B1028
%iBKDG% = i845G, PCI\VEN_8086&DEV_2562&SUBSYS_01601028
%iBKDG% = i845G, PCI\VEN_8086&DEV_2562&SUBSYS_01611028
%iBKDG% = i845G, PCI\VEN_8086&DEV_2562&SUBSYS_01291028
%iBKDG% = i845G, PCI\VEN_8086&DEV_2562&SUBSYS_01461028
%iBKDG% = i845G, PCI\VEN_8086&DEV_2562&SUBSYS_03031028
;845GM
%iBKDGM% = i845GM, PCI\VEN_8086&DEV_2562&SUBSYS_01491028