Skip to content

Instantly share code, notes, and snippets.

@m8r1us
Last active June 30, 2023 09:51
Show Gist options
  • Save m8r1us/69dcd19b2f3c53cd8f06d477fff0ff0a to your computer and use it in GitHub Desktop.
Save m8r1us/69dcd19b2f3c53cd8f06d477fff0ff0a to your computer and use it in GitHub Desktop.
Simple KeyCroc croc_char.log analysis script
# Author: Marius Elmiger (@m8r1us)
# Description: Simple KeyCroc croc_char.log analysis script
# Croc_char.log location
$file = "C:\tmp\croc_char.log"
$content = Get-Content $file
# Format Loot file with line breaks
$modifiedText = $content -replace '(\[[^\]]+\])', "`n`$1`n"
$modifiedText = $modifiedText -replace "`n{2,}", "`n"
$modifiedText | Out-file "$($file)-linebr.log"
# Format Loot file with line breaks and only output text
$modifiedText = $modifiedText -replace '\[[^\]]+\]', ''
$modifiedText = $modifiedText -replace "`n{2,}", "`n"
$modifiedText | Out-file "$($file)-linebr-textonly.log"
# Pattern Matching
## Split the content into individual words
$words = $content -split '\W+' | Where-Object { $_ -ne '' }
## Count the occurrences of each word
$wordCounts = $words | Group-Object | Where-Object { $_.Count -gt 1 }
## Print the words that appear multiple times
$wordCounts | ForEach-Object {
$word = $_.Name
$count = $_.Count
Write-Host "Word '$word' appears $count times"
}
## Count the occurrences of each character
$characters = $content -join '' -split '(?<=.)' | Where-Object { $_ -ne ' ' }
$charCounts = $characters | Group-Object | Where-Object { $_.Count -gt 1 }
## Print the characters that appear multiple times
$charCounts | ForEach-Object {
$character = $_.Name
$count = $_.Count
Write-Host "Character '$character' appears $count times"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment