Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in /home/iano/public_html/tpforums-vb5/forum/includes/class_core.php on line 5842

PHP Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_BOTH - assumed 'MYSQL_BOTH' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 588

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 612

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6
How could I use a procedure from .dll? I really need help.
Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: How could I use a procedure from .dll? I really need help.

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    19

    How could I use a procedure from .dll? I really need help.

    Hi.
    I found this topic: http://tpforums.org/forum/threads/40...Tibia-internal and I would like to write it in my .dll and when I want I would like to use this procedure in my .exe file.

    I've got a lot problems with that, so I will be grateful when someone will just look at this.

    That's the code of my current dll:
    Code:
     library oskar;
     
    uses
      SysUtils,
      Classes,
      Messages,
      Windows;
     
    {$R *.res}
     
    procedure FSpeech(AType: Byte; AText:PChar); cdecl; export;
     
    const
      Adr = $004073F0; //8.60
     
    var
      FSpeech: procedure(AType: Byte; AText:PChar);
     
    begin
      @FSpeech := Ptr(Adr);
     
    end;
     
    exports
    FSpeech;
    end.
    I calling this procedure in my exe by using this code:
    Code:
    procedure FSpeech(AType: Byte; AText:PChar); cdecl; external 'oskar.dll';
    I trying to use it by clicking on button. That's what I've got on my button:
    fspeech(1,'help me');

    I think that everything looks normal and it should be work, but it isn't. Could someone help me?

    Thanks.


    @@Edit
    If anything is not able to understand please tell me. I will try to make it easier to understand. My english is not perfect (especially when I am drunk). xD
    Last edited by Dronic; 06-01-2014 at 04:42 PM.

  2. #2
    Senior Member
    Join Date
    Dec 2011
    Posts
    249
    You need to inject the DLL or call the internal procedure using codecaves and CreateRemoteThread

  3. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    19
    Okay. So you just saying that everything is fine with my dll, but I have to inject it, yes?
    As I said I calling my .dll file by using this code: procedure FSpeech(AType: Byte; AText:PChar); cdecl; external 'oskar.dll';
    I think it should be enough. We're not injecting packet.dll into your client, we just calling function written inside. I used same method.

  4. #4
    Senior Member
    Join Date
    Dec 2011
    Posts
    249
    If you look at the link you posted you can see an example of how the DLL should like and how you inject it

  5. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    19
    The problem is that my .dll cannot looks like this one from the link what I posted. I would like to use this function when I will click on button. To do it I should make a procedure what I could call whenever I want.

  6. #6
    Senior Member
    Join Date
    Dec 2011
    Posts
    249
    It looks like you're just exporting the DLL function. This won't work. You need to inject the DLL.

  7. #7
    Senior Member
    Join Date
    Jan 2012
    Posts
    417
    if I understood you correctly, you just want to expose Tibias functions through an injected dll to your main program outside the dll.

    You can create a named pipe between your .exe <-> injected dll to call functions, talk to each other and so on (if I'm not wrong, TibiaApi does this way). Alternatively, as ottizy said, CreateRemoteThread and call the internal function (ex: at $004073F0) directly without inject a dll, just by allocating and freeing memory to push parameters and bytes to the function call (sometimes called codecave) with VirtualAllocEx and VirtualFreeEx.

    Either way, you have to pay attention to the packet sender thread (stop it, execute the procedure, resume it) to prevent race conditions and so on.

  8. #8
    Junior Member
    Join Date
    Mar 2014
    Posts
    19
    I am able to use packet.dll and it's so easy to send packets to the game by this way
    I really want to do it by injecting dll, but if there is no chance (or it's harder) could you tell me more about CreateRemoteThread in delphi? Maybe any tutorial/example ?


    By the way. That's how my
    Code:
     unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Edit1: TEdit;
        Button3: TButton;
        Button4: TButton;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
      PID:Cardinal;
      hWndF:hwnd;
    
    
    implementation
    Procedure FSpeech (TalkMode: Integer;Text: Pchar);cdecl ;external 'say.dll';
    {$R *.dfm}
    
    procedure InjectDll(PID: dword;  DLL: pChar);
    var
      BytesWritten, hProcess, hThread, TID: Cardinal;
      Parameters: pointer;
      pThreadStartRoutine: Pointer;
    begin
      hProcess := OpenProcess(PROCESS_ALL_ACCESS,  False,  PID);
      Parameters := VirtualAllocEx( hProcess, nil, Length(DLL)+1, MEM_COMMIT or MEM_RESERVE, PAGE_READWRITE);
      WriteProcessMemory(hProcess,Parameters,Pointer(DLL),Length(DLL)+1,BytesWritten);
      pThreadStartRoutine := GetProcAddress(GetModuleHandle('KERNEL32.DLL'), 'LoadLibraryA');
      hThread := CreateRemoteThread(hProcess,  nil,  0,  pThreadStartRoutine,  Parameters,  0,  TID);
      CloseHandle(hProcess);
    end;
    
    
    
    
    
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      hwndf:=findwindow(nil,'Tibia');
      Getwindowthreadprocessid(hwndf,@PID);
    InjectDll(PID,pchar(ExtractFilePath(Application.ExeName)+'say.dll'));
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    FSpeech(1,'lolek');
    end;
    
    
    end.
    and that's how my .dll looks like:

    Code:
     library say;
     
    uses
      SysUtils,
      Classes,
      Messages,
      Windows;
     
    {$R *.res}
    
    
     
     
    procedure FSpeech (AType: Byte; AText:PChar); cdecl;
    const
      Adr = $004073F0;
    var
      FSpeech: procedure(AType: Byte; AText:PChar); cdecl;
    
    begin
      @FSpeech := Ptr(Adr);
    end;
     
    exports
    FSpeech;
    end.
    And one more think. As you said exacly I would like to export the procedure from .dll and I want to use this procedure in my .exe by clicking on button.
    Last edited by Dronic; 06-02-2014 at 04:09 PM.

  9. #9
    Senior Member
    Join Date
    Dec 2011
    Posts
    249
    It won't work to export the function from the DLL when it's injected. Like Blequi said, you can use named pipes to interact with the DLL while it's injected.

  10. #10
    Junior Member
    Join Date
    Mar 2014
    Posts
    19
    What the *** are named pipes ? xD How it works ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •