public override unsafe bool Cache(byte[] Input, int Offset, int Length, MemoryStream Output)
        {
            PayloadWriter pw = new PayloadWriter(Output);

            for (int i = Offset, j = 0; i < Length;)
            {
                int RamCacheIndex = j % base.CacheBuffer.Length;
                int length        = MemCmp(Input, i, base.CacheBuffer, RamCacheIndex);

                if (length > 0)
                {
                    CacheInfo inf = new CacheInfo(RamCacheIndex, i, length, true, Instruction.MEMCPY);
                    pw.WriteByte((byte)CachingType.Equal);
                    pw.WriteInteger(length);
                }
                else
                {
                    //first byte in offset wasn't equal
                    //lets scan to see how far it goes
                    length = UnMemCmp(Input, i, base.CacheBuffer, RamCacheIndex);

                    pw.WriteByte((byte)CachingType.NotEqual);
                    pw.WriteInteger(length);
                    pw.WriteBytes(Input, i, length);

                    CacheInfo inf = new CacheInfo(-1, i, length, false, Instruction.NEWDATA);
                    inf.instruction = Instruction.NEWDATA;
                }
                i += length;
                j += length;
            }
            return(true);
        }
Ejemplo n.º 2
0
        public override byte[] ToByteArray()
        {
            PayloadWriter writer = new PayloadWriter();

            writer.WriteBytes(OtherOpcodes.MOV_VARIABLE_VALUE);
            writer.WriteInteger(ModifiyValue.Address);
            writer.WriteString(varName);

            //lets serialize the new value
            writer.WriteByte(isRegister ? (byte)1 : (byte)0);

            if (isRegister)
            {
                writer.WriteByte((byte)register);
            }
            else
            {
                MemoryStream mem = new MemoryStream();
                new BinaryFormatter().Serialize(mem, newValue);
                writer.WriteInteger((int)mem.Length);
                writer.WriteBytes(mem.ToArray());
            }

            return(writer.ToByteArray());
        }
Ejemplo n.º 3
0
        public Task Set(byte parameter, object value, byte size, CancellationToken cancellationToken = default)
        {
            if (size < 1 || size > 4)
            {
                throw new ArgumentOutOfRangeException(nameof(size), size, "Size must be between 1 and 4");
            }

            using (var writer = new PayloadWriter())
            {
                writer.WriteByte(parameter);
                writer.WriteByte(size);
                switch (size)
                {
                case 1:
                    writer.WriteByte(Convert.ToByte(value));
                    break;

                case 2:
                    writer.WriteInt16(Convert.ToInt16(value));
                    break;

                case 3:
                    writer.WriteInt24(Convert.ToInt16(value));
                    break;

                case 4:
                    writer.WriteInt32(Convert.ToInt32(value));
                    break;
                }
                var command = new Command(CommandClass, ConfigurationCommand.Set, writer.ToPayload());
                return(Send(command, cancellationToken));
            }
        }
Ejemplo n.º 4
0
        internal RequestMessage Encode(ControllerRequest command, byte?callbackID)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            // create writer to serialize te request
            using (var writer = new PayloadWriter())
            {
                // write the function
                writer.WriteByte((byte)command.Function);

                // does the command has payload?
                if (command.Payload != null)
                {
                    // yes, so write the payload
                    writer.WriteObject(command.Payload);
                }

                if (callbackID != null)
                {
                    // write the callback
                    writer.WriteByte(callbackID.Value);
                }

                // create a hostmessage, use the serialized payload
                return(new RequestMessage(writer.ToPayload()));
            }
        }
Ejemplo n.º 5
0
 protected override void Write(PayloadWriter writer)
 {
     writer.WriteByte((byte)CommandClass);
     writer.WriteByte(CommandID);
     writer.WriteByte(SourceEndpointID);
     writer.WriteByte(TargetEndpointID);
     writer.WriteObject(Payload);
 }
Ejemplo n.º 6
0
        protected override void Write(PayloadWriter writer)
        {
            writer.WriteByte((byte)CommandClass);
            writer.WriteByte(CommandID);
            writer.WriteObject(Payload);

            var checksum = new byte[] { (byte)CommandClass, CommandID }.Concat(Payload.ToArray()).CalculateCrc16Checksum();

            writer.WriteInt16(checksum);
        }
Ejemplo n.º 7
0
        protected virtual void Write(PayloadWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            writer.WriteByte((byte)CommandClass);
            writer.WriteByte(CommandID);
            writer.WriteObject(Payload);
        }
Ejemplo n.º 8
0
        private void DoLogin()
        {
            if (!cbRememberMe.Checked)
            {
                File.Delete(loginData);
            }
            if (!cbAutoLogin.Checked)
            {
                File.Delete(autoLogin);
            }
            if (cbRememberMe.Checked && !File.Exists(loginData))
            {
                string data = tbUsername.txtbox.Text + Environment.NewLine + tbPassword.txtbox.Text;
                File.WriteAllText(loginData, GlobalVariables.cryptor.Encrypt(data, GlobalVariables.HWID));
            }
            if (cbAutoLogin.Checked && !File.Exists(autoLogin))
            {
                File.WriteAllText(autoLogin, string.Empty);
            }

            using (PayloadWriter pw = new PayloadWriter())
            {
                tbUsername.Enabled = false;
                tbPassword.Enabled = false;
                btnLogin.Enabled   = false;
                pw.WriteByte(0x02);
                pw.WriteString(tbUsername.txtbox.Text);
                pw.WriteString(tbPassword.txtbox.Text);
                pw.WriteString(GlobalVariables.HWID);
                pw.WriteString(GlobalVariables.version);
                GlobalVariables.Username = tbUsername.txtbox.Text;
                GlobalVariables.SendData(pw.ToByteArray());
            }
        }
Ejemplo n.º 9
0
        public override byte[] ToByteArray()
        {
            PayloadWriter writer = new PayloadWriter();

            writer.WriteByte((byte)OpcodeList.MOV_EAX_DWORD_PTR);
            writer.WriteInteger(ModifiyValue.Address);
            writer.WriteByte(varName == null ? (byte)0 : (byte)1);
            writer.WriteInteger(Index);

            if (varName != null)
            {
                writer.WriteString(varName);
            }
            writer.WriteByte((byte)register);
            return(writer.ToByteArray());
        }
Ejemplo n.º 10
0
        private static PayloadWriter CreateCapabilitiesPayload(ProtocolCapabilities serverCapabilities, ConnectionSettings cs, bool useCompression, ProtocolCapabilities additionalCapabilities = 0)
        {
            var writer = new PayloadWriter();

            writer.WriteInt32((int)(
                                  ProtocolCapabilities.Protocol41 |
                                  ProtocolCapabilities.LongPassword |
                                  ProtocolCapabilities.SecureConnection |
                                  (serverCapabilities & ProtocolCapabilities.PluginAuth) |
                                  (serverCapabilities & ProtocolCapabilities.PluginAuthLengthEncodedClientData) |
                                  ProtocolCapabilities.MultiStatements |
                                  ProtocolCapabilities.MultiResults |
                                  ProtocolCapabilities.LocalFiles |
                                  (string.IsNullOrWhiteSpace(cs.Database) ? 0 : ProtocolCapabilities.ConnectWithDatabase) |
                                  (cs.UseAffectedRows ? 0 : ProtocolCapabilities.FoundRows) |
                                  (useCompression ? ProtocolCapabilities.Compress : ProtocolCapabilities.None) |
                                  (serverCapabilities & ProtocolCapabilities.ConnectionAttributes) |
                                  (serverCapabilities & ProtocolCapabilities.DeprecateEof) |
                                  additionalCapabilities));
            writer.WriteInt32(0x4000_0000);
            writer.WriteByte((byte)CharacterSet.Utf8Mb4Binary);
            writer.Write(new byte[23]);

            return(writer);
        }
Ejemplo n.º 11
0
        void IPayloadSerializable.Write(PayloadWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            writer.WriteByte(NodeID);

            var payload = Command.Serialize();

            writer.WriteByte((byte)payload.Length);
            writer.WriteObject(payload);

            writer.WriteByte((byte)(TransmitOptions.Ack | TransmitOptions.AutoRoute | TransmitOptions.Explore));
        }
Ejemplo n.º 12
0
        public static PayloadData Create(string databaseName)
        {
            var writer = new PayloadWriter();

            writer.WriteByte((byte)CommandKind.InitDatabase);
            writer.Write(Encoding.UTF8.GetBytes(databaseName));

            return(writer.ToPayloadData());
        }
Ejemplo n.º 13
0
        public static PayloadData Create(string user, byte[] authResponse, string schemaName, byte[] connectionAttributes)
        {
            var writer = new PayloadWriter();

            writer.WriteByte((byte)CommandKind.ChangeUser);
            writer.WriteNullTerminatedString(user);
            writer.WriteByte(checked ((byte)authResponse.Length));
            writer.Write(authResponse);
            writer.WriteNullTerminatedString(schemaName ?? "");
            writer.WriteByte((byte)CharacterSet.Utf8Mb4Binary);
            writer.WriteByte(0);
            writer.WriteNullTerminatedString("mysql_native_password");
            if (connectionAttributes != null)
            {
                writer.Write(connectionAttributes);
            }

            return(writer.ToPayloadData());
        }
Ejemplo n.º 14
0
        public Task SetInterval(TimeSpan interval, byte targetNodeID, CancellationToken cancellationToken = default)
        {
            using (var writer = new PayloadWriter())
            {
                writer.WriteInt24((int)interval.TotalSeconds);
                writer.WriteByte(targetNodeID);

                var command = new Command(CommandClass, WakeUpCommand.IntervalSet, writer.ToPayload());
                return(Send(command, cancellationToken));
            }
        }
Ejemplo n.º 15
0
 private static byte[] WriteInstruction(InstructionInfo Instruction)
 {
     using (PayloadWriter pw = new PayloadWriter())
         using (MemoryStream ms = new MemoryStream())
         {
             Serializer.Serialize(ms, Instruction);
             pw.WriteByte((byte)ms.Length);
             pw.WriteBytes(ms.ToArray());
             return(pw.ToByteArray());
         }
 }
Ejemplo n.º 16
0
 internal SSPError SendUdpMessage(IMessage message, UdpPAcketId packetId)
 {
     lock (UdpHandle)
     {
         PayloadWriter pw = new PayloadWriter();
         pw.WriteDecimal(this.ClientId);
         pw.WriteByte((byte)packetId);
         pw.WriteUInteger(Connection.messageHandler.GetMessageId(message.GetType()));
         message.WritePacket(message, ref pw);
         this.UdpHandle.SendTo(pw.GetBuffer(), 0, pw.Length, SocketFlags.None, this.UdpEndPoint);
         return(SSPError.ErrorSuccess);
     }
 }
Ejemplo n.º 17
0
        private static void SaveMaskTable(ref List <double> Digits, ref DataShuffler dataShuffler, int ByteIndex, ref Stream OutStream)
        {
            if (Digits.Count == 0)
            {
                return;
            }

            Console.WriteLine("Digits:" + Digits.Count);
            PayloadWriter pw = new PayloadWriter();

            double[] Shuffled = dataShuffler.Shuffle <double>(Digits.ToArray(), 1, (double progress, TimeSpan TimeLeft, int speed) =>
            {
                if ((int)progress % 5 == 0.0F)
                {
                    Console.WriteLine("Shuffle progress:" + progress + ", Speed: " + speed + ", Time Left: " + TimeLeft.Hours.ToString("D2") + ":" + TimeLeft.Minutes.ToString("D2") + ":" + TimeLeft.Seconds.ToString("D2"));
                }
            });

            for (int k = 0; k < Shuffled.Length; k++)
            {
                int Target = (int)Shuffled[k];

                pw.WriteByte((byte)ByteIndex);        //byte length

                if (ByteIndex >= 1 || ByteIndex <= 3) //play it safe
                {
                    pw.WriteUInteger((uint)Target);
                }
                else
                {
                    pw.WriteDecimal(Target);
                }

                if (pw.Length >= 65535)
                {
                    OutStream.Write(pw.GetBuffer(), 0, pw.Length);
                    OutStream.Flush();
                    pw = new PayloadWriter();
                }
            }
            if (pw.Length > 0)
            {
                OutStream.Write(pw.GetBuffer(), 0, pw.Length);
                OutStream.Flush();
            }
            pw.Dispose();
            Digits.Clear();
        }
Ejemplo n.º 18
0
        public override byte[] ToByteArray()
        {
            byte[]        tmp    = new byte[0];
            PayloadWriter writer = new PayloadWriter();

            writer.WriteByte((byte)OpcodeList.PUSH_VALUE);

            if (Value.GetType() == typeof(int))
            {
                tmp = BitConverter.GetBytes((int)Value);
                writer.WriteByte(0);
            }
            else if (Value.GetType() == typeof(uint))
            {
                tmp = BitConverter.GetBytes((uint)Value);
                writer.WriteByte(1);
            }
            else if (Value.GetType() == typeof(byte))
            {
                tmp = BitConverter.GetBytes((byte)Value);
                writer.WriteByte(2);
            }
            else if (Value.GetType() == typeof(short))
            {
                tmp = BitConverter.GetBytes((short)Value);
                writer.WriteByte(3);
            }
            else if (Value.GetType() == typeof(ushort))
            {
                tmp = BitConverter.GetBytes((ushort)Value);
                writer.WriteByte(4);
            }
            else if (Value.GetType() == typeof(ulong))
            {
                tmp = BitConverter.GetBytes((ulong)Value);
                writer.WriteByte(5);
            }
            else if (Value.GetType() == typeof(long))
            {
                tmp = BitConverter.GetBytes((long)Value);
                writer.WriteByte(6);
            }
            writer.WriteBytes(tmp);
            return(writer.ToByteArray());
        }
Ejemplo n.º 19
0
        private void _Invoke(ref object RetObject, params object[] args)
        {
            if (args.Length < ArgumentTypes.Length) //check if a argument is using "params x[] args"
                throw new Exception("missing arguments");

            List<int> usedDelegates = new List<int>();
            PayloadWriter pw = new PayloadWriter();
            pw.WriteInteger(sharedClass.SharedId);
            pw.WriteInteger(MethodId);
            pw.WriteByte(isDelegate ? (byte)1 : (byte)0);

            if (isDelegate)
            {
                pw.WriteInteger(this.DelegateId);
                pw.WriteInteger(this.sharedClass.SharedId);
            }

            SmartSerializer serializer = new SmartSerializer();
            for (int i = 0; i < args.Length; i++)
            {
                object obj = ArgumentTypes[i].IsByRef ? null : args[i];

                if (DelegateIndex.ContainsKey(i))
                    obj = null;

                byte[] SerializedObj = serializer.Serialize(obj);
                pw.WriteInteger(SerializedObj.Length);
                pw.WriteBytes(SerializedObj);
            }

            for (int i = 0; i < DelegateIndex.Count; i++)
            {
                Delegate del = args[DelegateIndex.Keys[i]] as Delegate;

                if (del != null)
                {
                    if (del.Method == null)
                        throw new Exception("Target delegate is NULL");

                    int id = rnd.Next();
                    while(Delegates.ContainsKey(id))
                        id = rnd.Next();

                    pw.WriteByte(1);
                    SharedDelegate sharedDel = new SharedDelegate(del.Method, sharedClass, del.GetType(), id, del, this.MethodId);
                    sharedDel.sharedMethod.Unchecked = DelegateIndex.Values[i].isUnchecked;
                    sharedDel.sharedMethod.usePacketQueue = DelegateIndex.Values[i].UsePacketQueue;
                    sharedDel.sharedMethod.useUdp = DelegateIndex.Values[i].UseUDP;
                    sharedDel.sharedMethod.NoWaitingTime = DelegateIndex.Values[i].NoWaitingTime;
                    pw.WriteObject(sharedDel);

                    if (!isDelegate)
                    {
                        Delegates.Add(id, sharedDel);
                    }
                    continue;
                }
                pw.WriteByte(0);
            }

            if (Unchecked || useUdp)
            {
                //just execute the method and don't wait for response
                sharedClass.connection.Connection.SendMessage(new MsgExecuteMethod(0, pw.ToByteArray(), false));
            }
            else
            {
                SyncObject syncObject = null;
                Random rnd = new Random();
                int RequestId = rnd.Next();
                lock (sharedClass.connection.MethodRequests)
                {
                    while(sharedClass.connection.MethodRequests.ContainsKey(RequestId))
                        RequestId = rnd.Next();
                    syncObject = new SyncObject(sharedClass.connection.Connection.Connection);
                    sharedClass.connection.MethodRequests.Add(RequestId, syncObject);
                    sharedClass.connection.Connection.SendMessage(new MsgExecuteMethod(RequestId, pw.ToByteArray(), true));
                }
                RetObject = syncObject.Wait<ReturnResult>(null, 0);
            }

            /*if (callback != null)
            {
                sharedClass.connection.BeginSendRequest(pw, callback, true, this.usePacketQueue);
            }
            else
            {
                if (Unchecked || useUdp)
                {
                    //just don't wait till we received something back since it's a VOID anyway
                    sharedClass.connection.BeginSendRequest(pw, (object obj) => { }, false, this.usePacketQueue);
                }
                else
                {
                    RetObject = sharedClass.connection.SendRequest(pw, this.usePacketQueue);
                }
            }*/
            serializer = null;
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Send data to the established connection
        /// </summary>
        /// <param name="Message">The data to send</param>
        /// <param name="Header">The Header to use for adding additional information</param>
        /// <param name="feature">The Feature that has been used for this Message</param>
        /// <param name="OpSocket">The OperationalSocket that has been used for this Message</param>
        internal int SendMessage(IMessage Message, Header Header, Feature feature = null, OperationalSocket OpSocket = null)
        {
            lock (SendLock)
            {
                if (!Connected)
                {
                    return(-1);
                }

                if (Message == null)
                {
                    throw new ArgumentException("Message cannot be null");
                }
                if (Header == null)
                {
                    throw new ArgumentException("Header cannot be null");
                }

                ushort HeaderId = OpSocket != null?OpSocket.Headers.GetHeaderId(Header) : Headers.GetHeaderId(Header);

                byte[] SerializedHeader = Header.Serialize(Header);

                uint messageId = OpSocket != null?OpSocket.MessageHandler.GetMessageId(Message.GetType()) : messageHandler.GetMessageId(Message.GetType());

                if (SerializedHeader.Length >= MAX_PACKET_SIZE)
                {
                    throw new ArgumentException("Header length cannot be greater then " + MAX_PAYLOAD);
                }

                using (MemoryStream outStream = new MemoryStream())
                    using (PayloadWriter pw = new PayloadWriter(outStream))
                    {
                        pw.WriteBytes(new byte[HEADER_SIZE], 0, HEADER_SIZE); //reserve space

                        pw.WriteBytes(SerializedHeader);
                        pw.WriteUInteger(messageId);

                        int packetSize = messageHandler.EncryptMessage(this, Message, outStream);

                        if (pw.Length > MAX_PACKET_SIZE)
                        {
                            throw new OverflowException("Message size cannot be greater then " + MAX_PACKET_SIZE);
                        }

                        int  PayloadLength = pw.Length - Connection.HEADER_SIZE;
                        byte CurPacketId   = 0;
                        int  FeatureId     = feature != null?feature.GetFeatureId() : -1;

                        ushort ConnectionId = OpSocket != null ? OpSocket.ConnectionId : (ushort)0;

                        byte checksum = 0;
                        checksum += (byte)PayloadLength;
                        checksum += CurPacketId;
                        checksum += (byte)ConnectionId;
                        checksum += (byte)HeaderId;
                        checksum += (byte)FeatureId;

                        pw.Position = 0;
                        pw.WriteThreeByteInteger(PayloadLength); //length
                        pw.WriteByte(CurPacketId);               //cur packet id
                        pw.WriteUShort(ConnectionId);            //Connection Id
                        pw.WriteUShort(HeaderId);                //Header Id
                        pw.WriteByte(checksum);
                        pw.WriteInteger(FeatureId);

                        //encrypt the header
                        lock (HeaderEncryption)
                        {
                            HeaderEncryption.Encrypt(pw.GetBuffer(), 0, HEADER_SIZE);

                            byte[] temp = pw.GetBuffer();
                            headerConfuser.Obfuscate(ref temp, 0);
                        }

                        int SendNum = 0;

                        try
                        {
                            for (int i = 0; i < outStream.Length;)
                            {
                                int len = i + 65535 < outStream.Length ? 65535 : (int)outStream.Length - i;
                                Handle.Send(outStream.GetBuffer(), i, len, SocketFlags.None);
                                i       += len;
                                SendNum += len;
                            }
                        }
                        catch (Exception ex)
                        {
                            Disconnect();
                            return(-1);
                        }

                        SysLogger.Log("Send " + outStream.Length, SysLogType.Network);

                        PacketsOut++;
                        DataOut += (ulong)outStream.Length;
                        this.LastPacketSendSW = Stopwatch.StartNew();
                        return(SendNum);
                    }


                /*using (OptimizedPayloadStream ms = new OptimizedPayloadStream(SerializedHeader, HeaderId, feature, OpSocket))
                 * {
                 *  ms.Write(BitConverter.GetBytes(messageId), 0, 4);
                 *
                 *  MemoryStream stream = ms.PayloadFrames[ms.PayloadFrames.Count - 1];
                 *
                 *  int ReservedPos = (int)stream.Position;
                 *  ms.Write(new byte[3], 0, 3); //reserve space
                 *
                 *  ms.WritingMessage = true;
                 *  Serializer.Serialize(ms, Message);
                 *  ms.WritingMessage = false;
                 *
                 *  using (PayloadWriter pw = new PayloadWriter(new MemoryStream(stream.GetBuffer())))
                 *  {
                 *      pw.Position = ReservedPos; //skip MessageId data
                 *      pw.WriteThreeByteInteger(ms.MessageLength);//Reserved Space + MessageId = 7
                 *  }
                 *  ms.Commit(this);
                 *
                 *  for (int i = 0; i < ms.PayloadFrames.Count; i++)
                 *  {
                 *      stream = ms.PayloadFrames[i];
                 *
                 *      lock (HeaderEncryption)
                 *      {
                 *          HeaderEncryption.Encrypt(stream.GetBuffer(), 0, HEADER_SIZE);
                 *
                 *          byte[] temp = stream.GetBuffer();
                 *          headerConfuser.Obfuscate(ref temp, 0);
                 *      }
                 *      //lock (PayloadEncryption)
                 *      //{
                 *      //    PayloadEncryption.Encrypt(stream.GetBuffer(), HEADER_SIZE, (int)stream.Length - HEADER_SIZE);
                 *      //}
                 *
                 *      Handle.Send(stream.GetBuffer(), 0, (int)stream.Length, SocketFlags.None);
                 *  }
                 * }*/
            }
        }
Ejemplo n.º 21
0
        private void BuildFile()
        {
            this.Enabled = false;
            string uploadKey = tbUploadKey.txtbox.Text;
            string time      = nudInterval.Value.ToString();
            string mutex     = Random();

            if (string.IsNullOrEmpty(uploadKey) || string.IsNullOrEmpty(time))
            {
                this.Enabled = true;
                return;
            }
            tbBuildLog.Text += "> Upload Key: " + uploadKey + Environment.NewLine;
            tbBuildLog.Text += "> Log Interval: " + time + Environment.NewLine;
            tbBuildLog.Text += "> Mutex: " + mutex + Environment.NewLine;


            bool   installFile = cbInstallFile.Checked;
            string processName = tbProcessName.txtbox.Text;
            string folder      = tbFolder.txtbox.Text;
            string directory   = cbDirectory.Text;

            bool   hkcu    = cbHKCU.Checked;
            bool   hklm    = cbHKLM.Checked;
            string hkcuKey = tbHKCU.txtbox.Text;
            string hklmKey = tbHKLM.txtbox.Text;

            bool meltFile        = cbMeltFile.Checked;
            bool antis           = cbAntis.Checked;
            bool sendScreenshots = cbSendScreenshots.Checked;
            bool hideFile        = cbHideFile.Checked;
            bool pinlogger       = cbPinlogger.Checked;

            bool stealers = cbStealers.Checked;

            string title       = tbTitle.txtbox.Text;
            string description = tbDescription.txtbox.Text;
            string product     = tbProduct.txtbox.Text;
            string copyright   = tbCopyright.txtbox.Text;
            string version     = tbVersion.txtbox.Text;
            string guid        = tbGUID.txtbox.Text;

            string iconPath   = tbIconPath.txtbox.Text;
            bool   changeIcon = !string.IsNullOrEmpty(tbIconPath.txtbox.Text);

            byte[] iconFile = null;
            if (changeIcon)
            {
                iconFile = File.ReadAllBytes(iconPath);
            }

            using (PayloadWriter pw = new PayloadWriter())
            {
                pw.WriteByte(0x03);
                pw.WriteString(uploadKey);
                pw.WriteString(time);
                pw.WriteString(mutex);
                pw.WriteBool(installFile);
                if (installFile)
                {
                    pw.WriteString(processName);
                    pw.WriteString(folder);
                    pw.WriteString(directory);
                }
                pw.WriteBool(hkcu);
                if (hkcu)
                {
                    pw.WriteString(hkcuKey);
                }
                pw.WriteBool(hklm);
                if (hklm)
                {
                    pw.WriteString(hklmKey);
                }


                pw.WriteBool(meltFile);
                pw.WriteBool(antis);
                pw.WriteBool(sendScreenshots);
                pw.WriteBool(hideFile);
                pw.WriteBool(pinlogger);

                pw.WriteBool(stealers);


                pw.WriteString(title);
                pw.WriteString(description);
                pw.WriteString(product);
                pw.WriteString(copyright);
                pw.WriteString(version);
                pw.WriteString(guid);

                pw.WriteBool(changeIcon);

                if (changeIcon)
                {
                    pw.WriteInteger(iconFile.Length);
                    pw.WriteBytes(iconFile);
                }

                byte[] packet = pw.ToByteArray();
                tbBuildLog.Text += "> Sending packet size: " + packet.Length + Environment.NewLine;
                GlobalVariables.SendData(packet);
            }
        }
Ejemplo n.º 22
0
        private void _Invoke(ref object RetObject, params object[] args)
        {
            if (args.Length < ArgumentTypes.Length) //check if a argument is using "params x[] args"
            {
                throw new Exception("missing arguments");
            }

            List <int>    usedDelegates = new List <int>();
            PayloadWriter pw            = new PayloadWriter();

            pw.WriteInteger(sharedClass.SharedId);
            pw.WriteInteger(MethodId);
            pw.WriteByte(isDelegate ? (byte)1 : (byte)0);

            if (isDelegate)
            {
                pw.WriteInteger(this.DelegateId);
                pw.WriteInteger(this.sharedClass.SharedId);
            }

            SmartSerializer serializer = new SmartSerializer();

            for (int i = 0; i < args.Length; i++)
            {
                object obj = ArgumentTypes[i].IsByRef ? null : args[i];

                if (DelegateIndex.ContainsKey(i))
                {
                    obj = null;
                }

                byte[] SerializedObj = serializer.Serialize(obj);
                pw.WriteInteger(SerializedObj.Length);
                pw.WriteBytes(SerializedObj);
            }

            for (int i = 0; i < DelegateIndex.Count; i++)
            {
                Delegate del = args[DelegateIndex.Keys[i]] as Delegate;

                if (del != null)
                {
                    if (del.Method == null)
                    {
                        throw new Exception("Target delegate is NULL");
                    }

                    int id = rnd.Next();
                    while (Delegates.ContainsKey(id))
                    {
                        id = rnd.Next();
                    }

                    pw.WriteByte(1);
                    SharedDelegate sharedDel = new SharedDelegate(del.Method, sharedClass, del.GetType(), id, del, this.MethodId);
                    sharedDel.sharedMethod.Unchecked      = DelegateIndex.Values[i].isUnchecked;
                    sharedDel.sharedMethod.usePacketQueue = DelegateIndex.Values[i].UsePacketQueue;
                    sharedDel.sharedMethod.useUdp         = DelegateIndex.Values[i].UseUDP;
                    sharedDel.sharedMethod.NoWaitingTime  = DelegateIndex.Values[i].NoWaitingTime;
                    pw.WriteObject(sharedDel);

                    if (!isDelegate)
                    {
                        Delegates.Add(id, sharedDel);
                    }
                    continue;
                }
                pw.WriteByte(0);
            }

            if (Unchecked || useUdp)
            {
                //just execute the method and don't wait for response
                sharedClass.connection.Connection.SendMessage(new MsgExecuteMethod(0, pw.ToByteArray(), false));
            }
            else
            {
                SyncObject syncObject = null;
                Random     rnd        = new Random();
                int        RequestId  = rnd.Next();
                lock (sharedClass.connection.MethodRequests)
                {
                    while (sharedClass.connection.MethodRequests.ContainsKey(RequestId))
                    {
                        RequestId = rnd.Next();
                    }
                    syncObject = new SyncObject(sharedClass.connection.Connection.Connection);
                    sharedClass.connection.MethodRequests.Add(RequestId, syncObject);
                    sharedClass.connection.Connection.SendMessage(new MsgExecuteMethod(RequestId, pw.ToByteArray(), true));
                }
                RetObject = syncObject.Wait <ReturnResult>(null, 0);
            }

            /*if (callback != null)
             * {
             *  sharedClass.connection.BeginSendRequest(pw, callback, true, this.usePacketQueue);
             * }
             * else
             * {
             *  if (Unchecked || useUdp)
             *  {
             *      //just don't wait till we received something back since it's a VOID anyway
             *      sharedClass.connection.BeginSendRequest(pw, (object obj) => { }, false, this.usePacketQueue);
             *  }
             *  else
             *  {
             *      RetObject = sharedClass.connection.SendRequest(pw, this.usePacketQueue);
             *  }
             * }*/
            serializer = null;
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Decrypt the data
        /// </summary>
        /// <param name="Data">The data to decrypt</param>l
        /// <param name="Offset">The index where the data starts</param>
        /// <param name="Length">The length to decrypt</param>
        public void Decrypt(byte[] Data, int Offset, int Length)
        {
            lock (DecState)
            {
                int OrgLen = Length;
                Length += Offset;

                for (int round = 0; round < Rounds; round++)
                {
                    using (PayloadWriter pw = new PayloadWriter(new System.IO.MemoryStream(Data)))
                    {
                        ulong temp_Value = DecState.IV[EncMode == WopEncMode.Simple ? 0 : DecState.IV_Pos]; //is being used for CBC Mode (Block-Cipher-Chaining Mode)
                        for (int i = Offset, k = 0; i < Length; k++)
                        {
                            pw.vStream.Position = i;
                            int   usedsize     = 0;
                            ulong value        = 0;
                            ulong OrgReadValue = 0;

                            if (i + 8 < Length)
                            {
                                OrgReadValue = BitConverter.ToUInt64(Data, i);
                                usedsize     = 8;

                                value = Decrypt_Core_Big(OrgReadValue ^ temp_Value, OrgLen, k);
                                pw.WriteULong(value);
                            }
                            else
                            {
                                OrgReadValue = Data[i];
                                usedsize     = 1;

                                value = Decrypt_Core_Small((byte)OrgReadValue, OrgLen, k);
                                pw.WriteByte((byte)value);
                            }

                            temp_Value    += OrgReadValue;
                            DecState.Seed += (int)value;
                            i             += usedsize;

                            if (EncMode != WopEncMode.Simple)
                            {
                                DecState.Key_Pos  += 1;
                                DecState.Salt_Pos += 1;
                            }
                        }
                    }
                }

                DecState.IV_Pos = (DecState.IV_Pos + 1) % DecState.IV.Length;

                switch (EncMode)
                {
                case WopEncMode.GenerateNewAlgorithm:
                {
                    InstructionInfo tempEncCode = null;
                    InstructionInfo tempDecCode = null;
                    FastRandom      fastRand    = new FastRandom(DecState.Seed);

                    for (int i = 0; i < DecState.Instructions.Length; i++)
                    {
                        GetNextRandomInstruction(fastRand, ref tempEncCode, ref tempDecCode);
                        DecState.Instructions[i] = tempDecCode;
                    }

                    if (UseDynamicCompiler)
                    {
                        DecState.Compile();
                    }
                    break;
                }

                case WopEncMode.ShuffleInstructions:
                {
                    ShuffleInstructions(DecState.Instructions, DecState.Seed);

                    if (UseDynamicCompiler)
                    {
                        DecState.Compile();
                    }
                    break;
                }
                }
            }
        }