You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Memory addresses for class fields cycle when a super method is called, and its return value is stored.
As seen in the code snippet below, despite both Print methods being passed the exact same field, subVar, the first call returns the super class's field superVar.
class Super {
superVar{_superVar}
construct new(superVar) {
_superVar="Super"
}
//This method doesn't even need to return anything
method() { }
}
class Sub is Super {
subVar{_subVar}
construct new() {
super()
_subVar="Sub"
System.print("Sub from Constructor: "+_subVar) //Prints "Sub"
System.print("Super from Constructor: "+superVar) //Prints "Super"
System.print("")
}
method() {
//Storing the output causes this behavior
//Reading _subVar before the method call still gives expected behavior
var someName=super.method()
System.print("Sub from Method: "+_subVar) //Prints "Super" !
System.print("Sub from Method: "+_subVar) //Prints "Sub" !?!
}
}
var sub=Sub.new()
sub.method()
This still happens no matter what names are given to the classes, their fields, or their methods and constructors, and even how _subVar is read.
Simply by storing the return value from a super call, the fields are messed up, until it _subVar is read again.
On a side note: using the syntax subVar instead of _subVar still allows for the proper behavior, and doing any operation on _subVar causes the address to be set back to normal.
method() {
var someName=super.method()
_subVar is String
System.print("Sub from Method: "+_subVar) //Prints "Sub"
System.print("Sub from Method: "+_subVar) //Prints "Sub"
}
This allows for reading of normally unreadable memory addresses, simply by adding more fields to the sub-class.
class Super {
construct new() {
//Private fields, not readable
_super1="A"
_super2="B"
_super3="C"
}
method() {}
}
class Sub is Super {
construct new() {
super()
}
hackerman() {
_hack1=null
var ret1=super.method()
System.print(_hack1) //Prints "B", not "null"
_hack2=null
var ret2=super.method()
System.print(_hack2) //Prints "C", not "null"
}
}
var sub=Sub.new()
sub.hackerman()
The text was updated successfully, but these errors were encountered:
Memory addresses for class fields cycle when a super method is called, and its return value is stored.
As seen in the code snippet below, despite both Print methods being passed the exact same field, subVar, the first call returns the super class's field superVar.
This still happens no matter what names are given to the classes, their fields, or their methods and constructors, and even how _subVar is read.
Simply by storing the return value from a super call, the fields are messed up, until it _subVar is read again.
On a side note: using the syntax subVar instead of _subVar still allows for the proper behavior, and doing any operation on _subVar causes the address to be set back to normal.
This allows for reading of normally unreadable memory addresses, simply by adding more fields to the sub-class.
The text was updated successfully, but these errors were encountered: