Leaderboard
Popular Content
Showing content with the highest reputation on 08/03/2015 in all areas
-
Open Control Panel Page(Items)
GuyFromNJo and 2 others reacted to Danyfirex for a topic
Hi Mate. Some times we need to launch a control panel item to users. So I Implemented an IOpenControlPanel Interface. It allows to launch control panel items easily. #include "ControlPanelConstants.au3" Global Const $sCLSID_OpenControlPanel = "{06622D85-6856-4460-8DE1-A81921B41C4B}" Global Const $sIID_IOpenControlPanel = "{D11AD862-66DE-4DF4-BF6C-1F5621996AF1}" Global Const $sTagIOpenControlPanel= "Open hresult(wstr;wstr;ptr);GetPath hresult(wstr;wstr;uint);GetCurrentView hresult(int*)" Local $oOpenControlPanel = ObjCreateInterface($sCLSID_OpenControlPanel, $sIID_IOpenControlPanel, $sTagIOpenControlPanel) $oOpenControlPanel.Open($MicrosoftAdministrativeTools,"",Null) $oOpenControlPanel.Open($MicrosoftDateAndTime,$AdditionalClocks,Null) $oOpenControlPanel.Open($MicrosoftDefaultPrograms,$pageDefaultProgram,Null) $oOpenControlPanel.Open($GUID_MicrosoftDeviceManager,"",Null) $oOpenControlPanel.Open($GUID_MicrosoftDevicesAndPrinters,"",Null) $oOpenControlPanel.Open($MicrosoftHomeGroup,"",Null) $oOpenControlPanel.Open($MicrosoftInternetOptions,$Connections,Null) $oOpenControlPanel.Open($MicrosoftPersonalization,$pageWallpaper,Null) $oOpenControlPanel=0;Free ControlPanelConstants.au3 Saludos3 points -
There has been many questions about using tesseract of late. Here is a very basic example which works for me, along with the exact version of standalone tesseract executable and English language data used I found it some time ago at a time I thought I needed it, I do not recall from where. $ImageToReadPath = @ScriptDir & "\image.bmp" $ResultTextPath = @ScriptDir & "\Result" $OutPutPath = $ResultTextPath & ".txt" $TesseractExePath = @ScriptDir & "\Tesseract.exe" ShellExecuteWait($TesseractExePath, '"' & $ImageToReadPath & '" "' & $ResultTextPath & '"', "", "", @SW_HIDE) If @error Then Exit MsgBox(0, "Error", @error) EndIf MsgBox(0, "Result", FileRead($OutPutPath)) FileDelete($OutPutPath)Some Answers: The files contained in the download, only support English language. From the only documentation I got with this version... Original Binaries and Source can be found here: http://code.google.com/p/tesseract-ocr/I do not know where to get other languages support. I do not know if there is a later standalone version. I do not know why it does not read your image accurately. It does not have a virus in it. You can search the forums or internet to learn how to create / cut / copy / paste, or otherwise manipulate your own images. TesseractExample.zip2 points
-
2 points
-
Hi, I think, you all know this: You look at a script containing color values. You have a rough idea of the colors, but would like to know how it looks like. I have created a Lua script that displays the color of the value in SciTE as Calltip. Set the cursor in the Hex-value, press the hotkey. Above the value a Call tip appears. The background color corresponds to the hex value. Read the function header to obtain installation instructions. So it looks. EDIT: I think it's better to bind the function not only of AutoIt. If it can be called in all files, also the color settings in the * .properties can view. For this purpose remove the file attachment from the call. Use: command.13.*= instead of: command.13.*.au3= EDIT 20.07.2015: Now I've made some changes - You can switch to show colors as RGB or BGR - added new function: PreviewBackForeColor To have a preview for back and fore color: - Write in one line first the back color, than the fore color (i. e. as comment: "; 0xDEDEDE 0x000080") OR have this values inside a function call: "_AnyFunction($param1, $param2, 0xDEDEDE, $param3 0x000080)". If the order inside the call is reverse (first hex value is fore color), you can call the function with Flag "_fFore1st=true" - No other color value may be included in this line. If any - the first and second color will used. - Set the cursor in this line and hit the Hotkey. - A Calltip appears with the back color and the text "FORE-COLOR" with color of the fore value. - If only one color value was find in this line, this value will used as back color or, if Flag is "true", as fore color. In this cases the fore color is set to black and with Flag the back color is the default GUI back color "0xF0F0F0" Because you've different functions in one script, you need another way to install and call it. Read the instructions inside the script. First color used as back color, second as fore color. Function called with flag - first color is now the fore color. EDIT 2018-01-16: Added: Now be also recognized in au3 scripts, variables/constants which have an color assignment inside the script or inside an include file from this script. But it can only be one assignment per line. If the assignment is inside a comment line or -block, it will ignored. The assignment can also be build by using function(s) [from script or include files]. example: "Local $COLOR = '0x' & Hex(Mod(@SEC, 2) ? Random(0,0x000FFF, 1) : Random(0x001000, 0xFFF000, 1), 8)" But the functions must NOT CONTAIN any VARIABLES! This would require a recursive assignment search. Impossible if variables get values only at runtime. You can disable the search inside include files with an entry in SciTEUser.properties: #~ "ShowHexColorFromCursor.lua", Dis/Enable search in Includes (0/1 NO/YES) Get.Color.Assignment.Includes=0 The default value (without settings) is '1', enabled. Includes in comments will ignored. current version v0.8 EDIT 2018-02-22: Changed: Read assignment from function call got any problems - removed. Fixed: Unexpected behavior if caret doesn't touch any hex value while calling the function. Added: Recognition of hex values from length 1 hex character. Added: Instead of default behavior for hiding the calltip, [line 75] local bCALLTIP_END_ANYKEY = true can be used to immediately fade out the tip every time you press a key or move a mouse. current version v0.10 -- TIME_STAMP 2018-02-22 10:26:36 v 0.10 --[[------------- I N S T A L L A T I O N A N D U S I N G I N S T R U C T I O N -------------- Save the file. At first, make an entry in your SciTEStartup.lua LoadLuaFile("ShowHexColorFromCursor.lua", "C:\\Your Path\\with Backslash\\") Select free command-numbers from your SciTEUser.properties. Customize the following settings with this numbers. # 13 Show HexColor RGB command.name.13.*=Show RGB-Color From Cursor command.13.*=dostring ShowHexColorFromCursor() command.mode.13.*=subsystem:lua,savebefore:yes command.shortcut.13.*=Ctrl+Shift+F11 # 14 Show HexColor BGR command.name.14.*=Show BGR-Color From Cursor command.14.*=dostring ShowHexColorFromCursor(true) command.mode.14.*=subsystem:lua,savebefore:yes command.shortcut.14.*=Ctrl+Alt+F11 Set the cursor in the Hex-value, press the hotkey to show the color as RGB or as BGR. Above the value a Call tip appears. The background color corresponds to the hex value. A possible alpha component is ignored. [NEW] Now be also recognized in au3 scripts, variables/constants which have an color assignment inside the script or inside an include file from this script. PLEASE NOTE: Each line may only contain one assignment! If the assignment is inside a comment line or -block, it will ignored. You can disable the search inside include files with an entry in SciTEUser.properties: #~ "ShowHexColorFromCursor.lua", Dis/Enable search in Includes (0/1 NO/YES) Get.Color.Assignment.Includes=0 The default value (without settings) is '1', enabled. Includes in comments will ignored. Be recognized AutoIt hex color code "0x12AB34" and also HTML hex color code "#12AB34" with length from 1 to 6 hex characters. Possible alpha information will ignored. PREVIEW FOR BACK AND FORE COLOR: - Write in one line first the back color, than the fore color (i. e. as comment: "; 0xDEDEDE 0x000080") OR have this values inside a function call: "_AnyFunction($param1, $param2, 0xDEDEDE, $param3 0x000080)". If the order inside the call is reverse (first hex value is fore color), you can call the function with Flag "_fFore1st=true" - No other color value may be included in this line. If any - the first and second color will used. - Set the cursor in this line and hit the Hotkey. - A Calltip appears with the back color and the text "FORE-COLOR" with color of the fore value. - If only one color value was find in this line, this value will used as back color or, if Flag is "true", as fore color. In this cases the fore color is set to black and with Flag the back color is the default GUI back color "0xF0F0F0" For use with AutoIt color values only. To have both calls (w/wo flag) make two commands: # 11 Preview Back and Fore Color / first color value is back color command.name.11.*.au3=Preview Back and Fore Color command.11.*.au3=dostring PreviewBackForeColor() command.mode.11.*.au3=subsystem:lua,savebefore:yes command.shortcut.11.*.au3=Ctrl+Shift+F12 # 16 Preview Fore and Back Color / first color value is fore color command.name.16.*.au3=Preview Fore and Back Color command.16.*.au3=dostring PreviewBackForeColor(true) command.mode.16.*.au3=subsystem:lua,savebefore:yes command.shortcut.16.*.au3=Ctrl+Alt+F12 --------------------------------------------------------------------------------------------------]] local bDEBUG = false -- set "true" to get debug output local bCALLTIP_END_ANYKEY = false -- set "true" to cancel the calltip with any key or mouse move ------------------------------------------------------------ list object to manipulate simple tables local objList = { list = {}, delall = function(self) self.list = {} return self end, addonce = function(self, _val, _casesense) -- return true, if added local exists = function(_val, _casesense) for k in pairs(self.list) do if _casesense then if self.list[k] == _val then return true end else if tostring(self.list[k]):upper() == tostring(_val):upper() then return true end end end return false end if not exists(_val, _casesense) then table.insert(self.list, _val) return true end return nil end, new = function(self, _obj) _obj = _obj or {} setmetatable(_obj, self) self.__index = self return _obj end } --------------------------------------------------------------------------------------- /object list --------------------------------------------------------------------------------------- object color local objColor = { --------------------------------------------- variable will un/set if color-calltip is not/shown colortip_show = false, --------------------------------- user can disable search inside include files, default: enabled search_in_includes = true, ------------------------------------------------------------------- the default calltip position calltips_pos_def = false, ------------------------------------------------------------ the default calltip highlight color calltips_colorhlt_def = 0x0000FF, -- BGR (red) ---------------------------------------------------------- list with include storage directories lInclPathes = objList:new(), -------------------------------------------------- list/string with includes from current buffer lIncl = objList:new(), sIncl = '', ---------------------------------------------------------------------------------------- pattern pattHex = '()0x([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])', pattHex2 = '[0-9a-fA-F][0-9a-fA-F]', pattHexN = '0-[x#]([0-9a-fA-F]+)', pattHexEnd = '0x[0-9a-fA-F]+()', pattCS1 = '^#[Cc][Oo][Mm][Mm][Ee][Nn][Tt][Ss]%-[Ss][Tt][Aa][Rr][Tt]', pattCE1 = '^#[Cc][Oo][Mm][Mm][Ee][Nn][Tt][Ss]%-[Ee][Nn][Dd]', pattCS2 = '^#[Cc][Ss]', pattCE2 = '^#[Cc][Ee]', pattComment = '^%s*;', ----------------------------------------------------------------------------------------- pathes sPathGetColorAU3, sFileResult, TEMPDIR = props['SciteUserHome']..'\\..\\..\\Temp', sAU3exe = props['SciteDefaultHome']..'\\..\\AutoIt3.exe', ------------------------------------------------------------------------------------------------ ------------------------------------------------------------ set calltip values back to defaults SetCalltipsDefault = function(self) self.colortip_show = false scite.SendEditor(SCI_CALLTIPSETBACK, 0xFFFFFF) scite.SendEditor(SCI_CALLTIPSETFOREHLT, self.calltips_colorhlt_def) scite.SendEditor(SCI_CALLTIPSETPOSITION, self.calltips_pos_def) if bDEBUG then output:AppendText('> DEBUG: Calltips set to defaults') end end, ---------------------------------------------------------------------------- /SetCalltipsDefault ------------------------------------------------------------------------------ initialize values Startup = function(self) if props['Get.Color.Assignment.Includes'] == '0' then self.search_in_includes = false end if tonumber(props['calltips.set.above']) == 1 then self.calltips_pos_def = true end if props['calltips.color.highlight'] ~= '' then local colorhlt_user = myCallTips:BGR2Decimal(props['calltips.color.highlight']) if colorhlt_user ~= nil then self.calltips_colorhlt_def = colorhlt_user end end local sProp = props['openpath.$(au3)'] for w in sProp:gmatch('([^;]+)') do self.lInclPathes:addonce(w) end self.sPathGetColorAU3 = self.TEMPDIR..'\\ExecLineGetColor.au3' self.sFileResult = self.TEMPDIR..'\\ExecLineColor.txt' end, --------------------------------------------------------------------------------------- /Startup -------- check for comment line/block. Return "true/false, 0/1/-1" (0=comment line/1=#cs/-1=#ce) -- returned number for de/increase comment counter CheckComment = function(self, _s) local iMatch = _s:find(self.pattComment) if iMatch ~= nil then return true, 0 end iMatch = _s:find(self.pattCS1) or _s:find(self.pattCS2) if iMatch ~= nil then return true, 1 end iMatch = _s:find(self.pattCE1) or _s:find(self.pattCE2) if iMatch ~= nil then return true, -1 end return false, 0 end, ------------------------------------------------------------------------------------------------ --------------------------------------------------------- read include files from current buffer IncludesFromBuffer = function(self) local sText, boolCmnt, countCmnt, n, incl = editor:GetText(), false, 0 self.lIncl:delall() self.sIncl = '' for line in sText:gmatch('([^\r\n]+)') do boolCmnt, n = self:CheckComment(line) if boolCmnt then countCmnt = countCmnt + (n) end if not boolCmnt and countCmnt == 0 then -- none comment line or block -- #include <abc.au3> incl = line:match("#[iI][nN][cC][lL][uU][dD][eE]%s-<([%w%s_.]+)>") if incl ~= nil then if self.lIncl:addonce(incl) then self.sIncl = self.sIncl..'#include <'..incl..'>\n' if bDEBUG then output:AppendText('> DEBUG: IncludesFromBuffer.Add "#include <'..incl..'>"\n') end end else -- #include 'abc.au3' or #include "abc.au3" _, incl = line:match("#[iI][nN][cC][lL][uU][dD][eE]%s-([\"'])([%w%s_.:\\]+)%1") if incl ~= nil then if incl:sub(1,1) == '\\' then incl = incl:sub(2,-1) end if self.lIncl:addonce(incl) then if incl:sub(2,2) == ':' then self.sIncl = self.sIncl..'#include "'..incl..'"\n' if bDEBUG then output:AppendText('> DEBUG: IncludesFromBuffer.Add "#include '.."'"..incl.."'"..'"\n') end else self.sIncl = self.sIncl..'#include "'..props['FileDir']..'\\'..incl..'"\n' if bDEBUG then output:AppendText('> DEBUG: IncludesFromBuffer.Add "#include '.."'"..props['FileDir']..'\\'..incl.."'"..'"\n') end end end end end end end end, ---------------------------------------------------------------------------- /IncludesFromBuffer ------------------------------------------ create the au3 file for executing the assignment line CreateAU3 = function(self, _sLineAssignment) local sTextAU3 = self.sIncl.. 'Global $sFileExport = @TempDir & "\\ExecLineColor.txt"\n'.. 'FileDelete($sFileExport)\n'.. 'Global $sLine = "'.._sLineAssignment..'" ; line: $Variable = assignment\n'.. 'If $sLine = "NONE" Then Exit\n'.. 'Global $sExec = StringTrimLeft($sLine, StringInStr($sLine, "="))\n'.. 'Global $sColor = "0x" & Hex(Execute($sExec), 6)\n'.. 'If Not StringRegExp($sColor, "^0x[0-9A-F]{6}$") Then Exit\n'.. 'FileWrite($sFileExport, $sColor)\n' local fH = io.open(self.sPathGetColorAU3, 'w+') fH:write(sTextAU3) fH:close() end, ------------------------------------------------------------------------------------- /CreateAU3 --------------------------------- check, if file containing the assignment for selected variable FindAssignment = function(self, _path, _sSelection) local fH = io.open(_path) if fH ~= nil then local sRead, boolCmnt, countCmnt, n = fH:read('*all'), false, 0 fH:close() for line in sRead:gmatch('([^\r\n]+)') do boolCmnt, n = self:CheckComment(line) if boolCmnt then countCmnt = countCmnt + (n) end if not boolCmnt and countCmnt == 0 then -- none comment line or block if line:find(_sSelection..'%s*=') then if bDEBUG then output:AppendText('> DEBUG: Assignment line "'..line..'"\n') end return line end end end end return nil end, -------------------------------------------------------------------------------- /FindAssignment -------------------------------------------------------------------- detects color from variable GetColorValueFromVariable = function(self, _sSelection, _iCursor, _var_beginPos, _var_endPos, _fBGR) local sLine = self:FindAssignment(props['FilePath'], _sSelection) if sLine == nil then -- search inside include files -- do it not, if the user has disabled: "Get.Color.Assignment.Includes=0" (default = 1 - enabled) if self.search_in_includes then self:IncludesFromBuffer() -- get include files if #self.lIncl.list ~= 0 then -- open each include file, search line with assignment "_sSelection =" for i=1, #self.lIncl.list do if self.lIncl.list[i]:sub(2,2) == ':' then -- include has full path, search only in this file sLine = self:FindAssignment(self.lIncl.list[i], _sSelection) if bDEBUG then output:AppendText('> DEBUG: Search "'.._sSelection..'" in "'..self.lIncl.list[i]..'" --> '..tostring(sLine ~= nil)..'\n') end end if sLine == nil and self.lIncl.list[i]:find('\\') then -- include has partial path, check first if exist in @ScriptDir sLine = self:FindAssignment(props['FileDir']..'\\'..self.lIncl.list[i], _sSelection) if bDEBUG then output:AppendText('> DEBUG: Search "'.._sSelection..'" in "'..props['FileDir']..'\\'..self.lIncl.list[i]..'" --> '..tostring(sLine ~= nil)..'\n') end end if sLine == nil then -- include has filename only (or partial path), -- .. concanate all directories with this for searching for j=1, #self.lInclPathes.list do sLine = self:FindAssignment(self.lInclPathes.list[j]..'\\'..self.lIncl.list[i], _sSelection) if bDEBUG then output:AppendText('> DEBUG: Search "'.._sSelection..'" in "'..self.lInclPathes.list[j]..'\\'..self.lIncl.list[i]..'" --> '..tostring(sLine ~= nil)..'\n') end if sLine == nil then sLine = self:FindAssignment(props['FileDir']..'\\'..self.lIncl.list[i], _sSelection) if bDEBUG then output:AppendText('> DEBUG: Search "'.._sSelection..'" in "'..props['FileDir']..'\\'..self.lIncl.list[i]..'" --> '..tostring(sLine ~= nil)..'\n') end end if sLine ~= nil then break end end end end end end end if sLine == nil then sLine = 'NONE' else -- trim characters right from assignment sLine = sLine:sub(1,sLine:match(self.pattHexEnd)) end if bDEBUG then output:AppendText('> DEBUG: Search "'.._sSelection..'" \n> DEBUG: Result "'..sLine..'"\n') end -- create the au3-file for executing the assignment line, with 'NONE' - the last result file will delete self:CreateAU3(sLine) -- run the au3-file local sCmd = '"'..self.sAU3exe..'" /AutoIt3ExecuteScript "'..self.sPathGetColorAU3..'"'..' "'..sLine..'"' if shell then shell.exec(sCmd, nil, true, true) else os.execute('start "" '..sCmd) end -- check for result local fH = io.open(self.sFileResult) if fH == nil then scite.SendEditor(SCI_CALLTIPSHOW, _var_beginPos +1, (' NONE COLOR ASSIGNED! ')) scite.SendEditor(SCI_CALLTIPSETHLT, 0, 22) scite.SendEditor(SCI_CALLTIPSETBACK, 0x33FFFF) scite.SendEditor(SCI_CALLTIPSETFOREHLT, 0x0000FF) scite.SendEditor(SCI_CALLTIPSETPOSITION, true) if bDEBUG then output:AppendText('> DEBUG: Set Calltip "'.._sSelection..'" --> "NONE COLOR ASSIGNED!"\n') end else local sValue = fH:read() fH:close() local R,G,B = sValue:match('('..self.pattHex2..')('..self.pattHex2..')('..self.pattHex2..')$') local iLen = _var_endPos - _var_beginPos -1 scite.SendEditor(SCI_CALLTIPSHOW, _var_beginPos +1, (' '):rep(iLen)) scite.SendEditor(SCI_CALLTIPSETHLT, 0, iLen) scite.SendEditor(SCI_CALLTIPSETPOSITION, true) if _fBGR == true then scite.SendEditor(SCI_CALLTIPSETBACK, tonumber(string.format('0x%s%s%s', R,G,B))) if bDEBUG then output:AppendText('> DEBUG: Set Calltip BGR "'.._sSelection..'" --> "'..string.format('0x%s%s%s', R,G,B)..'"\n') end else scite.SendEditor(SCI_CALLTIPSETBACK, tonumber(string.format('0x%s%s%s', B,G,R))) if bDEBUG then output:AppendText('> DEBUG: Set Calltip RGB "'.._sSelection..'" --> "'..string.format('0x%s%s%s', B,G,R)..'"\n') end end end self.colortip_show = true editor:SetSelection(_iCursor, _iCursor) end, --------------------------------------------------------------------- /GetColorValueFromVariable ----------------------------------------- grabs the color value or variable from cursor position FromCursor = function(self, _fBGR) local function isHexChar(_asc) local sChar = string.char(_asc) if sChar:find('[#x0-9a-fA-F]') then return true else return false end end local cursor = editor.CurrentPos -- check if cursor is possible inside a variable local var_beginPos, var_endPos = cursor if string.char(editor.CharAt[cursor]) ~= '$' then -- cursor is inside or behind the variable (if its a variable) editor:WordLeft() -- skip to the left end var_beginPos = editor.CurrentPos -- is it a variable? if string.char(editor.CharAt[var_beginPos]) == '$' then -- now the cursor is in front of variable editor:WordRight() var_endPos = editor.CurrentPos editor:SetSelection(var_beginPos, var_endPos) local sSelection = editor:GetSelText() local iLenSel = sSelection:len() -- trim spaces on right site, if any sSelection = sSelection:gsub('%s+$','') var_endPos = var_endPos - (iLenSel - sSelection:len()) if bDEBUG then output:AppendText('> DEBUG: Cursor on variable "'..sSelection..'"\n') end return self:GetColorValueFromVariable(sSelection, cursor, var_beginPos, var_endPos, _fBGR) end -- cursor inside hex value? local beginPos, endPos = cursor, cursor while isHexChar(editor.CharAt[beginPos-1]) do beginPos = beginPos - 1 end while isHexChar(editor.CharAt[endPos]) do endPos = endPos + 1 end if beginPos ~= endPos then if beginPos > endPos then editor:SetSelection(endPos, beginPos) else editor:SetSelection(beginPos, endPos) end local sMatch = tostring(editor:GetSelText()):match(self.pattHexN) if sMatch == nil then return editor:SetSelection(cursor, cursor) end local sHex6 = '0x'..('0'):rep(6-sMatch:len())..sMatch local iLen = sMatch:len() +2 local R,G,B = tostring(sHex6):match('('..self.pattHex2..')('..self.pattHex2..')('..self.pattHex2..')$') if bDEBUG then output:AppendText('> DEBUG: Cursor on hex value\n') end editor:SetSelection(cursor, cursor) scite.SendEditor(SCI_CALLTIPSHOW, beginPos+1, (' '):rep(iLen-1)) scite.SendEditor(SCI_CALLTIPSETHLT, 0, iLen-1) scite.SendEditor(SCI_CALLTIPSETPOSITION, true) if _fBGR == true then scite.SendEditor(SCI_CALLTIPSETBACK, tonumber(string.format('0x%s%s%s', R,G,B))) if bDEBUG then output:AppendText('> DEBUG: Set Calltip BGR hex value --> "'..string.format('0x%s%s%s', R,G,B)..'"\n') end else scite.SendEditor(SCI_CALLTIPSETBACK, tonumber(string.format('0x%s%s%s', B,G,R))) if bDEBUG then output:AppendText('> DEBUG: Set Calltip RGB hex value --> "'..string.format('0x%s%s%s', B,G,R)..'"\n') end end self.colortip_show = true else editor:SetSelection(cursor, cursor) end end, ------------------------------------------------------------------------------------ /FromCursor ----------------------------------------------------------------------- show back and fore color PreviewBackForeColor = function(self, _fFore1st) local iBackCol, iForeCol = 0xF0F0F0, 0x000000 local cursor = editor.CurrentPos local sLine, iColumn = editor:GetCurLine() local iLineStartPos = cursor - iColumn local tMatch, beginPos = {}, nil for s, r, g, b in sLine:gmatch(self.pattHex) do if beginPos == nil then beginPos = s end local t = {} t['R']=r t['G']=g t['B']=b table.insert(tMatch, t) end if #tMatch == 0 then if bDEBUG then output:AppendText('> DEBUG: Search back/fore color --> "FAILED"\n') end return elseif #tMatch == 1 then if _fFore1st == true then iForeCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)) if bDEBUG then output:AppendText('> DEBUG: Search back/fore color "ForeColor" --> "'..string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)..'"\n') end else iBackCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)) if bDEBUG then output:AppendText('> DEBUG: Search back/fore color "BackColor" --> "'..string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)..'"\n') end end else if _fFore1st == true then iForeCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)) iBackCol = tonumber(string.format('0x%s%s%s', tMatch[2].B, tMatch[2].G, tMatch[2].R)) if bDEBUG then output:AppendText('> DEBUG: Search back/fore color "ForeColor" --> "'..string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)..'"\n') end if bDEBUG then output:AppendText('> DEBUG: Search back/fore color "BackColor" --> "'..string.format('0x%s%s%s', tMatch[2].B, tMatch[2].G, tMatch[2].R)..'"\n') end else iForeCol = tonumber(string.format('0x%s%s%s', tMatch[2].B, tMatch[2].G, tMatch[2].R)) iBackCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)) if bDEBUG then output:AppendText('> DEBUG: Search back/fore color "ForeColor" --> "'..string.format('0x%s%s%s', tMatch[2].B, tMatch[2].G, tMatch[2].R)..'"\n') end if bDEBUG then output:AppendText('> DEBUG: Search back/fore color "BackColor" --> "'..string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)..'"\n') end end end if bDEBUG then output:AppendText('> DEBUG: Set calltip back/fore color\n') end scite.SendEditor(SCI_CALLTIPSHOW, iLineStartPos + beginPos, ' FORE-COLOR ') scite.SendEditor(SCI_CALLTIPSETHLT, 0, 12) scite.SendEditor(SCI_CALLTIPSETBACK, iBackCol) scite.SendEditor(SCI_CALLTIPSETFOREHLT, iForeCol) self.colortip_show = true end -------------------------------------------------------------------------- /PreviewBackForeColor } -------------------------------------------------------------------------------------- /object color ---------------------------------------------------------------------------------- region EventClass ShowColorEvt = EventClass:new(Common) function ShowColorEvt:OnKey() if objColor.colortip_show then if bCALLTIP_END_ANYKEY then scite.SendEditor(SCI_CALLTIPCANCEL) end objColor:SetCalltipsDefault() end end function ShowColorEvt:OnDwellStart() if objColor.colortip_show then if bCALLTIP_END_ANYKEY then scite.SendEditor(SCI_CALLTIPCANCEL) end objColor:SetCalltipsDefault() end end --------------------------------------------------------------------------------- /region EventClass -------------------------------------------------------------------------- function call redirection function ShowHexColorFromCursor(_fBGR) objColor:FromCursor(_fBGR) end --> ShowHexColorFromCursor function PreviewBackForeColor(_fFore1st) objColor:PreviewBackForeColor(_fFore1st) end --> PreviewBackForeColor ---------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- run startup objColor:Startup() ---------------------------------------------------------------------------------------------------- ShowHexColorFromCursor[0.10].lua1 point
-
GetModuleFunc.h 1. Introduction This writing describes in detail method for retrieving the address of exported function for loaded module without using any available API on either 32bit, 64bit or ARM based Windows systems. Structures definitions are taken from Microsoft SDK 7.1, unless otherwise specified. Loaded module is searched by name, not path. The code is written in form of function that has two parameters, WCHAR pointer to the module name and CHAR pointer to the function name, written in C++ and compiled using Microsoft Visual Studio Express 2013 for Windows Desktop. Basic knowledge of C++ is assumed. Attached GetModuleFunc.h has the full code for the function. 2. NT_TIB Structure defined inside winnt.h. It's the staring point for the algorithm. It includes self-referencing field - Self pointer, offset of which is used on non-ARM systems to read Thread Environment Block data. typedef struct _NT_TIB { struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList; PVOID StackBase; PVOID StackLimit; PVOID SubSystemTib; #if defined(_MSC_EXTENSIONS) union { PVOID FiberData; DWORD Version; }; #else PVOID FiberData; #endif PVOID ArbitraryUserPointer; struct _NT_TIB *Self; } NT_TIB; typedef NT_TIB *PNT_TIB; 2.1. TEBThread Environment Block is chunk of memory filled with various information about the thread. TEB is defined inside winternl.h as: typedef struct _TEB { PVOID Reserved1[12]; PPEB ProcessEnvironmentBlock; PVOID Reserved2[399]; BYTE Reserved3[1952]; PVOID TlsSlots[64]; BYTE Reserved4[8]; PVOID Reserved5[26]; PVOID ReservedForOle; // Windows 2000 only PVOID Reserved6[4]; PVOID TlsExpansionSlots; } TEB, *PTEB; After the executable is loaded by the Windows PE loader and before the thread starts running, TEB is saved to fs(x86) or gs(x64 flavor) processor register. ARM systems use different technique which utilize coprocessors scheme (it's unclear whether the coprocessor is real hardware component or emulated). Self field of NT_TIB is the TEB pointer for the current thread.Even not officially documented, this behavior is observed on/for all available Windows operating systems with NT kernel. Acquiring pointer to the TEB is done using Microsoft specific compiler intrinsics: #include <winnt.h> #include <winternl.h> #if defined(_M_X64) // x64 auto pTeb = reinterpret_cast<PTEB>(__readgsqword(reinterpret_cast<DWORD>(&static_cast<NT_TIB*>(nullptr)->Self))); #elif defined(_M_ARM) // ARM auto pTeb = reinterpret_cast<PTEB>(_MoveFromCoprocessor(15, 0, 13, 0, 2)); // CP15_TPIDRURW #else // x86 auto pTeb = reinterpret_cast<PTEB>(__readfsdword(reinterpret_cast<DWORD>(&static_cast<NT_TIB*>(nullptr)->Self))); #endif Among others, one of the fields inside the TEB is pointer to the PEB (Process Environment Block). 3. PEB Process Environment Block is memory area filled with information about a process. PEB is defined inside winternl.h as: typedef struct _PEB { BYTE Reserved1[2]; BYTE BeingDebugged; BYTE Reserved2[1]; PVOID Reserved3[2]; PPEB_LDR_DATA Ldr; PRTL_USER_PROCESS_PARAMETERS ProcessParameters; PVOID Reserved4[3]; PVOID AtlThunkSListPtr; PVOID Reserved5; ULONG Reserved6; PVOID Reserved7; ULONG Reserved8; ULONG AtlThunkSListPtr32; PVOID Reserved9[45]; BYTE Reserved10[96]; PPS_POST_PROCESS_INIT_ROUTINE PostProcessInitRoutine; BYTE Reserved11[128]; PVOID Reserved12[1]; ULONG SessionId; } PEB, *PPEB; Pointer to the PEB is read from the TEB: auto pPeb = pTeb->ProcessEnvironmentBlock; 3.1. PEB_LDR_DATAContains information about the loaded modules for the process. Ldr field of the PEB points to PEB_LDR_DATA structure, defined inside winternl.h as: typedef struct _PEB_LDR_DATA { BYTE Reserved1[8]; PVOID Reserved2[3]; LIST_ENTRY InMemoryOrderModuleList; } PEB_LDR_DATA, *PPEB_LDR_DATA; Pointer to the PEB_LDR_DATA is read from the PEB: auto pLdrData = pPeb->Ldr; 3.2. LIST_ENTRYInMemoryOrderModuleList field of the PEB_LDR_DATA is doubly-linked list that contains the loaded modules for the process, defined inside winnt.h as: typedef struct _LIST_ENTRY { struct _LIST_ENTRY *Flink; struct _LIST_ENTRY *Blink; } LIST_ENTRY, *PLIST_ENTRY, *RESTRICTED_POINTER PRLIST_ENTRY; auto pModListHdr = &pLdrData->InMemoryOrderModuleList; 4. LDR_DATA_TABLE_ENTRYEach item in the list is a pointer to an LDR_DATA_TABLE_ENTRY structure, defined inside winternl.h as: typedef struct _LDR_DATA_TABLE_ENTRY { PVOID Reserved1[2]; LIST_ENTRY InMemoryOrderLinks; PVOID Reserved2[2]; PVOID DllBase; PVOID Reserved3[2]; UNICODE_STRING FullDllName; BYTE Reserved4[8]; PVOID Reserved5[3]; union { ULONG CheckSum; PVOID Reserved6; } DUMMYUNIONNAME; ULONG TimeDateStamp; } LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY; DllBase field is the base address of the loaded module.This stucture doesn't give wanted info for the module, being its name. One option is to read FullDllName which includes full path and extract module name from it. However, some independent authors give slightly different definition which include another field - BaseDllName. Modified LDR_DATA_TABLE_ENTRY struct can be defined, including BaseDllName field and freed from superfluous fields. InMemoryOrderLinks will be iterated, so that field is the top of the struct: typedef struct _LDR_DATA_TABLE_ENTRY { /*LIST_ENTRY InLoadOrderLinks;*/ LIST_ENTRY InMemoryOrderLinks; LIST_ENTRY InInitializationOrderList; PVOID DllBase; PVOID EntryPoint; PVOID Reserved3; UNICODE_STRING FullDllName; UNICODE_STRING BaseDllName; } LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY; 4.1. IterationGoing through the items in the list is straightforward. The last item points to the first, meaning the end is reached, hence it can be written: for (auto pModListCurrent = pModListHdr->Flink; pModListCurrent != pModListHdr; pModListCurrent = pModListCurrent->Flink) { // Get current module in list auto pModEntry = reinterpret_cast<PLDR_DATA_TABLE_ENTRY>(pModListCurrent); //... } 4.2. Reading Module NameThis data is stored in form of UNICODE_STRING. winternl.h definition is: typedef struct _UNICODE_STRING { USHORT Length; USHORT MaximumLength; PWSTR Buffer; } UNICODE_STRING; Module name lookup is case insensitive. Lengths specified inside UNICODE_STRING represent bytes, which means number of WCHAR characters is half of the numbers.One of the ways to make case insensitive comparison of the specified module name and listed one is to turn both to uppercase before comparing them: for (int i = 0; i < pModEntry->BaseDllName.Length / 2 /* length is in bytes */; ++i) { if (sModuleName[i] == '\0') // the end of the string break; else if ((sModuleName[i] & ~' ') != (pModEntry->BaseDllName.Buffer[i] & ~' ')) // case-insensitive break; else if (i == iLenModule - 1) // gone through all characters and they all matched { //... the rest of the code } } iLenModule is length of the wanted module name. It's get by counting number of characters inside the string until null-terminator is encountered: int iLenModule = 0; for (; sModuleName[iLenModule]; ++iLenModule); Comparison written in this manner allows for matching function argument L"kernel32" to listed L"kernel32.dll", which mimics to a decent degree (not completely for brevity) behavior of GetModuleHandle WinAPI function. In case of two different loaded modules whose names differs only in extensions, first listed is matched. 5. PE format walkthrough The Portable Executable (PE) format is a file format for executables, object code, DLLs, etc... It describes how and where inside the file the executable code is, import table, export table, resources, and every other data needed for loader. Exported functions are listed inside the Export Table. Reaching export table is done in few steps parsing the PE data. 5.1. IMAGE_DOS_HEADER The matching module's DllBase points to the first byte of the loaded image. PE starts with legacy DOS header defined inside winnt.h as: typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header WORD e_magic; // Magic number WORD e_cblp; // Bytes on last page of file WORD e_cp; // Pages in file WORD e_crlc; // Relocations WORD e_cparhdr; // Size of header in paragraphs WORD e_minalloc; // Minimum extra paragraphs needed WORD e_maxalloc; // Maximum extra paragraphs needed WORD e_ss; // Initial (relative) SS value WORD e_sp; // Initial SP value WORD e_csum; // Checksum WORD e_ip; // Initial IP value WORD e_cs; // Initial (relative) CS value WORD e_lfarlc; // File address of relocation table WORD e_ovno; // Overlay number WORD e_res[4]; // Reserved words WORD e_oemid; // OEM identifier (for e_oeminfo) WORD e_oeminfo; // OEM information; e_oemid specific WORD e_res2[10]; // Reserved words LONG e_lfanew; // File address of new exe header } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER; Therefore it can be written: auto pImageDOSHeader = reinterpret_cast<PIMAGE_DOS_HEADER>(pModEntry->DllBase); e_lfanew is offset to a NT header. 5.2. IMAGE_NT_HEADERS Another area of PE is NT header. This is effectively the starting point of the portable executable format description. Definition and the size of it depends on bitness. For 32bit it's: typedef struct _IMAGE_NT_HEADERS { DWORD Signature; IMAGE_FILE_HEADER FileHeader; IMAGE_OPTIONAL_HEADER32 OptionalHeader; } IMAGE_NT_HEADERS32, *PIMAGE_NT_HEADERS32; ...and 64bit version is: typedef struct _IMAGE_NT_HEADERS64 { DWORD Signature; IMAGE_FILE_HEADER FileHeader; IMAGE_OPTIONAL_HEADER64 OptionalHeader; } IMAGE_NT_HEADERS64, *PIMAGE_NT_HEADERS64; 5.3. IMAGE_NT_HEADERSOptionalHeader field is another structure discribing in detail PE file. It's directly followed by number of IMAGE_DATA_DIRECTORY structures. The exact number of these structures is saved inside IMAGE_NT_HEADERS as NumberOfRvaAndSizes field. For 32bit PE IMAGE_NT_HEADERS is defined as: typedef struct _IMAGE_OPTIONAL_HEADER { // // Standard fields. // WORD Magic; BYTE MajorLinkerVersion; BYTE MinorLinkerVersion; DWORD SizeOfCode; DWORD SizeOfInitializedData; DWORD SizeOfUninitializedData; DWORD AddressOfEntryPoint; DWORD BaseOfCode; DWORD BaseOfData; // // NT additional fields. // DWORD ImageBase; DWORD SectionAlignment; DWORD FileAlignment; WORD MajorOperatingSystemVersion; WORD MinorOperatingSystemVersion; WORD MajorImageVersion; WORD MinorImageVersion; WORD MajorSubsystemVersion; WORD MinorSubsystemVersion; DWORD Win32VersionValue; DWORD SizeOfImage; DWORD SizeOfHeaders; DWORD CheckSum; WORD Subsystem; WORD DllCharacteristics; DWORD SizeOfStackReserve; DWORD SizeOfStackCommit; DWORD SizeOfHeapReserve; DWORD SizeOfHeapCommit; DWORD LoaderFlags; DWORD NumberOfRvaAndSizes; IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; } IMAGE_OPTIONAL_HEADER32, *PIMAGE_OPTIONAL_HEADER32; ...and for 64bit version it's: typedef struct _IMAGE_OPTIONAL_HEADER64 { WORD Magic; BYTE MajorLinkerVersion; BYTE MinorLinkerVersion; DWORD SizeOfCode; DWORD SizeOfInitializedData; DWORD SizeOfUninitializedData; DWORD AddressOfEntryPoint; DWORD BaseOfCode; ULONGLONG ImageBase; DWORD SectionAlignment; DWORD FileAlignment; WORD MajorOperatingSystemVersion; WORD MinorOperatingSystemVersion; WORD MajorImageVersion; WORD MinorImageVersion; WORD MajorSubsystemVersion; WORD MinorSubsystemVersion; DWORD Win32VersionValue; DWORD SizeOfImage; DWORD SizeOfHeaders; DWORD CheckSum; WORD Subsystem; WORD DllCharacteristics; ULONGLONG SizeOfStackReserve; ULONGLONG SizeOfStackCommit; ULONGLONG SizeOfHeapReserve; ULONGLONG SizeOfHeapCommit; DWORD LoaderFlags; DWORD NumberOfRvaAndSizes; IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; } IMAGE_OPTIONAL_HEADER64, *PIMAGE_OPTIONAL_HEADER64; PE files generated by Microsoft tools allways create IMAGE_NUMBEROF_DIRECTORY_ENTRIES (16) IMAGE_DATA_DIRECTORY structures, 15 of which are documented in this order (winnt.h): #define IMAGE_DIRECTORY_ENTRY_EXPORT 0 // Export Directory #define IMAGE_DIRECTORY_ENTRY_IMPORT 1 // Import Directory #define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 // Resource Directory #define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 // Exception Directory #define IMAGE_DIRECTORY_ENTRY_SECURITY 4 // Security Directory #define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 // Base Relocation Table #define IMAGE_DIRECTORY_ENTRY_DEBUG 6 // Debug Directory // IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7 // (X86 usage) #define IMAGE_DIRECTORY_ENTRY_ARCHITECTURE 7 // Architecture Specific Data #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 // RVA of GP #define IMAGE_DIRECTORY_ENTRY_TLS 9 // TLS Directory #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 // Load Configuration Directory #define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 11 // Bound Import Directory in headers #define IMAGE_DIRECTORY_ENTRY_IAT 12 // Import Address Table #define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT 13 // Delay Load Import Descriptors #define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 14 // COM Runtime descriptor 5.4. IMAGE_DATA_DIRECTORYDefinition is: typedef struct _IMAGE_DATA_DIRECTORY { DWORD VirtualAddress; DWORD Size; } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY; It can now be written: auto pExport = reinterpret_cast<PIMAGE_DATA_DIRECTORY>(&pImageNtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT]); VirtualAddress field is RVA of the directory counting from the first byte (base) of the loaded module. If both VirtualAddress and Size fields are filled then the module exports functions. 5.5. IMAGE_EXPORT_DIRECTORY Definition is (winnt.h): typedef struct _IMAGE_EXPORT_DIRECTORY { DWORD Characteristics; DWORD TimeDateStamp; WORD MajorVersion; WORD MinorVersion; DWORD Name; DWORD Base; DWORD NumberOfFunctions; DWORD NumberOfNames; DWORD AddressOfFunctions; // RVA from base of image DWORD AddressOfNames; // RVA from base of image DWORD AddressOfNameOrdinals; // RVA from base of image } IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY; Base is ordinal value of the first exported function.NumberOfFunctions is overall number of exported functions from the module. NumberOfNames is number of functions exported only by name. AddressOfFunctions is RVA of the array of RVAs of exported functions addresses. AddressOfNames is RVA of the array of RVAs of exported functions names. AddressOfNameOrdinals is RVA of the array of WORD values each representing index of function exported by name, into the array of addresses. It's: auto pExports = reinterpret_cast<PIMAGE_EXPORT_DIRECTORY>(reinterpret_cast<ULONG_PTR>(pImageDOSHeader) + pExport->VirtualAddress); 6. Getting function RVAEvery exported function is accessible by odinal value. Functions exported by name are also accessible by name. Finding function by its ordinal value is fairly simple and fast. The lowest ordinal value is Base field of IMAGE_EXPORT_DIRECTORY struct. The highest ordinal value is get by adding the number of exported functions to that number, minus one of course. If the specified ordinal value is within this range, RVA is read from the array of functions addresses: if (iOrdinal) // function is wanted by its ordinal value { // Check to see if valid ordinal value is specified if (iOrdinal >= pExports->Base && iOrdinal < pExports->Base + pExports->NumberOfFunctions) dwExportRVA = pdwBufferAddress[iOrdinal - pExports->Base]; } In case of functions exported by name, name lookup needs to be performed.The code is: // Array of functions names auto pdwBufferNames = reinterpret_cast<LPDWORD>(reinterpret_cast<ULONG_PTR>(pImageDOSHeader) + pExports->AddressOfNames); // Array of functions indexes into array of addresses auto pwBufferNamesOrdinals = reinterpret_cast<LPWORD>(reinterpret_cast<ULONG_PTR>(pImageDOSHeader) + pExports->AddressOfNameOrdinals); And then the loop: // Loop through all functions exported by name for (DWORD j = 0; j < pExports->NumberOfNames; ++j) { // Read the listed function name auto sFunc = reinterpret_cast<LPCSTR>(reinterpret_cast<ULONG_PTR>(pImageDOSHeader) + pdwBufferNames[j]); //... } When the name of the function is matched (case sensitive) the RVA of the function will be read from pdwBufferAddress array at index read from pwBufferNamesOrdinals at loop counter value index: dwExportRVA = pdwBufferAddress[pwBufferNamesOrdinals[j]]; 6.1. Export ForwardingRVA of the function will resolve fonction's pointer. However there is one special case when the RVA offset points to a value inside the exports section and not to the function body which is normally found in some other sections of PE. When that happens, RVA will resolve to a null-terminated ASCII string value. This is called Export Forwarding. RVA is then replaced by the RVA value of the resolved function. if (dwExportRVA > pExport->VirtualAddress && dwExportRVA < pExport->VirtualAddress + pExport->Size) { // Read forwarded data. auto sForwarder = reinterpret_cast<LPCSTR>(reinterpret_cast<ULONG_PTR>(pImageDOSHeader) + dwExportRVA); //... } The format of the forwarding string is: ModuleName.FunctionName or ModuleName.#OrdinalValueTo resolve the RVA of the new exported function a recursive call to this function will be used. ModuleName has to be wide string. WCHAR buffer is allocated and all characters from ModuleName portion of forwarded string copied to it: WCHAR sForwarderDll[MAX_PATH]; // Reinterpret WCHAR buffer as CHAR one auto sForwarderDll_A = reinterpret_cast<CHAR*>(sForwarderDll); // Now go through all characters for (int iPos = 0; sForwarder[iPos]; ++iPos) { // Fill WCHAR buffer reading/copying from CHAR one sForwarderDll_A[2 * iPos] = sForwarder[iPos]; // copy character sForwarderDll_A[2 * iPos + 1] = '\0'; if (sForwarder[iPos] == '.') { sForwarderDll[iPos] = '\0'; // null-terminate the ModuleName string break; } } In case forwarding string specifies function name, pointer to that string is simply a pointer to a character following the dot.For OrdinalValue version the presence of hashtek character after the dot has to be checked and the hashtag string converted to integer value before recursive call made. The full code for this is: // Allocate big enough buffer for the new module name WCHAR sForwarderDll[MAX_PATH]; LPCSTR sForwarderFunc = nullptr; DWORD dwForwarderOrdinal = 0; // Reinterpret WCHAR buffer as CHAR one auto sForwarderDll_A = reinterpret_cast<CHAR*>(sForwarderDll); // Now go through all characters for (int iPos = 0; sForwarder[iPos]; ++iPos) { // Fill WCHAR buffer reading/copying from CHAR one sForwarderDll_A[2 * iPos] = sForwarder[iPos]; // copy character sForwarderDll_A[2 * iPos + 1] = '\0'; if (sForwarder[iPos] == '.') { sForwarderDll[iPos] = '\0'; // null-terminate the ModuleName string ++iPos; if (sForwarder[iPos] == '#') { ++iPos; // skip # character // OrdinalValue is hashtag, convert ASCII string to integer value for (; sForwarder[iPos]; ++iPos) { dwForwarderOrdinal *= 10; dwForwarderOrdinal += (sForwarder[iPos] - '0'); } if (dwForwarderOrdinal > MAX_ORDINAL) // something is wrong return nullptr; // Reinterpret the ordinal value as string sForwarderFunc = reinterpret_cast<LPSTR>(dwForwarderOrdinal); break; } else { sForwarderFunc = &sForwarder[iPos]; // FunctionName follows the dot break; } } } 6.2. FinalizingOnce funcion address RVA is get, it's added to the base address and returned from the function: return reinterpret_cast<LPVOID>(reinterpret_cast<ULONG_PTR>(pImageDOSHeader) + dwExportRVA); 7. ExampleThe attached zip contains two executables compiled from the source of 1K-Mandelbrot project, written by Emil Persson. The source had no explicit License Agreement. It's modified not to use WinAPI, rather to use method desribed here to call functions from used dlls and then compiled. Beautiful examples of visualisation of complex calculations, done in efficient way using OpenGL. Requirement is OpenGL 2.0. Third example is compiled for ARM. It's simple analog Direct2D clock, the original code of which is released under Artistic License/GPL by vckzdd. GetModuleFunc_Examples.zip 8. Conclusion This method isn't usually used by executables ran from user mode. It should be avoided used for production software, because it ommits taking ownership of critical section object used by windows during load/unload actions of the module, which could result in any kind of unhandled exception. Limited speed tests show that it's faster than standard GetModuleHandle/GetProcAddress method. Mimicking WinAPI behavior is achieved to a high level for valid input, with omitted special error handling and reporting. The only major difference is unsupported full-path processing. 8.1. Anti-Virus Software considerations This method enables compiling PE files with empty imports directory. In combination with accessing fs register at TEB/PEB offset it has been observed that 18.2% of AV scanners tend to flag 32bit executables, containing no code other than this function, as malware. 64 bit and ARM executables compiled from the same source never get flagged. References: Microsoft Corporation: Microsoft Portable Executable and Common Object File Format Specification, Revision 6.0 Matt Pietrek: Under The Hood - http://www.microsoft.com/msj/archive/s2ce.aspx An In-Depth Look into the Win32 Portable Executable File Format - http://msdn.microsoft.com/en-us/magazine/bb985992.aspx An In-Depth Look into the Win32 Portable Executable File Format, Part 2 - http://msdn.microsoft.com/en-us/magazine/cc301808.aspx Mark Russinovich, David A. Solomon, Alex Ionescu : Microsoft Windows Internals, 6th edition VirusTotal: Web Service - https://www.virustotal.com/ Emil Persson: 1K-Mandelbrot - http://www.humus.name/index.php?page=3D&ID=85 vckzdd: directxcode - https://code.google.com/p/directxcode/source/browse/#svn/Direct2D/Clock1 point
-
1 point
-
Automate Adobe Acrobat
Jfish reacted to JLogan3o13 for a topic
As much as I am for scripting all things possible, sometimes the manual route is just easier if you are only doing it once. In the optimization wizard in Acrobat there is an option to add multiple files. Click on Multiple files, Add Files, browse to the folder, CTRL+A, Open. Bob's your uncle, you're done.1 point -
1 point
-
One other thing to talk about is code and documentation licensing; I have no license preference -- I just don't want somebody to help then tell us we can't use their code two years from now. --Edit: I've been reading through the code, and I have a question pertaining to the global tables. In your port of IO Environment.vb -- would it be useful to enumerate the object structures? For example, $eSymbolsIsProto = 0, $eSymbolsName, $eSymbolsOffset, $eSymbolsSection, $eSymbolsSymType? When using the table, I know every symbol has a name, but I don't need to know that the name is in $Symbols[$x][1] -- I can just call it $Symbols[$x][$eSymbolsName] and be done with it.1 point
-
OTOH there is a huge advantage with that: a zero-byte program is provably both non malicious and bug-free. Keep positive!1 point
-
$form = _IEFormGetObjByName($oIE, "measure_wizard_form") $name = _IEFormElementGetObjByName($form, "title") _IEFormElementSetValue($name, "mikell") $height = _IEFormElementGetObjByName($form, "feet") _IEFormElementOptionSelect($height, "6") _IEFormElementRadioSelect($form, "straight", "param_shoulders") ; etc1 point
-
Autoit icon on the right corner of Windows bar
232showtime reacted to guinness for a topic
So open the help file and look at the GUI Menu UDF and search around the Forum for titlebar context menu. In SciTE Jump (Alt+Q in SciTE) you will see I have something like that. Check the source code for how/what I did.1 point -
@Jfish, first of all, thank you for putting in all the effort into this, it is really great! Most people would charge for something like this but you are providing it for free, truly in the spirit of Autoit :). Great job, well done! I do have one suggestion only at this stage and it's that it would be nice if any code sections or variables etc would stand out better from the regular text in the PDF. E.g. using a console style font with a grey/other color highlight background for any code would be great.1 point
-
You can do through the class name instead of ID using this function: ;=============================================================================== ; ; Function Name: _IEGetObjByClass() ; Description: Returns an object variable by Class ; Parameter(s): $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; $s_Class - Specifies class of the object you wish to match ; $i_index - Optional: If the class occurs more than once, specify which instance by 0-based index ; Requirement(s): AutoIt3 V3.2 or higher ; Return Value(s): On Success - Returns an object variable pointing to the specified Object ; On Failure - Returns 0 and sets @ERROR ; @ERROR - 0 ($_IEStatus_Success) = No Error ; - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type ; - 7 ($_IEStatus_NoMatch) = No Match ; @Extended - Contains invalid parameter number ; Author(s): Bob Anthony (big_daddy) ; ;=============================================================================== ; Func _IEGetObjByClass(ByRef $o_object, $s_Class, $i_index = 0) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IEGetObjByClass", "$_IEStatus_InvalidDataType") SetError($_IEStatus_InvalidDataType, 1) Return 0 EndIf ; If Not __IEIsObjType($o_object, "browserdom") Then __IEErrorNotify("Error", "_IEGetObjByClass", "$_IEStatus_InvalidObjectType") SetError($_IEStatus_InvalidObjectType, 1) Return 0 EndIf ; Local $i_found = 0 ; $o_tags = _IETagNameAllGetCollection($o_object) For $o_tag In $o_tags If String($o_tag.className) = $s_Class Then If ($i_found = $i_index) Then SetError($_IEStatus_Success) Return $o_tag Else $i_found += 1 EndIf EndIf Next ; __IEErrorNotify("Warning", "_IEGetObjByClass", "$_IEStatus_NoMatch", $s_Class) SetError($_IEStatus_NoMatch, 2) Return 0 EndFunc ;==>_IEGetObjByClass1 point
-
AutoIt Snippets
argumentum reacted to TheDcoder for a topic
I am continuing my posting combo , RunCommand! Get both the output & the exitcode of a command with a single line of code, TD There is a better RunCommand function in the Process UDF with many more options & functions However if you still wish to use the old one, here is the code:1 point -
Got it finally Credits to Lazycat for the idea #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $hGUI = GUICreate('Main GUI', 300, 300, 300, 300) $hGUI_Child = GUICreate('#2', 150, 100,100,100,-1,BitOr($WS_EX_MDICHILD,$WS_EX_TOPMOST),$hGUI) GUISetBkColor(0xffffff) GUISetState(@SW_SHOW, $hGUI) GUISetState(@SW_SHOW, $hGUI_Child) GUIRegisterMsg($WM_WINDOWPOSCHANGING, "MY_WM_WINDOWPOSCHANGING") Global $nGap = 10, $size = WinGetClientSize($hGUI) While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func MY_WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam) If $hWnd = $hGUI_Child Then Local $pos = WinGetPos($hGUI) Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam) Local $border = ($pos[2] - $size[1]) ;/ 2 Local $nLeft = $pos[0] + $border Local $nTop = $pos[1] + $pos[3] - $size[1] - $border Local $nRight = $pos[0] + $pos[2] - $border - DllStructGetData($stWinPos, 5) Local $nBottom = $pos[1] + $pos[3] - $border - DllStructGetData($stWinPos, 6) Local $wLeft = DllStructGetData($stWinPos, 3) Local $wTop = DllStructGetData($stWinPos, 4) If $wLeft < $nLeft Or Abs($nLeft - $wLeft) < $nGap Then DllStructSetData($stWinPos, 3, $nLeft) If $wTop < $nTop Or Abs($nTop - $wTop) < $nGap Then DllStructSetData($stWinPos, 4, $nTop) If $wLeft > $nRight Or Abs($nRight - $wLeft) < $nGap Then DllStructSetData($stWinPos, 3, $nRight) If $wTop > $nBottom Or Abs($nBottom - $wTop) < $nGap Then DllStructSetData($stWinPos, 4, $nBottom) EndIf Return 'GUI_RUNDEFMSG' EndFunc1 point
-
Windows 10 - How To
jvanegmond reacted to JohnOne for a topic
Anyone know how to disable web searching in the windows search? I've tried group policy as per here but I still get results from web, even after forcing update EDIT: Never mind, I missed a big settings icon at the side of the actual search window wherein there is a setting to turn it off. Duh!1 point -
And another one joined. Cool. I'd say I'll be finished setting things up by next weekend (7+ Aug.). I'll send a message to everyone when we're ready to go.1 point
-
1 point
-
I would have made that @ComSpec in stead of cmd. Jos1 point
-
1 point