Skip to content

Commit c6e42e7

Browse files
authored
Merge pull request #3 from Samueru-sama/main
add POSIX script to get offset of AppImage
2 parents b1fdcc3 + b1702dc commit c6e42e7

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

get_appimage_offset

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/sh
2+
3+
export LC_ALL=C
4+
offset="$(od -An -vtx1 -N 64 -- "$1" | awk '
5+
BEGIN {
6+
for (i = 0; i < 16; i++) {
7+
c = sprintf("%x", i)
8+
H[c] = i
9+
H[toupper(c)] = i
10+
}
11+
}
12+
{
13+
elfHeader = elfHeader " " $0
14+
}
15+
END {
16+
$0 = toupper(elfHeader)
17+
if ($5 == "02") is64 = 1; else is64 = 0
18+
if ($6 == "02") isBE = 1; else isBE = 0
19+
if (is64) {
20+
if (isBE) {
21+
shoff = $41 $42 $43 $44 $45 $46 $47 $48
22+
shentsize = $59 $60
23+
shnum = $61 $62
24+
} else {
25+
shoff = $48 $47 $46 $45 $44 $43 $42 $41
26+
shentsize = $60 $59
27+
shnum = $62 $61
28+
}
29+
} else {
30+
if (isBE) {
31+
shoff = $33 $34 $35 $36
32+
shentsize = $47 $48
33+
shnum = $49 $50
34+
} else {
35+
shoff = $36 $35 $34 $33
36+
shentsize = $48 $47
37+
shnum = $50 $49
38+
}
39+
}
40+
print parsehex(shoff) + parsehex(shentsize) * parsehex(shnum)
41+
}
42+
function parsehex(v, i, r) {
43+
r = 0
44+
for (i = 1; i <= length(v); i++)
45+
r = r * 16 + H[substr(v, i, 1)]
46+
return r
47+
}'
48+
)"
49+
50+
if [ -n "$offset" ]; then
51+
echo "$offset"
52+
else
53+
exit 1
54+
fi

make-appimage.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,12 @@ quick-sharun /usr/bin/gearlever \
3939
sed -i '/^pkgdatadir/c\pkgdatadir = os.getenv("SHARUN_DIR", "/usr") + "/share/gearlever"' ./AppDir/bin/gearlever
4040
sed -i '/^localedir/c\localedir = os.getenv("SHARUN_DIR", "/usr") + "/share/locale"' ./AppDir/bin/gearlever
4141

42+
# Gear lever uses a bash script to get offset that depends on readelf
43+
# Replace it for a POSIX alternative that does not need bash
44+
cp -v ./get_appimage_offset ./AppDir/lib/gearlever
45+
chmod +x ./AppDir/lib/gearlever/get_appimage_offset
46+
rm -f ./AppDir/bin/get_appimage_offset
47+
4248
# Turn AppDir into AppImage
4349
quick-sharun --make-appimage
50+

0 commit comments

Comments
 (0)