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

The following examples show how to use com.sun.jna.Pointer#getInt() . 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 6 votes vote down vote up
private int select(int nfds, Pointer checkfds, Pointer clearfds) {
    int count = 0;
    for (int i = 0; i < nfds; i++) {
        int mask = checkfds.getInt(i / 32);
        if(((mask >> i) & 1) == 1) {
            count++;
        }
    }
    if (count > 0) {
        if (clearfds != null) {
            for (int i = 0; i < nfds; i++) {
                clearfds.setInt(i / 32, 0);
            }
        }
    }
    return count;
}
 
Example 2
Source File: UdpSocket.java    From unidbg with Apache License 2.0 6 votes vote down vote up
@Override
public int sendto(byte[] data, int flags, Pointer dest_addr, int addrlen) {
    if (addrlen != 16) {
        throw new IllegalStateException("addrlen=" + addrlen);
    }

    if (log.isDebugEnabled()) {
        byte[] addr = dest_addr.getByteArray(0, addrlen);
        Inspector.inspect(addr, "addr");
    }

    int sa_family = dest_addr.getInt(0);
    if (sa_family != AF_INET) {
        throw new AbstractMethodError("sa_family=" + sa_family);
    }

    try {
        InetAddress address = InetAddress.getByAddress(dest_addr.getByteArray(4, 4));
        throw new UnsupportedOperationException("address=" + address);
    } catch (IOException e) {
        log.debug("sendto failed", e);
        emulator.getMemory().setErrno(UnixEmulator.EACCES);
        return -1;
    }
}
 
Example 3
Source File: ARM32SyscallHandler.java    From unidbg with Apache License 2.0 6 votes vote down vote up
private int clone(Unicorn u, Emulator<?> emulator) {
    Arm32RegisterContext context = emulator.getContext();
    Pointer child_stack = context.getPointerArg(1);
    if (child_stack == null &&
            context.getPointerArg(2) == null) {
        // http://androidxref.com/6.0.1_r10/xref/bionic/libc/bionic/fork.cpp#47
        return fork(emulator); // vfork
    }

    int fn = context.getR5Int();
    int arg = context.getR6Int();
    if (child_stack != null && child_stack.getInt(-4) == fn && child_stack.getInt(-8) == arg) {
        // http://androidxref.com/6.0.1_r10/xref/bionic/libc/arch-arm/bionic/__bionic_clone.S#49
        return bionic_clone(u, emulator);
    } else {
        return pthread_clone(u, emulator);
    }
}
 
Example 4
Source File: ARM32SyscallHandler.java    From unidbg with Apache License 2.0 6 votes vote down vote up
private int select(int nfds, Pointer checkfds, Pointer clearfds) {
    int count = 0;
    for (int i = 0; i < nfds; i++) {
        int mask = checkfds.getInt(i / 32);
        if(((mask >> i) & 1) == 1) {
            count++;
        }
    }
    if (count > 0) {
        if (clearfds != null) {
            for (int i = 0; i < nfds; i++) {
                clearfds.setInt(i / 32, 0);
            }
        }
    }
    return count;
}
 
Example 5
Source File: ARM32SyscallHandler.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private int nanosleep(Emulator<?> emulator) {
    Arm32RegisterContext context = emulator.getContext();
    Pointer req = context.getR0Pointer();
    Pointer rem = context.getR1Pointer();
    int tv_sec = req.getInt(0);
    int tv_nsec = req.getInt(4);
    if (log.isDebugEnabled()) {
        log.debug("nanosleep req=" + req + ", rem=" + rem + ", tv_sec=" + tv_sec + ", tv_nsec=" + tv_nsec);
    }
    try {
        java.lang.Thread.sleep(tv_sec * 1000L + tv_nsec / 1000000L);
    } catch (InterruptedException ignored) {
    }
    return 0;
}
 
Example 6
Source File: Face3DAngle.java    From arcface with MIT License 5 votes vote down vote up
private void initData() {
	if (!inited) {
		rolls = new float[num];
		Pointer pointer = roll.getPointer();
		for (int i = 0; i < rolls.length; i++) {
			rolls[i] = pointer.getFloat(4 * i);// 浮点型,4字节
		}

		yaws = new float[num];
		pointer = yaw.getPointer();
		for (int i = 0; i < yaws.length; i++) {
			yaws[i] = pointer.getFloat(4 * i);// 浮点型,4字节
		}

		pitchs = new float[num];
		pointer = pitch.getPointer();
		for (int i = 0; i < pitchs.length; i++) {
			pitchs[i] = pointer.getFloat(4 * i);// 浮点型,4字节
		}

		statuses = new int[num];
		pointer = status.getPointer();
		for (int i = 0; i < statuses.length; i++) {
			statuses[i] = pointer.getInt(4 * i);// 整型,4字节
		}
	}
}
 
Example 7
Source File: AgeInfo.java    From arcface with MIT License 5 votes vote down vote up
public int[] getAges() {
	if (ages == null) {
		ages = new int[num];
		Pointer pointer = ageArray.getPointer();
		for (int i = 0; i < ages.length; i++) {
			ages[i] = pointer.getInt(4 * i);// 整形,4字节
		}
	}
	return ages;
}
 
Example 8
Source File: GenderInfo.java    From arcface with MIT License 5 votes vote down vote up
public int[] getGenders() {
	if (genders == null) {
		genders = new int[num];
		Pointer pointer = genderArray.getPointer();
		for (int i = 0; i < genders.length; i++) {
			genders[i] = pointer.getInt(4 * i);// 整形,4字节
		}
	}
	return genders;
}
 
Example 9
Source File: ARM64SyscallHandler.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private long pipe(Emulator<?> emulator) {
    RegisterContext context = emulator.getContext();
    Pointer pipefd = context.getPointerArg(0);
    if (log.isDebugEnabled()) {
        int readfd = pipefd.getInt(0);
        int writefd = pipefd.getInt(4);
        log.debug("pipe readfd=" + readfd + ", writefd=" + writefd);
    }
    emulator.getMemory().setErrno(UnixEmulator.EFAULT);
    return -1;
}
 
Example 10
Source File: WinNT.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initialize a TOKEN_PRIVILEGES instance from initialized memory.
 *
 * @param p p
 */
public TOKEN_PRIVILEGES(Pointer p) {
    super(p);
    int count = p.getInt(0);
    PrivilegeCount = new DWORD(count);
    Privileges = new LUID_AND_ATTRIBUTES[count];
    read();
}
 
Example 11
Source File: ARM32SyscallHandler.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private int futex(Unicorn u, Emulator<?> emulator) {
    Pointer uaddr = UnicornPointer.register(emulator, ArmConst.UC_ARM_REG_R0);
    int futex_op = ((Number) u.reg_read(ArmConst.UC_ARM_REG_R1)).intValue();
    int val = ((Number) u.reg_read(ArmConst.UC_ARM_REG_R2)).intValue();
    int old = uaddr.getInt(0);
    if (log.isDebugEnabled()) {
        log.debug("futex uaddr=" + uaddr + ", _futexop=" + futex_op + ", op=" + (futex_op & 0x7f) + ", val=" + val + ", old=" + old);
    }

    switch (futex_op & 0x7f) {
        case FUTEX_WAIT:
            if (old != val) {
                throw new IllegalStateException("old=" + old + ", val=" + val);
            }
            Pointer timeout = UnicornPointer.register(emulator, ArmConst.UC_ARM_REG_R3);
            int mytype = val & 0xc000;
            int shared = val & 0x2000;
            if (log.isDebugEnabled()) {
                log.debug("futex FUTEX_WAIT mytype=" + mytype + ", shared=" + shared + ", timeout=" + timeout + ", test=" + (mytype | shared));
            }
            uaddr.setInt(0, mytype | shared);
            return 0;
        case FUTEX_WAKE:
            return 0;
        default:
            throw new AbstractMethodError();
    }
}
 
Example 12
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;
}
 
Example 13
Source File: ARM32SyscallHandler.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private int pipe(Emulator<?> emulator) {
    Pointer pipefd = UnicornPointer.register(emulator, ArmConst.UC_ARM_REG_R0);
    if (log.isDebugEnabled()) {
        int readfd = pipefd.getInt(0);
        int writefd = pipefd.getInt(4);
        log.debug("pipe readfd=" + readfd + ", writefd=" + writefd);
    }
    emulator.getMemory().setErrno(UnixEmulator.EFAULT);
    return -1;
}
 
Example 14
Source File: ARM64SyscallHandler.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private int futex(Unicorn u, Emulator<?> emulator) {
    Pointer uaddr = UnicornPointer.register(emulator, Arm64Const.UC_ARM64_REG_X0);
    int futex_op = ((Number) u.reg_read(Arm64Const.UC_ARM64_REG_X1)).intValue();
    int val = ((Number) u.reg_read(Arm64Const.UC_ARM64_REG_X2)).intValue();
    int old = uaddr.getInt(0);
    if (log.isDebugEnabled()) {
        log.debug("futex uaddr=" + uaddr + ", _futexop=" + futex_op + ", op=" + (futex_op & 0x7f) + ", val=" + val + ", old=" + old);
    }

    switch (futex_op & 0x7f) {
        case FUTEX_WAIT:
            if (old != val) {
                throw new IllegalStateException("old=" + old + ", val=" + val);
            }
            Pointer timeout = UnicornPointer.register(emulator, Arm64Const.UC_ARM64_REG_X3);
            int mytype = val & 0xc000;
            int shared = val & 0x2000;
            if (log.isDebugEnabled()) {
                log.debug("futex FUTEX_WAIT mytype=" + mytype + ", shared=" + shared + ", timeout=" + timeout + ", test=" + (mytype | shared));
            }
            uaddr.setInt(0, mytype | shared);
            return 0;
        case FUTEX_WAKE:
            return 0;
        default:
            throw new AbstractMethodError();
    }
}
 
Example 15
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 16
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 17
Source File: MacNetworkProxy.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Converts CFNumber to int.
 * 
 * @param cfNumberPointer pointer to CFNumber object
 * @return int from CFNumber
 */
private int getIntFromCFNumberRef(Pointer cfNumberPointer) {
    if (cfNumberPointer != null) {
        Pointer cfNumberType = cfLibrary.CFNumberGetType(cfNumberPointer);
        
        long numberSize = cfLibrary.CFNumberGetByteSize(cfNumberPointer);
        Pointer numberValue = new Memory(numberSize);
        if (cfLibrary.CFNumberGetValue(cfNumberPointer, cfNumberType, numberValue)) {
            return numberValue.getInt(0L);
        }
    }
    
    return 0;
}
 
Example 18
Source File: SizeTByReference.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public SizeT getValue() {
  Pointer p = getPointer();
  return new SizeT(Native.SIZE_T_SIZE == 8 ? p.getLong(0) : p.getInt(0));
}
 
Example 19
Source File: SocketIO.java    From unidbg with Apache License 2.0 4 votes vote down vote up
@Override
public int setsockopt(int level, int optname, Pointer optval, int optlen) {
    try {
        switch (level) {
            case SOL_SOCKET:
                switch (optname) {
                    case SO_REUSEADDR:
                        if (optlen != 4) {
                            throw new IllegalStateException("optlen=" + optlen);
                        }
                        setReuseAddress(optval.getInt(0));
                        return 0;
                    case SO_BROADCAST:
                        if (optlen != 4) {
                            throw new IllegalStateException("optlen=" + optlen);
                        }
                        optval.getInt(0); // broadcast_pings
                        return 0;
                    case SO_RCVBUF:
                        if (optlen != 4) {
                            throw new IllegalStateException("optlen=" + optlen);
                        }
                        setSocketRecvBuf(optval.getInt(0));
                        return 0;
                    case SO_KEEPALIVE:
                        if (optlen != 4) {
                            throw new IllegalStateException("optlen=" + optlen);
                        }
                        setKeepAlive(optval.getInt(0));
                        return 0;
                    case SO_RCVTIMEO:
                    case SO_SNDTIMEO: {
                        return 0;
                    }
                }
                break;
            case IPPROTO_TCP:
                switch (optname) {
                    case TCP_NODELAY:
                        if (optlen != 4) {
                            throw new IllegalStateException("optlen=" + optlen);
                        }
                        setTcpNoDelay(optval.getInt(0));
                        return 0;
                    case TCP_MAXSEG:
                        if (optlen != 4) {
                            throw new IllegalStateException("optlen=" + optlen);
                        }
                        log.debug("setsockopt TCP_MAXSEG=" + optval.getInt(0));
                        return 0;
                }
                break;
            case IPPROTO_IP:
                return 0;
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }

    log.warn("setsockopt level=" + level + ", optname=" + optname + ", optval=" + optval + ", optlen=" + optlen);
    return 0;
}
 
Example 20
Source File: SocketIO.java    From unidbg with Apache License 2.0 4 votes vote down vote up
@Override
public int setsockopt(int level, int optname, Pointer optval, int optlen) {
    try {
        switch (level) {
            case SOL_SOCKET:
                switch (optname) {
                    case SO_REUSEADDR:
                        if (optlen != 4) {
                            throw new IllegalStateException("optlen=" + optlen);
                        }
                        setReuseAddress(optval.getInt(0));
                        return 0;
                    case SO_BROADCAST:
                        if (optlen != 4) {
                            throw new IllegalStateException("optlen=" + optlen);
                        }
                        optval.getInt(0); // broadcast_pings
                        return 0;
                    case SO_RCVBUF:
                        if (optlen != 4) {
                            throw new IllegalStateException("optlen=" + optlen);
                        }
                        setSocketRecvBuf(optval.getInt(0));
                        return 0;
                    case SO_KEEPALIVE:
                        if (optlen != 4) {
                            throw new IllegalStateException("optlen=" + optlen);
                        }
                        setKeepAlive(optval.getInt(0));
                        return 0;
                    case SO_RCVTIMEO:
                    case SO_SNDTIMEO: {
                        return 0;
                    }
                }
                break;
            case IPPROTO_TCP:
                switch (optname) {
                    case TCP_NODELAY:
                        if (optlen != 4) {
                            throw new IllegalStateException("optlen=" + optlen);
                        }
                        setTcpNoDelay(optval.getInt(0));
                        return 0;
                    case TCP_MAXSEG:
                        if (optlen != 4) {
                            throw new IllegalStateException("optlen=" + optlen);
                        }
                        log.debug("setsockopt TCP_MAXSEG=" + optval.getInt(0));
                        return 0;
                }
                break;
            case IPPROTO_IP:
                return 0;
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }

    log.warn("setsockopt level=" + level + ", optname=" + optname + ", optval=" + optval + ", optlen=" + optlen);
    return 0;
}