private String readLine(int fd, long addr, String prefix) throws IOException { if(LOGGER.isLoggable(FINEST)) LOGGER.finest("Reading "+prefix+" at "+addr); Memory m = new Memory(1); byte ch = 1; ByteArrayOutputStream buf = new ByteArrayOutputStream(); int i = 0; while(true) { if (i++ > LINE_LENGTH_LIMIT) { LOGGER.finest("could not find end of line, giving up"); throw new IOException("could not find end of line, giving up"); } LIBC.pread(fd, m, new NativeLong(1), new NativeLong(addr)); ch = m.getByte(0); if (ch == 0) break; buf.write(ch); addr++; } String line = buf.toString(); if(LOGGER.isLoggable(FINEST)) LOGGER.finest(prefix+" was "+line); return line; } }
private String readLine(int fd, long addr, String prefix) throws IOException { if(LOGGER.isLoggable(FINEST)) LOGGER.finest("Reading "+prefix+" at "+addr); Memory m = new Memory(1); byte ch = 1; ByteArrayOutputStream buf = new ByteArrayOutputStream(); int i = 0; while(true) { if (i++ > LINE_LENGTH_LIMIT) { LOGGER.finest("could not find end of line, giving up"); throw new IOException("could not find end of line, giving up"); } long r = LIBC.pread(fd, m, new NativeLong(1), new NativeLong(addr)); ch = m.getByte(0); if (ch == 0) break; buf.write(ch); addr++; } String line = buf.toString(); if(LOGGER.isLoggable(FINEST)) LOGGER.finest(prefix+" was "+line); return line; } }
public synchronized List<String> getArguments() { if(arguments!=null) return arguments; arguments = new ArrayList<String>(argc); if (argc == 0) { return arguments; } int psize = b64 ? 8 : 4; Memory m = new Memory(psize); try { if(LOGGER.isLoggable(FINER)) LOGGER.finer("Reading "+getFile("as")); int fd = LIBC.open(getFile("as").getAbsolutePath(), 0); try { for( int n=0; n<argc; n++ ) { // read a pointer to one entry LIBC.pread(fd, m, new NativeLong(psize), new NativeLong(argp+n*psize)); long addr = b64 ? m.getLong(0) : to64(m.getInt(0)); arguments.add(readLine(fd, addr, "argv["+ n +"]")); } } finally { LIBC.close(fd); } } catch (IOException | LastErrorException e) { // failed to read. this can happen under normal circumstances (most notably permission denied) // so don't report this as an error. } arguments = Collections.unmodifiableList(arguments); return arguments; }
for( int n=0; ; n++ ) { LIBC.pread(fd, m, new NativeLong(psize), new NativeLong(envp+n*psize)); long addr = b64 ? m.getLong(0) : to64(m.getInt(0)); if (addr == 0) // completed the walk
private String readLine(int fd, long addr, String prefix) throws IOException { if(LOGGER.isLoggable(FINEST)) LOGGER.finest("Reading "+prefix+" at "+addr); Memory m = new Memory(1); byte ch = 1; ByteArrayOutputStream buf = new ByteArrayOutputStream(); int i = 0; while(true) { if (i++ > LINE_LENGTH_LIMIT) { LOGGER.finest("could not find end of line, giving up"); throw new IOException("could not find end of line, giving up"); } LIBC.pread(fd, m, new NativeLong(1), new NativeLong(addr)); ch = m.getByte(0); if (ch == 0) break; buf.write(ch); addr++; } String line = buf.toString(); if(LOGGER.isLoggable(FINEST)) LOGGER.finest(prefix+" was "+line); return line; } }
public synchronized List<String> getArguments() { if(arguments!=null) return arguments; arguments = new ArrayList<String>(argc); if (argc == 0) { return arguments; } int psize = b64 ? 8 : 4; Memory m = new Memory(psize); try { if(LOGGER.isLoggable(FINER)) LOGGER.finer("Reading "+getFile("as")); int fd = LIBC.open(getFile("as").getAbsolutePath(), 0); try { for( int n=0; n<argc; n++ ) { // read a pointer to one entry LIBC.pread(fd, m, new NativeLong(psize), new NativeLong(argp+n*psize)); long addr = b64 ? m.getLong(0) : to64(m.getInt(0)); arguments.add(readLine(fd, addr, "argv["+ n +"]")); } } finally { LIBC.close(fd); } } catch (IOException | LastErrorException e) { // failed to read. this can happen under normal circumstances (most notably permission denied) // so don't report this as an error. } arguments = Collections.unmodifiableList(arguments); return arguments; }
for( int n=0; ; n++ ) { LIBC.pread(fd, m, new NativeLong(psize), new NativeLong(envp+n*psize)); long addr = b64 ? m.getLong(0) : to64(m.getInt(0)); if (addr == 0) // completed the walk