Advertisement
aveyo

SVF_Info

Oct 24th, 2019 (edited)
1,283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 9.22 KB | None | 0 0
  1. @echo off & set /a ver=20220804 & title SVF Info context menu via svfdll
  2. :: prepare
  3. call :svfsetup
  4. :: show svf info for param1 if it is a svf file
  5. if %~x1. equ .svf. call :svfInfo "%~f1" & pause & exit /b
  6. :: else show info for all svf files in param1 folder or current directory
  7. set "dir=%~dp0" & for /f "tokens=1 delims=r-" %%s in ("%~a1") do if /i "%%s"=="d" set "dir=%~1"
  8. cd /d "%dir%" & for /r %%s in (*.svf) do call :svfInfo "%%~fs"
  9. :: done
  10. pause
  11. exit /b
  12.  
  13. :svfsetup
  14. reg query "HKCU\Software\Classes\.svf\shell\svfInfo" /v MuiVerb >nul 2>nul || (
  15.   reg add HKCU\Software\Classes\.svf\shell\svfInfo /v MuiVerb /d "SVF Info" /f
  16.   reg add HKCU\Software\Classes\.svf\shell\svfInfo\command /ve /d "cmd /c call \"%APPDATA%\svfInfo\SVF_Info.bat\" \"%%1\"" /f
  17. ) >nul 2>nul
  18. mkdir "%APPDATA%\svfInfo" >nul 2>nul & pushd "%APPDATA%\svfInfo"
  19. if not exist SVF_Info.bat copy /y "%~f0" SVF_Info.bat >nul 2>nul
  20. set oldver=0 & for /f "tokens=6" %%v in ('findstr /C:"/a ver=" SVF_Info.bat') do set "old%%v"
  21. rem allow updated script to override APPDATA cached file
  22. if %oldver% lss %ver% copy /y "%~f0" SVF_Info.bat >nul 2>nul & del /f /q svfdll.dll >nul 2>nul
  23. if exist svfdll.dll popd & exit /b
  24. :: try to download svfdll.dll from subversion site
  25. set "url=http://www.smartversion.com/smvsdk_382_004.zip"
  26. set "file=smvsdk_382_004.zip"
  27. set "dldir=%APPDATA%\svfInfo\_%random%_%random%_"
  28. mkdir "%dldir%" & pushd "%dldir%"
  29. if not exist %file% call :DOWNLOAD "%url%" %file%
  30. if exist %file% call :UNZIP %file% "%dldir%"
  31. timeout /t 3 /nobreak >nul
  32. set "ARCH=x64" & if "%PROCESSOR_ARCHITECTURE:~-2%"=="86" if not defined PROCESSOR_ARCHITEW6432 set "ARCH=Win32"
  33. set "svfdll=%dldir%\%ARCH%\svfdll_vs2019\Release\svfdll.dll"
  34. copy /y "%svfdll%" "%APPDATA%\svfInfo\"
  35. popd & rd /s /q "%dldir%" >nul 2>nul
  36. set err_message=ERROR! cannot download %url% and extract svfdll.dll to %APPDATA%\svfInfo\svfdll.dll
  37. if not exist "%APPDATA%\svfInfo\svfdll.dll" echo %err_message%
  38. exit /b
  39.  
  40. #:DOWNLOAD:# [PARAMS] "url" "file" [optional]"path"
  41. set ^ #=& for %%. in (%2) do if "%~z2" gtr "0" (exit /b 0) else echo;%~1
  42. set ^ #=;$f0=[io.file]::ReadAllText($env:0); $0=($f0-split '#\:DOWNLOAD\:' ,3)[1]; $1=$env:1-replace'([`@$])','`$1'; iex($0+$1)
  43. set ^ #=& set "0=%~f0"& set 1=;DOWNLOAD %*& powershell -nop -c "%#%"& exit /b %errorcode%
  44. function DOWNLOAD ($u, $f, $p = (get-location).Path) {
  45.   $null = Import-Module BitsTransfer -ea 0; $wc = new-object Net.WebClient; $wc.Headers.Add('user-agent','ipad')
  46.   $file = join-path $p $f; $s = 'https://'; $i = 'http://'; $d = ($u -replace $s,'') -replace $i,''; $https = $s+$d; $http = $i+$d
  47.   foreach ($url in $http, $https) {
  48.     if (([IO.FileInfo]$file).Length -gt 0) {return}; try {Start-BitsTransfer $url $file -ea 1} catch {}
  49.     if (([IO.FileInfo]$file).Length -gt 0) {return}; try {Invoke-WebRequest $url -OutFile $file} catch {} ; $j = (Get-Date).Ticks
  50.     if (([IO.FileInfo]$file).Length -gt 0) {return}; try {$null = bitsadmin /transfer $j /priority foreground $url $file} catch {}
  51.     if (([IO.FileInfo]$file).Length -gt 0) {return}; try {$wc.DownloadFile($url, $file)} catch {}
  52.   }
  53.   if (([IO.FileInfo]$file).Length -gt 0) {return}; write-host -fore Yellow " $f download failed "
  54. } #:DOWNLOAD:# try download url via bits, net, and http/https - snippet by AveYo, 2021
  55.  
  56. #:UNZIP:# [PARAMS] "file" [optional]"path"
  57. set ^ #=;$f0=[io.file]::ReadAllText($env:0); $0=($f0-split '#\:UNZIP\:' ,3)[1]; $1=$env:1-replace'([`@$])','`$1'; iex($0+$1)
  58. set ^ #=& set "0=%~f0"& set 1=;UNZIP %*& powershell -nop -c "%#%"& exit /b %errorcode%
  59. function UNZIP ($file, $target = (get-location).Path) {
  60.   $f = resolve-path -lit $file; mkdir $target -ea 0 >$null; $t = resolve-path -lit $target;
  61.   if (get-command Expand-Archive -ea 0) {Expand-Archive "$f" "$t" -force -ea 0}
  62.   else {$s=new-object -com shell.application; foreach($i in $s.NameSpace("$f").items()) {$s.Namespace("$t").copyhere($i,0x14)}}
  63. } #:UNZIP:# extract zip folder - snippet by AveYo, 2021
  64.  
  65. :svfInfo
  66. pushd "%APPDATA%\svfInfo" & set "0=%~f0" & set "1=%~f1"
  67. powershell -nop -c "$svf=$env:1; iex ([io.file]::ReadAllText($env:0) -split '[:]ps_svf[:]')[1];" & exit /b :ps_svf:
  68. $SmartVersionDLL=@'
  69. // Svfdll.cs from SmartVersion SDK, adapted by AveYo
  70. // translation of winimage.h header, made with the help of Tom McCartney
  71. using System.Runtime.InteropServices;
  72. using System.Text;
  73. using System;
  74. using System.IO;
  75. public static class SvfDll
  76. {
  77.   [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi,Pack=1)] public struct MD5Info {
  78.     [MarshalAs(UnmanagedType.ByValArray,SizeConst=16)] public byte[] data;
  79.   }
  80.  
  81.   [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi,Pack=1)] public struct SHA1Info {
  82.     [MarshalAs(UnmanagedType.ByValArray,SizeConst=20)] public byte[] data;
  83.   }
  84.  
  85.   [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi,Pack=1)] public struct SHA256Info {
  86.     [MarshalAs(UnmanagedType.ByValArray,SizeConst=32)] public byte[] data;
  87.   }
  88.  
  89.   public enum KindDfsFile {
  90.     KINDDFSFILE_INVALID=0, KINDDFSFILE_REFERENCE=1, KINDDFSFILE_FULL=2, KINDDFSFILE_PATCH=3
  91.   };
  92.  
  93.   [DllImport("svfdll.dll",EntryPoint="GetSvfMonoPatchInfoEx2",ExactSpelling=true,CharSet=CharSet.Ansi,SetLastError=true)]
  94.   public static extern int GetSvfMonoPatchInfoEx2( string a,ref KindDfsFile b,StringBuilder c,Int32 d,ref UInt64 e,ref UInt32 f,
  95.     ref Boolean g,ref MD5Info h,ref Boolean i,ref SHA1Info j,ref Boolean k,ref SHA256Info l,ref Boolean m,StringBuilder n,
  96.     Int32 o,ref UInt64 p,ref UInt32 q,ref Boolean r,ref MD5Info s,ref Boolean t,ref SHA1Info u,ref Boolean v,ref SHA256Info w,
  97.     ref Boolean x,ref UInt64 y,ref UInt64 z,ref Boolean z1,ref int z2,ref int z3,StringBuilder z4,Int32 z5,ref UInt32 z6,
  98.     ref UInt32 z7,ref IntPtr z8,UInt32 z9
  99.   );
  100.  
  101.   public static string toHash(byte[]hashData)
  102.   {
  103.     string hashText = String.Empty;
  104.     foreach (byte b in hashData)
  105.     {
  106.       string hexValue = b.ToString("X").ToLower(); // Lowercase for compatibility on case-sensitive systems
  107.       hashText += (hexValue.Length == 1 ? "0" : "") + hexValue;
  108.     }
  109.     return hashText;
  110.   }
  111.  
  112.   public static string toCRC(UInt32 crcData)
  113.   {
  114.     byte[] crc = BitConverter.GetBytes(crcData); Array.Reverse(crc); return toHash(crc);
  115.   }
  116.  
  117.   public static void Info(string svf)
  118.   {
  119.     KindDfsFile KindDfs = new KindDfsFile(); Int32 errSize = 1024;
  120.  
  121.     StringBuilder srcName = new StringBuilder(errSize + 1); UInt64 srcSize = 0;
  122.     UInt32 srcCRC32 = 0; Boolean bsrcCRC32 = false;
  123.     MD5Info srcMD5 = new MD5Info(); Boolean bsrcMD5 = false;
  124.     SHA1Info srcSHA1 = new SHA1Info(); Boolean bsrcSHA1 = false;
  125.     SHA256Info srcSHA256 = new SHA256Info(); Boolean bsrcSHA256 = false;
  126.  
  127.     StringBuilder tgtName = new StringBuilder(errSize + 1); UInt64 tgtSize = 0;
  128.     UInt32 tgtCRC32 = 0; Boolean btgtCRC32 = false;
  129.     MD5Info tgtMD5 = new MD5Info(); Boolean btgtMD5 = false;
  130.     SHA1Info tgtSHA1 = new SHA1Info(); Boolean btgtSHA1 =  false;
  131.     SHA256Info tgtSHA256 = new SHA256Info(); Boolean btgtSHA256 = false;
  132.  
  133.     UInt64 deplInPlaceSize = 0; UInt64 deplOutPlaceSize = 0; Boolean fInsertSizeFound = false;
  134.     int err_moment = 0; int errinfo = 0; StringBuilder errMsg = new StringBuilder(errSize + 1);
  135.     UInt32 pNbVersion = 0; UInt32 pSuggestedExtractMethod = 0;
  136.     IntPtr pBufFullCompressInfo = IntPtr.Zero; UInt32 fullCompressInfoBufsize = 4;
  137.  
  138.     GetSvfMonoPatchInfoEx2( svf,ref KindDfs,srcName,errSize,ref srcSize,ref srcCRC32,
  139.       ref bsrcCRC32,ref srcMD5,ref bsrcMD5,ref srcSHA1,ref bsrcSHA1,ref srcSHA256,
  140.       ref bsrcSHA256,tgtName,errSize,ref tgtSize,ref tgtCRC32,ref btgtCRC32,
  141.       ref tgtMD5,ref btgtMD5,ref tgtSHA1,ref btgtSHA1,ref tgtSHA256,ref btgtSHA256,
  142.       ref deplInPlaceSize,ref deplOutPlaceSize,ref fInsertSizeFound,ref err_moment,ref errinfo,errMsg,errSize,
  143.       ref pNbVersion,ref pSuggestedExtractMethod,ref pBufFullCompressInfo,fullCompressInfoBufsize
  144.     );
  145.     Boolean bsrcName = (srcName.Length!=0); Boolean btgtName = (tgtName.Length!=0);
  146.  
  147.     Console.WriteLine(" {0}", svf);
  148.     Console.WriteLine(new string('-', 100));
  149.     if (bsrcName)   Console.WriteLine(" source.File   = {0}", srcName.ToString());
  150.     if (srcSize>0)  Console.WriteLine(" source.Size   = {0}", srcSize);
  151.     if (bsrcCRC32)  Console.WriteLine(" source.CRC32  = {0}", toCRC(srcCRC32));
  152.     if (bsrcMD5)    Console.WriteLine(" source.MD5    = {0}", toHash(srcMD5.data));
  153.     if (bsrcSHA1)   Console.WriteLine(" source.SHA1   = {0}", toHash(srcSHA1.data));
  154.     if (bsrcSHA256) Console.WriteLine(" source.SHA256 = {0}", toHash(srcSHA256.data));
  155.     if (bsrcName)   Console.WriteLine();
  156.     if (btgtName)   Console.WriteLine(" target.File   = {0}", tgtName.ToString());
  157.     if (tgtSize>0)  Console.WriteLine(" target.Size   = {0}", tgtSize);
  158.     if (btgtCRC32)  Console.WriteLine(" target.CRC32  = {0}", toCRC(tgtCRC32));
  159.     if (btgtMD5)    Console.WriteLine(" target.MD5    = {0}", toHash(tgtMD5.data));
  160.     if (btgtSHA1)   Console.WriteLine(" target.SHA1   = {0}", toHash(tgtSHA1.data));
  161.     if (btgtSHA256) Console.WriteLine(" target.SHA256 = {0}", toHash(tgtSHA256.data));
  162.     if (!bsrcName && !btgtName) Console.WriteLine(" partially downloaded / corrupted ");
  163.     Console.WriteLine(new string('-', 100));
  164.     Console.WriteLine();
  165.   }
  166. }
  167. '@; Add-Type -TypeDefinition $SmartVersionDLL; [SvfDll]::Info($svf); # :ps_svf:
  168. :-_-:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement