J
jing.zong
Hello,
I don't know why "VirtualCopy" always returns false in the following
C# (.net compact framework).
Also, I cannot find the value of PAGE_PHYSICAL, which I really need
it.
Thanks,
Jing
//================== Code begin
[DllImport("Coredll.dll")]
extern public static bool VirtualCopy (IntPtr lpvDest, IntPtr lpvSrc,
UInt32 cbSize, PageAccessFlags fdwProtect);
[DllImport("Coredll.dll")]
extern public static IntPtr VirtualAlloc(IntPtr lpAddress, UInt32
dwSize, MemUsageFlags flAllocationType, PageAccessFlags
flProtect);
[DllImport("Coredll.dll")]
extern public static bool VirtualFree(IntPtr lpAddress, UInt32 dwSize,
MemUsageFlags dwFreeType);
//Flags
public enum PageAccessFlags : int
{
PAGE_READONLY = 0x02,
PAGE_READWRITE = 0x04,
PAGE_EXECUTE = 0x10,
PAGE_EXECUTE_READ = 0x20,
PAGE_EXECUTE_READWRITE= 0x40,
PAGE_GUARD = 0x100,
PAGE_NOACCESS = 0x01,
PAGE_NOCACHE = 0x200
//PAGE_PHYSICAL = ?
}
public enum MemUsageFlags : int
{
MEM_COMMIT = 0x1000,
MEM_RESERVE = 0x2000,
MEM_DECOMMIT = 0x4000,
MEM_RELEASE = 0x8000
}
// Maps Physical address to Virtual Address
private void button1_Click(object sender, System.EventArgs e)
{
IntPtr PHYSADDR = (IntPtr)0x10000000; // This could be any
physical address
UInt32 SIZE = 4800*4; // Size to map
IntPtr lpv;
bool bRet;
lpv = VirtualAlloc(IntPtr.Zero,
SIZE,
MemUsageFlags.MEM_RESERVE,
PageAccessFlags.PAGE_NOACCESS);
bRet = VirtualCopy(lpv,
PHYSADDR,
SIZE,
PageAccessFlags.PAGE_READWRITE |
PageAccessFlags.PAGE_NOCACHE);
Console.WriteLine(bRet);
if (bRet == false)
{
Console.WriteLine("VirtualCopy Error");
VirtualFree(lpv,
0,
MemUsageFlags.MEM_RELEASE );
}
}
//====================== Code End
I don't know why "VirtualCopy" always returns false in the following
C# (.net compact framework).
Also, I cannot find the value of PAGE_PHYSICAL, which I really need
it.
Thanks,
Jing
//================== Code begin
[DllImport("Coredll.dll")]
extern public static bool VirtualCopy (IntPtr lpvDest, IntPtr lpvSrc,
UInt32 cbSize, PageAccessFlags fdwProtect);
[DllImport("Coredll.dll")]
extern public static IntPtr VirtualAlloc(IntPtr lpAddress, UInt32
dwSize, MemUsageFlags flAllocationType, PageAccessFlags
flProtect);
[DllImport("Coredll.dll")]
extern public static bool VirtualFree(IntPtr lpAddress, UInt32 dwSize,
MemUsageFlags dwFreeType);
//Flags
public enum PageAccessFlags : int
{
PAGE_READONLY = 0x02,
PAGE_READWRITE = 0x04,
PAGE_EXECUTE = 0x10,
PAGE_EXECUTE_READ = 0x20,
PAGE_EXECUTE_READWRITE= 0x40,
PAGE_GUARD = 0x100,
PAGE_NOACCESS = 0x01,
PAGE_NOCACHE = 0x200
//PAGE_PHYSICAL = ?
}
public enum MemUsageFlags : int
{
MEM_COMMIT = 0x1000,
MEM_RESERVE = 0x2000,
MEM_DECOMMIT = 0x4000,
MEM_RELEASE = 0x8000
}
// Maps Physical address to Virtual Address
private void button1_Click(object sender, System.EventArgs e)
{
IntPtr PHYSADDR = (IntPtr)0x10000000; // This could be any
physical address
UInt32 SIZE = 4800*4; // Size to map
IntPtr lpv;
bool bRet;
lpv = VirtualAlloc(IntPtr.Zero,
SIZE,
MemUsageFlags.MEM_RESERVE,
PageAccessFlags.PAGE_NOACCESS);
bRet = VirtualCopy(lpv,
PHYSADDR,
SIZE,
PageAccessFlags.PAGE_READWRITE |
PageAccessFlags.PAGE_NOCACHE);
Console.WriteLine(bRet);
if (bRet == false)
{
Console.WriteLine("VirtualCopy Error");
VirtualFree(lpv,
0,
MemUsageFlags.MEM_RELEASE );
}
}
//====================== Code End