Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Android HOOK tool Cydia Substrate

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to use the Android HOOK tool Cydia Substrate, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Cydia Substrate is a platform for code modification. It can modify the code of any main process, whether it is written in Java or native code. Xposed only supports the java function in HOOK app_process, so Cydia Substrate is a powerful and practical HOOK tool.

Substrate several important API introduces MS.hookClassLoad function prototype: void hookClassLoad (String name, MS.ClassLoadHook hook)

The method implementation notifies when the specified class is loaded. Because a class can be loaded at any time, Substrate provides a method to detect when a class of interest to the user is loaded.

Parameters.

Description

Name

Package name + class name, using java. Symbol

Hook

An instance of MS.ClassLoadHook whose classLoaded method is executed when the class is loaded.

MS.hookMethod

The API allows developers to provide a callback function that replaces the original method, which is an object that implements the MS.MethodHook interface and is a typical anonymous inner class. It contains an invoked function.

Function prototype:

Void hookMethod (Class _ class, Member member, MS.MethodHook hook, MS.MethodPointer old); void hookMethod (Class _ class, Member member, MS.MethodAlteration alteration)

Parameter description

(1)

Parameters.

Description

_ class

The loaded target class, which is the class parameter passed down by classLoaded

Member

A method (or constructor) that requires hook obtained by reflection. Note: the HOOK field is not allowed (it will be detected at compile time).

Hook

An instance of MS.MethodHook that contains an invoked method that is called instead of the code in member

(2)

Parameters.

Description

_ class

The loaded target class, which is the class parameter passed down by classLoaded

Member

A method (or constructor) that requires hook obtained by reflection. Note: the HOOK field is not allowed (it will be detected at compile time).

Alteration

An instance of MS.MethodAlteration whose boxedinvoked method will be called instead of member. This instance will also be filled in using information from the original implementation, allowing you to use invoke to call the original method implementation.

It is recommended that developers use the second approach, which is simple to use and rarely makes mistakes, and does not require a separate instance of the MS.MethodPointer class.

Usage

The following is an example of the official website to illustrate the use of cydia substrate. The example is to change the color of multiple interface components to violet.

Need to install: http://www.cydiasubstrate.com/download/com.saurik.substrate.apk

Step 1: create an empty Android project. Because the created project will be loaded as a plug-in, activity is not required. Copy the substrate-api.jar from SDK to the project/libs folder.

Step 2: configure the Manifest file

(1) you need to specify permission: cydia.permission.SUBSTRATE

(2) add the meta tag, and name is the name of the class created by cydia.permission.SUBSTRATE,value in the next step. main

Step 2: create a class named Main. The class contains a static method initialize, and when the plug-in is loaded, the code in the method runs, completing some necessary initialization.

Import com.saurik.substrate.MS; public class Main {static void initialize () {/ /... Code to run when extension is loaded}}

Step 3: in order to implement HOOK and modify the code in the target class, we need to get an instance of the target class, such as resources in the example.

Public class Main {static void initialize () {MS.hookClassLoad ("android.content.res.Resources", new MS.ClassLoadHook () {public void classLoaded (Class resources) {/ /... Code to modify the class when loaded});}}

Step 4: modify the original code through an example of MS.MethodHook.

To call the method in the original code, we need to create an instance of the MS.MethodPointer class that can run the original code at any time.

Here we change all green to violet by calling and modifying the original code of the resources object in the original code.

Public void classLoaded (Class resources) {Method getColor; try {getColor = resources.getMethod ("getColor", Integer.TYPE);} catch (NoSuchMethodException e) {getColor = null;} if (getColor! = null) {final MS.MethodPointer old = new MS.MethodPointer (); MS.hookMethod (resources, getColor, new MS.MethodHook) {public Object invoked (Object resources, Object...) Args) throws Throwable {int color = (Integer) old.invoke (resources, args); return color & ~ 0x0000ff00 | 0x00ff000000;}}, old);}}

Install and run, restart the system and find that many font colors have changed. As shown in the following figure:

The code for MS.hookMethod in the example can be changed to:

MS.hookMethod (resources, getColor, new MS.MethodAlteration () {public Integer invoked (Resources resources, Object...) Args) throws Throwable {int color = invoke (resources, args); return color & ~ 0x0000ff00 | 0x00ffee00;}}); SMS monitoring instance

In the following example, we implement the SMS monitoring function to print out the sender, receiver and content of the SMS:

1 import java.lang.reflect.Method; 2 import android.app.PendingIntent; 3 import android.util.Log; 4 import com.saurik.substrate.MS 5 6 7 public class Main {8 9 static void initialize () {10 11 MS.hookClassLoad ("android.telephony.SmsManager", new MS.ClassLoadHook () {12 13 14 @ Override 15 16 public void classLoaded (Class SmsManager) {17 18 / / code to modify the class when loaded 19 20 Method sendTextMessage 21 22 try {23 24 sendTextMessage = SmsManager.getMethod ("sendTextMessage", 25 26 new Class [] {String.class,String.class,String.class,PendingIntent.class,PendingIntent.class}); 27 28 29} catch (NoSuchMethodException e) {30 31 sendTextMessage = null 32 33} 34 35 MS.hookMethod (SmsManager, sendTextMessage, new MS.MethodAlteration () {36 37 public Object invoked (Object _ this,Object...) _ args) throws Throwable {38 39 Log.i ("SMSHOOK", "SEND_SMS"); 40 41 Log.i ("SMSHOOK", "destination:" + _ args [0]); 42 43 Log.i ("SMSHOOK", "source:" + _ args [1]); 44 45 Log.i ("SMSHOOK", "text:" + _ args [2]) 46 47 return invoke (_ this, _ args); 48 49} 50 51}); 52 53 54} 55 56}); 57 58} 59 60}

The result of running is:

On how to use the Android HOOK tool Cydia Substrate to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 302

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report