Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 

(시리즈 글이 4개 있습니다.)
.NET Framework: 872. C# - 로딩된 Native DLL의 export 함수 목록 출력
; https://www.sysnet.pe.kr/2/0/12093

디버깅 기술: 197. Windbg - PE 포맷의 Export Directory 탐색
; https://www.sysnet.pe.kr/2/0/13689

디버깅 기술: 199. Windbg - 리눅스에서 뜬 닷넷 응용 프로그램 덤프 파일에 포함된 DLL의 Export Directory 탐색
; https://www.sysnet.pe.kr/2/0/13692

디버깅 기술: 200. DLL Export/Import의 Hint 의미
; https://www.sysnet.pe.kr/2/0/13700




Windbg - 리눅스에서 뜬 닷넷 응용 프로그램 덤프 파일에 포함된 DLL의 Export Directory 탐색

리눅스에서 실행한 닷넷 응용 프로그램을 "dotnet-dump"로 덤프를 뜰 수 있는데요, 재미있게도 해당 덤프 파일을 Windbg에서도 그대로 열어 분석할 수 있습니다.

예를 들어, lm 명령을 내리면 이렇게 로딩된 PE 목록이 나오는데요,

0:000> lm
start             end                 module name
000055c1`e5672000 000055c1`e5696000   dotnet     (deferred)             
00007f34`35a30000 00007f34`36338400   System_Private_CoreLib   (deferred)      
...[생략]...

아쉬운 것은, 윈도우와는 달리 dt 명령어들이 동작하지 않지만,

0:000> dt -n _IMAGE_DOS_HEADER
...[생략]...
Symbol _IMAGE_DOS_HEADER not found.

그래도 PE(Portable Executable) 구조를 따라 닷넷 DLL들이 만들어지기 때문에 기존 지식을 활용해 분석할 수는 있습니다.

게다가 windbg의 명령어들은 여전히 동작하는데요, 다행히 그중 dh도 있습니다.

