May 03, 2024, 01:45:46 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


injecting DLL

Started by H.Brill, September 12, 2007, 11:10:26 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

H.Brill

i have a static lib. it can inject a DLL (see Res1).
first insert a resource into your program <project>  (id = 100, custom, DLL).
the first program shows me the function adresses,  but i have trouble
with dereferncing the adresses with the second programm (LVTest).
can anyone help me ?

the needed files are attached.


sapero

You need to declare the function pointer as UINT, not INTDEF pfnCreateListview, pfnShowListview, pfnIColumn : UINT
pfnCreateListview = GetProcAddressM(hmodule, "CreateListview")
pfnShowListview   = GetProcAddressM(hmodule, "ShowListview")
pfnIColumn        = GetProcAddressM(hmodule, "IColumn")

lv1 = !<CreateListview>pfnCreateListview(d1.hwnd, 0, 0, RGB(255, 255, 255), -1, &H31) /* why not 0x31 ? */
!<IColumn>pfnIColumn(lv1, sp1, 60, 0)
!<IColumn>pfnIColumn(lv1, sp2, 100, 0)
!<ShowListview>pfnShowListview(lv1, 10, 30, 200,100)

Before calling pfnCreateListview, your dialog must be created - call first "ShowDialog d1" or move pfnCreateListview (and the other calls) inside @IDINITDIALOG.
The second method:
SUB dialog_main
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
lv1 = !<CreateListview>pfnCreateListview(d1.hwnd, 0, 0, RGB(255, 255, 255), -1, &H31)
!<IColumn>pfnIColumn(lv1, sp1, 60, 0)
!<IColumn>pfnIColumn(lv1, sp2, 100, 0)
!<ShowListview>pfnShowListview(lv1, 10, 30, 200,100)
ENDSELECT
RETURN
ENDSUB

H.Brill

September 16, 2007, 03:05:49 AM #2 Last Edit: September 16, 2007, 03:12:07 AM by H.Brill
Thank you, i have resolved it and it works.


$Main
Type rows
  Def row1 : Pointer
  Def row2 : Pointer
EndType

$USE "PBOSL_LOADDLLMEMORY.lib"
DECLARE EXTERN LoadDLLM Alias _PB_LoadLibraryM@4(lmem as Memory), Int
DECLARE EXTERN GetProcAddressM Alias _PB_GetProcAddressM@8(hmodule as Int, Func as String),Int
DECLARE EXTERN FreLibraryM alias _PB_FreeLibraryM@4(hmodule as Int)

DECLARE CreateListview(f : Int, i : Int, t : Int, h : Int, g : Int, s : Int),Int
DECLARE IColumn(h : Int, t : String, b : Int, f : Int)
DECLARE SItem(h : Int, p : Memory, a : Int)
DECLARE ShowListview(h : Int, x : Int,y : Int, b : Int, h : Int)
DECLARE InitMessages(w : Int)
DECLARE EnableEdits(h : Int, f : Int)

DEF d1 as DIALOG
DEF success, hmodule, lv1 : Int
DEF adr : Int
DEF sp1, sp2, col1, clo2 as String
DEF p1, p2 : Pointer
DEF myrow : rows
DEF mem, buffer : Memory
DEF pfnCreateListview, pfnShowListview, pfnIColumn, pfnSItem, pfnInitMessages, pfnEnableEdits : UINT

success = LOADRESOURCE(100, "DLL", mem)
hmodule = LoadDLLM(mem)
AllocMem buffer, 1, Len(myrow)

pfnCreateListview = GetProcAddressM(hmodule, "CreateListview")
pfnShowListview   = GetProcAddressM(hmodule, "ShowListview")
pfnIColumn        = GetProcAddressM(hmodule, "IColumn")
pfnSItem          = GetProcAddressM(hmodule, "SItem")
pfnEnableEdits    = GetProcAddressM(hmodule, "EnableEdits")
pfnInitMessages   = GetProcAddressM(hmodule, "InitMessages")

sp1 = "Nummer"
sp2 = "Name"

CREATEDIALOG d1,0,0,600,500,0x80C80080, 0, "LV Test", &dialog_main
CONTROL d1,@BUTTON,"Ende",10,10,60,20,0, 1
CONTROL d1,@BUTTON,"Insert",180,10,60,20,0, 2
CONTROL d1,@STATIC,"Nummer :", 180, 40, 80, 20, 0, 3
CONTROL d1,@STATIC,"Name   :", 180, 70, 180,20, 0, 4
CONTROL d1,@EDIT, "", 280, 40, 100, 20, 0, 5
CONTROL d1,@EDIT, "", 280, 70, 180, 20, 0, 6
DOMODAL d1

FreLibraryM(hmodule)
FreeMem(mem)
FreeMem(buffer)

END

SUB dialog_main
SELECT @MESSAGE
    CASE @IDINITDIALOG
                 CENTERWINDOW d1
lv1 = !<CreateListview>pfnCreateListview(d1.hwnd, 0, 0, RGB(255, 255, 255), -1, &H31)
!<IColumn>pfnIColumn(lv1, sp1, 100, 0)
!<IColumn>pfnIColumn(lv1, sp2, 440, 0)
!<EnableEdits>pfnEnableEdits(lv1, 1 + 16)
!<InitMessages>pfnInitMessages(d1.hwnd)
!<ShowListview>pfnShowListview(lv1, 10, 100, 580,300)
    CASE @IDCONTROL
        SELECT @CONTROLID
            CASE 1
                 CLOSEDIALOG d1,@IDOK
            CASE 2
   col1 = GETCONTROLTEXT(d1, 5)
   col2 = GETCONTROLTEXT(d1, 6)
   p1 = col1
   p2 = col2
   myrow.row1 = p1
                   myrow.row2 = p2
                   WriteMem buffer, 1, myrow
                   !<SItem>pfnSItem(lv1, buffer, 2)
        ENDSELECT
    CASE @IDCLOSEWINDOW
            CLOSEDIALOG d1, @IDOK
ENDSELECT
RETURN
ENDSUB