| 176 | } |
| 177 | |
| 178 | bool GDREPackedSource::_get_exe_embedded_pck_info(Ref<FileAccess> f, const String &p_path, EXEPCKInfo &r_info) { |
| 179 | bool pck_header_found = false; |
| 180 | uint32_t magic = 0; |
| 181 | if (f.is_null()) { |
| 182 | return false; |
| 183 | } |
| 184 | |
| 185 | pck_header_found = p_path.get_extension().to_lower() == "exe" ? get_pck_section_info_windows(f, r_info) : get_pck_section_info_unix(f, r_info); |
| 186 | if (pck_header_found && r_info.pck_embed_off != 0) { |
| 187 | r_info.pck_actual_off = r_info.pck_embed_off; |
| 188 | // Search for the header, in case PCK start and section have different alignment. |
| 189 | for (int i = 0; i < 8; i++) { |
| 190 | f->seek(r_info.pck_actual_off); |
| 191 | |
| 192 | magic = f->get_32(); |
| 193 | if (magic == PACK_HEADER_MAGIC) { |
| 194 | uint64_t ret_pos = f->get_position(); |
| 195 | f->seek(r_info.pck_embed_off + r_info.pck_embed_size - 4); |
| 196 | if (f->get_32() == PACK_HEADER_MAGIC) { |
| 197 | f->seek(r_info.pck_embed_off + r_info.pck_embed_size - 12); |
| 198 | r_info.pck_actual_size = f->get_64(); |
| 199 | } else { |
| 200 | WARN_PRINT("PCK header not found at the end of the embed section."); |
| 201 | r_info.pck_actual_size = r_info.pck_embed_size - i; |
| 202 | } |
| 203 | f->seek(ret_pos); |
| 204 | return true; |
| 205 | } |
| 206 | r_info.pck_actual_off++; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // Search for the header at the end of file - self contained executable. |
| 211 | { |
| 212 | f->seek_end(); |
| 213 | f->seek(f->get_position() - 4); |
| 214 | magic = f->get_32(); |
| 215 | |
| 216 | if (magic == PACK_HEADER_MAGIC) { |
| 217 | f->seek(f->get_position() - 12); |
| 218 | r_info.pck_actual_size = f->get_64(); |
| 219 | r_info.pck_embed_size = r_info.pck_actual_size + 12; // pck_size + magic at the end |
| 220 | f->seek(f->get_position() - r_info.pck_actual_size - 8); |
| 221 | r_info.pck_embed_off = f->get_position(); |
| 222 | r_info.pck_actual_off = r_info.pck_embed_off; |
| 223 | magic = f->get_32(); |
| 224 | if (magic == PACK_HEADER_MAGIC) { |
| 225 | return true; |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | r_info.pck_actual_off = 0; |
| 230 | r_info.pck_actual_size = 0; |
| 231 | return false; |
| 232 | } |
| 233 | |
| 234 | bool GDREPackedSource::seek_offset_from_exe(Ref<FileAccess> f, const String &p_path, uint64_t &r_pck_size) { |
| 235 | EXEPCKInfo info; |
nothing calls this directly
no test coverage detected