somename 0 Newbie Poster

heh, thanks for reply.
I have actually fixed my code and made it work in an hour after posting topic here, there was some silly mistakes. Here is good one:

while((redirection_search = sys_strstr(tem, "Location:")) != (void*)0){
	CLEAR(recvbuffer);
	char *found, *uri;
	char con[512];
	CLEAR(con);
	t = sys_strtok(redirection_search,"\n");
	for(i = 0; t; t = sys_strtok((void*)0,"\n"), i++) token[i] = t;
	found = cut_it(token[0], " ");
	found = (found+8);
	sys_strcpy(con, found);
	sys_strtok(found,"/");
	uri = sys_strstr(con, "/");
	VisitSite(found, uri);
	break; 
}

CLEAR(var) => sys_memset(&var, 0x00, sizeof(var))
sys_ => my own syscalls based functions, libc equivalents, as i have stopped using libc.
VisitSite(found, uri) => calling function from itself
^^ this code handles as many redirections as it receives.
Cheers

somename 0 Newbie Poster

Hi all. Ok, i got such php script:

<?php
header('Location: http://localhost/current/');
?>

Now i am sending GET request to this script with my C app and receiving following header:

HTTP/1.1 302 Found
Date: Sat, 20 Feb 2010 18:50:17 GMT
Server: Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4.5 with Suhosin-Patch
X-Powered-By: PHP/5.2.6-2ubuntu4.5
Location: http://localhost/current/
Vary: Accept-Encoding
Content-Length: 0
Connection: close
Content-Type: text/html

So my question is, how to implement at this moment redirection to this new uri? Parse header, extract this uri and call same function from itself? Or use

goto

? By the way i was trying to parse it this way:

char *red = strstr(recvbuffer, "Location:");
	if(red != NULL){
	char *found, *uri;
	t = strtok(red,"\n");
	for(i = 0; t; t = strtok(NULL,"\n"), i++) token[i] = t;
	found = cut_it(token[0], " ");
	found = (found+8);
	puts(found);
	uri = strstr(found, "/");
	if(uri != NULL){
		printf("h: %s, p: %s\n", found, uri);
		}
	}

It should print at the end:
"h: localhost, p: /current/"
but instead it prints: ", p: /current/urrent/".
What is wrong with this code?
Here is my cut_it function:

char *cut_it( char *xx,  char *yy){
   if ( !*yy ) return xx;
   for ( ; *xx; ++xx ){
      if ( *xx == *yy ){
          char *h, *n;
         for ( h = xx, n = yy; *h && *n; ++h, ++n ){
            if ( *h != *n )break;
         }
         if ( !*n ){
            return xx;
         }}}
   return 0;
}

And i cannot use …

somename 0 Newbie Poster

Hi there, i am trying to implement thread injection from my windows forms .NET project. Here is the code which works just fine from simple console app or Gtk+ gui application, but unfortunately not from .NET gui app.

#define  NtCurrentThread()		           ((HANDLE) -2)
#define  NtCurrentProcess()		           ((HANDLE) -1)

typedef DWORD (WINAPI *Rm_MessageBoxA)(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType);
#pragma warning( disable : 4996 )

typedef struct _Structure {
PVOID RmMessageBoxA;
char Message[MAX_PATH];
char Title[MAX_PATH];
} Structure;

Structure my_Structure,*pmy_Structure;

DWORD __stdcall ReThread(Structure *Parameter){
Rm_MessageBoxA myMessageBoxA = (Rm_MessageBoxA)Parameter->RmMessageBoxA;
myMessageBoxA(0, Parameter->Message, Parameter->Title,0);
return 0;
}

/* whole below function replacemenet with 1 line of code
RtlAdjustPrivilege(20, TRUE, AdjustCurrentProcess, &en);
*/
static BOOL SetPrivilege(char* SeNamePriv, BOOL EnableTF){
   HANDLE hToken;
   LUID SeValue;
   TOKEN_PRIVILEGES tp;

   if (!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&hToken))return FALSE;
   
   if (!LookupPrivilegeValue(NULL, SeNamePriv, &SeValue)){
      CloseHandle(hToken);
      return FALSE;
   }
   
   tp.PrivilegeCount = 1;
   tp.Privileges[0].Luid = SeValue;
   tp.Privileges[0].Attributes = EnableTF ? SE_PRIVILEGE_ENABLED : 0;
   AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL);
   CloseHandle(hToken);
   return TRUE;
}

static DWORD GetPIDbyName(LPTSTR p_Name){
	HANDLE m_Snap;
	PROCESSENTRY32 pe = { sizeof(pe) };
	m_Snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
	if (m_Snap == INVALID_HANDLE_VALUE) return 0; 
	if (!Process32First(m_Snap, &pe)) return 0;
	
	do{
		if( !lstrcmpi(pe.szExeFile, p_Name)){		
			return pe.th32ProcessID;
		}
	} while (Process32Next(m_Snap, &pe));

	CloseHandle(m_Snap);
	return 0;
}

bool Load(){

    void *pThread; SIZE_T dwThreadSize=4000;
    SetPrivilege("SeDebugPrivilege", TRUE);
	HANDLE RemoProc;
    DWORD dwPid = GetPIDbyName("notepad.exe");
    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPid);
    pThread = VirtualAllocEx(hProcess, 0, dwThreadSize, MEM_COMMIT | MEM_RESERVE,PAGE_EXECUTE_READWRITE);
	if(pThread == NULL){MessageBoxA(0,"pThread == NULL","error",0); return false;}
	if(WriteProcessMemory(hProcess, pThread, (void *)ReThread, dwThreadSize,0) == 0){
	MessageBoxA(0,"WriteProcessMemory failed!","error",0);
	return false;
	}
    RtlZeroMemory(&my_Structure,sizeof(Structure));
    HINSTANCE hUser;
    hUser = LoadLibraryExA("user32.dll", NULL, …
somename 0 Newbie Poster

Hello. Here goes the problem: i got my movie made elsewhere then in adobe flash, converted to .fla and imported to adobe flash to add some AS. But the movie is not assigned to a main timeline and i cannot do a thing with it now. It is playing nicely after saving project as .swf, but for example i want to redirect user to main page after movie finishes, but cant because there is no last frame in project. I got only one frame and it seems that this one frame contains whole movie which is 45 sec long. I was looking, trying everything, posting at adobe forums with no result. Maybe someone knows how to solve this, any hints would be a great help to me.

somename 0 Newbie Poster

Solved. If anyone have ever encounter such problem here is 100% working code for me. Grepped from microsoft, modified a little by me.

#include <windows.h>
#include <tchar.h>
#include <strsafe.h>
#define mb(x,z) MessageBox(0,x,z,0)
// compiled as multi-byte project, not unicode
int main(){
	TCHAR dllName[] = "C:\\WINDOWS\\SYSTEM32\\eventSource.dll"; 
    DWORD dwCategoryNum = 1;
    HKEY hk; 
    DWORD dwData, dwDisp; 

   if(RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\SampleEventSourceName"), 0, NULL, 0,  KEY_ALL_ACCESS, NULL, &hk, &dwDisp)){
      mb("Could not create the registry key.", ""); 
      return 0;
   }

// name as "EventMessageFile", data as "C:\\WINDOWS\\SYSTEM32\\eventSource.dll"
    if (RegSetValueEx(hk, TEXT("EventMessageFile"), 0, REG_EXPAND_SZ, (LPBYTE) dllName,(DWORD) (lstrlen(dllName)+1)*sizeof(TCHAR))){
    mb("Could not set the event message file.", ""); 
    RegCloseKey(hk); 
    return 0;
  }


   // Set the supported event types. 
   dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | 
        EVENTLOG_INFORMATION_TYPE; 

 // name as "TypesSupported", data as "(7)"
   if (RegSetValueEx(hk, TEXT("TypesSupported"), 0, REG_DWORD,(LPBYTE) &dwData, sizeof(DWORD))){
      mb("Could not set the supported types.", ""); 
      RegCloseKey(hk); 
      return 0;
   }
 
 // name as "CategoryCount", data as "(1)"
  if (RegSetValueEx(hk, TEXT("CategoryCount"), 0, REG_DWORD,  (LPBYTE) &dwCategoryNum, sizeof(DWORD))) {
      mb("Could not set the category count.", ""); 
      RegCloseKey(hk); 
      return 0;
   }
   RegCloseKey(hk); 
   return 1;
}
somename 0 Newbie Poster

Hello. Maybe someone can help me with this, here is my code:

#include <windows.h>
#include <stdio.h>
#include <wininet.h>
#include <shlwapi.h>
#define mb(x,z) MessageBox(0,x,z,0)
#define		REGKEY		    	"PATH\\to\\my\\key"
#define		REGNAME		    	"zzzzzzzzzzzzz"
#define     EXENAME             "zzzzzz.exe"
void Reg()
{

 HKEY   hkey;
 DWORD  dwDisposition;
 DWORD  m_dwMaxFileSize = 16 * 1024; 
 TCHAR m_szLastFileName[MAX_PATH];
 DWORD dwType, dwSize;
 int data = 10;
 char somechar[MAX_PATH];
 strcpy(somechar, "somechar");
  strcpy(m_szLastFileName, TEXT("Datafile.TXT"));

 if(RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("PATH\\to\\my\\key\\zzzz"), 0, NULL, 0, 0, NULL, &hkey, &dwDisposition)== ERROR_SUCCESS)
 {
 RegSetValueEx(hkey, REGNAME, 0, REG_SZ, (LPSTR)somechar, strlen(somechar));
            RegSetValueEx(hkey, NULL, 0, REG_SZ,
                          (BYTE *)data,
                          sizeof(data)+1) ;
  dwType = REG_DWORD;
  dwSize = sizeof(DWORD);
  if(RegSetValueEx(hkey, TEXT("MaxFileSize"), 0, dwType, 
        (PBYTE)&m_dwMaxFileSize, dwSize) != ERROR_SUCCESS) mb("error","");
 
  dwType = REG_SZ;
  dwSize = (strlen(m_szLastFileName) + 1) * sizeof(TCHAR);
  if(RegSetValueEx(hkey, TEXT("LastFileName"), 0, dwType, 
        (PBYTE)&m_szLastFileName, dwSize) != ERROR_SUCCESS) mb("errorr","");
 
  RegCloseKey(hkey);
 }
}

int main(int argc, char *argv[]){
Reg();
}

and it is not working no matter what. Its combination of code from microsoft site and some my own. That progie only creates key, and after that crashes. If key is already in registry, then its not crashes but not adding values either. The same issue i got with RegDeleteValue function, which doesnot deleting values in my case.
The only function wich is working for me is:
SHDeleteKey...
Maybe someone can point me to some tut about shell registry functions, but not msdn, there aren't any examples ;p

somename 0 Newbie Poster

Hello. My question is about perlTk. I'm wondering how to write a gui app like that: it has 2 buttons, 1 is "run" and 2 is "stop". App should run some function and when i press "stop" button, it should stop. But when "run" button pressed whole app gets inactive and to stop it i have to terminate whole process. I'm writing this for win32. On linux i've solved it with creating a child process with fork, but on win my gui proggie crashes all the time if i'm using fork. Can anyone help me please?

somename 0 Newbie Poster

Hi guys. I cannot figure out how to do next thing.
for example i have a little progie like this:

int myfunction(int argc, char *argv[]){
int i;
  	for(i=0;i<argc;i++)
    	unlink(argv[i]);
}
int main(int argc, char *argv[]){
myfunction(argc,argv);
}

works fine, but i'm trying to do that:

int myfunction(int argc, char *argv[]){
int i;
  	for(i=0;i<argc;i++)
    	unlink(argv[i]);
}
int main(){
int argc;
char **argv;
myfunction(argc,argv);
}

and it's not working. and i got no idea how to get rid from int main declaration of argc and argv. Can anyone help me plz?

somename 0 Newbie Poster

thank you for your replies, but i have to deal with it later because now i have devastating exams and absolutely now free time for programming ;(

somename 0 Newbie Poster

Hi. i'm trying to copy a binary already with a predefined permissions. I got this code:

FILE *f1, *f2;
  char cp;
f1 = fopen("file1","rb");
f2 = fopen("file2","wb");
while(!feof(f1)) {
cp = fgetc(f1);
if(!feof(f1)) fputc(cp, f2);
fclose(f1);
fclose(f2);

but this just copy a file. But what i'm trying to do is copy file for example with permissions 0777.
i saw somewhere that people using something like this:

f1=open("file1",O_RDONLY);
f2=open("file2",O_WRONLY|O_CREAT,0777);

i was trying many ways but always it copy a binary into another which is just empty file. Plz help

somename 0 Newbie Poster

Duoas, thank you! Problem solved. Yes, i was about how to convert number to string, just didnt know how to express myself properly. Thanks!

somename 0 Newbie Poster

Hello. I got a problem of that type:
for example i have a simple program like this:

int main(){
sleep(10);
}

now if i define time to be 10 sec, prog works fine.

#define TIME 10
sleep(TIME)

but i am trying to do something like that:

char time; // or int time;
time = "10";
sleep(time);

and it's not working. Prog sleeps untill i finish it myself manualy.
The same thing i am trying to do in simple socket app to connect the net.
This line:

dest_addr.sin_port = htons(DEST_PORT);

when DEST_PORT is defined, it's ok. But i'm trying to rebuild this like with that app with sleep. The errors i've got are:
passing argument 1 of 'htons' makes integer from pointer without a cast
or
assignment makes integer from pointer without a cast.
Please help me how to do it...

somename 0 Newbie Poster

guys, thank you very much for your replies, especially jephthah, your code works great and i get it now where i got lost with my code! Thanks once again!

somename 0 Newbie Poster

Hello. I am trying to find out how to write a function to replace a string in a text file. So far i got this:
find -> is a word i am looking for replace, rep -> new word, f1 -> my file. And i'm stuck with that piece of code:

while ( fgets( buff, BUFSIZ, f1 ) != NULL ) {
if ( strstr( buff, find ) != NULL ) {...

so i'm thinking about something like that:

strcpy(buff2, (buff - strlen(find) + strlen(rep) + 1);
fputs(buff2, f2)

where f2 is output file. So plz, maybe anyone can help me with this code?

somename 0 Newbie Poster

HI guys. Jeezz, perl forum is kind of abandoned ;/ Anyway, maybe some one will have an idea.
I want to write a selfkilling perl prog :D Ok, i got a simple prog which shows up a simple tk window with some text in it, to go to the next function (in my app), i have to close window manualy. Is it posible to make that window disappear, lets say, after 10 seconds, without my interference? The same is about perl scripts which runs an xterm and after some function you always have to close that window to go forward. Or, is there a way to run perl script without shell environment (i'm not talking about daemons here)?

somename 0 Newbie Poster

Salem, thank you!:) the code:

int main()
{
FILE *fp;
fp=fopen("file.txt","r");
char s[256];
while( fgets(s, sizeof(s),fp)!= NULL)
if ( strncmp( s, "hi", 2 ) == 0 ){
{
system("xterm");
}}
fclose(fp);
return 0;
}

working perfect!
problem solved.

somename 0 Newbie Poster

Hi everyone. I got a total newbe question and i am new to c programming. I want to write a program that will executing commands , written in separate text file.
Lets say, in perl i got something like that:

open (F,"<file.txt");
$x = <F>;
if ($x == "2"){
system "whatever";}

In c i've stuck with something like:

int main()
{
FILE *fp;
fp=fopen("file.txt","r");
char s[256];
while( fgets(s, sizeof(s),fp)!= NULL)
{
system("xterm");
}
fclose(fp);
return 0;
}

what i'm trying to do in my newbe eyes should look maybe like:

int main()
{
FILE *fp;
fp=fopen("file.txt","r");
char s[256];
if( fgets(s,fp)==1)
{
system("xterm");
}
fclose(fp);
return 0;
}

but i realy cannot find solution anywhere, so maybe someone can help me with that...