Jump to content

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


Recommended Posts

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

_____________________________________________________________________________

Link to comment
Share on other sites

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
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...