Пример #1
0
        public static LSTD get(LSSettings.LSMeta m, bool getRaw)
        {
            if (m.reader == LSSettings.LSMeta.Reader.WindowCaption)
            {
                if (m.src.Trim() == "*")
                {
                    int   myId    = System.Diagnostics.Process.GetCurrentProcess().Id;
                    int[] handles = EnumHandles.Run();
                    foreach (int hWnd in handles)
                    {
                        IntPtr ptr  = new IntPtr(hWnd);
                        uint   proc = WinapiShit.getProcId(ptr);
                        if (proc <= 1)
                        {
                            continue;
                        }
                        if (proc == myId)
                        {
                            continue;
                        }
                        string text = WinapiShit.getWinText(ptr);
                        if (string.IsNullOrEmpty(text))
                        {
                            continue;
                        }

                        //gList.Items.Add("<" + hWnd + "> // <" + proc + "> // <" + text + ">");
                        LSTD td = get(m, text);
                        if (td.ok)
                        {
                            return(td);
                        }
                    }
                    return(new LSTD(false, "(no hits)",
                                    "The pattern in this profile did not match any of your windows.\n" +
                                    "\n" +
                                    "If you are using an in-browser media player (cloud service),\n" +
                                    "make sure the media player is in a dedicated browser window.\n" +
                                    "\n" +
                                    "(you must construct additional windows)"));
                }


                string raw = null;
                if (m.src.Contains('*'))
                {
                    raw = WinapiShit.getWinText(new IntPtr(Convert.ToInt32(m.src.Split('*')[1], 16)));
                }
                if (string.IsNullOrEmpty(raw))
                {
                    Process[] proc = Process.GetProcessesByName(m.src.Split('*')[0]);
                    if (proc.Length < 1)
                    {
                        return(new LSTD(false, "(no such process)", "The media player  «" + m.src + "»  could not be found!\n\nAre you sure that it is running?"));
                    }
                    raw = proc[0].MainWindowTitle;
                }
                if (string.IsNullOrEmpty(raw))
                {
                    return(new LSTD(false, "(no such target)", "The media player  «" + m.src + "»  could not be found!\n\nAre you sure that it is running?"));
                }
                return(getRaw ? new LSTD(true, raw, "SUCCESS") : get(m, raw));
            }
            if (m.reader == LSSettings.LSMeta.Reader.File)
            {
                try
                {
                    string ret = System.IO.File.ReadAllText(m.src, m.enc);
                    return(getRaw ? new LSTD(true, ret, "SUCCESS") : get(m, ret));
                }
                catch
                {
                    return(new LSTD(false, "(file read failure)", "Something went wrong while reading the provided file.\nAre you sure it exists?\n\nPath: " + m.src));
                }
            }
            if (m.reader == LSSettings.LSMeta.Reader.Website)
            {
                byte[] b;
                try
                {
                    b = new System.Net.WebClient().DownloadData(m.src);
                    try
                    {
                        string ret = m.enc.GetString(b);
                        return(getRaw ? new LSTD(true, ret, "SUCCESS") : get(m, ret));
                    }
                    catch
                    {
                        return(new LSTD(false, "(web decode failure)", "I failed to unpack the data from the web server.\nMaybe incorrect address?\n\nLink: " + m.src));
                    }
                }
                catch
                {
                    return(new LSTD(false, "(web request failure)", "I failed to download the data from the web server.\nMaybe it is down?\n\nLink: " + m.src));
                }
            }
            if (m.reader == LSSettings.LSMeta.Reader.ProcessMemory)
            {
                // this is the fun one
                Process[] proc = Process.GetProcessesByName(m.src);
                if (proc.Length < 1)
                {
                    return(new LSTD(false, "(no such process)", "The media player  «" + m.src + "»  could not be found!\n\nAre you sure that it is running?"));
                }
                LSMem mem;
                try
                {
                    mem = new LSMem(proc[0]);
                }
                catch
                {
                    return(new LSTD(false, "(poke failure)", "I failed to harvest the metadata from inside  «" + m.src + "»...\n\nMaybe system permissions blocked the request?\nTry running Loopstream as administrator."));
                }
                try
                {
                    string        ret      = "";
                    string        lpm      = "";
                    bool          hadError = false;
                    ProcessModule pm       = null;
                    byte[]        raw      = new byte[1024];
                    string[]      ad       = m.ptn.Split(' ');
                    for (int a = 0; a < ad.Length; a++)
                    {
                        string arg = ad[a].Trim(',', ' ');
                        IntPtr ofs = IntPtr.Zero;
                        if (arg.Contains('+'))
                        {
                            string[] args = arg.Split('+');
                            if (args[0] != lpm)
                            {
                                pm  = null;
                                lpm = null;
                                foreach (ProcessModule mod in proc[0].Modules)
                                {
                                    if (mod.ModuleName == args[0])
                                    //if (mod.FileName.EndsWith("\\iTunes.dll"))
                                    {
                                        pm  = mod;
                                        lpm = pm.ModuleName;
                                        ofs = pm.BaseAddress;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                ofs = pm.BaseAddress;
                            }
                            arg = args[1];
                        }
                        int[] steps = new int[0];
                        if (arg.Contains('*'))
                        {
                            string[] args = arg.Split('*');
                            steps = new int[args.Length - 1];
                            for (int b = 1; b < args.Length; b++)
                            {
                                steps[b - 1] = Convert.ToInt32(args[b], 16);
                            }
                            arg = args[0];
                        }
                        ofs += Convert.ToInt32(arg, 16);
                        ret += a == 0 || ret.Length == 0 ? "" : " - ";
                        int len = mem.read(ofs, raw, steps);
                        if (len < 0)
                        {
                            ret     += "(read error)";
                            hadError = true;
                        }
                        else if (len > 0)
                        {
                            ret += m.enc.GetString(raw);
                            int i = ret.IndexOf('\0');
                            if (i >= 0)
                            {
                                ret = ret.Substring(0, i);
                            }
                        }
                    }
                    return(new LSTD(!hadError, ret, hadError ? "Could not peek into the target application.\n\nThe media player is likely a 32bit process, while\nLoopstream is running in 64bit mode\n(or the other way around)." : "SUCCESS"));
                }
                catch
                {
                    return(new LSTD(false, "(peek failure)", "I failed to harvest the metadata from inside  «" + m.src + "»...\n\nThis is probably a bug in Loopstream,  but it could\nalso be system permissions getting in the way.\n\nYou could try running Loopstream as Administrator."));
                }
            }
            try
            {
                return(new LSTD(false, "(unexpected metadata reader)", "You somehow managed to select a\nMetaReader which does not exist:\n\n      «" + m.reader.ToString() + "»"));
            }
            catch
            {
                return(new LSTD(false, "(unexpected metadata reader)", "You somehow managed to select a\nMetaReader which does not exist. How?"));
            }
        }
Пример #2
0
        public static LSTD get(LSSettings.LSMeta m, bool getRaw)
        {
            if (m.reader == LSSettings.LSMeta.Reader.WindowCaption)
            {
                if (m.src.Trim() == "*")
                {
                    int myId = System.Diagnostics.Process.GetCurrentProcess().Id;
                    int[] handles = EnumHandles.Run();
                    foreach (int hWnd in handles)
                    {
                        IntPtr ptr = new IntPtr(hWnd);
                        uint proc = WinapiShit.getProcId(ptr);
                        if (proc <= 1) continue;
                        if (proc == myId) continue;
                        string text = WinapiShit.getWinText(ptr);
                        if (string.IsNullOrEmpty(text)) continue;

                        //gList.Items.Add("<" + hWnd + "> // <" + proc + "> // <" + text + ">");
                        LSTD td = get(m, text);
                        if (td.ok)
                        {
                            return td;
                        }
                    }
                    return new LSTD(false, "(no hits)",
                        "The pattern in this profile did not match any of your windows.\n" +
                        "\n" +
                        "If you are using an in-browser media player (cloud service),\n" +
                        "make sure the media player is in a dedicated browser window.\n" +
                        "\n" +
                        "(you must construct additional windows)");
                }

                string raw = null;
                if (m.src.Contains('*'))
                {
                    raw = WinapiShit.getWinText(new IntPtr(Convert.ToInt32(m.src.Split('*')[1], 16)));
                }
                if (string.IsNullOrEmpty(raw))
                {
                    Process[] proc = Process.GetProcessesByName(m.src.Split('*')[0]);
                    if (proc.Length < 1)
                    {
                        return new LSTD(false, "(no such process)", "The media player  «" + m.src + "»  could not be found!\n\nAre you sure that it is running?");
                    }
                    raw = proc[0].MainWindowTitle;
                }
                if (string.IsNullOrEmpty(raw))
                {
                    return new LSTD(false, "(no such target)", "The media player  «" + m.src + "»  could not be found!\n\nAre you sure that it is running?");
                }
                return getRaw ? new LSTD(true, raw, "SUCCESS") : get(m, raw);
            }
            if (m.reader == LSSettings.LSMeta.Reader.File)
            {
                try
                {
                    string ret = System.IO.File.ReadAllText(m.src, m.enc);
                    return getRaw ? new LSTD(true, ret, "SUCCESS") : get(m, ret);
                }
                catch
                {
                    return new LSTD(false, "(file read failure)", "Something went wrong while reading the provided file.\nAre you sure it exists?\n\nPath: " + m.src);
                }
            }
            if (m.reader == LSSettings.LSMeta.Reader.Website)
            {
                byte[] b;
                try
                {
                    b = new System.Net.WebClient().DownloadData(m.src);
                    try
                    {
                        string ret = m.enc.GetString(b);
                        return getRaw ? new LSTD(true, ret, "SUCCESS") : get(m, ret);
                    }
                    catch
                    {
                        return new LSTD(false, "(web decode failure)",  "I failed to unpack the data from the web server.\nMaybe incorrect address?\n\nLink: " + m.src);
                    }
                }
                catch
                {
                    return new LSTD(false, "(web request failure)", "I failed to download the data from the web server.\nMaybe it is down?\n\nLink: " + m.src);
                }
            }
            if (m.reader == LSSettings.LSMeta.Reader.ProcessMemory)
            {
                // this is the fun one
                Process[] proc = Process.GetProcessesByName(m.src);
                if (proc.Length < 1)
                {
                    return new LSTD(false, "(no such process)", "The media player  «" + m.src + "»  could not be found!\n\nAre you sure that it is running?");
                }
                LSMem mem;
                try
                {
                    mem = new LSMem(proc[0]);
                }
                catch
                {
                    return new LSTD(false, "(poke failure)", "I failed to harvest the metadata from inside  «" + m.src + "»...\n\nMaybe system permissions blocked the request?\nTry running Loopstream as administrator.");
                }
                try
                {
                    string ret = "";
                    string lpm = "";
                    bool hadError = false;
                    ProcessModule pm = null;
                    byte[] raw = new byte[1024];
                    string[] ad = m.ptn.Split(' ');
                    for (int a = 0; a < ad.Length; a++)
                    {
                        string arg = ad[a].Trim(',', ' ');
                        IntPtr ofs = IntPtr.Zero;
                        if (arg.Contains('+'))
                        {
                            string[] args = arg.Split('+');
                            if (args[0] != lpm)
                            {
                                pm = null;
                                lpm = null;
                                foreach (ProcessModule mod in proc[0].Modules)
                                {
                                    if (mod.ModuleName == args[0])
                                    //if (mod.FileName.EndsWith("\\iTunes.dll"))
                                    {
                                        pm = mod;
                                        lpm = pm.ModuleName;
                                        ofs = pm.BaseAddress;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                ofs = pm.BaseAddress;
                            }
                            arg = args[1];
                        }
                        int[] steps = new int[0];
                        if (arg.Contains('*'))
                        {
                            string[] args = arg.Split('*');
                            steps = new int[args.Length-1];
                            for (int b = 1; b < args.Length; b++)
                            {
                                steps[b - 1] = Convert.ToInt32(args[b], 16);
                            }
                            arg = args[0];
                        }
                        ofs += Convert.ToInt32(arg, 16);
                        ret += a == 0 || ret.Length == 0 ? "" : " - ";
                        int len = mem.read(ofs, raw, steps);
                        if (len < 0)
                        {
                            ret += "(read error)";
                            hadError = true;
                        }
                        else if (len > 0)
                        {
                            ret += m.enc.GetString(raw);
                            int i = ret.IndexOf('\0');
                            if (i >= 0)
                            {
                                ret = ret.Substring(0, i);
                            }
                        }
                    }
                    return new LSTD(!hadError, ret, hadError ? "Could not peek into the target application.\n\nThe media player is likely a 32bit process, while\nLoopstream is running in 64bit mode\n(or the other way around)." : "SUCCESS");
                }
                catch
                {
                    return new LSTD(false, "(peek failure)", "I failed to harvest the metadata from inside  «" + m.src + "»...\n\nThis is probably a bug in Loopstream,  but it could\nalso be system permissions getting in the way.\n\nYou could try running Loopstream as Administrator.");
                }
            }
            try
            {
                return new LSTD(false, "(unexpected metadata reader)", "You somehow managed to select a\nMetaReader which does not exist:\n\n      «" + m.reader.ToString() + "»");
            }
            catch
            {
                return new LSTD(false, "(unexpected metadata reader)", "You somehow managed to select a\nMetaReader which does not exist. How?");
            }
        }