G4Vi / Perl-Dist-APPerl

Actually Portable Perl
Other
35 stars 1 forks source link

OpenBSD --assimilate #2

Closed Veraellyunjie closed 1 year ago

Veraellyunjie commented 1 year ago

The foremost: APPerl is a wow-awesome project, sharing freaking awesomeness of αcτµαlly pδrταblε εxεcµταblε and Cosmopolitan Libc!
Man, you have introduced an exorbitant amount of excitement into my life!
Please, keep on and the best of luck to you!


Now, having downloaded binaries from https://computoid.com/APPerl/ to an OpenBSD 7.2 amd64 machine, and having chmod +x ...:

> ./perl.com -E 'say "APPerl works on OpenBSD!"'
/tmp/perl.com[18]: /home/v11e/.ape: Permission denied

It is said on https://metacpan.org/pod/Perl::Dist::APPerl that

in certain cases such as magic (modifying $0, etc.) The binary must be assimilated for it to work properly. Note, you likely want to copy before this operation as it modifies the binary in-place to be bound to the current environment. cp perl.com perl ./perl --assimilate

(please also note missing markup of snippet cp perl.com perl ./perl --assimilate)

Indeed, having done cp perl.com perl and ./perl --assimilate:

> ./perl -E 'say "APPerl works on OpenBSD!"'
APPerl works on OpenBSD!

Also tried perl-small-vista.com after --assimilate — works as well.

Neither https://computoid.com/APPerl/ nor https://github.com/G4Vi/Perl-Dist-APPerl pages mention --assimilate in case of OpenBSD, so such a note would be welcome

G4Vi commented 1 year ago

@Veraellyunjie Thank you, I'm glad you're enjoying it.

--assimilate shouldn't be required for your example, could you please test with bash?

Edit, does this happen with other APEs such as hello.com?: https://justine.lol/hello.com

Veraellyunjie commented 1 year ago

I just stumbled upon your explanation at https://news.ycombinator.com/item?id=34002858

on unix-like they install the APE loader to$HOME/.apeand use that ELF executable to run the APE

My /home is mounted noexec so $HOME/.ape will not run.
it brings me a bit of calmness as some potential malware will just remain inactive, yet have to ln -s ... some paths for actually needed software manually — me weirdo :)

I have moved .ape and done ln -s ... and indeed, now I can just run any of perl.com perl-small.com perl-vista.com perl-small-vista.com without --assimilate

does this happen with other APEs such as hello.com?: https://justine.lol/hello.com

hello.com works fine even with no $HOME/.ape run permission:

> chmod +x hello.com
> ./hello.com
hello world

Is hello.com somewhat different and doesn't rely on $HOME/.ape?

G4Vi commented 1 year ago

My /home is mounted noexec so $HOME/.ape will not run.

That would do it.

I have moved .ape and done ln -s ... and indeed, now I can just run any of perl.com perl-small.com perl-vista.com perl-small-vista.com without --assimilate

You could also install the ape loader to /usr/bin/ape. Download and info on the new ape loader: https://justine.lol/apeloader/ . I can add some ape loader info to the docs.

Is hello.com somewhat different and doesn't rely on $HOME/.ape?

hello.com was a bad example, it uses the older self-modifying ape loader (doesn't use .ape)

$ sha256sum hello.com
8b819469b3e6e268d117d26dbd17820c4640a269666a235d62ccf726c91d0992  hello.com
$ chmod +x hello.com && ./hello.com
hello world
$ sha256sum hello.com
c975dcfa125706524d28321eaa5fc23fc723c21f598694c7511b1528cec46160  hello.com

Maybe also implement some additional ENV_VAR and/or --argument for specifying custom .ape path?

To avoid bloating APEs, I don't think Justine would be interested in adding those, but you could try proposing changes: https://github.com/jart/cosmopolitan. Adding more arguments (in addition to --assimilate) is messy as they prevent those arguments from being passed on to the executable.

G4Vi commented 1 year ago

Added USAGE NOTES section to APPerl webpage with various APE info.

Veraellyunjie commented 1 year ago

USAGE NOTES

Usually, the APE Loader is installed to $HOME/.ape

Not completely correct: https://justine.lol/apeloader/

${TMPDIR:-${HOME:-.}}/.ape

With a verbose explanation:

If your operating system defines the POSIX-specified $TMPDIR variable, then the ape loader will become $TMPDIR/.ape. Otherwise if $HOME is defined, it's dropped in in $HOME/.ape. Then, if neither is defined, ./.ape is created in the current directory.


From OpenBSD's /etc/skel/.profile: export PATH HOME TERM:
TMPDIR is not exported by default (and I didn't set it manually);
HOME is exported by default.
/home by default doesn't have noexec — that's my custom config.
So, with ${TMPDIR:-${HOME:-.}}/.ape, on default OpenBSD, the APE Loader will indeed be installed to $HOME/.ape and will work fine from there.

Generally however, APPerl USAGE NOTES should probably say ${TMPDIR:-${HOME:-.}}/.ape instead of $HOME/.ape?