Solved

HELP need to call function from another exe

Posted on 2004-10-26
425 Views
Last Modified: 2010-05-18
i need to call a function from another .exe file .. which i dont have the source for

i disassembled the .exe and found the function i need so much .. tried to export disassembled output to an .asm file .. and with some effort compiled it into a new .exe .. but by old ida happened to have bugs .. disassembling wrong opcodes
whatever this doesnt make sense to me neither ..

i have a .exe file .. and want to write a program that .. calls a function within that .exe file and gets the output .. all i know is the offset to the function

the function i need to call .. uses 1 stack and 3 register parameters
i believe the program was built under delphi

x86/windows/masm32

thanks in advance
0
Question by:skumria
    7 Comments
     
    LVL 12

    Expert Comment

    by:stefan73
    Hi skumria,
    Be aware that disassembling existing programs to re-engineer their functions is illegal in many countries. We can't help you there.

    Cheers!

    Stefan
    0
     
    LVL 1

    Author Comment

    by:skumria
    :) luckily in my country (bulgaria) its still legal

    ok another scenario .. i write an exe file with function and try to call it from another .exe ?
    0
     
    LVL 12

    Expert Comment

    by:stefan73
    skumria,

    This is tricky. The PE loader has to load the other exe, then you can mount its memory by ReadProcessMemory()
    (see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/readprocessmemory.asp) - BUT: As all process base addresses are in the same area and the code of the function won't be position-independent, you probably won't be able to map it at its original address. Also, mounting it won't give you write access to the other process. And the other process may not allow you to read its memory at all (it's a security problem to allow this).
    0
     
    LVL 16

    Expert Comment

    by:PaulCaswell
    >>which i dont have the source for
    Do you have any .lib or .obj files that make up the .EXE?

    A second option:

    In your program, malloc enough memory to fit the other EXE.
    Read the EXE into your memory.
    typedef a function pointer of the correct type and point it at the correct offset in the EXE.
    Call it.

    Paul
    0
     
    LVL 16

    Assisted Solution

    by:PaulCaswell
    Note: If you use my method, any linker fixups will not be performed.
    This method will only work if the function you call only calls functions with relative addresses and does not require access to any data.

    Paul
    0
     
    LVL 12

    Accepted Solution

    by:
    Yes, that's the problem. The linker fixups are necessary, but by default, you'll get overlapping address spaces for your own and the other exe.

    Perhaps it's worthwile to think about looking at the PE link format? It might be possible to merge the other exe to yours, so both are loaded properly and non-overlapping when you start your program.

    It'll be quite some work, though.
    0
     
    LVL 1

    Author Comment

    by:skumria
    >Perhaps it's worthwile to think about looking at the PE link format? It might be possible >o merge the other exe to yours, so both are loaded properly and non-overlapping >when you start your program.

    have to try that .. as soon as i have the time

    to Paul .. the program needed to set its memory space which involved some decoding

    anyway .. the easiest way i found on the net is the CreateRemoteThread/LoadLibrary technique .. backed with some read/writeprocessmemory calls it turned not to be that hard


    5.am here falling asleep sowwy about english
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    Help with X86_64 Assembly commands 20 1,537
    Change Characters to Hex 15 423
    Why does je branch when they are not equal? 2 308
    What does this assembly code do 4 423
    New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
    It’s an age old story, whether you’re looking for full-time employment or contract work. In order to land a job, you must have experience.
    Want to pick and choose which updates you receive? Feel free to check out this quick video on how to manage your email notifications.
    Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    931 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now