;;;pointers and dereferenceing #include HotKeySet("{ESC}","exit1") Global $PointerTracker,$DummyStruct $a="mark" $b=-15.34334534 $c=True $d=Binary("Gerbal") $e=32 Global $f[5]=["mark", 13.4332, True, "Gerbal", 32] ;arrays arn't compatible, the array is the pointer to the underlying data ;~ $f=DllStructCreate("struct;int;endstruct") ;~ DllStructSetData($f,1,987) ;~ MsgBox('','',_GetPtr($a)) ;~ $f=_GetPtr($a) ;~ $g=_GetPtr($b) ;~ $h=_GetPtr($c) ;~ $i=_GetPtr($d) ;~ $j=_GetPtr($e) $a=_GetPtr($a) $b=_GetPtr($b) $c=_GetPtr($c) $d=_GetPtr($d) $e=_GetPtr($e) ;~ ; can get pointer but not dereference dllstruct type variable maybe implemented in the future ;~ _ArrayDisplay($PointerTracker) $a=_Dereference($a) $b=_Dereference($b) $c=_Dereference($c) $d=_Dereference($d) $e=_Dereference($e) ConsoleWrite($a & @CRLF) ConsoleWrite($b & @CRLF) ConsoleWrite($c & @CRLF) ConsoleWrite($d & @CRLF) ConsoleWrite($e & @CRLF) ;~ _ArrayDisplay($PointerTracker) $a=_GetExistingPtr($a) $b=_GetExistingPtr($b) $c=_GetExistingPtr($c) $d=_GetExistingPtr($d) $e=_GetExistingPtr($e) ;~ _ArrayDisplay($PointerTracker) _WriteToPtr($a,"butterNuggets") ;the pointer should stay the same.....only the data should change _WriteToPtr($b,Binary("hello")) _WriteToPtr($c,146.76554) _WriteToPtr($d,True) _WriteToPtr($e,15) ;~ _ArrayDisplay($PointerTracker) $a=_Dereference($a) $b=_Dereference($b) $c=_Dereference($c) $d=_Dereference($d) $e=_Dereference($e) ConsoleWrite($a & @CRLF) ConsoleWrite($b & @CRLF) ConsoleWrite($c & @CRLF) ConsoleWrite($d & @CRLF) ConsoleWrite($e & @CRLF) ;~ MsgBox("","",$a,1) ;~ MsgBox("","",$b,1) ;~ MsgBox("","",$c,1) ;~ MsgBox("","",$d,1) ;~ MsgBox("","",$e,1) _PointerDelete($a) _PointerDelete($b) _PointerDelete($c) _PointerDelete($d) _PointerDelete($e) ;~ _ArrayDisplay($PointerTracker) Func _GetExistingPtr($var) if not IsArray($PointerTracker) Then MsgBox('',"ERROR","No pointers exist") Exit EndIf for $x=0 to UBound($PointerTracker)-1 ;[$x][0]=value x[1]=Tag x[2]=pointer [3]datatype [4]elementsize [5] variable size if $PointerTracker[$x][0]=$var Then Return $PointerTracker[$x][2] EndIf Next MsgBox('','ERROR','Could Not Find Existing Ptr [_GetExistingPtr()]') Exit EndFunc func _WriteToPtr($pointer,$data) $DataType=VarGetType($pointer) $DataTypeData=VarGetType($data) $DataSize=1 if $DataType<> "ptr" Then MsgBox('',"ERROR","Variable Must Be Pointer Type [_WriteToPtr()]") ;[$x][0]=value x[1]=Tag x[2]=pointer [3]datatype [4]elementsize [5]variablesize Exit elseif $DataTypeData="dllstruct" Then MsgBox('',"ERROR","Data Cannot be Dllstruct DataType [_WriteToPtr()]") Exit elseif not IsArray($PointerTracker) Then MsgBox('',"ERROR","No Pointers Exist [_WriteToPtr()]") ElseIf $DataTypeData<>"int32" and $DataType<>"int64" Then $data=string($data) $data=Binary($data) $DataSize=BinaryLen($data) elseif $DataType="int32" or $DataType="int64" then $DataSize=stringlen($data) EndIf ;~ MsgBox('',"size",$size) $DummyData="" for $x=0 to UBound($PointerTracker)-1 if $PointerTracker[$x][2]=$pointer then ;found a match $PointerTracker[$x][5]=$DataSize ;saves the variable size $size=$PointerTracker[$x][4] ;~ MsgBox('',"size",$size) for $p=1 to $size/4 $DummyData&=" " Next ;~ MsgBox('',"p",$p) If $DataTypeData<>"int32" and $DataType<>"int64" Then $DummyData=Binary($DummyData) EndIf ;~ MsgBox('','',$data) DllStructSetData($DummyStruct[$x],1,$DummyData) $success=DllStructSetData($DummyStruct[$x],1,$data) ;[$x][0]=value x[1]=Tag x[2]=pointer [3]datatype [4]size [5]variablesize ;~ MsgBox('',"success",$success) if $success=$data Then ;~ if $DataTypeData="int32" or $DataTypeData="int64" then ;~ $data=BinaryToString($data) ;~ EndIf ;~ MsgBox('','',$data) ;~ $data=StringTrimRight($data,$p-1) ;~ MsgBox('','',$data) if $DataTypeData<>"int32" and $DataType<>"int64" Then $PointerTracker[$x][0]=BinaryToString($data) Elseif $DataTypeData="int32" or $DataTypeData="int64" then $PointerTracker[$x][0]=$data ;~ _ArrayDisplay($PointerTracker) Return 1 Else MsgBox('',"ERROR","Data Failed to Set [_WritePtr()]") Return 0 EndIf EndIf EndIf Next EndFunc func _Dereference($pointer) ;_Dereference($pointer) $DataType=VarGetType($pointer) ;[$x][0]=value x[1]=Tag x[2]=pointer [3]datatype [4]element size [5] variable size if $DataType<>"ptr" Then MsgBox('','ERROR',"Var Must Be a Pointer!!") Exit EndIf $result="" for $x=0 to UBound($PointerTracker)-1 if $PointerTracker[$x][2]=$pointer then ;match if $PointerTracker[$x][3]="dllstruct" Then MsgBox('',"ERROR","Cannot Dereference DllStruct type variable") Exit EndIf $result=DllStructGetData($DummyStruct[$x],1) if $PointerTracker[$x][3]="int" Then $PointerTracker[$x][0]=StringLeft($result,$PointerTracker[$x][5]) Return $result Else Return StringLeft(BinaryTostring($result),$PointerTracker[$x][5]) EndIf EndIf Next Exit EndFunc func _GetPtr($var) local $tag="",$len="" $DataType=VarGetType($var) if $DataType<>"int32" and $DataType<>"dllstruct" and $DataType<>"int64" Then ;changes the datatype variable for use in the tag $var=String($var) $var=binary($var) ElseIf $DataType="int32" or $DataType="int64" Then $DataType="int" EndIf ;[$x][0]=value x[1]=Tag x[2]=pointer [3]datatype [4]elementsize [5]variablesize if Not IsArray($PointerTracker) Then dim $PointerTracker[1][6] elseif IsArray($PointerTracker) Then ReDim $PointerTracker[UBound($PointerTracker)+1][6] EndIf $PointerTracker[UBound($PointerTracker)-1][3]=$DataType ;saves the data type if $DataType<>"int" Then $PointerTracker[UBound($PointerTracker)-1][0]=BinaryToString($var) ;just saves the original value elseif $DataType="int" Then $PointerTracker[UBound($PointerTracker)-1][0]=$var EndIf if $DataType<>"int" and $DataType<>"dllstruct" Then ;creates the tag $len=BinaryLen($var) $tag="struct;align 1;byte[" & $len+128 & "];endstruct" ElseIf $DataType="int" Then $tag="struct;int[" & $len+128 & "];endstruct" $len=stringlen($var) ElseIf $DataType="dllstruct" Then ;<-----------this basically does nothing dllstruct type variables don't create a new struct bc they alread exist $bin=Binary($var) $len=BinaryLen($bin) $tag="struct;align 1;byte[" & $len & "];endstruct" Else $len=128 EndIf $PointerTracker[UBound($PointerTracker)-1][5]=$len $PointerTracker[UBound($PointerTracker)-1][4]=$len+128 ;saves the size!! $PointerTracker[UBound($PointerTracker)-1][1]=$tag ;saves the tag $DummyData='' for $b=1 to $PointerTracker[UBound($PointerTracker)-1][4] $DummyData&=" " Next $DummyData=Binary($DummyData) if not IsArray($DummyStruct) Then ;first time through dim $DummyStruct[1] if IsArray($DummyStruct) Then if $DataType<>"dllstruct" Then $DummyStruct[0]=DllStructCreate($tag) ;creates struct DllStructSetData($DummyStruct[0],1,$DummyData) $success=DllStructSetData($DummyStruct[0],1,$var) ;sets the data EndIf if $DataType="dllstruct" Then ;if datatye is dllstruct sets the variable as the dummystruct ;[$x][0]=value x[1]=Tag x[2]=pointer [3]datatype [4]elementsize [5]variablesize $DummyStruct[0]=$var EndIf $PointerTracker[0][0]=StringLeft(BinaryToString($success),$len) $PointerTracker[0][2]=DllStructGetPtr($DummyStruct[0],1) ;gets the pointer and returns it Return $PointerTracker[0][2] EndIf ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Elseif UBound($DummyStruct)>=1 Then ;subsequent times through ReDim $DummyStruct[UBound($DummyStruct)+1] if IsArray($DummyStruct) Then if $DataType<>"dllstruct" Then $DummyStruct[UBound($DummyStruct)-1]=DllStructCreate($tag) ;create struct DllStructSetData($DummyStruct[UBound($DummyStruct)-1],1,$DummyData) $success=DllStructSetData($DummyStruct[UBound($DummyStruct)-1],1,$var) ;sets data EndIf if $DataType="dllstruct" Then $DummyStruct[UBound($DummyStruct)-1]=$var ;if datatye is dllstruct sets the variable as the dummystruct EndIf $PointerTracker[UBound($PointerTracker)-1][2]=DllStructGetPtr($DummyStruct[UBound($DummyStruct)-1],1) ;gets pointer and returns it ;~ _ArrayDisplay($PointerTracker) $PointerTracker[UBound($PointerTracker)-1][0]=StringLeft(BinaryToString($success),$len) Return $PointerTracker[UBound($PointerTracker)-1][2] EndIf ;[$x][0]=value x[1]=Tag x[2]=pointer [3]datatype EndIf EndFunc Func _PointerDelete(ByRef $pointer) $DataType=VarGetType($pointer) if IsArray($PointerTracker) Then ;match ;[$x][0]=value x[1]=Tag x[2]=pointer [3]datatype for $x=0 to UBound($PointerTracker)-1 if $pointer=$PointerTracker[$x][2] Then _ArrayDelete($DummyStruct,$x) _ArrayDelete($PointerTracker,$x) ;~ _ArrayDisplay($PointerTracker) $pointer=0 Return EndIf Next for $i=0 to UBound($PointerTracker)-1 _ArrayDelete($DummyStruct, $i) _ArrayDelete($PointerTracker, $i) ;~ _ArrayDisplay($PointerTracker) Next EndIf EndFunc func exit1() Exit EndFunc