Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ######################################################################
- #Copyright (C) 2025 Kris Occhipinti
- #https://filmsbykris.com
- #This program is free software: you can redistribute it and/or modify
- #it under the terms of the GNU General Public License as published by
- #the Free Software Foundation version 3 of the License.
- #This program is distributed in the hope that it will be useful,
- #but WITHOUT ANY WARRANTY; without even the implied warranty of
- #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- #GNU General Public License for more details.
- #You should have received a copy of the GNU General Public License
- #along with this program. If not, see <http://www.gnu.org/licenses/>.
- ######################################################################
- # Extracts all files from an har file
- # fatal uses SIGUSR1 to allow clean fatal errors
- trap "exit 1" 10
- PROC=$$
- function error() {
- red=$(echo -en "\e[31m")
- normal=$(echo -en "\e[0m")
- echo -e "${red}$@${normal}" >&2
- # exit 1
- kill -10 $PROC
- }
- [[ $1 ]] || error "Input file needed\n$0 file.har"
- har_file="$1"
- [[ -f $har_file ]] || error "$har_file does not exist"
- output_dir="extracted_files"
- mkdir -p "$output_dir"
- cat "$har_file" | jq -cr '.log.entries[] | {url: .request.url, content: .response.content.text, encoding: .response.content.encoding}' |
- while read -r entry; do
- echo "$entry"
- url=$(echo "$entry" | jq -r '.url')
- content=$(echo "$entry" | jq -r '.content')
- encoding=$(echo "$entry" | jq -r '.encoding')
- # Simple filename based on URL (adjust as needed)
- filename=$(basename "$url" | cut -d\? -f1)
- if [ "$encoding" == "base64" ]; then
- echo "$content" | base64 -d >"$output_dir/$filename"
- else
- echo "$content" >"$output_dir/$filename"
- fi
- done
Add Comment
Please, Sign In to add comment