Executing a shell script from assembly language(.a

2019-03-02 21:28发布

I want to execute a shell script(exactly as mentioned in the code below) from my .asm file but can,t find the alternative to the following lines in assembly.I am using masm611 to assemble and compile the files.

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "myscript.sh";
proc.Start();

2条回答
老娘就宠你
2楼-- · 2019-03-02 21:57

First, you don't say which architecture; so this is unanswerable. An easy solution should be to just code this in C, then compile to assembly code - that's a switch all popular C compilers have, AFAIK - then just transplant to your own code, linking with appropriate libraries.

Disclaimer: I don't work in assembly.

查看更多
beautiful°
3楼-- · 2019-03-02 22:00

Since your example is in .NET and you mention MASM, I assume that you work on Windows. On Windows, you can use either Win32 API to start a process, or the C RTL. Either way, you have to link to a static (.lib) library and call a function. In Win32 API, ShellExecute() is the easiest one to use (there's also CreateProcess(), but the calling sequence is a pain). In the RTL, there's _execl() and its relatives. Read up on consuming static libraries from assembly.

.NET code, like the Process.Start() stuff you've mentioned, does not translate into x86 assembly at all.

May I ask why this has to be done from assembly? "Assembly" and "shell scripts" rarely go together. Note: on Windows, shell scripts have a .bat or a .cmd extension. .sh, on the other hand, is characteristic of *nix or MacOS.

查看更多
登录 后发表回答