コード例 #1
0
 void ISerializable.Deserialize(ref MemoryReader reader)
 {
     Flags               = (MessageFlags)reader.ReadByte();
     Command             = (MessageCommand)reader.ReadByte();
     _payload_compressed = reader.ReadVarMemory(PayloadMaxSize);
     DecompressPayload();
 }
コード例 #2
0
        public IList <Step> Convert(byte[] data)
        {
            var reader = new MemoryReader(data);
            var count  = reader.ReadInt32();

            var metricOffsets = Enumerable
                                .Range(0, count)
                                // ReSharper disable once AccessToDisposedClosure
                                .Select(i => reader.ReadInt32())
                                .AsList();

            var panels  = reader.ReadBytes(count);
            var padding = count & 1;

            reader.ReadBytes(padding);

            return(Enumerable
                   .Range(0, count)
                   .Select(i => new Step
            {
                MetricOffset = metricOffsets[i],
                Panels = panels[i],
                // ReSharper disable once AccessToDisposedClosure
                ExtraPanels = panels[i] == 0
                        ? reader.ReadByte()
                        : (byte?)null,
                // ReSharper disable once AccessToDisposedClosure
                ExtraPanelInfo = panels[i] == 0
                        ? reader.ReadByte()
                        : (byte?)null
            })
                   .AsList());
        }
コード例 #3
0
            InvocationScript.GetVarSize();      //InvocationScript

            void ISerializable.Deserialize(ref MemoryReader reader)
            {
                ViewNumber       = reader.ReadByte();
                ValidatorIndex   = reader.ReadByte();
                Signature        = reader.ReadMemory(64);
                InvocationScript = reader.ReadVarMemory(1024);
            }
コード例 #4
0
            InvocationScript.GetVarSize();      //InvocationScript

            void ISerializable.Deserialize(ref MemoryReader reader)
            {
                ValidatorIndex     = reader.ReadByte();
                OriginalViewNumber = reader.ReadByte();
                Timestamp          = reader.ReadUInt64();
                InvocationScript   = reader.ReadVarMemory(1024);
            }
コード例 #5
0
        /// <summary>
        /// We want to know if a given method implements a redirected interface.
        /// For example, if we are given the method RemoveAt on a class "A"
        /// which implements the IVector interface (which is redirected
        /// to IList in .NET) then this method would return true. The most
        /// likely reason why we would want to know this is that we wish to hide
        /// (mark private) all methods which implement methods on a redirected
        /// interface.
        /// </summary>
        /// <param name="memberRef">The declaration token for the method</param>
        /// <param name="isIDisposable">
        /// Returns true if the redirected interface is <see cref="IDisposable"/>.
        /// </param>
        /// <returns>True if the method implements a method on a redirected interface.
        /// False otherwise.</returns>
        private bool ImplementsRedirectedInterface(MemberReferenceHandle memberRef, out bool isIDisposable)
        {
            isIDisposable = false;

            MetadataToken parent = peFileReader.GetMemberReference((MemberReferenceHandle)memberRef).Parent;

            TypeReferenceHandle typeRef;

            if (parent.HandleType == HandleType.TypeReference)
            {
                typeRef = (TypeReferenceHandle)parent;
            }
            else if (parent.HandleType == HandleType.TypeSpecification)
            {
                BlobHandle  blob     = peFileReader.GetTypeSpecification((TypeSpecificationHandle)parent);
                MemoryBlock sigBlock = peFileReader.BlobStream.GetMemoryBlockAt(blob);

                if (sigBlock.Length < 2)
                {
                    return(false);
                }

                MemoryReader sig = new MemoryReader(sigBlock);

                if (sig.ReadByte() != (byte)CorElementType.ELEMENT_TYPE_GENERICINST ||
                    sig.ReadByte() != (byte)CorElementType.ELEMENT_TYPE_CLASS)
                {
                    return(false);
                }

                MetadataToken token = SignatureHelpers.DecodeToken(ref sig);

                if (token.HandleType != HandleType.TypeReference)
                {
                    return(false);
                }

                typeRef = (TypeReferenceHandle)token;
            }
            else
            {
                return(false);
            }

            TypeReference reference = peFileReader.GetTypeReference(typeRef);

            if (reference.Namespace.IsNil)
            {
                return(false);
            }

            string name       = peFileReader.StringStream[reference.Name];
            string @namespace = peFileReader.StringStream[reference.Namespace];

            return(WinRTProjectedTypes.IsWinRTTypeReference(name, @namespace, out isIDisposable));
        }
コード例 #6
0
 public virtual void Deserialize(ref MemoryReader reader)
 {
     if (Type != (ConsensusMessageType)reader.ReadByte())
     {
         throw new FormatException();
     }
     BlockIndex     = reader.ReadUInt32();
     ValidatorIndex = reader.ReadByte();
     ViewNumber     = reader.ReadByte();
 }
コード例 #7
0
ファイル: Inventory.cs プロジェクト: 5l1v3r1/MemoryScanner
 public TreeNode(int _baseAddr, MemoryReader _memread)
 {
     BaseAddress      = _baseAddr;
     Memread          = _memread;
     Left             = Memread.ReadInt32(BaseAddress);
     Parrent          = Memread.ReadInt32(BaseAddress + 4);
     Right            = Memread.ReadInt32(BaseAddress + 8);
     Color            = Memread.ReadByte(BaseAddress + 12);
     IsNull           = Memread.ReadByte(BaseAddress + 13);
     Index            = Memread.ReadInt32(BaseAddress + 16);
     ContainerAddress = Memread.ReadInt32(BaseAddress + 20);
 }
コード例 #8
0
        public void Deserialize(ref MemoryReader reader)
        {
            type = (NodeType)reader.ReadByte();
            switch (type)
            {
            case NodeType.BranchNode:
                DeserializeBranch(ref reader);
                Reference = (int)reader.ReadVarInt();
                break;

            case NodeType.ExtensionNode:
                DeserializeExtension(ref reader);
                Reference = (int)reader.ReadVarInt();
                break;

            case NodeType.LeafNode:
                DeserializeLeaf(ref reader);
                Reference = (int)reader.ReadVarInt();
                break;

            case NodeType.Empty:
                break;

            case NodeType.HashNode:
                DeserializeHash(ref reader);
                break;

            default:
                throw new FormatException(nameof(Deserialize));
            }
        }
コード例 #9
0
        public void UpdateCreaturesMethod()
        {
            var tabs          = TabCreatures.Items.SourceCollection.OfType <TabItem>().ToArray();
            var creatureCount = MemoryReader.ReadByte(0x9FA6C1);

            for (int i = 0; i < 8; i++)
            {
                var creatureTab = tabs[i];
                if (creatureTab == null)
                {
                    continue;
                }
                if (i >= creatureCount)
                {
                    creatureTab.Visibility = Visibility.Collapsed;
                    continue;
                }

                creatureTab.Visibility = Visibility.Visible;

                var nameBytes = MemoryReader.ReadBytes(_offsetCreatureName + (i * 40), 18);
                var name      = StringConverter.ToString(nameBytes);
                creatureTab.Header = name;
                _editors[i].Refresh();
            }
        }
コード例 #10
0
 private void ReadingPacket()
 {
     while (running)
     {
         if (memRead.ReadByte(GotPacketAdr.ToInt32()) == 1)
         {
             byte   packetLen = memRead.ReadByte(Addresses.MyAddresses.OutGoingPacketLen.Address);
             byte[] packet    = memRead.ReadBytes(Addresses.MyAddresses.OutGoingBuffer.Address + 8, (uint)packetLen);
             if (OutGoingPacket != null)
             {
                 OutGoingPacket.Invoke(packet);
             }
             memRead.WriteByte(GotPacketAdr.ToInt32(), 0);
         }
     }
 }
