Table of Contents
1.java Complex Class
2.smali code
2.1 The first module - information module
2.2 The second module - construction method
2.2.1 .method
2.2.2 public
2.2.3 constructor
2.2.5 (Ljava/lang/String;I)
2.2.6 v
2.3 方法模块
2.4 练习
0x02 smali类相互调用
1. java代码
2.smali代码
3.总结
0x03 小练习(甜点)
Home Operation and Maintenance Safety Analysis of smali complex class examples in Android reverse engineering

Analysis of smali complex class examples in Android reverse engineering

May 12, 2023 pm 04:22 PM
android smali

1.java Complex Class

If you don’t understand anything, please see: JAVA General Outline or Construction Method
Analysis of smali complex class examples in Android reverse engineering

Post the code here, it is very simple and not difficult.

2.smali code

We need to convert java code to smali code, you can refer to java to smali

Analysis of smali complex class examples in Android reverse engineering

Analysis of smali complex class examples in Android reverse engineering

Let’s look at it in modules.

2.1 The first module - information module


Analysis of smali complex class examples in Android reverse engineering

This module is the basic information, indicating the class name, etc., just know it Good doesn't help much with analysis.

2.2 The second module - construction method


Analysis of smali complex class examples in Android reverse engineering

# Let’s analyze it sentence by sentence. If there are duplicates in the previous analysis, we will not repeat them. . But a link will be provided.

.method public constructor <init>(Ljava/lang/String;I)V</init>
Copy after login

This sentence is divided into

.methodpublicconstructor<init>(Ljava/lang/String;I)v</init>
Copy after login
2.2.1 .method

means method

2.2.2 public

Modification method, public properties

2.2.3 constructor

Constructor here means that this method is a constructor method

2.2.4 <init> </init>

After compilation, Java will generate an method in the bytecode file, called an instance constructor. This instance constructor will initialize statement blocks, variables, and call the parent class's Constructor and other operations converge into the method, and the order of convergence (only non-static variables and statement blocks are discussed here) is:

  1. Parent class variable initialization

  2. Parent class statement block

  3. Parent class constructor

  4. Subclass variable initialization

  5. Subclass statement block

  6. Subclass constructor

The so-called convergence into the method means that These operations are put into for execution

2.2.5 (Ljava/lang/String;I)

The content in the brackets is first Ljava/lang/String, here it is Say the first parameter is of type String.
; There is an I at the end, which means there is an int type parameter that also belongs to Ljava/lang.

2.2.6 v

There is a v at the end, which means void. That is, there is no return value type.


Let’s look at the meaning of the second sentence.

.registers 6
Copy after login

Register 6. The registers here start from v0-v5. This is easy to understand.


The third sentence.

.prologue
Copy after login

Opening means the beginning of the program.


The fourth sentence.

.line 10
Copy after login

The meaning of the 10th line of code.


The fifth sentence is:

invoke-direct {p0}, Ljava/lang/Object;-><init>()V</init>
Copy after login

First break down this sentence.

invoke-direct{p0}Ljava/lang/Object;-><init>
()
V</init>
Copy after login
invoke-direct
Copy after login

means method call.

{p0}
Copy after login

p0 means the first parameter. But there is no first parameter here. The default here is this. The parameters we pass in start counting from p1.

Ljava/lang/Object;-><init></init>
Copy after login

Call<init></init>There is no content in the method

(), which means there are no parameters. v is equivalent to void and will not be repeated here.


The sixth sentence is

iput-object p1, p0, LPerson;->name:Ljava/lang/String;
Copy after login

Break it down

iput-object p1,p0LPerson;->name:Ljava/lang/String;
Copy after login

iput-object p1, p0 means to give the content of p1 to p0.

LPerson;->name:Ljava/lang/String;
Copy after login

The meaning of this sentence is to take an attribute named name and type String from the Person class. These are to modify p0. In fact, it is this.name.


The seventh sentence

iput p2, p0, LPerson;->age:I
Copy after login

is also broken down into two parts.

iput p2, p0LPerson;->age:I
Copy after login

iput p2, p0, here is to give the value of p2 to p0

LPerson;->age:I
Copy after login

It shows that the data type of age is int.

You may find that calling the two properties is different. This is because String is not a basic data type. So iput-object is used, if the basic data type is iput.


The eighth sentence

 sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
Copy after login

Decomposition

 sget-object v0
 Ljava/lang/System;->out:
 Ljava/io/PrintStream;
Copy after login

sget-object v0 is to give v0 the things that will be met after getting them.

Ljava/io/PrintStream;This means that there is a Ljava/lang/System;->out: method in this class.


The ninth sentence

new-instance v1, Ljava/lang/StringBuilder;
Copy after login

Create a new StringBuilder class for v1.


The tenth sentence

invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V</init>
Copy after login

is similar to the previous one, calling v1 from the constructor.


The eleventh sentence

const-string v2, "name:"
Copy after login

const-string constant string. v2, the content is name:


The twelfth sentence

 invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
Copy after login

Broken it down is

invoke-virtual {v1, v2}Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
Copy after login

invoke-virtual {v1, v2} calls the virtual method,
->append(Ljava/lang/String;)Ljava/lang/StringBuilder;Call a function named append, the parameter is String type, and the return value is StringBuilder type.


The thirteenth sentence

move-result-object v1
Copy after login

is to give the result of the previous sentence to the v1 register.

之后的内容就是相似的了。
Analysis of smali complex class examples in Android reverse engineering

有兴趣可以自己继续向下分析。

2.3 方法模块

这个模块在之前的一篇文章里已经说过了,这里就不再啰嗦了。

