Shebang Quine
github.com
github.com
https://github.com/mame/quine-relay/blob/master/thumbnail.pn...
(Attention to detail, they haz it.)
Any idea how this works? It's just to much for my mind to bear I think.
Edit: Ah, nvm. It looks like this is a Javascript port of a famous Ruby quine from 2010, the Qlobe[1].
https://jsfiddle.net/f17yr7qh/
For example, line 9 of the source:
~(32sin(o)/* , (W#####Xx######.P^ T % */sin(.5+y/7))\
You can see that there are more chars than just '#' inside the "globe", like '(W' and 'Xx' and '.P^'
I even changed those inside the globe and the effect is non obvious. Sometimes it stops working sometimes it works fine with other chars. No idea why.
In any other language, a program that opens and prints file containing its own source code is not considered a quine.
But in what language is this "program" written?
The best I can guess is that the unix shebang hack/convention is a (very, very minimal) language all of its own.
#!/bin/rmFor those who are puzzled by the term "quine": http://meta.codegolf.stackexchange.com/questions/4877/what-c...
Any other funny commands? ls -l is cool too.
I'm not sure I've used it since, but I still like the xgraph thing.
#!/bin/rm
#!/sbin/md5
#!/usr/bin/file
#!/usr/bin/du -h
And yet another quine: #!./quine
cat $0
Edit: I was not sure about #!/sbin/poweroff, and I cannot try now, so removed.Refer to sys/kern/imgact_shell.c and ^do_execve in sys/kern/kern_exec.c, I skimmed but could not find why it ran.
$ sudo dtrace -n 'syscall::execve*:entry { printf("%s %s", execname, copyinstr(arg0)); }'
I had this output 0 51617 execve:entry sh ./quine
1 51617 execve:entry sh /bin/sh
1 51617 execve:entry sh /bin/cat
Altho this is the first time I use dtrace. I can try to run another command you can ask me to.My login shell is the Bourne shell. However I tried bash, csh and tcsh too, it works, so it's probably the system level code that substitutes /bin/sh (maybe because it's my login shell?) to the interpreter.
TARGET(binary)
OUTPUT_FORMAT(elf32-i386)
ENTRY(_start)
SECTIONS
{
. = 2M;
.text 2M: {
_start = .;
BYTE(0xb8); LONG(4) /* mov $4, %eax */
BYTE(0xbb); LONG(1) /* mov $1, %ebx */
BYTE(0xb9); LONG(data); /* mov data, %ecx */
BYTE(0xba); LONG(data_len); /* mov data_len, %edx */
BYTE(0xcd); BYTE(0x80); /* int $0x80 */
BYTE(0xb8); LONG(1) /* mov $1, %eax */
BYTE(0x31); BYTE(0xdb); /* xor %ebx, %ebx */
BYTE(0xcd); BYTE(0x80); /* int $0x80 */
data = .;
*(.data);
data_len = ABSOLUTE(. - data);
}
}
Building and running it: /tmp$ ld -T quine.ld quine.ld -o quine
/tmp$ ./quine | diff -s quine.ld -
Files quine.ld and - are identical#!/bin/cat
[EDIT] as pointed out, I misspoke, and this is false.
- The shell finds opens up the file you want to execute
- It gets the first line of the file
- It figures out what program to execute
- It calls fork()
- In the new process, it executes the program (using exec()) and passes the file as the input to the program. #include <unistd.h>
int main() {
execl("cat-quine", "cat-quine", NULL);
return 0;
}
Is sufficient to have this work.