w6l: islinkable/isso magic-byte pyramids -> strings.hasprefix (Wave-2 str-lift)
This commit is contained in:
@@ -10,6 +10,7 @@ package main;
|
||||
|
||||
import os;
|
||||
import rt;
|
||||
import strings;
|
||||
import sym;
|
||||
import obj;
|
||||
import dyn;
|
||||
@@ -106,23 +107,12 @@ fn islinkable(path: *u8) bool = {
|
||||
let n: i64 = os.read(fd, &mp[0], 8u64);
|
||||
os.close(fd);
|
||||
if (n < 4i64) { return false; };
|
||||
// archive: "!<arch>\n"
|
||||
if (n >= 8i64) {
|
||||
if (mp[0u64] == '!') { if (mp[1u64] == '<') {
|
||||
if (mp[2u64] == 'a') { if (mp[3u64] == 'r') {
|
||||
if (mp[4u64] == 'c') { if (mp[5u64] == 'h') {
|
||||
if (mp[6u64] == '>') { if (mp[7u64] == '\n') {
|
||||
return true;
|
||||
}; }; }; }; }; }; }; };
|
||||
};
|
||||
// ELF: "\x7fELF"
|
||||
if (mp[0u64] == 127u8) {
|
||||
if (mp[1u64] == 'E') {
|
||||
if (mp[2u64] == 'L') {
|
||||
if (mp[3u64] == 'F') { return true; };
|
||||
};
|
||||
};
|
||||
};
|
||||
// hasprefix length-bails when the header is shorter than the magic,
|
||||
// matching the old n>=8 archive guard (str len < 8 => no match).
|
||||
let hn: i32 = n: i32;
|
||||
let hdr: str = strings.frombytes(mp[0:hn]);
|
||||
if (strings.hasprefix(hdr, "!<arch>\n")) { return true; };
|
||||
if (strings.hasprefix(hdr, "\x7fELF")) { return true; };
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -176,10 +166,8 @@ fn isso(path: *u8) i32 = {
|
||||
let n: i64 = os.read(fd, &mp[0], 20u64);
|
||||
os.close(fd);
|
||||
if (n < 20i64) { return 0; };
|
||||
if (mp[0u64] != 127u8) { return 0; };
|
||||
if (mp[1u64] != 'E') { return 0; };
|
||||
if (mp[2u64] != 'L') { return 0; };
|
||||
if (mp[3u64] != 'F') { return 0; };
|
||||
let hdr: str = strings.frombytes(mp[0:4]);
|
||||
if (!strings.hasprefix(hdr, "\x7fELF")) { return 0; };
|
||||
// e_type at offset 16, u16 little-endian
|
||||
let t: u16 = (mp[16u64]: u16) | ((mp[17u64]: u16) << 8u16);
|
||||
if (t == 3u16) { return 1; };
|
||||
|
||||
Reference in New Issue
Block a user