0:000> !dh 00007f34`35a30000 -f

File Type: DLL
FILE HEADER VALUES
    FD1D machine (Unknown)
       3 number of sections
99DB2862 time date stamp Thu Oct 19 06:19:30 2051

       0 file pointer to symbol table
       0 number of symbols
      F0 size of optional header
    2022 characteristics
            Executable
            App can handle >2gb addresses
            DLL

OPTIONAL HEADER VALUES
     20B magic #
   11.00 linker version
       0 size of code
       0 size of initialized data
       0 size of uninitialized data
       0 address of entry point
       0 base of code
         ----- new -----
0000000005000000 image base
     200 section alignment
     200 file alignment
       3 subsystem (Windows CUI)
    5.02 operating system version
    0.00 image version
    5.02 subsystem version
  908400 size of image
     200 size of headers
       0 checksum
0000000000400000 size of stack reserve
0000000000004000 size of stack commit
0000000000000000 size of heap reserve
0000000000000000 size of heap commit
    8160  DLL characteristics
            High entropy VA supported
            Dynamic base
            NX compatible
            Terminal server aware
  8F1D5C [      43] address [size] of Export Directory
       0 [       0] address [size] of Import Directory
   42800 [     494] address [size] of Resource Directory
   4301C [   59124] address [size] of Exception Directory
       0 [       0] address [size] of Security Directory
  901E00 [    6514] address [size] of Base Relocation Directory
  8F1894 [      38] address [size] of Debug Directory
       0 [       0] address [size] of Description Directory
       0 [       0] address [size] of Special Directory
       0 [       0] address [size] of Thread Storage Directory
       0 [       0] address [size] of Load Configuration Directory
       0 [       0] address [size] of Bound Import Directory
       0 [       0] address [size] of Import Address Table Directory
       0 [       0] address [size] of Delay Import Directory
   42CA0 [      48] address [size] of COR20 Header Directory
       0 [       0] address [size] of Reserved Directory

Export DataDirectory의 VirtualAddress == 8F1D5C, Size == 43인데 이를 이용해 IMAGE_EXPORT_DIRECTORY를 덤프해 보면,

0:000> dd 00007f34`35a30000+8F1D5C LA
00007f34`36321d5c  00000000 00000000 00000000 008f1d84
00007f34`36321d6c  00000000 00000000 00000000 00000000
00007f34`36321d7c  00000000 00000000

[StructLayout(LayoutKind.Sequential)]
public struct IMAGE_EXPORT_DIRECTORY
{
    public uint Characteristics; // 00000000
    public uint TimeDateStamp;   // 00000000
    public short MajorVersion;   // 0000
    public short MinorVersion;   // 0000
    public uint Name;            // 008f1d84
    public uint Base;            // 00000000
    public uint NumberOfFunctions;     // 00000000
    public uint NumberOfNames;         // 00000000
    public uint AddressOfFunctions;    // 00000000
    public uint AddressOfNames;        // 00000000
    public uint AddressOfNameOrdinals; // 00000000
}

보는 바와 같이 DLL의 이름을 가리키는 Name 필드를 제외하고는 설정된 것이 없습니다.

0:000> da 00007f34`35a30000+008f1d84
00007f34`36321d84  "System.Private.CoreLib.dll"

또한, 이전과 달리 Export DataDirectory의 크기가 별도 여분의 공간을 차지하지 않고 정확히 저 DLL 이름까지만 포함하고 있습니다.

0:000> db 00007f34`35a30000+8F1D5C L43
00007f34`36321d5c  00 00 00 00 00 00 00 00-00 00 00 00 84 1d 8f 00  ................
00007f34`36321d6c  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................
00007f34`36321d7c  00 00 00 00 00 00 00 00-53 79 73 74 65 6d 2e 50  ........System.P
00007f34`36321d8c  72 69 76 61 74 65 2e 43-6f 72 65 4c 69 62 2e 64  rivate.CoreLib.d
00007f34`36321d9c  6c 6c 00      

그래서, 거창한 제목과는 달리 ^^ 딱히 Export Data Directory에 대해 탐색할 것이 없습니다.

암튼, .NET DLL이 PE 포맷을 따르는 덕분에 Windbg로 기존 지식을 활용해 분석할 수 있어서 디버깅도 한결 쉽게 되었습니다. ^^




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 7/24/2024]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 16  17  18  19  20  21  22  23  24  25  [26]  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13287정성태3/16/202311599Windows: 229. Win32 - 대화창 템플릿의 2진 리소스를 읽어들여 윈도우를 직접 띄우는 방법파일 다운로드1
13286정성태3/15/202312023Windows: 228. Win32 - 리소스에 포함된 대화창 Template의 2진 코드 해석 방법
13285정성태3/14/202311407Windows: 227. Win32 C/C++ - Dialog Procedure를 재정의하는 방법 [2]파일 다운로드1
13284정성태3/13/202311279Windows: 226. Win32 C/C++ - Dialog에서 값을 반환하는 방법파일 다운로드1
13283정성태3/12/202310105오류 유형: 852. 파이썬 - TypeError: coercing to Unicode: need string or buffer, NoneType found
13282정성태3/12/202310496Linux: 58. WSL - nohup 옵션이 필요한 경우
13281정성태3/12/202311142Windows: 225. 윈도우 바탕화면의 아이콘들이 넓게 퍼지는 경우 [2]
13280정성태3/9/202312627개발 환경 구성: 670. WSL 2에서 호스팅 중인 TCP 서버를 외부에서 접근하는 방법
13279정성태3/9/202312087오류 유형: 851. 파이썬 ModuleNotFoundError: No module named '_cffi_backend'
13278정성태3/8/202311889개발 환경 구성: 669. WSL 2의 (init이 아닌) systemd 지원 [1]
13277정성태3/6/202313162개발 환경 구성: 668. 코드 사인용 인증서 신청 및 적용 방법(예: Digicert)
13276정성태3/5/202312761.NET Framework: 2102. C# 11 - ref struct/ref field를 위해 새롭게 도입된 scoped 예약어 [1]
13275정성태3/3/202312674.NET Framework: 2101. C# 11의 ref 필드 설명
13274정성태3/2/202311947.NET Framework: 2100. C# - ref 필드로 ref struct 타입을 허용하지 않는 이유
13273정성태2/28/202310968.NET Framework: 2099. C# - 관리 포인터로서의 ref 예약어 의미
13272정성태2/27/202311838오류 유형: 850. SSMS - mdf 파일을 Attach 시킬 때 Operating system error 5: "5(Access is denied.)" 에러
13271정성태2/25/202311658오류 유형: 849. Sql Server Configuration Manager가 시작 메뉴에 없는 경우
13270정성태2/24/202310934.NET Framework: 2098. dotnet build에 /p 옵션을 적용 시 유의점
13269정성태2/23/202312318스크립트: 46. 파이썬 - uvicorn의 콘솔 출력을 UDP로 전송
13268정성태2/22/202312754개발 환경 구성: 667. WSL 2 내부에서 열고 있는 UDP 서버를 호스트 측에서 접속하는 방법
13267정성태2/21/202313087.NET Framework: 2097. C# - 비동기 소켓 사용 시 메모리 해제가 finalizer 단계에서 발생하는 사례파일 다운로드1
13266정성태2/20/202312394오류 유형: 848. .NET Core/5+ - Process terminated. Couldn't find a valid ICU package installed on the system
13265정성태2/18/202312805.NET Framework: 2096. .NET Core/5+ - PublishSingleFile 유형에 대한 runtimeconfig.json 설정
13264정성태2/17/202314769스크립트: 45. 파이썬 - uvicorn 사용자 정의 Logger 작성
13263정성태2/16/202312083개발 환경 구성: 666. 최신 버전의 ilasm.exe/ildasm.exe 사용하는 방법
13262정성태2/15/202313474디버깅 기술: 191. dnSpy를 이용한 (소스 코드가 없는) 닷넷 응용 프로그램 디버깅 방법 [1]
... 16  17  18  19  20  21  22  23  24  25  [26]  27  28  29  30  ...