Problem bei meiner "Patch" UDF ...

  • Also als allererstes mal ein Frohes neues an alle...

    So und gleich zu meinem eigentlichen Problem, ich versuche mir ein UDF zu schreiben mit dem ich Dateien Patchen kann...

    Das Problem das ich habe ist, an $data hängt er während dem Patchen immer ein "00" (in HEX) an... jemand eine Idee was ich falsch mache? ?(

    Grüßle AlkoholiX

    Einmal editiert, zuletzt von AlkoholiX (1. Januar 2008 um 18:45)

  • Das hier?

    [autoit]

    If $hex = 0 Then
    $AFW_n = StringLen($data) ;Stringlen ist die Länge des Strings, warum addierst du dann 1?
    $AFW_ptr = DllStructCreate("char["&$AFW_n&"]")
    DllStructSetData($AFW_ptr,1,String($data))
    Else
    $data = StringSplit($data,",")
    $AFW_n = $data[0] ;$Data ist ein Array! Die Anzahl der Elemente steht in [0]
    $AFW_ptr = DllStructCreate("byte[" & $AFW_n & "]")
    For $AFW_i = 1 to $AFW_n
    DllStructSetData($AFW_ptr,1,Dec($data[$AFW_i]),$AFW_i)
    Next
    EndIf

    [/autoit]
  • Das hier?

    [autoit]

    $AFW_n = StringLen($data) ;Stringlen ist die Länge des Strings, warum addierst du dann 1?

    [/autoit]

    Wenn ich die 1 nicht addiere schreibt es einen Byte zuwenig, weiß auch nicht warum, aber er hängt trotzdem diese "00" an...

    Das hier?

    [autoit]

    $AFW_n = $data[0] ;$Data ist ein Array! Die Anzahl der Elemente steht in [0]

    [/autoit]

    Das hat leider auch nicht weiter geholfen...

    Die ganzen befehle habe ich aus der API.au3 kopiert, weiß aber nicht mehr woher ich die habe...

    API.au3

    Spoiler anzeigen
    [autoit]

    #include-once

    [/autoit] [autoit][/autoit] [autoit]

    ; _APIFileOpen( )
    ;
    ; Returns a "REAL" file handle for reading and writing.
    ; The return value comes directly from "CreateFile" api.
    Func _APIFileOpen( $szFile )
    Local $GENERIC_READ = 0x80000000, $GENERIC_WRITE = 0x40000000
    Local $OPEN_ALWAYS = 4, $FILE_ATTRIBUTE_NORMAL = 0x00000080
    Local $AFO_h
    $AFO_h = DllCall( "kernel32.dll", "hwnd", "CreateFile","str", $szFile,"long", BitOR($GENERIC_READ,$GENERIC_WRITE),"long", 0,"ptr", 0,"long", $OPEN_ALWAYS,"long", $FILE_ATTRIBUTE_NORMAL,"long", 0 )
    Return $AFO_h[0]
    EndFunc
    ; _APIFileClose( )
    ;
    ; The return value comes directly from "CloseHandle" api.
    Func _APIFileClose( $hFile )
    Local $AFC_r
    $AFC_r = DllCall( "kernel32.dll", "int", "CloseHandle","hwnd", $hFile )
    Return $AFC_r[0]
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; _APIFileSetPos( , )
    ;
    ; The return value comes directly from "SetFilePointer" api.
    Func _APIFileSetPos( $hFile, $nPos )
    Local $FILE_BEGIN = 0
    Local $AFSP_r
    $AFSP_r = DllCall( "kernel32.dll", "long", "SetFilePointer","hwnd",$hFile,"long",$nPos,"long*",0,"long",$FILE_BEGIN )
    Return $AFSP_r[0]
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; _APIFileRead( , , )
    ;
    ; Returns the data read. (Binary is comma delimited Hex values)
    ; Sets @error to the return from ReadFile api.
    Func _APIFileRead( $hFile, $nBytes, $Option=0 )
    Local $AFR_r, $AFR_n
    Local $AFR_str, $AFR_ret = ""

    [/autoit] [autoit][/autoit] [autoit]

    If $Option = 0 Then
    $AFR_str = DllStructCreate("char[" & $nBytes & "]")
    Else
    $AFR_str = DllStructCreate("byte[" & $nBytes & "]")
    EndIf

    $AFR_r = DllCall( "kernel32.dll", "int", "ReadFile","hwnd", $hFile,"ptr",DllStructGetPtr($AFR_str),"long",$nBytes,"long*",0,"ptr",0 )

    [/autoit] [autoit][/autoit] [autoit]

    If $Option = 0 Then
    $AFR_ret = StringLeft(DllStructGetData($AFR_str,1),$AFR_r[4])
    Else
    For $AFR_n = 1 to $AFR_r[4]
    $AFR_ret = $AFR_ret & Hex(DllStructGetData($AFR_str,1,$AFR_n),2) & ","
    Next
    $AFR_ret = StringTrimRight($AFR_ret,1)
    EndIf

    SetError($AFR_r[0])
    ; DllStructDelete($AFR_str)
    Return $AFR_ret
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; _APIFileWrite( , , )
    ;
    ; Returns # of Bytes written.
    ; Sets @error to the return from WriteFile api.
    ; For binary must be comma delimited hex values
    Func _APIFileWrite( $hFile, $szData, $Option=0 )
    Local $AFW_r, $AFW_n, $AFW_i
    Local $AFW_ptr

    [/autoit] [autoit][/autoit] [autoit]

    If $Option = 0 Then
    $AFW_n = StringLen($szData)+1
    $AFW_ptr = DllStructCreate("char[" & $AFW_n & "]")
    DllStructSetData($AFW_ptr,1,String($szData))
    Else
    $szData = StringSplit($szData,",")
    $AFW_n = $szData[0]
    $AFW_ptr = DllStructCreate("byte[" & $AFW_n & "]")
    For $AFW_i = 1 to $AFW_n
    DllStructSetData($AFW_ptr,1,Dec($szData[$AFW_i]),$AFW_i)
    Next
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $AFW_r = DllCall( "kernel32.dll", "int", "WriteFile","hwnd", $hFile,"ptr",DllStructGetPtr($AFW_ptr),"long",$AFW_n,"long*",0,"ptr",0 )

    [/autoit] [autoit][/autoit] [autoit]

    SetError($AFW_r[0])
    ; DllStructDelete($AFW_ptr)
    Return $AFW_r[4]
    EndFunc

    [/autoit]


    Habe das ganze auch schon erfolgreich genutzt, nur halt ohne eine Extra UDF dafür zu erstellen...

    Grüßle AlkoholiX

  • Also wenn ich das richtig verstehe, hast Du einen String, den nenn ich jetzt mal $a und er sieht so aus 123456. An diesen wird 00 angehängt -> 12345600.
    Dafüf gibt es die Funktion

    [autoit]

    StringTrimRight()

    [/autoit]

    .

    Sollte es doch ein Array sein, lass dir über Ubound($meinArray) -1 den letzten Wert ausgeben, der wo 00 drinsteht und lösche diesen, z.B.

    [autoit]

    ArrayDelete($meinArray, Ubound($meinArray) - 1))

    [/autoit]

    .

    PS: Sollten irgendwelche Fehler in meinem Post sein, dürfen diese gerne verbessert werden.

  • Im Hex wird "00" angehängt... sieht im Texteditor aus wie ein Leerzeichen...

    Bsp.:
    Eingegeben:
    ASCII: HEX:
    123456 -> 31,32,33,34,35,36
    Geschrieben wird aber:
    123456 -> 31,32,33,34,35,36,00

    Und diese "00" am ende macht das ganze leider nutzlos... (für meine zwecke)

    Grüßle AlkoholiX