Help for sending packets

05/11/2012 03:54 rufat2005#1
Hello Dear programmers, botovody!
I am a novice programmer, and started programming in the language of Delphi!
there is a couple of my works [Only registered and activated users can see links. Click Here To Register...]!
But another question!
I would like to implement the sending of packages to craft nirvana clothing, weapons. But I have a problem with traffic light emitted from the fact that the package that I send a very large ie 256 characters!
Please help or point me where to look! that used
вот код которым я пользуюсь :
Code:
///////////////////////////////////////////////////
procedure InjectFunc(ProcessID: Cardinal; Func: Pointer; aParams: Pointer; aParamsSize: DWORD);
var
  hThread: THandle;
  lpNumberOfBytes: DWORD;

  ThreadAddr, ParamAddr: Pointer;
begin
  if ProcessID<>0 then
  begin
    // ---- Write function address
    ThreadAddr := VirtualAllocEx(ProcessID, nil, 438, MEM_COMMIT or MEM_RESERVE, PAGE_EXECUTE_READWRITE);
    WriteProcessMemory(ProcessID, ThreadAddr, Func, 438, lpNumberOfBytes);

    // ---- Address to write parameters
    ParamAddr := VirtualAllocEx(ProcessID, nil, aParamsSize, MEM_COMMIT or MEM_RESERVE, PAGE_EXECUTE_READWRITE);
    WriteProcessMemory(ProcessID, ParamAddr, aParams, aParamsSize, lpNumberOfBytes);

    // ---- Create a remote thread
    hThread := CreateRemoteThread(ProcessID, nil, 0, ThreadAddr, ParamAddr, 0, lpNumberOfBytes);

    // ---- Thread to wait for the end of
    WaitForSingleObject(hThread, 3000);

    VirtualFreeEx(ProcessID,ThreadAddr,0,MEM_RELEASE);
    VirtualFreeEx(ProcessID,ParamAddr,0,MEM_RELEASE);
    VirtualFreeEx(ProcessID,Func,0,MEM_RELEASE);
    VirtualFreeEx(ProcessID,aParams,0,MEM_RELEASE);

    CloseHandle(hThread);
  end
end;

//////////////////////////////////////////////////////////////
procedure PacketCall(aPParams:PParams); stdcall;
var
CallAddress,pPacket,_BASE_ADD_,_Ofs,_SendPacket:Pointer;
Len:DWord;
begin
_SendPacket:=aPParams^.SendPacket;
CallAddress:=Pointer(_SendPacket); //адрес был устаревший
Len:=aPParams^.Param1;
_BASE_ADD_:=aPParams^.BASE_ADD;
_Ofs:=aPParams^.Ofs;
pPacket:=@aPParams^.Packet;
 asm
 pushad
 mov ecx, _BASE_ADD_
 mov ecx, dword ptr [ecx]
 mov esi, _Ofs
 mov ecx, dword ptr [ecx+esi] //20
 push Len
 push pPacket
 call CallAddress
 popad
 end;
end;

procedure StrToByte(Packet:string; var aParams:TParams);
var
i:integer;
begin
i:=(length(Packet) div 2)-1;
aParams.Param1:=i+1;
 for i:=0 to i do
 aParams.Packet[i]:=strtoint('$'+Packet[i*2+1]+Packet[i*2+2]);
end;

procedure Packet(Packet: string);
var
aParams: TParams;
  PID, hProcess: DWord;
begin
  aParams.BASE_ADD := Pointer(BASE_ADD);
  aParams.Ofs :=Pointer(OffSets_Uchastvuelvotpravkepaketa);
  aParams.SendPacket:= Pointer(OffSets_SendPacket);
  GetWindowThreadProcessId(WID, @PID);
  hProcess:=OpenProcess(PROCESS_ALL_ACCESS, False, PID);
StrToByte(Packet,aParams);
InjectFunc(hProcess,@PacketCall,@aParams,sizeof(aParams));
CloseHandle(hProcess); //забыл дописать
end;
Thanks in advance! And sorry for my bad english .. I just do not know the English language and simply translated using google
05/11/2012 12:00 Sᴡoosh#2
Did you set breakpoint on CreateRemoteThread and checked ingame if functions/parameters where written correctly? I didn't check your whole source - just some things I noticed at first glance :

Code:
    VirtualFreeEx(ProcessID,Func,0,MEM_RELEASE);
    VirtualFreeEx(ProcessID,aParams,0,MEM_RELEASE);
Not needed, this is a local variable reference - you can leave this out. You only need to free the forgein ram again, which you did here :

Code:
    VirtualFreeEx(ProcessID,ThreadAddr,0,MEM_RELEASE);
    VirtualFreeEx(ProcessID,ParamAddr,0,MEM_RELEASE);
Why do you use string as parameter for your packet function? And why do you allocate exactly 438 byte for function? Seems a bit high to me - but certainly not the cause of crash.

Best for you really is to do what I suggested at start - set breakpoint and check if all is written well before you CRT it.

Cheers