#include #include Global Enum $BYTE=1,$INT,$CHAR,$STRING,$PTR Global $MAX_STRING_LEN=130,$Array_tag="int;ptr",$IT_tag="int,ptr,ptr" Main() Func Main() $a=CustomArray(3,$INT) ArrayWriteElement($a,0,12) ArrayWriteElement($a,1,999999) ArrayWriteElement($a,2,123456) $c=$a ConsoleWrite($c=$a ? "true" & @CRLF : "false" & @CRLF) $b=CustomArray(3,$STRING) ArrayWriteElement($b,0,"hello") ArrayWriteElement($b,1,"hI") ArrayWriteElement($b,2,"Its Me!!") ArrayPrint($a) ConsoleWrite("___________________________________"&@CRLF) ArrayPrint($b) ConsoleWrite("___________________________________"&@CRLF) ArrayPrint($c) ConsoleWrite("___________________________________"&@CRLF) ArrayWriteElement($c,0,1776) ArrayPrint($a) ConsoleWrite("___________________________________"&@CRLF) ArrayPrint($c) ArrayDelete($b) ;$c is an alias so no need to delete it ArrayDelete($a) ArrayPrint($a) ;this purposefully errors out to show that the delete is working ArrayPrint($b) EndFunc func It_Init($Array) ;untested just ignore this $type=ArrayType($Array) $size=ArraySize($Array) $begin=ArrayBegin($Array) $Tsize=SizeOf($type) $s=DllStructCreate($IT_tag) $itsize=DllStructGetSize($s) $it=malloc($itsize*$size) ZeroMemory($it,$itsize*$size) $tempit=$it $hprocess=0 $hprocess=_WinAPI_OpenProcess($PROCESS_ALL_ACCESS,false,@AutoItPID) $iWritten=0 if $hprocess Then DllStructSetData($s,1,$type) DllStructSetData($s,2,$Array) for $begin=$begin to $begin+($Tsize*($size-1)) step $Tsize DllStructSetData($s,3,$begin) If not _WinAPI_WriteProcessMemory($hprocess,$tempit,DllStructGetPtr($s),$itsize,$iWritten) Then ConsoleWriteError(_WinAPI_GetLastErrorMessage()) $tempit+=$itsize Next _WinAPI_CloseHandle($hprocess) Return $it EndIf Return -1 EndFunc Func ArrayDelete($Array) $type=ArrayType($Array) $size=ArraySize($Array) if $type=4 Then $s=DllStructCreate("ptr["&$size&"]",ArrayBegin($Array)) for $x=1 to $size ;~ ConsoleWrite(DllStructGetData($s,1,$x)) _MemVirtualFree(DllStructGetData($s,1,$x),0,$MEM_RELEASE) Next Else _MemVirtualFree(ArrayBegin($Array),0,$MEM_RELEASE) EndIf EndFunc Func ArrayPrint($Array) for $x=0 to ArraySize($Array)-1 ConsoleWrite(ArrayReadElement($Array,$x) & @CRLF) Next EndFunc Func ArrayWriteElement($Array,$Element,$Data);needs work $size=ArraySize($Array) if $Element>$size-1 then Return -1 $type=ArrayType($Array) $p=ArrayGetElementPtr($Array,$Element) if $type=4 Then $m=malloc($MAX_STRING_LEN*2) ZeroMemory($m,$MAX_STRING_LEN*2) $s=DllStructCreate("char["&$MAX_STRING_LEN&"]",$m) DllStructSetData($s,1,$Data) DllStructSetData(DllStructCreate("ptr",$p),1,$m) Else DllStructSetData(DllStructCreate(TypeToString($type),$p),1,$Data) EndIf EndFunc func ArrayReadElement($Array,$Element) $type=ArrayType($Array) $stype=TypeToString($type) if $type=4 Then $s=DllStructCreate("ptr",ArrayGetElementPtr($Array,$Element)) $charptr=DllStructGetData($s,1) $x=1 $s=DllStructCreate("char[" & $MAX_STRING_LEN & "]",$charptr) Return DllStructGetData($s,1) Else $s=DllStructCreate($stype,ArrayGetElementPtr($Array,$Element)) Return DllStructGetData($s,1) EndIf EndFunc Func ArrayGetElementPtr($Array,$Element) if $Element>ArraySize($Array)-1 then Return -1 $type=ArrayType($Array) $begin=ArrayBegin($Array) ;ConsoleWrite($begin) Return $begin+(SizeOf($type)*$element) EndFunc Func ArrayType($Array) if VarGetType($Array)<>"Ptr" then Return -1 $s=Hex(DllStructGetData(DllStructCreate($Array_tag,$Array),1)) Return int(StringTrimRight($s,7)) EndFunc func ArraySize($Array) if VarGetType($Array)<>"Ptr" then Return -1 $s=Hex(DllStructGetData(DllStructCreate($Array_tag,$Array),1)) $type=int(StringTrimRight($s,7)) $s=int("0x" & $s) Return $s-int("0x" & $type & "0000000") EndFunc func CustomArray($N_elements,$type) Local $p=malloc(SizeOf($type)*$N_elements) ;ConsoleWrite($p) ZeroMemory($p,SizeOf($type)*$N_elements) $s=DllStructCreate($Array_tag) DllStructSetData($s,1,Int("0x" & $type & "0000000")+$N_elements) ;keeps track of the type and number of elements DllStructSetData($s,2,$p) Return DllStructGetPtr($s) EndFunc func malloc($size) ;~ VirtualAlloc( ;~ _In_opt_ LPVOID lpAddress, ;~ _In_ SIZE_T dwSize, ;~ _In_ DWORD flAllocationType, ;~ _In_ DWORD flProtect ;~ ) ;~ Specifies the type of allocation: ;~ $MEM_COMMIT - Allocates physical storage in memory or in the paging file on disk for the specified region of pages. ;~ $MEM_RESERVE - Reserves a range of the process's virtual address space without allocating any physical storage. ;~ $MEM_TOP_DOWN - Allocates memory at the highest possible address ;~ $iProtect Type of access protection: ;~ $PAGE_READONLY - Enables read access to the committed region of pages ;~ $PAGE_READWRITE - Enables read and write access to the committed region ;~ $PAGE_EXECUTE - Enables execute access to the committed region ;~ $PAGE_EXECUTE_READ - Enables execute and read access to the committed region ;~ $PAGE_EXECUTE_READWRITE - Enables execute, read, and write access to the committed region of pages ;~ $PAGE_GUARD - Pages in the region become guard pages ;~ $PAGE_NOACCESS - Disables all access to the committed region of pages ;~ $PAGE_NOCACHE - Allows no caching of the committed regions of pages Return _MemVirtualAlloc ( Null, $size, BitOR($MEM_COMMIT,$MEM_RESERVE), $PAGE_EXECUTE_READWRITE) EndFunc func ArrayBegin($Array) Return DllStructGetData(DllStructCreate($Array_tag,$Array),2) EndFunc func SizeOf($type) Select Case $type = 1 or $type=3 Return 1 case $type=2 Return DllStructGetSize(DllStructCreate("int")) Case $type=4 Return DllStructGetSize(DllStructCreate("ptr")) Case $type=5 Return DllStructGetSize(DllStructCreate("ptr")) Case Else Return -1 EndSelect EndFunc func TypeToString($type) Select Case $type = 1 Return "byte" case $type=2 Return "int" Case $type=3 Return "char" Case $type=4 Return "string" Case $type=5 Return "ptr" Case Else Return -1 EndSelect EndFunc func ZeroMemory($p,$size) $s=DllStructCreate("byte["&$size&"]",$p) for $x=1 to $size DllStructSetData($s,$x,0) Next EndFunc