Comments (3)
package com.hack.lesson5;
import com.alibaba.fastjson.support.hsf.HSFJSONUtils;
import com.github.unidbg.AndroidEmulator;
import com.github.unidbg.Emulator;
import com.github.unidbg.Module;
import com.github.unidbg.arm.HookStatus;
import com.github.unidbg.arm.backend.DynarmicFactory;
import com.github.unidbg.hook.HookContext;
import com.github.unidbg.hook.IHook;
import com.github.unidbg.hook.ReplaceCallback;
import com.github.unidbg.hook.hookzz.HookZz;
import com.github.unidbg.linux.android.AndroidEmulatorBuilder;
import com.github.unidbg.linux.android.AndroidResolver;
import com.github.unidbg.linux.android.dvm.DalvikModule;
import com.github.unidbg.linux.android.dvm.DvmObject;
import com.github.unidbg.linux.android.dvm.StringObject;
import com.github.unidbg.linux.android.dvm.VM;
import com.github.unidbg.linux.android.dvm.jni.ProxyDvmObject;
import com.github.unidbg.memory.Memory;
import com.sun.jna.Pointer;
import unicorn.Unicorn;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class MainActivity {
private final AndroidEmulator emulator;
private final VM vm;
private final Memory memory;
private final Module module;
public MainActivity(){
emulator= AndroidEmulatorBuilder.for32Bit().addBackendFactory(new DynarmicFactory(true)).build();
memory=emulator.getMemory();
memory.setLibraryResolver(new AndroidResolver(23));
vm=emulator.createDalvikVM();
DalvikModule dalvikModule=vm.loadLibrary(new File("unidbg-android/src/test/java/com/hack/lesson5/libnative-lib.so"),true);
module=dalvikModule.getModule();
vm.callJNI_OnLoad(emulator,module);
}
public void callAdd(){
DvmObject object= ProxyDvmObject.createObject(vm,this);
final int result = object.callJniMethodInt(emulator, "add(II)I", 3,2);
System.out.println("call the so add function result is ==>"+result);
}
public void hook(){
//unidbg集成了HookZz框架
HookZz hook = HookZz.getInstance(emulator);
//直接hook add函数的地址,比通过符号hook更具有“普适性”
hook.replace(module.base + 0x3DC + 1, new ReplaceCallback() {
@Override
public HookStatus onCall(Emulator<?> emulator, HookContext context, long originFunction) {
//R2和R3才是参数,R0是env,R1是object
System.out.println(String.format("R2: %d, R3: %d",context.getIntArg(2),context.getIntArg(3)));
//把第二个参数R3改成5
emulator.getBackend().reg_write(Unicorn.UC_ARM_REG_R3,5);
return super.onCall(emulator, context, originFunction);
}
@Override
public void postCall(Emulator<?> emulator, HookContext context) {
emulator.getBackend().reg_write(Unicorn.UC_ARM_REG_R0,10);
//返回值放R0,这里直接修改返回值
super.postCall(emulator, context);
}
}, true);
}
//psvm快速输入
public static void main(String[] args) {
long start = System.currentTimeMillis();
MainActivity mainActivity=new MainActivity();
System.out.println("load the vm "+(System.currentTimeMillis()-start)+"ms");
mainActivity.hook();
mainActivity.callAdd();
}
}
from unidbg.
nativelib代码如下
from unidbg.
#include <jni.h>
#include
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
extern "C"
JNIEXPORT jint JNICALL
Java_com_hack_lesson5_MainActivity_add(JNIEnv *env, jobject thiz, jint a,jint b) {
if(a<0){
a=-a;
}
if(b<0){
b=-b;
}
return a+b;
}
from unidbg.
Related Issues (20)
- 这个环境怎么补啊,android/content/pm/Signature->toChars()[C
- nativeInitialize mmap failed[dynarmic.cpp->Java_com_github_unidbg_arm_backend_dynarmic_Dynarmic_nativeInitialize:583] size=0x8000000, errno=1455, msg=Unknown error terminate called after throwing an instance of 'Xbyak::Error' what(): can't alloc
- 开始模板启动就断点是什么情况啊?求大佬解答
- so 里面ftruncate方法时会报错
- 调用so的方法后怎么释放内存?我看这些都是GCRoot,调用次数多了直接内存吃满了
- 执行报错:Read memory failed和 Invalid memory read (UC_ERR_READ_UNMAPPED) HOT 1
- Dynarmic link in README is gone
- 有没有大佬知道java/lang/String->toCharArray()[C该怎么补啊?求解
- BackendException on CallObjectMethodV
- 大佬们,看看 这种怎么补啊 "android/os/Parcel->setDataPosition(I)V"
- libopenjdk.so
- 需要api文档 HOT 1
- 最新版代码32位好像不支持Unicorn2Factory?
- dump模拟执行时候发现的错误
- 怎么重写读取目录下所有文件的io
- 调用问题
- 运行报错DalvikVM64$128.handle,怎么解决呀
- 小白的第一个unidbg
- 运行其他示例正常,运行anjuke示例报错了,用了unidbg-0.9.7 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unidbg.