Jump to content

help. string to array?


Recommended Posts

hi,

I want to move a string to an array without the use of Files (.txt).

I have a code that works this way:

$m=TCPrecv ($connectedsocket,16000,1)

now $m has the following input:

#'ת'נתנ!This system is restricted solely to authorized users for legitimate business
purposes only.  The actual or attempted unauthorized access, use, or
modification of this system is strictly prohibited.  Unauthorized users are
subject to company disciplinary procedures and or criminal and civil penalties
under state, federal, or other applicable domestic and foreign laws.  The use of
this system may be monitored and recorded for administrative and security
reasons.  Anyone accessing this system expressly consents to such monitoring and
recording, and is advised that if it reveals possible evidence of criminal
activity, the evidence of such activity may be provided to law enforcement
officials.  All users must comply with all corporate instructions regarding the
protection of information assets.
login: sa
Password: 
Last login: Tue Jul 22 09:56:23 from 192.100.100.54
Welcome to Intuity Audix sa login
TERM=[linux]? 4410
[1;25r[m[1;25r[m[0m[1;03q               OP[2;03q                OQ[3;03q                OR[4;03q                OS[5;03q                OT[6;03q                OU[7;03q                OV[8;03q                OW[1;00qCancel        [2;00qRefresh      [3;00qEnter           [4;00qClearFld       [5;00qHelp          [6;00qChoices        [7;00qNextPage     [8;00qPrevPage      [H[J[B[0;7m                                                                             [A[m[B[23;1H[0;7m                                                                               [A[m[H[24;1Henter command: [Hyashir[1;20HActive[1;37HAlarms:   w[1;72HLogins: 1[24;16Hdisp adminlay administrator's-log [H[B[0;7mdisplay administrator's-log[24;44H[m[2;70H[0;7mPlease Wait[24;44H[m[2;71H[0;7mage 1 of 1[24;44H[m[3;30HADMINISTRATOR'S LOG[6;3HThe following options control which entries will be displayed.[9;6HStart Date: [0;4m07[m/[0;4m21[m/[0;4m08[9;36H[mTime: [0;4m09[m:[0;4m48[11;5H[mApplication: [0;4m  [11;32H[mEvent ID: [0;4m             
[B[B[mSearch String:
[B[B[0;4m                                                                             [9;18H[m[C[0;4m [m[0;4m7[m[C[C[C[0;4m [m[0;4m2[m[C[C[9;42H[C[0;4m [m[0;4m9[m[C[C[11;18H[0;4mV[m[0;4mM[m[1;80H2[11;19H[11;42H[0;4mA[m[0;4mD[m[0;4mM[m[0;4m_[m[0;4ma[m[0;4mp[m[0;4mi[m[0;4mb[m[15;1H[2;70H[0;7m        [15;1H[m[2;70H[0;7mPlease Wait[15;1H[m[2;71H[0;7mage 1 of 1[15;1H[m[2;71H[0;7mlease Wait[m[2;70H[0;7m     Page 1[m[5;3HDate   Time   App Event ID     Cnt       Message
[B  [K[9;6H[K[B[B[K
[B[B[K[B[B[K[22;42H
[B[0;7mPress [NextPage], [PrevPage] or [Cancel] to abort[22;42H[m[3;1H

I don't want to do this:

$j=fileopen ("c:\erez.txt",2)

filewrite ("c:\erez.txt",$m)

fileclose ($j)

I don't want to use the harddrive at all.

I only have this command: "filereadtoarray", to move the string into an array for manipulation. but isn't there a better way?

no "stringtoarray" or something like it?

Edited by erezlevi
Link to comment
Share on other sites

StringSplit()

Tired it allready, it isn't working. I am guessing to much data. but if I put the following lines with a file involved in the middle then the file has all the data nessecery:

TCPSend($ConnectedSocket, Binary("0x1b4f52"))
Sleep(2000)
$m = TCPRecv($ConnectedSocket, 16000, 0)
Sleep(1500)
;MsgBox (0,"this is $m",$m)
$J=FileOpen ("c:\stringtest.txt",2)
filewrite ("c:\stringtest.txt",$m)
FileClose ($J)
;$sfileread = StringReplace($m, Chr(0), "")
;$Replace = StringReplace($sfileread, "", "")
;$Replace = StringReplace($Replace, Chr("7f"), "")
$E = StringSplit($m, "TERM=[linux]",1)
_ArrayDisplay($E)

the file "stringtest.txt" contains all the data I needs, but , $E array contains nothing. how come?

Link to comment
Share on other sites

Maximum string length: 2,147,483,647 characters

StringSplit is the main function in the UDF named _FileReadToArray

Just as a test, does _FileReadToArray work for you?

yes, thats is what the problem, if using a file instead of $m as a string it is working.

Link to comment
Share on other sites

Hi, i'm a newbie...

I try to use "IsString" fonction but it doesn't work for me too !

I don't understand... very simple fonction script !

Let me explain to us :

==> I try to check the word "Failed" in a text file name "toto.txt"

In the case where the word (failed) doesn't exist, the return code is "1" equal to good match ????!!!!

Is it a bug ?

here is my script:

#include <file.au3>

#include <String.au3>

Dim $file

Dim $line

Dim $result = 0

$file = FileOpen("c:\toto.txt", 0)

$result = IsString("failed")

While 1

$line = FileRead($file)

If $result = 1 Then

MsgBox(0, "Ok", "The word is in the box ! ")

ExitLoop

Else

MsgBox(0, $line, "Sorry...no more word !")

ExitLoop

EndIf

Wend

FileClose($file)

FileReadLine.au3

Link to comment
Share on other sites

Hi, i'm a newbie...

I try to use "IsString" fonction but it doesn't work for me too !

I don't understand... very simple fonction script !

Let me explain to us :

==> I try to check the word "Failed" in a text file name "toto.txt"

In the case where the word (failed) doesn't exist, the return code is "1" equal to good match ????!!!!

Is it a bug ?

here is my script:

#include <file.au3>

#include <String.au3>

Dim $file

Dim $line

Dim $result = 0

$file = FileOpen("c:\toto.txt", 0)

$result = IsString("failed")

While 1

$line = FileRead($file)

If $result = 1 Then

MsgBox(0, "Ok", "The word is in the box ! ")

ExitLoop

Else

MsgBox(0, $line, "Sorry...no more word !")

ExitLoop

EndIf

Wend

FileClose($file)

go with :

local $Array[500]

_filereadtoarray ("c:\toto.txt",$Array)

_Arraydisplay ($Array)

$m=Arraysearch ($Array,"Failed",0,0,1,1)

if $m = -1 then msgbox (0,"no word","")

if $m <> -1 then msgbox (0,"word!","")

Link to comment
Share on other sites

... I try to use "IsString" fonction but it doesn't work for me too ! ...

IsString() tells you if the variant* contains numeric or string data.

Try this code:

$result = IsString("failed")
MsgBox(0, 'IsString("failed")', $result)

$result = IsString(7)
MsgBox(0, "IsString(7)", $result)

*

In AutoIt there is only one datatype called a Variant. A variant can contain numeric or string data and decides how to use the data depending on the situation it is being used in. For example, if you try and multiply two variants they will be treated as numbers, if you try and concatenate (join) two variants they will be treated as strings.

^^^ from the help file ^^^ Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Hi,

well remember my problem. well my script run as a system service. so it was something like this:

while 1
call ("erez1")
sleep (4 minutes)
wend

func erez1()
connect tcp to server
get data....
put data on txt file because you can't save it to memory (to much I guess).
put txt file into array.
search for string.
if string found reconnect and make a change.
if string not found return the function.
return
endfunc

I found out that if this script runs as a service after a day it can't write to the Harddrive anymore. so I'v changed it to not use a while but I am now using the windows schedual tasks for every 4 min to run it.

it works for three days now....don't know if this is a bug or what, but strange thing.

Link to comment
Share on other sites

... I found out that if this script runs as a service after a day it can't write to the Harddrive anymore. ...

I realize that you were writing pseudo-code in your post above, so some lines are missing by definition... but be sure to open/close the file.

I do not think that you are reaching the limit for a string. It is probably something else. Maybe someone will spot it.

pseudo-code without the 4 minute loop implemented by Task Scheduler:

[maybe no While/WEnd is needed]

[maybe no Func/EndFunc is needed]

connect tcp to server

get data....

open file for erase/write

put data in txt file

close file

open file for read

put txt file into array

close file

search for string

if string found reconnect and make a change

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

the code is correct,

the file size is 3kb.

I am opening the file like that:

$J=fileopen ("C:\test.txt",2)
filewrite ("c:\test.txt",$data)
fileclose ($J)

here is the full code if any one want to see:

#include <File.au3>
#include <Array.au3>
#include <String.au3>

FileDelete("c:\audix.txt")
FileDelete("c:\audix1.txt")
Call("erez1")
Exit

Func erez1()
    
    If Not FileExists("c:\auidxlog.txt") Then
        FileOpen("c:\audixlog.txt", 1)
    EndIf

; Start The TCP Services
;==============================================
    TCPStartup()
    $i = 1
; Set Some reusable info
;--------------------------
    Dim $szServerPC = "10.0.50.220"
; Set $szIPADDRESS to wherever the SERVER is. We will change a PC name into an IP Address
    Dim $szIPADDRESS = "10.0.50.220"
    Dim $nPORT = 23

    $i = 1
; Initialize a variable to represent a connection
;==============================================
    Dim $ConnectedSocket = -1
;Dim $FirstGUI = GUICreate ("Please choose what information you would like to have",250,350,100,100)
;$button1=GUICtrlCreateButton ("Skill"&$s0,100,50)
;$button2=GUICtrlCreateButton ("VDN"&$s1,100,80)
;Dim $edit = GUICtrlCreateEdit("", 10, 10, 280, 180)
;GUISetState()

;Attempt to connect to SERVER at its IP and PORT 23 (TELNET)
;=======================================================
    $ConnectedSocket = TCPConnect($szIPADDRESS, $nPORT)
    Sleep(600)
    TCPSend($ConnectedSocket, Binary("0xfffb18fffb1f"))
    Sleep(300)
    TCPSend($ConnectedSocket, Binary("0xfffc20fffc23fffb27"))
    Sleep(500)
    TCPSend($ConnectedSocket, Binary("0xfffa1f00500019fff0"))
    Sleep(500)
    TCPSend($ConnectedSocket, Binary("0xfffa2700fff0"))
    Sleep(500)
    TCPSend($ConnectedSocket, Binary("0xfffa1800414e5349fff0"))
    Sleep(500)
    TCPSend($ConnectedSocket, Binary("0xfffd03"))
    Sleep(500)
    TCPSend($ConnectedSocket, Binary("0xfffb01fffe05fffc21"))
    Sleep(500)
    TCPSend($ConnectedSocket, Binary("0xfffc01"))
    Sleep(500)
    TCPSend($ConnectedSocket, Binary("0xfffd01"))
    Sleep(500)
;===========================================================user name + password========

    TCPSend($ConnectedSocket, "sa")
    Sleep(500)
    TCPSend($ConnectedSocket, Binary("0x0d"))
    Sleep(500)
    TCPSend($ConnectedSocket, "yashir")
    Sleep(500)
    TCPSend($ConnectedSocket, Binary("0x0d"))
    Sleep(2500)
;============================================================Terminal type
    TCPSend($ConnectedSocket, "4410")
    Sleep(500)
    TCPSend($ConnectedSocket, Binary("0x0d"))
    Sleep(2000)
;===========================================================================
;==================display admin log======================================
    TCPSend($ConnectedSocket, "disp admin")
    Sleep(1300)
    TCPSend($ConnectedSocket, Binary("0x0d"))
    Sleep(2000)
    TCPSend($ConnectedSocket, @MON)
    Sleep(1500)
    TCPSend($ConnectedSocket, Binary("0x0d"))
    Sleep(1500)
    TCPSend($ConnectedSocket, @MDAY)
    Sleep(1500)
    TCPSend($ConnectedSocket, Binary("0x0d"))
    Sleep(1500)
    TCPSend($ConnectedSocket, Binary("0x0d"))
    Sleep(1500)
    If @MIN = 00 Then
        TCPSend($ConnectedSocket, @HOUR - 1)
        Sleep(1500)
        TCPSend($ConnectedSocket, Binary("0x0d"))
        Sleep(1500)
        TCPSend($ConnectedSocket, "58")
        Sleep(1500)
    EndIf
    If @MIN = 01 Then
        TCPSend($ConnectedSocket, @HOUR - 1)
        Sleep(1500)
        TCPSend($ConnectedSocket, Binary("0x0d"))
        Sleep(1500)
        TCPSend($ConnectedSocket, "59")
        Sleep(1500)
    EndIf
    If @MIN <> 00 Or 01 Then
        TCPSend($ConnectedSocket, @HOUR)
        Sleep(1500)
        TCPSend($ConnectedSocket, Binary("0x0d"))
        Sleep(1500)
        TCPSend($ConnectedSocket, @MIN - 2)
        Sleep(1500)
    EndIf
    
    TCPSend($ConnectedSocket, Binary("0x0d"))
    Sleep(1500)
    TCPSend($ConnectedSocket, "VM")
    Sleep(1500)
    TCPSend($ConnectedSocket, Binary("0x0d"))
    Sleep(1500)
    TCPSend($ConnectedSocket, "ADM_apib")
    Sleep(1500)
    TCPSend($ConnectedSocket, Binary("0x0d"))
    Sleep(2000)
    TCPSend($ConnectedSocket, Binary("0x1b4f52"))
    Sleep(2000)
    $m = TCPRecv($ConnectedSocket, 16000, 1)
    Sleep(1500)
    $j = FileOpen("c:\audix.txt", 2)
    FileWrite("c:\audix.txt", $m)
    FileClose($j)
;====================================================buliding up an array for searching...================
    Local $EREZ[500]
    $FileOrig = "c:\audix.txt"
    $sfileread = FileRead($FileOrig)
    $sfileread = StringReplace($sfileread, Chr(0), "")
;$sfileread = StringReplace($sfileread, Chr(13), "")
    $FileResult = "c:\audix1.txt"
    $hFile = FileOpen($FileResult, 2)
    FileWrite($hFile, $sfileread)
    FileClose($hFile)
    $Read = FileRead("c:\audix1.txt")
    $Replace = StringReplace($Read, "", "")
    $Replace = StringReplace($Replace, Chr("7f"), "")
    $EREZ = StringSplit($Replace, "[")
;_ArrayDisplay($EREZ)
    $k = _ArraySearch($EREZ, "Break-in", 0, 0, 1, 1)
    If @error Then
    ;FileWrite("c:\audixlog.txt", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & " -> NO problem" &@CRLF)
        TCPCloseSocket($ConnectedSocket)
        TCPShutdown()
        Return
    EndIf

    $t = $EREZ[$k]
    $t1 = StringSplit($t, ",")
    $t1 = $t1[2]
;MsgBox (0,"this is $t1",$t1)
    $t1 = StringStripWS($t1, 8)
    $t1 = StringTrimLeft($t1, 1)
    $t1 = StringTrimRight($t1, 4)
;MsgBox(0, "this is $t1", $t1)
;======================================sending F1 and starting to change if needed==============================================
    TCPSend($ConnectedSocket, Binary("0x1b4f50"))
    Sleep(1300)
    TCPSend($ConnectedSocket, "change sub " & $t1)
    Sleep(1300)
    TCPSend($ConnectedSocket, Binary("0x0d"))
    Sleep(1300)
    TCPSend($ConnectedSocket, Binary("0x1b5b43"))
    Sleep(1300)
    TCPSend($ConnectedSocket, "n")
    Sleep(1300)
    TCPSend($ConnectedSocket, Binary("0x1b5b42"))
    Sleep(1300)
    TCPSend($ConnectedSocket, "2486")
    Sleep(1300)
    TCPSend($ConnectedSocket, Binary("0x1b4f52"))
    Sleep(1300)
    TCPSend($ConnectedSocket, "exit")
    Sleep(1300)
    TCPSend($ConnectedSocket, Binary("0x0d"))
    Sleep(1300)
;================================================================================================

=========================
    FileWrite("c:\audixlog.txt", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & " -> " & $t &" POP3"& @CRLF)
    TCPCloseSocket($ConnectedSocket)
    TCPShutdown()
    Return
EndFunc  ;==>erez1
Link to comment
Share on other sites

the code is correct,...

it sure seems to be - but there is no reason for it not to be able to read from and write to the hard drive all day long.

I might have missed your answer - did you try the IsString() on $m

http://www.autoitscript.com/forum/index.ph...st&p=562138

If it is not a string - then maybe:

$m = String($m)

[size="1"][font="Arial"].[u].[/u][/font][/size]

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