Ejemplo n.º 1
0
 private void RegValueKind(TFunctionData _sframe)
 {
     _sframe.AssertParamCount(3);
     using (RegistryKey key = OpenKey(_sframe.GetParameter <string>(1), false)) {
         _sframe.Data = key.GetValueKind(_sframe.GetParameter <string>(2)).ToString();
     }
 }
Ejemplo n.º 2
0
 private static void RegEnumKeys(TFunctionData _sframe)
 {
     _sframe.AssertParamCount(2);
     using (RegistryKey key = OpenKey(_sframe.GetParameter <string>(1), false)) {
         _sframe.Data = key.GetSubKeyNames();
     }
 }
Ejemplo n.º 3
0
        private void FileWriteAll(TFunctionData _sframe)
        {
            _sframe.AssertParamCount(3);
            string path = _sframe.GetParameter <string>(1);
            object data = _sframe.GetParameter(2);

            string sData = data as string;

            if (sData != null)
            {
                File.WriteAllText(path, sData);
            }

            string[] saData = data as string[];
            if (saData != null)
            {
                File.WriteAllLines(path, saData);
            }

            byte[] bData = data as byte[];
            if (bData != null)
            {
                File.WriteAllBytes(path, bData);
            }

            _sframe.Status = ErrorSuccess.Warnings; // data is written, but not necessarily useful
            File.WriteAllText(path, data + "");
        }
Ejemplo n.º 4
0
        internal void DIM(TFunctionData stackFrame)
        {
            if (stackFrame.ParameterCount < 2)
            {
                stackFrame.AssertParamCount(2);
            }

            StringSegment text    = new StringSegment(stackFrame.Text);
            Scanner       scanner = new Scanner(text);

            scanner.IntPosition += stackFrame.Name.Length;
            scanner.SkipWhiteSpace();

            Variable v;

            if (!scanner.NextVariable(stackFrame.StackExecuter, out v))
            {
                throw ThrowHelper.InvalidVariableName();
            }

            string        name    = v.Name.ToString();
            ObjectContext context = stackFrame.Context.FindVariableContext(name);

            if (context == null)
            {
                stackFrame.Context.SetVariable(name, array_alloc(v.Indices, 0));
            }
            else
            {
                object obj = context.GetVariable(name);
                array_realloc(ref obj, v.Indices, 0);
                context.SetVariable(name, obj);
            }
            NULL(stackFrame);
        }
Ejemplo n.º 5
0
        private void WinList(TFunctionData parameters)
        {
            if (parameters.ParameterCount == 1)
            {
                parameters.AddParameter(WindowFlag.Existing);
            }
            parameters.AssertParamCount(2);
            WindowFlag state = parameters.GetParameter <WindowFlag>(1);

            IntPtr[] hwnds = WinList(state).ToArray();

            if (hwnds.Length > 0)
            {
                object[][] windows = new object[hwnds.Length][];
                for (int index = 0; index < windows.Length; index++)
                {
                    windows[index] = new object[] {
                        Evaluator.ConvertToObject(hwnds[index]),
                        WinGetTitle(hwnds[index])
                    };
                }
                parameters.Data = windows;
            }
            else
            {
                parameters.Status = ErrorSuccess.NoContent;
            }
        }
Ejemplo n.º 6
0
        private void ArrayLastIndexOf(TFunctionData stackFrame)
        {
            object[] arr = stackFrame.GetParameter <object[]>(1);
            if (stackFrame.ParameterCount == 3)
            {
                stackFrame.AddParameter(0);
            }
            if (stackFrame.ParameterCount == 4)
            {
                stackFrame.AddParameter(arr.Length);
            }
            stackFrame.AssertParamCount(5);
            int    i     = stackFrame.GetParameter <int>(3);
            object o     = stackFrame.GetParameter(2);
            int    count = stackFrame.GetParameter <int>(5);

            for (; i >= 0 && i > count; i--)
            {
                if (arr[i] == o)
                {
                    stackFrame.Data = i;
                    return;
                }
            }
            stackFrame.Data = -1;
        }
Ejemplo n.º 7
0
        private void GetScreen(TFunctionData parameters)
        {
            parameters.AssertParamCount(2);
            int compression = parameters.GetFromIntRange(1, 0, 100);

            parameters.Data = GetScreen(compression);
        }
Ejemplo n.º 8
0
        private void MouseClick(TFunctionData _sframe)
        {
            if (_sframe.ParameterCount == 4)
            {
                _sframe.AddParameter(1);
                _sframe.AddParameter(1);
            }
            if (_sframe.ParameterCount == 5)
            {
                _sframe.AddParameter(5);
            }
            _sframe.AssertParamCount(6);

            int x      = _sframe.GetParameter <int>(2),
                y      = _sframe.GetParameter <int>(3),
                clicks = _sframe.GetParameter <int>(4),
                speed  = _sframe.GetParameter <int>(5);

            MouseButton button;

            if (_sframe.GetFromEnum(1, "button", "LEFT", "RIGHT").EqualsIgnoreCase("LEFT"))
            {
                button = MouseButton.Left;
            }
            else
            {
                button = MouseButton.Right;
            }
            MouseClick(button, x, y, clicks, speed);
        }