コード例 #11
0
        public override VideoState?GetVideoState()
        {
            if (gameSettings.Version < 7)
            {
                return(null);
            }

            var active = MemoryReader.ReadByte(EngineAddr + smushActiveOffset) != 0;

            if (!active)
            {
                return(null);
            }

            var addr = MemoryReader.ReadIntPtr(EngineAddr + smushPlayerOffset);

            if (addr == IntPtr.Zero)
            {
                throw new InconsistentDataException();
            }

            var state = new VideoState();

            state.CurrentFrame = MemoryReader.ReadUInt32(addr + smushPlayerFrameOffset);
            state.FrameCount   = MemoryReader.ReadUInt32(addr + smushPlayerNBFramesOffset);
            state.FrameRate    = new Rational(MemoryReader.ReadInt32(addr + smushPlayerSpeedOffset));
            state.FileName     = ReadComString(addr + smushPlayerSeekFileOffset);
            return(state);
        }
コード例 #12
0
        public void Refresh()
        {
            refreshing = true;

            CheckAllyInvincible.IsChecked  = MemoryReader.ReadByteFlag((int)Offsets.DebugFlags.AllyInvincible);
            CheckEnemyInvincible.IsChecked = MemoryReader.ReadByteFlag((int)Offsets.DebugFlags.EnemyInvincible);
            CheckControlEnemies.IsChecked  = MemoryReader.ReadByteFlag((int)Offsets.DebugFlags.ControlEnemies);
            CheckControlMonsters.IsChecked = MemoryReader.ReadByteFlag((int)Offsets.DebugFlags.ControlMonsters);
            CheckZeroMP.IsChecked          = MemoryReader.ReadByteFlag((int)Offsets.DebugFlags.MPZero);
            CheckInfoOutput.IsChecked      = MemoryReader.ReadByteFlag((int)Offsets.DebugFlags.InfoOutput);
            CheckAlwaysCritical.IsChecked  = MemoryReader.ReadByteFlag((int)Offsets.DebugFlags.AlwaysCritical);
            CheckCritical.IsChecked        = MemoryReader.ReadByteFlag((int)Offsets.DebugFlags.Critical);
            CheckProbability.IsChecked     = MemoryReader.ReadByteFlag((int)Offsets.DebugFlags.Probability100);
            CheckDamageRandom.IsChecked    = MemoryReader.ReadByteFlag((int)Offsets.DebugFlags.DamageRandom);
            CheckDamage1.IsChecked         = MemoryReader.ReadByteFlag((int)Offsets.DebugFlags.Damage1);
            CheckDamage9999.IsChecked      = MemoryReader.ReadByteFlag((int)Offsets.DebugFlags.Damage9999);
            CheckDamage99999.IsChecked     = MemoryReader.ReadByteFlag((int)Offsets.DebugFlags.Damage99999);
            CheckRareDrop.IsChecked        = MemoryReader.ReadByteFlag((int)Offsets.DebugFlags.RareDrop100);
            CheckEXP100x.IsChecked         = MemoryReader.ReadByteFlag((int)Offsets.DebugFlags.EXP100x);
            CheckGil100x.IsChecked         = MemoryReader.ReadByteFlag((int)Offsets.DebugFlags.Gil100x);
            CheckAlwaysOversoul.IsChecked  = MemoryReader.ReadByteFlag((int)Offsets.DebugFlags.AlwaysOversoul);

            var firstAttack = MemoryReader.ReadByte((int)Offsets.DebugFlags.FirstAttack);

            CheckAttackFirst.IsChecked = firstAttack != 0xFF;

            refreshing = false;
        }
コード例 #13
0
 public void Deserialize(ref MemoryReader reader)
 {
     if (reader.ReadUInt32() != Magic)
     {
         throw new FormatException("Wrong magic");
     }
     Compiler = reader.ReadFixedString(64);
     Source   = reader.ReadVarString(256);
     if (reader.ReadByte() != 0)
     {
         throw new FormatException("Reserved bytes must be 0");
     }
     Tokens = reader.ReadSerializableArray <MethodToken>(128);
     if (reader.ReadUInt16() != 0)
     {
         throw new FormatException("Reserved bytes must be 0");
     }
     Script = reader.ReadVarMemory(MaxScriptLength);
     if (Script.Length == 0)
     {
         throw new ArgumentException($"Script can't be empty");
     }
     CheckSum = reader.ReadUInt32();
     if (CheckSum != ComputeChecksum(this))
     {
         throw new FormatException("CRC verification fail");
     }
 }
コード例 #14
0
 void ISerializable.Deserialize(ref MemoryReader reader)
 {
     if (reader.ReadByte() != (byte)Type)
     {
         throw new FormatException();
     }
     DeserializeWithoutType(ref reader, MaxNestingDepth);
 }
コード例 #15
0
        public GameState GetState()
        {
            var state = new GameState();

            state.CutContent = MemoryReader.ReadByte(EngineAddr + cutContentOffset) != 0;
            state.flagData   = readGameFlagData();
            return(state);
        }
コード例 #16
0
 public void Deserialize(ref MemoryReader reader)
 {
     if (reader.ReadByte() != (byte)Type)
     {
         throw new FormatException();
     }
     DeserializeWithoutType(ref reader);
 }
コード例 #17
0
ファイル: ExtensiblePayload.cs プロジェクト: neo-project/neo
 void ISerializable.Deserialize(ref MemoryReader reader)
 {
     ((IVerifiable)this).DeserializeUnsigned(ref reader);
     if (reader.ReadByte() != 1)
     {
         throw new FormatException();
     }
     Witness = reader.ReadSerializable <Witness>();
 }
コード例 #18
0
 void ISerializable.Deserialize(ref MemoryReader reader)
 {
     Action = (WitnessRuleAction)reader.ReadByte();
     if (Action != WitnessRuleAction.Allow && Action != WitnessRuleAction.Deny)
     {
         throw new FormatException();
     }
     Condition = WitnessCondition.DeserializeFrom(ref reader, WitnessCondition.MaxNestingDepth);
 }
コード例 #19
0
 void ISerializable.Deserialize(ref MemoryReader reader)
 {
     Filter = reader.ReadVarMemory(36000);
     K      = reader.ReadByte();
     if (K > 50)
     {
         throw new FormatException();
     }
     Tweak = reader.ReadUInt32();
 }
コード例 #20
0
        private void ButtonMax_Click(object sender, RoutedEventArgs e)
        {
            var currentMax = MemoryReader.ReadByte(
                _partyOffset + (_characterIndex * 0x94) + (int)PartyStatOffset.OverdriveMax);

            MemoryReader.WriteByte(
                _partyOffset + (_characterIndex * 0x94) + (int)PartyStatOffset.OverdriveLevel,
                currentMax);
            Refresh(_characterIndex);
        }
コード例 #21
0
        /// <summary>
        /// Deserializes an <see cref="WitnessCondition"/> object from a <see cref="MemoryReader"/>.
        /// </summary>
        /// <param name="reader">The <see cref="MemoryReader"/> for reading data.</param>
        /// <param name="maxNestDepth">The maximum nesting depth allowed during deserialization.</param>
        /// <returns>The deserialized <see cref="WitnessCondition"/>.</returns>
        public static WitnessCondition DeserializeFrom(ref MemoryReader reader, int maxNestDepth)
        {
            WitnessConditionType type = (WitnessConditionType)reader.ReadByte();

            if (ReflectionCache <WitnessConditionType> .CreateInstance(type) is not WitnessCondition condition)
            {
                throw new FormatException();
            }
            condition.DeserializeWithoutType(ref reader, maxNestDepth);
            return(condition);
        }
コード例 #22
0
        /// <summary>
        /// Deserializes an <see cref="TransactionAttribute"/> object from a <see cref="MemoryReader"/>.
        /// </summary>
        /// <param name="reader">The <see cref="MemoryReader"/> for reading data.</param>
        /// <returns>The deserialized attribute.</returns>
        public static TransactionAttribute DeserializeFrom(ref MemoryReader reader)
        {
            TransactionAttributeType type = (TransactionAttributeType)reader.ReadByte();

            if (ReflectionCache <TransactionAttributeType> .CreateInstance(type) is not TransactionAttribute attribute)
            {
                throw new FormatException();
            }
            attribute.DeserializeWithoutType(ref reader);
            return(attribute);
        }
コード例 #23
0
        public void Refresh()
        {
            _refreshing = true;
            var nameBytes = MemoryReader.ReadBytes(_offsetCreatureName + (_creatureIndex * 40), 18);
            var name      = StringConverter.ToString(nameBytes);

            CreatureName.Text          = name;
            CreatureSize.SelectedIndex = MemoryReader.ReadByte(_statsOffset + (int)Offsets.StatOffsets.Size) - 1;
            _statsPanel.Refresh();
            _creatureAbilities.Refresh();
            _refreshing = false;
        }
コード例 #24
0
        public override VideoState?GetVideoState()
        {
            var playing = MemoryReader.ReadByte(EngineAddr + vqaIsPlayingOffset) != 0;

            if (!playing)
            {
                return(null);
            }

            var state = new VideoState();

            return(state);
        }
コード例 #25
0
        public override VideoState?GetVideoState()
        {
            var  moviePlayerPtrVal = MemoryReader.ReadIntPtr(EngineAddr + moviePlayerOffset);
            bool playing           = MemoryReader.ReadByte(moviePlayerPtrVal + moviePlayingOffset) != 0;

            if (!playing)
            {
                return(null);
            }
            var decoderPtrVal = MemoryReader.ReadIntPtr(moviePlayerPtrVal + movieDecoderOffset);

            return(videoAccessor.ReadDecoder(decoderPtrVal));
        }
コード例 #26
0
        /// <summary>
        /// Deserializes an <see cref="NodeCapability"/> object from a <see cref="MemoryReader"/>.
        /// </summary>
        /// <param name="reader">The <see cref="MemoryReader"/> for reading data.</param>
        /// <returns>The deserialized <see cref="NodeCapability"/>.</returns>
        public static NodeCapability DeserializeFrom(ref MemoryReader reader)
        {
            NodeCapabilityType type       = (NodeCapabilityType)reader.ReadByte();
            NodeCapability     capability = type switch
            {
                NodeCapabilityType.TcpServer or NodeCapabilityType.WsServer => new ServerCapability(type),
                NodeCapabilityType.FullNode => new FullNodeCapability(),
                _ => throw new FormatException(),
            };

            capability.DeserializeWithoutType(ref reader);
            return(capability);
        }
コード例 #27
0
 protected override void DeserializeWithoutType(ref MemoryReader reader)
 {
     Id   = reader.ReadUInt64();
     Code = (OracleResponseCode)reader.ReadByte();
     if (!Enum.IsDefined(typeof(OracleResponseCode), Code))
     {
         throw new FormatException();
     }
     Result = reader.ReadVarMemory(MaxResultSize);
     if (Code != OracleResponseCode.Success && Result.Length > 0)
     {
         throw new FormatException();
     }
 }
コード例 #28
0
        public PersistentData ReadPersistent()
        {
            IntPtr persAddr = EngineAddr + persistentOffset;
            var    pers     = new PersistentData();

            pers.Gender         = (Gender)MemoryReader.ReadByte(persAddr + genderOffset);
            pers.HeroName       = ReadComString(persAddr + heroNameOffset);
            pers.Quest          = (Quest)MemoryReader.ReadByte(persAddr + questOffset);
            pers.HintsEnabled   = MemoryReader.ReadByte(persAddr + hintsAreEnabledOffset) != 0;
            pers.CurrentRoomId  = (RoomId)MemoryReader.ReadByte(persAddr + currentRoomIdOffset);
            pers.PreviousRoomId = (RoomId)MemoryReader.ReadByte(persAddr + previousRoomIdOffset);

            return(pers);
        }
