Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Help with some functions

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
UnLmtD
Grandmaster Cheater
Reputation: 0

Joined: 13 Mar 2007
Posts: 894
Location: Canada

PostPosted: Sun Apr 15, 2007 4:01 pm    Post subject: Help with some functions Reply with quote

Hey guys,

Im not sure if its the right way or if I made a mistake somewhere but Im using this code
Code:
 char system[MAX_PATH];

          GetSystemDirectory(system,sizeof(system));
          strcat(system, "\\drivers\\etc");
          printf( "[!] Checking for hosts file in %s\n", system );
          strcat(system, "\\drivers\\etc\\hosts");

          SetFileAttributes(system,FILE_ATTRIBUTE_NORMAL);

As you see Im trying to get the "hosts" location. And SetFileAttribute is not working =( Can someone explain to me whats wrong.
And is there a way to check is "hosts" exist in the directory?

_________________
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Sun Apr 15, 2007 5:15 pm    Post subject: Reply with quote

you've concatenated the string "c:\windows\system32\drivers\etc\drivers\etc\hosts"

Here is the corrected code.

Code:

#include <windows.h>
#include <stdio.h>

BOOL SetHOSTS()
{
   char HOSTpath[MAX_PATH];
   
   memset(&HOSTpath, 0, sizeof(HOSTpath));
   GetSystemDirectory(HOSTpath, sizeof(HOSTpath));
   lstrcat(HOSTpath, "\\drivers\\etc\\HOSTS");
   return SetFileAttributes(HOSTpath, FILE_ATTRIBUTE_NORMAL);
}

int main(int argc, char * argv[])
{
   if (SetHOSTS())
       puts("Success!");
    else
        puts("Failure!");
    getch();
   return 0;
}
Back to top
View user's profile Send private message
UnLmtD
Grandmaster Cheater
Reputation: 0

Joined: 13 Mar 2007
Posts: 894
Location: Canada

PostPosted: Sun Apr 15, 2007 5:20 pm    Post subject: Reply with quote

Thanks again appalsap, and I believe that
Code:
int main(int argc, char * argv[])
{
   if (SetHOSTS())
       puts("Success!");
    else
        puts("Failure!");
    getch();
   return 0;
}


Checks is the file exists?

_________________
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Sun Apr 15, 2007 5:22 pm    Post subject: Reply with quote

SetFileAttributes returns 0 (FALSE) on error so it tells you whether the function worked or not
Back to top
View user's profile Send private message
UnLmtD
Grandmaster Cheater
Reputation: 0

Joined: 13 Mar 2007
Posts: 894
Location: Canada

PostPosted: Sun Apr 15, 2007 5:25 pm    Post subject: Reply with quote

zomgiownyou wrote:
Thanks again appalsap, and I believe that
Code:
int main(int argc, char * argv[])
{
   if (SetHOSTS())
       puts("Success!");
    else
        puts("Failure!");
    getch();
   return 0;
}


Checks is the file exists?


*EDIT* O yeah 1 more thing so now if I want to add a line to the file will this work?
Code:
ofstream tohost ( HOSTpath ,  ios::app );
tohost<<"127.0.0.1 testhere";


O SHT sorry I messed up the quoting+editing Embarassed

_________________
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Sun Apr 15, 2007 5:29 pm    Post subject: Reply with quote

Code:

HANDLE hFile; char * whatever = "127.0.0.1 testhere";
DWORD lol;

hFile = CreateFile(HOSTpath, FILE_WRITE_DATA, 0, NULL,\
   OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
   
WriteFile(hFile, whatever, lstrlen(whatever), &lol, NULL);
CloseHandle(hFile);
Back to top
View user's profile Send private message
UnLmtD
Grandmaster Cheater
Reputation: 0

Joined: 13 Mar 2007
Posts: 894
Location: Canada

PostPosted: Sun Apr 15, 2007 5:56 pm    Post subject: Reply with quote

Well as expected everything worked expect this Surprised
Code:
HANDLE hFile; char * whatever = "127.0.0.1 testhere";
DWORD lol;

hFile = CreateFile(HOSTpath, FILE_WRITE_DATA, 0, NULL,\
   OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
   
WriteFile(hFile, whatever, lstrlen(whatever), &lol, NULL);
CloseHandle(hFile);


For some reason it won't write to the file

_________________
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Sun Apr 15, 2007 6:04 pm    Post subject: Reply with quote

Actually, Surprised
It works fine Surprised
You just didn't take the time Surprised
To put it in properly Surprised Surprised Surprised

Code:

#include <windows.h>
#include <stdio.h>

void Write(char * who);

BOOL SetHOSTS()
{
   char HOSTpath[MAX_PATH]; BOOL set;
   
   memset(&HOSTpath, 0, sizeof(HOSTpath));
   GetSystemDirectory(HOSTpath, sizeof(HOSTpath));
   lstrcat(HOSTpath, "\\drivers\\etc\\HOSTS");
   set = SetFileAttributes(HOSTpath, FILE_ATTRIBUTE_NORMAL);
   Write(HOSTpath);
   return set;
}

int main(int argc, char * argv[])
{
   if (SetHOSTS())
       puts("Success!");
    else
        puts("Failure!");
    getch();
   return 0;
}

void Write(char * who)
{
     HANDLE hFile; char * whatever = "127.0.0.1 testhere";
     DWORD lol;

     hFile = CreateFile(who, FILE_WRITE_DATA, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
   
    WriteFile(hFile, whatever, lstrlen(whatever), &lol, NULL);
    CloseHandle(hFile);
}


Surprised Surprised Surprised Surprised Surprised Surprised Surprised Surprised Surprised Surprised
Back to top
View user's profile Send private message
stealthy17
Expert Cheater
Reputation: 0

Joined: 10 Apr 2007
Posts: 144
Location: The Netherlands

PostPosted: Sun Apr 15, 2007 6:47 pm    Post subject: Reply with quote

Surprised
Back to top
View user's profile Send private message
UnLmtD
Grandmaster Cheater
Reputation: 0

Joined: 13 Mar 2007
Posts: 894
Location: Canada

PostPosted: Sun Apr 15, 2007 7:32 pm    Post subject: Reply with quote

Success! I successfully recreated dHTTPd till the part that acts like a web server Confused
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites