Exemplo n.º 1
1
        static void Main(string[] args)
        {
            ModelManager.Add(typeof(LoginMsg), delegate() { return new LoginMsg(); });
            Person person = new Person();
            person.id = 10;
            person.name = "一阿萨德法萨芬";
            person.addr = "沃尔沃人情味儿阿是否是";

            LoginMsg msg = new LoginMsg();
            msg.id = 1;
            msg.name = "asdfasdfasfasasdfsadfsadfsafsaf";
            msg.info = person;
            msg.infos.Add(person);

            MemoryStream stream = new MemoryStream();
            Encoder encoder = new Encoder(stream);
            encoder.Encode(msg);

            Decoder decoder = new Decoder(stream);
            LoginMsg result = decoder.Decode<LoginMsg>();
        }
Exemplo n.º 2
0
        public void Decode_CorrectlyDecodesInstructions(UInt64 raw, InstructionType expectedOp, Int32 expecteOperand)
        {
            // Arrange
            var decoder = new Decoder();

            // Act
            var instruction = decoder.Decode(raw);

            // Assert
            instruction.Type.Should().Be(expectedOp);
            instruction.Operand.Should().Be(expecteOperand);
        }
        public void TestWithPointers()
        {
            var path = Path.Combine("..", "..", "TestData", "MaxMind-DB", "test-data", "maps-with-pointers.raw");
            using (var database = new ArrayReader(path))
            {
                var decoder = new Decoder(database, 0);

                var node = decoder.Decode(0).Node;
                Assert.That(node.Value<string>("long_key"), Is.EqualTo("long_value1"));

                node = decoder.Decode(22).Node;
                Assert.That(node.Value<string>("long_key"), Is.EqualTo("long_value2"));

                node = decoder.Decode(37).Node;
                Assert.That(node.Value<string>("long_key2"), Is.EqualTo("long_value1"));

                node = decoder.Decode(50).Node;
                Assert.That(node.Value<string>("long_key2"), Is.EqualTo("long_value2"));

                node = decoder.Decode(55).Node;
                Assert.That(node.Value<string>("long_key"), Is.EqualTo("long_value1"));

                node = decoder.Decode(57).Node;
                Assert.That(node.Value<string>("long_key2"), Is.EqualTo("long_value2"));
            }
        }
        public void TestWithPointers()
        {
            var path = Path.Combine(new[] { "..", "..", "TestData", "MaxMind-DB", "test-data", "maps-with-pointers.raw" });
            var stream = new ThreadLocal<Stream>(() => new MemoryStream(File.ReadAllBytes(path)));
            using (stream)
            {
                var decoder = new Decoder(stream, 0);

                var node = decoder.Decode(0).Node;
                Assert.That(node.Value<string>("long_key"), Is.EqualTo("long_value1"));

                node = decoder.Decode(22).Node;
                Assert.That(node.Value<string>("long_key"), Is.EqualTo("long_value2"));

                node = decoder.Decode(37).Node;
                Assert.That(node.Value<string>("long_key2"), Is.EqualTo("long_value1"));

                node = decoder.Decode(50).Node;
                Assert.That(node.Value<string>("long_key2"), Is.EqualTo("long_value2"));

                node = decoder.Decode(55).Node;
                Assert.That(node.Value<string>("long_key"), Is.EqualTo("long_value1"));

                node = decoder.Decode(57).Node;
                Assert.That(node.Value<string>("long_key2"), Is.EqualTo("long_value2"));
            }
        }
Exemplo n.º 5
0
        private void OnMessage(object sender, MessageEventArgs e)
        {
#if SOCKET_IO_DEBUG
            debugMethod.Invoke("[SocketIO] Raw message: " + e.Data);
#endif
            Packet packet = decoder.Decode(e);

            switch (packet.enginePacketType)
            {
            case EnginePacketType.OPEN: HandleOpen(packet); break;

            case EnginePacketType.CLOSE: EmitEvent("close"); break;

            case EnginePacketType.PING: HandlePing(); break;

            case EnginePacketType.PONG: HandlePong(); break;

            case EnginePacketType.MESSAGE: HandleMessage(packet); break;
            }
        }
Exemplo n.º 6
0
        public override Avr32Instruction DisassembleInstruction()
        {
            this.addr = rdr.Address;
            if (!rdr.TryReadBeUInt16(out ushort uInstr))
            {
                return(null);
            }
            this.iclass    = InstrClass.None;
            this.condition = Avr32Condition.al;
            ops.Clear();
            var instr = rootDecoder.Decode(uInstr, this);

            if (uInstr == 0)
            {
                instr.InstructionClass |= InstrClass.Zero;
            }
            instr.Address = addr;
            instr.Length  = (int)(rdr.Address - addr);
            return(instr);
        }
        public static void TestTypeDecoding <T>(Dictionary <T, byte[]> tests, bool useShouldBe = false) where T : class
        {
            foreach (var entry in tests)
            {
                var expect = entry.Key;
                var input  = entry.Value;

                using var database = new ArrayBuffer(input);
                var decoder = new Decoder(database, 0, false);
                var val     = decoder.Decode <T>(0, out _);
                if (useShouldBe)
                {
                    val.Should().Be(expect);
                }
                else
                {
                    val.Should().BeEquivalentTo(expect, options => options.RespectingRuntimeTypes());
                }
            }
        }
Exemplo n.º 8
0
 public override X86Instruction Decode(uint op, X86Disassembler disasm)
 {
     if (disasm.decodingContext.F2Prefix)
     {
         disasm.decodingContext.F2Prefix = false;
         disasm.decodingContext.F3Prefix = false;
         var instr = decoderF2.Decode(op, disasm);
         return(instr);
     }
     else if (disasm.decodingContext.F3Prefix)
     {
         disasm.decodingContext.F2Prefix = false;
         disasm.decodingContext.F3Prefix = false;
         var instr = decoderF3.Decode(op, disasm);
         return(instr);
     }
     else if (disasm.decodingContext.SizeOverridePrefix)
     {
         if (disasm.isRegisterExtensionEnabled && disasm.decodingContext.RegisterExtension.FlagWideValue)
         {
             disasm.decodingContext.dataWidth = PrimitiveType.Word64;
             return(decoder66Wide.Decode(op, disasm));
         }
         else
         {
             disasm.decodingContext.dataWidth = disasm.defaultDataWidth;
             return(decoder66.Decode(op, disasm));
         }
     }
     else
     {
         if (disasm.isRegisterExtensionEnabled && disasm.decodingContext.RegisterExtension.FlagWideValue)
         {
             return(decoderWide.Decode(op, disasm));
         }
         else
         {
             return(this.decoderBase.Decode(op, disasm));
         }
     }
 }
Exemplo n.º 9
0
        public void ShouldAllowReceivingNeverIndexedFieldsWithIndexedName()
        {
            var decoder = new Decoder();

            var buf = new Buffer();

            buf.WriteByte(0x12); // Never indexed, header index 2
            buf.WriteByte(0x03); // 3 bytes
            buf.WriteString("abc");
            var consumed = decoder.Decode(buf.View);

            Assert.True(decoder.Done);
            Assert.Equal(":method", decoder.HeaderField.Name);
            Assert.Equal("abc", decoder.HeaderField.Value);
            Assert.True(decoder.HeaderField.Sensitive);
            Assert.Equal(42, decoder.HeaderSize);
            Assert.Equal(5, consumed);
            Assert.True(decoder.HasInitialState);
            Assert.Equal(decoder.DynamicTableLength, 0);
            Assert.Equal(decoder.DynamicTableUsedSize, 0);
        }
Exemplo n.º 10
0
        public void ReceiveBytes(byte[] encodedData, int length)
        {
            if (decoder != null)
            {
                var pcmLength = decoder.Decode(encodedData, length, pcmBuffer);

                if (audioClipData == null || audioClipData.Length != pcmLength)
                {
                    // assume that pcmLength will not change.
                    audioClipData = new float[pcmLength];
                }
                Array.Copy(pcmBuffer, audioClipData, pcmLength);
                source.clip.SetData(audioClipData, samplePos);
                samplePos += pcmLength;
                if (!source.isPlaying && samplePos > audioClipLength / 2)
                {
                    source.Play();
                }
                samplePos %= audioClipLength;
            }
        }
Exemplo n.º 11
0
        private void AnalyzeFunctions()
        {
            foreach (Function function in Functions)
            {
                int         offset      = function.StartOffset;
                Instruction instruction = Decoder.Decode(offset);

                Debug.Assert(instruction is InstructionFnBegin);

                var fnBegin = instruction as InstructionFnBegin;
                if (fnBegin != null)
                {
                    function.ParameterCount = fnBegin.ParameterCount;
                    function.VariableCount  = fnBegin.VarCount;

                    function.MainCodePath.StartOffset = function.Instruction.Offset + function.Instruction.InstructionLength;

                    AnalyzeCodePath(function.MainCodePath);
                }
            }
        }
Exemplo n.º 12
0
        public static void Decode(NvdecDecoderContext context, ResourceManager rm, ref NvdecRegisters state)
        {
            PictureInfo         pictureInfo = rm.Gmm.DeviceRead <PictureInfo>(state.SetPictureInfoOffset);
            ReadOnlySpan <byte> bitstream   = rm.Gmm.DeviceGetSpan(state.SetBitstreamOffset, (int)pictureInfo.VLDBufferSize);

            Decoder decoder = context.GetVp8Decoder();

            ISurface outputSurface = rm.Cache.Get(decoder, 0, 0, pictureInfo.FrameWidth, pictureInfo.FrameHeight);

            Vp8PictureInfo info = pictureInfo.Convert();

            uint lumaOffset   = state.SetSurfaceLumaOffset[3];
            uint chromaOffset = state.SetSurfaceChromaOffset[3];

            if (decoder.Decode(ref info, outputSurface, bitstream))
            {
                SurfaceWriter.Write(rm.Gmm, outputSurface, lumaOffset, chromaOffset);
            }

            rm.Cache.Put(outputSurface);
        }
Exemplo n.º 13
0
        // TODO: Extract all AMD64-related logics to other helper class

        public static unsafe void HijackManagedMethod(MethodInfo target, MethodInfo hook, HijackContextBase context)
        {
            // Make sure method is jitted already.
            RuntimeHelpers.PrepareMethod(hook.MethodHandle);

            Byte *pTargetMethod = (Byte *)target.MethodHandle.GetFunctionPointer();

            // TODO: make allocation free way to allocate decoder.
            Decoder d = Decoder.Create(64, new BytePtrCodeReader(pTargetMethod));

            Instruction inst = d.Decode();

            switch (inst.Code)
            {
            case Code.Jmp_rel32_64:
                pTargetMethod += inst.Immediate32to64;
                break;
            }

            HijackUnmanagedMethod(pTargetMethod, hook, context);
        }
Exemplo n.º 14
0
            public override X86Instruction Decode(uint op, X86Disassembler disasm)
            {
                if (!disasm.TryEnsureModRM(out byte modRm))
                {
                    return(disasm.CreateInvalidInstruction());
                }
                if (mutators != null)
                {
                    foreach (var m in this.mutators)
                    {
                        if (!m(op, disasm))
                        {
                            return(disasm.CreateInvalidInstruction());
                        }
                    }
                }

                Decoder decoder = group[((modRm >> 3) & 0x07)];

                return(decoder.Decode(op, disasm));
            }
Exemplo n.º 15
0
            public override bool Decode(X86Disassembler disasm, byte op)
            {
                if (!disasm.TryEnsureModRM(out byte modRm))
                {
                    return(false);
                }
                if (mutators != null)
                {
                    foreach (var m in this.mutators)
                    {
                        if (!m(op, disasm))
                        {
                            return(false);
                        }
                    }
                }

                Decoder decoder = group[((modRm >> 3) & 0x07)];

                return(decoder.Decode(disasm, op));
            }
Exemplo n.º 16
0
        /// <summary>
        /// Decodes an encoded frame.
        /// </summary>
        /// <param name="encodedFrame">The encoded frame.</param>
        /// <returns></returns>
        public override VideoBuffer Decode(byte[] encodedFrame)
        {
            if (_Decoder == null)
            {
                _Decoder = new Decoder();
            }

            if (_Padep.SequenceNumberingViolated)
            {
                _Decoder.NeedsKeyFrame = true;
                return(null);
            }

            var frame = _Decoder.Decode(encodedFrame);

            if (frame == null)
            {
                return(null);
            }

            var planes = new List <VideoPlane>();

            if (frame.Plane1 != null)
            {
                planes.Add(new VideoPlane(frame.Plane1.Data, 0, frame.Plane1.Index, frame.Plane1.Length));
            }
            if (frame.Plane2 != null)
            {
                planes.Add(new VideoPlane(frame.Plane2.Data, 0, frame.Plane2.Index, frame.Plane2.Length));
            }
            if (frame.Plane3 != null)
            {
                planes.Add(new VideoPlane(frame.Plane3.Data, 0, frame.Plane3.Index, frame.Plane3.Length));
            }
            if (frame.Plane4 != null)
            {
                planes.Add(new VideoPlane(frame.Plane4.Data, 0, frame.Plane4.Index, frame.Plane4.Length));
            }
            return(new VideoBuffer(frame.Width, frame.Height, frame.Rotate, planes.ToArray()));
        }
