Skip to content

Commit

Permalink
add exp startJdwpThrad
Browse files Browse the repository at this point in the history
  • Loading branch information
axhlzy committed May 27, 2024
1 parent a80a236 commit 8a435ce
Show file tree
Hide file tree
Showing 3 changed files with 276 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Il2cppHook/agent/plugin/http.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get, IncomingMessage, request, RequestOptions } from "http"
import { get, IncomingMessage, request } from "http"

// http://v0.yiketianqi.com/api?unescape=1&version=v91&appid=43656176&appsecret=I42og6Lm&ext=&cityid=&city=%E5%B9%BF%E5%B7%9E
const httpGet = (url: string) => {
Expand Down
4 changes: 3 additions & 1 deletion Il2cppHook/agent/plugin/include.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ import "./qbdi/main-qdbi"
import "./std/_include"

// 翻译
// import "./translate/include"
// import "./translate/include"

import './jdwp/jdwp'
272 changes: 272 additions & 0 deletions Il2cppHook/agent/plugin/jdwp/jdwp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
// try {
// void *art_handle = xdl_open("libart.so", XDL_DEFAULT);
// if (art_handle == nullptr) {
// throw std::runtime_error("art_handle is nullptr");
// } else {
// LOGI("art_handle = %p", art_handle);
// }

// // _ZN3art3Dbg9StartJdwpEv | static void StartJdwp();
// auto lam_startJdwp = [&]() {
// void *sym = xdl_sym(art_handle, "_ZN3art3Dbg9StartJdwpEv", nullptr);
// LOGW("StartJdwp = %p", sym);
// if (sym != nullptr) {
// typedef void (*StartJdwp)();
// StartJdwp startJdwp = (StartJdwp)sym;
// startJdwp();
// } else {
// throw std::runtime_error("StartJdwp is nullptr");
// }
// };

const startJdwp = ()=>{
const addr = Module.findExportByName("libart.so", "_ZN3art3Dbg9StartJdwpEv")
if(addr){
const StartJdwp = new NativeFunction(addr, 'void', [])
StartJdwp()
} else {
throw new Error("StartJdwp is nullptr")
}
}

// // _ZN3art3Dbg8StopJdwpEv | static void StopJdwp();
// auto lam_stopJdwp = [&]() {
// void *sym = xdl_sym(art_handle, "_ZN3art3Dbg8StopJdwpEv", nullptr);
// LOGW("StopJdwp = %p", sym);
// if (sym != nullptr) {
// typedef void (*StopJdwp)();
// StopJdwp stopJdwp = (StopJdwp)sym;
// stopJdwp();
// } else {
// throw std::runtime_error("StopJdwp is nullptr");
// }
// };
const stopJdwp = ()=>{
const addr = Module.findExportByName("libart.so", "_ZN3art3Dbg8StopJdwpEv")
if(addr){
const StopJdwp = new NativeFunction(addr, 'void', [])
StopJdwp()
} else {
throw new Error("StopJdwp is nullptr")
}
}

// // _ZN3art3Dbg14SetJdwpAllowedEb | static void SetJdwpAllowed(bool allowed);
// auto lam_setJdwpAllowed = [&](bool allowed) {
// void *sym = xdl_sym(art_handle, "_ZN3art3Dbg14SetJdwpAllowedEb", nullptr);
// LOGW("SetJdwpAllowed = %p", sym);
// if (sym != nullptr) {
// typedef void (*SetJdwpAllowed)(bool);
// SetJdwpAllowed setJdwpAllowed = (SetJdwpAllowed)sym;
// setJdwpAllowed(allowed);
// } else {
// throw std::runtime_error("SetJdwpAllowed is nullptr");
// }
// };
const setJdwpAllowed = (allowed:boolean)=>{
const addr = Module.findExportByName("libart.so", "_ZN3art3Dbg14SetJdwpAllowedEb")
if(addr){
const SetJdwpAllowed = new NativeFunction(addr, 'void', ['int'])
SetJdwpAllowed(allowed ? 1 : 0)
} else {
throw new Error("SetJdwpAllowed is nullptr")
}
}

// // _ZN3art3Dbg13IsJdwpAllowedEv | static bool IsJdwpAllowed();
// auto lam_isJdwpAllowed = [&]() {
// void *sym = xdl_sym(art_handle, "_ZN3art3Dbg13IsJdwpAllowedEv", nullptr);
// LOGW("IsJdwpAllowed = %p", sym);
// if (sym != nullptr) {
// typedef bool (*IsJdwpAllowed)();
// IsJdwpAllowed isJdwpAllowed = (IsJdwpAllowed)sym;
// return isJdwpAllowed();
// } else {
// throw std::runtime_error("IsJdwpAllowed is nullptr");
// }
// };
const isJdwpAllowed = ()=>{
const addr = Module.findExportByName("libart.so", "_ZN3art3Dbg13IsJdwpAllowedEv")
if(addr){
const IsJdwpAllowed = new NativeFunction(addr, 'bool', [])
return IsJdwpAllowed()
} else {
throw new Error("IsJdwpAllowed is nullptr")
}
}

// // _ZN3art3Dbg12GetJdwpStateEv | static JDWP::JdwpState* GetJdwpState();
// auto lam_getJdwpState = [&]() {
// void *sym = xdl_sym(art_handle, "_ZN3art3Dbg12GetJdwpStateEv", nullptr);
// LOGW("GetJdwpState = %p", sym);
// if (sym != nullptr) {
// typedef void *(*GetJdwpState)();
// GetJdwpState getJdwpState = (GetJdwpState)sym;
// return getJdwpState();
// } else {
// throw std::runtime_error("GetJdwpState is nullptr");
// }
// };
const getJdwpState = ()=>{
const addr = Module.findExportByName("libart.so", "_ZN3art3Dbg12GetJdwpStateEv")
if(addr){
const GetJdwpState = new NativeFunction(addr, 'pointer', [])
return GetJdwpState()
} else {
throw new Error("GetJdwpState is nullptr")
}
}

// // _ZN3art3Dbg16IsJdwpConfiguredEvFUNC
// auto lam_isJdwpConfigured = [&]() {
// void *sym = xdl_sym(art_handle, "_ZN3art3Dbg16IsJdwpConfiguredEv", nullptr);
// LOGW("IsJdwpConfigured = %p", sym);
// if (sym != nullptr) {
// typedef bool (*IsJdwpConfigured)();
// IsJdwpConfigured isJdwpConfigured = (IsJdwpConfigured)sym;
// return isJdwpConfigured();
// } else {
// throw std::runtime_error("IsJdwpConfigured is nullptr");
// }
// };
const isJdwpConfigured = ()=>{
const addr = Module.findExportByName("libart.so", "_ZN3art3Dbg16IsJdwpConfiguredEv")
if(addr){
const IsJdwpConfigured = new NativeFunction(addr, 'bool', [])
return IsJdwpConfigured()
} else {
throw new Error("IsJdwpConfigured is nullptr")
}
}

// enum JdwpTransportType {
// kJdwpTransportNone = 0,
// kJdwpTransportUnknown, // Unknown tranpsort
// kJdwpTransportSocket, // transport=dt_socket
// kJdwpTransportAndroidAdb, // transport=dt_android_adb
// };
enum JdwpTransportType {
kJdwpTransportNone = 0,
kJdwpTransportUnknown = 1,
kJdwpTransportSocket = 2,
kJdwpTransportAndroidAdb = 3
}

// struct JdwpOptions {
// JdwpTransportType transport = kJdwpTransportNone;
// bool server = false;
// bool suspend = false;
// std::string host = "";
// uint16_t port = static_cast<uint16_t>(-1);
// };
class JdwpOptions {
transport = JdwpTransportType.kJdwpTransportNone
server = false
suspend = false
host = ""
port = 0

static tempMem = NULL

constructor(transport:JdwpTransportType, server:boolean, suspend:boolean, host:string, port:number){
this.transport = transport
this.server = server
this.suspend = suspend
this.host = host
this.port = port
}

public get_pointer(){
JdwpOptions.tempMem = Memory.alloc(0x4 + 0x2 + 0x2 + Process.pointerSize*3 + 0x2)
if (Process.arch == "arm64") {
JdwpOptions.tempMem.add(0x0).writeInt(this.transport)
JdwpOptions.tempMem.add(0x4).writeU16(this.server ? 1 : 0)
JdwpOptions.tempMem.add(0x6).writeU16(this.suspend ? 1 : 0)
JdwpOptions.tempMem.add(0x8).writeU8(this.host.length*2)
JdwpOptions.tempMem.add(0x9).writeUtf8String(this.host)
JdwpOptions.tempMem.add(0x20).writeU16(this.port)
} else if (Process.arch == "arm") {
JdwpOptions.tempMem = Memory.alloc(0x28)
JdwpOptions.tempMem.add(0x0).writeInt(this.transport)
JdwpOptions.tempMem.add(0x4).writeU16(this.server ? 1 : 0)
JdwpOptions.tempMem.add(0x6).writeU16(this.suspend ? 1 : 0)
JdwpOptions.tempMem.add(0x8).writeU8(this.host.length*2)
JdwpOptions.tempMem.add(0x9).writeUtf8String(this.host)
JdwpOptions.tempMem.add(0x14).writeU16(this.port)
} else {
throw new Error("Not support arch")
}
return JdwpOptions.tempMem
}
}

// // _ZN3art3Dbg13ConfigureJdwpERKNS_4JDWP11JdwpOptionsEFUNC | static void ConfigureJdwp(const JDWP::JdwpOptions& jdwp_options)
// auto lam_configureJdwp = [&](const JdwpOptions &jdwp_options) {
// void *sym = xdl_sym(art_handle, "_ZN3art3Dbg13ConfigureJdwpERKNS_4JDWP11JdwpOptionsE", nullptr);
// LOGW("ConfigureJdwp = %p", sym);
// if (sym != nullptr) {
// typedef void (*ConfigureJdwp)(const JdwpOptions &);
// ConfigureJdwp configureJdwp = (ConfigureJdwp)sym;
// configureJdwp(jdwp_options);
// } else {
// throw std::runtime_error("ConfigureJdwp is nullptr");
// }
// };
const configureJdwp = (jdwp_options:JdwpOptions)=>{
const addr = Module.findExportByName("libart.so", "_ZN3art3Dbg13ConfigureJdwpERKNS_4JDWP11JdwpOptionsE")
if(addr){
const ConfigureJdwp = new NativeFunction(addr, 'void', ['pointer'])
ConfigureJdwp(jdwp_options.get_pointer())
} else {
throw new Error("ConfigureJdwp is nullptr")
}
}

// lam_stopJdwp();

// if (!lam_isJdwpAllowed()) {
// lam_setJdwpAllowed(true);
// }

// if (!lam_isJdwpConfigured()) {
// static JdwpOptions jdwpOptions;
// jdwpOptions.server = true;
// jdwpOptions.suspend = false;
// jdwpOptions.port = 8000;
// jdwpOptions.host = "127.0.0.1";
// jdwpOptions.transport = JdwpTransportType::kJdwpTransportAndroidAdb;
// lam_configureJdwp(jdwpOptions);
// }

// lam_startJdwp();

export function startJdwpThrad(){
stopJdwp()

if (!isJdwpAllowed()) {
setJdwpAllowed(true)
}

if (!isJdwpConfigured()) {
const jdwpOptions = new JdwpOptions(
JdwpTransportType.kJdwpTransportAndroidAdb,
true,
false,
"127.0.0.1",
8000,
)
configureJdwp(jdwpOptions)
}
startJdwp()
}

// } catch (const std::exception &e) {
// LOGD("error: %s", e.what());
// }


declare global {
var startJdwpThrad: ()=>void
}

globalThis.startJdwpThrad = startJdwpThrad

0 comments on commit 8a435ce

Please sign in to comment.