Java Code Examples for com.sun.jna.Pointer#setShort()

The following examples show how to use com.sun.jna.Pointer#setShort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ARM64SyscallHandler.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private int ppoll(Emulator<?> emulator) {
    RegisterContext context = emulator.getContext();
    Pointer fds = context.getPointerArg(0);
    int nfds = context.getIntArg(1);
    Pointer tmo_p = context.getPointerArg(2);
    Pointer sigmask = context.getPointerArg(3);
    int count = 0;
    for (int i = 0; i < nfds; i++) {
        Pointer pollfd = fds.share(i * 8);
        int fd = pollfd.getInt(0);
        short events = pollfd.getShort(4); // requested events
        if (log.isDebugEnabled()) {
            log.debug("ppoll fds=" + fds + ", nfds=" + nfds + ", tmo_p=" + tmo_p + ", sigmask=" + sigmask + ", fd=" + fd + ", events=" + events);
        }
        if (fd < 0) {
            pollfd.setShort(6, (short) 0);
        } else {
            short revents = 0;
            if((events & POLLOUT) != 0) {
                revents = POLLOUT;
            } else if ((events & POLLIN) != 0) {
                revents = POLLIN;
            }
            pollfd.setShort(6, revents); // returned events
            count++;
        }
    }
    return count;
}
 
Example 2
Source File: ARM64SyscallHandler.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private int poll(Unicorn u, Emulator<?> emulator) {
    Pointer fds = UnicornPointer.register(emulator, ArmConst.UC_ARM_REG_R0);
    int nfds = ((Number) u.reg_read(ArmConst.UC_ARM_REG_R1)).intValue();
    int timeout = ((Number) u.reg_read(ArmConst.UC_ARM_REG_R2)).intValue();
    int count = 0;
    for (int i = 0; i < nfds; i++) {
        Pointer pollfd = fds.share(i * 8);
        int fd = pollfd.getInt(0);
        short events = pollfd.getShort(4); // requested events
        if (log.isDebugEnabled()) {
            log.debug("poll fds=" + fds + ", nfds=" + nfds + ", timeout=" + timeout + ", fd=" + fd + ", events=" + events);
        }
        if (fd < 0) {
            pollfd.setShort(6, (short) 0);
        } else {
            short revents = 0;
            if((events & POLLOUT) != 0) {
                revents = POLLOUT;
            } else if ((events & POLLIN) != 0) {
                revents = POLLIN;
            }
            pollfd.setShort(6, revents); // returned events
            count++;
        }
    }
    return count;
}
 
Example 3
Source File: ARM32SyscallHandler.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private int poll(Unicorn u, Emulator<?> emulator) {
    Pointer fds = UnicornPointer.register(emulator, ArmConst.UC_ARM_REG_R0);
    int nfds = ((Number) u.reg_read(ArmConst.UC_ARM_REG_R1)).intValue();
    int timeout = ((Number) u.reg_read(ArmConst.UC_ARM_REG_R2)).intValue();
    int count = 0;
    for (int i = 0; i < nfds; i++) {
        Pointer pollfd = fds.share(i * 8);
        int fd = pollfd.getInt(0);
        short events = pollfd.getShort(4); // requested events
        if (log.isDebugEnabled()) {
            log.debug("poll fds=" + fds + ", nfds=" + nfds + ", timeout=" + timeout + ", fd=" + fd + ", events=" + events);
        }
        if (fd < 0) {
            pollfd.setShort(6, (short) 0);
        } else {
            short revents = 0;
            if((events & POLLOUT) != 0) {
                revents = POLLOUT;
            } else if ((events & POLLIN) != 0) {
                revents = POLLIN;
            }
            pollfd.setShort(6, revents); // returned events
            count++;
        }
    }
    return count;
}