PID로 프로세스 FullPath를 검색 및 Cache하는 기능을 개발하고 있습니다.
AVL 타입의 GenericTable을 사용하구요... 메모리 관리는 LookAsideList (NonPaged)를 사용합니다.
이 과정에서 RtlInsertElementGenericTable 을 이용해 새로 구한 프로세스 정보를 GenericTable에 집어넣는데요...
MSDN에 보면 다음과 같이 되어 있습니다.
위의 내용을 요약하면 다음과 같습니다.
네... 상식적으로 잘 이해가 되죠...
그런데, 디버깅을 하다가 좀 이상한 현상을 발견했습니다. 이모저모로 분석을 하다가... 결국 아래와 같은 테스트를 하게 되었습니다.
MSDN 에 따르면 "### pProcessInfoInserted == pProcessInfo == %p ###" 이 로그는 절대 찍혀선 안되겠군요.... 그렇죠?? ^^;;
그런데 실제로는... 저 로그가 찍히는 경우가 있었습니다.
이럴수기...!! 혼란스럽군요.... @.@
이건 정말 중요한 문제입니다. 왜냐하면...
테스트해 본 바로는... 일단 저 84E297C0 라는 버퍼는 GenericTable에 저장된 것이 맞는 것 같습니다.
왜나하면.. 그 이후로 저 버퍼가 GenericTable에서 검색된 로그가 있거든요...
(뭐 로그는 제가 알아보기 쉽게 적은거니 내용에 신경쓰실 필요 없구요... 그냥 저 값이 GenericTable에서 검색되고 있다는 것만 보시면 됩니다.)
음... GenericTable을 처음 써보는 것도 아니고... 지금까지 로컬변수를 Insert해서 사용한 적도 많았는데요... 이게 어찌된 일일까요... ^^;;
AVL 타입의 GenericTable은 처음 써보는데요... AVL 타입은 구현이 약간 다른 걸까요?
아니면... 위의 인자로 넣어준 버퍼와 GenericTable 내에서 할당하는 버퍼가 동일한 LookAsideList에서 할당된다는 점 때문에 저렇게 동작하는 것일까요?
나중에 시간날때... RtlInsertElementGenericTable 의 어셈코드를 한번 분석해봐야겠습니다.
접기
kd> uf nt!RtlInsertElementGenericTable
nt!RtlInsertElementGenericTable:
82c71882 8bff mov edi,edi
82c71884 55 push ebp
82c71885 8bec mov ebp,esp
82c71887 57 push edi
82c71888 8b7d08 mov edi,dword ptr [ebp+8]
82c7188b 8d4508 lea eax,[ebp+8]
82c7188e 50 push eax
82c7188f ff750c push dword ptr [ebp+0Ch]
82c71892 e824590600 call nt!SwapSplayLinks+0xd8 (82cd71bb)
82c71897 50 push eax
82c71898 ff7508 push dword ptr [ebp+8]
82c7189b ff7514 push dword ptr [ebp+14h]
82c7189e ff7510 push dword ptr [ebp+10h]
82c718a1 ff750c push dword ptr [ebp+0Ch]
82c718a4 57 push edi
82c718a5 e82bffffff call nt!RtlInsertElementGenericTableFull (82c717d5)
82c718aa 5f pop edi
82c718ab 5d pop ebp
82c718ac c21000 ret 10h
kd> uf nt!RtlInsertElementGenericTableFull
nt!RtlInsertElementGenericTableFull:
82c717d5 8bff mov edi,edi
82c717d7 55 push ebp
82c717d8 8bec mov ebp,esp
82c717da 837d1c01 cmp dword ptr [ebp+1Ch],1
82c717de 56 push esi
82c717df 57 push edi
82c717e0 8b7d08 mov edi,dword ptr [ebp+8]
82c717e3 7474 je nt!RtlInsertElementGenericTableFull+0x84 (82c71859)
nt!RtlInsertElementGenericTableFull+0x10:
82c717e5 8b4d10 mov ecx,dword ptr [ebp+10h]
82c717e8 8d4118 lea eax,[ecx+18h]
82c717eb 3bc1 cmp eax,ecx
82c717ed 720b jb nt!RtlInsertElementGenericTableFull+0x25 (82c717fa)
nt!RtlInsertElementGenericTableFull+0x1a:
82c717ef 50 push eax
82c717f0 57 push edi
82c717f1 ff571c call dword ptr [edi+1Ch]
82c717f4 8bf0 mov esi,eax
82c717f6 85f6 test esi,esi
82c717f8 750e jne nt!RtlInsertElementGenericTableFull+0x33 (82c71808)
nt!RtlInsertElementGenericTableFull+0x25:
82c717fa 8b4514 mov eax,dword ptr [ebp+14h]
82c717fd 85c0 test eax,eax
82c717ff 7403 je nt!RtlInsertElementGenericTableFull+0x2f (82c71804)
nt!RtlInsertElementGenericTableFull+0x2c:
82c71801 c60000 mov byte ptr [eax],0
nt!RtlInsertElementGenericTableFull+0x2f:
82c71804 33c0 xor eax,eax
82c71806 eb6f jmp nt!RtlInsertElementGenericTableFull+0xa2 (82c71877)
nt!RtlInsertElementGenericTableFull+0x33:
82c71808 83660400 and dword ptr [esi+4],0
82c7180c 83660800 and dword ptr [esi+8],0
82c71810 8936 mov dword ptr [esi],esi
82c71812 8d4f04 lea ecx,[edi+4]
82c71815 8b5104 mov edx,dword ptr [ecx+4]
82c71818 8d460c lea eax,[esi+0Ch]
82c7181b 8908 mov dword ptr [eax],ecx
82c7181d 895004 mov dword ptr [eax+4],edx
82c71820 8902 mov dword ptr [edx],eax
82c71822 894104 mov dword ptr [ecx+4],eax
82c71825 ff4714 inc dword ptr [edi+14h]
82c71828 837d1c00 cmp dword ptr [ebp+1Ch],0
82c7182c 7504 jne nt!RtlInsertElementGenericTableFull+0x5d (82c71832)
nt!RtlInsertElementGenericTableFull+0x59:
82c7182e 8937 mov dword ptr [edi],esi
82c71830 eb13 jmp nt!RtlInsertElementGenericTableFull+0x70 (82c71845)
nt!RtlInsertElementGenericTableFull+0x5d:
82c71832 837d1c02 cmp dword ptr [ebp+1Ch],2
82c71836 8b4518 mov eax,dword ptr [ebp+18h]
82c71839 7505 jne nt!RtlInsertElementGenericTableFull+0x6b (82c71840)
nt!RtlInsertElementGenericTableFull+0x66:
82c7183b 897004 mov dword ptr [eax+4],esi
82c7183e eb03 jmp nt!RtlInsertElementGenericTableFull+0x6e (82c71843)
nt!RtlInsertElementGenericTableFull+0x6b:
82c71840 897008 mov dword ptr [eax+8],esi
nt!RtlInsertElementGenericTableFull+0x6e:
82c71843 8906 mov dword ptr [esi],eax
nt!RtlInsertElementGenericTableFull+0x70:
82c71845 ff7510 push dword ptr [ebp+10h]
82c71848 8d4618 lea eax,[esi+18h]
82c7184b ff750c push dword ptr [ebp+0Ch]
82c7184e 50 push eax
82c7184f e86c9f0100 call nt!memcpy (82c8b7c0)
82c71854 83c40c add esp,0Ch
82c71857 eb03 jmp nt!RtlInsertElementGenericTableFull+0x87 (82c7185c)
nt!RtlInsertElementGenericTableFull+0x84:
82c71859 8b7518 mov esi,dword ptr [ebp+18h]
nt!RtlInsertElementGenericTableFull+0x87:
82c7185c 56 push esi
82c7185d e8495b0600 call nt!RtlSplay (82cd73ab)
82c71862 8907 mov dword ptr [edi],eax
82c71864 8b4514 mov eax,dword ptr [ebp+14h]
82c71867 85c0 test eax,eax
82c71869 7409 je nt!RtlInsertElementGenericTableFull+0x9f (82c71874)
nt!RtlInsertElementGenericTableFull+0x96:
82c7186b 837d1c01 cmp dword ptr [ebp+1Ch],1
82c7186f 0f95c1 setne cl
82c71872 8808 mov byte ptr [eax],cl
nt!RtlInsertElementGenericTableFull+0x9f:
82c71874 8d4618 lea eax,[esi+18h]
nt!RtlInsertElementGenericTableFull+0xa2:
82c71877 5f pop edi
82c71878 5e pop esi
82c71879 5d pop ebp
82c7187a c21800 ret 18h
접기