Search code examples
javacassemblyjnaequivalent

What will be the java equivalant code for the following code?


I am using JNA to call methods of user32.dll and kernel32.dll. It is working fine as of now. I got stuck in some issue, and I got to know that I have to call this method.

void SendCommandToConsole( char* Cmd )
{
    DWORD dwCall = 0x004C1030;
    __asm
    {
        push Cmd;
        push 0;
        call dwCall;
    }
}

SendCommandToConsole ( "rp 2000" );

But I am not even getting it what it is? What this __asm is doing ?

Please add appropriate tags, if the tags I have used are not correct. :)

Edit Added .Net and C# tags as suggested. Above code is in either C# or .NET, may be someone with the knowledge of this language can tell us what actually it is, and how can we do this in java.


Solution

  • Just to show what is happening under the hood:

    Your call:

    SendCommandToConsole ( "rp 2000" );

    Is calling the function (SendCommandToConsole) with a parameter of type (char* Cmd).

    In the case above, (char* Cmd) equates to the character string (sic) of "rp 2000".

    Now what happens under the covers is that higher level languages (Java in your example) need to tell lower level languages how to interpret their instructions in a language that they understand.

    So to take the example above of ("I want to call the function "SendCommandToConsole" with the string parameter of "rp 2000"), means that we need to communicate to the lower level language:

    • The "uppity-ups want us to run a command". "Oh yea, which one?"
    • "They're telling me 'SendCommandToConsole'"
    • "Oh, that dude? He lives at the address '0x004C1030' down here."
    • "Oh, you know the dude's address? Can you deliver this package that the uppity-ups want delivered?"
    • "Sure thing, but he only accepts packages in a certain order, and only of a certain type."
    • "No problem, I have their manifest right here... let's see if it matches the dude's requirements."

    "First off, the dude at that address only wants to know 2 things, and they have to be in order:

    • What do you want me do do,
    • and who do I report the results to?"

    "Ok, that's easy"

    I'll assert what I want him to do:

    • "Cmd"
    • Now I'll assert who I want him to report the results to: "No one (0)"

    All right, I'll ring him up... you can go on with your day now.

    (Because it is a "void" return, which means you don't care about the result of the transaction)