aboutsummaryrefslogtreecommitdiff
path: root/tools/meta-rip
blob: d91195a7f2d85bd1f71077691c87defb3934db4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash

if [[ ! -f $1 ]]
then
    echo "File not found: $1"
    exit
fi

readelf -S $1 | grep -q "\.meta\.note" > /dev/null
if [ $? -ne 0 ]
then
    echo "No metadata in ELF; '.meta.note' non-existent"
    exit
fi

meta=$(objcopy $1 /dev/null --dump-section .meta.note=/dev/stdout | cat | tr -d '\0')

# Remove the leading and trailing '$' characters
meta=${meta#'$'}
meta=${meta%'$'}

# Use regular expression to extract the cookie, filename, author, and description
if [[ $meta =~ ^([^:]+):\s*([^,]+),\s*([^,]+),\s*(.*)$ ]]; then
    cookie=${BASH_REMATCH[1]}
    filename=${BASH_REMATCH[2]}
    author=${BASH_REMATCH[3]}
    description=${BASH_REMATCH[4]}
    cookie=${cookie%?}  # Remove the last character
fi

if [[ $cookie != "Vega" ]]
then
    echo "Invalid cookie found!"
    exit
fi

# Trim leading spaces
cookie=$(echo "$cookie" | sed -e 's/^[[:space:]]*//')
filename=$(echo "$filename" | sed -e 's/^[[:space:]]*//')
author=$(echo "$author" | sed -e 's/^[[:space:]]*//')
description=$(echo "$description" | sed -e 's/^[[:space:]]*//')

echo "Cookie: $cookie"
echo "Filename: $filename"
echo "Author: $author"
echo "Description: $description"