Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pad runtime to multiple of 512 bytes #602

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/build-runtime.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,20 @@ HEXOFFSET=$(objdump -h runtime | grep .upd_info | awk '{print $6}')
HEXLENGTH=$(objdump -h runtime | grep .upd_info | awk '{print $3}')
dd bs=1 if=runtime skip=$(($(echo 0x$HEXOFFSET)+0)) count=$(($(echo 0x$HEXLENGTH)+0)) | xxd

APPIMAGEOFFSET=$(./runtime --appimage-offset)

# Insert AppImage magic bytes
printf '\x41\x49\x02' | dd of=runtime bs=1 seek=8 count=3 conv=notrunc

# Pad runtime to multiple of 512bytes
dd if=/dev/null of=runtime bs=1 count=1 seek=$APPIMAGEOFFSET

# Add boot signature to runtime, this way fdisk recognize the appimage as a partitioned disk image
printf '\x55\xaa' | dd of=runtime bs=1 seek=510 count=2 conv=notrunc

# Add partition entry to runtime, this way gnome-disk-image-mounter can open it.
printf "0x%08x" $((APPIMAGEOFFSET / 512 )) | xxd -r | tac -rs. | dd of=runtime bs=1 seek=454 count=4 conv=notrunc

# Convert runtime into a data object that can be embedded into appimagetool
ld -r -b binary -o data.o runtime

Expand Down
4 changes: 3 additions & 1 deletion src/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ main (int argc, char *argv[])
sprintf(argv0_path, argv[0]);

fs_offset = get_elf_size(appimage_path);

/*It's better to keep filesystems aligned at 512bytes intervals, like sectors on a real partitioned disk*/
fs_offset = ((fs_offset-1)|511)+1;

arg=getArg(argc,argv,'-');

/* Print the help and then exit */
Expand Down