Subversion Repositories Kolibri OS

Rev

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