Subversion Repositories Kolibri OS

Rev

Rev 607 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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