Skip to content

Commit

Permalink
Use mktemp() instead of all others
Browse files Browse the repository at this point in the history
  • Loading branch information
merces committed Nov 28, 2024
1 parent 71eed75 commit d4f8738
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/reversing/bh_replacestring.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ bh_replacestring() {
local src="$2"
local dst="$3"

local srchex=$(echo $src | xxd -pu)
local dsthex=$(echo $dst | xxd -pu)
local srchex=$(echo "$src" | xxd -pu)
local dsthex=$(echo "$dst" | xxd -pu)

local tmpfile=".$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)"
local tmpfile=$(mktemp)

xxd -p < $fil | tr -d '\n' | sed "s/${srchex::-2}/${dsthex::-2}/g" | xxd -r -p > $tmpfile
cat $tmpfile > $fil && rm -f $tmpfile
xxd -p $fil | tr -d \\n | sed "s/${srchex::-2}/${dsthex::-2}/g" | xxd -rp > $tmpfile

[[ -s $tmpfile ]] && mv $tmpfile $fil
}

0 comments on commit d4f8738

Please sign in to comment.