binary files, read hex add anumber to it and put in output.

Ok i am trying to make a program that reads every nth byte in hex from a binary file and adding a number to the hex to get a diffrent char.

example I want to edit every 10 bytes. the first 10th byte i read in binary is 010000001, which in ascii it is character A which is 41 in hex and i want to add 1 to the hex to get a 42 in hex, which is B in ascii...

The overall program i am trying to make is a file corruptor that edits every nth byte of a binary. My psuedocode is:

while(!eof)
{
for(int count =0; cout < (nythbyte -1);count++)
{ read and write byte in to output file}
read byte as ascii and write to output
}

my code so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <stdio.h>
#include <cstring>
#include <fstream>
#include <string>
#include <cstdio>
using namespace std;

int main()
{

	int nthByte = 0;
	char byte = ' ';
	FILE *in

	fstream outfile;
	fstream infile;
	infile.open("smb3.nes", ios::in|ios::binary);
	outfile.open("o.nes", ios::in|ios::out|ios::binary|ios::ate|ios::trunc); //open file in binary, in out mode, plan on reading and editing the outfile later in the program, also if exist delete and start over
	while(!outfile.eof())
   {
       for(int count =0; count < (nthByte -1);count++)
        { getc(infile); putc(outfile);}
   }
}


Last edited on
Topic archived. No new replies allowed.