Skip to content

Commit

Permalink
Update bits-info.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
ale5000-git authored Sep 26, 2024
1 parent 8d2568f commit 97ad287
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tools/bits-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,20 @@ check_bitness_of_pe_file()
{
local _pe_header_pos _pe_header 2> /dev/null

echo 1>&2 '---'
echo 1>&2 '_"${1:?}"_'
echo '---'
echo ':_"${1:?}"_'
if test ! -e "${1:?}" || ! command -v hexdump; then
printf '%s\n' 'unknown'
return 1
fi

# More info: https://learn.microsoft.com/en-us/windows/win32/debug/pe-format

hexdump 1>&2 -v -s 0x3C -n 4 -e '/1 "%02x\n"' -- "${1:?}" | tac | tr -d '\n'
echo '---'
hexdump -v -s 0x3C -n 4 -e '/1 "%02x\n"' -- "${1:?}" | tac | tr -d '\n'
if _pe_header_pos="$(hexdump -v -s 0x3C -n 4 -e '/1 "%02x\n"' -- "${1:?}" | tac | tr -d '\n')" && test -n "${_pe_header_pos?}" && _pe_header_pos="0x${_pe_header_pos:?}"; then
hexdump 1>&2 -v -s "${_pe_header_pos:?}" -n 6 -e '/1 "%02x"' -- "${1:?}"
echo '---'
hexdump -v -s "${_pe_header_pos:?}" -n 6 -e '/1 "%02x"' -- "${1:?}"
if _pe_header="$(hexdump 2> /dev/null -v -s "${_pe_header_pos:?}" -n 6 -e '/1 "%02x"' -- "${1:?}")" && printf '%s\n' "${_pe_header?}" | grep -m 1 -q -e '^50450000'; then
# PE header => PE (0x50 0x45) + 0x00 0x00 + Machine field
case "${_pe_header?}" in
Expand All @@ -275,6 +277,7 @@ hexdump 1>&2 -v -s "${_pe_header_pos:?}" -n 6 -e '/1 "%02x"' -- "${1:?}"
return 2
;;
esac
echo '---'
return 0
fi
fi
Expand Down Expand Up @@ -312,6 +315,7 @@ main()
shell_name="$(printf '%s\n' "${shell_info:?}" | cut -d ' ' -f '1' || true)"

echo "_${shell_exe?}_"
check_bitness_of_pe_file "${shell_exe:?}"
if test -n "${shell_exe?}" && tmp_var="$(hexdump 2> /dev/null -v -n 5 -e '/1 "%02x"' -- "${shell_exe:?}")" && test -n "${tmp_var?}" && printf '%s\n' "${tmp_var:?}" | grep -m 1 -q -e '^7f454c46'; then
# On Linux / Android
# ELF header => 0x7F + ELF (0x45 0x4C 0x46) + 0x01 for 32-bit or 0x02 for 64-bit
Expand All @@ -320,8 +324,8 @@ echo "_${shell_exe?}_"
*'01') shell_bit='32-bit ELF' ;;
*) shell_bit='unknown' ;;
esac
elif test -n "${shell_exe?}" && shell_bit="$(check_bitness_of_pe_file "${shell_exe:?}")"; then
:
#elif test -n "${shell_exe?}" && shell_bit="$(check_bitness_of_pe_file "${shell_exe:?}")"; then
#:
elif tmp_var="$(uname 2> /dev/null -m)"; then
case "${tmp_var?}" in
x86_64 | ia64 | arm64 | aarch64 | mips64) shell_bit='64-bit' ;;
Expand Down

0 comments on commit 97ad287

Please sign in to comment.