³ò
‘u³Fc           @   sŒ  d  Z  d Z d Z y e Wn d  \ Z Z n Xyž d d k Z d d k Z d d k Z d d k Z d d k	 Z	 e i
 i e i
 i e	 i e i ƒ  ƒ d d d	 ƒ ƒ e e e i
 ƒ Z d d
 k l Z l Z Wn1 y e i i d e ƒ Wn e GHn X‚  n Xe i
 i e i d ƒ d Z e i
 i e ƒ d Z e i d ƒ i e ƒ i ƒ  Z d „  Z d „  Z d „  Z d d k Z d „  Z  d „  Z! d „  Z" d „  Z# d „  Z$ d „  Z% d „  Z& d „  Z' d „  Z( d „  Z) d „  Z* e+ d j ož e Z, e i d Z- e e j oR yD e. e- ƒ o3 e/ d e- d ƒ o e i d Z, e i d Z- n Wq\q\Xn e/ d e, e e0 e- ƒ ƒ f ƒ p d GHn d S(!   s‚   pe.py - routines to create minimalistic Windows PE executables

   emphasis on symbol tables and hashtables for building postFORTHs1  
    pe.py - routines to create minimalistic ELF files
    Copyright (C) 2005  John Comeau <jc.jcomeau.com>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    s7   Not all needed libraries found, upgrade or check path: i   i    iÿÿÿÿNi   t   libt   python(   t   gplt	   jclicenses   %s
s   [0-9A-Za-z]+c          G   s   t  S(   N(   t   False(   t   whatever(    (    s   ./pe.pyt
   DebugPrint2   s    c          G   s´   |  \ } } t  | ƒ t i j o t | ƒ } n t t d ƒ o | i | ƒ Sn^ d } xP t d t | ƒ ƒ D]9 } | | | } | t | ƒ d j o | | } qo qo W| Sd S(   s   for pythons without str.joint   joint    i    i   N(	   t   typet   typest
   StringTypet   evalt   hasattrt   strR   t   ranget   len(   t   argst   stringt   arrayt   joinedt   index(    (    s   ./pe.pyR   5   s    & c          G   sg   |  \ } } t  | ƒ p
 d } n t d d ƒ o | i | ƒ Sn  t i t i | ƒ ƒ i | ƒ Sd S(   s   for pythons without str.splitR   t   splitN(   R   t   NoneR   R   t   ret   compilet   escape(   R   R   t   string_to_split(    (    s   ./pe.pyR   C   s
    c          G   sT   d } t  i d | ƒ } d } t | ƒ t | ƒ } | d | | 7} | | 7} | S(   sW   create a non-runnable DOS stub

    required by spec, doesn't really need to run on DOSi@   s   <Lt   MZt    (   t   structt   packR   (   R   t   lengtht   e_lfanewt   headert
   skiplength(    (    s   ./pe.pyt   null_dos_stubO   s    
c          G   s­   d } d } | t  i d | ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ 7} | t  i d d d	 ƒ 7} | S(
   s   24-byte PE headeriL  t   PE  s   <Hi   s   <Li    ià   s   <BBi   (   R   R   (   R   t   i386R"   (    (    s   ./pe.pyt	   pe_header[   s    c          G   s  d } t  i d | ƒ } | t  i d d d ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ 7} | t  i d d	 ƒ 7} | t  i d d
 ƒ 7} | t  i d d d ƒ 7} | t  i d d d ƒ 7} | t  i d d d ƒ 7} | t  i d d d ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ 7} | t  i d d d d d ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ 7} | S(   s{   not optional for PE files, the name may be from COFF

    this header specifies some vital runtime parameters of this imagei  s   <Ht   BBi    s   <Li    i    i   iÀ  i   s   <LLs   <HHi   iÀ   i   s   <LLLLi   i   (   R   R   (   R   t   magicR"   (    (    s   ./pe.pyt   optional_headerh   s0    c          G   sO   t  i d d d ƒ } | t  i d d d ƒ 7} | t  i d d d ƒ d 7} | S(   s0  generate default values for the data directories

    all have names in the format IMAGE_DIRECTORY_ENTRY_x,
    where x has the names, in order:
    EXPORT, IMPORT, RESOURCE, EXCEPTION, SECURITY, BASERELOC, DEBUG, COPYRIGHT,
    GLOBALPTR, TLS, LOAD_CONFIG, BOUND_IMPORT, IAT. offsets 13-15 are unused.
 s   <LLi    ià  io   i   (   R   R   (   R   t   dirs(    (    s   ./pe.pyt   data_directories†   s    c         C   s<   | o1 t  |  ƒ | } | o |  d | | 7}  q8 n |  S(   NR   (   R   (   t   scalart	   alignmentt   modulus(    (    s   ./pe.pyt   nullpad“   s
    c          G   s    t  d d ƒ } | t i d d ƒ 7} | t i d d ƒ 7} | t i d d ƒ 7} | t i d d ƒ 7} | t i d d d d d ƒ 7} | t i d d ƒ 7} | S(	   s+   create a sectionheader for the code sections   .codei   s   <Li    i   i    s   <LLHHi   `(   R0   R   R   (   R   R"   (    (    s   ./pe.pyt   code_headerš   s    c          G   s    t  d d ƒ } | t i d d ƒ 7} | t i d d ƒ 7} | t i d d ƒ 7} | t i d d ƒ 7} | t i d d d d d ƒ 7} | t i d d ƒ 7} | S(	   s+   create a sectionheader for the code sections   .datai   s   <Li    iÀ  i    s   <LLHHiÀ  @(   R0   R   R   (   R   R"   (    (    s   ./pe.pyt   data_header¥   s    c          G   sZ   d } | d 7} | d 7} | d 7} | d 7} | d 7} | d 7} | d 7} | d	 7} | S(
   Nt   j s   hÐ s   js   hÀ s   jõs   .ÿ( t   Ps   .ÿ$ s   Ã(    (   R   t   code(    (    s   ./pe.pyt   code_section°   s    







c          G   s)   t  d d ƒ } | t i d d ƒ 7} | S(   Ns   hello, world
i   s   <Li    (   R0   R   R   (   R   t   data(    (    s   ./pe.pyt   data_section¼   s    c          G   s[  t  i d d ƒ } | t  i d d ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ 7} | t  i d d d d d d ƒ 7} | t d d	 ƒ 7} | t  i d d
 ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ 7} | t  i d d
 ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ 7} | t  i d d ƒ d 7} | t  i d d ƒ d 7} | S(   Ns   <Li  i    iÿÿÿÿi  i$  s   <LLLLLs   kernel32.dlli   i0  i@  s   <Hi   t   WriteConsoleA i   t   GetStdHandle (   R   R   R0   (   R   t   descriptors(    (    s   ./pe.pyt   import_descriptorsÁ   s     "c          G   s¿   t  ƒ  } | t ƒ  7} | t ƒ  7} | t ƒ  7} | t ƒ  7} | t ƒ  7} t | d ƒ } | t ƒ  7} | t ƒ  7} t | d ƒ } | t	 ƒ  7} t | d ƒ } t
 d | ƒ t i i | ƒ d S(   sÈ   create a default PE file, output to stdout

    the PE file consists of:
     DOS stub
     PE header
     "optional" header (actually vital)
     data directories
     section headers
     sections
 i   i   i    t   pe_fileN(   R$   R'   R*   R,   R1   R2   R0   R6   R8   R<   R   t   syst   stdoutt   write(   R   R=   (    (    s   ./pe.pyt   peÓ   s    	t   __main__s   type(%s) == types.FunctionTypei   s   %s%sR   (   i   i    (1   t   __doc__t	   Copyrightt   errormessaget   TrueR   R>   t   osR
   R   t   pwdt   patht   appendR   t   getpwuidt   geteuidt   reprt   com.jcomeauR   R   t   stderrR@   R   t   argvt   myselft   splitextt   commandR   t   searcht   groupt   originalselfR   R   R$   R'   R*   R,   R0   R1   R2   R6   R8   R<   RA   t   __name__t   functionR   R   R   t   tuple(    (    (    s   ./pe.pys   <module>   sX   <5				
											"",