Subversion Repositories Kolibri OS

Rev

Rev 1053 | Go to most recent revision | 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,[esp]
  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     al,al
  485.         rep     stos byte [edi]
  486.         mov     dword [org_origin],edi
  487.         mov     dword [org_origin+4],0
  488.         mov     [org_registers],0
  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     word [edx+4],1
  672.         mov     word [edx+2],ax
  673.         mov     word [edx+8],4
  674.         mov     word [edx+0Ah],10h
  675.         mov     word [edx+0Ch],0FFFFh
  676.         mov     word [edx+10h],cx
  677.         mov     word [edx+3Ch],ax
  678.         mov     word [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     word [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     word [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     dword [edx+38h],1000h   ; section alignment
  981.         mov     dword [edx+3Ch],200h    ; file alignment
  982.         mov     word [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     dword [edx+14h],0E0h    ; size of optional header
  997.         mov     dword [edx+16h],10B010Eh; flags and magic value
  998.         mov     eax,[image_base]
  999.         mov     dword [edx+34h],eax
  1000.         mov     dword [edx+60h],1000h   ; stack reserve
  1001.         mov     dword [edx+64h],1000h   ; stack commit
  1002.         mov     dword [edx+68h],10000h  ; heap reserve
  1003.         mov     dword [edx+6Ch],0       ; heap commit
  1004.         mov     dword [edx+74h],16      ; number of directories
  1005.         jmp     pe_header_ok
  1006.       init_peplus_specific:
  1007.         mov     dword [edx+14h],0F0h    ; size of optional header
  1008.         mov     dword [edx+16h],20B002Eh; flags and magic value
  1009.         mov     eax,[image_base]
  1010.         mov     dword [edx+30h],eax
  1011.         mov     eax,[image_base_high]
  1012.         mov     dword [edx+34h],eax
  1013.         mov     dword [edx+60h],1000h   ; stack reserve
  1014.         mov     dword [edx+68h],1000h   ; stack commit
  1015.         mov     dword [edx+70h],10000h  ; heap reserve
  1016.         mov     dword [edx+78h],0       ; heap commit
  1017.         mov     dword [edx+84h],16      ; number of directories
  1018.       pe_header_ok:
  1019.         bsf     ecx,[edx+3Ch]
  1020.         imul    ebx,[number_of_sections],28h
  1021.         or      ebx,ebx
  1022.         jnz     reserve_space_for_section_headers
  1023.         mov     ebx,28h
  1024.       reserve_space_for_section_headers:
  1025.         add     ebx,ebp
  1026.         dec     ebx
  1027.         shr     ebx,cl
  1028.         inc     ebx
  1029.         shl     ebx,cl
  1030.         sub     ebx,ebp
  1031.         mov     ecx,ebx
  1032.         mov     eax,[display_buffer]
  1033.         sub     eax,ecx
  1034.         cmp     edi,eax
  1035.         jae     out_of_memory
  1036.         shr     ecx,2
  1037.         xor     eax,eax
  1038.         rep     stos dword [edi]
  1039.         mov     eax,edi
  1040.         sub     eax,[code_start]
  1041.         add     eax,[stub_size]
  1042.         mov     [edx+54h],eax           ; size of headers
  1043.         mov     ecx,[edx+38h]
  1044.         dec     ecx
  1045.         add     eax,ecx
  1046.         not     ecx
  1047.         and     eax,ecx
  1048.         bt      [format_flags],8
  1049.         jc      pe_entry_init_ok
  1050.         mov     [edx+28h],eax           ; entry point rva
  1051.       pe_entry_init_ok:
  1052.         mov     [number_of_sections],0
  1053.         movzx   ebx,word [edx+14h]
  1054.         lea     ebx,[edx+18h+ebx]
  1055.         mov     [current_section],ebx
  1056.         mov     dword [ebx],'.fla'
  1057.         mov     dword [ebx+4],'t'
  1058.         mov     [ebx+14h],edi
  1059.         mov     [ebx+0Ch],eax
  1060.         mov     dword [ebx+24h],0E0000060h
  1061.         xor     ecx,ecx
  1062.         not     eax
  1063.         not     ecx
  1064.         add     eax,1
  1065.         adc     ecx,0
  1066.         add     eax,edi
  1067.         adc     ecx,0
  1068.         test    [format_flags],8
  1069.         jnz     peplus_org
  1070.         sub     eax,[edx+34h]
  1071.         sbb     ecx,0
  1072.         mov     bl,2
  1073.         mov     [code_type],32
  1074.         jmp     pe_org_ok
  1075.       peplus_org:
  1076.         sub     eax,[edx+30h]
  1077.         sbb     ecx,[edx+34h]
  1078.         mov     bl,4
  1079.         mov     [code_type],64
  1080.       pe_org_ok:
  1081.         bt      [resolver_flags],0
  1082.         jc      pe_labels_type_ok
  1083.         xor     bl,bl
  1084.       pe_labels_type_ok:
  1085.         mov     [labels_type],bl
  1086.         mov     dword [org_origin],eax
  1087.         mov     dword [org_origin+4],ecx
  1088.         mov     [org_registers],0
  1089.         mov     [org_start],edi
  1090.         bt      [format_flags],8
  1091.         jnc     dll_flag_ok
  1092.         or      dword [edx+16h],2000h
  1093.       dll_flag_ok:
  1094.         bt      [format_flags],9
  1095.         jnc     wdm_flag_ok
  1096.         or      word [edx+5Eh],2000h
  1097.       wdm_flag_ok:
  1098.         jmp     format_defined
  1099. pe_section:
  1100.         call    close_pe_section
  1101.         bts     [format_flags],5
  1102.         lea     ecx,[ebx+28h]
  1103.         add     edx,[edx+54h]
  1104.         sub     edx,[stub_size]
  1105.         cmp     ecx,edx
  1106.         jbe     new_section
  1107.         lea     ebx,[edx-28h]
  1108.         or      [next_pass_needed],-1
  1109.         push    edi
  1110.         mov     edi,ebx
  1111.         mov     ecx,28h shr 4
  1112.         xor     eax,eax
  1113.         rep     stos dword [edi]
  1114.         pop     edi
  1115.       new_section:
  1116.         mov     [ebx+0Ch],eax
  1117.         lods    word [esi]
  1118.         cmp     ax,'('
  1119.         jne     invalid_argument
  1120.         lea     edx,[esi+4]
  1121.         mov     ecx,[esi]
  1122.         lea     esi,[esi+4+ecx+1]
  1123.         cmp     ecx,8
  1124.         ja      name_too_long
  1125.         xor     eax,eax
  1126.         mov     [ebx],eax
  1127.         mov     [ebx+4],eax
  1128.         push    esi edi
  1129.         mov     edi,ebx
  1130.         mov     esi,edx
  1131.         rep     movs byte [edi],[esi]
  1132.         pop     edi esi
  1133.         mov     dword [ebx+24h],0
  1134.         mov     [ebx+14h],edi
  1135.         mov     edx,[code_start]
  1136.         mov     eax,edi
  1137.         xor     ecx,ecx
  1138.         sub     eax,[ebx+0Ch]
  1139.         sbb     ecx,0
  1140.         test    [format_flags],8
  1141.         jnz     peplus_section_org
  1142.         sub     eax,[edx+34h]
  1143.         sbb     ecx,0
  1144.         mov     [labels_type],2
  1145.         mov     [code_type],32
  1146.         bt      [resolver_flags],0
  1147.         jc      pe_section_org_ok
  1148.         mov     [labels_type],0
  1149.         jmp     pe_section_org_ok
  1150.       peplus_section_org:
  1151.         sub     eax,[edx+30h]
  1152.         sbb     ecx,[edx+34h]
  1153.         mov     [labels_type],4
  1154.         mov     [code_type],64
  1155.         bt      [resolver_flags],0
  1156.         jc      pe_section_org_ok
  1157.         mov     [labels_type],0
  1158.       pe_section_org_ok:
  1159.         mov     dword [org_origin],eax
  1160.         mov     dword [org_origin+4],ecx
  1161.         mov     [org_registers],0
  1162.         mov     [org_start],edi
  1163.       get_section_flags:
  1164.         lods    byte [esi]
  1165.         cmp     al,1Ah
  1166.         je      set_directory
  1167.         cmp     al,19h
  1168.         je      section_flag
  1169.         dec     esi
  1170.         jmp     instruction_assembled
  1171.       set_directory:
  1172.         movzx   eax,byte [esi]
  1173.         inc     esi
  1174.         mov     ecx,ebx
  1175.         test    [format_flags],8
  1176.         jnz     peplus_directory
  1177.         xchg    ecx,[edx+78h+eax*8]
  1178.         mov     dword [edx+78h+eax*8+4],-1
  1179.         jmp     pe_directory_set
  1180.       peplus_directory:
  1181.         xchg    ecx,[edx+88h+eax*8]
  1182.         mov     dword [edx+88h+eax*8+4],-1
  1183.       pe_directory_set:
  1184.         or      ecx,ecx
  1185.         jnz     data_already_defined
  1186.         push    ebx edx
  1187.         call    generate_pe_data
  1188.         pop     edx ebx
  1189.         jmp     get_section_flags
  1190.       section_flag:
  1191.         lods    byte [esi]
  1192.         cmp     al,9
  1193.         je      invalid_argument
  1194.         cmp     al,11
  1195.         je      invalid_argument
  1196.         mov     cl,al
  1197.         mov     eax,1
  1198.         shl     eax,cl
  1199.         test    dword [ebx+24h],eax
  1200.         jnz     setting_already_specified
  1201.         or      dword [ebx+24h],eax
  1202.         jmp     get_section_flags
  1203.       close_pe_section:
  1204.         mov     ebx,[current_section]
  1205.         mov     edx,[code_start]
  1206.         mov     eax,edi
  1207.         sub     eax,[ebx+14h]
  1208.         jnz     finish_section
  1209.         bt      [format_flags],5
  1210.         jc      finish_section
  1211.         mov     eax,[ebx+0Ch]
  1212.         ret
  1213.       finish_section:
  1214.         mov     [ebx+8],eax
  1215.         cmp     edi,[undefined_data_end]
  1216.         jne     align_section
  1217.         cmp     dword [edx+38h],1000h
  1218.         jb      align_section
  1219.         mov     edi,[undefined_data_start]
  1220.       align_section:
  1221.         mov     [undefined_data_end],0
  1222.         mov     ebp,edi
  1223.         sub     ebp,[ebx+14h]
  1224.         mov     ecx,[edx+3Ch]
  1225.         dec     ecx
  1226.         lea     eax,[ebp+ecx]
  1227.         not     ecx
  1228.         and     eax,ecx
  1229.         mov     [ebx+10h],eax
  1230.         sub     eax,ebp
  1231.         mov     ecx,eax
  1232.         xor     al,al
  1233.         rep     stos byte [edi]
  1234.         mov     eax,[code_start]
  1235.         sub     eax,[stub_size]
  1236.         sub     [ebx+14h],eax
  1237.  
  1238.         mov     ecx,[ebx+10h]
  1239.         test    byte [ebx+24h],20h
  1240.         jz      pe_code_sum_ok
  1241.         add     [edx+1Ch],ecx
  1242.         cmp     dword [edx+2Ch],0
  1243.         jne     pe_code_sum_ok
  1244.         mov     eax,[ebx+0Ch]
  1245.         mov     [edx+2Ch],eax
  1246.       pe_code_sum_ok:
  1247.         test    byte [ebx+24h],40h
  1248.         jz      pe_data_sum_ok
  1249.         add     [edx+20h],ecx
  1250.         test    [format_flags],8
  1251.         jnz     pe_data_sum_ok
  1252.         cmp     dword [edx+30h],0
  1253.         jne     pe_data_sum_ok
  1254.         mov     eax,[ebx+0Ch]
  1255.         mov     [edx+30h],eax
  1256.       pe_data_sum_ok:
  1257.  
  1258.         mov     eax,[ebx+8]
  1259.         or      eax,eax
  1260.         jz      udata_ok
  1261.         cmp     dword [ebx+10h],0
  1262.         jne     udata_ok
  1263.         or      byte [ebx+24h],80h
  1264.         add     [edx+24h],ecx
  1265.       udata_ok:
  1266.  
  1267.         mov     ecx,[edx+38h]
  1268.         dec     ecx
  1269.         add     eax,ecx
  1270.         not     ecx
  1271.         and     eax,ecx
  1272.         add     eax,[ebx+0Ch]
  1273.         add     ebx,28h
  1274.         mov     [current_section],ebx
  1275.         inc     word [number_of_sections]
  1276.         jz      format_limitations_exceeded
  1277.         ret
  1278. data_directive:
  1279.         cmp     [output_format],3
  1280.         jne     illegal_instruction
  1281.         lods    byte [esi]
  1282.         cmp     al,1Ah
  1283.         je      predefined_data_type
  1284.         cmp     al,'('
  1285.         jne     invalid_argument
  1286.         call    get_byte_value
  1287.         cmp     al,16
  1288.         jb      data_type_ok
  1289.         jmp     invalid_value
  1290.       predefined_data_type:
  1291.         movzx   eax,byte [esi]
  1292.         inc     esi
  1293.       data_type_ok:
  1294.         mov     ebx,[current_section]
  1295.         mov     ecx,edi
  1296.         sub     ecx,[ebx+14h]
  1297.         add     ecx,[ebx+0Ch]
  1298.         mov     edx,[code_start]
  1299.         test    [format_flags],8
  1300.         jnz     peplus_data
  1301.         xchg    ecx,[edx+78h+eax*8]
  1302.         jmp     init_pe_data
  1303.       peplus_data:
  1304.         xchg    ecx,[edx+88h+eax*8]
  1305.       init_pe_data:
  1306.         or      ecx,ecx
  1307.         jnz     data_already_defined
  1308.         call    allocate_structure_data
  1309.         mov     word [ebx],data_directive-assembler
  1310.         mov     [ebx+2],al
  1311.         mov     edx,[current_line]
  1312.         mov     [ebx+4],edx
  1313.         call    generate_pe_data
  1314.         jmp     instruction_assembled
  1315.       end_data:
  1316.         cmp     [output_format],3
  1317.         jne     illegal_instruction
  1318.         call    find_structure_data
  1319.         jc      unexpected_instruction
  1320.         movzx   eax,byte [ebx+2]
  1321.         mov     edx,[current_section]
  1322.         mov     ecx,edi
  1323.         sub     ecx,[edx+14h]
  1324.         add     ecx,[edx+0Ch]
  1325.         mov     edx,[code_start]
  1326.         test    [format_flags],8
  1327.         jnz     end_peplus_data
  1328.         sub     ecx,[edx+78h+eax*8]
  1329.         mov     [edx+78h+eax*8+4],ecx
  1330.         jmp     remove_structure_data
  1331.       end_peplus_data:
  1332.         sub     ecx,[edx+88h+eax*8]
  1333.         mov     [edx+88h+eax*8+4],ecx
  1334.         jmp     remove_structure_data
  1335. pe_entry:
  1336.         lods    byte [esi]
  1337.         cmp     al,'('
  1338.         jne     invalid_argument
  1339.         cmp     byte [esi],'.'
  1340.         je      invalid_value
  1341.         test    [format_flags],8
  1342.         jnz     peplus_entry
  1343.         call    get_dword_value
  1344.         mov     bl,2
  1345.         bt      [resolver_flags],0
  1346.         jc      check_pe_entry_label_type
  1347.         xor     bl,bl
  1348.       check_pe_entry_label_type:
  1349.         cmp     [value_type],bl
  1350.         je      pe_entry_ok
  1351.         cmp     [error_line],0
  1352.         jne     pe_entry_ok
  1353.         mov     edx,[current_line]
  1354.         mov     [error_line],edx
  1355.         mov     [error],invalid_address
  1356.       pe_entry_ok:
  1357.         mov     edx,[code_start]
  1358.         sub     eax,[edx+34h]
  1359.         mov     [edx+28h],eax
  1360.         jmp     instruction_assembled
  1361.       peplus_entry:
  1362.         call    get_qword_value
  1363.         mov     bl,4
  1364.         bt      [resolver_flags],0
  1365.         jc      check_peplus_entry_label_type
  1366.         xor     bl,bl
  1367.       check_peplus_entry_label_type:
  1368.         cmp     [value_type],bl
  1369.         je      peplus_entry_type_ok
  1370.         cmp     [error_line],0
  1371.         jne     peplus_entry_type_ok
  1372.         mov     edx,[current_line]
  1373.         mov     [error_line],edx
  1374.         mov     [error],invalid_address
  1375.       peplus_entry_type_ok:
  1376.         mov     ecx,[code_start]
  1377.         sub     eax,[ecx+30h]
  1378.         sbb     edx,[ecx+34h]
  1379.         jz      peplus_entry_range_ok
  1380.         mov     edx,[current_line]
  1381.         mov     [error_line],edx
  1382.         mov     [error],value_out_of_range
  1383.       peplus_entry_range_ok:
  1384.         mov     [ecx+28h],eax
  1385.         jmp     instruction_assembled
  1386. pe_stack:
  1387.         lods    byte [esi]
  1388.         cmp     al,'('
  1389.         jne     invalid_argument
  1390.         cmp     byte [esi],'.'
  1391.         je      invalid_value
  1392.         test    [format_flags],8
  1393.         jnz     peplus_stack
  1394.         call    get_dword_value
  1395.         cmp     [value_type],0
  1396.         jne     invalid_use_of_symbol
  1397.         mov     edx,[code_start]
  1398.         mov     [edx+60h],eax
  1399.         cmp     byte [esi],','
  1400.         jne     default_stack_commit
  1401.         lods    byte [esi]
  1402.         lods    byte [esi]
  1403.         cmp     al,'('
  1404.         jne     invalid_argument
  1405.         cmp     byte [esi],'.'
  1406.         je      invalid_value
  1407.         call    get_dword_value
  1408.         cmp     [value_type],0
  1409.         jne     invalid_use_of_symbol
  1410.         mov     edx,[code_start]
  1411.         mov     [edx+64h],eax
  1412.         cmp     eax,[edx+60h]
  1413.         ja      value_out_of_range
  1414.         jmp     instruction_assembled
  1415.       default_stack_commit:
  1416.         mov     dword [edx+64h],1000h
  1417.         mov     eax,[edx+60h]
  1418.         cmp     eax,1000h
  1419.         ja      instruction_assembled
  1420.         mov     dword [edx+64h],eax
  1421.         jmp     instruction_assembled
  1422.       peplus_stack:
  1423.         call    get_qword_value
  1424.         cmp     [value_type],0
  1425.         jne     invalid_use_of_symbol
  1426.         mov     ecx,[code_start]
  1427.         mov     [ecx+60h],eax
  1428.         mov     [ecx+64h],edx
  1429.         cmp     byte [esi],','
  1430.         jne     default_peplus_stack_commit
  1431.         lods    byte [esi]
  1432.         lods    byte [esi]
  1433.         cmp     al,'('
  1434.         jne     invalid_argument
  1435.         cmp     byte [esi],'.'
  1436.         je      invalid_value
  1437.         call    get_qword_value
  1438.         cmp     [value_type],0
  1439.         jne     invalid_use_of_symbol
  1440.         mov     ecx,[code_start]
  1441.         mov     [ecx+68h],eax
  1442.         mov     [ecx+6Ch],edx
  1443.         cmp     edx,[ecx+64h]
  1444.         ja      value_out_of_range
  1445.         jb      instruction_assembled
  1446.         cmp     eax,[ecx+60h]
  1447.         ja      value_out_of_range
  1448.         jmp     instruction_assembled
  1449.       default_peplus_stack_commit:
  1450.         mov     dword [ecx+68h],1000h
  1451.         cmp     dword [ecx+64h],0
  1452.         jne     instruction_assembled
  1453.         mov     eax,[ecx+60h]
  1454.         cmp     eax,1000h
  1455.         ja      instruction_assembled
  1456.         mov     dword [ecx+68h],eax
  1457.         jmp     instruction_assembled
  1458. pe_heap:
  1459.         lods    byte [esi]
  1460.         cmp     al,'('
  1461.         jne     invalid_argument
  1462.         cmp     byte [esi],'.'
  1463.         je      invalid_value
  1464.         test    [format_flags],8
  1465.         jnz     peplus_heap
  1466.         call    get_dword_value
  1467.         cmp     [value_type],0
  1468.         jne     invalid_use_of_symbol
  1469.         mov     edx,[code_start]
  1470.         mov     [edx+68h],eax
  1471.         cmp     byte [esi],','
  1472.         jne     instruction_assembled
  1473.         lods    byte [esi]
  1474.         lods    byte [esi]
  1475.         cmp     al,'('
  1476.         jne     invalid_argument
  1477.         cmp     byte [esi],'.'
  1478.         je      invalid_value
  1479.         call    get_dword_value
  1480.         cmp     [value_type],0
  1481.         jne     invalid_use_of_symbol
  1482.         mov     edx,[code_start]
  1483.         mov     [edx+6Ch],eax
  1484.         cmp     eax,[edx+68h]
  1485.         ja      value_out_of_range
  1486.         jmp     instruction_assembled
  1487.       peplus_heap:
  1488.         call    get_qword_value
  1489.         cmp     [value_type],0
  1490.         jne     invalid_use_of_symbol
  1491.         mov     ecx,[code_start]
  1492.         mov     [ecx+70h],eax
  1493.         mov     [ecx+74h],edx
  1494.         cmp     byte [esi],','
  1495.         jne     instruction_assembled
  1496.         lods    byte [esi]
  1497.         lods    byte [esi]
  1498.         cmp     al,'('
  1499.         jne     invalid_argument
  1500.         cmp     byte [esi],'.'
  1501.         je      invalid_value
  1502.         call    get_qword_value
  1503.         cmp     [value_type],0
  1504.         jne     invalid_use_of_symbol
  1505.         mov     ecx,[code_start]
  1506.         mov     [ecx+78h],eax
  1507.         mov     [ecx+7Ch],edx
  1508.         cmp     edx,[ecx+74h]
  1509.         ja      value_out_of_range
  1510.         jb      instruction_assembled
  1511.         cmp     eax,[edx+70h]
  1512.         ja      value_out_of_range
  1513.         jmp     instruction_assembled
  1514. mark_pe_relocation:
  1515.         push    eax ebx
  1516.         test    [format_flags],8
  1517.         jz      check_pe32_relocation_type
  1518.         cmp     [value_type],4
  1519.         je      pe_relocation_type_ok
  1520.       check_pe32_relocation_type:
  1521.         cmp     [value_type],2
  1522.         je      pe_relocation_type_ok
  1523.         cmp     [error_line],0
  1524.         jne     pe_relocation_type_ok
  1525.         mov     eax,[current_line]
  1526.         mov     [error_line],eax
  1527.         mov     [error],invalid_use_of_symbol
  1528.       pe_relocation_type_ok:
  1529.         mov     ebx,[current_section]
  1530.         mov     eax,edi
  1531.         sub     eax,[ebx+14h]
  1532.         add     eax,[ebx+0Ch]
  1533.         mov     ebx,[free_additional_memory]
  1534.         inc     [number_of_relocations]
  1535.         jz      invalid_use_of_symbol
  1536.         add     ebx,5
  1537.         cmp     ebx,[structures_buffer]
  1538.         jae     out_of_memory
  1539.         mov     [free_additional_memory],ebx
  1540.         mov     [ebx-5],eax
  1541.         cmp     [value_type],2
  1542.         je      fixup_32bit
  1543.         mov     byte [ebx-1],0Ah
  1544.         jmp     fixup_ok
  1545.       fixup_32bit:
  1546.         mov     byte [ebx-1],3
  1547.       fixup_ok:
  1548.         pop     ebx eax
  1549.         ret
  1550. generate_pe_data:
  1551.         cmp     al,2
  1552.         je      make_pe_resource
  1553.         cmp     al,5
  1554.         je      make_pe_fixups
  1555.         ret
  1556. make_pe_fixups:
  1557.         bts     [resolver_flags],0
  1558.         jc      pe_relocatable_ok
  1559.         or      [next_pass_needed],-1
  1560.      pe_relocatable_ok:
  1561.         push    esi
  1562.         mov     ecx,[number_of_relocations]
  1563.         mov     esi,[free_additional_memory]
  1564.         lea     eax,[ecx*5]
  1565.         sub     esi,eax
  1566.         mov     [free_additional_memory],esi
  1567.         or      [number_of_relocations],-1
  1568.         xor     edx,edx
  1569.         mov     ebp,edi
  1570.       make_fixups:
  1571.         cmp     [esi],edx
  1572.         jb      store_fixup
  1573.         mov     eax,edi
  1574.         sub     eax,ebp
  1575.         test    eax,11b
  1576.         jz      fixups_block
  1577.         xor     ax,ax
  1578.         stos    word [edi]
  1579.         add     dword [ebx],2
  1580.       fixups_block:
  1581.         mov     eax,edx
  1582.         add     edx,1000h
  1583.         cmp     [esi],edx
  1584.         jae     fixups_block
  1585.         stos    dword [edi]
  1586.         mov     ebx,edi
  1587.         mov     eax,8
  1588.         stos    dword [edi]
  1589.       store_fixup:
  1590.         jecxz   fixups_done
  1591.         add     dword [ebx],2
  1592.         mov     ah,[esi+1]
  1593.         and     ah,0Fh
  1594.         mov     al,[esi+4]
  1595.         shl     al,4
  1596.         or      ah,al
  1597.         mov     al,[esi]
  1598.         stos    word [edi]
  1599.         add     esi,5
  1600.         loop    make_fixups
  1601.       fixups_done:
  1602.         pop     esi
  1603.         ret
  1604. make_pe_resource:
  1605.         cmp     byte [esi],82h
  1606.         jne     resource_done
  1607.         inc     esi
  1608.         lods    word [esi]
  1609.         cmp     ax,'('
  1610.         jne     invalid_argument
  1611.         lods    dword [esi]
  1612.         mov     edx,esi
  1613.         lea     esi,[esi+eax+1]
  1614.         cmp     [next_pass_needed],0
  1615.         je      resource_from_file
  1616.         cmp     [current_pass],0
  1617.         jne     reserve_space_for_resource
  1618.         mov     [resource_size],0
  1619.       reserve_space_for_resource:
  1620.         add     edi,[resource_size]
  1621.         cmp     edi,[display_buffer]
  1622.         ja      out_of_memory
  1623.         jmp     resource_done
  1624.       resource_from_file:
  1625.         push    esi
  1626.         mov     esi,edx
  1627.         call    open_binary_file
  1628.         push    ebx
  1629.         mov     esi,[free_additional_memory]
  1630.         lea     eax,[esi+20h]
  1631.         cmp     eax,[structures_buffer]
  1632.         ja      out_of_memory
  1633.         mov     edx,esi
  1634.         mov     ecx,20h
  1635.         call    read
  1636.         jc      invalid_file_format
  1637.         xor     eax,eax
  1638.         cmp     [esi],eax
  1639.         jne     invalid_file_format
  1640.         mov     ax,0FFFFh
  1641.         cmp     [esi+8],eax
  1642.         jne     invalid_file_format
  1643.         cmp     [esi+12],eax
  1644.         jne     invalid_file_format
  1645.         mov     eax,20h
  1646.         cmp     [esi+4],eax
  1647.         jne     invalid_file_format
  1648.       read_resource_headers:
  1649.         test    eax,11b
  1650.         jz      resource_file_alignment_ok
  1651.         mov     edx,4
  1652.         and     eax,11b
  1653.         sub     edx,eax
  1654.         mov     al,1
  1655.         call    lseek
  1656.       resource_file_alignment_ok:
  1657.         mov     [esi],eax
  1658.         lea     edx,[esi+12]
  1659.         mov     ecx,8
  1660.         call    read
  1661.         jc      resource_headers_ok
  1662.         mov     ecx,[esi+16]
  1663.         add     [esi],ecx
  1664.         lea     edx,[esi+20]
  1665.         sub     ecx,8
  1666.         mov     [esi+16],ecx
  1667.         lea     eax,[edx+ecx]
  1668.         cmp     eax,[structures_buffer]
  1669.         ja      out_of_memory
  1670.         call    read
  1671.         jc      invalid_file_format
  1672.         mov     edx,[esi]
  1673.         add     edx,[esi+12]
  1674.         mov     eax,[esi+16]
  1675.         lea     ecx,[esi+20]
  1676.         lea     esi,[ecx+eax]
  1677.         add     ecx,2
  1678.         cmp     word [ecx-2],0FFFFh
  1679.         je      resource_header_type_ok
  1680.       check_resource_header_type:
  1681.         cmp     ecx,esi
  1682.         jae     invalid_file_format
  1683.         cmp     word [ecx],0
  1684.         je      resource_header_type_ok
  1685.         add     ecx,2
  1686.         jmp     check_resource_header_type
  1687.       resource_header_type_ok:
  1688.         add     ecx,2
  1689.         cmp     word [ecx],0FFFFh
  1690.         je      resource_header_name_ok
  1691.       check_resource_header_name:
  1692.         cmp     ecx,esi
  1693.         jae     invalid_file_format
  1694.         cmp     word [ecx],0
  1695.         je      resource_header_name_ok
  1696.         add     ecx,2
  1697.         jmp     check_resource_header_name
  1698.       resource_header_name_ok:
  1699.         xor     al,al
  1700.         call    lseek
  1701.         jmp     read_resource_headers
  1702.       resource_headers_ok:
  1703.         xor     eax,eax
  1704.         mov     [esi],eax
  1705.         mov     [resource_data],edi
  1706.         lea     eax,[edi+16]
  1707.         cmp     eax,[display_buffer]
  1708.         jae     out_of_memory
  1709.         xor     eax,eax
  1710.         stos    dword [edi]
  1711.         call    make_timestamp
  1712.         stos    dword [edi]
  1713.         xor     eax,eax
  1714.         stos    dword [edi]
  1715.         stos    dword [edi]
  1716.         xor     ebx,ebx
  1717.       make_type_name_directory:
  1718.         mov     esi,[free_additional_memory]
  1719.         xor     edx,edx
  1720.       find_type_name:
  1721.         cmp     dword [esi],0
  1722.         je      type_name_ok
  1723.         add     esi,20
  1724.         cmp     word [esi],0FFFFh
  1725.         je      check_next_type_name
  1726.         or      ebx,ebx
  1727.         jz      check_this_type_name
  1728.         xor     ecx,ecx
  1729.       compare_with_previous_type_name:
  1730.         mov     ax,[esi+ecx]
  1731.         cmp     ax,[ebx+ecx]
  1732.         ja      check_this_type_name
  1733.         jb      check_next_type_name
  1734.         add     ecx,2
  1735.         mov     ax,[esi+ecx]
  1736.         or      ax,[ebx+ecx]
  1737.         jnz     compare_with_previous_type_name
  1738.         jmp     check_next_type_name
  1739.       check_this_type_name:
  1740.         or      edx,edx
  1741.         jz      type_name_found
  1742.         xor     ecx,ecx
  1743.       compare_with_current_type_name:
  1744.         mov     ax,[esi+ecx]
  1745.         cmp     ax,[edx+ecx]
  1746.         ja      check_next_type_name
  1747.         jb      type_name_found
  1748.         add     ecx,2
  1749.         mov     ax,[esi+ecx]
  1750.         or      ax,[edx+ecx]
  1751.         jnz     compare_with_current_type_name
  1752.         jmp     same_type_name
  1753.       type_name_found:
  1754.         mov     edx,esi
  1755.       same_type_name:
  1756.         mov     [esi-16],edi
  1757.       check_next_type_name:
  1758.         mov     eax,[esi-4]
  1759.         add     esi,eax
  1760.         jmp     find_type_name
  1761.       type_name_ok:
  1762.         or      edx,edx
  1763.         jz      type_name_directory_done
  1764.         mov     ebx,edx
  1765.       make_type_name_entry:
  1766.         mov     eax,[resource_data]
  1767.         inc     word [eax+12]
  1768.         lea     eax,[edi+8]
  1769.         cmp     eax,[display_buffer]
  1770.         jae     out_of_memory
  1771.         mov     eax,ebx
  1772.         stos    dword [edi]
  1773.         xor     eax,eax
  1774.         stos    dword [edi]
  1775.         jmp     make_type_name_directory
  1776.       type_name_directory_done:
  1777.         mov     ebx,-1
  1778.       make_type_id_directory:
  1779.         mov     esi,[free_additional_memory]
  1780.         mov     edx,10000h
  1781.       find_type_id:
  1782.         cmp     dword [esi],0
  1783.         je      type_id_ok
  1784.         add     esi,20
  1785.         cmp     word [esi],0FFFFh
  1786.         jne     check_next_type_id
  1787.         movzx   eax,word [esi+2]
  1788.         cmp     eax,ebx
  1789.         jle     check_next_type_id
  1790.         cmp     eax,edx
  1791.         jg      check_next_type_id
  1792.         mov     edx,eax
  1793.         mov     [esi-16],edi
  1794.       check_next_type_id:
  1795.         mov     eax,[esi-4]
  1796.         add     esi,eax
  1797.         jmp     find_type_id
  1798.       type_id_ok:
  1799.         cmp     edx,10000h
  1800.         je      type_id_directory_done
  1801.         mov     ebx,edx
  1802.       make_type_id_entry:
  1803.         mov     eax,[resource_data]
  1804.         inc     word [eax+14]
  1805.         lea     eax,[edi+8]
  1806.         cmp     eax,[display_buffer]
  1807.         jae     out_of_memory
  1808.         mov     eax,ebx
  1809.         stos    dword [edi]
  1810.         xor     eax,eax
  1811.         stos    dword [edi]
  1812.         jmp     make_type_id_directory
  1813.       type_id_directory_done:
  1814.         mov     esi,[resource_data]
  1815.         add     esi,10h
  1816.         mov     ecx,[esi-4]
  1817.         or      cx,cx
  1818.         jz      resource_directories_ok
  1819.       make_resource_directories:
  1820.         push    ecx
  1821.         push    edi
  1822.         mov     edx,edi
  1823.         sub     edx,[resource_data]
  1824.         bts     edx,31
  1825.         mov     [esi+4],edx
  1826.         lea     eax,[edi+16]
  1827.         cmp     eax,[display_buffer]
  1828.         jae     out_of_memory
  1829.         xor     eax,eax
  1830.         stos    dword [edi]
  1831.         call    make_timestamp
  1832.         stos    dword [edi]
  1833.         xor     eax,eax
  1834.         stos    dword [edi]
  1835.         stos    dword [edi]
  1836.         mov     ebp,esi
  1837.         xor     ebx,ebx
  1838.       make_resource_name_directory:
  1839.         mov     esi,[free_additional_memory]
  1840.         xor     edx,edx
  1841.       find_resource_name:
  1842.         cmp     dword [esi],0
  1843.         je      resource_name_ok
  1844.         push    esi
  1845.         cmp     [esi+4],ebp
  1846.         jne     check_next_resource_name
  1847.         add     esi,20
  1848.         call    skip_resource_name
  1849.         cmp     word [esi],0FFFFh
  1850.         je      check_next_resource_name
  1851.         or      ebx,ebx
  1852.         jz      check_this_resource_name
  1853.         xor     ecx,ecx
  1854.       compare_with_previous_resource_name:
  1855.         mov     ax,[esi+ecx]
  1856.         cmp     ax,[ebx+ecx]
  1857.         ja      check_this_resource_name
  1858.         jb      check_next_resource_name
  1859.         add     ecx,2
  1860.         mov     ax,[esi+ecx]
  1861.         or      ax,[ebx+ecx]
  1862.         jnz     compare_with_previous_resource_name
  1863.         jmp     check_next_resource_name
  1864.       skip_resource_name:
  1865.         cmp     word [esi],0FFFFh
  1866.         jne     skip_unicode_string
  1867.         add     esi,4
  1868.         ret
  1869.       skip_unicode_string:
  1870.         add     esi,2
  1871.         cmp     word [esi-2],0
  1872.         jne     skip_unicode_string
  1873.         ret
  1874.       check_this_resource_name:
  1875.         or      edx,edx
  1876.         jz      resource_name_found
  1877.         xor     ecx,ecx
  1878.       compare_with_current_resource_name:
  1879.         mov     ax,[esi+ecx]
  1880.         cmp     ax,[edx+ecx]
  1881.         ja      check_next_resource_name
  1882.         jb      resource_name_found
  1883.         add     ecx,2
  1884.         mov     ax,[esi+ecx]
  1885.         or      ax,[edx+ecx]
  1886.         jnz     compare_with_current_resource_name
  1887.         jmp     same_resource_name
  1888.       resource_name_found:
  1889.         mov     edx,esi
  1890.       same_resource_name:
  1891.         mov     eax,[esp]
  1892.         mov     [eax+8],edi
  1893.       check_next_resource_name:
  1894.         pop     esi
  1895.         mov     eax,[esi+16]
  1896.         lea     esi,[esi+20+eax]
  1897.         jmp     find_resource_name
  1898.       resource_name_ok:
  1899.         or      edx,edx
  1900.         jz      resource_name_directory_done
  1901.         mov     ebx,edx
  1902.       make_resource_name_entry:
  1903.         mov     eax,[esp]
  1904.         inc     word [eax+12]
  1905.         lea     eax,[edi+8]
  1906.         cmp     eax,[display_buffer]
  1907.         jae     out_of_memory
  1908.         mov     eax,ebx
  1909.         stos    dword [edi]
  1910.         xor     eax,eax
  1911.         stos    dword [edi]
  1912.         jmp     make_resource_name_directory
  1913.       resource_name_directory_done:
  1914.         mov     ebx,-1
  1915.       make_resource_id_directory:
  1916.         mov     esi,[free_additional_memory]
  1917.         mov     edx,10000h
  1918.       find_resource_id:
  1919.         cmp     dword [esi],0
  1920.         je      resource_id_ok
  1921.         push    esi
  1922.         cmp     [esi+4],ebp
  1923.         jne     check_next_resource_id
  1924.         add     esi,20
  1925.         call    skip_resource_name
  1926.         cmp     word [esi],0FFFFh
  1927.         jne     check_next_resource_id
  1928.         movzx   eax,word [esi+2]
  1929.         cmp     eax,ebx
  1930.         jle     check_next_resource_id
  1931.         cmp     eax,edx
  1932.         jg      check_next_resource_id
  1933.         mov     edx,eax
  1934.         mov     eax,[esp]
  1935.         mov     [eax+8],edi
  1936.       check_next_resource_id:
  1937.         pop     esi
  1938.         mov     eax,[esi+16]
  1939.         lea     esi,[esi+20+eax]
  1940.         jmp     find_resource_id
  1941.       resource_id_ok:
  1942.         cmp     edx,10000h
  1943.         je      resource_id_directory_done
  1944.         mov     ebx,edx
  1945.       make_resource_id_entry:
  1946.         mov     eax,[esp]
  1947.         inc     word [eax+14]
  1948.         lea     eax,[edi+8]
  1949.         cmp     eax,[display_buffer]
  1950.         jae     out_of_memory
  1951.         mov     eax,ebx
  1952.         stos    dword [edi]
  1953.         xor     eax,eax
  1954.         stos    dword [edi]
  1955.         jmp     make_resource_id_directory
  1956.       resource_id_directory_done:
  1957.         pop     eax
  1958.         mov     esi,ebp
  1959.         pop     ecx
  1960.         add     esi,8
  1961.         dec     cx
  1962.         jnz     make_resource_directories
  1963.       resource_directories_ok:
  1964.         shr     ecx,16
  1965.         jnz     make_resource_directories
  1966.         mov     esi,[resource_data]
  1967.         add     esi,10h
  1968.         movzx   eax,word [esi-4]
  1969.         movzx   edx,word [esi-2]
  1970.         add     eax,edx
  1971.         lea     esi,[esi+eax*8]
  1972.         push    edi                     ; address of language directories
  1973.       update_resource_directories:
  1974.         cmp     esi,[esp]
  1975.         je      resource_directories_updated
  1976.         add     esi,10h
  1977.         mov     ecx,[esi-4]
  1978.         or      cx,cx
  1979.         jz      language_directories_ok
  1980.       make_language_directories:
  1981.         push    ecx
  1982.         push    edi
  1983.         mov     edx,edi
  1984.         sub     edx,[resource_data]
  1985.         bts     edx,31
  1986.         mov     [esi+4],edx
  1987.         lea     eax,[edi+16]
  1988.         cmp     eax,[display_buffer]
  1989.         jae     out_of_memory
  1990.         xor     eax,eax
  1991.         stos    dword [edi]
  1992.         call    make_timestamp
  1993.         stos    dword [edi]
  1994.         xor     eax,eax
  1995.         stos    dword [edi]
  1996.         stos    dword [edi]
  1997.         mov     ebp,esi
  1998.         mov     ebx,-1
  1999.       make_language_id_directory:
  2000.         mov     esi,[free_additional_memory]
  2001.         mov     edx,10000h
  2002.       find_language_id:
  2003.         cmp     dword [esi],0
  2004.         je      language_id_ok
  2005.         push    esi
  2006.         cmp     [esi+8],ebp
  2007.         jne     check_next_language_id
  2008.         add     esi,20
  2009.         mov     eax,esi
  2010.         call    skip_resource_name
  2011.         call    skip_resource_name
  2012.         neg     eax
  2013.         add     eax,esi
  2014.         and     eax,11b
  2015.         add     esi,eax
  2016.       get_language_id:
  2017.         movzx   eax,word [esi+6]
  2018.         cmp     eax,ebx
  2019.         jle     check_next_language_id
  2020.         cmp     eax,edx
  2021.         jge     check_next_language_id
  2022.         mov     edx,eax
  2023.         mov     eax,[esp]
  2024.         mov     dword [value],eax
  2025.       check_next_language_id:
  2026.         pop     esi
  2027.         mov     eax,[esi+16]
  2028.         lea     esi,[esi+20+eax]
  2029.         jmp     find_language_id
  2030.       language_id_ok:
  2031.         cmp     edx,10000h
  2032.         je      language_id_directory_done
  2033.         mov     ebx,edx
  2034.       make_language_id_entry:
  2035.         mov     eax,[esp]
  2036.         inc     word [eax+14]
  2037.         lea     eax,[edi+8]
  2038.         cmp     eax,[display_buffer]
  2039.         jae     out_of_memory
  2040.         mov     eax,ebx
  2041.         stos    dword [edi]
  2042.         mov     eax,dword [value]
  2043.         stos    dword [edi]
  2044.         jmp     make_language_id_directory
  2045.       language_id_directory_done:
  2046.         pop     eax
  2047.         mov     esi,ebp
  2048.         pop     ecx
  2049.         add     esi,8
  2050.         dec     cx
  2051.         jnz     make_language_directories
  2052.       language_directories_ok:
  2053.         shr     ecx,16
  2054.         jnz     make_language_directories
  2055.         jmp     update_resource_directories
  2056.       resource_directories_updated:
  2057.         mov     esi,[resource_data]
  2058.         push    edi
  2059.       make_name_strings:
  2060.         add     esi,10h
  2061.         movzx   eax,word [esi-2]
  2062.         movzx   ecx,word [esi-4]
  2063.         add     eax,ecx
  2064.         lea     eax,[esi+eax*8]
  2065.         push    eax
  2066.         or      ecx,ecx
  2067.         jz      string_entries_processed
  2068.       process_string_entries:
  2069.         push    ecx
  2070.         mov     edx,edi
  2071.         sub     edx,[resource_data]
  2072.         bts     edx,31
  2073.         xchg    [esi],edx
  2074.         mov     ebx,edi
  2075.         xor     ax,ax
  2076.         stos    word [edi]
  2077.       copy_string_data:
  2078.         lea     eax,[edi+2]
  2079.         cmp     eax,[display_buffer]
  2080.         jae     out_of_memory
  2081.         mov     ax,[edx]
  2082.         or      ax,ax
  2083.         jz      string_data_copied
  2084.         stos    word [edi]
  2085.         inc     word [ebx]
  2086.         add     edx,2
  2087.         jmp     copy_string_data
  2088.       string_data_copied:
  2089.         add     esi,8
  2090.         pop     ecx
  2091.         loop    process_string_entries
  2092.       string_entries_processed:
  2093.         pop     esi
  2094.         cmp     esi,[esp]
  2095.         jb      make_name_strings
  2096.         mov     eax,edi
  2097.         sub     eax,[resource_data]
  2098.         test    al,11b
  2099.         jz      resource_strings_alignment_ok
  2100.         xor     ax,ax
  2101.         stos    word [edi]
  2102.       resource_strings_alignment_ok:
  2103.         pop     edx
  2104.         pop     ebx                     ; address of language directories
  2105.         mov     ebp,edi
  2106.       update_language_directories:
  2107.         add     ebx,10h
  2108.         movzx   eax,word [ebx-2]
  2109.         movzx   ecx,word [ebx-4]
  2110.         add     ecx,eax
  2111.       make_data_records:
  2112.         push    ecx
  2113.         mov     esi,edi
  2114.         sub     esi,[resource_data]
  2115.         xchg    esi,[ebx+4]
  2116.         lea     eax,[edi+16]
  2117.         cmp     eax,[display_buffer]
  2118.         jae     out_of_memory
  2119.         mov     eax,esi
  2120.         stos    dword [edi]
  2121.         mov     eax,[esi+12]
  2122.         stos    dword [edi]
  2123.         xor     eax,eax
  2124.         stos    dword [edi]
  2125.         stos    dword [edi]
  2126.         pop     ecx
  2127.         add     ebx,8
  2128.         loop    make_data_records
  2129.         cmp     ebx,edx
  2130.         jb      update_language_directories
  2131.         pop     ebx                     ; file handle
  2132.         mov     esi,ebp
  2133.         mov     ebp,edi
  2134.       update_data_records:
  2135.         push    ebp
  2136.         mov     ecx,edi
  2137.         mov     eax,[current_section]
  2138.         sub     ecx,[eax+14h]
  2139.         add     ecx,[eax+0Ch]
  2140.         xchg    ecx,[esi]
  2141.         mov     edx,[ecx]
  2142.         xor     al,al
  2143.         call    lseek
  2144.         mov     edx,edi
  2145.         mov     ecx,[esi+4]
  2146.         add     edi,ecx
  2147.         cmp     edi,[display_buffer]
  2148.         ja      out_of_memory
  2149.         call    read
  2150.         mov     eax,edi
  2151.         sub     eax,[resource_data]
  2152.         and     eax,11b
  2153.         jz      resource_data_alignment_ok
  2154.         mov     ecx,4
  2155.         sub     ecx,eax
  2156.         xor     al,al
  2157.         rep     stos byte [edi]
  2158.       resource_data_alignment_ok:
  2159.         pop     ebp
  2160.         add     esi,16
  2161.         cmp     esi,ebp
  2162.         jb      update_data_records
  2163.         pop     esi
  2164.         call    close
  2165.         mov     eax,edi
  2166.         sub     eax,[resource_data]
  2167.         mov     [resource_size],eax
  2168.       resource_done:
  2169.         ret
  2170. close_pe:
  2171.         call    close_pe_section
  2172.         mov     edx,[code_start]
  2173.         mov     [edx+50h],eax
  2174.         call    make_timestamp
  2175.         mov     edx,[code_start]
  2176.         mov     [edx+8],eax
  2177.         mov     eax,[number_of_relocations]
  2178.         cmp     eax,-1
  2179.         je      pe_relocations_ok
  2180.         shl     eax,2
  2181.         sub     [free_additional_memory],eax
  2182.         btr     [resolver_flags],0
  2183.         jnc     pe_relocations_ok
  2184.         or      [next_pass_needed],-1
  2185.       pe_relocations_ok:
  2186.         mov     eax,[number_of_sections]
  2187.         mov     [edx+6],ax
  2188.         imul    eax,28h
  2189.         movzx   ecx,word [edx+14h]
  2190.         lea     eax,[eax+18h+ecx]
  2191.         add     eax,[stub_size]
  2192.         mov     ecx,[edx+3Ch]
  2193.         dec     ecx
  2194.         add     eax,ecx
  2195.         not     ecx
  2196.         and     eax,ecx
  2197.         cmp     eax,[edx+54h]
  2198.         je      pe_sections_ok
  2199.         or      [next_pass_needed],-1
  2200.       pe_sections_ok:
  2201.         xor     ecx,ecx
  2202.         add     edx,78h
  2203.         test    [format_flags],8
  2204.         jz      process_directories
  2205.         add     edx,10h
  2206.       process_directories:
  2207.         mov     eax,[edx+ecx*8]
  2208.         or      eax,eax
  2209.         jz      directory_ok
  2210.         cmp     dword [edx+ecx*8+4],-1
  2211.         jne     directory_ok
  2212.       section_data:
  2213.         mov     ebx,[edx+ecx*8]
  2214.         mov     eax,[ebx+0Ch]
  2215.         mov     [edx+ecx*8],eax         ; directory rva
  2216.         mov     eax,[ebx+8]
  2217.         mov     [edx+ecx*8+4],eax       ; directory size
  2218.       directory_ok:
  2219.         inc     cl
  2220.         cmp     cl,10h
  2221.         jb      process_directories
  2222.         mov     ebx,[code_start]
  2223.         sub     ebx,[stub_size]
  2224.         mov     ecx,edi
  2225.         sub     ecx,ebx
  2226.         mov     ebp,ecx
  2227.         shr     ecx,1
  2228.         xor     eax,eax
  2229.         cdq
  2230.       calculate_checksum:
  2231.         mov     dx,[ebx]
  2232.         add     eax,edx
  2233.         mov     dx,ax
  2234.         shr     eax,16
  2235.         add     eax,edx
  2236.         add     ebx,2
  2237.         loop    calculate_checksum
  2238.         add     eax,ebp
  2239.         mov     ebx,[code_start]
  2240.         mov     [ebx+58h],eax
  2241.         ret
  2242.  
  2243. format_coff:
  2244.         mov     eax,[additional_memory]
  2245.         mov     [symbols_stream],eax
  2246.         mov     ebx,eax
  2247.         add     eax,20h
  2248.         cmp     eax,[structures_buffer]
  2249.         jae     out_of_memory
  2250.         mov     [free_additional_memory],eax
  2251.         xor     eax,eax
  2252.         mov     [ebx],al
  2253.         mov     [ebx+4],eax
  2254.         mov     [ebx+8],edi
  2255.         mov     al,4
  2256.         mov     [ebx+10h],eax
  2257.         mov     al,60h
  2258.         bt      [format_flags],0
  2259.         jnc     flat_section_flags_ok
  2260.         or      eax,0E0000000h
  2261.       flat_section_flags_ok:
  2262.         mov     dword [ebx+14h],eax
  2263.         mov     [current_section],ebx
  2264.         mov     [number_of_sections],0
  2265.         mov     dword [org_origin],edi
  2266.         mov     dword [org_origin+4],0
  2267.         mov     [org_registers],0
  2268.         mov     [org_start],edi
  2269.         mov     [org_symbol],ebx
  2270.         mov     [labels_type],2
  2271.         mov     [code_type],32
  2272.         test    [format_flags],8
  2273.         jz      format_defined
  2274.         mov     [labels_type],4
  2275.         mov     [code_type],64
  2276.         jmp     format_defined
  2277. coff_section:
  2278.         call    close_coff_section
  2279.         mov     ebx,[free_additional_memory]
  2280.         lea     eax,[ebx+20h]
  2281.         cmp     eax,[structures_buffer]
  2282.         jae     out_of_memory
  2283.         mov     [free_additional_memory],eax
  2284.         mov     [current_section],ebx
  2285.         inc     [number_of_sections]
  2286.         xor     eax,eax
  2287.         mov     [ebx],al
  2288.         mov     [ebx+8],edi
  2289.         mov     dword [org_origin],edi
  2290.         mov     dword [org_origin+4],0
  2291.         mov     [org_registers],0
  2292.         mov     [org_start],edi
  2293.         mov     [org_symbol],ebx
  2294.         mov     [labels_type],2
  2295.         test    [format_flags],8
  2296.         jz      coff_labels_type_ok
  2297.         mov     [labels_type],4
  2298.       coff_labels_type_ok:
  2299.         mov     [ebx+10h],eax
  2300.         mov     [ebx+14h],eax
  2301.         lods    word [esi]
  2302.         cmp     ax,'('
  2303.         jne     invalid_argument
  2304.         mov     [ebx+4],esi
  2305.         mov     ecx,[esi]
  2306.         lea     esi,[esi+4+ecx+1]
  2307.         cmp     ecx,8
  2308.         ja      name_too_long
  2309.       coff_section_flags:
  2310.         cmp     byte [esi],1Ch
  2311.         je      coff_section_alignment
  2312.         cmp     byte [esi],19h
  2313.         jne     coff_section_settings_ok
  2314.         inc     esi
  2315.         lods    byte [esi]
  2316.         bt      [format_flags],0
  2317.         jc      coff_section_flag_ok
  2318.         cmp     al,7
  2319.         ja      invalid_argument
  2320.       coff_section_flag_ok:
  2321.         mov     cl,al
  2322.         mov     eax,1
  2323.         shl     eax,cl
  2324.         test    dword [ebx+14h],eax
  2325.         jnz     setting_already_specified
  2326.         or      dword [ebx+14h],eax
  2327.         jmp     coff_section_flags
  2328.       coff_section_alignment:
  2329.         bt      [format_flags],0
  2330.         jnc     invalid_argument
  2331.         inc     esi
  2332.         lods    byte [esi]
  2333.         or      al,al
  2334.         jnz     invalid_argument
  2335.         lods    byte [esi]
  2336.         cmp     al,'('
  2337.         jne     invalid_argument
  2338.         cmp     byte [esi],'.'
  2339.         je      invalid_value
  2340.         push    ebx
  2341.         call    get_dword_value
  2342.         pop     ebx
  2343.         cmp     [value_type],0
  2344.         jne     invalid_use_of_symbol
  2345.         mov     edx,eax
  2346.         dec     edx
  2347.         test    eax,edx
  2348.         jnz     invalid_value
  2349.         or      eax,eax
  2350.         jz      invalid_value
  2351.         cmp     eax,2000h
  2352.         ja      invalid_value
  2353.         bsf     edx,eax
  2354.         inc     edx
  2355.         shl     edx,20
  2356.         or      [ebx+14h],edx
  2357.         xchg    [ebx+10h],eax
  2358.         or      eax,eax
  2359.         jnz     setting_already_specified
  2360.         jmp     coff_section_flags
  2361.       coff_section_settings_ok:
  2362.         cmp     dword [ebx+10h],0
  2363.         jne     instruction_assembled
  2364.         mov     dword [ebx+10h],4
  2365.         bt      [format_flags],0
  2366.         jnc     instruction_assembled
  2367.         or      dword [ebx+14h],300000h
  2368.         jmp     instruction_assembled
  2369.       close_coff_section:
  2370.         mov     ebx,[current_section]
  2371.         mov     eax,edi
  2372.         mov     edx,[ebx+8]
  2373.         sub     eax,edx
  2374.         mov     [ebx+0Ch],eax
  2375.         xor     eax,eax
  2376.         xchg    [undefined_data_end],eax
  2377.         cmp     eax,edi
  2378.         jne     coff_section_ok
  2379.         cmp     edx,[undefined_data_start]
  2380.         jne     coff_section_ok
  2381.         mov     edi,edx
  2382.         or      byte [ebx+14h],80h
  2383.       coff_section_ok:
  2384.         ret
  2385. mark_coff_relocation:
  2386.         cmp     [value_type],3
  2387.         je      coff_relocation_relative
  2388.         push    ebx eax
  2389.         test    [format_flags],8
  2390.         jnz     coff_64bit_relocation
  2391.         mov     al,6
  2392.         cmp     [value_type],5
  2393.         jne     coff_relocation
  2394.         inc     al
  2395.         jmp     coff_relocation
  2396.       coff_64bit_relocation:
  2397.         mov     al,1
  2398.         cmp     [value_type],4
  2399.         je      coff_relocation
  2400.         mov     al,2
  2401.         cmp     [value_type],5
  2402.         jne     coff_relocation
  2403.         inc     al
  2404.         jmp     coff_relocation
  2405.       coff_relocation_relative:
  2406.         push    ebx
  2407.         bt      [format_flags],0
  2408.         jnc     relative_ok
  2409.         mov     ebx,[current_section]
  2410.         mov     ebx,[ebx+8]
  2411.         sub     ebx,edi
  2412.         sub     eax,ebx
  2413.         add     eax,4
  2414.       relative_ok:
  2415.         push    eax
  2416.         mov     al,20
  2417.         test    [format_flags],8
  2418.         jnz     relative_coff_64bit_relocation
  2419.         cmp     [labels_type],2
  2420.         jne     invalid_use_of_symbol
  2421.         jmp     coff_relocation
  2422.       relative_coff_64bit_relocation:
  2423.         mov     al,4
  2424.         cmp     [labels_type],4
  2425.         jne     invalid_use_of_symbol
  2426.       coff_relocation:
  2427.         mov     ebx,[free_additional_memory]
  2428.         add     ebx,0Ch
  2429.         cmp     ebx,[structures_buffer]
  2430.         jae     out_of_memory
  2431.         mov     [free_additional_memory],ebx
  2432.         mov     byte [ebx-0Ch],al
  2433.         mov     eax,[current_section]
  2434.         mov     eax,[eax+8]
  2435.         neg     eax
  2436.         add     eax,edi
  2437.         mov     [ebx-0Ch+4],eax
  2438.         mov     eax,[symbol_identifier]
  2439.         mov     [ebx-0Ch+8],eax
  2440.         pop     eax ebx
  2441.         ret
  2442. close_coff:
  2443.         call    close_coff_section
  2444.         cmp     [next_pass_needed],0
  2445.         je      coff_closed
  2446.         mov     eax,[symbols_stream]
  2447.         mov     [free_additional_memory],eax
  2448.       coff_closed:
  2449.         ret
  2450. coff_formatter:
  2451.         sub     edi,[code_start]
  2452.         mov     [code_size],edi
  2453.         call    prepare_default_section
  2454.         mov     edi,[free_additional_memory]
  2455.         mov     ebx,edi
  2456.         mov     ecx,28h shr 2
  2457.         imul    ecx,[number_of_sections]
  2458.         add     ecx,14h shr 2
  2459.         lea     eax,[edi+ecx*4]
  2460.         cmp     eax,[structures_buffer]
  2461.         jae     out_of_memory
  2462.         xor     eax,eax
  2463.         rep     stos dword [edi]
  2464.         mov     word [ebx],14Ch
  2465.         test    [format_flags],8
  2466.         jz      coff_magic_ok
  2467.         mov     word [ebx],8664h
  2468.       coff_magic_ok:
  2469.         mov     word [ebx+12h],104h
  2470.         bt      [format_flags],0
  2471.         jnc     coff_flags_ok
  2472.         or      byte [ebx+12h],80h
  2473.       coff_flags_ok:
  2474.         push    ebx
  2475.         call    make_timestamp
  2476.         pop     ebx
  2477.         mov     [ebx+4],eax
  2478.         mov     eax,[number_of_sections]
  2479.         mov     [ebx+2],ax
  2480.         mov     esi,[symbols_stream]
  2481.         xor     eax,eax
  2482.         xor     ecx,ecx
  2483.       enumerate_symbols:
  2484.         cmp     esi,[free_additional_memory]
  2485.         je      symbols_enumerated
  2486.         mov     dl,[esi]
  2487.         or      dl,dl
  2488.         jz      enumerate_section
  2489.         cmp     dl,0C0h
  2490.         jae     enumerate_public
  2491.         cmp     dl,80h
  2492.         jae     enumerate_extrn
  2493.         add     esi,0Ch
  2494.         jmp     enumerate_symbols
  2495.       enumerate_section:
  2496.         mov     edx,eax
  2497.         shl     edx,8
  2498.         mov     [esi],edx
  2499.         inc     eax
  2500.         inc     ecx
  2501.         mov     [esi+1Eh],cx
  2502.         add     esi,20h
  2503.         jmp     enumerate_symbols
  2504.       enumerate_public:
  2505.         mov     edx,eax
  2506.         shl     edx,8
  2507.         mov     dl,[esi]
  2508.         mov     [esi],edx
  2509.         mov     edx,[esi+8]
  2510.         add     esi,10h
  2511.         inc     eax
  2512.         cmp     byte [edx+11],2
  2513.         jne     enumerate_symbols
  2514.         mov     edx,[edx+20]
  2515.         cmp     byte [edx],0C0h
  2516.         jae     enumerate_symbols
  2517.         cmp     byte [edx],80h
  2518.         jb      enumerate_symbols
  2519.         inc     eax
  2520.         jmp     enumerate_symbols
  2521.       enumerate_extrn:
  2522.         mov     edx,eax
  2523.         shl     edx,8
  2524.         mov     dl,[esi]
  2525.         mov     [esi],edx
  2526.         add     esi,0Ch
  2527.         inc     eax
  2528.         jmp     enumerate_symbols
  2529.       prepare_default_section:
  2530.         mov     ebx,[symbols_stream]
  2531.         cmp     dword [ebx+0Ch],0
  2532.         jne     default_section_ok
  2533.         cmp     [number_of_sections],0
  2534.         je      default_section_ok
  2535.         mov     edx,ebx
  2536.       find_references_to_default_section:
  2537.         cmp     ebx,[free_additional_memory]
  2538.         jne     check_reference
  2539.         add     [symbols_stream],20h
  2540.         ret
  2541.       check_reference:
  2542.         mov     al,[ebx]
  2543.         or      al,al
  2544.         jz      skip_other_section
  2545.         cmp     al,0C0h
  2546.         jae     check_public_reference
  2547.         cmp     al,80h
  2548.         jae     next_reference
  2549.         cmp     edx,[ebx+8]
  2550.         je      default_section_ok
  2551.       next_reference:
  2552.         add     ebx,0Ch
  2553.         jmp     find_references_to_default_section
  2554.       check_public_reference:
  2555.         mov     eax,[ebx+8]
  2556.         add     ebx,10h
  2557.         test    byte [eax+8],1
  2558.         jz      find_references_to_default_section
  2559.         mov     cx,[current_pass]
  2560.         cmp     cx,[eax+16]
  2561.         jne     find_references_to_default_section
  2562.         cmp     edx,[eax+20]
  2563.         je      default_section_ok
  2564.         jmp     find_references_to_default_section
  2565.       skip_other_section:
  2566.         add     ebx,20h
  2567.         jmp     find_references_to_default_section
  2568.       default_section_ok:
  2569.         inc     [number_of_sections]
  2570.         ret
  2571.       symbols_enumerated:
  2572.         mov     [ebx+0Ch],eax
  2573.         mov     ebp,edi
  2574.         sub     ebp,ebx
  2575.         push    ebp
  2576.         lea     edi,[ebx+14h]
  2577.         mov     esi,[symbols_stream]
  2578.       find_section:
  2579.         cmp     esi,[free_additional_memory]
  2580.         je      sections_finished
  2581.         mov     al,[esi]
  2582.         or      al,al
  2583.         jz      section_found
  2584.         add     esi,0Ch
  2585.         cmp     al,0C0h
  2586.         jb      find_section
  2587.         add     esi,4
  2588.         jmp     find_section
  2589.       section_found:
  2590.         push    esi edi
  2591.         mov     esi,[esi+4]
  2592.         or      esi,esi
  2593.         jz      default_section
  2594.         mov     ecx,[esi]
  2595.         add     esi,4
  2596.         rep     movs byte [edi],[esi]
  2597.         jmp     section_name_ok
  2598.       default_section:
  2599.         mov     al,'.'
  2600.         stos    byte [edi]
  2601.         mov     eax,'flat'
  2602.         stos    dword [edi]
  2603.       section_name_ok:
  2604.         pop     edi esi
  2605.         mov     eax,[esi+0Ch]
  2606.         mov     [edi+10h],eax
  2607.         mov     eax,[esi+14h]
  2608.         mov     [edi+24h],eax
  2609.         test    al,80h
  2610.         jnz     section_ptr_ok
  2611.         mov     eax,[esi+8]
  2612.         sub     eax,[code_start]
  2613.         add     eax,ebp
  2614.         mov     [edi+14h],eax
  2615.       section_ptr_ok:
  2616.         mov     ebx,[code_start]
  2617.         mov     edx,[code_size]
  2618.         add     ebx,edx
  2619.         add     edx,ebp
  2620.         xor     ecx,ecx
  2621.         add     esi,20h
  2622.       find_relocations:
  2623.         cmp     esi,[free_additional_memory]
  2624.         je      section_relocations_done
  2625.         mov     al,[esi]
  2626.         or      al,al
  2627.         jz      section_relocations_done
  2628.         cmp     al,80h
  2629.         jb      add_relocation
  2630.         cmp     al,0C0h
  2631.         jb      next_relocation
  2632.         add     esi,10h
  2633.         jmp     find_relocations
  2634.       add_relocation:
  2635.         lea     eax,[ebx+0Ah]
  2636.         cmp     eax,[display_buffer]
  2637.         ja      out_of_memory
  2638.         mov     eax,[esi+4]
  2639.         mov     [ebx],eax
  2640.         mov     eax,[esi+8]
  2641.         mov     eax,[eax]
  2642.         shr     eax,8
  2643.         mov     [ebx+4],eax
  2644.         movzx   ax,byte [esi]
  2645.         mov     [ebx+8],ax
  2646.         add     ebx,0Ah
  2647.         inc     ecx
  2648.       next_relocation:
  2649.         add     esi,0Ch
  2650.         jmp     find_relocations
  2651.       section_relocations_done:
  2652.         cmp     ecx,10000h
  2653.         jb      section_relocations_count_16bit
  2654.         bt      [format_flags],0
  2655.         jnc     format_limitations_exceeded
  2656.         mov     word [edi+20h],0FFFFh
  2657.         or      dword [edi+24h],1000000h
  2658.         mov     [edi+18h],edx
  2659.         push    esi edi
  2660.         push    ecx
  2661.         lea     esi,[ebx-1]
  2662.         add     ebx,0Ah
  2663.         lea     edi,[ebx-1]
  2664.         imul    ecx,0Ah
  2665.         std
  2666.         rep     movs byte [edi],[esi]
  2667.         cld
  2668.         pop     ecx
  2669.         inc     esi
  2670.         inc     ecx
  2671.         mov     [esi],ecx
  2672.         xor     eax,eax
  2673.         mov     [esi+4],eax
  2674.         mov     [esi+8],ax
  2675.         pop     edi esi
  2676.         jmp     section_relocations_ok
  2677.       section_relocations_count_16bit:
  2678.         mov     [edi+20h],cx
  2679.         jcxz    section_relocations_ok
  2680.         mov     [edi+18h],edx
  2681.       section_relocations_ok:
  2682.         sub     ebx,[code_start]
  2683.         mov     [code_size],ebx
  2684.         add     edi,28h
  2685.         jmp     find_section
  2686.       sections_finished:
  2687.         mov     edx,[free_additional_memory]
  2688.         mov     ebx,[code_size]
  2689.         add     ebp,ebx
  2690.         mov     [edx+8],ebp
  2691.         add     ebx,[code_start]
  2692.         mov     edi,ebx
  2693.         mov     ecx,[edx+0Ch]
  2694.         imul    ecx,12h shr 1
  2695.         xor     eax,eax
  2696.         shr     ecx,1
  2697.         jnc     zero_symbols_table
  2698.         stos    word [edi]
  2699.       zero_symbols_table:
  2700.         rep     stos dword [edi]
  2701.         mov     edx,edi
  2702.         stos    dword [edi]
  2703.         mov     esi,[symbols_stream]
  2704.       make_symbols_table:
  2705.         cmp     esi,[free_additional_memory]
  2706.         je      symbols_table_ok
  2707.         mov     al,[esi]
  2708.         cmp     al,0C0h
  2709.         jae     add_public_symbol
  2710.         cmp     al,80h
  2711.         jae     add_extrn_symbol
  2712.         or      al,al
  2713.         jz      add_section_symbol
  2714.         add     esi,0Ch
  2715.         jmp     make_symbols_table
  2716.       add_section_symbol:
  2717.         call    store_symbol_name
  2718.         movzx   eax,word [esi+1Eh]
  2719.         mov     [ebx+0Ch],ax
  2720.         mov     byte [ebx+10h],3
  2721.         add     esi,20h
  2722.         add     ebx,12h
  2723.         jmp     make_symbols_table
  2724.       add_extrn_symbol:
  2725.         call    store_symbol_name
  2726.         mov     byte [ebx+10h],2
  2727.         add     esi,0Ch
  2728.         add     ebx,12h
  2729.         jmp     make_symbols_table
  2730.       add_public_symbol:
  2731.         call    store_symbol_name
  2732.         mov     eax,[esi+0Ch]
  2733.         mov     [current_line],eax
  2734.         mov     eax,[esi+8]
  2735.         test    byte [eax+8],1
  2736.         jz      undefined_coff_public
  2737.         mov     cx,[current_pass]
  2738.         cmp     cx,[eax+16]
  2739.         jne     undefined_coff_public
  2740.         mov     cl,[eax+11]
  2741.         or      cl,cl
  2742.         jz      public_constant
  2743.         test    [format_flags],8
  2744.         jnz     check_64bit_public_symbol
  2745.         cmp     cl,2
  2746.         je      public_symbol_type_ok
  2747.         jmp     invalid_use_of_symbol
  2748.       undefined_coff_public:
  2749.         mov     eax,[eax+24]
  2750.         mov     [error_info],eax
  2751.         jmp     undefined_symbol
  2752.       check_64bit_public_symbol:
  2753.         cmp     cl,4
  2754.         jne     invalid_use_of_symbol
  2755.       public_symbol_type_ok:
  2756.         mov     ecx,[eax+20]
  2757.         cmp     byte [ecx],80h
  2758.         je      alias_symbol
  2759.         cmp     byte [ecx],0
  2760.         jne     invalid_use_of_symbol
  2761.         mov     cx,[ecx+1Eh]
  2762.         mov     [ebx+0Ch],cx
  2763.       public_symbol_section_ok:
  2764.         cmp     dword [eax+4],0
  2765.         je      store_public_symbol
  2766.         cmp     dword [eax+4],-1
  2767.         jne     value_out_of_range
  2768.         bt      dword [eax],31
  2769.         jnc     value_out_of_range
  2770.       store_public_symbol:
  2771.         mov     eax,[eax]
  2772.         mov     [ebx+8],eax
  2773.         mov     al,2
  2774.         cmp     byte [esi],0C0h
  2775.         je      store_symbol_class
  2776.         inc     al
  2777.         cmp     byte [esi],0C1h
  2778.         je      store_symbol_class
  2779.         mov     al,105
  2780.       store_symbol_class:
  2781.         mov     byte [ebx+10h],al
  2782.         add     esi,10h
  2783.         add     ebx,12h
  2784.         jmp     make_symbols_table
  2785.       alias_symbol:
  2786.         bt      [format_flags],0
  2787.         jnc     invalid_use_of_symbol
  2788.         mov     ecx,[eax]
  2789.         or      ecx,[eax+4]
  2790.         jnz     invalid_use_of_symbol
  2791.         mov     byte [ebx+10h],69h
  2792.         mov     byte [ebx+11h],1
  2793.         add     ebx,12h
  2794.         mov     ecx,[eax+20]
  2795.         mov     ecx,[ecx]
  2796.         shr     ecx,8
  2797.         mov     [ebx],ecx
  2798.         mov     byte [ebx+4],3
  2799.         add     esi,10h
  2800.         add     ebx,12h
  2801.         jmp     make_symbols_table
  2802.       public_constant:
  2803.         mov     word [ebx+0Ch],0FFFFh
  2804.         jmp     public_symbol_section_ok
  2805.       symbols_table_ok:
  2806.         mov     eax,edi
  2807.         sub     eax,edx
  2808.         mov     [edx],eax
  2809.         sub     edi,[code_start]
  2810.         mov     [code_size],edi
  2811.         mov     [written_size],0
  2812.         mov     edx,[output_file]
  2813.         call    create
  2814.         jc      write_failed
  2815.         mov     edx,[free_additional_memory]
  2816.         pop     ecx
  2817.         add     [written_size],ecx
  2818.         call    write
  2819.         jc      write_failed
  2820.         jmp     write_output
  2821.       store_symbol_name:
  2822.         push    esi
  2823.         mov     esi,[esi+4]
  2824.         or      esi,esi
  2825.         jz      default_name
  2826.         lods    dword [esi]
  2827.         mov     ecx,eax
  2828.         cmp     ecx,8
  2829.         ja      add_string
  2830.         push    edi
  2831.         mov     edi,ebx
  2832.         rep     movs byte [edi],[esi]
  2833.         pop     edi esi
  2834.         ret
  2835.       default_name:
  2836.         mov     dword [ebx],'.fla'
  2837.         mov     dword [ebx+4],'t'
  2838.         pop     esi
  2839.         ret
  2840.       add_string:
  2841.         mov     eax,edi
  2842.         sub     eax,edx
  2843.         mov     [ebx+4],eax
  2844.         inc     ecx
  2845.         rep     movs byte [edi],[esi]
  2846.         pop     esi
  2847.         ret
  2848.  
  2849. format_elf:
  2850.         test    [format_flags],8
  2851.         jnz     format_elf64
  2852.         mov     edx,edi
  2853.         mov     ecx,34h shr 2
  2854.         lea     eax,[edi+ecx*4]
  2855.         cmp     eax,[display_buffer]
  2856.         jae     out_of_memory
  2857.         xor     eax,eax
  2858.         rep     stos dword [edi]
  2859.         mov     dword [edx],7Fh + 'ELF' shl 8
  2860.         mov     al,1
  2861.         mov     [edx+4],al
  2862.         mov     [edx+5],al
  2863.         mov     [edx+6],al
  2864.         mov     [edx+14h],al
  2865.         mov     byte [edx+12h],3
  2866.         mov     byte [edx+28h],34h
  2867.         mov     byte [edx+2Eh],28h
  2868.         mov     [code_type],32
  2869.         cmp     word [esi],1D19h
  2870.         je      format_elf_exe
  2871.         mov     [labels_type],2
  2872.       elf_header_ok:
  2873.         mov     byte [edx+10h],1
  2874.         mov     eax,[additional_memory]
  2875.         mov     [symbols_stream],eax
  2876.         mov     ebx,eax
  2877.         add     eax,20h
  2878.         cmp     eax,[structures_buffer]
  2879.         jae     out_of_memory
  2880.         mov     [free_additional_memory],eax
  2881.         xor     eax,eax
  2882.         mov     [current_section],ebx
  2883.         mov     [number_of_sections],eax
  2884.         mov     dword [org_origin],edi
  2885.         mov     dword [org_origin+4],eax
  2886.         mov     [org_registers],eax
  2887.         mov     [org_start],edi
  2888.         mov     [org_symbol],ebx
  2889.         mov     [ebx],al
  2890.         mov     [ebx+4],eax
  2891.         mov     [ebx+8],edi
  2892.         mov     al,111b
  2893.         mov     [ebx+14h],eax
  2894.         mov     al,4
  2895.         mov     [ebx+10h],eax
  2896.         test    [format_flags],8
  2897.         jz      format_defined
  2898.         mov     byte [ebx+10h],8
  2899.         jmp     format_defined
  2900.       format_elf64:
  2901.         mov     edx,edi
  2902.         mov     ecx,40h shr 2
  2903.         lea     eax,[edi+ecx*4]
  2904.         cmp     eax,[display_buffer]
  2905.         jae     out_of_memory
  2906.         xor     eax,eax
  2907.         rep     stos dword [edi]
  2908.         mov     dword [edx],7Fh + 'ELF' shl 8
  2909.         mov     al,1
  2910.         mov     [edx+5],al
  2911.         mov     [edx+6],al
  2912.         mov     [edx+14h],al
  2913.         mov     byte [edx+4],2
  2914.         mov     byte [edx+12h],62
  2915.         mov     byte [edx+34h],40h
  2916.         mov     byte [edx+3Ah],40h
  2917.         mov     [code_type],64
  2918.         cmp     word [esi],1D19h
  2919.         je      format_elf64_exe
  2920.         mov     [labels_type],4
  2921.         jmp     elf_header_ok
  2922. elf_section:
  2923.         bt      [format_flags],0
  2924.         jc      illegal_instruction
  2925.         call    close_coff_section
  2926.         mov     ebx,[free_additional_memory]
  2927.         lea     eax,[ebx+20h]
  2928.         cmp     eax,[structures_buffer]
  2929.         jae     out_of_memory
  2930.         mov     [free_additional_memory],eax
  2931.         mov     [current_section],ebx
  2932.         inc     word [number_of_sections]
  2933.         jz      format_limitations_exceeded
  2934.         xor     eax,eax
  2935.         mov     [ebx],al
  2936.         mov     [ebx+8],edi
  2937.         mov     dword [org_origin],edi
  2938.         mov     dword [org_origin+4],0
  2939.         mov     [org_registers],0
  2940.         mov     [org_start],edi
  2941.         mov     [org_symbol],ebx
  2942.         test    [format_flags],8
  2943.         jnz     elf64_labels_type
  2944.         mov     [labels_type],2
  2945.         jmp     elf_labels_type_ok
  2946.       elf64_labels_type:
  2947.         mov     [labels_type],4
  2948.       elf_labels_type_ok:
  2949.         mov     [ebx+10h],eax
  2950.         mov     al,10b
  2951.         mov     [ebx+14h],eax
  2952.         lods    word [esi]
  2953.         cmp     ax,'('
  2954.         jne     invalid_argument
  2955.         mov     [ebx+4],esi
  2956.         mov     ecx,[esi]
  2957.         lea     esi,[esi+4+ecx+1]
  2958.       elf_section_flags:
  2959.         cmp     byte [esi],1Ch
  2960.         je      elf_section_alignment
  2961.         cmp     byte [esi],19h
  2962.         jne     elf_section_settings_ok
  2963.         inc     esi
  2964.         lods    byte [esi]
  2965.         sub     al,28
  2966.         xor     al,11b
  2967.         test    al,not 10b
  2968.         jnz     invalid_argument
  2969.         mov     cl,al
  2970.         mov     al,1
  2971.         shl     al,cl
  2972.         test    byte [ebx+14h],al
  2973.         jnz     setting_already_specified
  2974.         or      byte [ebx+14h],al
  2975.         jmp     elf_section_flags
  2976.       elf_section_alignment:
  2977.         inc     esi
  2978.         lods    byte [esi]
  2979.         or      al,al
  2980.         jnz     invalid_argument
  2981.         lods    byte [esi]
  2982.         cmp     al,'('
  2983.         jne     invalid_argument
  2984.         cmp     byte [esi],'.'
  2985.         je      invalid_value
  2986.         push    ebx
  2987.         call    get_dword_value
  2988.         pop     ebx
  2989.         cmp     [value_type],0
  2990.         jne     invalid_use_of_symbol
  2991.         mov     edx,eax
  2992.         dec     edx
  2993.         test    eax,edx
  2994.         jnz     invalid_value
  2995.         or      eax,eax
  2996.         jz      invalid_value
  2997.         xchg    [ebx+10h],eax
  2998.         or      eax,eax
  2999.         jnz     setting_already_specified
  3000.         jmp     elf_section_flags
  3001.       elf_section_settings_ok:
  3002.         cmp     dword [ebx+10h],0
  3003.         jne     instruction_assembled
  3004.         mov     dword [ebx+10h],4
  3005.         test    [format_flags],8
  3006.         jz      instruction_assembled
  3007.         mov     byte [ebx+10h],8
  3008.         jmp     instruction_assembled
  3009. mark_elf_relocation:
  3010.         cmp     [value_type],3
  3011.         je      elf_relocation_relative
  3012.         cmp     [value_type],7
  3013.         je      elf_relocation_relative
  3014.         push    ebx eax
  3015.         cmp     [value_type],5
  3016.         je      elf_gotoff_relocation
  3017.         ja      invalid_use_of_symbol
  3018.         mov     al,1                    ; R_386_32 / R_AMD64_64
  3019.         test    [format_flags],8
  3020.         jz      coff_relocation
  3021.         cmp     [value_type],4
  3022.         je      coff_relocation
  3023.         mov     al,11                   ; R_AMD64_32S
  3024.         jmp     coff_relocation
  3025.       elf_gotoff_relocation:
  3026.         test    [format_flags],8
  3027.         jnz     invalid_use_of_symbol
  3028.         mov     al,9                    ; R_386_GOTOFF
  3029.         jmp     coff_relocation
  3030.       elf_relocation_relative:
  3031.         cmp     [labels_type],0
  3032.         je      invalid_use_of_symbol
  3033.         push    ebx
  3034.         mov     ebx,[current_section]
  3035.         mov     ebx,[ebx+8]
  3036.         sub     ebx,edi
  3037.         sub     eax,ebx
  3038.         push    eax
  3039.         mov     al,2                    ; R_386_PC32 / R_AMD64_PC32
  3040.         cmp     [value_type],3
  3041.         je      coff_relocation
  3042.         mov     al,4                    ; R_386_PLT32 / R_AMD64_PLT32
  3043.         jmp     coff_relocation
  3044. close_elf:
  3045.         bt      [format_flags],0
  3046.         jc      close_elf_exe
  3047.         call    close_coff_section
  3048.         cmp     [next_pass_needed],0
  3049.         je      elf_closed
  3050.         mov     eax,[symbols_stream]
  3051.         mov     [free_additional_memory],eax
  3052.       elf_closed:
  3053.         ret
  3054. elf_formatter:
  3055.         push    edi
  3056.         call    prepare_default_section
  3057.         mov     esi,[symbols_stream]
  3058.         mov     edi,[free_additional_memory]
  3059.         xor     eax,eax
  3060.         mov     ecx,4
  3061.         rep     stos dword [edi]
  3062.         test    [format_flags],8
  3063.         jz      find_first_section
  3064.         mov     ecx,2
  3065.         rep     stos dword [edi]
  3066.       find_first_section:
  3067.         mov     al,[esi]
  3068.         or      al,al
  3069.         jz      first_section_found
  3070.         cmp     al,0C0h
  3071.         jb      skip_other_symbol
  3072.         add     esi,4
  3073.       skip_other_symbol:
  3074.         add     esi,0Ch
  3075.         jmp     find_first_section
  3076.       first_section_found:
  3077.         mov     ebx,esi
  3078.         mov     ebp,esi
  3079.         add     esi,20h
  3080.         xor     ecx,ecx
  3081.         xor     edx,edx
  3082.       find_next_section:
  3083.         cmp     esi,[free_additional_memory]
  3084.         je      make_section_symbol
  3085.         mov     al,[esi]
  3086.         or      al,al
  3087.         jz      make_section_symbol
  3088.         cmp     al,0C0h
  3089.         jae     skip_public
  3090.         cmp     al,80h
  3091.         jae     skip_extrn
  3092.         or      byte [ebx+14h],40h
  3093.       skip_extrn:
  3094.         add     esi,0Ch
  3095.         jmp     find_next_section
  3096.       skip_public:
  3097.         add     esi,10h
  3098.         jmp     find_next_section
  3099.       make_section_symbol:
  3100.         mov     eax,edi
  3101.         xchg    eax,[ebx+4]
  3102.         stos    dword [edi]
  3103.         test    [format_flags],8
  3104.         jnz     elf64_section_symbol
  3105.         xor     eax,eax
  3106.         stos    dword [edi]
  3107.         stos    dword [edi]
  3108.         call    store_section_index
  3109.         jmp     section_symbol_ok
  3110.       store_section_index:
  3111.         inc     ecx
  3112.         mov     eax,ecx
  3113.         shl     eax,8
  3114.         mov     [ebx],eax
  3115.         inc     dx
  3116.         jz      format_limitations_exceeded
  3117.         mov     eax,edx
  3118.         shl     eax,16
  3119.         mov     al,3
  3120.         test    byte [ebx+14h],40h
  3121.         jz      section_index_ok
  3122.         or      ah,-1
  3123.         inc     dx
  3124.         jz      format_limitations_exceeded
  3125.       section_index_ok:
  3126.         stos    dword [edi]
  3127.         ret
  3128.       elf64_section_symbol:
  3129.         call    store_section_index
  3130.         xor     eax,eax
  3131.         stos    dword [edi]
  3132.         stos    dword [edi]
  3133.         stos    dword [edi]
  3134.         stos    dword [edi]
  3135.       section_symbol_ok:
  3136.         mov     ebx,esi
  3137.         add     esi,20h
  3138.         cmp     ebx,[free_additional_memory]
  3139.         jne     find_next_section
  3140.         inc     dx
  3141.         jz      format_limitations_exceeded
  3142.         mov     [current_section],edx
  3143.         mov     esi,[symbols_stream]
  3144.       find_other_symbols:
  3145.         cmp     esi,[free_additional_memory]
  3146.         je      elf_symbol_table_ok
  3147.         mov     al,[esi]
  3148.         or      al,al
  3149.         jz      skip_section
  3150.         cmp     al,0C0h
  3151.         jae     make_public_symbol
  3152.         cmp     al,80h
  3153.         jae     make_extrn_symbol
  3154.         add     esi,0Ch
  3155.         jmp     find_other_symbols
  3156.       skip_section:
  3157.         add     esi,20h
  3158.         jmp     find_other_symbols
  3159.       make_public_symbol:
  3160.         mov     eax,[esi+0Ch]
  3161.         mov     [current_line],eax
  3162.         cmp     byte [esi],0C0h
  3163.         jne     invalid_argument
  3164.         mov     ebx,[esi+8]
  3165.         test    byte [ebx+8],1
  3166.         jz      undefined_public
  3167.         mov     ax,[current_pass]
  3168.         cmp     ax,[ebx+16]
  3169.         jne     undefined_public
  3170.         mov     dl,[ebx+11]
  3171.         or      dl,dl
  3172.         jz      public_absolute
  3173.         mov     eax,[ebx+20]
  3174.         cmp     byte [eax],0
  3175.         jne     invalid_use_of_symbol
  3176.         mov     eax,[eax+4]
  3177.         test    [format_flags],8
  3178.         jnz     elf64_public
  3179.         cmp     dl,2
  3180.         jne     invalid_use_of_symbol
  3181.         mov     dx,[eax+0Eh]
  3182.         jmp     section_for_public_ok
  3183.       undefined_public:
  3184.         mov     eax,[ebx+24]
  3185.         mov     [error_info],eax
  3186.         jmp     undefined_symbol
  3187.       elf64_public:
  3188.         cmp     dl,4
  3189.         jne     invalid_use_of_symbol
  3190.         mov     dx,[eax+6]
  3191.         jmp     section_for_public_ok
  3192.       public_absolute:
  3193.         mov     dx,0FFF1h
  3194.       section_for_public_ok:
  3195.         mov     eax,[esi+4]
  3196.         stos    dword [edi]
  3197.         test    [format_flags],8
  3198.         jnz     elf64_public_symbol
  3199.         call    get_public_value
  3200.         stos    dword [edi]
  3201.         xor     eax,eax
  3202.         mov     al,[ebx+10]
  3203.         stos    dword [edi]
  3204.         mov     eax,edx
  3205.         shl     eax,16
  3206.         mov     al,10h
  3207.         cmp     byte [ebx+10],0
  3208.         je      elf_public_function
  3209.         or      al,1
  3210.         jmp     store_elf_public_info
  3211.       elf_public_function:
  3212.         or      al,2
  3213.       store_elf_public_info:
  3214.         stos    dword [edi]
  3215.         jmp     public_symbol_ok
  3216.       elf64_public_symbol:
  3217.         mov     eax,edx
  3218.         shl     eax,16
  3219.         mov     al,10h
  3220.         cmp     byte [ebx+10],0
  3221.         je      elf64_public_function
  3222.         or      al,1
  3223.         jmp     store_elf64_public_info
  3224.       elf64_public_function:
  3225.         or      al,2
  3226.       store_elf64_public_info:
  3227.         stos    dword [edi]
  3228.         call    get_public_value
  3229.         stos    dword [edi]
  3230.         xor     eax,eax
  3231.         stos    dword [edi]
  3232.         mov     al,[ebx+10]
  3233.         stos    dword [edi]
  3234.         xor     al,al
  3235.         stos    dword [edi]
  3236.       public_symbol_ok:
  3237.         inc     ecx
  3238.         mov     eax,ecx
  3239.         shl     eax,8
  3240.         mov     al,0C0h
  3241.         mov     [esi],eax
  3242.         add     esi,10h
  3243.         jmp     find_other_symbols
  3244.       get_public_value:
  3245.         mov     eax,[ebx]
  3246.         cmp     dword [ebx+4],0
  3247.         je      public_value_ok
  3248.         cmp     dword [ebx+4],-1
  3249.         jne     value_out_of_range
  3250.         bt      eax,31
  3251.         jnc     value_out_of_range
  3252.       public_value_ok:
  3253.         ret
  3254.       make_extrn_symbol:
  3255.         mov     eax,[esi+4]
  3256.         stos    dword [edi]
  3257.         test    [format_flags],8
  3258.         jnz     elf64_extrn_symbol
  3259.         xor     eax,eax
  3260.         stos    dword [edi]
  3261.         mov     eax,[esi+8]
  3262.         stos    dword [edi]
  3263.         mov     eax,10h
  3264.         stos    dword [edi]
  3265.         jmp     extrn_symbol_ok
  3266.       elf64_extrn_symbol:
  3267.         mov     eax,10h
  3268.         stos    dword [edi]
  3269.         xor     al,al
  3270.         stos    dword [edi]
  3271.         stos    dword [edi]
  3272.         mov     eax,[esi+8]
  3273.         stos    dword [edi]
  3274.         xor     eax,eax
  3275.         stos    dword [edi]
  3276.       extrn_symbol_ok:
  3277.         inc     ecx
  3278.         mov     eax,ecx
  3279.         shl     eax,8
  3280.         mov     al,80h
  3281.         mov     [esi],eax
  3282.         add     esi,0Ch
  3283.         jmp     find_other_symbols
  3284.       elf_symbol_table_ok:
  3285.         mov     edx,edi
  3286.         mov     ebx,[free_additional_memory]
  3287.         xor     al,al
  3288.         stos    byte [edi]
  3289.         add     edi,16
  3290.         mov     [edx+1],edx
  3291.         add     ebx,10h
  3292.         test    [format_flags],8
  3293.         jz      make_string_table
  3294.         add     ebx,8
  3295.       make_string_table:
  3296.         cmp     ebx,edx
  3297.         je      elf_string_table_ok
  3298.         test    [format_flags],8
  3299.         jnz     make_elf64_string
  3300.         cmp     byte [ebx+0Dh],0
  3301.         je      rel_prefix_ok
  3302.         mov     byte [ebx+0Dh],0
  3303.         mov     eax,'.rel'
  3304.         stos    dword [edi]
  3305.       rel_prefix_ok:
  3306.         mov     esi,edi
  3307.         sub     esi,edx
  3308.         xchg    esi,[ebx]
  3309.         add     ebx,10h
  3310.       make_elf_string:
  3311.         or      esi,esi
  3312.         jz      default_string
  3313.         lods    dword [esi]
  3314.         mov     ecx,eax
  3315.         rep     movs byte [edi],[esi]
  3316.         xor     al,al
  3317.         stos    byte [edi]
  3318.         jmp     make_string_table
  3319.       make_elf64_string:
  3320.         cmp     byte [ebx+5],0
  3321.         je      elf64_rel_prefix_ok
  3322.         mov     byte [ebx+5],0
  3323.         mov     eax,'.rel'
  3324.         stos    dword [edi]
  3325.         mov     al,'a'
  3326.         stos    byte [edi]
  3327.       elf64_rel_prefix_ok:
  3328.         mov     esi,edi
  3329.         sub     esi,edx
  3330.         xchg    esi,[ebx]
  3331.         add     ebx,18h
  3332.         jmp     make_elf_string
  3333.       default_string:
  3334.         mov     eax,'.fla'
  3335.         stos    dword [edi]
  3336.         mov     ax,'t'
  3337.         stos    word [edi]
  3338.         jmp     make_string_table
  3339.       elf_string_table_ok:
  3340.         mov     [edx+1+8],edi
  3341.         mov     ebx,[code_start]
  3342.         mov     eax,edi
  3343.         sub     eax,[free_additional_memory]
  3344.         test    [format_flags],8
  3345.         jnz     finish_elf64_header
  3346.         mov     [ebx+20h],eax
  3347.         mov     eax,[current_section]
  3348.         inc     ax
  3349.         jz      format_limitations_exceeded
  3350.         mov     [ebx+32h],ax
  3351.         inc     ax
  3352.         jz      format_limitations_exceeded
  3353.         mov     [ebx+30h],ax
  3354.         jmp     elf_header_finished
  3355.       finish_elf64_header:
  3356.         mov     [ebx+28h],eax
  3357.         mov     eax,[current_section]
  3358.         inc     ax
  3359.         jz      format_limitations_exceeded
  3360.         mov     [ebx+3Eh],ax
  3361.         inc     ax
  3362.         jz      format_limitations_exceeded
  3363.         mov     [ebx+3Ch],ax
  3364.       elf_header_finished:
  3365.         xor     eax,eax
  3366.         mov     ecx,10
  3367.         rep     stos dword [edi]
  3368.         test    [format_flags],8
  3369.         jz      elf_null_section_ok
  3370.         mov     ecx,6
  3371.         rep     stos dword [edi]
  3372.       elf_null_section_ok:
  3373.         mov     esi,ebp
  3374.         xor     ecx,ecx
  3375.       make_section_entry:
  3376.         mov     ebx,edi
  3377.         mov     eax,[esi+4]
  3378.         mov     eax,[eax]
  3379.         stos    dword [edi]
  3380.         mov     eax,1
  3381.         cmp     dword [esi+0Ch],0
  3382.         je      bss_section
  3383.         test    byte [esi+14h],80h
  3384.         jz      section_type_ok
  3385.       bss_section:
  3386.         mov     al,8
  3387.       section_type_ok:
  3388.         stos    dword [edi]
  3389.         mov     eax,[esi+14h]
  3390.         and     al,3Fh
  3391.         call    store_elf_machine_word
  3392.         xor     eax,eax
  3393.         call    store_elf_machine_word
  3394.         mov     eax,[esi+8]
  3395.         mov     [image_base],eax
  3396.         sub     eax,[code_start]
  3397.         call    store_elf_machine_word
  3398.         mov     eax,[esi+0Ch]
  3399.         call    store_elf_machine_word
  3400.         xor     eax,eax
  3401.         stos    dword [edi]
  3402.         stos    dword [edi]
  3403.         mov     eax,[esi+10h]
  3404.         call    store_elf_machine_word
  3405.         xor     eax,eax
  3406.         call    store_elf_machine_word
  3407.         inc     ecx
  3408.         add     esi,20h
  3409.         xchg    edi,[esp]
  3410.         mov     ebp,edi
  3411.       convert_relocations:
  3412.         cmp     esi,[free_additional_memory]
  3413.         je      relocations_converted
  3414.         mov     al,[esi]
  3415.         or      al,al
  3416.         jz      relocations_converted
  3417.         cmp     al,80h
  3418.         jb      make_relocation_entry
  3419.         cmp     al,0C0h
  3420.         jb      relocation_entry_ok
  3421.         add     esi,10h
  3422.         jmp     convert_relocations
  3423.       make_relocation_entry:
  3424.         test    [format_flags],8
  3425.         jnz     make_elf64_relocation_entry
  3426.         mov     eax,[esi+4]
  3427.         stos    dword [edi]
  3428.         mov     eax,[esi+8]
  3429.         mov     eax,[eax]
  3430.         mov     al,[esi]
  3431.         stos    dword [edi]
  3432.         jmp     relocation_entry_ok
  3433.       make_elf64_relocation_entry:
  3434.         mov     eax,[esi+4]
  3435.         stos    dword [edi]
  3436.         xor     eax,eax
  3437.         stos    dword [edi]
  3438.         movzx   eax,byte [esi]
  3439.         stos    dword [edi]
  3440.         mov     eax,[esi+8]
  3441.         mov     eax,[eax]
  3442.         shr     eax,8
  3443.         stos    dword [edi]
  3444.         xor     eax,eax
  3445.         stos    dword [edi]
  3446.         stos    dword [edi]
  3447.       relocation_entry_ok:
  3448.         add     esi,0Ch
  3449.         jmp     convert_relocations
  3450.       store_elf_machine_word:
  3451.         stos    dword [edi]
  3452.         test    [format_flags],8
  3453.         jz      elf_machine_word_ok
  3454.         mov     dword [edi],0
  3455.         add     edi,4
  3456.       elf_machine_word_ok:
  3457.         ret
  3458.       relocations_converted:
  3459.         cmp     edi,ebp
  3460.         xchg    edi,[esp]
  3461.         je      rel_section_ok
  3462.         mov     eax,[ebx]
  3463.         sub     eax,4
  3464.         test    [format_flags],8
  3465.         jz      store_relocations_name_offset
  3466.         dec     eax
  3467.       store_relocations_name_offset:
  3468.         stos    dword [edi]
  3469.         test    [format_flags],8
  3470.         jnz     rela_section
  3471.         mov     eax,9
  3472.         jmp     store_relocations_type
  3473.       rela_section:
  3474.         mov     eax,4
  3475.       store_relocations_type:
  3476.         stos    dword [edi]
  3477.         xor     al,al
  3478.         call    store_elf_machine_word
  3479.         call    store_elf_machine_word
  3480.         mov     eax,ebp
  3481.         sub     eax,[code_start]
  3482.         call    store_elf_machine_word
  3483.         mov     eax,[esp]
  3484.         sub     eax,ebp
  3485.         call    store_elf_machine_word
  3486.         mov     eax,[current_section]
  3487.         stos    dword [edi]
  3488.         mov     eax,ecx
  3489.         stos    dword [edi]
  3490.         inc     ecx
  3491.         test    [format_flags],8
  3492.         jnz     finish_elf64_rela_section
  3493.         mov     eax,4
  3494.         stos    dword [edi]
  3495.         mov     al,8
  3496.         stos    dword [edi]
  3497.         jmp     rel_section_ok
  3498.       finish_elf64_rela_section:
  3499.         mov     eax,8
  3500.         stos    dword [edi]
  3501.         xor     al,al
  3502.         stos    dword [edi]
  3503.         mov     al,24
  3504.         stos    dword [edi]
  3505.         xor     al,al
  3506.         stos    dword [edi]
  3507.       rel_section_ok:
  3508.         cmp     esi,[free_additional_memory]
  3509.         jne     make_section_entry
  3510.         pop     eax
  3511.         mov     ebx,[code_start]
  3512.         sub     eax,ebx
  3513.         mov     [code_size],eax
  3514.         mov     ecx,20h
  3515.         test    [format_flags],8
  3516.         jz      adjust_elf_section_headers_offset
  3517.         mov     ecx,28h
  3518.       adjust_elf_section_headers_offset:
  3519.         add     [ebx+ecx],eax
  3520.         mov     eax,1
  3521.         stos    dword [edi]
  3522.         mov     al,2
  3523.         stos    dword [edi]
  3524.         xor     al,al
  3525.         call    store_elf_machine_word
  3526.         call    store_elf_machine_word
  3527.         mov     eax,[code_size]
  3528.         call    store_elf_machine_word
  3529.         mov     eax,[edx+1]
  3530.         sub     eax,[free_additional_memory]
  3531.         call    store_elf_machine_word
  3532.         mov     eax,[current_section]
  3533.         inc     eax
  3534.         stos    dword [edi]
  3535.         mov     eax,[number_of_sections]
  3536.         inc     eax
  3537.         stos    dword [edi]
  3538.         test    [format_flags],8
  3539.         jnz     finish_elf64_sym_section
  3540.         mov     eax,4
  3541.         stos    dword [edi]
  3542.         mov     al,10h
  3543.         stos    dword [edi]
  3544.         jmp     sym_section_ok
  3545.       finish_elf64_sym_section:
  3546.         mov     eax,8
  3547.         stos    dword [edi]
  3548.         xor     al,al
  3549.         stos    dword [edi]
  3550.         mov     al,18h
  3551.         stos    dword [edi]
  3552.         xor     al,al
  3553.         stos    dword [edi]
  3554.       sym_section_ok:
  3555.         mov     al,1+8
  3556.         stos    dword [edi]
  3557.         mov     al,3
  3558.         stos    dword [edi]
  3559.         xor     al,al
  3560.         call    store_elf_machine_word
  3561.         call    store_elf_machine_word
  3562.         mov     eax,[edx+1]
  3563.         sub     eax,[free_additional_memory]
  3564.         add     eax,[code_size]
  3565.         call    store_elf_machine_word
  3566.         mov     eax,[edx+1+8]
  3567.         sub     eax,[edx+1]
  3568.         call    store_elf_machine_word
  3569.         xor     eax,eax
  3570.         stos    dword [edi]
  3571.         stos    dword [edi]
  3572.         mov     al,1
  3573.         call    store_elf_machine_word
  3574.         xor     eax,eax
  3575.         call    store_elf_machine_word
  3576.         mov     eax,'tab'
  3577.         mov     dword [edx+1],'.sym'
  3578.         mov     [edx+1+4],eax
  3579.         mov     dword [edx+1+8],'.str'
  3580.         mov     [edx+1+8+4],eax
  3581.         mov     [resource_data],edx
  3582.         mov     [written_size],0
  3583.         mov     edx,[output_file]
  3584.         call    create
  3585.         jc      write_failed
  3586.         call    write_code
  3587.         mov     ecx,edi
  3588.         mov     edx,[free_additional_memory]
  3589.         sub     ecx,edx
  3590.         add     [written_size],ecx
  3591.         call    write
  3592.         jc      write_failed
  3593.         jmp     output_written
  3594.  
  3595. format_elf_exe:
  3596.         add     esi,2
  3597.         or      [format_flags],1
  3598.         mov     [image_base],8048000h
  3599.         cmp     byte [esi],80h
  3600.         jne     elf_exe_base_ok
  3601.         lods    word [esi]
  3602.         cmp     ah,'('
  3603.         jne     invalid_argument
  3604.         cmp     byte [esi],'.'
  3605.         je      invalid_value
  3606.         push    edx
  3607.         call    get_dword_value
  3608.         cmp     [value_type],0
  3609.         jne     invalid_use_of_symbol
  3610.         mov     [image_base],eax
  3611.         pop     edx
  3612.       elf_exe_base_ok:
  3613.         mov     byte [edx+10h],2
  3614.         mov     byte [edx+2Ah],20h
  3615.         mov     ebx,edi
  3616.         mov     ecx,20h shr 2
  3617.         cmp     [current_pass],0
  3618.         je      init_elf_segments
  3619.         imul    ecx,[number_of_sections]
  3620.       init_elf_segments:
  3621.         xor     eax,eax
  3622.         rep     stos dword [edi]
  3623.         mov     [number_of_sections],0
  3624.         mov     byte [ebx],1
  3625.         mov     word [ebx+1Ch],1000h
  3626.         mov     byte [ebx+18h],111b
  3627.         mov     eax,edi
  3628.         sub     eax,[code_start]
  3629.         mov     [ebx+4],eax
  3630.         add     eax,[image_base]
  3631.         mov     [ebx+8],eax
  3632.         mov     [ebx+0Ch],eax
  3633.         mov     [edx+18h],eax
  3634.         xor     edx,edx
  3635.         not     eax
  3636.         not     edx
  3637.         add     eax,1
  3638.         adc     edx,0
  3639.         add     eax,edi
  3640.         adc     edx,0
  3641.         mov     dword [org_origin],eax
  3642.         mov     dword [org_origin+4],edx
  3643.         mov     [org_registers],0
  3644.         mov     [org_start],edi
  3645.         mov     [symbols_stream],edi
  3646.         jmp     format_defined
  3647.       format_elf64_exe:
  3648.         add     esi,2
  3649.         or      [format_flags],1
  3650.         mov     [image_base],400000h
  3651.         mov     [image_base_high],0
  3652.         cmp     byte [esi],80h
  3653.         jne     elf64_exe_base_ok
  3654.         lods    word [esi]
  3655.         cmp     ah,'('
  3656.         jne     invalid_argument
  3657.         cmp     byte [esi],'.'
  3658.         je      invalid_value
  3659.         push    edx
  3660.         call    get_qword_value
  3661.         cmp     [value_type],0
  3662.         jne     invalid_use_of_symbol
  3663.         mov     [image_base],eax
  3664.         mov     [image_base_high],edx
  3665.         pop     edx
  3666.       elf64_exe_base_ok:
  3667.         mov     byte [edx+10h],2
  3668.         mov     byte [edx+36h],38h
  3669.         mov     ebx,edi
  3670.         mov     ecx,38h shr 2
  3671.         cmp     [current_pass],0
  3672.         je      init_elf64_segments
  3673.         imul    ecx,[number_of_sections]
  3674.       init_elf64_segments:
  3675.         xor     eax,eax
  3676.         rep     stos dword [edi]
  3677.         mov     [number_of_sections],0
  3678.         mov     byte [ebx],1
  3679.         mov     word [ebx+30h],1000h
  3680.         mov     byte [ebx+4],111b
  3681.         push    edx
  3682.         mov     eax,edi
  3683.         sub     eax,[code_start]
  3684.         mov     [ebx+8],eax
  3685.         xor     edx,edx
  3686.         add     eax,[image_base]
  3687.         adc     edx,[image_base_high]
  3688.         mov     [ebx+10h],eax
  3689.         mov     [ebx+10h+4],edx
  3690.         mov     [ebx+18h],eax
  3691.         mov     [ebx+18h+4],edx
  3692.         pop     ebx
  3693.         mov     [ebx+18h],eax
  3694.         mov     [ebx+18h+4],edx
  3695.         not     eax
  3696.         not     edx
  3697.         add     eax,1
  3698.         adc     edx,0
  3699.         add     eax,edi
  3700.         adc     edx,0
  3701.         mov     dword [org_origin],eax
  3702.         mov     dword [org_origin+4],edx
  3703.         mov     [org_registers],0
  3704.         mov     [org_start],edi
  3705.         mov     [symbols_stream],edi
  3706.         jmp     format_defined
  3707. elf_entry:
  3708.         lods    byte [esi]
  3709.         cmp     al,'('
  3710.         jne     invalid_argument
  3711.         cmp     byte [esi],'.'
  3712.         je      invalid_value
  3713.         test    [format_flags],8
  3714.         jnz     elf64_entry
  3715.         call    get_dword_value
  3716.         cmp     [value_type],0
  3717.         jne     invalid_use_of_symbol
  3718.         mov     edx,[code_start]
  3719.         mov     [edx+18h],eax
  3720.         jmp     instruction_assembled
  3721.       elf64_entry:
  3722.         call    get_qword_value
  3723.         cmp     [value_type],0
  3724.         jne     invalid_use_of_symbol
  3725.         mov     ebx,[code_start]
  3726.         mov     [ebx+18h],eax
  3727.         mov     [ebx+1Ch],edx
  3728.         jmp     instruction_assembled
  3729. elf_segment:
  3730.         bt      [format_flags],0
  3731.         jnc     illegal_instruction
  3732.         test    [format_flags],8
  3733.         jnz     elf64_segment
  3734.         call    close_elf_segment
  3735.         push    eax
  3736.         mov     ebx,[number_of_sections]
  3737.         shl     ebx,5
  3738.         add     ebx,[code_start]
  3739.         add     ebx,34h
  3740.         cmp     ebx,[symbols_stream]
  3741.         jb      new_elf_segment
  3742.         mov     ebx,[symbols_stream]
  3743.         sub     ebx,20h
  3744.         push    edi
  3745.         mov     edi,ebx
  3746.         mov     ecx,20h shr 2
  3747.         xor     eax,eax
  3748.         rep     stos dword [edi]
  3749.         pop     edi
  3750.         or      [next_pass_needed],-1
  3751.       new_elf_segment:
  3752.         mov     byte [ebx],1
  3753.         mov     word [ebx+1Ch],1000h
  3754.       elf_segment_flags:
  3755.         cmp     byte [esi],19h
  3756.         jne     elf_segment_flags_ok
  3757.         lods    word [esi]
  3758.         sub     ah,28
  3759.         jbe     invalid_argument
  3760.         cmp     ah,1
  3761.         je      mark_elf_segment_flag
  3762.         cmp     ah,3
  3763.         ja      invalid_argument
  3764.         xor     ah,1
  3765.         cmp     ah,2
  3766.         je      mark_elf_segment_flag
  3767.         inc     ah
  3768.       mark_elf_segment_flag:
  3769.         test    [ebx+18h],ah
  3770.         jnz     setting_already_specified
  3771.         or      [ebx+18h],ah
  3772.         jmp     elf_segment_flags
  3773.       elf_segment_flags_ok:
  3774.         mov     eax,edi
  3775.         sub     eax,[code_start]
  3776.         mov     [ebx+4],eax
  3777.         pop     edx
  3778.         and     eax,0FFFh
  3779.         add     edx,eax
  3780.         mov     [ebx+8],edx
  3781.         mov     [ebx+0Ch],edx
  3782.         mov     eax,edx
  3783.         xor     edx,edx
  3784.         not     eax
  3785.         not     edx
  3786.         add     eax,1
  3787.         adc     edx,0
  3788.         add     eax,edi
  3789.         adc     edx,0
  3790.         mov     dword [org_origin],eax
  3791.         mov     dword [org_origin+4],edx
  3792.         mov     [org_registers],0
  3793.         mov     [org_start],edi
  3794.         inc     [number_of_sections]
  3795.         jmp     instruction_assembled
  3796.       close_elf_segment:
  3797.         cmp     [number_of_sections],0
  3798.         jne     finish_elf_segment
  3799.         cmp     edi,[symbols_stream]
  3800.         jne     first_elf_segment_ok
  3801.         push    edi
  3802.         mov     edi,[code_start]
  3803.         add     edi,34h
  3804.         mov     ecx,20h shr 2
  3805.         xor     eax,eax
  3806.         rep     stos dword [edi]
  3807.         pop     edi
  3808.         mov     eax,[image_base]
  3809.         ret
  3810.       first_elf_segment_ok:
  3811.         inc     [number_of_sections]
  3812.       finish_elf_segment:
  3813.         mov     ebx,[number_of_sections]
  3814.         dec     ebx
  3815.         shl     ebx,5
  3816.         add     ebx,[code_start]
  3817.         add     ebx,34h
  3818.         mov     eax,edi
  3819.         sub     eax,[code_start]
  3820.         sub     eax,[ebx+4]
  3821.         mov     edx,edi
  3822.         cmp     edi,[undefined_data_end]
  3823.         jne     elf_segment_size_ok
  3824.         mov     edi,[undefined_data_start]
  3825.       elf_segment_size_ok:
  3826.         mov     [ebx+14h],eax
  3827.         add     eax,edi
  3828.         sub     eax,edx
  3829.         mov     [ebx+10h],eax
  3830.         mov     eax,[ebx+8]
  3831.         add     eax,[ebx+14h]
  3832.         add     eax,0FFFh
  3833.         and     eax,not 0FFFh
  3834.         ret
  3835.       elf64_segment:
  3836.         call    close_elf64_segment
  3837.         push    eax edx
  3838.         mov     ebx,[number_of_sections]
  3839.         imul    ebx,38h
  3840.         add     ebx,[code_start]
  3841.         add     ebx,40h
  3842.         cmp     ebx,[symbols_stream]
  3843.         jb      new_elf64_segment
  3844.         mov     ebx,[symbols_stream]
  3845.         sub     ebx,38h
  3846.         push    edi
  3847.         mov     edi,ebx
  3848.         mov     ecx,38h shr 2
  3849.         xor     eax,eax
  3850.         rep     stos dword [edi]
  3851.         pop     edi
  3852.         or      [next_pass_needed],-1
  3853.       new_elf64_segment:
  3854.         mov     byte [ebx],1
  3855.         mov     word [ebx+30h],1000h
  3856.       elf64_segment_flags:
  3857.         cmp     byte [esi],19h
  3858.         jne     elf64_segment_flags_ok
  3859.         lods    word [esi]
  3860.         sub     ah,28
  3861.         jbe     invalid_argument
  3862.         cmp     ah,1
  3863.         je      mark_elf64_segment_flag
  3864.         cmp     ah,3
  3865.         ja      invalid_argument
  3866.         xor     ah,1
  3867.         cmp     ah,2
  3868.         je      mark_elf64_segment_flag
  3869.         inc     ah
  3870.       mark_elf64_segment_flag:
  3871.         test    [ebx+4],ah
  3872.         jnz     setting_already_specified
  3873.         or      [ebx+4],ah
  3874.         jmp     elf64_segment_flags
  3875.       elf64_segment_flags_ok:
  3876.         mov     ecx,edi
  3877.         sub     ecx,[code_start]
  3878.         mov     [ebx+8],ecx
  3879.         pop     edx eax
  3880.         and     ecx,0FFFh
  3881.         add     eax,ecx
  3882.         adc     edx,0
  3883.         mov     [ebx+10h],eax
  3884.         mov     [ebx+10h+4],edx
  3885.         mov     [ebx+18h],eax
  3886.         mov     [ebx+18h+4],edx
  3887.         not     eax
  3888.         not     edx
  3889.         add     eax,1
  3890.         adc     edx,0
  3891.         add     eax,edi
  3892.         adc     edx,0
  3893.         mov     dword [org_origin],eax
  3894.         mov     dword [org_origin+4],edx
  3895.         mov     [org_registers],0
  3896.         mov     [org_start],edi
  3897.         inc     [number_of_sections]
  3898.         jmp     instruction_assembled
  3899.       close_elf64_segment:
  3900.         cmp     [number_of_sections],0
  3901.         jne     finish_elf64_segment
  3902.         cmp     edi,[symbols_stream]
  3903.         jne     first_elf64_segment_ok
  3904.         push    edi
  3905.         mov     edi,[code_start]
  3906.         add     edi,40h
  3907.         mov     ecx,38h shr 2
  3908.         xor     eax,eax
  3909.         rep     stos dword [edi]
  3910.         pop     edi
  3911.         mov     eax,[image_base]
  3912.         mov     edx,[image_base_high]
  3913.         ret
  3914.       first_elf64_segment_ok:
  3915.         inc     [number_of_sections]
  3916.       finish_elf64_segment:
  3917.         mov     ebx,[number_of_sections]
  3918.         dec     ebx
  3919.         imul    ebx,38h
  3920.         add     ebx,[code_start]
  3921.         add     ebx,40h
  3922.         mov     eax,edi
  3923.         sub     eax,[code_start]
  3924.         sub     eax,[ebx+8]
  3925.         mov     edx,edi
  3926.         cmp     edi,[undefined_data_end]
  3927.         jne     elf64_segment_size_ok
  3928.         mov     edi,[undefined_data_start]
  3929.       elf64_segment_size_ok:
  3930.         mov     [ebx+28h],eax
  3931.         add     eax,edi
  3932.         sub     eax,edx
  3933.         mov     [ebx+20h],eax
  3934.         mov     eax,[ebx+10h]
  3935.         mov     edx,[ebx+10h+4]
  3936.         add     eax,[ebx+28h]
  3937.         adc     edx,0
  3938.         sub     eax,1
  3939.         sbb     edx,0
  3940.         shrd    eax,edx,12
  3941.         shr     edx,12
  3942.         add     eax,1
  3943.         adc     edx,0
  3944.         shld    edx,eax,12
  3945.         shl     eax,12
  3946.         ret
  3947. close_elf_exe:
  3948.         test    [format_flags],8
  3949.         jnz     close_elf64_exe
  3950.         call    close_elf_segment
  3951.         mov     edx,[code_start]
  3952.         mov     eax,[number_of_sections]
  3953.         mov     byte [edx+1Ch],34h
  3954.         mov     [edx+2Ch],ax
  3955.         shl     eax,5
  3956.         add     eax,edx
  3957.         add     eax,34h
  3958.         cmp     eax,[symbols_stream]
  3959.         je      elf_exe_ok
  3960.         or      [next_pass_needed],-1
  3961.       elf_exe_ok:
  3962.         ret
  3963.       close_elf64_exe:
  3964.         call    close_elf64_segment
  3965.         mov     edx,[code_start]
  3966.         mov     eax,[number_of_sections]
  3967.         mov     byte [edx+20h],40h
  3968.         mov     [edx+38h],ax
  3969.         imul    eax,38h
  3970.         add     eax,edx
  3971.         add     eax,40h
  3972.         cmp     eax,[symbols_stream]
  3973.         je      elf64_exe_ok
  3974.         or      [next_pass_needed],-1
  3975.       elf64_exe_ok:
  3976.         ret
  3977.  
  3978. dump_symbols:
  3979.         mov     ebx,[code_start]
  3980.         mov     dword [ebx],'fas'+27 shl 24
  3981.         mov     dword [ebx+4],VERSION_MAJOR + VERSION_MINOR shl 8 + 38h shl 16
  3982.         add     ebx,38h
  3983.         mov     edi,ebx
  3984.         mov     dword [ebx-38h+10h],38h
  3985.         mov     dword [ebx-38h+8],0
  3986.         mov     esi,[input_file]
  3987.         call    copy_asciiz
  3988.         cmp     edi,[display_buffer]
  3989.         jae     out_of_memory
  3990.         mov     eax,edi
  3991.         sub     eax,ebx
  3992.         mov     [ebx-38h+0Ch],eax
  3993.         mov     esi,[output_file]
  3994.         call    copy_asciiz
  3995.         cmp     edi,[display_buffer]
  3996.         jae     out_of_memory
  3997.         mov     edx,[symbols_stream]
  3998.         mov     ebp,[free_additional_memory]
  3999.         mov     [number_of_sections],0
  4000.         cmp     [output_format],4
  4001.         je      prepare_strings_table
  4002.         cmp     [output_format],5
  4003.         jne     strings_table_ready
  4004.         bt      [format_flags],0
  4005.         jc      strings_table_ready
  4006.       prepare_strings_table:
  4007.         cmp     edx,ebp
  4008.         je      strings_table_ready
  4009.         mov     al,[edx]
  4010.         test    al,al
  4011.         jz      prepare_string
  4012.         cmp     al,80h
  4013.         je      prepare_string
  4014.         add     edx,0Ch
  4015.         cmp     al,0C0h
  4016.         jne     prepare_strings_table
  4017.         add     edx,4
  4018.         jmp     prepare_strings_table
  4019.       prepare_string:
  4020.         mov     esi,edi
  4021.         sub     esi,ebx
  4022.         xchg    esi,[edx+4]
  4023.         test    al,al
  4024.         jz      prepare_section_string
  4025.         or      dword [edx+4],1 shl 31
  4026.         add     edx,0Ch
  4027.       prepare_external_string:
  4028.         mov     ecx,[esi]
  4029.         add     esi,4
  4030.         rep     movs byte [edi],[esi]
  4031.         mov     byte [edi],0
  4032.         inc     edi
  4033.         cmp     edi,[display_buffer]
  4034.         jae     out_of_memory
  4035.         jmp     prepare_strings_table
  4036.       prepare_section_string:
  4037.         mov     ecx,[number_of_sections]
  4038.         mov     eax,ecx
  4039.         inc     eax
  4040.         mov     [number_of_sections],eax
  4041.         xchg    eax,[edx+4]
  4042.         shl     ecx,2
  4043.         add     ecx,[free_additional_memory]
  4044.         mov     [ecx],eax
  4045.         add     edx,20h
  4046.         test    esi,esi
  4047.         jz      prepare_default_section_string
  4048.         cmp     [output_format],5
  4049.         jne     prepare_external_string
  4050.         bt      [format_flags],0
  4051.         jc      prepare_external_string
  4052.         mov     esi,[esi]
  4053.         add     esi,[resource_data]
  4054.       copy_elf_section_name:
  4055.         lods    byte [esi]
  4056.         cmp     edi,[display_buffer]
  4057.         jae     out_of_memory
  4058.         stos    byte [edi]
  4059.         test    al,al
  4060.         jnz     copy_elf_section_name
  4061.         jmp     prepare_strings_table
  4062.       prepare_default_section_string:
  4063.         mov     eax,'.fla'
  4064.         stos    dword [edi]
  4065.         mov     ax,'t'
  4066.         stos    word [edi]
  4067.         cmp     edi,[display_buffer]
  4068.         jae     out_of_memory
  4069.         jmp     prepare_strings_table
  4070.       strings_table_ready:
  4071.         mov     edx,[display_buffer]
  4072.         mov     ebp,[memory_end]
  4073.         sub     ebp,[labels_list]
  4074.         add     ebp,edx
  4075.       prepare_labels_dump:
  4076.         cmp     edx,ebp
  4077.         je      labels_dump_ok
  4078.         mov     eax,[edx+24]
  4079.         test    eax,eax
  4080.         jz      label_dump_name_ok
  4081.         cmp     eax,[memory_start]
  4082.         jb      label_name_outside_source
  4083.         cmp     eax,[source_start]
  4084.         ja      label_name_outside_source
  4085.         sub     eax,[memory_start]
  4086.         dec     eax
  4087.         mov     [edx+24],eax
  4088.         jmp     label_dump_name_ok
  4089.       label_name_outside_source:
  4090.         mov     esi,eax
  4091.         mov     eax,edi
  4092.         sub     eax,ebx
  4093.         or      eax,1 shl 31
  4094.         mov     [edx+24],eax
  4095.         movzx   ecx,byte [esi-1]
  4096.         lea     eax,[edi+ecx+1]
  4097.         cmp     edi,[display_buffer]
  4098.         jae     out_of_memory
  4099.         rep     movsb
  4100.         xor     al,al
  4101.         stosb
  4102.       label_dump_name_ok:
  4103.         mov     eax,[edx+28]
  4104.         test    eax,eax
  4105.         jz      label_dump_line_ok
  4106.         sub     eax,[memory_start]
  4107.         mov     [edx+28],eax
  4108.       label_dump_line_ok:
  4109.         mov     eax,[edx+20]
  4110.         test    eax,eax
  4111.         jz      base_symbol_for_label_ok
  4112.         cmp     eax,[symbols_stream]
  4113.         mov     eax,[eax+4]
  4114.         jae     base_symbol_for_label_ok
  4115.         xor     eax,eax
  4116.       base_symbol_for_label_ok:
  4117.         mov     [edx+20],eax
  4118.         add     edx,LABEL_STRUCTURE_SIZE
  4119.         jmp     prepare_labels_dump
  4120.       labels_dump_ok:
  4121.         mov     eax,edi
  4122.         sub     eax,ebx
  4123.         mov     [ebx-38h+14h],eax
  4124.         add     eax,38h
  4125.         mov     [ebx-38h+18h],eax
  4126.         mov     ecx,[memory_end]
  4127.         sub     ecx,[labels_list]
  4128.         mov     [ebx-38h+1Ch],ecx
  4129.         add     eax,ecx
  4130.         mov     [ebx-38h+20h],eax
  4131.         mov     ecx,[source_start]
  4132.         sub     ecx,[memory_start]
  4133.         mov     [ebx-38h+24h],ecx
  4134.         add     eax,ecx
  4135.         mov     [ebx-38h+28h],eax
  4136.         mov     eax,[number_of_sections]
  4137.         shl     eax,2
  4138.         mov     [ebx-38h+34h],eax
  4139.         mov     esi,[memory_start]
  4140.       prepare_preprocessed_source:
  4141.         cmp     esi,[source_start]
  4142.         jae     preprocessed_source_ok
  4143.         mov     eax,[memory_start]
  4144.         mov     edx,[input_file]
  4145.         cmp     [esi],edx
  4146.         jne     line_not_from_main_input
  4147.         mov     [esi],eax
  4148.       line_not_from_main_input:
  4149.         sub     [esi],eax
  4150.         test    byte [esi+7],1 shl 7
  4151.         jz      prepare_next_preprocessed_line
  4152.         sub     [esi+8],eax
  4153.         sub     [esi+12],eax
  4154.       prepare_next_preprocessed_line:
  4155.         add     esi,16
  4156.         call    skip_foreign_line
  4157.         jmp     prepare_preprocessed_source
  4158.       preprocessed_source_ok:
  4159.         mov     esi,[labels_list]
  4160.         mov     ebp,edi
  4161.       make_lines_dump:
  4162.         cmp     esi,[display_buffer]
  4163.         je      lines_dump_ok
  4164.         mov     eax,[esi-4]
  4165.         mov     ecx,[esi-8]
  4166.         sub     esi,8
  4167.         sub     esi,ecx
  4168.         cmp     eax,1
  4169.         jne     make_lines_dump
  4170.         mov     eax,[esi+4]
  4171.         sub     eax,[code_start]
  4172.         add     eax,[headers_size]
  4173.         cmp     byte [esi+1Ah],0
  4174.         je      store_offset
  4175.         xor     eax,eax
  4176.       store_offset:
  4177.         stos    dword [edi]
  4178.         mov     eax,[esi]
  4179.         sub     eax,[memory_start]
  4180.         stos    dword [edi]
  4181.         mov     eax,[esi+4]
  4182.         xor     edx,edx
  4183.         sub     eax,[esi+8]
  4184.         sbb     edx,[esi+8+4]
  4185.         stos    dword [edi]
  4186.         mov     eax,edx
  4187.         stos    dword [edi]
  4188.         mov     eax,[esi+10h]
  4189.         stos    dword [edi]
  4190.         mov     eax,[esi+14h]
  4191.         test    eax,eax
  4192.         jz      base_symbol_for_line_ok
  4193.         cmp     eax,[symbols_stream]
  4194.         mov     eax,[eax+4]
  4195.         jae     base_symbol_for_line_ok
  4196.         xor     eax,eax
  4197.       base_symbol_for_line_ok:
  4198.         stos    dword [edi]
  4199.         mov     eax,[esi+18h]
  4200.         and     eax,001FFFFh
  4201.         stos    dword [edi]
  4202.         jmp     make_lines_dump
  4203.       lines_dump_ok:
  4204.         mov     edx,edi
  4205.         mov     eax,[current_offset]
  4206.         sub     eax,[code_start]
  4207.         add     eax,[headers_size]
  4208.         stos    dword [edi]
  4209.         mov     ecx,edi
  4210.         sub     ecx,ebx
  4211.         sub     ecx,[ebx-38h+14h]
  4212.         mov     [ebx-38h+2Ch],ecx
  4213.         add     ecx,[ebx-38h+28h]
  4214.         mov     [ebx-38h+30h],ecx
  4215.       find_inexisting_offsets:
  4216.         sub     edx,1Ch
  4217.         cmp     edx,ebp
  4218.         jb      write_symbols
  4219.         test    byte [edx+1Ah],1
  4220.         jnz     find_inexisting_offsets
  4221.         cmp     eax,[edx]
  4222.         jb      correct_inexisting_offset
  4223.         mov     eax,[edx]
  4224.         jmp     find_inexisting_offsets
  4225.       correct_inexisting_offset:
  4226.         mov     dword [edx],0
  4227.         or      byte [edx+1Ah],2
  4228.         jmp     find_inexisting_offsets
  4229.       write_symbols:
  4230.         mov     edx,[symbols_file]
  4231.         call    create
  4232.         jc      write_failed
  4233.         mov     edx,[code_start]
  4234.         mov     ecx,[edx+14h]
  4235.         add     ecx,38h
  4236.         call    write
  4237.         mov     edx,[display_buffer]
  4238.         mov     ecx,[memory_end]
  4239.         sub     ecx,[labels_list]
  4240.         call    write
  4241.         mov     edx,[memory_start]
  4242.         mov     ecx,[source_start]
  4243.         sub     ecx,edx
  4244.         call    write
  4245.         mov     edx,ebp
  4246.         mov     ecx,edi
  4247.         sub     ecx,edx
  4248.         call    write
  4249.         mov     edx,[free_additional_memory]
  4250.         mov     ecx,[number_of_sections]
  4251.         shl     ecx,2
  4252.         call    write
  4253.         call    close
  4254.         ret
  4255.