首页
社区
课程
招聘
[讨论]关于FS寄存器
发表于: 2011-9-1 10:24 5222

[讨论]关于FS寄存器

2011-9-1 10:24
5222
老罗解释得很好了
http://www.luocong.com/articles/show_article.asp?Article_ID=30
但是  我最近看到如下两句代码
mov eax,fs:[0x124] //TEB
mov esi,[eax+0x44] //EPROCESS

问题2个:
1 老罗给出的代码只有0X30那么大啊  上面两句是怎么来的?
是不是老罗没给出全部的结构体说明啊,哪个能给个 TEB全部的结构体说明
2 上面2句代码用到MFC程序里面会出错  我出错的代码如下
DWORD _declspec(naked)  GetCurPEP(  )
{
        __asm
        {
                mov eax,fs:[0x124] //TEB
                mov eax,[eax+0x44] //EPROCESS
                ret
        }
}

老罗给出的结构如下
#pragma pack(1)

typedef struct _EXCEPTION_REGISTRATION_RECORD
{
    struct _EXCEPTION_REGISTRATION_RECORD * pNext;
    FARPROC                                 pfnHandler;
} EXCEPTION_REGISTRATION_RECORD, *PEXCEPTION_REGISTRATION_RECORD;

typedef struct _TIB
{
PEXCEPTION_REGISTRATION_RECORD pvExcept; // 00h Head of exception record list
PVOID   pvStackUserTop;         // 04h Top of user stack
PVOID   pvStackUserBase;        // 08h Base of user stack

union                           // 0Ch (NT/Win95 differences)
{
    struct  // Win95 fields
    {
        WORD    pvTDB;          // 0Ch TDB
        WORD    pvThunkSS;      // 0Eh SS selector used for thunking to 16 bits
        DWORD   unknown1;       // 10h
    } WIN95;

    struct  // WinNT fields
    {
        PVOID SubSystemTib;     // 0Ch
        ULONG FiberData;        // 10h
    } WINNT;
} TIB_UNION1;

PVOID   pvArbitrary;            // 14h Available for application use
struct _tib *ptibSelf;          // 18h Linear address of TIB structure

union                           // 1Ch (NT/Win95 differences)
{
    struct  // Win95 fields
    {
        WORD    TIBFlags;           // 1Ch
        WORD    Win16MutexCount;    // 1Eh
        DWORD   DebugContext;       // 20h
        DWORD   pCurrentPriority;   // 24h
        DWORD   pvQueue;            // 28h Message Queue selector
    } WIN95;

    struct  // WinNT fields
    {
        DWORD unknown1;             // 1Ch
        DWORD processID;            // 20h
        DWORD threadID;             // 24h
        DWORD unknown2;             // 28h
    } WINNT;
} TIB_UNION2;

PVOID*  pvTLSArray;             // 2Ch Thread Local Storage array

union                           // 30h (NT/Win95 differences)
{
    struct  // Win95 fields
    {
        PVOID*  pProcess;       // 30h Pointer to owning process database
    } WIN95;
} TIB_UNION3;

} TIB, *PTIB;
#pragma pack()

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (3)
雪    币: 204
活跃值: (25)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
  为什么没人回答啊
2011-9-1 11:26
0
雪    币: 113
活跃值: (100)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
3
这是什么系统的结构?
嗯,其实用windbg看下就好了吧。

0: kd> dt nt!_kpcr 84975c00
   +0x000 NtTib            : _NT_TIB
   +0x000 Used_ExceptionList : 0xbfaa7a94 _EXCEPTION_REGISTRATION_RECORD
   +0x004 Used_StackBase   : (null)
   +0x008 Spare2           : (null)
   +0x00c TssCopy          : 0x801ed000 Void
   +0x010 ContextSwitches  : 0x7c38e4
   +0x014 SetMemberCopy    : 1
   +0x018 Used_Self        : 0x7ffdd000 Void
   +0x01c SelfPcr          : 0x84975c00 _KPCR
   +0x020 Prcb             : 0x84975d20 _KPRCB
   ......
   +0x0dc KernelReserved2  : [17] 0
   +0x120 PrcbData         : _KPRCB

120是PrcbData,offset 4的地方是_KPRCB中放kthread指针,

0: kd> dt _kthread
ntdll!_KTHREAD
   +0x000 Header           : _DISPATCHER_HEADER
   +0x010 CycleTime        : Uint8B
   +0x018 HighCycleTime    : Uint4B
   +0x020 QuantumTarget    : Uint8B
   +0x028 InitialStack     : Ptr32 Void
   +0x02c StackLimit       : Ptr32 Void
   +0x030 KernelStack      : Ptr32 Void
   +0x034 ThreadLock       : Uint4B
   +0x038 WaitRegister     : _KWAIT_STATUS_REGISTER
   +0x039 Running          : UChar
   +0x03a Alerted          : [2] UChar
   +0x03c KernelStackResident : Pos 0, 1 Bit
   +0x03c ReadyTransition  : Pos 1, 1 Bit
   +0x03c ProcessReadyQueue : Pos 2, 1 Bit
   +0x03c WaitNext         : Pos 3, 1 Bit
   +0x03c SystemAffinityActive : Pos 4, 1 Bit
   +0x03c Alertable        : Pos 5, 1 Bit
   +0x03c GdiFlushActive   : Pos 6, 1 Bit
   +0x03c UserStackWalkActive : Pos 7, 1 Bit
   +0x03c ApcInterruptRequest : Pos 8, 1 Bit
   +0x03c ForceDeferSchedule : Pos 9, 1 Bit
   +0x03c QuantumEndMigrate : Pos 10, 1 Bit
   +0x03c UmsDirectedSwitchEnable : Pos 11, 1 Bit
   +0x03c TimerActive      : Pos 12, 1 Bit
   +0x03c SystemThread     : Pos 13, 1 Bit
   +0x03c Reserved         : Pos 14, 18 Bits
   +0x03c MiscFlags        : Int4B
   +0x040 ApcState         : _KAPC_STATE
......

offset 44其实访问了_KAPC_STATE结构中了。
0: kd> dt _kthread apcstate. 887c9030
ntdll!_KTHREAD
   +0x040 ApcState  :
      +0x000 ApcListHead : [2] _LIST_ENTRY [ 0x887c9070 - 0x887c9070 ]
      +0x010 Process   : 0x8c8e73e8 _KPROCESS
      +0x014 KernelApcInProgress : 0 ''
      +0x015 KernelApcPending : 0 ''
      +0x016 UserApcPending : 0 ''
   +0x040 ApcStateFill : [23]  "p???"
   +0x134 ApcStateIndex : 0 ''
   +0x168 ApcStatePointer : [2]

最后说下,我的系统是Win 7,KProcess字段应该是offset 50才对。你的代码可能是XP的或者是更早的系统。使用IDA找了一段代码看,确实如此。

mov     eax, large fs:124h ; _kthread
mov     eax, [eax+_KTHREAD.___u12.ApcState.Process] ; _kproces (50h)
2011-9-1 14:22
0
雪    币: 204
活跃值: (25)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
结构套结构 差点疯掉
不过还是懂了 无比感谢对待如此小菜的问题 你也如此详细的给出指导
2011-9-1 15:52
0
游客
登录 | 注册 方可回帖
返回
//