Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Done Provide PSHELL with the ability to read a stream, and execute a stream

Aug
2,799
144
It does not appear that PSHELL can read a stream, and execute a stream.

It would be beneficial for PSHELL to have this ability.

Code:
U:\>pshell isnetdll.btm:isnetdll.ps1
PSHELL: The term 'U:\isnetdll.btm:isnetdll.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

U:\>type IsNETDll.btm:isnetdll.ps1
$r = [System.IO.File]::ReadAllBytes("U:\cs2ps1.dll")
$peOffset = [BitConverter]::ToInt32($r, 0x3C)
$optHeader = $peOffset + 0x18
$comDirRVA  = [BitConverter]::ToInt32($r, $optHeader + 0xE0)
$comDirSize = [BitConverter]::ToInt32($r, $optHeader + 0xE4)
if ($comDirRVA -ne 0 -and $comDirSize -ne 0) {
"This DLL contains a CLR header ? .NET assembly."
} else {
"No CLR header ? native Win32 DLL."
}

U:\>type IsNETDll.btm:isnetdll.ps1 > isnetdll.ps1

U:\>pshell isnetdll.ps1
This DLL contains a CLR header ? .NET assembly.

Joe
 
I use .btm files as wrappers to run;

VBScript code .vbs
JScript code .js
Tiny C code .c
CS-Script code .cs
Harbour code .hb

...and other scripting code.

I store the code generated from the .btm file into a stream

Sometimes, I even store more than one generated script code into a stream with a .btm

Code:
2026-01-21   9:27           2,113  jlcage.btm
                              183    jlcage.hb:$DATA
                              869    jlcage.js:$DATA

I can presently do the same thing with a .ps1 file,
but I have to load the .ps1 file from the stream as raw bytes into memory,
and then execute the code from memory.

Code:
pshell /s "$code = Get-Content -Raw '%_batchname:%@name[%_batchname].ps1';Invoke-Expression $code"

Thus, this works as it should.

Code:
@SETLOCAL
@ECHO OFF

iff %# eq 0 then
  echo USAGE: IsNETDLL.btm mydll.dll
  quit
endiff

iff not exist %1 then
  echo %1 does not exist.
  quit
endiff

Gosub MakePS1
pshell /s "$code = Get-Content -Raw '%_batchname:%@name[%_batchname].ps1';Invoke-Expression $code"
quit

:MakePS1
type <<- endtext > %_batchname:%@name[%_batchname].ps1
$r = [System.IO.File]::ReadAllBytes("%1")
$peOffset = [BitConverter]::ToInt32($r, 0x3C)
$optHeader = $peOffset + 0x18
$comDirRVA  = [BitConverter]::ToInt32($r, $optHeader + 0xE0)
$comDirSize = [BitConverter]::ToInt32($r, $optHeader + 0xE4)
if ($comDirRVA -ne 0 -and $comDirSize -ne 0) {
     "This DLL contains a CLR header (.NET assembly)."
 } else {
     "No CLR header (native Win32 DLL)."
 }
endtext
Return
ENDLOCAL

I was hoping that you could include this ability in the PSHELL command.

Joe
 
Back
Top