vfsfitvnm / frida-il2cpp-bridge

A Frida module to dump, trace or hijack any Il2Cpp application at runtime, without needing the global-metadata.dat file.
https://github.com/vfsfitvnm/frida-il2cpp-bridge/wiki
MIT License
1.03k stars 202 forks source link

how to print class's fields["] all key and value? #163

Closed zbx911 closed 2 years ago

zbx911 commented 2 years ago

// Runtime.dll class Network.HttpTracer : System.Object { static Network.HttpTracer Instance; // 0x0 System.Object _lock; // 0x10 System.Collections.Generic.Dictionary<System.String,Trace.ITraceSpan> _requestSpans; // 0x18

System.IDisposable Register(System.String key, Trace.ITraceSpan span); // 0x038bb7b4
System.Boolean TryGetPendingSpan(System.String key, Trace.ITraceSpan& result); // 0x038bb9b0
System.Void Deregister(System.String key); // 0x038bbacc
System.Void .ctor(); // 0x038bbbd4
static System.Void .cctor(); // 0x038bbc90

}

print ["_requestSpans"] all key and value?

vfsfitvnm commented 2 years ago
      for (const field of instance.class.fields) {
          if (field.isStatic) continue;

          console.log(`${field} ${instance.field(field.name).value}`);
      }
zbx911 commented 2 years ago

this Dictionary one: System.Collections.Generic.Dictionary<System.String,Trace.ITraceSpan> _requestSpans; // 0x18

zbx911 commented 2 years ago
      for (const field of instance.class.fields) {
          if (field.isStatic) continue;

          console.log(`${field} ${instance.field(field.name).value}`);
      }

const instance=c.methods["get_Instance"].invoke(); // @ts-ignore for (const field of instance.class.fields) { if (field.isStatic) continue; // @ts-ignore console.log(${field} ${instance.fields[field.name].value}); }

WimpyMistake commented 2 years ago

@zbx911 I may need something like yours (but I don't really understand), do you comes up with a solution?

vfsfitvnm commented 2 years ago

@WimpyMistake Did the snippet I posted work for you?

WimpyMistake commented 2 years ago

@WimpyMistake Did the snippet I posted work for you?

In a sense it does work. It works well with simple values like string, number and booelan. But with Il2Cpp.Object, it just shows FQCN as such Game.Namespace.Players.PlayerData. Similarly with List and Dictionary. I was looking for something that can print out an Il2Cpp.Object's value without having to loop the object again.

vfsfitvnm commented 2 years ago

@WimpyMistake Objects are printed via their ToString C# method: if it doesn't fit you use case, you'd better create a custom function with the desired behavior, e.g. that prints the items in a List. A universal method that correctly prints any object doesn't exist, so I cannot provide a function of this genre in frida-il2cpp-bridge.

WimpyMistake commented 2 years ago

@vfsfitvnm yeah sure. That's what I'm doing now. Thank you for your reply