Can I put a data breakpoint which triggers if any variable is assigned to a string containing a certain substring?
For example, I want to reverse-engineer how a URL containing &ctoken=
is constructed. It's done with plicated JavaScript where the goal is to obfuscate it.
If I could tell the JS VM to monitor all string variables and break when a certain substring appears on any variable, this would help me a lot.
Is this possible?
Can I put a data breakpoint which triggers if any variable is assigned to a string containing a certain substring?
For example, I want to reverse-engineer how a URL containing &ctoken=
is constructed. It's done with plicated JavaScript where the goal is to obfuscate it.
If I could tell the JS VM to monitor all string variables and break when a certain substring appears on any variable, this would help me a lot.
Is this possible?
Share Improve this question asked Nov 12, 2017 at 19:31 sashoalmsashoalm 79.9k136 gold badges478 silver badges822 bronze badges 5- I understand the technical requirement. Can you also write the business requirement. – Subir Kumar Sao Commented Nov 15, 2017 at 9:06
-
Depending on your IDE you can put conditional breakpoints which only cause the code to stop executing if a certain condition is met. In your case you could do something along the lines of:
myString.search("&ctoken=") !== -1
– Thomas Cook Commented Nov 15, 2017 at 9:16 -
As I understand, you want to create
global conditional breakpoint
, but unfortunately it's unpossible. Description of possible types of breakpoints (Chrome) – RQman Commented Nov 15, 2017 at 9:43 - @ThomasCook Yes, only with the caveat that it should work for any string variable, not just for a particular variable with a particular name. That is, the condition is "if at any point of execution, any variable at all holds a string that contains a certain substring, then break execution". – sashoalm Commented Nov 15, 2017 at 14:01
-
A partial solution can be override che String constructor method and set breakpoint on it. This cannot work for assignment
var str = "Hello"
but works withvar str = new String("Hello");
– Matteo Gaggiano Commented Nov 22, 2017 at 9:04
2 Answers
Reset to default 7 +50Before I start - as of my knowledge this is not possible.
What you'd need (even before creating the debugging feature) is the raw string types already boxed to String
the native built-in object and String
then already proxied.
Some more explanation:
only having
const s = "hi"
is not yet an instance of String
- the built-in native object, which is supplied by the ECMAScript implementation to your scope - but a raw type.
Such raw types are nothing more than pointers to a raw data memory reference. I even assume there are built in pools like in Java to optimize cases like
const s = "hi"
const x = new String("hi")
to be the same memory reference of the data object. but the later of course would be boxed by String
.
http://bespin.cz/~ondras/html/classv8_1_1String.html
On raw types we couldn't - even if we wanted to - add a subscriber.
for example then:
s.charAt(i)
will autobox s
to its wrapper String
.
to observe every raw type would mean that we'd have to box all raw strings to String
which wouldn't be a good thing for performance at all.
not only that but also the implementation of String
itself would have to allow us to add a subscriber and therefore be proxied already.
in JS such proxy would look like this (to make it more understandable what I mean by proxied):
var proxiedString = new Proxy(String, {
defineProperty(target, propKey, propDesc) {
console.log('defined a new string')
},
set(obj, prop, value) {
console.log('set a new value to a string')
}
});
proxiedString.x = 'newPropValue'
and that again I guess - wouldn't be good for performance.
- You can use condition breakpoints at browser devTools, by right click with a menu.
- If you can write a js somewhere in a page, you can do this:
.
if(window.location.pathname.indexOf("&ctoken=") > -1){
debugger;// browser will put breakpoint automaticaly here, if condition is trully.
console.dir(window.location);
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744705746a4589046.html
评论列表(0条)