Math.atan2(0xbadc0de, "Msg");

WinDbg로 javascript를 디버깅 할 때 보통 Math.atan2로 2번째 인자에 출력할 로그를 전달한 코드를 각 javascript의 라인에 추가하는 방법을 쓴다.


이렇게 추가 한 로그 메시지는 WinDbg에서 아래와 같은 명령으로 로그를 출력한다.

- bp jscript9!Js::Math::Atan2 ".printf \"%mu\", poi(poi(esp+14)+0c);.echo;g"


여기서 쓰이는 poi(poi(esp+14)+0c)에 대해 알아본다.


poi : pointer


Math::Atan2는 다음과 같이 5개의 인자를 전달받는다.

- char *__cdecl Js::Math::Atan2(int a1, int a2, int a3, signed int a4, signed int a5)


poi(esp+14)의 메모리 내용은 다음과 같다.

03a07130 69753198 jscript9!Js::ArenaLiteralString::`vftable'
03a07134 039c8080
03a07138 00000022
03a0713c 039b45d0
03a07140 ffffffff
03a07144 00000000
03a07148 69753198 jscript9!Js::ArenaLiteralString::`vftable'
03a0714c 039c8080
03a07150 00000004
03a07154 039b4616
03a07158 ffffffff
03a0715c 00000000
03a07160 69753198 jscript9!Js::ArenaLiteralString::`vftable'
03a07164 039c8080
03a07168 00000021
03a0716c 039b4620
03a07170 ffffffff

03a07174 00000000


esp+14(위에서 signed int a5)에 뭔가 구조체가 들어가는 것으로 보인다.


poi(poi(esp+14)+0c)의 메모리 내용은 아래와 같다.

039b45d0 43 00 61 00 6c 00 6c 00 20 00 64 00 6f 00 63 00  C.a.l.l. .d.o.c.
039b45e0 75 00 6d 00 65 00 6e 00 74 00 2e 00 63 00 72 00  u.m.e.n.t...c.r.
039b45f0 65 00 61 00 74 00 65 00 45 00 6c 00 65 00 6d 00  e.a.t.e.E.l.e.m.
039b4600 65 00 6e 00 74 00 20 00 2d 00 20 00 73 00 70 00  e.n.t. .-. .s.p.
039b4610 61 00 6e 00 00 00 73 00 70 00 61 00 6e 00 00 00  a.n...s.p.a.n...
039b4620 43 00 61 00 6c 00 6c 00 20 00 64 00 6f 00 63 00  C.a.l.l. .d.o.c.
039b4630 75 00 6d 00 65 00 6e 00 74 00 2e 00 63 00 72 00  u.m.e.n.t...c.r.
039b4640 65 00 61 00 74 00 65 00 45 00 6c 00 65 00 6d 00  e.a.t.e.E.l.e.m.

039b4650 65 00 6e 00 74 00 20 00 2d 00 20 00 64 00 69 00  e.n.t. .-. .d.i.


이를 보아 jscript에서는 문자열 상수들을 구조화하여 저장하는데, 위와 같이 0x18 단위로 저장됨을 추측할 수 있다.


structure maybe_java_string{

ArenaLiteralString_vtable

address_of_JavascriptFunction_vftable

unicode_string_length

unicode_string

-1

0

}


결국, poi(poi(esp+14)+0c)는 메모리에 저장된 구조화된 데이터에서 문자열 상수를 접근하는 코드로 확인되었다.



Posted by bong9
,