void Settings_PropertyChanged(object sender, PropertyChangedEventArgs e) { lock (settingslock) { StaticLogger.Trace("Settings saved"); Settings.Save(SettingsFile); } }
static Bitmap SafeBitmap(string file) { try { return(File.Exists(file) ? new Bitmap(file) : null); } catch (Exception e) { StaticLogger.Trace(e); return(null); } }
public virtual void Stop() { Action <Action> runandlog = delegate(Action act) { try { act(); } catch (Exception ex) { StaticLogger.Trace(ex); } }; runandlog(SourceTcp.Close); runandlog(RemoteTcp.Close); }
protected void CheckLoop() { while (CheckThread != null) { if (CurrentProcess == null || CurrentProcess.HasExited) { IsInjected = false; CurrentProcess = Process.GetProcessesByName(ProcessName).FirstOrDefault(); if (CurrentProcess != null) { try { Inject(); IsInjected = true; } catch (FileNotFoundException fe) { //LoLClient does not have ws2_32 yet. Lets try again in 1 second. StaticLogger.Trace(fe.Message); CurrentProcess = null; Thread.Sleep(1000); continue; } catch (WarningException we) { IsInjected = true; StaticLogger.Info(we.Message); } catch (NotSupportedException nse) { StaticLogger.Warning(nse); } catch (Exception ex) { StaticLogger.Error(new Exception(string.Format("{0} [{1}]", ex.Message, From), ex)); } } } Thread.Sleep(500); } }
protected void CheckLoop() { bool showedError = false; while (CheckThread != null) { if (CurrentProcess != null) { try { if (CurrentProcess.HasExited) { CurrentProcess = null; IsInjected = false; // update icon } } catch (Exception ex) { if (!showedError) { ErrorMessage = "Privilege of LoLNotes must be greater or equal to that of the LoLClient.\n\nSituations where LoLClient is run as admin and LoLNotes is not are no good."; showedError = true; } StaticLogger.Error(ex); CurrentProcess = null; IsInjected = false; // update icon } } if (CurrentProcess == null) { CurrentProcess = Process.GetProcessesByName(ProcessName).FirstOrDefault(); if (CurrentProcess != null) { try { Inject(); IsInjected = true; } catch (FileNotFoundException fe) { //LoLClient does not have ws2_32 yet. Lets try again in 1 second. StaticLogger.Trace(fe.Message); CurrentProcess = null; Thread.Sleep(1000); continue; } catch (WarningException we) { IsInjected = true; StaticLogger.Info(we.Message); } catch (NotSupportedException nse) { StaticLogger.Warning(nse); } catch (Exception ex) { StaticLogger.Error(new Exception(string.Format("{0} [{1}]", ex.Message, From), ex)); } } } Thread.Sleep(500); } }
protected override void OnReceive(byte[] buffer, int idx, int len) { StaticLogger.Trace(string.Format("Recv {0} bytes", len)); if (logtofiles) { using (var fs = File.Open("realrecv.dmp", FileMode.Append, FileAccess.Write)) { fs.Write(buffer, idx, len); } } receivebuffer.Append(buffer, idx, len); var objs = RtmpProtocolDecoder.DecodeBuffer(remotecontext, receivebuffer); if (objs != null) { foreach (var obj in objs) { var pck = obj as RtmpPacket; if (pck != null) { var result = pck.Message as Notify; if (result != null) { Notify inv = null; if (RtmpUtil.IsResult(result)) { lock (InvokeList) { int fidx = InvokeList.FindIndex(i => i.InvokeId == result.InvokeId); if (fidx != -1) { inv = InvokeList[fidx]; InvokeList.RemoveAt(fidx); } } if (inv != null) { OnCall(inv, result); StaticLogger.Trace( string.Format( "Ret ({0}) (Id:{1})", string.Join(", ", inv.ServiceCall.Arguments.Select(o => o.ToString())), pck.Header.ChannelId ) ); } } else { OnNotify(result); } } else { StaticLogger.Trace(string.Format("Recv {0} (Id:{1})", pck.Message, pck.Header.ChannelId)); } } else if (obj is ByteBuffer) { //Just handshakes, ignore } else { StaticLogger.Warning(string.Format("Unknown object {0}", obj.GetType())); } if (obj != null && encode) { if (pck != null && pck.Message is Notify) { InternalReceive((Notify)pck.Message); remotecontext.ObjectEncoding = ObjectEncoding.AMF3; } else { var buf = RtmpProtocolEncoder.Encode(remotecontext, obj); if (buf == null) { StaticLogger.Fatal("Unable to encode " + obj); } else { var buff = buf.ToArray(); if (logtofiles) { using (var fs = File.Open("recv.dmp", FileMode.Append, FileAccess.Write)) { fs.Write(buff, 0, buff.Length); } } if (encode) { base.OnReceive(buff, 0, buff.Length); } } } } } } if (!encode) { base.OnReceive(buffer, idx, len); } }
protected override void OnSend(byte[] buffer, int idx, int len) { if (postbuffer != null) { postbuffer.Append(buffer, idx, len); if (postbuffer.Length > 4) { int num = postbuffer.GetInt(); postbuffer.Dispose(); postbuffer = null; if (num == 0x504f5354) { StaticLogger.Trace(string.Format("Rejecting POST request", len)); Stop(); return; } } } StaticLogger.Trace(string.Format("Send {0} bytes", len)); if (logtofiles) { using (var fs = File.Open("realsend.dmp", FileMode.Append, FileAccess.Write)) { fs.Write(buffer, idx, len); } } sendbuffer.Append(buffer, idx, len); var objs = RtmpProtocolDecoder.DecodeBuffer(sourcecontext, sendbuffer); if (objs != null) { foreach (var obj in objs) { var pck = obj as RtmpPacket; if (pck != null) { var inv = pck.Message as Notify; if (inv != null) { lock (InvokeList) { InvokeList.Add(inv); } StaticLogger.Trace( string.Format("Call {0}({1}) (Id:{2})", inv.ServiceCall.ServiceMethodName, string.Join(", ", inv.ServiceCall.Arguments.Select(o => o.ToString())), pck.Header.ChannelId ) ); } else { StaticLogger.Trace(string.Format("Sent {0} (Id:{1})", pck.Message.GetType(), pck.Header.ChannelId)); } } else if (obj is ByteBuffer) { //Just handshakes, ignore } else { StaticLogger.Warning(string.Format("Unknown object {0}", obj.GetType())); } if (obj != null && encode) { if (pck != null && pck.Message is Notify) { InternalSend((Notify)pck.Message, true); sourcecontext.ObjectEncoding = ObjectEncoding.AMF3; } else { var buf = RtmpProtocolEncoder.Encode(sourcecontext, obj); if (buf == null) { StaticLogger.Fatal("Unable to encode " + obj); } else { var buff = buf.ToArray(); if (logtofiles) { using (var fs = File.Open("send.dmp", FileMode.Append, FileAccess.Write)) { fs.Write(buff, 0, buff.Length); } } if (encode) { base.OnSend(buff, 0, buff.Length); } } } } } } if (!encode) { base.OnSend(buffer, idx, len); } }