PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > I can't read the first byte of an EXE file!!!!!
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
I can't read the first byte of an EXE file!!!!!

Réponse
 
LinkBack Outils de la discussion
Vieux 01/07/2008, 19h53   #1
Medvedev
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut I can't read the first byte of an EXE file!!!!!

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);
  Réponse avec citation
Vieux 01/07/2008, 20h05   #2
Goedson Paixao
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: I can't read the first byte of an EXE file!!!!!



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.
  Réponse avec citation
Vieux 01/07/2008, 20h23   #3
Medvedev
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: I can't read the first byte of an EXE file!!!!!

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?!
  Réponse avec citation
Vieux 02/07/2008, 01h01   #4
Adem24
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: I can't read the first byte of an EXE file!!!!!

"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... :-)

  Réponse avec citation
Vieux 26/08/2008, 14h03   #5
Goedson Paixao
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: I can't read the first byte of an EXE file!!!!!

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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 00h20.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13727 seconds with 13 queries