Example #1
0
 ///<summary> the newValue must be serializable </summary>
 public MOV_VARIABLE_VALUE(VirtualAddress VariableAddress, string varName, object newValue)
     : base(3, typeof(IMov)) //0x66, 0xC7, 0x05
 {
     this.ModifiyValue = VariableAddress;
     this.varName      = varName;
     this.newValue     = newValue;
 }
Example #2
0
        /// <summary>
        /// Pads the stream with zeros until the specific alignment is reached.
        /// </summary>
        /// <param name="alignment">The alignment.</param>
        private void InsertPadding(int alignment)
        {
            long address = VirtualAddress.ToInt64() + _sectionStream.Length;
            int  pad     = (int)(alignment - (address % alignment));

            _sectionStream.Write(new byte[pad], 0, pad);
        }
Example #3
0
 public MOV_VARIABLE_VALUE(VirtualAddress VariableAddress, string varName, Register register)
     : base(3, typeof(IMov)) //0x66, 0xC7, 0x05
 {
     this.ModifiyValue = VariableAddress;
     this.varName      = varName;
     this.register     = register;
     this.isRegister   = true;
 }
Example #4
0
 ///<summary> the newValue must be serializable </summary>
 public MOV_VARIABLE_INDEX_VALUE(VirtualAddress VariableAddress, int index, object newValue)
     : base(3, typeof(IMov)) //0x66, 0xC7, 0x45
 {
     this.ModifiyValue = VariableAddress;
     this.newValue     = newValue;
     this.Index        = index;
     this.varName      = null;
 }
Example #5
0
 public MOV_REGISTER_VARIABLE_INDEX(VirtualAddress VariableAddress, int index, Register register)
     : base(6, typeof(IMov))
 {
     this.varName      = null;
     this.ModifiyValue = VariableAddress;
     this.register     = register;
     this.Index        = index;
 }
Example #6
0
        public VirtualAddress AddString(string value)
        {
            VirtualAddress addr = new VirtualAddress(value.Length, (int)stream.Count);

            stream.AddRange(ASCIIEncoding.ASCII.GetBytes(value));
            stream.Add(0);
            return(addr);
        }
Example #7
0
 public MOV_VARIABLE_INDEX_VALUE(VirtualAddress VariableAddress, int index, Register register)
     : base(3, typeof(IMov)) //0x66, 0xC7, 0x45
 {
     this.varName      = null;
     this.ModifiyValue = VariableAddress;
     this.register     = register;
     this.isRegister   = true;
     this.Index        = index;
 }
Example #8
0
 public PUSH_VARIABLE(VirtualAddress VariableAddress, DataSection dataSection)
     : base(5, typeof(IPush))
 {
     /*string val = "";
      * if (dataSection.LoadString(VariableAddress, ref val))
      * {
      *  this.Value = val;
      * }*/
     this.ValueAddress = VariableAddress.Address;
     this.dataSection  = dataSection;
 }
Example #9
0
        public override int GetHashCode()
        {
            var hash = 13;

            hash = (hash * 7) + FileOffset.GetHashCode();
            hash = (hash * 7) + FileSize.GetHashCode();
            hash = (hash * 7) + RelativeVirtualAddress.GetHashCode();
            hash = (hash * 7) + VirtualAddress.GetHashCode();
            hash = (hash * 7) + VirtualSize.GetHashCode();

            return(hash);
        }
Example #10
0
        private void mathToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpcodeWriter writer = new OpcodeWriter();
            VirtualAddress addr = writer.dataSection.CreateVariable((int)668);
            writer.codeSection.MOV_ECX(2);
            writer.codeSection.MOV_REGISTER_DWORD_PTR(Register.EAX, addr);
            writer.codeSection.MUL(MulRegisterOpcodes.MUL_EAX_ECX); //1336
            writer.codeSection.INC_EAX(); //1337
            writer.codeSection.MOV_DWORD_PTR_EAX(addr); //set value from EAX to variable

            ExecuteCode(writer);
        }
Example #11
0
        public void WorksForValidAddresses(string input, string networkLocation, string networkName, string networkId, string deviceLocation, string deviceName, string deviceId)
        {
            var result = VirtualAddress.Parse(input);

            Assert.That(result.NetworkLocation, Is.EqualTo(networkLocation));
            Assert.That(result.NetworkName, Is.EqualTo(networkName));
            Assert.That(result.NetworkNodeId, Is.EqualTo(networkId));

            Assert.That(result.DeviceLocation, Is.EqualTo(deviceLocation));
            Assert.That(result.DeviceName, Is.EqualTo(deviceName));
            Assert.That(result.DeviceNodeId, Is.EqualTo(deviceId));
        }
Example #12
0
        public ActionResult GetAddressById(int id)
        {
            var            item       = UserAddressBLL.Read(id, uid);
            VirtualAddress newaddress = new VirtualAddress();

            newaddress.id          = item.Id;
            newaddress.name        = item.Consignee;
            newaddress.address     = item.Address;
            newaddress.mobile      = item.Mobile;
            newaddress.isdefault   = Convert.ToBoolean(item.IsDefault);
            newaddress.regionnames = string.Join(",", RegionBLL.RegionNameList(item.RegionId).Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Skip(1));

            return(Json(new { address = newaddress }, JsonRequestBehavior.AllowGet));
        }
Example #13
0
        private void changeValueAtIndexToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpcodeWriter writer = new OpcodeWriter();
            VirtualAddress addr = writer.dataSection.CreateVariable(":)"); //create variable
            writer.codeSection.MOV_VARIABLE_INDEX_VALUE(addr, 1, '('); //change ')' to '('

            //show result
            writer.codeSection.PUSH_VALUE(0);
            writer.codeSection.PUSH_VARIABLE(addr);
            writer.codeSection.PUSH_VARIABLE(addr);
            writer.codeSection.PUSH_VALUE(0);
            writer.codeSection.CALL(Functions.User32_MessageBoxA);
            ExecuteCode(writer);
        }
Example #14
0
 public bool LoadString(VirtualAddress addr, ref string ret)
 {
     if (addr.Address >= 0 && addr.Address <= stream.Count)
     {
         for (int i = addr.Address; i < stream.Count; i++)
         {
             if (stream[i] == 0)
             {
                 break;
             }
             ret += (char)stream[i];
         }
         return(true);
     }
     return(false);
 }
Example #15
0
        public ActionResult GetAddress()
        {
            var address = UserAddressBLL.ReadList(uid);

            List <VirtualAddress> addresslist = new List <VirtualAddress>();

            foreach (var item in address)
            {
                VirtualAddress newaddress = new VirtualAddress();
                newaddress.id        = item.Id;
                newaddress.name      = item.Consignee;
                newaddress.address   = RegionBLL.RegionNameList(item.RegionId) + " " + item.Address;
                newaddress.mobile    = item.Mobile;
                newaddress.isdefault = Convert.ToBoolean(item.IsDefault);
                addresslist.Add(newaddress);
            }

            return(Json(new { address = addresslist }, JsonRequestBehavior.AllowGet));
        }
Example #16
0
        public VirtualAddress GetApiAddress(string lib, string func)
        {
            IntPtr libPtr = LoadLibrary(lib);

            if (libPtr == IntPtr.Zero)
            {
                return(new VirtualAddress(4, 0));
            }

            VirtualAddress addr = new VirtualAddress(4, GetProcAddress(libPtr, func).ToInt32());

            if (!ResolveList.ContainsKey(lib))
            {
                ResolveList.Add(lib, new SortedList <string, VirtualAddress>());
            }
            if (!ResolveList[lib].ContainsKey(func))
            {
                ResolveList[lib].Add(func, addr);
            }
            return(addr);
        }
