This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Runtime.InteropServices; // тут знаходиться опис атрибуту DllImport | |
| namespace Sample | |
| { | |
| class Program | |
| { | |
| static void Main() | |
| { | |
| Console.Title = "C++ Strikes Back!"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Runtime.InteropServices; | |
| using System.Text; | |
| public delegate bool CallBack(int hwnd, int lParam); | |
| public class OldFunctionsHolder | |
| { | |
| [DllImport("user32.dll")] | |
| public static extern int EnumWindows(CallBack x, int nothing); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Runtime.InteropServices; | |
| using System.Text; | |
| // CallingConvention — це перелік, який визначає угоду про виклик функції, | |
| // тобто правила, що визначають, як параметри передаються у функцію, хто очищає стек | |
| // і як передаються повернені значення. Важливість вибору правильної угоди полягає | |
| // у коректній організації обміну даними між керованим і нативним кодом. | |
| // CallingConvention.Cdecl — зазвичай використовується у програмах на C і C++. | |
| // Параметри передаються справа наліво, і сторона, що викликає, очищає стек після виклику функції. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // компілювати цей додаток потрібно з параметром /unsafe !!! | |
| // https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/language | |
| // https://www.dotnetperls.com/unsafe | |
| class UnsafelApp | |
| { | |
| public static unsafe void GetValues(int* x, int* y) | |
| { | |
| *x = 6; | |
| *y = 42; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Runtime.InteropServices; | |
| using System.Text; | |
| class Cat | |
| { | |
| public int paws = 4; | |
| // якщо зробити властивість, то не вдасться застосувати оператор & | |
| } | |
| class CopyMaker |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Diagnostics; | |
| using System.Runtime.InteropServices; | |
| class Program | |
| { | |
| [DllImport("user32.dll", CharSet = CharSet.Auto)] | |
| public static extern IntPtr FindWindow(string className, string? windowName); | |
| [DllImport("user32.dll", CharSet = CharSet.Auto)] | |
| public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string? lpszWindow); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // код для файлу Program.cs, стандартну форму з шаблону треба видалити | |
| using System.Diagnostics; | |
| using System.Runtime.InteropServices; | |
| using System.Text; | |
| namespace HookKeylogger | |
| { | |
| public class Program : Form | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Diagnostics; | |
| using System.Runtime.InteropServices; | |
| using System.Text; | |
| using static Program; | |
| public static class DllImports | |
| { | |
| [DllImport("user32.dll")] | |
| public static extern bool EnumWindows(EnumWindowsProc enumFunc, IntPtr lParam); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Diagnostics; | |
| using System.Runtime.InteropServices; | |
| using System.Text; | |
| class Program | |
| { | |
| static void Main() | |
| { | |
| Console.OutputEncoding = Encoding.UTF8; | |
| Console.WriteLine("Створення процесу notepad.exe..."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Diagnostics; | |
| using System.Security.Principal; | |
| using System.Text; | |
| class Program | |
| { | |
| static bool IsRunAsAdministrator() | |
| { | |
| var principal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); | |
| return principal.IsInRole(WindowsBuiltInRole.Administrator); |