Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off & set /a ver=20220804 & title SVF Info context menu via svfdll
- :: prepare
- call :svfsetup
- :: show svf info for param1 if it is a svf file
- if %~x1. equ .svf. call :svfInfo "%~f1" & pause & exit /b
- :: else show info for all svf files in param1 folder or current directory
- set "dir=%~dp0" & for /f "tokens=1 delims=r-" %%s in ("%~a1") do if /i "%%s"=="d" set "dir=%~1"
- cd /d "%dir%" & for /r %%s in (*.svf) do call :svfInfo "%%~fs"
- :: done
- pause
- exit /b
- :svfsetup
- reg query "HKCU\Software\Classes\.svf\shell\svfInfo" /v MuiVerb >nul 2>nul || (
- reg add HKCU\Software\Classes\.svf\shell\svfInfo /v MuiVerb /d "SVF Info" /f
- reg add HKCU\Software\Classes\.svf\shell\svfInfo\command /ve /d "cmd /c call \"%APPDATA%\svfInfo\SVF_Info.bat\" \"%%1\"" /f
- ) >nul 2>nul
- mkdir "%APPDATA%\svfInfo" >nul 2>nul & pushd "%APPDATA%\svfInfo"
- if not exist SVF_Info.bat copy /y "%~f0" SVF_Info.bat >nul 2>nul
- set oldver=0 & for /f "tokens=6" %%v in ('findstr /C:"/a ver=" SVF_Info.bat') do set "old%%v"
- rem allow updated script to override APPDATA cached file
- if %oldver% lss %ver% copy /y "%~f0" SVF_Info.bat >nul 2>nul & del /f /q svfdll.dll >nul 2>nul
- if exist svfdll.dll popd & exit /b
- :: try to download svfdll.dll from subversion site
- set "url=http://www.smartversion.com/smvsdk_382_004.zip"
- set "file=smvsdk_382_004.zip"
- set "dldir=%APPDATA%\svfInfo\_%random%_%random%_"
- mkdir "%dldir%" & pushd "%dldir%"
- if not exist %file% call :DOWNLOAD "%url%" %file%
- if exist %file% call :UNZIP %file% "%dldir%"
- timeout /t 3 /nobreak >nul
- set "ARCH=x64" & if "%PROCESSOR_ARCHITECTURE:~-2%"=="86" if not defined PROCESSOR_ARCHITEW6432 set "ARCH=Win32"
- set "svfdll=%dldir%\%ARCH%\svfdll_vs2019\Release\svfdll.dll"
- copy /y "%svfdll%" "%APPDATA%\svfInfo\"
- popd & rd /s /q "%dldir%" >nul 2>nul
- set err_message=ERROR! cannot download %url% and extract svfdll.dll to %APPDATA%\svfInfo\svfdll.dll
- if not exist "%APPDATA%\svfInfo\svfdll.dll" echo %err_message%
- exit /b
- #:DOWNLOAD:# [PARAMS] "url" "file" [optional]"path"
- set ^ #=& for %%. in (%2) do if "%~z2" gtr "0" (exit /b 0) else echo;%~1
- set ^ #=;$f0=[io.file]::ReadAllText($env:0); $0=($f0-split '#\:DOWNLOAD\:' ,3)[1]; $1=$env:1-replace'([`@$])','`$1'; iex($0+$1)
- set ^ #=& set "0=%~f0"& set 1=;DOWNLOAD %*& powershell -nop -c "%#%"& exit /b %errorcode%
- function DOWNLOAD ($u, $f, $p = (get-location).Path) {
- $null = Import-Module BitsTransfer -ea 0; $wc = new-object Net.WebClient; $wc.Headers.Add('user-agent','ipad')
- $file = join-path $p $f; $s = 'https://'; $i = 'http://'; $d = ($u -replace $s,'') -replace $i,''; $https = $s+$d; $http = $i+$d
- foreach ($url in $http, $https) {
- if (([IO.FileInfo]$file).Length -gt 0) {return}; try {Start-BitsTransfer $url $file -ea 1} catch {}
- if (([IO.FileInfo]$file).Length -gt 0) {return}; try {Invoke-WebRequest $url -OutFile $file} catch {} ; $j = (Get-Date).Ticks
- if (([IO.FileInfo]$file).Length -gt 0) {return}; try {$null = bitsadmin /transfer $j /priority foreground $url $file} catch {}
- if (([IO.FileInfo]$file).Length -gt 0) {return}; try {$wc.DownloadFile($url, $file)} catch {}
- }
- if (([IO.FileInfo]$file).Length -gt 0) {return}; write-host -fore Yellow " $f download failed "
- } #:DOWNLOAD:# try download url via bits, net, and http/https - snippet by AveYo, 2021
- #:UNZIP:# [PARAMS] "file" [optional]"path"
- set ^ #=;$f0=[io.file]::ReadAllText($env:0); $0=($f0-split '#\:UNZIP\:' ,3)[1]; $1=$env:1-replace'([`@$])','`$1'; iex($0+$1)
- set ^ #=& set "0=%~f0"& set 1=;UNZIP %*& powershell -nop -c "%#%"& exit /b %errorcode%
- function UNZIP ($file, $target = (get-location).Path) {
- $f = resolve-path -lit $file; mkdir $target -ea 0 >$null; $t = resolve-path -lit $target;
- if (get-command Expand-Archive -ea 0) {Expand-Archive "$f" "$t" -force -ea 0}
- else {$s=new-object -com shell.application; foreach($i in $s.NameSpace("$f").items()) {$s.Namespace("$t").copyhere($i,0x14)}}
- } #:UNZIP:# extract zip folder - snippet by AveYo, 2021
- :svfInfo
- pushd "%APPDATA%\svfInfo" & set "0=%~f0" & set "1=%~f1"
- powershell -nop -c "$svf=$env:1; iex ([io.file]::ReadAllText($env:0) -split '[:]ps_svf[:]')[1];" & exit /b :ps_svf:
- $SmartVersionDLL=@'
- // Svfdll.cs from SmartVersion SDK, adapted by AveYo
- // translation of winimage.h header, made with the help of Tom McCartney
- using System.Runtime.InteropServices;
- using System.Text;
- using System;
- using System.IO;
- public static class SvfDll
- {
- [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi,Pack=1)] public struct MD5Info {
- [MarshalAs(UnmanagedType.ByValArray,SizeConst=16)] public byte[] data;
- }
- [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi,Pack=1)] public struct SHA1Info {
- [MarshalAs(UnmanagedType.ByValArray,SizeConst=20)] public byte[] data;
- }
- [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi,Pack=1)] public struct SHA256Info {
- [MarshalAs(UnmanagedType.ByValArray,SizeConst=32)] public byte[] data;
- }
- public enum KindDfsFile {
- KINDDFSFILE_INVALID=0, KINDDFSFILE_REFERENCE=1, KINDDFSFILE_FULL=2, KINDDFSFILE_PATCH=3
- };
- [DllImport("svfdll.dll",EntryPoint="GetSvfMonoPatchInfoEx2",ExactSpelling=true,CharSet=CharSet.Ansi,SetLastError=true)]
- public static extern int GetSvfMonoPatchInfoEx2( string a,ref KindDfsFile b,StringBuilder c,Int32 d,ref UInt64 e,ref UInt32 f,
- ref Boolean g,ref MD5Info h,ref Boolean i,ref SHA1Info j,ref Boolean k,ref SHA256Info l,ref Boolean m,StringBuilder n,
- 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,
- 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,
- ref UInt32 z7,ref IntPtr z8,UInt32 z9
- );
- public static string toHash(byte[]hashData)
- {
- string hashText = String.Empty;
- foreach (byte b in hashData)
- {
- string hexValue = b.ToString("X").ToLower(); // Lowercase for compatibility on case-sensitive systems
- hashText += (hexValue.Length == 1 ? "0" : "") + hexValue;
- }
- return hashText;
- }
- public static string toCRC(UInt32 crcData)
- {
- byte[] crc = BitConverter.GetBytes(crcData); Array.Reverse(crc); return toHash(crc);
- }
- public static void Info(string svf)
- {
- KindDfsFile KindDfs = new KindDfsFile(); Int32 errSize = 1024;
- StringBuilder srcName = new StringBuilder(errSize + 1); UInt64 srcSize = 0;
- UInt32 srcCRC32 = 0; Boolean bsrcCRC32 = false;
- MD5Info srcMD5 = new MD5Info(); Boolean bsrcMD5 = false;
- SHA1Info srcSHA1 = new SHA1Info(); Boolean bsrcSHA1 = false;
- SHA256Info srcSHA256 = new SHA256Info(); Boolean bsrcSHA256 = false;
- StringBuilder tgtName = new StringBuilder(errSize + 1); UInt64 tgtSize = 0;
- UInt32 tgtCRC32 = 0; Boolean btgtCRC32 = false;
- MD5Info tgtMD5 = new MD5Info(); Boolean btgtMD5 = false;
- SHA1Info tgtSHA1 = new SHA1Info(); Boolean btgtSHA1 = false;
- SHA256Info tgtSHA256 = new SHA256Info(); Boolean btgtSHA256 = false;
- UInt64 deplInPlaceSize = 0; UInt64 deplOutPlaceSize = 0; Boolean fInsertSizeFound = false;
- int err_moment = 0; int errinfo = 0; StringBuilder errMsg = new StringBuilder(errSize + 1);
- UInt32 pNbVersion = 0; UInt32 pSuggestedExtractMethod = 0;
- IntPtr pBufFullCompressInfo = IntPtr.Zero; UInt32 fullCompressInfoBufsize = 4;
- GetSvfMonoPatchInfoEx2( svf,ref KindDfs,srcName,errSize,ref srcSize,ref srcCRC32,
- ref bsrcCRC32,ref srcMD5,ref bsrcMD5,ref srcSHA1,ref bsrcSHA1,ref srcSHA256,
- ref bsrcSHA256,tgtName,errSize,ref tgtSize,ref tgtCRC32,ref btgtCRC32,
- ref tgtMD5,ref btgtMD5,ref tgtSHA1,ref btgtSHA1,ref tgtSHA256,ref btgtSHA256,
- ref deplInPlaceSize,ref deplOutPlaceSize,ref fInsertSizeFound,ref err_moment,ref errinfo,errMsg,errSize,
- ref pNbVersion,ref pSuggestedExtractMethod,ref pBufFullCompressInfo,fullCompressInfoBufsize
- );
- Boolean bsrcName = (srcName.Length!=0); Boolean btgtName = (tgtName.Length!=0);
- Console.WriteLine(" {0}", svf);
- Console.WriteLine(new string('-', 100));
- if (bsrcName) Console.WriteLine(" source.File = {0}", srcName.ToString());
- if (srcSize>0) Console.WriteLine(" source.Size = {0}", srcSize);
- if (bsrcCRC32) Console.WriteLine(" source.CRC32 = {0}", toCRC(srcCRC32));
- if (bsrcMD5) Console.WriteLine(" source.MD5 = {0}", toHash(srcMD5.data));
- if (bsrcSHA1) Console.WriteLine(" source.SHA1 = {0}", toHash(srcSHA1.data));
- if (bsrcSHA256) Console.WriteLine(" source.SHA256 = {0}", toHash(srcSHA256.data));
- if (bsrcName) Console.WriteLine();
- if (btgtName) Console.WriteLine(" target.File = {0}", tgtName.ToString());
- if (tgtSize>0) Console.WriteLine(" target.Size = {0}", tgtSize);
- if (btgtCRC32) Console.WriteLine(" target.CRC32 = {0}", toCRC(tgtCRC32));
- if (btgtMD5) Console.WriteLine(" target.MD5 = {0}", toHash(tgtMD5.data));
- if (btgtSHA1) Console.WriteLine(" target.SHA1 = {0}", toHash(tgtSHA1.data));
- if (btgtSHA256) Console.WriteLine(" target.SHA256 = {0}", toHash(tgtSHA256.data));
- if (!bsrcName && !btgtName) Console.WriteLine(" partially downloaded / corrupted ");
- Console.WriteLine(new string('-', 100));
- Console.WriteLine();
- }
- }
- '@; Add-Type -TypeDefinition $SmartVersionDLL; [SvfDll]::Info($svf); # :ps_svf:
- :-_-:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement