Jump to content

Recommended Posts

Posted
1 hour ago, jchd said:

AutoIt uses a variant of duck typing.

I like to think of it as fuzzy logic with sprinkles.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted (edited)
Procedure.s GetIpToHostname(hostname.s)
    Define result.s = "", netid.i, ip.l ; Wrong, see below.
Procedure.s GetIpToHostname(hostname.s)
    Protected result.s = "", netid.i, ip.l
Procedure.s FileGetTime (NomFichier.s,flag,DateFormat.s="%mm/%dd/%yyyy %hh:%ii:%ss")
    Protected Directory$, FileName$, Time
Procedure.s Ping (hostname.s)
    Protected Ping, cont, work, risposta.s, time.s
Procedure.s FileGetSize(NomFichier.s) ; Update Function
    Protected Directory$, FileName$, Size$
    
FileName$ = NomFichier  ; ????
Procedure.s FileGetSize(NomFichier.s)
Procedure.s FileGetSize(FileName$) ; Directly variable

Macro FileGetSize(FileName)
    FileSize(FileName)
EndMacro

Debug FileGetSize ( "C:\Windows\explorer.exe" )
Macro ScriptDir ()
    GetPathPart(ProgramFilename())
EndMacro

Macro ScriptName ()
    GetFilePart(ProgramFilename())
EndMacro

Macro ScriptFullPath ()
    ProgramFilename()
EndMacro

