0

I am trying to fopen a file into a file buffer and then create a new process with it. I was trying ASM to goto the start of the file but sadly because of windows it wouldn't actually do anything because all of the information on the top of a windows executable. So I tried to create a new process, and I am not to good with the windows API. Can anyone tell me what I am doing wrong?

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

char *file0_buffer;
int file0_size;

STARTUPINFO si;
PROCESS_INFORMATION pi;


int main(int argc, char **argv){

   ZeroMemory( &si, sizeof(si) );
   si.cb = sizeof(si);
   ZeroMemory( &pi, sizeof(pi) );

   FILE *file0 = fopen("./input.exe", "rb");
   if(file0 == NULL){printf("fopen file0 error"); getchar(); return 0;}

   fseek(file0, 0, SEEK_END);
   file0_size = ftell(file0);
   rewind(file0);

   file0_buffer = (char*)malloc(file0_size);
   fread(file0_buffer, sizeof(char), file0_size, file0);
   fclose(file0);

   CreateProcess(NULL, NULL, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE, &file0_buffer, NULL, &si, &pi);

   getchar(); return 0;
}
Emma Skye
  • 23
  • 1
  • 1
  • 4
  • You can try `GetLastError` to find out the what kind of error the system is reporting. I haven't see the use of `CreateProcess` with both the first and the second arguments set to `NULL`. – R Sahu Jun 10 '14 at 20:48
  • What's wrong is everything. What you attempt is not supported. – David Heffernan Jun 10 '14 at 23:52

1 Answers1

-1

The 7th parameter to CreateProcess is for specifying the environment variables in the new process.

See this: CreateProcess from memory buffer

Community
  • 1
  • 1
josh poley
  • 7,236
  • 1
  • 25
  • 25