I learned some basics about MemoryMappedFile and I saw that there is an enum member called MemoryMappedFileAccess.ReadExcute.
I thought it means when you open an exe file, it (my programme) execute it (.exe file) and read the bytes that inside it (.exe file) but when i execute the program it throw me an error:
Acceess to the path is denied [UnauthorizedAccessException]
mycode:
static void Main(string[] args)
{
FileStream fs = new FileStream("programe.exe", FileMode.OpenOrCreate, FileAccess.ReadWrite,
FileShare.ReadWrite);
MemoryMappedFile memory = MemoryMappedFile.CreateFromFile(fs, "mapname", 0,
MemoryMappedFileAccess.ReadExecute,null,0,false);
MemoryMappedViewAccessor mmr = memory.CreateViewAccessor(0, fs.Length, MemoryMappedFileAccess.Read);
Console.ReadKey();
}
Can any one explain it to me ?
Plenty of things to try here:
Check three and one below:
static void Main(string[] args)
{
// Try with Read here and Read on your create view to see if anything changes
FileStream fs = new FileStream("programe.exe", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);
// Set the length of the file here.
MemoryMappedFile memory = MemoryMappedFile.CreateFromFile(fs, "mapname", fs.Length, MemoryMappedFileAccess.ReadExecute,null,0,false);
MemoryMappedViewAccessor mmr = memory.CreateViewAccessor(0, fs.Length, MemoryMappedFileAccess.Read);
Console.ReadKey();
}
Based on the documentation the ReadExecute is just a Read access right for executable files:
ReadExecute 4
Read access to the file that can store and run executable code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With