Ë
    ãß²jÀ  ã                   ó&  — U d 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mZ  ej                  «       dk(  Z
 ej                  d«      Zi Zeeef   ed<   i Zeeef   ed<   daded	<   d
ZdZdZdedefd„Zdd„Zdedefd„Zddededefd„Zdedefd„Zy)zÉGit Bash health probe + Mandatory-ASLR diagnostics (Windows), used by
``local._find_bash`` to pick a bash.exe that can actually launch MSYS children
and to build the targeted remediation when none can.é    N)Úbounded_probe_runÚwindows_hide_flagsÚWindowsztools.environments.localÚ_bash_starts_cacheÚ_bash_probe_details_cacheúbool | NoneÚ_mandatory_aslr_enabled_cacheg      .@z0/usr/bin/true; /usr/bin/cat --version >/dev/null)zdofork:zchild_copy:Ú
0xc0000142Ú
0xc0000005ÚdetailsÚreturnc                 óT   ‡— | j                  «       Št        ˆfd„t        D «       «      S )zAMatch Git-for-Windows child-launch failures associated with ASLR.c              3   ó&   •K  — | ]  }|‰v –— Œ
 y ­w)N© )Ú.0ÚmarkerÚlowereds     €úK/home/ubuntu/.hermes/hermes-agent/tools/environments/local_gitbash_probe.pyú	<genexpr>z1_looks_like_msys_spawn_failure.<locals>.<genexpr>!   s   øè ø€ ÒK Vˆv˜Ô ÑKùs   ƒ)ÚlowerÚanyÚ_MSYS_SPAWN_FAILURE_MARKERS)r   r   s    @r   Ú_looks_like_msys_spawn_failurer      s    ø€ à�m‰m‹o€GÜÓKÔ/JÔKÓKÐKó    c            
      óÄ  — t         �t         S t        j                  d«      xs dddddg} 	 t        j                  | dddd	d
t        «       t        j                  ¬«      }|j                  dk7  ry|j                  xs dj                  «       j                  «       }ddddœj                  |«      a t         S # t        $ r }t        j                  d|«       Y d}~yd}~ww xY w)zEReturn Windows' system-wide ForceRelocateImages state when available.Nzpowershell.exez
-NoProfilez-NonInteractivez-CommandzC(Get-ProcessMitigation -System).Aslr.ForceRelocateImages.ToString()Tzutf-8Úreplaceé
   )Úcapture_outputÚtextÚencodingÚerrorsÚtimeoutÚcreationflagsÚstdinz0Could not query Windows Mandatory ASLR state: %sr   Ú F)ÚONÚOFFÚNOTSET)r	   ÚshutilÚwhichÚ
subprocessÚrunr   ÚDEVNULLÚ	ExceptionÚloggerÚdebugÚ
returncodeÚstdoutÚstripÚupperÚget)ÚcmdÚresultÚexcÚvalues       r   Ú_mandatory_aslr_enabledr:   $   sÜ   € ô %Ð0Ü,Ð,Ü�<‰<Ð(Ó)Ò=Ð-=¸|ÐM^ØÐ\ð^€CðÜ—‘ °D¸tÈgØ'0¸"ÔL^ÓL`Ôhr×hzÑhzô|ˆð
 ×Ñ˜AÒØØ�]‰]Ò ˜b×'Ñ'Ó)×/Ñ/Ó1€EØ+/¸ÈÑ$O×$SÑ$SÐTYÓ$ZÐ!Ü(Ð(øô ò Ü�‰ÐGÈÔMÜûðús   ¬3B6 Â6	CÂ?CÃCÚbashc                 ól  — t        j                  t        j                  | «      «      }t        j                  |«      j	                  «       dk7  rt        j                  |«      S t        j                  |«      }t        j                  |«      j	                  «       dk(  rt        j                  |«      S |S )zAResolve Git's root from either <root>/bin or <root>/usr/bin bash.ÚbinÚusr)ÚntpathÚdirnameÚnormpathÚbasenamer   )r;   Úbin_dirÚparents      r   Ú_git_root_from_bashrE   8   s~   € ä�n‰nœVŸ_™_¨TÓ2Ó3€GÜ‡��wÓ×%Ñ%Ó'¨5Ò0Ü�~‰~˜gÓ&Ð&Ü�^‰^˜GÓ$€FÜ%+§_¡_°VÓ%<×%BÑ%BÓ%DÈÒ%MŒ6�>‰>˜&Ó!ÐYÐSYÐYr   c                 óh   — t        | «      j                  dd«      }|rd|dd › �nd}d| › d|› d	|› d
