CodeExplorer Posted September 11, 2024 Posted September 11, 2024 Hi. I have problems with restoring local variable from byte array, when I get variables Signature and I try to convert them to LocalSig I get and exception because can't convert MethodSig to LocalSig. Any help would be great. { using (BinaryReader binaryReader4 = new BinaryReader(new MemoryStream(this.DataStructure.LEH))) { binaryReader4.BaseStream.Position = (long)hInt; MethodBodySize1 = binaryReader4.ReadInt32() >> 8; // 104 short LocalsSize2 = binaryReader4.ReadInt16(); short EHSize2 = binaryReader4.ReadInt16(); binaryReader4.ReadInt16(); methodInfo2.MethodData = binaryReader.ReadBytes(MethodBodySize1); var SignatureRead = SignatureReader.ReadSig(this.module, binaryReader4.ReadBytes((int)LocalsSize2)); IList<TypeSig> locals; if (SignatureRead is LocalSig) { locals = ((LocalSig)(SignatureRead)).GetLocals(); for (int k = 0; k < locals.Count; k++) methodInfo2.Method_Locals.Add(new Local(locals[k])); } else if (SignatureRead is MethodSig) { MethodSig SignatureRead_MS = SignatureRead as MethodSig; //locals = ((MethodSig)(SignatureRead)).GetLocals(); } methodInfo2.MethodEH = ((EHSize2 == 0) ? null : binaryReader4.ReadBytes((int)EHSize2)); } } 1
jackyjask Posted September 11, 2024 Posted September 11, 2024 how about explore/educate from the de4dot code? class MethodBodyReader.... 1
Mr-Toms Posted September 11, 2024 Posted September 11, 2024 here's how i do in jitdumper anonymoose when using dnlib 1
CodeExplorer Posted September 12, 2024 Author Posted September 12, 2024 Actually there is no error with the above code, it is just that bytes signatures was wrong so it will throw exception; throwing error is naturally in such case I think! Here is the final code used: IList<TypeSig> locals = ((LocalSig)SignatureReader.ReadSig(this.module, binaryReader4.ReadBytes((int)LocalsSize2))).GetLocals(); for (int l = 0; l < locals.Count; l++) { methodInfo2.Method_Locals.Add(new Local(locals[l])); } 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now