Topic
  • 11 replies
  • Latest Post - ‏2014-10-28T20:20:16Z by MattPeterson
MattPeterson
MattPeterson
17 Posts

Pinned topic Copy sha1 right click tool

‏2014-06-04T20:45:46Z |

I'm looking for a way to customize the copy sha1 right click tool to change the default http location. I searched the registry for EXAMPLEURL, but didn't find anything.

This is the default output which is copied to the clipboard from the utility:


prefetch file.txt sha1:976f6ecc6c9d791d74bfac09d7a1fee9c14bdef0 size:3924361 http://EXAMPLEURL/REPLACEME.exe
 

 .

  • MattPeterson
    MattPeterson
    17 Posts

    Re: Copy sha1 right click tool

    ‏2014-06-06T15:18:13Z  

    bump...

  • TGTheierl
    TGTheierl
    1 Post

    Re: Copy sha1 right click tool

    ‏2014-09-08T20:41:02Z  

    bump...

    The http://EXAMPLEURL/REPLACEME.exe should be replaced by the URL and location where the sha1.exe is located on the IEM webserver, under the BES Server\wwwrootbes folder.

     

  • MattPeterson
    MattPeterson
    17 Posts

    Re: Copy sha1 right click tool

    ‏2014-09-08T20:48:44Z  
    • TGTheierl
    • ‏2014-09-08T20:41:02Z

    The http://EXAMPLEURL/REPLACEME.exe should be replaced by the URL and location where the sha1.exe is located on the IEM webserver, under the BES Server\wwwrootbes folder.

     

    I get that. I'm asking if there is a way to change the way the .exe works so instead of http://EXAMPLEURL/REPLACEME.exe, it outputs a custom URL...

  • TyTheierl
    TyTheierl
    2 Posts

    Re: Copy sha1 right click tool

    ‏2014-09-08T21:04:28Z  

    I get that. I'm asking if there is a way to change the way the .exe works so instead of http://EXAMPLEURL/REPLACEME.exe, it outputs a custom URL...

    The "prefetch file.txt sha1:976f6ecc6c9d791d74bfac09d7a1fee9c14bdef0 size:3924361 http://EXAMPLEURL/REPLACEME.exe" is part of action relevance. The prefetch command simply downloads file.txt from the specified URL provided the size and SHA1 values match.

    Not sure what you mean by "outputs a custom URL". Nothing is outputed other than the "file.txt".

     

  • MattPeterson
    MattPeterson
    17 Posts

    Re: Copy sha1 right click tool

    ‏2014-09-09T13:46:50Z  
    • TyTheierl
    • ‏2014-09-08T21:04:28Z

    The "prefetch file.txt sha1:976f6ecc6c9d791d74bfac09d7a1fee9c14bdef0 size:3924361 http://EXAMPLEURL/REPLACEME.exe" is part of action relevance. The prefetch command simply downloads file.txt from the specified URL provided the size and SHA1 values match.

    Not sure what you mean by "outputs a custom URL". Nothing is outputed other than the "file.txt".

     

    I understand how the prefetch command works in an action.

    I'm looking for a way to modify the right click tool (sha1.exe), so when I right click on a file and choose "copy sha1", instead this being added to my clipboard:

    prefetch file.txt sha1:976f6ecc6c9d791d74bfac09d7a1fee9c14bdef0 size:3924361 http://EXAMPLEURL/REPLACEME.exe

    I get the URL of the BES Server, and file name i.e.

    prefetch file.txt sha1:976f6ecc6c9d791d74bfac09d7a1fee9c14bdef0 size:3924361 http://besserver.domain.com:52311/Uploads/976f6ecc6c9d791d74bfac09d7a1fee9c14bdef0/filename.exe

  • TyTheierl
    TyTheierl
    2 Posts

    Re: Copy sha1 right click tool

    ‏2014-09-09T16:18:36Z  

    I understand how the prefetch command works in an action.

    I'm looking for a way to modify the right click tool (sha1.exe), so when I right click on a file and choose "copy sha1", instead this being added to my clipboard:

    prefetch file.txt sha1:976f6ecc6c9d791d74bfac09d7a1fee9c14bdef0 size:3924361 http://EXAMPLEURL/REPLACEME.exe

    I get the URL of the BES Server, and file name i.e.

    prefetch file.txt sha1:976f6ecc6c9d791d74bfac09d7a1fee9c14bdef0 size:3924361 http://besserver.domain.com:52311/Uploads/976f6ecc6c9d791d74bfac09d7a1fee9c14bdef0/filename.exe

    Ah, I understand now.

    You will need to modify the HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\Copy Sha1\Command reg key. 

    "C:\Program Files (x86)\BigFix Enterprise\BES Console\RunQuiet.exe" Sha1.exe -r "%1" -c

    It looks like the "%1" value is what generates the URL but I cannot find where it is stored.

  • MattPeterson
    MattPeterson
    17 Posts

    Re: Copy sha1 right click tool

    ‏2014-09-09T16:28:02Z  
    • TyTheierl
    • ‏2014-09-09T16:18:36Z

    Ah, I understand now.

    You will need to modify the HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\Copy Sha1\Command reg key. 

    "C:\Program Files (x86)\BigFix Enterprise\BES Console\RunQuiet.exe" Sha1.exe -r "%1" -c

    It looks like the "%1" value is what generates the URL but I cannot find where it is stored.

    The %1 is for the file path (the file you right click on). If I run that command manually and enter a file path, it copies the sha info from that file.

    It looks like it must be hard coded in the .exe.

  • JasonWalker
    JasonWalker
    7 Posts

    Re: Copy sha1 right click tool

    ‏2014-10-25T03:29:23Z  

    I thought of something you could try if you don't mind getting dirty.

    The BES Root Server handles all of your downloads.  You could precache all of your files so that the downloads don't actually have to occur.  For example I use the sha1.exe command line tool in a batch file to rename the files I need to match their sha1 values, and copy the files to the BES server at \bfmirror\downloads\sha1.  You also need to increase the download cache size on the BES server to a large enough value to make sure that the sha1 folder is never purged.

    Then, when your action runs, the BES server uses the existing file copies from the sha1 folder, and never has to actually attempt the download.  I don't know what the odds are of a sha1 filename collision though.

  • MattPeterson
    MattPeterson
    17 Posts

    Re: Copy sha1 right click tool

    ‏2014-10-27T14:19:06Z  

    I thought of something you could try if you don't mind getting dirty.

    The BES Root Server handles all of your downloads.  You could precache all of your files so that the downloads don't actually have to occur.  For example I use the sha1.exe command line tool in a batch file to rename the files I need to match their sha1 values, and copy the files to the BES server at \bfmirror\downloads\sha1.  You also need to increase the download cache size on the BES server to a large enough value to make sure that the sha1 folder is never purged.

    Then, when your action runs, the BES server uses the existing file copies from the sha1 folder, and never has to actually attempt the download.  I don't know what the odds are of a sha1 filename collision though.

    I like the idea, would you be willing to share your batch script?

  • JasonWalker
    JasonWalker
    7 Posts

    Re: Copy sha1 right click tool

    ‏2014-10-27T14:54:56Z  

    I like the idea, would you be willing to share your batch script?

    Sure.  Assume you have sha1.exe and this rename_sha1.cmd in the PATH.

    Content of rename_sha1.cmd:

    @set /P SURE=Are you sure you want to rename %* based on its sha1 value?
    @if /I NOT %SURE%==Y @echo Ok then & exit /B 0
    for %%i in (%*) do for /F %%j in ('sha1 -s "%%i"') do rename "%%i" "%%j"
    

    To call it, open a command prompt and enter the directory containing your files.  Execute "rename_sha1 <filespec>", where filespec is a filename or filename pattern that DIR recognizes, like "filename.exe", "file*.exe", or "*.*".  This renames the specified files to match their sha1 hash.  I'm not doing this part yet, but I believe you could amend it to the following one-liner:

    @REM Since we aren't renaming/deleting files, less need for safety so we can remove this check
    @REM @set /P SURE=Are you sure you want to rename %* based on its sha1 value?
    @REM @if /I NOT %SURE%==Y @echo Ok then & exit /B 0
    
    @REM wwwrootbes$ is a hidden windows share to the BES Server's wwwrootbes directory,
    @REM  usually c:\Program Files (x86)\BigFix Enterprise\BigFix Server\wwwrootbes
    
    for %%i in (%*) do for /F %%j in ('sha1 -s "%%i"') do xcopy /D "%%i" 
    "\\MYBESSERVER\wwwrootbes$\bfmirror\downloads\sha1\%%j"
    

    To prevent the cached files from being removed from the BES Server, we can set the following BigFix setting:

    _BESGather_Download_CacheLimitMB="409600"
    

    This sets the cache size limit to 4 TB.

  • MattPeterson
    MattPeterson
    17 Posts

    Re: Copy sha1 right click tool

    ‏2014-10-28T20:20:16Z  

    Sure.  Assume you have sha1.exe and this rename_sha1.cmd in the PATH.

    Content of rename_sha1.cmd:

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">@set /P SURE=Are you sure you want to rename %* based on its sha1 value? @if /I NOT %SURE%==Y @echo Ok then & exit /B 0 for %%i in (%*) do for /F %%j in ('sha1 -s "%%i"') do rename "%%i" "%%j" </pre>

    To call it, open a command prompt and enter the directory containing your files.  Execute "rename_sha1 <filespec>", where filespec is a filename or filename pattern that DIR recognizes, like "filename.exe", "file*.exe", or "*.*".  This renames the specified files to match their sha1 hash.  I'm not doing this part yet, but I believe you could amend it to the following one-liner:

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">@REM Since we aren't renaming/deleting files, less need for safety so we can remove this check @REM @set /P SURE=Are you sure you want to rename %* based on its sha1 value? @REM @if /I NOT %SURE%==Y @echo Ok then & exit /B 0 @REM wwwrootbes$ is a hidden windows share to the BES Server's wwwrootbes directory, @REM usually c:\Program Files (x86)\BigFix Enterprise\BigFix Server\wwwrootbes for %%i in (%*) do for /F %%j in ('sha1 -s "%%i"') do xcopy /D "%%i" "\\MYBESSERVER\wwwrootbes$\bfmirror\downloads\sha1\%%j" </pre>

    To prevent the cached files from being removed from the BES Server, we can set the following BigFix setting:

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">_BESGather_Download_CacheLimitMB="409600" </pre>

    This sets the cache size limit to 4 TB.

    Thanks for your help, I ended up using some of your logic to do something a little different. I created a script that can be called by right clicking on any file. The script does the following.

    create a directory named by the sha1 of the selected file in the same directory as the file.
    move the selected file into that directory
    Copy the prefetch statement, but change URL to match our needs

    This is the .cmd file which I saved to my Bigfix console directory named prefetch.cmd. This also relies on the sha1.exe tool to reside in that directory

    @echo off
    rem get filename from path
    for /r %%f in (%1) do set filename=%%~nxf

    rem get the sha1 of the file
    for /f %%i in ('"C:\Program Files (x86)\BigFix Enterprise\BES Console\sha1.exe" -s %filename%') do set sha1=%%i

    rem get the prefetch statement from the file and copy to clipboard
    for /f "tokens=1-4" %%a in ('"C:\Program Files (x86)\BigFix Enterprise\BES Console\sha1.exe" -r %filename%') do echo %%a %%b %%c %%d http://servername:52311/Uploads/%sha1%/%filename% | clip

    rem create a directory that matches the sha1 of the file and move the file to it
    mkdir %sha1%
    move %1 %sha1%\%filename%

    I could add a line to copy that folder to the Uploads folder on the BESServer if I wanted, but I'm going to leave that out for now (we're hosted on Linux so I'd have to scp).

    To enable this as a right click option in Windows explorer you can copy the text below into a file with a .reg extention and import.

    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\Move-Copy Sha1]

    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\Move-Copy Sha1\Command]
    @="\"C:\\Program Files (x86)\\BigFix Enterprise\\BES Console\\Prefetch.cmd\" %1"