Smali Syntax of apk Disassembly

Source: Internet
Author: User

The Type Dalvik bytecode has two main types: base class and reference type. The reference type references objects and arrays, and all others are the base class described by a simple character. I did not propose these acronyms-they are actually stored in the dex file in string form they are defined in a webpage document with dex format (the path in the AOSP library is dalvik/docs/dex-format.html) V null type --- it can only be used as the return type Z Boolean B Byte type S Short INTEGER (16 bits) C Char character type I Int integer J long (64 bits) long Integer (64-bit) F Float Type D double (64 bits) double Precision type (64-bit) the object starts with Lpackage/name/ObjectName --- indicates that this is an object type, package/name/indicates this object, and the object name is the object name, the semicolon indicates the end of the Object Name. This is equivalent to the package in java. name. objectName structure. For a more specific example, "Ljava/lang/String;" is equivalent to "java. lang. string ". The array uses the [I form-this represents a one-dimensional integer array, just like the int [] in java. For multi-dimensional arrays, simply add the character '['. For example, [[I = int [] [] (the maximum dimension is 255 ). you can also use array objects. For example, [Ljava/lang/String is a String array. Method methods are always defined as a very complex form that includes methods, method names, parameter types, and returned values. All of this information is required to find the correct method for the Virtual Machine and be capable of representing Static Analysis on bytecode (Optimal Selection for confirmation ). They use the following form: Lpackage/name/ObjectName;-> MethodName (III) Z. In this example, you should identify "Lpackage/name/ObjectName;" as a class, methodName is obviously a method name, (III) Z is the method signature, 'II' is three Integer Parameters in this example, Z is to return a boolean type return value. They take the formLpackage/name/ObjectName;-> MethodName (III) ZIn this example, you shoshould recognize Lpackage/name/ObjectName; as a type. methodName is obviusly the name of the method. (III) Z is the method's signature. III are the parameters (in this case, 3 ints), and Z is the return type (bool ). method parameters are listed one by one on the right without semicolons. A more complex example is provided: method (I [[IILjava/lang/String; [Ljava/lang/Object;) Ljava/lang/String; in java, this String method (int, int [] [], int, String, Object []) domain is also specified as a lengthy domain, including domain name, the format of the domain type. In addition, it allows virtual machines to find the correct domain to perform static analysis of byte encoding. They use the following format: Lpackage/name/ObjectName;-> FieldName: Ljava/lang/String; this is quite self-evident-the domain name and domain type are in the dalvik bytecode, respectively, registers are always 32-bit and can store any type of value. Two registers can be used to store 64-bit values (long integer and double precision type) the Register number in the specified method can be used to specify multiple registers in one method. Registers directly specify the total number of registers in the method, or regional variables directly specify the number of non-parameter registers in the method. The total number of registers includes all registers required for parameters in the method. Number of parameters passed into the method when a method is called, the parameters in the method are placed in the latest registers. If a method has two parameters and five registers, these parameters are stored in the last two registers V3 and V4. the first parameter of the dynamic method is always the first object called, for example, if you want to write a dynamic method LMyObject;-> callMe (II) V, this method has two integer parameters, but there is also an implicit parameter 'lmyobject' before the two integer parameters, therefore, there are three parameters in this method. We assume that you have developed five registers (v0-v4) in a method, neither register 5 management nor local register 2 Management (2 local registers and 3 parameter registers) after this method is called, The called object is V2, the first integer parameter is V3, and the second is V4. The same applies to static methods unless there is no implicit this pointer parameter. Register names have two naming schemes for registers: The standard V naming scheme and the P naming scheme for parameter registers. The first register named p is the first parameter register in the method, so let's return to the example with a total of five registers and three parameters. The following table shows the Standard v name for each register, next is to name p in the parameter register v0 the first local register v1 the second local register v2 p0 the first parameter register v3 p1 the second parameter register the second parameter register v4 p2 the third parameter register you can refer to the parameter register through each name class-there are no two p naming schemes as a practical content introduced to solve the common difficulties in editing smali encoding. Suppose you have an existing method with a certain number of parameters. If you want to add some code to this method, you will find that you need an additional register. You will think, it's no big deal. I just need to increase the number of registers in register management. Unfortunately, this is not easy. Remember that the parameters in the method are stored in the nearest register. If you increase the number of registers-you will change the input of method parameters in the register. So you have to change the register management and recode the parameter register. But if you use the p naming mode in the method to reference the parameter register, you can easily change the number of registers in the method without worrying about re-numbering any existing registers. Note: by default, baksmali uses the p naming mode for parameter registers. If you use the V naming mode for some reason, you can choose-p/-- no-parameter-registers. Long/Double values Long integer/Double-precision value as previously mentioned, the basic unit of the Long integer and Double-precision type (represented by J and D respectively) is 64-bit, two registers are required. When you reference parameters in a method, you must keep them in mind. For example, we hold your own non-static method LMyObject;-> MyMethod (IJZ) V. The parameters of the method are "LMyObject;", integer, long integer, and Boolean. Therefore, this method requires five registers to store all the parameters. In addition, when you call this method later, you have to specify two registers in the register list to store any 64-bit parameter Baksmali. Now you can decompile the odex file, and select deodex. Note: This page only applies to baksmali v0.96-v1.1. V1.2 and later versions do not require deodexrant. Find. He asked deodexrant for help in detail. This is a small binary file that can run on a mobile phone and connect to dalvik cool. His goal is to get a similar register table from the running dalvik, the syntax of the domain offset information provided to baksmaliDeodexrant is as follows: deodexerant <odex_file> <port> then baksmali has a new option to tell the deodex file. The syntax is as follows: baksmali-x

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.