Thread: Help calling function is asm

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    61

    Help calling function is asm

    How would i call this in inline asm?
    Code:
    ZPostShotSp
    -----------
    00478890  /$ 64:A1 00000000 MOV EAX,DWORD PTR FS:[0]
    00478896  |. 6A FF          PUSH -1
    00478898  |. 68 57A15D00    PUSH Gunz.005DA157
    0047889D  |. 50             PUSH EAX
    0047889E  |. 64:8925 000000>MOV DWORD PTR FS:[0],ESP
    004788A5  |. 83EC 10        SUB ESP,10
    004788A8  |. 53             PUSH EBX
    004788A9  |. 55             PUSH EBP
    004788AA  |. 56             PUSH ESI
    004788AB  |. 57             PUSH EDI
    004788AC  |. 68 33270000    PUSH 2733
    004788B1  |. E8 EADD0400    CALL Gunz.004C66A0
    004788B6  |. 8B1D 80735E00  MOV EBX,DWORD PTR DS:[5E7380]
    004788BC  |. 83C4 04        ADD ESP,4
    004788BF  |. 68 B4876600    PUSH Gunz.006687B4
    004788C4  |. 8BF8           MOV EDI,EAX
    004788C6  |. FFD3           CALL EBX
    004788C8  |. 8B35 B0876600  MOV ESI,DWORD PTR DS:[6687B0]
    004788CE  |. 85F6           TEST ESI,ESI
    004788D0  |. 74 0A          JE SHORT Gunz.004788DC
    004788D2  |. 8B46 08        MOV EAX,DWORD PTR DS:[ESI+8]
    004788D5  |. A3 B0876600    MOV DWORD PTR DS:[6687B0],EAX
    004788DA  |. EB 0C          JMP SHORT Gunz.004788E8
    004788DC  |> 6A 10          PUSH 10
    004788DE  |. E8 C2771500    CALL Gunz.005D00A5
    004788E3  |. 83C4 04        ADD ESP,4
    004788E6  |. 8BF0           MOV ESI,EAX
    004788E8  |> 68 B4876600    PUSH Gunz.006687B4
    004788ED  |. FF15 84735E00  CALL DWORD PTR DS:[5E7384]
    004788F3  |. 897424 18      MOV DWORD PTR SS:[ESP+18],ESI
    004788F7  |. 85F6           TEST ESI,ESI
    004788F9  |. C74424 28 0000>MOV DWORD PTR SS:[ESP+28],0
    00478901  |. 74 24          JE SHORT Gunz.00478927
    00478903  |. 8B0D 78DC6600  MOV ECX,DWORD PTR DS:[66DC78]
    00478909  |. 8B41 30        MOV EAX,DWORD PTR DS:[ECX+30]
    0047890C  |. 8B50 18        MOV EDX,DWORD PTR DS:[EAX+18]
    0047890F  |. 8B40 0C        MOV EAX,DWORD PTR DS:[EAX+C]
    00478912  |. 8B0490         MOV EAX,DWORD PTR DS:[EAX+EDX*4]
    00478915  |. 8B08           MOV ECX,DWORD PTR DS:[EAX]
    00478917  |. 8BD1           MOV EDX,ECX
    00478919  |. 894C24 10      MOV DWORD PTR SS:[ESP+10],ECX
    0047891D  |. 52             PUSH EDX
    0047891E  |. 8BCE           MOV ECX,ESI
    00478920  |. E8 8B190900    CALL Gunz.0050A2B0
    00478925  |. EB 02          JMP SHORT Gunz.00478929
    00478927  |> 33C0           XOR EAX,EAX
    00478929  |> 83CD FF        OR EBP,FFFFFFFF
    0047892C  |. 50             PUSH EAX
    0047892D  |. 8BCF           MOV ECX,EDI
    0047892F  |. 896C24 2C      MOV DWORD PTR SS:[ESP+2C],EBP
    00478933  |. E8 A8380900    CALL Gunz.0050C1E0
    00478938  |. 68 D0876600    PUSH Gunz.006687D0
    0047893D  |. FFD3           CALL EBX
    0047893F  |. 8B35 CC876600  MOV ESI,DWORD PTR DS:[6687CC]
    00478945  |. 85F6           TEST ESI,ESI
    00478947  |. 74 0A          JE SHORT Gunz.00478953
    00478949  |. 8B46 14        MOV EAX,DWORD PTR DS:[ESI+14]
    0047894C  |. A3 CC876600    MOV DWORD PTR DS:[6687CC],EAX
    00478951  |. EB 0C          JMP SHORT Gunz.0047895F
    00478953  |> 6A 18          PUSH 18
    00478955  |. E8 4B771500    CALL Gunz.005D00A5
    0047895A  |. 83C4 04        ADD ESP,4
    0047895D  |. 8BF0           MOV ESI,EAX
    0047895F  |> 68 D0876600    PUSH Gunz.006687D0
    00478964  |. FF15 84735E00  CALL DWORD PTR DS:[5E7384]
    0047896A  |. 897424 1C      MOV DWORD PTR SS:[ESP+1C],ESI
    0047896E  |. 85F6           TEST ESI,ESI
    00478970  |. C74424 28 0100>MOV DWORD PTR SS:[ESP+28],1
    00478978  |. 74 31          JE SHORT Gunz.004789AB
    0047897A  |. 8B4424 30      MOV EAX,DWORD PTR SS:[ESP+30]
    0047897E  |. 8B48 08        MOV ECX,DWORD PTR DS:[EAX+8]
    00478981  |. 8B50 04        MOV EDX,DWORD PTR DS:[EAX+4]
    00478984  |. 8B00           MOV EAX,DWORD PTR DS:[EAX]
    00478986  |. 51             PUSH ECX
    00478987  |. 52             PUSH EDX
    00478988  |. 894C24 18      MOV DWORD PTR SS:[ESP+18],ECX
    0047898C  |. 50             PUSH EAX
    0047898D  |. 8BCE           MOV ECX,ESI
    0047898F  |. 895424 20      MOV DWORD PTR SS:[ESP+20],EDX
    00478993  |. 894424 24      MOV DWORD PTR SS:[ESP+24],EAX
    00478997  |. E8 741B0900    CALL Gunz.0050A510
    0047899C  |. C706 D4145F00  MOV DWORD PTR DS:[ESI],Gunz.005F14D4
    004789A2  |. C746 04 060000>MOV DWORD PTR DS:[ESI+4],6
    004789A9  |. EB 02          JMP SHORT Gunz.004789AD
    004789AB  |> 33F6           XOR ESI,ESI
    004789AD  |> 56             PUSH ESI
    004789AE  |. 8BCF           MOV ECX,EDI
    004789B0  |. 896C24 2C      MOV DWORD PTR SS:[ESP+2C],EBP
    004789B4  |. E8 27380900    CALL Gunz.0050C1E0
    004789B9  |. 6A 14          PUSH 14
    004789BB  |. E8 E5761500    CALL Gunz.005D00A5
    004789C0  |. 83C4 04        ADD ESP,4
    004789C3  |. 894424 1C      MOV DWORD PTR SS:[ESP+1C],EAX
    004789C7  |. 85C0           TEST EAX,EAX
    004789C9  |. C74424 28 0200>MOV DWORD PTR SS:[ESP+28],2
    004789D1  |. 74 18          JE SHORT Gunz.004789EB
    004789D3  |. 8B4C24 34      MOV ECX,DWORD PTR SS:[ESP+34]
    004789D7  |. 8B51 08        MOV EDX,DWORD PTR DS:[ECX+8]
    004789DA  |. 52             PUSH EDX
    004789DB  |. 8B51 04        MOV EDX,DWORD PTR DS:[ECX+4]
    004789DE  |. 8B09           MOV ECX,DWORD PTR DS:[ECX]
    004789E0  |. 52             PUSH EDX
    004789E1  |. 51             PUSH ECX
    004789E2  |. 8BC8           MOV ECX,EAX
    004789E4  |. E8 271B0900    CALL Gunz.0050A510
    004789E9  |. EB 02          JMP SHORT Gunz.004789ED
    004789EB  |> 33C0           XOR EAX,EAX
    004789ED  |> 50             PUSH EAX
    004789EE  |. 8BCF           MOV ECX,EDI
    004789F0  |. 896C24 2C      MOV DWORD PTR SS:[ESP+2C],EBP
    004789F4  |. E8 E7370900    CALL Gunz.0050C1E0
    004789F9  |. 68 E8746600    PUSH Gunz.006674E8
    004789FE  |. FFD3           CALL EBX
    00478A00  |. 8B35 E4746600  MOV ESI,DWORD PTR DS:[6674E4]
    00478A06  |. 85F6           TEST ESI,ESI
    00478A08  |. 74 0B          JE SHORT Gunz.00478A15
    00478A0A  |. 8B56 08        MOV EDX,DWORD PTR DS:[ESI+8]
    00478A0D  |. 8915 E4746600  MOV DWORD PTR DS:[6674E4],EDX
    00478A13  |. EB 0C          JMP SHORT Gunz.00478A21
    00478A15  |> 6A 10          PUSH 10
    00478A17  |. E8 89761500    CALL Gunz.005D00A5
    00478A1C  |. 83C4 04        ADD ESP,4
    00478A1F  |. 8BF0           MOV ESI,EAX
    00478A21  |> 68 E8746600    PUSH Gunz.006674E8
    00478A26  |. FF15 84735E00  CALL DWORD PTR DS:[5E7384]
    00478A2C  |. 897424 1C      MOV DWORD PTR SS:[ESP+1C],ESI
    00478A30  |. 85F6           TEST ESI,ESI
    00478A32  |. C74424 28 0300>MOV DWORD PTR SS:[ESP+28],3
    00478A3A  |. 74 0E          JE SHORT Gunz.00478A4A
    00478A3C  |. 8B4424 38      MOV EAX,DWORD PTR SS:[ESP+38]
    00478A40  |. 50             PUSH EAX
    00478A41  |. 8BCE           MOV ECX,ESI
    00478A43  |. E8 B8160900    CALL Gunz.0050A100
    00478A48  |. EB 02          JMP SHORT Gunz.00478A4C
    00478A4A  |> 33C0           XOR EAX,EAX
    00478A4C  |> 50             PUSH EAX
    00478A4D  |. 8BCF           MOV ECX,EDI
    00478A4F  |. 896C24 2C      MOV DWORD PTR SS:[ESP+2C],EBP
    00478A53  |. E8 88370900    CALL Gunz.0050C1E0
    00478A58  |. 68 E8746600    PUSH Gunz.006674E8
    00478A5D  |. FFD3           CALL EBX
    00478A5F  |. 8B35 E4746600  MOV ESI,DWORD PTR DS:[6674E4]
    00478A65  |. 85F6           TEST ESI,ESI
    00478A67  |. 74 0B          JE SHORT Gunz.00478A74
    00478A69  |. 8B4E 08        MOV ECX,DWORD PTR DS:[ESI+8]
    00478A6C  |. 890D E4746600  MOV DWORD PTR DS:[6674E4],ECX
    00478A72  |. EB 0C          JMP SHORT Gunz.00478A80
    00478A74  |> 6A 10          PUSH 10
    00478A76  |. E8 2A761500    CALL Gunz.005D00A5
    00478A7B  |. 83C4 04        ADD ESP,4
    00478A7E  |. 8BF0           MOV ESI,EAX
    00478A80  |> 68 E8746600    PUSH Gunz.006674E8
    00478A85  |. FF15 84735E00  CALL DWORD PTR DS:[5E7384]
    00478A8B  |. 897424 1C      MOV DWORD PTR SS:[ESP+1C],ESI
    00478A8F  |. 85F6           TEST ESI,ESI
    00478A91  |. C74424 28 0400>MOV DWORD PTR SS:[ESP+28],4
    00478A99  |. 74 0E          JE SHORT Gunz.00478AA9
    00478A9B  |. 8B5424 3C      MOV EDX,DWORD PTR SS:[ESP+3C]
    00478A9F  |. 52             PUSH EDX
    00478AA0  |. 8BCE           MOV ECX,ESI
    00478AA2  |. E8 59160900    CALL Gunz.0050A100
    00478AA7  |. EB 02          JMP SHORT Gunz.00478AAB
    00478AA9  |> 33C0           XOR EAX,EAX
    00478AAB  |> 50             PUSH EAX
    00478AAC  |. 8BCF           MOV ECX,EDI
    00478AAE  |. 896C24 2C      MOV DWORD PTR SS:[ESP+2C],EBP
    00478AB2  |. E8 29370900    CALL Gunz.0050C1E0
    00478AB7  |. 57             PUSH EDI
    00478AB8  |. E8 23CF0400    CALL Gunz.004C59E0
    00478ABD  |. 8B4C24 24      MOV ECX,DWORD PTR SS:[ESP+24]
    00478AC1  |. 83C4 04        ADD ESP,4
    00478AC4  |. 5F             POP EDI
    00478AC5  |. 5E             POP ESI
    00478AC6  |. 5D             POP EBP
    00478AC7  |. 5B             POP EBX
    00478AC8  |. 64:890D 000000>MOV DWORD PTR FS:[0],ECX
    00478ACF  |. 83C4 1C        ADD ESP,1C
    00478AD2  \. C3             RETN
    
    0052EBEF  |. 68 74196000    PUSH Gunz.00601974                       ;  ASCII "ShotSp"
    0052EBF4  |. 68 64196000    PUSH Gunz.00601964                       ;  ASCII "Peer.Shot.Sp"
    0052EBF9  |. 68 33270000    PUSH 2733
    0052EBFE  |. 8BC8           MOV ECX,EAX
    0052EC00  |. E8 8BD3FDFF    CALL Gunz.0050BF90
    0052EC05  |. 8BF8           MOV EDI,EAX
    0052EC07  |. EB 02          JMP SHORT Gunz.0052EC0B
    0052EC09  |> 33FF           XOR EDI,EDI
    0052EC0B  |> 57             PUSH EDI                                 ; /Arg1
    0052EC0C  |. 8BCD           MOV ECX,EBP                              ; |
    0052EC0E  |. 897424 24      MOV DWORD PTR SS:[ESP+24],ESI            ; |
    0052EC12  |. E8 E9A7FEFF    CALL Gunz.00519400                       ; \Gunz.00519400
    0052EC17  |. 6A 58          PUSH 58
    0052EC19  |. E8 87140A00    CALL Gunz.005D00A5
    0052EC1E  |. 83C4 04        ADD ESP,4
    0052EC21  |. 894424 14      MOV DWORD PTR SS:[ESP+14],EAX
    0052EC25  |. 85C0           TEST EAX,EAX
    0052EC27  |. C74424 20 5503>MOV DWORD PTR SS:[ESP+20],355
    0052EC2F  |. 74 10          JE SHORT Gunz.0052EC41
    0052EC31  |. 68 8CC35E00    PUSH Gunz.005EC38C                       ;  ASCII "Time"
    0052EC36  |. 6A 02          PUSH 2
    0052EC38  |. 8BC8           MOV ECX,EAX
    0052EC3A  |. E8 C1C8FDFF    CALL Gunz.0050B500
    0052EC3F  |. EB 02          JMP SHORT Gunz.0052EC43
    0052EC41  |> 33C0           XOR EAX,EAX
    0052EC43  |> 50             PUSH EAX
    0052EC44  |. 8BCF           MOV ECX,EDI
    0052EC46  |. 897424 24      MOV DWORD PTR SS:[ESP+24],ESI
    0052EC4A  |. E8 31DDFDFF    CALL Gunz.0050C980
    0052EC4F  |. 6A 58          PUSH 58
    0052EC51  |. E8 4F140A00    CALL Gunz.005D00A5
    0052EC56  |. 83C4 04        ADD ESP,4
    0052EC59  |. 894424 14      MOV DWORD PTR SS:[ESP+14],EAX
    0052EC5D  |. 85C0           TEST EAX,EAX
    0052EC5F  |. C74424 20 5603>MOV DWORD PTR SS:[ESP+20],356
    0052EC67  |. 74 10          JE SHORT Gunz.0052EC79
    0052EC69  |. 68 C4456000    PUSH Gunz.006045C4                       ;  ASCII "Position"
    0052EC6E  |. 6A 06          PUSH 6
    0052EC70  |. 8BC8           MOV ECX,EAX
    0052EC72  |. E8 89C8FDFF    CALL Gunz.0050B500
    0052EC77  |. EB 02          JMP SHORT Gunz.0052EC7B
    0052EC79  |> 33C0           XOR EAX,EAX
    0052EC7B  |> 50             PUSH EAX
    0052EC7C  |. 8BCF           MOV ECX,EDI
    0052EC7E  |. 897424 24      MOV DWORD PTR SS:[ESP+24],ESI
    0052EC82  |. E8 F9DCFDFF    CALL Gunz.0050C980
    0052EC87  |. 6A 58          PUSH 58
    0052EC89  |. E8 17140A00    CALL Gunz.005D00A5
    0052EC8E  |. 83C4 04        ADD ESP,4
    0052EC91  |. 894424 14      MOV DWORD PTR SS:[ESP+14],EAX
    0052EC95  |. 85C0           TEST EAX,EAX
    0052EC97  |. C74424 20 5703>MOV DWORD PTR SS:[ESP+20],357
    0052EC9F  |. 74 10          JE SHORT Gunz.0052ECB1
    0052ECA1  |. 68 B8456000    PUSH Gunz.006045B8                       ;  ASCII "Direction"
    0052ECA6  |. 6A 05          PUSH 5
    0052ECA8  |. 8BC8           MOV ECX,EAX
    0052ECAA  |. E8 51C8FDFF    CALL Gunz.0050B500
    0052ECAF  |. EB 02          JMP SHORT Gunz.0052ECB3
    0052ECB1  |> 33C0           XOR EAX,EAX
    0052ECB3  |> 50             PUSH EAX
    0052ECB4  |. 8BCF           MOV ECX,EDI
    0052ECB6  |. 897424 24      MOV DWORD PTR SS:[ESP+24],ESI
    0052ECBA  |. E8 C1DCFDFF    CALL Gunz.0050C980
    0052ECBF  |. 6A 58          PUSH 58
    0052ECC1  |. E8 DF130A00    CALL Gunz.005D00A5
    0052ECC6  |. 83C4 04        ADD ESP,4
    0052ECC9  |. 894424 14      MOV DWORD PTR SS:[ESP+14],EAX
    0052ECCD  |. 85C0           TEST EAX,EAX
    0052ECCF  |. C74424 20 5803>MOV DWORD PTR SS:[ESP+20],358
    0052ECD7  |. 74 10          JE SHORT Gunz.0052ECE9
    0052ECD9  |. 68 24556000    PUSH Gunz.00605524                       ;  ASCII "Type"
    0052ECDE  |. 6A 00          PUSH 0
    0052ECE0  |. 8BC8           MOV ECX,EAX
    0052ECE2  |. E8 19C8FDFF    CALL Gunz.0050B500
    0052ECE7  |. EB 02          JMP SHORT Gunz.0052ECEB
    0052ECE9  |> 33C0           XOR EAX,EAX
    0052ECEB  |> 50             PUSH EAX
    0052ECEC  |. 8BCF           MOV ECX,EDI
    0052ECEE  |. 897424 24      MOV DWORD PTR SS:[ESP+24],ESI
    0052ECF2  |. E8 89DCFDFF    CALL Gunz.0050C980
    0052ECF7  |. 6A 58          PUSH 58
    0052ECF9  |. E8 A7130A00    CALL Gunz.005D00A5
    0052ECFE  |. 83C4 04        ADD ESP,4
    0052ED01  |. 894424 14      MOV DWORD PTR SS:[ESP+14],EAX
    0052ED05  |. 85C0           TEST EAX,EAX
    0052ED07  |. C74424 20 5903>MOV DWORD PTR SS:[ESP+20],359
    0052ED0F  |. 74 10          JE SHORT Gunz.0052ED21
    0052ED11  |. 68 5C196000    PUSH Gunz.0060195C                       ;  ASCII "SelType"
    0052ED16  |. 6A 00          PUSH 0
    0052ED18  |. 8BC8           MOV ECX,EAX
    0052ED1A  |. E8 E1C7FDFF    CALL Gunz.0050B500
    0052ED1F  |. EB 02          JMP SHORT Gunz.0052ED23
    0052ED21  |> 33C0           XOR EAX,EAX
    0052ED23  |> 50             PUSH EAX
    0052ED24  |. 8BCF           MOV ECX,EDI
    it tried:
    Code:
    void ZPostShotSp()
    {
             float Pos[3] = {0,0,0};
             float Dir[3] = {0,0,0};
             _asm{
                      pushad
                      mov eax,0x00478890
                      PUSH 7 //SelType
                      PUSH 2 //Type
                      PUSH Dir //Direction
                      PUSH Pos //Position
                      call eax
                      add esp,16
                      popad
              }
    }
    But it's making me crash..

  2. #2
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144

    Try this

    According to my textbook, if your compiler recognizes "asm" as an extension, you can add your asm staements DIRECTLY into your program thusly:

    Code:
    void func()
    {
    .
    .
    .
         asm       move AX, 88
         asm       out 20,    AX
         asm       out 21,    AX
    
    .
    .
    .
    
    and so on
    
    }
    Some compilers may recognize _asm or __asm. If possible check your compiler. But this is supposed to standard within C++ ANSI.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It's best to do:
    Code:
    mov eax, function_name_here;
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Some compilers may recognize _asm or __asm. If possible check your compiler. But this is supposed to standard within C++ ANSI.
    I have zero experience with (and almost no knowledge about, for that matter) embedding assembly code in C++, but it seems to be that that is incorrect. The 2003 edition of the C++ states and an asm declaration has the form:
    Code:
    asm-definition:
        asm ( string-literal ) ;
    So the use of the asm keyword as you have described is non-standard, which is probably why __asm and _asm are more likely used (names with double underscores are reserved to the implementation for any use, and names that begin with an underscore not followed by an uppercase letter or another underscore are reserved to the implementation for use in the global namespace).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Jul 2007
    Posts
    61
    Quote Originally Posted by Elysia View Post
    It's best to do:
    Code:
    mov eax, function_name_here;
    schould I just do
    Code:
    #define function_name_here 0xTheAddr
    Then?

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, if you want to call a function, then replace function_name_here with actual name of the function you're going to call (from assembly)!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    What's wrong with
    Code:
    typedef void (*func_ptr_t)(float*, float*, int, int);
    func_ptr_t func_ptr = (func_ptr_t)0x00478890;
    func_ptr(Pos, Dir, 2, 7);
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by CornedBee View Post
    What's wrong with
    Code:
    typedef void (*func_ptr_t)(float*, float*, int, int);
    func_ptr_t func_ptr = (func_ptr_t)0x00478890;
    func_ptr(Pos, Dir, 2, 7);
    That's essentially what I asked in the previous two or so posts on the subject. But I think you got the arguments swapped:
    Code:
    typedef void (*func_ptr_t)(int, int, float*, float*);
    ...
    func_ptr(7, 2, Dir, Pos);
    Without knowing where it crashes, it's almost impossible to know what's wrong with that call. Perhaps teh float values should not be all zero? E.g. if one of those valuse is used to divide with, you'd get a FPU exception, which may cause a bit of a problem.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    C calling convention, argument pushing is from right to left. My prototype was correct.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by CornedBee View Post
    C calling convention, argument pushing is from right to left. My prototype was correct.
    You are right. Sorry.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #11
    Registered User
    Join Date
    Jul 2007
    Posts
    61
    Quote Originally Posted by CornedBee View Post
    What's wrong with
    Code:
    typedef void (*func_ptr_t)(float*, float*, int, int);
    func_ptr_t func_ptr = (func_ptr_t)0x00478890;
    func_ptr(Pos, Dir, 2, 7);
    Because that doesn't work.
    Making my app crash.

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by brietje698 View Post
    Because that doesn't work.
    Making my app crash.
    But so does the call from assembler, as I understand it, so perhaps the crashing is caused by SOMETHING ELSE?

    If you disassemble the suggested C code, does it actually do something different from your assembler code?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #13
    Registered User
    Join Date
    Jul 2007
    Posts
    61
    You can call this :
    Code:
    ZPostShotMelee
    ---------------
    00480C70  /$ 64:A1 00000000 MOV EAX,DWORD PTR FS:[0]
    00480C76  |. 6A FF          PUSH -1
    00480C78  |. 68 4DA55D00    PUSH Gunz.005DA54D
    00480C7D  |. 50             PUSH EAX
    00480C7E  |. 64:8925 000000>MOV DWORD PTR FS:[0],ESP
    00480C85  |. 83EC 10        SUB ESP,10
    00480C88  |. 53             PUSH EBX
    00480C89  |. 56             PUSH ESI
    00480C8A  |. 57             PUSH EDI
    00480C8B  |. 68 35270000    PUSH 2735
    00480C90  |. E8 0B5A0400    CALL Gunz.004C66A0
    00480C95  |. 8B1D 80735E00  MOV EBX,DWORD PTR DS:[5E7380]
    00480C9B  |. 83C4 04        ADD ESP,4
    00480C9E  |. 68 B4876600    PUSH Gunz.006687B4
    00480CA3  |. 8BF8           MOV EDI,EAX
    00480CA5  |. FFD3           CALL EBX
    00480CA7  |. 8B35 B0876600  MOV ESI,DWORD PTR DS:[6687B0]
    00480CAD  |. 85F6           TEST ESI,ESI
    00480CAF  |. 74 0A          JE SHORT Gunz.00480CBB
    00480CB1  |. 8B46 08        MOV EAX,DWORD PTR DS:[ESI+8]
    00480CB4  |. A3 B0876600    MOV DWORD PTR DS:[6687B0],EAX
    00480CB9  |. EB 0C          JMP SHORT Gunz.00480CC7
    00480CBB  |> 6A 10          PUSH 10
    00480CBD  |. E8 E3F31400    CALL Gunz.005D00A5
    00480CC2  |. 83C4 04        ADD ESP,4
    00480CC5  |. 8BF0           MOV ESI,EAX
    00480CC7  |> 68 B4876600    PUSH Gunz.006687B4
    00480CCC  |. FF15 84735E00  CALL DWORD PTR DS:[5E7384]
    00480CD2  |. 897424 14      MOV DWORD PTR SS:[ESP+14],ESI
    00480CD6  |. 85F6           TEST ESI,ESI
    00480CD8  |. C74424 24 0000>MOV DWORD PTR SS:[ESP+24],0
    00480CE0  |. 74 24          JE SHORT Gunz.00480D06
    00480CE2  |. 8B0D 78DC6600  MOV ECX,DWORD PTR DS:[66DC78]
    00480CE8  |. 8B41 30        MOV EAX,DWORD PTR DS:[ECX+30]
    00480CEB  |. 8B50 18        MOV EDX,DWORD PTR DS:[EAX+18]
    00480CEE  |. 8B40 0C        MOV EAX,DWORD PTR DS:[EAX+C]
    00480CF1  |. 8B0490         MOV EAX,DWORD PTR DS:[EAX+EDX*4]
    00480CF4  |. 8B08           MOV ECX,DWORD PTR DS:[EAX]
    00480CF6  |. 8BD1           MOV EDX,ECX
    00480CF8  |. 894C24 0C      MOV DWORD PTR SS:[ESP+C],ECX
    00480CFC  |. 52             PUSH EDX
    00480CFD  |. 8BCE           MOV ECX,ESI
    00480CFF  |. E8 AC950800    CALL Gunz.0050A2B0
    00480D04  |. EB 02          JMP SHORT Gunz.00480D08
    00480D06  |> 33C0           XOR EAX,EAX
    00480D08  |> 50             PUSH EAX
    00480D09  |. 8BCF           MOV ECX,EDI
    00480D0B  |. C74424 28 FFFF>MOV DWORD PTR SS:[ESP+28],-1
    00480D13  |. E8 C8B40800    CALL Gunz.0050C1E0
    00480D18  |. 68 D0876600    PUSH Gunz.006687D0
    00480D1D  |. FFD3           CALL EBX
    00480D1F  |. 8B35 CC876600  MOV ESI,DWORD PTR DS:[6687CC]
    00480D25  |. 85F6           TEST ESI,ESI
    00480D27  |. 74 0A          JE SHORT Gunz.00480D33
    00480D29  |. 8B46 14        MOV EAX,DWORD PTR DS:[ESI+14]
    00480D2C  |. A3 CC876600    MOV DWORD PTR DS:[6687CC],EAX
    00480D31  |. EB 0C          JMP SHORT Gunz.00480D3F
    00480D33  |> 6A 18          PUSH 18
    00480D35  |. E8 6BF31400    CALL Gunz.005D00A5
    00480D3A  |. 83C4 04        ADD ESP,4
    00480D3D  |. 8BF0           MOV ESI,EAX
    00480D3F  |> 68 D0876600    PUSH Gunz.006687D0
    00480D44  |. FF15 84735E00  CALL DWORD PTR DS:[5E7384]
    00480D4A  |. 897424 18      MOV DWORD PTR SS:[ESP+18],ESI
    00480D4E  |. 85F6           TEST ESI,ESI
    00480D50  |. C74424 24 0100>MOV DWORD PTR SS:[ESP+24],1
    00480D58  |. 74 31          JE SHORT Gunz.00480D8B
    00480D5A  |. 8B4424 2C      MOV EAX,DWORD PTR SS:[ESP+2C]
    00480D5E  |. 8B48 08        MOV ECX,DWORD PTR DS:[EAX+8]
    00480D61  |. 8B50 04        MOV EDX,DWORD PTR DS:[EAX+4]
    00480D64  |. 8B00           MOV EAX,DWORD PTR DS:[EAX]
    00480D66  |. 51             PUSH ECX
    00480D67  |. 52             PUSH EDX
    00480D68  |. 894C24 14      MOV DWORD PTR SS:[ESP+14],ECX
    00480D6C  |. 50             PUSH EAX
    00480D6D  |. 8BCE           MOV ECX,ESI
    00480D6F  |. 895424 1C      MOV DWORD PTR SS:[ESP+1C],EDX
    00480D73  |. 894424 20      MOV DWORD PTR SS:[ESP+20],EAX
    00480D77  |. E8 94970800    CALL Gunz.0050A510
    00480D7C  |. C706 D4145F00  MOV DWORD PTR DS:[ESI],Gunz.005F14D4
    00480D82  |. C746 04 060000>MOV DWORD PTR DS:[ESI+4],6
    00480D89  |. EB 02          JMP SHORT Gunz.00480D8D
    00480D8B  |> 33F6           XOR ESI,ESI
    00480D8D  |> 56             PUSH ESI
    00480D8E  |. 8BCF           MOV ECX,EDI
    00480D90  |. C74424 28 FFFF>MOV DWORD PTR SS:[ESP+28],-1
    00480D98  |. E8 43B40800    CALL Gunz.0050C1E0
    00480D9D  |. 68 E8746600    PUSH Gunz.006674E8
    00480DA2  |. FFD3           CALL EBX
    00480DA4  |. 8B35 E4746600  MOV ESI,DWORD PTR DS:[6674E4]
    00480DAA  |. 85F6           TEST ESI,ESI
    00480DAC  |. 74 0B          JE SHORT Gunz.00480DB9
    00480DAE  |. 8B4E 08        MOV ECX,DWORD PTR DS:[ESI+8]
    00480DB1  |. 890D E4746600  MOV DWORD PTR DS:[6674E4],ECX
    00480DB7  |. EB 0C          JMP SHORT Gunz.00480DC5
    00480DB9  |> 6A 10          PUSH 10
    00480DBB  |. E8 E5F21400    CALL Gunz.005D00A5
    00480DC0  |. 83C4 04        ADD ESP,4
    00480DC3  |. 8BF0           MOV ESI,EAX
    00480DC5  |> 68 E8746600    PUSH Gunz.006674E8
    00480DCA  |. FF15 84735E00  CALL DWORD PTR DS:[5E7384]
    00480DD0  |. 897424 18      MOV DWORD PTR SS:[ESP+18],ESI
    00480DD4  |. 85F6           TEST ESI,ESI
    00480DD6  |. C74424 24 0200>MOV DWORD PTR SS:[ESP+24],2
    00480DDE  |. 74 0E          JE SHORT Gunz.00480DEE
    00480DE0  |. 8B5424 30      MOV EDX,DWORD PTR SS:[ESP+30]
    00480DE4  |. 52             PUSH EDX
    00480DE5  |. 8BCE           MOV ECX,ESI
    00480DE7  |. E8 14930800    CALL Gunz.0050A100
    00480DEC  |. EB 02          JMP SHORT Gunz.00480DF0
    00480DEE  |> 33C0           XOR EAX,EAX
    00480DF0  |> 50             PUSH EAX
    00480DF1  |. 8BCF           MOV ECX,EDI
    00480DF3  |. C74424 28 FFFF>MOV DWORD PTR SS:[ESP+28],-1
    00480DFB  |. E8 E0B30800    CALL Gunz.0050C1E0
    00480E00  |. 57             PUSH EDI
    00480E01  |. E8 DA4B0400    CALL Gunz.004C59E0
    00480E06  |. 8B4C24 20      MOV ECX,DWORD PTR SS:[ESP+20]
    00480E0A  |. 83C4 04        ADD ESP,4
    00480E0D  |. 5F             POP EDI
    00480E0E  |. 5E             POP ESI
    00480E0F  |. 5B             POP EBX
    00480E10  |. 64:890D 000000>MOV DWORD PTR FS:[0],ECX
    00480E17  |. 83C4 1C        ADD ESP,1C
    00480E1A  \. C3             RETN
    by doing this:
    Code:
    /*	ZPostShotMelee	*/
    void ZPostShotMelee()
    {
    	_asm {
    		pushad
    			mov eax,ZGetGameAddress
    			call eax
    			mov esi,dword ptr ds:[eax+0x50]
    			PUSH 7
    			mov ecx,esi
    			mov eax,PositionEncrypterAddress
    			call eax
    			push eax
    			mov eax,ZPostShotMeleeAddress
    			call eax
    			pop eax
    			pop eax
    		popad
    	}
    }
    Didn't write that one myself to, so I don't know how to call ZPostShotSp, I hope someone can help me

  14. #14
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    I still can't figure out why you're trying to call all these functions using asm?
    It seems like hard work, and you often get it wrong.

    If (and I stress "IF") you get the types right, and the address right, then there is no reason for the function pointer approach to fail.

    For example, how do you know that ZPostShotMelee begins at 00480C70 ?
    Is that address even in the same address space as your program?
    Is it in a DLL, which may relocate to another address?
    Do you have the correct calling convention. There are several on a win32 platform.

    Another question is why don't you have the source code for all of these asm functions you keep posting.

    Also, how do you know you're getting the right setup/teardown sequence? It seems to me you're just calling things at random. It's a bit like calling fread() without calling fopen() first kinda thing.

    Are you trying to hack a game to give yourself some magic powers which normal people won't have? That's what I read into the snippets you've posted so far.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  15. #15
    Registered User
    Join Date
    Jul 2007
    Posts
    61
    Quote Originally Posted by Salem View Post
    I still can't figure out why you're trying to call all these functions using asm?
    It seems like hard work, and you often get it wrong.

    If (and I stress "IF") you get the types right, and the address right, then there is no reason for the function pointer approach to fail.

    For example, how do you know that ZPostShotMelee begins at 00480C70 ?
    Is that address even in the same address space as your program?
    Is it in a DLL, which may relocate to another address?
    Do you have the correct calling convention. There are several on a win32 platform.

    Another question is why don't you have the source code for all of these asm functions you keep posting.

    Also, how do you know you're getting the right setup/teardown sequence? It seems to me you're just calling things at random. It's a bit like calling fread() without calling fopen() first kinda thing.

    Are you trying to hack a game to give yourself some magic powers which normal people won't have? That's what I read into the snippets you've posted so far.
    Because you can't call them without asm. And yes I'm sure the address is right.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  4. calling function in asm
    By brietje698 in forum C++ Programming
    Replies: 10
    Last Post: 11-29-2007, 02:07 PM
  5. Replies: 28
    Last Post: 07-16-2006, 11:35 PM