# ============================================================ # PROBE HFSQL SHUTDOWN CRASH — diagnostic isolé du crash natif # wd300vm64.dll à la fermeture du process. # # Objectif : reproduire le crash SANS Omika.Api, sans ASP.NET, # sans Generic Host, sans DI, sans repository, sans RSA/QR/licence. # # Compatible Windows PowerShell 5.1 (.NET Framework 4.x). # Aucune dépendance applicative. # # TROIS MODES : # NoConnection : aucune connexion OLE DB (contrôle). # OpenClose : Open + SELECT + Close + Dispose. # OpenCloseReleasePool : idem + OleDbConnection.ReleaseObjectPool(). # # Sécurité : le mot de passe est demandé interactivement # (Read-Host -AsSecureString), converti en texte uniquement en # mémoire, puis le BSTR est nettoyé (ZeroFreeBSTR). Ni le mot de # passe ni la chaîne de connexion complète ne sont jamais affichés. # ============================================================ param( [Parameter(Mandatory = $true)] [ValidateSet('NoConnection', 'OpenClose', 'OpenCloseReleasePool')] [string]$Mode, [Parameter(Mandatory = $true)] [string]$Server, [int]$Port = 4900, [Parameter(Mandatory = $true)] [string]$Database, [Parameter(Mandatory = $true)] [string]$User, [string]$Query = 'SELECT 1' ) $ErrorActionPreference = 'Stop' Write-Host '=== PROBE HFSQL SHUTDOWN CRASH (PS 5.1) ===' Write-Host "Mode : $Mode" Write-Host "Serveur : ${Server}:${Port}" Write-Host "Base : $Database" Write-Host "Compte : $User" Write-Host '' # ------------------------------------------------------------ # MODE A : aucune connexion OLE DB n'est créée. # ------------------------------------------------------------ if ($Mode -eq 'NoConnection') { Write-Host 'PROBE_TERMINE (NoConnection)' Write-Host '>>> Le process se termine sans avoir touche a HFSQL. <<<' exit 0 } # ------------------------------------------------------------ # Mot de passe interactif (jamais affiché). # ------------------------------------------------------------ $secure = Read-Host -Prompt 'Mot de passe HFSQL' -AsSecureString $plain = '' if ($null -ne $secure -and $secure.Length -gt 0) { $bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure) try { $plain = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr) } finally { # Nettoyage du BSTR (mémoire non managée). [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr) } $secure.Dispose() } # ------------------------------------------------------------ # Construction de la chaîne de connexion (jamais affichée). # ------------------------------------------------------------ $csb = New-Object System.Data.OleDb.OleDbConnectionStringBuilder $csb.Provider = 'PCSOFT.HFSQL' $csb.DataSource = "$($Server):$($Port)" $csb['Initial Catalog'] = $Database $csb['User ID'] = $User if ($plain -ne '') { $csb['Password'] = $plain } $conn = New-Object System.Data.OleDb.OleDbConnection($csb.ConnectionString) # ------------------------------------------------------------ # Open() # ------------------------------------------------------------ try { $conn.Open() Write-Host "Ouverture OK : $($conn.State)" } catch { Write-Host "ERREUR_OUVERTURE : $($_.Exception.GetType().Name) : $($_.Exception.Message)" try { $conn.Dispose() } catch { } $plain = $null exit 2 } # ------------------------------------------------------------ # SELECT lecture seule, puis fermeture reader / command. # ------------------------------------------------------------ $cmd = $null $reader = $null try { $cmd = $conn.CreateCommand() $cmd.CommandText = $Query $reader = $cmd.ExecuteReader() $rows = 0 while ($reader.Read()) { $rows++ } Write-Host "SELECT_OK : $rows ligne(s)" } catch { Write-Host "ERREUR_SELECT : $($_.Exception.GetType().Name) : $($_.Exception.Message)" } finally { if ($null -ne $reader) { try { $reader.Close() } catch { } try { $reader.Dispose() } catch { } } if ($null -ne $cmd) { try { $cmd.Dispose() } catch { } } } # ------------------------------------------------------------ # Close() / Dispose() # ------------------------------------------------------------ try { if ($conn.State -eq [System.Data.ConnectionState]::Open) { $conn.Close() } } catch { Write-Host "ERREUR_CLOSE : $($_.Exception.GetType().Name) : $($_.Exception.Message)" } $conn.Dispose() Write-Host 'Connexion close/disposee.' # ------------------------------------------------------------ # MODE C : ReleaseObjectPool() avant la sortie. # ------------------------------------------------------------ if ($Mode -eq 'OpenCloseReleasePool') { [System.Data.OleDb.OleDbConnection]::ReleaseObjectPool() Write-Host 'ReleaseObjectPool() appele.' } # ------------------------------------------------------------ # Nettoyage mémoire du mot de passe (best effort côté managé). # ------------------------------------------------------------ $plain = $null $secure = $null Write-Host "PROBE_TERMINE ($Mode)" Write-Host '>>> Le process se termine maintenant. Observer un eventuel crash natif (wd300vm64.dll). <<<'