Example #17
0
        private void tCPClientToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpcodeWriter writer = new OpcodeWriter();
            WSAData wsaData = new WSAData();
            sockaddr_in sockaddr = new sockaddr_in();
            sockaddr_in Clientsockaddr = new sockaddr_in();
            VirtualAddress wsaDataAddr = writer.dataSection.CreateVariable(wsaData);
            VirtualAddress SockinAddress = writer.dataSection.CreateVariable(sockaddr);
            VirtualAddress ClientSockinAddress = writer.dataSection.CreateVariable(Clientsockaddr);
            VirtualAddress UsernameAddress = writer.dataSection.CreateVariable(ASCIIEncoding.ASCII.GetBytes("****************")); //the data we want to send when a client connects
            VirtualAddress PasswordAddress = writer.dataSection.CreateVariable(ASCIIEncoding.ASCII.GetBytes("****************")); //the data we want to send when a client connects
            VirtualAddress SocketAddress = writer.dataSection.CreateVariable(IntPtr.Zero);

            //socket initialization
            //set the WSADATA settings
            writer.codeSection.MOV_VARIABLE_VALUE(wsaDataAddr, "HighVersion", (ushort)2);
            writer.codeSection.MOV_VARIABLE_VALUE(wsaDataAddr, "Version", (ushort)2);

            //set the sockaddr_in settings, setting the family IPv4
            writer.codeSection.MOV_VARIABLE_VALUE(SockinAddress, "sin_family", (short)ValueCodes.InterNetworkv4);
            //setting port, we need to encode it first...
            writer.codeSection.PUSH_VALUE(1337); //1337=listen port
            writer.codeSection.CALL(Functions.ws2_32_htons);
            writer.codeSection.MOV_VARIABLE_REGISTER(SockinAddress, "sin_port", Register.EAX);

            
            writer.codeSection.PUSH_STRING("127.0.0.1"); //ip
            writer.codeSection.CALL(Functions.ws2_32_inet_addr);
            writer.codeSection.MOV_VARIABLE_REGISTER(SockinAddress, "sin_addr", Register.EAX);

            writer.codeSection.PUSH_VARIABLE(wsaDataAddr);
            writer.codeSection.PUSH_VALUE(36);
            writer.codeSection.CALL(Functions.ws2_32_WSAStartup);

            //started successfully ?
            writer.codeSection.MOV_ECX(0);
            writer.codeSection.CMP(CmpRegisterOpcodes.CMP_ECX_EAX);
            writer.codeSection.JNE("failed");

        //create a socket
            writer.codeSection.PUSH_VALUE(ValueCodes.Tcp, (int)0);
            writer.codeSection.PUSH_VALUE(ValueCodes.Stream, (int)0);
            writer.codeSection.PUSH_VALUE(ValueCodes.InterNetworkv4, (int)0);
            writer.codeSection.CALL(Functions.ws2_32_socket);
                
        //is socket > 0 ?
            writer.codeSection.MOV_ECX((int)ValueCodes.INVALID_SOCKET);
            writer.codeSection.CMP(CmpRegisterOpcodes.CMP_ECX_EAX);
            writer.codeSection.JE("failed");

        //lets move our socket handle to EBX
            writer.codeSection.MOV(MovRegisterOpcodes.MOV_EBX_EAX);

            
            writer.codeSection.PUSH_VALUE(Marshal.SizeOf(new sockaddr_in()));
            writer.codeSection.PUSH_VARIABLE(SockinAddress);
            writer.codeSection.PUSH_EBX();
            writer.codeSection.CALL(Functions.ws2_32_connect);

            
            writer.codeSection.MOV_ECX(0);
            writer.codeSection.CMP(CmpRegisterOpcodes.CMP_ECX_EAX);
            writer.codeSection.JNE("UnableToConnect");
            writer.codeSection.JMP("end");


            writer.codeSection.CreateLabel("failed");
            writer.codeSection.PUSH_VALUE(0);
            writer.codeSection.PUSH_STRING("Something went wrong... unable to connect?");
            writer.codeSection.PUSH_STRING("Something went wrong... unable to connect?");
            writer.codeSection.PUSH_VALUE(ValueCodes.MB_OK, (int)0);
            writer.codeSection.CALL(Functions.User32_MessageBoxA);
            writer.codeSection.JMP("end");

            
            writer.codeSection.CreateLabel("UnableToConnect");
            writer.codeSection.PUSH_VALUE(0);
            writer.codeSection.PUSH_STRING("unable to connect?");
            writer.codeSection.PUSH_STRING("unable to connect?");
            writer.codeSection.PUSH_VALUE(ValueCodes.MB_OK, (int)0);
            writer.codeSection.CALL(Functions.User32_MessageBoxA);
            writer.codeSection.JMP("end");


            writer.codeSection.CreateLabel("end");
            writer.codeSection.XOR(XorRegisterOpcodes.XOR_ECX_ECX);
            ExecuteCode(writer);
        }
Example #18
0
 public MOV_EDX(VirtualAddress virtualAddress)
     : base(5, typeof(IMov))
 {
     this.ModifiyValue = virtualAddress;
 }
Example #19
0
        public void FailsForInvalidAddresses(string input)
        {
            var result = VirtualAddress.Parse(input);

            Assert.That(result, Is.Null);
        }
