Reverse hex string – Big endian to little endian

Reverse hex string – Big endian to little endian

Working with a payload for a buffer overflow shellcode. For this particular task the payload needs to be reversed i.e “\x01\x02” should be “\x02\x01” etc. Didn’t find any online conversion tools so I wrote my one using C#.
It could of course be done manually but if you have a payload of 400 bytes…there are more fun things to do.

The code:

        string original = @"\xbc\xd1\xbb\x02\xb1";
        original = original.Replace("\\x", ",");
        IEnumerable<string> reversed = original.Split(',').Reverse();
        string final = string.Join(@"\x", reversed);
        System.Console.WriteLine($"\\x{final.Substring(0, final.Length - 2)}");

Example:

reverse hex string endian

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.