[DebuggingToolbox]Portable Executable 헤더 얻기

"이 문서는 https://blogs.msdn.com/debuggingtoolbox/default.aspx blog 의 번역이며 원래의 자료가 통보 없이 변경될 수 있습니다. 이 자료는 법률적 보증이 없으며 의견을 주시기 위해 원래의 blog 를 방문하실 수 있습니다. ( https://blogs.msdn.com/debuggingtoolbox/archive/2007/05/03/windbg-script-get-portable-executable-headers.aspx )

 

[Windbg Script] Portable Executable 헤더 얻기

There are several tools you can use to read the image headers, like Dumpbin.exe and Link.exe, for instance. You can, however, also use Windbg for doing that! In other words, during your debugging session you can see the header from an image file without executing any other tool except this script.

Dumpbin.exe와 Link.exe 와 같이 이미지 헤더를 읽을 수 있는 많은 툴이 있지만 Windbg 또한 읽을 수 있습니다. 다시 말하면 디버깅 도중 다른 툴의 도움이 필요 없이 이미지 헤더를 읽을 수 있습니다.

 

This is a very simple script that lists all loaded modules and gives you two options:

- Visualize a summarized view of the header for a specific image.

- Visualize a detailed view of the header for a specific image.

Actually, there is one more option: run the script and provide the module as an argument. J

이번에 알려드릴 스크립트는 매우 간단한 것으로 로드 되어 있는 모든 모듈을 리스트 하는 것으로 두 가지 옵션이 있습니다.

- 특정 이미지의 간략한 헤더 정보만 보이기

- 특정 이미지의 자세한 헤더 정보 보이기

인자로 모듈을 전달할 수 있는 옵션이 하나 더 있습니다.

 

디버깅 스립트를 실행하는 중에 인자를 사용하는 방법을 이 스크립트를 통해서 배울 수 있었습니다. 매우 좋은 기능으로 다음 Windbg 버전에서는 이것을 추가 하였으면 합니다. 여러분 또한 스크립트를 실행하고 인자를 변경하면서 배우실 수 있습니다.

아래와 같이 스크립트를 실행할 수 있습니다.

$$>a<scriptname.txt arg1 arg2 arg3 … <- >a<에 주의

 

별칭을 사용하여 스크립트 소스코드에서 인자를 받을 수 있습니다.

${$arg1} <- 별칭, 가상 레지스터가 아닙니다.

$art1 에서 시작해서 $arg<n> 로 이어 집니다.

저의 스크립트에서 인자를 사용할 수 있는지 확인해 보았고 이 아이디어를 사용하기를 원하실 수도 있습니다.

문법상 에러를 발견할 경우 한번 더 실행하면 실행될 것 입니다. 이러한 문제는 별칭과 관련된 것으로 이미 이전에 말씀 드린바 있습니다.

아래 스크린 샷이 있습니다.

스크립트를 실행할 때 모듈 이름을 사용해 보도록 하겠습니다.

Source code for GET_HEADERS.TXT:

$$

$$ =============================================================================

$$ Get headers from images.

$$

$$ Compatibility: Win32.

$$

$$ Usage: $$>< to run the program without arguments.

$$ $$>a<scriptfile dllname to run the program using arguments.

$$

$$ Example: $$>a<myscripts\get_headers.txt kernel32

$$

$$ If necessary change the filename below to include your path and filename.

$$ Default file name and path should be changed below if necessary.

$$

$$ Roberto Alexis Farah

$$ Blog: https://blogs.msdn.com/debuggingtoolbox/

$$

$$ All my scripts are provided "AS IS" with no warranties, and confer no rights.

$$ =============================================================================

$$

.block

{

as ${/v:ScriptName} MYSCRIPTS\\GET_HEADERS.TXT

}

r @$t0 = 0

.if(${/d:$arg1})

{

.printf /D "\nYou selected the module: <b>${$arg1}</b>\n\n"

!dh ${$arg1} -a

}

.else

{

.printf /D "\n\n<b>Select option below for loaded modules:</b>\n\n"

.foreach(obj {lm1mo})

{

.block

{

.printf "${obj}\t <-- "

.printf /D "<link cmd=\".echo ${obj};!lmi ${obj};ad ${/v:ScriptName};$$><${ScriptName}\">Summarized</link> or "

.printf /D "<link cmd=\".echo ${obj};!dh ${obj} -a;ad ${/v:ScriptName} *;$$><${ScriptName}\">Detailed</link>\n"

}

}

.printf /D "<b>\nAfter selection scroll up the screen to see the information.</b>\n"

}