会否将以下代码转换成DELPHI 。
最后能否将仿问,比如ISA,PCI扩展槽上 的数据
的办法赋上。
 为谢谢,特拿100分回报。
  
    typedef struct
    {
        unsigned short  offset_0_15;
        unsigned short  selector;
        unsigned char    param_count : 4;
        unsigned char    some_bits   : 4;
        unsigned char    type        : 4;
        unsigned char    app_system  : 1;
        unsigned char    dpl         : 2;
        unsigned char    present     : 1;
        unsigned short  offset_16_31;
    } CALLGATE_DESCRIPTOR;
 
    C:\NTDDK\bin>objdir /D \Device
    PhysicalMemory                   
        Section
        DACL - 
           Ace[ 0] - Grant - 0xf001f - NT AUTHORITY\SYSTEM
                             Inherit: 
                             Access: 0x001F  and  ( D RCtl WOwn WDacl )
           Ace[ 1] - Grant - 0x2000d - BUILTIN\Administrators
                             Inherit: 
                             Access: 0x000D  and  ( RCtl )
 
    VOID SetPhyscialMemorySectionCanBeWrited(HANDLE hSection)
    {
       PACL pDacl=NULL;
       PACL pNewDacl=NULL;
       PSECURITY_DESCRIPTOR pSD=NULL;
       DWORD dwRes;
       EXPLICIT_ACCESS ea;
       if(dwRes=GetSecurityInfo(hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION,
                  NULL,NULL,&pDacl,NULL,&pSD)!=ERROR_SUCCESS)
          {
             printf( "GetSecurityInfo Error %u\n", dwRes );
             goto CleanUp;
          }
       ZeroMemory(&ea, sizeof(EXPLICIT_ACCESS));
       ea.grfAccessPermissions = SECTION_MAP_WRITE;
       ea.grfAccessMode = GRANT_ACCESS;
       ea.grfInheritance= NO_INHERITANCE;
       ea.Trustee.TrusteeForm = TRUSTEE_IS_NAME;
       ea.Trustee.TrusteeType = TRUSTEE_IS_USER;
       ea.Trustee.ptstrName = "CURRENT_USER";
       if(dwRes=SetEntriesInAcl(1,&ea,pDacl,&pNewDacl)!=ERROR_SUCCESS)
          {
             printf( "SetEntriesInAcl %u\n", dwRes );
             goto CleanUp;
          }
       if(dwRes=SetSecurityInfo(hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION,NULL,NULL,pNewDacl,NULL)!=ERROR_SUCCESS)
          {
             printf("SetSecurityInfo %u\n",dwRes);
             goto CleanUp;
          }
    CleanUp:
       if(pSD)
          LocalFree(pSD);
       if(pNewDacl)
          LocalFree(pSD);
    }
    这段代码对给定HANDLE的对象增加了如下的ACE: 
    PhysicalMemory                   
        Section
        DACL - 
           Ace[ 0] - Grant - 0x2 - WEBCRAZY\Administrator
                             Inherit: 
                             Access: 0x0002    //SECTION_MAP_WRITE    typedef struct gdtr {
        short Limit;
        short BaseLow;
        short BaseHigh;
    } Gdtr_t, *PGdtr_t;
    ULONG MiniMmGetPhysicalAddress(ULONG virtualaddress)
    {
        if(virtualaddress<0x80000000||virtualaddress>=0xA0000000)
           return 0;
        return virtualaddress&0x1FFFF000;
    }
    BOOL ExecRing0Proc(ULONG Entry,ULONG seglen)
    {
       Gdtr_t gdt;
       __asm sgdt gdt;     
       ULONG mapAddr=MiniMmGetPhysicalAddress(gdt.BaseHigh<<16U|gdt.BaseLow);
       if(!mapAddr) return 0;
       HANDLE   hSection=NULL;
       NTSTATUS status;
       OBJECT_ATTRIBUTES        objectAttributes;
       UNICODE_STRING objName;
       CALLGATE_DESCRIPTOR *cg;
       status = STATUS_SUCCESS;
       RtlInitUnicodeString(&objName,L"\\Device\\PhysicalMemory");
       InitializeObjectAttributes(&objectAttributes,
                                  &objName,
                                  OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
                                  NULL,
                                 (PSECURITY_DESCRIPTOR) NULL);
       status = ZwOpenSection(&hSection,SECTION_MAP_READ|SECTION_MAP_WRITE,&objectAttributes);
       if(status == STATUS_ACCESS_DENIED){
          status = ZwOpenSection(&hSection,READ_CONTROL|WRITE_DAC,&objectAttributes);
          SetPhyscialMemorySectionCanBeWrited(hSection);
          ZwClose(hSection);
          status =ZwOpenSection(&hSection,SECTION_MAP_WRITE|SECTION_MAP_WRITE,&objectAttributes);
       }
       if(status != STATUS_SUCCESS)
         {
            printf("Error Open PhysicalMemory Section Object,Status:%08X\n",status);
            return 0;
         }   
       PVOID BaseAddress;
       BaseAddress=MapViewOfFile(hSection,
                     FILE_MAP_READ|FILE_MAP_WRITE,
                     0,
                     mapAddr,    //low part
                     (gdt.Limit+1));
       if(!BaseAddress)
          {
             printf("Error MapViewOfFile:");
             PrintWin32Error(GetLastError());
             return 0;
          }
       BOOL setcg=FALSE;
       for(cg=(CALLGATE_DESCRIPTOR *)((ULONG)BaseAddress+(gdt.Limit&0xFFF8));(ULONG)cg>(ULONG)BaseAddress;cg--)
           if(cg->type == 0){
             cg->offset_0_15 = LOWORD(Entry);
             cg->selector = 8;
             cg->param_count = 0;
             cg->some_bits = 0;
             cg->type = 0xC;          // 386 call gate
             cg->app_system = 0;      // A system descriptor
             cg->dpl = 3;             // Ring 3 code can call
             cg->present = 1;
             cg->offset_16_31 = HIWORD(Entry);
             setcg=TRUE;
             break;
          }
       if(!setcg){
            ZwClose(hSection);
            return 0;
       }
       short farcall[3];
       farcall[2]=((short)((ULONG)cg-(ULONG)BaseAddress))|3;  //Ring 3 callgate;
       if(!VirtualLock((PVOID)Entry,seglen))
          {
             printf("Error VirtualLock:");
             PrintWin32Error(GetLastError());
             return 0;
          }
       SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL);
       Sleep(0);
       _asm call fword ptr [farcall]
       SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_NORMAL);
       VirtualUnlock((PVOID)Entry,seglen);
       //Clear callgate
       *(ULONG *)cg=0;
       *((ULONG *)cg+1)=0;
       ZwClose(hSection);
       return TRUE;
    }