Re: generating mach-o executable files by hand
Re: generating mach-o executable files by hand
- Subject: Re: generating mach-o executable files by hand
- From: Joel Reymont <email@hidden>
- Date: Fri, 9 Jan 2009 12:03:04 +0000
On Jan 7, 2009, at 2:48 PM, Terry Lambert wrote:
I also rather expect you aren't going to get help from the tools
folks to deal with these issues, or to document how to generate a
valid Mach-o.
I'm happy to report that I can generate a proper "hello world" in
assembler and without using a linker. I _am_ using printf and exit
from libc.
It only took me a week.
nasm -f bin -o hello hello.asm && chmod +x hello
./hello
Hello, World!
otool -h hello
hello:
Mach header
magic cputype cpusubtype caps filetype ncmds
sizeofcmds flags
0xfeedface 7 3 0x00 2 10 748
0x00000085
otool -l hello
hello:
Load command 0
cmd LC_SEGMENT
cmdsize 56
segname __PAGEZERO
vmaddr 0x00000000
vmsize 0x00001000
fileoff 0
filesize 0
maxprot 0x00000000
initprot 0x00000000
nsects 0
flags 0x0
Load command 1
cmd LC_SEGMENT
cmdsize 124
segname __TEXT
vmaddr 0x00001000
vmsize 0x00001000
fileoff 0
filesize 4096
maxprot 0x00000007
initprot 0x00000005
nsects 1
flags 0x0
Section
sectname __text
segname __TEXT
addr 0x00001308
size 0x00000039
offset 776
align 2^0 (1)
reloff 0
nreloc 0
flags 0x80000400
reserved1 0
reserved2 0
Load command 2
cmd LC_SEGMENT
cmdsize 124
segname __DATA
vmaddr 0x00002000
vmsize 0x00001000
fileoff 4096
filesize 4096
maxprot 0x00000007
initprot 0x00000003
nsects 1
flags 0x0
Section
sectname __const
segname __DATA
addr 0x00002000
size 0x0000000f
offset 4096
align 2^0 (1)
reloff 0
nreloc 0
flags 0x00000000
reserved1 0
reserved2 0
Load command 3
cmd LC_SEGMENT
cmdsize 124
segname __IMPORT
vmaddr 0x00003000
vmsize 0x00001000
fileoff 8192
filesize 4096
maxprot 0x00000007
initprot 0x00000007
nsects 1
flags 0x0
Section
sectname __jump_table
segname __IMPORT
addr 0x00003000
size 0x0000000a
offset 8192
align 2^6 (64)
reloff 0
nreloc 0
flags 0x04000008
reserved1 0 (index into indirect symbol table)
reserved2 5 (size of stubs)
Load command 4
cmd LC_SEGMENT
cmdsize 56
segname __LINKEDIT
vmaddr 0x00004000
vmsize 0x00001000
fileoff 12288
filesize 108
maxprot 0x00000007
initprot 0x00000001
nsects 0
flags 0x0
Load command 5
cmd LC_SYMTAB
cmdsize 24
symoff 12288
nsyms 4
stroff 12344
strsize 52
Load command 6
cmd LC_DYSYMTAB
cmdsize 80
ilocalsym 0
nlocalsym 1
iextdefsym 1
nextdefsym 2
iundefsym 2
nundefsym 2
tocoff 0
ntoc 0
modtaboff 0
nmodtab 0
extrefsymoff 0
nextrefsyms 0
indirectsymoff 12336
nindirectsyms 2
extreloff 0
nextrel 0
locreloff 0
nlocrel 0
Load command 7
cmd LC_LOAD_DYLINKER
cmdsize 28
name /usr/lib/dyld (offset 12)
Load command 8
cmd LC_UNIXTHREAD
cmdsize 80
flavor i386_THREAD_STATE
count i386_THREAD_STATE_COUNT
eax 0x00000000 ebx 0x00000000 ecx 0x00000000 edx 0x00000000
edi 0x00000000 esi 0x00000000 ebp 0x00000000 esp 0x00000000
ss 0x00000000 eflags 0x00000000 eip 0x00001308 cs 0x00000000
ds 0x00000000 es 0x00000000 fs 0x00000000 gs 0x00000000
Load command 9
cmd LC_LOAD_DYLIB
cmdsize 52
name /usr/lib/libSystem.B.dylib (offset 24)
time stamp 2 Thu Jan 1 01:00:02 1970
current version 111.1.3
compatibility version 1.0.0
---
http://twitter.com/wagerlabs
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden