Created
July 6, 2022 08:07
-
-
Save odzhan/088a0f49e90415f5d590da59ee8f14d6 to your computer and use it in GitHub Desktop.
Uses Windows COM to create an ISO
This file contains hidden or 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
| // | |
| // adapted from : https://gist.github.com/daaximus/a48b0a991b31e8841b68dbbc480a0a5a | |
| // | |
| #define UNICODE | |
| #include <windows.h> | |
| #include <imapi2fs.h> | |
| #include <shlwapi.h> | |
| #include <objbase.h> | |
| #include <oleauto.h> | |
| #pragma comment(lib, "shlwapi") | |
| #pragma comment(lib, "ole32") | |
| #pragma comment(lib, "oleaut32") | |
| void create_iso( PWCHAR src, PWCHAR iso_path ) | |
| { | |
| HRESULT hr; | |
| IFileSystemImage* fsimg; | |
| IFsiDirectoryItem* fsdir; | |
| IFileSystemImageResult* fsresult; | |
| IStream* img; | |
| IStream* filestream; | |
| hr = CoCreateInstance( __uuidof( MsftFileSystemImage ), | |
| NULL, | |
| CLSCTX_INPROC_SERVER, | |
| __uuidof( IFileSystemImage ), | |
| ( LPVOID* ) &fsimg ); | |
| if ( SUCCEEDED( hr ) ) | |
| { | |
| fsimg->get_Root( &fsdir ); | |
| BSTR src_bstr = SysAllocString(src); | |
| fsdir->AddTree( src_bstr, VARIANT_TRUE ); | |
| SysFreeString(src_bstr); | |
| hr = fsimg->CreateResultImage( &fsresult ); | |
| if ( SUCCEEDED( hr ) ) | |
| { | |
| fsresult->get_ImageStream( &img ); | |
| if ( SUCCEEDED( hr ) ) | |
| { | |
| STATSTG statstg; | |
| ULARGE_INTEGER rd; | |
| ULARGE_INTEGER wr; | |
| BSTR iso_bstr = SysAllocString(iso_path); | |
| SHCreateStreamOnFileEx( iso_bstr, | |
| STGM_READWRITE, | |
| FILE_ATTRIBUTE_NORMAL, | |
| TRUE, | |
| NULL, | |
| &filestream ); | |
| SysFreeString(iso_bstr); | |
| img->Stat( &statstg, STATFLAG_DEFAULT ); | |
| img->CopyTo( filestream, statstg.cbSize, &rd, &wr ); | |
| filestream->Release(); | |
| img->Release(); | |
| } | |
| fsresult->Release(); | |
| } | |
| fsimg->Release(); | |
| } | |
| } | |
| int | |
| main(void) { | |
| CoInitialize(NULL); | |
| create_iso(L"c:\\windows\\system32\\cmd.exe", L"cmd.iso"); | |
| CoUninitialize(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment