`
netxdiy
  • 浏览: 728281 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

example-structures.smali

 
阅读更多

转载自 :http://androidcracking.blogspot.com/p/way-of-android-cracker-lessons.html(得大笑

many people find this blog by searching for smali syntax examples and finding a previous post onexample smali syntax. since i originally hastily wrote it, i have learned more so i updated it as best i could for now. more helpfully, i worked out a syntax highlighter for smali usingsyntaxhighlighter. i'll upload itsomewhere officialwhen i'm finished so others can use it. because i know there are throngs of people just itching to have highlighted smali code!

so for the googler's out there trying to make sense of smali, here's example-structures.smali fromlesson 1 from way of the android cracker.


.class publicLcom/lohan/crackme1/example;

.superLjava/lang/Object;

.source"example.java"

# staticfields

.field privatestatic Counter:I

# directmethods

# all theconstructor does is set Counter to 0x10 (or 16)

.method publicconstructor <init>()V

.registers 2

.prologue

.line 11

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

const/16 v0, 0x10

sput v0,Lcom/lohan/crackme1/example;->Counter:I

return-void

.end method

.method publicstatic ArrayExample()V

.registers 4

.prologue

const/4 v3, 0x1

const/4 v2, 0x0

.line 50

const/4 v1, 0x5

new-array v0, v1, [Ljava/lang/String;

.line 52

.local v0, someArray:[Ljava/lang/String;

# put value v1 inside array v0 at index v2(0x0)

const-string v1, "set value at index0"

aput-object v1, v0, v2

.line 53

# put value v1 inside array v0 at index v3(0x1)

const-string v1, "index 1 has thisvalue"

aput-object v1, v0, v3

.line 55

# store in v1 the value from array v0 atindex v2

aget-object v1, v0, v2

# store in v2 the value from array v0 atindex v3

aget-object v2, v0, v3

# compare two strings

invoke-virtual {v1, v2},Ljava/lang/String;->equals(Ljava/lang/Object;)Z

move-result v1

# if equals() returns 0, it means they arenot equal, so just return

if-eqz v1, :cond_1e

.line 57

sget-object v1,Ljava/lang/System;->out:Ljava/io/PrintStream;

const-string v2, "array at index 0 = 1(wont happen)"

invoke-virtual {v1, v2},Ljava/io/PrintStream;->println(Ljava/lang/String;)V

.line 59

:cond_1e

return-void

.end method

# loop from 0to Counter

# just a fewlines in java

.method publicstatic LoopExample()V

.registers 4

.prologue

.line 15

const/4 v0, 0x0

.local v0, i:I

:goto_1

sget v1,Lcom/lohan/crackme1/example;->Counter:I

if-lt v0, v1, :cond_6

.line 17

return-void

.line 16

:cond_6

sget-object v1,Ljava/lang/System;->out:Ljava/io/PrintStream;

new-instance v2, Ljava/lang/StringBuilder;

const-string v3, "current val forloop: "

invoke-direct {v2, v3},Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

invoke-virtual {v2, v0},Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

move-result-object v2

invoke-virtual {v2},Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

move-result-object v2

invoke-virtual {v1, v2},Ljava/io/PrintStream;->println(Ljava/lang/String;)V

.line 15

add-int/lit8 v0, v0, 0x1

goto :goto_1

.end method

.method publicstatic SwitchExample()V

.registers 3

.prologue

.line 21

const/16 v0, 0x2a

.line 22

.local v0, val:I

# begin the switch

# look down at .sparse_switch directive

sparse-switch v0, :sswitch_data_2e

# switch default just passes through tohere

.line 27

sget-object v1,Ljava/lang/System;->out:Ljava/io/PrintStream;

const-string v2, "invalid value"

invoke-virtual {v1, v2},Ljava/io/PrintStream;->println(Ljava/lang/String;)V

.line 29

:goto_c

return-void

.line 23

:sswitch_d # if v0 is 1, we'll be here

sget-object v1,Ljava/lang/System;->out:Ljava/io/PrintStream;

const-string v2, "val 1"

invoke-virtual {v1, v2},Ljava/io/PrintStream;->println(Ljava/lang/String;)V

goto :goto_c

.line 24

:sswitch_15 # if v0 is 2

sget-object v1,Ljava/lang/System;->out:Ljava/io/PrintStream;

const-string v2, "val 2"

invoke-virtual {v1, v2},Ljava/io/PrintStream;->println(Ljava/lang/String;)V

goto :goto_c

.line 25

:sswitch_1d # if v0 is 42

sget-object v1,Ljava/lang/System;->out:Ljava/io/PrintStream;

const-string v2, "val 42"

invoke-virtual {v1, v2}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

goto :goto_c

.line 26

:sswitch_25 # if v0 is 5

sget-object v1,Ljava/lang/System;->out:Ljava/io/PrintStream;

const-string v2, "val 5"

invoke-virtual {v1, v2},Ljava/io/PrintStream;->println(Ljava/lang/String;)V

goto :goto_c

.line 22

nop

:sswitch_data_2e

# if v0 is 0x1 goto :sswitch_d

# if 0x2 :sswitch_15

# and so on...

.sparse-switch

0x1 -> :sswitch_d # 1

0x2 -> :sswitch_15 # 2

0x5 -> :sswitch_25 # 5

0x2a -> :sswitch_1d # 42

.end sparse-switch

.end method

.method publicstatic TryCatchExample()V

.registers 8

.prologue

const-string v7, ": "

.line 33

const-string v3, "google.com"

.line 36

.local v3, urlStr:Ljava/lang/String;

# begin try here

:try_start_4

new-instance v2, Ljava/net/URL;

invoke-direct {v2, v3},Ljava/net/URL;-><init>(Ljava/lang/String;)V

.line 37

.local v2, url:Ljava/net/URL;

invoke-virtual {v2},Ljava/net/URL;->openStream()Ljava/io/InputStream;

move-result-object v1

.line 38

.local v1, is:Ljava/io/InputStream;

invoke-virtual {v1},Ljava/io/InputStream;->close()V

:try_end_10

# end of the try

# if there was a MalformedURLException,goto :catch_11

.catch Ljava/net/MalformedURLException;{:try_start_4 .. :try_end_10} :catch_11

# IOException goes to :catch_36

.catch Ljava/io/IOException; {:try_start_4.. :try_end_10} :catch_36

# ifNO exception, just pass through:

.line 46

.end local v1 #is:Ljava/io/InputStream;

.end local v2 #url:Ljava/net/URL;

:goto_10

return-void

.line 39

:catch_11

# move the exception to v4, then to v0

# allof the code below is what happens with an exception

move-exception v4

move-object v0, v4

.line 41

.local v0,e:Ljava/net/MalformedURLException;

sget-object v4,Ljava/lang/System;->out:Ljava/io/PrintStream;

new-instance v5, Ljava/lang/StringBuilder;

const-string v6, "Invalid URL "

invoke-direct {v5, v6},Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

invoke-virtual {v5, v3},Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v5

const-string v6, ": "

invoke-virtual {v5, v7},Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v5

invoke-virtual {v0},Ljava/net/MalformedURLException;->getMessage()Ljava/lang/String;

move-result-object v6

invoke-virtual {v5, v6},Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v5

invoke-virtual {v5},Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

move-result-object v5

invoke-virtual {v4, v5},Ljava/io/PrintStream;->println(Ljava/lang/String;)V

goto :goto_10

.line 42

.end local v0 #e:Ljava/net/MalformedURLException;

# end exception code

# begin exception code

:catch_36

move-exception v4

move-object v0, v4

.line 44

.local v0, e:Ljava/io/IOException;

sget-object v4,Ljava/lang/System;->out:Ljava/io/PrintStream;

new-instance v5, Ljava/lang/StringBuilder;

const-string v6, "Unable to execute"

invoke-direct {v5, v6},Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

invoke-virtual {v5, v3},Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v5

const-string v6, ": "

invoke-virtual {v5, v7},Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v5

invoke-virtual {v0},Ljava/io/IOException;->getMessage()Ljava/lang/String;

move-result-object v6

invoke-virtual {v5, v6},Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v5

invoke-virtual {v5},Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

move-result-object v5

invoke-virtual {v4, v5},Ljava/io/PrintStream;->println(Ljava/lang/String;)V

goto :goto_10

# end exception code

.end method




分享到:
评论

相关推荐

    hapi-structures-v23-2.2.zip

    《深入理解RPKI与HSM集成:开源项目hapi-structures-v23-2.2.zip解析》 在IT行业中,网络安全与数据保护是至关重要的领域。资源公钥基础设施(RPKI)是一种用于验证互联网路由安全性的重要技术,而硬件安全模块...

    Algorithm-Play-with-Data-Structures.zip

    Algorithm-Play-with-Data-Structures.zip,我的MOOC课程代码中的游戏数据结构&gt;。更新的内容和做法也包括在内。并用Java语言编写了Java语言。,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。

    html css js网页设计-Data-Structures.rar

    html css js网页设计-Data-Structures.rar

    Algorithm-data-structures-questions.zip

    在"Algorithm-data-structures-questions.zip"的"data-structures-questions-master"文件中,可能包含了关于算法与数据结构的各种练习和问题,旨在帮助学习者深入理解和掌握这些概念。通过解决这些问题,你可以提升...

    Play-with-Data-Structures-master.zip

    《Play-with-Data-Structures-master》是一个涵盖了数据结构基础到高级应用的全面教程,包含1-12章的源代码实现。这个课程是学习和深入理解数据结构的理想资源,对于计算机科学的学生、程序员以及对算法和数据结构有...

    PyPI 官网下载 | aa-structures-1.1.0.tar.gz

    《PyPI官网下载:aa-structures-1.1.0.tar.gz详解》 在Python的世界里,PyPI(Python Package Index)是最重要的软件仓库,它为开发者提供了分享和下载Python库的平台。本文将深入探讨从PyPI官网下载的"aa-...

    Algorithm-Cormen-Algorithms-Data-Structures.zip

    Algorithm-Cormen-Algorithms-Data-Structures.zip,《算法导论,第三版-CLRS》一书中算法的实现和数据结构,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。

    Algorithm-Structures.zip

    在这个"Structures-master"目录下,很可能包含了上述各种数据结构的Java实现,通过阅读和分析这些代码,我们可以加深对数据结构的理解,提升编程技能。 总结来说,"Algorithm-Structures.zip"是一个宝贵的学习资源...

    Algorithm-C-Common-Data-Structures.zip

    Algorithm-C-Common-Data-Structures.zip,一种快速且内存高效的C库,用于操作顺序容器、关联结构和高级字符串处理,如树映射、哈希映射和trie。,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。

    Algorithm-data-structures.zip

    本资源"Algorithm-data-structures.zip"的"data-structures-master"目录下,可能包含了各种数据结构的实现源码,以及相关的测试案例。通过对这些代码的学习和实践,开发者不仅可以深入了解数据结构和算法的工作原理...

    Algorithm-algorithms-and-data-structures.zip

    在"algorithms-and-data-structures-master"这个目录下,可能包含了各种关于算法和数据结构的源代码示例、练习题、讲义或教程。学习者可以从中探索经典的排序算法实现,如快速排序、归并排序、堆排序等,理解它们的...

    Algorithm-Python-and-Algorithms-and-Data-Structures.zip

    Algorithm-Python-and-Algorithms-and-Data-Structures.zip,python书籍中的算法和数据结构(由hanbit media,inc.出版)——python解决方案,解决“破解代码面试”中的每一个难题,算法是为计算机程序高效、彻底地...

    data-structures.zip

    这份压缩包“data-structures.zip”包含了一系列的知识文档和配套的Java源代码,旨在帮助学习者深入理解并掌握这些关键技能。 数据结构是计算机科学的基础,它涉及如何在内存中有效地存储和组织数据,以便于快速...

    PyPI 官网下载 | mercury-engine-data-structures-0.9.2.tar.gz

    《PyPI官网下载 | mercury-engine-data-structures-0.9.2.tar.gz——Python库解析与分布式技术概览》 PyPI(Python Package Index)是Python开发者常用的资源库,其中包含了大量的开源软件包和模块。在本文中,我们...

    python-data-structures.rar

    python-data_structures.rar

    Algorithm-Algorithms-and-Data-Structures.zip

    在"Algorithms-and-Data-Structures-master"目录中,我们可以预期找到各种算法和数据结构的实现源码,可能包括以下内容: 1. **排序算法**:例如,快速排序、归并排序、堆排序、插入排序、选择排序等,每种排序算法...

    algorithms-and-data-structures.rar_algorithms

    "algorithms-and-data-structures.rar_algorithms"这个压缩包文件聚焦于几个关键的算法和概念,包括线段树、后缀数组、最大权闭合子图、求逆元、斜率优化以及强连通分量。下面我们将详细探讨这些知识点。 1. **线段...

    python数据分析与可视化python-data-structures.rar

    在这个压缩包"python-data-structures.rar"中,我们可以预见到它可能包含了一系列关于Python数据结构及其在数据分析和可视化中的应用的教程或代码示例。 首先,我们要理解数据结构是编程的基础,特别是在处理数据时...

    Algorithm-Data-Structures-Algorithms.zip

    Algorithm-Data-Structures-Algorithms.zip,Python 3和C 中85种流行的数据结构和算法及面试问题的实现,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。

    Algorithm-Problem-Solving-with-Algorithms-and-Data-Structures-using-Python.zip

    Algorithm-Problem-Solving-with-Algorithms-and-Data-Structures-using-Python.zip,使用python的算法和数据结构解决问题的代码,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。

Global site tag (gtag.js) - Google Analytics