�S )z:Build the targeted per-program Mandatory-ASLR remediation.ú'z''z
Git Bash probe output: Niô  r%   zGit Bash at z¥ cannot launch required MSYS child processes while Windows Mandatory ASLR (ForceRelocateImages) is enabled, or its output matches that Git-for-Windows failure class.zw
Reinstalling Git will not change the Windows mitigation policy. Open PowerShell as Administrator and run:
$gitRoot = 'a=  '
Get-Item "$gitRoot\bin\bash.exe", "$gitRoot\usr\bin\*.exe" -ErrorAction SilentlyContinue | ForEach-Object { Set-ProcessMitigation -Name $_.FullName -Disable ForceRelocateImages }
Then restart Hermes. If the override is blocked or later re-applied, ask your Windows administrator to allow this per-program exception.)rE   r   )r;   r   Úescaped_rootÚdetail_lines       r   Ú_git_bash_aslr_helprJ   A   s_   € ä& tÓ,×4Ñ4°S¸$Ó?€LÙAHÐ-¨g°d°s¨m¨_Ñ=Èb€Kà
�t�fð 6à6A°]ð Cð $�nð %Nð
	Nðr   c                 óî  — | t         v r	t         |    S 	 t        | dddt        gt        d¬«      }|duxr |j                  dk(  }|sc|�0|j
                  xs d› |j                  xs d› �j                  «       n
d	t        d
›d�}|dd t        | <   t        j                  d| |dd «       |t         | <   |S # t        $ r8}t        |«      dd t        | <   t        j                  d| |«       d}Y d}~ŒGd}~ww xY w)zÑTrue if *bash* can launch external MSYS programs (cached per path).
    ``--noprofile --norc`` so a broken login post-install (``Directory
    \drivers\etc``) does not falsely condemn an otherwise usable bash.z--noprofilez--norcz-cT)r"   Úraise_on_spawn_failureNr   r%   zprobe timed out after ÚgÚsiÐ  zbash probe failed for %s: %séÈ   zbash probe error for %s: %sF)r   r   Ú_BASH_EXTERNAL_PROGRAM_PROBEÚ_BASH_PROBE_TIMEOUTr1   r2   Ústderrr3   r   r/   r0   r.   Ústr)r;   r7   ÚokÚcombinedr8   s        r   Ú_bash_startsrV   T   s  € ð Ô!Ñ!Ü! $Ñ'Ð'ðô #Ø�= (¨DÔ2NÐOÜ'ÀôFˆð ˜4ÐÒ: F×$5Ñ$5¸Ñ$:ˆÙØQWÐQc˜6Ÿ=™=Ò.¨BÐ/°·±Ò0CÀÐ/DÐE×KÑKÔMØ5Ô6IÈ!Ð5LÈAÐNð à.6°u¸¨oÔ% dÑ+Ü�L‰LÐ7¸¸xÈÈ¸~ÔNð
  "Ô�tÑØ€Iøô ò Ü*-¨c«(°5°D¨/Ô! $Ñ'Ü�‰Ð2°D¸#Ô>Ø�ûðús   “BB3 Â3	C4Â<.C/Ã/C4)r   r   )r%   )Ú__doc__Úloggingr?   Úplatformr)   r+   Úhermes_cli._subprocess_compatr   r   ÚsystemÚ_IS_WINDOWSÚ	getLoggerr/   r   ÚdictrS   ÚboolÚ__annotations__r   r	   rQ   rP   r   r   r:   rE   rJ   rV   r   r   r   ú<module>ra      sê   ðò8ó Û Û Û Û ç Oàˆh�o‰oÓ 9Ñ,€ð 
ˆ×	Ñ	Ð5Ó	6€à&(Ð �D˜˜d˜‘OÓ (Ø,.Ð ˜4  S ™>Ó .Ø/3Ð ˜}Ó 3ØÐ ð  RÐ àTÐ ðL¨Cð L°Dó Ló)ð(Z˜cð Z có Zñ˜cð ¨Cð ¸ó ð&�sð ˜tô r   