コード例 #29
0
        public AuthenticatorData(byte[] authData)
        {
            // Input validation
            if (authData is null)
            {
                throw new Fido2VerificationException("Authenticator data cannot be null");
            }

            if (authData.Length < MinLength)
            {
                throw new Fido2VerificationException($"Authenticator data is less than the minimum structure length of {MinLength}");
            }

            // Input parsing
            var reader = new MemoryReader(authData);

            RpIdHash = reader.ReadBytes(SHA256HashLenBytes);

            _flags = (AuthenticatorFlags)reader.ReadByte();

            SignCount = reader.ReadUInt32BigEndian();

            // Attested credential data is only present if the AT flag is set
            if (HasAttestedCredentialData)
            {
                // Decode attested credential data, which starts at the next byte past the minimum length of the structure.
                AttestedCredentialData = new AttestedCredentialData(authData.AsMemory(reader.Position), out int bytesRead);

                reader.Advance(bytesRead);
            }

            // Extensions data is only present if the ED flag is set
            if (HasExtensionsData)
            {
                // Read the CBOR object
                var ext = CborObject.Decode(authData.AsMemory(reader.Position), out int bytesRead);

                reader.Advance(bytesRead);

                // Encode the CBOR object back to a byte array.
                Extensions = new Extensions(ext.Encode());
            }

            // There should be no bytes left over after decoding all data from the structure
            if (reader.RemainingBytes != 0)
            {
                throw new Fido2VerificationException("Leftover bytes decoding AuthenticatorData");
            }
        }
コード例 #30
0
        private GameSettings GetGameSettings()
        {
            IntPtr addr = EngineAddr + gameOffset;

            var settings     = new GameSettings();
            var gameIdPtrVal = MemoryReader.ReadIntPtr(addr + gameIdOffset);

            settings.GameId = gameIdPtrVal == IntPtr.Zero ? "" : MemoryReader.ReadNullTermString(gameIdPtrVal);
            var variantPtrVal = MemoryReader.ReadIntPtr(addr + variantOffset);

            settings.Variant   = variantPtrVal == IntPtr.Zero ? "" : MemoryReader.ReadNullTermString(variantPtrVal);
            settings.Version   = MemoryReader.ReadByte(addr + versionOffset);
            settings.HeVersion = MemoryReader.ReadByte(addr + heVersionOffset);
            return(settings);
        }
コード例 #31
0
ファイル: WinMDModule.cs プロジェクト: EkardNT/Roslyn
        /// <summary>
        /// We want to know if a given method implements a redirected interface.
        /// For example, if we are given the method RemoveAt on a class "A" 
        /// which implements the IVector interface (which is redirected
        /// to IList in .NET) then this method would return true. The most 
        /// likely reason why we would want to know this is that we wish to hide
        /// (mark private) all methods which implement methods on a redirected 
        /// interface.
        /// </summary>
        /// <param name="memberRef">The declaration token for the method</param>
        /// <param name="isIDisposable">
        /// Returns true if the redirected interface is <see cref="IDisposable"/>.
        /// </param>
        /// <returns>True if the method implements a method on a redirected interface.
        /// False otherwise.</returns>
        private bool ImplementsRedirectedInterface(MemberReferenceHandle memberRef, out bool isIDisposable)
        {
            isIDisposable = false;

            MetadataToken parent = peFileReader.GetMemberReference((MemberReferenceHandle)memberRef).Parent;

            TypeReferenceHandle typeRef;
            if (parent.HandleType == HandleType.TypeReference)
            {
                typeRef = (TypeReferenceHandle)parent;
            }
            else if (parent.HandleType == HandleType.TypeSpecification)
            {
                BlobHandle blob = peFileReader.GetTypeSpecification((TypeSpecificationHandle)parent);
                MemoryBlock sigBlock = peFileReader.BlobStream.GetMemoryBlockAt(blob);

                if (sigBlock.Length < 2)
                    return false;

                MemoryReader sig = new MemoryReader(sigBlock);

                if (sig.ReadByte() != (byte)CorElementType.ELEMENT_TYPE_GENERICINST ||
                    sig.ReadByte() != (byte)CorElementType.ELEMENT_TYPE_CLASS)
                {
                    return false;
                }

                MetadataToken token = SignatureHelpers.DecodeToken(ref sig);

                if (token.HandleType != HandleType.TypeReference)
                    return false;

                typeRef = (TypeReferenceHandle)token;
            }
            else
            {
                return false;
            }

            TypeReference reference = peFileReader.GetTypeReference(typeRef);
            if (reference.Namespace.IsNil)
            {
                return false;
            }

            string name = peFileReader.StringStream[reference.Name];
            string @namespace = peFileReader.StringStream[reference.Namespace];
            return WinRTProjectedTypes.IsWinRTTypeReference(name, @namespace, out isIDisposable);
        }