Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  

Показать сообщение отдельно

Забанен


Сообщения: 793
Благодарности: 260

Профиль | Цитировать


Код: Выделить весь код
param(
  [Parameter(Mandatory=$true, ValueFromPipeline=$true)]
  [ValidateScript({Test-Path $_})]
  [String]$FileName
)

(Add-Type -Mem @'
  [DllImport("ntdll.dll")]
  internal static extern UInt32 RtlComputeCrc32(
      UInt32 InitialCrc,
      Byte[] Buffer,
      Int32  Length
  );
  
  public static String ComputeCrc32(String file) {
    UInt32 crc32 = 0;
    Int32  read;
    Byte[] buf = new Byte[4096];
    
    FileStream fs = null;
    
    try {
      fs = File.OpenRead(file);
      while((read = fs.Read(buf, 0, buf.Length)) != 0)
        crc32 = RtlComputeCrc32(crc32, buf, read);
    }
    catch (Exception e) {
      Console.WriteLine(e.Message);
    }
    finally {
      if (fs != null) fs.Close();
    }
    
    return (crc32 != 0 ? "0x" + crc32.ToString("X", CultureInfo.CurrentCulture) : "n/a");
  }
'@ -Name RtlCrc32 -NameSpace Crc32 -Using System.IO,
System.Globalization -PassThru)::ComputeCrc32((Convert-Path $FileName))
Это сообщение посчитали полезным следующие участники:

Отправлено: 17:58, 26-05-2015 | #2