예제 #1
0
        void AddRange_throws_if_invalid_input()
        {
            var list = new InstructionList(Array.Empty <Instruction>());

            Assert.Throws <ArgumentNullException>(() => list.AddRange(null));

            list = new InstructionList(GetInstructions());
            Assert.Throws <ArgumentNullException>(() => list.AddRange(null));
        }
예제 #2
0
        void AddRange_works(InstructionList list, IEnumerable <Instruction> inserted, Instruction[] expected)
        {
            list.AddRange(inserted);
            Assert.Equal(expected.Length, list.Count);
            Assert.True(expected.Length <= list.Capacity);
            var listElems = new Instruction[list.Count];

            list.CopyTo(listElems);
            AssertEqual(expected, listElems);
        }
예제 #3
0
        public static uint AutoEncode(this Encoder Encoder, Instruction Instruction, ulong IP)
        {
            InstructionList List = new InstructionList();

            if (Encoder.Bitness <= 32)
            {
                List.Add(Instruction);
            }
            else
            {
                if (Instruction.IsJmp() && !Instruction.IsCallFar && Instruction.Op0Kind != OpKind.Register)
                {
                    if (!Instruction.IsANotJmp())
                    {
                        Instruction.NegateConditionCode();
                    }

                    var Jmp = Instruction.IPRelativeMemoryAddress.x64FarJmp();

                    //Get Far Jmp Size + Short Conditional Jmp Size
                    var JmpSize = (uint)Jmp.GetAutoEncodedSize(64, IP);
                    JmpSize += (uint)Instruction.ConditionCode.ToShortJmp(IP + JmpSize, 64).GetEncodedSize(64, IP);

                    List.Add(Instruction.ConditionCode.ToShortJmp(IP + JmpSize, 64));
                    List.AddRange(Jmp);
                }
                else
                {
                    switch (Instruction.Code)
                    {
                    case Code.Mov_r64_rm64:
                        List.Add(Instruction.Create(Code.Mov_r64_imm64, Instruction.Op0Register, Instruction.IPRelativeMemoryAddress));
                        List.Add(Instruction.Create(Code.Mov_r64_rm64, Instruction.Op0Register, new MemoryOperand(Instruction.Op0Register)));
                        break;

                    default:
                        List.Add(Instruction);
                        break;
                    }
                }
            }
            uint TotalSize = 0;

            foreach (var Inst in List)
            {
                TotalSize += Encoder.Encode(Inst, IP + TotalSize);
            }
            return(TotalSize);
        }
예제 #4
0
        public static InstructionList AutoEncode(this Encoder Encoder, Instruction Instruction, ulong IP)
        {
            InstructionList List = new InstructionList();

            if (Encoder.Bitness <= 32)
            {
                List.Add(Instruction);
            }
            else
            {
                if (Instruction.IsJmp() && !Instruction.IsCallFar && Instruction.Op0Kind != OpKind.Register)
                {
                    if (!Instruction.IsANotJmp())
                    {
                        Instruction.NegateConditionCode();
                    }

                    var Jmp = Instruction.Immediate64.AssemblyJmp();

                    //Get Far Jmp Size + Short Conditional Jmp Size
                    var JmpSize = (uint)Jmp.GetAutoEncodedSize(64, IP);
                    JmpSize += (uint)Instruction.ConditionCode.ToShortJmp(IP + JmpSize, 64).GetEncodedSize(64, IP);

                    List.Add(Instruction.ConditionCode.ToShortJmp(IP + JmpSize, 64));
                    List.AddRange(Jmp);
                }
                else
                {
                    switch (Instruction.Code)
                    {
                    case Code.Mov_r64_rm64:
                        if (Instruction.Op1Kind != OpKind.Memory || Instruction.MemoryBase != Register.RIP)
                        {
                            goto default;
                        }
                        List.Add(Instruction.Create(Code.Mov_r64_imm64, Instruction.Op0Register, Instruction.IPRelativeMemoryAddress));
                        List.Add(Instruction.Create(Code.Mov_r64_rm64, Instruction.Op0Register, new MemoryOperand(Instruction.Op0Register)));
                        break;

                    default:
                        List.Add(Instruction);
                        break;
                    }
                }
            }
            return(List);
        }
예제 #5
0
        public static uint AutoEncode(this Encoder Encoder, InstructionList List, ulong IP)
        {
            uint            Len     = 0;
            InstructionList NewList = new InstructionList();

            foreach (var Instruction in List)
            {
                var NewInstruction = Encoder.AutoEncode(Instruction, IP + Len);
                NewList.AddRange(NewInstruction);
                Len += (uint)NewInstruction.GetEncodedSize(64, IP + Len);
            }

            Len = 0;
            foreach (var Instruction in NewList)
            {
                Len += Encoder.Encode(Instruction, IP + Len);
            }

            return(Len);
        }
예제 #6
0
        public void Play(double timeToStartAt, bool cycle)
        {
            // There are 3 categories of TimedKeyframeLists:
            // 1:  Ones that begin and end before timeToStartAt
            // 2:  Ones that begin before timeToStartAt but end after - in other words
            //     timeToStartAt is in the middle of these TimedKeyframeLists
            // 3:  Ones that have not started yet.

            // Category 1:
            List <TimedKeyframeList> keyframesBefore = new List <TimedKeyframeList>();

            // Category 2:
            List <TimedKeyframeList> keyframesDuring = new List <TimedKeyframeList>();

            // Category 3:
            List <TimedKeyframeList> keyframesAfter = new List <TimedKeyframeList>();

            #region Sort all timed keyframes in the lists
            foreach (TimedKeyframeList timedKeyframeList in this)
            {
                if (timedKeyframeList.TimeToExecute < timeToStartAt)
                {
                    if (timedKeyframeList.TimeToExecute + timedKeyframeList.Length < timeToStartAt)
                    {
                        keyframesBefore.Add(timedKeyframeList);
                    }
                    else
                    {
                        keyframesDuring.Add(timedKeyframeList);
                    }
                }
                else
                {
                    keyframesAfter.Add(timedKeyframeList);
                }
            }
            #endregion


            InstructionList instructionsToExecute = new InstructionList();

            #region Add the keyframes before

            TimedKeyframeList.SortEndTimeAscending(keyframesBefore);

            foreach (TimedKeyframeList keyframeList in keyframesBefore)
            {
                // TODO
            }


            #endregion

            foreach (TimedKeyframeList keyframeList in keyframesAfter)
            {
                InstructionList instructionsToAdd =
                    keyframeList.KeyframeList.CreateVelocityListAtTime(timeToStartAt);

                instructionsToAdd.ShiftTime(keyframeList.TimeToExecute);

                instructionsToExecute.AddRange(instructionsToAdd);
            }

            #region If cycle == true

            if (cycle == true)
            {
                foreach (Instruction instruction in instructionsToExecute)
                {
                    instruction.CycleTime = this.Length;
                }
            }
            #endregion
            instructionsToExecute.ShiftTime(TimeManager.CurrentTime);

            instructionsToExecute.ExecuteAndRemoveOrCyclePassedInstructions(
                timeToStartAt + TimeManager.CurrentTime);


            InstructionManager.Instructions.AddRange(instructionsToExecute);
        }