Пример #1
0
        public void Test_RET()
        {
            ushort sp      = 0x4242;
            byte   lsbData = 0x11;
            byte   msbData = 0x22;

            var expectedState = new CpuState();

            expectedState.StackPointer   = (ushort)(sp + 2);
            expectedState.ProgramCounter = (ushort)((msbData << 8) | lsbData);

            var actualState = new CpuState();

            actualState.StackPointer = sp;

            var memoryMock = new Mock <IRandomAccessMemory>();

            memoryMock.Setup(m => m.ReadByte(sp)).Returns(lsbData);
            memoryMock.Setup(m => m.ReadByte((ushort)(sp + 1))).Returns(msbData);

            var instruction = new RET();

            instruction.Initialize();

            //act
            while (!instruction.IsFetchNecessary())
            {
                instruction.ExecuteCycle(actualState, memoryMock.Object);
            }

            TestHelper.AssertCpuState(expectedState, actualState);
            memoryMock.Verify(m => m.WriteByte(It.IsAny <ushort>(), It.IsAny <byte>()), Times.Never);
        }
        public ActionResult <RET> Post([FromBody] Models.User value)
        {
            RET ret = new RET();

            try
            {
                if (value.Id == 0)
                {
                    _context.Users.Add(new Models.User {
                        Age = value.Age, Address = value.Address, Name = value.Name
                    });
                }
                else
                {
                    Models.User user = _context.Users.Find(value.Id);
                    user.Address = value.Address; user.Age = value.Age; user.Name = value.Name;
                    _context.Users.Update(user);
                }
                _context.SaveChanges();
                ret.MESSAGE = "OK";
            }
            catch (System.Exception)
            {
                ret.MESSAGE = "ERROR...";
            }

            return(Ok(ret));
        }
