What does ".line" mean in smali code syntax? (Android-Smali Code)

11,506

Solution 1

.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.

Solution 2

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.

Share:
11,506
Behzad Gh
Author by

Behzad Gh

Updated on June 05, 2022

Comments

  • Behzad Gh
    Behzad Gh almost 2 years

    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.

  • Behzad Gh
    Behzad Gh over 10 years
    can i remove .line markers when i want to recompile smali codes ?
  • nanofarad
    nanofarad over 10 years
    @user2525702 As per what I have already stated, yes, but debugging will be harder.
  • zapl
    zapl over 10 years
    @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)
  • Simon
    Simon over 10 years
    @user2525702 But why do you want to do this? Simply recompile the original source with the modifications.
  • DevZer0
    DevZer0 about 10 years
    @Simon its useful when you don't have the original source
  • Simon
    Simon about 10 years
    @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?
  • DevZer0
    DevZer0 about 10 years
    @Simon its useful when you inspect closed source application for potential malware code in them.
  • Jaynam Modi
    Jaynam Modi almost 5 years
    Thanks @Andrey. You Just Saved me Hours of Bullsh*t