On Saturday, 2 May 2020 at 21:05:32 UTC, Baby Beaker wrote:
I need open a Binary EXE, it can be using "rb" mode and convert it to Hexadecimal for me make some changes and save as "rb" again. How can I make it? Thank you.

You dont convert binary data to hexadecimal. You display it as hexadecimal. If you want to print file contents to console in hex do something like this.

import std.stdio;
import std.algorithm;

auto fd = File("filename", "r"); //open file for reading
ubyte[] data; //a GC allocated buffer for data
fd.rawRead(data); //read the data

data[0..50].each!(n => stdout.writef("%X ",n));
/*take 50 elements from array and for each of them call lambda that converts ubyte to string in hex format and prints to the stdout*/

if you want to assign to this data you can do something like this

data[0] = Oxff;

And then write to file

Reply via email to