Пример #3
0
        public void RETHttpPost_ReturnsAViewResult_ViewResultIsNotNull_ObjectIsNotNull()
        {
            // Arrange
            HomeController controller = new HomeController();
            RET            ret        = new RET();

            // Act
            ViewResult result = controller.RET(ret) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
        public ActionResult <RET> Delete(int id)
        {
            RET ret = new RET();

            try
            {
                Models.User usr = _context.Users.Find(id);
                _context.Users.Remove(usr);
                _context.SaveChanges();
                ret.MESSAGE = "OK";
            }
            catch (System.Exception)
            {
                ret.MESSAGE = "ERROR...";
            }
            return(Ok(ret));
        }
            internal static bool TryParse(string ASMLine, ASMLine Current, out ASMLine Out)
            {
                Out     = null;
                ASMLine = ASMLine.ToLower().Trim();
                string[] split = null;

                if (ASMLine.Length < 1)
                {
                    return(false); //empty line
                }
                if (ASMLine[0] == ';')
                {
                    return(false); //comment line, end of section
                }
                //section headers
                if ((split = ASMLine.Split(':')).Length > 1 && Regex.IsMatch(split[0], "^[a-z_0-9]+$"))
                {
                    return((Out = new SectionHeader(split[0])) != null);
                }

                split = SPR.Split(ASMLine);

                switch (split[0])
                {
                case "nop":
                    return((Out = new NOP(Current)) != null);

                case "movzx":
                    return((Out = new MOVZX(Current, split)) != null);

                case "cmp":
                    return((Out = new CMP(Current, split)) != null);

                case "jnb":
                case "jbe":
                case "jmp":
                    return((Out = new JUMP(Current, split)) != null);

                case "retn":
                    return((Out = new RET(Current)) != null);

                default:
                    throw new NotImplementedException($"Unable to parse instruction {split[0]}");
                }
            }
Пример #6
0
        public List <Row_C_SN_RULE_DETAIL> GetDataByRuleID(string RuleID, OleExec DB)
        {
            List <Row_C_SN_RULE_DETAIL> RET = null;
            string  strSql = $@"select * from C_SN_RULE_DETAIL c where c.c_sn_rule_id = '{RuleID}' order by seq ";
            DataSet res    = DB.RunSelect(strSql);

            for (int i = 0; i < res.Tables[0].Rows.Count; i++)
            {
                if (i == 0)
                {
                    RET = new List <Row_C_SN_RULE_DETAIL>();
                }
                Row_C_SN_RULE_DETAIL R = (Row_C_SN_RULE_DETAIL)NewRow();
                R.loadData(res.Tables[0].Rows[i]);
                RET.Add(R);
            }

            return(RET);
        }
Пример #7
0
        public void RET_WhenValuesExceedBound_ShouldNotMeetGoal()
        {
            // Arrange
            int    age = 23; double salary = 80000; double saved = 18.2; double goal = 1500000;
            double result = 100; bool willMeetGoal = false;

            RET ret = new RET();

            ret.age = age; ret.salary = salary; ret.saved = saved; ret.goal = goal;

            Tuple <double, bool> expected = Tuple.Create(result, willMeetGoal);

            // Act
            Tuple <double, bool> actual = ret.RETTest();

            // Assert
            Assert.AreEqual(expected.Item1, actual.Item1, 0.125, "Value of RET does not match expected.");
            Assert.AreEqual(expected.Item2, actual.Item2, "", "Value of Goal does not match expected.");
        }
Пример #8
0
        public static void AssociateOpcodes()
        {
            instructions[0] = new NOP();
            instructions[1] = new PRNT();

            instructions[16] = new PUSH();
            instructions[17] = new POP();
            instructions[18] = new SAVE();
            instructions[19] = new CPY();
            instructions[20] = new RNDM();
            instructions[21] = new EMPTY();

            instructions[128] = new ADD();
            instructions[129] = new SUB();
            instructions[130] = new MUL();
            instructions[131] = new DIV();

            instructions[132] = new SUB2();
            instructions[133] = new DIV2();

            instructions[134] = new NEG();
            instructions[135] = new ABS();

            instructions[144] = new INC();
            instructions[145] = new DEC();

            instructions[64] = new JMP();
            instructions[65] = new JGZ();
            instructions[66] = new JLZ();
            instructions[67] = new JEZ();
            instructions[68] = new JNZ();
            instructions[69] = new CALL();
            instructions[70] = new RET();
            instructions[71] = new LDLOC();
            instructions[72] = new STLOC();
            instructions[73] = new LDARG();
            instructions[74] = new STARG();

            instructions[0b10100100] = new CMP();
Пример #9
0
        public IActionResult RET(RET ret)
        {
            ViewBag.Title = "Retirement Calculator";

            try
            {
                if (ret == null)
                {
                    throw new ArgumentNullException();
                }

                double resultAge  = ret.CalculateRET();
                string resultGoal = ret.DetermineGoalMet();
                string result     = ("The age you could retire is " + (resultAge.ToString()) + ", " + resultGoal);
                ViewBag.Message = result;

                return(View());
            }
            catch (ArgumentNullException)
            {
                return(View());
            }
        }
Пример #10
0
        public static Instruction[] PeToInstructions(string FilePath)
        {
            UnmanagedBuffer    buffer    = new UnmanagedBuffer(File.ReadAllBytes(FilePath));
            List <Instruction> instructs = new List <Instruction>();
            Disasm             disasm    = new Disasm();

            disasm.EIP = new IntPtr(buffer.Ptr.ToInt64() + 0x400);

            List <int> Addresses = new List <int>();

            while (true)
            {
                int result = Asm.Net.src.BeaEngine.BeaEngine.Disasm(disasm);
                Addresses.Add(disasm.EIP.ToInt32());

                if (result == (int)BeaConstants.SpecialInfo.UNKNOWN_OPCODE)
                {
                    break;
                }

                //Console.WriteLine("0x" + disasm.EIP.ToString("X") + " " + disasm.CompleteInstr);

                //convert the data to instructions so we are able to execute it in Asm.Net
                //We also need to change the pointers for push, call, inc, dec etc... so Asm.Net is able to understand it

                switch (disasm.Instruction.Opcode)
                {
                case (int)OpcodeList.CALL:
                {
                    string tmp      = disasm.Argument1.ArgMnemonic.Substring(0, disasm.Argument1.ArgMnemonic.Length - 1).Replace("FFFFFFFF", "");
                    int    Jmpvalue = Convert.ToInt32(tmp, 16);

                    CALL call = new CALL(Jmpvalue);
                    call.NativeVirtualAddress.Address = disasm.EIP.ToInt32();
                    instructs.Add(call);
                    break;
                }

                case (int)OpcodeList.INC_EAX:
                {
                    INC_EAX IncEax = new INC_EAX();
                    IncEax.NativeVirtualAddress.Address = disasm.EIP.ToInt32();
                    instructs.Add(IncEax);
                    break;
                }

                case (int)OpcodeList.INC_EDX:
                {
                    break;
                }

                case (int)OpcodeList.JE:
                {
                    break;
                }

                case (int)OpcodeList.JMP:
                {
                    string tmp      = disasm.Argument1.ArgMnemonic.Substring(0, disasm.Argument1.ArgMnemonic.Length - 1);
                    int    Jmpvalue = Convert.ToInt32(tmp.Replace("FFFFFFFF", ""), 16);

                    JMP jmp = new JMP(Jmpvalue);
                    jmp.NativeVirtualAddress.Address = disasm.EIP.ToInt32();
                    //instructs.Add(jmp);
                    break;
                }

                case (int)OpcodeList.JNZ:
                {
                    string tmp      = disasm.Argument1.ArgMnemonic.Substring(0, disasm.Argument1.ArgMnemonic.Length - 1);
                    int    Jmpvalue = Convert.ToInt32(tmp.Replace("FFFFFFFF", ""), 16);

                    JNZ jnz = new JNZ(Jmpvalue);
                    jnz.NativeVirtualAddress.Address = disasm.EIP.ToInt32();
                    //instructs.Add(jnz);
                    break;
                }

                case (int)OpcodeList.MOV_EAX:
                {
                    string  tmp      = disasm.Argument2.ArgMnemonic.Substring(0, disasm.Argument2.ArgMnemonic.Length - 1);
                    int     MovValue = Convert.ToInt32(tmp, 16);
                    MOV_EAX MovEAX   = new MOV_EAX(new VirtualAddress(0, MovValue));
                    MovEAX.NativeVirtualAddress.Address = disasm.EIP.ToInt32();
                    instructs.Add(MovEAX);
                    break;
                }

                case (int)OpcodeList.NOP:
                {
                    NOP nop = new NOP();
                    nop.NativeVirtualAddress.Address = disasm.EIP.ToInt32();
                    instructs.Add(nop);
                    break;
                }

                case (int)OpcodeList.PUSH_EAX:
                {
                    break;
                }

                case (int)OpcodeList.RET:
                {
                    RET ret = new RET();
                    ret.NativeVirtualAddress.Address = disasm.EIP.ToInt32();
                    instructs.Add(ret);
                    break;
                }

                case (int)OpcodeList.ADD:
                {
                    //need to reverse check the opcodes...
                    Instruction ADD = null;
                    switch (disasm.Argument1.ArgMnemonic)
                    {
                    case "eax":
                    {
                        switch (disasm.Argument2.ArgMnemonic)
                        {
                        case "al":
                        {
                            ADD = new ADD_BYTE_PTR_EAX_AL();
                            break;
                        }
                        }
                        break;
                    }
                    }

                    if (ADD != null)
                    {
                        ADD.NativeVirtualAddress.Address = disasm.EIP.ToInt32();
                        instructs.Add(ADD);
                    }
                    break;
                }

                case (int)OpcodeList.XOR_REGISTER:
                {
                    Instruction xor = null;
                    switch (disasm.Argument1.ArgMnemonic)
                    {
                    case "eax":
                    {
                        switch (disasm.Argument2.ArgMnemonic)
                        {
                        case "eax": { xor = new XOR_EAX_EAX(); break; }

                        case "ecx": { xor = new XOR_EAX_ECX(); break; }

                        case "edx": { xor = new XOR_EAX_EDX(); break; }

                        case "ebx": { xor = new XOR_EAX_EBX(); break; }

                        case "esp": { xor = new XOR_EAX_ESP(); break; }

                        case "ebp": { xor = new XOR_EAX_EBP(); break; }

                        case "esi": { xor = new XOR_EAX_ESI(); break; }

                        case "edi": { xor = new XOR_EAX_EDI(); break; }
                        }
                        break;
                    }

                    case "ecx":
                    {
                        switch (disasm.Argument2.ArgMnemonic)
                        {
                        case "eax": { xor = new XOR_ECX_EAX(); break; }

                        case "ecx": { xor = new XOR_ECX_ECX(); break; }

                        case "edx": { xor = new XOR_ECX_EDX(); break; }

                        case "ebx": { xor = new XOR_ECX_EBX(); break; }

                        case "esp": { xor = new XOR_ECX_ESP(); break; }

                        case "ebp": { xor = new XOR_ECX_EBP(); break; }

                        case "esi": { xor = new XOR_ECX_ESI(); break; }

                        case "edi": { xor = new XOR_ECX_EDI(); break; }
                        }
                        break;
                    }

                    case "edx":
                    {
                        switch (disasm.Argument2.ArgMnemonic)
                        {
                        case "eax": { xor = new XOR_EDX_EAX(); break; }

                        case "ecx": { xor = new XOR_EDX_ECX(); break; }

                        case "edx": { xor = new XOR_EDX_EDX(); break; }

                        case "ebx": { xor = new XOR_EDX_EBX(); break; }

                        case "esp": { xor = new XOR_EDX_ESP(); break; }

                        case "ebp": { xor = new XOR_EDX_EBP(); break; }

                        case "esi": { xor = new XOR_EDX_ESI(); break; }

                        case "edi": { xor = new XOR_EDX_EDI(); break; }
                        }
                        break;
                    }

                    case "ebx":
                    {
                        switch (disasm.Argument2.ArgMnemonic)
                        {
                        case "eax": { xor = new XOR_EBX_EAX(); break; }

                        case "ecx": { xor = new XOR_EBX_ECX(); break; }

                        case "edx": { xor = new XOR_EBX_EDX(); break; }

                        case "ebx": { xor = new XOR_EBX_EBX(); break; }

                        case "esp": { xor = new XOR_EBX_ESP(); break; }

                        case "ebp": { xor = new XOR_EBX_EBP(); break; }

                        case "esi": { xor = new XOR_EBX_ESI(); break; }

                        case "edi": { xor = new XOR_EBX_EDI(); break; }
                        }
                        break;
                    }

                    case "esp":
                    {
                        switch (disasm.Argument2.ArgMnemonic)
                        {
                        case "eax": { xor = new XOR_ESP_EAX(); break; }

                        case "ecx": { xor = new XOR_ESP_ECX(); break; }

                        case "edx": { xor = new XOR_ESP_EDX(); break; }

                        case "ebx": { xor = new XOR_ESP_EBX(); break; }

                        case "esp": { xor = new XOR_ESP_ESP(); break; }

                        case "ebp": { xor = new XOR_ESP_EBP(); break; }

                        case "esi": { xor = new XOR_ESP_ESI(); break; }

                        case "edi": { xor = new XOR_ESP_EDI(); break; }
                        }
                        break;
                    }

                    case "ebp":
                    {
                        switch (disasm.Argument2.ArgMnemonic)
                        {
                        case "eax": { xor = new XOR_EBP_EAX(); break; }

                        case "ecx": { xor = new XOR_EBP_ECX(); break; }

                        case "edx": { xor = new XOR_EBP_EDX(); break; }

                        case "ebx": { xor = new XOR_EBP_EBX(); break; }

                        case "esp": { xor = new XOR_EBP_ESP(); break; }

                        case "ebp": { xor = new XOR_EBP_EBP(); break; }

                        case "esi": { xor = new XOR_EBP_ESI(); break; }

                        case "edi": { xor = new XOR_EBP_EDI(); break; }
                        }
                        break;
                    }

                    case "esi":
                    {
                        switch (disasm.Argument2.ArgMnemonic)
                        {
                        case "eax": { xor = new XOR_ESI_EAX(); break; }

                        case "ecx": { xor = new XOR_ESI_ECX(); break; }

                        case "edx": { xor = new XOR_ESI_EDX(); break; }

                        case "ebx": { xor = new XOR_ESI_EBX(); break; }

                        case "esp": { xor = new XOR_ESI_ESP(); break; }

                        case "ebp": { xor = new XOR_ESI_EBP(); break; }

                        case "esi": { xor = new XOR_ESI_ESI(); break; }

                        case "edi": { xor = new XOR_ESI_EDI(); break; }
                        }
                        break;
                    }

                    case "edi":
                    {
                        switch (disasm.Argument2.ArgMnemonic)
                        {
                        case "eax": { xor = new XOR_EDI_EAX(); break; }

                        case "ecx": { xor = new XOR_EDI_ECX(); break; }

                        case "edx": { xor = new XOR_EDI_EDX(); break; }

                        case "ebx": { xor = new XOR_EDI_EBX(); break; }

                        case "esp": { xor = new XOR_EDI_ESP(); break; }

                        case "ebp": { xor = new XOR_EDI_EBP(); break; }

                        case "esi": { xor = new XOR_EDI_ESI(); break; }

                        case "edi": { xor = new XOR_EDI_EDI(); break; }
                        }
                        break;
                    }
                    }

                    if (xor != null)     //this check is just for temp, not all the XOR instructions are added
                    {
                        xor.NativeVirtualAddress.Address = disasm.EIP.ToInt32();
                        instructs.Add(xor);
                    }
                    break;
                }
                }

                disasm.EIP = new IntPtr(disasm.EIP.ToInt64() + result);
            }

            //set all the pointers correct
            int offset = Options.MemoryBaseAddress;

            foreach (Instruction instruction in instructs)
            {
                switch (instruction.ToByteArray()[0])
                {
                case (int)OpcodeList.CALL:
                {
                    break;
                }

                case (int)OpcodeList.INC_EAX:
                {
                    break;
                }

                case (int)OpcodeList.INC_EDX:
                {
                    break;
                }

                case (int)OpcodeList.JE:
                {
                    break;
                }

                case (int)OpcodeList.JMP:
                {
                    //lets set our new jmp pointer, We also should load the modules which are required to run this program
                    //We need to load the Import Table and get all the .dll's from it and getting all the instructions from it
                    bool NewSet = false;
                    foreach (Instruction instruct in instructs)
                    {
                        if (Addresses.Contains(((IJump)instruction).JumpAddress))
                        {
                            //Set the ASM.net pointer
                            int index = Addresses.IndexOf(((IJump)instruction).JumpAddress) - 1;
                        }

                        //if (((IJump)instruction).JumpAddress == instruct.NativeVirtualAddress.Address)
                        //{
                        //}
                    }

                    //if (!NewSet)
                    //    throw new Exception("Unable to find the JMP Pointer, Invalid memory address ?");
                    break;
                }

                case (int)OpcodeList.MOV_EAX:
                {
                    break;
                }

                case (int)OpcodeList.NOP:
                {
                    break;
                }

                case (int)OpcodeList.PUSH_EAX:
                {
                    break;
                }

                case (int)OpcodeList.RET:
                {
                    break;
                }
                }

                instruction.VirtualAddress.Address = offset;
                offset += instruction.VirtualAddress.Size;
            }

            return(instructs.ToArray());
        }