Jump to content

How to convert following C to autoit?


E1M1
 Share

Recommended Posts

byte szCode[] = {
        0x60,                           //pushad
        0x68, 0x00, 0x00, 0x00, 0x00,   //push 0h
        0x68, 0x00, 0x00, 0x00, 0x00,   //push 0h
        0x68, 0x00, 0x00, 0x00, 0x00,   //push 0h
        0xB8, 0x00, 0x00, 0x00, 0x00,   //mov eax, 0h
        0xFF, 0xD0,                     //call eax
        0x61,                           //popad
        0xC3                            //ret
    };
    *(DWORD*)&szCode[2] = (DWORD)pRemotePacket;
    *(DWORD*)&szCode[7] = 0;
    *(DWORD*)&szCode[12] = aLen;
    *(DWORD*)&szCode[17] = dwOffset;

I have converter szCode like follows:

dim $szCode[25] = [ 0x60, 0x68, 0x00, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0xB8, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xD0, 0x61, 0xC3 ]

But how to convert

*(DWORD*)&szCode[2] = (DWORD)pRemotePacket;

I guess it's not just $szCode[2] = $pRemotePacket

edited

Link to comment
Share on other sites

You can't combine array elements to 'cast' to a wider type. In AutoIt, the only way to do what you want is to use a DLLStruct or a Hex string ("0x6068000000006800000000B800000000FFD061C3").

The latter is easiest in replacing values. You just need to make sure the values are hexadecimal (strip the '0x' with StringTrimLeft() or Hex() if you need to), then do a StringReplace() on the main hex string. You might even replace the 00's you want to replace with special characters so you can do a replace much easier. Afterwards, the whole thing can be written as binary to a DLLStruct (of type 'byte[xx]').

Link to comment
Share on other sites

but why

$szCode[2] = $pRemotePacket

$szCode[7] = 0

$szCode[12] = $dwALen

$szCode[17] = $dwOffset

wouldn't work?

With strings it would be bit hard because I would have to convert something to hex and variables might have diferent size so I would have to recalculate offsets. but replacing array elements would be with out calculating. Then I could use for loop to put it back to string.

edited

Link to comment
Share on other sites

Each array element is a separate entity in AutoIt. They aren't connected in a long sequence in memory. If you are that determined to keep it like the C code, then by all means, use an array - but you will need to go through those array elements one-by-one when putting them in a DLLStruct.

If you are worried about width, there is such a thing as padding. [$sPaddedNumber=StringRight('00000000'&$iNumber,8)]

But it seems like you don't really know C, AutoIt, or Assembly at all from your posts. I'd say it looks like you are copying and pasting bits of code from others and kludging it together to try and make it work for you.

One other thing: endianness is important. You'll need to rearrange pointers if adding them in a binary sequence.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...