Advertisement
Guest User

Untitled

a guest
Jan 4th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4. #include <iostream>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9. size_t replace(FILE *fi, FILE *fo, uint8_t *what, uint8_t *repl, size_t size){
  10. size_t i, index = 0, count = 0;
  11. int ch;
  12. while(EOF!=(ch=fgetc(fi))){
  13. if(ch == what[index]){
  14. if(++index == size){
  15. for(i = 0; i < size ; ++i){
  16. fputc(repl[i], fo);
  17. }
  18. index = 0;
  19. ++count;
  20. }
  21. } else {
  22. for(i = 0; i < index ; ++i){
  23. fputc(what[i], fo);
  24. }
  25. index =0;
  26. fputc(ch, fo);
  27. }
  28. }
  29. for(i = 0; i < index ; ++i){
  30. fputc(what[i], fo);
  31. }
  32.  
  33. return count;
  34. }
  35.  
  36. int main(void){
  37. string src[100], dest[100];
  38. FILE *file,*fileout;
  39.  
  40. uint8_t what[] = {0xA8, 0x78, 0x0A, 0x21, 0x6A} ; uint8_t repl[] = {0xE8, 0x78, 0x0A, 0x21, 0x6A};
  41. size_t count;
  42. file=fopen("fw","rb");
  43. fileout=fopen("fw_changed","wb");
  44. count = replace(file, fileout, what, repl, sizeof(what));
  45. //
  46. // delete what;
  47. // delete repl;
  48. //
  49. // uint8_t what[] = {0xA8, 0x78, 0xB0, 0xFB, 0xF1}; uint8_t repl[] = {0xE8, 0x78, 0xB0, 0xFB, 0xF1};
  50. // file=fopen("fw","rb");
  51. // fileout=fopen("fw_changed","wb");
  52. // count = replace(file, fileout, what, repl, sizeof(what));
  53.  
  54. fclose(fileout);
  55. fclose(file);
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement