patchAVR Downloader/UploaDEr - Patches: patch #5245, User mode IO access in WIN32...

 
 

You are not allowed to post comments on this tracker with your current authentification level.

patch #5245: User mode IO access in WIN32 wiyhout giveio.sys

Submitted by:  None
Submitted on:  Mon 17 Jul 2006 04:26:21 PM UTC  
 
Category: NonePriority: 5 - Normal
Status: NonePrivacy: Public
Assigned to: Eric Weddington <arcanum>Originator Email: -unavailable-
Open/Closed: Open

Fri 01 Sep 2006 09:04:04 PM UTC, comment #3:

Tried that on a Win2K system using MinGW today.

The suggested procedure didn't work. enable_user_mode_io()
bailed out with an error in the last function call (the
indirect one), so the attempt to access the IO ports caused
an exception.

The inline asm needs to be written differently for GCC:

asm("movl $0x378, %edx" "\n\t"
"inb %dx, %al");

Joerg Wunsch <joerg_wunsch>
Project Administrator
Mon 14 Aug 2006 09:36:50 PM UTC, comment #2:

That looks like something for you to verify, Eric.

Joerg Wunsch <joerg_wunsch>
Project Administrator
Fri 11 Aug 2006 03:57:58 PM UTC, comment #1:

Zoltan,

Which Windows OS versions has this been tested on? Does it work for Windows 2000 and XP?

Thanks
Eric

Eric Weddington <arcanum>
Project MemberIn charge of this item.
Mon 17 Jul 2006 04:26:21 PM UTC, original submission:

Hi,

Here is a code to enable user mode IO access in Windows without using any external driver. After enable_user_mode_io() is called, process can execute in/out calls.

Regards,

Zoltan

////////////////////////////////////////////////////////////

#include <windows.h>

#ifdef WIN32

static int enable_privilege(const char* priv)
{
int rc = -1;
HANDLE hToken;
LUID seValue;
TOKEN_PRIVILEGES tkPriv;

// Open process token
if (!OpenProcessToken(
GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
&hToken))
return -1;

if (!LookupPrivilegeValue(NULL, priv, &seValue))
goto cleanup;

tkPriv.PrivilegeCount = 1;
tkPriv.Privileges[0].Luid = seValue;
tkPriv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

// Enable privilege
if (!AdjustTokenPrivileges(hToken, FALSE, &tkPriv, sizeof(tkPriv), NULL, NULL))
goto cleanup;

// Success
rc = 0;

cleanup:

CloseHandle(hToken);

return rc;
}

static int enable_user_mode_io()
{
typedef ULONG (__stdcall* PFn)(HANDLE, ULONG, PVOID, ULONG);

int rc = -1;
HMODULE hNtDll = NULL;
PFn fn;
ULONG nIOPL = 3;

// Find NTDLL.DLL
hNtDll = GetModuleHandle("ntdll.dll");
if (hNtDll == NULL)
// Failed to find NTDLL.DLL
return -1;

// Find ZwSetInformationProcess in NTDLL.DLL
fn = (PFn)GetProcAddress(hNtDll, "ZwSetInformationProcess");
if (fn == NULL)
return -1;

// Enable SE_TCB_NAME privilege
enable_privilege(SE_TCB_NAME);

// Set user mode IO access
if (fn(GetCurrentProcess(), 16, &nIOPL, sizeof(nIOPL)) != 0)
return -1;

return 0;
}

#if 1
int main(int argc, char** argv)
{
enable_user_mode_io();

// Test direct IO access
{
ULONG port = 0x378;
__asm mov edx, port
__asm in al, dx
}

return 0;
}
#endif

#endif // WIN32

Anonymous

 

Attached Files
file #10368:  userio.c added by None (2kB - application/hex)

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

Do you think this task is very important?
If so, you can click here to add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.

 

Please enter the title of George Orwell's famous dystopian book (it's a date):

 

 

Follow 2 latest changes.

Date Changed By Updated Field Previous Value => Replaced By
Mon 14 Aug 2006 09:36:50 PM UTCjoerg_wunschAssigned toNone=>arcanum
Mon 17 Jul 2006 04:26:21 PM UTCNoneAttached File-=>Added userio.c, #10368

Back to the top


Powered by Savane 3.1-cleanup