[Windows Phone 7 Development and Hacking] Martin7Pro:
May be this way, I will remove IOCTL structure inicialisation from driver loading, it was unlogical, you can stay all intacted.

Driver says now:

KMD_Init

pDriverContext->Instance 2

KMD_Init Success, MmMapIoSpace returns D8EF0008

KMD_Open

KMD_Open

KMD_IoControl entry, dwCode=9

KMD_IoControl WP7_DLL_CALL, dwCode=9

Function kmode_dll.dll::KGetProcInfo returns 0

KMD_IoControl returned 1

and dll:

GetProcInfo(0x23a1ce4, 1, 0x23A1F00, 576)

sizeof(VOID_STRUCT) = 1, sizeof(PROCESSOR_INFO) = 576)

pinfo not filled, GetProcInfo returns ERROR_SUCCESS

This code is wrong:

TRACE_SAVE(L"pinfo not filled, GetProcInfo returns ERROR_SUCCESS\n");
return ERROR;

It may be something similar to:

DWORD dwError = 0x80070000 | GetLastError();
TRACE_SAVE(L"pinfo not filled, GetProcInfo returns 0x%X\n", dwError);
return dwError;

After it:

KMD_Open

KMD_Open

KMD_IoControl entry, dwCode=9

KMD_IoControl WP7_DLL_CALL, dwCode=9

Function kmode_dll.dll::KGetProcInfo returns 8007007A

KMD_IoControl returned 1

KMD_IoControl entry, dwCode=10303FF

KMD_IoControl default, errorneous dwCode=10303FF

KMD_IoControl returned 0

KMD_IoControl entry, dwCode=10303FF

KMD_IoControl default, errorneous dwCode=10303FF

KMD_IoControl returned 0

KMD_IoControl entry, dwCode=10303FF

KMD_IoControl default, errorneous dwCode=10303FF

KMD_IoControl returned 0

KMD_IoControl entry, dwCode=10303FF

KMD_IoControl default, errorneous dwCode=10303FF

KMD_IoControl returned 0

KMD_Close

KMD_Close

...

GetProcInfo(0xe81ce4, 1, 0xE81F00, 576)

sizeof(VOID_STRUCT) = 1, sizeof(PROCESSOR_INFO) = 576)

pinfo not filled, GetProcInfo returns 0x8007007A

ERROR: 0x8007007a = The data area passed to a system call is too small.

I am not sure, but if this is related, then structure may be longer.

Warning: The image must implement IOCTL_PROCESSOR_INFORMATION.

But, when I resize structure and trace returned needed size too, code

TRACE_SAVE(L"pinfo not filled, GetProcInfo returns 0x%X, rsize = %d\n", dwError, rsize);

returned:

GetProcInfo(0x3d11ce4, 1, 0x3D11F00, 8576)

sizeof(VOID_STRUCT) = 1, sizeof(PROCESSOR_INFO) = 8576)

pinfo not filled, GetProcInfo returns 0x8007007A, rsize = 576

This means buffer was correctly sized probably, but pointer is wrong.

EDIT:

There was error in pointer. It must be:

DWORD rsize = 0;
memset(pinfo, sizeof(PROCESSOR_INFO), 0);
int ret = KernelIoControl(IOCTL_PROCESSOR_INFORMATION, NULL, 0, pinfo,
sizeof(PROCESSOR_INFO), &rsize);

instead &pinfo.

EDIT2:

I am not sure why, but structure must be defined in dll, not in driver (?????). May be allocation in driver is wrong, I will check it.

Now it works:

GetProcInfo(0x3e51ce4, 1, 0x3E51F00, 576)

sizeof(VOID_STRUCT) = 1, sizeof(PROCESSOR_INFO) = 576

pinfo filled, GetProcInfo returns ERROR_SUCCESS

wVersion = 1

szProcessCore = Snapdragon

wCoreRevision = 0

szProcessorName = QSD8250

wProcessorRevision = 0

szCatalogNumber =

szVendor = QUALCOMM

dwInstructionSet = 0

dwClockSpeed = 998

Repaired code:

