AppImage / appimagetool

A low-level tool to generate an AppImage from an existing AppDir
58 stars 11 forks source link

Is the e_machine field not being read correctly as two bytes? #49

Closed msojocs closed 1 month ago

msojocs commented 1 month ago

x86_64 works fine, not loongarch.

x86_64

single byte.

ELF

  Offset: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F   
00000000: 7F 45 4C 46 02 01 01 00 00 00 00 00 00 00 00 00    .ELF............
00000010: 03 00 3E 00 01 00 00 00 90 97 00 00 00 00 00 00    ..>.............

RESULT

file: /tmp/appimagetool-build-MppgfA/AppDir/usr/bin/mksquashfs
e machine-------------------------->62

loongarch

0x0102 -> 258 (https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_e_machine_identifies_the_machine)

ELF

  Offset: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F   
00000000: 7F 45 4C 46 02 01 01 00 41 49 02 00 00 00 00 00    .ELF....AI......
00000010: 02 00 02 01 01 00 00 00 E4 4F 01 20 01 00 00 00    ........dO......

RESULT

file: /tmp/appimagetool-build-MppgfA/AppDir/usr/bin/mksquashfs
e machine-------------------------->2

MODIFY

I changed the read_elf_e_machine_field function to:

int16_t read_elf_e_machine_field(const gchar* file_path) {
    int16_t e_machine = 0x00;
    FILE* file = 0;
    file = fopen(file_path, "rb");
    if (file) {
        fseek(file, 0x12, SEEK_SET);
        fread(&e_machine, sizeof(e_machine), 1, file);
        fclose(file);
        e_machine = GINT16_FROM_LE(e_machine);
    }

    return e_machine;
}

and it can be identify correctly:

file: /tmp/appimagetool-build-MppgfA/AppDir/usr/bin/mksquashfs
e machine-------------------------->258
TheAssassin commented 1 month ago

Closed by #50.