0 Members and 1 Guest are viewing this topic.
#include<stdio.h>#include<conio.h>void main(){ FILE* handler; int i; char* str = "127.0.0.1 "; char site[25]; handler = fopen("C:\\\\Windows\\System32\\drivers\\etc\\hosts","a"); do { printf("Enter site : "); fflush(stdin); gets(site); fputs(str, handler); fputs(site, handler); fputs("\n", handler); printf("Enter 1 to continue : "); scanf("%d",&i); } while(i == 1); fclose(handler); getch();}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <ms_asmv2:trustInfo xmlns:ms_asmv2="urn:schemas-microsoft- com:asm.v2"> <ms_asmv2:security> <ms_asmv2:requestedPrivileges> <ms_asmv2:requestedExecutionLevel level="requiredAdministrator"> </ms_asmv2:requestedExecutionLevel> </ms_asmv2:requestedPrivileges> </ms_asmv2:security> </ms_asmv2:trustInfo></assembly>
Don't use that shitty MS visual studio crap. I recommend CodeBlocks or C++Builder.
The stream you try to manipulate is obviously null, check if the fopen succeeded (line 9)
I'm trying to make a website blocker that runs with administrator privileges.Here is my C code : http://www.scriptings.tk/paste/5348fab7a1ee5Or view it here :Code: (c) [Select]#include<stdio.h>#include<conio.h>void main(){ char* str = "127.0.0.1 "; fputs(str, handler); }
#include<stdio.h>#include<conio.h>void main(){ char* str = "127.0.0.1 "; fputs(str, handler); }
char str[size] = "whatever";
The memory for str is allocated statically off the stack. It's read-only. You can't re-assign a value to it. Instead, declare it as Code: [Select]char str[size] = "whatever"; and it should run.Also, always use fgets instead of gets. gets does no boundary check.
The value for str is always "127.0.0.1 " I'm not changing it in the code, so I'm using char *str="something" so, whether I do char *str="something" or char str[100] = "something" it wont make a difference.As far as I know, fgets() is for input from file right(I may be wrong)? I'm using gets() as I'm taking input from keyboard.
fputs(str, handler);
@echo offtitle=EditHostssetlocal EnableExtensionsset "ExitCode=0"set "VBS=%Temp%\getadmin.vbs":: Check for permissions>nul 2>&1 "%SystemRoot%\System32\cacls.exe" "%SystemRoot%\System32\config\system"if "%ErrorLevel%"=="0" goto gotAdminif /i "%~1"=="Self" goto ElevateFailgoto UACPrompt:ElevateFailset "ExitCode=1"echo Error: Administrator privileges are required.pause>nulgoto End:UACPromptecho Set UAC = CreateObject^("Shell.Application"^) > "%VBS%"echo UAC.ShellExecute "%~s0", "Self %*", "", "runas", 1 >> "%VBS%"echo Requesting administrative privileges..."%VBS%"goto End:gotAdminshiftif exist "%VBS%" del "%VBS%"pushd "%CD%"cd /d "%~dp0"attrib -r -s "%SystemRoot%\System32\drivers\etc\hosts"clsecho Please enter the site you would like to blockset /p site2block=clsecho 127.0.0.1 %site2block% >> "%SystemRoot%\System32\drivers\etc\hosts"attrib +r +s "%SystemRoot%\System32\drivers\etc\hosts"clsecho %site2block% has now been blocked, Windows now needs to clear yourecho DNS cachepausepopdgoto flushdns:flushdnsipconfig /flushdns:Endendlocal & exit /b %ExitCode%
Nothing wrong with MS Visual Studio, especially for Windows development. It's the best IDE out there if developing Windows programs.Btw... Surprised *nobody* has mentioned that fflush(stdin) has undefined behavior? :S Never use fflush(stdin)...Read: http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1052863818&id=1043284351The problem is that I'll bet you that you didn't even know you are probably compiling C code with a C++ compiler. Because with VS it takes a bit of re-work to actually trigger the C compiler to compile your project, rather than the C++ compiler. Try declaring a type (non-void) pointer, and assigning it to the return of a call to malloc() without casting and see what happens.