Ejemplo n.º 9
0
 private void RegDeleteKey(TFunctionData _sframe)
 {
     _sframe.AssertParamCount(2);
     using (RegistryKey key = GetRootKey(_sframe.GetParameter <string>(1))) {
         key.DeleteSubKeyTree(RemoveKeyRoot(_sframe.GetParameter <string>(1)));
     }
 }
Ejemplo n.º 10
0
 private void RegRenameKey(TFunctionData _sframe)
 {
     _sframe.AssertParamCount(3);
     using (RegistryKey key = OpenParentKey(_sframe.GetParameter <string>(1), true)) {
         RegistryUtilities.RenameSubKey(key, RemoveKeyRoot(_sframe.GetParameter <string>(1)), _sframe.GetParameter <string>(2));
     }
 }
Ejemplo n.º 11
0
        private void Shell(TFunctionData _sframe)
        {
            _sframe.AssertParamCount(2);
            string output;

            _sframe.Status = Shell(_sframe.GetParameter <string>(1), out output);
            _sframe.Data   = output;
        }
Ejemplo n.º 12
0
        private void FileGetAttributes(TFunctionData _sframe)
        {
            _sframe.AssertParamCount(2);
            string         path    = _sframe.GetParameter <string>(1);
            FileAttributes current = File.GetAttributes(path);

            _sframe.Data = GetStringFromAttributes(current);
        }
Ejemplo n.º 13
0
        private void IsDefined(TFunctionData stackFrame)
        {
            stackFrame.AssertParamCount(2);
            string        name    = stackFrame.GetParameter <string>(1);
            ObjectContext context = stackFrame.Context.FindContext(name);

            stackFrame.Data = context != null;
        }
Ejemplo n.º 14
0
        private void WinPicture(TFunctionData parameters)
        {
            parameters.AssertParamCount(3);
            int    compression = parameters.GetFromIntRange(2, 0, 100);
            IntPtr hwnd        = new IntPtr(parameters.GetParameter <long>(1));

            parameters.Data = WinPicture(hwnd, compression);
        }
Ejemplo n.º 15
0
 private void WinActivate(TFunctionData parameters)
 {
     parameters.AssertParamCount(2);
     if (!WinActivate(new IntPtr(parameters.GetParameter <long>(1))))
     {
         throw new TbasicException(ErrorServer.GenericError, "Unable to activate window");
     }
 }
Ejemplo n.º 16
0
 private void RegCreateKey(TFunctionData _sframe)
 {
     _sframe.AssertParamCount(3);
     using (RegistryKey key = OpenKey(_sframe.GetParameter <string>(1), true)) {
         key.CreateSubKey(_sframe.GetParameter <string>(2));
         _sframe.Status = ErrorSuccess.Created;
     }
 }
Ejemplo n.º 17
0
 private void BlockInput(TFunctionData _sframe)
 {
     _sframe.AssertParamCount(2);
     _sframe.SetAll(_sframe.GetParameter(0), _sframe.GetParameter(1).ToString().Replace("1", "true").Replace("0", "false"));
     if (!BlockInput(_sframe.GetParameter <bool>(1)))
     {
         _sframe.Status = ErrorClient.Forbidden;
     }
 }
Ejemplo n.º 18
0
 private void Round(TFunctionData stackFrame)
 {
     if (stackFrame.ParameterCount == 2)
     {
         stackFrame.AddParameter(2);
     }
     stackFrame.AssertParamCount(3);
     stackFrame.Data = Round(stackFrame.GetParameter <double>(1), stackFrame.GetParameter <int>(2));
 }
Ejemplo n.º 19
0
        private void RegWrite(TFunctionData _sframe)
        {
            _sframe.AssertParamCount(5);

            object value = _sframe.GetParameter(3);

            RegistryValueKind kind;

            switch (_sframe.GetParameter <string>(4).ToLower())
            {
            case "binary":
                kind = RegistryValueKind.Binary;
                List <string> slist = new List <string>();
                slist.AddRange(_sframe.GetParameter <string>(3).Split(' '));
                value = slist.ConvertAll(s => Convert.ToByte(s, 16)).ToArray();
                break;

            case "dword":
                kind = RegistryValueKind.DWord;
                break;

            case "expandstring":
                kind = RegistryValueKind.ExpandString;
                break;

            case "multistring":
                kind = RegistryValueKind.MultiString;
                if (value is string)
                {
                    value = _sframe.GetParameter <string>(3).Replace("\r\n", "\n").Split('\n');
                }
                else if (value is string[])
                {
                    value = _sframe.GetParameter <string[]>(3);
                }
                else
                {
                    throw new ArgumentException("Parameter is not a valid multi-string");
                }
                break;

            case "qword":
                kind = RegistryValueKind.QWord;
                break;

            case "string":
                kind = RegistryValueKind.String;
                break;

            default:
                throw new ArgumentException("Unknown registry type '" + _sframe.GetParameter(4) + "'");
            }

            using (RegistryKey key = OpenKey(_sframe.GetParameter <string>(1), true)) {
                key.SetValue(_sframe.GetParameter <string>(2), value, kind);
            }
        }
Ejemplo n.º 20
0
 private void VolumeDown(TFunctionData _sframe)
 {
     if (_sframe.ParameterCount == 1)
     {
         _sframe.SetAll(_sframe.GetParameter(0), "1");
     }
     _sframe.AssertParamCount(2);
     VolumeDown(_sframe.GetParameter <int>(1));
 }
Ejemplo n.º 21
0
        private void RegDelete(TFunctionData _sframe)
        {
            _sframe.AssertParamCount(3);
            RegistryKey key = GetRootKey(_sframe.GetParameter <string>(1));

            using (key = key.OpenSubKey(RemoveKeyRoot(_sframe.GetParameter <string>(1)), true)) {
                key.DeleteValue(_sframe.GetParameter <string>(2), true);
            }
        }
Ejemplo n.º 22
0
 private void ToInt(TFunctionData stackFrame)
 {
     stackFrame.AssertParamCount(2);
     try {
         stackFrame.Data = stackFrame.GetParameter <int>(1);
     }
     catch (InvalidCastException) {
         throw new TbasicException(ErrorClient.BadRequest, "Parameter cannot be int");
     }
 }
Ejemplo n.º 23
0
        private void WinSetTrans(TFunctionData parameters)
        {
            parameters.AssertParamCount(3);
            IntPtr hwnd = new IntPtr(parameters.GetParameter <long>(1));

            if (!WinSetTrans(hwnd, parameters.GetParameter <byte>(2)))
            {
                throw new TbasicException(ErrorServer.GenericError, "Unable to set window transparency");
            }
        }
Ejemplo n.º 24
0
        private void WinKill(TFunctionData parameters)
        {
            parameters.AssertParamCount(2);
            long hwnd = parameters.GetParameter <long>(1);

            if (!WinKill(new IntPtr(hwnd)))
            {
                throw new TbasicException(ErrorServer.GenericError, "Unable to kill window");
            }
        }
Ejemplo n.º 25
0
        private void WinSize(TFunctionData parameters)
        {
            parameters.AssertParamCount(4);
            IntPtr hwnd = new IntPtr(parameters.GetParameter <long>(1));

            if (!WinSize(hwnd, parameters.GetParameter <int>(2), parameters.GetParameter <int>(3)))
            {
                throw new TbasicException(ErrorServer.GenericError, "Unable to resize window");
            }
        }
Ejemplo n.º 26
0
        private void WinSetState(TFunctionData parameters)
        {
            parameters.AssertParamCount(3);
            uint flag = parameters.GetParameter <uint>(2);

            if (!WinSetState(new IntPtr(parameters.GetParameter <long>(1)), flag))
            {
                throw new TbasicException(ErrorServer.GenericError, "Unable to set window state");
            }
        }
Ejemplo n.º 27
0
        private void WinSetTitle(TFunctionData parameters)
        {
            parameters.AssertParamCount(3);
            IntPtr hwnd = new IntPtr(parameters.GetParameter <long>(1));

            if (!User32.SetWindowText(hwnd, parameters.GetParameter <string>(2)))
            {
                throw new TbasicException(ErrorServer.GenericError, "Unable to set window title");
            }
        }
Ejemplo n.º 28
0
 private void Eval(TFunctionData stackFrame)
 {
     stackFrame.AssertParamCount(2);
     try {
         stackFrame.Data = Eval(stackFrame.GetParameter <string>(1));
     }
     catch (Exception ex) {
         throw TbasicException.WrapException(ex);
     }
 }
Ejemplo n.º 29
0
 public FuncBlock(int index, LineCollection code)
 {
     LoadFromCollection(
         code.ParseBlock(
             index,
             c => c.Name.EqualsIgnoreCase("FUNCTION"),
             c => c.Text.EqualsIgnoreCase("END FUNCTION")
             ));
     Template = new TFunctionData(null);
     Template.SetAll(ParseFunction(Header.Text.Substring(Header.Name.Length)));
 }
Ejemplo n.º 30
0
        private void CharsToString(TFunctionData stackFrame)
        {
            stackFrame.AssertParamCount(2);
            StringBuilder hanz = new StringBuilder();

            foreach (char c in stackFrame.GetParameter <char[]>(1))
            {
                hanz.Append(c);
            }
            stackFrame.Data = hanz.ToString();
        }