Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)

windbg - .NET 4.0 이상의 환경에서 모든 DLL에 대한 심벌 파일을 로드하는 파이썬 스크립트

지난 글에서 .NET 4.0 이상의 환경에서 DLL에 대한 심벌 파일 로드에 대해 알아봤습니다.

windbg - .NET 4.0 이상의 환경에서 DLL의 심벌 파일 로드 방법
; https://www.sysnet.pe.kr/2/0/11330

그런데, 규모가 좀 있는 프로그램이라면 DLL이 꽤나 많을 텐데 언제 저런 작업을 하고 있겠습니까? ^^

그래서 예전에 소개한 pykd를 이용해,

windbg에서 python 스크립트 실행하는 방법 - pykd
; https://www.sysnet.pe.kr/2/0/11227

다음과 같은 확장 스크립트(symbol_net.py)를 만들었습니다.

from pykd import *

def getItem(text, key):
    result = text
    for line in text.splitlines():
        if key in line:
            result = line.split(":")[1].strip()
    return result

def getAddress(text):
    return text.split("(")[0].strip()

outputText = pykd.dbgCommand("!name2ee *!enumerate_all_dlls")

for line in outputText.split("--------------------------------------"):
    moduleAddress = getItem(line, "Module:")
    moduleName = getItem(line, "Assembly:")

    if moduleName == "":
        continue

    moduleInfo = pykd.dbgCommand("!dumpmodule " + moduleAddress)

    moduleStartAdderss = getItem(moduleInfo, "MetaData start address")
    hInstance = long(getAddress(moduleStartAdderss), 16)

    hInstance = hInstance & 0xFFFFFFFFFFFF0000

    dprintln(moduleName + ": " + hex(hInstance).strip('L'))
    cmdText = ".reload /f " + moduleName + "=" + hex(hInstance).strip('L')
    dprintln("\t" + cmdText)
    pykd.dbgCommand(cmdText)

사용법은 간단합니다. pykd를 로드하고 그냥 실행만 하면 됩니다.

// 물론 사전에 sos.dll이 로드되어 있어야 함.

0:000> .load d:\pykd\x64\pykd.dll

0:000> !py d:\pykd\symbol_net.py
mscorlib.dll: 0x7ff962690000
    .reload /f mscorlib.dll=0x7ff962690000
ConsoleApp1.exe: 0x1eae1220000
    .reload /f ConsoleApp1.exe=0x1eae1220000
ClassLibrary1.dll: 0x1eae1550000
    .reload /f ClassLibrary1.dll=0x1eae1550000

그럼 위와 같이 !name2ee 명령어로 출력되던 모든 닷넷 어셈블리에 대해 MetaData start address 값에서 64KB 단위의 정렬로 가정한 주소로 매핑시켜 줍니다. (이 가정은 마이크로소프트의 구현에 따라 달라질 수 있다는 점을 유의하세요.)

제법 큰 예제 프로젝트를 통해 모든 DLL들이 64KB 정렬되었다는 가정이 잘 통했으므로 이 정도 선에서 ^^ 마무리합니다.




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

[연관 글]






[최초 등록일: ]
[최종 수정일: 6/28/2021]

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

비밀번호

댓글 작성자
 




... 46  47  48  [49]  50  51  52  53  54  55  56  57  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
12409정성태11/12/202011165.NET Framework: 968. C# 9.0의 Function pointer를 이용한 함수 주소 구하는 방법파일 다운로드1
12408정성태11/9/202022594도서: 시작하세요! C# 9.0 프로그래밍 [8]
12407정성태11/9/202011450.NET Framework: 967. "clr!JIT_DbgIsJustMyCode" 호출이 뭘까요?
12406정성태11/8/202013005.NET Framework: 966. C# 9.0 - (15) 최상위 문(Top-level statements) [5]파일 다운로드1
12405정성태11/8/202010484.NET Framework: 965. C# 9.0 - (14) 부분 메서드에 대한 새로운 기능(New features for partial methods)파일 다운로드1
12404정성태11/7/202010999.NET Framework: 964. C# 9.0 - (13) 모듈 이니셜라이저(Module initializers)파일 다운로드1
12403정성태11/7/202011059.NET Framework: 963. C# 9.0 - (12) foreach 루프에 대한 GetEnumerator 확장 메서드 지원(Extension GetEnumerator)파일 다운로드1
12402정성태11/7/202011642.NET Framework: 962. C# 9.0 - (11) 공변 반환 형식(Covariant return types) [1]파일 다운로드1
12401정성태11/5/202010563VS.NET IDE: 153. 닷넷 응용 프로그램에서의 "My Code" 범위와 "Enable Just My Code"의 역할 [1]
12400정성태11/5/20207576오류 유형: 679. Visual Studio - "Source Not Found" 창에 "Decompile source code" 링크가 없는 경우
12399정성태11/5/202011228.NET Framework: 961. C# 9.0 - (10) 대상으로 형식화된 조건식(Target-typed conditional expressions)파일 다운로드1
12398정성태11/4/20209702오류 유형: 678. Windows Server 2008 R2 환경에서 Powershell을 psexec로 원격 실행할 때 hang이 발생하는 문제
12397정성태11/4/20209837.NET Framework: 960. C# - 조건 연산자(?:)를 사용하는 경우 달라지는 메서드 선택 사례파일 다운로드1
12396정성태11/3/20208210VS.NET IDE: 152. Visual Studio - "Tools" / "External Tools..."에 등록된 외부 명령어에 대한 단축키 설정 방법
12395정성태11/3/20209532오류 유형: 677. SSMS로 DB 접근 시 The server principal "..." is not able to access the database "..." under the current security context.
12394정성태11/3/20207946오류 유형: 676. cacls - The Recycle Bin on ... is corrupted. Do you want to empty the Recycle Bin for this drive?
12393정성태11/3/20208431오류 유형: 675. Visual Studio - 닷넷 응용 프로그램 디버깅 시 Disassembly 창에서 BP 설정할 때 "Error while processing breakpoint." 오류
12392정성태11/2/202012555.NET Framework: 959. C# 9.0 - (9) 레코드(Records) [4]파일 다운로드1
12390정성태11/1/202010764디버깅 기술: 173. windbg - System.Configuration.ConfigurationErrorsException 예외 분석 방법
12389정성태11/1/202010598.NET Framework: 958. C# 9.0 - (8) 정적 익명 함수 (static anonymous functions)파일 다운로드1
12388정성태10/29/202010034오류 유형: 674. 어느 순간부터 닷넷 응용 프로그램 실행 시 System.Configuration.ConfigurationErrorsException 예외가 발생한다면?
12387정성태10/28/202010776.NET Framework: 957. C# - static 필드의 정보가 GC Heap에 저장될까요? [3]파일 다운로드1
12386정성태10/28/202011019Linux: 34. 사용자 정보를 함께 출력하는 리눅스의 ps 명령어 사용 방법
12385정성태10/28/20208788오류 유형: 673. openssl - req: No value provided for Subject Attribute CN, skipped
12384정성태10/27/202010019오류 유형: 672. AllowPartiallyTrustedCallers 특성이 적용된 어셈블리의 struct 멤버 메서드를 재정의하면 System.Security.VerificationException 예외 발생
12383정성태10/27/202010964.NET Framework: 956. C# 9.0 - (7) 패턴 일치 개선 사항(Pattern matching enhancements) [3]파일 다운로드1
... 46  47  48  [49]  50  51  52  53  54  55  56  57  58  59  60  ...