ó
!«ÛNc           @   s  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 m Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l Z d  d l Z d Z e d Z d Z d Z d Z d Z d	 Z e j d
 k ræ d GHe j d ƒ n  d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d d „ Z d d d „ Z d „  Z d „  Z e  e j! ƒ d k  rke ƒ  n¡e j! d d k r’e e j! d ƒ nze j! d d k r›yY e j e j! d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. g ƒ \ Z" Z# Wn- e j$ k
 r-d/ GHe ƒ  e j d ƒ n Xd Z% d Z& xû e" D]ó \ Z' Z( e' d0 k rbd Z& qAe' d1 k rwd Z& qAe' dN k rŒd4 Z& qAe' dO k r¡d7 Z& qAe' d8 k r¶d9 Z& qAe' d: k rËd; Z& qAe' dP k ràd> Z& qAe' d? k rõd@ Z& qAe' dQ k r
d Z% qAe' dR k rd Z% qAe' dS k rAd4 Z% qAqAWe  e" ƒ d k  sVe& d k rme ƒ  e j d ƒ n  e# d Z) e# d Z* e dG e) e* e% e& ƒ nqe j! d dH k røy_ e j e j! d d d d d  d! d# d" d% d$ d& d' d( dI dJ d) d* d+ d, d- d. g ƒ \ Z" Z# Wn- e j$ k
 r<d/ GHe ƒ  e j d ƒ n Xd Z+ d Z, d Z% d Z& x1e" D])\ Z' Z( e' d0 k r}d Z& q\e' d1 k r’d Z& q\e' dT k r§d4 Z& q\e' dU k r¼d7 Z& q\e' d8 k rÑd9 Z& q\e' d: k ræd; Z& q\e' dV k rûd> Z& q\e' d? k rd@ Z& q\e' dK k r%d Z+ q\e' dL k rFe& d7 k rFd Z, q\e' dW k r[d Z% q\e' dX k rpd Z% q\e' dY k r\d4 Z% q\q\We  e" ƒ d k  s§e& d k r¾e ƒ  e j d ƒ n  e# d Z) e# d Z- e dG e) e- e% e& dI e+ dM e, ƒn e ƒ  e j d ƒ d S(Z   iÿÿÿÿN(   t   hexlifys   openssl dgst -sha256 s-   -sign %(privkey)s -out %(outfile)s %(infile)ss   /etc/ukss   pubprodkey01.pems|  
-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQDJn1jWU+xxVv/eRKfCPR9e47lPWN2rH33z9QbfnqmCxBRLP6mM
jGy6APyycQXg3nPi5fcb75alZo+Oh012HpMe9LnpeEgloIdm1E4LOsyrz4kttQtG
RlzCErmBGt6+cAVEV86y2phOJ3mLk0Ek9UQXbIUfrvyJnS2MKLG2cczjlQIDAQAB
AoGASLym1POD2kOznSERkF5yoc3vvXNmzORYkRk1eJkJuDY6yAbYiO7kDppqj4l8
wGogTpv98OMXauY8JgQj6tgO5LkY2upttukDr8uhE2z9Dh7HMZV/rDYa+9rybJus
RiAQDmF+VCzY2HirjpsSzgRu0r82NC8znNm2eGORys9BvmECQQDoIokOr0fYz3UT
SbHfD3engXFPZ+JaJqU8xayR7C+Gp5I0CgSnCDTQVgdkVGbPuLVYiWDIcEaxjvVr
hXYt2Ac9AkEA3lnERgg0RmWBC3K8toCyfDvr8eXao+xgUJ3lNWbqS0HtwxczwnIE
H49IIDojbTnLUr3OitFMZuaJuT2MtWzTOQJBAK6GCHU54tJmZqbxqQEDJ/qPnxkM
CWmt1F00YOH0qGacZZcqUQUjblGT3EraCdHyFKVT46fOgdfMm0cTOB6PZCECQQDI
s5Zq8HTfJjg5MTQOOFTjtuLe0m9sj6zQl/WRInhRvgzzkDn0Rh5armaYUGIx8X0K
DrIks4+XQnkGb/xWtwhhAkEA3FdnrsFiCNNJhvit2aTmtLzXxU46K+sV6NIY1tEJ
G+RFzLRwO4IFDY4a/dooh1Yh1iFFGjcmpqza6tRutaw8zA==
-----END RSA PRIVATE KEY-----
s  
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDJn1jWU+xxVv/eRKfCPR9e47lP
WN2rH33z9QbfnqmCxBRLP6mMjGy6APyycQXg3nPi5fcb75alZo+Oh012HpMe9Lnp
eEgloIdm1E4LOsyrz4kttQtGRlzCErmBGt6+cAVEV86y2phOJ3mLk0Ek9UQXbIUf
rvyJnS2MKLG2cczjlQIDAQAB
-----END PUBLIC KEY-----
sí  
#!/bin/sh

