Jump to content
Sign in to follow this  
captionx

3 quick DLL struc questions

Recommended Posts

captionx

;Question 01: Why does this not return the data?
$myStruct = DllStructCreate('unit, Tempstruc[8]')
DllStructSetData($myStruct,"Tempstruc",Binary("0x90217F0B00000000000000000000000000000000000000000000000000000000"))
ConsoleWrite(Binary(DllStructGetData($myStruct,"Tempstruc"))&@CRLF)




;Question 02: How do i get the size of a struc item
; ie: itemsize("var4") == 128
Local $str = "int var1;byte var2;uint var3;char var4[128]"
Local $a = DllStructCreate($str)
DllStructSetData($a, "var1", -1)
DllStructSetData($a, "var2", 255)
DllStructSetData($a, "var3", -1)
DllStructSetData($a, "var4", "Hello")




;Question 03: Can you read a binary file using a DLL struc?
$File = FileOpenDialog("Select file to patch","C:\","bin (*.bin)")
$BinaryStruc = DllStructCreate (  _
"dword Headername;"  & _
"dword Filetype;"  & _
"dword Fileversion;" )

Share this post


Link to post
Share on other sites
Yashied

1.

$tByte = DllStructCreate('byte Tempstruc[32]')
DllStructSetData($tByte, 'Tempstruc', Binary('0x90217F0B00000000000000000000000000000000000000000000000000000000'))

ConsoleWrite(DllStructGetData($tByte, 'Tempstruc') & @CRLF)

$tUInt = DllStructCreate('uint Tempstruc[8]', DllStructGetPtr($tByte))
For $i = 1 To 8
    ConsoleWrite('0x' & Hex(DllStructGetData($tUInt, 1, $i)) & @CR)
Next

2. You can't but this is not necessary because the size is known in advance.

3.

#Include <WinAPI.au3>

Global $Bytes

$tStruct = DllStructCreate('dword Headername;dword Filetype;dword Fileversion')
$hFile = _WinAPI_CreateFile($File, 2, 2)
_WinAPI_ReadFile($hFile, DllStructGetPtr($tStruct), DllStructGetSize($tStruct), $Bytes)
_WinAPI_CloseHandle($hFile)

ConsoleWrite('Headername: ' & DllStructGetData($tStruct, 'Headername') & @CR)
ConsoleWrite('Filetype: ' & DllStructGetData($tStruct, 'Filetype') & @CR)
ConsoleWrite('Fileversion: ' & DllStructGetData($tStruct, 'Fileversion') & @CR)
Edited by Yashied

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
Sign in to follow this  

×