unsigned long KGetProcInfo(unsigned char * InStructurePointer,
unsigned long InStructureLength, unsigned char * OutStructurePointer,
unsigned long OutStructureLength) {

TRACE_SAVE(L"GetProcInfo(0x%x, %d, 0x%X, %d)\n", InStructurePointer,
InStructureLength, OutStructurePointer, OutStructureLength);

TRACE_SAVE(
L"sizeof(VOID_STRUCT) = %d, sizeof(PROCESSOR_INFO) = %d\n",
sizeof(VOID_STRUCT), sizeof(PROCESSOR_INFO));

if (InStructurePointer && OutStructurePointer
&& sizeof(VOID_STRUCT) == InStructureLength
&& sizeof(PROCESSOR_INFO) == OutStructureLength) {
///	PROCESSOR_INFO * pinfo = (PROCESSOR_INFO *) OutStructurePointer;

PROCESSOR_INFO pinfo;

// Try to lookup processor type.
DWORD rsize = 0;
memset(&pinfo, sizeof(PROCESSOR_INFO), 0);
int ret = KernelIoControl(IOCTL_PROCESSOR_INFORMATION, NULL, 0, &pinfo,
sizeof(pinfo), &rsize);
if (ret) {
TRACE_SAVE(L"pinfo filled, GetProcInfo returns ERROR_SUCCESS\n");

TRACE_SAVE(L"wVersion = %d\n", pinfo.wVersion);
TRACE_SAVE(L"szProcessCore = %s\n", pinfo.szProcessCore);
TRACE_SAVE(L"wCoreRevision = %d\n", pinfo.wCoreRevision);
TRACE_SAVE(L"szProcessorName = %s\n", pinfo.szProcessorName);
TRACE_SAVE(L"wProcessorRevision = %d\n", pinfo.wProcessorRevision);
TRACE_SAVE(L"szCatalogNumber = %s\n", pinfo.szCatalogNumber);
TRACE_SAVE(L"szVendor = %s\n", pinfo.szVendor);
TRACE_SAVE(L"dwInstructionSet = %d\n", pinfo.dwInstructionSet);
TRACE_SAVE(L"dwClockSpeed = %d\n", pinfo.dwClockSpeed);

memcpy(OutStructurePointer, &pinfo, min(OutStructureLength, sizeof(PROCESSOR_INFO)));

return ERROR_SUCCESS;
}
DWORD dwError = 0x80070000 | GetLastError();
TRACE_SAVE(L"pinfo not filled, GetProcInfo returns 0x%X, rsize = %d\n", dwError, rsize);

return dwError;
}
return ERROR_INVALID_PARAMETER;
}

EDIT3: sizeof(pinfo) != sizeof(PROCESSOR_INFO)

There was error in pointer and its size too. Definitively right code is

:

unsigned long KGetProcInfo(unsigned char * InStructurePointer,
unsigned long InStructureLength, unsigned char * OutStructurePointer,
unsigned long OutStructureLength) {

TRACE_SAVE(L"GetProcInfo(0x%X, %d, 0x%X, %d)\n", InStructurePointer,
InStructureLength, OutStructurePointer, OutStructureLength);

if (OutStructurePointer
&& sizeof(PROCESSOR_INFO) == OutStructureLength) {
PROCESSOR_INFO * pinfo = (PROCESSOR_INFO *) OutStructurePointer;

// Try to lookup processor type.
DWORD rsize = 0;
memset(pinfo, sizeof(PROCESSOR_INFO), 0);
int ret = KernelIoControl(IOCTL_PROCESSOR_INFORMATION, NULL, 0, pinfo,
sizeof(PROCESSOR_INFO), &rsize);
if (ret) {
TRACE_SAVE(L"pinfo filled, GetProcInfo returns ERROR_SUCCESS\n");

TRACE_SAVE(L"wVersion = %d\n", pinfo->wVersion);
TRACE_SAVE(L"szProcessCore = %s\n", pinfo->szProcessCore);
TRACE_SAVE(L"wCoreRevision = %d\n", pinfo->wCoreRevision);
TRACE_SAVE(L"szProcessorName = %s\n", pinfo->szProcessorName);
TRACE_SAVE(L"wProcessorRevision = %d\n", pinfo->wProcessorRevision);
TRACE_SAVE(L"szCatalogNumber = %s\n", pinfo->szCatalogNumber);
TRACE_SAVE(L"szVendor = %s\n", pinfo->szVendor);
TRACE_SAVE(L"dwInstructionSet = %d\n", pinfo->dwInstructionSet);
TRACE_SAVE(L"dwClockSpeed = %d\n", pinfo->dwClockSpeed);

return ERROR_SUCCESS;
}
DWORD dwError = 0x80070000 | GetLastError();
TRACE_SAVE(L"pinfo not filled, GetProcInfo returns 0x%X, needs rsize %d\n", dwError, rsize);

return dwError;
}
return ERROR_INVALID_PARAMETER;
}

It returns:

GetProcInfo(0x3F31CE4, 1, 0x3F31F00, 576)

pinfo filled, GetProcInfo returns ERROR_SUCCESS

wVersion = 1

szProcessCore = Snapdragon

wCoreRevision = 0

szProcessorName = QSD8250

wProcessorRevision = 0

szCatalogNumber =

szVendor = QUALCOMM

dwInstructionSet = 0

dwClockSpeed = 998

KMD_Open

KMD_Open

KMD_IoControl entry, dwCode=9

KMD_IoControl WP7_DLL_CALL, dwCode=9

Function kmode_dll.dll::KGetProcInfo returns 0

KMD_IoControl returned 1