Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

MethodSig to LocalSig conversion problem - resolve Local variables from byte array

Featured Replies

Posted

 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));
                                }
                            }

 

how about explore/educate from the de4dot code?

class MethodBodyReader.... 

here's how i do in jitdumper anonymoose when using dnlib

image.png.38097bd14616293f0319965003d5fc5d.png

  • Author

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]));
                            }


 

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.