F
Frankooo
Guest
so am trying to send a struct from 1 process to another and it is not reading it correctly in my second process . i guess it has to do with pointers but i really don't know how to send a struct or a pointer to a struct with MapViewOfFile.(please note: that i am trying to send the whole struct + the data that it has.)
i have tried to send a pointer of an object address via memcpy but i think that wouldn't work because am using typdef struct.
// this is my second process 2
// using mmcopyvirtualmemory btw.
KM_WRITE_REQUEST* WriteInput = (KM_WRITE_REQUEST*)SharedSection; // this should get our struct pointer from User mode.
PEPROCESS Process;
NTSTATUS Status;
if (NT_SUCCESS(PsLookupProcessByProcessId(WriteInput->ProcessId, &Process))) {
Status = WriteKernelMemory(Process, WriteInput->SourceAddress, WriteInput->TargetAddress, WriteInput->Size);
DbgPrintEx(0, 0, "Status debug \n",Status);
}
else {
Status = STATUS_ACCESS_DENIED;
ObDereferenceObject(Process);
DbgPrintEx(0, 0, "Status debug \n", Status);
return Status;
}
DbgPrintEx(0, 0, "Write Params: %lu, %#010x \n", WriteInput->SourceAddress, WriteInput->TargetAddress);
// this is my struct
typedef struct _KM_WRITE_REQUEST
{
ULONG ProcessId;
UINT_PTR SourceAddress;
UINT_PTR TargetAddress;
ULONG Size;
} KM_WRITE_REQUEST, *PKM_WRITE_REQUEST;
// and this is how am trying to send my struct and write to it well , write to it before sending it .
// this is in my first process.
bool WriteVirtualMemoryRaw(UINT_PTR WriteAddress, UINT_PTR SourceAddress, SIZE_T WriteSize)
{
DWORD res;
res = WaitForSingleObject(g_hMutex, INFINITE);
auto Write_memoryst = (char*)MapViewOfFile(hMapFileW, FILE_MAP_WRITE, 0, 0, 4096);
char str[8];
strcpy_s(str, "Write");
RtlCopyMemory(Write_memoryst, str, strlen(str) + 1);
printf("message has been sent to kernel [Write]! \n");
UnmapViewOfFile(Write_memoryst);
WaitForSingleObject(SharedEvent_dataarv, INFINITE); // wait for kernel event to happen
KM_WRITE_REQUEST* Sent_struct = (KM_WRITE_REQUEST*)MapViewOfFile(hMapFileW, FILE_MAP_WRITE, 0, 0, sizeof(KM_WRITE_REQUEST));
if (!Sent_struct) {
printf("Error MapViewOfFile(Sent_struct)\n");
return false;
}
KM_WRITE_REQUEST WriteRequest;
WriteRequest.ProcessId = PID;
WriteRequest.TargetAddress = WriteAddress;
WriteRequest.SourceAddress = SourceAddress;
WriteRequest.Size = WriteSize;
KM_WRITE_REQUEST* test_ptr = &WriteRequest;
if (!memcpy(Sent_struct, test_ptr, sizeof(KM_WRITE_REQUEST))) {
printf("Error copying memory with (memcpy) to struct\n");
return false;
}
UnmapViewOfFile(Sent_struct);
ReleaseMutex(g_hMutex);
return true;
}
am sure am doing something wrong when sending the struct pointer , but this is how i have done it and its not working
Continue reading...
i have tried to send a pointer of an object address via memcpy but i think that wouldn't work because am using typdef struct.
// this is my second process 2
// using mmcopyvirtualmemory btw.
KM_WRITE_REQUEST* WriteInput = (KM_WRITE_REQUEST*)SharedSection; // this should get our struct pointer from User mode.
PEPROCESS Process;
NTSTATUS Status;
if (NT_SUCCESS(PsLookupProcessByProcessId(WriteInput->ProcessId, &Process))) {
Status = WriteKernelMemory(Process, WriteInput->SourceAddress, WriteInput->TargetAddress, WriteInput->Size);
DbgPrintEx(0, 0, "Status debug \n",Status);
}
else {
Status = STATUS_ACCESS_DENIED;
ObDereferenceObject(Process);
DbgPrintEx(0, 0, "Status debug \n", Status);
return Status;
}
DbgPrintEx(0, 0, "Write Params: %lu, %#010x \n", WriteInput->SourceAddress, WriteInput->TargetAddress);
// this is my struct
typedef struct _KM_WRITE_REQUEST
{
ULONG ProcessId;
UINT_PTR SourceAddress;
UINT_PTR TargetAddress;
ULONG Size;
} KM_WRITE_REQUEST, *PKM_WRITE_REQUEST;
// and this is how am trying to send my struct and write to it well , write to it before sending it .
// this is in my first process.
bool WriteVirtualMemoryRaw(UINT_PTR WriteAddress, UINT_PTR SourceAddress, SIZE_T WriteSize)
{
DWORD res;
res = WaitForSingleObject(g_hMutex, INFINITE);
auto Write_memoryst = (char*)MapViewOfFile(hMapFileW, FILE_MAP_WRITE, 0, 0, 4096);
char str[8];
strcpy_s(str, "Write");
RtlCopyMemory(Write_memoryst, str, strlen(str) + 1);
printf("message has been sent to kernel [Write]! \n");
UnmapViewOfFile(Write_memoryst);
WaitForSingleObject(SharedEvent_dataarv, INFINITE); // wait for kernel event to happen
KM_WRITE_REQUEST* Sent_struct = (KM_WRITE_REQUEST*)MapViewOfFile(hMapFileW, FILE_MAP_WRITE, 0, 0, sizeof(KM_WRITE_REQUEST));
if (!Sent_struct) {
printf("Error MapViewOfFile(Sent_struct)\n");
return false;
}
KM_WRITE_REQUEST WriteRequest;
WriteRequest.ProcessId = PID;
WriteRequest.TargetAddress = WriteAddress;
WriteRequest.SourceAddress = SourceAddress;
WriteRequest.Size = WriteSize;
KM_WRITE_REQUEST* test_ptr = &WriteRequest;
if (!memcpy(Sent_struct, test_ptr, sizeof(KM_WRITE_REQUEST))) {
printf("Error copying memory with (memcpy) to struct\n");
return false;
}
UnmapViewOfFile(Sent_struct);
ReleaseMutex(g_hMutex);
return true;
}
am sure am doing something wrong when sending the struct pointer , but this is how i have done it and its not working
Continue reading...