Announcement

Collapse
No announcement yet.

Little-Endian to Big-Endian Convertor?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Little-Endian to Big-Endian Convertor?

    I'd like something (online script, program, etc) that will allow me to dump a list of little-endian memory addresses (say, 32-bit/4-byte) somewhere, and have a list of big-endian addresses come out the other side. I'd rather not have to compile whatever this is, if possible (I see there are a few C source code files floating around for such a thing). I don't mind using something like CScript, Windows batch script, VBScript, etc, but I'm too lazy to set up a dev environment on my machine at the moment, especially to be disappointed when whatever I've found won't compile for some reason or another.

    Anyone know of something that will work?
    I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

  • #2
    This is something I wrote in VB6. It is slow, and I think something in C/C++ would be more practical, but it does work.

    It exports as a string like this: DATA (32 bits) and then a newline and the next 32 bits. Alternatively, if you have the interest of making a code out of this, you may check the 'Address' box and specify an initial address. Then it will output like this (in hex);

    ADDRESS DATA
    ADDRESS + 4 DATA

    and so on. Also, you can specify a range with the Load Offset and Load End Offset. It counts in bytes and will round to the lowest multiple of 4 (VALUE - (VALUE % 4)). If the Load End Offset is 0, it will use the file length of the file specified.

    Hope this helps.
    Last edited by dnawrkshp; 02-21-2013, 09:41:25 PM. Reason: Update on 2nd page

    Comment


    • #3
      addresses.txt
      Code:
      20101002
      24101002
      28101002
      2C101002
      30101002
      341010
      3810
      3C
      endianswap.bat
      Code:
      @ECHO OFF
      SETLOCAL EnableDelayedExpansion
      FOR /F "tokens=*" %%G IN (addresses.txt) DO (
        SET ADDRESS=%%G
        ECHO !ADDRESS:~6,2!!ADDRESS:~4,2!!ADDRESS:~2,2!!ADDRESS:~0,2!
      )
      ENDLOCAL
      Sample Output
      Code:
      02101020
      02101024
      02101028
      0210102C
      02101030
      101034
      1038
      3C

      Comment


      • #4
        Originally posted by dnawrkshp View Post
        This is something I wrote in VB6. It is slow, and I think something in C/C++ would be more practical, but it does work.

        It exports as a string like this: DATA (32 bits) and then a newline and the next 32 bits. Alternatively, if you have the interest of making a code out of this, you may check the 'Address' box and specify an initial address. Then it will output like this (in hex);

        ADDRESS DATA
        ADDRESS + 4 DATA

        and so on. Also, you can specify a range with the Load Offset and Load End Offset. It counts in bytes and will round to the lowest multiple of 4 (VALUE - (VALUE % 4)). If the Load End Offset is 0, it will use the file length of the file specified.

        Hope this helps.
        Looks great, but I can't seem to make it work properly. I feed it a text file with lines like this:

        00430D80
        00F20C80
        04300D80
        04480C80
        04C40C80

        ...and give it an output file to save to, but when I hit Convert, it says "Address not valid!". Any idea?





        Originally posted by Pyriel View Post
        addresses.txt
        Code:
        20101002
        24101002
        28101002
        2C101002
        30101002
        341010
        3810
        3C
        endianswap.bat
        Code:
        @ECHO OFF
        SETLOCAL EnableDelayedExpansion
        FOR /F "tokens=*" %%G IN (addresses.txt) DO (
          SET ADDRESS=%%G
          ECHO !ADDRESS:~6,2!!ADDRESS:~4,2!!ADDRESS:~2,2!!ADDRESS:~0,2!
        )
        ENDLOCAL
        Sample Output
        Code:
        02101020
        02101024
        02101028
        0210102C
        02101030
        101034
        1038
        3C

        Perfect; does exactly what I need it to. Thanks I just added a >> addressesbig.txt to the end of the echo command to output to a new file.

        When grabbing chunks of offsets from a file in a hex editor (HxD, usually), I end up with a blob of one byte, space, another byte, space, etc. I usually like my data in this format, but in the case of offsets, it's obviously a hassle. So, I'm currently doing the following for each chunk of offsets:

        Switch to byte group size 4 (so 32 bits before each space)
        Copy, paste to something like sortmylist.com
        Switch back to byte group size 1 (for whatever I'm doing with the next chunk of data)
        In sortmylist.com, create columns delimited by space (yeah, I could do this in Excel, but it's quicker this way)
        Run the list through the batch script you provided above.

        Although, it would be optimal to simply toss the entire single-byte-separated blob at something, and have the finished product spit out the other end. Ideas?
        I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

        Comment


        • #5
          Code:
          20 10 10 02
          24 10 10 02
          28 10 10 02
          2C 10 10 02
          30 10 10 02
          34 10 10
          38 10
          3C
          Code:
          @ECHO OFF
          SETLOCAL EnableDelayedExpansion
          FOR /F "tokens=1-4" %%A IN (addresses.txt) DO (
            ECHO %%D%%C%%B%%A
          )
          ENDLOCAL
          Kind of depends on how many you have per line. You can do up to say 61 pairs per line, technically, but Windows batch scripting is kind of cruddy, so you can't really do an arbitrary number per line.

          Edit: Also, >> will append if the file exists. Obviously, that's necessary in the echo, unless you only want one address in the file, but you need to clear out that file somehow on each run. Unless you want a running list from all executions, that is. Generally, I'd just call the batch file and redirect its output on the command line.

          Edit 2: I should clarify. You can do 61 or fewer bytes per line, with the possibility of gobbledy-gook for the last set of tokens, as long as you have the %%D%%C%%B%%A, %%H%%G%%F%%E, etc. for them. You just can't have 5 bytes on a line, and then 3 bytes on the next, and have that pair up.
          Last edited by Pyriel; 02-21-2013, 10:14:46 AM.

          Comment


          • #6
            Or http://regexr.com?33ru0

            Alter to your liking.
            Please put all complaints in writing and submit them here.

            Above link not working? Try here.

            Comment


            • #7
              Originally posted by Pyriel View Post
              Code:
              20 10 10 02
              24 10 10 02
              28 10 10 02
              2C 10 10 02
              30 10 10 02
              34 10 10
              38 10
              3C
              Code:
              @ECHO OFF
              SETLOCAL EnableDelayedExpansion
              FOR /F "tokens=1-4" %%A IN (addresses.txt) DO (
                ECHO %%D%%C%%B%%A
              )
              ENDLOCAL
              Kind of depends on how many you have per line. You can do up to say 61 pairs per line, technically, but Windows batch scripting is kind of cruddy, so you can't really do an arbitrary number per line.

              Edit: Also, >> will append if the file exists. Obviously, that's necessary in the echo, unless you only want one address in the file, but you need to clear out that file somehow on each run. Unless you want a running list from all executions, that is. Generally, I'd just call the batch file and redirect its output on the command line.

              Edit 2: I should clarify. You can do 61 or fewer bytes per line, with the possibility of gobbledy-gook for the last set of tokens, as long as you have the %%D%%C%%B%%A, %%H%%G%%F%%E, etc. for them. You just can't have 5 bytes on a line, and then 3 bytes on the next, and have that pair up.

              Per "Edit": right, I understand. Generally, I'm just performing this one chunk at a time, and I don't mind Cut/Paste as a suitable method of both putting the finished product somewhere else and clearing the output file.

              Per "Edit 2": The problem is, it's all technically one line, since it's just a raw blob. Most of the time, it'll be more than 61 bytes.

              Still, once I've got a line-by-line, little-endian input ready, your initial suggestion works perfectly.



              Originally posted by rimsky82 View Post
              Or http://regexr.com?33ru0

              Alter to your liking.

              That saves even more time Now I just have to copy from a hex editor, paste into the above regex script, copy from the above regex script, paste into a sorting script such as sortmylist.com, break into new lines by space, and it's in its finished form. To make it slightly more efficient, it should be possible to incorporate the newline-by-space step in the regex script, right? I know next to nothing about regex...
              I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

              Comment


              • #8
                Paste me an example of what you're starting with, and then a sample of what you want the output to be.
                Please put all complaints in writing and submit them here.

                Above link not working? Try here.

                Comment


                • #9
                  OK. For example,

                  Input:

                  Code:
                  20 3A 0C 80 7C 2F 0C 80 FC 2F 0C 80 7C 30 0C 80 FC 30 0C 80 E4 31 0C 80 CC 32 0C 80 34 3C 0C 80 78 FE 0C 80 80 01 0D 80 00 F2 0C 80 BC F2 0C 80 54 0B 0C 80 54 0B 0C 80 3C 52 0C 80 64 21 0D 80 A0 3F 0C 80 1C 40 0C 80 A0 3E 0C 80 1C 3F 0C 80 E4 1D 0C 80 EC 1E 0C 80 8C 22 0C 80 94 23 0C 80 54 27 0C 80 5C 28 0C 80 54 0B 0C 80 54 0B 0C 80 54 0B 0C 80 54 0B 0C 80 54 0B 0C 80 54 0B 0C 80 C4 43 0C 80 E8 4E 0C 80 14 42 0D 80 00 43 0D 80 18 0C 0C 80 4C 18 0D 80 20 44 0D 80 EC 50 0C 80 E8 44 0D 80 80 47 0D 80 3C 7C 0C 80 24 1D 0C 80 A8 28 0D 80 94 27 0D 80 CC B1 0C 80 8C B2 0C 80 FC 2B 0C 80 A8 2C 0C 80 54 2D 0C 80 2C 53 0C 80 C0 81 0C 80 88 85 0C 80 30 3F 0D 80 38 40 0D 80 64 3E 0D 80 88 3B 0D 80 18 3C 0D 80 A8 3C 0D 80 8C 36 0D 80 8C 36 0D 80 48 35 0D 80 8C 36 0D 80 60 AF 0C 80 04 30 0D 80 24 31 0D 80 1C B0 0C 80 54 0B 0C 80 28 37 0D 80 54 0B 0C 80 40 38 0D 80 B8 B0 0C 80 60 2C 0D 80 94 2E 0D 80 78 43 0D 80 54 0B 0C 80 58 39 0D 80 54 0B 0C 80 70 3A 0D 80 54 B3 0C 80 F8 B4 0C 80 18 B7 0C 80 C0 B5 0C 80 60 B6 0C 80 50 B4 0C 80 94 1B 0D 80 68 1C 0D 80 20 1F 0D 80 DC 1F 0D 80 98 20 0D 80 8C 29 0D 80 70 2A 0D 80 60 2B 0D 80 B8 1D 0D 80 E8 0B 0C 80 A4 40 0C 80 94 51 0C 80 14 D2 0C 80 E8 D2 0C 80 6C D1 0C 80 54 D5 0C 80 F0 D5 0C 80 70 D7 0C 80 B0 D6 0C 80 BC 54 0C 80 E4 FC 0C 80 54 16 0D 80 5C 19 0D 80 80 1A 0D 80 3C 1D 0D 80 F0 D3 0C 80 AC 45 0C 80 14 54 0C 80 60 41 0D 80 54 A2 0C 80 3C 2F 0D 80 7C A7 0C 80 F4 BB 0C 80 40 BD 0C 80 94 BE 0C 80 DC BF 0C 80 58 C5 0C 80 70 C6 0C 80 8C C7 0C 80 A8 C8 0C 80 24 AA 0C 80 EC C9 0C 80 E0 0D 0C 80 5C 0E 0C 80 74 16 0C 80 14 17 0C 80 B8 17 0C 80 5C BB 0C 80 A4 BC 0C 80 FC BD 0C 80 40 BF 0C 80 98 C0 0C 80 34 C1 0C 80 D4 C1 0C 80 84 C2 0C 80 58 C3 0C 80 04 C4 0C 80 C0 B7 0C 80 58 B8 0C 80 F4 B8 0C 80 8C B9 0C 80 28 BA 0C 80 C0 BA 0C 80 D8 C4 0C 80 EC C5 0C 80 0C C7 0C 80 24 C8 0C 80 44 C9 0C 80 DC 0E 0C 80 58 0F 0C 80 D8 0F 0C 80 7C 10 0C 80 14 12 0C 80 B0 13 0C 80 94 EB 0C 80 40 57 0C 80 98 58 0C 80 E8 5C 0C 80 5C A9 0C 80 EC AA 0C 80 FC AD 0C 80 98 AC 0C 80 24 69 0C 80 D8 6F 0C 80 E8 7C 0C 80 14 85 0C 80 48 67 0C 80 64 6D 0C 80 E8 5C 0C 80 80 5E 0C 80 F4 5F 0C 80 CC 63 0C 80 78 9F 0C 80 20 9A 0C 80 5C 95 0C 80 D8 91 0C 80 4C 81 0C 80 58 A1 0C 80 90 A4 0C 80 94 A3 0C 80 80 5E 0C 80 F4 5F 0C 80 CC 63 0C 80 74 A0 0C 80 54 0B 0C 80 68 56 0C 80 54 73 0C 80 D4 A5 0C 80 F0 75 0C 80 98 8B 0C 80 64 8F 0C 80 80 9D 0C 80 88 9B 0C 80 1C FC 0C 80 44 EE 0C 80 28 F0 0C 80 40 F1 0C 80 18 F7 0C 80 74 F8 0C 80 B8 F9 0C 80 F0 FA 0C 80 84 FB 0C 80 58 18 0C 80 F4 1B 0C 80 C4 D0 0C 80 B4 1A 0C 80 64 32 0D 80 30 33 0D 80 7C 9E 0C 80 84 9C 0C 80 B0 42 0C 80 50 43 0C 80 04 48 0C 80 8C 72 0C 80 2C 5A 0C 80 4C 68 0C 80 80 90 0C 80 04 E9 0C 80 68 CA 0C 80 10 CB 0C 80 3C CC 0C 80 C8 CC 0C 80 BC CB 0C 80 34 D8 0C 80 24 DA 0C 80 28 DC 0C 80 8C DE 0C 80 14 E2 0C 80 F4 E6 0C 80 1C D9 0C 80 0C DB 0C 80 40 DD 0C 80 54 E0 0C 80 80 E4 0C 80 EC 49 0C 80 3C 49 0C 80 D0 46 0C 80 40 4A 0C 80 94 4A 0C 80 6C 50 0C 80 E8 4C 0C 80 40 3D 0D 80 54 CD 0C 80 94 CE 0C 80 E8 CF 0C 80 64 55 0C 80 E8 4D 0C 80 E8 4A 0C 80 CC 3D 0D 80 0C 56 0C 80


                  Output:

                  Code:
                  800C3A20
                  800C2F7C
                  800C2FFC
                  800C307C
                  800C30FC
                  800C31E4
                  800C32CC
                  800C3C34
                  800CFE78
                  800D0180
                  800CF200
                  800CF2BC
                  800C0B54
                  800C0B54
                  800C523C
                  800D2164
                  800C3FA0
                  800C401C
                  800C3EA0
                  800C3F1C
                  800C1DE4
                  800C1EEC
                  800C228C
                  800C2394
                  800C2754
                  800C285C
                  800C0B54
                  800C0B54
                  800C0B54
                  800C0B54
                  800C0B54
                  800C0B54
                  800C43C4
                  800C4EE8
                  800D4214
                  800D4300
                  800C0C18
                  800D184C
                  800D4420
                  800C50EC
                  800D44E8
                  800D4780
                  800C7C3C
                  800C1D24
                  800D28A8
                  800D2794
                  800CB1CC
                  800CB28C
                  800C2BFC
                  800C2CA8
                  800C2D54
                  800C532C
                  800C81C0
                  800C8588
                  800D3F30
                  800D4038
                  800D3E64
                  800D3B88
                  800D3C18
                  800D3CA8
                  800D368C
                  800D368C
                  800D3548
                  800D368C
                  800CAF60
                  800D3004
                  800D3124
                  800CB01C
                  800C0B54
                  800D3728
                  800C0B54
                  800D3840
                  800CB0B8
                  800D2C60
                  800D2E94
                  800D4378
                  800C0B54
                  800D3958
                  800C0B54
                  800D3A70
                  800CB354
                  800CB4F8
                  800CB718
                  800CB5C0
                  800CB660
                  800CB450
                  800D1B94
                  800D1C68
                  800D1F20
                  800D1FDC
                  800D2098
                  800D298C
                  800D2A70
                  800D2B60
                  800D1DB8
                  800C0BE8
                  800C40A4
                  800C5194
                  800CD214
                  800CD2E8
                  800CD16C
                  800CD554
                  800CD5F0
                  800CD770
                  800CD6B0
                  800C54BC
                  800CFCE4
                  800D1654
                  800D195C
                  800D1A80
                  800D1D3C
                  800CD3F0
                  800C45AC
                  800C5414
                  800D4160
                  800CA254
                  800D2F3C
                  800CA77C
                  800CBBF4
                  800CBD40
                  800CBE94
                  800CBFDC
                  800CC558
                  800CC670
                  800CC78C
                  800CC8A8
                  800CAA24
                  800CC9EC
                  800C0DE0
                  800C0E5C
                  800C1674
                  800C1714
                  800C17B8
                  800CBB5C
                  800CBCA4
                  800CBDFC
                  800CBF40
                  800CC098
                  800CC134
                  800CC1D4
                  800CC284
                  800CC358
                  800CC404
                  800CB7C0
                  800CB858
                  800CB8F4
                  800CB98C
                  800CBA28
                  800CBAC0
                  800CC4D8
                  800CC5EC
                  800CC70C
                  800CC824
                  800CC944
                  800C0EDC
                  800C0F58
                  800C0FD8
                  800C107C
                  800C1214
                  800C13B0
                  800CEB94
                  800C5740
                  800C5898
                  800C5CE8
                  800CA95C
                  800CAAEC
                  800CADFC
                  800CAC98
                  800C6924
                  800C6FD8
                  800C7CE8
                  800C8514
                  800C6748
                  800C6D64
                  800C5CE8
                  800C5E80
                  800C5FF4
                  800C63CC
                  800C9F78
                  800C9A20
                  800C955C
                  800C91D8
                  800C814C
                  800CA158
                  800CA490
                  800CA394
                  800C5E80
                  800C5FF4
                  800C63CC
                  800CA074
                  800C0B54
                  800C5668
                  800C7354
                  800CA5D4
                  800C75F0
                  800C8B98
                  800C8F64
                  800C9D80
                  800C9B88
                  800CFC1C
                  800CEE44
                  800CF028
                  800CF140
                  800CF718
                  800CF874
                  800CF9B8
                  800CFAF0
                  800CFB84
                  800C1858
                  800C1BF4
                  800CD0C4
                  800C1AB4
                  800D3264
                  800D3330
                  800C9E7C
                  800C9C84
                  800C42B0
                  800C4350
                  800C4804
                  800C728C
                  800C5A2C
                  800C684C
                  800C9080
                  800CE904
                  800CCA68
                  800CCB10
                  800CCC3C
                  800CCCC8
                  800CCBBC
                  800CD834
                  800CDA24
                  800CDC28
                  800CDE8C
                  800CE214
                  800CE6F4
                  800CD91C
                  800CDB0C
                  800CDD40
                  800CE054
                  800CE480
                  800C49EC
                  800C493C
                  800C46D0
                  800C4A40
                  800C4A94
                  800C506C
                  800C4CE8
                  800D3D40
                  800CCD54
                  800CCE94
                  800CCFE8
                  800C5564
                  800C4DE8
                  800C4AE8
                  800D3DCC
                  800C560C
                  I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

                  Comment


                  • #10
                    http://regexr.com?33s0k
                    Please put all complaints in writing and submit them here.

                    Above link not working? Try here.

                    Comment


                    • #11
                      Didn't think of using one of those regex tester pages. If you want to be really lazy, stick a "\s*" at the tail end of the expression (instead of the space that's there) so it'll always pick up the last one. There are better ways, but adding complexity to a regex for an ad hoc job is kind of silly.

                      I might recommend looking up another regex tester. I had the expression highlighted, and clicked in the syntax/sets listing box by accident, and suddenly the flash plugin pegged my CPU and tried to crash my browser. I know of a couple of simpler ones, but I don't think any of them will give a very well-formatted listing of the captured text. The output always has labels and such embedded in it.
                      Last edited by Pyriel; 02-21-2013, 01:36:52 PM.

                      Comment


                      • #12
                        Originally posted by Pyriel View Post
                        Didn't think of using one of those regex tester pages. If you want to be really lazy, stick a "\s*" at the tail end of the expression (instead of the space that's there) so it'll always pick up the last one. There are better ways, but adding complexity to a regex for an ad hoc job is kind of silly.

                        I might recommend looking up another regex tester. I had the expression highlighted, and clicked in the syntax/sets listing box by accident, and suddenly the flash plugin pegged my CPU and tried to crash my browser. I know of a couple of simpler ones, but I don't think any of them will give a very well-formatted listing of the captured text. The output always has labels and such embedded in it.
                        Nice; that takes care of the trailing offset. There's even a desktop version of the RegExr app (though it's just Adobe Air), so I don't have to bother with working in the browser.
                        I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

                        Comment


                        • #13
                          @LB, it was intended to load binary files and convert the bytes within it to the string representation of each 32 bits. I hadn't realized that you wanted to convert a string to begin with.

                          Though it looks like you have your solution, you can find where you want to begin reading the data and where you want to end and input that as the Load Offsets (If hex, add 0x). Then input the binary file and that should work.

                          ...and give it an output file to save to, but when I hit Convert, it says "Address not valid!". Any idea?
                          Oops, I hadn't fully tested it I guess... Fixed.
                          Attached Files

                          Comment


                          • #14
                            Cool; that will be a useful alternative. Thanks.
                            I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

                            Comment

                            Working...
                            X