Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.IO;
- using System.Runtime.InteropServices;
- using DWORD = System.UInt32;
- namespace ChatBlocker
- {
- class Program
- {
- public enum State{
- All=0,
- Closed=1,
- Listen=2,
- Syn_Sent=3,
- Syn_Rcvd=4,
- Established=5,
- Fin_Wait1=6,
- Fin_Wait2=7,
- Close_Wait=8,
- Closing=9,
- Last_Ack=10,
- Time_Wait=11,
- Delete_TCB=12
- }
- private struct MIB_TCPROW{
- public int dwState;
- public int dwLocalAddr;
- public int dwLocalPort;
- public int dwRemoteAddr;
- public int dwRemotePort;
- }
- [DllImport("iphlpapi.dll")]
- private static extern int GetTcpTable(IntPtr pTcpTable,ref int pdwSize,bool bOrder);
- [DllImport("iphlpapi.dll")]
- private static extern int SetTcpEntry(IntPtr pTcprow);
- [DllImport("wsock32.dll")]
- private static extern int ntohs(int netshort);
- [DllImport("wsock32.dll")]
- private static extern int htons(int netshort);
- public static void CloseRemotePort(int port)
- {
- MIB_TCPROW[] rows = getTcpTable();
- for (int i = 0; i < rows.Length; i++)
- {
- if (port == ntohs(rows[i].dwRemotePort))
- {
- rows[i].dwState = (int)State.Delete_TCB;
- IntPtr ptr = GetPtrToNewObject(rows[i]);
- int ret = SetTcpEntry(ptr);
- }
- }
- }
- private static IntPtr GetPtrToNewObject(object obj)
- {
- IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(obj));
- Marshal.StructureToPtr(obj, ptr, false);
- return ptr;
- }
- private static MIB_TCPROW[] getTcpTable()
- {
- IntPtr buffer = IntPtr.Zero; bool allocated = false;
- try
- {
- int iBytes = 0;
- GetTcpTable(IntPtr.Zero, ref iBytes, false); //Getting size of return data
- buffer = Marshal.AllocCoTaskMem(iBytes); //allocating the datasize
- allocated = true;
- GetTcpTable(buffer, ref iBytes, false); //Run it again to fill the memory with the data
- int structCount = Marshal.ReadInt32(buffer); // Get the number of structures
- IntPtr buffSubPointer = buffer; //Making a pointer that will point into the buffer
- buffSubPointer = (IntPtr)((int)buffer + 4); //Move to the first data (ignoring dwNumEntries from the original MIB_TCPTABLE struct)
- MIB_TCPROW[] tcpRows = new MIB_TCPROW[structCount]; //Declaring the array
- //Get the struct size
- MIB_TCPROW tmp = new MIB_TCPROW();
- int sizeOfTCPROW = Marshal.SizeOf(tmp);
- //Fill the array 1 by 1
- for (int i = 0; i < structCount; i++)
- {
- tcpRows[i] = (MIB_TCPROW)Marshal.PtrToStructure(buffSubPointer, typeof(MIB_TCPROW)); //copy struct data
- buffSubPointer = (IntPtr)((int)buffSubPointer + sizeOfTCPROW); //move to next structdata
- }
- return tcpRows;
- }
- catch (Exception ex)
- {
- throw new Exception("getTcpTable failed! [" + ex.GetType().ToString() + "," + ex.Message + "]");
- }
- finally
- {
- if (allocated) Marshal.FreeCoTaskMem(buffer); //Free the allocated memory
- }
- }
- static void Main(string[] args)
- {
- Menu();
- }
- static void Menu()
- {
- int id = 0;
- string[] lines = { "127.0.0.1 chat.na1.lol.riotgames.com", "127.0.0.1 chat.eu.lol.riotgames.com", "127.0.0.1 chat.eun1.lol.riotgames.com" };
- while (true)
- {
- switch (id)
- {
- case 1:
- {
- Console.Clear();
- try
- {
- FileStream file = new FileStream(System.Environment.SystemDirectory+ @"\drivers\etc\hosts", FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
- foreach (string line in lines)
- {
- byte[] message = Encoding.ASCII.GetBytes("\n"+line+"\n");
- file.Write(message, 0, message.Length);
- }
- file.Close();
- CloseRemotePort(5223);
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- Console.WriteLine("Unable to open file, is it open by any other program?");
- Console.WriteLine("Press any button to go back to the menu");
- Console.Read();
- id = 0;
- break;
- }
- Console.WriteLine("Succesfully wrote to hosts file!");
- Console.WriteLine("Press any button to go back to the menu");
- Console.Read();
- id = 0;
- break;
- }
- case 2:
- {
- Console.Clear();
- try
- {
- string[] alllines = File.ReadAllLines(System.Environment.SystemDirectory + @"\drivers\etc\hosts");
- List<string> list = new List<string>(alllines);
- foreach (string line in lines)
- {
- list.Remove(line);
- }
- list.RemoveAll(delegate(string line) { return line == ""; });
- FileStream file = new FileStream(System.Environment.SystemDirectory + @"\drivers\etc\hosts", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
- foreach (string str in list)
- {
- byte[] message = Encoding.ASCII.GetBytes(str+"\n");
- file.Write(message, 0, message.Length);
- }
- file.Close();
- }
- catch (Exception)
- {
- Console.WriteLine("Unable to open file, is it open by any other program?");
- Console.WriteLine("Press any button to go back to the menu");
- Console.Read();
- id = 0;
- break;
- }
- Console.WriteLine("Succesfully wrote to hosts file!");
- Console.WriteLine("Press any button to go back to the menu");
- Console.Read();
- id = 0;
- break;
- }
- case 3:
- {
- return;
- }
- default:
- {
- Console.Write("\n\n");
- Console.WriteLine("Invisible Mode for League of Legends!");
- Console.Write("\n\n");
- Console.WriteLine("1. Enable Invisible Mode");
- Console.WriteLine("2. Disable Invisible Mode");
- Console.WriteLine("3. Exit\n");
- try
- {
- id = Int32.Parse(Console.ReadLine());
- }
- catch (Exception)
- {
- Console.WriteLine("\n Please write a valid number!");
- }
- break;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement