⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myfunctions.cs

📁 一个抓包工具
💻 CS
📖 第 1 页 / 共 5 页
字号:
using System;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace MyClasses
{
	using SECURITY_DESCRIPTOR = System.Int32;

	public class Function
	{


		public static uint FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x100;
		public static uint FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x2000;
		public static uint FORMAT_MESSAGE_FROM_HMODULE = 0x800;
		public static uint FORMAT_MESSAGE_FROM_STRING = 0x400;
		public static uint FORMAT_MESSAGE_FROM_SYSTEM = 0x1000;
		public static uint FORMAT_MESSAGE_IGNORE_INSERTS = 0x200;
		public static uint FORMAT_MESSAGE_MAX_WIDTH_MASK = 0xFF;
		public static uint LANG_BULGARIAN = 0x2;
		public static uint LANG_CHINESE = 0x4;
		public static uint LANG_CROATIAN = 0x1A;
		public static uint LANG_CZECH = 0x5;
		public static uint LANG_DANISH = 0x6;
		public static uint LANG_DUTCH = 0x13;
		public static uint LANG_ENGLISH = 0x9;
		public static uint LANG_FINNISH = 0xB;
		public static uint LANG_FRENCH = 0xC;
		public static uint LANG_GERMAN = 0x7;
		public static uint LANG_GREEK = 0x8;
		public static uint LANG_HUNGARIAN = 0xE;
		public static uint LANG_ICELANDIC = 0xF;
		public static uint LANG_ITALIAN = 0x10;
		public static uint LANG_JAPANESE = 0x11;
		public static uint LANG_KOREAN = 0x12;
		public static uint LANG_NEUTRAL = 0x0;
		public static uint LANG_NORWEGIAN = 0x14;
		public static uint LANG_POLISH = 0x15;
		public static uint LANG_PORTUGUESE = 0x16;
		public static uint LANG_ROMANIAN = 0x18;
		public static uint LANG_RUSSIAN = 0x19;
		public static uint LANG_SLOVAK = 0x1B;
		public static uint LANG_SLOVENIAN = 0x24;
		public static uint LANG_SPANISH = 0xA;
		public static uint LANG_SWEDISH = 0x1D;
		public static uint LANG_TURKISH = 0x1F;
		public static uint SUBLANG_CHINESE_HONGKONG = 0x3;
		public static uint SUBLANG_CHINESE_SIMPLIFIED = 0x2;
		public static uint SUBLANG_CHINESE_SINGAPORE = 0x4;
		public static uint SUBLANG_CHINESE_TRADITIONAL = 0x1;
		public static uint SUBLANG_DEFAULT = 0x1;
		public static uint SUBLANG_DUTCH = 0x1;
		public static uint SUBLANG_DUTCH_BELGIAN = 0x2;
		public static uint SUBLANG_ENGLISH_AUS = 0x3;
		public static uint SUBLANG_ENGLISH_CAN = 0x4;
		public static uint SUBLANG_ENGLISH_EIRE = 0x6;
		public static uint SUBLANG_ENGLISH_NZ = 0x5;
		public static uint SUBLANG_ENGLISH_UK = 0x2;
		public static uint SUBLANG_ENGLISH_US = 0x1;
		public static uint SUBLANG_FRENCH = 0x1;
		public static uint SUBLANG_FRENCH_BELGIAN = 0x2;
		public static uint SUBLANG_FRENCH_CANADIAN = 0x3;
		public static uint SUBLANG_FRENCH_SWISS = 0x4;
		public static uint SUBLANG_GERMAN = 0x1;
		public static uint SUBLANG_GERMAN_AUSTRIAN = 0x3;
		public static uint SUBLANG_GERMAN_SWISS = 0x2;
		public static uint SUBLANG_ITALIAN = 0x1;
		public static uint SUBLANG_ITALIAN_SWISS = 0x2;
		public static uint SUBLANG_NEUTRAL = 0x0;
		public static uint SUBLANG_NORWEGIAN_BOKMAL = 0x1;
		public static uint SUBLANG_NORWEGIAN_NYNORSK = 0x2;
		public static uint SUBLANG_PORTUGUESE = 0x2;
		public static uint SUBLANG_PORTUGUESE_BRAZILIAN = 0x1;
		public static uint SUBLANG_SPANISH = 0x1;
		public static uint SUBLANG_SPANISH_MEXICAN = 0x2;
		public static uint SUBLANG_SPANISH_MODERN = 0x3;
		public static uint SUBLANG_SYS_DEFAULT = 0x2;
		public static uint SUCCESSFUL_ACCESS_ACE_FLAG = 0x40;

		public static uint LMEM_ZEROINIT = 0x40;
		public static uint LOAD_LIBRARY_AS_DATAFILE = 0x2;

		public static uint RT_ACCELERATOR = 9;
		public static uint RT_BITMAP = 2;
		public static uint RT_CURSOR = 1;
		public static uint RT_DIALOG = 5;
		public static uint RT_FONT = 8;
		public static uint RT_FONTDIR = 7;
		public static uint RT_ICON = 3;
		public static uint RT_MENU = 4;
		public static uint RT_RCDATA = 10;
		public static uint RT_STRING = 6;
		public static uint RT_MESSAGETABLE = 11;

		public static uint ERROR_ALREADY_EXISTS = 183;
		public static uint INFINITE = 0xFFFF;

		public static uint MOVEFILE_REPLACE_EXISTING = 0x1;
		public static uint FILE_ATTRIBUTE_TEMPORARY = 0x100;
		public static uint FILE_BEGIN = 0;
		public static uint FILE_SHARE_READ = 0x1;
		public static uint FILE_SHARE_WRITE = 0x2;
		public static uint CREATE_NEW = 1;
		public static uint OPEN_EXISTING = 3;
		public static uint GENERIC_READ = 0x80000000;
		public static uint GENERIC_WRITE = 0x40000000;


		public const int ANSI_CHARSET = 0;
		public const int ANSI_FIXED_FONT = 11;
		public const int OEM_CHARSET = 255;
		public const int OEM_FIXED_FONT = 10;
		public const int OUT_CHARACTER_PRECIS = 2;
		public const int OUT_DEFAULT_PRECIS = 0;
		public const int OUT_DEVICE_PRECIS = 5;
		public const int OUT_OUTLINE_PRECIS = 8;
		public const int OUT_PS_ONLY_PRECIS = 10;
		public const int OUT_RASTER_PRECIS = 6;
		public const int OUT_SCREEN_OUTLINE_PRECIS = 9;
		public const int OUT_STRING_PRECIS = 1;
		public const int OUT_STROKE_PRECIS = 3;
		public const int OUT_TT_ONLY_PRECIS = 7;
		public const int OUT_TT_PRECIS = 4;
		public const int CLIP_CHARACTER_PRECIS = 1;
		public const int CLIP_DEFAULT_PRECIS = 0;
		public const int CLIP_EMBEDDED = 128;
		public const int CLIP_LH_ANGLES = 16;
		public const int CLIP_MASK = 0xF;
		public const int CLIP_NOT = 0x0;
		public const int CLIP_STROKE_PRECIS = 2;
		public const int CLIP_SUS = 0x20;
		public const int CLIP_TO_PATH = 4097;
		public const int CLIP_TT_ALWAYS = 32;
		public const int DEFAULT_PRECIS = 0;
		public const int DEFAULT_QUALITY = 0;
		public const int FIXED_PITCH = 1;
		public const int FF_DECORATIVE = 80;
		public const int FF_DONTCARE = 0;
		public const int FF_MODERN = 48;
		public const int FF_ROMAN = 16;
		public const int FF_SCRIPT = 64;
		public const int FF_SWISS = 32;
		public const int LOGPIXELSX = 88;
		public const int LOGPIXELSY = 90;
		public const int WM_SETFONT = 0x30;
		public const int WM_GETFONT = 0x31;
		public const int EM_SETSEL = 0xB1;

		public const int NORMAL = 0;
		public const int VALUE = 1;


		public struct TEXTMETRIC 
		{ // tm  
			public int tmHeight; 
			public int tmAscent; 
			public int tmDescent; 
			public int tmInternalLeading; 
			public int tmExternalLeading; 
			public int tmAveCharWidth; 
			public int tmMaxCharWidth; 
			public int tmWeight; 
			public int tmOverhang; 
			public int tmDigitizedAspectX; 
			public int tmDigitizedAspectY; 
			public byte tmFirstChar; 
			public byte tmLastChar; 
			public byte tmDefaultChar; 
			public byte tmBreakChar; 
			public byte tmItalic; 
			public byte tmUnderlined; 
			public byte tmStruckOut; 
			public byte tmPitchAndFamily; 
			public byte tmCharSet; 
		};

		public struct SECURITY_ATTRIBUTES 
		{
			public ulong nLength; 
			public SECURITY_DESCRIPTOR lpSecurityDescriptor; 
			public int bInheritHandle; 
		};

		public struct LARGE_INTEGER
		{
			public long LowPart; // long
			public long HighPart; // long
		}


		public struct PACKET_OID_DATA
		{
			public ulong Oid;					///< OID code. See the Microsoft DDK documentation or the file ntddndis.h
			///< for a complete list of valid codes.
			public ulong Length;				///< Length of the data field
			public byte [] Data; //[1];				///< variable-lenght field that contains the information passed to or received 
			///< from the adapter.
		}; 

		//**********************************************************************
		[DllImport("gdi32.dll")] public extern static int
			GetTextMetrics(
				int hdc,	// handle of device context 
				ref TEXTMETRIC Tm 	// address of text metrics structure 
			);
		//**********************************************************************
		[DllImport("kernel32.dll")] public extern static int
			WaitForSingleObject( int hHandle, uint dwMilliseconds );
		//**********************************************************************
		[DllImport("kernel32.dll")] public extern static int
			QueryPerformanceFrequency(ref LARGE_INTEGER lpFrequency );
		//**********************************************************************
		[DllImport("kernel32.dll")] public extern static int
			QueryPerformanceCounter( ref LARGE_INTEGER lpPerformanceCount ); 	// address of current counter value
		//**********************************************************************
		[DllImport("kernel32.dll")] public extern static int
			SetEvent( int hEvent ); 	// handle of event object 
		//**********************************************************************
		[DllImport("kernel32.dll")] public extern static int
			CloseHandle( int hObject ); 	// handle to object to close  
		//**********************************************************************
		[DllImport("kernel32.dll")] public extern static int
			GetLastError();
		//**********************************************************************
		[DllImport("kernel32.dll")] public extern static void
			SetLastError( ulong dwErrCode ); // per-thread error code  

		[DllImport("kernel32.dll")] public extern static void
			SetLastError( int dwErrCode ); // per-thread error code  
		//**********************************************************************
		[DllImport("kernel32.dll", EntryPoint="GlobalAlloc")] public extern static char *
			GlobalAllocPtr( uint wFlags, uint dwBytes );
		//**********************************************************************
		[DllImport("kernel32.dll", EntryPoint="lstrcpyA", CharSet=CharSet.Ansi)] public extern static int
			StrCpy( int lpString1, int lpString2);
		//**********************************************************************
		[DllImport("kernel32.dll", EntryPoint="RtlMoveMemory")] public extern static int
			CopyIntToInt( int DstAddr, int SrcAddr , int length );
		//**********************************************************************
		[DllImport("kernel32.dll", EntryPoint="RtlMoveMemory")] public extern static int
			CopyIntToByte( ref byte Value , int DstAddr, int length );

		//**********************************************************************
		[DllImport("kernel32")] public static extern void
			Sleep(int dwMilliseconds);
		//**********************************************************************
		[DllImport("kernel32")] public static extern int
			GetTickCount();
		//**********************************************************************
		[DllImport("Kernel32", EntryPoint="RtlMoveMemory")] public static extern int 
			CopyMemory(int dest, int src, int length);
		//**********************************************************************
		[DllImport("kernel32.dll")] public extern static int
			FormatMessage(
			int dwFlags,	// source and processing options 
			int lpSource,	// pointer to  message source 
			int dwMessageId,	// requested message identifier 
			int dwLanguageId,	// language identifier for requested message 
			int lpBuffer,	// pointer to message buffer 
			int nSize,	// maximum size of message buffer 
			int Arguments 	// address of array of message inserts 
			);

		[DllImport("kernel32.dll")] public extern static int
			FormatMessage(
			int dwFlags,	// source and processing options 
			int lpSource,	// pointer to  message source 
			int dwMessageId,	// requested message identifier 
			int dwLanguageId,	// language identifier for requested message 
			ref int lpBuffer,	// pointer to message buffer 
			int nSize,	// maximum size of message buffer 
			int Arguments 	// address of array of message inserts 
			);
		//**********************************************************************
			[DllImport("kernel32.dll")] public extern static int
				LocalFree( int hMem ); 	// handle of local memory object 
		//**********************************************************************
		[DllImport("user32.dll")] public static extern int
			ReleaseDC(
			int hWnd,	// handle of window 
			int hDC 	// handle of device context  
			);
		//**********************************************************************
		[DllImport("gdi32.dll")] public static extern int
			DeleteObject(
			int hObject 	// handle to graphic object  
			);
		//**********************************************************************
		[DllImport("user32.dll")] public static extern int
			GetDC(
			int hWnd 	// handle of window  
			);
		//**********************************************************************
		[DllImport("gdi32.dll")] public static extern int
			GetDeviceCaps(
			int hdc,	// device-context handle 
			int nIndex 	// index of capability to query  
			);	
 		//**********************************************************************
		[DllImport("gdi32.dll")] public static extern int
			CreateFont(
			int nHeight,	// logical height of font 
			int nWidth,	// logical average character width 
			int nEscapement,	// angle of escapement 
			int nOrientation,	// base-line orientation angle 
			int fnWeight,	// font weight 
			uint fdwItalic,	// italic attribute flag 
			uint fdwUnderline,	// underline attribute flag 
			uint fdwStrikeOut,	// strikeout attribute flag 
			uint fdwCharSet,	// character set identifier 
			uint fdwOutputPrecision,	// output precision 
			uint fdwClipPrecision,	// clipping precision 
			uint fdwQuality,	// output quality 
			uint fdwPitchAndFamily,	// pitch and family 
			int lpszFace 	// pointer to typeface name string 
			);
		//**********************************************************************
		[DllImport("kernel32.dll")] public static extern int
			MulDiv(
			int nNumber,	// 32-bit signed multiplicand  
			int nNumerator,	// 32-bit signed multiplier 
			int nDenominator 	// 32-bit signed divisor 
			);
		//**********************************************************************
		[DllImport("user32.dll")] public static extern int
			SendMessage(
			int hWnd,	// handle of destination window
			uint Msg,	// message to send
			int wParam,	// first message parameter
			int lParam 	// second message parameter
			);
		//**********************************************************************

		public Function()
		{

		}


		public static byte GetByteFromPtr( int Ptr )
		{
			byte b = 0;
			int bPtr = AddressOf( b );

			CopyIntToInt( bPtr , Ptr , 1 );
			return b;
		}

		public static ushort GetShortFromPtr( int Ptr )
		{
			short b = 0;
			int bPtr = AddressOf( b );

			CopyIntToInt( bPtr , Ptr , 2 );
			return (ushort) b;
		}

		public static uint GetIntFromPtr( int Ptr )
		{
			int b = 0;
			int bPtr = AddressOf( b );

			CopyIntToInt( bPtr , Ptr , 4 );
			return (uint) b;
		}

		public static ulong GetLongFromPtr( int Ptr )
		{
			long b = 0;
			int bPtr = AddressOf( b );

			CopyIntToInt( bPtr , Ptr , 8 );
			return (ulong) b;
		}

		public static string GetIpAddress( string SrvName )
		{
			IPHostEntry ipEntry = new IPHostEntry();
			IPAddress Ip = new IPAddress(0);

			if( SrvName.Trim() == "" )
			{
				ipEntry = Dns.Resolve( Dns.GetHostName() );
			}
			else
			{
				ipEntry = Dns.Resolve( SrvName );
			}

			Ip = ipEntry.AddressList[0];

			return Ip.ToString();

		}


		public static string GetHostName( string IpAddr )
		{
			IPHostEntry iphEntry = new IPHostEntry();

			if( IpAddr.Trim() == "" )
			{
				return Dns.GetHostName();
			}
			else
			{
				iphEntry = Dns.GetHostByAddress(IpAddr );
			}

			return iphEntry.HostName;

		}


		// Converting dotted ip address to equivalent integer value
		// Snmp
		public static int IpAddressToInt(string ipaddr)
		{

			int Rslt = 0;
			string[] strarr = new string[4];

			strarr = ipaddr.Split((char)46); // split ip address into 4 pieces
			// and make a 32 bit value
			Rslt = ( int.Parse( strarr[3] ) << 24 ) + 
				( int.Parse(strarr[2]) << 16 ) + 
				( int.Parse(strarr[1]) << 8 ) + 
				int.Parse(strarr[0]);

			return Rslt;

		}


		// Convert an ip address stored an address to equivalent string value
		public static string GetPtrToIpAddr(int intPtr, int varlen)
		{
			int i = 0;
			string tmp = "";
			byte[] byx = new byte[varlen];
			int ptrptr;

			// ip address cann't have zero value
			// ip address cann't have zero length
			if( ( intPtr == 0 ) || ( varlen == 0 ) ) return "";
			tmp = "";
			// get address of array byx
			ptrptr = AddressOf(byx);
			// copy into array byx
			CopyMemory(ptrptr,intPtr,varlen);
			// store it in a string format
			for( i = 0;i<varlen; i++)
			{
				tmp = tmp + byx[i].ToString() + ".";
			}

			// remove last char "."
			tmp = tmp.Substring(0,tmp.Length-1);
			return tmp;

		}


		// convert a string value stored in an address to equilavent string format
		public static string GetPtrToString(int intPtr, int varlen)
		{

			int i = 0;
			string tmp = "";
			byte[] cyx = new byte[varlen];
			int ptrptr;

			// string value cann't have zero value
			// string value cann't have zero length
			if( ( intPtr == 0 ) || ( varlen == 0 ) ) return "";
			tmp = "";
			// get address of array byx
			ptrptr = AddressOf(cyx);
			// copy into array byx
			CopyMemory(ptrptr,intPtr,varlen);
			// store it in a string format
			for( i = 0;i<varlen; i++)
			{
				tmp = tmp + (char)cyx[i];
			}

			return tmp;
		}


		// get address function for various input types
		unsafe public static int AddressOf(int[] variable)
		{
			int ptrptr;

			fixed(int* ptr = variable)
			{ptrptr = (int) ptr;}

			return ptrptr;
		}

		unsafe public static int AddressOf(byte[] variable)
		{
			int ptrptr;

			fixed(byte* ptr = variable)
			{ptrptr = (int) ptr;}

			return ptrptr;
		}

		unsafe public static int AddressOf(char[] variable)
		{
			int ptrptr;

			fixed(char* ptr = variable)
			{ptrptr = (int) ptr;}

			return ptrptr;
		}

		unsafe public static int AddressOf(char variable)
		{
			int ptrptr;

			char* ptr = (char*) &variable;
			ptrptr = (int) ptr;

			return ptrptr;
		}


		unsafe public static int AddressOf(byte variable)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -