Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breakpoint on any string assignment if string contains a certain substring

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 complicated 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?

like image 749
sashoalm Avatar asked Nov 12 '17 19:11

sashoalm


People also ask

How do you do a conditional breakpoint?

To set a conditional breakpointOn the Home tab, in the Breakpoints group, choose Set/Clear Condition. In the Debugger Breakpoint Condition window, enter a condition. On the Home tab, in the Breakpoints group, choose List. In the Debugger Breakpoint List window, enter a condition in the Condition column.

How do I check if a string contains any value?

The Java String contains() method is used to check whether the specific set of characters are part of the given string or not. It returns a boolean value true if the specified characters are substring of a given string and returns false otherwise.

How do you see if a string contains a word?

You can use the PHP strpos() function to check whether a string contains a specific word or not. The strpos() function returns the position of the first occurrence of a substring in a string. If the substring is not found it returns false .


1 Answers

Before 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.

like image 194
Robin F. Avatar answered Oct 27 '22 00:10

Robin F.