powershell - Extracting Binary Data from MSI -
i'm trying extract binary data msi file using powershell. can other piece of data, can't seem extract binary information.
$query = "select data binary name = 'bannrbmp'" $view = $database.gettype().invokemember("openview", "invokemethod", $null, $database, ($query)) $view.gettype().invokemember("execute", "invokemethod", $null, $view, $null) $record = $view.gettype().invokemember("fetch", "invokemethod", $null, $view, $null) $binarydata = $record.gettype().invokemember("stringdata", "getproperty", $null, $record, 1)
it breaks on final line, leads me believe issue exists "stringdata", way off target. here table looks when opened in orca.
this code complete when extracting textual data below.
$query = "select component featurecomponents feature = 'orcahelp'" $view = $database.gettype().invokemember("openview", "invokemethod", $null, $database, ($query)) $view.gettype().invokemember("execute", "invokemethod", $null, $view, $null) $record = $view.gettype().invokemember("fetch", "invokemethod", $null, $view, $null) $data = $record.gettype().invokemember("stringdata", "getproperty", $null, $record, 1)
i couldn't seem find on web, if able appreciated.
this c++ code fragment extracts binary , writes disk. use it, or @ least see flow , stream read. these basic win32 api calls scripting languages call, no interop required. need includes of stdio.h, windows.h, msiquery.h , packaging in program or dll call - don't know c++ comfort level. should work ok, though i've not tested recently.
pmsihandle hdatabase; pmsihandle hbinaryview; pmsihandle hbinaryrecord; //get handle active database. need view manipulation uint nr = msiopendatabase ("some.msi", msidbopen_readonly, &hdatabase); //get view of binary table based on sql query char squery [] = {"select * binary name='somebinary'"}; // binary nr = msidatabaseopenview(hdatabase, squery, &hbinaryview); if (nr!= error_success) return 1; //msiviewexecute needs to called msifetchview. //we pass null because query above granular can //so not need take further specifying additional value. nr = msiviewexecute(hbinaryview, null); if (nr == error_success) //fetch view record. because can //streams out of record , not out of view. nr = msiviewfetch(hbinaryview, &hbinaryrecord); //make sure entry found in table if (nr == error_success) { //build path write file tchar filename [max_path] = {"somefile.ext"}; char bstream [4096] = {0}; bool bokay=true; handle hfile = createfile(filename, generic_write, 0, 0, create_always, file_attribute_normal, 0); if (hfile == invalid_handle_value) nr = -1; else { long ntotal = 0; long nattr = 0; dword nwritten, nbuffer; { // read stream buffer, 1023 bytes @ time nbuffer=1023; nr = msirecordreadstream(hbinaryrecord, 2, bstream, &nbuffer); // binary & cab 2 if ((error_success == nr) && (nbuffer > 0)) { //write buffer file. nr = writefile(hfile, bstream, nbuffer, &nwritten, null); if (nr != 0)// 0 bad ntotal = ntotal + nbuffer; // debug else bokay = false; } else if (nr != error_success) bokay = false; } // record record stream while (bokay == true && (nbuffer > 0)); // done copying file closehandle(hfile); }// create file // needed 1 row, close view msiviewclose(hbinaryview); // done query msiclosehandle(hbinaryrecord); } // done binary table msiclosehandle(hbinaryview); // done msi database msiclosehandle(hdatabase);
Comments
Post a Comment