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 authentication level.

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

Submitter:  None
Submitted:  Mon 17 Jul 2006 04:26:21 PM UTC
   
 
Category:  None Priority:  5 - Normal
Status:  Wont Do Privacy:  Public
Assigned to:  arcanum Originator Email:  -email is unavailable-
Open/Closed:  Closed

Sat 27 Nov 2021 09:33:54 PM UTC, comment #4: 

The audit trail indicates this didn't work, at least in some cases.

Parallel port PCs are no longer readily available, so this one can be closed I think.

Joerg Wunsch <joerg_wunsch>
Group administrator
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>
Group 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>
Group 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>
Group Member
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

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

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

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by joerg_wunsch (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-11-27 joerg_wunsch StatusNone Wont Do
        Open/ClosedOpen Closed
    2006-08-14 joerg_wunsch Assigned toNone arcanum
    2006-07-17 None Attached File- Added userio.c, #10368

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code