Page 2 of 2

Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch

Posted: 03 Oct 2016 12:20
by Squashman
ShadowThief wrote:Weird.
Image

I believe I talked to Foxidrive about this already. Windows 8 and above no longer require admin privileges.

Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch

Posted: 03 Oct 2016 12:39
by aGerman
Squashman wrote:Windows 8 and above no longer require admin privileges.

That's correct. We recently discussed it there:
viewtopic.php?t=7347&p=49172#p49172

Steffen

Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch

Posted: 03 Oct 2016 13:33
by Aacini
Ok. I modified the method to create the binary file. Please, download BinToBat223.bat file again and test it... :oops:

Antonio

Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch

Posted: 04 Oct 2016 06:28
by JeffryDenn
It really seems like everybody tries a script like this at some point prior to finding this forum. I'd post mine but it doesn't really offer anything new other than support for multiple files and directories.

I found that typically I got better performance by packing executables with UPX before encoding with certutil rather than compressing as a cab.
I'm also fond of compacting the certutil output to fewer lines. Why leave each line to 64 characters wide when encoding 8kb per line works just fine:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

if %~z1 GEQ 74472448 (echo Input file too large ^> 72MB & pause & exit /b)

:ARGLOOP
set outfile="%~dp1\%~n1_Packed.bat"

if %1.==. goto :EOF
call :PACK %1
shift /1
goto :ARGLOOP

:PACK
echo Packing %~nx1
echo.
certutil -encode "%~1" b64
echo Writing datablock to %outfile%...
(   echo @echo off
    echo :: %~nx1
    set/p=(echo.<NUL
    for /F "tokens=* delims=" %%A in ('findstr /v " CERTIFICATE-----$" b64') do (
        if !count! GEQ 127 set count=0 & echo.& set/p=echo.<NUL
        set /a count+=1
        set/p=%%A<NUL
    )
    echo.
    echo ^)^>tmp_
    echo certutil -decode -f tmp_ "%~nx1"
    echo del /q/f tmp_
)>>%outfile%
del /q/f b64
echo.
GOTO :EOF


This is pretty slow for files over a few MB though, so if you have a unix-like paste binary you can use the following to turn certutil output into as few lines as possible

Code: Select all

certutil -encode input.exe b64
set -=-
for /l %%i in (1,1,7) do set -=!-! !-!
findstr /v " CERTIFICATE-----$" b64 | %tmp%\paste !-!d\0 > b64.txt

Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch

Posted: 04 Oct 2016 06:40
by Squashman
JeffryDenn wrote:It really seems like everybody tries a script like this at some point prior to finding this forum. I'd post mine but it doesn't really offer anything new other than support for multiple files and directories.

I found that typically I got better performance by packing executables with UPX before encoding with certutil rather than compressing as a cab.
I'm also fond of compacting the certutil output to fewer lines. Why leave each line to 64 characters wide when encoding 8kb per line works just fine:

Welcome to DosTips! Thanks for sharing your code!

Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch

Posted: 04 Oct 2016 08:41
by siberia-man
numcheck.bat: do it easier

Code: Select all

if "%~1" == "" (
   echo:EMPTY VALUE
) else (
   set /a "val=%~1" 2>nul
   if "%val%" == "%~1" (
      echo:NUMBER: [%~1]
   ) else (
      echo:NOT A NUMBER: [%~1]
   )
)

Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch

Posted: 04 Oct 2016 09:02
by Squashman
siberia-man wrote:numcheck.bat: do it easier

Code: Select all

if "%~1" == "" (
   echo:EMPTY VALUE
) else (
   set /a "val=%~1" 2>nul
   if "%val%" == "%~1" (
      echo:NUMBER: [%~1]
   ) else (
      echo:NOT A NUMBER: [%~1]
   )
)

Did you mean to post this in a different thread? Not sure what this has to do with this thread topic.

Also, you most certainly will need delayed expansion for your code to work.

Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch

Posted: 04 Oct 2016 09:03
by JeffryDenn
It's in reference to other code in the github linked in the first post.

(that solution also limits input to natural numbers no more than the 32bit integer ceiling (2147483647) and fails for numbers prefixed by 0)

Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch

Posted: 04 Oct 2016 09:19
by Squashman
JeffryDenn wrote:It's in reference to other code in the github linked in the first post.

Ok. This thread is going to get confusing if we start talking about other part of the users framework. The title of the thread is for To.Bat.

JeffryDenn wrote:(that solution also limits input to natural numbers no more than the 32bit integer ceiling (2147483647) and fails for numbers prefixed by 0)

Correct in regards to Siberia-man's code.

Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch

Posted: 04 Oct 2016 14:08
by siberia-man
Sorry, if I posted the message in wrong thread. I have thought this is discussion about the BatFramework.

And, yes. Confirm that my example has a bug as it was mentioned early. The better way is to escape extra parentheses.

Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch

Posted: 04 Oct 2016 18:37
by Squashman
siberia-man wrote:Sorry, if I posted the message in wrong thread. I have thought this is discussion about the BatFramework.

Not a problem.

siberia-man wrote:And, yes. Confirm that my example has a bug as it was mentioned early. The better way is to escape extra parentheses.

Not sure what you mean by this. The main problem with your code is not using delayed expansion. Jeff also pointed out the problem as well.

Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch

Posted: 06 Oct 2016 15:03
by foxidrive
I can't help but smile when guys are talking about a 64KB batch file (and trying to shave a few Kbytes off it) ... which transfers by email in the blink-of-an-eye these days.

I remember downloading programs on a BBS and using on a 14400 dialup modem. And that was blindingly fast compared to a 300 Baud acoustic coupler. :D

It was easy to have a cup of coffee and a meal by the time your program downloaded.

Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch

Posted: 06 Oct 2016 19:21
by Squashman
foxidrive wrote:I can't help but smile when guys are talking about a 64KB batch file (and trying to shave a few Kbytes off it) ... which transfers by email in the blink-of-an-eye these days.

I remember downloading programs on a BBS and using on a 14400 dialup modem. And that was blindingly fast compared to a 300 Baud acoustic coupler. :D

It was easy to have a cup of coffee and a meal by the time your program downloaded.

And we were all happier then pigs in shit when 28K modems came out.

Re: tobat.bat (Part of the BatFramework) - Drag and drop a file and turn it into batch

Posted: 07 Oct 2016 05:54
by foxidrive
Squashman wrote:And we were all happier then pigs in shit when 28K modems came out.


Oink!