As
grinder said: "there will always be a race condition between the moment the kernel launches your program and the point in time at which you'll be able to set $0 to something else.".
Anyways If you still want to hide your command line, I have a solution for you :)
It consists on saving the command line in an environment variable when the process start and then exec the same program without any arguments. Doing this, you will pass the arguments on the environment variable to the new process.
Here I show you a little program, that you can execute (e.g. myprogram -arg1 -arg2 234 -private "secret"), and try to see if you can use ps -ef to show its command line arguments.
#!/usr/bin/perl
if (@ARGV) {
print "Command line arguments detected ... \nHidding command l
+ine ...";
my $cmdline = join " ", @ARGV;
$ENV{MY_CMDLINE} = $cmdline;
print "[done]\n";
exec ($0) or die "Exec: $!";
}
print "\nHere is my real code baby!\n";
print "command line: $ENV{MY_CMDLINE}\n";
sleep 300;
Hope it helps.
perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'