[Debugging Toolbox]Playing with Notepad

https://blogs.msdn.com/debuggingtoolbox/archive/2007/04/11/windbg-script-playing-with-notepad.aspx

글 : Roberto Alexis Farah
번역 : 이태화
역자 : 해당 script 를 실행시켜 봤는데 잘 실행되지 않네요 ^^;

이것은 오직 저의 재미를 위해서 만든 script 입니다. 이것은 매우 simple 하고 약간의 제약사항이 있지만 재미 있습니다.

이것이 어떤 일을 할까요? Notepad.exe 을 열고 text 파일을 열어서 copy and paste 를 하거나 write 를 하여 문자들을 넣습니다. script 를 열고 StringToFind 와 StringToReplace 를
원하는 것으로 변경합니다. ' 이나 "" 를 사용하지 말고 string 만을 사용해야 합니다.

 

Example:
Test           Correct!
“Test”         Wrong!

 

파일을 저장하고 WinDbg 를 Notepad 예 attach 시킵니다. script 를 실행한 후 g 를 누르면 실행 됩니다.

 

Windows XP SP2 에서 실행 시켜야 합니다.

 

<코드설명>
as 별명 설정

r pseudo register 에 값 설정

.foreach
.foreach [Options] ( Variable  { InCommands } ) { OutCommands }
.foreach 명령으로 InCommand 의 결과를 variable 에 넣고 이를 outcommand 에서 사용

s momory 에서 특정 패턴 찾기
1 찾은 패턴의 address 를 나타내는 것으로 .foreach 에서 사용
u Unicode string

low 하위 16 bits

Source code for NOTEPAD.TXT:

$$
$$ =============================================================================
$$ Replace a string for another string like the Replace feature from Notepad.
$$
$$ Note: It always replace the last char with space.
$$       It does a case comparison.
$$       It's a "just for fun" script not something you should use as a tool.
$$
$$ Compatibility: Win32.
$$
$$ Usage: First replace the StringsToFind and StringsToReplace with your strings.
$$        Don't use "" or '' just the string.
$$        For a better effect they should have the same size.
$$        Use $$>< to run the program.
$$
$$
$$ Requirements: Public symbols.
$$
$$ Roberto Alexis Farah
$$ Blog: https://blogs.msdn.com/debuggingtoolbox/
$$
$$ All my scripts are provided "AS IS" with no warranties, and confer no rights.
$$ =============================================================================
$$
ad /q *
.block
{
    as ToFind StringsToFind
}
.block
{
    as ToReplace StringsToReplace
}
.printf /D "<b>\n\nFinding and replacing words...</b>\n"
r @$t1 = 0
.foreach(obj {s -[1]u 0x00100000 0x0FFFFFFF ${ToFind}})
{
    r @$t1 = 0x1
    .block
    {
        eu ${obj} "${ToReplace}"
    }
    r @$t0 = ${obj}
    .while( (low(poi(@$t0)) != 0x3b))
    {
        r @$t0 = @$t0 + 0x1
    }
    eb @$t0 0x20
}
.if(@$t1)
{
    .printf /D "<b>\nDone! The words were replaced!\n</b>"
}
.else
{
    .printf /D "<b>\nNo strings that match were found!\n</b>"
}
ad /q *