commandline

I have a code like the one below. I want to run it by specifying different processes or file names on the commandline instead of hardcoding the process to be created on the code like ChildProcess below after the if statement. Instead of TEXT("ChildProcess") what do i suppose to put?
[code]
if (argc !=2)
{
printf("Error in the input line, Usage: Inputfile");
exit(2);
}

printf("Process %d creates a child process
",GetCurrentProcessId());//print out our process ID
GetStartupInfo(&si);
if( !CreateProcess( NULL, // No module name (use command line).
TEXT("ChildProcess"), // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
[/code]

Comments

  • : I have a code like the one below. I want to run it by specifying different processes or file names on the commandline instead of hardcoding the process to be created on the code like ChildProcess below after the if statement. Instead of TEXT("ChildProcess") what do i suppose to put?

    just replace it with argv[1];

  • : : I have a code like the one below. I want to run it by specifying different processes or file names on the commandline instead of hardcoding the process to be created on the code like ChildProcess below after the if statement. Instead of TEXT("ChildProcess") what do i suppose to put?
    :
    : just replace it with argv[1];
    :
    :

    thanks, it works
  • [b][red]This message was edited by mpapeo at 2005-3-10 17:57:15[/red][/b][hr]
    : : : I have a code like the one below. I want to run it by specifying different processes or file names on the commandline instead of hardcoding the process to be created on the code like ChildProcess below after the if statement. Instead of TEXT("ChildProcess") what do i suppose to put?
    : :
    : : just replace it with argv[1];
    : :
    : :
    :
    : thanks, it works
    :
    But now i have some slight problem with this function [code] ZeroMemory(buf, sizeof(buf));
    if( ReadProcessMemory( hProcess, &baseaddr, &buf, bufsize, NULL ) == FALSE )
    {
    printf("
    Process memory read failed", GetLastError());
    _exit(1);
    }
    else
    {
    printf("
    Process memory read:
    ",buf);
    }[/code]. Why is it that it returns false even though the process is created. I want to retrieve the size of memory read


  • : But now i have some slight problem with this function

    call GetLastError() then FormatMessage() to find out why it didn't work. Probably either you buffer was not large enough or, as MSDN says, the other process'es memory was not accessable (whatever that means???)

  • : : But now i have some slight problem with this function
    :
    : call GetLastError() then FormatMessage() to find out why it didn't work. Probably either you buffer was not large enough or, as MSDN says, the other process'es memory was not accessable (whatever that means???)
    :
    :
    Yes i can see it.
    But am i going about it correctly?Note that in the commandline you can supply notepad as a process to be created

    [code]
    int main(int argc, char **argv[])
    {
    PROCESS_INFORMATION pi; /* filled in by CreateProcess */
    STARTUPINFO si; /* startup info for the new process*/
    HANDLE hProcess;
    BYTE buf[200000]; DWORD bufsize = sizeof buf;
    DWORD baseaddr = 0;
    LPCVOID lpAddress = 0;
    PMEMORY_BASIC_INFORMATION lpBuffer = 0;
    DWORD dwLength = 0;
    DWORD flNewProtect =0;
    PDWORD lpflOldProtect = 0;
    DWORD dwSize =0;
    LPCVOID lpBaseAddress = 0;
    DWORD nSize = 0;
    DWORD buff = 0;
    LPDWORD lpNumberOfBytesRead = sizeof buf;
    if (argc !=2)
    {
    printf("Error in the input line, Usage: Inputfile");
    exit(0);
    }
    //menu();

    printf("Process %d creates a child process
    ",GetCurrentProcessId());//print out our process ID
    GetStartupInfo(&si);

    // Call CreateProcess, telling it to run an exe file
    CreateProcess(NULL,/* lpApplicationName */
    argv[1],/* lpCommandLine assumes to use curent process directory*/ NULL, /* lpsaProcess */
    NULL, /* lpsaThread */
    FALSE, /* bInheritHandles */ CREATE_NEW_CONSOLE, /* dwCreationFlags */
    NULL, /* lpEnvironment */
    NULL, /* lpCurDir */
    &si, /* lpStartupInfo */
    &pi /* lpProcInfo */
    );
    hProcess = pi.hProcess;
    printf("New Process ID: %d ",pi.dwProcessId);
    printf("has started
    ");

    VirtualQueryEx(
    hProcess, // handle to process
    lpAddress, // address of region
    lpBuffer,// address of information buffer
    dwLength,// size of buffer
    GetLastError()
    );
    //*to avoid crashing
    VirtualProtectEx(
    hProcess, // handle to process
    lpAddress, // address of region of committed pages
    dwSize, // size of region
    flNewProtect, // desired access protection
    lpflOldProtect );// address of variable to get old protection

    ZeroMemory(buf, sizeof(buf));
    if( ReadProcessMemory( hProcess, lpBaseAddress, nSize, bufsize, buff ) == FALSE )
    {
    printf("
    Process ID %d ",pi.dwProcessId);
    printf (" memory read failed (errcode: %d)", GetLastError());
    printf("
    memory read:
    ",&buf);
    }
    else
    {
    printf("
    Process ID %d ",pi.dwProcessId);
    printf("memory read:
    ",buf);
    }
    return (0);
    }
    [/code]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories