TuMaGoNx Posted August 19, 2017 Posted August 19, 2017 (edited) Introducing portabat https://github.com/tumagonx/portabat This is custom 7zsfx (7zip SDK 17.00) that make your batch more realistically like an executable. Try demo here https://github.com/tumagonx/portabat/releases Editing: All you need is open portabat.exe with 7zip and edit hello.bat or add your own batch, no need to copy /b or create config.txt. See filename execution order from homepage Requirement: XP or later Current version: 0.2-beta portabat is a small 7z-sfx at just 220KB (160KB if standalone cmd.exe and reg.exe removed), it is about the same size of busybox-w32 compressed. Portabat packed with almost a hundred executables. Content (all listed here is open source software): cmd.exe (161KB) : compatible standalone CMD from ReactOS reg.exe (17KB) : standalone registry query/editor from ReactOS bundled helpers: un7z.exe (21KB) : 7zip-17.0 extractor (constructed from SFX) unzip (5KB) : zip extractor fwpipes (4KB) : named pipes data transfer of two program ppx2 (9KB) : win32 port of xargs for multi processing setprio 8KB) : process affinity getppid (2KB) : get parent pid genuuid (2KB) : generate uuid msxsl (20KB) : xslt processor showwin (4KB) and enumwim (4KB) : window handle control and query rawcopy (12KB) : create image/iso from drive isadmin (2KB) : check admin privilege isdrive (2KB) : check drive type ispe (3KB): check executable type pehdr (6KB) : basic PE header editor iconv (16KB) : text codepage conversion gdipconv (5KB) : png/bmp/jpg/tiff/gif conversion pclip (2KB) (and clip) : paste/copy clipboard content timer (4KB) and timeout (2KB) beep (2KB) gplay (5KB) : play dshow audio files dwnl (7KB) : download from http, https, ftp devioctl (9KB) : control low level device operation eltorito (5KB) : retrieve iso boot image isoimage.exe (6KB) : create cd/dvd/bd iso image and bootable iso getwu (7KB) : query windows update cabit (8KB) : create cabinet archive, support spanned volume junc (5KB) and hardlink (2KB) : create symlink ( as hardlink file or junction directory) makelnk (6KB) : create shortcut gsar (19KB) : search and replace file content support binary (NOT unicode path aware) msgbox (2KB) : create message dialog wincrypt (5KB) : AES decrpyt/encrypt xor (5KB) : XOR a file winhash (6KB) : MD/SHA/CRC digest partfile (7KB) : file part copy/peek, splitter chsize (3KB) : create new file (sparse) at arbitrary size resetcur (2KB) : restore console cursor touch (2KB) : file timestamp uptime (2KB) : system uptime bundled helpers from multi-call busybox 1.28 (161KB) lite version, these are NOT unicode aware : awk : tool for text processing, data extraction and reporting sed : stream text editor grep/egrep/fgrep: regex search on text dc : reverse polish calculator base64 cat and tac : print / reverse print file(s) cmp : summarize between two files comm and uniq : unique/common filter cut and paste pdate (renamed date) : represent date in various ways diff and patch : compare two text, no better than FC IMO but it has defacto formatting used by patch dos2unix and unix2dos : crlf <-> lf du : directory size expand and unexpand : tab <-> space expr : condition expression, like batch ~expansion, if or set /a stuff factor : prime factor head and tail : print lines of BOF/EOF hd/hexdump/xxd : print binary files ipcalc nl and seq : line number sequence adder/printer rev : byte reverse file shuf : shuffle lines of text psort (renamed sort) : sort filter based various criteria split : split files/lines of text, use partfile above instead for files (faster) tee : stdin stdout redirector uuencode and uudecode wc : counter for text Planned: add/make msi query tool (anyone know such? not wix, not gnome msitool) add clink/readline support direcly to cmd.exe (no hooking) Note: Portabat itself is multi-call binary, it will prioritize execute batch or executables which has the same as basename of the sfx If "cwd" file/folder (no extension) present inside sfx current directory set to extraction directory. ReactOS cmd is about 95% compatible, if you're batch nerd you can see few different quirks behavior compared to windows cmd separate 7z.sfx available at https://github.com/tumagonx/portabat/raw/master/basebin/7z.sfx (about 20KB if packed) Suggestions are welcome! Edited September 23, 2017 by TuMaGoNx
jaclaz Posted August 19, 2017 Posted August 19, 2017 (edited) Interesting. You could really spend a few words (on the site) explaining how it works (not really how it works, but how one can create a self extracting archive with that). Is the roscmd "needed" or it is only in the case one want to workaround command execution policies? Or if you prefer, which of the zillion files in the example are actually *needed*? Maybe - besides the example - you could provide an "empty", "bare minimum" template? Any way to ONLY open a command prompt? Or, if you prefer, to drop to command line once the batch has been executed OR interrupted and then need to type EXIT to close the command window? I mean without directly invoking %~dp0\roscmd.exe? (like an internal .ini file with a setting *like* DropToDos=1) Also there is an issue. In the roscmd.exe window the ALT+code seemingly does not work , which plainly means that on an Italian keyboard (but I suspect on many other ones) I cannot input the tilde ~ on command line (that is ALT+0126), Yes, I know I can run %comspec% /? and that I can do SET Mydir=%comspec:\roscmd.exe=% and cd /d %mydir%, but it is a big limitation, as I see it. By the same token of the "DropToDos", it would be nice to have in the (hypothetical) .ini settings file the option to choose whether to run in the directory where the .exe is (i.e. %SFXPATH%) or in the directory where the sfx is temporarily extracted (i.e. %~dp0), In any case pushd %mydir% and popd work just fine . jaclaz Edited August 19, 2017 by jaclaz
TuMaGoNx Posted August 22, 2017 Author Posted August 22, 2017 Is the roscmd "needed" or it is only in the case one want to workaround command execution policies? +1 Right, I should check the policy registry before launching batch and use system cmd if ok roscmd is base requirement ATM, my plan is to merge some external helpers program into internal ReactOS command, but it's bad idea as it promote non-standard practice. Or if you prefer, which of the zillion files in the example are actually *needed*? No idea, I think batch is good for file processing so those related to that Any way to ONLY open a command prompt? That not what batch file behave no? it also behave like usual 7zsfx, aka simply having only roscmd.exe inside the SFX will simply launch it (command prompt) (rename roscmd.exe to setup.exe to get priority if other exes presents) Or, if you prefer, to drop to command line once the batch has been executed OR interrupted and then need to type EXIT to close the command window? I try to make it behave like regular batch, quit after done, it's batch author consideration to add pause/%COMSPEC% By the same token of the "DropToDos", it would be nice to have in the (hypothetical) .ini settings file the option to choose whether to run in the directory where the .exe is (i.e. %SFXPATH%) or in the directory where the sfx is temporarily extracted (i.e. %~dp0), Same above, I try to be consistent with default batch behavior it would be CWD=SFXPATH or CWD=CWD of the caller (aka called from existing cmd box), thus up to author to switch into %~dp0 You could really spend a few words (on the site) explaining how it works (not really how it works, but how one can create a self extracting archive with that). I will create smaller template, I try avoid explaining "you need to: copy /b 7z.sfx+archive.7z mybatch.exe" :D my hope is people use 7zip file manager to edit the batch or drag and drop their batch into it. Thanks for the inputs, it's a shame about the keyboard issue, I guess you spot new incompatibility in roscmd judging the way you asks it seems you concern more how to work in roscmd box instead of run batch file? do you have different use cases?
jaclaz Posted August 22, 2017 Posted August 22, 2017 The point is just that to write a batch file you (actually I) normally test the command in the exact same environment where the batch will be run, not really an issue (for me) but a potential user will (in this order): 1) add his/her batch file AND remove the roscmd.exe from the archive (FAIL) 2) add his/her batch file AND NOT remove the roscmd.exe BUT have no PAUSE in the batch (FAIL) 3) add his/her batch file AND NOT remove the roscmd.exe AND have PAUSE in the batch BUT the batch only works in CMD.EXE (FAIL) Personally I hate programs that "decide" what is better for me, where a simple file with a few settings would allow me to decide myself what is better on a case by case basis. Actually when/if the little ROSCMD.EXE incompatibilities will be "leveled out" it is actually "better" (IMHO) to use that command processor (and also "guaranteed" executables inside the 7-zip sfx), so that the batch (tested on that command processor and with that exact version of the other .exe's) surely works, avoiding possible incompatibilities between different CMD.EXE's on different OS's, including a few related to localization. A teeny-tiny issue with Roscmd.exe is the different behaviour of PUSHD. On Windows CMD.EXE once you have PUSHD a directory, running PUSHD without arguments will show the pushed directory, on ROSCMD, it doesn't, this may "break" some particular batches, this is a workaround for tilde assigning the variable %sfxextpath% so that it can be typed and the variable tilde: myhello.cmd: @echo off title %SFXPATH%%SFX% SET SFXEXTPATH=%~dp0 SET SFX SET TILDE=~ SET TILDE %~dp0\roscmd.exe then (output and commands): SFX=mytest.exe SFXEXTPATH=C:\DOCUME~1\jaclaz\IMPOST~1\temp\7z14024E48\ SFXPATH=C:\batches\Portabat\ ReactOS Operating System [Version 0.4.5 20170801-rUNKNOWN] (C) Copyright 1998-2017 ReactOS Team. C:\batches\Portabat>pushd %sfxextpath% C:\Documents and Settings\jaclaz\Impostazioni locali\temp\7z14024E48>pushd C:\Documents and Settings\jaclaz\Impostazioni locali\temp\7z14024E48>popd C:\Documents and Settings\jaclaz\Impostazioni locali\temp\7z14024E48>popd C:\batches\Portabat>cmd.exe Microsoft Windows XP [Versione 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\batches\Portabat>set sfx SFX=mytest.exe SFXEXTPATH=C:\DOCUME~1\jaclaz\IMPOST~1\temp\7z14024E48\ SFXPATH=C:\batches\Portabat\ C:\batches\Portabat>pushd %sfxextpath% C:\DOCUME~1\jaclaz\IMPOST~1\temp\7z14024E48>pushd C:\batches\Portabat C:\DOCUME~1\jaclaz\IMPOST~1\temp\7z14024E48>popd C:\batches\Portabat> Another side-side note (very minor) is that traditionally .bat should be compatible with DOS/9x, while .cmd is the extension for batches to be executed by CMD.EXE (or ROSCMD.EXE). jaclaz
TuMaGoNx Posted August 23, 2017 Author Posted August 23, 2017 Actually when/if the little ROSCMD.EXE incompatibilities will be "leveled out" it is actually "better" (IMHO) to use that command processor (and also "guaranteed" executables inside the 7-zip sfx), so that the batch (tested on that command processor and with that exact version of the other .exe's) surely works, avoiding possible incompatibilities between different CMD.EXE's on different OS's, including a few related to localization. Originally that's what I thought, but also realized the "no guarantee to run" issue is dilemma. Yet you found even more incompatibility :) (though ReactOS also under development) I think exe less than 50KB will be bundled by default (like now) but will be put in its own folder Another side-side note (very minor) is that traditionally .bat should be compatible with DOS/9x, while .cmd is the extension for batches to be executed by CMD.EXE (or ROSCMD.EXE). Oops my bad habit, but this is also dilemma for those born with XP or later experience (like me)
jaclaz Posted August 23, 2017 Posted August 23, 2017 Yes, it was only to show a possible issue in "inserting a batch tested on cmd,exe", if you (IMHO wrongly) implement the "autodetect policies" there would be no certainties about which command processor is used, and thus a same batch file may work fine in a machine and not work on another one because two different command processors are run depending on the autodetection. As said, no matter which small quirks this or that command processor .exe, they don't really matter, as long as the batch has been tested on that specific command processor. In this the "embedded" command processor is a very good idea. Putting it in a subdirectory of the 7-zip is (still IMHO) not only unneeded, but also an unneeded complication, however. What would be useful would be to be able to change the command processor, so that we are not limited to ROSCMD.EXE, as an example one might want to use 4NT/TCCLE: https://jpsoft.com/tccle-cmd-replacement.html http://www.portablefreeware.com/forums/viewtopic.php?t=3392 or Greg's Shell: https://www.gammadyne.com/cmdline.htm#gs or whatever other alternative command line processor, including (of course not for redistribution) a copy of a Windows CMD.EXE. Again, a simple .INI file with a number of simple choices possible would add greater flexibility without making anyway the thing too complex. Here is another quirk, this one serious, it seems like ROSCMD does not exits loops : @ECHO OFF SETLOCAL ENABLEDELAYEDEXPANSION SETLOCAL ENABLEEXTENSIONS FOR /L %%A IN (0,1,5) DO ( SET Number=%%A IF %%A==2 GOTO :out_of_loop IF %%A==2 ECHO %%A IS equal to 2 ECHO %%A IS NOT equal to 2 ) GOTO :EOF ECHO. ECHO You won't see this :out_of_loop ECHO Here is out of loop, number is %number% C:\>looptest.cmd 0 IS NOT equal to 2 1 IS NOT equal to 2 Here is out of loop, number is 2 C:\>roscmd ReactOS Operating System [Version 0.4.5 20170801-rUNKNOWN] (C) Copyright 1998-2017 ReactOS Team. C:\>looptest.cmd 0 IS NOT equal to 2 1 IS NOT equal to 2 2 IS equal to 2 2 IS NOT equal to 2 3 IS NOT equal to 2 4 IS NOT equal to 2 5 IS NOT equal to 2 Here is out of loop, number is 5 C:\>exit jaclaz
roytam1 Posted August 23, 2017 Posted August 23, 2017 (edited) 1 hour ago, jaclaz said: Yes, it was only to show a possible issue in "inserting a batch tested on cmd,exe", if you (IMHO wrongly) implement the "autodetect policies" there would be no certainties about which command processor is used, and thus a same batch file may work fine in a machine and not work on another one because two different command processors are run depending on the autodetection. As said, no matter which small quirks this or that command processor .exe, they don't really matter, as long as the batch has been tested on that specific command processor. In this the "embedded" command processor is a very good idea. Putting it in a subdirectory of the 7-zip is (still IMHO) not only unneeded, but also an unneeded complication, however. What would be useful would be to be able to change the command processor, so that we are not limited to ROSCMD.EXE, as an example one might want to use 4NT/TCCLE: https://jpsoft.com/tccle-cmd-replacement.html http://www.portablefreeware.com/forums/viewtopic.php?t=3392 or Greg's Shell: https://www.gammadyne.com/cmdline.htm#gs or whatever other alternative command line processor, including (of course not for redistribution) a copy of a Windows CMD.EXE. Again, a simple .INI file with a number of simple choices possible would add greater flexibility without making anyway the thing too complex. Here is another quirk, this one serious, it seems like ROSCMD does not exits loops : @ECHO OFF SETLOCAL ENABLEDELAYEDEXPANSION SETLOCAL ENABLEEXTENSIONS FOR /L %%A IN (0,1,5) DO ( SET Number=%%A IF %%A==2 GOTO :out_of_loop IF %%A==2 ECHO %%A IS equal to 2 ECHO %%A IS NOT equal to 2 ) GOTO :EOF ECHO. ECHO You won't see this :out_of_loop ECHO Here is out of loop, number is %number% C:\>looptest.cmd 0 IS NOT equal to 2 1 IS NOT equal to 2 Here is out of loop, number is 2 C:\>roscmd ReactOS Operating System [Version 0.4.5 20170801-rUNKNOWN] (C) Copyright 1998-2017 ReactOS Team. C:\>looptest.cmd 0 IS NOT equal to 2 1 IS NOT equal to 2 2 IS equal to 2 2 IS NOT equal to 2 3 IS NOT equal to 2 4 IS NOT equal to 2 5 IS NOT equal to 2 Here is out of loop, number is 5 C:\>exit jaclaz I'd just opened a ros jira ticket: https://jira.reactos.org/browse/CORE-13713 Edited August 23, 2017 by roytam1
TuMaGoNx Posted August 24, 2017 Author Posted August 24, 2017 Holy sh*t thats serious one! frankly during my test I only knew that START has different behavior as it only wait child process depends on whether it is console/window executable "Putting it in a subdirectory of the 7-zip is (still IMHO) not only unneeded, but also an unneeded complication, however." because it quickly become cramped... root will be only for batches and user data, the exe subdir automatically *pre-pended* in %PATH% before %COMSPEC% run (so no complication, you still called them just by name) yes I'm aware of tcc and greg but, I don't naturally mess with non-OSS :D I will think about the ini file
TuMaGoNx Posted September 7, 2017 Author Posted September 7, 2017 Added windows update lister Before this I use OnePiece Get_Microsoft_Update_List.exe but it doesn't show url which I want to feed the output to curl/wget in automated batch downloading getwu will fetch download link per line getwu -v will show additional info of each update download https://github.com/tumagonx/portabat/raw/master/minbin/getwu.exe (6.5KB)
TuMaGoNx Posted September 9, 2017 Author Posted September 9, 2017 Add more info in getwu example: getwu -v Searching for updates ... List of applicable items on the machine: 1. Windows Media Player 11 (for Windows XP Professional x64 Edition) Size=27936568 Date=Tue Apr 22 00:00:00 2008 Priority=2 Delta=0 Beta=0 Action=1 ID=40394e2a-1935-4233-8171-b4c5b85e67ec Download URL(s): http://www.download.windowsupdate.com/msdownload/update/v3-19990518/cabpool/wmp11-windowsxp-x64-enu_35583b427a7488e386998c6dd2c3b71d68c3c1ae.exe 2. Windows Search 4.0 for Windows XP x64 Edition (KB940157) Size=8840208 Date=Tue Jul 22 00:00:00 2008 Priority=2 Delta=0 Beta=0 Action=1 ID=46e24996-7f60-46a4-b14c-8e7340375068 Download URL(s): http://www.download.windowsupdate.com/msdownload/update/software/ftpk/2008/06/windowssearch-kb940157-srv2k3_xp-x64-enu_774aa531cfd4d7f7baf3d2b8011f4da551975bf4.exe 3. Update for Windows XP x64 Edition (KB961118) Size=872312 Date=Tue Feb 24 00:00:00 2009 Priority=2 Delta=0 Beta=0 Action=1 ID=72ae05ee-6290-4e4c-a8f9-ecfa416b067c Download URL(s): http://download.windowsupdate.com/msdownload/update/software/crup/2009/02/windowsserver2003.windowsxp-kb961118-x64-enu_dcb0eef40327825d619ed19338a9a68fe69bb6fe.exe 4. Microsoft .NET Framework 3.5 SP1 and .NET Framework 2.0 SP2 Update for Windows Server 2003 and Windows XP for x64-based Systems (KB982524) Size=31680584 Date=Tue Jul 27 00:00:00 2010 Priority=1 Delta=0 Beta=0 Action=1 ID=fd730688-8e7a-41ce-93f2-3450c5b3832f Download URL(s): http://download.windowsupdate.com/msdownload/update/software/secu/2010/05/msipatchregfix-x64_dd729362b73e94700b3eeec77fd581bd767b47e1.exe http://download.windowsupdate.com/msdownload/update/software/updt/2010/02/ndp20sp2-kb976576-x64_29d95e9cee9cf2e838a3e1fe8d6216cc2799550b.exe http://download.windowsupdate.com/msdownload/update/software/crup/2010/06/ndp30sp2-kb977354-v2-x64_f19f9ebce70fc004c33be93e5c595925f4f05899.exe 5. Microsoft .NET Framework 4 Client Profile for Windows XP x64-based Systems (KB982670) Size=45071024 Date=Tue Sep 13 00:00:00 2011 Priority=1 Delta=0 Beta=0 Action=1 ID=434aa8fa-b425-47a9-be5b-dd000b66c6ed Download URL(s): http://download.windowsupdate.com/msdownload/update/software/ftpk/2011/08/dotnetfx40_client_x86_x64_a96cef357b16f0dea3423bf6c515a96a3c2233de.exe 6. Security Update for Microsoft .NET Framework 2.0 SP2 on Windows Server 2003 and Windows XP for x64-based Systems (KB2729450) Size=31454256 Date=Tue Nov 13 00:00:00 2012 Priority=2 Delta=0 Beta=0 Action=1 ID=cee83adc-d8d7-43d0-905b-6351e3341822 Superseded ID(s): 2b4df0db-ada4-4ae4-86ef-6634d0cd3219 6894a994-d6fc-4f15-8142-83d79c84eff0 ae04de58-8ea0-47a9-a49a-0ac80ba2835b aee1e679-770b-40ef-9701-02ed03f78468 Download URL(s): http://download.windowsupdate.com/msdownload/update/software/secu/2012/10/msipatchregfix-amd64_5011cb29b096fb674a4795ee8fc2f7fdad33863a.exe http://download.windowsupdate.com/msdownload/update/software/secu/2012/10/ndp20sp2-kb2729450-x64_26a72f0f0db6ebac5aede881c56102b3cf250928.exe
TuMaGoNx Posted September 9, 2017 Author Posted September 9, 2017 SFX now prioritize batch file of same filename, useful for mass wrapper for ex. put several batch files into sfx renaming sfx.exe as myprogram.exe will try execute myprogram.bat/cmd if exists, similar to busybox SFX now fallback to system cmd if roscmd not present all executables now should reside in bin subdir which prepended into PATH download https://github.com/tumagonx/portabat/raw/master/basebin/7z.sfx https://github.com/tumagonx/portabat/raw/master/basebin/roscmd.exe
TuMaGoNx Posted September 23, 2017 Author Posted September 23, 2017 @jaclaz I have add cwd exception (not from ini file though) see note at first post
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now