Skip to content

Instantly share code, notes, and snippets.

@y-ack
Created April 14, 2018 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y-ack/a9a3bac9363f8fc9e84e463dbfd4469e to your computer and use it in GitHub Desktop.
Save y-ack/a9a3bac9363f8fc9e84e463dbfd4469e to your computer and use it in GitHub Desktop.
script everyday
#PowerShell: convert strings copied as integers back to byte-characters
function convertchars([uint32]$a){return [bitconverter]::GetBytes([uint32]$a) | %{[char]$_}}
#Powershell: lookup function for ISE editor quick analysis of functions
enum Language
{
dcc
smilebasic = 1
sb = 1
python
}
function lookup
{
param(
[Parameter(Position=0,ValueFromPipeline=$True)][alias("n")][String]$function,
[Parameter(Position=1)][Language]$language
)
# Find calls:
$DefinitionRegex = Get-LanguageDefinition $language
$CallRegex = Get-LanguageCall $language
$CurrentText = $psISE.CurrentFile.Editor.Text
$FunctionCalls = $CallRegex.Matches($CurrentText)
# Output:
Write-Host "$function Analysis:" -ForegroundColor Magenta
if ($FunctionCalls.Count -eq 0)
{
Write-Host "Never called (directly)" -ForegroundColor Red
} else
{
$FunctionCalls | ForEach-Object {
Write-Host $_.Index": " -NoNewline -ForegroundColor White
Write-Host $_.Value -ForegroundColor Cyan
For ($i = $_.Index; $i -gt ($_.Index - 2200); $i = $i - 80)
{
$DidIGetAGood = $DefinitionRegex.Match($CurrentText,$i, 240)
If ($DidIGetAGood.Success)
{
break;
}
}
if ($DidIGetAGood.Success)
{
Write-Host "`t|- in" $DidIGetAGood.Value -ForegroundColor DarkCyan
}
}
}
}
function Get-LanguageDefinition
{
param([Language]$Language)
switch ($Language)
{
dcc
{
return [Regex]::new("(\S)+\s__fastcall\s([_A-Za-z][_A-Za-z0-9]*)(.*)")
}
smilebasic
{
return [Regex]::new("(COMMON)?\s[Dd][Ee][Ff]\s([_A-Za-z][_A-Za-z0-9]*)(.*)")
}
python
{
return [Regex]::new("[Dd][Ee][Ff]\s([_A-Za-z][_A-Za-z0-9]*)(.*)")
}
}
}
function Get-LanguageCall
{
param([Language]$Language)
switch ($Language)
{
dcc
{
return [Regex]::new("\S.*(?<!call )$function[^;\n]*")
}
smilebasic
{
return [Regex]::new("(?<![Dd[Ee]Ff] )$function[^:$]*")
}
python
{
return [Regex]::new("(?<![Dd[Ee]Ff] )$function.*")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment