| 289 | } |
| 290 | |
| 291 | private static void read(ElfByteChannel bc, ByteBuffer bb, int sz, long offset) |
| 292 | throws IOException { |
| 293 | bb.position(0); |
| 294 | bb.limit(sz); |
| 295 | |
| 296 | while (bb.remaining() > 0) { |
| 297 | int numBytesRead = bc.read(bb, offset); |
| 298 | if (numBytesRead == -1) { |
| 299 | break; // Reached end of channel |
| 300 | } |
| 301 | offset += numBytesRead; |
| 302 | } |
| 303 | |
| 304 | if (bb.remaining() > 0) { |
| 305 | throw new ElfError("ELF file truncated"); |
| 306 | } |
| 307 | |
| 308 | bb.position(0); |
| 309 | } |
| 310 | |
| 311 | private static long get64(ElfByteChannel bc, ByteBuffer bb, long offset) throws IOException { |
| 312 | read(bc, bb, 8, offset); |