13

Please take a look at this question

Decompiled smali code contains things like .line 3 or .line 7.

I cannot understand what .line is supposed to be, please elaborate on the usage.

Community
  • 1
  • 1
Behzad Gh
  • 325
  • 1
  • 2
  • 10

2 Answers2

23

.line n markers are used for debugging and stacktraces. When an exception goes uncaught, or the stacktrace needs to be filled in, the line number is taken from the .line statement. If this were missing, then stacktraces would lack line numbers.

nanofarad
  • 40,330
  • 4
  • 86
  • 117
  • can i remove .line markers when i want to recompile smali codes ? – Behzad Gh Aug 16 '13 at 13:11
  • 1
    @user2525702 As per what I have already stated, yes, but debugging will be harder. – nanofarad Aug 16 '13 at 13:16
  • 2
    @user2525702 `.line` is the line in the original Java sourcecode that translates to the following part of smali. If you remove them you probably don't get nice Exception stacktraces like `at com.foo.bar.Bar(Bar.java:85)` – zapl Aug 16 '13 at 13:29
  • @user2525702 But *why* do you want to do this? Simply recompile the original source with the modifications. – Simon Aug 16 '13 at 15:30
  • @Simon its useful when you don't have the original source – DevZer0 Feb 27 '14 at 05:59
  • @DevZer0 Like when? In what scenario do you not have the code? Either; a) it's your code, b) it's open source, c) the developer has provided the code. There are no other legitimate scenarios - or are there? – Simon Feb 27 '14 at 08:13
  • 4
    @Simon its useful when you inspect closed source application for potential malware code in them. – DevZer0 Mar 01 '14 at 11:48
  • Thanks @Andrey. You Just Saved me Hours of Bullsh*t – Jaynam Modi Jul 24 '19 at 07:15
1

Almost everything in the smali language has a direct analogue in the dalvik bytecode or dex format.

The .line directive in particular corresponds to the position entries emitted by the state machine that the debug_info_item defines, as specified at https://source.android.com/devices/tech/dalvik/dex-format.

Community
  • 1
  • 1
JesusFreke
  • 19,784
  • 5
  • 65
  • 68