wisp-cvs Mailing List for Wisp interpreter (Page 16)
Status: Alpha
Brought to you by:
digg
You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(30) |
Sep
(312) |
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(5) |
Feb
(131) |
Mar
(17) |
Apr
(184) |
May
(252) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
From: <di...@us...> - 2003-04-15 21:27:35
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv9161 Modified Files: elf.py tran.py Log Message: added .bss handling Index: elf.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elf.py,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- elf.py 14 Apr 2003 22:19:55 -0000 1.36 +++ elf.py 15 Apr 2003 21:27:31 -0000 1.37 @@ -498,14 +498,17 @@ if 'x' in flags: p_flags |= PF.X return p_flags -def make_ELF32_object (text = None, data = None, flags = '', +def make_ELF32_object (text = None, data = None, bss = None, flags = '', memory_bottom = 0x08048000): + # Will set given sections' origins. want_symbols = 's' in flags want_relocatable = 'r' in flags - # Will set given sections' origins. + if bss <> None and bss.filesz() <> 0: + raise '.bss not bitless', bss sections = {} - sections['.text'] = text - sections['.data'] = data + if text <> None: sections['.text'] = text + if data <> None: sections['.data'] = data + if bss <> None: sections['.bss'] = bss binary = Linkie('<') memory_boundary = memory_bottom # must be at page boundary @@ -517,7 +520,10 @@ binary.place_symbol('#elf/machine', EM.I386) binary.place_symbol('#elf/flags', 0) # no flags for ia386 - shentnames = ['.text', '.data'] + shentnames = [] + for s in '.text', '.data', '.bss': + if sections.has_key(s): + shentnames.append(s) if want_symbols or want_relocatable: shentnames += ['.symstr', '.symtab'] sections['.symstr'] = ELF32_strtab('<') Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- tran.py 15 Apr 2003 15:44:09 -0000 1.9 +++ tran.py 15 Apr 2003 21:27:32 -0000 1.10 @@ -62,6 +62,9 @@ else: raise 'Literal expected', n def label (name): cursect.place_symbol('&' + name) +def dot_bss (): + global cursect + cursect = Bss def dot_data (): global cursect cursect = Data @@ -71,6 +74,8 @@ def ref (name): Regstack.append('&' + name) def drop (x): pass +def align (n): cursect.align(n) +def reserve (n): cursect.skip(n) def minor (reg): Regstack.append(long(reg[-1])) def swap (x, y): @@ -193,6 +198,7 @@ # Main output sections. Text = Linkie('<') Data = Linkie('<') +Bss = Linkie('<') cursect = Text Regstack = [] Generic_Register = Register() @@ -203,10 +209,13 @@ Meaning = { '+ int int': ('builtin', plus, 2), '- int int': ('builtin', minus, 2), + '.bss': ('builtin', dot_bss, 0), '.data': ('builtin', dot_data, 0), '.text': ('builtin', dot_text, 0), ':macro': ('builtin', colon_macro, 0 | MA_PREFIX), - ':regs': ('builtin', colon_regs, 0 | MA_PREFIX), + ':regs': ('builtin', colon_regs, 0 | MA_PREFIX), + 'align int': ('builtin', align, 1), + 'reserve int': ('builtin', reserve, 1), 'any': ('simple', ClassMarker('any')), 'b, lit': ('builtin', b_comma, 1), 'drop any': ('builtin', drop, 1), @@ -255,9 +264,11 @@ mainloop() print 'TEXT'; Text.dump() print 'DATA'; Data.dump() + print 'BSS'; Bss.dump() if Regstack: raise 'Regstack not empty after parsing ended', Regstack - binary = elf.make_ELF32_object(text = Text, data = Data, flags = 's') + binary = elf.make_ELF32_object(text = Text, data = Data, bss = Bss, + flags = 's') f = open(output_name, 'w') binary.get_file().tofile(f) f.close() |
From: <di...@us...> - 2003-04-15 21:12:19
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv328 Added Files: mswhello.tran Log Message: added a preliminary mswhello.tran --- NEW FILE: mswhello.tran --- \\\\ mswhello.tran - produce a friendly greeting \ \ Copyleft © 2003 by Andres Soolo (di...@us...) \ This file is licensed under the GNU GPL v2. If you \ don't know what that means, please do read the GPL. \ \\\\ @(#) $Id: mswhello.tran,v 1.1 2003/04/15 21:12:15 digg Exp $ \ NOTE that mswhello.tran is not currently translatable \ ia32 registers :regs reg32 %eax %ecx %edx %ebx %esp %ebp %esi %edi ; :regs reg16 %ax %cx %dx %bx %sp %bp %si %di ; :regs reg8 %al %cl %dl %bl %ah %ch %dh %bh ; lit :macro $int #xCD b, b, ; lit :macro $push #x68 b, t, ; reg32 lit :macro $mov swap minor #o270 + b, t, ; \ main entry point label _start -11 $push ref GetStdHandle@kernel32 $call 0 $push ref rckeep $push 7 $push ref message $push %eax $push ref WriteFile@kernel32 $call 0 $push ref ExitProcess@kernel32 $call .data label message #/H b, #/E b, #/L b, #/L b, #/O b, 13 b, 10 b, .bss label rckeep 1 tetras reserve \ vim: ft=forth |
From: <di...@us...> - 2003-04-15 21:04:06
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv27358 Modified Files: pedump.py Log Message: advanced pedump.py yet more Index: pedump.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/pedump.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- pedump.py 15 Apr 2003 00:50:38 -0000 1.3 +++ pedump.py 15 Apr 2003 21:04:02 -0000 1.4 @@ -120,7 +120,8 @@ shtable_ofs = f.tell() + dict_entries * 8 print ' ======== ========' print '00. Export table: %08x %08x' % take('tt') - print '01. Import table: %08x %08x' % take('tt') + imports_rva, imports_size = take('tt') + print '01. Import table: %08x %08x' % (imports_rva, imports_size) print '02. Resource table: %08x %08x' % take('tt') print '03. Exception table: %08x %08x' % take('tt') print '04. Certificate table: %08x %08x' % take('tt') @@ -140,19 +141,73 @@ f.seek(shtable_ofs) print 'name memsz RVA filesz offset !rel !ln #rel #ln flags' print '======== ====== ====== ====== ====== ==== ==== ==== ==== ========' + section_table = [] for i in range(section_count): name = f.read(8) while '\0' in name: name = name[:-1] print '%-8s' % name, - print '%6x' % take('t'), # memory size - print '%6x' % take('t'), # RVA - print '%6x' % take('t'), # file size - print '%6x' % take('t'), # offset + memsize = take('t'); print '%6x' % memsize, + rva = take('t'); print '%6x' % rva, + filesize = take('t'); print '%6x' % filesize, + offset = take('t'); print '%6x' % offset, + section_table.append((name, offset, filesize, rva, memsize)) print '%4x' % take('t'), # reloc offset print '%4x' % take('t'), # line number data offset print '%4x' % take('w'), # reloc count print '%4x' % take('w'), # line number count print '%8x' % take('t'), # flags + print + print 'Loading', + by_rva = '' + for name, offset, filesize, rva, memsize in section_table: + print name, + f.seek(offset) + section = f.read(filesize) + if len(section) <> filesize: raise 'Broken file' + # grow/shrink the section to memsize + section = section[:memsize] + section += '\0' * (memsize - len(section)) + if rva > len(by_rva): by_rva += '\0' * (rva - len(by_rva)) + by_rva = by_rva[:rva] + section + by_rva[rva + memsize:] + print + print 'len(by_rva) = 0x%08x' % len(by_rva) + def string_by_rva (loc): + stop = by_rva.index('\0', loc) + return by_rva[loc:stop] + print '=== Import table: 0x%08x bytes at 0x%08x ===' % (imports_size, imports_rva) + i = imports_rva + hint_name, timestamp, fwdr_chain, dll_name, first_thunk = \ + struct.unpack('<LLLLL', by_rva[i:i + 20]) + i += 20 + while hint_name <> 0 or timestamp <> 0 or fwdr_chain <> 0 or \ + dll_name <> 0 or first_thunk <> 0: + print 'Hint/name table: 0x%08x' % hint_name + print 'Timestamp: %i (%s)' % \ + (timestamp, time.strftime('%Y-%m-%d %H:%M:%S GMT', + time.gmtime(timestamp))) + print 'Forwarder chain: 0x%08x' % fwdr_chain + print 'DLL name: 0x%08x %r' % (dll_name, string_by_rva(dll_name)) + print 'First thunk: 0x%08x' % first_thunk + print 'Hint name array:' + h = hint_name + herva, = struct.unpack('<L', by_rva[h:h + 4]); h += 4 + while herva <> 0: + exord, = struct.unpack('<H', by_rva[herva:herva + 2]) + print ' [%08x] %04x %r' % (herva, exord, + string_by_rva(herva + 2)) + herva, = struct.unpack('<L', by_rva[h:h + 4]); h += 4 + print 'Thunk array:' + t = first_thunk + terva, = struct.unpack('<L', by_rva[t:t + 4]); t += 4 + while terva <> 0: + exord, = struct.unpack('<H', by_rva[terva:terva + 2]) + print ' [%08x] %04x %r' % (terva, exord, + string_by_rva(terva + 2)) + terva, = struct.unpack('<L', by_rva[t:t + 4]); t += 4 + + hint_name, timestamp, fwdr_chain, dll_name, first_thunk = \ + struct.unpack('<LLLLL', by_rva[i:i + 20]) + i += 20 print else: print 'Usage: pedump.py file ...' |
From: <di...@us...> - 2003-04-15 15:44:14
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv15322 Modified Files: tran.py Log Message: added the |dup any| word Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- tran.py 14 Apr 2003 22:24:00 -0000 1.8 +++ tran.py 15 Apr 2003 15:44:09 -0000 1.9 @@ -75,6 +75,8 @@ Regstack.append(long(reg[-1])) def swap (x, y): Regstack.append(y); Regstack.append(x) +def dup (x): + Regstack.append(x); Regstack.append(x) def colon_macro (name): global State, Regstack, current_recordee if len(Regstack) > 2: raise 'too long argument pattern', Regstack @@ -216,6 +218,7 @@ 'reg': ('simple', Generic_Register), 'sum': ('simple', ClassMarker('sum')), 'swap any any': ('builtin', swap, 2), + 'dup any': ('builtin', dup, 1), 't, lit': ('builtin', t_comma, 1), } current_recordee = None |
From: <di...@us...> - 2003-04-15 00:50:42
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv26114 Modified Files: pedump.py Log Message: parse even more of PE headers Index: pedump.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/pedump.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pedump.py 14 Apr 2003 23:44:01 -0000 1.2 +++ pedump.py 15 Apr 2003 00:50:38 -0000 1.3 @@ -60,7 +60,8 @@ 0x0284: 'Alpha AXP 64-bit', 0x0366: 'Mips with FPU', 0x0466: 'Mips 16 with FPU'}) - print 'Section count: %i' % take('w') + section_count = take('w') + print 'Section count: %i' % section_count timestamp = take('t') print 'Timestamp: %i (%s)' % \ (timestamp, time.strftime('%Y-%m-%d %H:%M:%S GMT', @@ -102,5 +103,56 @@ take('t') # reserved print 'Size of image: 0x%08x headers: 0x%08x' % take('tt') print 'Checksum: 0x%08x' % take('t') + state_enum('Subsystem', take('w'), { + 0: 'unknown', + 1: 'native', + 2: 'Windows GUI', + 3: 'Windows character', + 5: 'OS/2 character', + 7: 'POSIX character', + 9: 'Windows CE GUI'}) + print 'DLL characteristics: 0x%04x' % take('w') + print 'Stack size: reserve 0x%08x commit 0x%08x' % take('tt') + print 'Heap size: reserve 0x%08x commit 0x%08x' % take('tt') + print 'Loader flags (obsolete?) 0x%08x' % take('t') + dict_entries = take('t') + print 'Dictionary entry count: %i' % dict_entries + shtable_ofs = f.tell() + dict_entries * 8 + print ' ======== ========' + print '00. Export table: %08x %08x' % take('tt') + print '01. Import table: %08x %08x' % take('tt') + print '02. Resource table: %08x %08x' % take('tt') + print '03. Exception table: %08x %08x' % take('tt') + print '04. Certificate table: %08x %08x' % take('tt') + print '05. Base relocation table: %08x %08x' % take('tt') + print '06. Debug: %08x %08x' % take('tt') + print '07. Architecture specific: %08x %08x' % take('tt') + print '08. Global pointer: %08x %08x' % take('tt') + print '09. TLS table: %08x %08x' % take('tt') + print '10. Load config table: %08x %08x' % take('tt') + print '11. Bound import table: %08x %08x' % take('tt') + print '12. Import address table: %08x %08x' % take('tt') + print '13. Delay import descriptor: %08x %08x' % take('tt') + print '14. COM+ runtime header: %08x %08x' % take('tt') + print '15. (reserved) %08x %08x' % take('tt') + print + print 'Section table' + f.seek(shtable_ofs) + print 'name memsz RVA filesz offset !rel !ln #rel #ln flags' + print '======== ====== ====== ====== ====== ==== ==== ==== ==== ========' + for i in range(section_count): + name = f.read(8) + while '\0' in name: name = name[:-1] + print '%-8s' % name, + print '%6x' % take('t'), # memory size + print '%6x' % take('t'), # RVA + print '%6x' % take('t'), # file size + print '%6x' % take('t'), # offset + print '%4x' % take('t'), # reloc offset + print '%4x' % take('t'), # line number data offset + print '%4x' % take('w'), # reloc count + print '%4x' % take('w'), # line number count + print '%8x' % take('t'), # flags + print else: print 'Usage: pedump.py file ...' |
From: <di...@us...> - 2003-04-15 00:14:30
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv14967 Modified Files: elfdump.py Log Message: cleanup Index: elfdump.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elfdump.py,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- elfdump.py 15 Apr 2003 00:08:16 -0000 1.8 +++ elfdump.py 15 Apr 2003 00:14:22 -0000 1.9 @@ -13,7 +13,6 @@ from bindump import * from elf import * import bindump -import struct import sys args = sys.argv[1:] @@ -119,11 +118,8 @@ print 'No type flags addr offset size link info align each' print '== ==== ======== ======== ====== ====== ==== ==== ===== ====' for i in range(e_shnum): - shentry = f.read(e_shentsize) - sh_name, sh_type, sh_flags, sh_addr, sh_offset, sh_size, \ - sh_link, sh_info, sh_addralign, sh_entsize = \ - struct.unpack(bytesex + ' 10L', shentry[0:40]) print '%2x' % i, + sh_name = take('t') try: print {SHT.NULL: 'null', SHT.PROGBITS: 'prog', SHT.SYMTAB: 'symt', @@ -142,21 +138,22 @@ SHT.GROUP: 'grou', SHT.GNU_verdef: 'verd', SHT.GNU_verneed: 'vern', - SHT.GNU_versym: 'vers'}[sh_type], + SHT.GNU_versym: 'vers'}[take('t')], except: print '%4x' % sh_type, - flags_shortly('oism?xaw', sh_flags) - print '%8x' % sh_addr, - print '%6x' % sh_offset, - print '%6x' % sh_size, - print '%4x' % sh_link, - print '%4x' % sh_info, - print '%5x' % sh_addralign, - print '%4x' % sh_entsize, + flags_shortly('oism?xaw', take('t')) + print '%8x' % take('t'), + print '%6x' % take('t'), + print '%6x' % take('t'), + print '%4x' % take('t'), + print '%4x' % take('t'), + print '%5x' % take('t'), + print '%4x' % take('t'), if shstr <> None: name = asciiz(shstr, sh_name) if name == '': name = '0x%x' % sh_name print name, print + f.read(e_shentsize - 40) print else: print 'Usage: elfdump.py file ...' |
From: <di...@us...> - 2003-04-15 00:08:21
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv12836 Modified Files: elfdump.py Log Message: cleanup Index: elfdump.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elfdump.py,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- elfdump.py 15 Apr 2003 00:03:49 -0000 1.7 +++ elfdump.py 15 Apr 2003 00:08:16 -0000 1.8 @@ -88,28 +88,27 @@ print '== ==== ====== ======== ======== ====== ====== === =====' for i in range(e_phnum): - phentry = f.read(e_phentsize) - p_type, p_offset, p_vaddr, p_paddr, p_filesz, p_memsz, \ - p_flags, p_align = struct.unpack(bytesex + ' 8L', phentry[:32]) print '%2x' % i, - enum_shortly(4, p_type, {PT.NULL: 'null', - PT.LOAD: 'load', - PT.DYNAMIC: 'dyna', - PT.INTERP: 'inte', - PT.NOTE: 'note', - PT.SHLIB: 'shli', - PT.PHDR: 'phdr', - PT.TLS: 'tls '}) - print '%6x' % p_offset, - print '%8x' % p_vaddr, - print '%8x' % p_paddr, + enum_shortly(4, take('t'), {PT.NULL: 'null', + PT.LOAD: 'load', + PT.DYNAMIC: 'dyna', + PT.INTERP: 'inte', + PT.NOTE: 'note', + PT.SHLIB: 'shli', + PT.PHDR: 'phdr', + PT.TLS: 'tls '}) + print '%6x' % take('t'), + print '%8x' % take('t'), + print '%8x' % take('t'), + p_filesz, p_memsz = take('tt') if p_filesz > p_memsz: c = '>' elif p_filesz < p_memsz: c = '<' else: c = ' ' print '%6x%c%6x' % (p_filesz, c, p_memsz), - flags_shortly('rwx', p_flags) - print '%5x' % p_align, + flags_shortly('rwx', take('t')) + print '%5x' % take('t'), print + phentry = f.read(32 - e_phentsize) # skip unprocessed bytes print else: print 'No program header table' |
From: <di...@us...> - 2003-04-15 00:03:57
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv11332 Modified Files: elfdump.py Log Message: cleanup Index: elfdump.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elfdump.py,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- elfdump.py 14 Apr 2003 23:59:09 -0000 1.6 +++ elfdump.py 15 Apr 2003 00:03:49 -0000 1.7 @@ -54,8 +54,8 @@ e_shoff = take('t') print 'Processor-specific flags: [%08x]' % take('t') - e_ehsize, e_phentsize, e_phnum, e_shentsize = take('wwww') - print 'ELF header size: [%08x] bytes' % e_ehsize + print 'ELF header size: [%08x] bytes' % take('w') + e_phentsize, e_phnum, e_shentsize = take('www') print 'Program header table: %i entries at [%08x], 0x%x bytes each' % \ (e_phnum, e_phoff, e_phentsize) @@ -67,11 +67,9 @@ # load section header string table if e_shstrndx <> 0: - f.seek(e_shoff + e_shentsize * e_shstrndx) - shstrshent = f.read(e_shentsize) - if len(shstrshent) == e_shentsize >= 24: - shstr_ofs, = struct.unpack(bytesex + ' L', shstrshent[16:20]) - shstr_size, = struct.unpack(bytesex + ' L', shstrshent[20:24]) + f.seek(e_shoff + e_shentsize * e_shstrndx + 16) + if e_shentsize >= 24: + shstr_ofs, shstr_size = take('tt') f.seek(shstr_ofs) shstr = f.read(shstr_size) if len(shstr) <> shstr_size: |
From: <di...@us...> - 2003-04-14 23:59:13
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv9489 Modified Files: elfdump.py Log Message: cleanup Index: elfdump.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elfdump.py,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- elfdump.py 14 Apr 2003 23:56:42 -0000 1.5 +++ elfdump.py 14 Apr 2003 23:59:09 -0000 1.6 @@ -22,15 +22,15 @@ for filename in args: f = open(filename, 'r') def take (tpl): return ftake(f, tpl) - e_ident = f.read(6) print 'ELF header of %r:' % filename - print 'Magic: %r:' % e_ident[0:4] - state_enum('File class', ord(e_ident[4]), {1: '32-bit', 2: '64-bit'}) - state_enum('Data encoding', ord(e_ident[5]), { + print 'Magic: %r:' % f.read(4) + state_enum('File class', take('b'), {1: '32-bit', 2: '64-bit'}) + encoding = take('b') + state_enum('Data encoding', encoding, { 1: "2's complement LittleEndian", 2: "2's complement BigEndian"}) - if ord(e_ident[5]) == 1: bytesex = '<'; bindump.bytesex = '<' - elif ord(e_ident[5]) == 2: bytesex = '>'; bindump.bytesex = '>' + if encoding == 1: bytesex = '<'; bindump.bytesex = '<' + elif encoding == 2: bytesex = '>'; bindump.bytesex = '>' else: bytesex = ''; bindump.bytesex = '' state_enum('File version', take('b'), {1: 'current'}) print 'Padding bytes: %s' % shorthex(f.read(9)) @@ -52,9 +52,9 @@ state_enum('Object file version', e_version, {1: 'current'}) print 'Entry point: [%08x]' % e_entry - e_shoff, e_flags, e_ehsize, e_phentsize, e_phnum, e_shentsize = \ - take('ttwwww') - print 'Processor-specific flags: [%08x]' % e_flags + e_shoff = take('t') + print 'Processor-specific flags: [%08x]' % take('t') + e_ehsize, e_phentsize, e_phnum, e_shentsize = take('wwww') print 'ELF header size: [%08x] bytes' % e_ehsize print 'Program header table: %i entries at [%08x], 0x%x bytes each' % \ (e_phnum, e_phoff, e_phentsize) |
From: <di...@us...> - 2003-04-14 23:56:46
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv8711 Modified Files: elfdump.py bindump.py Log Message: cleanup Index: elfdump.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elfdump.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- elfdump.py 14 Apr 2003 23:47:50 -0000 1.4 +++ elfdump.py 14 Apr 2003 23:56:42 -0000 1.5 @@ -10,10 +10,11 @@ from __future__ import nested_scopes -import sys -import struct from bindump import * from elf import * +import bindump +import struct +import sys args = sys.argv[1:] @@ -21,18 +22,18 @@ for filename in args: f = open(filename, 'r') def take (tpl): return ftake(f, tpl) - e_ident = f.read(16) + e_ident = f.read(6) print 'ELF header of %r:' % filename print 'Magic: %r:' % e_ident[0:4] state_enum('File class', ord(e_ident[4]), {1: '32-bit', 2: '64-bit'}) state_enum('Data encoding', ord(e_ident[5]), { 1: "2's complement LittleEndian", 2: "2's complement BigEndian"}) - if ord(e_ident[5]) == 1: bytesex = '<' - elif ord(e_ident[5]) == 2: bytesex = '>' - else: bytesex = '' - state_enum('File version', ord(e_ident[6]), {1: 'current'}) - print 'Padding bytes: %0r' % e_ident[7:] + if ord(e_ident[5]) == 1: bytesex = '<'; bindump.bytesex = '<' + elif ord(e_ident[5]) == 2: bytesex = '>'; bindump.bytesex = '>' + else: bytesex = ''; bindump.bytesex = '' + state_enum('File version', take('b'), {1: 'current'}) + print 'Padding bytes: %s' % shorthex(f.read(9)) e_type, e_machine, e_version, e_entry, e_phoff = take('wwttt') state_enum('Object file type', e_type, { Index: bindump.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/bindump.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- bindump.py 14 Apr 2003 23:37:56 -0000 1.2 +++ bindump.py 14 Apr 2003 23:56:43 -0000 1.3 @@ -48,9 +48,11 @@ def shorthex (s): return ' '.join(['%02X' % ord(c) for c in s]) +bytesex = '' + def ftake (f, tpl): amount = 0 - struc = '<' + struc = bytesex for c in tpl: amount += {'b': 1, 'w': 2, 't': 4}[c] struc += {'b': 'B', 'w': 'H', 't': 'L'}[c] |
From: <di...@us...> - 2003-04-14 23:47:54
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv6233 Modified Files: elfdump.py Log Message: cleanup Index: elfdump.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elfdump.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- elfdump.py 14 Apr 2003 22:31:23 -0000 1.3 +++ elfdump.py 14 Apr 2003 23:47:50 -0000 1.4 @@ -20,6 +20,7 @@ if args: for filename in args: f = open(filename, 'r') + def take (tpl): return ftake(f, tpl) e_ident = f.read(16) print 'ELF header of %r:' % filename print 'Magic: %r:' % e_ident[0:4] @@ -33,8 +34,7 @@ state_enum('File version', ord(e_ident[6]), {1: 'current'}) print 'Padding bytes: %0r' % e_ident[7:] - e_type, e_machine, e_version, e_entry, e_phoff = \ - struct.unpack(bytesex + 'HHLLL', f.read(16)) + e_type, e_machine, e_version, e_entry, e_phoff = take('wwttt') state_enum('Object file type', e_type, { 1: 'relocatable', 2: 'executable', @@ -52,14 +52,13 @@ print 'Entry point: [%08x]' % e_entry e_shoff, e_flags, e_ehsize, e_phentsize, e_phnum, e_shentsize = \ - struct.unpack(bytesex + 'LLHHHH', f.read(16)) + take('ttwwww') print 'Processor-specific flags: [%08x]' % e_flags print 'ELF header size: [%08x] bytes' % e_ehsize print 'Program header table: %i entries at [%08x], 0x%x bytes each' % \ (e_phnum, e_phoff, e_phentsize) - e_shnum, e_shstrndx = \ - struct.unpack(bytesex + 'HH', f.read(4)) + e_shnum, e_shstrndx = take('ww') print 'Section header table: %i entries at [%08x], 0x%x bytes each' % \ (e_shnum, e_shoff, e_shentsize) print 'Section header strings in section #%i' % e_shstrndx |
From: <di...@us...> - 2003-04-14 23:44:04
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv4935 Modified Files: pedump.py Log Message: parse more of PE headers Index: pedump.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/pedump.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- pedump.py 14 Apr 2003 22:38:29 -0000 1.1 +++ pedump.py 14 Apr 2003 23:44:01 -0000 1.2 @@ -11,19 +11,96 @@ from __future__ import nested_scopes import sys -import struct +import time from bindump import * from elf import * +from types import * args = sys.argv[1:] if args: for filename in args: f = open(filename, 'r') - mz_magic, bytes_in_last_block, blocks_in_file = \ - struct.unpack('<HHH', f.read(6)) - print 'MZ magic: %04x' % mz_magic - print 'Bytes in last block: %04x' % bytes_in_last_block - print 'Blocks in file: %04x' % blocks_in_file + def take (tpl): return ftake(f, tpl) + print '=== MZ header ===' + print 'MZ magic: %r' % f.read(2) + bytes_in_last_block, blocks_in_file, reloc_count = take('www') + print '0x%04x blocks in file, last has 0x%04x bytes' % \ + (blocks_in_file, bytes_in_last_block) + print 'Header size: 0x%04x paragraphs' % take('w') + print 'Extra paragraphs needed: min 0x%04x, max 0x%04x' % take('ww') + print 'Initial SS:SP = %04x:%04x' % take('ww') + print 'Checksum: 0x%04x' % take('w') + ip, cs, reloc_ofs = take('www') + print 'Initial CS:IP = %04x:%04x' % (cs, ip) + print 'Relocation table: %i entries at [%04x]' % \ + (reloc_count, reloc_ofs) + f.seek(0x3C); ne_ofs = take('t') + print 'New EXE header at [%08x]' % ne_ofs + print '=== PE header ===' + f.seek(ne_ofs) + print 'PE magic: %r' % f.read(4) + state_enum('Target machine/a.out magic', take('w'), { + 0x0000: 'unknown or platform independent', + 0x014C: 'i80386', + 0x014D: 'i80486', + 0x014E: 'Pentium', + 0x0162: 'Mips Mark I (R2000, R3000)', + 0x0163: 'Mips Mark II (R6000)', + 0x0166: 'Mips Mark III (R4000)', + 0x0168: 'R10000', + 0x0184: 'Alpha AXP', + 0x01A2: 'Hitachi SH3', + 0x01A6: 'Hitachi SH4', + 0x01C0: 'ARM', + 0x01F0: 'PowerPC LittleEndian', + 0x0200: 'ia64', + 0x0266: 'Mips 16', + 0x0268: 'm68k', + 0x0284: 'Alpha AXP 64-bit', + 0x0366: 'Mips with FPU', + 0x0466: 'Mips 16 with FPU'}) + print 'Section count: %i' % take('w') + timestamp = take('t') + print 'Timestamp: %i (%s)' % \ + (timestamp, time.strftime('%Y-%m-%d %H:%M:%S GMT', + time.gmtime(timestamp))) + symbol_table, symbol_count = take('tt') + print 'Symbol table: %i entries at [%08x]' % \ + (symbol_count, symbol_table) + print 'Optional header size: 0x%04x bytes' % take('w') + print 'Characteristics:', + flags_shortly('?uds?iD3??ltSLxR', take('w')) + # Flags: + # R - relocations stripped + # x - is executable + # L - line numbers stripped + # S - local symbols stripped + # t - aggressively trim working set (?) + # l - app is large address aware + # 3 - machine is based on 32-bit word architecture + # D - debugging information stripped away + # i - if file on removable media, copy and run from swap (?) + # s - is a system file (?) + # d - is a DLL + # u - should only be run on uniprocessor systems + print '=== Optional (a.out) header ===' + state_enum('Optional header magic', take('w'), { + 0x010B: 'PE32', + 0x020B: 'PE32+'}) + print 'Linker version: %i.%i' % take('bb') + print 'Text size: 0x%08x Data size: 0x%08x BSS size: 0x%08x' % \ + take('ttt') + print 'Entry point (RVA): [%08x]' % take('t') + print 'Base of text segment: [%08x]' % take('t') + print 'Base of data segment: [%08x]' % take('t') + print 'Preferred image base address: [%08x]' % take('t') + print 'Alignment: memory 0x%08x file 0x%08x' % take('tt') + print 'OS version: %i.%i' % take('ww') + print 'Image version: %i.%i' % take('ww') + print 'Subsystem version: %i.%i' % take('ww') + take('t') # reserved + print 'Size of image: 0x%08x headers: 0x%08x' % take('tt') + print 'Checksum: 0x%08x' % take('t') else: print 'Usage: pedump.py file ...' |
From: <di...@us...> - 2003-04-14 23:38:00
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv2708 Modified Files: bindump.py Log Message: wrote shorthex and ftake Index: bindump.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/bindump.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- bindump.py 14 Apr 2003 22:31:23 -0000 1.1 +++ bindump.py 14 Apr 2003 23:37:56 -0000 1.2 @@ -11,6 +11,7 @@ from __future__ import nested_scopes import string +import struct def state_enum (field_name, value, dict): print '%s: %i' % (field_name, value), @@ -44,3 +45,15 @@ else: return all[start:stop] +def shorthex (s): + return ' '.join(['%02X' % ord(c) for c in s]) + +def ftake (f, tpl): + amount = 0 + struc = '<' + for c in tpl: + amount += {'b': 1, 'w': 2, 't': 4}[c] + struc += {'b': 'B', 'w': 'H', 't': 'L'}[c] + data = struct.unpack(struc, f.read(amount)) + if len(data) == 1: data, = data + return data |
From: <di...@us...> - 2003-04-14 22:38:33
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv12981 Added Files: pedump.py Log Message: introduced pedump.py --- NEW FILE: pedump.py --- #! /usr/bin/python #### pedump.py - parse PE data structures # # Copyleft © 2003 by Andres Soolo (di...@us...) # This file is licensed under the GNU GPL v2. If you # don't know what that means, please do read the GPL. # #### @(#) $Id: pedump.py,v 1.1 2003/04/14 22:38:29 digg Exp $ from __future__ import nested_scopes import sys import struct from bindump import * from elf import * args = sys.argv[1:] if args: for filename in args: f = open(filename, 'r') mz_magic, bytes_in_last_block, blocks_in_file = \ struct.unpack('<HHH', f.read(6)) print 'MZ magic: %04x' % mz_magic print 'Bytes in last block: %04x' % bytes_in_last_block print 'Blocks in file: %04x' % blocks_in_file else: print 'Usage: pedump.py file ...' |
From: <di...@us...> - 2003-04-14 22:31:27
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv10001 Modified Files: elfdump.py Added Files: bindump.py Log Message: extracted bindump.py from elfdump.py --- NEW FILE: bindump.py --- #! /usr/bin/python #### bindump.py - generic binary dumping routines # # Copyleft © 2003 by Andres Soolo (di...@us...) # This file is licensed under the GNU GPL v2. If you # don't know what that means, please do read the GPL. # #### @(#) $Id: bindump.py,v 1.1 2003/04/14 22:31:23 digg Exp $ from __future__ import nested_scopes import string def state_enum (field_name, value, dict): print '%s: %i' % (field_name, value), try: print '(' + dict[value] + ')' except: print '- INVALID' def enum_shortly (length, value, dict): try: print ('%%-%is' % length) % dict[value], except: print ('%%%ix' % length) % value, def flags_shortly (pattern, value): r = '' badp = 0 v = value for i in range(len(pattern)): if v & 1: c = pattern[-1 - i] if c == '-': badp = 1 r = c + r else: r = '-' + r v >>= 1 if v: badp = 1 if not badp: print r, else: print ('%%%ix' % len(pattern)) % value, def asciiz (all, start): stop = string.find(all, chr(0), start) if stop == -1: return all[start:] else: return all[start:stop] Index: elfdump.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elfdump.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- elfdump.py 12 Apr 2003 12:06:32 -0000 1.2 +++ elfdump.py 14 Apr 2003 22:31:23 -0000 1.3 @@ -11,43 +11,11 @@ from __future__ import nested_scopes import sys -import string import struct +from bindump import * from elf import * args = sys.argv[1:] - -def state_enum (field_name, value, dict): - print '%s: %i' % (field_name, value), - try: print '(' + dict[value] + ')' - except: print '- INVALID' - -def enum_shortly (length, value, dict): - try: print ('%%-%is' % length) % dict[value], - except: print ('%%%ix' % length) % value, - -def flags_shortly (pattern, value): - r = '' - badp = 0 - v = value - for i in range(len(pattern)): - if v & 1: - c = pattern[-1 - i] - if c == '-': badp = 1 - r = c + r - else: - r = '-' + r - v >>= 1 - if v: badp = 1 - if not badp: print r, - else: print ('%%%ix' % len(pattern)) % value, - -def asciiz (all, start): - stop = string.find(all, chr(0), start) - if stop == -1: - return all[start:] - else: - return all[start:stop] if args: for filename in args: |
From: <di...@us...> - 2003-04-14 22:24:08
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv6131 Modified Files: tran.py Log Message: less forcing Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- tran.py 14 Apr 2003 21:59:25 -0000 1.7 +++ tran.py 14 Apr 2003 22:24:00 -0000 1.8 @@ -256,7 +256,7 @@ raise 'Regstack not empty after parsing ended', Regstack binary = elf.make_ELF32_object(text = Text, data = Data, flags = 's') f = open(output_name, 'w') - binary.get_file(force = 1).tofile(f) + binary.get_file().tofile(f) f.close() main() |
From: <di...@us...> - 2003-04-14 22:19:59
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv4004 Modified Files: elf.py makehello.py Log Message: less forcing Index: elf.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elf.py,v retrieving revision 1.35 retrieving revision 1.36 diff -u -d -r1.35 -r1.36 --- elf.py 14 Apr 2003 01:57:52 -0000 1.35 +++ elf.py 14 Apr 2003 22:19:55 -0000 1.36 @@ -564,7 +564,10 @@ offset = binary.filesz() - if want_relocatable or p_flags == 0: + if p_flags == 0: + section.set_origin(0) + binary.place_symbol('&' + name, 0) + elif want_relocatable: section.set_origin(0) else: address = memory_boundary | (offset & 0xFFF) Index: makehello.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/makehello.py,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- makehello.py 14 Apr 2003 21:59:25 -0000 1.24 +++ makehello.py 14 Apr 2003 22:19:55 -0000 1.25 @@ -29,7 +29,7 @@ hello.dump() f = open('hello', 'w') -hello.get_file(force = 1).tofile(f) +hello.get_file().tofile(f) f.close() print 'Without symbols' @@ -37,7 +37,7 @@ hellowosym.dump() f = open('hellowosym', 'w') -hellowosym.get_file(force = 1).tofile(f) +hellowosym.get_file().tofile(f) f.close() print 'Relocatable' |
From: <di...@us...> - 2003-04-14 21:59:29
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv27914 Modified Files: linkie.py make-pe-exe.py makehello.py tran.py Log Message: made Linkie.get_file refuse emitting unlinked executables unless explicitly forced Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- linkie.py 14 Apr 2003 21:46:42 -0000 1.26 +++ linkie.py 14 Apr 2003 21:59:24 -0000 1.27 @@ -202,11 +202,12 @@ this._symbols[i] = symbol, value + delta this._origin_secondary = origin - def get_file (this): + def get_file (this, force = 0): """get_file() -> array of chars Returns a copy of the file image of the linkie. See also get_memory.""" - if this._unresolved_locals: raise 'Incomplete linkie', this + if this._unresolved_locals: raise 'incomplete linkie', this + if this._linker_notes and not force: raise 'unlinked linkie', this return this._binary[:] def get_memory (this): """get_memory() -> array of chars Index: make-pe-exe.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/make-pe-exe.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- make-pe-exe.py 14 Apr 2003 21:47:06 -0000 1.4 +++ make-pe-exe.py 14 Apr 2003 21:59:25 -0000 1.5 @@ -210,4 +210,4 @@ e.paste(None, make_pe_aout_header()) e.link() e.dump() -e.get_file().tofile(open('pehello.exe', 'w')) +e.get_file(force = 1).tofile(open('pehello.exe', 'w')) Index: makehello.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/makehello.py,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- makehello.py 13 Apr 2003 23:40:56 -0000 1.23 +++ makehello.py 14 Apr 2003 21:59:25 -0000 1.24 @@ -29,7 +29,7 @@ hello.dump() f = open('hello', 'w') -hello.get_file().tofile(f) +hello.get_file(force = 1).tofile(f) f.close() print 'Without symbols' @@ -37,7 +37,7 @@ hellowosym.dump() f = open('hellowosym', 'w') -hellowosym.get_file().tofile(f) +hellowosym.get_file(force = 1).tofile(f) f.close() print 'Relocatable' @@ -45,5 +45,5 @@ hellorel.dump() f = open('hellorel.o', 'w') -hellorel.get_file().tofile(f) +hellorel.get_file(force = 1).tofile(f) f.close() Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- tran.py 14 Apr 2003 14:15:00 -0000 1.6 +++ tran.py 14 Apr 2003 21:59:25 -0000 1.7 @@ -224,7 +224,6 @@ Macrostack = [] Registers = {Generic_Register: 'reg'} # for reverse translation - def get_token (): if Macrostack: tok = Macrostack[-1][1][Macrostack[-1][0]] @@ -257,7 +256,7 @@ raise 'Regstack not empty after parsing ended', Regstack binary = elf.make_ELF32_object(text = Text, data = Data, flags = 's') f = open(output_name, 'w') - binary.get_file().tofile(f) + binary.get_file(force = 1).tofile(f) f.close() main() |
From: <di...@us...> - 2003-04-14 21:47:10
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv23439 Modified Files: make-pe-exe.py Log Message: generate more of PE headers Index: make-pe-exe.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/make-pe-exe.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- make-pe-exe.py 1 Apr 2003 08:03:01 -0000 1.3 +++ make-pe-exe.py 14 Apr 2003 21:47:06 -0000 1.4 @@ -64,23 +64,150 @@ b.link() return b -p = make_mz_prefix('OS too broken') -p.get_file().tofile(open('pehello1.exe', 'w')) - -p = make_mz_prefix('OS too broken:(') -p.get_file().tofile(open('pehello2.exe', 'w')) - -p = make_mz_prefix('OS too broken :(') -p.get_file().tofile(open('pehello3.exe', 'w')) - -p = make_mz_prefix('! OS too broken!') -p.get_file().tofile(open('pehello4.exe', 'w')) - -p = make_mz_prefix('! OS too broken !') -p.get_file().tofile(open('pehello5.exe', 'w')) +def make_coff_header (): + h = Linkie('<') + h.align(4) + h.emit_wyde_sum(['#coff/magic']) + # Known magic values: + # 0x0000 unknown + # 0x014C i80386 + # 0x014D i80486 + # 0x014E Pentium + # 0x0162 Mips Mark I (R2000, R3000) + # 0x0163 Mips Mark II (R6000) + # 0x0166 Mips Mark III (R4000) + # 0x0168 R10000 + # 0x0184 Alpha AXP + # 0x01A2 Hitachi SH3 + # 0x01A6 Hitachi SH4 + # 0x01C0 ARM + # 0x01F0 PowerPC LittleEndian + # 0x0200 ia64 + # 0x0266 Mips 16 + # 0x0268 m68k + # 0x0284 Alpha AXP 64-bit + # 0x0366 Mips with FPU + # 0x0466 Mips 16 with FPU + h.emit_wyde_sum(['#coff/nscns']) + h.emit_tetra_sum(['#coff/timdat']) + h.emit_tetra_sum(['!coff/symptr']) + h.emit_tetra_sum(['#coff/nsyms']) + h.emit_wyde_sum(['#coff/opthdr']) + h.emit_wyde_sum(['#coff/flags']) + # Flags for PE: + # 0x0001 no relocations -- can only be loaded at the preferred address + # 0x0002 executable + # 0x0004 no COFF line number data + # 0x0008 no COFF local symbol entries + # 0x0010 aggressively trim working set (?) + # 0x0020 program is aware of addresses larger than 2Gi + # 0x0040 reserved + # 0x0200 debugging information stripped away + # 0x0400 if file on removable media, copy and run from swap (?) + # 0x1000 is a system program (?) + # 0x2000 library + # 0x4000 should only be run on uniprocessor machines + return h -p = make_mz_prefix('A very long message\nspanning several lines.') -p.get_file().tofile(open('pehello6.exe', 'w')) +def make_pe_aout_header (): + h = Linkie('<') + h.align(4) + # #aout/magic = 0x10B + h.emit_wyde_sum(['#aout/magic']) + h.emit_byte_sum(['#aout/linker-version-major']) + h.emit_byte_sum(['#aout/linker-version-minor']) + h.emit_tetra_sum(['#aout/text-size']) + h.emit_tetra_sum(['#aout/data-size']) + h.emit_tetra_sum(['#aout/bss-size']) + h.emit_tetra_sum(['%_entry']) + h.emit_tetra_sum(['!.text']) + h.emit_tetra_sum(['!.data']) # not present in PE32+ (?) + # #aout/image-base must be multiple of 64ki + h.emit_tetra_sum(['#aout/image-base']) + h.emit_tetra_sum(['#aout/memory-align']) + # #aout/file-align must be a power of 2 in range of [512 ... 64Ki] + h.emit_tetra_sum(['#aout/file-align']) + h.emit_wyde_sum(['#aout/os-version-major']) + h.emit_wyde_sum(['#aout/os-version-minor']) + h.emit_wyde_sum(['#aout/image-version-major']) + h.emit_wyde_sum(['#aout/image-version-minor']) + h.emit_wyde_sum(['#aout/subsys-version-major']) + h.emit_wyde_sum(['#aout/subsys-version-minor']) + h.emit_tetra(0) + # #aout/image-size must be a multiple of #aout/object-align + h.emit_tetra_sum(['#aout/image-size']) + h.emit_tetra_sum(['#aout/header-size']) + h.emit_tetra(0) # checksum + h.emit_wyde_sum(['#aout/subsys']) + # Known values for #aout/subsys + # 0x0000 - unknown + # 0x0001 - native + # 0x0002 - Windows GUI + # 0x0003 - Windows character + # 0x0005 - OS/2 character + # 0x0007 - POSIX character + # 0x0009 - Windows CE GUI + h.emit_wyde_sum(['#aout/dll-flags']) + # Known flags for #aout/dll-flags + # 0x0001 - per-process library initialization + # 0x0002 - per-process library termination + # 0x0004 - per-thread library initialization + # 0x0008 - per-thread library termination + # All others must be zero. + h.emit_tetra_sum(['#aout/stack-reserve-size']) + h.emit_tetra_sum(['#aout/stack-commit-size']) + h.emit_tetra_sum(['#aout/heap-reserve-size']) + h.emit_tetra_sum(['#aout/heap-commit-size']) + h.emit_tetra(0) # loader flags - obsolete + h.emit_tetra_sum(['#aout/dict-entry-count']) + h.emit_tetra_sum(['%export-table']) + h.emit_tetra_sum(['#export-table/size']) + h.emit_tetra_sum(['%import-table']) + h.emit_tetra_sum(['#import-table/size']) + h.emit_tetra_sum(['%resource-table']) + h.emit_tetra_sum(['#resource-table/size']) + h.emit_tetra_sum(['%exception-table']) + h.emit_tetra_sum(['#exception-table/size']) + h.emit_tetra_sum(['!certificate-table']) + h.emit_tetra_sum(['#certificate-table/size']) + h.emit_tetra_sum(['%base-relocation-table']) + h.emit_tetra_sum(['#base-relocation-table/size']) + h.emit_tetra_sum(['%debug-data']) + h.emit_tetra_sum(['#debug-data/size']) + h.emit_tetra_sum(['%architecture-specific']) + h.emit_tetra_sum(['#architecture-specific/size']) + h.emit_tetra_sum(['%global-pointer']) + h.emit_tetra(0) + h.emit_tetra_sum(['%thread-local-storage']) + h.emit_tetra_sum(['#thread-local-storage/size']) + h.emit_tetra_sum(['%load-config-table']) + h.emit_tetra_sum(['#load-config-table/size']) + h.emit_tetra_sum(['%bound-import-table']) + h.emit_tetra_sum(['#bound-import-table/size']) + h.emit_tetra_sum(['%import-address-table']) + h.emit_tetra_sum(['#import-address-table/size']) + h.emit_tetra_sum(['%delay-import-descriptor']) + h.emit_tetra_sum(['#delay-import-descriptor/size']) + h.emit_tetra_sum(['%COM+-runtime-header']) + h.emit_tetra_sum(['#COM+-runtime-header/size']) + h.emit_tetra(0); h.emit_tetra(0) # reserved + return h -p = make_mz_prefix('Many lines spanning several blocks in total.\n' * 40) -p.get_file().tofile(open('pehello7.exe', 'w')) +e = Linkie('<'); e.paste(0, make_mz_prefix('OS too broken')) +e.align(8) # PE header must be aligned to 8 +e.place_symbol('!pe') +e.emit_string('PE\0\0') +e.paste(None, make_coff_header()) +e.place_symbol('#coff/magic', 0x014C) # I386MAGIC +e.place_symbol('#coff/timdat', int(time.time())) +e.place_symbol('!coff/symptr', 0) +e.place_symbol('#coff/nsyms', 0) +e.place_symbol('#coff/opthdr', 0x00E0) +e.place_symbol('#coff/flags', 0x0002) +e.place_symbol('#aout/image-base', 0x00400000) +e.place_symbol('#aout/memory-align', 4096) +e.place_symbol('#aout/file-align', 512) +e.paste(None, make_pe_aout_header()) +e.link() +e.dump() +e.get_file().tofile(open('pehello.exe', 'w')) |
From: <di...@us...> - 2003-04-14 21:46:47
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv23275 Modified Files: linkie.py Log Message: added support for MS RVAs Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- linkie.py 14 Apr 2003 21:30:20 -0000 1.25 +++ linkie.py 14 Apr 2003 21:46:42 -0000 1.26 @@ -19,6 +19,7 @@ this._locals = [] # label no -> address this._unresolved_locals = [] # order is irrelevant this._origin = 0 # the base address of this linkie + this._origin_secondary = 0 # support MS-style RVAs (%foo symbols) if byte_order == '<': this.emit_wyde = this.emit_lewyde this.emit_tetra = this.emit_letetra @@ -84,7 +85,7 @@ else: # forwards this._unresolved_locals.append((a, size, len(this._binary))) elif type(a) == StringType: # global reference - if not a[0] in '#&!': + if not a[0] in '#&!%': raise 'unprefixed symbol being referred to', a this.notify_linker(this.memsz(), size, a) else: raise 'Invalid addend', a @@ -146,14 +147,14 @@ """place_symbol(symbol, value = None) => value Places a globally visible symbol in the linkie. Takes care of adding the base address if the symbol - starts in '&'. + starts in '&' or '%'. Does NOT check uniqueness. None signifies the current offset.""" if type(symbol) <> StringType: raise 'Not a string', symbol if not symbol[0] in '#&!': raise 'unprefixed symbol being placed', symbol if value == None: value = len(this._binary) + this._skipped - if symbol[0] == '&': value += this._origin + if symbol[0] in '&%': value += this._origin this._symbols.append((symbol, value)) return value def align (this, boundary): @@ -173,8 +174,8 @@ def set_origin (this, origin): """set_origin(origin) Sets the base address of the linkie to the specified value. - Recalculates the &foo symbols. Does NOT influence already - resolved references to changing labels, so be careful + Recalculates the &foo symbols. Does NOT influence + already resolved references to changing labels, so be careful if using after partial linkage.""" if (origin % this._alignment) != 0: raise 'New base address violates alignment', \ @@ -182,9 +183,24 @@ delta = origin - this._origin for i in range(len(this._symbols)): symbol, value = this._symbols[i] - if symbol[0] == '&': + if symbol[0] in '&': this._symbols[i] = symbol, value + delta this._origin = origin + def set_secondary_origin (this, origin): + """set_secondary_origin(origin) + Sets the secondary base address of the linkie to the specified + value. Recalculates the %foo symbols. Does NOT influence + already resolved references to changing labels, so be careful + if using after partial linkage.""" + if (origin % this._alignment) != 0: + raise 'New base address violates alignment', \ + (boundary, this._origin) + delta = origin - this._origin_secondary + for i in range(len(this._symbols)): + symbol, value = this._symbols[i] + if symbol[0] in '%': + this._symbols[i] = symbol, value + delta + this._origin_secondary = origin def get_file (this): """get_file() -> array of chars @@ -254,12 +270,7 @@ this._binary.extend(that._binary) this._skipped = that._skipped for sym, val in that._symbols: - if sym[0] in '#&!': - this._symbols.append((sym, val)) - else: - # FIXME: backwards compatibility - print 'WARNING: unprefixed symbol', sym - this._symbols.append((sym, val + delta)) + this._symbols.append((sym, val)) for ofs, typ, arg in that._linker_notes: this._linker_notes.append((ofs + delta, typ, arg)) return delta @@ -292,9 +303,9 @@ for sym, val in that._symbols: if sym[0] == '!': this._symbols.append((sym, val + thatofs)) - elif sym[0] in '#': + elif sym[0] == '#': this._symbols.append((sym, val)) - elif sym[0] in '&': + elif sym[0] in '&%': if not skip_addr: this._symbols.append((sym, val)) else: raise 'unprefixed symbol', sym @@ -334,6 +345,7 @@ rnotes = {}; othernotes = [] for sym, val in this._symbols: if sym[0] == '&': val -= this._origin + if sym[0] == '%': val -= this._origin_secondary if sym[0] != '#' and 0 <= val < this.memsz(): if rsymbols.has_key(val): rsymbols[val].append(sym) else: rsymbols[val] = [sym] |
From: <di...@us...> - 2003-04-14 21:30:25
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv16257 Modified Files: linkie.py Log Message: grammatical sugar for Linkie.paste Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- linkie.py 14 Apr 2003 00:52:40 -0000 1.24 +++ linkie.py 14 Apr 2003 21:30:20 -0000 1.25 @@ -274,7 +274,8 @@ if that._unresolved_locals: raise 'Incomplete linkie', that # provide sufficient padding - if offset < 0: this.align(- offset) + if offset == None: this.align(that.get_alignment()) + elif offset < 0: this.align(- offset) else: this.skip(offset - this.memsz()) # convert any padding to hard zeroes if needed |
From: <di...@us...> - 2003-04-14 14:15:06
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv12898 Modified Files: tran.py Log Message: simplified the Register class Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- tran.py 14 Apr 2003 02:09:39 -0000 1.5 +++ tran.py 14 Apr 2003 14:15:00 -0000 1.6 @@ -34,14 +34,16 @@ except: pass return tok -class _Register (tuple): +class Register (tuple): + def __new__ (cls, *args): + return tuple.__new__(cls, args) def parent (this): - if len(this): return _Register(this[:-1]) + if len(this): return apply(Register, this[:-1]) else: return None def child_generator (this): i = 0 while 1: - yield Register(this + (i,)) + yield apply(Register, this + (i,)) i += 1 def __repr__ (this): return 'Register' + tuple.__repr__(this) @@ -50,9 +52,6 @@ def __init__ (this, id): this.id = id -def Register (*args): - return _Register(args) - def b_comma (n): if type(n) == LongType: cursect.emit_byte(n) elif type(n) == StringType: cursect.emit_byte_sum([n]) @@ -109,7 +108,7 @@ elif type(object) == StringType: yield 'sym' yield 'lit' - elif isinstance(object, _Register): + elif isinstance(object, Register): while object <> None: yield Registers[object] object = object.parent() |
From: <di...@us...> - 2003-04-14 11:53:57
|
Update of /cvsroot/wisp/wisp/modules In directory sc8-pr-cvs1:/tmp/cvs-serv20908 Modified Files: Makefile.am unix.wim Added Files: unix.wid Log Message: generalized pipe-from to accept explicit file descriptors to be diverted --- NEW FILE: unix.wid --- #### unix.wid # # Copyleft © 2003 by Andres Soolo (di...@us...) # This file is licensed under the GNU GPL v2. If you # don't know what that means, please do read the GPL. # #### @(#) $Id: unix.wid,v 1.1 2003/04/14 11:53:53 digg Exp $ pipe-from (|pipe-from| /prog/ /option/ ...) => /port/ Invokes /prog/ by forking a new process that applies |dedicated| on it. The new process' standard output will be attached to the current process via a pipe. Returns a Wisp port wrapper for the pipe. The following /option/s are known: * ~divert-stderr~ -- if given, use dup2(2) to divert the new process' stderr as well as stdout to the /port/. * any integer -- all integers used as options will be treated as file descriptors to be attached to /port/. If any integer is specified, stdout (descriptor ~1~) will not attached to /port/ unless it's explicitly specified too. :Conforms to: Wisp extension. :See also: |pipe-to|, |dedicated|. Index: Makefile.am =================================================================== RCS file: /cvsroot/wisp/wisp/modules/Makefile.am,v retrieving revision 1.59 retrieving revision 1.60 diff -u -d -r1.59 -r1.60 --- Makefile.am 9 Feb 2003 16:43:01 -0000 1.59 +++ Makefile.am 14 Apr 2003 11:53:51 -0000 1.60 @@ -31,7 +31,7 @@ wid_DATA = builtin.wid help.wid help-et.wid \ files.wid getopt.wid ini.wid lists.wid locale.wid random.wid \ - strings.wid unicode.wid + strings.wid unicode.wid unix.wid wrti_DATA = ia32.wrti io.wrti linux.wrti universal.wrti wisptyp.wrti Index: unix.wim =================================================================== RCS file: /cvsroot/wisp/wisp/modules/unix.wim,v retrieving revision 1.45 retrieving revision 1.46 diff -u -d -r1.45 -r1.46 --- unix.wim 9 Feb 2003 15:41:38 -0000 1.45 +++ unix.wim 14 Apr 2003 11:53:53 -0000 1.46 @@ -74,21 +74,27 @@ (define (pipe-from proc . options) (let* ((pipe (sys:pipe)) (child (sys:fork)) - (divert-stderr? #f)) - (for-each - (lambda (option) - (case option - ((divert-stderr) (set! divert-stderr? #t)) - (else (raise 'pipe-from-option? option)))) - options) + (divert-fds '())) + (my divert-stderr? #f + (for-each + (lambda (option) + (case option + ((divert-stderr) (set! divert-stderr? #t)) + (integer? (cons! divert-fds option)) + (else (raise 'pipe-from-option? option)))) + options) + (if (null? divert-fds) + (set! divert-fds '(1))) ; stdout + (if divert-stderr? + (cons! divert-fds 2))) (if (zero? child) ; child (begin (sys:close (car pipe)) - (sys:dup2 (cdr pipe) 1) - (if divert-stderr? - (sys:dup2 (cdr pipe) 2)) - (sys:close (cdr pipe)) + (for-each (cut sys:dup2 (cdr pipe) <>) + divert-fds) + (if (not (memv (cdr pipe) divert-fds)) + (sys:close (cdr pipe))) (dedicated proc)) ; parent (begin |
From: <di...@us...> - 2003-04-14 02:09:42
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv28620 Modified Files: tran.py Log Message: added the |- int int| word Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- tran.py 14 Apr 2003 02:06:42 -0000 1.4 +++ tran.py 14 Apr 2003 02:09:39 -0000 1.5 @@ -97,6 +97,8 @@ State = state_regs def plus (a, b): Regstack.append(a + b) +def minus (a, b): + Regstack.append(a - b) def matchers (object): if isinstance(object, ClassMarker): @@ -199,6 +201,7 @@ MA_PREFIX = 010 Meaning = { '+ int int': ('builtin', plus, 2), + '- int int': ('builtin', minus, 2), '.data': ('builtin', dot_data, 0), '.text': ('builtin', dot_text, 0), ':macro': ('builtin', colon_macro, 0 | MA_PREFIX), |
From: <di...@us...> - 2003-04-14 02:06:45
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv26503 Modified Files: tran.py Log Message: added the |sum| class marker Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- tran.py 13 Apr 2003 08:47:50 -0000 1.3 +++ tran.py 14 Apr 2003 02:06:42 -0000 1.4 @@ -198,6 +198,7 @@ MA_ARGC = 007 MA_PREFIX = 010 Meaning = { + '+ int int': ('builtin', plus, 2), '.data': ('builtin', dot_data, 0), '.text': ('builtin', dot_text, 0), ':macro': ('builtin', colon_macro, 0 | MA_PREFIX), @@ -208,12 +209,12 @@ 'int': ('simple', ClassMarker('int')), 'label': ('builtin', label, 0 | MA_PREFIX), 'lit': ('simple', ClassMarker('lit')), + 'minor reg': ('builtin', minor, 1), 'ref': ('builtin', ref, 0 | MA_PREFIX), 'reg': ('simple', Generic_Register), + 'sum': ('simple', ClassMarker('sum')), 'swap any any': ('builtin', swap, 2), 't, lit': ('builtin', t_comma, 1), - 'minor reg': ('builtin', minor, 1), - '+ int int': ('builtin', plus, 2), } current_recordee = None current_register_family = 0 |