Example #20
0
 public MOV_DWORD_PTR_EBX(VirtualAddress virtualAddress)
     : base(6, typeof(IMov))
 {
     this.ModifiyValue = virtualAddress;
 }
Example #21
0
 public MOV_REGISTER_DWORD_PTR(Register register, VirtualAddress VariableAddr)
     : base(6, typeof(IMov))
 {
     this.register     = register;
     this.ModifiyValue = VariableAddr;
 }
Example #22
0
 public static VirtualAddress ToVirtualAddress(this IParameter parameter)
 {
     return(VirtualAddress.Parse(parameter.Value));
 }
Example #23
0
        private void ExecuteNextInstruction()
        {
            //check if we reached the end
            if (HALT || RamMemory.Instructions.Count == 0)
            {
                return;
            }

            if (!RamMemory.Instructions.ContainsKey(registers.EIP))
            {
                if (RamMemory.Instructions.IndexOfKey(PreviousEIP.Address) == RamMemory.Instructions.Count - 1)
                {
                    registers.EIP = PreviousEIP.Address;
                    HALT          = true;
                    return;
                }
            }

            Instruction CurInstruction = RamMemory.Instructions[registers.EIP];

            //Call event if we are in debug mode
            if (IsDebugMode)
            {
                if (GetCurrentInstructionEventHandler() != null)
                {
                    GetCurrentInstructionEventHandler()(CurInstruction);
                }
            }

            IncreaseEIP = true;

            if (CurInstruction.InterfaceType == typeof(IPush))
            {
                ((IPush)CurInstruction).AddToStack(registers, Stack, this.dataSection);
            }
            else if (CurInstruction.InterfaceType == typeof(INop))
            {
            }
            else if (CurInstruction.InterfaceType == typeof(ICall))
            {
                ((CALL)CurInstruction).CallFunction(Stack, this.registers);
            }
            else if (CurInstruction.InterfaceType == typeof(IJump))
            {
                IncreaseEIP   = false;
                registers.EIP = ((IJump)CurInstruction).NextIpAddress(flags, registers);
            }
            else if (CurInstruction.InterfaceType == typeof(IInc))
            {
                ((IInc)CurInstruction).Execute(registers);
            }
            else if (CurInstruction.InterfaceType == typeof(IMov))
            {
                ((IMov)CurInstruction).Execute(registers, dataSection);
            }
            else if (CurInstruction.InterfaceType == typeof(IXor))
            {
                ((IXor)CurInstruction).XorValue(registers);
            }
            else if (CurInstruction.InterfaceType == typeof(IXor))
            {
                ((IXor)CurInstruction).XorValue(registers);
            }
            else if (CurInstruction.InterfaceType == typeof(IAnd))
            {
                ((IAnd)CurInstruction).AndValue(registers);
            }
            else if (CurInstruction.InterfaceType == typeof(ICmp))
            {
                ((ICmp)CurInstruction).Compare(ref flags, registers);
            }
            else if (CurInstruction.InterfaceType == typeof(IMul))
            {
                ((IMul)CurInstruction).Multiply(registers);
            }

            PreviousEIP = new VirtualAddress(4, registers.EIP);
            if (IncreaseEIP) //set new EIP for going to our next instruction
            {
                registers.EIP += CurInstruction.VirtualAddress.Size;
            }
        }
Example #24
0
 public static bool IsVirtualAddress(this IParameter parameter)
 {
     return(VirtualAddress.IsValid(parameter.Value));
 }
Example #25
0
        private void tCPServerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpcodeWriter writer = new OpcodeWriter();

            WSAData wsaData = new WSAData();
            sockaddr_in sockaddr = new sockaddr_in();
            sockaddr_in Clientsockaddr = new sockaddr_in();
            VirtualAddress wsaDataAddr = writer.dataSection.CreateVariable(wsaData);
            VirtualAddress SockinAddress = writer.dataSection.CreateVariable(sockaddr);
            VirtualAddress ClientSockinAddress = writer.dataSection.CreateVariable(Clientsockaddr);
            VirtualAddress ArrayAddress = writer.dataSection.CreateVariable(ASCIIEncoding.ASCII.GetBytes(":)")); //the data we want to send when a client connects

            //socket initialization
            //set the WSADATA settings
            writer.codeSection.MOV_VARIABLE_VALUE(wsaDataAddr, "HighVersion", (ushort)2);
            writer.codeSection.MOV_VARIABLE_VALUE(wsaDataAddr, "Version", (ushort)2);

            //set the sockaddr_in settings, setting the family IPv4
            writer.codeSection.MOV_VARIABLE_VALUE(SockinAddress, "sin_family", (short)ValueCodes.InterNetworkv4);
            //setting port, we need to encode it first...
            writer.codeSection.PUSH_VALUE(1337); //1337=listen port
            writer.codeSection.CALL(Functions.ws2_32_htons);
            writer.codeSection.MOV_VARIABLE_REGISTER(SockinAddress, "sin_port", Register.EAX);

            writer.codeSection.PUSH_VARIABLE(wsaDataAddr);
            writer.codeSection.PUSH_VALUE(36);
            writer.codeSection.CALL(Functions.ws2_32_WSAStartup);

            //started successfully ?
            writer.codeSection.MOV_ECX(0);
            writer.codeSection.CMP(CmpRegisterOpcodes.CMP_ECX_EAX);
            writer.codeSection.JNE("failed");

        //create a socket
            writer.codeSection.PUSH_VALUE(ValueCodes.Tcp, (int)0);
            writer.codeSection.PUSH_VALUE(ValueCodes.Stream, (int)0);
            writer.codeSection.PUSH_VALUE(ValueCodes.InterNetworkv4, (int)0);
            writer.codeSection.CALL(Functions.ws2_32_socket);
                
        //is socket > 0 ?
            writer.codeSection.MOV_ECX((int)ValueCodes.INVALID_SOCKET);
            writer.codeSection.CMP(CmpRegisterOpcodes.CMP_ECX_EAX);
            writer.codeSection.JE("failed");

        //lets move our socket handle to EBX
            writer.codeSection.MOV(MovRegisterOpcodes.MOV_EBX_EAX);

        //lets bind our socket
            writer.codeSection.PUSH_VALUE(Marshal.SizeOf(sockaddr));
            writer.codeSection.PUSH_VARIABLE(SockinAddress); //our sockaddr_in
            writer.codeSection.PUSH_EBX(); //socket handle
            writer.codeSection.CALL(Functions.ws2_32_bind);

            //ok lets listen at a port
            writer.codeSection.PUSH_VALUE((int)100);
            writer.codeSection.PUSH_EBX(); //socket
            writer.codeSection.CALL(Functions.ws2_32_listen);


            //now a infinite loop for accept our connections but lets setup our console
            writer.codeSection.PUSH_VALUE(-11); //STD_OUTPUT_HANDLE
            writer.codeSection.CALL(Functions.Kernel32_GetStdHandle);
            writer.codeSection.MOV(MovRegisterOpcodes.MOV_EDX_EAX);

            writer.codeSection.CreateLabel("loop");
                //lets accept connections
                writer.codeSection.PUSH_VALUE(Marshal.SizeOf(Clientsockaddr));
                writer.codeSection.PUSH_VARIABLE(ClientSockinAddress);
                writer.codeSection.PUSH_EBX(); //server socket
                writer.codeSection.CALL(Functions.ws2_32_accept);
                writer.codeSection.MOV(MovRegisterOpcodes.MOV_EDI_EAX); //set client socket to EDI


                writer.codeSection.PUSH_VALUE(0);
                writer.codeSection.PUSH_VALUE(0);
                writer.codeSection.PUSH_VALUE(20);//char length
                writer.codeSection.PUSH_STRING("new client accepted\r\n");
                writer.codeSection.PUSH_EDX();
                writer.codeSection.CALL(Functions.Kernel32_WriteConsoleA);

                //lets send a packet
                writer.codeSection.PUSH_VALUE(0);
                writer.codeSection.PUSH_VALUE(2);
                writer.codeSection.PUSH_VARIABLE(ArrayAddress);
                writer.codeSection.PUSH_EDI(); //client socket
                writer.codeSection.CALL(Functions.ws2_32_send);

                //close our connection with the client...
                writer.codeSection.PUSH_EDI();
                writer.codeSection.CALL(Functions.ws2_32_closesocket);

            writer.codeSection.JMP("loop");

            writer.codeSection.PUSH_EBX();
            writer.codeSection.CALL(Functions.ws2_32_closesocket);

            writer.codeSection.CreateLabel("failed");
            writer.codeSection.XOR(XorRegisterOpcodes.XOR_ECX_ECX);
            ExecuteCode(writer);
        }