Advertisement
sanych_dv

Untitled

Apr 7th, 2018
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Runtime.InteropServices;
  7.  
  8.  
  9.  
  10. namespace IeCookiesGetter
  11. {
  12.     class Program
  13.     {
  14.  
  15.         [DllImport("wininet.dll", SetLastError = true)]
  16.  
  17.         public static extern bool InternetGetCookie(
  18.             string lpszUrl,
  19.             string lpszCookieName,
  20.             StringBuilder lpszCookieData,
  21.             ref int lpdwSize
  22.         );
  23.  
  24.            [DllImport("wininet.dll", SetLastError = true)]
  25.       public static extern  bool InternetGetCookieEx(
  26.   string lpszURL,
  27.   string lpszCookieName,
  28.   StringBuilder lpszCookieData,
  29.    ref int lpdwSize,
  30.   Int32 dwFlags,
  31.   IntPtr lpReserved
  32. );
  33.  
  34.            private const Int32 InternetCookieHttponly = 0x2000;
  35.  
  36.         [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
  37.         public static extern bool InternetSetCookie(
  38.             string lpszUrlName,
  39.             string lpszCookieName,
  40.             string lpszCookieData
  41.         );
  42.  
  43.         [DllImport("wininet.dll")]
  44.         static extern InternetCookieState InternetSetCookieEx(
  45.             string lpszURL,
  46.             string lpszCookieName,
  47.             string lpszCookieData,
  48.             int dwFlags,
  49.             int dwReserved);
  50.  
  51.         enum InternetCookieState : int
  52.         {
  53.             COOKIE_STATE_UNKNOWN = 0x0,
  54.             COOKIE_STATE_ACCEPT = 0x1,
  55.             COOKIE_STATE_PROMPT = 0x2,
  56.             COOKIE_STATE_LEASH = 0x3,
  57.             COOKIE_STATE_DOWNGRADE = 0x4,
  58.             COOKIE_STATE_REJECT = 0x5,
  59.             COOKIE_STATE_MAX = COOKIE_STATE_REJECT
  60.         }
  61.  
  62.         static void Main(string[] args)
  63.         {
  64.  
  65.  
  66.       getCookie("https://www.instagram.com/");
  67.  
  68.     //    setCookie("https://www.instagram.com/", "csrftoken=2h1scGo9cDWSdtfjGZ1ZYdtzEgU5Iv17; mid=WsivtQAEAAG7jsgFzaDM-MM9tcKG; sessionid=IGSCf4180bfa871315dca124753a44cbc4b71c07067c3e425cde5fd2514d27fa147a%3AFpSIYIJOEaaHYc8AOLo8F0zQgB7oCz4u%3A%7B%22_auth_user_id%22%3A1591784797%2C%22_auth_user_backend%22%3A%22accounts.backends.CaseInsensitiveModelBackend%22%2C%22_auth_user_hash%22%3A%22%22%2C%22_platform%22%3A4%2C%22_token_ver%22%3A2%2C%22_token%22%3A%221591784797%3AqIVGwmXImpiwazR7NeLv2xtwIyqcxdhR%3Aef79af92c302726fb3cd80cde75f9525a57a183b1387a8d011bb5d317a782e80%22%2C%22last_refreshed%22%3A1523103088.6970789433%7D; ds_user_id=1591784797" + "; Expires=" + DateTime.Now.AddDays(10).ToString("R"));
  69.  
  70.             Console.ReadLine();
  71.         }
  72.  
  73.         public static void getCookie(string domainName)
  74.         {
  75.  
  76.             int size = 0;
  77.             InternetGetCookieEx(domainName, null, null, ref size, InternetCookieHttponly, IntPtr.Zero);
  78.  
  79.             // create buffer of correct size
  80.             StringBuilder lpszCookieData = new StringBuilder(size);
  81.             InternetGetCookieEx(domainName, null, lpszCookieData, ref size, InternetCookieHttponly, IntPtr.Zero);
  82.  
  83.             // get cookie
  84.             string cookie = lpszCookieData.ToString();
  85.  
  86.             Console.Write(cookie);
  87.         }
  88.  
  89.         public static void setCookie(string domain, string variables)
  90.         {
  91.  
  92.             InternetSetCookieEx(domain, null, variables, 0, 0);
  93.  
  94.            // InternetSetCookie(domain, null, variables);
  95.  
  96.         }
  97.  
  98.  
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement