Jump to content
Sign in to follow this  
GodlessSinner

help to read 256 bytes of the file & write into array

Recommended Posts

GodlessSinner

Help me.


_____________________________________________________________________________

Share this post


Link to post
Share on other sites
azure

Help me.

SEND("{F1}")

/thread

Share this post


Link to post
Share on other sites
Authenticity

_WinAPI_ReadFile($hFile, $pBuffer, $iToRead, ByRef $iRead[, $pOverlapped = 0])

From the help file, set $iToRead to 256...

Edit: stupid, mistake... keep it as it was.

Edited by Authenticity

Share this post


Link to post
Share on other sites
GodlessSinner

Global $sFile, $hFile, $sText, $nBytes, $tBuffer, $Copy, $hCopy

$sFile = @ScriptDir & '\dmaster.exe'

$Copy = @ScriptDir & '\dmaster2.exe'

$tBuffer = DLLStructCreate("byte[256]")

$hFile = _WinAPI_CreateFile($sFile, 2, 2)

_WinAPI_SetFilePointer($hFile, 0)

_WinAPI_ReadFile($hFile, DLLStructGetPtr($tBuffer), 256, $nBytes)

_WinAPI_CloseHandle($hFile)

$sText = DLLStructGetData($tBuffer, 1)

$hCopy = _WinAPI_CreateFile($Copy, 1, 4)

_WinAPI_WriteFile($hCopy, DLLStructGetPtr($tBuffer), 256, $nBytes)

---------------

Its copying 256 bytes from one file to another. Can I give, says, 134th element of DllStructure?

Edited by Vitas

_____________________________________________________________________________

Share this post


Link to post
Share on other sites
Authenticity

Yes, $byte = DllStructGetData($sText, 1, 134)

Share this post


Link to post
Share on other sites
PsaltyDS

Global $sFile, $hFile, $sText, $nBytes, $tBuffer, $Copy, $hCopy

$sFile = @ScriptDir & '\dmaster.exe'

$Copy = @ScriptDir & '\dmaster2.exe'

$tBuffer = DLLStructCreate("byte[256]")

$hFile = _WinAPI_CreateFile($sFile, 2, 2)

_WinAPI_SetFilePointer($hFile, 0)

_WinAPI_ReadFile($hFile, DLLStructGetPtr($tBuffer), 256, $nBytes)

_WinAPI_CloseHandle($hFile)

ConsoleWrite('2) ' & $buffer & @LF)

$sText = DLLStructGetData($tBuffer, 1)

$hCopy = _WinAPI_CreateFile($Copy, 1, 4)

_WinAPI_WriteFile($hCopy, DLLStructGetPtr($tBuffer), 256, $nBytes)

---------------

Its copying 256 bytes from one file to another. Can I give, says, 134th element of DllStructure?

Seems like you are over-thinking this a bit:
Global $sSrc = @ScriptDir & '\dmaster.exe', $hSrc, $binData, $binByte134
Global $sDest = @ScriptDir & '\dmaster2.exe', $hDest

$hSrc = FileOpen($sSrc, 16)
$binData = FileRead($hSrc, 256)
FileClose($hSrc)
$binByte134 = BinaryMid($binData, 134, 1)
$hDest = FileOpen($sDest, 16 + 2)
FileWrite($hDest, $binData)
FileClose($hDest)
$sByte134 = "0x" & Hex($binByte134, 2)
MsgBox(64, "134th Byte", "The 134th byte was:  " & $sByte134)

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
GodlessSinner

Thanks, @PsaltyDS! Its a most right way.


_____________________________________________________________________________

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  

×