Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <iostream>
- #include <fstream>
- using namespace std;
- size_t replace(FILE *fi, FILE *fo, uint8_t *what, uint8_t *repl, size_t size){
- size_t i, index = 0, count = 0;
- int ch;
- while(EOF!=(ch=fgetc(fi))){
- if(ch == what[index]){
- if(++index == size){
- for(i = 0; i < size ; ++i){
- fputc(repl[i], fo);
- }
- index = 0;
- ++count;
- }
- } else {
- for(i = 0; i < index ; ++i){
- fputc(what[i], fo);
- }
- index =0;
- fputc(ch, fo);
- }
- }
- for(i = 0; i < index ; ++i){
- fputc(what[i], fo);
- }
- return count;
- }
- int main(void){
- string src[100], dest[100];
- FILE *file,*fileout;
- uint8_t what[] = {0xA8, 0x78, 0x0A, 0x21, 0x6A} ; uint8_t repl[] = {0xE8, 0x78, 0x0A, 0x21, 0x6A};
- size_t count;
- file=fopen("fw","rb");
- fileout=fopen("fw_changed","wb");
- count = replace(file, fileout, what, repl, sizeof(what));
- //
- // delete what;
- // delete repl;
- //
- // uint8_t what[] = {0xA8, 0x78, 0xB0, 0xFB, 0xF1}; uint8_t repl[] = {0xE8, 0x78, 0xB0, 0xFB, 0xF1};
- // file=fopen("fw","rb");
- // fileout=fopen("fw_changed","wb");
- // count = replace(file, fileout, what, repl, sizeof(what));
- fclose(fileout);
- fclose(file);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement