Subversion Repositories Kolibri OS

Rev

Rev 1115 | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. ; flat assembler core
  3. ; Copyright (c) 1999-2009, Tomasz Grysztar.
  4. ; All rights reserved.
  5.  
  6. formatter:
  7.         mov     [current_offset],edi
  8.         cmp     [output_file],0
  9.         jne     output_path_ok
  10.         mov     esi,[input_file]
  11.         mov     edi,[free_additional_memory]
  12.       copy_output_path:
  13.         lods    byte [esi]
  14.         cmp     edi,[structures_buffer]
  15.         jae     out_of_memory
  16.         stos    byte [edi]
  17.         or      al,al
  18.         jnz     copy_output_path
  19.         dec     edi
  20.         mov     eax,edi
  21.       find_extension:
  22.         dec     eax
  23.         cmp     eax,[free_additional_memory]
  24.         jb      extension_found
  25.         cmp     byte [eax],'\'
  26.         je      extension_found
  27.         cmp     byte [eax],'/'
  28.         je      extension_found
  29.         cmp     byte [eax],'.'
  30.         jne     find_extension
  31.         mov     edi,eax
  32.       extension_found:
  33.         lea     eax,[edi+9]
  34.         cmp     eax,[structures_buffer]
  35.         jae     out_of_memory
  36.         cmp     [file_extension],0
  37.         jne     extension_specified
  38.         cmp     [output_format],2
  39.         je      exe_extension
  40.         jb      bin_extension
  41.         cmp     [output_format],4
  42.         je      obj_extension
  43.         cmp     [output_format],5
  44.         je      o_extension
  45.         cmp     [output_format],3
  46.         jne     no_extension
  47.         cmp     [subsystem],1
  48.         je      sys_extension
  49.         cmp     [subsystem],10
  50.         jae     efi_extension
  51.         bt      [format_flags],8
  52.         jnc     exe_extension
  53.         mov     eax,'.dll'
  54.         jmp     make_extension
  55.       sys_extension:
  56.         mov     eax,'.sys'
  57.         jmp     make_extension
  58.       efi_extension:
  59.         mov     eax,'.efi'
  60.         jmp     make_extension
  61.       bin_extension:
  62.         mov     eax,'.bin'
  63.         bt      [format_flags],0
  64.         jnc     make_extension
  65.         mov     eax,'.com'
  66.         jmp     make_extension
  67.       obj_extension:
  68.         mov     eax,'.obj'
  69.         jmp     make_extension
  70.       o_extension:
  71.         mov     eax,'.o'
  72.         bt      [format_flags],0
  73.         jnc     make_extension
  74.       no_extension:
  75.         xor     eax,eax
  76.         jmp     make_extension
  77.       exe_extension:
  78.         mov     eax,'.exe'
  79.       make_extension:
  80.         xchg    eax,[edi]
  81.         scas    dword [edi]
  82.         mov     byte [edi],0
  83.         scas    byte [edi]
  84.         mov     esi,edi
  85.         stos    dword [edi]
  86.         sub     edi,9
  87.         xor     eax,eax
  88.         mov     ebx,characters
  89.       adapt_case:
  90.         mov     al,[esi]
  91.         or      al,al
  92.         jz      adapt_next
  93.         xlat    byte [ebx]
  94.         cmp     al,[esi]
  95.         je      adapt_ok
  96.         sub     byte [edi],20h
  97.       adapt_ok:
  98.         inc     esi
  99.       adapt_next:
  100.         inc     edi
  101.         cmp     byte [edi],0
  102.         jne     adapt_case
  103.         jmp     extension_ok
  104.       extension_specified:
  105.         mov     al,'.'
  106.         stos    byte [edi]
  107.         mov     esi,[file_extension]
  108.       copy_extension:
  109.         lods    byte [esi]
  110.         stos    byte [edi]
  111.         test    al,al
  112.         jnz     copy_extension
  113.         dec     edi
  114.       extension_ok:
  115.         mov     esi,edi
  116.         lea     ecx,[esi+1]
  117.         sub     ecx,[free_additional_memory]
  118.         mov     edi,[structures_buffer]
  119.         dec     edi
  120.         std
  121.         rep     movs byte [edi],[esi]
  122.         cld
  123.         inc     edi
  124.         mov     [structures_buffer],edi
  125.         mov     [output_file],edi
  126.       output_path_ok:
  127.         cmp     [symbols_file],0
  128.         je      labels_table_ok
  129.         mov     ecx,[memory_end]
  130.         sub     ecx,[labels_list]
  131.         mov     edi,[display_buffer]
  132.         sub     edi,8
  133.         mov     [edi],ecx
  134.         or      dword [edi+4],-1
  135.         sub     edi,ecx
  136.         cmp     edi,[current_offset]
  137.         jbe     out_of_memory
  138.         mov     [display_buffer],edi
  139.         mov     esi,[memory_end]
  140.       copy_labels:
  141.         sub     esi,32
  142.         cmp     esi,[labels_list]
  143.         jb      labels_table_ok
  144.         mov     ecx,32 shr 2
  145.         rep     movs dword [edi],[esi]
  146.         sub     esi,32
  147.         jmp     copy_labels
  148.       labels_table_ok:
  149.         mov     edi,[current_offset]
  150.         cmp     [output_format],4
  151.         je      coff_formatter
  152.         cmp     [output_format],5
  153.         jne     common_formatter
  154.         bt      [format_flags],0
  155.         jnc     elf_formatter
  156.       common_formatter:
  157.         mov     eax,edi
  158.         sub     eax,[code_start]
  159.         mov     [real_code_size],eax
  160.         cmp     edi,[undefined_data_end]
  161.         jne     calculate_code_size
  162.         mov     edi,[undefined_data_start]
  163.       calculate_code_size:
  164.         mov     [current_offset],edi
  165.         sub     edi,[code_start]
  166.         mov     [code_size],edi
  167.         mov     [written_size],0
  168.         mov     edx,[output_file]
  169.         call    create
  170.         jc      write_failed
  171.         cmp     [output_format],3
  172.         jne     stub_written
  173.         mov     edx,[code_start]
  174.         mov     ecx,[stub_size]
  175.         sub     edx,ecx
  176.         add     [written_size],ecx
  177.         call    write
  178.       stub_written:
  179.         cmp     [output_format],2
  180.         jne     write_output
  181.         call    write_mz_header
  182.       write_output:
  183.         call    write_code
  184.       output_written:
  185.         call    close
  186.         cmp     [symbols_file],0
  187.         jne     dump_symbols
  188.         ret
  189.       write_code:
  190.         mov     eax,[written_size]
  191.         mov     [headers_size],eax
  192.         mov     edx,[code_start]
  193.         mov     ecx,[code_size]
  194.         add     [written_size],ecx
  195.         lea     eax,[edx+ecx]
  196.         call    write
  197.         jc      write_failed
  198.         ret
  199. format_directive:
  200.         cmp     edi,[code_start]
  201.         jne     unexpected_instruction
  202.         cmp     [virtual_data],0
  203.         jne     unexpected_instruction
  204.         cmp     [output_format],0
  205.         jne     unexpected_instruction
  206.         lods    byte [esi]
  207.         cmp     al,17h
  208.         je      format_prefix
  209.         cmp     al,18h
  210.         jne     invalid_argument
  211.         lods    byte [esi]
  212.       select_format:
  213.         mov     dl,al
  214.         shr     al,4
  215.         mov     [output_format],al
  216.         and     edx,0Fh
  217.         or      [format_flags],edx
  218.         cmp     al,2
  219.         je      format_mz
  220.         cmp     al,3
  221.         je      format_pe
  222.         cmp     al,4
  223.         je      format_coff
  224.         cmp     al,5
  225.         je      format_elf
  226.       format_defined:
  227.         cmp     byte [esi],86h
  228.         jne     instruction_assembled
  229.         cmp     word [esi+1],'('
  230.         jne     invalid_argument
  231.         mov     eax,[esi+3]
  232.         add     esi,3+4
  233.         mov     [file_extension],esi
  234.         lea     esi,[esi+eax+1]
  235.         jmp     instruction_assembled
  236.       format_prefix:
  237.         lods    byte [esi]
  238.         mov     ah,al
  239.         lods    byte [esi]
  240.         cmp     al,18h
  241.         jne     invalid_argument
  242.         lods    byte [esi]
  243.         mov     edx,eax
  244.         shr     dl,4
  245.         shr     dh,4
  246.         cmp     dl,dh
  247.         jne     invalid_argument
  248.         or      al,ah
  249.         jmp     select_format
  250. entry_directive:
  251.         bts     [format_flags],10h
  252.         jc      setting_already_specified
  253.         mov     al,[output_format]
  254.         cmp     al,2
  255.         je      mz_entry
  256.         cmp     al,3
  257.         je      pe_entry
  258.         cmp     al,5
  259.         jne     illegal_instruction
  260.         bt      [format_flags],0
  261.         jc      elf_entry
  262.         jmp     illegal_instruction
  263. stack_directive:
  264.         bts     [format_flags],11h
  265.         jc      setting_already_specified
  266.         mov     al,[output_format]
  267.         cmp     al,2
  268.         je      mz_stack
  269.         cmp     al,3
  270.         je      pe_stack
  271.         jmp     illegal_instruction
  272. heap_directive:
  273.         bts     [format_flags],12h
  274.         jc      setting_already_specified
  275.         mov     al,[output_format]
  276.         cmp     al,2
  277.         je      mz_heap
  278.         cmp     al,3
  279.         je      pe_heap
  280.         jmp     illegal_instruction
  281. segment_directive:
  282.         cmp     [virtual_data],0
  283.         jne     illegal_instruction
  284.         mov     al,[output_format]
  285.         cmp     al,2
  286.         je      mz_segment
  287.         cmp     al,5
  288.         je      elf_segment
  289.         jmp     illegal_instruction
  290. section_directive:
  291.         cmp     [virtual_data],0
  292.         jne     illegal_instruction
  293.         mov     al,[output_format]
  294.         cmp     al,3
  295.         je      pe_section
  296.         cmp     al,4
  297.         je      coff_section
  298.         cmp     al,5
  299.         je      elf_section
  300.         jmp     illegal_instruction
  301. public_directive:
  302.         mov     al,[output_format]
  303.         cmp     al,4
  304.         je      public_allowed
  305.         cmp     al,5
  306.         jne     illegal_instruction
  307.         bt      [format_flags],0
  308.         jc      illegal_instruction
  309.       public_allowed:
  310.         mov     [base_code],0C0h
  311.         lods    byte [esi]
  312.         cmp     al,2
  313.         je      public_label
  314.         cmp     al,1Dh
  315.         jne     invalid_argument
  316.         lods    byte [esi]
  317.         and     al,7
  318.         add     [base_code],al
  319.         lods    byte [esi]
  320.         cmp     al,2
  321.         jne     invalid_argument
  322.       public_label:
  323.         lods    dword [esi]
  324.         cmp     eax,0Fh
  325.         jb      invalid_use_of_symbol
  326.         je      reserved_word_used_as_symbol
  327.         mov     dx,[current_pass]
  328.         mov     [eax+18],dx
  329.         or      byte [eax+8],8
  330.         inc     esi
  331.         mov     ebx,[free_additional_memory]
  332.         lea     edx,[ebx+10h]
  333.         cmp     edx,[structures_buffer]
  334.         jae     out_of_memory
  335.         mov     [free_additional_memory],edx
  336.         mov     [ebx+8],eax
  337.         mov     eax,[current_line]
  338.         mov     [ebx+0Ch],eax
  339.         lods    byte [esi]
  340.         cmp     al,86h
  341.         jne     invalid_argument
  342.         lods    word [esi]
  343.         cmp     ax,'('
  344.         jne     invalid_argument
  345.         mov     [ebx+4],esi
  346.         lods    dword [esi]
  347.         lea     esi,[esi+eax+1]
  348.         mov     al,[base_code]
  349.         mov     [ebx],al
  350.         jmp     instruction_assembled
  351. extrn_directive:
  352.         mov     al,[output_format]
  353.         cmp     al,4
  354.         je      extrn_allowed
  355.         cmp     al,5
  356.         jne     illegal_instruction
  357.         bt      [format_flags],0
  358.         jc      illegal_instruction
  359.       extrn_allowed:
  360.         lods    word [esi]
  361.         cmp     ax,'('
  362.         jne     invalid_argument
  363.         mov     ebx,esi
  364.         lods    dword [esi]
  365.         lea     esi,[esi+eax+1]
  366.         mov     edx,[free_additional_memory]
  367.         lea     eax,[edx+0Ch]
  368.         cmp     eax,[structures_buffer]
  369.         jae     out_of_memory
  370.         mov     [free_additional_memory],eax
  371.         mov     byte [edx],80h
  372.         mov     [edx+4],ebx
  373.         lods    byte [esi]
  374.         cmp     al,86h
  375.         jne     invalid_argument
  376.         lods    byte [esi]
  377.         cmp     al,2
  378.         jne     invalid_argument
  379.         lods    dword [esi]
  380.         cmp     eax,0Fh
  381.         jb      invalid_use_of_symbol
  382.         je      reserved_word_used_as_symbol
  383.         inc     esi
  384.         mov     ebx,eax
  385.         xor     ah,ah
  386.         lods    byte [esi]
  387.         cmp     al,':'
  388.         je      get_extrn_size
  389.         dec     esi
  390.         cmp     al,11h
  391.         jne     extrn_size_ok
  392.       get_extrn_size:
  393.         lods    word [esi]
  394.         cmp     al,11h
  395.         jne     invalid_argument
  396.       extrn_size_ok:
  397.         mov     [address_symbol],edx
  398.         movzx   ecx,ah
  399.         mov     [edx+8],ecx
  400.         xor     eax,eax
  401.         xor     edx,edx
  402.         xor     ebp,ebp
  403.         mov     ch,2
  404.         test    [format_flags],8
  405.         jz      make_free_label
  406.         mov     ch,4
  407.         jmp     make_free_label
  408. mark_relocation:
  409.         cmp     [value_type],0
  410.         je      relocation_ok
  411.         cmp     [virtual_data],0
  412.         jne     relocation_ok
  413.         cmp     [output_format],2
  414.         je      mark_mz_relocation
  415.         cmp     [output_format],3
  416.         je      mark_pe_relocation
  417.         cmp     [output_format],4
  418.         je      mark_coff_relocation
  419.         cmp     [output_format],5
  420.         je      mark_elf_relocation
  421.       relocation_ok:
  422.         ret
  423. close_pass:
  424.         mov     al,[output_format]
  425.         cmp     al,3
  426.         je      close_pe
  427.         cmp     al,4
  428.         je      close_coff
  429.         cmp     al,5
  430.         je      close_elf
  431.         ret
  432.  
  433. format_mz:
  434.         mov     edx,[additional_memory]
  435.         push    edi
  436.         mov     edi,edx
  437.         mov     ecx,1Ch shr 2
  438.         xor     eax,eax
  439.         rep     stos dword [edi]
  440.         mov     [free_additional_memory],edi
  441.         pop     edi
  442.         mov     word [edx+0Ch],0FFFFh
  443.         mov     word [edx+10h],1000h
  444.         mov     [code_type],16
  445.         jmp     format_defined
  446. mark_mz_relocation:
  447.         push    eax ebx
  448.         inc     [number_of_relocations]
  449.         mov     ebx,[free_additional_memory]
  450.         mov     eax,edi
  451.         sub     eax,[code_start]
  452.         mov     [ebx],ax
  453.         shr     eax,16
  454.         shl     ax,12
  455.         mov     [ebx+2],ax
  456.         cmp     word [ebx],0FFFFh
  457.         jne     mz_relocation_ok
  458.         inc     word [ebx+2]
  459.         sub     word [ebx],10h
  460.       mz_relocation_ok:
  461.         add     ebx,4
  462.         cmp     ebx,[structures_buffer]
  463.         jae     out_of_memory
  464.         mov     [free_additional_memory],ebx
  465.         pop     ebx eax
  466.         ret
  467. mz_segment:
  468.         lods    byte [esi]
  469.         cmp     al,2
  470.         jne     invalid_argument
  471.         lods    dword [esi]
  472.         cmp     eax,0Fh
  473.         jb      invalid_use_of_symbol
  474.         je      reserved_word_used_as_symbol
  475.         inc     esi
  476.         mov     ebx,eax
  477.         mov     eax,edi
  478.         sub     eax,[code_start]
  479.         mov     ecx,0Fh
  480.         add     eax,0Fh
  481.         and     eax,1111b
  482.         sub     ecx,eax
  483.         mov     edx,edi
  484.         xor     eax,eax
  485.         rep     stos byte [edi]
  486.         mov     dword [org_origin],edi
  487.         mov     dword [org_origin+4],eax
  488.         mov     [org_registers],eax
  489.         mov     [org_start],edi
  490.         mov     eax,edx
  491.         call    undefined_data
  492.         mov     eax,edi
  493.         sub     eax,[code_start]
  494.         shr     eax,4
  495.         cmp     eax,10000h
  496.         jae     value_out_of_range
  497.         mov     edx,eax
  498.         mov     al,16
  499.         cmp     byte [esi],13h
  500.         jne     segment_type_ok
  501.         inc     esi
  502.         lods    byte [esi]
  503.       segment_type_ok:
  504.         mov     [code_type],al
  505.         mov     eax,edx
  506.         mov     cx,0100h
  507.         xor     edx,edx
  508.         xor     ebp,ebp
  509.         mov     [address_symbol],edx
  510.         jmp     make_free_label
  511. mz_entry:
  512.         lods    byte [esi]
  513.         cmp     al,'('
  514.         jne     invalid_argument
  515.         call    get_word_value
  516.         cmp     [value_type],1
  517.         je      initial_cs_ok
  518.         cmp     [error_line],0
  519.         jne     initial_cs_ok
  520.         mov     eax,[current_line]
  521.         mov     [error_line],eax
  522.         mov     [error],invalid_address
  523.       initial_cs_ok:
  524.         mov     edx,[additional_memory]
  525.         mov     [edx+16h],ax
  526.         lods    byte [esi]
  527.         cmp     al,':'
  528.         jne     invalid_argument
  529.         lods    byte [esi]
  530.         cmp     al,'('
  531.         jne     invalid_argument
  532.         ja      invalid_address
  533.         call    get_word_value
  534.         cmp     [value_type],0
  535.         jne     invalid_use_of_symbol
  536.         mov     edx,[additional_memory]
  537.         mov     [edx+14h],ax
  538.         jmp     instruction_assembled
  539. mz_stack:
  540.         lods    byte [esi]
  541.         cmp     al,'('
  542.         jne     invalid_argument
  543.         call    get_word_value
  544.         cmp     byte [esi],':'
  545.         je      stack_pointer
  546.         cmp     ax,10h
  547.         jb      invalid_value
  548.         cmp     [value_type],0
  549.         jne     invalid_use_of_symbol
  550.         mov     edx,[additional_memory]
  551.         mov     [edx+10h],ax
  552.         jmp     instruction_assembled
  553.       stack_pointer:
  554.         cmp     [value_type],1
  555.         je      initial_ss_ok
  556.         cmp     [error_line],0
  557.         jne     initial_ss_ok
  558.         mov     eax,[current_line]
  559.         mov     [error_line],eax
  560.         mov     [error],invalid_address
  561.       initial_ss_ok:
  562.         mov     edx,[additional_memory]
  563.         mov     [edx+0Eh],ax
  564.         lods    byte [esi]
  565.         cmp     al,':'
  566.         jne     invalid_argument
  567.         lods    byte [esi]
  568.         cmp     al,'('
  569.         jne     invalid_argument
  570.         call    get_word_value
  571.         cmp     [value_type],0
  572.         jne     invalid_use_of_symbol
  573.         mov     edx,[additional_memory]
  574.         mov     [edx+10h],ax
  575.         bts     [format_flags],4
  576.         jmp     instruction_assembled
  577. mz_heap:
  578.         cmp     [output_format],2
  579.         jne     illegal_instruction
  580.         lods    byte [esi]
  581.         call    get_size_operator
  582.         cmp     ah,1
  583.         je      invalid_value
  584.         cmp     ah,2
  585.         ja      invalid_value
  586.         cmp     al,'('
  587.         jne     invalid_argument
  588.         call    get_word_value
  589.         cmp     [value_type],0
  590.         jne     invalid_use_of_symbol
  591.         mov     edx,[additional_memory]
  592.         mov     [edx+0Ch],ax
  593.         jmp     instruction_assembled
  594. write_mz_header:
  595.         mov     edx,[additional_memory]
  596.         bt      [format_flags],4
  597.         jc      mz_stack_ok
  598.         mov     eax,[real_code_size]
  599.         dec     eax
  600.         shr     eax,4
  601.         inc     eax
  602.         mov     [edx+0Eh],ax
  603.         shl     eax,4
  604.         movzx   ecx,word [edx+10h]
  605.         add     eax,ecx
  606.         mov     [real_code_size],eax
  607.       mz_stack_ok:
  608.         mov     edi,[free_additional_memory]
  609.         mov     eax,[number_of_relocations]
  610.         shl     eax,2
  611.         add     eax,1Ch
  612.         sub     edi,eax
  613.         xchg    edi,[free_additional_memory]
  614.         mov     ecx,0Fh
  615.         add     eax,0Fh
  616.         and     eax,1111b
  617.         sub     ecx,eax
  618.         xor     al,al
  619.         rep     stos byte [edi]
  620.         sub     edi,[free_additional_memory]
  621.         mov     ecx,edi
  622.         shr     edi,4
  623.         mov     word [edx],'MZ'         ; signature
  624.         mov     [edx+8],di              ; header size in paragraphs
  625.         mov     eax,[number_of_relocations]
  626.         mov     [edx+6],ax              ; number of relocation entries
  627.         mov     eax,[code_size]
  628.         add     eax,ecx
  629.         mov     esi,eax
  630.         shr     esi,9
  631.         and     eax,1FFh
  632.         inc     si
  633.         or      ax,ax
  634.         jnz     mz_size_ok
  635.         dec     si
  636.       mz_size_ok:
  637.         mov     [edx+2],ax              ; number of bytes in last page
  638.         mov     [edx+4],si              ; number of pages
  639.         mov     eax,[real_code_size]
  640.         dec     eax
  641.         shr     eax,4
  642.         inc     eax
  643.         mov     esi,[code_size]
  644.         dec     esi
  645.         shr     esi,4
  646.         inc     esi
  647.         sub     eax,esi
  648.         mov     [edx+0Ah],ax            ; minimum memory in addition to code
  649.         add     [edx+0Ch],ax            ; maximum memory in addition to code
  650.         salc
  651.         mov     ah,al
  652.         or      [edx+0Ch],ax
  653.         mov     word [edx+18h],1Ch      ; offset of relocation table
  654.         add     [written_size],ecx
  655.         call    write
  656.         jc      write_failed
  657.         ret
  658.  
  659. make_stub:
  660.         mov     [stub_file],edx
  661.         or      edx,edx
  662.         jnz     stub_from_file
  663.         push    esi
  664.         mov     edx,edi
  665.         xor     eax,eax
  666.         mov     ecx,20h
  667.         rep     stos dword [edi]
  668.         mov     eax,40h+default_stub_end-default_stub
  669.         mov     cx,100h+default_stub_end-default_stub
  670.         mov     word [edx],'MZ'
  671.         mov     byte [edx+4],1
  672.         mov     word [edx+2],ax
  673.         mov     byte [edx+8],4
  674.         mov     byte [edx+0Ah],10h
  675.         mov     word [edx+0Ch],0FFFFh
  676.         mov     word [edx+10h],cx
  677.         mov     word [edx+3Ch],ax
  678.         mov     byte [edx+18h],40h
  679.         lea     edi,[edx+40h]
  680.         mov     esi,default_stub
  681.         mov     ecx,default_stub_end-default_stub
  682.         rep     movs byte [edi],[esi]
  683.         pop     esi
  684.         jmp     stub_ok
  685.       default_stub:
  686.         use16
  687.         push    cs
  688.         pop     ds
  689.         mov     dx,stub_message-default_stub
  690.         mov     ah,9
  691.         int     21h
  692.         mov     ax,4C01h
  693.         int     21h
  694.       stub_message db 'This program cannot be run in DOS mode.',0Dh,0Ah,24h
  695.         rq      1
  696.       default_stub_end:
  697.         use32
  698.       stub_from_file:
  699.         push    esi
  700.         mov     esi,edx
  701.         call    open_binary_file
  702.         mov     edx,edi
  703.         mov     ecx,1Ch
  704.         mov     esi,edx
  705.         call    read
  706.         jc      binary_stub
  707.         cmp     word [esi],'MZ'
  708.         jne     binary_stub
  709.         add     edi,1Ch
  710.         movzx   ecx,word [esi+6]
  711.         add     ecx,11b
  712.         and     ecx,not 11b
  713.         add     ecx,(40h-1Ch) shr 2
  714.         lea     eax,[edi+ecx*4]
  715.         cmp     edi,[display_buffer]
  716.         jae     out_of_memory
  717.         xor     eax,eax
  718.         rep     stos dword [edi]
  719.         mov     edx,40h
  720.         xchg    dx,[esi+18h]
  721.         xor     al,al
  722.         call    lseek
  723.         movzx   ecx,word [esi+6]
  724.         shl     ecx,2
  725.         lea     edx,[esi+40h]
  726.         call    read
  727.         mov     edx,edi
  728.         sub     edx,esi
  729.         shr     edx,4
  730.         xchg    dx,[esi+8]
  731.         shl     edx,4
  732.         xor     al,al
  733.         call    lseek
  734.         movzx   ecx,word [esi+4]
  735.         dec     ecx
  736.         shl     ecx,9
  737.         movzx   edx,word [esi+2]
  738.         test    edx,edx
  739.         jnz     stub_header_size_ok
  740.         mov     dx,200h
  741.      stub_header_size_ok:
  742.         add     ecx,edx
  743.         mov     edx,edi
  744.         sub     ecx,eax
  745.         je      read_stub_code
  746.         jb      stub_code_ok
  747.         push    ecx
  748.         dec     ecx
  749.         shr     ecx,3
  750.         inc     ecx
  751.         shl     ecx,1
  752.         lea     eax,[edi+ecx*4]
  753.         cmp     eax,[display_buffer]
  754.         jae     out_of_memory
  755.         xor     eax,eax
  756.         rep     stos dword [edi]
  757.         pop     ecx
  758.      read_stub_code:
  759.         call    read
  760.      stub_code_ok:
  761.         call    close
  762.         mov     edx,edi
  763.         sub     edx,esi
  764.         mov     ax,dx
  765.         and     ax,1FFh
  766.         mov     [esi+2],ax
  767.         dec     edx
  768.         shr     edx,9
  769.         inc     edx
  770.         mov     [esi+4],dx
  771.         mov     eax,edi
  772.         sub     eax,esi
  773.         mov     [esi+3Ch],eax
  774.         pop     esi
  775.       stub_ok:
  776.         ret
  777.       binary_stub:
  778.         mov     esi,edi
  779.         mov     ecx,40h shr 2
  780.         xor     eax,eax
  781.         rep     stos dword [edi]
  782.         mov     al,2
  783.         xor     edx,edx
  784.         call    lseek
  785.         push    eax
  786.         xor     al,al
  787.         xor     edx,edx
  788.         call    lseek
  789.         mov     ecx,[esp]
  790.         add     ecx,40h+111b
  791.         and     ecx,not 111b
  792.         mov     ax,cx
  793.         and     ax,1FFh
  794.         mov     [esi+2],ax
  795.         lea     eax,[ecx+1FFh]
  796.         shr     eax,9
  797.         mov     [esi+4],ax
  798.         mov     [esi+3Ch],ecx
  799.         sub     ecx,40h
  800.         mov     eax,10000h
  801.         sub     eax,ecx
  802.         jbe     binary_heap_ok
  803.         shr     eax,4
  804.         mov     [esi+0Ah],ax
  805.       binary_heap_ok:
  806.         mov     word [esi],'MZ'
  807.         mov     byte [esi+8],4
  808.         mov     ax,0FFFFh
  809.         mov     [esi+0Ch],ax
  810.         dec     ax
  811.         mov     [esi+10h],ax
  812.         sub     ax,0Eh
  813.         mov     [esi+0Eh],ax
  814.         mov     [esi+16h],ax
  815.         mov     word [esi+14h],100h
  816.         mov     byte [esi+18h],40h
  817.         mov     eax,[display_buffer]
  818.         sub     eax,ecx
  819.         cmp     edi,eax
  820.         jae     out_of_memory
  821.         mov     edx,edi
  822.         shr     ecx,2
  823.         xor     eax,eax
  824.         rep     stos dword [edi]
  825.         pop     ecx
  826.         call    read
  827.         call    close
  828.         pop     esi
  829.         ret
  830.  
  831. format_pe:
  832.         xor     edx,edx
  833.         mov     [machine],14Ch
  834.         mov     [subsystem],3
  835.         mov     [subsystem_version],3 + 10 shl 16
  836.         mov     [image_base],400000h
  837.         test    [format_flags],8
  838.         jz      pe_settings
  839.         mov     [machine],8664h
  840.         mov     [subsystem_version],5 + 0 shl 16
  841.         mov     [image_base_high],0
  842.       pe_settings:
  843.         cmp     byte [esi],84h
  844.         je      get_stub_name
  845.         cmp     byte [esi],80h
  846.         je      get_pe_base
  847.         cmp     byte [esi],1Bh
  848.         jne     pe_settings_ok
  849.         lods    byte [esi]
  850.         lods    byte [esi]
  851.         test    al,80h+40h
  852.         jz      subsystem_setting
  853.         cmp     al,80h
  854.         je      dll_flag
  855.         cmp     al,81h
  856.         je      wdm_flag
  857.         jmp     pe_settings
  858.       dll_flag:
  859.         bts     [format_flags],8
  860.         jc      setting_already_specified
  861.         jmp     pe_settings
  862.       wdm_flag:
  863.         bts     [format_flags],9
  864.         jc      setting_already_specified
  865.         jmp     pe_settings
  866.       subsystem_setting:
  867.         bts     [format_flags],7
  868.         jc      setting_already_specified
  869.         and     ax,3Fh
  870.         mov     [subsystem],ax
  871.         cmp     ax,10
  872.         jb      subsystem_type_ok
  873.         or      [format_flags],8
  874.       subsystem_type_ok:
  875.         cmp     byte [esi],'('
  876.         jne     pe_settings
  877.         inc     esi
  878.         cmp     byte [esi],'.'
  879.         jne     invalid_value
  880.         inc     esi
  881.         push    edx
  882.         cmp     byte [esi+11],0
  883.         jne     invalid_value
  884.         cmp     byte [esi+10],2
  885.         ja      invalid_value
  886.         mov     dx,[esi+8]
  887.         cmp     dx,8000h
  888.         je      zero_version
  889.         mov     eax,[esi+4]
  890.         cmp     dx,7
  891.         jg      invalid_value
  892.         mov     cx,7
  893.         sub     cx,dx
  894.         mov     eax,[esi+4]
  895.         shr     eax,cl
  896.         mov     ebx,eax
  897.         shr     ebx,24
  898.         cmp     bl,100
  899.         jae     invalid_value
  900.         and     eax,0FFFFFFh
  901.         mov     ecx,100
  902.         mul     ecx
  903.         shrd    eax,edx,24
  904.         jnc     version_value_ok
  905.         inc     eax
  906.       version_value_ok:
  907.         shl     eax,16
  908.         mov     ax,bx
  909.         jmp     subsystem_version_ok
  910.       zero_version:
  911.         xor     eax,eax
  912.       subsystem_version_ok:
  913.         pop     edx
  914.         add     esi,13
  915.         mov     [subsystem_version],eax
  916.         jmp     pe_settings
  917.       get_pe_base:
  918.         bts     [format_flags],10
  919.         jc      setting_already_specified
  920.         lods    word [esi]
  921.         cmp     ah,'('
  922.         jne     invalid_argument
  923.         cmp     byte [esi],'.'
  924.         je      invalid_value
  925.         push    edx edi
  926.         add     edi,[stub_size]
  927.         test    [format_flags],8
  928.         jnz     get_peplus_base
  929.         call    get_dword_value
  930.         mov     [image_base],eax
  931.         jmp     pe_base_ok
  932.       get_peplus_base:
  933.         call    get_qword_value
  934.         mov     [image_base],eax
  935.         mov     [image_base_high],edx
  936.       pe_base_ok:
  937.         pop     edi edx
  938.         cmp     [value_type],0
  939.         jne     invalid_use_of_symbol
  940.         cmp     byte [esi],84h
  941.         jne     pe_settings_ok
  942.       get_stub_name:
  943.         lods    byte [esi]
  944.         lods    word [esi]
  945.         cmp     ax,'('
  946.         jne     invalid_argument
  947.         lods    dword [esi]
  948.         mov     edx,esi
  949.         add     esi,eax
  950.         inc     esi
  951.       pe_settings_ok:
  952.         mov     ebp,[stub_size]
  953.         or      ebp,ebp
  954.         jz      make_pe_stub
  955.         cmp     edx,[stub_file]
  956.         je      pe_stub_ok
  957.         sub     edi,[stub_size]
  958.         mov     [code_start],edi
  959.       make_pe_stub:
  960.         call    make_stub
  961.         mov     eax,edi
  962.         sub     eax,[code_start]
  963.         mov     [stub_size],eax
  964.         mov     [code_start],edi
  965.         mov     ebp,eax
  966.       pe_stub_ok:
  967.         mov     edx,edi
  968.         mov     ecx,18h+0E0h
  969.         test    [format_flags],8
  970.         jz      zero_pe_header
  971.         add     ecx,10h
  972.       zero_pe_header:
  973.         add     ebp,ecx
  974.         shr     ecx,2
  975.         xor     eax,eax
  976.         rep     stos dword [edi]
  977.         mov     word [edx],'PE'         ; signature
  978.         mov     ax,[machine]
  979.         mov     word [edx+4],ax
  980.         mov     byte [edx+38h+1],10h    ; section alignment
  981.         mov     byte [edx+3Ch+1],2      ; file alignment
  982.         mov     byte [edx+40h],1        ; OS version
  983.         mov     eax,[subsystem_version]
  984.         mov     [edx+48h],eax
  985.         mov     ax,[subsystem]
  986.         mov     [edx+5Ch],ax
  987.         cmp     ax,1
  988.         jne     pe_alignment_ok
  989.         mov     eax,20h
  990.         mov     dword [edx+38h],eax
  991.         mov     dword [edx+3Ch],eax
  992.       pe_alignment_ok:
  993.         mov     word [edx+1Ah],VERSION_MAJOR + VERSION_MINOR shl 8
  994.         test    [format_flags],8
  995.         jnz     init_peplus_specific
  996.         mov     byte [edx+14h],0E0h     ; size of optional header
  997.         mov     dword [edx+16h],10B010Eh; flags and magic value
  998.         mov     eax,[image_base]
  999.         mov     [edx+34h],eax
  1000.         mov     byte [edx+60h+1],10h    ; stack reserve
  1001.         mov     byte [edx+64h+1],10h    ; stack commit
  1002.         mov     byte [edx+68h+2],1      ; heap reserve
  1003.         mov     byte [edx+74h],16       ; number of directories
  1004.         jmp     pe_header_ok
  1005.       init_peplus_specific:
  1006.         mov     byte [edx+14h],0F0h     ; size of optional header
  1007.         mov     dword [edx+16h],20B002Eh; flags and magic value
  1008.         mov     eax,[image_base]
  1009.         mov     [edx+30h],eax
  1010.         mov     eax,[image_base_high]
  1011.         mov     [edx+34h],eax
  1012.         mov     byte [edx+60h+1],10h    ; stack reserve
  1013.         mov     byte [edx+68h+1],10h    ; stack commit
  1014.         mov     byte [edx+70h+2],1      ; heap reserve
  1015.         mov     byte [edx+84h],16       ; number of directories
  1016.       pe_header_ok:
  1017.         bsf     ecx,[edx+3Ch]
  1018.         imul    ebx,[number_of_sections],28h
  1019.         or      ebx,ebx
  1020.         jnz     reserve_space_for_section_headers
  1021.         mov     ebx,28h
  1022.       reserve_space_for_section_headers:
  1023.         add     ebx,ebp
  1024.         dec     ebx
  1025.         shr     ebx,cl
  1026.         inc     ebx
  1027.         shl     ebx,cl
  1028.         sub     ebx,ebp
  1029.         mov     ecx,ebx
  1030.         mov     eax,[display_buffer]
  1031.         sub     eax,ecx
  1032.         cmp     edi,eax
  1033.         jae     out_of_memory
  1034.         shr     ecx,2
  1035.         xor     eax,eax
  1036.         rep     stos dword [edi]
  1037.         mov     eax,edi
  1038.         sub     eax,[code_start]
  1039.         add     eax,[stub_size]
  1040.         mov     [edx+54h],eax           ; size of headers
  1041.         mov     ecx,[edx+38h]
  1042.         dec     ecx
  1043.         add     eax,ecx
  1044.         not     ecx
  1045.         and     eax,ecx
  1046.         bt      [format_flags],8
  1047.         jc      pe_entry_init_ok
  1048.         mov     [edx+28h],eax           ; entry point rva
  1049.       pe_entry_init_ok:
  1050.         mov     [number_of_sections],0
  1051.         movzx   ebx,word [edx+14h]
  1052.         lea     ebx,[edx+18h+ebx]
  1053.         mov     [current_section],ebx
  1054.         mov     dword [ebx],'.fla'
  1055.         mov     dword [ebx+4],'t'
  1056.         mov     [ebx+14h],edi
  1057.         mov     [ebx+0Ch],eax
  1058.         mov     dword [ebx+24h],0E0000060h
  1059.         xor     ecx,ecx
  1060.         not     eax
  1061.         not     ecx
  1062.         add     eax,1
  1063.         adc     ecx,0
  1064.         add     eax,edi
  1065.         adc     ecx,0
  1066.         test    [format_flags],8
  1067.         jnz     peplus_org
  1068.         sub     eax,[edx+34h]
  1069.         sbb     ecx,0
  1070.         mov     bl,2
  1071.         mov     [code_type],32
  1072.         jmp     pe_org_ok
  1073.       peplus_org:
  1074.         sub     eax,[edx+30h]
  1075.         sbb     ecx,[edx+34h]
  1076.         mov     bl,4
  1077.         mov     [code_type],64
  1078.       pe_org_ok:
  1079.         bt      [resolver_flags],0
  1080.         jc      pe_labels_type_ok
  1081.         xor     bl,bl
  1082.       pe_labels_type_ok:
  1083.         mov     [labels_type],bl
  1084.         mov     dword [org_origin],eax
  1085.         mov     dword [org_origin+4],ecx
  1086.         mov     [org_registers],0
  1087.         mov     [org_start],edi
  1088.         bt      [format_flags],8
  1089.         jnc     dll_flag_ok
  1090.         or      byte [edx+16h+1],20h
  1091.       dll_flag_ok:
  1092.         bt      [format_flags],9
  1093.         jnc     wdm_flag_ok
  1094.         or      byte [edx+5Eh+1],20h
  1095.       wdm_flag_ok:
  1096.         jmp     format_defined
  1097. pe_section:
  1098.         call    close_pe_section
  1099.         bts     [format_flags],5
  1100.         lea     ecx,[ebx+28h]
  1101.         add     edx,[edx+54h]
  1102.         sub     edx,[stub_size]
  1103.         cmp     ecx,edx
  1104.         jbe     new_section
  1105.         lea     ebx,[edx-28h]
  1106.         or      [next_pass_needed],-1
  1107.         push    edi
  1108.         mov     edi,ebx
  1109.         mov     ecx,28h shr 4
  1110.         xor     eax,eax
  1111.         rep     stos dword [edi]
  1112.         pop     edi
  1113.       new_section:
  1114.         mov     [ebx+0Ch],eax
  1115.         lods    word [esi]
  1116.         cmp     ax,'('
  1117.         jne     invalid_argument
  1118.         lea     edx,[esi+4]
  1119.         mov     ecx,[esi]
  1120.         lea     esi,[esi+4+ecx+1]
  1121.         cmp     ecx,8
  1122.         ja      name_too_long
  1123.         xor     eax,eax
  1124.         mov     [ebx],eax
  1125.         mov     [ebx+4],eax
  1126.         push    esi edi
  1127.         mov     edi,ebx
  1128.         mov     esi,edx
  1129.         rep     movs byte [edi],[esi]
  1130.         pop     edi esi
  1131.         mov     dword [ebx+24h],0
  1132.         mov     [ebx+14h],edi
  1133.         mov     edx,[code_start]
  1134.         mov     eax,edi
  1135.         xor     ecx,ecx
  1136.         sub     eax,[ebx+0Ch]
  1137.         sbb     ecx,0
  1138.         test    [format_flags],8
  1139.         jnz     peplus_section_org
  1140.         sub     eax,[edx+34h]
  1141.         sbb     ecx,0
  1142.         mov     [labels_type],2
  1143.         mov     [code_type],32
  1144.         bt      [resolver_flags],0
  1145.         jc      pe_section_org_ok
  1146.         mov     [labels_type],0
  1147.         jmp     pe_section_org_ok
  1148.       peplus_section_org:
  1149.         sub     eax,[edx+30h]
  1150.         sbb     ecx,[edx+34h]
  1151.         mov     [labels_type],4
  1152.         mov     [code_type],64
  1153.         bt      [resolver_flags],0
  1154.         jc      pe_section_org_ok
  1155.         mov     [labels_type],0
  1156.       pe_section_org_ok:
  1157.         mov     dword [org_origin],eax
  1158.         mov     dword [org_origin+4],ecx
  1159.         mov     [org_registers],0
  1160.         mov     [org_start],edi
  1161.       get_section_flags:
  1162.         lods    byte [esi]
  1163.         cmp     al,1Ah
  1164.         je      set_directory
  1165.         cmp     al,19h
  1166.         je      section_flag
  1167.         dec     esi
  1168.         jmp     instruction_assembled
  1169.       set_directory:
  1170.         movzx   eax,byte [esi]
  1171.         inc     esi
  1172.         mov     ecx,ebx
  1173.         test    [format_flags],8
  1174.         jnz     peplus_directory
  1175.         xchg    ecx,[edx+78h+eax*8]
  1176.         mov     dword [edx+78h+eax*8+4],-1
  1177.         jmp     pe_directory_set
  1178.       peplus_directory:
  1179.         xchg    ecx,[edx+88h+eax*8]
  1180.         mov     dword [edx+88h+eax*8+4],-1
  1181.       pe_directory_set:
  1182.         or      ecx,ecx
  1183.         jnz     data_already_defined
  1184.         push    ebx edx
  1185.         call    generate_pe_data
  1186.         pop     edx ebx
  1187.         jmp     get_section_flags
  1188.       section_flag:
  1189.         lods    byte [esi]
  1190.         cmp     al,9
  1191.         je      invalid_argument
  1192.         cmp     al,11
  1193.         je      invalid_argument
  1194.         mov     cl,al
  1195.         mov     eax,1
  1196.         shl     eax,cl
  1197.         test    dword [ebx+24h],eax
  1198.         jnz     setting_already_specified
  1199.         or      dword [ebx+24h],eax
  1200.         jmp     get_section_flags
  1201.       close_pe_section:
  1202.         mov     ebx,[current_section]
  1203.         mov     edx,[code_start]
  1204.         mov     eax,edi
  1205.         sub     eax,[ebx+14h]
  1206.         jnz     finish_section
  1207.         bt      [format_flags],5
  1208.         jc      finish_section
  1209.         mov     eax,[ebx+0Ch]
  1210.         ret
  1211.       finish_section:
  1212.         mov     [ebx+8],eax
  1213.         cmp     edi,[undefined_data_end]
  1214.         jne     align_section
  1215.         cmp     dword [edx+38h],1000h
  1216.         jb      align_section
  1217.         mov     edi,[undefined_data_start]
  1218.       align_section:
  1219.         mov     [undefined_data_end],0
  1220.         mov     ebp,edi
  1221.         sub     ebp,[ebx+14h]
  1222.         mov     ecx,[edx+3Ch]
  1223.         dec     ecx
  1224.         lea     eax,[ebp+ecx]
  1225.         not     ecx
  1226.         and     eax,ecx
  1227.         mov     [ebx+10h],eax
  1228.         sub     eax,ebp
  1229.         mov     ecx,eax
  1230.         xor     al,al
  1231.         rep     stos byte [edi]
  1232.         mov     eax,[code_start]
  1233.         sub     eax,[stub_size]
  1234.         sub     [ebx+14h],eax
  1235.         mov     ecx,[ebx+10h]
  1236.         test    byte [ebx+24h],20h
  1237.         jz      pe_code_sum_ok
  1238.         add     [edx+1Ch],ecx
  1239.         cmp     dword [edx+2Ch],0
  1240.         jne     pe_code_sum_ok
  1241.         mov     eax,[ebx+0Ch]
  1242.         mov     [edx+2Ch],eax
  1243.       pe_code_sum_ok:
  1244.         test    byte [ebx+24h],40h
  1245.         jz      pe_data_sum_ok
  1246.         add     [edx+20h],ecx
  1247.         test    [format_flags],8
  1248.         jnz     pe_data_sum_ok
  1249.         cmp     dword [edx+30h],0
  1250.         jne     pe_data_sum_ok
  1251.         mov     eax,[ebx+0Ch]
  1252.         mov     [edx+30h],eax
  1253.       pe_data_sum_ok:
  1254.         mov     eax,[ebx+8]
  1255.         or      eax,eax
  1256.         jz      udata_ok
  1257.         cmp     dword [ebx+10h],0
  1258.         jne     udata_ok
  1259.         or      byte [ebx+24h],80h
  1260.         add     [edx+24h],ecx
  1261.       udata_ok:
  1262.         mov     ecx,[edx+38h]
  1263.         dec     ecx
  1264.         add     eax,ecx
  1265.         not     ecx
  1266.         and     eax,ecx
  1267.         add     eax,[ebx+0Ch]
  1268.         add     ebx,28h
  1269.         mov     [current_section],ebx
  1270.         inc     word [number_of_sections]
  1271.         jz      format_limitations_exceeded
  1272.         ret
  1273. data_directive:
  1274.         cmp     [output_format],3
  1275.         jne     illegal_instruction
  1276.         lods    byte [esi]
  1277.         cmp     al,1Ah
  1278.         je      predefined_data_type
  1279.         cmp     al,'('
  1280.         jne     invalid_argument
  1281.         call    get_byte_value
  1282.         cmp     al,16
  1283.         jb      data_type_ok
  1284.         jmp     invalid_value
  1285.       predefined_data_type:
  1286.         movzx   eax,byte [esi]
  1287.         inc     esi
  1288.       data_type_ok:
  1289.         mov     ebx,[current_section]
  1290.         mov     ecx,edi
  1291.         sub     ecx,[ebx+14h]
  1292.         add     ecx,[ebx+0Ch]
  1293.         mov     edx,[code_start]
  1294.         test    [format_flags],8
  1295.         jnz     peplus_data
  1296.         xchg    ecx,[edx+78h+eax*8]
  1297.         jmp     init_pe_data
  1298.       peplus_data:
  1299.         xchg    ecx,[edx+88h+eax*8]
  1300.       init_pe_data:
  1301.         or      ecx,ecx
  1302.         jnz     data_already_defined
  1303.         call    allocate_structure_data
  1304.         mov     word [ebx],data_directive-instruction_handler
  1305.         mov     [ebx+2],al
  1306.         mov     edx,[current_line]
  1307.         mov     [ebx+4],edx
  1308.         call    generate_pe_data
  1309.         jmp     instruction_assembled
  1310.       end_data:
  1311.         cmp     [output_format],3
  1312.         jne     illegal_instruction
  1313.         call    find_structure_data
  1314.         jc      unexpected_instruction
  1315.         movzx   eax,byte [ebx+2]
  1316.         mov     edx,[current_section]
  1317.         mov     ecx,edi
  1318.         sub     ecx,[edx+14h]
  1319.         add     ecx,[edx+0Ch]
  1320.         mov     edx,[code_start]
  1321.         test    [format_flags],8
  1322.         jnz     end_peplus_data
  1323.         sub     ecx,[edx+78h+eax*8]
  1324.         mov     [edx+78h+eax*8+4],ecx
  1325.         jmp     remove_structure_data
  1326.       end_peplus_data:
  1327.         sub     ecx,[edx+88h+eax*8]
  1328.         mov     [edx+88h+eax*8+4],ecx
  1329.         jmp     remove_structure_data
  1330. pe_entry:
  1331.         lods    byte [esi]
  1332.         cmp     al,'('
  1333.         jne     invalid_argument
  1334.         cmp     byte [esi],'.'
  1335.         je      invalid_value
  1336.         test    [format_flags],8
  1337.         jnz     peplus_entry
  1338.         call    get_dword_value
  1339.         mov     bl,2
  1340.         bt      [resolver_flags],0
  1341.         jc      check_pe_entry_label_type
  1342.         xor     bl,bl
  1343.       check_pe_entry_label_type:
  1344.         cmp     [value_type],bl
  1345.         je      pe_entry_ok
  1346.         cmp     [error_line],0
  1347.         jne     pe_entry_ok
  1348.         mov     edx,[current_line]
  1349.         mov     [error_line],edx
  1350.         mov     [error],invalid_address
  1351.       pe_entry_ok:
  1352.         mov     edx,[code_start]
  1353.         sub     eax,[edx+34h]
  1354.         mov     [edx+28h],eax
  1355.         jmp     instruction_assembled
  1356.       peplus_entry:
  1357.         call    get_qword_value
  1358.         mov     bl,4
  1359.         bt      [resolver_flags],0
  1360.         jc      check_peplus_entry_label_type
  1361.         xor     bl,bl
  1362.       check_peplus_entry_label_type:
  1363.         cmp     [value_type],bl
  1364.         je      peplus_entry_type_ok
  1365.         cmp     [error_line],0
  1366.         jne     peplus_entry_type_ok
  1367.         mov     edx,[current_line]
  1368.         mov     [error_line],edx
  1369.         mov     [error],invalid_address
  1370.       peplus_entry_type_ok:
  1371.         mov     ecx,[code_start]
  1372.         sub     eax,[ecx+30h]
  1373.         sbb     edx,[ecx+34h]
  1374.         jz      peplus_entry_range_ok
  1375.         mov     edx,[current_line]
  1376.         mov     [error_line],edx
  1377.         mov     [error],value_out_of_range
  1378.       peplus_entry_range_ok:
  1379.         mov     [ecx+28h],eax
  1380.         jmp     instruction_assembled
  1381. pe_stack:
  1382.         lods    byte [esi]
  1383.         cmp     al,'('
  1384.         jne     invalid_argument
  1385.         cmp     byte [esi],'.'
  1386.         je      invalid_value
  1387.         test    [format_flags],8
  1388.         jnz     peplus_stack
  1389.         call    get_dword_value
  1390.         cmp     [value_type],0
  1391.         jne     invalid_use_of_symbol
  1392.         mov     edx,[code_start]
  1393.         mov     [edx+60h],eax
  1394.         cmp     byte [esi],','
  1395.         jne     default_stack_commit
  1396.         lods    byte [esi]
  1397.         lods    byte [esi]
  1398.         cmp     al,'('
  1399.         jne     invalid_argument
  1400.         cmp     byte [esi],'.'
  1401.         je      invalid_value
  1402.         call    get_dword_value
  1403.         cmp     [value_type],0
  1404.         jne     invalid_use_of_symbol
  1405.         mov     edx,[code_start]
  1406.         mov     [edx+64h],eax
  1407.         cmp     eax,[edx+60h]
  1408.         ja      value_out_of_range
  1409.         jmp     instruction_assembled
  1410.       default_stack_commit:
  1411.         mov     dword [edx+64h],1000h
  1412.         mov     eax,[edx+60h]
  1413.         cmp     eax,1000h
  1414.         ja      instruction_assembled
  1415.         mov     dword [edx+64h],eax
  1416.         jmp     instruction_assembled
  1417.       peplus_stack:
  1418.         call    get_qword_value
  1419.         cmp     [value_type],0
  1420.         jne     invalid_use_of_symbol
  1421.         mov     ecx,[code_start]
  1422.         mov     [ecx+60h],eax
  1423.         mov     [ecx+64h],edx
  1424.         cmp     byte [esi],','
  1425.         jne     default_peplus_stack_commit
  1426.         lods    byte [esi]
  1427.         lods    byte [esi]
  1428.         cmp     al,'('
  1429.         jne     invalid_argument
  1430.         cmp     byte [esi],'.'
  1431.         je      invalid_value
  1432.         call    get_qword_value
  1433.         cmp     [value_type],0
  1434.         jne     invalid_use_of_symbol
  1435.         mov     ecx,[code_start]
  1436.         mov     [ecx+68h],eax
  1437.         mov     [ecx+6Ch],edx
  1438.         cmp     edx,[ecx+64h]
  1439.         ja      value_out_of_range
  1440.         jb      instruction_assembled
  1441.         cmp     eax,[ecx+60h]
  1442.         ja      value_out_of_range
  1443.         jmp     instruction_assembled
  1444.       default_peplus_stack_commit:
  1445.         mov     dword [ecx+68h],1000h
  1446.         cmp     dword [ecx+64h],0
  1447.         jne     instruction_assembled
  1448.         mov     eax,[ecx+60h]
  1449.         cmp     eax,1000h
  1450.         ja      instruction_assembled
  1451.         mov     dword [ecx+68h],eax
  1452.         jmp     instruction_assembled
  1453. pe_heap:
  1454.         lods    byte [esi]
  1455.         cmp     al,'('
  1456.         jne     invalid_argument
  1457.         cmp     byte [esi],'.'
  1458.         je      invalid_value
  1459.         test    [format_flags],8
  1460.         jnz     peplus_heap
  1461.         call    get_dword_value
  1462.         cmp     [value_type],0
  1463.         jne     invalid_use_of_symbol
  1464.         mov     edx,[code_start]
  1465.         mov     [edx+68h],eax
  1466.         cmp     byte [esi],','
  1467.         jne     instruction_assembled
  1468.         lods    byte [esi]
  1469.         lods    byte [esi]
  1470.         cmp     al,'('
  1471.         jne     invalid_argument
  1472.         cmp     byte [esi],'.'
  1473.         je      invalid_value
  1474.         call    get_dword_value
  1475.         cmp     [value_type],0
  1476.         jne     invalid_use_of_symbol
  1477.         mov     edx,[code_start]
  1478.         mov     [edx+6Ch],eax
  1479.         cmp     eax,[edx+68h]
  1480.         ja      value_out_of_range
  1481.         jmp     instruction_assembled
  1482.       peplus_heap:
  1483.         call    get_qword_value
  1484.         cmp     [value_type],0
  1485.         jne     invalid_use_of_symbol
  1486.         mov     ecx,[code_start]
  1487.         mov     [ecx+70h],eax
  1488.         mov     [ecx+74h],edx
  1489.         cmp     byte [esi],','
  1490.         jne     instruction_assembled
  1491.         lods    byte [esi]
  1492.         lods    byte [esi]
  1493.         cmp     al,'('
  1494.         jne     invalid_argument
  1495.         cmp     byte [esi],'.'
  1496.         je      invalid_value
  1497.         call    get_qword_value
  1498.         cmp     [value_type],0
  1499.         jne     invalid_use_of_symbol
  1500.         mov     ecx,[code_start]
  1501.         mov     [ecx+78h],eax
  1502.         mov     [ecx+7Ch],edx
  1503.         cmp     edx,[ecx+74h]
  1504.         ja      value_out_of_range
  1505.         jb      instruction_assembled
  1506.         cmp     eax,[edx+70h]
  1507.         ja      value_out_of_range
  1508.         jmp     instruction_assembled
  1509. mark_pe_relocation:
  1510.         push    eax ebx
  1511.         test    [format_flags],8
  1512.         jz      check_pe32_relocation_type
  1513.         cmp     [value_type],4
  1514.         je      pe_relocation_type_ok
  1515.       check_pe32_relocation_type:
  1516.         cmp     [value_type],2
  1517.         je      pe_relocation_type_ok
  1518.         cmp     [error_line],0
  1519.         jne     pe_relocation_type_ok
  1520.         mov     eax,[current_line]
  1521.         mov     [error_line],eax
  1522.         mov     [error],invalid_use_of_symbol
  1523.       pe_relocation_type_ok:
  1524.         mov     ebx,[current_section]
  1525.         mov     eax,edi
  1526.         sub     eax,[ebx+14h]
  1527.         add     eax,[ebx+0Ch]
  1528.         mov     ebx,[free_additional_memory]
  1529.         inc     [number_of_relocations]
  1530.         jz      invalid_use_of_symbol
  1531.         add     ebx,5
  1532.         cmp     ebx,[structures_buffer]
  1533.         jae     out_of_memory
  1534.         mov     [free_additional_memory],ebx
  1535.         mov     [ebx-5],eax
  1536.         cmp     [value_type],2
  1537.         je      fixup_32bit
  1538.         mov     byte [ebx-1],0Ah
  1539.         jmp     fixup_ok
  1540.       fixup_32bit:
  1541.         mov     byte [ebx-1],3
  1542.       fixup_ok:
  1543.         pop     ebx eax
  1544.         ret
  1545. generate_pe_data:
  1546.         cmp     al,2
  1547.         je      make_pe_resource
  1548.         cmp     al,5
  1549.         je      make_pe_fixups
  1550.         ret
  1551. make_pe_fixups:
  1552.         bts     [resolver_flags],0
  1553.         jc      pe_relocatable_ok
  1554.         or      [next_pass_needed],-1
  1555.      pe_relocatable_ok:
  1556.         push    esi
  1557.         mov     ecx,[number_of_relocations]
  1558.         mov     esi,[free_additional_memory]
  1559.         lea     eax,[ecx*5]
  1560.         sub     esi,eax
  1561.         mov     [free_additional_memory],esi
  1562.         or      [number_of_relocations],-1
  1563.         xor     edx,edx
  1564.         mov     ebp,edi
  1565.       make_fixups:
  1566.         cmp     [esi],edx
  1567.         jb      store_fixup
  1568.         mov     eax,edi
  1569.         sub     eax,ebp
  1570.         test    eax,11b
  1571.         jz      fixups_block
  1572.         xor     ax,ax
  1573.         stos    word [edi]
  1574.         add     dword [ebx],2
  1575.       fixups_block:
  1576.         mov     eax,edx
  1577.         add     edx,1000h
  1578.         cmp     [esi],edx
  1579.         jae     fixups_block
  1580.         stos    dword [edi]
  1581.         mov     ebx,edi
  1582.         mov     eax,8
  1583.         stos    dword [edi]
  1584.       store_fixup:
  1585.         jecxz   fixups_done
  1586.         add     dword [ebx],2
  1587.         mov     ah,[esi+1]
  1588.         and     ah,0Fh
  1589.         mov     al,[esi+4]
  1590.         shl     al,4
  1591.         or      ah,al
  1592.         mov     al,[esi]
  1593.         stos    word [edi]
  1594.         add     esi,5
  1595.         loop    make_fixups
  1596.       fixups_done:
  1597.         pop     esi
  1598.         ret
  1599. make_pe_resource:
  1600.         cmp     byte [esi],82h
  1601.         jne     resource_done
  1602.         inc     esi
  1603.         lods    word [esi]
  1604.         cmp     ax,'('
  1605.         jne     invalid_argument
  1606.         lods    dword [esi]
  1607.         mov     edx,esi
  1608.         lea     esi,[esi+eax+1]
  1609.         cmp     [next_pass_needed],0
  1610.         je      resource_from_file
  1611.         cmp     [current_pass],0
  1612.         jne     reserve_space_for_resource
  1613.         mov     [resource_size],0
  1614.       reserve_space_for_resource:
  1615.         add     edi,[resource_size]
  1616.         cmp     edi,[display_buffer]
  1617.         ja      out_of_memory
  1618.         jmp     resource_done
  1619.       resource_from_file:
  1620.         push    esi
  1621.         mov     esi,edx
  1622.         call    open_binary_file
  1623.         push    ebx
  1624.         mov     esi,[free_additional_memory]
  1625.         lea     eax,[esi+20h]
  1626.         cmp     eax,[structures_buffer]
  1627.         ja      out_of_memory
  1628.         mov     edx,esi
  1629.         mov     ecx,20h
  1630.         call    read
  1631.         jc      invalid_file_format
  1632.         xor     eax,eax
  1633.         cmp     [esi],eax
  1634.         jne     invalid_file_format
  1635.         mov     ax,0FFFFh
  1636.         cmp     [esi+8],eax
  1637.         jne     invalid_file_format
  1638.         cmp     [esi+12],eax
  1639.         jne     invalid_file_format
  1640.         mov     eax,20h
  1641.         cmp     [esi+4],eax
  1642.         jne     invalid_file_format
  1643.       read_resource_headers:
  1644.         test    eax,11b
  1645.         jz      resource_file_alignment_ok
  1646.         mov     edx,4
  1647.         and     eax,11b
  1648.         sub     edx,eax
  1649.         mov     al,1
  1650.         call    lseek
  1651.       resource_file_alignment_ok:
  1652.         mov     [esi],eax
  1653.         lea     edx,[esi+12]
  1654.         mov     ecx,8
  1655.         call    read
  1656.         jc      resource_headers_ok
  1657.         mov     ecx,[esi+16]
  1658.         add     [esi],ecx
  1659.         lea     edx,[esi+20]
  1660.         sub     ecx,8
  1661.         mov     [esi+16],ecx
  1662.         lea     eax,[edx+ecx]
  1663.         cmp     eax,[structures_buffer]
  1664.         ja      out_of_memory
  1665.         call    read
  1666.         jc      invalid_file_format
  1667.         mov     edx,[esi]
  1668.         add     edx,[esi+12]
  1669.         mov     eax,[esi+16]
  1670.         lea     ecx,[esi+20]
  1671.         lea     esi,[ecx+eax]
  1672.         add     ecx,2
  1673.         cmp     word [ecx-2],0FFFFh
  1674.         je      resource_header_type_ok
  1675.       check_resource_header_type:
  1676.         cmp     ecx,esi
  1677.         jae     invalid_file_format
  1678.         cmp     word [ecx],0
  1679.         je      resource_header_type_ok
  1680.         add     ecx,2
  1681.         jmp     check_resource_header_type
  1682.       resource_header_type_ok:
  1683.         add     ecx,2
  1684.         cmp     word [ecx],0FFFFh
  1685.         je      resource_header_name_ok
  1686.       check_resource_header_name:
  1687.         cmp     ecx,esi
  1688.         jae     invalid_file_format
  1689.         cmp     word [ecx],0
  1690.         je      resource_header_name_ok
  1691.         add     ecx,2
  1692.         jmp     check_resource_header_name
  1693.       resource_header_name_ok:
  1694.         xor     al,al
  1695.         call    lseek
  1696.         jmp     read_resource_headers
  1697.       resource_headers_ok:
  1698.         xor     eax,eax
  1699.         mov     [esi],eax
  1700.         mov     [resource_data],edi
  1701.         lea     eax,[edi+16]
  1702.         cmp     eax,[display_buffer]
  1703.         jae     out_of_memory
  1704.         xor     eax,eax
  1705.         stos    dword [edi]
  1706.         call    make_timestamp
  1707.         stos    dword [edi]
  1708.         xor     eax,eax
  1709.         stos    dword [edi]
  1710.         stos    dword [edi]
  1711.         xor     ebx,ebx
  1712.       make_type_name_directory:
  1713.         mov     esi,[free_additional_memory]
  1714.         xor     edx,edx
  1715.       find_type_name:
  1716.         cmp     dword [esi],0
  1717.         je      type_name_ok
  1718.         add     esi,20
  1719.         cmp     word [esi],0FFFFh
  1720.         je      check_next_type_name
  1721.         or      ebx,ebx
  1722.         jz      check_this_type_name
  1723.         xor     ecx,ecx
  1724.       compare_with_previous_type_name:
  1725.         mov     ax,[esi+ecx]
  1726.         cmp     ax,[ebx+ecx]
  1727.         ja      check_this_type_name
  1728.         jb      check_next_type_name
  1729.         add     ecx,2
  1730.         mov     ax,[esi+ecx]
  1731.         or      ax,[ebx+ecx]
  1732.         jnz     compare_with_previous_type_name
  1733.         jmp     check_next_type_name
  1734.       check_this_type_name:
  1735.         or      edx,edx
  1736.         jz      type_name_found
  1737.         xor     ecx,ecx
  1738.       compare_with_current_type_name:
  1739.         mov     ax,[esi+ecx]
  1740.         cmp     ax,[edx+ecx]
  1741.         ja      check_next_type_name
  1742.         jb      type_name_found
  1743.         add     ecx,2
  1744.         mov     ax,[esi+ecx]
  1745.         or      ax,[edx+ecx]
  1746.         jnz     compare_with_current_type_name
  1747.         jmp     same_type_name
  1748.       type_name_found:
  1749.         mov     edx,esi
  1750.       same_type_name:
  1751.         mov     [esi-16],edi
  1752.       check_next_type_name:
  1753.         mov     eax,[esi-4]
  1754.         add     esi,eax
  1755.         jmp     find_type_name
  1756.       type_name_ok:
  1757.         or      edx,edx
  1758.         jz      type_name_directory_done
  1759.         mov     ebx,edx
  1760.       make_type_name_entry:
  1761.         mov     eax,[resource_data]
  1762.         inc     word [eax+12]
  1763.         lea     eax,[edi+8]
  1764.         cmp     eax,[display_buffer]
  1765.         jae     out_of_memory
  1766.         mov     eax,ebx
  1767.         stos    dword [edi]
  1768.         xor     eax,eax
  1769.         stos    dword [edi]
  1770.         jmp     make_type_name_directory
  1771.       type_name_directory_done:
  1772.         mov     ebx,-1
  1773.       make_type_id_directory:
  1774.         mov     esi,[free_additional_memory]
  1775.         mov     edx,10000h
  1776.       find_type_id:
  1777.         cmp     dword [esi],0
  1778.         je      type_id_ok
  1779.         add     esi,20
  1780.         cmp     word [esi],0FFFFh
  1781.         jne     check_next_type_id
  1782.         movzx   eax,word [esi+2]
  1783.         cmp     eax,ebx
  1784.         jle     check_next_type_id
  1785.         cmp     eax,edx
  1786.         jg      check_next_type_id
  1787.         mov     edx,eax
  1788.         mov     [esi-16],edi
  1789.       check_next_type_id:
  1790.         mov     eax,[esi-4]
  1791.         add     esi,eax
  1792.         jmp     find_type_id
  1793.       type_id_ok:
  1794.         cmp     edx,10000h
  1795.         je      type_id_directory_done
  1796.         mov     ebx,edx
  1797.       make_type_id_entry:
  1798.         mov     eax,[resource_data]
  1799.         inc     word [eax+14]
  1800.         lea     eax,[edi+8]
  1801.         cmp     eax,[display_buffer]
  1802.         jae     out_of_memory
  1803.         mov     eax,ebx
  1804.         stos    dword [edi]
  1805.         xor     eax,eax
  1806.         stos    dword [edi]
  1807.         jmp     make_type_id_directory
  1808.       type_id_directory_done:
  1809.         mov     esi,[resource_data]
  1810.         add     esi,10h
  1811.         mov     ecx,[esi-4]
  1812.         or      cx,cx
  1813.         jz      resource_directories_ok
  1814.       make_resource_directories:
  1815.         push    ecx
  1816.         push    edi
  1817.         mov     edx,edi
  1818.         sub     edx,[resource_data]
  1819.         bts     edx,31
  1820.         mov     [esi+4],edx
  1821.         lea     eax,[edi+16]
  1822.         cmp     eax,[display_buffer]
  1823.         jae     out_of_memory
  1824.         xor     eax,eax
  1825.         stos    dword [edi]
  1826.         call    make_timestamp
  1827.         stos    dword [edi]
  1828.         xor     eax,eax
  1829.         stos    dword [edi]
  1830.         stos    dword [edi]
  1831.         mov     ebp,esi
  1832.         xor     ebx,ebx
  1833.       make_resource_name_directory:
  1834.         mov     esi,[free_additional_memory]
  1835.         xor     edx,edx
  1836.       find_resource_name:
  1837.         cmp     dword [esi],0
  1838.         je      resource_name_ok
  1839.         push    esi
  1840.         cmp     [esi+4],ebp
  1841.         jne     check_next_resource_name
  1842.         add     esi,20
  1843.         call    skip_resource_name
  1844.         cmp     word [esi],0FFFFh
  1845.         je      check_next_resource_name
  1846.         or      ebx,ebx
  1847.         jz      check_this_resource_name
  1848.         xor     ecx,ecx
  1849.       compare_with_previous_resource_name:
  1850.         mov     ax,[esi+ecx]
  1851.         cmp     ax,[ebx+ecx]
  1852.         ja      check_this_resource_name
  1853.         jb      check_next_resource_name
  1854.         add     ecx,2
  1855.         mov     ax,[esi+ecx]
  1856.         or      ax,[ebx+ecx]
  1857.         jnz     compare_with_previous_resource_name
  1858.         jmp     check_next_resource_name
  1859.       skip_resource_name:
  1860.         cmp     word [esi],0FFFFh
  1861.         jne     skip_unicode_string
  1862.         add     esi,4
  1863.         ret
  1864.       skip_unicode_string:
  1865.         add     esi,2
  1866.         cmp     word [esi-2],0
  1867.         jne     skip_unicode_string
  1868.         ret
  1869.       check_this_resource_name:
  1870.         or      edx,edx
  1871.         jz      resource_name_found
  1872.         xor     ecx,ecx
  1873.       compare_with_current_resource_name:
  1874.         mov     ax,[esi+ecx]
  1875.         cmp     ax,[edx+ecx]
  1876.         ja      check_next_resource_name
  1877.         jb      resource_name_found
  1878.         add     ecx,2
  1879.         mov     ax,[esi+ecx]
  1880.         or      ax,[edx+ecx]
  1881.         jnz     compare_with_current_resource_name
  1882.         jmp     same_resource_name
  1883.       resource_name_found:
  1884.         mov     edx,esi
  1885.       same_resource_name:
  1886.         mov     eax,[esp]
  1887.         mov     [eax+8],edi
  1888.       check_next_resource_name:
  1889.         pop     esi
  1890.         mov     eax,[esi+16]
  1891.         lea     esi,[esi+20+eax]
  1892.         jmp     find_resource_name
  1893.       resource_name_ok:
  1894.         or      edx,edx
  1895.         jz      resource_name_directory_done
  1896.         mov     ebx,edx
  1897.       make_resource_name_entry:
  1898.         mov     eax,[esp]
  1899.         inc     word [eax+12]
  1900.         lea     eax,[edi+8]
  1901.         cmp     eax,[display_buffer]
  1902.         jae     out_of_memory
  1903.         mov     eax,ebx
  1904.         stos    dword [edi]
  1905.         xor     eax,eax
  1906.         stos    dword [edi]
  1907.         jmp     make_resource_name_directory
  1908.       resource_name_directory_done:
  1909.         mov     ebx,-1
  1910.       make_resource_id_directory:
  1911.         mov     esi,[free_additional_memory]
  1912.         mov     edx,10000h
  1913.       find_resource_id:
  1914.         cmp     dword [esi],0
  1915.         je      resource_id_ok
  1916.         push    esi
  1917.         cmp     [esi+4],ebp
  1918.         jne     check_next_resource_id
  1919.         add     esi,20
  1920.         call    skip_resource_name
  1921.         cmp     word [esi],0FFFFh
  1922.         jne     check_next_resource_id
  1923.         movzx   eax,word [esi+2]
  1924.         cmp     eax,ebx
  1925.         jle     check_next_resource_id
  1926.         cmp     eax,edx
  1927.         jg      check_next_resource_id
  1928.         mov     edx,eax
  1929.         mov     eax,[esp]
  1930.         mov     [eax+8],edi
  1931.       check_next_resource_id:
  1932.         pop     esi
  1933.         mov     eax,[esi+16]
  1934.         lea     esi,[esi+20+eax]
  1935.         jmp     find_resource_id
  1936.       resource_id_ok:
  1937.         cmp     edx,10000h
  1938.         je      resource_id_directory_done
  1939.         mov     ebx,edx
  1940.       make_resource_id_entry:
  1941.         mov     eax,[esp]
  1942.         inc     word [eax+14]
  1943.         lea     eax,[edi+8]
  1944.         cmp     eax,[display_buffer]
  1945.         jae     out_of_memory
  1946.         mov     eax,ebx
  1947.         stos    dword [edi]
  1948.         xor     eax,eax
  1949.         stos    dword [edi]
  1950.         jmp     make_resource_id_directory
  1951.       resource_id_directory_done:
  1952.         pop     eax
  1953.         mov     esi,ebp
  1954.         pop     ecx
  1955.         add     esi,8
  1956.         dec     cx
  1957.         jnz     make_resource_directories
  1958.       resource_directories_ok:
  1959.         shr     ecx,16
  1960.         jnz     make_resource_directories
  1961.         mov     esi,[resource_data]
  1962.         add     esi,10h
  1963.         movzx   eax,word [esi-4]
  1964.         movzx   edx,word [esi-2]
  1965.         add     eax,edx
  1966.         lea     esi,[esi+eax*8]
  1967.         push    edi                     ; address of language directories
  1968.       update_resource_directories:
  1969.         cmp     esi,[esp]
  1970.         je      resource_directories_updated
  1971.         add     esi,10h
  1972.         mov     ecx,[esi-4]
  1973.         or      cx,cx
  1974.         jz      language_directories_ok
  1975.       make_language_directories:
  1976.         push    ecx
  1977.         push    edi
  1978.         mov     edx,edi
  1979.         sub     edx,[resource_data]
  1980.         bts     edx,31
  1981.         mov     [esi+4],edx
  1982.         lea     eax,[edi+16]
  1983.         cmp     eax,[display_buffer]
  1984.         jae     out_of_memory
  1985.         xor     eax,eax
  1986.         stos    dword [edi]
  1987.         call    make_timestamp
  1988.         stos    dword [edi]
  1989.         xor     eax,eax
  1990.         stos    dword [edi]
  1991.         stos    dword [edi]
  1992.         mov     ebp,esi
  1993.         mov     ebx,-1
  1994.       make_language_id_directory:
  1995.         mov     esi,[free_additional_memory]
  1996.         mov     edx,10000h
  1997.       find_language_id:
  1998.         cmp     dword [esi],0
  1999.         je      language_id_ok
  2000.         push    esi
  2001.         cmp     [esi+8],ebp
  2002.         jne     check_next_language_id
  2003.         add     esi,20
  2004.         mov     eax,esi
  2005.         call    skip_resource_name
  2006.         call    skip_resource_name
  2007.         neg     eax
  2008.         add     eax,esi
  2009.         and     eax,11b
  2010.         add     esi,eax
  2011.       get_language_id:
  2012.         movzx   eax,word [esi+6]
  2013.         cmp     eax,ebx
  2014.         jle     check_next_language_id
  2015.         cmp     eax,edx
  2016.         jge     check_next_language_id
  2017.         mov     edx,eax
  2018.         mov     eax,[esp]
  2019.         mov     dword [value],eax
  2020.       check_next_language_id:
  2021.         pop     esi
  2022.         mov     eax,[esi+16]
  2023.         lea     esi,[esi+20+eax]
  2024.         jmp     find_language_id
  2025.       language_id_ok:
  2026.         cmp     edx,10000h
  2027.         je      language_id_directory_done
  2028.         mov     ebx,edx
  2029.       make_language_id_entry:
  2030.         mov     eax,[esp]
  2031.         inc     word [eax+14]
  2032.         lea     eax,[edi+8]
  2033.         cmp     eax,[display_buffer]
  2034.         jae     out_of_memory
  2035.         mov     eax,ebx
  2036.         stos    dword [edi]
  2037.         mov     eax,dword [value]
  2038.         stos    dword [edi]
  2039.         jmp     make_language_id_directory
  2040.       language_id_directory_done:
  2041.         pop     eax
  2042.         mov     esi,ebp
  2043.         pop     ecx
  2044.         add     esi,8
  2045.         dec     cx
  2046.         jnz     make_language_directories
  2047.       language_directories_ok:
  2048.         shr     ecx,16
  2049.         jnz     make_language_directories
  2050.         jmp     update_resource_directories
  2051.       resource_directories_updated:
  2052.         mov     esi,[resource_data]
  2053.         push    edi
  2054.       make_name_strings:
  2055.         add     esi,10h
  2056.         movzx   eax,word [esi-2]
  2057.         movzx   ecx,word [esi-4]
  2058.         add     eax,ecx
  2059.         lea     eax,[esi+eax*8]
  2060.         push    eax
  2061.         or      ecx,ecx
  2062.         jz      string_entries_processed
  2063.       process_string_entries:
  2064.         push    ecx
  2065.         mov     edx,edi
  2066.         sub     edx,[resource_data]
  2067.         bts     edx,31
  2068.         xchg    [esi],edx
  2069.         mov     ebx,edi
  2070.         xor     ax,ax
  2071.         stos    word [edi]
  2072.       copy_string_data:
  2073.         lea     eax,[edi+2]
  2074.         cmp     eax,[display_buffer]
  2075.         jae     out_of_memory
  2076.         mov     ax,[edx]
  2077.         or      ax,ax
  2078.         jz      string_data_copied
  2079.         stos    word [edi]
  2080.         inc     word [ebx]
  2081.         add     edx,2
  2082.         jmp     copy_string_data
  2083.       string_data_copied:
  2084.         add     esi,8
  2085.         pop     ecx
  2086.         loop    process_string_entries
  2087.       string_entries_processed:
  2088.         pop     esi
  2089.         cmp     esi,[esp]
  2090.         jb      make_name_strings
  2091.         mov     eax,edi
  2092.         sub     eax,[resource_data]
  2093.         test    al,11b
  2094.         jz      resource_strings_alignment_ok
  2095.         xor     ax,ax
  2096.         stos    word [edi]
  2097.       resource_strings_alignment_ok:
  2098.         pop     edx
  2099.         pop     ebx                     ; address of language directories
  2100.         mov     ebp,edi
  2101.       update_language_directories:
  2102.         add     ebx,10h
  2103.         movzx   eax,word [ebx-2]
  2104.         movzx   ecx,word [ebx-4]
  2105.         add     ecx,eax
  2106.       make_data_records:
  2107.         push    ecx
  2108.         mov     esi,edi
  2109.         sub     esi,[resource_data]
  2110.         xchg    esi,[ebx+4]
  2111.         lea     eax,[edi+16]
  2112.         cmp     eax,[display_buffer]
  2113.         jae     out_of_memory
  2114.         mov     eax,esi
  2115.         stos    dword [edi]
  2116.         mov     eax,[esi+12]
  2117.         stos    dword [edi]
  2118.         xor     eax,eax
  2119.         stos    dword [edi]
  2120.         stos    dword [edi]
  2121.         pop     ecx
  2122.         add     ebx,8
  2123.         loop    make_data_records
  2124.         cmp     ebx,edx
  2125.         jb      update_language_directories
  2126.         pop     ebx                     ; file handle
  2127.         mov     esi,ebp
  2128.         mov     ebp,edi
  2129.       update_data_records:
  2130.         push    ebp
  2131.         mov     ecx,edi
  2132.         mov     eax,[current_section]
  2133.         sub     ecx,[eax+14h]
  2134.         add     ecx,[eax+0Ch]
  2135.         xchg    ecx,[esi]
  2136.         mov     edx,[ecx]
  2137.         xor     al,al
  2138.         call    lseek
  2139.         mov     edx,edi
  2140.         mov     ecx,[esi+4]
  2141.         add     edi,ecx
  2142.         cmp     edi,[display_buffer]
  2143.         ja      out_of_memory
  2144.         call    read
  2145.         mov     eax,edi
  2146.         sub     eax,[resource_data]
  2147.         and     eax,11b
  2148.         jz      resource_data_alignment_ok
  2149.         mov     ecx,4
  2150.         sub     ecx,eax
  2151.         xor     al,al
  2152.         rep     stos byte [edi]
  2153.       resource_data_alignment_ok:
  2154.         pop     ebp
  2155.         add     esi,16
  2156.         cmp     esi,ebp
  2157.         jb      update_data_records
  2158.         pop     esi
  2159.         call    close
  2160.         mov     eax,edi
  2161.         sub     eax,[resource_data]
  2162.         mov     [resource_size],eax
  2163.       resource_done:
  2164.         ret
  2165. close_pe:
  2166.         call    close_pe_section
  2167.         mov     edx,[code_start]
  2168.         mov     [edx+50h],eax
  2169.         call    make_timestamp
  2170.         mov     edx,[code_start]
  2171.         mov     [edx+8],eax
  2172.         mov     eax,[number_of_relocations]
  2173.         cmp     eax,-1
  2174.         je      pe_relocations_ok
  2175.         shl     eax,2
  2176.         sub     [free_additional_memory],eax
  2177.         btr     [resolver_flags],0
  2178.         jnc     pe_relocations_ok
  2179.         or      [next_pass_needed],-1
  2180.       pe_relocations_ok:
  2181.         mov     eax,[number_of_sections]
  2182.         mov     [edx+6],ax
  2183.         imul    eax,28h
  2184.         movzx   ecx,word [edx+14h]
  2185.         lea     eax,[eax+18h+ecx]
  2186.         add     eax,[stub_size]
  2187.         mov     ecx,[edx+3Ch]
  2188.         dec     ecx
  2189.         add     eax,ecx
  2190.         not     ecx
  2191.         and     eax,ecx
  2192.         cmp     eax,[edx+54h]
  2193.         je      pe_sections_ok
  2194.         or      [next_pass_needed],-1
  2195.       pe_sections_ok:
  2196.         xor     ecx,ecx
  2197.         add     edx,78h
  2198.         test    [format_flags],8
  2199.         jz      process_directories
  2200.         add     edx,10h
  2201.       process_directories:
  2202.         mov     eax,[edx+ecx*8]
  2203.         or      eax,eax
  2204.         jz      directory_ok
  2205.         cmp     dword [edx+ecx*8+4],-1
  2206.         jne     directory_ok
  2207.       section_data:
  2208.         mov     ebx,[edx+ecx*8]
  2209.         mov     eax,[ebx+0Ch]
  2210.         mov     [edx+ecx*8],eax         ; directory rva
  2211.         mov     eax,[ebx+8]
  2212.         mov     [edx+ecx*8+4],eax       ; directory size
  2213.       directory_ok:
  2214.         inc     cl
  2215.         cmp     cl,10h
  2216.         jb      process_directories
  2217.         mov     ebx,[code_start]
  2218.         sub     ebx,[stub_size]
  2219.         mov     ecx,edi
  2220.         sub     ecx,ebx
  2221.         mov     ebp,ecx
  2222.         shr     ecx,1
  2223.         xor     eax,eax
  2224.         cdq
  2225.       calculate_checksum:
  2226.         mov     dx,[ebx]
  2227.         add     eax,edx
  2228.         mov     dx,ax
  2229.         shr     eax,16
  2230.         add     eax,edx
  2231.         add     ebx,2
  2232.         loop    calculate_checksum
  2233.         add     eax,ebp
  2234.         mov     ebx,[code_start]
  2235.         mov     [ebx+58h],eax
  2236.         ret
  2237.  
  2238. format_coff:
  2239.         mov     eax,[additional_memory]
  2240.         mov     [symbols_stream],eax
  2241.         mov     ebx,eax
  2242.         add     eax,20h
  2243.         cmp     eax,[structures_buffer]
  2244.         jae     out_of_memory
  2245.         mov     [free_additional_memory],eax
  2246.         xor     eax,eax
  2247.         mov     [ebx],al
  2248.         mov     [ebx+4],eax
  2249.         mov     [ebx+8],edi
  2250.         mov     al,4
  2251.         mov     [ebx+10h],eax
  2252.         mov     al,60h
  2253.         bt      [format_flags],0
  2254.         jnc     flat_section_flags_ok
  2255.         or      eax,0E0000000h
  2256.       flat_section_flags_ok:
  2257.         mov     dword [ebx+14h],eax
  2258.         mov     [current_section],ebx
  2259.         xor     eax,eax
  2260.         mov     [number_of_sections],eax
  2261.         mov     dword [org_origin],edi
  2262.         mov     dword [org_origin+4],eax
  2263.         mov     [org_registers],eax
  2264.         mov     [org_start],edi
  2265.         mov     [org_symbol],ebx
  2266.         mov     [labels_type],2
  2267.         mov     [code_type],32
  2268.         test    [format_flags],8
  2269.         jz      format_defined
  2270.         mov     [labels_type],4
  2271.         mov     [code_type],64
  2272.         jmp     format_defined
  2273. coff_section:
  2274.         call    close_coff_section
  2275.         mov     ebx,[free_additional_memory]
  2276.         lea     eax,[ebx+20h]
  2277.         cmp     eax,[structures_buffer]
  2278.         jae     out_of_memory
  2279.         mov     [free_additional_memory],eax
  2280.         mov     [current_section],ebx
  2281.         inc     [number_of_sections]
  2282.         xor     eax,eax
  2283.         mov     [ebx],al
  2284.         mov     [ebx+8],edi
  2285.         mov     dword [org_origin],edi
  2286.         mov     dword [org_origin+4],eax
  2287.         mov     [org_registers],eax
  2288.         mov     [org_start],edi
  2289.         mov     [org_symbol],ebx
  2290.         mov     [labels_type],2
  2291.         test    [format_flags],8
  2292.         jz      coff_labels_type_ok
  2293.         mov     [labels_type],4
  2294.       coff_labels_type_ok:
  2295.         mov     [ebx+10h],eax
  2296.         mov     [ebx+14h],eax
  2297.         lods    word [esi]
  2298.         cmp     ax,'('
  2299.         jne     invalid_argument
  2300.         mov     [ebx+4],esi
  2301.         mov     ecx,[esi]
  2302.         lea     esi,[esi+4+ecx+1]
  2303.         cmp     ecx,8
  2304.         ja      name_too_long
  2305.       coff_section_flags:
  2306.         cmp     byte [esi],1Ch
  2307.         je      coff_section_alignment
  2308.         cmp     byte [esi],19h
  2309.         jne     coff_section_settings_ok
  2310.         inc     esi
  2311.         lods    byte [esi]
  2312.         bt      [format_flags],0
  2313.         jc      coff_section_flag_ok
  2314.         cmp     al,7
  2315.         ja      invalid_argument
  2316.       coff_section_flag_ok:
  2317.         mov     cl,al
  2318.         mov     eax,1
  2319.         shl     eax,cl
  2320.         test    dword [ebx+14h],eax
  2321.         jnz     setting_already_specified
  2322.         or      dword [ebx+14h],eax
  2323.         jmp     coff_section_flags
  2324.       coff_section_alignment:
  2325.         bt      [format_flags],0
  2326.         jnc     invalid_argument
  2327.         inc     esi
  2328.         lods    byte [esi]
  2329.         or      al,al
  2330.         jnz     invalid_argument
  2331.         lods    byte [esi]
  2332.         cmp     al,'('
  2333.         jne     invalid_argument
  2334.         cmp     byte [esi],'.'
  2335.         je      invalid_value
  2336.         push    ebx
  2337.         call    get_dword_value
  2338.         pop     ebx
  2339.         cmp     [value_type],0
  2340.         jne     invalid_use_of_symbol
  2341.         mov     edx,eax
  2342.         dec     edx
  2343.         test    eax,edx
  2344.         jnz     invalid_value
  2345.         or      eax,eax
  2346.         jz      invalid_value
  2347.         cmp     eax,2000h
  2348.         ja      invalid_value
  2349.         bsf     edx,eax
  2350.         inc     edx
  2351.         shl     edx,20
  2352.         or      [ebx+14h],edx
  2353.         xchg    [ebx+10h],eax
  2354.         or      eax,eax
  2355.         jnz     setting_already_specified
  2356.         jmp     coff_section_flags
  2357.       coff_section_settings_ok:
  2358.         cmp     dword [ebx+10h],0
  2359.         jne     instruction_assembled
  2360.         mov     dword [ebx+10h],4
  2361.         bt      [format_flags],0
  2362.         jnc     instruction_assembled
  2363.         or      dword [ebx+14h],300000h
  2364.         jmp     instruction_assembled
  2365.       close_coff_section:
  2366.         mov     ebx,[current_section]
  2367.         mov     eax,edi
  2368.         mov     edx,[ebx+8]
  2369.         sub     eax,edx
  2370.         mov     [ebx+0Ch],eax
  2371.         xor     eax,eax
  2372.         xchg    [undefined_data_end],eax
  2373.         cmp     eax,edi
  2374.         jne     coff_section_ok
  2375.         cmp     edx,[undefined_data_start]
  2376.         jne     coff_section_ok
  2377.         mov     edi,edx
  2378.         or      byte [ebx+14h],80h
  2379.       coff_section_ok:
  2380.         ret
  2381. mark_coff_relocation:
  2382.         cmp     [value_type],3
  2383.         je      coff_relocation_relative
  2384.         push    ebx eax
  2385.         test    [format_flags],8
  2386.         jnz     coff_64bit_relocation
  2387.         mov     al,6
  2388.         cmp     [value_type],5
  2389.         jne     coff_relocation
  2390.         inc     al
  2391.         jmp     coff_relocation
  2392.       coff_64bit_relocation:
  2393.         mov     al,1
  2394.         cmp     [value_type],4
  2395.         je      coff_relocation
  2396.         mov     al,2
  2397.         cmp     [value_type],5
  2398.         jne     coff_relocation
  2399.         inc     al
  2400.         jmp     coff_relocation
  2401.       coff_relocation_relative:
  2402.         push    ebx
  2403.         bt      [format_flags],0
  2404.         jnc     relative_ok
  2405.         mov     ebx,[current_section]
  2406.         mov     ebx,[ebx+8]
  2407.         sub     ebx,edi
  2408.         sub     eax,ebx
  2409.         add     eax,4
  2410.       relative_ok:
  2411.         push    eax
  2412.         mov     al,20
  2413.         test    [format_flags],8
  2414.         jnz     relative_coff_64bit_relocation
  2415.         cmp     [labels_type],2
  2416.         jne     invalid_use_of_symbol
  2417.         jmp     coff_relocation
  2418.       relative_coff_64bit_relocation:
  2419.         mov     al,4
  2420.         cmp     [labels_type],4
  2421.         jne     invalid_use_of_symbol
  2422.       coff_relocation:
  2423.         mov     ebx,[free_additional_memory]
  2424.         add     ebx,0Ch
  2425.         cmp     ebx,[structures_buffer]
  2426.         jae     out_of_memory
  2427.         mov     [free_additional_memory],ebx
  2428.         mov     byte [ebx-0Ch],al
  2429.         mov     eax,[current_section]
  2430.         mov     eax,[eax+8]
  2431.         neg     eax
  2432.         add     eax,edi
  2433.         mov     [ebx-0Ch+4],eax
  2434.         mov     eax,[symbol_identifier]
  2435.         mov     [ebx-0Ch+8],eax
  2436.         pop     eax ebx
  2437.         ret
  2438. close_coff:
  2439.         call    close_coff_section
  2440.         cmp     [next_pass_needed],0
  2441.         je      coff_closed
  2442.         mov     eax,[symbols_stream]
  2443.         mov     [free_additional_memory],eax
  2444.       coff_closed:
  2445.         ret
  2446. coff_formatter:
  2447.         sub     edi,[code_start]
  2448.         mov     [code_size],edi
  2449.         call    prepare_default_section
  2450.         mov     edi,[free_additional_memory]
  2451.         mov     ebx,edi
  2452.         mov     ecx,28h shr 2
  2453.         imul    ecx,[number_of_sections]
  2454.         add     ecx,14h shr 2
  2455.         lea     eax,[edi+ecx*4]
  2456.         cmp     eax,[structures_buffer]
  2457.         jae     out_of_memory
  2458.         xor     eax,eax
  2459.         rep     stos dword [edi]
  2460.         mov     word [ebx],14Ch
  2461.         test    [format_flags],8
  2462.         jz      coff_magic_ok
  2463.         mov     word [ebx],8664h
  2464.       coff_magic_ok:
  2465.         mov     word [ebx+12h],104h
  2466.         bt      [format_flags],0
  2467.         jnc     coff_flags_ok
  2468.         or      byte [ebx+12h],80h
  2469.       coff_flags_ok:
  2470.         push    ebx
  2471.         call    make_timestamp
  2472.         pop     ebx
  2473.         mov     [ebx+4],eax
  2474.         mov     eax,[number_of_sections]
  2475.         mov     [ebx+2],ax
  2476.         mov     esi,[symbols_stream]
  2477.         xor     eax,eax
  2478.         xor     ecx,ecx
  2479.       enumerate_symbols:
  2480.         cmp     esi,[free_additional_memory]
  2481.         je      symbols_enumerated
  2482.         mov     dl,[esi]
  2483.         or      dl,dl
  2484.         jz      enumerate_section
  2485.         cmp     dl,0C0h
  2486.         jae     enumerate_public
  2487.         cmp     dl,80h
  2488.         jae     enumerate_extrn
  2489.         add     esi,0Ch
  2490.         jmp     enumerate_symbols
  2491.       enumerate_section:
  2492.         mov     edx,eax
  2493.         shl     edx,8
  2494.         mov     [esi],edx
  2495.         inc     eax
  2496.         inc     ecx
  2497.         mov     [esi+1Eh],cx
  2498.         add     esi,20h
  2499.         jmp     enumerate_symbols
  2500.       enumerate_public:
  2501.         mov     edx,eax
  2502.         shl     edx,8
  2503.         mov     dl,[esi]
  2504.         mov     [esi],edx
  2505.         mov     edx,[esi+8]
  2506.         add     esi,10h
  2507.         inc     eax
  2508.         cmp     byte [edx+11],2
  2509.         jne     enumerate_symbols
  2510.         mov     edx,[edx+20]
  2511.         cmp     byte [edx],0C0h
  2512.         jae     enumerate_symbols
  2513.         cmp     byte [edx],80h
  2514.         jb      enumerate_symbols
  2515.         inc     eax
  2516.         jmp     enumerate_symbols
  2517.       enumerate_extrn:
  2518.         mov     edx,eax
  2519.         shl     edx,8
  2520.         mov     dl,[esi]
  2521.         mov     [esi],edx
  2522.         add     esi,0Ch
  2523.         inc     eax
  2524.         jmp     enumerate_symbols
  2525.       prepare_default_section:
  2526.         mov     ebx,[symbols_stream]
  2527.         cmp     dword [ebx+0Ch],0
  2528.         jne     default_section_ok
  2529.         cmp     [number_of_sections],0
  2530.         je      default_section_ok
  2531.         mov     edx,ebx
  2532.       find_references_to_default_section:
  2533.         cmp     ebx,[free_additional_memory]
  2534.         jne     check_reference
  2535.         add     [symbols_stream],20h
  2536.         ret
  2537.       check_reference:
  2538.         mov     al,[ebx]
  2539.         or      al,al
  2540.         jz      skip_other_section
  2541.         cmp     al,0C0h
  2542.         jae     check_public_reference
  2543.         cmp     al,80h
  2544.         jae     next_reference
  2545.         cmp     edx,[ebx+8]
  2546.         je      default_section_ok
  2547.       next_reference:
  2548.         add     ebx,0Ch
  2549.         jmp     find_references_to_default_section
  2550.       check_public_reference:
  2551.         mov     eax,[ebx+8]
  2552.         add     ebx,10h
  2553.         test    byte [eax+8],1
  2554.         jz      find_references_to_default_section
  2555.         mov     cx,[current_pass]
  2556.         cmp     cx,[eax+16]
  2557.         jne     find_references_to_default_section
  2558.         cmp     edx,[eax+20]
  2559.         je      default_section_ok
  2560.         jmp     find_references_to_default_section
  2561.       skip_other_section:
  2562.         add     ebx,20h
  2563.         jmp     find_references_to_default_section
  2564.       default_section_ok:
  2565.         inc     [number_of_sections]
  2566.         ret
  2567.       symbols_enumerated:
  2568.         mov     [ebx+0Ch],eax
  2569.         mov     ebp,edi
  2570.         sub     ebp,ebx
  2571.         push    ebp
  2572.         lea     edi,[ebx+14h]
  2573.         mov     esi,[symbols_stream]
  2574.       find_section:
  2575.         cmp     esi,[free_additional_memory]
  2576.         je      sections_finished
  2577.         mov     al,[esi]
  2578.         or      al,al
  2579.         jz      section_found
  2580.         add     esi,0Ch
  2581.         cmp     al,0C0h
  2582.         jb      find_section
  2583.         add     esi,4
  2584.         jmp     find_section
  2585.       section_found:
  2586.         push    esi edi
  2587.         mov     esi,[esi+4]
  2588.         or      esi,esi
  2589.         jz      default_section
  2590.         mov     ecx,[esi]
  2591.         add     esi,4
  2592.         rep     movs byte [edi],[esi]
  2593.         jmp     section_name_ok
  2594.       default_section:
  2595.         mov     al,'.'
  2596.         stos    byte [edi]
  2597.         mov     eax,'flat'
  2598.         stos    dword [edi]
  2599.       section_name_ok:
  2600.         pop     edi esi
  2601.         mov     eax,[esi+0Ch]
  2602.         mov     [edi+10h],eax
  2603.         mov     eax,[esi+14h]
  2604.         mov     [edi+24h],eax
  2605.         test    al,80h
  2606.         jnz     section_ptr_ok
  2607.         mov     eax,[esi+8]
  2608.         sub     eax,[code_start]
  2609.         add     eax,ebp
  2610.         mov     [edi+14h],eax
  2611.       section_ptr_ok:
  2612.         mov     ebx,[code_start]
  2613.         mov     edx,[code_size]
  2614.         add     ebx,edx
  2615.         add     edx,ebp
  2616.         xor     ecx,ecx
  2617.         add     esi,20h
  2618.       find_relocations:
  2619.         cmp     esi,[free_additional_memory]
  2620.         je      section_relocations_done
  2621.         mov     al,[esi]
  2622.         or      al,al
  2623.         jz      section_relocations_done
  2624.         cmp     al,80h
  2625.         jb      add_relocation
  2626.         cmp     al,0C0h
  2627.         jb      next_relocation
  2628.         add     esi,10h
  2629.         jmp     find_relocations
  2630.       add_relocation:
  2631.         lea     eax,[ebx+0Ah]
  2632.         cmp     eax,[display_buffer]
  2633.         ja      out_of_memory
  2634.         mov     eax,[esi+4]
  2635.         mov     [ebx],eax
  2636.         mov     eax,[esi+8]
  2637.         mov     eax,[eax]
  2638.         shr     eax,8
  2639.         mov     [ebx+4],eax
  2640.         movzx   ax,byte [esi]
  2641.         mov     [ebx+8],ax
  2642.         add     ebx,0Ah
  2643.         inc     ecx
  2644.       next_relocation:
  2645.         add     esi,0Ch
  2646.         jmp     find_relocations
  2647.       section_relocations_done:
  2648.         cmp     ecx,10000h
  2649.         jb      section_relocations_count_16bit
  2650.         bt      [format_flags],0
  2651.         jnc     format_limitations_exceeded
  2652.         mov     word [edi+20h],0FFFFh
  2653.         or      dword [edi+24h],1000000h
  2654.         mov     [edi+18h],edx
  2655.         push    esi edi
  2656.         push    ecx
  2657.         lea     esi,[ebx-1]
  2658.         add     ebx,0Ah
  2659.         lea     edi,[ebx-1]
  2660.         imul    ecx,0Ah
  2661.         std
  2662.         rep     movs byte [edi],[esi]
  2663.         cld
  2664.         pop     ecx
  2665.         inc     esi
  2666.         inc     ecx
  2667.         mov     [esi],ecx
  2668.         xor     eax,eax
  2669.         mov     [esi+4],eax
  2670.         mov     [esi+8],ax
  2671.         pop     edi esi
  2672.         jmp     section_relocations_ok
  2673.       section_relocations_count_16bit:
  2674.         mov     [edi+20h],cx
  2675.         jcxz    section_relocations_ok
  2676.         mov     [edi+18h],edx
  2677.       section_relocations_ok:
  2678.         sub     ebx,[code_start]
  2679.         mov     [code_size],ebx
  2680.         add     edi,28h
  2681.         jmp     find_section
  2682.       sections_finished:
  2683.         mov     edx,[free_additional_memory]
  2684.         mov     ebx,[code_size]
  2685.         add     ebp,ebx
  2686.         mov     [edx+8],ebp
  2687.         add     ebx,[code_start]
  2688.         mov     edi,ebx
  2689.         mov     ecx,[edx+0Ch]
  2690.         imul    ecx,12h shr 1
  2691.         xor     eax,eax
  2692.         shr     ecx,1
  2693.         jnc     zero_symbols_table
  2694.         stos    word [edi]
  2695.       zero_symbols_table:
  2696.         rep     stos dword [edi]
  2697.         mov     edx,edi
  2698.         stos    dword [edi]
  2699.         mov     esi,[symbols_stream]
  2700.       make_symbols_table:
  2701.         cmp     esi,[free_additional_memory]
  2702.         je      symbols_table_ok
  2703.         mov     al,[esi]
  2704.         cmp     al,0C0h
  2705.         jae     add_public_symbol
  2706.         cmp     al,80h
  2707.         jae     add_extrn_symbol
  2708.         or      al,al
  2709.         jz      add_section_symbol
  2710.         add     esi,0Ch
  2711.         jmp     make_symbols_table
  2712.       add_section_symbol:
  2713.         call    store_symbol_name
  2714.         movzx   eax,word [esi+1Eh]
  2715.         mov     [ebx+0Ch],ax
  2716.         mov     byte [ebx+10h],3
  2717.         add     esi,20h
  2718.         add     ebx,12h
  2719.         jmp     make_symbols_table
  2720.       add_extrn_symbol:
  2721.         call    store_symbol_name
  2722.         mov     byte [ebx+10h],2
  2723.         add     esi,0Ch
  2724.         add     ebx,12h
  2725.         jmp     make_symbols_table
  2726.       add_public_symbol:
  2727.         call    store_symbol_name
  2728.         mov     eax,[esi+0Ch]
  2729.         mov     [current_line],eax
  2730.         mov     eax,[esi+8]
  2731.         test    byte [eax+8],1
  2732.         jz      undefined_coff_public
  2733.         mov     cx,[current_pass]
  2734.         cmp     cx,[eax+16]
  2735.         jne     undefined_coff_public
  2736.         mov     cl,[eax+11]
  2737.         or      cl,cl
  2738.         jz      public_constant
  2739.         test    [format_flags],8
  2740.         jnz     check_64bit_public_symbol
  2741.         cmp     cl,2
  2742.         je      public_symbol_type_ok
  2743.         jmp     invalid_use_of_symbol
  2744.       undefined_coff_public:
  2745.         mov     eax,[eax+24]
  2746.         mov     [error_info],eax
  2747.         jmp     undefined_symbol
  2748.       check_64bit_public_symbol:
  2749.         cmp     cl,4
  2750.         jne     invalid_use_of_symbol
  2751.       public_symbol_type_ok:
  2752.         mov     ecx,[eax+20]
  2753.         cmp     byte [ecx],80h
  2754.         je      alias_symbol
  2755.         cmp     byte [ecx],0
  2756.         jne     invalid_use_of_symbol
  2757.         mov     cx,[ecx+1Eh]
  2758.         mov     [ebx+0Ch],cx
  2759.       public_symbol_section_ok:
  2760.         cmp     dword [eax+4],0
  2761.         je      store_public_symbol
  2762.         cmp     dword [eax+4],-1
  2763.         jne     value_out_of_range
  2764.         bt      dword [eax],31
  2765.         jnc     value_out_of_range
  2766.       store_public_symbol:
  2767.         mov     eax,[eax]
  2768.         mov     [ebx+8],eax
  2769.         mov     al,2
  2770.         cmp     byte [esi],0C0h
  2771.         je      store_symbol_class
  2772.         inc     al
  2773.         cmp     byte [esi],0C1h
  2774.         je      store_symbol_class
  2775.         mov     al,105
  2776.       store_symbol_class:
  2777.         mov     byte [ebx+10h],al
  2778.         add     esi,10h
  2779.         add     ebx,12h
  2780.         jmp     make_symbols_table
  2781.       alias_symbol:
  2782.         bt      [format_flags],0
  2783.         jnc     invalid_use_of_symbol
  2784.         mov     ecx,[eax]
  2785.         or      ecx,[eax+4]
  2786.         jnz     invalid_use_of_symbol
  2787.         mov     byte [ebx+10h],69h
  2788.         mov     byte [ebx+11h],1
  2789.         add     ebx,12h
  2790.         mov     ecx,[eax+20]
  2791.         mov     ecx,[ecx]
  2792.         shr     ecx,8
  2793.         mov     [ebx],ecx
  2794.         mov     byte [ebx+4],3
  2795.         add     esi,10h
  2796.         add     ebx,12h
  2797.         jmp     make_symbols_table
  2798.       public_constant:
  2799.         mov     word [ebx+0Ch],0FFFFh
  2800.         jmp     public_symbol_section_ok
  2801.       symbols_table_ok:
  2802.         mov     eax,edi
  2803.         sub     eax,edx
  2804.         mov     [edx],eax
  2805.         sub     edi,[code_start]
  2806.         mov     [code_size],edi
  2807.         mov     [written_size],0
  2808.         mov     edx,[output_file]
  2809.         call    create
  2810.         jc      write_failed
  2811.         mov     edx,[free_additional_memory]
  2812.         pop     ecx
  2813.         add     [written_size],ecx
  2814.         call    write
  2815.         jc      write_failed
  2816.         jmp     write_output
  2817.       store_symbol_name:
  2818.         push    esi
  2819.         mov     esi,[esi+4]
  2820.         or      esi,esi
  2821.         jz      default_name
  2822.         lods    dword [esi]
  2823.         mov     ecx,eax
  2824.         cmp     ecx,8
  2825.         ja      add_string
  2826.         push    edi
  2827.         mov     edi,ebx
  2828.         rep     movs byte [edi],[esi]
  2829.         pop     edi esi
  2830.         ret
  2831.       default_name:
  2832.         mov     dword [ebx],'.fla'
  2833.         mov     dword [ebx+4],'t'
  2834.         pop     esi
  2835.         ret
  2836.       add_string:
  2837.         mov     eax,edi
  2838.         sub     eax,edx
  2839.         mov     [ebx+4],eax
  2840.         inc     ecx
  2841.         rep     movs byte [edi],[esi]
  2842.         pop     esi
  2843.         ret
  2844.  
  2845. format_elf:
  2846.         test    [format_flags],8
  2847.         jnz     format_elf64
  2848.         mov     edx,edi
  2849.         mov     ecx,34h shr 2
  2850.         lea     eax,[edi+ecx*4]
  2851.         cmp     eax,[display_buffer]
  2852.         jae     out_of_memory
  2853.         xor     eax,eax
  2854.         rep     stos dword [edi]
  2855.         mov     dword [edx],7Fh + 'ELF' shl 8
  2856.         mov     al,1
  2857.         mov     [edx+4],al
  2858.         mov     [edx+5],al
  2859.         mov     [edx+6],al
  2860.         mov     [edx+14h],al
  2861.         mov     byte [edx+12h],3
  2862.         mov     byte [edx+28h],34h
  2863.         mov     byte [edx+2Eh],28h
  2864.         mov     [code_type],32
  2865.         cmp     word [esi],1D19h
  2866.         je      format_elf_exe
  2867.         mov     [labels_type],2
  2868.       elf_header_ok:
  2869.         mov     byte [edx+10h],1
  2870.         mov     eax,[additional_memory]
  2871.         mov     [symbols_stream],eax
  2872.         mov     ebx,eax
  2873.         add     eax,20h
  2874.         cmp     eax,[structures_buffer]
  2875.         jae     out_of_memory
  2876.         mov     [free_additional_memory],eax
  2877.         xor     eax,eax
  2878.         mov     [current_section],ebx
  2879.         mov     [number_of_sections],eax
  2880.         mov     dword [org_origin],edi
  2881.         mov     dword [org_origin+4],eax
  2882.         mov     [org_registers],eax
  2883.         mov     [org_start],edi
  2884.         mov     [org_symbol],ebx
  2885.         mov     [ebx],al
  2886.         mov     [ebx+4],eax
  2887.         mov     [ebx+8],edi
  2888.         mov     al,111b
  2889.         mov     [ebx+14h],eax
  2890.         mov     al,4
  2891.         mov     [ebx+10h],eax
  2892.         test    [format_flags],8
  2893.         jz      format_defined
  2894.         mov     byte [ebx+10h],8
  2895.         jmp     format_defined
  2896.       format_elf64:
  2897.         mov     edx,edi
  2898.         mov     ecx,40h shr 2
  2899.         lea     eax,[edi+ecx*4]
  2900.         cmp     eax,[display_buffer]
  2901.         jae     out_of_memory
  2902.         xor     eax,eax
  2903.         rep     stos dword [edi]
  2904.         mov     dword [edx],7Fh + 'ELF' shl 8
  2905.         mov     al,1
  2906.         mov     [edx+5],al
  2907.         mov     [edx+6],al
  2908.         mov     [edx+14h],al
  2909.         mov     byte [edx+4],2
  2910.         mov     byte [edx+12h],62
  2911.         mov     byte [edx+34h],40h
  2912.         mov     byte [edx+3Ah],40h
  2913.         mov     [code_type],64
  2914.         cmp     word [esi],1D19h
  2915.         je      format_elf64_exe
  2916.         mov     [labels_type],4
  2917.         jmp     elf_header_ok
  2918. elf_section:
  2919.         bt      [format_flags],0
  2920.         jc      illegal_instruction
  2921.         call    close_coff_section
  2922.         mov     ebx,[free_additional_memory]
  2923.         lea     eax,[ebx+20h]
  2924.         cmp     eax,[structures_buffer]
  2925.         jae     out_of_memory
  2926.         mov     [free_additional_memory],eax
  2927.         mov     [current_section],ebx
  2928.         inc     word [number_of_sections]
  2929.         jz      format_limitations_exceeded
  2930.         xor     eax,eax
  2931.         mov     [ebx],al
  2932.         mov     [ebx+8],edi
  2933.         mov     dword [org_origin],edi
  2934.         mov     dword [org_origin+4],eax
  2935.         mov     [org_registers],eax
  2936.         mov     [org_start],edi
  2937.         mov     [org_symbol],ebx
  2938.         test    [format_flags],8
  2939.         jnz     elf64_labels_type
  2940.         mov     [labels_type],2
  2941.         jmp     elf_labels_type_ok
  2942.       elf64_labels_type:
  2943.         mov     [labels_type],4
  2944.       elf_labels_type_ok:
  2945.         mov     [ebx+10h],eax
  2946.         mov     al,10b
  2947.         mov     [ebx+14h],eax
  2948.         lods    word [esi]
  2949.         cmp     ax,'('
  2950.         jne     invalid_argument
  2951.         mov     [ebx+4],esi
  2952.         mov     ecx,[esi]
  2953.         lea     esi,[esi+4+ecx+1]
  2954.       elf_section_flags:
  2955.         cmp     byte [esi],1Ch
  2956.         je      elf_section_alignment
  2957.         cmp     byte [esi],19h
  2958.         jne     elf_section_settings_ok
  2959.         inc     esi
  2960.         lods    byte [esi]
  2961.         sub     al,28
  2962.         xor     al,11b
  2963.         test    al,not 10b
  2964.         jnz     invalid_argument
  2965.         mov     cl,al
  2966.         mov     al,1
  2967.         shl     al,cl
  2968.         test    byte [ebx+14h],al
  2969.         jnz     setting_already_specified
  2970.         or      byte [ebx+14h],al
  2971.         jmp     elf_section_flags
  2972.       elf_section_alignment:
  2973.         inc     esi
  2974.         lods    byte [esi]
  2975.         or      al,al
  2976.         jnz     invalid_argument
  2977.         lods    byte [esi]
  2978.         cmp     al,'('
  2979.         jne     invalid_argument
  2980.         cmp     byte [esi],'.'
  2981.         je      invalid_value
  2982.         push    ebx
  2983.         call    get_dword_value
  2984.         pop     ebx
  2985.         cmp     [value_type],0
  2986.         jne     invalid_use_of_symbol
  2987.         mov     edx,eax
  2988.         dec     edx
  2989.         test    eax,edx
  2990.         jnz     invalid_value
  2991.         or      eax,eax
  2992.         jz      invalid_value
  2993.         xchg    [ebx+10h],eax
  2994.         or      eax,eax
  2995.         jnz     setting_already_specified
  2996.         jmp     elf_section_flags
  2997.       elf_section_settings_ok:
  2998.         cmp     dword [ebx+10h],0
  2999.         jne     instruction_assembled
  3000.         mov     dword [ebx+10h],4
  3001.         test    [format_flags],8
  3002.         jz      instruction_assembled
  3003.         mov     byte [ebx+10h],8
  3004.         jmp     instruction_assembled
  3005. mark_elf_relocation:
  3006.         cmp     [value_type],3
  3007.         je      elf_relocation_relative
  3008.         cmp     [value_type],7
  3009.         je      elf_relocation_relative
  3010.         push    ebx eax
  3011.         cmp     [value_type],5
  3012.         je      elf_gotoff_relocation
  3013.         ja      invalid_use_of_symbol
  3014.         mov     al,1                    ; R_386_32 / R_AMD64_64
  3015.         test    [format_flags],8
  3016.         jz      coff_relocation
  3017.         cmp     [value_type],4
  3018.         je      coff_relocation
  3019.         mov     al,11                   ; R_AMD64_32S
  3020.         jmp     coff_relocation
  3021.       elf_gotoff_relocation:
  3022.         test    [format_flags],8
  3023.         jnz     invalid_use_of_symbol
  3024.         mov     al,9                    ; R_386_GOTOFF
  3025.         jmp     coff_relocation
  3026.       elf_relocation_relative:
  3027.         cmp     [labels_type],0
  3028.         je      invalid_use_of_symbol
  3029.         push    ebx
  3030.         mov     ebx,[current_section]
  3031.         mov     ebx,[ebx+8]
  3032.         sub     ebx,edi
  3033.         sub     eax,ebx
  3034.         push    eax
  3035.         mov     al,2                    ; R_386_PC32 / R_AMD64_PC32
  3036.         cmp     [value_type],3
  3037.         je      coff_relocation
  3038.         mov     al,4                    ; R_386_PLT32 / R_AMD64_PLT32
  3039.         jmp     coff_relocation
  3040. close_elf:
  3041.         bt      [format_flags],0
  3042.         jc      close_elf_exe
  3043.         call    close_coff_section
  3044.         cmp     [next_pass_needed],0
  3045.         je      elf_closed
  3046.         mov     eax,[symbols_stream]
  3047.         mov     [free_additional_memory],eax
  3048.       elf_closed:
  3049.         ret
  3050. elf_formatter:
  3051.         push    edi
  3052.         call    prepare_default_section
  3053.         mov     esi,[symbols_stream]
  3054.         mov     edi,[free_additional_memory]
  3055.         xor     eax,eax
  3056.         mov     ecx,4
  3057.         rep     stos dword [edi]
  3058.         test    [format_flags],8
  3059.         jz      find_first_section
  3060.         mov     ecx,2
  3061.         rep     stos dword [edi]
  3062.       find_first_section:
  3063.         mov     al,[esi]
  3064.         or      al,al
  3065.         jz      first_section_found
  3066.         cmp     al,0C0h
  3067.         jb      skip_other_symbol
  3068.         add     esi,4
  3069.       skip_other_symbol:
  3070.         add     esi,0Ch
  3071.         jmp     find_first_section
  3072.       first_section_found:
  3073.         mov     ebx,esi
  3074.         mov     ebp,esi
  3075.         add     esi,20h
  3076.         xor     ecx,ecx
  3077.         xor     edx,edx
  3078.       find_next_section:
  3079.         cmp     esi,[free_additional_memory]
  3080.         je      make_section_symbol
  3081.         mov     al,[esi]
  3082.         or      al,al
  3083.         jz      make_section_symbol
  3084.         cmp     al,0C0h
  3085.         jae     skip_public
  3086.         cmp     al,80h
  3087.         jae     skip_extrn
  3088.         or      byte [ebx+14h],40h
  3089.       skip_extrn:
  3090.         add     esi,0Ch
  3091.         jmp     find_next_section
  3092.       skip_public:
  3093.         add     esi,10h
  3094.         jmp     find_next_section
  3095.       make_section_symbol:
  3096.         mov     eax,edi
  3097.         xchg    eax,[ebx+4]
  3098.         stos    dword [edi]
  3099.         test    [format_flags],8
  3100.         jnz     elf64_section_symbol
  3101.         xor     eax,eax
  3102.         stos    dword [edi]
  3103.         stos    dword [edi]
  3104.         call    store_section_index
  3105.         jmp     section_symbol_ok
  3106.       store_section_index:
  3107.         inc     ecx
  3108.         mov     eax,ecx
  3109.         shl     eax,8
  3110.         mov     [ebx],eax
  3111.         inc     dx
  3112.         jz      format_limitations_exceeded
  3113.         mov     eax,edx
  3114.         shl     eax,16
  3115.         mov     al,3
  3116.         test    byte [ebx+14h],40h
  3117.         jz      section_index_ok
  3118.         or      ah,-1
  3119.         inc     dx
  3120.         jz      format_limitations_exceeded
  3121.       section_index_ok:
  3122.         stos    dword [edi]
  3123.         ret
  3124.       elf64_section_symbol:
  3125.         call    store_section_index
  3126.         xor     eax,eax
  3127.         stos    dword [edi]
  3128.         stos    dword [edi]
  3129.         stos    dword [edi]
  3130.         stos    dword [edi]
  3131.       section_symbol_ok:
  3132.         mov     ebx,esi
  3133.         add     esi,20h
  3134.         cmp     ebx,[free_additional_memory]
  3135.         jne     find_next_section
  3136.         inc     dx
  3137.         jz      format_limitations_exceeded
  3138.         mov     [current_section],edx
  3139.         mov     esi,[symbols_stream]
  3140.       find_other_symbols:
  3141.         cmp     esi,[free_additional_memory]
  3142.         je      elf_symbol_table_ok
  3143.         mov     al,[esi]
  3144.         or      al,al
  3145.         jz      skip_section
  3146.         cmp     al,0C0h
  3147.         jae     make_public_symbol
  3148.         cmp     al,80h
  3149.         jae     make_extrn_symbol
  3150.         add     esi,0Ch
  3151.         jmp     find_other_symbols
  3152.       skip_section:
  3153.         add     esi,20h
  3154.         jmp     find_other_symbols
  3155.       make_public_symbol:
  3156.         mov     eax,[esi+0Ch]
  3157.         mov     [current_line],eax
  3158.         cmp     byte [esi],0C0h
  3159.         jne     invalid_argument
  3160.         mov     ebx,[esi+8]
  3161.         test    byte [ebx+8],1
  3162.         jz      undefined_public
  3163.         mov     ax,[current_pass]
  3164.         cmp     ax,[ebx+16]
  3165.         jne     undefined_public
  3166.         mov     dl,[ebx+11]
  3167.         or      dl,dl
  3168.         jz      public_absolute
  3169.         mov     eax,[ebx+20]
  3170.         cmp     byte [eax],0
  3171.         jne     invalid_use_of_symbol
  3172.         mov     eax,[eax+4]
  3173.         test    [format_flags],8
  3174.         jnz     elf64_public
  3175.         cmp     dl,2
  3176.         jne     invalid_use_of_symbol
  3177.         mov     dx,[eax+0Eh]
  3178.         jmp     section_for_public_ok
  3179.       undefined_public:
  3180.         mov     eax,[ebx+24]
  3181.         mov     [error_info],eax
  3182.         jmp     undefined_symbol
  3183.       elf64_public:
  3184.         cmp     dl,4
  3185.         jne     invalid_use_of_symbol
  3186.         mov     dx,[eax+6]
  3187.         jmp     section_for_public_ok
  3188.       public_absolute:
  3189.         mov     dx,0FFF1h
  3190.       section_for_public_ok:
  3191.         mov     eax,[esi+4]
  3192.         stos    dword [edi]
  3193.         test    [format_flags],8
  3194.         jnz     elf64_public_symbol
  3195.         call    get_public_value
  3196.         stos    dword [edi]
  3197.         xor     eax,eax
  3198.         mov     al,[ebx+10]
  3199.         stos    dword [edi]
  3200.         mov     eax,edx
  3201.         shl     eax,16
  3202.         mov     al,10h
  3203.         cmp     byte [ebx+10],0
  3204.         je      elf_public_function
  3205.         or      al,1
  3206.         jmp     store_elf_public_info
  3207.       elf_public_function:
  3208.         or      al,2
  3209.       store_elf_public_info:
  3210.         stos    dword [edi]
  3211.         jmp     public_symbol_ok
  3212.       elf64_public_symbol:
  3213.         mov     eax,edx
  3214.         shl     eax,16
  3215.         mov     al,10h
  3216.         cmp     byte [ebx+10],0
  3217.         je      elf64_public_function
  3218.         or      al,1
  3219.         jmp     store_elf64_public_info
  3220.       elf64_public_function:
  3221.         or      al,2
  3222.       store_elf64_public_info:
  3223.         stos    dword [edi]
  3224.         call    get_public_value
  3225.         stos    dword [edi]
  3226.         xor     eax,eax
  3227.         stos    dword [edi]
  3228.         mov     al,[ebx+10]
  3229.         stos    dword [edi]
  3230.         xor     al,al
  3231.         stos    dword [edi]
  3232.       public_symbol_ok:
  3233.         inc     ecx
  3234.         mov     eax,ecx
  3235.         shl     eax,8
  3236.         mov     al,0C0h
  3237.         mov     [esi],eax
  3238.         add     esi,10h
  3239.         jmp     find_other_symbols
  3240.       get_public_value:
  3241.         mov     eax,[ebx]
  3242.         cmp     dword [ebx+4],0
  3243.         je      public_value_ok
  3244.         cmp     dword [ebx+4],-1
  3245.         jne     value_out_of_range
  3246.         bt      eax,31
  3247.         jnc     value_out_of_range
  3248.       public_value_ok:
  3249.         ret
  3250.       make_extrn_symbol:
  3251.         mov     eax,[esi+4]
  3252.         stos    dword [edi]
  3253.         test    [format_flags],8
  3254.         jnz     elf64_extrn_symbol
  3255.         xor     eax,eax
  3256.         stos    dword [edi]
  3257.         mov     eax,[esi+8]
  3258.         stos    dword [edi]
  3259.         mov     eax,10h
  3260.         stos    dword [edi]
  3261.         jmp     extrn_symbol_ok
  3262.       elf64_extrn_symbol:
  3263.         mov     eax,10h
  3264.         stos    dword [edi]
  3265.         xor     al,al
  3266.         stos    dword [edi]
  3267.         stos    dword [edi]
  3268.         mov     eax,[esi+8]
  3269.         stos    dword [edi]
  3270.         xor     eax,eax
  3271.         stos    dword [edi]
  3272.       extrn_symbol_ok:
  3273.         inc     ecx
  3274.         mov     eax,ecx
  3275.         shl     eax,8
  3276.         mov     al,80h
  3277.         mov     [esi],eax
  3278.         add     esi,0Ch
  3279.         jmp     find_other_symbols
  3280.       elf_symbol_table_ok:
  3281.         mov     edx,edi
  3282.         mov     ebx,[free_additional_memory]
  3283.         xor     al,al
  3284.         stos    byte [edi]
  3285.         add     edi,16
  3286.         mov     [edx+1],edx
  3287.         add     ebx,10h
  3288.         test    [format_flags],8
  3289.         jz      make_string_table
  3290.         add     ebx,8
  3291.       make_string_table:
  3292.         cmp     ebx,edx
  3293.         je      elf_string_table_ok
  3294.         test    [format_flags],8
  3295.         jnz     make_elf64_string
  3296.         cmp     byte [ebx+0Dh],0
  3297.         je      rel_prefix_ok
  3298.         mov     byte [ebx+0Dh],0
  3299.         mov     eax,'.rel'
  3300.         stos    dword [edi]
  3301.       rel_prefix_ok:
  3302.         mov     esi,edi
  3303.         sub     esi,edx
  3304.         xchg    esi,[ebx]
  3305.         add     ebx,10h
  3306.       make_elf_string:
  3307.         or      esi,esi
  3308.         jz      default_string
  3309.         lods    dword [esi]
  3310.         mov     ecx,eax
  3311.         rep     movs byte [edi],[esi]
  3312.         xor     al,al
  3313.         stos    byte [edi]
  3314.         jmp     make_string_table
  3315.       make_elf64_string:
  3316.         cmp     byte [ebx+5],0
  3317.         je      elf64_rel_prefix_ok
  3318.         mov     byte [ebx+5],0
  3319.         mov     eax,'.rel'
  3320.         stos    dword [edi]
  3321.         mov     al,'a'
  3322.         stos    byte [edi]
  3323.       elf64_rel_prefix_ok:
  3324.         mov     esi,edi
  3325.         sub     esi,edx
  3326.         xchg    esi,[ebx]
  3327.         add     ebx,18h
  3328.         jmp     make_elf_string
  3329.       default_string:
  3330.         mov     eax,'.fla'
  3331.         stos    dword [edi]
  3332.         mov     ax,'t'
  3333.         stos    word [edi]
  3334.         jmp     make_string_table
  3335.       elf_string_table_ok:
  3336.         mov     [edx+1+8],edi
  3337.         mov     ebx,[code_start]
  3338.         mov     eax,edi
  3339.         sub     eax,[free_additional_memory]
  3340.         test    [format_flags],8
  3341.         jnz     finish_elf64_header
  3342.         mov     [ebx+20h],eax
  3343.         mov     eax,[current_section]
  3344.         inc     ax
  3345.         jz      format_limitations_exceeded
  3346.         mov     [ebx+32h],ax
  3347.         inc     ax
  3348.         jz      format_limitations_exceeded
  3349.         mov     [ebx+30h],ax
  3350.         jmp     elf_header_finished
  3351.       finish_elf64_header:
  3352.         mov     [ebx+28h],eax
  3353.         mov     eax,[current_section]
  3354.         inc     ax
  3355.         jz      format_limitations_exceeded
  3356.         mov     [ebx+3Eh],ax
  3357.         inc     ax
  3358.         jz      format_limitations_exceeded
  3359.         mov     [ebx+3Ch],ax
  3360.       elf_header_finished:
  3361.         xor     eax,eax
  3362.         mov     ecx,10
  3363.         rep     stos dword [edi]
  3364.         test    [format_flags],8
  3365.         jz      elf_null_section_ok
  3366.         mov     ecx,6
  3367.         rep     stos dword [edi]
  3368.       elf_null_section_ok:
  3369.         mov     esi,ebp
  3370.         xor     ecx,ecx
  3371.       make_section_entry:
  3372.         mov     ebx,edi
  3373.         mov     eax,[esi+4]
  3374.         mov     eax,[eax]
  3375.         stos    dword [edi]
  3376.         mov     eax,1
  3377.         cmp     dword [esi+0Ch],0
  3378.         je      bss_section
  3379.         test    byte [esi+14h],80h
  3380.         jz      section_type_ok
  3381.       bss_section:
  3382.         mov     al,8
  3383.       section_type_ok:
  3384.         stos    dword [edi]
  3385.         mov     eax,[esi+14h]
  3386.         and     al,3Fh
  3387.         call    store_elf_machine_word
  3388.         xor     eax,eax
  3389.         call    store_elf_machine_word
  3390.         mov     eax,[esi+8]
  3391.         mov     [image_base],eax
  3392.         sub     eax,[code_start]
  3393.         call    store_elf_machine_word
  3394.         mov     eax,[esi+0Ch]
  3395.         call    store_elf_machine_word
  3396.         xor     eax,eax
  3397.         stos    dword [edi]
  3398.         stos    dword [edi]
  3399.         mov     eax,[esi+10h]
  3400.         call    store_elf_machine_word
  3401.         xor     eax,eax
  3402.         call    store_elf_machine_word
  3403.         inc     ecx
  3404.         add     esi,20h
  3405.         xchg    edi,[esp]
  3406.         mov     ebp,edi
  3407.       convert_relocations:
  3408.         cmp     esi,[free_additional_memory]
  3409.         je      relocations_converted
  3410.         mov     al,[esi]
  3411.         or      al,al
  3412.         jz      relocations_converted
  3413.         cmp     al,80h
  3414.         jb      make_relocation_entry
  3415.         cmp     al,0C0h
  3416.         jb      relocation_entry_ok
  3417.         add     esi,10h
  3418.         jmp     convert_relocations
  3419.       make_relocation_entry:
  3420.         test    [format_flags],8
  3421.         jnz     make_elf64_relocation_entry
  3422.         mov     eax,[esi+4]
  3423.         stos    dword [edi]
  3424.         mov     eax,[esi+8]
  3425.         mov     eax,[eax]
  3426.         mov     al,[esi]
  3427.         stos    dword [edi]
  3428.         jmp     relocation_entry_ok
  3429.       make_elf64_relocation_entry:
  3430.         mov     eax,[esi+4]
  3431.         stos    dword [edi]
  3432.         xor     eax,eax
  3433.         stos    dword [edi]
  3434.         movzx   eax,byte [esi]
  3435.         stos    dword [edi]
  3436.         mov     eax,[esi+8]
  3437.         mov     eax,[eax]
  3438.         shr     eax,8
  3439.         stos    dword [edi]
  3440.         xor     eax,eax
  3441.         stos    dword [edi]
  3442.         stos    dword [edi]
  3443.       relocation_entry_ok:
  3444.         add     esi,0Ch
  3445.         jmp     convert_relocations
  3446.       store_elf_machine_word:
  3447.         stos    dword [edi]
  3448.         test    [format_flags],8
  3449.         jz      elf_machine_word_ok
  3450.         mov     dword [edi],0
  3451.         add     edi,4
  3452.       elf_machine_word_ok:
  3453.         ret
  3454.       relocations_converted:
  3455.         cmp     edi,ebp
  3456.         xchg    edi,[esp]
  3457.         je      rel_section_ok
  3458.         mov     eax,[ebx]
  3459.         sub     eax,4
  3460.         test    [format_flags],8
  3461.         jz      store_relocations_name_offset
  3462.         dec     eax
  3463.       store_relocations_name_offset:
  3464.         stos    dword [edi]
  3465.         test    [format_flags],8
  3466.         jnz     rela_section
  3467.         mov     eax,9
  3468.         jmp     store_relocations_type
  3469.       rela_section:
  3470.         mov     eax,4
  3471.       store_relocations_type:
  3472.         stos    dword [edi]
  3473.         xor     al,al
  3474.         call    store_elf_machine_word
  3475.         call    store_elf_machine_word
  3476.         mov     eax,ebp
  3477.         sub     eax,[code_start]
  3478.         call    store_elf_machine_word
  3479.         mov     eax,[esp]
  3480.         sub     eax,ebp
  3481.         call    store_elf_machine_word
  3482.         mov     eax,[current_section]
  3483.         stos    dword [edi]
  3484.         mov     eax,ecx
  3485.         stos    dword [edi]
  3486.         inc     ecx
  3487.         test    [format_flags],8
  3488.         jnz     finish_elf64_rela_section
  3489.         mov     eax,4
  3490.         stos    dword [edi]
  3491.         mov     al,8
  3492.         stos    dword [edi]
  3493.         jmp     rel_section_ok
  3494.       finish_elf64_rela_section:
  3495.         mov     eax,8
  3496.         stos    dword [edi]
  3497.         xor     al,al
  3498.         stos    dword [edi]
  3499.         mov     al,24
  3500.         stos    dword [edi]
  3501.         xor     al,al
  3502.         stos    dword [edi]
  3503.       rel_section_ok:
  3504.         cmp     esi,[free_additional_memory]
  3505.         jne     make_section_entry
  3506.         pop     eax
  3507.         mov     ebx,[code_start]
  3508.         sub     eax,ebx
  3509.         mov     [code_size],eax
  3510.         mov     ecx,20h
  3511.         test    [format_flags],8
  3512.         jz      adjust_elf_section_headers_offset
  3513.         mov     ecx,28h
  3514.       adjust_elf_section_headers_offset:
  3515.         add     [ebx+ecx],eax
  3516.         mov     eax,1
  3517.         stos    dword [edi]
  3518.         mov     al,2
  3519.         stos    dword [edi]
  3520.         xor     al,al
  3521.         call    store_elf_machine_word
  3522.         call    store_elf_machine_word
  3523.         mov     eax,[code_size]
  3524.         call    store_elf_machine_word
  3525.         mov     eax,[edx+1]
  3526.         sub     eax,[free_additional_memory]
  3527.         call    store_elf_machine_word
  3528.         mov     eax,[current_section]
  3529.         inc     eax
  3530.         stos    dword [edi]
  3531.         mov     eax,[number_of_sections]
  3532.         inc     eax
  3533.         stos    dword [edi]
  3534.         test    [format_flags],8
  3535.         jnz     finish_elf64_sym_section
  3536.         mov     eax,4
  3537.         stos    dword [edi]
  3538.         mov     al,10h
  3539.         stos    dword [edi]
  3540.         jmp     sym_section_ok
  3541.       finish_elf64_sym_section:
  3542.         mov     eax,8
  3543.         stos    dword [edi]
  3544.         xor     al,al
  3545.         stos    dword [edi]
  3546.         mov     al,18h
  3547.         stos    dword [edi]
  3548.         xor     al,al
  3549.         stos    dword [edi]
  3550.       sym_section_ok:
  3551.         mov     al,1+8
  3552.         stos    dword [edi]
  3553.         mov     al,3
  3554.         stos    dword [edi]
  3555.         xor     al,al
  3556.         call    store_elf_machine_word
  3557.         call    store_elf_machine_word
  3558.         mov     eax,[edx+1]
  3559.         sub     eax,[free_additional_memory]
  3560.         add     eax,[code_size]
  3561.         call    store_elf_machine_word
  3562.         mov     eax,[edx+1+8]
  3563.         sub     eax,[edx+1]
  3564.         call    store_elf_machine_word
  3565.         xor     eax,eax
  3566.         stos    dword [edi]
  3567.         stos    dword [edi]
  3568.         mov     al,1
  3569.         call    store_elf_machine_word
  3570.         xor     eax,eax
  3571.         call    store_elf_machine_word
  3572.         mov     eax,'tab'
  3573.         mov     dword [edx+1],'.sym'
  3574.         mov     [edx+1+4],eax
  3575.         mov     dword [edx+1+8],'.str'
  3576.         mov     [edx+1+8+4],eax
  3577.         mov     [resource_data],edx
  3578.         mov     [written_size],0
  3579.         mov     edx,[output_file]
  3580.         call    create
  3581.         jc      write_failed
  3582.         call    write_code
  3583.         mov     ecx,edi
  3584.         mov     edx,[free_additional_memory]
  3585.         sub     ecx,edx
  3586.         add     [written_size],ecx
  3587.         call    write
  3588.         jc      write_failed
  3589.         jmp     output_written
  3590.  
  3591. format_elf_exe:
  3592.         add     esi,2
  3593.         or      [format_flags],1
  3594.         cmp     byte [esi],'('
  3595.         jne     elf_exe_brand_ok
  3596.         inc     esi
  3597.         cmp     byte [esi],'.'
  3598.         je      invalid_value
  3599.         push    edx
  3600.         call    get_byte_value
  3601.         cmp     [value_type],0
  3602.         jne     invalid_use_of_symbol
  3603.         pop     edx
  3604.         mov     [edx+7],al
  3605.       elf_exe_brand_ok:
  3606.         mov     [image_base],8048000h
  3607.         cmp     byte [esi],80h
  3608.         jne     elf_exe_base_ok
  3609.         lods    word [esi]
  3610.         cmp     ah,'('
  3611.         jne     invalid_argument
  3612.         cmp     byte [esi],'.'
  3613.         je      invalid_value
  3614.         push    edx
  3615.         call    get_dword_value
  3616.         cmp     [value_type],0
  3617.         jne     invalid_use_of_symbol
  3618.         mov     [image_base],eax
  3619.         pop     edx
  3620.       elf_exe_base_ok:
  3621.         mov     byte [edx+10h],2
  3622.         mov     byte [edx+2Ah],20h
  3623.         mov     ebx,edi
  3624.         mov     ecx,20h shr 2
  3625.         cmp     [current_pass],0
  3626.         je      init_elf_segments
  3627.         imul    ecx,[number_of_sections]
  3628.       init_elf_segments:
  3629.         xor     eax,eax
  3630.         rep     stos dword [edi]
  3631.         mov     [number_of_sections],0
  3632.         mov     byte [ebx],1
  3633.         mov     word [ebx+1Ch],1000h
  3634.         mov     byte [ebx+18h],111b
  3635.         mov     eax,edi
  3636.         sub     eax,[code_start]
  3637.         mov     [ebx+4],eax
  3638.         add     eax,[image_base]
  3639.         mov     [ebx+8],eax
  3640.         mov     [ebx+0Ch],eax
  3641.         mov     [edx+18h],eax
  3642.         xor     edx,edx
  3643.         not     eax
  3644.         not     edx
  3645.         add     eax,1
  3646.         adc     edx,0
  3647.         add     eax,edi
  3648.         adc     edx,0
  3649.         mov     dword [org_origin],eax
  3650.         mov     dword [org_origin+4],edx
  3651.         mov     [org_registers],0
  3652.         mov     [org_start],edi
  3653.         mov     [symbols_stream],edi
  3654.         jmp     format_defined
  3655.       format_elf64_exe:
  3656.         add     esi,2
  3657.         or      [format_flags],1
  3658.         cmp     byte [esi],'('
  3659.         jne     elf64_exe_brand_ok
  3660.         inc     esi
  3661.         cmp     byte [esi],'.'
  3662.         je      invalid_value
  3663.         push    edx
  3664.         call    get_byte_value
  3665.         cmp     [value_type],0
  3666.         jne     invalid_use_of_symbol
  3667.         pop     edx
  3668.         mov     [edx+7],al
  3669.       elf64_exe_brand_ok:
  3670.         mov     [image_base],400000h
  3671.         mov     [image_base_high],0
  3672.         cmp     byte [esi],80h
  3673.         jne     elf64_exe_base_ok
  3674.         lods    word [esi]
  3675.         cmp     ah,'('
  3676.         jne     invalid_argument
  3677.         cmp     byte [esi],'.'
  3678.         je      invalid_value
  3679.         push    edx
  3680.         call    get_qword_value
  3681.         cmp     [value_type],0
  3682.         jne     invalid_use_of_symbol
  3683.         mov     [image_base],eax
  3684.         mov     [image_base_high],edx
  3685.         pop     edx
  3686.       elf64_exe_base_ok:
  3687.         mov     byte [edx+10h],2
  3688.         mov     byte [edx+36h],38h
  3689.         mov     ebx,edi
  3690.         mov     ecx,38h shr 2
  3691.         cmp     [current_pass],0
  3692.         je      init_elf64_segments
  3693.         imul    ecx,[number_of_sections]
  3694.       init_elf64_segments:
  3695.         xor     eax,eax
  3696.         rep     stos dword [edi]
  3697.         mov     [number_of_sections],0
  3698.         mov     byte [ebx],1
  3699.         mov     word [ebx+30h],1000h
  3700.         mov     byte [ebx+4],111b
  3701.         push    edx
  3702.         mov     eax,edi
  3703.         sub     eax,[code_start]
  3704.         mov     [ebx+8],eax
  3705.         xor     edx,edx
  3706.         add     eax,[image_base]
  3707.         adc     edx,[image_base_high]
  3708.         mov     [ebx+10h],eax
  3709.         mov     [ebx+10h+4],edx
  3710.         mov     [ebx+18h],eax
  3711.         mov     [ebx+18h+4],edx
  3712.         pop     ebx
  3713.         mov     [ebx+18h],eax
  3714.         mov     [ebx+18h+4],edx
  3715.         not     eax
  3716.         not     edx
  3717.         add     eax,1
  3718.         adc     edx,0
  3719.         add     eax,edi
  3720.         adc     edx,0
  3721.         mov     dword [org_origin],eax
  3722.         mov     dword [org_origin+4],edx
  3723.         mov     [org_registers],0
  3724.         mov     [org_start],edi
  3725.         mov     [symbols_stream],edi
  3726.         jmp     format_defined
  3727. elf_entry:
  3728.         lods    byte [esi]
  3729.         cmp     al,'('
  3730.         jne     invalid_argument
  3731.         cmp     byte [esi],'.'
  3732.         je      invalid_value
  3733.         test    [format_flags],8
  3734.         jnz     elf64_entry
  3735.         call    get_dword_value
  3736.         cmp     [value_type],0
  3737.         jne     invalid_use_of_symbol
  3738.         mov     edx,[code_start]
  3739.         mov     [edx+18h],eax
  3740.         jmp     instruction_assembled
  3741.       elf64_entry:
  3742.         call    get_qword_value
  3743.         cmp     [value_type],0
  3744.         jne     invalid_use_of_symbol
  3745.         mov     ebx,[code_start]
  3746.         mov     [ebx+18h],eax
  3747.         mov     [ebx+1Ch],edx
  3748.         jmp     instruction_assembled
  3749. elf_segment:
  3750.         bt      [format_flags],0
  3751.         jnc     illegal_instruction
  3752.         test    [format_flags],8
  3753.         jnz     elf64_segment
  3754.         call    close_elf_segment
  3755.         push    eax
  3756.         mov     ebx,[number_of_sections]
  3757.         shl     ebx,5
  3758.         add     ebx,[code_start]
  3759.         add     ebx,34h
  3760.         cmp     ebx,[symbols_stream]
  3761.         jb      new_elf_segment
  3762.         mov     ebx,[symbols_stream]
  3763.         sub     ebx,20h
  3764.         push    edi
  3765.         mov     edi,ebx
  3766.         mov     ecx,20h shr 2
  3767.         xor     eax,eax
  3768.         rep     stos dword [edi]
  3769.         pop     edi
  3770.         or      [next_pass_needed],-1
  3771.       new_elf_segment:
  3772.         mov     byte [ebx],1
  3773.         mov     word [ebx+1Ch],1000h
  3774.       elf_segment_flags:
  3775.         cmp     byte [esi],1Eh
  3776.         je      elf_segment_type
  3777.         cmp     byte [esi],19h
  3778.         jne     elf_segment_flags_ok
  3779.         lods    word [esi]
  3780.         sub     ah,28
  3781.         jbe     invalid_argument
  3782.         cmp     ah,1
  3783.         je      mark_elf_segment_flag
  3784.         cmp     ah,3
  3785.         ja      invalid_argument
  3786.         xor     ah,1
  3787.         cmp     ah,2
  3788.         je      mark_elf_segment_flag
  3789.         inc     ah
  3790.       mark_elf_segment_flag:
  3791.         test    [ebx+18h],ah
  3792.         jnz     setting_already_specified
  3793.         or      [ebx+18h],ah
  3794.         jmp     elf_segment_flags
  3795.       elf_segment_type:
  3796.         cmp     byte [ebx],1
  3797.         jne     setting_already_specified
  3798.         lods    word [esi]
  3799.         mov     ecx,[number_of_sections]
  3800.         jecxz   elf_segment_type_ok
  3801.         mov     edx,[code_start]
  3802.         add     edx,34h
  3803.       scan_elf_segment_types:
  3804.         cmp     edx,[symbols_stream]
  3805.         jae     elf_segment_type_ok
  3806.         cmp     [edx],ah
  3807.         je      data_already_defined
  3808.         add     edx,20h
  3809.         loop    scan_elf_segment_types
  3810.       elf_segment_type_ok:
  3811.         mov     [ebx],ah
  3812.         mov     word [ebx+1Ch],1
  3813.         jmp     elf_segment_flags
  3814.       elf_segment_flags_ok:
  3815.         mov     eax,edi
  3816.         sub     eax,[code_start]
  3817.         mov     [ebx+4],eax
  3818.         pop     edx
  3819.         and     eax,0FFFh
  3820.         add     edx,eax
  3821.         mov     [ebx+8],edx
  3822.         mov     [ebx+0Ch],edx
  3823.         mov     eax,edx
  3824.         xor     edx,edx
  3825.         not     eax
  3826.         not     edx
  3827.         add     eax,1
  3828.         adc     edx,0
  3829.         add     eax,edi
  3830.         adc     edx,0
  3831.         mov     dword [org_origin],eax
  3832.         mov     dword [org_origin+4],edx
  3833.         mov     [org_registers],0
  3834.         mov     [org_start],edi
  3835.         inc     [number_of_sections]
  3836.         jmp     instruction_assembled
  3837.       close_elf_segment:
  3838.         cmp     [number_of_sections],0
  3839.         jne     finish_elf_segment
  3840.         cmp     edi,[symbols_stream]
  3841.         jne     first_elf_segment_ok
  3842.         push    edi
  3843.         mov     edi,[code_start]
  3844.         add     edi,34h
  3845.         mov     ecx,20h shr 2
  3846.         xor     eax,eax
  3847.         rep     stos dword [edi]
  3848.         pop     edi
  3849.         mov     eax,[image_base]
  3850.         ret
  3851.       first_elf_segment_ok:
  3852.         inc     [number_of_sections]
  3853.       finish_elf_segment:
  3854.         mov     ebx,[number_of_sections]
  3855.         dec     ebx
  3856.         shl     ebx,5
  3857.         add     ebx,[code_start]
  3858.         add     ebx,34h
  3859.         mov     eax,edi
  3860.         sub     eax,[code_start]
  3861.         sub     eax,[ebx+4]
  3862.         mov     edx,edi
  3863.         cmp     edi,[undefined_data_end]
  3864.         jne     elf_segment_size_ok
  3865.         mov     edi,[undefined_data_start]
  3866.       elf_segment_size_ok:
  3867.         mov     [ebx+14h],eax
  3868.         add     eax,edi
  3869.         sub     eax,edx
  3870.         mov     [ebx+10h],eax
  3871.         mov     eax,[ebx+8]
  3872.         cmp     byte [ebx],1
  3873.         jne     elf_segment_position_ok
  3874.         add     eax,[ebx+14h]
  3875.         add     eax,0FFFh
  3876.       elf_segment_position_ok:
  3877.         and     eax,not 0FFFh
  3878.         ret
  3879.       elf64_segment:
  3880.         call    close_elf64_segment
  3881.         push    eax edx
  3882.         mov     ebx,[number_of_sections]
  3883.         imul    ebx,38h
  3884.         add     ebx,[code_start]
  3885.         add     ebx,40h
  3886.         cmp     ebx,[symbols_stream]
  3887.         jb      new_elf64_segment
  3888.         mov     ebx,[symbols_stream]
  3889.         sub     ebx,38h
  3890.         push    edi
  3891.         mov     edi,ebx
  3892.         mov     ecx,38h shr 2
  3893.         xor     eax,eax
  3894.         rep     stos dword [edi]
  3895.         pop     edi
  3896.         or      [next_pass_needed],-1
  3897.       new_elf64_segment:
  3898.         mov     byte [ebx],1
  3899.         mov     word [ebx+30h],1000h
  3900.       elf64_segment_flags:
  3901.         cmp     byte [esi],1Eh
  3902.         je      elf64_segment_type
  3903.         cmp     byte [esi],19h
  3904.         jne     elf64_segment_flags_ok
  3905.         lods    word [esi]
  3906.         sub     ah,28
  3907.         jbe     invalid_argument
  3908.         cmp     ah,1
  3909.         je      mark_elf64_segment_flag
  3910.         cmp     ah,3
  3911.         ja      invalid_argument
  3912.         xor     ah,1
  3913.         cmp     ah,2
  3914.         je      mark_elf64_segment_flag
  3915.         inc     ah
  3916.       mark_elf64_segment_flag:
  3917.         test    [ebx+4],ah
  3918.         jnz     setting_already_specified
  3919.         or      [ebx+4],ah
  3920.         jmp     elf64_segment_flags
  3921.       elf64_segment_type:
  3922.         cmp     byte [ebx],1
  3923.         jne     setting_already_specified
  3924.         lods    word [esi]
  3925.         mov     ecx,[number_of_sections]
  3926.         jecxz   elf64_segment_type_ok
  3927.         mov     edx,[code_start]
  3928.         add     edx,40h
  3929.       scan_elf64_segment_types:
  3930.         cmp     edx,[symbols_stream]
  3931.         jae     elf64_segment_type_ok
  3932.         cmp     [edx],ah
  3933.         je      data_already_defined
  3934.         add     edx,38h
  3935.         loop    scan_elf64_segment_types
  3936.       elf64_segment_type_ok:
  3937.         mov     [ebx],ah
  3938.         mov     word [ebx+30h],1
  3939.         jmp     elf64_segment_flags
  3940.       elf64_segment_flags_ok:
  3941.         mov     ecx,edi
  3942.         sub     ecx,[code_start]
  3943.         mov     [ebx+8],ecx
  3944.         pop     edx eax
  3945.         and     ecx,0FFFh
  3946.         add     eax,ecx
  3947.         adc     edx,0
  3948.         mov     [ebx+10h],eax
  3949.         mov     [ebx+10h+4],edx
  3950.         mov     [ebx+18h],eax
  3951.         mov     [ebx+18h+4],edx
  3952.         not     eax
  3953.         not     edx
  3954.         add     eax,1
  3955.         adc     edx,0
  3956.         add     eax,edi
  3957.         adc     edx,0
  3958.         mov     dword [org_origin],eax
  3959.         mov     dword [org_origin+4],edx
  3960.         mov     [org_registers],0
  3961.         mov     [org_start],edi
  3962.         inc     [number_of_sections]
  3963.         jmp     instruction_assembled
  3964.       close_elf64_segment:
  3965.         cmp     [number_of_sections],0
  3966.         jne     finish_elf64_segment
  3967.         cmp     edi,[symbols_stream]
  3968.         jne     first_elf64_segment_ok
  3969.         push    edi
  3970.         mov     edi,[code_start]
  3971.         add     edi,40h
  3972.         mov     ecx,38h shr 2
  3973.         xor     eax,eax
  3974.         rep     stos dword [edi]
  3975.         pop     edi
  3976.         mov     eax,[image_base]
  3977.         mov     edx,[image_base_high]
  3978.         ret
  3979.       first_elf64_segment_ok:
  3980.         inc     [number_of_sections]
  3981.       finish_elf64_segment:
  3982.         mov     ebx,[number_of_sections]
  3983.         dec     ebx
  3984.         imul    ebx,38h
  3985.         add     ebx,[code_start]
  3986.         add     ebx,40h
  3987.         mov     eax,edi
  3988.         sub     eax,[code_start]
  3989.         sub     eax,[ebx+8]
  3990.         mov     edx,edi
  3991.         cmp     edi,[undefined_data_end]
  3992.         jne     elf64_segment_size_ok
  3993.         mov     edi,[undefined_data_start]
  3994.       elf64_segment_size_ok:
  3995.         mov     [ebx+28h],eax
  3996.         add     eax,edi
  3997.         sub     eax,edx
  3998.         mov     [ebx+20h],eax
  3999.         mov     eax,[ebx+10h]
  4000.         mov     edx,[ebx+10h+4]
  4001.         cmp     byte [ebx],1
  4002.         jne     elf64_segment_position_ok
  4003.         add     eax,[ebx+28h]
  4004.         adc     edx,0
  4005.         add     eax,0FFFh
  4006.         adc     edx,0
  4007.       elf64_segment_position_ok:
  4008.         and     eax,not 0FFFh
  4009.         ret
  4010.  
  4011. close_elf_exe:
  4012.         test    [format_flags],8
  4013.         jnz     close_elf64_exe
  4014.         call    close_elf_segment
  4015.         mov     edx,[code_start]
  4016.         mov     eax,[number_of_sections]
  4017.         mov     byte [edx+1Ch],34h
  4018.         mov     [edx+2Ch],ax
  4019.         shl     eax,5
  4020.         add     eax,edx
  4021.         add     eax,34h
  4022.         cmp     eax,[symbols_stream]
  4023.         je      elf_exe_ok
  4024.         or      [next_pass_needed],-1
  4025.       elf_exe_ok:
  4026.         ret
  4027.       close_elf64_exe:
  4028.         call    close_elf64_segment
  4029.         mov     edx,[code_start]
  4030.         mov     eax,[number_of_sections]
  4031.         mov     byte [edx+20h],40h
  4032.         mov     [edx+38h],ax
  4033.         imul    eax,38h
  4034.         add     eax,edx
  4035.         add     eax,40h
  4036.         cmp     eax,[symbols_stream]
  4037.         je      elf64_exe_ok
  4038.         or      [next_pass_needed],-1
  4039.       elf64_exe_ok:
  4040.         ret
  4041.  
  4042. dump_symbols:
  4043.         mov     ebx,[code_start]
  4044.         mov     dword [ebx],'fas'+1Ah shl 24
  4045.         mov     dword [ebx+4],VERSION_MAJOR + VERSION_MINOR shl 8 + 38h shl 16
  4046.         add     ebx,38h
  4047.         mov     edi,ebx
  4048.         mov     dword [ebx-38h+10h],38h
  4049.         mov     dword [ebx-38h+8],0
  4050.         mov     esi,[input_file]
  4051.         call    copy_asciiz
  4052.         cmp     edi,[display_buffer]
  4053.         jae     out_of_memory
  4054.         mov     eax,edi
  4055.         sub     eax,ebx
  4056.         mov     [ebx-38h+0Ch],eax
  4057.         mov     esi,[output_file]
  4058.         call    copy_asciiz
  4059.         cmp     edi,[display_buffer]
  4060.         jae     out_of_memory
  4061.         mov     edx,[symbols_stream]
  4062.         mov     ebp,[free_additional_memory]
  4063.         mov     [number_of_sections],0
  4064.         cmp     [output_format],4
  4065.         je      prepare_strings_table
  4066.         cmp     [output_format],5
  4067.         jne     strings_table_ready
  4068.         bt      [format_flags],0
  4069.         jc      strings_table_ready
  4070.       prepare_strings_table:
  4071.         cmp     edx,ebp
  4072.         je      strings_table_ready
  4073.         mov     al,[edx]
  4074.         test    al,al
  4075.         jz      prepare_string
  4076.         cmp     al,80h
  4077.         je      prepare_string
  4078.         add     edx,0Ch
  4079.         cmp     al,0C0h
  4080.         jne     prepare_strings_table
  4081.         add     edx,4
  4082.         jmp     prepare_strings_table
  4083.       prepare_string:
  4084.         mov     esi,edi
  4085.         sub     esi,ebx
  4086.         xchg    esi,[edx+4]
  4087.         test    al,al
  4088.         jz      prepare_section_string
  4089.         or      dword [edx+4],1 shl 31
  4090.         add     edx,0Ch
  4091.       prepare_external_string:
  4092.         mov     ecx,[esi]
  4093.         add     esi,4
  4094.         rep     movs byte [edi],[esi]
  4095.         mov     byte [edi],0
  4096.         inc     edi
  4097.         cmp     edi,[display_buffer]
  4098.         jae     out_of_memory
  4099.         jmp     prepare_strings_table
  4100.       prepare_section_string:
  4101.         mov     ecx,[number_of_sections]
  4102.         mov     eax,ecx
  4103.         inc     eax
  4104.         mov     [number_of_sections],eax
  4105.         xchg    eax,[edx+4]
  4106.         shl     ecx,2
  4107.         add     ecx,[free_additional_memory]
  4108.         mov     [ecx],eax
  4109.         add     edx,20h
  4110.         test    esi,esi
  4111.         jz      prepare_default_section_string
  4112.         cmp     [output_format],5
  4113.         jne     prepare_external_string
  4114.         bt      [format_flags],0
  4115.         jc      prepare_external_string
  4116.         mov     esi,[esi]
  4117.         add     esi,[resource_data]
  4118.       copy_elf_section_name:
  4119.         lods    byte [esi]
  4120.         cmp     edi,[display_buffer]
  4121.         jae     out_of_memory
  4122.         stos    byte [edi]
  4123.         test    al,al
  4124.         jnz     copy_elf_section_name
  4125.         jmp     prepare_strings_table
  4126.       prepare_default_section_string:
  4127.         mov     eax,'.fla'
  4128.         stos    dword [edi]
  4129.         mov     ax,'t'
  4130.         stos    word [edi]
  4131.         cmp     edi,[display_buffer]
  4132.         jae     out_of_memory
  4133.         jmp     prepare_strings_table
  4134.       strings_table_ready:
  4135.         mov     edx,[display_buffer]
  4136.         mov     ebp,[memory_end]
  4137.         sub     ebp,[labels_list]
  4138.         add     ebp,edx
  4139.       prepare_labels_dump:
  4140.         cmp     edx,ebp
  4141.         je      labels_dump_ok
  4142.         mov     eax,[edx+24]
  4143.         test    eax,eax
  4144.         jz      label_dump_name_ok
  4145.         cmp     eax,[memory_start]
  4146.         jb      label_name_outside_source
  4147.         cmp     eax,[source_start]
  4148.         ja      label_name_outside_source
  4149.         sub     eax,[memory_start]
  4150.         dec     eax
  4151.         mov     [edx+24],eax
  4152.         jmp     label_dump_name_ok
  4153.       label_name_outside_source:
  4154.         mov     esi,eax
  4155.         mov     eax,edi
  4156.         sub     eax,ebx
  4157.         or      eax,1 shl 31
  4158.         mov     [edx+24],eax
  4159.         movzx   ecx,byte [esi-1]
  4160.         lea     eax,[edi+ecx+1]
  4161.         cmp     edi,[display_buffer]
  4162.         jae     out_of_memory
  4163.         rep     movsb
  4164.         xor     al,al
  4165.         stosb
  4166.       label_dump_name_ok:
  4167.         mov     eax,[edx+28]
  4168.         test    eax,eax
  4169.         jz      label_dump_line_ok
  4170.         sub     eax,[memory_start]
  4171.         mov     [edx+28],eax
  4172.       label_dump_line_ok:
  4173.         mov     eax,[edx+20]
  4174.         test    eax,eax
  4175.         jz      base_symbol_for_label_ok
  4176.         cmp     eax,[symbols_stream]
  4177.         mov     eax,[eax+4]
  4178.         jae     base_symbol_for_label_ok
  4179.         xor     eax,eax
  4180.       base_symbol_for_label_ok:
  4181.         mov     [edx+20],eax
  4182.         add     edx,LABEL_STRUCTURE_SIZE
  4183.         jmp     prepare_labels_dump
  4184.       labels_dump_ok:
  4185.         mov     eax,edi
  4186.         sub     eax,ebx
  4187.         mov     [ebx-38h+14h],eax
  4188.         add     eax,38h
  4189.         mov     [ebx-38h+18h],eax
  4190.         mov     ecx,[memory_end]
  4191.         sub     ecx,[labels_list]
  4192.         mov     [ebx-38h+1Ch],ecx
  4193.         add     eax,ecx
  4194.         mov     [ebx-38h+20h],eax
  4195.         mov     ecx,[source_start]
  4196.         sub     ecx,[memory_start]
  4197.         mov     [ebx-38h+24h],ecx
  4198.         add     eax,ecx
  4199.         mov     [ebx-38h+28h],eax
  4200.         mov     eax,[number_of_sections]
  4201.         shl     eax,2
  4202.         mov     [ebx-38h+34h],eax
  4203.         mov     esi,[memory_start]
  4204.       prepare_preprocessed_source:
  4205.         cmp     esi,[source_start]
  4206.         jae     preprocessed_source_ok
  4207.         mov     eax,[memory_start]
  4208.         mov     edx,[input_file]
  4209.         cmp     [esi],edx
  4210.         jne     line_not_from_main_input
  4211.         mov     [esi],eax
  4212.       line_not_from_main_input:
  4213.         sub     [esi],eax
  4214.         test    byte [esi+7],1 shl 7
  4215.         jz      prepare_next_preprocessed_line
  4216.         sub     [esi+8],eax
  4217.         sub     [esi+12],eax
  4218.       prepare_next_preprocessed_line:
  4219.         add     esi,16
  4220.       skip_preprocessed_line:
  4221.         lods    byte [esi]
  4222.         cmp     al,1Ah
  4223.         je      skip_preprocessed_symbol
  4224.         cmp     al,3Bh
  4225.         je      skip_preprocessed_symbol
  4226.         cmp     al,22h
  4227.         je      skip_preprocessed_string
  4228.         or      al,al
  4229.         jnz     skip_preprocessed_line
  4230.         jmp     prepare_preprocessed_source
  4231.       skip_preprocessed_string:
  4232.         lods    dword [esi]
  4233.         add     esi,eax
  4234.         jmp     skip_preprocessed_line
  4235.       skip_preprocessed_symbol:
  4236.         lods    byte [esi]
  4237.         movzx   eax,al
  4238.         add     esi,eax
  4239.         jmp     skip_preprocessed_line
  4240.       preprocessed_source_ok:
  4241.         mov     esi,[labels_list]
  4242.         mov     ebp,edi
  4243.       make_lines_dump:
  4244.         cmp     esi,[display_buffer]
  4245.         je      lines_dump_ok
  4246.         mov     eax,[esi-4]
  4247.         mov     ecx,[esi-8]
  4248.         sub     esi,8
  4249.         sub     esi,ecx
  4250.         cmp     eax,1
  4251.         jne     make_lines_dump
  4252.         mov     eax,[esi+4]
  4253.         sub     eax,[code_start]
  4254.         add     eax,[headers_size]
  4255.         cmp     byte [esi+1Ah],0
  4256.         je      store_offset
  4257.         xor     eax,eax
  4258.       store_offset:
  4259.         stos    dword [edi]
  4260.         mov     eax,[esi]
  4261.         sub     eax,[memory_start]
  4262.         stos    dword [edi]
  4263.         mov     eax,[esi+4]
  4264.         xor     edx,edx
  4265.         sub     eax,[esi+8]
  4266.         sbb     edx,[esi+8+4]
  4267.         stos    dword [edi]
  4268.         mov     eax,edx
  4269.         stos    dword [edi]
  4270.         mov     eax,[esi+10h]
  4271.         stos    dword [edi]
  4272.         mov     eax,[esi+14h]
  4273.         test    eax,eax
  4274.         jz      base_symbol_for_line_ok
  4275.         cmp     eax,[symbols_stream]
  4276.         mov     eax,[eax+4]
  4277.         jae     base_symbol_for_line_ok
  4278.         xor     eax,eax
  4279.       base_symbol_for_line_ok:
  4280.         stos    dword [edi]
  4281.         mov     eax,[esi+18h]
  4282.         and     eax,001FFFFh
  4283.         stos    dword [edi]
  4284.         jmp     make_lines_dump
  4285.       lines_dump_ok:
  4286.         mov     edx,edi
  4287.         mov     eax,[current_offset]
  4288.         sub     eax,[code_start]
  4289.         add     eax,[headers_size]
  4290.         stos    dword [edi]
  4291.         mov     ecx,edi
  4292.         sub     ecx,ebx
  4293.         sub     ecx,[ebx-38h+14h]
  4294.         mov     [ebx-38h+2Ch],ecx
  4295.         add     ecx,[ebx-38h+28h]
  4296.         mov     [ebx-38h+30h],ecx
  4297.       find_inexisting_offsets:
  4298.         sub     edx,1Ch
  4299.         cmp     edx,ebp
  4300.         jb      write_symbols
  4301.         test    byte [edx+1Ah],1
  4302.         jnz     find_inexisting_offsets
  4303.         cmp     eax,[edx]
  4304.         jb      correct_inexisting_offset
  4305.         mov     eax,[edx]
  4306.         jmp     find_inexisting_offsets
  4307.       correct_inexisting_offset:
  4308.         mov     dword [edx],0
  4309.         or      byte [edx+1Ah],2
  4310.         jmp     find_inexisting_offsets
  4311.       write_symbols:
  4312.         mov     edx,[symbols_file]
  4313.         call    create
  4314.         jc      write_failed
  4315.         mov     edx,[code_start]
  4316.         mov     ecx,[edx+14h]
  4317.         add     ecx,38h
  4318.         call    write
  4319.         mov     edx,[display_buffer]
  4320.         mov     ecx,[memory_end]
  4321.         sub     ecx,[labels_list]
  4322.         call    write
  4323.         mov     edx,[memory_start]
  4324.         mov     ecx,[source_start]
  4325.         sub     ecx,edx
  4326.         call    write
  4327.         mov     edx,ebp
  4328.         mov     ecx,edi
  4329.         sub     ecx,edx
  4330.         call    write
  4331.         mov     edx,[free_additional_memory]
  4332.         mov     ecx,[number_of_sections]
  4333.         shl     ecx,2
  4334.         call    write
  4335.         call    close
  4336.         ret
  4337.