Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
# Magic patch
An extensible tool for extracting windows patches


## Install

Initiate vitrual environment for good luck:

~~~shell
PS S:\tools\windows_patch_extract> python.exe -m venv venv
PS S:\tools\windows_patch_extract> . venv\Scripts\activate
(venv) PS S:\tools\windows_patch_extract>
~~~

Install from `pyproject.toml` - note that due to the `distutils` dependency the maximum supported Python version is 3.10:

~~~shell
(venv) PS S:\tools\windows_patch_extract> pip install .
~~~

The install script creates the `magic-cli` wrapper that should be available in you PATH.


## Usage
Normal files: Full file doesn't need to apply delta patch

Expand All @@ -12,7 +32,7 @@ Reverse files: Upated + Reverse = Base

- List windows product_id
~~~shell
PS S:\tools\windows_patch_extract> py -3 .\magic.py -l
PS S:\tools\windows_patch_extract> magic-cli -l
List of products
{
"9312": "Windows RT 8.1",
Expand Down Expand Up @@ -60,7 +80,7 @@ List of products

- Search for a specific CVE update
~~~shell
PS S:\tools\windows_patch_extract> py -3 .\magic.py -cve CVE-2022-37987 12086
PS S:\tools\windows_patch_extract> magic-cli -cve CVE-2022-37987 12086
[!WARNING] product_id doesn't match local machine
Security update 2022-Oct for CVE-2022-37987 on Windows 11 Version 22H2 for x64-based Systems
{
Expand All @@ -78,7 +98,7 @@ Security update 2022-Oct for CVE-2022-37987 on Windows 11 Version 22H2 for x64-b

- Expand an update file
~~~shell
PS S:\tools\windows_patch_extract> py -3 .\magic.py -expand E:\windows11.0-kb5018427-x64_ba6a752015a4115e688beea33f2afe8c55156b55.cab
PS S:\tools\windows_patch_extract> magic-cli -expand E:\windows11.0-kb5018427-x64_ba6a752015a4115e688beea33f2afe8c55156b55.cab
create E:\expand
[INFO] Running expand.exe -F:* E:\windows11.0-kb5018427-x64_ba6a752015a4115e688beea33f2afe8c55156b55.cab E:\expand
[INFO] Running expand.exe -F:* E:\expand\DesktopDeployment.cab E:\expand\DesktopDeployment_cab
Expand All @@ -92,7 +112,7 @@ create E:\expand

- Scan an expanded directory
~~~shell
PS S:\tools\windows_patch_extract> py -3 .\magic.py -scan e:\expand
PS S:\tools\windows_patch_extract> magic-cli -scan e:\expand
[INFO] Scanning e:\expand
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -------------- ----- ------
e:\expand\SSU-22621_378-x64_cab\amd64_microsoft-windows-s..-installers-onecore_31bf3856ad364e35_10.0.22621.378_none_4db921ab6e990364\appxprovisionpackage.dll 10.0.22621.378 amd64 normal
Expand All @@ -106,7 +126,7 @@ e:\expand\SSU-22621_378-x64_cab\amd64_microsoft-windows-s..-installers-onecore_3

- Extract a single file
~~~shell
PS S:\tools\windows_patch_extract> py -3 .\magic.py -extract sxssrv.dll amd64 e:\expand
PS S:\tools\windows_patch_extract> magic-cli -extract sxssrv.dll amd64 e:\expand
[INFO] Scanning e:\expand
[INFO] Using cached result
[INFO] Forward file found at E:\expand\Windows10_0-KB5018418-x64_cab\amd64_microsoft-windows-sxssrv_31bf3856ad364e35_10.0.22000.1098_none_d9d9980beec843d4\f\sxssrv.dll
Expand All @@ -120,7 +140,7 @@ PS S:\tools\windows_patch_extract> py -3 .\magic.py -extract sxssrv.dll amd64 e:

- Extract 2 files for diffing in IDA
~~~shell
PS S:\tools\windows_patch_extract> py -3 .\magic.py -diff vmemulateddevices.dll amd64 E:\expand\
PS S:\tools\windows_patch_extract> magic-cli -diff vmemulateddevices.dll amd64 E:\expand\
[INFO] Using platform amd64
[INFO] Scanning E:\expand\
[INFO] Forward file found at E:\expand\Windows10_0-KB5018418-x64_cab\amd64_hyperv-vmemulateddevices_31bf3856ad364e35_10.0.22000.1042_none_25945f084ac0858f\f\vmemulateddevices.dll
Expand Down
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[project]
name = "windows_patch_extractor"
version = "2025.2.0"
requires-python = "< 3.11, >= 3.0"
dependencies = [
"requests",
"termcolor",
"tabulate",
"tqdm"
]

[project.scripts]
magic-cli = "magic:main_cli"

File renamed without changes.
8 changes: 6 additions & 2 deletions magic.py → src/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def do_scan(scan_dir: str):
def scan_file_exists(dir: str):
return os.path.exists(os.path.join(dir, SCAN_FILE_NAME))

if __name__ == '__main__':
def main_cli():
action = sys.argv[1]

if action == '-expand':
Expand Down Expand Up @@ -643,4 +643,8 @@ def func(f:UpdateFile):
else:
print_error(f'invalid action: {action}')




if __name__ == '__main__':
main_cli()

File renamed without changes.