3 \-@sddlZddlZddlZddlZejdkrBddZddZddZejd krlejd krldd l m Z d dZnejd krddl Z ddl Z d dZejdkrddZnddZejjd%rddZddZn6ejdkrddZd&ddZnddZdd Zd!dZd"d#Zed$kredS)'NntcCsd}tjj|}|d krdS|t|}tj|djdd\}}t|dd d}|dkrf|d7}t|ddd}|dkrd }|dkr||SdS) NzMSC v.  g$@r)sysversionfindlensplitint)prefixisrestZ majorVersionZ minorVersionr#/usr/lib64/python3.6/ctypes/util.py_get_build_version s  rcCs^t}|dkrdS|dkr d}n|dkr6d|d}ndSddl}d|jjkrV|d7}|d S) Nrmsvcrtrzmsvcr%d rz_d.pyddz.dll)rimportlib.machinery machineryEXTENSION_SUFFIXES)r Zclibname importlibrrr find_msvcrt"s rcCst|dkrtSx`tjdjtjD]J}tjj||}tjj|rD|S|jj drTq"|d}tjj|r"|Sq"WdS)NcmPATHz.dll)r r!) rosenvironrpathseppathjoinisfilelowerendswith)nameZ directoryZfnamerrr find_library7s  r,posixdarwin) dyld_findc CsLd|d|d||fg}x,|D]$}yt|Stk rBw Yq Xq WdS)Nz lib%s.dylibz%s.dylibz%s.framework/%s) _dyld_find ValueError)r+possiblerrrr,Hs  c !Cstjdtj|}tjd}|s,tjd}|s4dStj}z||dd|jd|g}t tj }d|d<d|d <yt j |t j t j|d }Wntk rdSX||jj}WdQRXWdy |jWntk rYnXXtj||}|sdStj|jd S) Nz[^\(\)\s]*lib%s\.[^\(\)\s]*gccZccz-Wl,-tz-oz-lCLC_ALLLANG)stdoutstderrenvr)r#fsencodereescapeshutilwhichtempfileZNamedTemporaryFiler+dictr$ subprocessPopenPIPEZSTDOUTOSErrorr7readcloseFileNotFoundErrorsearchfsdecodegroup) r+exprZ c_compilerZtempargsr9procZtraceresrrr _findLib_gccWs:      rOZsunos5cCsz|sdSytjdd|ftjtjd}Wntk r:dSX||jj}WdQRXtjd|}|sjdSt j |j dS)Nz/usr/ccs/bin/dumpz-Lpv)r7r8s\[.*\]\sSONAME\s+([^\s]+)r) rArBrCDEVNULLrDr7rEr;rHr#rIrJ)frMdatarNrrr _get_sonames  rScCs|sdStjd}|sdSy"tj|ddd|ftjtjd}Wntk rPdSX||jj}WdQRXt j d|}|sdSt j |j dS)Nobjdumpz-pz-jz.dynamic)r7r8s\sSONAME\s+([^\s]+)r)r=r>rArBrCrPrDr7rEr;rHr#rIrJ)rQrTrMdumprNrrrrSs"  freebsdopenbsd dragonflyc CsR|jd}g}y"x|r,|jdt|jqWWntk rDYnX|pPtjgS)N.r)rinsertrpopr1r maxsize)ZlibnamepartsZnumsrrr _num_versions r^cCstj|}d||f}tj|}ytjdtjtjd}Wntk rPd}YnX||j j }WdQRXtj ||}|st t |S|jtdtj|d S) Nz:-l%s\.\S+ => \S*/(lib%s\.\S+)/sbin/ldconfig-r)r7r8)keyr)r_r`r )r;r<r#r:rArBrCrPrDr7rEfindallrSrOsortr^rI)r+ZenamerKrMrRrNrrrr,s        c CstjjdsdSttj}d|d<|r,d }nd }d}ytj|tjtj|d}Wnt k rbdSX|:x2|j D](}|j }|j drrtj |jd}qrWWdQRX|sdSx4|jdD]&}tjj|d |}tjj|r|SqWdS) N /usr/bin/crler4r5-64)r7r8r9sDefault Library Path (ELF)::zlib%s.so)rerf)re)r#r&existsr@r$rArBrCrPrDr7strip startswithrIrr') r+is64r9rLpathsrMlinedirZlibfilerrr _findLib_crles6       rpFcCstt||pt|S)N)rSrprO)r+rlrrrr,scCsddl}|jddkr&tjjd}ntjjd}dddddd }|j|d }d }tj|tj||f}yZt j d d gt j t j t j dddd,}tj ||jj}|rtj|jdSWdQRXWntk rYnXdS)Nrlrgz-32z-64z libc6,x86-64z libc6,64bitz libc6,IA-64)z x86_64-64zppc64-64z sparc64-64zs390x-64zia64-64Zlibc6z\s+(lib%s\.[^\s]+)\s+\(%sz/sbin/ldconfigz-pr4)r5r6)stdinr8r7r9r)structZcalcsizer#unamemachinegetr:r;r<rArBrPrCrHr7rErIrJrD)r+rsruZmach_mapZabi_typeZregexprNrrr_findSoname_ldconfigs.  rxc Csdtj|}ddg}tjjd}|rHx |jdD]}|jd|gq2W|jdtjd|gd}yFtj |tj tj d d }|j \}}tj |tj |} | r| jd }Wn"tk r} zWYdd} ~ XnX|S) Nz[^\(\)\s]*lib%s\.[^\(\)\s]*Zldz-tZLD_LIBRARY_PATHrhz-Lz-oz-l%sT)r7r8Zuniversal_newlinesr)r;r<r#r$rvrextenddevnullrArBrCZ communicaterHrIrJ Exception) r+rKcmdZlibpathrresultrwout_rNerrr _findLib_lds&   rcCst|ptt|pt|S)N)rxrSrOr)r+rrrr,,scCsddlm}tjdkr:t|jt|jdttdtjdkrttdttdttdtj d krt|j d t|j d t|j d t|j d n(t|j dt|j dttddS)Nr)cdllrrr-r!r bz2r.z libm.dylibzlibcrypto.dylibzlibSystem.dylibzSystem.framework/Systemzlibm.soz libcrypt.soZcrypt) Zctypesrr#r+printrloadr,r platformZ LoadLibrary)rrrrtest4s"         r__main__)rVrWrX)F)r#r=rAr r+rrr,rZctypes.macholib.dyldr/r0r;r?rOrSrkr^rprxrr__name__rrrrs8   +     $