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

비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  8  9  10  11  12  [13]  14  15  ...
NoWriterDateCnt.TitleFile(s)
13616정성태5/3/20248614닷넷: 2256. ASP.NET Core 웹 사이트의 HTTP/HTTPS + Dual mode Socket (IPv4/IPv6) 지원 방법파일 다운로드1
13615정성태5/3/20249521닷넷: 2255. C# 배열을 Numpy ndarray 배열과 상호 변환
13614정성태5/2/20249181닷넷: 2254. C# - COM 인터페이스의 상속 시 중복으로 메서드를 선언
13613정성태5/1/20248912닷넷: 2253. C# - Video Capture 장치(Camera) 열거 및 지원 포맷 조회파일 다운로드1
13612정성태4/30/20249179오류 유형: 902. Visual Studio - error MSB3021: Unable to copy file
13611정성태4/29/20248568닷넷: 2252. C# - GUID 타입 전용의 UnmanagedType.LPStruct - 두 번째 이야기파일 다운로드1
13610정성태4/28/20248948닷넷: 2251. C# - 제네릭 인자를 가진 타입을 생성하는 방법 - 두 번째 이야기
13609정성태4/27/20249166닷넷: 2250. PInvoke 호출 시 참조 타입(class)을 마샬링하는 [IN], [OUT] 특성파일 다운로드1
13608정성태4/26/20249502닷넷: 2249. C# - 부모의 필드/프로퍼티에 대해 서로 다른 자식 클래스 간에 Reflection 접근이 동작할까요?파일 다운로드1
13607정성태4/25/20249499닷넷: 2248. C# - 인터페이스 타입의 다중 포인터를 인자로 갖는 C/C++ 함수 연동
13606정성태4/24/20249368닷넷: 2247. C# - tensorflow 연동 (MNIST 예제)파일 다운로드1
13605정성태4/23/202410708닷넷: 2246. C# - Python.NET을 이용한 파이썬 소스코드 연동파일 다운로드1
13604정성태4/22/20248402오류 유형: 901. Visual Studio - Unable to set the next statement. Set next statement cannot be used in '[Exception]' call stack frames.
13603정성태4/21/20249665닷넷: 2245. C# - IronPython을 이용한 파이썬 소스코드 연동파일 다운로드1
13602정성태4/20/20248946닷넷: 2244. C# - PCM 오디오 데이터를 연속(Streaming) 재생 (Windows Multimedia)파일 다운로드1
13601정성태4/19/20249056닷넷: 2243. C# - PCM 사운드 재생(NAudio)파일 다운로드1
13600정성태4/18/20249670닷넷: 2242. C# - 관리 스레드와 비관리 스레드
13599정성태4/17/20249515닷넷: 2241. C# - WAV 파일의 PCM 사운드 재생(Windows Multimedia)파일 다운로드1
13598정성태4/16/202410730닷넷: 2240. C# - WAV 파일 포맷 + LIST 헤더파일 다운로드2
13597정성태4/15/20249108닷넷: 2239. C# - WAV 파일의 PCM 데이터 생성 및 출력파일 다운로드1
13596정성태4/14/20249746닷넷: 2238. C# - WAV 기본 파일 포맷파일 다운로드1
13595정성태4/13/20249897닷넷: 2237. C# - Audio 장치 열기 (Windows Multimedia, NAudio)파일 다운로드1
13594정성태4/12/20249760닷넷: 2236. C# - Audio 장치 열람 (Windows Multimedia, NAudio)파일 다운로드1
13593정성태4/8/20248978닷넷: 2235. MSBuild - AccelerateBuildsInVisualStudio 옵션
13592정성태4/2/202411302C/C++: 165. CLion으로 만든 Rust Win32 DLL을 C#과 연동 [1]
13591정성태4/2/20249425닷넷: 2234. C# - WPF 응용 프로그램에 Blazor App 통합파일 다운로드1
1  2  3  4  5  6  7  8  9  10  11  12  [13]  14  15  ...