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.

(C# , DNLIB) How to replace a byte[] with dnlib?

Featured Replies

Posted

Can you ülease help me with some code snippet or example on how to change a byte[] with dnlib or other libs ? 

thanks

Yes, we saw your previous topic, thank you. Honestly, I can't understand what you're trying to do. Perhaps you could explain it in more details ?

 

 

maybe he wants to patch an existing array of bytes in some assembly ? using a hex editor ?

If you are meaning to modifying the byte array in some assemblies just use FileStream

https://stackoverflow.com/a/3217953/8902883

Edited by DorAEm0nKiNG-TH

  • Author

thank you so far ,) 

i want to know how to change the value of a byte[] with dnlib ...

in assembly there is i.e this code :

byte[] data = { 1, 2, 4, 8, 16, 32 };

and i want to know how i can replace the array with my own values with dnlib or similar

i hope i could explain it better now 

Example code just to get you started:

            using (var module = ModuleDefMD.Load(args[0]))
            {
                foreach (var type in module.GetTypes())
                {
                    foreach (FieldDef field in type.Fields)
                    {
                        // this will change all byte[] field values to my own. Make sure to fix the `if`!!!
                        if (field.HasFieldRVA && field.InitialValue != null)
                        {
                            byte[] fake = new byte[] { 0x6B, 0x61, 0x6F };

                            // it's hard to change the size of initialized byte[]. If you really need to have array of different length 
                            // it will be much easier to create a new byte[] and use that instead
                            Array.Resize(ref fake, (int)field.GetFieldSize());  // this line forces new byte[] to be the same length as old one..
                            field.InitialValue = fake;
                        }
                    }
                }
                module.Write(args[1]);

 

You can see more details about how byte[] are implemented internally in my blog: https://lifeinhex.com/how-to-inject-byte-array-using-dnlib/

 

  • Author

great thank you for the info!

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.