Jump to content

How to create a ZIP file with altenate data streams included?


Recommended Posts

For my next project I would like to send files with "alternate data streams" by email in ZIP format.
I can not use any external program like 7-Zip or WinRAR. (They would fit😥)
Who knows how to create a ZIP file with "alternate data streams" included with the Powershell command "Compress-Archive"? 

Here a test script:  (save as "ADSTester.cmd")

@rem Try to create a zip file with alternate data streams (ADS) included

@rem Housekeeping
@cls
@del ADSTester.zip >nul:
@RD /S /Q Extracted >nul:
@del ADSTester.txt >nul:
@rem End of Housekeeping

echo This is the ADSTester.txt file >ADSTester.txt
echo This is the ADSTester.txt:Part1 file >ADSTester.txt:Part1
echo This is the ADSTester.txt:Part2 file >ADSTester.txt:Part2

dir /r ADSTester.txt
@rem See the 3 files

@rem ****************************************************************
@rem ****************************************************************
@rem Please alter the next lines to include the alternate data streams.   
powershell Compress-Archive -Path .\ADSTester.txt -Update -DestinationPath ADSTester.zip 
powershell Expand-Archive -Path ADSTester.zip -DestinationPath .\Extracted\

dir /r Extracted\ADSTester.txt
@rem Only one file left :-(

pause

 

Edited by Exit

App: Au3toCmd              UDF: _SingleScript()                             

Link to post
Share on other sites

Not sure if the Compress-Archive method will collect the stream data and embed it in an archive, then put it back in place when the file is extracted.  You might have to do a custom script to extract the stream data and add it to the archive, then a archive extraction process to "rebuild" the streams.  

I saw an article that says the RAR file format supports NTFS ADS, but haven't looked into it.

Link to post
Share on other sites
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Exit
      Au3toCmd  ---  Avoid false positives
      Since many virus scanners sometimes prevent a "compiled autoit EXE" from being executed as "false positive", the "*.A3X" format is a suitable format to avoid this problem.
      In order to simplify this procedure, I wrote the Au3toCmd script. Here a *.Cmd file is generated from a *.Au3 file. The necessary files Autoit3.exe and *.A3x are added to the "*.Cmd" file as "alternate data streams" "Base64" encoded data.
      Now the Autoit Script can be called by clicking on the cmd file and the anti-virus scanners do not recognize the "false positive".
      If the short-term flashing of the CMD window bothers you, you can click the desktop shutcut that runs in a minimized window.
      Unfortunately, because the "alternate data streams", this CMD file cannot be distributed via FTP or email.
      Only a USB stiof ck or removable disk formatted with NTFS can be used.
      As the new version now uses Base64 data instead of ADS, this statement is out of date.
      For reasons of compatibility, the old version was sunk into the spoiler here.
       
       
      Here the new  version using base64 data
      ;============================================================================================================== ; Script Name: Au3toCmd.au3 ; Description: Creates a CMD file from any AU3 file. ; The CMD file will contain the compiled version (A3X) of the AU3 input file ; and the AUTOIT3.EXE file as BASE64 data. ; This avoids the problem with the false positives of the virus scanners on EXE files. ; To avoid the short-term flashing of the CMD window, a shortcut is created on the desktop ; that runs in a minimized window. You may delete or move it. ; ; ; Syntax: Au3toCmd (input-file) ; Default: none ; Parameter: Name of AU3 file (optional) ; can be set by using SHIFT+F8 in SciTE4AutoIt3 Editor. ; if parameter is empty, a FileOpenDialog prompts you. ; ; ; The execxution environment can be set by using the #AutoIt3Wrapper directives in the source code. ; #AutoIt3Wrapper_Version=Prod/P/0/Beta/B/1 ; #AutoIt3Wrapper_UseX64=Y/1/N/0 ; #AutoIt3Wrapper_Icon=C:\users\...\anyname.ico ; ; Example: Au3toCmd c:\testdir\testfile.au3 ; ; Author: Exit ( http://www.autoitscript.com/forum/user/45639-exit ) ; SourceCode: http://www.autoitscript.com/forum/index.php?showtopic=201562 Version: 2022.01.11 ; COPYLEFT: © 2020 Freeware by "Exit" ; ALL WRONGS RESERVED ;============================================================================================================== #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Version=Prod #AutoIt3Wrapper_UseX64=Y #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Global $_a2c_Debug =0 ; change to '1' for debugging informations on output console #include <File.au3> Global $sSourcepath, $sSourceData, $sTargetpath, $aPathSplit, $sDrive, $sDir, $sFileName, $sExtension, $sIconPath = "", $iIconNumber = 0, $sRDir Exit _Main() Func _Main() __DebugInfo() If Not _Sourcepath() Then Return SetError(1, 0, 0) If Not _IconPath() Then Return SetError(2, 0, 0) If Not _Targetpath() Then Return SetError(3, 0, 0) EndFunc ;==>_Main Func _Sourcepath() If $cmdline[0] > 0 Then $sSourcepath = $cmdline[1] If Not FileExists($sSourcepath) Then Beep(1000, 80) $sSourcepath = FileOpenDialog(" Enter AU3 Inputfile for Au3toCmd Application ", "", "Autoit Files(*.au3)", 3) If @error Then Return SetError(5, MsgBox(16 + 262144, Default, "Error: No Inputfile given", 3), 0) EndIf $sSourcepath = _PathFull($sSourcepath) $aPathSplit = _PathSplit($sSourcepath, $sDrive, $sDir, $sFileName, $sExtension) FileChangeDir($sDrive & $sDir) $sSourceData = FileRead($sSourcepath) __CW("Sourcepath: " & $sSourcepath & @LF) Return 1 EndFunc ;==>_Sourcepath Func _IconPath() Local $aTemp = StringRegExp($sSourceData, "(?m)\n#AutoIt3Wrapper_Icon=(.*)", 1) If IsArray($aTemp) And FileExists($aTemp[0]) Then $sIconPath = $aTemp[0] ElseIf FileExists($sDrive & $sDir & $sFileName & ".ico") Then $sIconPath = $sDrive & $sDir & $sFileName & ".ico" Else $sIconPath = @WindowsDir & "\system32\shell32.dll" ;~ $iIconNumber = 71 $iIconNumber = 132 EndIf __CW("IconNumber: " & $iIconNumber & " IconPath: " & $sIconPath & @CRLF) Return 1 EndFunc ;==>_IconPath Func _Targetpath() Local $sA3Dir, $sA3Ver, $hTargetpath, $t, $x64 = 0, $beta = 0 $sTargetpath = $sDrive & $sDir & $sFileName & ".cmd" FileDelete($sTargetpath) $beta = StringRegExp($sSourceData, "(?m)\n#AutoIt3Wrapper_Version=[bByY1]", 0) $sA3Dir = RegRead("HKLM\SOFTWARE" & ((@OSArch = 'X64') ? "\Wow6432Node" : "") & "\AutoIt v3\AutoIt", ($beta ? "beta" : "") & "InstallDir") $sA3Ver = RegRead("HKLM\SOFTWARE" & ((@OSArch = 'X64') ? "\Wow6432Node" : "") & "\AutoIt v3\AutoIt", ($beta ? "beta" : "") & "Version") __CW("Regread A3Dir: " & $sA3Dir & " Version: " & $sA3Ver & @CRLF) If Not (FileExists($sA3Dir & "\autoit3.exe") And FileExists($sA3Dir & "\au3check.exe") And FileExists($sA3Dir & "\Aut2Exe\Aut2exe.exe")) Then Return SetError(9, MsgBox(16 + 262144, Default, "Error: Autoit " & ($beta ? "Beta Version " : "") & "not installed on this system.", 0), 0) $x64 = StringRegExp($sSourceData, "(?m)\n#AutoIt3Wrapper_UseX64=[yY1]", 0) __CW("X64: >" & $x64 & "< beta: >" & $beta & "< A3Dir: " & $sA3Dir & @LF) If ShellExecuteWait($sA3Dir & "\au3check.exe", ' -q "' & $sSourcepath & '"', "", "", @SW_HIDE) Then Return SetError(10, MsgBox(16 + 262144, Default, "Error: Input file """ & $sSourcepath & """ has Errors according to Au3Check.exe. ", 0), 0) If ShellExecuteWait($sA3Dir & "\Aut2Exe\Aut2exe" & ($x64 ? '_x64' : '') & ".exe", "/In """ & $sSourcepath & """ /out """ & $sTargetpath & ".sa3x"" " & ($x64 ? '/X64' : ' ')) Then Return SetError(11, MsgBox(16 + 262144, Default, "Error : Cannot create target file """ & $sTargetpath & ".sa3x"" ", 0), 0) FileCopy($sA3Dir & "\Autoit3" & ($x64 ? '_x64' : '') & ".exe", $sTargetpath & ".sprog") $hTargetpath = FileOpen($sTargetpath, $FO_APPEND) FileWriteLine($hTargetpath, _ '@if not DEFINED _ set _=_ & start "" /min "%~f0" %* & exit' _ & @CRLF & 'cd /D %~dp0' _ & @CRLF & 'set r=%appdata%\Au3toCmd\' _ & @CRLF & 'set n=%~n0' _ & @CRLF & 'set ver=' & $sA3Ver _ & @CRLF & 'set x64=' & ($x64 ? "_64" : "") _ & @CRLF & 'if not exist "%r%exe\%ver%\AutoIt3%x64%.exe" (' _ & @CRLF & ' mkdir %r%exe\%ver%\' _ & @CRLF & ' more +35 %0 >~~' _ & @CRLF & ' certutil -decode -f ~~ "%r%exe\%ver%\AutoIt3%x64%.exe"' _ & @CRLF & ' del ~~' _ & @CRLF & ')' _ & @CRLF & 'call :ts %0 "%r%a3x\%n%.a3x"' _ & @CRLF & 'if %t1% geq %t2% (' _ & @CRLF & 'mkdir %r%a3x\' _ & @CRLF & 'certutil -decode -f %0 "%r%a3x\%n%.a3x"' _ & @CRLF & ')' _ & @CRLF & 'wmic process call create ''"%r%exe\%ver%\AutoIt3%x64%.exe" "%r%a3x\%n%.a3x" "%*"'' ' _ & @CRLF & 'rem pause' _ & @CRLF & 'exit' _ & @CRLF & ':ts t1 t2' _ & @CRLF & 'set t1=%~t1' _ & @CRLF & 'set t2=%~t2' _ & @CRLF & 'set t1=%t1:~3,2%%t1:~0,2%%t1:~11,2%%t1:~14,2%' _ & @CRLF & 'set t2=%t2:~3,2%%t2:~0,2%%t2:~11,2%%t2:~14,2%' _ & @CRLF & 'goto :eof' _ ) RunWait(@ComSpec & " /c " & 'certutil -encode -f "' & $sTargetpath & '.sa3x" "' & $sTargetpath & '.a3x"', "", @SW_HIDE) $t = FileRead($sTargetpath & '.a3x') FileDelete($sTargetpath & '.sa3x') FileDelete($sTargetpath & '.a3x') FileWriteLine($hTargetpath, $t) RunWait(@ComSpec & " /c " & 'certutil -encode -f "' & $sTargetpath & '.sprog" "' & $sTargetpath & '.prog"', "", @SW_HIDE) $t = FileRead($sTargetpath & '.prog') FileDelete($sTargetpath & '.sprog') FileDelete($sTargetpath & '.prog') FileWriteLine($hTargetpath, $t) FileClose($hTargetpath) If Not FileCreateShortcut($sTargetpath, @DesktopDir & "\" & $sFileName & ".lnk", $sDrive & $sDir, "", "", $sIconPath, "", $iIconNumber, 7) Then Return SetError(16, MsgBox(16 + 262144, Default, "Unable to create shortcut", 0), 0) __CW("$sTargetpath: " & $sTargetpath & @LF) MsgBox(64 + 262144, Default, $sTargetpath & " and " & @CRLF & @DesktopDir & "\" & $sFileName & ".lnk created." & @CRLF & @CRLF & "X64 Mode=" & ($x64 ? "Yes" : "No") & " Beta Mode=" & ($beta ? "Yes" : "No"), 0) Return 1 EndFunc ;==>_Targetpath Func __CW($sText) If Not Eval("_a2c_Debug") Then Return ;~ FileWriteLine(@ScriptFullPath & ".console.txt", $sText) ConsoleWrite($sText & @CRLF) EndFunc ;==>__CW Func __DebugInfo() FileDelete(@ScriptFullPath & ".console.txt") If @Compiled Then $_a2c_Debug = 0 If Not Eval("_a2c_Debug") Then Return __CW("============ Start of DebugInfo ===============") __CW("Au3toCmd Version: " & (StringRegExp(FileRead(@ScriptFullPath), "(?i)Version: (.*)", 1))[0]) __CW("@ScriptFullPath: " & @ScriptFullPath) __CW("@AutoItExe: " & @AutoItExe) __CW("@AutoItVersion: " & @AutoItVersion) __CW("@AutoItX64: " & @AutoItX64) __CW("@CPUArch: " & @CPUArch) __CW("@OSArch: " & @OSArch) __CW("@OSBuild: " & @OSBuild) __CW("@OSLang: " & @OSLang) __CW("@OSType: " & @OSType) __CW("@OSVersion: " & @OSVersion) __CW("@OSServicePack: " & @OSServicePack) __CW("@UserName: " & @UserName) __CW("@UserProfileDir: " & @UserProfileDir) __CW("============ End of DebugInfo ===============") EndFunc ;==>__DebugInfo ; End of Au3toCmd.au3 script The script can be called with a file name of an AU3 script as a parameter.
      If no name is entered, a query is made.
      Suggestions, improvements and bug reports are welcome.
    • By DannyJ
      $sCommands1 = 'powershell.exe Get-ChildItem' $iPid = run($sCommands1   , @WorkingDir , @SW_SHOW , 0x2) $sOutput = ""  While 1     $sOutput &= StdoutRead($iPID)         If @error Then             ExitLoop         EndIf  WEnd ;~ msgbox(0, '' , $sOutput) ConsoleWrite("$sOutput") ConsoleWrite($sOutput) ConsoleWrite(@CRLF) $aOutput = stringsplit($sOutput ,@LF , 2) For $i=0 To  UBound($aOutput) - 1 Step 1     ConsoleWrite($aOutput[$i]) Next The script above reads the whole directory into a one dimensional array, but I need to work with the array, so I need to split the array into multiple dimensions.
      I have already read some forum answers here, and I have already tried these commands:
       
      Are there any way to use the $aOutput variable like in PowerShell:
      PowerShell:
      $a = Get-ChildItem $a.Mode I imagine this in AutoIt  $aOutput
      ConsoleWrite($aOutput[i].Mode) Or if I split this command into 2 dimension like:
      For $i To UBound($aOutput)-1 Step 1 ConsoleWrite($aOutput[$i][1]) ConsoleWrite($aOutput[$i][2]) Next  
    • By DannyJ
      If I try to run this script with   Get-ChildItem which means dir this script works perfectly, but If I try to run this command Get-RDUserSession, my script has the following error message:
      This command runs perfectly in PowerShell admin and I get back the values
      Get-RDUserSession -ConnectionBroker  broker.local | sort Username Or you can try this command as well
      Get-Command Get-RDUserSession If I run the above mentioned command this runs perfectly in PowerShell but not with AutoIt.
      Here is my script you can test the commands:
      #include<array.au3> $iPid = run('powershell Get-Command Get-RDUserSession'  , @WindowsDir , @SW_HIDE , 0x2) ;; This command not works in AutoIT you can test it in PowerShell but it won't work in Autoit ;$iPid = run('powershell Get-RDUserSession -ConnectionBroker  broker.local | sort Username'  , @WindowsDir , @SW_MAXIMIZE , 0x2) ; This command not works in AutoIT ;$iPid = run('powershell Get-ChildItem | sort Name'  , @WindowsDir , @SW_HIDE , 0x2) ; This runs perfectly $sOutput = ""  While 1     $sOutput &= StdoutRead($iPID)         If @error Then             ExitLoop         EndIf  WEnd ;~ msgbox(0, '' , $sOutput) $aOutput = stringsplit($sOutput , @LF , 2) _ArrayDisplay($aOutput)  
      That could be the solution of the problem if I could run, directly this PowerShell command window and Write to it and save it's values.
    • By DrLarch
      I'm trying to run this powershell command from Autoit and can't figure out how to pull it off:
      Get-ProvisionedAppxPackage -Online | Where-Object { $_.PackageName -match "xbox" } | ForEach-Object { Remove-ProvisionedAppxPackage -Online -AllUsers -PackageName $_.PackageName } I've been trying to run it many different ways including:
      $sCMD = 'Get-ProvisionedAppxPackage -Online | Where-Object { $_.PackageName -match "xbox" } | ForEach-Object { Remove-ProvisionedAppxPackage -Online -AllUsers -PackageName $_.PackageName }' RunWait(@comspec & ' /c powershell.exe -nologo -executionpolicy bypass -noprofile -Command "&' & $sCMD & '"') The problem is that it seems I'm missing something in how to escape or double the quotes. I've tried doubling the quotes in many different ways, but the end result always produces a syntax error in powershell. I could just run powershell first, then paste and run the command, then close the powershell window, but that's clunky. I'm trying to do it either via parameter (as above) or in one line like this:
      RunWait(@comspec & ' /c powershell.exe -nologo -executionpolicy bypass -noprofile -Command "&Get-ProvisionedAppxPackage -Online | Where-Object { $_.PackageName -match "xbox" } | ForEach-Object { Remove-ProvisionedAppxPackage -Online -AllUsers -PackageName $_.PackageName }"')  
    • By antonioj84
      any assistance how to incorporate this powershell command within autoit
       
      powershell.exe -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -command "&Set-WinUserLanguageList -LanguageList fr-CA, en-CA -Force"
×
×
  • Create New...