|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
i write this code to read the first byte from my EXE and compare it
with the entered EXE file the byte read from both files supposed to be the same but that's don't happened!! i tried also with different EXE's but it also failed to read the first byte which is "M" -- here is the code: FILE *a,*b; int z; char str1[2]; char str2[2]; a= fopen(argv[0],"rb"); //try to change both file with another EXE's and u will also fail b= fopen(argv[1],"rb+"); z= fread(str1,1,1,a); if (z !=1) printf("-101"); z= fread(str2,1,1,b); if (z !=1) printf("-102"); if(str1 == str2) { fwrite("a",1,1,b); // i want to change the first byte with this char printf("OK"); }else{ fwrite(str1,1,1,b); printf("NO"); } fclose(a); fclose(b); |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Medvedev escreveu: > i write this code to read the first byte from my EXE and compare it > with the entered EXE file > the byte read from both files supposed to be the same but that's don't > happened!! > i tried also with different EXE's but it also failed to read the first > byte which is "M" > -- > here is the code: > char str1[2]; > char str2[2]; > if(str1 == str2) Here you're comparing the two pointers str1 and str2 (which will never be equal). What you want to do is if (str1[0] == str2[0]) to compare the read bytes. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Jul 1, 12:05 pm, Goedson Paixao <goed...@gmail.com> wrote:
> Medvedev escreveu: > > > i write this code to read the first byte from my EXE and compare it > > with the entered EXE file > > the byte read from both files supposed to be the same but that's don't > > happened!! > > i tried also with different EXE's but it also failed to read the first > > byte which is "M" > > -- > > here is the code: > > char str1[2]; > > char str2[2]; > > if(str1 == str2) > > Here you're comparing the two pointers str1 and str2 (which will never > be equal). What you want to do is > > if (str1[0] == str2[0]) > > to compare the read bytes. it works but it don't configure the EXE as i called fwrite("a",1,1,b); why?! |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
"Medvedev" <3D.v.World@gmail.com> wrote
> On Jul 1, 12:05 pm, Goedson Paixao <goed...@gmail.com> wrote: > > Medvedev escreveu: > > > > > i write this code to read the first byte from my EXE and compare it > > > with the entered EXE file > > > the byte read from both files supposed to be the same but that's don't > > > happened!! > > > i tried also with different EXE's but it also failed to read the first > > > byte which is "M" > > > -- > > > here is the code: > > > char str1[2]; > > > char str2[2]; > > > if(str1 == str2) > > > > Here you're comparing the two pointers str1 and str2 (which will never > > be equal). What you want to do is > > > > if (str1[0] == str2[0]) > > > > to compare the read bytes. > > it works but it don't configure the EXE as i called > fwrite("a",1,1,b); > why?! Check the position of the file pointer... :-) And of course the file opening mode... :-) |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On 1 jul, 16:23, Medvedev <3D.v.Wo...@gmail.com> wrote:
> On Jul 1, 12:05 pm, Goedson Paixao <goed...@gmail.com> wrote: > > > > > Medvedev escreveu: > > > > i write this code to read the first byte from my EXE and compare it > > > with the entered EXE file > > > the byte read from both files supposed to be the same but that's don't > > > happened!! > > > i tried also with different EXE's but it also failed to read the first > > > byte which is "M" > > > -- > > > here is the code: > > > char str1[2]; > > > char str2[2]; > > > if(str1 == str2) > > > Here you're comparing the two pointers str1 and str2 (which will never > > be equal). What you want to do is > > > if (str1[0] == str2[0]) > > > to compare the read bytes. > > it works but it don't configure the EXE as i called > fwrite("a",1,1,b); > why?! In order to write the first byte of the file, you first need to move back to that position (you've already read it before). Doing this: fseek(b, 0L, SEEK_SET); before the fwrite, should do the trick. |
|
![]() |
| Outils de la discussion | |
|
|