Bash: How to extract an executable from within?

Daniel B. Thurman dant at cdkkt.com
Tue Sep 15 04:39:38 UTC 2009


On 09/14/2009 06:46 PM, Patrick O'Callaghan wrote:
> On Mon, 2009-09-14 at 17:48 -0700, Daniel B. Thurman wrote:
>   
>> outname=selfextractExe.$$
>>
>> function unWrapExe() {
>> cat <<'EOF'
>> <executable>
>> EOF
>> }
>>
>> # Do pre-shell stuff
>>
>> unWrapExe > $outname
>> ./outname
>>     
> A few comments on this (I realize it's only a sketch of the code):
>
> 1) Why declare a function if it has no argument? Just put the code
> inline.
> 2) You need to make the output file executable ("chmod ...")
> 3) The executable isn't ./outname, it's $outname
>
> poc
>   
Yeah, I messed up for sure but as you said,
I was conveying the idea.

Still - I wondered why cat/echo would not work
under such a scenario when there is ELF code
involved.  I attempted to look at 'printf' but
could not figure it out.

How would you do it, really?




More information about the users mailing list