示例#1
0
文件: Z.cs 项目: bakape/Loopstream
        public static string comExMsg(uint ec)
        {
            string errmsg = WinapiShit.comEx(ec);

            if (errmsg == "")
            {
                errmsg = "(i don't know what this means but please report it)";
            }

            return("could not start audio capture from device; error code 0x" + ec.ToString("x") + "\r\n\r\n" + errmsg);
        }
示例#2
0
 void doit()
 {
     starget = "WINPECK_ERROR";
     try
     {
         if ((int)target <= 1)
         {
             label1.Text = "Sorry, illegal window id :(";
             throw new Exception();
         }
         uint iproc = WinapiShit.getProcId(target);
         if (iproc <= 1)
         {
             label1.Text = "Sorry, process resolver failed :(";
             throw new Exception();
         }
         System.Diagnostics.Process oproc = System.Diagnostics.Process.GetProcessById((int)iproc);
         if (oproc == null)
         {
             label1.Text = "Sorry, module lookup failed :(";
             throw new Exception();
         }
         string title = WinapiShit.getWinText(target);
         if (string.IsNullOrWhiteSpace(title))
         {
             label1.Text = "Sorry, caption reader failed :(";
             throw new Exception();
         }
         itarget     = (int)target;
         starget     = oproc.ProcessName;
         label1.Text =
             "OK !\n\n" +
             "Proc.ID " + iproc.ToString("X") + "\n" +
             "Window.ID " + target.ToString("X") + "\n" +
             "«" + starget + "»\n\n" +
             "«" + title + "»";
     }
     catch { }
     //this.TopMost = true;
     //this.Focus();
     WinapiShit.topmost(this.Handle);
 }
示例#3
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?"));
            }
        }
示例#4
0
        public Testfeed(LSDevice src, int[] chans, VolumeSlider[] vus, int outDev)
        {
            this.src   = src;
            this.chans = chans;
            this.vus   = vus;
            this.ok    = false;

            dummies = new List <DummySink>();

            try
            {
                cap = null;
                if (src.isPlay)
                {
                    cap = new WasapiLoopbackCapture(src.mm);
                }
                else
                {
                    cap = new WasapiCapture(src.mm);
                }
            }
            catch (System.Runtime.InteropServices.COMException ce)
            {
                string errmsg = WinapiShit.comEx((uint)ce.ErrorCode);
                if (errmsg == "")
                {
                    errmsg = "(i don't know what this means but please report it)";
                }

                MessageBox.Show("could not access audio device; error code " + ce.ErrorCode.ToString("x") + "\r\n\r\n" + errmsg);
                return;
            }

            cap.DataAvailable += input_DataAvailable;
            wi = new BufferedWaveProvider(cap.WaveFormat);
            var cap_samples   = wi.ToSampleProvider();
            var chan_splitter = new ChannelSplitter(cap_samples, chans);

            for (var a = 0; a < vus.Length; a++)
            {
                vus[a].SetSource(chan_splitter.output[a]);
                dummies.Add(new DummySink(vus[a]));
            }

            if (outDev >= -1)
            {
                wo = new WaveOut();
                wo.DeviceNumber = outDev;
                wo.Init(chan_splitter);
                wo.Play();
            }
            else
            {
                dummies.Add(new DummySink(chan_splitter));
                wo = null;
            }

            try
            {
                cap.StartRecording();
            }
            catch (System.Runtime.InteropServices.COMException ce)
            {
                MessageBox.Show(WinapiShit.comExMsg((uint)ce.ErrorCode));
                return;
            }
            this.ok = true;
        }
示例#5
0
        void doMagic()
        {
            Logger.mix.a("doMagic");
            cage = new List <Object>();
            string lq = "";

            recCap = null;
            micCap = null;
            recRe  = micRe = null;
            ISampleProvider recProv;

            format = WaveFormat.CreateIeeeFloatWaveFormat(settings.samplerate, 2);
            mixa   = new NPatch.Mixa(format);

            Logger.mix.a("create rec");
            if (settings.devRec is LSDevice)
            {
                recCap = new WasapiLoopbackCapture(((LSDevice)settings.devRec).mm);
            }
            else
            {
                recCap = new LSWavetailDev((LSWavetail)settings.devRec);
            }

            recCap.DataAvailable += recDev_DataAvailable_03;
            recIn = new BufferedWaveProvider(recCap.WaveFormat);

            //recIn.ReadFully = false;
            if (recCap.WaveFormat.SampleRate != settings.samplerate)
            {
                Logger.mix.a("create rec resampler");
                recRe = new MediaFoundationResampler(recIn, settings.samplerate);
                recRe.ResamplerQuality = 60;
                lq += "Incorrect samplerate on music device, resampling\n";

                if (settings.devRec is LSDevice)
                {
                    lq +=
                        ((LSDevice)settings.devRec).mm.DeviceFriendlyName + "\n" +
                        ((LSDevice)settings.devRec).mm.FriendlyName + "\n";
                }

                lq += settings.devRec.id + "\n" +
                      LSDevice.stringer(settings.devRec.wf) + "\n" +
                      LSDevice.stringer(recCap.WaveFormat) + "\n\n";
            }

            recProv = new WaveToSampleProvider((IWaveProvider)recRe ?? (IWaveProvider)recIn);
            if (recCap.WaveFormat.Channels != settings.chRec.Length)
            {
                cage.Add(recProv);
                Logger.mix.a("rec chanselector");
                recProv = new NPatch.ChannelSelectorIn(recProv, settings.chRec, 2);
            }
            cage.Add(recProv);
            recVol = new NPatch.VolumeSlider();
            recVol.SetSource(recProv);
            mixa.AddMixerInput(recVol);
            Logger.mix.a("rec done");

            killmic          = new System.Windows.Forms.Timer();
            killmic.Interval = 1000;
            killmic.Tick    += killmic_Tick;
            micVol           = new NPatch.VolumeSlider();
            lq += micAdd();

            NPatch.Fork fork = new NPatch.Fork(mixa, 2);
            cage.Add(fork);
            lameOutlet = fork.providers[1];
            outVol     = new NPatch.VolumeSlider();
            outVol.SetSource(fork.providers[0]);

            ISampleProvider outProv = outVol;

            if (settings.devOut.wf.Channels != settings.chOut.Length)
            {
                Logger.mix.a("create ChannelMapperOut " + settings.devOut.wf.Channels);
                outProv = new NPatch.ChannelMapperOut(outVol, settings.chOut, settings.devOut.wf.Channels);
                cage.Add(outProv);
            }
            SampleToWaveProvider muxer = new SampleToWaveProvider(outProv);

            cage.Add(muxer);

            Logger.mix.a("init mixer vol");
            recVol.SetVolume((float)settings.mixer.vRec);
            micVol.SetVolume((float)settings.mixer.vMic);
            outVol.SetVolume((float)settings.mixer.vOut);
            recVol.boostLock = (float)settings.mixer.yRec;
            micVol.boostLock = (float)settings.mixer.yMic;
            recVol.boost     = (float)settings.mixer.xRec;
            micVol.boost     = (float)settings.mixer.xMic;
            recVol.muted     = !settings.mixer.bRec;
            micVol.muted     = !settings.mixer.bMic;
            outVol.muted     = !settings.mixer.bOut;

            Logger.mix.a("create mixOut");
            mixOut = new WasapiOut(((LSDevice)settings.devOut).mm,
                                   AudioClientShareMode.Shared, false, 100);

            Logger.mix.a("init mixOut");
            mixOut.Init(muxer);

            try
            {
                Logger.mix.a("rec.startRec");
                recCap.StartRecording();

                if (micCap != null)
                {
                    Logger.mix.a("mic.startRec");
                    micCap.StartRecording();
                }
                //throw new System.Runtime.InteropServices.COMException("fgsfds", 1234);
            }
            catch (System.Runtime.InteropServices.COMException ce)
            {
                string msg = WinapiShit.comExMsg((uint)ce.ErrorCode);
                System.Windows.Forms.MessageBox.Show(msg + "\r\n\r\ngonna crash now, bye");
                throw;
            }

            // give wasapicapture some time to fill the buffer
            startReading = new System.Windows.Forms.Timer();
            //startReading_Tick(null, null);
            startReading.Tick    += startReading_Tick;
            startReading.Interval = 300;
            startReading.Start();

            if (settings.vu)
            {
                recVol.enVU = true;
                micVol.enVU = true;
                outVol.enVU = true;
                bars[0].src = recVol;
                bars[1].src = micVol;
                bars[2].src = outVol;
            }

            if (!string.IsNullOrEmpty(lq))
            {
                isLQ = lq;
            }
        }