hzqst
没碰到过这种情况
你map的物理地址哪来的?
NTSTATUS Mapped_Memory_Addr(ULONG LowAddr, ULONG HigAddr, PULONG Addr_Arry, int Mapped_len)
{
NTSTATUS Status = STATUS_UNSUCCESSFUL;
PHYSICAL_ADDRESS Physical_address;
//PULONG Page_dri_base;
RtlZeroMemory(&Physical_address, sizeof(PHYSICAL_ADDRESS));
if (LowAddr == 0)
{
return Status;
}
Physical_address.u.LowPart = ProcessCr3Low;
Physical_address.u.HighPart = ProcessCr3Hig;
//DbgBreakPoint();
PULONG Page_dri_base = (PULONG)MmMapIoSpace(Physical_address, Mapped_len, TRUE);
if (ARGUMENT_PRESENT(Page_dri_base) && MmIsAddressValid(Page_dri_base))
{
for (ULONG i = 0; i < PAGE_DIR_MAX; i++)
{
Addr_Arry[i] = Page_dri_base[i];
if (i % 8== 0)
{
DbgPrint("\n");
}
DbgPrint("%08X ", Addr_Arry[i]);
}
DbgPrint("\n");
Status = STATUS_SUCCESS;
MmUnmapIoSpace(Page_dri_base, Mapped_len);
return Status;
}
return Status;
}
NTSTATUS OpenProcess(HANDLE ProcessPid)
{
PEPROCESS ProcessInfo = NULL;
PKPROCESS ProccessMemoryInfo = NULL;
NTSTATUS Status = STATUS_UNSUCCESSFUL;
ProcessCr3Low = 0;
ProcessCr3Hig = 0;
if (ProcessPid < 0)
return Status;
Status = PsLookupProcessByProcessId(ProcessPid, &ProcessInfo);
if (!NT_SUCCESS(Status))
{
DbgPrint("GetPidCr3Error:%X", Status);
return Status;
}
if (ARGUMENT_PRESENT(ProcessInfo) && MmIsAddressValid(ProcessInfo))
{
ProccessMemoryInfo = ProcessInfo + 0X0;
Status = STATUS_SUCCESS;
ProcessCr3Low = ProccessMemoryInfo->DirectoryTableBase[0];
ProcessCr3Hig = ProccessMemoryInfo->DirectoryTableBase[1];
DbgPrint("CR3 =%X%X\n", ProcessCr3Hig, ProcessCr3Low);
return Status;
}
return Status;
}
LONGLONG Get_Last_digit(ULONG Addr)
{
LONGLONG Tmp = Addr;
Tmp &= 0x000000000F;
Tmp *= 0x100000000;
return Tmp;
}
ULONGLONG translate_Linear_address(int Linearaddress)
{
NTSTATUS Status = STATUS_UNSUCCESSFUL;
VIRTUAL_ADDRESS virtualAddress = { 0 };
ULONG tmp_arry[PAGE_DIR_MAX] = { 0 };
ULONG32 Tmp = 0;
virtualAddress.ulVirtualAddress = Linearaddress;
if (ProcessCr3Low == 0 )
{
DbgPrint("OpenProcessFail\n");
return Status;
}
DbgPrint("CR3 =%X%X,offset = %X,pt = %X,pdt = %X,pdpt = %X,plm4 = %X\n", ProcessCr3Hig, ProcessCr3Low, virtualAddress.stVirtualAddress.offset, virtualAddress.stVirtualAddress.PT, virtualAddress.stVirtualAddress.PDT, virtualAddress.stVirtualAddress.PDPT, virtualAddress.stVirtualAddress.PLM4);
Status = Mapped_Memory_Addr(ProcessCr3Low, ProcessCr3Hig,tmp_arry, MAPING_MAX_LEN);
if (!NT_SUCCESS(Status))
{
DbgPrint("PLM4_Addr Mapped Fail\n");
return Status;
}
/* ULONG PLM4_Addr = tmp_arry[virtualAddress.stVirtualAddress.PLM4];
Tmp = tmp_arry[virtualAddress.stVirtualAddress.PLM4 + 1];
Tmp &= 0x000000000F;
PLM4_Addr &= 0x000000FFFFFFF000;
DbgPrint("PLM4_Addr = %X\n", PLM4_Addr);
ULONG PDPT_Addr = PLM4_Addr + virtualAddress.stVirtualAddress.PDPT * 0x8;
Status = Mapped_Memory_Addr(PDPT_Addr, Tmp,tmp_arry, MAPING_MAX_LEN);
if (!NT_SUCCESS(Status))
{
DbgPrint("PDPT_Addr Mapped Fail\n");
return Status;
}
PDPT_Addr = tmp_arry[0];
Tmp = tmp_arry[1];
Tmp &= 0x000000000F;
PDPT_Addr &= 0x000000FFFFFFF000;
DbgPrint("PDPT_Addr = %X\n", PDPT_Addr);
ULONG PDT_Addr = PDPT_Addr + virtualAddress.stVirtualAddress.PDT * 0x8;
Status = Mapped_Memory_Addr(PDT_Addr, Tmp,tmp_arry, MAPING_MAX_LEN);
if (!NT_SUCCESS(Status))
{
DbgPrint("PDT_Addr Mapped Fail\n");
return Status;
}
PDT_Addr = tmp_arry[0];
Tmp = tmp_arry[1];
Tmp &= 0x000000000F;
PDT_Addr &= 0x000000FFFFFFF000;
DbgPrint("PDT_Addr = %X\n", PDT_Addr);
ULONG PT_Addr = PDT_Addr + virtualAddress.stVirtualAddress.PT * 0x8;
Status = Mapped_Memory_Addr(PT_Addr, Tmp,tmp_arry, MAPING_MAX_LEN);
if (!NT_SUCCESS(Status))
{
DbgPrint("PT_Addr Mapped Fail\n");
return Status;
}
PT_Addr = tmp_arry[0];
Tmp = tmp_arry[1];
Tmp &= 0x000000000F;
PT_Addr &= 0x000000FFFFFFF000;
DbgPrint("PT_Addr = %X\n", PT_Addr);
ULONGLONG Physucal_Addr = PT_Addr + virtualAddress.stVirtualAddress.offset;
Physucal_Addr = Physucal_Addr | Get_Last_digit(tmp_arry[1]);
return Physucal_Addr;
/*PHYSICAL_ADDRESS Physical_address;
DbgPrint("Physucal_Addr: %p\n", Physucal_Addr);
RtlZeroMemory(&Physical_address, sizeof(PHYSICAL_ADDRESS));
Physical_address.u.LowPart = Physucal_Addr;
Physical_address.u.HighPart = Tmp;
char *Buffer = (char *)MmMapIoSpace(Physical_address, sizeof(PHYSICAL_ADDRESS), TRUE);
DbgPrint("Data:%s\n", Buffer);*/
return 0L;
}
我的CR3是获取的进程的。
最后于 2018-8-2 15:09
被BDBig编辑
,原因: