using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32.SafeHandles;
using System.Threading;
using System.Runtime.InteropServices;
namespace IReaper{
/// <summary>
/// 2Win32
/// </summary>
public class Utils
{
#region const
public const UInt32 STANDARD_RIGHTS_REQUIRED = 0x000F0000;
public const UInt32 SECTION_QUERY = 0x0001;
public const UInt32 SECTION_MAP_WRITE = 0x0002;
public const UInt32 SECTION_MAP_READ = 0x0004;
public const UInt32 SECTION_MAP_EXECUTE = 0x0008;
public const UInt32 SECTION_EXTEND_SIZE = 0x0010;
public const UInt32 SECTION_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED | SECTION_QUERY |
SECTION_MAP_WRITE |
SECTION_MAP_READ |
SECTION_MAP_EXECUTE |
SECTION_EXTEND_SIZE);
public const UInt32 FILE_MAP_ALL_ACCESS = SECTION_ALL_ACCESS;
#endregion
[DllImport("kernel32", SetLastError = true)]
[System.Security.SuppressUnmanagedCodeSecurity()]
public static extern unsafe bool WriteFile
(
SafeFileHandle hFile, // handle to file
void* pBuffer, // data buffer
int NumberOfBytesToWrite, // number of bytes to write
int* pNumberOfBytesWrite, // number of bytes write
NativeOverlapped* Overlapped // overlapped buffer
);
[DllImport("kernel32", SetLastError = true)]
[System.Security.SuppressUnmanagedCodeSecurity()]
public static extern unsafe bool ReadFile
(
SafeFileHandle hFile, // handle to file
void* pBuffer, // data buffer
int NumberOfBytesToRead, // number of bytes to read
int* pNumberOfBytesRead, // number of bytes read
NativeOverlapped* Overlapped // overlapped buffer
);
/// <summary>
/// Set Culture of current assembly.
/// </summary>
/// <param name="Culture"></param>
public static void SetCulture(System.Globalization.CultureInfo Culture)
{
IReaper.Properties.StringResources.Culture = Culture;
}
/// <summary>
/// srcdesdesbuflength
/// </summary>
/// <param name="des"></param>
/// <param name="src"></param>
/// <param name="buflength"></param>
public static unsafe void StringCopy(char* des, int buflength, string src)
{
if (buflength < 0)
return;
int i = 0;
if (src == null)
src = "";
for (; i < src.Length && i < buflength - 1; i++)
{
des[i] = src[i];
}
des[i] = '\0';
}
}
[Flags]
public enum PageProtection : uint
{
NoAccess = 0x01,
Readonly = 0x02,
ReadWrite = 0x04,
WriteCopy = 0x08,
Execute = 0x10,
ExecuteRead = 0x20,
ExecuteReadWrite = 0x40,
ExecuteWriteCopy = 0x80,
Guard = 0x100,
NoCache = 0x200,
WriteCombine = 0x400,
}
}
|