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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

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

#16 Post by Squashman » 03 Oct 2016 12:20

ShadowThief wrote:Weird.
Image

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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

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

#17 Post by aGerman » 03 Oct 2016 12:39

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

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

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

#18 Post by Aacini » 03 Oct 2016 13:33

Ok. I modified the method to create the binary file. Please, download BinToBat223.bat file again and test it... :oops:

Antonio

JeffryDenn
Posts: 2
Joined: 03 Oct 2016 06:14

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

#19 Post by JeffryDenn » 04 Oct 2016 06:28

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

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

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

#20 Post by Squashman » 04 Oct 2016 06:40

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!

siberia-man
Posts: 208
Joined: 26 Dec 2013 09:28
Contact:

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

#21 Post by siberia-man » 04 Oct 2016 08:41

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]
   )
)

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

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

#22 Post by Squashman » 04 Oct 2016 09:02

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.

JeffryDenn
Posts: 2
Joined: 03 Oct 2016 06:14

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

#23 Post by JeffryDenn » 04 Oct 2016 09:03

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)

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

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

#24 Post by Squashman » 04 Oct 2016 09:19

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.

siberia-man
Posts: 208
Joined: 26 Dec 2013 09:28
Contact:

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

#25 Post by siberia-man » 04 Oct 2016 14:08

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.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

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

#26 Post by Squashman » 04 Oct 2016 18:37

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#27 Post by foxidrive » 06 Oct 2016 15:03

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.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

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

#28 Post by Squashman » 06 Oct 2016 19:21

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#29 Post by foxidrive » 07 Oct 2016 05:54

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


Oink!

Post Reply