Exemplo n.º 17
0
        public void ReceiveValidInput_SetDecoderList(string input)
        {
            var inputList = new List <string> {
                input
            };

            uut.Decode(inputList);

            Assert.That(uut.OldPlaneList[0].XCoordinate, Is.EqualTo(CorrectPlane.XCoordinate));
            Assert.That(uut.OldPlaneList[0].YCoordinate, Is.EqualTo(CorrectPlane.YCoordinate));
            Assert.That(uut.OldPlaneList[0].LastUpdate, Is.EqualTo(CorrectPlane.LastUpdate));
            Assert.That(uut.OldPlaneList[0].Tag, Is.EqualTo(CorrectPlane.Tag));
            Assert.That(uut.OldPlaneList[0].Altitude, Is.EqualTo(CorrectPlane.Altitude));
            Assert.That(uut.OldPlaneList[0].Direction, Is.EqualTo(CorrectPlane.Direction));
            Assert.That(uut.OldPlaneList[0].Speed, Is.EqualTo(CorrectPlane.Speed));
        }
Exemplo n.º 18
0
        private void GenerateFunctions()
        {
            int offset = 0;

            while (offset < Decoder.File.Header.CodeSize)
            {
                Instruction instruction = Decoder.Decode(offset);
                offset += instruction.InstructionLength;

                if (instruction is InstructionFnBegin)
                {
                    var function = new Function();
                    function.Instruction = instruction;
                    function.StartOffset = instruction.Offset;
                    function.Name        = (function.StartOffset == 0)
                                        ? "main"
                                        : string.Format("sub_{0:x}", instruction.Offset);
                    FunctionTargets.Add(instruction.Offset, function);
                    Functions.Add(function);
                }
            }
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            Encoder encoder = new Encoder();
            Decoder decoder = new Decoder();
            string  input   = string.Empty;
            int     length  = input.Length;
            char    convertType;

            Console.Write("Do you want to Encode (E) or Decode (D)? ");
            convertType = char.Parse(Console.ReadLine());
            while (convertType != 'd' && convertType != 'D' && convertType != 'e' && convertType != 'E')
            {
                Console.Write("\nPlease try again (E or D): ");
                convertType = char.Parse(Console.ReadLine());
            }
            if (convertType == 'e' || convertType == 'E') //e || E
            {
                Console.Write("Please enter a character to encode (\"finish\" to finish): ");
                input = Console.ReadLine();
                encoder.Encode(input);
            }
            else if (convertType == 'd' || convertType == 'D') //d || D
            {
                Console.Write("Please enter the requested numbers to decode (\"finish\" to finish): ");
                input = Console.ReadLine();
                decoder.Decode(input);
            }

            if (convertType == 'e' || convertType == 'E')
            {
                Console.WriteLine(encoder);
            }
            if (convertType == 'd' || convertType == 'D')
            {
                Console.WriteLine(decoder);
            }
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
Exemplo n.º 20
0
 public override bool Decode(X86Disassembler disasm, byte op)
 {
     if (disasm.decodingContext.F2Prefix)
     {
         var instr = decoderF2.Decode(disasm, op);
         disasm.decodingContext.F2Prefix = false;
         disasm.decodingContext.F3Prefix = false;
         return(instr);
     }
     else if (disasm.decodingContext.F3Prefix)
     {
         var instr = decoderF3.Decode(disasm, op);
         disasm.decodingContext.F2Prefix = false;
         disasm.decodingContext.F3Prefix = false;
         return(instr);
     }
     else if (disasm.decodingContext.SizeOverridePrefix)
     {
         if (disasm.isRegisterExtensionEnabled && disasm.decodingContext.RegisterExtension.FlagWideValue)
         {
             return(decoder66Wide.Decode(disasm, op));
         }
         else
         {
             return(decoder66.Decode(disasm, op));
         }
     }
     else
     {
         if (disasm.isRegisterExtensionEnabled && disasm.decodingContext.RegisterExtension.FlagWideValue)
         {
             return(decoderWide.Decode(disasm, op));
         }
         else
         {
             return(this.decoderBase.Decode(disasm, op));
         }
     }
 }
Exemplo n.º 21
0
        static int Main(string[] args)
        {
            ArgsParser ArgsParser = new ArgsParser();

            if (!ArgsParser.Validate(args))
            {
                return(0);
            }

            PdfReader PdfReader = new PdfReader(ArgsParser.GetBookPath());
            PdfParser PdfParser = new PdfParser(PdfReader);

            string result = "No action has been executed";

            if (ArgsParser.GetMode() == ArgsParser.Mode.Encode)
            {
                try {
                    Encoder Encoder = new Encoder(PdfParser);
                    result = string.Format("Encoded text: {0}", Encoder.Encode(ArgsParser.GetText()));
                } catch (EncodeException e) {
                    result = e.Message;
                } catch (Exception e) {
                    result = "Couldn't encode this string. ";
                }
            }
            if (ArgsParser.GetMode() == ArgsParser.Mode.Decode)
            {
                try {
                    Decoder Decoder = new Decoder(PdfParser);
                    result = string.Format("Decoded text: {0}", Decoder.Decode(ArgsParser.GetText()));
                } catch (Exception e) {
                    result = "Couldn't decode this string.";
                }
            }

            Console.WriteLine(result);

            return(1);
        }
Exemplo n.º 22
0
        public void Process(File file, TextWriter writer)
        {
            var decoder = new Decoder(file);

            int length = file.Code.Length;
            int offset = 0;

            while (offset < length)
            {
                Instruction instruction = decoder.Decode(offset);
                writer.WriteLine(instruction.ToString());
                //instruction.ToString();

                offset += instruction.InstructionLength;
            }

            /*
             * foreach (uint item in Scruff.Script.Natives.UnknownNatives)
             * {
             *  writer.WriteLine(string.Format("0x{0:x}", item));
             * }
             * */
        }
Exemplo n.º 23
0
 public override bool Decode(X86Disassembler disasm, byte op)
 {
     if (!disasm.TryEnsureModRM(out byte modRm))
     {
         return(false);
     }
     if ((modRm & 0xC0) == 0xC0)
     {
         var i = modRm & 0x07;
         if (i < regDecoders.Length)
         {
             return(regDecoders[i].Decode(disasm, op));
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(memDecoder.Decode(disasm, op));
     }
 }
Exemplo n.º 24
0
            public override bool Decode(X86Disassembler disasm, byte op)
            {
                int grp = Group - 1;

                if (!disasm.TryEnsureModRM(out byte modRm))
                {
                    return(false);
                }
                if (mutators != null)
                {
                    foreach (var m in this.mutators)
                    {
                        if (!m(op, disasm))
                        {
                            return(false);
                        }
                    }
                }

                Decoder opRec = s_aOpRecGrp[grp * 8 + ((modRm >> 3) & 0x07)];

                return(opRec.Decode(disasm, op));
            }
Exemplo n.º 25
0
        public void PlayAudio(OpusData opusData)
        {
            if (opusData == null)
            {
                return;
            }

            var pcmLength = decoder.Decode(opusData.Bytes, opusData.EncodedLength, pcmBuffer);

            if (audioClipData == null || audioClipData.Length != pcmLength)
            {
                audioClipData = new float[pcmLength];
            }
            Array.Copy(pcmBuffer, audioClipData, pcmLength);
            audioSource.clip.SetData(audioClipData, head);
            head += pcmLength;

            if (!audioSource.isPlaying && head > audioClipLength / 2)
            {
                audioSource.Play();
            }
            head %= audioClipLength;
        }
Exemplo n.º 26
0
        public void KeepAliveTest()
        {
            var res = Decoder.Decode("376600").First();

            Assert.Equal(false, res.Occupied);
            Assert.Null(res.RecalibrationOrReboot);
            Assert.Null(res.VehicleCount);

            res = Decoder.Decode("376601").First();
            Assert.Equal(true, res.Occupied);
            Assert.Null(res.RecalibrationOrReboot);
            Assert.Null(res.VehicleCount);

            res = Decoder.Decode("370080").First();
            Assert.Null(res.VehicleCount);
            Assert.Equal(true, res.RecalibrationOrReboot);
            Assert.Null(res.Occupied);

            res = Decoder.Decode("370020").First();
            Assert.Equal(32, res.VehicleCount);
            Assert.Null(res.RecalibrationOrReboot);
            Assert.Null(res.Occupied);
        }
Exemplo n.º 27
0
        public static ReadOnlySpan <byte> ExtractCode(ReadOnlySpan <byte> code, bool compute, out int headerSize)
        {
            headerSize = compute ? 0 : HeaderSize;

            Block[] cfg = Decoder.Decode(code, (ulong)headerSize);

            if (cfg == null)
            {
                return(code);
            }

            ulong endAddress = 0;

            foreach (Block block in cfg)
            {
                if (endAddress < block.EndAddress)
                {
                    endAddress = block.EndAddress;
                }
            }

            return(code.Slice(0, headerSize + (int)endAddress));
        }
Exemplo n.º 28
0
        private static void PreSetup(string gameRoot)
        {
            System.Net.ServicePointManager.Expect100Continue = true;
            System.Net.ServicePointManager.SecurityProtocol |= (System.Net.SecurityProtocolType) 3072;

            GameAssembly_Path = Path.Combine(gameRoot, "GameAssembly.dll");

            AssemblyFolder = Path.Combine(gameRoot, "MelonLoader", "Managed");

            MSCORLIB_Path = Path.Combine(AssemblyFolder, "mscorlib.dll");

            BaseFolder = SetupDirectory(Path.Combine(Path.Combine(Path.Combine(gameRoot, "MelonLoader"), "Dependencies"), "AssemblyGenerator"));

            Il2CppDumper.BaseFolder             = SetupDirectory(Path.Combine(BaseFolder, "Il2CppDumper"));
            Il2CppAssemblyUnhollower.BaseFolder = SetupDirectory(Path.Combine(BaseFolder, "Il2CppAssemblyUnhollower"));
            UnityDependencies.BaseFolder        = SetupDirectory(Path.Combine(BaseFolder, "UnityDependencies"));

            localConfigPath = Path.Combine(BaseFolder, "config.json");
            if (File.Exists(localConfigPath))
            {
                localConfig = Decoder.Decode(File.ReadAllText(localConfigPath)).Make <LocalConfig>();
            }
        }
Exemplo n.º 29
0
        public void ShouldAllowReceivingNeverIndexedFieldsWithNotIndexedName()
        {
            var decoder = new Decoder();

            var buf = new Buffer();

            buf.WriteByte(0x10); // Never indexed, no name index
            buf.WriteByte(0x02);
            buf.WriteString("de");
            buf.WriteByte(0x03);
            buf.WriteString("fgh");
            var consumed = decoder.Decode(buf.View);

            Assert.True(decoder.Done);
            Assert.Equal("de", decoder.HeaderField.Name);
            Assert.Equal("fgh", decoder.HeaderField.Value);
            Assert.True(decoder.HeaderField.Sensitive);
            Assert.Equal(37, decoder.HeaderSize);
            Assert.Equal(8, consumed);
            Assert.True(decoder.HasInitialState);
            Assert.Equal(decoder.DynamicTableLength, 0);
            Assert.Equal(decoder.DynamicTableUsedSize, 0);
        }
 public override X86Instruction Decode(X86Disassembler disasm, byte op, string opFormat)
 {
     if (!disasm.TryEnsureModRM(out byte modRm))
     {
         return(null);
     }
     if ((modRm & 0xC0) == 0xC0)
     {
         var i = modRm & 0x07;
         if (i < regDecoders.Length)
         {
             return(regDecoders[i].Decode(disasm, op, opFormat));
         }
         else
         {
             return(disasm.Illegal());
         }
     }
     else
     {
         return(memDecoder.Decode(disasm, op, opFormat));
     }
 }
Exemplo n.º 31
0
 public override X86Instruction Decode(uint op, X86Disassembler disasm)
 {
     if (!disasm.TryEnsureModRM(out byte modRm))
     {
         return(disasm.CreateInvalidInstruction());
     }
     if ((modRm & 0xC0) == 0xC0)
     {
         var i = modRm & 0x07;
         if (i < regDecoders.Length)
         {
             return(regDecoders[i].Decode(op, disasm));
         }
         else
         {
             return(disasm.CreateInvalidInstruction());
         }
     }
     else
     {
         return(memDecoder.Decode(op, disasm));
     }
 }
 public override X86Instruction Decode(X86Disassembler disasm, byte op, string opFormat)
 {
     if (disasm.currentDecodingContext.F2Prefix)
     {
         var instr = decoderF2.Decode(disasm, op, opFormat);
         instr.repPrefix = 0;
         return(instr);
     }
     else if (disasm.currentDecodingContext.F3Prefix)
     {
         var instr = decoderF3.Decode(disasm, op, opFormat);
         instr.repPrefix = 0;
         return(instr);
     }
     else if (disasm.currentDecodingContext.SizeOverridePrefix)
     {
         if (disasm.isRegisterExtensionEnabled && disasm.currentDecodingContext.RegisterExtension.FlagWideValue)
         {
             return(decoder66Wide.Decode(disasm, op, opFormat));
         }
         else
         {
             return(decoder66.Decode(disasm, op, opFormat));
         }
     }
     else
     {
         if (disasm.isRegisterExtensionEnabled && disasm.currentDecodingContext.RegisterExtension.FlagWideValue)
         {
             return(decoderWide.Decode(disasm, op, opFormat));
         }
         else
         {
             return(this.decoderBase.Decode(disasm, op, opFormat));
         }
     }
 }
Exemplo n.º 33
0
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            HttpSessionStateBase session = filterContext.HttpContext.Session;

            if (filterContext.HttpContext.Request.Cookies["userId"] != null && filterContext.HttpContext.Request.Cookies["userId"].Value.ToString().Trim() != "")
            {
                session["userId"] = filterContext.HttpContext.Request.Cookies["userId"].Value;
            }

            if (session["userId"] == null || (filterContext.HttpContext.Request.Cookies["token"] == null || filterContext.HttpContext.Request.Cookies["token"].Value.ToString().Trim() == ""))
            {
                session.Remove("Menu");
                session.Remove("MyMenu");
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Login", action = "Index" }));
                return;
            }
            var    language       = filterContext.HttpContext.Request.Cookies["Lang"] == null ? "en-US" : filterContext.HttpContext.Request.Cookies["Lang"].Value.ToString();
            string actionName     = filterContext.ActionDescriptor.ActionName;
            string controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;

            if (actionName.ToLower() == "Index".ToLower() && controllerName.ToLower() == "Home".ToLower())
            {
                session["PageName"] = language == "ar-EG"?"الشاشة الرئيسية":"Main Page";
                return;
            }
            var    querystring = filterContext.RequestContext.HttpContext.Request.QueryString;
            string parameter   = querystring["ScreenType"] == null ? null : Decoder.Decode(querystring["ScreenType"]);
            //IRestfulApi<List<bool>, List<bool>> res = new RestfulApi<List<bool>, List<bool>>(ConfigurationManager.AppSettings["ApiUrl"]);
            var restClientContainer = new RestClientContainer(ConfigurationManager.AppSettings["ApiUrl"]);

            //var menu = res.GetAsyncByGetVerb($"Role/CanShowPage/{language}/{controllerName}/{actionName}/{parameter}", null, filterContext.HttpContext.Request.Cookies["token"].Value.ToString()).Result;
            //if (menu != null ) session["PageName"] = menu;
            //if (menu == null )
            //{
            filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "UnAuthorize", action = "Index" }));
            // }
        }
Exemplo n.º 34
0
        public void TestDecode()
        {
            Decoder decoder1 = new Decoder("11101001", 3, 3);

            decoder1.Decode();
            string expectedResult1 = "11110001";

            Assert.AreEqual(expectedResult1, decoder1.decodedMessage);

            Decoder decoder2 = new Decoder("01101001", 3, 3);

            decoder2.Decode();
            string expectedResult2 = "11110000";

            Assert.AreEqual(expectedResult2, decoder2.decodedMessage);

            Decoder decoder3 = new Decoder("01010000", 3, 2);

            decoder3.Decode();
            string expectedResult3 = "0100010";

            Assert.AreEqual(expectedResult3, decoder3.decodedMessage);

            Decoder decoder4 = new Decoder("111101010000", 2, 1);

            decoder4.Decode();
            string expectedResult4 = "100101000";

            Assert.AreEqual(expectedResult4, decoder4.decodedMessage);

            Decoder decoder5 = new Decoder("00100010", 3, 2);

            decoder5.Decode();
            string expectedResult5 = "0001001";

            Assert.AreEqual(expectedResult5, decoder5.decodedMessage);
        }