2.4 练习

这个练习我们就自己添加一个构造方法。

.method public constructor <init>()V    .registers 1
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V
    return-void
.end method</init></init>
Copy after login

这个是我们自己写的一个构造方法。无参无返回值。

编译成jar文件进行查看。


Analysis of smali complex class examples in Android reverse engineering

0x02 smali类相互调用

1. java代码

在0x01的前提上我们再写一个调用demo。

public class Demo{
    public static void main(String[]args)    {
        Person p=new Person("zhuzhu",14);
    }
}
Copy after login

代码很简单。

2.smali代码

这里我们要使用

javac -source 1.6 -target 1.6 *.java
Copy after login

编译所有.java文件

然后使用

dx --dex --output=demo.dex *.class
Copy after login

把所有的.class文件编译成dex文件。


Analysis of smali complex class examples in Android reverse engineering

我们来主要看看main函数。

.method public static main([Ljava/lang/String;)V
    .registers 4

    .prologue
    .line 4
    new-instance v0, LPerson;

    const-string v1, "zhuzhu"    const/16 v2, 0xe    invoke-direct {v0, v1, v2}, LPerson;-><init>(Ljava/lang/String;I)V

    .line 5    return-void.end method</init>
Copy after login
new-instance v0, LPerson;
Copy after login

新建一个类,v0

const-string v1, "zhuzhu"
Copy after login

然后定义一个常量 v1。

const/16 v2, 0xe
Copy after login

定义一个16位的常量

invoke-direct {v0, v1, v2}, LPerson;-><init>(Ljava/lang/String;I)V</init>
Copy after login

调用Person类的构造方法,然后把v0,v1,v2当做参数传进去。

其实类之前的交互调用其实并不难。

3.总结

我们调用其他类的时候。

1.new-instance 实例化一个对象
2.invoke-direct 调用构造方法

0x03 小练习(甜点)

首先来看看我们写的程序。

Analysis of smali complex class examples in Android reverse engineering

然后是手写的smali代码。

.class public LPd;
.super Ljava/lang/Object;
.source "Pd.java"# direct methods
.method public constructor <init>()V
    .registers 1    .prologue
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void.end method

.method public static main([Ljava/lang/String;)V

    .registers 4    .prologue

    new-instance v0,LPerson;

    invoke-direct {v0}, LPerson;-><init>()V

    return-void.end method</init></init></init>
Copy after login

The above is the detailed content of Analysis of smali complex class examples in Android reverse engineering. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades Sep 12, 2024 pm 12:23 PM

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

Samsung Galaxy S25 Ultra leaks in first render images with rumoured design changes revealed Samsung Galaxy S25 Ultra leaks in first render images with rumoured design changes revealed Sep 11, 2024 am 06:37 AM

OnLeaks has now partnered with Android Headlines to provide a first look at the Galaxy S25 Ultra, a few days after a failed attempt to generate upwards of $4,000 from his X (formerly Twitter) followers. For context, the render images embedded below h

IFA 2024 | TCL\'s NXTPAPER 14 won\'t match the Galaxy Tab S10 Ultra in performance, but it nearly matches it in size IFA 2024 | TCL\'s NXTPAPER 14 won\'t match the Galaxy Tab S10 Ultra in performance, but it nearly matches it in size Sep 07, 2024 am 06:35 AM

Alongside announcing two new smartphones, TCL has also announced a new Android tablet called the NXTPAPER 14, and its massive screen size is one of its selling points. The NXTPAPER 14 features version 3.0 of TCL's signature brand of matte LCD panels

Vivo Y300 Pro packs 6,500 mAh battery in a slim 7.69 mm body Vivo Y300 Pro packs 6,500 mAh battery in a slim 7.69 mm body Sep 07, 2024 am 06:39 AM

The Vivo Y300 Pro just got fully revealed, and it's one of the slimmest mid-range Android phones with a large battery. To be exact, the smartphone is only 7.69 mm thick but features a 6,500 mAh battery. This is the same capacity as the recently launc

Samsung Galaxy S24 FE billed to launch for less than expected in four colours and two memory options Samsung Galaxy S24 FE billed to launch for less than expected in four colours and two memory options Sep 12, 2024 pm 09:21 PM

Samsung has not offered any hints yet about when it will update its Fan Edition (FE) smartphone series. As it stands, the Galaxy S23 FE remains the company's most recent edition, having been presented at the start of October 2023. However, plenty of

New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades Sep 12, 2024 pm 12:22 PM

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

Xiaomi Redmi Note 14 Pro Plus arrives as first Qualcomm Snapdragon 7s Gen 3 smartphone with Light Hunter 800 camera Xiaomi Redmi Note 14 Pro Plus arrives as first Qualcomm Snapdragon 7s Gen 3 smartphone with Light Hunter 800 camera Sep 27, 2024 am 06:23 AM

The Redmi Note 14 Pro Plus is now official as a direct successor to last year'sRedmi Note 13 Pro Plus(curr. $375 on Amazon). As expected, the Redmi Note 14 Pro Plus heads up the Redmi Note 14 series alongside theRedmi Note 14and Redmi Note 14 Pro. Li

iQOO Z9 Turbo Plus: Reservations begin for the potentially beefed-up series flagship iQOO Z9 Turbo Plus: Reservations begin for the potentially beefed-up series flagship Sep 10, 2024 am 06:45 AM

OnePlus'sister brand iQOO has a 2023-4 product cycle that might be nearlyover; nevertheless, the brand has declared that it is not done with itsZ9series just yet. Its final, and possibly highest-end,Turbo+variant has just beenannouncedas predicted. T

See all articles