Live data from Hacker News

Main is usually a function – when is it not?

jroweboy.github.io

1–10 of 62 posts

Re: Main is usually a function – when is it not?

#3
I wonder if one could write a header file containing definitions that would make the following possible.

  char main[] = {
  	movl(1, eax),
  	movl(1, ebx),
  	movl(message, esi),
  	movl(13, edx),
  	syscall(),
  	movl(60, eax),
  	xorl(ebx, ebx),
  	syscall(),
  };
Obviously there are some technical difficulties like handling literal values and code sections, but it could be a fun hack, and I've love to see what someone could come up with.

Re: Main is usually a function – when is it not?

#5
I believe you could get around the problem of finding the address of the string by pushing 4 (8?)-byte pieces of it onto the stack and then doing "mov esi, esp".

On the topic of "executable ASCII", the EICAR test file is an interesting example: http://en.wikipedia.org/wiki/EICAR_test_file

Re: Main is usually a function – when is it not?

#6
post #4

I recall from somewhere: int main = 0; This code compiles (cleanly!), but segfaults.

I think that sets the address of main to NULL, so it segfaults as soon as `_start` jumps to `main`. It's known for being one of the smallest compilable C programs.

EDIT: Your original post contained

  int main=0;

Re: Main is usually a function – when is it not?

#9
> My problem solving process is typically the same thing I imagine most programmers do.

I'm afraid I may be a victim of Poe's law here, but this attitude is... distressing. It completely discounts the value of problem solving, which, once upon a time, was the entire point of the profession.

Re: Main is usually a function – when is it not?

#10

> My problem solving process is typically the same thing I imagine most programmers do. I'm afraid I may be a victim of Poe's law here, but this attitude is... distressing. It completely discounts the value of problem solving, which, once upon a time, was the entire point of the profession.

It does not. It just moves what "the problem" is.

An example of that is the article itself which leverages the gained information from SO to solve the real problem.

Also arcane knowledge is not the same thing as problem solving.

Post reply on HN