
YYc           @   s  d  d l  Td  d l Td  d l Td  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l Z d  d l Z d  d l Z d  d l Z d   Z d   Z e j d k r e j j e j d  e j Z nV e j j e j j e j d   Z e e j Z e j e d  Z e j e d  d Z d	 Z d	 Z d
 Z  d Z! d Z" d Z# e a$ e# Z% d g Z& d g Z' d  d l Z d dA d     YZ( d   Z) d   Z* d   Z+ d   Z, d   Z- d   Z. d   Z/ d   Z0 d   Z1 d   Z2 d   Z3 d   Z4 d   Z5 d   Z6 d    Z7 d!   Z8 d"   Z9 d#   Z: d$   Z; d%   Z< d&   Z= d'   Z> d(   Z? d)   Z@ d*   ZA d+   ZB eC d, k rd- GHe jD   y/ e
 j
 e j d	 d. d/ d0 d1 g  \ ZE ZF Wn& e
 jG k
 rd2 GHe jH d	  n Xx eE D] \ ZI ZJ eI d3 k r4eJ ZK n  eI d4 k rIeJ ZL n  eI dB k r^d	 Z n  eI d7 k reM eJ  Z e jN e  n  eI d8 k reM eJ  d9 k re" Z% qe Z% qqWe j jO eK  eP k rd: eK GHe jH d	  n  e j j e j j eK   e j ZQ eQ e& d <d; eL GHe) eK  e> eK d<  ZR e? eK d< eR  eR jS   eR jT   e@ e d= e d>  eB eL  e*   d? eU e jD    d@ GHn  d S(C   i(   t   *Nc         C   s   d t  d  |  t  d  f S(   Ns   %s[31;47m%s%s[0mi   (   t   chr(   t   s(    (    s
   PyMaker.pyt   inred   s    c         C   s   d t  d  |  t  d  f S(   Ns   %s[34;47m%s%s[0mi   (   R   (   R   (    (    s
   PyMaker.pyt   inblue   s    t   nti    s   /libScript.sot   /i   i   i   i   i   t   .t    t   stdoutc           B   s   e  Z d    Z RS(   c         C   s7   t  |  d k | d d k @r3 t j j |  n  d  S(   Ni    s   
(   t   lent   windllt   kernel32t   OutputDebugStringA(   t   selft   buf(    (    s
   PyMaker.pyt   write2   s     (   t   __name__t
   __module__R   (    (    (    s
   PyMaker.pyR	   1   s   c         C   s"   t  j |   t j |  d  d  S(   Ns
   .nocomment(   t	   UnCommentt   Func_DelCommentt   delcommentlistt   append(   t   strIn(    (    s
   PyMaker.pyt
   DelComment6   s    c          C   sp   x6 t  D]. }  t j j |   t k r t j |   q q Wt j t d  t j t d  t j t d  d  S(   Ns	   sample.dbs   temp.dbs   temp.img(   R   t   ost   patht   existst   Truet   removet   gAppPath(   t   item(    (    s
   PyMaker.pyt   ClearTmpFile:   s    c         C   s   t  d |  } |  j   j d  d k r< d | d } nP |  j   j d  d k rh d | d } n$ |  j   j d	  d k r d
 } n  | S(   NiA   t   NUMBERi    t   Numbers    intt   STRINGt   Strings    textt   FILENAMEs   FileName text(   R   t   uppert   find(   R   t   Indext   colIDt   strType(    (    s
   PyMaker.pyt	   GenColStrD   s    	c         C   s   |  j  d  S(   Nt   =(   t   split(   R   (    (    s
   PyMaker.pyt	   ParseLineQ   s    c         C   sz   |  j  d  } d } d } x5 | D]- } | t t |  |  d } | d } q" W| j   j d  } d | d } | S(   Nt   ,i    R   s   , i   t   (t   )(   R-   R+   t   stript   rstrip(   R   t   collistt   iIndext   sqlt   value(    (    s
   PyMaker.pyt   GenSql_DBTableColV   s    c         C   s6   t  |  d  } | d k r, | d d } n  t |  S(   Ni   iI    i   (   t   intt   str(   t   strHexInt   iValue(    (    s
   PyMaker.pyt   GetIntValuef   s    c         C   s   |  } |  j  d  d k rm d } |  j d  }  x! |  D] } t j |  | } q7 Wd | } t |  } n5 |  d d !d k s |  d d !d k r t |   } n  | S(   Ns   'i    R   t   0xi   t   0X(   R'   R2   t   binasciit   b2a_hexR=   (   R   t   strValuet   char(    (    s
   PyMaker.pyt   GenValueStrm   s    
&c         C   s   t  j  |   } d | _ t | _ t |  } d } d } x2 | D]* } | t t |   d } | d } q@ W| j   j d  } d | d } | S(   NR/   i    R   s   , i   R0   R1   (   t   shlext
   whitespaceR   t   whitespace_splitt   listRD   R2   R3   (   R   R:   R4   R5   R6   R7   (    (    s
   PyMaker.pyt   GenSql_InsertValue   s    		c         C   s^   t  |  d  } t  |  d  j d  } | d k r9 d  Sd | t |  } | j |  d  S(   Ni    i   t   ;t   CALLBACKs   CREATE TABLE (   R2   R3   R8   t   execute(   t   strListt   connt   Keyt   ValueR6   (    (    s
   PyMaker.pyt   GenTable   s    c         C   s]   d | } |  j  |  g  |  j D] } | d ^ q! } y | j d  } | SWn d SXd  S(   Ns   select * from i    t   FileNamei(   RL   t   descriptiont   index(   t   cursort	   tablenameR6   t   tuplet   col_name_listt   p(    (    s
   PyMaker.pyt   IsFileTable   s    
 c         C   s  | j  d  | j   j d  } d } |  | } t j j |  t k r d | GHxP t D]? } t j j | |  t k rZ | | } d } d | GHPqZ qZ Wn d } | d k r d  St j	 t
 d d |  d	 d | d
 d | d }	 | j |	  | j   }
 t j j |  } |
 d  k rQd d | d d | d t |  d }	 n, d t |  d d | d
 d | d }	 | j |	  t d k rd | d }	 | j |	  n  d  S(   NR/   s   "i    s   file not found: i   s   file found in: s   temp.imgs   \s(   select * from FileTable where Keyword = s   " and FileName = s   INSERT INTO FileTable VALUES(s   ",s   ,0)s"   UPDATE FileTable SET FileLength = s    where Keyword = s    INSERT INTO ProtectFile VALUES("s   ")(   R-   R2   R   R   R   t   Falset   dirlistR   t   libt   Py_AddFileToFWR   RL   t   fetchonet   getsizet   NoneR:   t   g_bProtectMode(   t   curDirRO   R   R5   RU   R7   t   bFoundt   fullpathR   R6   t   rect   filesize(    (    s
   PyMaker.pyt   InsertFileTable   s4    "
	
	/,c         C   s   |  j  d  } t | d  } t | d  j d  } | d k rH d  Sd | j   d t |  } | j |  t | | j    } | d k r t | | | | |  n  d  S(   NR,   i    i   RJ   t   MAKEFWU_FLAGs   INSERT INTO s    VALUES(   R-   R2   R3   R&   RI   RL   RZ   Rh   (   R   RU   Rc   RM   RO   RP   R6   t
   iFileIndex(    (    s
   PyMaker.pyt
   InsertData   s    c         C   s=   d } x0 | D]$ } | |  | k r' d S| d } q Wd Sd  S(   Ni    i   (    (   RH   t   flagR5   RC   (    (    s
   PyMaker.pyt	   CheckFlag   s    c         C   s   y t  |  d  } | j d  } | j   t | d  d k rD t St | d  d k r] t St | d  d k rv t St | d  d k r t Sd SWn d SXd  S(	   Nt   rbi@   t   SFDNABDWFTCAi   t   100TMFWFSTCAs	   "3DUfws   SQLite format 3i    (   t   opent   readt   closeRm   t   ENUM_DBType_TEMPDBt   ENUM_DBType_TEMPDB100t   ENUM_DBType_112233t   ENUM_DBType_SQLITE(   t   strPatht   fileDatat   binData(    (    s
   PyMaker.pyt   IsDBFile   s    
c         C   sX   t  d d  } t j |  |  } t | d  } | j |  | j |  | j   d  S(   Nt    i
   i   t   wbi (  i   (   t   c_bufferR]   t   Py_108Rq   R   t   truncateRs   (   t   fileInt   fileOutt   pOutBuft   buflenRy   (    (    s
   PyMaker.pyt   Decrypt112233  s    c         C   s  t  j j |   } t |  d  } | j d  | j d  } t j d |  d } | d | } t t d d  } | j |  } | j |  | j	 d  d }	 x' |	 D] }
 | j t j
 d |
   q W| j	 d  | j d  | j d  x0 t d d  D] } | j t j
 d d   qW| j t j
 d d   | j t j
 d d   | j   t | d d  } | j |  } | j |  | j   t | d |  t  j | d  | j   d  S(   NRn   i   i   t   ii    i   s   temp.imgR}   i   i<   i   iM   iS   iD   iO   i5   i.   i0   t   BiG   s	   NO NAME  s
     FAT32   i  iU   i   t   _en(   i   i<   i   iM   iS   iD   iO   iS   i5   i.   i0   (   R   R   R`   Rq   Rr   t   structt   unpackR   R   t   seekt   packt   rangeRs   R   R   (   R   R   Rg   t   fileBigR   t   imglent   dblent   fileImgt   imgDatat   headt   tupR   t   fileDBt   dbData(    (    s
   PyMaker.pyt   DecryptTempDB100  s8    

c         C   s  t  j j |   } t |  d  } | j d  | j d  } t j d |  d } | d | } t | d d  } | j |  } | j |  | j   t	 | d |  t  j
 | d  t t d	 d  }	 | j |  }
 |	 j |
  |	 j   | j   d  S(
   NRn   i   i   R   i    i   R   R}   s   temp.img(   R   R   R`   Rq   Rr   R   R   R   Rs   R   R   R   (   R   R   Rg   R   R   R   R   R   R   R   R   (    (    s
   PyMaker.pyt   DecryptTempDB=  s"    

c   	      C   s*  t  j j |   t k r d  St d } t |   } | a | t k rd t	 |  |  t
 j |  } | S| t k r t |  |  t
 j |  } | S| t k r t |  |  t
 j |  } | S| t k r t j |  |  t
 j |  } | St |   |  d }  t  j j |  r!t  j |  n  t  j j t d  rKt  j t d  n  t
 j |  } d } t |   } xg | j   } | sPn  | j d  d k  rqon  t t |   } | t |  d } t | |  qo| j d  | j d	  | j d
  d | d } d | d } | j |  | S(   Ns	   sample.dbs
   .nocomments   temp.imgR   R,   i    t    se   create table FileTable(Keyword text,FileName text,FileLength int,File blob,UNIQUE(Keyword,FileName));s(   create table ProtectFile(FileName text);sC   create table FuncSpec(Signature text,Body text ,UNIQUE(Signature));s	   SYNTAX { s   } ;s'   INSERT INTO FuncSpec VALUES("SYNTAX" ,"s   ");(   R   R   R   R[   Ra   R   R{   t   g_FWTypeRt   R   t   sqlite3t   connectRu   R   Rv   R   Rw   t   shutilt   copyR   R   Rq   t   readlineR'   R.   R2   RQ   RL   (	   Rx   t
   tempDBPatht   dbtypeRN   t   strFuncSpect   filet   linet	   tablePropt   sqlFuncSpec(    (    s
   PyMaker.pyt   LoadBaseFileX  s^    


c         C   s`   |  j  d  d } | j d  j d  } | j d t j  } | j d t j  } | t j S(   NR,   i   RJ   s   "s   \R   (   R-   R3   R2   t   replaceR   t   sep(   R   R   (    (    s
   PyMaker.pyt   Symbol_SETPATH  s
    c         C   sV   |  |  j  d  } | j   j d  } | j d t j  } | j d t j  } | S(   NR   s   "s   \R   (   R'   R2   R   R   R   (   R   R   (    (    s
   PyMaker.pyt   Symbol_INCLUDE  s
    c   
      C   sA  t  j j |   t k rz d |  GHt  j j |   } xD t D]9 } t  j j | |  t k r: | | }  d |  GHPq: q: Wn  t |   |  d }  t |   } t  j j	 |   t  j
 } | } x| j   } | s Pn  | j   } | j   j d  d k ret  j j | t |   t  j
 } t  j j |  t k rFt d  | GHn  | t k r:t j |  q:q | j   j d  d k rd } q | j   j d	  d k r| t |  }	 t  j j |	  t k rt d
  |	 GHn  t |	 |  q | j   j d  d k rd } q | j d  d k r t | | |  q q d  S(   Ns   File not found : s   file found in: s
   .nocommentt   SETPATHi    s   SETPATH not exists:t   BASEFILEi   s   #INCLUDEs   INCLUDE not exists:s   #!AFIBR,   (   R   R   R   R[   t   basenameR\   R   R   Rq   t   dirnameR   R   R2   R&   R'   t   abspathR   R   R   R   t   ParseIncludeFileRk   (
   t	   strInPathRU   t   filenameR   R   t   oriDirRc   R   t   espt   IncludeFilePath(    (    s
   PyMaker.pyR     sH    	
	

#		c         C   s  t  |   } t j j |   t j } | } x| j   } | sD Pn  | j   } | j   j d  d k r t j j	 | t
 |   t j } t j j |  t k r t d  | GHn  | t k rt j |  qq. | j   j d  d k rU| | j d  d j d  j d  } t j j |  t k rEt d	  | GHn  t |  } Pq. | j   j d
  d k r. | t |  } t j j |  t k rt d  | GHn  t |  | d } t |  } Pq. q. | S(   NR   i    s   SETPATH not exists:R   R,   i   RJ   s   "s   BASEFILE  not exists:s   #INCLUDEs   Include2 not exists:s
   .nocomment(   Rq   R   R   R   R   R   R2   R&   R'   R   R   R   R[   R   R\   R   R-   R3   R   R   R   t   IniBaseFile(   R   R   R   Rc   R   R   RN   R   (    (    s
   PyMaker.pyR     s<    #)

c   	      C   sk  t  |   } t j j |   t j } | } | j   } x-| j   } | sP Pn  | j   } | j   j	 d  d k r t j j
 | t |   t j } | t k rdt j |  qdq: | j   j	 d  d k r d } q: | j   j	 d  d k r| t |  } t | |  q: | j   j	 d  d k r<d } q: | j	 d  d k r: t | | |  q: q: d  S(   NR   i    R   i   s   #INCLUDEs   #!AFIBR,   (   Rq   R   R   R   R   RU   R   R2   R&   R'   R   R   R\   R   R   R   Rk   (	   R   RN   R   R   Rc   RU   R   R   R   (    (    s
   PyMaker.pyt   ParseCfgFile  s.    #		c         C   sz   t  j d k r" t j |  |  nT t d d  } t j |  |  } t | d  } | j |  | j	 |  | j
   d  S(   NR   R|   i
   i   R}   i (  i   (   R   t   nameR   R   R~   R]   t   Py_106Rq   R   R   Rs   (   R   R   R   R   Ry   (    (    s
   PyMaker.pyt	   EncryptFw"  s    c         C   s  t  d } t j j |  t k r& d  St  d } t j j |  t k rL d  Sd } t j j |  } t j j |  } t | d  } | j |  } | j   t | d  } | j	 d  | j
 d  | j	 d  | j	 d	  xB t d
 d  D]1 }	 t j d
 d  }
 | j	 t j d |
   q Wd  } x' | D] } | j	 t j d |   q3W| j
 d
  | j |  } | j   t |  d  } | j	 |  | j	 t j d |   | j	 |  | j	 |  | j   d  S(!   Ns   temp.imgs   temp.dbRp   Rn   s   rb+s   ACTS-FWT001iG   t   ACTIONSFW  t   FMT001  i    i  id   R   i   i"   i3   iD   iU   if   iw   i   i   i   i   i   i   i   i   iu   R}   R   (   i   i"   i3   iD   iU   if   iw   i   i   i   i   i   i   i   i   iu   (   R   R   R   R   R[   R`   Rq   Rr   Rs   R   R   R   t   randomt   randintR   R   (   t
   strOutFilet   tempImgPathR   t   strMagicR   R   R   R   R   R   t   irandt   endflagR   R   t   fileDest(    (    s
   PyMaker.pyt   CombineDbNImg100.  s@    



c         C   sf  t  t k r) t t k rC t |   d  Sn t  t k rC t |   d  St d } t j j |  t	 k ri d  St d } t j j |  t	 k r d  Sd } t j j
 |  } t j j
 |  } t | d  } | j |  } | j   t | d  } | j |  }	 | j   t |  d  }
 |
 j |  |
 j t j d |   |
 j |  |
 j |	  |
 j   d  S(   Ns   temp.imgs   temp.dbRo   Rn   R}   R   (   t   g_SaveFWTypet   ENUM_DBType_AUTOR   Ru   R   R   R   R   R   R[   R`   Rq   Rr   Rs   R   R   R   (   R   R   R   R   R   R   R   R   R   R   R   (    (    s
   PyMaker.pyt   CombineDbNImg[  s8    





t   __main__s   PyMaker 1.1.170825.1s   c:o:t   forceunextracts   mf=s   type=s   cmd param errors   -cs   -os   -fs   --forceunextracts   --mfs   --typeid   s   file not found:s	   Making...s
   .nocomments	   sample.dbs   temp.dbs   Saving Success, time cost: t   secs(    (   s   -fs   --forceunextract(V   t   ctypest   stringt   mathR   t   timet   threadR   R   t   sysR@   t   getoptR   R   RE   R   R   R   R   R   R   t   argvR   R   R   t   cwdt   cdllt   LoadLibraryR]   t   Py_SetLibPathRb   t   g_bFastEncryptModeRt   Rv   Rw   Ru   R   R   R   R\   R   R	   R   R    R+   R.   R8   R=   RD   RI   RQ   RZ   Rh   Rk   Rm   R{   R   R   R   R   R   R   R   R   R   R   R   R   R   t   clockt   optst   argst   GetoptErrort   exitt   ot   at   strCfgR   R9   t   Py_SetEncryptModeR   R[   t   cfgbasepathRN   t   commitRs   R:   (    (    (    s
   PyMaker.pyt   <module>   s   


		#%				
									1							&		>				0	*	!		-	*
/					%
	



