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

The following examples show how to use com.sun.jna.Pointer#setString() . 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
protected int uname(Emulator<?> emulator) {
    RegisterContext context = emulator.getContext();
    Pointer buf = context.getPointerArg(0);
    if (log.isDebugEnabled()) {
        log.debug("uname buf=" + buf);
    }

    final int SYS_NMLN = 65;

    Pointer sysName = buf.share(0);
    sysName.setString(0, "Linux"); /* Operating system name (e.g., "Linux") */

    Pointer nodeName = sysName.share(SYS_NMLN);
    nodeName.setString(0, "localhost"); /* Name within "some implementation-defined network" */

    Pointer release = nodeName.share(SYS_NMLN);
    release.setString(0, "1.0.0-unidbg"); /* Operating system release (e.g., "2.6.28") */

    Pointer version = release.share(SYS_NMLN);
    version.setString(0, "#1 SMP PREEMPT Thu Apr 19 14:36:58 CST 2018"); /* Operating system version */

    Pointer machine = version.share(SYS_NMLN);
    machine.setString(0, "arm64-v8a"); /* Hardware identifier */

    Pointer domainName = machine.share(SYS_NMLN);
    domainName.setString(0, ""); /* NIS or YP domain name */

    return 0;
}
 
Example 2
Source File: ARM32SyscallHandler.java    From unidbg with Apache License 2.0 5 votes vote down vote up
protected int uname(Emulator<?> emulator) {
    Pointer buf = UnicornPointer.register(emulator, ArmConst.UC_ARM_REG_R0);
    if (log.isDebugEnabled()) {
        log.debug("uname buf=" + buf);
    }

    final int SYS_NMLN = 65;

    Pointer sysname = buf.share(0);
    sysname.setString(0, "Linux");

    Pointer nodename = sysname.share(SYS_NMLN);
    nodename.setString(0, "localhost");

    Pointer release = nodename.share(SYS_NMLN);
    release.setString(0, "1.0.0-unidbg");

    Pointer version = release.share(SYS_NMLN);
    version.setString(0, "#1 SMP PREEMPT Thu Apr 19 14:36:58 CST 2018");

    Pointer machine = version.share(SYS_NMLN);
    machine.setString(0, "armv7l");

    Pointer domainname = machine.share(SYS_NMLN);
    domainname.setString(0, "");

    return 0;
}
 
Example 3
Source File: MyARMSyscallHandler.java    From unidbg with Apache License 2.0 5 votes vote down vote up
@Override
protected int readlink(Emulator<?> emulator, String path, Pointer buf, int bufSize) {
    int pid = emulator.getPid();
    int attachPid = pid - 1;
    if (("/proc/" + pid + "/exe").equals(path) || ("/proc/" + attachPid + "/exe").equals(path)) {
        String newPath = "/system/bin/android_server_7.4\n";
        buf.setString(0, newPath);
        System.out.println("readlink: path=" + path + ", newPath=" + newPath);
        return newPath.length();
    }

    System.out.println("readlink: path=" + path);
    return super.readlink(emulator, path, buf, bufSize);
}
 
Example 4
Source File: MyARM64SyscallHandler.java    From unidbg with Apache License 2.0 5 votes vote down vote up
@Override
protected int readlink(Emulator<?> emulator, String path, Pointer buf, int bufSize) {
    int pid = emulator.getPid();
    int attachPid = pid - 1;
    if (("/proc/" + pid + "/exe").equals(path) || ("/proc/" + attachPid + "/exe").equals(path)) {
        String newPath = "/system/bin/android_server64_7.4\0";
        buf.setString(0, newPath);
        System.out.println("readlink: path=" + path + ", newPath=" + newPath);
        return newPath.length();
    }

    System.out.println("readlink: path=" + path);
    return super.readlink(emulator, path, buf, bufSize);
}
 
Example 5
Source File: UnixSyscallHandler.java    From unidbg with Apache License 2.0 5 votes vote down vote up
protected int readlink(Emulator<?> emulator, String path, Pointer buf, int bufSize) {
    if (log.isDebugEnabled()) {
        log.debug("readlink path=" + path + ", buf=" + buf + ", bufSize=" + bufSize);
    }
    buf.setString(0, path);
    return path.length() + 1;
}
 
Example 6
Source File: ARM64SyscallHandler.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private int readlink(Emulator<?> emulator) {
    RegisterContext context = emulator.getContext();
    Pointer pathname = context.getPointerArg(0);
    Pointer buf = context.getPointerArg(1);
    int bufSize = context.getIntArg(2);
    String path = pathname.getString(0);
    if (log.isDebugEnabled()) {
        log.debug("readlink path=" + path + ", buf=" + buf + ", bufSize=" + bufSize);
    }
    if ("/var/db/timezone/localtime".equals(path)) { // 设置时区
        path = "/var/db/timezone/zoneinfo/Asia/Shanghai";
    }
    buf.setString(0, path);
    return path.length() + 1;
}
 
Example 7
Source File: FishHook.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private Pointer createRebinding(String symbol, ReplaceCallback callback, boolean enablePostCall) {
    Memory memory = emulator.getMemory();
    Pointer symbolPointer = memory.malloc(symbol.length() + 1, false).getPointer();
    symbolPointer.setString(0, symbol);

    final Pointer originCall = memory.malloc(emulator.getPointerSize(), false).getPointer();
    Pointer replaceCall = createReplacePointer(callback, originCall, enablePostCall);

    Pointer rebinding = memory.malloc(emulator.getPointerSize() * 3, false).getPointer();
    rebinding.setPointer(0, symbolPointer);
    rebinding.setPointer(emulator.getPointerSize(), replaceCall);
    rebinding.setPointer(2 * emulator.getPointerSize(), originCall);
    return rebinding;
}
 
Example 8
Source File: ARM32SyscallHandler.java    From unidbg with Apache License 2.0 5 votes vote down vote up
private int readlink(Unicorn u, Emulator<?> emulator) {
    Pointer pathname = UnicornPointer.register(emulator, ArmConst.UC_ARM_REG_R0);
    Pointer buf = UnicornPointer.register(emulator, ArmConst.UC_ARM_REG_R1);
    int bufSize = ((Number) u.reg_read(ArmConst.UC_ARM_REG_R2)).intValue();
    String path = pathname.getString(0);
    if (log.isDebugEnabled()) {
        log.debug("readlink path=" + path + ", buf=" + buf + ", bufSize=" + bufSize);
    }
    if ("/var/db/timezone/localtime".equals(path)) { // 设置时区
        path = "/var/db/timezone/zoneinfo/Asia/Shanghai";
    }
    buf.setString(0, path);
    return path.length() + 1;
}
 
Example 9
Source File: JNAUtils.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a {@link Pointer} to be used for {@code char*} parameters of C/C++ functions/methods.
 * <p/>
 * NOTE Assumes ascii-only string
 */
public static Pointer toCharPointer (final String str)
{
    final Pointer pointer = new Memory(str.length() + 1);
    pointer.setString(0, str);
    return pointer;
}