Java Code Examples for com.sun.jna.Pointer#setLong()
The following examples show how to use
com.sun.jna.Pointer#setLong() .
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 |
private int clock_gettime(Emulator<?> emulator) { RegisterContext context = emulator.getContext(); int clk_id = context.getIntArg(0); Pointer tp = context.getPointerArg(1); long offset = clk_id == CLOCK_REALTIME ? System.currentTimeMillis() * 1000000L : System.nanoTime() - nanoTime; long tv_sec = offset / 1000000000L; long tv_nsec = offset % 1000000000L; if (log.isDebugEnabled()) { log.debug("clock_gettime clk_id=" + clk_id + ", tp=" + tp + ", offset=" + offset + ", tv_sec=" + tv_sec + ", tv_nsec=" + tv_nsec); } switch (clk_id) { case CLOCK_REALTIME: case CLOCK_MONOTONIC: case CLOCK_MONOTONIC_RAW: case CLOCK_MONOTONIC_COARSE: case CLOCK_BOOTTIME: tp.setLong(0, tv_sec); tp.setLong(8, tv_nsec); return 0; } throw new UnsupportedOperationException("clk_id=" + clk_id); }
Example 2
Source File: DriverFileIO.java From unidbg with Apache License 2.0 | 6 votes |
private int androidAlarm(long dir, long c, AndroidAlarmType type, long size, long argp) { if (dir == _IOC_WRITE && c == ANDROID_ALARM_GET_TIME && type == AndroidAlarmType.ANDROID_ALARM_ELAPSED_REALTIME) { long offset = System.currentTimeMillis(); long tv_sec = offset / 1000000000L; long tv_nsec = offset % 1000000000L; Pointer pointer = UnicornPointer.pointer(emulator, argp); if (pointer == null) { throw new IllegalArgumentException(); } if (size == 8) { pointer.setInt(0, (int) tv_sec); pointer.setInt(4, (int) tv_nsec); return 0; } else if (size == 16) { pointer.setLong(0, tv_sec); pointer.setLong(8, tv_nsec); return 0; } else { throw new IllegalArgumentException("size=" + size); } } log.info("androidAlarm argp=0x" + Long.toHexString(argp) + ", c=" + c + ", type=" + type + ", size=" + size + ", dir=" + dir); return -1; }
Example 3
Source File: SimpleFileIO.java From unidbg with Apache License 2.0 | 6 votes |
@Override public int llseek(long offset, Pointer result, int whence) { try { switch (whence) { case SEEK_SET: randomAccessFile.seek(offset); result.setLong(0, randomAccessFile.getFilePointer()); return 0; case SEEK_END: randomAccessFile.seek(randomAccessFile.length() - offset); result.setLong(0, randomAccessFile.getFilePointer()); return 0; } } catch (IOException e) { throw new IllegalStateException(e); } return super.llseek(offset, result, whence); }
Example 4
Source File: Arm64Hook.java From unidbg with Apache License 2.0 | 6 votes |
@Override public final long handle(Emulator<?> emulator) { Unicorn u = emulator.getUnicorn(); Pointer sp = UnicornPointer.register(emulator, Arm64Const.UC_ARM64_REG_SP); try { HookStatus status = hook(emulator); if (status.forward || !enablePostCall) { sp = sp.share(-8); sp.setLong(0, status.jump); } else { sp = sp.share(-8); sp.setLong(0, 0); } return status.returnValue; } finally { u.reg_write(Arm64Const.UC_ARM64_REG_SP, ((UnicornPointer) sp).peer); } }
Example 5
Source File: SimpleFileIO.java From unidbg with Apache License 2.0 | 6 votes |
@Override public int llseek(long offset, Pointer result, int whence) { try { switch (whence) { case SEEK_SET: randomAccessFile.seek(offset); result.setLong(0, randomAccessFile.getFilePointer()); return 0; case SEEK_END: randomAccessFile.seek(randomAccessFile.length() - offset); result.setLong(0, randomAccessFile.getFilePointer()); return 0; } } catch (IOException e) { throw new IllegalStateException(e); } return super.llseek(offset, result, whence); }
Example 6
Source File: SizeTByReference.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void setValue(SizeT value) { Pointer p = getPointer(); if (Native.SIZE_T_SIZE == 8) { p.setLong(0, value.longValue()); } else { p.setInt(0, value.intValue()); } }
Example 7
Source File: DarwinARM64Emulator.java From unidbg with Apache License 2.0 | 5 votes |
protected void setupTraps() { super.setupTraps(); long _COMM_PAGE_MEMORY_SIZE = (MachO._COMM_PAGE64_BASE_ADDRESS+0x038); // uint64_t max memory size */ Pointer commPageMemorySize = UnicornPointer.pointer(this, _COMM_PAGE_MEMORY_SIZE); if (commPageMemorySize != null) { commPageMemorySize.setLong(0, 0); } long _COMM_PAGE_NCPUS = (MachO._COMM_PAGE64_BASE_ADDRESS+0x022); // uint8_t number of configured CPUs Pointer commPageNCpus = UnicornPointer.pointer(this, _COMM_PAGE_NCPUS); if (commPageNCpus != null) { commPageNCpus.setByte(0, (byte) 1); } long _COMM_PAGE_ACTIVE_CPUS = (MachO._COMM_PAGE64_BASE_ADDRESS+0x034); // uint8_t number of active CPUs (hw.activecpu) Pointer commPageActiveCpus = UnicornPointer.pointer(this, _COMM_PAGE_ACTIVE_CPUS); if (commPageActiveCpus != null) { commPageActiveCpus.setByte(0, (byte) 1); } long _COMM_PAGE_PHYSICAL_CPUS = (MachO._COMM_PAGE64_BASE_ADDRESS+0x035); // uint8_t number of physical CPUs (hw.physicalcpu_max) Pointer commPagePhysicalCpus = UnicornPointer.pointer(this, _COMM_PAGE_PHYSICAL_CPUS); if (commPagePhysicalCpus != null) { commPagePhysicalCpus.setByte(0, (byte) 1); } long _COMM_PAGE_LOGICAL_CPUS = (MachO._COMM_PAGE64_BASE_ADDRESS+0x036); // uint8_t number of logical CPUs (hw.logicalcpu_max) Pointer commPageLogicalCpus = UnicornPointer.pointer(this, _COMM_PAGE_LOGICAL_CPUS); if (commPageLogicalCpus != null) { commPageLogicalCpus.setByte(0, (byte) 1); } }
Example 8
Source File: DarwinARMEmulator.java From unidbg with Apache License 2.0 | 5 votes |
@Override protected void setupTraps() { super.setupTraps(); long _COMM_PAGE_MEMORY_SIZE = (MachO._COMM_PAGE32_BASE_ADDRESS+0x038); // uint64_t max memory size */ Pointer commPageMemorySize = UnicornPointer.pointer(this, _COMM_PAGE_MEMORY_SIZE); if (commPageMemorySize != null) { commPageMemorySize.setLong(0, 0); } long _COMM_PAGE_NCPUS = (MachO._COMM_PAGE32_BASE_ADDRESS+0x022); // uint8_t number of configured CPUs Pointer commPageNCpus = UnicornPointer.pointer(this, _COMM_PAGE_NCPUS); if (commPageNCpus != null) { commPageNCpus.setByte(0, (byte) 1); } long _COMM_PAGE_ACTIVE_CPUS = (MachO._COMM_PAGE32_BASE_ADDRESS+0x034); // uint8_t number of active CPUs (hw.activecpu) Pointer commPageActiveCpus = UnicornPointer.pointer(this, _COMM_PAGE_ACTIVE_CPUS); if (commPageActiveCpus != null) { commPageActiveCpus.setByte(0, (byte) 1); } long _COMM_PAGE_PHYSICAL_CPUS = (MachO._COMM_PAGE32_BASE_ADDRESS+0x035); // uint8_t number of physical CPUs (hw.physicalcpu_max) Pointer commPagePhysicalCpus = UnicornPointer.pointer(this, _COMM_PAGE_PHYSICAL_CPUS); if (commPagePhysicalCpus != null) { commPagePhysicalCpus.setByte(0, (byte) 1); } long _COMM_PAGE_LOGICAL_CPUS = (MachO._COMM_PAGE32_BASE_ADDRESS+0x036); // uint8_t number of logical CPUs (hw.logicalcpu_max) Pointer commPageLogicalCpus = UnicornPointer.pointer(this, _COMM_PAGE_LOGICAL_CPUS); if (commPageLogicalCpus != null) { commPageLogicalCpus.setByte(0, (byte) 1); } }
Example 9
Source File: ArmLD64.java From unidbg with Apache License 2.0 | 4 votes |
private long dlopen(Memory memory, String filename, Emulator<?> emulator) { Pointer pointer = UnicornPointer.register(emulator, Arm64Const.UC_ARM64_REG_SP); try { Module module = memory.dlopen(filename, false); pointer = pointer.share(-8); // return value if (module == null) { pointer.setLong(0, 0); pointer = pointer.share(-8); // NULL-terminated pointer.setLong(0, 0); if (!"libnetd_client.so".equals(filename)) { log.info("dlopen failed: " + filename); } else if(log.isDebugEnabled()) { log.debug("dlopen failed: " + filename); } this.error.setString(0, "Resolve library " + filename + " failed"); return 0; } else { pointer.setLong(0, module.base); pointer = pointer.share(-8); // NULL-terminated pointer.setLong(0, 0); for (Module md : memory.getLoadedModules()) { LinuxModule m = (LinuxModule) md; if (!m.getUnresolvedSymbol().isEmpty()) { continue; } for (InitFunction initFunction : m.initFunctionList) { if (log.isDebugEnabled()) { log.debug("[" + m.name + "]PushInitFunction: 0x" + Long.toHexString(initFunction.getAddress())); } pointer = pointer.share(-8); // init array pointer.setLong(0, initFunction.getAddress()); } m.initFunctionList.clear(); } return module.base; } } finally { unicorn.reg_write(Arm64Const.UC_ARM64_REG_SP, ((UnicornPointer) pointer).peer); } }
Example 10
Source File: MyARM64SyscallHandler.java From unidbg with Apache License 2.0 | 4 votes |
@Override protected long ptrace(Emulator<?> emulator) { RegisterContext context = emulator.getContext(); int request = context.getIntArg(0); int pid = context.getIntArg(1); UnicornPointer addr = context.getPointerArg(2); Pointer data = context.getPointerArg(3); String msg = "ptrace request=0x" + Integer.toHexString(request) + ", pid=" + pid + ", addr=" + addr + ", data=" + data + ", LR=" + context.getLRPointer(); switch (request) { case PTrace.PTRACE_ATTACH: case PTrace.PTRACE_CONT: case PTrace.PTRACE_DETACH: case PTrace.PTRACE_KILL: case PTrace.PTRACE_POKETEXT: break; case PTrace.PTRACE_POKEDATA: { addr.setPointer(0, data); break; } case PTrace.PTRACE_PEEKTEXT: { long val = addr.getLong(0); data.setLong(0, val); break; } case PTrace.PTRACE_GETREGSET: { if (addr.toUIntPeer() == PTrace.NT_PRSTATUS) { Arm64Register register = new Arm64Register(data); register.fill(emulator.getUnicorn()); register.pack(); System.out.println(register); break; } else { throw new UnsupportedOperationException(); } } /*case PTrace.PTRACE_PEEKUSR: { int off = (int) addr.toUIntPeer() / 4; int reg = ArmConst.UC_ARM_REG_INVALID; if (off == Reg32.ARM_pc) { reg = ArmConst.UC_ARM_REG_PC; } else { msg += (", off=" + off); } if (reg != ArmConst.UC_ARM_REG_INVALID) { data.setInt(0, ArmRegister.readReg(u, reg)); break; } }*/ default: System.err.println(msg); emulator.attach().debug(); return -1; } return 0; }