i need help finding a command line hex editor

Discussion in 'Computer Programming, Emulation, and Game Modding' started by MarioMasta64, Aug 7, 2017.

  1. MarioMasta64
    OP

    MarioMasta64 hi. i make batch stuff and portable shiz

    Member
    1,916
    411
    Dec 21, 2016
    United States
    i need a hex editor that i can use via command prompt something such as write.exe -bytes 0A4E3726594E -output=file.bin -offset 0E7
    anybody know if something like this exist and/or can be created? (ive read some documentation it can be made in c# c++ and vb.net but im not exactly able to do those languages..)
     
  2. MarioMasta64
    OP

    MarioMasta64 hi. i make batch stuff and portable shiz

    Member
    1,916
    411
    Dec 21, 2016
    United States
    basically i need either something that exists or someone good in vb.net c# or c++. if it matters any. i can pay for the program to be custom made as it would obviously take time out of a busy devs day.
     
  3. MarioMasta64
    OP

    MarioMasta64 hi. i make batch stuff and portable shiz

    Member
    1,916
    411
    Dec 21, 2016
    United States
    i might have someone making it in python. so far its going well. just fixing some kinks with him. anyone is still willing to write one.
     
  4. Larsenv

    Larsenv RiiConnect24 Developer

    Member
    545
    455
    Sep 28, 2013
    United States
    Texas
    That would be me...
     
    MarioMasta64 likes this.
  5. VinLark

    VinLark This machine kills bourgeois sentimentality.

    Member
    4,125
    4,910
    Jun 11, 2016
    Trinidad and Tobago
    Psychosystem Denomination
    vim maybe? Like, you can edit it in terminal. Not sure I know something that would do what you are asking
     
    MarioMasta64 likes this.
  6. MarioMasta64
    OP

    MarioMasta64 hi. i make batch stuff and portable shiz

    Member
    1,916
    411
    Dec 21, 2016
    United States
    what we have now:
    readbytes.py <start offset> <end offset> <input> <output> (saves a text file in hex instead of raw data)
    writebytes.py <bytes> <offset> <output>
    it works but requires python to be installed. made by @Larsenv
     
  7. Larsenv

    Larsenv RiiConnect24 Developer

    Member
    545
    455
    Sep 28, 2013
    United States
    Texas
    Yup we got it to work :)
     
    MarioMasta64 likes this.
  8. MarioMasta64
    OP

    MarioMasta64 hi. i make batch stuff and portable shiz

    Member
    1,916
    411
    Dec 21, 2016
    United States
    heres the code btw:

    readbytes.py:
    Code:
    #Made By Larsenv
    #https://github.com/Larsenv/
    
    import binascii
    import sys
    
    if len(sys.argv) != 5:
        print("Usage: readbytes.py <start offset> <end offset> <input> <output>")
        sys.exit(1)
    
    def main():
        with open(sys.argv[3], "rb") as source_file:
            read = source_file.read()
    
        with open(sys.argv[4], "wb") as dest_file:
            dest_file.write(binascii.hexlify(read[int(sys.argv[1], 16):int(sys.argv[2], 16)]))
    
    main()
    writebytes.py:
    Code:
    #Made By Larsenv
    #https://github.com/Larsenv/
    
    import binascii
    import sys
    
    if len(sys.argv) != 4:
         print("Usage: writebytes.py <bytes> <offset> <input>")
         sys.exit(1)
    
    def main():
        with open(sys.argv[3], "r+b") as f:
            read = f.read()
            f.seek(int(sys.argv[2], 16))
            f.write(binascii.unhexlify(sys.argv[1]))
    
    main()
    made by @Larsenv 2017. good man. even wanted me to donate to riiconnect24 rather than him.
     
    Last edited by MarioMasta64, Aug 9, 2017
  9. Boogieboo6

    Boogieboo6 @realDonaldTrump

    Member
    953
    1,298
    Jul 30, 2015
    United States
    Wow, that's it? I was thinking of how to do it in C++, but I don't know enough to make something like that. Good work Larsenv!
     
    MarioMasta64 likes this.
  10. MarioMasta64
    OP

    MarioMasta64 hi. i make batch stuff and portable shiz

    Member
    1,916
    411
    Dec 21, 2016
    United States
    yea thats it lol. i couldve probably made it but i only know powershell vbs and batch (thank god i didnt try to make this in powershell) and youre free to do it if you want. if you need references for c++ way of doing it i have a few tabs pulled up for it.
     
  11. CMDreamer

    CMDreamer GBAtemp Regular

    Member
    281
    101
    Oct 29, 2014
    Mexico
    Have your tried with the Windows Shell? (Not Power Shell).

    Try using:

    Code:
    C:\debug
    Then type an ?, to get all the available commands.
     
    MarioMasta64 likes this.
  12. MarioMasta64
    OP

    MarioMasta64 hi. i make batch stuff and portable shiz

    Member
    1,916
    411
    Dec 21, 2016
    United States
    also i made a modified one (that was really useful) by removing a single line in a buggy one (it would remove everything after) to remove everything after (im working on a 3ds -> dsi dsiware transfer program)
    heres the code for that:

    removeendbytes.py:
    Code:
    #Made By Larsenv
    #https://github.com/Larsenv/
    
    import binascii
    import sys
    
    if len(sys.argv) != 3:
         print("Usage: removeendbytes.py <offset> <input>")
         sys.exit(1)
    
    def main():
        with open(sys.argv[2], "r+b") as f:
            read = f.read()
            f.seek(int(sys.argv[1], 16))
            f.truncate()
    
    main()
    — Posts automatically merged - Please don't double post! —

    yea. but this works alot better and requires less code.

    — Posts automatically merged - Please don't double post! —

    heres a test of how the files will be used:
    Code:
    @echo off
    cls
    Color 0A
    
    call :skip
    
    title test reading bytes from offset 1xF1 to 1xF6 in test.bin and writing in hex to test.txt
    python readbytes.py 1F1 1F7 test.bin test.txt
    pause
    
    title test writing bytes DE24 to offset 1xF0 in test.bin
    python writebytes.py DE24 1F0 test.bin
    pause
    
    title removing all bytes starting at offset 1xF6 all the way to the end
    python removeendbytes.py 1F6 test.bin
    pause
    
    title removing all bytes starting at the 0x00 point and ending at offset 0x06
    python removestartbytes.py 006 test.bin
    pause
     
    Last edited by MarioMasta64, Aug 9, 2017
  13. MarioMasta64
    OP

    MarioMasta64 hi. i make batch stuff and portable shiz

    Member
    1,916
    411
    Dec 21, 2016
    United States
    oh yea. heres another one (a revision before writebytes.py) that would write raw values to a file:

    writebytesraw.py:
    Code:
    #Made By Larsenv
    #https://github.com/Larsenv/
    
    import binascii
    import sys
    
    if len(sys.argv) != 5:
        print("Usage: readbytes.py <start offset> <end offset> <input> <output>")
        sys.exit(1)
    
    def main():
        with open(sys.argv[3], "rb") as source_file:
            read = source_file.read()
    
        with open(sys.argv[4], "wb") as dest_file:
            dest_file.write(read[int(sys.argv[1], 16):int(sys.argv[2], 16)])
    
    main()
     
    Last edited by MarioMasta64, Aug 9, 2017
  14. MarioMasta64
    OP

    MarioMasta64 hi. i make batch stuff and portable shiz

    Member
    1,916
    411
    Dec 21, 2016
    United States
    a new addition:
    removestartbytes.py:
    Code:
    #Made By Larsenv
    #https://github.com/Larsenv/
    
    import binascii
    import sys
    
    if len(sys.argv) != 3:
        print("Usage: removestartbytes.py <bytes> <file>")
    
    def main():
        with open(sys.argv[2], "rb") as f:
            read = f.read()[int(sys.argv[1]):]
    
        with open(sys.argv[2], "wb") as f:
            f.write(read)
    
    main()
    usage: python removestartbytes.py <end at this offset> <file>
    exa: pythong removestartbytes.py 006 test.bin
    this will remove all files upto ofset 006 but not 006 itself. so bytes 000-005 will be removed.
     
    Last edited by MarioMasta64, Aug 9, 2017
  15. MarioMasta64
    OP

    MarioMasta64 hi. i make batch stuff and portable shiz

    Member
    1,916
    411
    Dec 21, 2016
    United States
    an archive containing all the scripts listed here.
     

    Attached Files:

  16. DanTheManMS

    DanTheManMS aka Ricochet Otter

    Member
    4,330
    107
    Jun 2, 2007
    United States
    Georgia
  17. MarioMasta64
    OP

    MarioMasta64 hi. i make batch stuff and portable shiz

    Member
    1,916
    411
    Dec 21, 2016
    United States
  18. SpiffyJUNIOR

    SpiffyJUNIOR GBAtemp Fan

    Member
    315
    135
    Apr 13, 2016
    United States
    US
    Aint command-line,but HxD works magic on modding my BL2 .upk's.
     
    MarioMasta64 likes this.
  19. MarioMasta64
    OP

    MarioMasta64 hi. i make batch stuff and portable shiz

    Member
    1,916
    411
    Dec 21, 2016
    United States
    i have something i can use for command line. and yea HxD is great.
     
  20. MarioMasta64
    OP

    MarioMasta64 hi. i make batch stuff and portable shiz

    Member
    1,916
    411
    Dec 21, 2016
    United States
    new addition:

    directorysize.py:
    Code:
    #Made By Larsenv
    #https://github.com/Larsenv/
    
    import glob
    import os
    import sys
    
    if len(sys.argv) != 3:
        print("Usage: directorysize.py <directory> <output>")
    
    def main():
        with open(sys.argv[2], "wb") as dest_file:
            dest_file.write(str(sum(os.path.getsize(f) for f in glob.iglob(sys.argv[1] + "/**", recursive=True))).encode("utf-8"))
    
    main()