Macro DesktopCommonDir ()
    GetUserDirectory(#PB_Directory_Desktop)
EndMacro

Macro MyDocumentsDir ()
    GetUserDirectory(#PB_Directory_Documents)
EndMacro

Macro ProgramFilesDir ()
    GetUserDirectory(#PB_Directory_Programs)
EndMacro

Macro TempDir ()
    GetTemporaryDirectory()
EndMacro

Macro Hours ()
    FormatDate("%hh", Date())
EndMacro

Macro Sec ()
    FormatDate("%ss", Date())
EndMacro

Macro Min ()
    FormatDate("%ii", Date())
EndMacro

Macro MDAY ()
    FormatDate("%dd", Date())
EndMacro

Macro MON ()
    FormatDate("%mm", Date())
EndMacro

Macro Years ()
    FormatDate("%yyyy", Date())
EndMacro

Macro CRLF ()
    #CRLF$
EndMacro

Macro CR ()
    #CR$
EndMacro

Macro LF ()
    #LF$
EndMacro

Macro MsgBox (flag,Title,Text)
    MessageRequester(Title, Text, flag)
EndMacro

Macro StringLen (String)
    Len(String)
EndMacro

Macro StringLenS (String)
    Str (Len(String))
EndMacro

Macro ClipPut (String)
    SetClipboardText(String)
EndMacro

Macro ClipGet ()
    GetClipboardText()
EndMacro

Macro Sleep (Time)
    Delay (Time)
EndMacro

; !i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i


Macro Randoms (Minimum,Maximum)
    Str (Random(Maximum,Minimum))
EndMacro

Macro DirCopy (Source,Dest)
    CopyDirectory(Source,Dest,"", #PB_FileSystem_Recursive)
EndMacro

Macro DirCreate (Source)
    CreateDirectory(Source)
EndMacro

Macro DirRemove (Source)
    DeleteDirectory(Source,"",#PB_FileSystem_Recursive)
EndMacro

Macro StringReplace (String,SearchString,Replace,Occurrence=0,Casesense=0)
    ReplaceString(String,SearchString,Replace,Casesense,Occurrence)
EndMacro

Macro StringRight (String,Count)
    Right (String,Count)
EndMacro

Macro StringLeft (String,Count)
    Left (String,Count)
EndMacro

Macro FileCopy (Source,Dest)
    CopyFile(Source,Dest)
EndMacro

Macro FileExists (Source)
    Bool(FileSize(Source) <> -1)
EndMacro

Macro StringUpper (String)
    UCase (String)
EndMacro

Macro StringLower (String)
    LCase (String)
EndMacro

Macro StringTrimLeft (String,n)
    Mid(String, n+1)
EndMacro

Macro StringTrimRight(String, n)
    Left(String, Len(String) - n)
EndMacro

Macro StringReverse(String)
    ReverseString(String)
EndMacro

Macro String(String)
    Str(String)
EndMacro

Macro TimerInit()
    Str (ElapsedMilliseconds())
EndMacro

Macro TimerDiff(StartTime)
    Str ((ElapsedMilliseconds() - Val(StartTime)))
EndMacro

Macro IsAdmin ()
    IsUserAnAdmin_()
EndMacro

; !i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i

MsgBox (#MB_ICONQUESTION, "Hello", ";)")

Debug ScriptDir ()
Debug ScriptName ()
Debug ScriptFullPath ()
Debug DesktopCommonDir ()
Debug MyDocumentsDir ()
Debug ProgramFilesDir ()
Debug TempDir ()
Debug Hours ()
Debug Sec ()
Debug Min ()
Debug MDAY ()
Debug MON ()
Debug Years ()
Debug CRLF ()
Debug CR ()
Debug LF ()
Debug StringLen ("Hello")
Debug StringLenS ("Hello")
ClipPut ("Hello")
Debug ClipGet ()
Sleep (100)

; !i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i

Debug Randoms (5,10)
Debug DirCopy ("Z:\19283746", "U:\56473829")
Debug DirCreate ("Z:\19283746")
Debug DirRemove ("Z:\19283746")
Debug StringReplace ("Hello","el","--")
Debug StringRight ("Hello",3)
Debug StringLeft ("Hello",3)
Debug FileCopy ("Z:\19283746", "U:\56473829")
Debug FileExists ("Z:\19283746")
Debug StringUpper ("Hello")
Debug StringLower ("Hello")
Debug StringTrimLeft ("Hello", 2)
Debug StringTrimRight("Hello", 2)
Debug StringReverse("Hello")
Debug String($FF)
st$ =  TimerInit()
Debug st$
Sleep (987)
Debug TimerDiff(st$)
Debug IsAdmin ()

Use "Protected". You must declare variables as local. Use "Macro" if the function fits on one line. An additional function will not be called, and instead of a function call, the contents are inserted.

Can do so

Macro aScriptDir
    GetPathPart(ProgramFilename())
EndMacro
Debug aScriptDir

At the end there is no slash. One character must be trimmed.

Macro aScriptDir
    StringTrimRight(GetPathPart(ProgramFilename()), 1)
EndMacro

Debug aScriptDir

 

Edited by AZJIO
Posted (edited)

@AZJIO thank you for your help I do not think it's a good idea to put everything in macro because with the functions there's a better management of the data it's my opinion

I think I'm going to turn some into macros and not others i will copy some part thank you 

the problem after procedures it does not duplicate I have to find a balance

Edited by ghost911
Posted

 

Macro StringLen (String)
    Len(String)
EndMacro
Debug StringLen ("Hello")

In this example, when you compile you get the following line

Debug Len ("Hello")

Debug, of course, does not compile, but I hope the meaning is clear. If you use the function, the string is copied and it requires memory. If you have a complex macro, has several variables and functions, then you can do it as a procedure

Posted (edited)

To understand what is happening, insert the contents of the macro at the point from where it is called. It will be a real representation of what is happening.

If you use it:

Macro StringLen (String,Flag=0) ; not working
If flag 
  Len(String)
ElseIf = 1 ; Seriously?
  Str(Len(String))
EndIf 
EndMacro

String$ = StringLen("Hello")
Debug String$

You will have the following:

String$ = If flag 
  Len(String)
ElseIf = 1 ; Seriously?
  Str(Len(String))
EndIf 
Debug String$

I hope it is clear that such code will not work

Can do so:

Define String$, String

Macro StringLen (String1,Flag=0)
If flag 
  String = Len(String1)
Else
  String$ = Str(Len(String1))
EndIf 
EndMacro

StringLen("Hello")
Debug String$
StringLen("Hello", 1)
Debug Str(String)

But it is not universal. I said earlier that you need to use macros on one line.

Edited by AZJIO
Posted (edited)

I now want to create a function to read a file (binary or not) and store it in the buffer and it comes out in hexadecimal mode

Local $hFileOpen = FileOpen("test RealCompilation.exe",16)
    If $hFileOpen = -1 Then
        MsgBox(0,"", "Error")
    EndIf
    Local $sFileRead = FileRead($hFileOpen)
    FileClose($hFileOpen)
    MsgBox(0,"", "Contenu du fichier:" & @CRLF & $sFileRead)

 

Edited by ghost911
Posted

PureBasic creates a null-terminated string or a pointer to the memory area. AutoIt3 creates a variable that can contain a null (Pascal type string, pointer and length). AutoIt3 can find Chr (0) in the string, but PureBasic cannot.

Posted

@AZJIO Hello I am not a great expert in purebasic so I have a question in purebasic strings are limited to a maximum size of 64K,how to get around this limit and find an exact address in memory to find the beginning of a string I imagine divide it into several pieces the idea is to store the file in hexadecimal form in memory I do not know if it is possible or if there are other solutions to imitate the function autoit

read.pb reads himself

If ReadFile(0,"read.pb")
    Taille = FileSize("read.pb")
    MemoireID = AllocateMemory(Taille)
    Debug Taille
  While Eof(0) = 0 
    String.s=Hex(ReadByte(0),#PB_Byte)
    CopyMemoryString(String,@MemoireID)
  Wend
  CloseFile(0)
  Byte=MemoryStringLength(MemoireID-Taille*2)
  Debug Byte
  Debug PeekS (MemoireID-Byte)
  Else
    MessageRequester("Info","Not open")
  EndIf

 

Posted

I do not know about the length limit of the string. If you read a string into memory, and then retrieve it with PeekS, then if the string is Null, it does not help, the string will still be trimmed. To read the file moving into memory, use ReadData. Data may contain #null. When retrieving data into a string variable, the end is #null. You cannot make string functions work with #null.

I haven’t studied PureBasic well enough, so contact the official forum for more accurate information. At least I would try replacing #null with the next character, checking that it was not there before, and then return it back. But how to replace if string functions do not work with it.

Posted

@AZJIO

Hello I just programmed a code to work around the problem and to read a file more quickly it read 33 byte at the same time for a faster reading it transforms any file in hexadecimal to then program the function ReadFile with the flag 16 missing code optimization or new ideas

 
TempsDepart.q = ElapsedMilliseconds()
If ReadFile(0,"test RealCompilation.exe")
length = Lof(0)
*MemoryID = AllocateMemory(length)
If *MemoryID
bytes = ReadData(0, *MemoryID, length) 
EndIf
CloseFile(0)
StringBytes$=""
For I=0 To length -1
Esult = MemorySize(*MemoryID)-I
If Esult => 33
StringBytes.s=StringBytes+Hex(PeekB (*MemoryID+I),#PB_Byte)+Hex(PeekB (*MemoryID+I+1),#PB_Byte)+Hex(PeekB (*MemoryID+2),#PB_Byte)+Hex(PeekB (*MemoryID+I+3),#PB_Byte)+Hex(PeekB (*MemoryID+I+4),#PB_Byte)+Hex(PeekB (*MemoryID+I+5),#PB_Byte)+Hex(PeekB (*MemoryID+I+6),#PB_Byte)+Hex(PeekB (*MemoryID+I+7),#PB_Byte)+Hex(PeekB (*MemoryID+I+8),#PB_Byte)+Hex(PeekB (*MemoryID+I+9),#PB_Byte)+Hex(PeekB (*MemoryID+I+10),#PB_Byte)+Hex(PeekB (*MemoryID+I+11),#PB_Byte)+Hex(PeekB (*MemoryID+I+12),#PB_Byte)+Hex(PeekB (*MemoryID+I+13),#PB_Byte)+Hex(PeekB (*MemoryID+I+14),#PB_Byte)+Hex(PeekB (*MemoryID+I+15),#PB_Byte)+Hex(PeekB (*MemoryID+I+16),#PB_Byte)+Hex(PeekB (*MemoryID+I+17),#PB_Byte)+Hex(PeekB (*MemoryID+18),#PB_Byte)+Hex(PeekB (*MemoryID+I+19),#PB_Byte)+Hex(PeekB (*MemoryID+I+20),#PB_Byte)+Hex(PeekB (*MemoryID+I+21),#PB_Byte)+Hex(PeekB (*MemoryID+I+22),#PB_Byte)+Hex(PeekB (*MemoryID+I+23),#PB_Byte)+Hex(PeekB (*MemoryID+I+24),#PB_Byte)+Hex(PeekB (*MemoryID+I+25),#PB_Byte)+Hex(PeekB (*MemoryID+I+26),#PB_Byte)+Hex(PeekB (*MemoryID+I+27),#PB_Byte)+Hex(PeekB (*MemoryID+I+28),#PB_Byte)+Hex(PeekB (*MemoryID+I+29),#PB_Byte)+Hex(PeekB (*MemoryID+I+30),#PB_Byte)+Hex(PeekB (*MemoryID+I+31),#PB_Byte)+Hex(PeekB (*MemoryID+I+32),#PB_Byte)
I=I+32
Else
StringBytes.s=StringBytes+Hex(PeekB (*MemoryID+I),#PB_Byte)
EndIf 
Next
Debug StringBytes
EndIf
TempsEcoule.q = ElapsedMilliseconds()-TempsDepart  ; La valeur 'TempsEcoule' devrait être d'environ 1000 millisecondes
Debug "Temps écoulé : "+Str(TempsEcoule)+" millisecondes"

 

Posted
the code is still slow for large file is missing the solution I thought increased the number of byte read but I do not know the limit yet

 
Posted

Can't you write a long string as a loop?

Define StringBytes.s
For j=0 To 32
    StringBytes + Hex(PeekB (*MemoryID+I+j),#PB_Byte)
Next
; Equally
I=I+32
I+32

I think we need a "Step" here.

For I=0 To length -1 Step 32
Quote

the code is still slow

If you copy into a variable each time, then memory is allocated each time, so slowly. Allocate memory 2 times more and copy new data there, and then read a line from the memory entirely. Use the following method:

Len=0
ForEach Files()
    Len + Len(Files())+2
Next

*Result\s = Space(Len)
*Point = @*Result\s
ForEach Files()
    CopyMemoryString(Files()+#CRLF$, @*Point)
Next

Instead of "Len" use your string size.

Posted (edited)

no because with "for" it does not work it's reading byte after byte

if the file is big it will take a long time to read it

made a comparison of the time with your method and mine to read an executable file

with my methode :

32 milliseconds

with your method

865 milliseconds

For j=0 To 32
    StringBytes + Hex(PeekB (*MemoryID+I+j),#PB_Byte)
Next

 

Edited by ghost911

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...