A
A
Andrey Strelkov2020-05-01 15:59:25
PowerShell
Andrey Strelkov, 2020-05-01 15:59:25

Is it possible to compile a Powershell script into an executable including the DLLs used?

Good afternoon, there is a Powershell script that uses additional DLL libraries via

[System.Reflection.Assembly]::LoadFrom("С:\temp\сustom_one.dll")
[System.Reflection.Assembly]::LoadFrom("С:\temp\сustom_two.dll")


Is it possible to compile it into the final EXE file inside which DLLs will already be embedded, so that the output has a single file to run?

I found various solutions like PS1 to EXE, but I did not see in them the ability to include the used DLL files

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
azarij, 2020-05-01
@azarij

here they do something similar:
https://www.loginvsi.com/blog/565-embed-external-f...

F
falconandy, 2020-05-01
@falconandy

Write a small Go program, for example. Using a library like https://github.com/rakyll/statik , add the necessary dlls and the powershell script itself into the binary. The Go binary will copy the dlls and the script to a temporary folder on the first run, and then run the powershell script. On next runs, the Go binary will simply run the script. Additionally, you can add a comparison of the hashes of the embedded and existing files in order to replace obsolete files (dlls and script) when a new version is released.
Alternative: if the powershell script is really simple (insert a record into the database) and dlls are used to communicate with the database or some other standard logic, just rewrite it in Go without any dlls and runtime dependencies.

M
MaxKozlov, 2020-05-01
@MaxKozlov

... Well, or completely hacker methods
https://clymb3r.wordpress.com/2013/04/06/reflectiv...
https://github.com/stephenfewer/ReflectiveDLLInjection

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question