cd - Dave's Blog

Search
My timeline on Mastodon

Data breakpoints in JavaScript

2016 Jun 17, 5:44

The other day I had to debug a JavaScript UWA that was failing when trying to use an undefined property. In a previous OS build this code would run and the property was defined. I wanted something similar to windbg/cdb's ba command that lets me set a breakpoint on read or writes to a memory location so I could see what was creating the object in the previous OS build and what that code was doing now in the current OS build. I couldn't find such a breakpoint mechanism in Visual Studio or F12 so I wrote a little script to approximate JavaScript data breakpoints.

The script creates a stub object with a getter and setter. It actually performs the get or set but also calls debugger; to break in the debugger. In order to handle my case of needing to break when window.object1.object2 was created or accessed, I further had it recursively set up such stub objects for the matching property names.

Its not perfect because it is an enumerable property and shows up in hasOwnProperty and likely other places. But for your average code that checks for the existence of a property via if (object.property) it works well.

PermalinkCommentsdebug debugging javascript

Cdb/Windbg Commands for Runtime Patching

2016 Feb 8, 1:47

You can use conditional breakpoints and debugging commands in windbg and cdb that together can amount to effectively patching a binary at runtime. This can be useful if you have symbols but you can't easily rebuild the binary. Or if the patch is small and the binary requires a great deal of time to rebuild.

Skipping code

If you want to skip a chunk of code you can set a breakpoint at the start address of the code to skip and set the breakpoint's command to change the instruction pointer register to point to the address at the end of the code to skip and go. Voila you're skipping over that code now. For example:

bp 0x6dd6879b "r @eip=0x6dd687c3 ; g"

Changing parameters

You may want to modify parameters or variables and this is simple of course. In the following example a conditional breakpoint ANDs out a bit from dwFlags. Now when we run its as if no one is passing in that flag.

bp wiwi!RelativeCrack "?? dwFlags &= 0xFDFFFFFF;g"

Slightly more difficult is to modify string values. If the new string length is the same size or smaller than the previous, you may be able to modify the string value in place. But if the string is longer or the string memory isn't writable, you'll need a new chunk of memory into which to write your new string. You can use .dvalloc to allocate some memory and ezu to write a string into the newly allocated memory. In the following example I then overwrite the register containing the parameter I want to modify:

.dvalloc 100
ezu 000002a9`d4eb0000 "mfcore.dll"
r rcx = 000002a9`d4eb0000

Calling functions

You can also use .call to actually make new calls to methods or functions. Read more about that on the Old New Thing: Stupid debugger tricks: Calling functions and methods. Again, all of this can be used in a breakpoint command to effectively patch a binary.

PermalinkCommentscdb debug technical windbg

Retweet of mathias

2016 Jan 27, 10:29
Take any Facebook/Instagram photo URL.👉 append `.txt` → ASCII art👉 append `.html` → colored ASCII artE.g. https://scontent-ams3-1.cdninstagram.com/t51.2885-15/e35/11906246_1700002456899911_1391970345_n.jpg.html …
PermalinkComments

JavaScript Types and WinRT Types

2016 Jan 21, 5:35PermalinkCommentschakra development javascript winrt

Retweet of eastwes

2015 Dec 8, 7:07
Forget the $2M, this is easily the most interesting part of the whole deal between Wu-Tang and Martin Shkreli. pic.twitter.com/5nSshXhjnJ
PermalinkComments

Retweet of Grathio

2015 Dec 4, 8:02
Good news! the patent on the Space Shuttle has expired. Go and build, royalty free! https://patents.google.com/patent/US3866863A/en … pic.twitter.com/1QliSmbnaM
PermalinkComments

Retweet of lamutsa

2015 Oct 20, 7:36
@USATODAY will you release this cover too? pic.twitter.com/d0VnrrhQzD
PermalinkComments

Retweet of radix42

2015 Aug 9, 8:55
She said "daddy I can't download this" and I looked and said "I'm so sorry we're living in a @doctorow novel" and had to explain :-(
PermalinkComments

Retweet of chockenberry

2015 Jul 27, 9:23
When we can’t even research the problem of gun violence, we’re screwed. http://www.washingtonpost.com/news/storyline/wp/2015/01/14/why-the-cdc-still-isnt-researching-gun-violence-despite-the-ban-being-lifted-two-years-ago/ …
PermalinkComments

Tweet from David_Risney

2015 Apr 12, 10:39
Does 'charset=utf8' work anywhere? Or do other browsers fallback to UTF-8 just giving the appearance? @ericlaw http://wp.me/p60i9o-r 
PermalinkComments

Tweet from David_Risney

2015 Apr 9, 11:21
CSS to render Markdown as unrendered Markdown https://gist.github.com/ImJasonH/c00cdd7aece6945fb8ea …
PermalinkComments

Tweet from David_Risney

2015 Apr 9, 4:34
Scripting in cdb/kd is not pleasant. Using PowerShell to script cdb/kd instead: http://www.leeholmes.com/blog/2009/01/21/scripting-windbg-with-powershell/ … . Any other better ways?
PermalinkComments

Retweet of bfosterjr

2015 Apr 6, 7:17
John Oliver with Snowden - http://www.theverge.com/2015/4/6/8352435/john-oliver-edward-snowden-last-week-tonight …
PermalinkComments

Retweet of anatudor

2015 Mar 22, 10:24
Collection can be found here - over 100 demos showing what can be done with just 1 range input http://codepen.io/collection/DgYaMj/8/ … pic.twitter.com/CAndEDATj9
PermalinkComments

Retweet of dveditz

2015 Mar 19, 6:56
The joys of bug bounty programs: someone reported that port 21 was open on http://ftp.mozilla.org 
PermalinkComments

nickholmes:HOW CAN THERE BE GLOBAL WARMING?!

2015 Feb 24, 3:35


nickholmes:

HOW CAN THERE BE GLOBAL WARMING?!

PermalinkComments

nickholmes:HOW CAN THERE BE GLOBAL WARMING?!

2015 Feb 24, 3:35


nickholmes:

HOW CAN THERE BE GLOBAL WARMING?!

PermalinkComments

Retweet of JustRogDigiTec

2015 Feb 13, 6:54
Still on the fence if this is good for the web. Love the progress!! “@shanselman: Flash isn't dead. It's undead. http://www.hanselman.com/blog/JavaScriptHasWonRunFlashWithMozillaShumwayAndDevelopSilverlightInJSWithFayde.aspx …
PermalinkComments

Retweet of DrPizza

2015 Feb 11, 12:38
btw, @fxshaw, if Microsoft wants to rebrand with my new logo, I'm sure we can come to a suitable arrangement. http://cdn.arstechnica.net/wp-content/uploads/2015/02/cool-microsoft1-300x150.png …
PermalinkComments

newsycombinator: The Hitchhiker's Guide to the Galaxy Game – 30th Anniversary Edition

2015 Jan 27, 8:31
Hacker News @newsycombinator :
The Hitchhiker's Guide to the Galaxy Game – 30th Anniversary Edition http://www.bbc.co.uk/programmes/articles/1g84m0sXpnNCv84GpN2PLZG/the-hitchhikers-guide-to-the-galaxy-game-30th-anniversary-edition …
PermalinkComments
Older Entries Creative Commons License Some rights reserved.