0

I have really fun problem. It's kind of sandbox escaping.

Aim: get private methods of class

What I can:
1) Load standart assemblies by assemblies by long name
2) Use GetType and Type's methods

What I cannot:
1) Use using in code 2) Use System word in code. When I load assemblies I use such hack Load("Sys" + "tem....")

Looks like I could load private methods like

myType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance);

but I haven't BindingFlags imported in my code.

OK, I could create instance of BindingFlags and use GetField of it, but again it returns Object and I can't cast it to BindingFlags.

var value = bindingFlagsType.GetField("NonPublic").GetValue(null); //it's Object not BindingFlags

I tried Convert.ChangeType method, but Invoke return Object :)

How could I resolve this issue?

fryday
  • 387
  • 2
  • 14
  • I´m not sure what your problem is. The Disposable object which you are getting can be casted into IDisposable. Public Methods u get with GetMethod(...) Popreties with GetProperty(...) – Felix Arnold Nov 05 '19 at 15:17
  • 1
    Write `System.Reflection.BindingFlags...` instead? – thehennyy Nov 05 '19 at 15:20
  • @MaxMustermann, the problem is that I want to get private method of class, that for I need to use BindingFlags that is not imported – fryday Nov 05 '19 at 15:29
  • @thehennyy...looks like solution, but I have restriction №2. Add it to topic – fryday Nov 05 '19 at 15:30
  • Can you do casts? Then just cast the return of GetValue or cast the underlaying integer to BindingFlags like `(BindingFlags)123`. – thehennyy Nov 05 '19 at 16:12
  • @thehennyy, no, I can't. Casts are possible when import is done. I cant't reference BindingFlags in my code – fryday Nov 06 '19 at 07:55

0 Answers0