_FUNCTIONS=/etc/rc.d/functions
[ -f ${_FUNCTIONS} ] && . ${_FUNCTIONS}

. /etc/sysconfig/mntus

#Restore original Kindle signing key
cat > /etc/uks/pubprodkey01.pem <<EOF
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxfpiZ1dbdSOgrikqXD6lESUrD
5l52nN50iMh2vDcmW/FzkPDv0eRf1ci6w3ifhmHwqDK9OYNnowPapzUHAiHukXjW
rOC3fZYzgAxzIPN4NyUw369zFK2AALZnXptc68D/xxtZ94porf+kLtw/4vF2NhHs
XtchrpvID+Jhkor8MQIDAQAB
-----END PUBLIC KEY-----
EOF

update_progressbar 100

return 0
i   sX   This script is incompatible with Python 3.x. Please install Python 2.6.x from python.orgi   c         C   sa   t  j  d |  ƒ } xB t t | ƒ ƒ D]. } | | d A} | d ?| d >Bd @| | <q% W| j ƒ  S(   Nt   Biz   i   iÿ   (   t   arrayt   xranget   lent   tostring(   t   st   arrt   it   b(    (    st   /home/danny_milo/scratchpost.org/software/<attic>/Nokia/N900/scratchbox_setupc/Kindle/packager/kindle_update_tool.pyt   dm\   s
    c         C   sg   t  j  d |  ƒ } xH t t | ƒ ƒ D]4 } | | } | d ?| d >Bd @} | d A| | <q% W| j ƒ  S(   NR   i   iÿ   iz   (   R   R   R   R   (   R   R   R   R	   (    (    st   /home/danny_milo/scratchpost.org/software/<attic>/Nokia/N900/scratchbox_setupc/Kindle/packager/kindle_update_tool.pyt   mdc   s    
c         C   s)   t  j  ƒ  } | j |  ƒ t | j ƒ  ƒ S(   N(   t   md5t   updateR    t   digest(   R   t   m(    (    st   /home/danny_milo/scratchpost.org/software/<attic>/Nokia/N900/scratchbox_setupc/Kindle/packager/kindle_update_tool.pyt   s_md5k   s    c         C   sI   t  j |  t ƒ } | j ƒ  } | j j ƒ  } | j j ƒ  } | | | f S(   sÁ   wrapper to simplify the execution of external programs.
    @param cmd: Command line to be executed
    @type cmd: string

    @return: tuple (exit code, stdout, stderr).
    @rtype: tuple
    (   t   popen2t   Popen3t   Truet   waitt	   fromchildt   readt   childerr(   t   cmdt   sslt   statust   outt   err(    (    st   /home/danny_milo/scratchpost.org/software/<attic>/Nokia/N900/scratchbox_setupc/Kindle/packager/kindle_update_tool.pyt
   runCommandp   s
    c         C   sµ  t  |  d ƒ } t j d | j d ƒ ƒ } | d } | d k rƒ | j d ƒ t j d | j d ƒ ƒ \ } } } } } } } }	 n' t j d	 | j d
 ƒ ƒ \ } } } }	 | d  k r¿ d }
 n | d! k rÔ d }
 n	 d GHd  Sd | |
 f GH| d" k rd | GHd | GHd t | d ƒ GHn  d t | j d ƒ ƒ GH| d# k rS| j d ƒ n8 | d$ k ro| j d ƒ n | d% k r‹| j d ƒ n  t  |  d d ƒ j t | j ƒ  ƒ ƒ d  S(&   Nt   rbs   <4si   i    t   SP01i@  s   <4sIIIIHHBxi   s   <IIHBxi   t   FC02t   FD03s
   OTA updatet   FB01t   FB02t   FC04s   Manual updates   Not a Kindle update file!s   Signature: %s (%s)s   min version: %ds   max version: %ds   device code: %d%di   s   md5 of tgz: %si    i@   i|  i   s   .tgzt   wb(   R   (   R    R!   (   R"   R#   R$   (   R    R!   R$   (   R    R!   (   R$   (   R"   R#   (   t   opent   structt   unpackR   t   seekt   divmodR
   t   write(   t   binnamet   ft   sigt   fromVert   iFoo1t   toVert   iFoo2t   iFoo3t   devCodet   optionalt   typ(    (    st   /home/danny_milo/scratchpost.org/software/<attic>/Nokia/N900/scratchbox_setupc/Kindle/packager/kindle_update_tool.pyt   extract_bin~   s4    
6'				i¤  c         C   sV   | |  _  d |  _ |  _ d |  _ |  _ t | d ƒ } | j |  | ƒ | j ƒ  d  S(   Ni    t   rootR   (   t   modet   uidt   gidt   unamet   gnameR&   t   addfilet   close(   t   tarinfot   filet   tarR9   t   fs(    (    st   /home/danny_milo/scratchpost.org/software/<attic>/Nokia/N900/scratchbox_setupc/Kindle/packager/kindle_update_tool.pyt   add_tarfile¡   s    	t    c   	      C   s¸   t  j ƒ  \ } } t j | ƒ t i |  d 6| d 6| d 6} t | ƒ } | d d k ri t d ƒ ‚ n  | d k r~ | } n  | j | d | d ƒ} t | | | ƒ t j	 | ƒ d  S(	   Nt   privkeyt   outfilet   infilei    s   Openssl failedRE   t   arcnames   .sig(
   t   tempfilet   mkstempt   osR?   t   CMD_SIGNR   t
   ValueErrort
   gettarinfoRD   t   remove(	   t   keyfilet   nameRB   t	   finalnamet   fdt   sigfileR   R   R@   (    (    st   /home/danny_milo/scratchpost.org/software/<attic>/Nokia/N900/scratchbox_setupc/Kindle/packager/kindle_update_tool.pyt
   create_sig©   s    	i    c      	   C   s  t  j ƒ  \ } } t j | ƒ t j | d ƒ } d }	 | r{ t  j ƒ  \ } }
 t j | d ƒ } | j t ƒ | j ƒ  n  | rït	 j
 ƒ  d t t	 j d d ƒ ƒ } t j | ƒ } t j | _ t | _ | j | ƒ t  j ƒ  \ } } t j | d ƒ } | j t ƒ | j ƒ  | j | d | d t ƒ} t | | | ƒ t j | ƒ d	 t t	 j d d ƒ ƒ d
 } t  j ƒ  \ } } t j | d ƒ } | j t ƒ | j ƒ  | j | d | ƒ} t | | | ƒ | rït |
 | | d | ƒqïn  | r"x* | D] } d | GHt |
 | | ƒ qüWn  x° | D]¨ } d | GH| j | ƒ } | j d
 ƒ r_d } n d } t | | | ƒ t j j | ƒ d } t | d ƒ } |	 d | t | j ƒ  ƒ | | | d f 7}	 | j ƒ  q)W| rGt j j | ƒ d } t | d ƒ } |	 d d t | j ƒ  ƒ | | | d f 7}	 | j ƒ  t j | ƒ n  t  j ƒ  \ } } t j | d ƒ } | j |	 ƒ | j ƒ  | j | d |  d ƒ} t | | | ƒ | rÝd GHt |
 | | |  d ƒ t j |
 ƒ n  t j | ƒ | j ƒ  t |  | | | ƒ t j | ƒ d  S(   Ns   w:gzRE   R%   t   __diriè  i'  RI   t   /t   _installs   .shRS   s   calculating signature for %ss	   adding %si   i€   i@   R   s   %d %s %s %d %s
t   _files   .dats%   calculating signature for bundle file(    RJ   RK   RL   R?   t   tarfileR&   t   fdopenR+   t   SIGN_KEYt   randomt   seedt   strt   randintt   TarInfot   SYMTYPEt   typet   KINDLE_HACK_DIRt   linknameR>   t   NEW_KEYRO   t   KINDLE_HACK_KEYNAMERD   RP   t   INSTALL_SCRIPTRV   t   endswitht   patht   getsizeR   R   t   convert_bin(   t   basenamet   filelistRd   t   kvert   signt	   jailbreakRT   t	   tgz_fnameRB   t   dat_listRQ   RC   t   namedirR@   t   tmpfilet   nameinstallt
   tmpinstallRR   t   fidt   fsizet   inft   tmpdat(    (    st   /home/danny_milo/scratchpost.org/software/<attic>/Nokia/N900/scratchbox_setupc/Kindle/packager/kindle_update_tool.pyt   make_bin»   s†    
	
 
			--


c   	      C   s  d GH| d k r  d } d } nB | d k r; d } d } n' | d k rV d } d	 } n d } d
 } t  | d ƒ j ƒ  } t  |  d d ƒ } t j d | d d | d d ƒ } | j | ƒ | j t t | ƒ ƒ ƒ | j d | | j ƒ  ƒ | j t | ƒ ƒ | j ƒ  d |  d GHd  S(   Ns   making bin filei   i@   R!   i   R    i   i   R"   R#   R   s   .binR%   s   <4sIIHBBi    iÿÿÿi   t    s   output written to (	   R&   R   R'   t   packR+   R   R   t   tellR?   (	   Rn   Rs   Rd   Rp   t
   BLOCK_SIZER.   R-   t   oft   header(    (    st   /home/danny_milo/scratchpost.org/software/<attic>/Nokia/N900/scratchbox_setupc/Kindle/packager/kindle_update_tool.pyRm     s*    			!
c           C   s	   d GHd  S(   Ns  
    Kindle Firmware Update tool v0.13
    Copyright (c) 2009-2011 Igor Skochinsky & Jean-Yves Avenard
    Usage:
    kindle_update_tool.py e update_mmm.bin
      Extract a Kindle or Kindle 2 firmware update file. Outputs a .tgz file
      with decrypted content.

    kindle_update_tool.py m [flags] name file1 [file2 ...]
      Where flags is one of the following:
        --k2 , --k2i, --dx, --dxi, --dxg, --k3g, --k3w, --k3gb
      Makes a Kindle 2, Kindle 2 International, Kindle DX, Kindle DX International,
      Kindle DX Graphite, Kindle 3G or Kindle 3 WiFi OTA firmware update
      file from the list of files.
      "name" is the update file suffix (final file will be called
      update_name.bin).
      Any file with .sh extension will be marked as a shell script to be
      executed.
      Flags:
        --k2:   generate a package for Kindle 2
        --k2i:  generate a package for Kindle 2 International
        --[dx|DX]:   generate a package for Kindle DX
        --[dxi|DXi]: generate a package for Kindle DX International
        --[dxg|DXg]: generate a package for Kindle DX Graphite
        --k3g:   generate a package for Kindle 3G
        --k3w:   generate a package for Kindle 3 WiFi
        --k3gb:  generate a package for Kindle 3G UK

        Flags for Firmware 2.2 and later:
        --sign: generate signed images.
                This is required for firmware 2.2 and later.
        --ex:   the generated package will install without the need to first
                install new RSA keys to the kindle (also called jailbreaking).
                It is imperative that the install script works 100%. As should
                they fail, it could leave your kindle in a corrupted state
                preventing to install future official Amazon updates.
                BIG FAT WARNING:
                This doesn't work anymore since firmware 2.4, and thus shouldn't
                be used when generating a package for current firmwares.
                No-op when generating a package for Kindle models always using
                firmware 2.5 or later (DXg, k3g, k3w, k3gb).

        Flags for Firmware 2.5 and later:
        --[fd|FD]:   generate a FD03 OTA update (instead of a FC02)
        --[fb|FB]:   generate a FB01 MANUAL (recovery) update (instead of an OTA FC02).
        --[fb2|FB2]: generate a FB02 MANUAL (recovery) update (instead of an OTA FC02).
                     Probably not working right now, but here for completeness sake.

    kindle_update_tool.py c [flags] name tarname]
      Convert a GZIPPED TAR file into a Kindle DX, Kindle 2, or
      Kindle 2 International OTA firmware update file.
      "name" is the update file suffix
      (final file will be called update_name.bin).
      Flags:
        --k2:   generate a package for Kindle 2
        --k2i:  generate a package for Kindle 2 International
        --[dx|DX]:   generate a package for Kindle DX
        --[dxi|DXi]: generate a package for Kindle DX International
        --[dxg|DXg]: generate a package for Kindle DX Graphite
        --k3g:   generate a package for Kindle 3G
        --k3w:   generate a package for Kindle 3 WiFi
        --k3gb:  generate a package for Kindle 3G UK

        Flags for Firmware 2.5 and later:
        --[fd|FD]:   generate a FD03 OTA update (instead of a FC02)
        --[fb|FB]:   generate a FB01 MANUAL (recovery) update (instead of an OTA FC02).
        --[fb2|FB2]: generate a FB02 MANUAL (recovery) update (instead of an OTA FC02).
                     Probably not working right now, but here for completeness sake.
(    (    (    (    st   /home/danny_milo/scratchpost.org/software/<attic>/Nokia/N900/scratchbox_setupc/Kindle/packager/kindle_update_tool.pyt   usage.  s    Ei   i   t   et   ct   k2t   k2it   DXt   dxt   dxit   DXit   dxgt   DXgt   k3gt   k3wt   k3gbRT   t   FDt   fbt   FBt   fb2t   FB2s   Unrecognised option: s   --k2s   --k2is   --DXs   --dxi   s   --DXis   --dxii   s   --k3gi   s   --k3wi   s   --DXgs   --dxgi	   s   --k3gbi
   s   --FDs   --fds   --FBs   --fbs   --FB2s   --fb2t   update_R   Rq   t   exs   --signs   --exRr   (   s   --DXs   --dx(   s   --DXis   --dxi(   s   --DXgs   --dxg(   s   --FDs   --fd(   s   --FBs   --fb(   s   --FB2s   --fb2(   s   --DXs   --dx(   s   --DXis   --dxi(   s   --DXgs   --dxg(   s   --FDs   --fd(   s   --FBs   --fb(   s   --FB2s   --fb2(.   R[   t   gzipR   R   t   sysR'   t   binasciiR    RL   R   R^   RJ   t   getoptt   BASE_CMDRM   Re   Rh   R]   Rg   Ri   t
   hexversiont   exitR
   R   R   R   R7   RD   RV   R}   Rm   R„   R   t   argvt   optst   argst   GetoptErrorRd   Rp   t   ot   aRR   t   tarnameRq   Rr   Ro   (    (    (    st   /home/danny_milo/scratchpost.org/software/<attic>/Nokia/N900/scratchbox_setupc/Kindle/packager/kindle_update_tool.pyt   <module>   sà   H
						#Y		G
Y										

_												

&