Jump to content
Bilgus

Type Casting using DllStructs

Recommended Posts

Bilgus

I just realized today looking for a way to cast to a byte that I could (ab)use The DllStructSetData() function for conversion

I didn't see anything when I searched the forums so maybe this is frowned upon?

Bool and UINT64 doesn't seem quite right but this might just be a limitation of the AutoIt variables

 

 

;Autoit Cast
Global $asTypes[] = ["BOOL", "BYTE", "CHAR", "WCHAR", "SHORT", "USHORT", "WORD", "INT", "UINT", "INT64", "UINT64"]
Global $avValues[] = [0, 1, -1, -128, 127, -255, 255, -32768, 32767, -65535, 65535, -2147483648, 2147483647, _
                      -4294967295, 4294967295, -9223372036854775808, 9223372036854775807]
Global $g_tData
For $i = 0 To UBound($asTypes) - 1

    $g_tData = DllStructCreate($asTypes[$i])
    ConsoleWrite($asTypes[$i] & ":" & @CRLF)
    For $j = 0 To UBound($avValues) - 1
        ConsoleWrite("IN: " & $avValues[$j] & " OUT: " & DllStructSetData($g_tData, 1, $avValues[$j]) & @CRLF)
    Next
Next
Spoiler
BOOL:
IN: 0 OUT: 0
IN: 1 OUT: 1
IN: -1 OUT: -1
IN: -128 OUT: -128
IN: 127 OUT: 127
IN: -255 OUT: -255
IN: 255 OUT: 255
IN: -32768 OUT: -32768
IN: 32767 OUT: 32767
IN: -65535 OUT: -65535
IN: 65535 OUT: 65535
IN: -2147483648 OUT: -2147483648
IN: 2147483647 OUT: 2147483647
IN: -4294967295 OUT: 1
IN: 4294967295 OUT: -1
IN: -9223372036854775807 OUT: 1
IN: 9223372036854775807 OUT: -1
BYTE:
IN: 0 OUT: 0
IN: 1 OUT: 1
IN: -1 OUT: 255
IN: -128 OUT: 128
IN: 127 OUT: 127
IN: -255 OUT: 1
IN: 255 OUT: 255
IN: -32768 OUT: 0
IN: 32767 OUT: 255
IN: -65535 OUT: 1
IN: 65535 OUT: 255
IN: -2147483648 OUT: 0
IN: 2147483647 OUT: 255
IN: -4294967295 OUT: 1
IN: 4294967295 OUT: 255
IN: -9223372036854775807 OUT: 1
IN: 9223372036854775807 OUT: 255
CHAR:
IN: 0 OUT: IN: 1 OUT: 
IN: -1 OUT: ?
IN: -128 OUT: ?
IN: 127 OUT: 
IN: -255 OUT: !
IN: 255 OUT: ��N: -32768 OUT: ?
IN: 32767 OUT: ?
IN: -65535 OUT: 
IN: 65535 OUT: ?
IN: -2147483648 OUT: IN: 2147483647 OUT: ?
IN: -4294967295 OUT: 
IN: 4294967295 OUT: ?
IN: -9223372036854775807 OUT: 
IN: 9223372036854775807 OUT: ?
WCHAR:
IN: 0 OUT: IN: 1 OUT: 
IN: -1 OUT: ?
IN: -128 OUT: ?
IN: 127 OUT: 
IN: -255 OUT: !
IN: 255 OUT: ��N: -32768 OUT: ?
IN: 32767 OUT: ?
IN: -65535 OUT: 
IN: 65535 OUT: ?
IN: -2147483648 OUT: IN: 2147483647 OUT: ?
IN: -4294967295 OUT: 
IN: 4294967295 OUT: ?
IN: -9223372036854775807 OUT: 
IN: 9223372036854775807 OUT: ?
SHORT:
IN: 0 OUT: 0
IN: 1 OUT: 1
IN: -1 OUT: -1
IN: -128 OUT: -128
IN: 127 OUT: 127
IN: -255 OUT: -255
IN: 255 OUT: 255
IN: -32768 OUT: -32768
IN: 32767 OUT: 32767
IN: -65535 OUT: 1
IN: 65535 OUT: -1
IN: -2147483648 OUT: 0
IN: 2147483647 OUT: -1
IN: -4294967295 OUT: 1
IN: 4294967295 OUT: -1
IN: -9223372036854775807 OUT: 1
IN: 9223372036854775807 OUT: -1
USHORT:
IN: 0 OUT: 0
IN: 1 OUT: 1
IN: -1 OUT: 65535
IN: -128 OUT: 65408
IN: 127 OUT: 127
IN: -255 OUT: 65281
IN: 255 OUT: 255
IN: -32768 OUT: 32768
IN: 32767 OUT: 32767
IN: -65535 OUT: 1
IN: 65535 OUT: 65535
IN: -2147483648 OUT: 0
IN: 2147483647 OUT: 65535
IN: -4294967295 OUT: 1
IN: 4294967295 OUT: 65535
IN: -9223372036854775807 OUT: 1
IN: 9223372036854775807 OUT: 65535
WORD:
IN: 0 OUT: 0
IN: 1 OUT: 1
IN: -1 OUT: 65535
IN: -128 OUT: 65408
IN: 127 OUT: 127
IN: -255 OUT: 65281
IN: 255 OUT: 255
IN: -32768 OUT: 32768
IN: 32767 OUT: 32767
IN: -65535 OUT: 1
IN: 65535 OUT: 65535
IN: -2147483648 OUT: 0
IN: 2147483647 OUT: 65535
IN: -4294967295 OUT: 1
IN: 4294967295 OUT: 65535
IN: -9223372036854775807 OUT: 1
IN: 9223372036854775807 OUT: 65535
INT:
IN: 0 OUT: 0
IN: 1 OUT: 1
IN: -1 OUT: -1
IN: -128 OUT: -128
IN: 127 OUT: 127
IN: -255 OUT: -255
IN: 255 OUT: 255
IN: -32768 OUT: -32768
IN: 32767 OUT: 32767
IN: -65535 OUT: -65535
IN: 65535 OUT: 65535
IN: -2147483648 OUT: -2147483648
IN: 2147483647 OUT: 2147483647
IN: -4294967295 OUT: 1
IN: 4294967295 OUT: -1
IN: -9223372036854775807 OUT: 1
IN: 9223372036854775807 OUT: -1
UINT:
IN: 0 OUT: 0
IN: 1 OUT: 1
IN: -1 OUT: 4294967295
IN: -128 OUT: 4294967168
IN: 127 OUT: 127
IN: -255 OUT: 4294967041
IN: 255 OUT: 255
IN: -32768 OUT: 4294934528
IN: 32767 OUT: 32767
IN: -65535 OUT: 4294901761
IN: 65535 OUT: 65535
IN: -2147483648 OUT: 2147483648
IN: 2147483647 OUT: 2147483647
IN: -4294967295 OUT: 1
IN: 4294967295 OUT: 4294967295
IN: -9223372036854775807 OUT: 1
IN: 9223372036854775807 OUT: 4294967295
INT64:
IN: 0 OUT: 0
IN: 1 OUT: 1
IN: -1 OUT: -1
IN: -128 OUT: -128
IN: 127 OUT: 127
IN: -255 OUT: -255
IN: 255 OUT: 255
IN: -32768 OUT: -32768
IN: 32767 OUT: 32767
IN: -65535 OUT: -65535
IN: 65535 OUT: 65535
IN: -2147483648 OUT: -2147483648
IN: 2147483647 OUT: 2147483647
IN: -4294967295 OUT: -4294967295
IN: 4294967295 OUT: 4294967295
IN: -9223372036854775807 OUT: -9223372036854775807
IN: 9223372036854775807 OUT: 9223372036854775807
UINT64:
IN: 0 OUT: 0
IN: 1 OUT: 1
IN: -1 OUT: -1
IN: -128 OUT: -128
IN: 127 OUT: 127
IN: -255 OUT: -255
IN: 255 OUT: 255
IN: -32768 OUT: -32768
IN: 32767 OUT: 32767
IN: -65535 OUT: -65535
IN: 65535 OUT: 65535
IN: -2147483648 OUT: -2147483648
IN: 2147483647 OUT: 2147483647
IN: -4294967295 OUT: -4294967295
IN: 4294967295 OUT: 4294967295
IN: -9223372036854775807 OUT: -9223372036854775807
IN: 9223372036854775807 OUT: 9223372036854775807

 

 

  • Like 1

Share this post


Link to post
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

×