Oh thank you. I actually didn't see that. I started the github story to learn how to use github.
So far I didn't have a pull request and thought I would get some notification in that case.
But I have received nothing.
Let's see if I can set something.
Now to your changes:
Basically you can drive several approaches.
Either you design your code so that it is usable with as many use cases as possible or you optimize it for certain special cases.
With the latter you buy speed compared to more code and possibly also clarity.
So far I have used exactly this general approach with _JSON_Generate(). If you take a closer look, you could consider two more common special cases when using it here: On the one hand the case of the most compact JSON code possible (which funnily enough I simplified just yesterday with the _JSON_GenerateCompact()) and on the other hand a more common parameter choice for good human readability. The latter I have covered so far via the default parameters of _JSON_Generate().
Now, of course, you can write special functions for both and, unsurprisingly, achieve a performance boost for these cases.
For one special case - the compact JSON code - you have now done this and in my measurements I get a performance increase of 20-25% compared to the general functions.
That's not little and now you can already ask if the tradeoff of performance improvement vs. code complexity makes sense or not. I myself needed the performance so far with _JSON_Parse(). With _JSON_Generate() I never reached a limit where I needed more. But that can be different for other users.
Therefore you can consider to add special functions for this, if there is a demand for it.
However, I would not like to take over the adjustments from you directly, for the following reasons:
_JSON_Generate() defaults to the nicely formatted _JSON code. With youre changes it becomes script-breaking because you now suddenly define the compact JSON code as the default case. Why not leave _JSON_Generate as the universal form and cast your case to a _JSON_GenerateCompact() instead? That way the backward compatibility would still exist.
I don't really like the $_JSON_TYPES approach considering the result achieved with this. You need another function which is executed once (and which itself could be ~80% faster), another global constant and the readability decreases (slightly). Result with my measurements: 1-2% faster.
That is not worth it, at least for me.
So in summary: Yes I could already imagine special _JSON_GenerateX functions for the two cases. But if then without the $_JSON_TYPES approach and without changing the behavior of _JSON_Generate().
But this concerns only my repository.
The nice thing about open source is that everyone can fork it and rewrite it according to their own ideas.
Otherwise, big thanks again for letting me continue to learn collaborative work via github through you!
Hi folks ๐ ,
I know about several of us do have AutoIt projects on GitHub.
In this hopefully growing collection I want to list forum members and their GitHub projects (AutoIt based).
Why?
One use case could be the contribution to some of their projects.
Assume that AutoIt projects are not that wide spreaded or supported in terms of contribution (participation), as JavaScript projects for example.
Wouldn't it be nice to get more contribution on your project?
Wouldn't it be nice to work on bigger projects in a community?
I personally would love to ๐ .
Disclaimer:
As the GitHub profiles (and repositories), I will list here, are public and your profiles either findable by your signature, your "About Me" page or by a simple Google or GitHub search ๐ , I see no restriction to collect these kind of information and post it here. In case you don't agree with this visualisation and you don't want to be listet here, please let me know and I will remove that entry as soon as possible ๐ค . I really hope that fits your feeling about it.
Collection (in progress):
@Forum username ยป GitHub username ยป Link to the GitHub projects (filtered by language=autoit)
@Alan72104 ยป Alan72104 ยป Projects
@alexanr1 ยป alexanr1 ยป Projects
@AspirinJunkie ยป Sylvan86 ยป Projects
@Centrally ยป ellysh ยป Projects
@Danp2 ยป Danp2 ยป Projects
@Danyfirex ยป DanysysTeam ยป Projects
@DonChunior ยป DonChunior ยป Projects
@ergo ยป seizu ยป Projects
@genius257 ยป genius257 ยป Projects
@J2TeaM ยป J2TEAM ยป Projects
@James ยป jbrooksuk ยป Projects
@Jefrey ยป jesobreira ยป Projects
@jvanegmond ยป jvanegmond ยป Projects
@kurtykurtyboy ยป KurtisLiggett ยป Projects
@lamnhan066 ยป lamnhan066 ยป Projects
@LinkOut ยป xLinkOut ยป Projects
@LoganCH ยป loganch ยป Projects
@Mat ยป MattDiesel ยป Projects
@Mateocedillo ยป rmcpantoja ยป Projects
@matwachich ยป matwachich ยป Projects
@mLipok ยป mlipok ยป Projects
@MrKm ยป MurageKabui ยป Projects
@NHD ยป nomi-san ยป Projects
@oHenry ยป htejera ยป Projects
@OvisMaximus ยป OvisMaximus ยป Projects
@philpw99 ยป philpw99 ยป Projects
@rcmaehl ยป rcmaehl ยป Projects
@Rurorita ยป OfficialLambdax ยป Projects
@rynow ยป 4ern ยป Projects
@scintilla4evr ยป scidsgn ยป Projects
@seadoggie01 ยป seadoggie01 ยป Projects
@seangriffin ยป seanhaydongriffin ยป Projects
@smbape ยป smbape ยป Projects
@SOLVE-SMART ยป Sven-Seyfert ยป Projects
@Stilgar ยป THWillert ยป Projects
@Surya ยป thesunRider ยป Projects
@tarretarretarre ยป tarreislam ยป Projects
@TheDcoder ยป TheDcoder ยป Projects
@TheSaint ยป Twombs ยป Projects
@trancexx ยป dragana-r ยป Projects
@vietanhdev ยป vietanhdev ยป Projects
ฮฃ = 41
I would love to see the list growing and I am very excited about a possibly upcoming behavior and improvement change, regarding AutoIt on GitHub ๐ .
๐ก Please help me to increase the list. Either by your GitHub link (profile) or through a link from a member you know.
Best regards
Sven
From time to time questions arise about listviews with multi-line headers or headers with increased height. Eg. these two questions: Multi-line listview column headings and Listview header height.
To use a multi-line header in a listview the height of the header must be increased to make room for multiple lines, and it must be possible to display multiple text lines in the header items.
Increase height of header control
Because the header control is contained in a listview, the height of the header must be increased in such a way that the listview will be aware of the increased height.
An easy and common method of increasing the height is to define a text font for the header with a suitable height. Increasing the height in this way requires that the header is not provided with any themes. However, it is possible to restore themes after the height is increased.
A better but slightly more cumbersome method is based on HDM_LAYOUT messages. A HDM_LAYOUT message (implemented in _GUICtrlHeader_Layout) is used to retrieve information about the size of a header control. To use this message to define the height, the header control must be subclassed.
The HDM_LAYOUT method is preferred in the examples. Two examples with the font height method are added in "Using font height" folder.
Whichever method is chosen, the header height must be increased before rows are added to the listview.
Subclassing controls
After Windows XP the recommended way to subclass controls is to use the four functions SetWindowSubclass, GetWindowSubclass, RemoveWindowSubclass and DefSubclassProc (all implemented in WinAPIShellEx.au3). These functions are used in the examples. And they are much easier to use than the old SetWindowLong (_WinAPI_SetWindowLong) function.
Since we are subclassing a header control contained in a listview this issue must be taking into account. I have verified that this is also an issue for _WinAPI_DefSubclassProc. The solution is the same as the solution in the link:
;Return _WinAPI_DefSubclassProc( ... ) ; Not so good
Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", ... )[0] ; Much better
Responding to HDM_LAYOUT messages
HDM_LAYOUT messages are generated when columns are added to the listview with _GUICtrlListView_AddColumn. To respond to these messages the header control must be subclassed before columns are added:
Local $pHeaderProc = DllCallbackGetPtr( DllCallbackRegister( "HeaderProc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) )
_WinAPI_SetWindowSubclass( $hHeader, $pHeaderProc, 9999, $iHeaderHeight ) ; SubclassId = 9999, $pData = $iHeaderHeight
If columns are added directly in GUICtrlCreateListView command, this code snippet (copied from _GUICtrlHeader_Create) can be used to generate a HDM_LAYOUT message:
Local $tRect = _WinAPI_GetClientRect( $hListView )
Local $tWindowPos = _GUICtrlHeader_Layout( $hHeader, $tRect )
_WinAPI_SetWindowPos( $hHeader, DllStructGetData( $tWindowPos , "InsertAfter" ), _
DllStructGetData( $tWindowPos , "X" ), DllStructGetData( $tWindowPos , "Y" ), _
DllStructGetData( $tWindowPos , "CX" ), DllStructGetData( $tWindowPos , "CY" ), _
DllStructGetData( $tWindowPos , "Flags" ) )
This is the subclass callback function:
Func HeaderProc( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $iHeaderHeight )
#forceref $iSubclassId
Switch $iMsg
Case $HDM_LAYOUT
Local $tHdLayout = DllStructCreate( $tagHDLAYOUT, $lParam )
Local $tRect = DllStructCreate( $tagRECT, DllStructGetData( $tHdLayout, "Rect" ) )
Local $tWindowPos = DllStructCreate( $tagWINDOWPOS, DllStructGetData( $tHdLayout, "WindowPos" ) )
; Modify $tRect and $tWindowPos in $tHdLayout to increase Header height
DllStructSetData( $tRect, "Top", $iHeaderHeight )
DllStructSetData( $tWindowPos, "X", DllStructGetData( $tRect, "Left" ) )
DllStructSetData( $tWindowPos, "Y", 0 )
DllStructSetData( $tWindowPos, "CX", DllStructGetData( $tRect, "Right" ) - DllStructGetData( $tRect, "Left" ) )
DllStructSetData( $tWindowPos, "CY", $iHeaderHeight )
DllStructSetData( $tWindowPos, "Flags", 0x0020 ) ; 0x0020 = $SWP_FRAMECHANGED
Return True
EndSwitch
; Call next function in subclass chain
Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0]
EndFunc
Multiple text lines in header items
The items in a standard header control can display a single line of text. There seems not to be any options to change this. There is no word wrap option. Fortunately the header control supports both custom and owner drawn items.
Custom drawn items are implemented through NM_CUSTOMDRAW notifications included in WM_NOTIFY messages. NM_CUSTOMDRAW notifications are generated automatically by the code in ComCtl32.dll when the header control is updated. Implementing custom drawn items is a matter of responding to these messages or not.
Owner drawn items are implemented through WM_DRAWITEM messages. The HDF_OWNERDRAW flag must be set for the header items to generate WM_DRAWITEM messages.
Custom drawn items are preferred in the examples. An example with owner drawn items is added in "Owner drawn" folder.
Custom drawn items
WM_NOTIFY (and WM_DRAWITEM) messages are send to the parent of the header control. The parent is usually an AutoIt GUI, and messages can be handled by a function registered with GUIRegisterMsg. In this case the listview is the parent of the header control. To catch header messages from the listview, the listview must be subclassed.
Implement subclassing for the listview:
Local $pListViewProc = DllCallbackGetPtr( DllCallbackRegister( "ListViewProc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) )
_WinAPI_SetWindowSubclass( $hListView, $pListViewProc, 9999, 0 )
The subclass callback function looks like this:
Func ListViewProc( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData )
#forceref $iSubclassId, $pData
Switch $iMsg
Case $WM_NOTIFY
Local $tNMHDR = DllStructCreate( $tagNMHDR, $lParam )
Local $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) )
Local $iCode = DllStructGetData( $tNMHDR, "Code" )
Switch $hWndFrom
Case $hHeader
Switch $iCode
Case $NM_CUSTOMDRAW
Local $tNMCustomDraw = DllStructCreate( $tagNMCUSTOMDRAW, $lParam )
Local $dwDrawStage = DllStructGetData( $tNMCustomDraw, "dwDrawStage" )
Switch $dwDrawStage ; Holds a value that specifies the drawing stage
Case $CDDS_PREPAINT ; Before the paint cycle begins
Return $CDRF_NOTIFYITEMDRAW ; Notify parent window of any item related drawing operations
Case $CDDS_ITEMPREPAINT ; Before an item is drawn: Default painting (frames and background)
Return $CDRF_NOTIFYPOSTPAINT ; Notify parent window of any post item related drawing operations
Case $CDDS_ITEMPOSTPAINT ; After an item is drawn: Custom painting (item texts)
Local $iIndex = DllStructGetData( $tNMCustomDraw, "dwItemSpec" ) ; Item index
Local $hDC = DllStructGetData( $tNMCustomDraw, "hdc" ) ; Device context
_WinAPI_SetBkMode( $hDC, $TRANSPARENT ) ; Transparent background
DllStructSetData( $tNMCustomDraw, "Left", DllStructGetData( $tNMCustomDraw, "Left" ) + $aHdrInfo[$iIndex][1] ) ; Left margin
DllStructSetData( $tNMCustomDraw, "Right", DllStructGetData( $tNMCustomDraw, "Right" ) - $aHdrInfo[$iIndex][1] ) ; Right margin
DllStructSetData( $tNMCustomDraw, "Top", DllStructGetData( $tNMCustomDraw, "Top" ) + 2 ) ; 2 pixel top margin
DllStructSetData( $tNMCustomDraw, "Bottom", DllStructGetData( $tNMCustomDraw, "Bottom" ) - 4 ) ; 4 pixel bottom margin
DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $aHdrInfo[$iIndex][0], "int", StringLen( $aHdrInfo[$iIndex][0] ), "struct*", DllStructGetPtr( $tNMCustomDraw, "Left" ), "uint", $aHdrInfo[$iIndex][2] ) ; _WinAPI_DrawText
Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
EndSwitch
EndSwitch
EndSwitch
EndSwitch
; Call next function in subclass chain
Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0]
EndFunc
Default code in the $CDDS_ITEMPREPAINT stage draws the item frames and background. Code is added to the $CDDS_ITEMPOSTPAINT stage to draw the multi-line item texts.
Since we are forced to use custom drawn (or owner drawn) items in any case, we might as well take the opportunity to use some of the options which custom drawn (or owner drawn) items offers. This includes various text styles and fonts, colored text and background, item icons or bitmaps and item frames.
The picture shows some of the possibilities:
Examples
The examples are divided into four folders:
Custom drawn contains the examples based on custom drawing. In these examples there is only added code to the $CDDS_ITEMPOSTPAINT stage to fill the inside of the item frames.
Owner drawn folder contains an example that shows how to use an owner drawn header control.
Two examples in Using font height shows how to use a font to increase the height of the header. Themes are disabled for the header control while the height is increased. Items are custom drawn. The first example restores the theme and draws multi-line texts in the $CDDS_ITEMPOSTPAINT stage. The second example draws entire header items including frames in the $CDDS_ITEMPREPAINT stage. Frames are drawn with _WinAPI_DrawFrameControl.
Two examples in Using HDM_LAYOUT shows how to use HDM_LAYOUT messages to increase the height of the header when columns are added with _GUICtrlListView_AddColumn and directly with GUICtrlCreateListView.
In all examples LVS_EX_HEADERDRAGDROP extended style is defined for the listview to be able to rearrange columns by drag-and-drop of header items.
ListviewHeader.7z
Custom drawn\
1) Simple multi-line header.au3
2) Simple formatted text.au3
3) Styles, fonts, colors.au3
4) Icons and bitmaps.au3
Pattern.bmp
Owner drawn\
1) Simple multi-line header.au3
DrawItem.au3
Using font height\
1) Restore header theme.au3
2) Drawing everything.au3
Using HDM_LAYOUT\
1) Columns added with _GUICtrlListView_AddColumn.au3
2) Columns added with GUICtrlCreateListView.au3
ListviewHeader.7z
Update 2015-11-24
I have made some tests with real listviews with more than 10 rows. It turns out that the method for increasing the height of the header has a significant impact on performance when rows are inserted in the listview.
Increasing the height by responding to HDM_LAYOUT messages is a slow method. Each row inserted generates a HDM_LAYOUT message. This makes insertion slow if there are many rows. (HDM_LAYOUT method can still be used. But it should not be used when the header is contained in a listview.)
Using a font to increase the height of the header does not have this negative effect on performance.
The purpose of the examples is to be able to use multi-line headers in real listviews. I have updated the examples to use the faster font method to increase the height.
A small UDF (GuiHeaderEx.au3) with one function is added to the zip:
#include-once
#include <WinAPITheme.au3>
Func _GUICtrlHeader_SetItemHeightByFont( $hHeader, $iHeight, $bRestoreTheme = True )
; Remove Header theme
_WinAPI_SetWindowTheme( $hHeader, "", "" )
; Get font of Header control
; Copied from _GUICtrlGetFont example by KaFu
; See https://www.autoitscript.com/forum/index.php?showtopic=124526
Local $hDC = _WinAPI_GetDC( $hHeader ), $hFont = _SendMessage( $hHeader, $WM_GETFONT )
Local $hObject = _WinAPI_SelectObject( $hDC, $hFont ), $lvLogFont = DllStructCreate( $tagLOGFONT )
_WinAPI_GetObject( $hFont, DllStructGetSize( $lvLogFont ), DllStructGetPtr( $lvLogFont ) )
Local $hHdrfont = _WinAPI_CreateFontIndirect( $lvLogFont ) ; Original Header font
_WinAPI_SelectObject( $hDC, $hObject )
_WinAPI_ReleaseDC( $hHeader, $hDC )
; Set height of Header items by applying text font with suitable height
$hFont = _WinAPI_CreateFont( $iHeight, 0 )
_WinAPI_SetFont( $hHeader, $hFont )
_WinAPI_DeleteObject( $hFont )
; Restore Header theme
If $bRestoreTheme Then _
_WinAPI_SetWindowTheme( $hHeader )
; Return original Header font
Return $hHdrfont
EndFunc
ListviewHeader 2015-11-24.7z
Custom drawn\
1) Simple multi-line header.au3
2) Simple formatted text.au3
3) Styles, fonts, colors.au3
4) Icons and bitmaps.au3
5) Drawing everything.au3
GuiHeaderEx.au3
Pattern.bmp
Owner drawn\
1) Simple multi-line header.au3
GuiHeaderEx.au3
DrawItem.au3
You need AutoIt 3.3.10 or later. Tested on Windows 7 32/64 bit and Windows XP 32 bit.
Comments are welcome. Let me know if there are any issues.
(Set tab width = 2 in SciTE to line up comments by column)
ListviewHeader 2015-11-24.7z
I wanted to hide my listvew temporarily, but i was using '_GUICtrlListView_Create' function, so I don't know how it will behave with 'GUICtrlCreateListView'
im sure there must be a way to hide the list view another way but i ended up doing the below code xD
$tradelist = _GUICtrlListView_Create($mGui, "",4, 20, 300, 300, -1, -1, False)
;hide litview by making in thin
_WinAPI_MoveWindow($tradelist, 4, 20, 1, 1)
;add items or etc
;restore the original position
_WinAPI_MoveWindow($tradelist, 4, 20, 300, 300)
@ARPFre
you can use MemoryScan.See Below
Note:remmber that wchar: read unicode string but char read non unicode
Array's of TaskManger Text's Unicode on Win 7:
Cpu Usage:43 00 50 00 55 00 20 00 55 00 73 00 61 00 67 00 65
Physical Memory:50 00 68 00 79 00 73 00 69 00 63 00 61 00 6C 00 20 00 4D 00 65 00 6D 00 6F 00 72 00 79
Array's of TaskManger Text's Non Unicode on Win 7:
Cpu Usage:43 50 55 20 55 73 61 67 65
Physical Memory:50 68 79 73 00 69 63 61 6C 20 4D 65 6D 6F 72 79
Array's of TaskManger Text's Unicode on Win 10:
Cpu:43 00 50 00 55 00 20 00 or 43 00 50 00 55 00 20 or 43 00 50 00 55 00
Disco:44 00 69 00 73 00 63 00 6f
Array's of TaskManger Text's Non Unicode on Win 10:
Cpu:43 50 55 20 or 43 50 55 20 or 43 50 55
Disco:44 69 73 63 6f
you can get those array's non unicode:below script: (if it's Unicode you need to inc 00 after every 2 byte
MsgBox(0, "", _StringToHex("CPU Usage:"))
just change array of :_MemoryScan(...,"43 00 50 00 55",....) to above array:
Note:you might want to change type of data to read if it was unicode use:"wchar[255]" else if it's non unicode then "char[255]" from below script:
Global $iPID = ProcessList("taskmgr.exe");;process name for task manger
#include <ProcessConstants.au3>
#include <WinAPIProc.au3>
#include <String.au3>
#RequireAdmin
SetPrivilege("SeDebugPrivilege", 1)
;MsgBox(0, "", _StringToHex("CPU Usage:"));;get hex just increse 00 after every 2 bit to order to work for Unicode if string is Unicode else..don't
;;;for CPU Usage array is:43 00 50 00 55 00 20 00 55 00 73 00 61 00 67 00 65 00 3A 00 20 string as Unicode(hex unicode)
Global $hMem = _MemoryOpen($iPID[1][1])
$Result = _MemoryScan($hMem, "43 00 50 00 55 00 20 00 55 00 73 00 61 00 67 00 65 00 3A 00 20", False, 0x00000000, _WinAPI_EnumProcessModules($iPID[1][1])[1][0])
$TResutl = _MemoryRead($Result, $hMem, "wchar[100]") ;;;read text from address
MsgBox(64, "", $TResutl) ;;;show CPU Usage:%d%% Message
Func _MemoryScan($ah_Handle, $pattern, $after = False, $iv_addrStart = 0x00400000, $iv_addrEnd = 0X0FFFFFFF, $step = 51200)
If Not IsArray($ah_Handle) Then
SetError(1)
Return -1
EndIf
$pattern = StringRegExpReplace($pattern, "[^0123456789ABCDEFabcdef.]", "")
If StringLen($pattern) = 0 Then
SetError(2)
Return -2
EndIf
For $addr = $iv_addrStart To $iv_addrEnd Step $step - (StringLen($pattern) / 2)
StringRegExp(_MemoryRead($addr, $ah_Handle, "byte[" & $step & "]"), $pattern, 1, 2)
If Not @error Then
If $after Then
Return StringFormat("0x%.8X", $addr + ((@extended - 2) / 2))
Else
Return StringFormat("0x%.8X", $addr + ((@extended - StringLen($pattern) - 2) / 2))
EndIf
EndIf
Next
Return -3
EndFunc ;==>_MemoryScan
;==================================================================================
; AutoIt Version: 3.1.127 (beta)
; Language: English
; Platform: All Windows
; Author: Nomad
; Requirements: These functions will only work with beta.
;==================================================================================
; Credits: wOuter - These functions are based on his original _Mem() functions.
; But they are easier to comprehend and more reliable. These
; functions are in no way a direct copy of his functions. His
; functions only provided a foundation from which these evolved.
;==================================================================================
;
; Functions:
;
;==================================================================================
; Function: _MemoryOpen($iv_Pid[, $iv_DesiredAccess[, $iv_InheritHandle]])
; Description: Opens a process and enables all possible access rights to the
; process. The Process ID of the process is used to specify which
; process to open. You must call this function before calling
; _MemoryClose(), _MemoryRead(), or _MemoryWrite().
; Parameter(s): $iv_Pid - The Process ID of the program you want to open.
; $iv_DesiredAccess - (optional) Set to 0x1F0FFF by default, which
; enables all possible access rights to the
; process specified by the Process ID.
; $iv_InheritHandle - (optional) If this value is TRUE, all processes
; created by this process will inherit the access
; handle. Set to 1 (TRUE) by default. Set to 0
; if you want it FALSE.
; Requirement(s): None.
; Return Value(s): On Success - Returns an array containing the Dll handle and an
; open handle to the specified process.
; On Failure - Returns 0
; @Error - 0 = No error.
; 1 = Invalid $iv_Pid.
; 2 = Failed to open Kernel32.dll.
; 3 = Failed to open the specified process.
; Author(s): Nomad
; Note(s):
;==================================================================================
Func _MemoryOpen($iv_Pid, $iv_DesiredAccess = 0x1F0FFF, $iv_InheritHandle = 1)
If Not ProcessExists($iv_Pid) Then
SetError(1)
Return 0
EndIf
Local $ah_Handle[2] = [DllOpen('kernel32.dll')]
If @error Then
SetError(2)
Return 0
EndIf
Local $av_OpenProcess = DllCall($ah_Handle[0], 'int', 'OpenProcess', 'int', $iv_DesiredAccess, 'int', $iv_InheritHandle, 'int', $iv_Pid)
If @error Then
DllClose($ah_Handle[0])
SetError(3)
Return 0
EndIf
$ah_Handle[1] = $av_OpenProcess[0]
Return $ah_Handle
EndFunc ;==>_MemoryOpen
;==================================================================================
; Function: _MemoryRead($iv_Address, $ah_Handle[, $sv_Type])
; Description: Reads the value located in the memory address specified.
; Parameter(s): $iv_Address - The memory address you want to read from. It must
; be in hex format (0x00000000).
; $ah_Handle - An array containing the Dll handle and the handle
; of the open process as returned by _MemoryOpen().
; $sv_Type - (optional) The "Type" of value you intend to read.
; This is set to 'dword'(32bit(4byte) signed integer)
; by default. See the help file for DllStructCreate
; for all types. An example: If you want to read a
; word that is 15 characters in length, you would use
; 'char[16]' since a 'char' is 8 bits (1 byte) in size.
; Return Value(s): On Success - Returns the value located at the specified address.
; On Failure - Returns 0
; @Error - 0 = No error.
; 1 = Invalid $ah_Handle.
; 2 = $sv_Type was not a string.
; 3 = $sv_Type is an unknown data type.
; 4 = Failed to allocate the memory needed for the DllStructure.
; 5 = Error allocating memory for $sv_Type.
; 6 = Failed to read from the specified process.
; Author(s): Nomad
; Note(s): Values returned are in Decimal format, unless specified as a
; 'char' type, then they are returned in ASCII format. Also note
; that size ('char[size]') for all 'char' types should be 1
; greater than the actual size.
;==================================================================================
Func _MemoryRead($iv_Address, $ah_Handle, $sv_Type = 'dword')
If Not IsArray($ah_Handle) Then
SetError(1)
Return 0
EndIf
Local $v_Buffer = DllStructCreate($sv_Type)
If @error Then
SetError(@error + 1)
Return 0
EndIf
DllCall($ah_Handle[0], 'int', 'ReadProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
If Not @error Then
Local $v_Value = DllStructGetData($v_Buffer, 1)
Return $v_Value
Else
SetError(6)
Return 0
EndIf
EndFunc ;==>_MemoryRead
;==================================================================================
; Function: _MemoryWrite($iv_Address, $ah_Handle, $v_Data[, $sv_Type])
; Description: Writes data to the specified memory address.
; Parameter(s): $iv_Address - The memory address which you want to write to.
; It must be in hex format (0x00000000).
; $ah_Handle - An array containing the Dll handle and the handle
; of the open process as returned by _MemoryOpen().
; $v_Data - The data to be written.
; $sv_Type - (optional) The "Type" of value you intend to write.
; This is set to 'dword'(32bit(4byte) signed integer)
; by default. See the help file for DllStructCreate
; for all types. An example: If you want to write a
; word that is 15 characters in length, you would use
; 'char[16]' since a 'char' is 8 bits (1 byte) in size.
; Return Value(s): On Success - Returns 1
; On Failure - Returns 0
; @Error - 0 = No error.
; 1 = Invalid $ah_Handle.
; 2 = $sv_Type was not a string.
; 3 = $sv_Type is an unknown data type.
; 4 = Failed to allocate the memory needed for the DllStructure.
; 5 = Error allocating memory for $sv_Type.
; 6 = $v_Data is not in the proper format to be used with the
; "Type" selected for $sv_Type, or it is out of range.
; 7 = Failed to write to the specified process.
; Author(s): Nomad
; Note(s): Values sent must be in Decimal format, unless specified as a
; 'char' type, then they must be in ASCII format. Also note
; that size ('char[size]') for all 'char' types should be 1
; greater than the actual size.
;==================================================================================
Func _MemoryWrite($iv_Address, $ah_Handle, $v_Data, $sv_Type = 'dword')
If Not IsArray($ah_Handle) Then
SetError(1)
Return 0
EndIf
Local $v_Buffer = DllStructCreate($sv_Type)
If @error Then
SetError(@error + 1)
Return 0
Else
DllStructSetData($v_Buffer, 1, $v_Data)
If @error Then
SetError(6)
Return 0
EndIf
EndIf
DllCall($ah_Handle[0], 'int', 'WriteProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
If Not @error Then
Return 1
Else
SetError(7)
Return 0
EndIf
EndFunc ;==>_MemoryWrite
;==================================================================================
; Function: _MemoryClose($ah_Handle)
; Description: Closes the process handle opened by using _MemoryOpen().
; Parameter(s): $ah_Handle - An array containing the Dll handle and the handle
; of the open process as returned by _MemoryOpen().
; Return Value(s): On Success - Returns 1
; On Failure - Returns 0
; @Error - 0 = No error.
; 1 = Invalid $ah_Handle.
; 2 = Unable to close the process handle.
; Author(s): Nomad
; Note(s):
;==================================================================================
Func _MemoryClose($ah_Handle)
If Not IsArray($ah_Handle) Then
SetError(1)
Return 0
EndIf
DllCall($ah_Handle[0], 'int', 'CloseHandle', 'int', $ah_Handle[1])
If Not @error Then
DllClose($ah_Handle[0])
Return 1
Else
DllClose($ah_Handle[0])
SetError(2)
Return 0
EndIf
EndFunc ;==>_MemoryClose
;==================================================================================
; Function: SetPrivilege( $privilege, $bEnable )
; Description: Enables (or disables) the $privilege on the current process
; (Probably) requires administrator privileges to run
;
; Author(s): Larry (from autoitscript.com's Forum)
; Notes(s):
; http://www.autoitscript.com/forum/index.php?s=&showtopic=31248&view=findpost&p=223999
;==================================================================================
Func SetPrivilege($privilege, $bEnable)
Const $MY_TOKEN_ADJUST_PRIVILEGES = 0x0020
Const $MY_TOKEN_QUERY = 0x0008
Const $MY_SE_PRIVILEGE_ENABLED = 0x0002
Local $hToken, $SP_auxret, $SP_ret, $hCurrProcess, $nTokens, $nTokenIndex, $priv
$nTokens = 1
$LUID = DllStructCreate("dword;int")
If IsArray($privilege) Then $nTokens = UBound($privilege)
$TOKEN_PRIVILEGES = DllStructCreate("dword;dword[" & (3 * $nTokens) & "]")
$NEWTOKEN_PRIVILEGES = DllStructCreate("dword;dword[" & (3 * $nTokens) & "]")
$hCurrProcess = DllCall("kernel32.dll", "hwnd", "GetCurrentProcess")
$SP_auxret = DllCall("advapi32.dll", "int", "OpenProcessToken", "hwnd", $hCurrProcess[0], _
"int", BitOR($MY_TOKEN_ADJUST_PRIVILEGES, $MY_TOKEN_QUERY), "int*", 0)
If $SP_auxret[0] Then
$hToken = $SP_auxret[3]
DllStructSetData($TOKEN_PRIVILEGES, 1, 1)
$nTokenIndex = 1
While $nTokenIndex <= $nTokens
If IsArray($privilege) Then
$priv = $privilege[$nTokenIndex - 1]
Else
$priv = $privilege
EndIf
$ret = DllCall("advapi32.dll", "int", "LookupPrivilegeValue", "str", "", "str", $priv, _
"ptr", DllStructGetPtr($LUID))
If $ret[0] Then
If $bEnable Then
DllStructSetData($TOKEN_PRIVILEGES, 2, $MY_SE_PRIVILEGE_ENABLED, (3 * $nTokenIndex))
Else
DllStructSetData($TOKEN_PRIVILEGES, 2, 0, (3 * $nTokenIndex))
EndIf
DllStructSetData($TOKEN_PRIVILEGES, 2, DllStructGetData($LUID, 1), (3 * ($nTokenIndex - 1)) + 1)
DllStructSetData($TOKEN_PRIVILEGES, 2, DllStructGetData($LUID, 2), (3 * ($nTokenIndex - 1)) + 2)
DllStructSetData($LUID, 1, 0)
DllStructSetData($LUID, 2, 0)
EndIf
$nTokenIndex += 1
WEnd
$ret = DllCall("advapi32.dll", "int", "AdjustTokenPrivileges", "hwnd", $hToken, "int", 0, _
"ptr", DllStructGetPtr($TOKEN_PRIVILEGES), "int", DllStructGetSize($NEWTOKEN_PRIVILEGES), _
"ptr", DllStructGetPtr($NEWTOKEN_PRIVILEGES), "int*", 0)
$f = DllCall("kernel32.dll", "int", "GetLastError")
EndIf
$NEWTOKEN_PRIVILEGES = 0
$TOKEN_PRIVILEGES = 0
$LUID = 0
If $SP_auxret[0] = 0 Then Return 0
$SP_auxret = DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hToken)
If Not $ret[0] And Not $SP_auxret[0] Then Return 0
Return $ret[0]
EndFunc ;==>SetPrivilege
#EndRegion
###################################################################
or you can use below tool to give address:
#include <ProcessConstants.au3>
#include <WinAPIProc.au3>
#include <String.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <String.au3>
#include <GuiEdit.au3>
#include <WinAPI.au3>
Global $Open, $Process_Text
OnAutoItExitRegister("_Detach")
Opt("GUIOnEventMode", 1)
Global $processname = "taskmgr.exe"
$hGUI = GUICreate("", 509, 316, -1, -1)
GUISetOnEvent(-3, "_Exit")
$Adress_Array = GUICtrlCreateEdit("", 4, 4, 209, 305, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY))
GUICtrlSetData(-1, "")
$Scan_Button = GUICtrlCreateButton("Scan", 220, 4, 75, 25)
$Text_Label = GUICtrlCreateLabel("Text:", 260, 40, 28, 17)
$Text_Input = GUICtrlCreateInput("", 292, 36, 209, 21)
$Value_Type_Label = GUICtrlCreateLabel("Value Type:", 228, 68, 58, 17)
$Memory_Group = GUICtrlCreateGroup("Memory Scan Options", 220, 92, 281, 81)
$Start_Label = GUICtrlCreateLabel("Start:", 228, 116, 29, 17)
$Start_Adress_Input = GUICtrlCreateInput("0x00000000", 268, 116, 225, 21)
$Stop_Label = GUICtrlCreateLabel("Stop:", 228, 148, 29, 17)
$Stop_Adress_Input = GUICtrlCreateInput("0x0FFFFFFF", 268, 140, 225, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Type_Combo = GUICtrlCreateCombo("String", 292, 64, 209, 25)
GUICtrlSetData(-1, "Array of Byte")
GUISetState(@SW_SHOW, $hGUI)
GUICtrlSetOnEvent($Scan_Button, "_Scan")
AdlibRegister("_Process")
While 1
Sleep(100)
WEnd
Func _Detach()
_MemoryClose($Open)
EndFunc ;==>_Detach
Func _Scan()
If GUICtrlRead($Type_Combo) = "String" = 1 Then
$String_Text = GUICtrlRead($Text_Input)
$Text_AoB = _StringToArrayOfByte($String_Text)
$Adress_Start = GUICtrlRead($Start_Adress_Input)
$Adress_End = GUICtrlRead($Stop_Adress_Input)
Do
$Result = _MemoryScan($Open, $Text_AoB, False, $Adress_Start, $Adress_End)
If $Result = -3 Then
ExitLoop
Else
_GUICtrlEdit_InsertText($Adress_Array, $Result & @CRLF, -1)
EndIf
$Adress_Start = $Result + 1
Until $Result = -3
ElseIf GUICtrlRead($Type_Combo) = "Array of Byte" = 1 Then
_GUICtrlEdit_SetText($Adress_Array, "")
$String_Text = GUICtrlRead($Text_Input)
$Adress_Start = GUICtrlRead($Start_Adress_Input)
$Adress_End = GUICtrlRead($Stop_Adress_Input)
Do
$Result = _MemoryScan($Open, $String_Text, False, $Adress_Start, $Adress_End)
If $Result = -3 Then
ExitLoop
Else
_GUICtrlEdit_InsertText($Adress_Array, $Result & @CRLF, -1)
EndIf
$Adress_Start = $Result + 1
Until $Result = -3
EndIf
EndFunc ;==>_Scan
Func _Process()
If ProcessExists($processname) > 0 Then
$Open = _MemoryOpen(ProcessExists($processname))
ToolTip("ATTACHED")
AdlibRegister("_Wait_for_close", 750)
AdlibUnRegister("_Process")
EndIf
EndFunc ;==>_Process
Func _Wait_for_close()
If Not ProcessExists($processname) = 1 Then
AdlibRegister("_Process")
AdlibUnRegister("_Wait_for_close")
EndIf
EndFunc ;==>_Wait_for_close
Func _Exit()
Exit
EndFunc ;==>_Exit
Func _MemoryScan($ah_Handle, $pattern, $after = False, $iv_addrStart = 0x00400000, $iv_addrEnd = 0X0FFFFFFF, $step = 51200)
If Not IsArray($ah_Handle) Then
SetError(1)
Return -1
EndIf
$pattern = StringRegExpReplace($pattern, "[^0123456789ABCDEFabcdef.]", "")
If StringLen($pattern) = 0 Then
SetError(2)
Return -2
EndIf
For $addr = $iv_addrStart To $iv_addrEnd Step $step - (StringLen($pattern) / 2)
StringRegExp(_MemoryRead($addr, $ah_Handle, "byte[" & $step & "]"), $pattern, 1, 2)
If Not @error Then
If $after Then
Return StringFormat("0x%.8X", $addr + ((@extended - 2) / 2))
Else
Return StringFormat("0x%.8X", $addr + ((@extended - StringLen($pattern) - 2) / 2))
EndIf
EndIf
Next
Return -3
EndFunc ;==>_MemoryScan
Func _StringToArrayOfByte($String)
Local $AoB = StringToBinary($String)
Local $AntiHex = _StringBetween($AoB, "0x", "")
Return $AntiHex[0]
EndFunc ;==>_StringToArrayOfByte
;==================================================================================
; AutoIt Version: 3.1.127 (beta)
; Language: English
; Platform: All Windows
; Author: Nomad
; Requirements: These functions will only work with beta.
;==================================================================================
; Credits: wOuter - These functions are based on his original _Mem() functions.
; But they are easier to comprehend and more reliable. These
; functions are in no way a direct copy of his functions. His
; functions only provided a foundation from which these evolved.
;==================================================================================
;
; Functions:
;
;==================================================================================
; Function: _MemoryOpen($iv_Pid[, $iv_DesiredAccess[, $iv_InheritHandle]])
; Description: Opens a process and enables all possible access rights to the
; process. The Process ID of the process is used to specify which
; process to open. You must call this function before calling
; _MemoryClose(), _MemoryRead(), or _MemoryWrite().
; Parameter(s): $iv_Pid - The Process ID of the program you want to open.
; $iv_DesiredAccess - (optional) Set to 0x1F0FFF by default, which
; enables all possible access rights to the
; process specified by the Process ID.
; $iv_InheritHandle - (optional) If this value is TRUE, all processes
; created by this process will inherit the access
; handle. Set to 1 (TRUE) by default. Set to 0
; if you want it FALSE.
; Requirement(s): None.
; Return Value(s): On Success - Returns an array containing the Dll handle and an
; open handle to the specified process.
; On Failure - Returns 0
; @Error - 0 = No error.
; 1 = Invalid $iv_Pid.
; 2 = Failed to open Kernel32.dll.
; 3 = Failed to open the specified process.
; Author(s): Nomad
; Note(s):
;==================================================================================
Func _MemoryOpen($iv_Pid, $iv_DesiredAccess = 0x1F0FFF, $iv_InheritHandle = 1)
If Not ProcessExists($iv_Pid) Then
SetError(1)
Return 0
EndIf
Local $ah_Handle[2] = [DllOpen('kernel32.dll')]
If @error Then
SetError(2)
Return 0
EndIf
Local $av_OpenProcess = DllCall($ah_Handle[0], 'int', 'OpenProcess', 'int', $iv_DesiredAccess, 'int', $iv_InheritHandle, 'int', $iv_Pid)
If @error Then
DllClose($ah_Handle[0])
SetError(3)
Return 0
EndIf
$ah_Handle[1] = $av_OpenProcess[0]
Return $ah_Handle
EndFunc ;==>_MemoryOpen
;==================================================================================
; Function: _MemoryRead($iv_Address, $ah_Handle[, $sv_Type])
; Description: Reads the value located in the memory address specified.
; Parameter(s): $iv_Address - The memory address you want to read from. It must
; be in hex format (0x00000000).
; $ah_Handle - An array containing the Dll handle and the handle
; of the open process as returned by _MemoryOpen().
; $sv_Type - (optional) The "Type" of value you intend to read.
; This is set to 'dword'(32bit(4byte) signed integer)
; by default. See the help file for DllStructCreate
; for all types. An example: If you want to read a
; word that is 15 characters in length, you would use
; 'char[16]' since a 'char' is 8 bits (1 byte) in size.
; Return Value(s): On Success - Returns the value located at the specified address.
; On Failure - Returns 0
; @Error - 0 = No error.
; 1 = Invalid $ah_Handle.
; 2 = $sv_Type was not a string.
; 3 = $sv_Type is an unknown data type.
; 4 = Failed to allocate the memory needed for the DllStructure.
; 5 = Error allocating memory for $sv_Type.
; 6 = Failed to read from the specified process.
; Author(s): Nomad
; Note(s): Values returned are in Decimal format, unless specified as a
; 'char' type, then they are returned in ASCII format. Also note
; that size ('char[size]') for all 'char' types should be 1
; greater than the actual size.
;==================================================================================
Func _MemoryRead($iv_Address, $ah_Handle, $sv_Type = 'dword')
If Not IsArray($ah_Handle) Then
SetError(1)
Return 0
EndIf
Local $v_Buffer = DllStructCreate($sv_Type)
If @error Then
SetError(@error + 1)
Return 0
EndIf
DllCall($ah_Handle[0], 'int', 'ReadProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
If Not @error Then
Local $v_Value = DllStructGetData($v_Buffer, 1)
Return $v_Value
Else
SetError(6)
Return 0
EndIf
EndFunc ;==>_MemoryRead
;==================================================================================
; Function: _MemoryWrite($iv_Address, $ah_Handle, $v_Data[, $sv_Type])
; Description: Writes data to the specified memory address.
; Parameter(s): $iv_Address - The memory address which you want to write to.
; It must be in hex format (0x00000000).
; $ah_Handle - An array containing the Dll handle and the handle
; of the open process as returned by _MemoryOpen().
; $v_Data - The data to be written.
; $sv_Type - (optional) The "Type" of value you intend to write.
; This is set to 'dword'(32bit(4byte) signed integer)
; by default. See the help file for DllStructCreate
; for all types. An example: If you want to write a
; word that is 15 characters in length, you would use
; 'char[16]' since a 'char' is 8 bits (1 byte) in size.
; Return Value(s): On Success - Returns 1
; On Failure - Returns 0
; @Error - 0 = No error.
; 1 = Invalid $ah_Handle.
; 2 = $sv_Type was not a string.
; 3 = $sv_Type is an unknown data type.
; 4 = Failed to allocate the memory needed for the DllStructure.
; 5 = Error allocating memory for $sv_Type.
; 6 = $v_Data is not in the proper format to be used with the
; "Type" selected for $sv_Type, or it is out of range.
; 7 = Failed to write to the specified process.
; Author(s): Nomad
; Note(s): Values sent must be in Decimal format, unless specified as a
; 'char' type, then they must be in ASCII format. Also note
; that size ('char[size]') for all 'char' types should be 1
; greater than the actual size.
;==================================================================================
Func _MemoryWrite($iv_Address, $ah_Handle, $v_Data, $sv_Type = 'dword')
If Not IsArray($ah_Handle) Then
SetError(1)
Return 0
EndIf
Local $v_Buffer = DllStructCreate($sv_Type)
If @error Then
SetError(@error + 1)
Return 0
Else
DllStructSetData($v_Buffer, 1, $v_Data)
If @error Then
SetError(6)
Return 0
EndIf
EndIf
DllCall($ah_Handle[0], 'int', 'WriteProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
If Not @error Then
Return 1
Else
SetError(7)
Return 0
EndIf
EndFunc ;==>_MemoryWrite
;==================================================================================
; Function: _MemoryClose($ah_Handle)
; Description: Closes the process handle opened by using _MemoryOpen().
; Parameter(s): $ah_Handle - An array containing the Dll handle and the handle
; of the open process as returned by _MemoryOpen().
; Return Value(s): On Success - Returns 1
; On Failure - Returns 0
; @Error - 0 = No error.
; 1 = Invalid $ah_Handle.
; 2 = Unable to close the process handle.
; Author(s): Nomad
; Note(s):
;==================================================================================
Func _MemoryClose($ah_Handle)
If Not IsArray($ah_Handle) Then
SetError(1)
Return 0
EndIf
DllCall($ah_Handle[0], 'int', 'CloseHandle', 'int', $ah_Handle[1])
If Not @error Then
DllClose($ah_Handle[0])
Return 1
Else
DllClose($ah_Handle[0])
SetError(2)
Return 0
EndIf
EndFunc ;==>_MemoryClose
;==================================================================================
; Function: SetPrivilege( $privilege, $bEnable )
; Description: Enables (or disables) the $privilege on the current process
; (Probably) requires administrator privileges to run
;
; Author(s): Larry (from autoitscript.com's Forum)
; Notes(s):
; http://www.autoitscript.com/forum/index.php?s=&showtopic=31248&view=findpost&p=223999
;==================================================================================
Func SetPrivilege($privilege, $bEnable)
Const $MY_TOKEN_ADJUST_PRIVILEGES = 0x0020
Const $MY_TOKEN_QUERY = 0x0008
Const $MY_SE_PRIVILEGE_ENABLED = 0x0002
Local $hToken, $SP_auxret, $SP_ret, $hCurrProcess, $nTokens, $nTokenIndex, $priv
$nTokens = 1
$LUID = DllStructCreate("dword;int")
If IsArray($privilege) Then $nTokens = UBound($privilege)
$TOKEN_PRIVILEGES = DllStructCreate("dword;dword[" & (3 * $nTokens) & "]")
$NEWTOKEN_PRIVILEGES = DllStructCreate("dword;dword[" & (3 * $nTokens) & "]")
$hCurrProcess = DllCall("kernel32.dll", "hwnd", "GetCurrentProcess")
$SP_auxret = DllCall("advapi32.dll", "int", "OpenProcessToken", "hwnd", $hCurrProcess[0], _
"int", BitOR($MY_TOKEN_ADJUST_PRIVILEGES, $MY_TOKEN_QUERY), "int*", 0)
If $SP_auxret[0] Then
$hToken = $SP_auxret[3]
DllStructSetData($TOKEN_PRIVILEGES, 1, 1)
$nTokenIndex = 1
While $nTokenIndex <= $nTokens
If IsArray($privilege) Then
$priv = $privilege[$nTokenIndex - 1]
Else
$priv = $privilege
EndIf
$ret = DllCall("advapi32.dll", "int", "LookupPrivilegeValue", "str", "", "str", $priv, _
"ptr", DllStructGetPtr($LUID))
If $ret[0] Then
If $bEnable Then
DllStructSetData($TOKEN_PRIVILEGES, 2, $MY_SE_PRIVILEGE_ENABLED, (3 * $nTokenIndex))
Else
DllStructSetData($TOKEN_PRIVILEGES, 2, 0, (3 * $nTokenIndex))
EndIf
DllStructSetData($TOKEN_PRIVILEGES, 2, DllStructGetData($LUID, 1), (3 * ($nTokenIndex - 1)) + 1)
DllStructSetData($TOKEN_PRIVILEGES, 2, DllStructGetData($LUID, 2), (3 * ($nTokenIndex - 1)) + 2)
DllStructSetData($LUID, 1, 0)
DllStructSetData($LUID, 2, 0)
EndIf
$nTokenIndex += 1
WEnd
$ret = DllCall("advapi32.dll", "int", "AdjustTokenPrivileges", "hwnd", $hToken, "int", 0, _
"ptr", DllStructGetPtr($TOKEN_PRIVILEGES), "int", DllStructGetSize($NEWTOKEN_PRIVILEGES), _
"ptr", DllStructGetPtr($NEWTOKEN_PRIVILEGES), "int*", 0)
$f = DllCall("kernel32.dll", "int", "GetLastError")
EndIf
$NEWTOKEN_PRIVILEGES = 0
$TOKEN_PRIVILEGES = 0
$LUID = 0
If $SP_auxret[0] = 0 Then Return 0
$SP_auxret = DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hToken)
If Not $ret[0] And Not $SP_auxret[0] Then Return 0
Return $ret[0]
EndFunc ;==>SetPrivilege
#EndRegion
after it give address you may need to Read Address using:
remmber that wchar: read unicode string but char read non unicode
#include <WinAPIMem.au3>
#include <ProcessConstants.au3>
#include <WinAPIHObj.au3>
#include <WinAPIProc.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIProc.au3>
#include <WinAPISys.au3>
#include <WinAPISys.au3>
#include <String.au3>
#RequireAdmin
Global $iPID = ProcessList("taskmgr.exe")
SetPrivilege("SeDebugPrivilege", 1)
;;;read address as wchar[255] = unicode or char[255] = non unicode
Global $hMem = _MemoryOpen($iPID[1][1])
Local $address = 0x000000
$TResutl = _MemoryRead($address, $hMem, "wchar[255]")
MsgBox(64, "", $TResutl) ;;;show CPU Usage
;==================================================================================
; AutoIt Version: 3.1.127 (beta)
; Language: English
; Platform: All Windows
; Author: Nomad
; Requirements: These functions will only work with beta.
;==================================================================================
; Credits: wOuter - These functions are based on his original _Mem() functions.
; But they are easier to comprehend and more reliable. These
; functions are in no way a direct copy of his functions. His
; functions only provided a foundation from which these evolved.
;==================================================================================
;
; Functions:
;
;==================================================================================
; Function: _MemoryOpen($iv_Pid[, $iv_DesiredAccess[, $iv_InheritHandle]])
; Description: Opens a process and enables all possible access rights to the
; process. The Process ID of the process is used to specify which
; process to open. You must call this function before calling
; _MemoryClose(), _MemoryRead(), or _MemoryWrite().
; Parameter(s): $iv_Pid - The Process ID of the program you want to open.
; $iv_DesiredAccess - (optional) Set to 0x1F0FFF by default, which
; enables all possible access rights to the
; process specified by the Process ID.
; $iv_InheritHandle - (optional) If this value is TRUE, all processes
; created by this process will inherit the access
; handle. Set to 1 (TRUE) by default. Set to 0
; if you want it FALSE.
; Requirement(s): None.
; Return Value(s): On Success - Returns an array containing the Dll handle and an
; open handle to the specified process.
; On Failure - Returns 0
; @Error - 0 = No error.
; 1 = Invalid $iv_Pid.
; 2 = Failed to open Kernel32.dll.
; 3 = Failed to open the specified process.
; Author(s): Nomad
; Note(s):
;==================================================================================
Func _MemoryOpen($iv_Pid, $iv_DesiredAccess = 0x1F0FFF, $iv_InheritHandle = 1)
If Not ProcessExists($iv_Pid) Then
SetError(1)
Return 0
EndIf
Local $ah_Handle[2] = [DllOpen('kernel32.dll')]
If @error Then
SetError(2)
Return 0
EndIf
Local $av_OpenProcess = DllCall($ah_Handle[0], 'int', 'OpenProcess', 'int', $iv_DesiredAccess, 'int', $iv_InheritHandle, 'int', $iv_Pid)
If @error Then
DllClose($ah_Handle[0])
SetError(3)
Return 0
EndIf
$ah_Handle[1] = $av_OpenProcess[0]
Return $ah_Handle
EndFunc ;==>_MemoryOpen
;==================================================================================
; Function: _MemoryRead($iv_Address, $ah_Handle[, $sv_Type])
; Description: Reads the value located in the memory address specified.
; Parameter(s): $iv_Address - The memory address you want to read from. It must
; be in hex format (0x00000000).
; $ah_Handle - An array containing the Dll handle and the handle
; of the open process as returned by _MemoryOpen().
; $sv_Type - (optional) The "Type" of value you intend to read.
; This is set to 'dword'(32bit(4byte) signed integer)
; by default. See the help file for DllStructCreate
; for all types. An example: If you want to read a
; word that is 15 characters in length, you would use
; 'char[16]' since a 'char' is 8 bits (1 byte) in size.
; Return Value(s): On Success - Returns the value located at the specified address.
; On Failure - Returns 0
; @Error - 0 = No error.
; 1 = Invalid $ah_Handle.
; 2 = $sv_Type was not a string.
; 3 = $sv_Type is an unknown data type.
; 4 = Failed to allocate the memory needed for the DllStructure.
; 5 = Error allocating memory for $sv_Type.
; 6 = Failed to read from the specified process.
; Author(s): Nomad
; Note(s): Values returned are in Decimal format, unless specified as a
; 'char' type, then they are returned in ASCII format. Also note
; that size ('char[size]') for all 'char' types should be 1
; greater than the actual size.
;==================================================================================
Func _MemoryRead($iv_Address, $ah_Handle, $sv_Type = 'dword')
If Not IsArray($ah_Handle) Then
SetError(1)
Return 0
EndIf
Local $v_Buffer = DllStructCreate($sv_Type)
If @error Then
SetError(@error + 1)
Return 0
EndIf
DllCall($ah_Handle[0], 'int', 'ReadProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
If Not @error Then
Local $v_Value = DllStructGetData($v_Buffer, 1)
Return $v_Value
Else
SetError(6)
Return 0
EndIf
EndFunc ;==>_MemoryRead
;==================================================================================
; Function: _MemoryWrite($iv_Address, $ah_Handle, $v_Data[, $sv_Type])
; Description: Writes data to the specified memory address.
; Parameter(s): $iv_Address - The memory address which you want to write to.
; It must be in hex format (0x00000000).
; $ah_Handle - An array containing the Dll handle and the handle
; of the open process as returned by _MemoryOpen().
; $v_Data - The data to be written.
; $sv_Type - (optional) The "Type" of value you intend to write.
; This is set to 'dword'(32bit(4byte) signed integer)
; by default. See the help file for DllStructCreate
; for all types. An example: If you want to write a
; word that is 15 characters in length, you would use
; 'char[16]' since a 'char' is 8 bits (1 byte) in size.
; Return Value(s): On Success - Returns 1
; On Failure - Returns 0
; @Error - 0 = No error.
; 1 = Invalid $ah_Handle.
; 2 = $sv_Type was not a string.
; 3 = $sv_Type is an unknown data type.
; 4 = Failed to allocate the memory needed for the DllStructure.
; 5 = Error allocating memory for $sv_Type.
; 6 = $v_Data is not in the proper format to be used with the
; "Type" selected for $sv_Type, or it is out of range.
; 7 = Failed to write to the specified process.
; Author(s): Nomad
; Note(s): Values sent must be in Decimal format, unless specified as a
; 'char' type, then they must be in ASCII format. Also note
; that size ('char[size]') for all 'char' types should be 1
; greater than the actual size.
;==================================================================================
Func _MemoryWrite($iv_Address, $ah_Handle, $v_Data, $sv_Type = 'dword')
If Not IsArray($ah_Handle) Then
SetError(1)
Return 0
EndIf
Local $v_Buffer = DllStructCreate($sv_Type)
If @error Then
SetError(@error + 1)
Return 0
Else
DllStructSetData($v_Buffer, 1, $v_Data)
If @error Then
SetError(6)
Return 0
EndIf
EndIf
DllCall($ah_Handle[0], 'int', 'WriteProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
If Not @error Then
Return 1
Else
SetError(7)
Return 0
EndIf
EndFunc ;==>_MemoryWrite
;==================================================================================
; Function: _MemoryClose($ah_Handle)
; Description: Closes the process handle opened by using _MemoryOpen().
; Parameter(s): $ah_Handle - An array containing the Dll handle and the handle
; of the open process as returned by _MemoryOpen().
; Return Value(s): On Success - Returns 1
; On Failure - Returns 0
; @Error - 0 = No error.
; 1 = Invalid $ah_Handle.
; 2 = Unable to close the process handle.
; Author(s): Nomad
; Note(s):
;==================================================================================
Func _MemoryClose($ah_Handle)
If Not IsArray($ah_Handle) Then
SetError(1)
Return 0
EndIf
DllCall($ah_Handle[0], 'int', 'CloseHandle', 'int', $ah_Handle[1])
If Not @error Then
DllClose($ah_Handle[0])
Return 1
Else
DllClose($ah_Handle[0])
SetError(2)
Return 0
EndIf
EndFunc ;==>_MemoryClose
;==================================================================================
; Function: SetPrivilege( $privilege, $bEnable )
; Description: Enables (or disables) the $privilege on the current process
; (Probably) requires administrator privileges to run
;
; Author(s): Larry (from autoitscript.com's Forum)
; Notes(s):
; http://www.autoitscript.com/forum/index.php?s=&showtopic=31248&view=findpost&p=223999
;==================================================================================
Func SetPrivilege($privilege, $bEnable)
Const $MY_TOKEN_ADJUST_PRIVILEGES = 0x0020
Const $MY_TOKEN_QUERY = 0x0008
Const $MY_SE_PRIVILEGE_ENABLED = 0x0002
Local $hToken, $SP_auxret, $SP_ret, $hCurrProcess, $nTokens, $nTokenIndex, $priv
$nTokens = 1
$LUID = DllStructCreate("dword;int")
If IsArray($privilege) Then $nTokens = UBound($privilege)
$TOKEN_PRIVILEGES = DllStructCreate("dword;dword[" & (3 * $nTokens) & "]")
$NEWTOKEN_PRIVILEGES = DllStructCreate("dword;dword[" & (3 * $nTokens) & "]")
$hCurrProcess = DllCall("kernel32.dll", "hwnd", "GetCurrentProcess")
$SP_auxret = DllCall("advapi32.dll", "int", "OpenProcessToken", "hwnd", $hCurrProcess[0], _
"int", BitOR($MY_TOKEN_ADJUST_PRIVILEGES, $MY_TOKEN_QUERY), "int*", 0)
If $SP_auxret[0] Then
$hToken = $SP_auxret[3]
DllStructSetData($TOKEN_PRIVILEGES, 1, 1)
$nTokenIndex = 1
While $nTokenIndex <= $nTokens
If IsArray($privilege) Then
$priv = $privilege[$nTokenIndex - 1]
Else
$priv = $privilege
EndIf
$ret = DllCall("advapi32.dll", "int", "LookupPrivilegeValue", "str", "", "str", $priv, _
"ptr", DllStructGetPtr($LUID))
If $ret[0] Then
If $bEnable Then
DllStructSetData($TOKEN_PRIVILEGES, 2, $MY_SE_PRIVILEGE_ENABLED, (3 * $nTokenIndex))
Else
DllStructSetData($TOKEN_PRIVILEGES, 2, 0, (3 * $nTokenIndex))
EndIf
DllStructSetData($TOKEN_PRIVILEGES, 2, DllStructGetData($LUID, 1), (3 * ($nTokenIndex - 1)) + 1)
DllStructSetData($TOKEN_PRIVILEGES, 2, DllStructGetData($LUID, 2), (3 * ($nTokenIndex - 1)) + 2)
DllStructSetData($LUID, 1, 0)
DllStructSetData($LUID, 2, 0)
EndIf
$nTokenIndex += 1
WEnd
$ret = DllCall("advapi32.dll", "int", "AdjustTokenPrivileges", "hwnd", $hToken, "int", 0, _
"ptr", DllStructGetPtr($TOKEN_PRIVILEGES), "int", DllStructGetSize($NEWTOKEN_PRIVILEGES), _
"ptr", DllStructGetPtr($NEWTOKEN_PRIVILEGES), "int*", 0)
$f = DllCall("kernel32.dll", "int", "GetLastError")
EndIf
$NEWTOKEN_PRIVILEGES = 0
$TOKEN_PRIVILEGES = 0
$LUID = 0
If $SP_auxret[0] = 0 Then Return 0
$SP_auxret = DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hToken)
If Not $ret[0] And Not $SP_auxret[0] Then Return 0
Return $ret[0]
EndFunc ;==>SetPrivilege
#EndRegion
AutoIt v3.3.16.0 has been released.
Thanks to @jpm and the MVPs who were responsible for the majority of code in this version.
Download it here.
Complete list of changes: History
Available here: https://github.com/OfficialLambdax/_netcode_Proxy-UDF/blob/main/examples/simple http_s proxy/simple http_s proxy.au3
Its a example for the _netcode_Proxy-UDF, but it runs quite well, so maybe someone has a use for it.
Its a forward-proxy that doesnt modify any data. So a website doesnt detect the proxy, atleast i havent found one. You could go ahead and make a reverse proxy of it, a load balancer or what ever you think of. _storageS-UDF might be of use then.
Bandwith wise i think 1 Gbit/s should be possible, couldnt test that yet. The script is single threaded, so it fully uses non blocking sockets and technics to keep lag low. Mem usage is also low because the proxy does not buffer data. It checks all sockets for those that have anything in the recv buffer and then checks the sockets, where the data is supposed to go, for if they are send ready. And only then the data is received and send.
The http/s request parser is quite old and could use some optimization, but there is no problem with it, so i focussed on other things.
Compatible with X64/32 Autoit Stable and Beta. Windows XP - 10. Havent tested Windows 11 or Wine.
Requires a good chunk of UDFs's. If you dont want to go through the hassle then just pick the AllInOne and modify the #include in the http_s proxy script, to use the AllInOne.
https://github.com/OfficialLambdax/_netcode_AllinOne-UDF
Otherwise here is the whole required list
_netcode_Proxy-UDF https://github.com/OfficialLambdax/_netcode_Proxy-UDF
_netcode_AddonCore-UDF https://github.com/OfficialLambdax/_netcode_AddonCore-UDF
_netcode_Core-UDF https://github.com/OfficialLambdax/_netcode_Core-UDF
_storageS-UDF https://github.com/OfficialLambdax/_storageS-UDF
Obviously there might be bugs, in that case please report them either here or there https://github.com/OfficialLambdax/_netcode_Proxy-UDF/issues
From this this thread, I started to get interested in very fast communication that could be used between VBS or AutoIt. And thanks to @argumentum, he is always there to challenge any IPC solution .
My last tests show that a request from a dedicated client is about 7ms to transit to the server. And a small response takes about 4ms to be sent from the server to the client.
From a basic snippet, I changed it to make a UDF on request from the community of @mLipok . Now with this UDF, you can create duplex communication but also dual channels (one way to) IPC. You can also make it persistent (close to a Peer-to-Peer approach) or a transactional (more of a client-server protocol).
Example 1 : Duplex and persistent
Example 2 : Dual and persistent (VBS example included)
Example 3 : Duplex and transactional
Whether you find it useful or not, your comments are always welcome ! (former is my preference though)
Version 2022-02-11
* Added security descriptor to allow mix elevation between Client and Server
* Added support for IPC between computers
Version : 2020-12-30
* Added documentation to the UDF file
* Optimized code
* Moved some code from Example files into UDF file
I made a TCP networking UDF https://github.com/OfficialLambdax/_netcode_Core-UDF
I launched this Thread to go into details of certain features and how i plan to implement them, mostly TLS, the Optional User Database and 2FA. Im going to create seperate posts in this Thread whenever i have something to show off.
Just to be clear, it is best to not use the UDF in your projects yet. Everything is subject to change and big potions of it need entire rewrites. So documentation and examples are ment to be created right before the UDF hits Alpha, thats not going to happen so fast.
The entire encryption part would never been possible without TheXman's CryptoNG UDF https://www.autoitscript.com/forum/topic/201002-cryptong-udf-cryptography-api-next-gen/#comments So big thanks to him and his help!
I made a TCP networking UDF https://github.com/OfficialLambdax/_netcode_Core-UDF
I launched this Thread to go into details of certain features and how i plan to implement them, mostly TLS, the Optional User Database and 2FA. Im going to create seperate posts in this Thread whenever i have something to show off.
Just to be clear, it is best to not use the UDF in your projects yet. Everything is subject to change and big potions of it need entire rewrites. So documentation and examples are ment to be created right before the UDF hits Alpha, thats not going to happen so fast.
The entire encryption part would never been possible without TheXman's CryptoNG UDF https://www.autoitscript.com/forum/topic/201002-cryptong-udf-cryptography-api-next-gen/#comments So big thanks to him and his help!
If you post the code for your test and the process you followed to get your benchmark, who knows maybe someone will look for speed improvements and someone might even run your program on their hardware and give you a reference.
Since you havenโt done this, Iโm assuming you just want some ad hoc โgut checkโ statement on your 41MB/s figure, so here it is:
โProbably reasonable.โ
Are you saying that the example, as provided above, works with other IP addresses? If so, I seriously doubt that. ๐ Your example does not initialize Winsock before trying to make the connection. If you would've added error checking after the line that executes your __netcode_TCPConnect() function, you would've seen that you received a 10093 Winsock error. That error basically means that Winsock was not initialized.
If you run the modified example below, as is, you will see the error. If you uncomment the TCPStartup() and TCPShutdown functions and run it again, it returns a socket handle -- at least it does for me. TCPStartup() is equivalent to calling the wsastartup Winsock API.
Global $__net_hWs2_32 = -1
;~ TCPStartup() ;added by TheXman
Global $hSocket = __netcode_TCPConnect("108.174.11.65", 443)
If @error Then Exit MsgBox(0, "ERROR", "__netcode_TCPConnect failed with @error = " & @error) ;added by TheXman
MsgBox(0, "", $hSocket)
;~ TCPShutdown() ;added by TheXman
Func __netcode_TCPConnect($sIP, $sPort, $nAdressFamily = 2)
if $__net_hWs2_32 = -1 Then $__net_hWs2_32 = DllOpen('Ws2_32.dll')
; create socket
Local $arGen = DllCall($__net_hWs2_32, "uint", "socket", "int", $nAdressFamily, "int", 1, "int", 6)
Local $hSocket = $arGen[0]
; create ip and port struct
; ~ todo IPv6 support here
Local $tDataBuffer = DllStructCreate("short; ushort; uint; char[8]")
DllStructSetData($tDataBuffer, 1, 2)
$arGen = DllCall($__net_hWs2_32, "ushort", "htons", "ushort", $sPort)
DllStructSetData($tDataBuffer, 2, $arGen[0])
$arGen = DllCall($__net_hWs2_32, "uint", "inet_addr", "str", $sIP)
DllStructSetData($tDataBuffer, 3, $arGen[0])
; connect
$arGen = DllCall($__net_hWs2_32, "int", "connect", "uint", $hSocket, "ptr", DllStructGetPtr($tDataBuffer), "int", DllStructGetSize($tDataBuffer))
if $arGen[0] <> 0 Then Return SetError(__netcode_WSAGetLastError(), 0, -1)
Return $hSocket
EndFunc
Func __netcode_WSAGetLastError()
If $__net_hWs2_32 = -1 Then $__net_hWs2_32 = DllOpen('Ws2_32.dll')
Local $iRet = DllCall($__net_hWs2_32, "int", "WSAGetLastError")
If @error Then
SetExtended(1)
Return 0
EndIf
Return $iRet[0]
EndFunc
To those who messaged me about the modified variant. I will release the Modified SocketIO UDF under the name SocketIOEx on Github and this forum. The framework around SocketIoEx will simply be called _netcode UDF.
It will not be so soon, as i need to address certain issues and thoughts. I want to make the SocketIOEx more redundant, more DDOS proof and faster overall. For that i, for example, need to recode certain Autoit Functions like TCPSend() and TCPRecv(), as those come with known issues. _netcode UDF will be a plug and play UDF, it manages the whole network stuff and also reacts to certain bugs that may appear and so on. It will be really easy to use, someone could call the Send function with hundreds of MB of data and the _netcode would manage that. Also, whats not done yet, i plan to add a feature where a Client could get parts of the same data set from different providers to maxout the download speed. Similiar to torrent.
But currently im working on Support for Tor, its already working, but the Tor app comes with a couple of issues.
What's New in Version v1.8.0
v1.8.0 (2021-04-12)
Added asymmetric (public/private key) RSA encryption/decryption functions
_CryptoNG_RSA_EncryptData
_CryptoNG_RSA_DecryptData
Modified _CryptoNG_CreateRSAKeyPair to be able to select the export format (CryptoAPI-Compatible/LEGACY or RSA)
Added create_legacy_rsa_key_pair_example to the CryptoNG_Examples.au3 file
Added rsa_public_private_key_encrypt_decrypt_data_example to the example file
Updated the help file to reflect the modifications above (including new constants).
Thanks @IanN1990 for asking the question that lead to me to adding the asymmetric encryption/decryption functions.
Wow you did it! And you also coded it so easy to understand that i can really learn from it, as someone with no cryptography knowledge. Thanks for realizing RSA in Autoit! i was searching seemingly endlessly. Thanks man!
What maybe would work too is to $nPing = ping() the server right before TCPConnect and setting this $nPing, if not unusally high, as the current tcptimeout. Then connect. And after success reseting the tcptimeout. maybe thats enough to fix any lag in the hope that tcpsend is not influenced by the timeout. if so then it maybe helps to have the ping for each socket stored. I will do some research and probably implement something into the framework to combat this.
You could easiely
_Io_Emit($socket, "privatemessage", $to_ip & '|' & $pm)
and on the receiving func simply
Func _On_privatemessage(Const $socket, $data)
Local $arData = StringSplit($data, '|', 1)
; $arData[1] will hold the ip
; $arData[2] will hold the pm
Endfunc
Hi @tarretarretarre,
i heaviely modified your SoketIO.au3 3.0.0 and also wrote a small framework around it.
I removed the serilization UDF completly and added alot of safety and convenience features. Idk if you care for 3.0.0 anymore as you work on 4.0.0.
However the Client can now Guess how much load is on the Server, this work vise versa. I call it Flood Prevention. It ensures that no packets get discarded because of $g__io_nMaxPacketSize
Then i added packet validation. The packets now also get verified and discarded if corrupted. The next feature is a Safety feature where bad packets get resend. There are more little feature as for example a counter per socket for how much bytes got send and received.. etc.
All of it can be toggled and if used with the framework both side even sync their configurations.
Even tho i didnt optimise nor polished what i coded yet, i still think that it got much faster and safer.
In this picture i have 10 Clients sending constantly packets of 2048 KB
The server handling them so nice that each client can send up to 2 packets per second
I try to make it much faster with certain other technics or by recoding more sections. As the Issue is less with the packet size but with the packet and socket count.
What maybe would work too is to $nPing = ping() the server right before TCPConnect and setting this $nPing, if not unusally high, as the current tcptimeout. Then connect. And after success reseting the tcptimeout. maybe thats enough to fix any lag in the hope that tcpsend is not influenced by the timeout. if so then it maybe helps to have the ping for each socket stored. I will do some research and probably implement something into the framework to combat this.