Advertisement
Guest User

Untitled

a guest
Jul 19th, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 5.05 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;;This program is distributed under the terms of the       ;;;
  3. ;;;GNU General Public License.                              ;;;
  4. ;;;Copyright (C) 2010 David Joseph Stith                    ;;;
  5. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6.  
  7. ;;;;;;;;;;;;;;;;;;
  8. ;;; ELF Header ;;;
  9. ;;;;;;;;;;;;;;;;;;
  10. (define dynstr-names '())
  11. (define (dynstr-index name)
  12.   (define (lookup i names)
  13.     (cond
  14.       ((null? names)
  15.        (set! dynstr-names (cons name dynstr-names))
  16.        i)
  17.       ((string=? name (car names)) (display (car names)) i)
  18.       (else (lookup (+ i (string-length (car names)) 1) (cdr names)))))
  19.   (lookup 1 (reverse dynstr-names)))
  20.  
  21. (bytes
  22.   #x7f #\E #\L #\F ;ELF identification
  23.   1  ;32bit
  24.   1  ;Little endian
  25.   1  ;File version
  26.   0  ;System V ABI
  27.   0  ;ABI version
  28.   0 0 0 0 0 0 0)
  29. (wyde 2)      ;Object File Type (Executable)
  30. (wyde 3)      ;Architecture (Intel 386)
  31. (tetras 1     ;ELF Version (Current)
  32.        'start ;Entry Point
  33.        (file-offset 'program_header) ;Program Header File Offset
  34.        (file-offset 'section_table_start) ;Section Table File Offset
  35.        0)     ;Processor-specific Flags
  36. (wydes (file-offset 'program_header)   ;ELF Header Size
  37.        #x20   ;Program Header Table Entry Size
  38.        (if LIBDL 4 2) ;Program Header Table Entry Count
  39.        #x28   ;Section Header Table Entry Size
  40.        0      ;Section Header Table Entry Count
  41.        0)     ;Section Header String Table Index
  42. ;;
  43. ;;Program header table
  44. ;;
  45. (: 'program_header)
  46. (if LIBDL
  47.   (begin
  48. ;;;INTERP entry
  49.     (tetras
  50.         3                ;Segment Type (PT_INTERP)
  51.         (file-offset 'interp) ;Segment File Offset
  52.         (lookup 'interp) ;Segment Virtual Address
  53.         0                ;Segment Physical Address (Ignored)
  54.         (- (lookup 'interp_end) (lookup 'interp)) ;Segment File Size
  55.         (- (lookup 'interp_end) (lookup 'interp)) ;Segment Memory Size
  56.         4                ;Segment Flags (read)
  57.         #x1000           ;Segment Alignment
  58.         )
  59. ;;;DYNAMIC entry
  60.     (tetras
  61.         2                ;Segment Type (PT_DYNAMIC)
  62.         (file-offset 'dynamic) ;Segment File Offset
  63.         (lookup 'dynamic) ;Segment Virtual Address
  64.         0                ;Segment Physical Address (Ignored)
  65.         (- (lookup 'dynamic_end) (lookup 'dynamic)) ;Segment File Size
  66.         (- (lookup 'dynamic_end) (lookup 'dynamic)) ;Segment Memory Size
  67.         6                ;Segment Flags (read+write)
  68.         #x1000           ;Segment Alignment
  69.         )))
  70.  
  71. ;;;TEXT entry
  72. (tetras 1                ;Segment Type (PT_LOAD)
  73.         0                ;Segment File Offset
  74.         x86-text-start   ;Segment Virtual Address
  75.         0                ;Segment Physical Address (Ignored)
  76.         (- x86-data-start x86-text-start) ;Segment File Size
  77.         (- x86-data-start x86-text-start) ;Segment Memory Size
  78.         5                ;Segment Flags (read+execute)
  79.         #x1000           ;Segment Alignment
  80.         )
  81. ;;;DATA entry
  82. (tetras 1                ;Segment Type (PT_LOAD)
  83.         (- x86-data-start x86-text-start) ;Segment File Offset
  84.         x86-data-start ;Segment Virtual Address
  85.         0                ;Segment Physical Address (Ignored)
  86.         (- x86-bss-start x86-data-start) ;Segment File Size
  87.         (- x86-bss-end x86-data-start) ;Segment Memory Size
  88.         7                ;Segment Flags (read+write+execute)
  89.         #x1000           ;Segment Alignment
  90.         )
  91. ;;
  92. ;;Section table
  93. ;;
  94. (: 'section_table_start)
  95. (tetras 0 0 0 0 0 0 0 0 0 0) ;Nevermind
  96.  
  97. (: 'hash)
  98.   (tetras 1 5 0 1 2 3 4 0)
  99.  
  100. (define dynamic_sym 1)
  101. (define dlopen_sym 2)
  102. (define dlclose_sym 3)
  103. (define dlsym_sym 4)
  104. (if LIBDL
  105.  (begin
  106.   ;;
  107.   ;;DYNAMIC Segment
  108.   ;;
  109.   (: 'dynamic)
  110.   (tetras 1 (dynstr-index LIBDL)) ;DT_NEEDED
  111.   (tetras 4 'hash)      ;DT_HASH
  112.   (tetras 5 'dynstr)    ;DT_STRTAB
  113.   (tetras 6 'dynsym)    ;DT_SYMTAB
  114.   (tetras 10 (- (lookup 'dynstr_end) (lookup 'dynstr))) ;DT_STRSZ
  115.   (tetras 11 #x10)      ;DT_SYMENT
  116.   (tetras 17 'reltext)  ;DT_REL
  117.   (tetras 18 (- (lookup 'reltext_end) (lookup 'reltext)));DT_RELSZ
  118.   (tetras 19 #x08)      ;DT_RELENT
  119.   (: 'dynamic_end)
  120.   (: 'dynsym)
  121.   (tetras 0 0 0)(wydes 0 0)
  122.   (tetras (dynstr-index "_DYNAMIC") 'dynamic 0)
  123.   (wydes #x11   ;STB_GLOBAL+STT_OBJECT
  124.          #xfff1);SHN_ABS
  125.   (tetras (dynstr-index "dlopen") 0 0)
  126.   (wydes #x22   ;STB_WEAK+STT_FUNC
  127.          0)
  128.   (tetras (dynstr-index "dlclose") 0 0)
  129.   (wydes #x22   ;STB_WEAK+STT_FUNC
  130.          0)
  131.   (tetras (dynstr-index "dlsym") 0 0)
  132.   (wydes #x22   ;STB_WEAK+STT_FUNC
  133.          0)
  134.   (: 'reltext)
  135.   (tetra 'dlopen_rel)
  136.   (byte 1) ;R_386_32
  137.   (byte dlopen_sym)
  138.   (wyde 0)
  139.  
  140.   (tetra 'dlclose_rel)
  141.   (byte 1) ;R_386_32
  142.   (byte dlclose_sym)
  143.   (wyde 0)
  144.  
  145.   (tetra 'dlsym_rel)
  146.   (byte 1) ;R_386_32
  147.   (byte dlsym_sym)
  148.   (wyde 0)
  149.   (: 'reltext_end)
  150.  
  151.   (: 'dynstr)
  152.   (byte 0)
  153.   (for-each asciz (reverse dynstr-names))
  154.   (: 'dynstr_end)
  155.  
  156.   ;;
  157.   ;;INTERP Segment
  158.   ;;
  159.   (: 'interp)
  160.   (asciz "/lib/ld-linux.so.2")
  161.   (: 'interp_end)))
  162. (align 8)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement