private void SynchronizeCryptoHashMessage(NetworkIncomingMessage message) { byte[] synchronize = HandshakeCryptoHashMessage.GetHash(keys.Secret); int offset = Bytes.Find(message.ToBytes(), synchronize); byte[] bytes = message.ToBytes(offset + 20, 20); HandshakeMatch match = new HandshakeMatch(keys.Secret, bytes); found = context.Hashes.Find(match); if (found == null) { context.OnRejected(new HandshakeRejection(match)); connection.CallHandshakeRejected(); connection.Terminate(); return; } keys.Local = new HandshakeKey(HandshakeKeyOwnership.Receiver, keys.Secret, found); keys.Remote = new HandshakeKey(HandshakeKeyOwnership.Initiator, keys.Secret, found); message.Acknowledge(offset + 40); connection.Receive(MeasureCryptoPayloadMessage, HandshakeCryptoPayload.MinimumSize); }
internal async Task <string> RenameThumbnailByStream( KeyValuePair <string, bool> oldFileHashCodeKeyPair, Stream stream) { if (!oldFileHashCodeKeyPair.Value) { return(string.Empty); } byte[] buffer = new byte[FileHash.MaxReadSize]; await stream.ReadAsync(buffer, 0, FileHash.MaxReadSize); var newHashCode = await FileHash.CalculateHashAsync(new MemoryStream(buffer)); if (string.IsNullOrEmpty(newHashCode)) { return(string.Empty); } if (oldFileHashCodeKeyPair.Key == newHashCode) { return(newHashCode); } new ThumbnailFileMoveAllSizes(_thumbnailStorage).FileMove( oldFileHashCodeKeyPair.Key, newHashCode); return(newHashCode); }
public async Task ShouldTriggersHandshakeCompletedOnHandshakeInitiator() { FileHash hash = FileHash.Random(); using (NegotiatorFixture fixture = new NegotiatorFixture()) using (NegotiatorFixturePair pair = await fixture.Create()) { Trigger handler = Trigger.Bind(ref fixture.Hooks.OnHandshakeCompleted, data => { data.Connection.Should().NotBeNull(); if (data.Connection.Identifier == pair.Local.Identifier) { data.Hash.Should().Be(hash); data.Handshake.Should().NotBeNull(); } return(data.Connection.Identifier == pair.Local.Identifier); }); fixture.Negotiator.Start(pair.Local, hash); fixture.Negotiator.Handle(pair.Remote, hash); handler.Wait().Should().BeTrue(); } }
public async Task ShouldTriggersHandshakeRejectedWhenInvalidHashOnHandshakeReceiver() { FileHash valid = FileHash.Random(); FileHash invalid = FileHash.Random(); using (NegotiatorFixture fixture = new NegotiatorFixture()) using (NegotiatorFixturePair pair = await fixture.Create()) { Trigger handler = Trigger.Bind(ref fixture.Hooks.OnHandshakeRejected, data => { data.Connection.Should().NotBeNull(); if (data.Connection.Identifier == pair.Remote.Identifier) { } return(data.Connection.Identifier == pair.Remote.Identifier); }); fixture.Negotiator.Start(pair.Local, valid); fixture.Negotiator.Handle(pair.Remote, invalid); handler.Wait().Should().BeTrue(); } }
public static void CallMetafileRejected(this MetafileHooks hooks, FileHash hash) { hooks.OnMetafileRejected?.Invoke(new MetafileRejected { Hash = hash }); }
public FilePatch(bool isUpdate, DirectorySetup directorySetup, SysFileInfo fileInfo, FileHash hash) { IsUpdate = isUpdate; DirectorySetup = directorySetup; FileInfo = fileInfo; Hash = hash; }
public BitfileContext(FileHash hash, string path) { this.hash = hash; this.path = path; this.destination = new BitfileDestination(this); }
public static void CallDataCompleted(this OmnibusHooks hooks, FileHash hash) { hooks.OnDataCompleted?.Invoke(new DataCompleted { Hash = hash }); }
internal void SaveFileInfo(System.Runtime.Serialization.StreamingContext context) { using (StreamWriter sw = File.AppendText("test.txt")) { sw.WriteLine(FileName.ToString() + ";" + FileHash.ToString() + ";"); } }
private static void Handle(FileHash hash, PeerHash peer, byte[] payload, Action <FileHash, PeerHash, NetworkAddress[]> callback) { BencodedValue value = Bencoder.Decode(payload); byte[] added = value.Find("added", x => x?.Data?.GetBytes()); List <NetworkAddress> peers = new List <NetworkAddress>(); if (added != null) { for (int i = 0; i < added.Length; i += 6) { string host = GetHost(added, i); int port = GetPort(added, i); if (port > 0) { peers.Add(new NetworkAddress(host, port)); } } } if (added?.Length > 0) { callback(hash, peer, peers.ToArray()); } }
public void EmptyFileHashTest() { var created = false; string tempfilename = ""; try { tempfilename = Path.GetTempFileName(); created = true; var filehash = new FileHash(tempfilename); // see: Additional Information of https://virustotal.com/en/file/e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855/analysis/ Assert.Equal(filehash.GetSha1Sum(), "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709"); Assert.Equal(filehash.GetSha256Sum(), "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855"); Assert.Equal(filehash.GetMd5Sum(), "D41D8CD98F00B204E9800998ECF8427E"); } finally { if (created) { File.Delete(tempfilename); } } }
public Handshake(PeerHash local, PeerHash remote, FileHash hash, HandshakeOptions options) { this.local = local; this.remote = remote; this.hash = hash; this.options = options; }
public override int GetHashCode() { int hash = 1; if (FileHash.Length != 0) { hash ^= FileHash.GetHashCode(); } if (CurLocation.Length != 0) { hash ^= CurLocation.GetHashCode(); } if (DstLocation.Length != 0) { hash ^= DstLocation.GetHashCode(); } if (DstType != global::RabbitMsg.Types.DstType.Minio) { hash ^= DstType.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public DownloadHandle( string name, string downloadPath, ref FileHash hash, Loader.OnError onError, int retryCount, int timeoutSeconds, System.Action <int> onProgress, StorageCache storageCache, FileWriter fileWriter) { Debug.Assert(name != null); Debug.Assert(downloadPath != null); Debug.Assert(onError != null); Debug.Assert(storageCache != null); Debug.Assert(fileWriter != null); this.name = name; _onError = onError; _downloadPath = downloadPath; _hash = hash; _restRetryCount = retryCount; _timeoutSeconds = timeoutSeconds; _onProgress = onProgress; _storageCache = storageCache; _fileWriter = fileWriter; }
public MetagetSession(IFileSandbox sandbox, FileHash hash, MetagetData data, MetagetService service) { this.sandbox = sandbox; this.hash = hash; this.data = data; this.service = service; }
/// <summary> /// Gets the first 32 bits of the file hash. /// </summary> /// <param name="obj">The wrapped <see cref="System.IO.FileInfo">FileInfo</see> to check.</param> /// <returns>The first 32 bits of the file hash.</returns> /// <exception cref="PSNotSupportedException">An error occured when hashing the file.</exception> public static FileHash GetFileHash(PSObject obj) { var path = GetFilePath(obj); if (!File.Exists(path)) { return(null); } // Get the hash of the file. var hash = new FileHash(); int ret = NativeMethods.MsiGetFileHash(path, 0, hash); if (NativeMethods.ERROR_SUCCESS != ret) { var ex = new Win32Exception(ret); var message = ex.Message.Replace("%1", path); throw new PSNotSupportedException(message, ex); } else { return(hash); } }
public void OnMessageSent(FileHash hash, PeerHash peer, byte[] payload) { BencodedValue bencoded = Bencoder.Decode(payload); int? message = bencoded.Find("msg_type", x => x?.ToInt32()); int? piece = bencoded.Find("piece", x => x?.ToInt32()); int? size = bencoded.Find("total_size", x => x?.ToInt32()); if (message == 0 && piece != null) { hooks.CallMetadataRequestSent(hash, peer, piece.Value); } if (message == 1 && size != null) { hooks.CallMetadataMeasured(hash, peer, size.Value); } if (message == 1 && piece != null) { byte[] content = Bytes.Copy(payload, bencoded.Data.Length); hooks.MetadataPieceSent(hash, peer, piece.Value, content); } if (message == 2 && piece != null) { hooks.CallMetadataRejectSent(hash, peer, piece.Value); } }
public Metainfo(FileHash hash, MetainfoEntry[] entries, MetainfoHash[] pieces, MetainfoProperties properties) { this.hash = hash; this.entries = entries; this.pieces = pieces; this.properties = properties; }
public static async Task MainAsync(string[] args) { Options options = Argument.Parse <Options>(args); if (options.IsValid()) { FileHash hash = FileHash.Parse(options.Hash); NetworkAddress address = new NetworkAddress(options.Host, Int32.Parse(options.Port)); using (PeerClient client = new PeerClient()) { Notification notification = null; PeerSession session = await client.ConnectAsync(hash, address); Console.WriteLine($"Hash: {hash}"); Console.WriteLine($"Peer: {session.Peer}"); Console.WriteLine(); switch (options.Command) { case "download": session.Download(options.Destination); break; } while (notification?.Type != NotificationType.DataCompleted) { notification = await session.NextAsync(); Console.WriteLine(notification); } } } }
static void Md5HashFiles(string folder) { try { if (!folder.EndsWith("/")) { folder += "/"; } var configFile = System.IO.File.ReadAllLines("./md5.txt"); var hashFiles = new System.Collections.Generic.List <FileHash>(); foreach (var file in configFile) { if (System.IO.File.Exists(folder + file)) { FileHash fh = new FileHash() { File = file }; fh.MD5 = GetFileMD5(folder + file); fh.Size = File.ReadAllBytes(folder + file).Length; hashFiles.Add(fh); } } System.IO.File.WriteAllText(folder + "md5.json", JsonConvert.SerializeObject(hashFiles)); } catch (System.Exception) { } }
private FileIndexItem InsertSearchData() { _iStorage = new FakeIStorage(new List <string> { "/" }, new List <string> { _createAnImage.DbPath }); var fileHashCode = new FileHash(_iStorage).GetHashCode(_createAnImage.DbPath).Key; if (string.IsNullOrEmpty(_query.GetSubPathByHash(fileHashCode))) { _query.AddItem(new FileIndexItem { FileName = "/", ParentDirectory = "/", IsDirectory = true }); _query.AddItem(new FileIndexItem { FileName = _createAnImage.FileName, ParentDirectory = "/", FileHash = fileHashCode, ColorClass = ColorClassParser.Color.Winner, // 1 }); } return(_query.GetObjectByFilePath(_createAnImage.DbPath)); }
public static void TMain(string[] args) { FileHash fileHash = new FileHash(); string output = FileHash.md5str("Hello"); Console.WriteLine(output); }
public static void CallMetafileMeasured(this MetagetHooks hooks, FileHash hash, int size) { hooks.OnMetafileMeasured?.Invoke(new MetafileMeasured { Hash = hash, Size = size }); }
/// <summary> /// Construct a FileEntry. /// </summary> public FileEntry(NameId name, long sizeInBytes, ContentFlags contentFlags, FileHash hash, int rewriteCount) { Path = name; SizeInBytes = sizeInBytes; ContentFlags = contentFlags; Hash = hash; RewriteCount = rewriteCount; }
public override bool Equals(object obj) { if (obj is AssemblyDescriptor ad) { return(FileHash.Equals(ad.FileHash)); } return(false); }
public static void CallBlockWritten(this RepositoryHooks hooks, FileHash hash, BlockIndex block) { hooks.OnBlockWritten?.Invoke(new BlockWritten { Hash = hash, Block = block }); }
public static void CallDataVerified(this RepositoryHooks hooks, FileHash hash, Bitfield bitfield) { hooks.OnDataVerified?.Invoke(new DataVerified { Hash = hash, Bitfield = bitfield }); }
public static void CallDataAllocated(this RepositoryHooks hooks, FileHash hash, string directory) { hooks.OnDataAllocated?.Invoke(new DataAllocated { Hash = hash, Directory = directory }); }
public static void CallPieceRejected(this RepositoryHooks hooks, FileHash hash, PieceInfo piece) { hooks.OnPieceRejected?.Invoke(new PieceRejected { Hash = hash, Piece = piece }); }
public static void CallPieceCompleted(this OmnibusHooks hooks, FileHash hash, int piece) { hooks.OnPieceCompleted?.Invoke(new PieceCompleted { Hash = hash, Piece = piece }); }
public void Serialize(FileFormats.Unreal.ISerializer stream) { if (stream.Mode == FileFormats.Unreal.SerializeMode.Reading) { uint a = 0, b = 0, c = 0, d = 0; stream.Serialize(ref a); stream.Serialize(ref b); stream.Serialize(ref c); stream.Serialize(ref d); this.Hash = new FileHash(a, b, c, d); } else { throw new NotSupportedException(); } stream.Serialize(ref this.Instances); }