├── lib
└── gson-2.7.jar
├── src
├── META-INF
│ └── MANIFEST.MF
└── com
│ └── android
│ ├── dx
│ ├── util
│ │ ├── package.html
│ │ ├── LabeledItem.java
│ │ ├── Warning.java
│ │ ├── ToHuman.java
│ │ ├── IntIterator.java
│ │ ├── MutabilityException.java
│ │ ├── Writers.java
│ │ └── IntSet.java
│ ├── rop
│ │ ├── code
│ │ │ ├── package.html
│ │ │ ├── ConservativeTranslationAdvice.java
│ │ │ └── CstInsn.java
│ │ ├── type
│ │ │ ├── package.html
│ │ │ └── TypeList.java
│ │ ├── cst
│ │ │ ├── package.html
│ │ │ ├── CstMethodRef.java
│ │ │ ├── TypedConstant.java
│ │ │ ├── CstInterfaceMethodRef.java
│ │ │ ├── Zeroes.java
│ │ │ ├── CstEnumRef.java
│ │ │ ├── Constant.java
│ │ │ ├── CstLiteral32.java
│ │ │ ├── CstLiteral64.java
│ │ │ └── CstLong.java
│ │ └── annotation
│ │ │ └── AnnotationVisibility.java
│ ├── unpacker
│ │ ├── JsonCodeItem.java
│ │ └── MethodCodeItem.java
│ ├── cf
│ │ ├── code
│ │ │ ├── package.html
│ │ │ ├── SimException.java
│ │ │ └── ByteBlockList.java
│ │ ├── attrib
│ │ │ ├── package.html
│ │ │ ├── AttSynthetic.java
│ │ │ ├── AttDeprecated.java
│ │ │ ├── AttLocalVariableTable.java
│ │ │ ├── AttLocalVariableTypeTable.java
│ │ │ ├── BaseAttribute.java
│ │ │ ├── AttRuntimeVisibleAnnotations.java
│ │ │ ├── AttRuntimeInvisibleAnnotations.java
│ │ │ ├── AttRuntimeVisibleParameterAnnotations.java
│ │ │ ├── AttRuntimeInvisibleParameterAnnotations.java
│ │ │ ├── AttSignature.java
│ │ │ ├── AttSourceFile.java
│ │ │ ├── AttSourceDebugExtension.java
│ │ │ ├── AttInnerClasses.java
│ │ │ ├── AttBootstrapMethods.java
│ │ │ ├── AttLineNumberTable.java
│ │ │ ├── AttAnnotationDefault.java
│ │ │ ├── BaseLocalVariables.java
│ │ │ ├── AttExceptions.java
│ │ │ ├── AttEnclosingMethod.java
│ │ │ └── BaseAnnotations.java
│ │ ├── iface
│ │ │ ├── package.html
│ │ │ ├── HasAttribute.java
│ │ │ ├── Method.java
│ │ │ ├── ParseException.java
│ │ │ ├── Field.java
│ │ │ ├── Attribute.java
│ │ │ ├── FieldList.java
│ │ │ ├── MethodList.java
│ │ │ ├── StdFieldList.java
│ │ │ ├── StdMethodList.java
│ │ │ ├── StdField.java
│ │ │ ├── StdMethod.java
│ │ │ └── Member.java
│ │ ├── direct
│ │ │ └── package.html
│ │ └── cst
│ │ │ ├── MethodHandleKind.java
│ │ │ └── ConstantTags.java
│ ├── dex
│ │ ├── cf
│ │ │ ├── package.html
│ │ │ └── CfOptions.java
│ │ ├── code
│ │ │ ├── CatchBuilder.java
│ │ │ ├── VariableSizeInsn.java
│ │ │ ├── ZeroSizeInsn.java
│ │ │ ├── SimpleInsn.java
│ │ │ ├── form
│ │ │ │ ├── Form10x.java
│ │ │ │ ├── SpecialFormat.java
│ │ │ │ └── Form30t.java
│ │ │ └── OddSpacer.java
│ │ └── file
│ │ │ ├── IdItem.java
│ │ │ ├── HeaderSection.java
│ │ │ ├── FieldIdItem.java
│ │ │ ├── MethodIdItem.java
│ │ │ ├── TypeIdItem.java
│ │ │ ├── MethodHandlesSection.java
│ │ │ ├── IndexedItem.java
│ │ │ └── AnnotationSetRefItem.java
│ ├── Version.java
│ ├── command
│ │ ├── UsageException.java
│ │ ├── dexer
│ │ │ └── DxContext.java
│ │ ├── grep
│ │ │ └── Main.java
│ │ ├── findusages
│ │ │ └── Main.java
│ │ └── dump
│ │ │ └── Args.java
│ ├── merge
│ │ └── CollisionPolicy.java
│ ├── io
│ │ ├── instructions
│ │ │ ├── CodeInput.java
│ │ │ ├── ZeroRegisterDecodedInstruction.java
│ │ │ ├── AddressMap.java
│ │ │ ├── CodeCursor.java
│ │ │ ├── OneRegisterDecodedInstruction.java
│ │ │ ├── BaseCodeCursor.java
│ │ │ ├── PackedSwitchPayloadDecodedInstruction.java
│ │ │ ├── TwoRegisterDecodedInstruction.java
│ │ │ ├── RegisterRangeDecodedInstruction.java
│ │ │ ├── SparseSwitchPayloadDecodedInstruction.java
│ │ │ ├── CodeOutput.java
│ │ │ ├── ThreeRegisterDecodedInstruction.java
│ │ │ ├── ShortArrayCodeInput.java
│ │ │ └── FourRegisterDecodedInstruction.java
│ │ └── IndexType.java
│ └── ssa
│ │ └── back
│ │ └── NullRegisterAllocator.java
│ ├── dex
│ ├── util
│ │ ├── ByteInput.java
│ │ ├── ByteOutput.java
│ │ ├── ByteArrayByteInput.java
│ │ └── Unsigned.java
│ ├── DexIndexOverflowException.java
│ ├── DexException.java
│ ├── CallSiteId.java
│ ├── EncodedValue.java
│ ├── TypeList.java
│ ├── Annotation.java
│ ├── ProtoId.java
│ ├── FieldId.java
│ └── MethodId.java
│ └── multidex
│ ├── ClassPathElement.java
│ └── FolderPathElement.java
├── README.md
├── .classpath
├── .project
├── dexfixer.iml
└── .gitignore
/lib/gson-2.7.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dqzg12300/dexfixer/HEAD/lib/gson-2.7.jar
--------------------------------------------------------------------------------
/src/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Main-Class: com.android.dx.unpacker.DexFixer
3 |
4 |
--------------------------------------------------------------------------------
/src/com/android/dx/util/package.html:
--------------------------------------------------------------------------------
1 |
2 | Utility classes for class file access/manipulation.
3 |
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # dexfixer
2 | 修复fart脱出来的结果
3 |
4 | ### 说明
5 |
6 | 项目来源于[Youpk](https://github.com/youlor/unpacker)
7 |
8 | 修改成对fart的脱壳结果进行修复合并
9 |
10 | ### 使用
11 |
12 | `java -jar ./dexfixer.jar dexpath binpath outpath`
--------------------------------------------------------------------------------
/src/com/android/dx/rop/code/package.html:
--------------------------------------------------------------------------------
1 |
2 | Classes relating to a register-based opcode system.
3 |
4 | PACKAGES USED:
5 |
6 | com.android.dx.util
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/com/android/dx/rop/type/package.html:
--------------------------------------------------------------------------------
1 |
2 | Implementation of classes that represent types (classes or primitives).
3 |
4 | PACKAGES USED:
5 |
6 | com.android.dx.util
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/com/android/dx/unpacker/JsonCodeItem.java:
--------------------------------------------------------------------------------
1 | package com.android.dx.unpacker;
2 |
3 | public class JsonCodeItem {
4 | String name;
5 | int method_idx;
6 | int offset;
7 | int code_item_len;
8 | String ins;
9 | }
10 |
--------------------------------------------------------------------------------
/src/com/android/dx/rop/cst/package.html:
--------------------------------------------------------------------------------
1 |
2 | Interfaces and implementation of things related to the constant pool.
3 |
4 | PACKAGES USED:
5 |
6 | com.android.dx.rop.type
7 | com.android.dx.util
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/code/package.html:
--------------------------------------------------------------------------------
1 |
2 | Implementation of classes having to do with Java simulation, such as
3 | is needed for verification or stack-to-register conversion.
4 |
5 | PACKAGES USED:
6 |
7 | com.android.dx.rop.pool
8 | com.android.dx.util
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/package.html:
--------------------------------------------------------------------------------
1 |
2 | Implementation of containers and utilities for all the standard Java
3 | attribute types.
4 |
5 | PACKAGES USED:
6 |
7 | com.android.dx.cf.iface
8 | com.android.dx.rop.pool
9 | com.android.dx.util
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/iface/package.html:
--------------------------------------------------------------------------------
1 |
2 | Interfaces and base classes for dealing with class files. This package
3 | doesn't have any parsing but does have basic container implementations.
4 |
5 | PACKAGES USED:
6 |
7 | com.android.dx.rop.pool
8 | com.android.dx.util
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/direct/package.html:
--------------------------------------------------------------------------------
1 |
2 | Implementation of cf.iface.* based on a direct representation
3 | of class files as byte[]s.
4 |
5 | PACKAGES USED:
6 |
7 | com.android.dx.cf.attrib
8 | com.android.dx.cf.iface
9 | com.android.dx.rop.pool
10 | com.android.dx.util
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | dexfixer
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/com/android/dx/dex/cf/package.html:
--------------------------------------------------------------------------------
1 |
2 | Classes for translating Java classfiles into Dalvik classes.
3 |
4 | PACKAGES USED:
5 |
6 | com.android.dx.cf.code
7 | com.android.dx.cf.direct
8 | com.android.dx.cf.iface
9 | com.android.dx.dex.code
10 | com.android.dx.dex.file
11 | com.android.dx.rop.code
12 | com.android.dx.rop.cst
13 | com.android.dx.util
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/com/android/dx/unpacker/MethodCodeItem.java:
--------------------------------------------------------------------------------
1 | package com.android.dx.unpacker;
2 |
3 | import com.android.dex.Code;
4 |
5 | import java.nio.ByteBuffer;
6 | import java.nio.ByteOrder;
7 |
8 | public class MethodCodeItem
9 | {
10 | public int index;
11 | public String descriptor;
12 | public int size;
13 | public byte[] code;
14 |
15 | public Code getCode() {
16 | ByteBuffer data = ByteBuffer.wrap(code);
17 | data.order(ByteOrder.LITTLE_ENDIAN);
18 | int registersSize = data.getShort();
19 | int insSize = data.getShort();
20 | int outsSize = data.getShort();
21 | int triesSize = data.getShort();
22 | int debugInfoOffset = data.getInt();
23 | return new Code(registersSize, insSize, outsSize, debugInfoOffset, null, null, null);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/dexfixer.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/com/android/dx/Version.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx;
18 |
19 | /**
20 | * Version number for dx.
21 | */
22 | public class Version {
23 | /** {@code non-null;} version string */
24 | public static final String VERSION = "1.16";
25 | }
26 |
--------------------------------------------------------------------------------
/src/com/android/dex/util/ByteInput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dex.util;
18 |
19 | /**
20 | * A byte source.
21 | */
22 | public interface ByteInput {
23 |
24 | /**
25 | * Returns a byte.
26 | *
27 | * @throws IndexOutOfBoundsException if all bytes have been read.
28 | */
29 | byte readByte();
30 | }
31 |
--------------------------------------------------------------------------------
/src/com/android/dx/command/UsageException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.command;
18 |
19 | /**
20 | * Simple exception class used to communicate that the command-line tool
21 | * should print the usage message.
22 | */
23 | public class UsageException extends RuntimeException {
24 | // This space intentionally left blank.
25 | }
26 |
--------------------------------------------------------------------------------
/src/com/android/dex/util/ByteOutput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dex.util;
18 |
19 | /**
20 | * A byte sink.
21 | */
22 | public interface ByteOutput {
23 |
24 | /**
25 | * Writes a byte.
26 | *
27 | * @throws IndexOutOfBoundsException if all bytes have been written.
28 | */
29 | void writeByte(int i);
30 | }
31 |
--------------------------------------------------------------------------------
/src/com/android/dx/util/LabeledItem.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.util;
18 |
19 | /**
20 | * An item that has an integer label.
21 | */
22 | public interface LabeledItem {
23 |
24 | /*
25 | * Gets the label of this block.
26 | *
27 | * @return {@code >= 0;} the label
28 | */
29 | public int getLabel();
30 | }
31 |
--------------------------------------------------------------------------------
/src/com/android/dx/util/Warning.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.util;
18 |
19 | /**
20 | * Exception which is meant to indicate a non-fatal warning.
21 | */
22 | public class Warning extends RuntimeException {
23 | /**
24 | * Constructs an instance.
25 | *
26 | * @param message human-oriented message
27 | */
28 | public Warning(String message) {
29 | super(message);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/com/android/dex/util/ByteArrayByteInput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dex.util;
18 |
19 | public final class ByteArrayByteInput implements ByteInput {
20 |
21 | private final byte[] bytes;
22 | private int position;
23 |
24 | public ByteArrayByteInput(byte... bytes) {
25 | this.bytes = bytes;
26 | }
27 |
28 | @Override
29 | public byte readByte() {
30 | return bytes[position++];
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/com/android/dex/DexIndexOverflowException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dex;
18 |
19 | /**
20 | * Thrown when there's an index overflow writing a dex file.
21 | */
22 | public final class DexIndexOverflowException extends DexException {
23 | public DexIndexOverflowException(String message) {
24 | super(message);
25 | }
26 |
27 | public DexIndexOverflowException(Throwable cause) {
28 | super(cause);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/iface/HasAttribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.iface;
18 |
19 | /**
20 | * An element that can have {@link Attribute}
21 | */
22 | public interface HasAttribute {
23 |
24 | /**
25 | * Get the element {@code attributes} (along with
26 | * {@code attributes_count}).
27 | *
28 | * @return {@code non-null;} the attributes list
29 | */
30 | public AttributeList getAttributes();
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/com/android/dx/command/dexer/DxContext.java:
--------------------------------------------------------------------------------
1 | package com.android.dx.command.dexer;
2 |
3 | import com.android.dx.dex.cf.CodeStatistics;
4 | import com.android.dx.dex.cf.OptimizerOptions;
5 | import java.io.IOException;
6 | import java.io.OutputStream;
7 | import java.io.PrintStream;
8 |
9 | /**
10 | * State used by a single invocation of {@link Main}.
11 | */
12 | public class DxContext {
13 | public final CodeStatistics codeStatistics = new CodeStatistics();
14 | public final OptimizerOptions optimizerOptions = new OptimizerOptions();
15 | public final PrintStream out;
16 | public final PrintStream err;
17 |
18 | @SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
19 | final PrintStream noop = new PrintStream(new OutputStream() {
20 | @Override
21 | public void write(int b) throws IOException {
22 | // noop;
23 | }
24 | });
25 |
26 | public DxContext(OutputStream out, OutputStream err) {
27 | this.out = new PrintStream(out);
28 | this.err = new PrintStream(err);
29 | }
30 |
31 | public DxContext() {
32 | this(System.out, System.err);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/com/android/dex/DexException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dex;
18 |
19 | import com.android.dex.util.ExceptionWithContext;
20 |
21 | /**
22 | * Thrown when there's a format problem reading, writing, or generally
23 | * processing a dex file.
24 | */
25 | public class DexException extends ExceptionWithContext {
26 | public DexException(String message) {
27 | super(message);
28 | }
29 |
30 | public DexException(Throwable cause) {
31 | super(cause);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/com/android/dx/util/ToHuman.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.util;
18 |
19 | /**
20 | * Simple interface for objects that can return a "human" (as opposed to
21 | * a complete but often hard to read) string form.
22 | */
23 | public interface ToHuman {
24 | /**
25 | * Return the "human" string form of this instance. This is
26 | * generally less "debuggy" than {@code toString()}.
27 | *
28 | * @return {@code non-null;} the human string form
29 | */
30 | public String toHuman();
31 | }
32 |
--------------------------------------------------------------------------------
/src/com/android/dx/merge/CollisionPolicy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.merge;
18 |
19 | /**
20 | * What to do when two dex files define the same class.
21 | */
22 | public enum CollisionPolicy {
23 |
24 | /**
25 | * Keep the class def from the first dex file and discard the def from the
26 | * second dex file. This policy is appropriate for incremental builds.
27 | */
28 | KEEP_FIRST,
29 |
30 | /**
31 | * Forbid collisions. This policy is appropriate for merging libraries.
32 | */
33 | FAIL
34 | }
35 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/iface/Method.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.iface;
18 |
19 | import com.android.dx.rop.type.Prototype;
20 |
21 | /**
22 | * Interface representing methods of class files.
23 | */
24 | public interface Method
25 | extends Member
26 | {
27 | /**
28 | * Get the effective method descriptor, which includes, if
29 | * necessary, a first {@code this} parameter.
30 | *
31 | * @return {@code non-null;} the effective method descriptor
32 | */
33 | public Prototype getEffectiveDescriptor();
34 | }
35 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/code/SimException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.code;
18 |
19 | import com.android.dex.util.ExceptionWithContext;
20 |
21 | /**
22 | * Exception from simulation.
23 | */
24 | public class SimException
25 | extends ExceptionWithContext {
26 | public SimException(String message) {
27 | super(message);
28 | }
29 |
30 | public SimException(Throwable cause) {
31 | super(cause);
32 | }
33 |
34 | public SimException(String message, Throwable cause) {
35 | super(message, cause);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/iface/ParseException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.iface;
18 |
19 | import com.android.dex.util.ExceptionWithContext;
20 |
21 | /**
22 | * Exception from parsing.
23 | */
24 | public class ParseException
25 | extends ExceptionWithContext {
26 | public ParseException(String message) {
27 | super(message);
28 | }
29 |
30 | public ParseException(Throwable cause) {
31 | super(cause);
32 | }
33 |
34 | public ParseException(String message, Throwable cause) {
35 | super(message, cause);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/com/android/dx/util/IntIterator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.util;
18 |
19 | /**
20 | * An iterator for a list of ints.
21 | */
22 | public interface IntIterator {
23 |
24 | /**
25 | * Checks to see if the iterator has a next value.
26 | *
27 | * @return true if next() will succeed
28 | */
29 | boolean hasNext();
30 |
31 | /**
32 | * Returns the next value in the iterator.
33 | *
34 | * @return next value
35 | * @throws java.util.NoSuchElementException if no next element exists
36 | */
37 | int next();
38 | }
39 |
--------------------------------------------------------------------------------
/src/com/android/dx/util/MutabilityException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.util;
18 |
19 | import com.android.dex.util.ExceptionWithContext;
20 |
21 | /**
22 | * Exception due to a mutability problem.
23 | */
24 | public class MutabilityException
25 | extends ExceptionWithContext {
26 | public MutabilityException(String message) {
27 | super(message);
28 | }
29 |
30 | public MutabilityException(Throwable cause) {
31 | super(cause);
32 | }
33 |
34 | public MutabilityException(String message, Throwable cause) {
35 | super(message, cause);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/AttSynthetic.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | /**
20 | * Attribute class for standard {@code Synthetic} attributes.
21 | */
22 | public final class AttSynthetic extends BaseAttribute {
23 | /** {@code non-null;} attribute name for attributes of this type */
24 | public static final String ATTRIBUTE_NAME = "Synthetic";
25 |
26 | /**
27 | * Constructs an instance.
28 | */
29 | public AttSynthetic() {
30 | super(ATTRIBUTE_NAME);
31 | }
32 |
33 | /** {@inheritDoc} */
34 | @Override
35 | public int byteLength() {
36 | return 6;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/com/android/dx/command/grep/Main.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.command.grep;
18 |
19 | import com.android.dex.Dex;
20 | import java.io.File;
21 | import java.io.IOException;
22 | import java.io.PrintWriter;
23 | import java.util.regex.Pattern;
24 |
25 | public final class Main {
26 | public static void main(String[] args) throws IOException {
27 | String dexFile = args[0];
28 | String pattern = args[1];
29 |
30 | Dex dex = new Dex(new File(dexFile));
31 | int count = new Grep(dex, Pattern.compile(pattern), new PrintWriter(System.out)).grep();
32 | System.exit((count > 0) ? 0 : 1);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/AttDeprecated.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | /**
20 | * Attribute class for standard {@code Deprecated} attributes.
21 | */
22 | public final class AttDeprecated extends BaseAttribute {
23 | /** {@code non-null;} attribute name for attributes of this type */
24 | public static final String ATTRIBUTE_NAME = "Deprecated";
25 |
26 | /**
27 | * Constructs an instance.
28 | */
29 | public AttDeprecated() {
30 | super(ATTRIBUTE_NAME);
31 | }
32 |
33 | /** {@inheritDoc} */
34 | @Override
35 | public int byteLength() {
36 | return 6;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/iface/Field.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.iface;
18 |
19 | import com.android.dx.rop.cst.TypedConstant;
20 |
21 | /**
22 | * Interface representing fields of class files.
23 | */
24 | public interface Field
25 | extends Member {
26 | /**
27 | * Get the constant value for this field, if any. This only returns
28 | * non-{@code null} for a {@code static final} field which
29 | * includes a {@code ConstantValue} attribute.
30 | *
31 | * @return {@code null-ok;} the constant value, or {@code null} if this
32 | * field isn't a constant
33 | */
34 | public TypedConstant getConstantValue();
35 | }
36 |
--------------------------------------------------------------------------------
/src/com/android/dx/command/findusages/Main.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.command.findusages;
18 |
19 | import com.android.dex.Dex;
20 | import java.io.File;
21 | import java.io.IOException;
22 | import java.io.PrintWriter;
23 |
24 | public final class Main {
25 | public static void main(String[] args) throws IOException {
26 | String dexFile = args[0];
27 | String declaredBy = args[1];
28 | String memberName = args[2];
29 |
30 | Dex dex = new Dex(new File(dexFile));
31 | PrintWriter out = new PrintWriter(System.out);
32 | new FindUsages(dex, declaredBy, memberName, out).findUsages();
33 | out.flush();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/com/android/dx/rop/cst/CstMethodRef.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.rop.cst;
18 |
19 | /**
20 | * Constants of type {@code CONSTANT_Methodref_info}.
21 | */
22 | public final class CstMethodRef
23 | extends CstBaseMethodRef {
24 | /**
25 | * Constructs an instance.
26 | *
27 | * @param definingClass {@code non-null;} the type of the defining class
28 | * @param nat {@code non-null;} the name-and-type
29 | */
30 | public CstMethodRef(CstType definingClass, CstNat nat) {
31 | super(definingClass, nat);
32 | }
33 |
34 | /** {@inheritDoc} */
35 | @Override
36 | public String typeName() {
37 | return "method";
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/iface/Attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.iface;
18 |
19 | /**
20 | * Interface representing attributes of class files (directly or indirectly).
21 | */
22 | public interface Attribute {
23 | /**
24 | * Get the name of the attribute.
25 | *
26 | * @return {@code non-null;} the name
27 | */
28 | public String getName();
29 |
30 | /**
31 | * Get the total length of the attribute in bytes, including the
32 | * header. Since the header is always six bytes, the result of
33 | * this method is always at least {@code 6}.
34 | *
35 | * @return {@code >= 6;} the total length, in bytes
36 | */
37 | public int byteLength();
38 | }
39 |
--------------------------------------------------------------------------------
/src/com/android/dex/util/Unsigned.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dex.util;
18 |
19 | /**
20 | * Unsigned arithmetic over Java's signed types.
21 | */
22 | public final class Unsigned {
23 | private Unsigned() {}
24 |
25 | public static int compare(short ushortA, short ushortB) {
26 | if (ushortA == ushortB) {
27 | return 0;
28 | }
29 | int a = ushortA & 0xFFFF;
30 | int b = ushortB & 0xFFFF;
31 | return a < b ? -1 : 1;
32 | }
33 |
34 | public static int compare(int uintA, int uintB) {
35 | if (uintA == uintB) {
36 | return 0;
37 | }
38 | long a = uintA & 0xFFFFFFFFL;
39 | long b = uintB & 0xFFFFFFFFL;
40 | return a < b ? -1 : 1;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/AttLocalVariableTable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | import com.android.dx.cf.code.LocalVariableList;
20 |
21 | /**
22 | * Attribute class for standard {@code LocalVariableTable} attributes.
23 | */
24 | public final class AttLocalVariableTable extends BaseLocalVariables {
25 | /** {@code non-null;} attribute name for attributes of this type */
26 | public static final String ATTRIBUTE_NAME = "LocalVariableTable";
27 |
28 | /**
29 | * Constructs an instance.
30 | *
31 | * @param localVariables {@code non-null;} list of local variable entries
32 | */
33 | public AttLocalVariableTable(LocalVariableList localVariables) {
34 | super(ATTRIBUTE_NAME, localVariables);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/AttLocalVariableTypeTable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | import com.android.dx.cf.code.LocalVariableList;
20 |
21 | /**
22 | * Attribute class for standard {@code LocalVariableTypeTable} attributes.
23 | */
24 | public final class AttLocalVariableTypeTable extends BaseLocalVariables {
25 | /** {@code non-null;} attribute name for attributes of this type */
26 | public static final String ATTRIBUTE_NAME = "LocalVariableTypeTable";
27 |
28 | /**
29 | * Constructs an instance.
30 | *
31 | * @param localVariables {@code non-null;} list of local variable entries
32 | */
33 | public AttLocalVariableTypeTable(LocalVariableList localVariables) {
34 | super(ATTRIBUTE_NAME, localVariables);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/com/android/multidex/ClassPathElement.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multidex;
18 |
19 | import java.io.IOException;
20 | import java.io.InputStream;
21 |
22 | /**
23 | * An element of the class path in which class files can be found.
24 | */
25 | interface ClassPathElement {
26 |
27 | char SEPARATOR_CHAR = '/';
28 |
29 | /**
30 | * Open a "file" from this {@code ClassPathElement}.
31 | * @param path a '/' separated relative path to the wanted file.
32 | * @return an {@code InputStream} ready to read the requested file.
33 | * @throws IOException if the path can not be found or if an error occurred while opening it.
34 | */
35 | InputStream open(String path) throws IOException;
36 |
37 | void close() throws IOException;
38 |
39 | Iterable list();
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/com/android/dx/rop/annotation/AnnotationVisibility.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.rop.annotation;
18 |
19 | import com.android.dx.util.ToHuman;
20 |
21 | /**
22 | * Visibility scope of an annotation.
23 | */
24 | public enum AnnotationVisibility implements ToHuman {
25 | RUNTIME("runtime"),
26 | BUILD("build"),
27 | SYSTEM("system"),
28 | EMBEDDED("embedded");
29 |
30 | /** {@code non-null;} the human-oriented string representation */
31 | private final String human;
32 |
33 | /**
34 | * Constructs an instance.
35 | *
36 | * @param human {@code non-null;} the human-oriented string representation
37 | */
38 | private AnnotationVisibility(String human) {
39 | this.human = human;
40 | }
41 |
42 | /** {@inheritDoc} */
43 | @Override
44 | public String toHuman() {
45 | return human;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/BaseAttribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | import com.android.dx.cf.iface.Attribute;
20 |
21 | /**
22 | * Base implementation of {@link Attribute}, which directly stores
23 | * the attribute name but leaves the rest up to subclasses.
24 | */
25 | public abstract class BaseAttribute implements Attribute {
26 | /** {@code non-null;} attribute name */
27 | private final String name;
28 |
29 | /**
30 | * Constructs an instance.
31 | *
32 | * @param name {@code non-null;} attribute name
33 | */
34 | public BaseAttribute(String name) {
35 | if (name == null) {
36 | throw new NullPointerException("name == null");
37 | }
38 |
39 | this.name = name;
40 | }
41 |
42 | /** {@inheritDoc} */
43 | @Override
44 | public String getName() {
45 | return name;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/com/android/dx/io/instructions/CodeInput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.io.instructions;
18 |
19 | import java.io.EOFException;
20 |
21 | /**
22 | * Input stream of code units, for reading in Dalvik bytecode.
23 | */
24 | public interface CodeInput extends CodeCursor {
25 | /**
26 | * Returns whether there are any more code units to read. This
27 | * is analogous to {@code hasNext()} on an interator.
28 | */
29 | public boolean hasMore();
30 |
31 | /**
32 | * Reads a code unit.
33 | */
34 | public int read() throws EOFException;
35 |
36 | /**
37 | * Reads two code units, treating them as a little-endian {@code int}.
38 | */
39 | public int readInt() throws EOFException;
40 |
41 | /**
42 | * Reads four code units, treating them as a little-endian {@code long}.
43 | */
44 | public long readLong() throws EOFException;
45 | }
46 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/iface/FieldList.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.iface;
18 |
19 | /**
20 | * Interface for lists of fields.
21 | */
22 | public interface FieldList
23 | {
24 | /**
25 | * Get whether this instance is mutable. Note that the
26 | * {@code FieldList} interface itself doesn't provide any means
27 | * of mutation, but that doesn't mean that there isn't a non-interface
28 | * way of mutating an instance.
29 | *
30 | * @return {@code true} iff this instance is somehow mutable
31 | */
32 | public boolean isMutable();
33 |
34 | /**
35 | * Get the number of fields in the list.
36 | *
37 | * @return the size
38 | */
39 | public int size();
40 |
41 | /**
42 | * Get the {@code n}th field.
43 | *
44 | * @param n {@code n >= 0, n < size();} which field
45 | * @return {@code non-null;} the field in question
46 | */
47 | public Field get(int n);
48 | }
49 |
--------------------------------------------------------------------------------
/src/com/android/dx/dex/code/CatchBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.dex.code;
18 |
19 | import com.android.dx.rop.type.Type;
20 | import java.util.HashSet;
21 |
22 | /**
23 | * Interface for the construction of {@link CatchTable} instances.
24 | */
25 | public interface CatchBuilder {
26 | /**
27 | * Builds and returns the catch table for this instance.
28 | *
29 | * @return {@code non-null;} the constructed table
30 | */
31 | public CatchTable build();
32 |
33 | /**
34 | * Gets whether this instance has any catches at all (either typed
35 | * or catch-all).
36 | *
37 | * @return whether this instance has any catches at all
38 | */
39 | public boolean hasAnyCatches();
40 |
41 | /**
42 | * Gets the set of catch types associated with this instance.
43 | *
44 | * @return {@code non-null;} the set of catch types
45 | */
46 | public HashSet getCatchTypes();
47 | }
48 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/iface/MethodList.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.iface;
18 |
19 | /**
20 | * Interface for lists of methods.
21 | */
22 | public interface MethodList {
23 | /**
24 | * Get whether this instance is mutable. Note that the
25 | * {@code MethodList} interface itself doesn't provide any means
26 | * of mutation, but that doesn't mean that there isn't a non-interface
27 | * way of mutating an instance.
28 | *
29 | * @return {@code true} iff this instance is somehow mutable
30 | */
31 | public boolean isMutable();
32 |
33 | /**
34 | * Get the number of methods in the list.
35 | *
36 | * @return the size
37 | */
38 | public int size();
39 |
40 | /**
41 | * Get the {@code n}th method.
42 | *
43 | * @param n {@code n >= 0, n < size();} which method
44 | * @return {@code non-null;} the method in question
45 | */
46 | public Method get(int n);
47 | }
48 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/AttRuntimeVisibleAnnotations.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | import com.android.dx.rop.annotation.Annotations;
20 |
21 | /**
22 | * Attribute class for standard {@code RuntimeVisibleAnnotations}
23 | * attributes.
24 | */
25 | public final class AttRuntimeVisibleAnnotations extends BaseAnnotations {
26 | /** {@code non-null;} attribute name for attributes of this type */
27 | public static final String ATTRIBUTE_NAME = "RuntimeVisibleAnnotations";
28 |
29 | /**
30 | * Constructs an instance.
31 | *
32 | * @param annotations {@code non-null;} the list of annotations
33 | * @param byteLength {@code >= 0;} attribute data length in the original
34 | * classfile (not including the attribute header)
35 | */
36 | public AttRuntimeVisibleAnnotations(Annotations annotations,
37 | int byteLength) {
38 | super(ATTRIBUTE_NAME, annotations, byteLength);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/com/android/dx/util/Writers.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.util;
18 |
19 | import java.io.PrintWriter;
20 | import java.io.Writer;
21 |
22 | /**
23 | * Utilities for dealing with {@code Writer}s.
24 | */
25 | public final class Writers {
26 | /**
27 | * This class is uninstantiable.
28 | */
29 | private Writers() {
30 | // This space intentionally left blank.
31 | }
32 |
33 | /**
34 | * Makes a {@code PrintWriter} for the given {@code Writer},
35 | * returning the given writer if it already happens to be the right
36 | * class.
37 | *
38 | * @param writer {@code non-null;} writer to (possibly) wrap
39 | * @return {@code non-null;} an appropriate instance
40 | */
41 | public static PrintWriter printWriterFor(Writer writer) {
42 | if (writer instanceof PrintWriter) {
43 | return (PrintWriter) writer;
44 | }
45 |
46 | return new PrintWriter(writer);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/AttRuntimeInvisibleAnnotations.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | import com.android.dx.rop.annotation.Annotations;
20 |
21 | /**
22 | * Attribute class for standard {@code RuntimeInvisibleAnnotations}
23 | * attributes.
24 | */
25 | public final class AttRuntimeInvisibleAnnotations extends BaseAnnotations {
26 | /** {@code non-null;} attribute name for attributes of this type */
27 | public static final String ATTRIBUTE_NAME = "RuntimeInvisibleAnnotations";
28 |
29 | /**
30 | * Constructs an instance.
31 | *
32 | * @param annotations {@code non-null;} the list of annotations
33 | * @param byteLength {@code >= 0;} attribute data length in the original
34 | * classfile (not including the attribute header)
35 | */
36 | public AttRuntimeInvisibleAnnotations(Annotations annotations,
37 | int byteLength) {
38 | super(ATTRIBUTE_NAME, annotations, byteLength);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/com/android/dx/rop/cst/TypedConstant.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.rop.cst;
18 |
19 | import com.android.dx.rop.type.TypeBearer;
20 |
21 | /**
22 | * Base class for constants which implement {@link TypeBearer}.
23 | */
24 | public abstract class TypedConstant
25 | extends Constant implements TypeBearer {
26 | /**
27 | * {@inheritDoc}
28 | *
29 | * This implementation always returns {@code this}.
30 | */
31 | @Override
32 | public final TypeBearer getFrameType() {
33 | return this;
34 | }
35 |
36 | /** {@inheritDoc} */
37 | @Override
38 | public final int getBasicType() {
39 | return getType().getBasicType();
40 | }
41 |
42 | /** {@inheritDoc} */
43 | @Override
44 | public final int getBasicFrameType() {
45 | return getType().getBasicFrameType();
46 | }
47 |
48 | /** {@inheritDoc} */
49 | @Override
50 | public final boolean isConstant() {
51 | return true;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/iface/StdFieldList.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.iface;
18 |
19 | import com.android.dx.util.FixedSizeList;
20 |
21 | /**
22 | * Standard implementation of {@link FieldList}, which directly stores
23 | * an array of {@link Field} objects and can be made immutable.
24 | */
25 | public final class StdFieldList extends FixedSizeList implements FieldList {
26 | /**
27 | * Constructs an instance. All indices initially contain {@code null}.
28 | *
29 | * @param size the size of the list
30 | */
31 | public StdFieldList(int size) {
32 | super(size);
33 | }
34 |
35 | /** {@inheritDoc} */
36 | @Override
37 | public Field get(int n) {
38 | return (Field) get0(n);
39 | }
40 |
41 | /**
42 | * Sets the field at the given index.
43 | *
44 | * @param n {@code >= 0, < size();} which field
45 | * @param field {@code null-ok;} the field object
46 | */
47 | public void set(int n, Field field) {
48 | set0(n, field);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/AttRuntimeVisibleParameterAnnotations.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | import com.android.dx.rop.annotation.AnnotationsList;
20 |
21 | /**
22 | * Attribute class for standard {@code RuntimeVisibleParameterAnnotations}
23 | * attributes.
24 | */
25 | public final class AttRuntimeVisibleParameterAnnotations
26 | extends BaseParameterAnnotations {
27 | /** {@code non-null;} attribute name for attributes of this type */
28 | public static final String ATTRIBUTE_NAME =
29 | "RuntimeVisibleParameterAnnotations";
30 |
31 | /**
32 | * Constructs an instance.
33 | *
34 | * @param annotations {@code non-null;} the parameter annotations
35 | * @param byteLength {@code >= 0;} attribute data length in the original
36 | * classfile (not including the attribute header)
37 | */
38 | public AttRuntimeVisibleParameterAnnotations(
39 | AnnotationsList annotations, int byteLength) {
40 | super(ATTRIBUTE_NAME, annotations, byteLength);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/iface/StdMethodList.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.iface;
18 |
19 | import com.android.dx.util.FixedSizeList;
20 |
21 | /**
22 | * Standard implementation of {@link MethodList}, which directly stores
23 | * an array of {@link Method} objects and can be made immutable.
24 | */
25 | public final class StdMethodList extends FixedSizeList implements MethodList {
26 | /**
27 | * Constructs an instance. All indices initially contain {@code null}.
28 | *
29 | * @param size the size of the list
30 | */
31 | public StdMethodList(int size) {
32 | super(size);
33 | }
34 |
35 | /** {@inheritDoc} */
36 | @Override
37 | public Method get(int n) {
38 | return (Method) get0(n);
39 | }
40 |
41 | /**
42 | * Sets the method at the given index.
43 | *
44 | * @param n {@code >= 0, < size();} which method
45 | * @param method {@code null-ok;} the method object
46 | */
47 | public void set(int n, Method method) {
48 | set0(n, method);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/com/android/dx/io/instructions/ZeroRegisterDecodedInstruction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.io.instructions;
18 |
19 | import com.android.dx.io.IndexType;
20 |
21 | /**
22 | * A decoded Dalvik instruction which has no register arguments.
23 | */
24 | public final class ZeroRegisterDecodedInstruction extends DecodedInstruction {
25 | /**
26 | * Constructs an instance.
27 | */
28 | public ZeroRegisterDecodedInstruction(InstructionCodec format, int opcode,
29 | int index, IndexType indexType, int target, long literal) {
30 | super(format, opcode, index, indexType, target, literal);
31 | }
32 |
33 | /** {@inheritDoc} */
34 | @Override
35 | public int getRegisterCount() {
36 | return 0;
37 | }
38 |
39 | /** {@inheritDoc} */
40 | @Override
41 | public DecodedInstruction withIndex(int newIndex) {
42 | return new ZeroRegisterDecodedInstruction(
43 | getFormat(), getOpcode(), newIndex, getIndexType(),
44 | getTarget(), getLiteral());
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/com/android/dex/CallSiteId.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dex;
18 |
19 | import com.android.dex.Dex.Section;
20 | import com.android.dex.util.Unsigned;
21 |
22 | /**
23 | * A call_site_id_item: https://source.android.com/devices/tech/dalvik/dex-format#call-site-id-item
24 | */
25 | public class CallSiteId implements Comparable {
26 |
27 | private final Dex dex;
28 | private final int offset;
29 |
30 | public CallSiteId(Dex dex, int offset) {
31 | this.dex = dex;
32 | this.offset = offset;
33 | }
34 |
35 | @Override
36 | public int compareTo(CallSiteId o) {
37 | return Unsigned.compare(offset, o.offset);
38 | }
39 |
40 | public int getCallSiteOffset() {
41 | return offset;
42 | }
43 |
44 | public void writeTo(Section out) {
45 | out.writeInt(offset);
46 | }
47 |
48 | @Override
49 | public String toString() {
50 | if (dex == null) {
51 | return String.valueOf(offset);
52 | }
53 | return dex.protoIds().get(offset).toString();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/com/android/dx/io/instructions/AddressMap.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.io.instructions;
18 |
19 | import java.util.HashMap;
20 |
21 | /**
22 | * Map from addresses to addresses, where addresses are all
23 | * {@code int}s.
24 | */
25 | public final class AddressMap {
26 | /** underlying map. TODO: This might be too inefficient. */
27 | private final HashMap map;
28 |
29 | /**
30 | * Constructs an instance.
31 | */
32 | public AddressMap() {
33 | map = new HashMap();
34 | }
35 |
36 | /**
37 | * Gets the value address corresponding to the given key address. Returns
38 | * {@code -1} if there is no mapping.
39 | */
40 | public int get(int keyAddress) {
41 | Integer value = map.get(keyAddress);
42 | return (value == null) ? -1 : value;
43 | }
44 |
45 | /**
46 | * Sets the value address associated with the given key address.
47 | */
48 | public void put(int keyAddress, int valueAddress) {
49 | map.put(keyAddress, valueAddress);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/AttRuntimeInvisibleParameterAnnotations.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | import com.android.dx.rop.annotation.AnnotationsList;
20 |
21 | /**
22 | * Attribute class for standard
23 | * {@code RuntimeInvisibleParameterAnnotations} attributes.
24 | */
25 | public final class AttRuntimeInvisibleParameterAnnotations
26 | extends BaseParameterAnnotations {
27 | /** {@code non-null;} attribute name for attributes of this type */
28 | public static final String ATTRIBUTE_NAME =
29 | "RuntimeInvisibleParameterAnnotations";
30 |
31 | /**
32 | * Constructs an instance.
33 | *
34 | * @param parameterAnnotations {@code non-null;} the parameter annotations
35 | * @param byteLength {@code >= 0;} attribute data length in the original
36 | * classfile (not including the attribute header)
37 | */
38 | public AttRuntimeInvisibleParameterAnnotations(
39 | AnnotationsList parameterAnnotations, int byteLength) {
40 | super(ATTRIBUTE_NAME, parameterAnnotations, byteLength);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/cst/MethodHandleKind.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.cst;
18 |
19 | /**
20 | * Method Handle kinds for {@code CONSTANT_MethodHandle_info} constants.
21 | */
22 | public interface MethodHandleKind {
23 | /** A method handle that gets an instance field. */
24 | int REF_getField = 1;
25 |
26 | /** A method handle that gets a static field. */
27 | int REF_getStatic = 2;
28 |
29 | /** A method handle that sets an instance field. */
30 | int REF_putField = 3;
31 |
32 | /** A method handle that sets a static field. */
33 | int REF_putStatic = 4;
34 |
35 | /** A method handle for {@code invokevirtual}. */
36 | int REF_invokeVirtual = 5;
37 |
38 | /** A method handle for {@code invokestatic}. */
39 | int REF_invokeStatic = 6;
40 |
41 | /** A method handle for {@code invokespecial}. */
42 | int REF_invokeSpecial = 7;
43 |
44 | /** A method handle for invoking a constructor. */
45 | int REF_newInvokeSpecial = 8;
46 |
47 | /** A method handle for {@code invokeinterface}. */
48 | int REF_invokeInterface = 9;
49 | }
50 |
--------------------------------------------------------------------------------
/src/com/android/dx/dex/cf/CfOptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.dex.cf;
18 |
19 | import com.android.dx.dex.code.PositionList;
20 | import java.io.PrintStream;
21 |
22 | /**
23 | * A class to contain options passed into dex.cf
24 | */
25 | public class CfOptions {
26 | /** how much source position info to preserve */
27 | public int positionInfo = PositionList.LINES;
28 |
29 | /** whether to keep local variable information */
30 | public boolean localInfo = false;
31 |
32 | /** whether strict file-name-vs-class-name checking should be done */
33 | public boolean strictNameCheck = true;
34 |
35 | /** whether to do SSA/register optimization */
36 | public boolean optimize = false;
37 |
38 | /** filename containing list of methods to optimize */
39 | public String optimizeListFile = null;
40 |
41 | /** filename containing list of methods not to optimize */
42 | public String dontOptimizeListFile = null;
43 |
44 | /** whether to print statistics to stdout at end of compile cycle */
45 | public boolean statistics;
46 |
47 | /** where to issue warnings to */
48 | public PrintStream warn = System.err;
49 | }
50 |
--------------------------------------------------------------------------------
/src/com/android/dx/command/dump/Args.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.command.dump;
18 |
19 | /**
20 | * contains command line parsedArgs values
21 | */
22 | class Args {
23 | /** whether to run in debug mode */
24 | boolean debug = false;
25 |
26 | /** whether to dump raw bytes where salient */
27 | boolean rawBytes = false;
28 |
29 | /** whether to dump information about basic blocks */
30 | boolean basicBlocks = false;
31 |
32 | /** whether to dump regiserized blocks */
33 | boolean ropBlocks = false;
34 |
35 | /** whether to dump SSA-form blocks */
36 | boolean ssaBlocks = false;
37 |
38 | /** Step in SSA processing to stop at, or null for all */
39 | String ssaStep = null;
40 |
41 | /** whether to run SSA optimizations */
42 | boolean optimize = false;
43 |
44 | /** whether to be strict about parsing classfiles*/
45 | boolean strictParse = false;
46 |
47 | /** max width for columnar output */
48 | int width = 0;
49 |
50 | /** whether to dump flow-graph in "dot" format */
51 | boolean dotDump = false;
52 |
53 | /** if non-null, an explicit method to dump */
54 | String method;
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/com/android/dx/dex/code/VariableSizeInsn.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.dex.code;
18 |
19 | import com.android.dx.rop.code.RegisterSpecList;
20 | import com.android.dx.rop.code.SourcePosition;
21 |
22 | /**
23 | * Pseudo-instruction base class for variable-sized instructions.
24 | */
25 | public abstract class VariableSizeInsn extends DalvInsn {
26 | /**
27 | * Constructs an instance. The output address of this instance is initially
28 | * unknown ({@code -1}).
29 | *
30 | * @param position {@code non-null;} source position
31 | * @param registers {@code non-null;} source registers
32 | */
33 | public VariableSizeInsn(SourcePosition position,
34 | RegisterSpecList registers) {
35 | super(Dops.SPECIAL_FORMAT, position, registers);
36 | }
37 |
38 | /** {@inheritDoc} */
39 | @Override
40 | public final DalvInsn withOpcode(Dop opcode) {
41 | throw new RuntimeException("unsupported");
42 | }
43 |
44 | /** {@inheritDoc} */
45 | @Override
46 | public final DalvInsn withRegisterOffset(int delta) {
47 | return withRegisters(getRegisters().withOffset(delta));
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/com/android/dx/io/instructions/CodeCursor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.io.instructions;
18 |
19 | /**
20 | * Cursor over code units, for reading or writing out Dalvik bytecode.
21 | */
22 | public interface CodeCursor {
23 | /**
24 | * Gets the cursor. The cursor is the offset in code units from
25 | * the start of the input of the next code unit to be read or
26 | * written, where the input generally consists of the code for a
27 | * single method.
28 | */
29 | public int cursor();
30 |
31 | /**
32 | * Gets the base address associated with the current cursor. This
33 | * differs from the cursor value when explicitly set (by {@link
34 | * #setBaseAddress}). This is used, in particular, to convey base
35 | * addresses to switch data payload instructions, whose relative
36 | * addresses are relative to the address of a dependant switch
37 | * instruction.
38 | */
39 | public int baseAddressForCursor();
40 |
41 | /**
42 | * Sets the base address for the given target address to be as indicated.
43 | *
44 | * @see #baseAddressForCursor
45 | */
46 | public void setBaseAddress(int targetAddress, int baseAddress);
47 | }
48 |
--------------------------------------------------------------------------------
/src/com/android/dx/util/IntSet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.util;
18 |
19 | /**
20 | * A set of integers
21 | */
22 | public interface IntSet {
23 |
24 | /**
25 | * Adds an int to a set
26 | *
27 | * @param value int to add
28 | */
29 | void add(int value);
30 |
31 | /**
32 | * Removes an int from a set.
33 | *
34 | * @param value int to remove
35 | */
36 | void remove(int value);
37 |
38 | /**
39 | * Checks to see if a value is in the set
40 | *
41 | * @param value int to check
42 | * @return true if in set
43 | */
44 | boolean has(int value);
45 |
46 | /**
47 | * Merges {@code other} into this set, so this set becomes the
48 | * union of the two.
49 | *
50 | * @param other {@code non-null;} other set to merge with.
51 | */
52 | void merge(IntSet other);
53 |
54 | /**
55 | * Returns the count of unique elements in this set.
56 | *
57 | * @return {@code > = 0;} count of unique elements
58 | */
59 | int elements();
60 |
61 | /**
62 | * Iterates the set
63 | *
64 | * @return {@code non-null;} a set iterator
65 | */
66 | IntIterator iterator();
67 | }
68 |
--------------------------------------------------------------------------------
/src/com/android/dex/EncodedValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dex;
18 |
19 | import com.android.dex.util.ByteArrayByteInput;
20 | import com.android.dex.util.ByteInput;
21 |
22 | /**
23 | * An encoded value or array.
24 | */
25 | public final class EncodedValue implements Comparable {
26 | private final byte[] data;
27 |
28 | public EncodedValue(byte[] data) {
29 | this.data = data;
30 | }
31 |
32 | public ByteInput asByteInput() {
33 | return new ByteArrayByteInput(data);
34 | }
35 |
36 | public byte[] getBytes() {
37 | return data;
38 | }
39 |
40 | public void writeTo(Dex.Section out) {
41 | out.write(data);
42 | }
43 |
44 | @Override
45 | public int compareTo(EncodedValue other) {
46 | int size = Math.min(data.length, other.data.length);
47 | for (int i = 0; i < size; i++) {
48 | if (data[i] != other.data[i]) {
49 | return (data[i] & 0xff) - (other.data[i] & 0xff);
50 | }
51 | }
52 | return data.length - other.data.length;
53 | }
54 |
55 | @Override
56 | public String toString() {
57 | return Integer.toHexString(data[0] & 0xff) + "...(" + data.length + ")";
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/com/android/dx/rop/code/ConservativeTranslationAdvice.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.rop.code;
18 |
19 | /**
20 | * Implementation of {@link TranslationAdvice} which conservatively answers
21 | * {@code false} to all methods.
22 | */
23 | public final class ConservativeTranslationAdvice
24 | implements TranslationAdvice {
25 | /** {@code non-null;} standard instance of this class */
26 | public static final ConservativeTranslationAdvice THE_ONE =
27 | new ConservativeTranslationAdvice();
28 |
29 | /**
30 | * This class is not publicly instantiable. Use {@link #THE_ONE}.
31 | */
32 | private ConservativeTranslationAdvice() {
33 | // This space intentionally left blank.
34 | }
35 |
36 | /** {@inheritDoc} */
37 | @Override
38 | public boolean hasConstantOperation(Rop opcode,
39 | RegisterSpec sourceA, RegisterSpec sourceB) {
40 | return false;
41 | }
42 |
43 | /** {@inheritDoc} */
44 | @Override
45 | public boolean requiresSourcesInOrder(Rop opcode,
46 | RegisterSpecList sources) {
47 | return false;
48 | }
49 |
50 | /** {@inheritDoc} */
51 | @Override
52 | public int getMaxOptimalRegisterCount() {
53 | return Integer.MAX_VALUE;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/AttSignature.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | import com.android.dx.rop.cst.CstString;
20 |
21 | /**
22 | * Attribute class for standards-track {@code Signature} attributes.
23 | */
24 | public final class AttSignature extends BaseAttribute {
25 | /** {@code non-null;} attribute name for attributes of this type */
26 | public static final String ATTRIBUTE_NAME = "Signature";
27 |
28 | /** {@code non-null;} the signature string */
29 | private final CstString signature;
30 |
31 | /**
32 | * Constructs an instance.
33 | *
34 | * @param signature {@code non-null;} the signature string
35 | */
36 | public AttSignature(CstString signature) {
37 | super(ATTRIBUTE_NAME);
38 |
39 | if (signature == null) {
40 | throw new NullPointerException("signature == null");
41 | }
42 |
43 | this.signature = signature;
44 | }
45 |
46 | /** {@inheritDoc} */
47 | @Override
48 | public int byteLength() {
49 | return 8;
50 | }
51 |
52 | /**
53 | * Gets the signature string.
54 | *
55 | * @return {@code non-null;} the signature string
56 | */
57 | public CstString getSignature() {
58 | return signature;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/com/android/dx/dex/file/IdItem.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.dex.file;
18 |
19 | import com.android.dx.rop.cst.CstType;
20 |
21 | /**
22 | * Representation of a reference to an item inside a Dalvik file.
23 | */
24 | public abstract class IdItem extends IndexedItem {
25 | /**
26 | * {@code non-null;} the type constant for the defining class of
27 | * the reference
28 | */
29 | private final CstType type;
30 |
31 | /**
32 | * Constructs an instance.
33 | *
34 | * @param type {@code non-null;} the type constant for the defining
35 | * class of the reference
36 | */
37 | public IdItem(CstType type) {
38 | if (type == null) {
39 | throw new NullPointerException("type == null");
40 | }
41 |
42 | this.type = type;
43 | }
44 |
45 | /** {@inheritDoc} */
46 | @Override
47 | public void addContents(DexFile file) {
48 | TypeIdsSection typeIds = file.getTypeIds();
49 | typeIds.intern(type);
50 | }
51 |
52 | /**
53 | * Gets the type constant for the defining class of the
54 | * reference.
55 | *
56 | * @return {@code non-null;} the type constant
57 | */
58 | public final CstType getDefiningClass() {
59 | return type;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/com/android/dx/io/instructions/OneRegisterDecodedInstruction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.io.instructions;
18 |
19 | import com.android.dx.io.IndexType;
20 |
21 | /**
22 | * A decoded Dalvik instruction which has one register argument.
23 | */
24 | public final class OneRegisterDecodedInstruction extends DecodedInstruction {
25 | /** register argument "A" */
26 | private final int a;
27 |
28 | /**
29 | * Constructs an instance.
30 | */
31 | public OneRegisterDecodedInstruction(InstructionCodec format, int opcode,
32 | int index, IndexType indexType, int target, long literal,
33 | int a) {
34 | super(format, opcode, index, indexType, target, literal);
35 |
36 | this.a = a;
37 | }
38 |
39 | /** {@inheritDoc} */
40 | @Override
41 | public int getRegisterCount() {
42 | return 1;
43 | }
44 |
45 | /** {@inheritDoc} */
46 | @Override
47 | public int getA() {
48 | return a;
49 | }
50 |
51 | /** {@inheritDoc} */
52 | @Override
53 | public DecodedInstruction withIndex(int newIndex) {
54 | return new OneRegisterDecodedInstruction(
55 | getFormat(), getOpcode(), newIndex, getIndexType(),
56 | getTarget(), getLiteral(), a);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/com/android/dx/ssa/back/NullRegisterAllocator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.ssa.back;
18 |
19 | import com.android.dx.ssa.BasicRegisterMapper;
20 | import com.android.dx.ssa.RegisterMapper;
21 | import com.android.dx.ssa.SsaMethod;
22 |
23 | /**
24 | * A register allocator that maps SSA register n to Rop register 2*n,
25 | * essentially preserving the original mapping and remaining agnostic
26 | * about normal or wide categories. Used for debugging.
27 | */
28 | public class NullRegisterAllocator extends RegisterAllocator {
29 | /** {@inheritDoc} */
30 | public NullRegisterAllocator(SsaMethod ssaMeth,
31 | InterferenceGraph interference) {
32 | super(ssaMeth, interference);
33 | }
34 |
35 | /** {@inheritDoc} */
36 | @Override
37 | public boolean wantsParamsMovedHigh() {
38 | // We're not smart enough for this.
39 | return false;
40 | }
41 |
42 | /** {@inheritDoc} */
43 | @Override
44 | public RegisterMapper allocateRegisters() {
45 | int oldRegCount = ssaMeth.getRegCount();
46 |
47 | BasicRegisterMapper mapper = new BasicRegisterMapper(oldRegCount);
48 |
49 | for (int i = 0; i < oldRegCount; i++) {
50 | mapper.addMapping(i, i*2, 2);
51 | }
52 |
53 | return mapper;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/AttSourceFile.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | import com.android.dx.rop.cst.CstString;
20 |
21 | /**
22 | * Attribute class for standard {@code SourceFile} attributes.
23 | */
24 | public final class AttSourceFile extends BaseAttribute {
25 | /** {@code non-null;} attribute name for attributes of this type */
26 | public static final String ATTRIBUTE_NAME = "SourceFile";
27 |
28 | /** {@code non-null;} name of the source file */
29 | private final CstString sourceFile;
30 |
31 | /**
32 | * Constructs an instance.
33 | *
34 | * @param sourceFile {@code non-null;} the name of the source file
35 | */
36 | public AttSourceFile(CstString sourceFile) {
37 | super(ATTRIBUTE_NAME);
38 |
39 | if (sourceFile == null) {
40 | throw new NullPointerException("sourceFile == null");
41 | }
42 |
43 | this.sourceFile = sourceFile;
44 | }
45 |
46 | /** {@inheritDoc} */
47 | @Override
48 | public int byteLength() {
49 | return 8;
50 | }
51 |
52 | /**
53 | * Gets the source file name of this instance.
54 | *
55 | * @return {@code non-null;} the source file
56 | */
57 | public CstString getSourceFile() {
58 | return sourceFile;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/com/android/dx/dex/file/HeaderSection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.dex.file;
18 |
19 | import com.android.dx.rop.cst.Constant;
20 | import java.util.Collection;
21 | import java.util.Collections;
22 | import java.util.List;
23 |
24 | /**
25 | * File header section of a {@code .dex} file.
26 | */
27 | public final class HeaderSection extends UniformItemSection {
28 | /** {@code non-null;} the list of the one item in the section */
29 | private final List list;
30 |
31 | /**
32 | * Constructs an instance. The file offset is initially unknown.
33 | *
34 | * @param file {@code non-null;} file that this instance is part of
35 | */
36 | public HeaderSection(DexFile file) {
37 | super(null, file, 4);
38 |
39 | HeaderItem item = new HeaderItem();
40 | item.setIndex(0);
41 |
42 | this.list = Collections.singletonList(item);
43 | }
44 |
45 | /** {@inheritDoc} */
46 | @Override
47 | public IndexedItem get(Constant cst) {
48 | return null;
49 | }
50 |
51 | /** {@inheritDoc} */
52 | @Override
53 | public Collection extends Item> items() {
54 | return list;
55 | }
56 |
57 | /** {@inheritDoc} */
58 | @Override
59 | protected void orderItems() {
60 | // Nothing to do here.
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/com/android/dx/io/IndexType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.io;
18 |
19 | /**
20 | * The various types that an index in a Dalvik instruction might refer to.
21 | */
22 | public enum IndexType {
23 | /** "Unknown." Used for undefined opcodes. */
24 | UNKNOWN,
25 |
26 | /** no index used */
27 | NONE,
28 |
29 | /** "It depends." Used for {@code throw-verification-error}. */
30 | VARIES,
31 |
32 | /** type reference index */
33 | TYPE_REF,
34 |
35 | /** string reference index */
36 | STRING_REF,
37 |
38 | /** method reference index */
39 | METHOD_REF,
40 |
41 | /** field reference index */
42 | FIELD_REF,
43 |
44 | /** method index and a proto index */
45 | METHOD_AND_PROTO_REF,
46 |
47 | /** call site reference index */
48 | CALL_SITE_REF,
49 |
50 | /** inline method index (for inline linked method invocations) */
51 | INLINE_METHOD,
52 |
53 | /** direct vtable offset (for static linked method invocations) */
54 | VTABLE_OFFSET,
55 |
56 | /** direct field offset (for static linked field accesses) */
57 | FIELD_OFFSET,
58 |
59 | /** method handle reference index (for loading constant method handles) */
60 | METHOD_HANDLE_REF,
61 |
62 | /** proto reference index (for loading constant proto ref) */
63 | PROTO_REF;
64 | }
65 |
--------------------------------------------------------------------------------
/src/com/android/dex/TypeList.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dex;
18 |
19 | import com.android.dex.util.Unsigned;
20 |
21 | public final class TypeList implements Comparable {
22 |
23 | public static final TypeList EMPTY = new TypeList(null, Dex.EMPTY_SHORT_ARRAY);
24 |
25 | private final Dex dex;
26 | private final short[] types;
27 |
28 | public TypeList(Dex dex, short[] types) {
29 | this.dex = dex;
30 | this.types = types;
31 | }
32 |
33 | public short[] getTypes() {
34 | return types;
35 | }
36 |
37 | @Override
38 | public int compareTo(TypeList other) {
39 | for (int i = 0; i < types.length && i < other.types.length; i++) {
40 | if (types[i] != other.types[i]) {
41 | return Unsigned.compare(types[i], other.types[i]);
42 | }
43 | }
44 | return Unsigned.compare(types.length, other.types.length);
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | StringBuilder result = new StringBuilder();
50 | result.append("(");
51 | for (int i = 0, typesLength = types.length; i < typesLength; i++) {
52 | result.append(dex != null ? dex.typeNames().get(types[i]) : types[i]);
53 | }
54 | result.append(")");
55 | return result.toString();
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/com/android/dx/io/instructions/BaseCodeCursor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.io.instructions;
18 |
19 | /**
20 | * Base implementation of {@link CodeCursor}.
21 | */
22 | public abstract class BaseCodeCursor implements CodeCursor {
23 | /** base address map */
24 | private final AddressMap baseAddressMap;
25 |
26 | /** next index within {@link #baseAddressMap} to read from or write to */
27 | private int cursor;
28 |
29 | /**
30 | * Constructs an instance.
31 | */
32 | public BaseCodeCursor() {
33 | this.baseAddressMap = new AddressMap();
34 | this.cursor = 0;
35 | }
36 |
37 | /** {@inheritDoc} */
38 | @Override
39 | public final int cursor() {
40 | return cursor;
41 | }
42 |
43 | /** {@inheritDoc} */
44 | @Override
45 | public final int baseAddressForCursor() {
46 | int mapped = baseAddressMap.get(cursor);
47 | return (mapped >= 0) ? mapped : cursor;
48 | }
49 |
50 | /** {@inheritDoc} */
51 | @Override
52 | public final void setBaseAddress(int targetAddress, int baseAddress) {
53 | baseAddressMap.put(targetAddress, baseAddress);
54 | }
55 |
56 | /**
57 | * Advance the cursor by the indicated amount.
58 | */
59 | protected final void advance(int amount) {
60 | cursor += amount;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/com/android/dx/rop/cst/CstInterfaceMethodRef.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.rop.cst;
18 |
19 | /**
20 | * Constants of type {@code CONSTANT_InterfaceMethodref_info}.
21 | */
22 | public final class CstInterfaceMethodRef
23 | extends CstBaseMethodRef {
24 | /**
25 | * {@code null-ok;} normal {@link CstMethodRef} that corresponds to this
26 | * instance, if calculated
27 | */
28 | private CstMethodRef methodRef;
29 |
30 | /**
31 | * Constructs an instance.
32 | *
33 | * @param definingClass {@code non-null;} the type of the defining class
34 | * @param nat {@code non-null;} the name-and-type
35 | */
36 | public CstInterfaceMethodRef(CstType definingClass, CstNat nat) {
37 | super(definingClass, nat);
38 | methodRef = null;
39 | }
40 |
41 | /** {@inheritDoc} */
42 | @Override
43 | public String typeName() {
44 | return "ifaceMethod";
45 | }
46 |
47 | /**
48 | * Gets a normal (non-interface) {@link CstMethodRef} that corresponds to
49 | * this instance.
50 | *
51 | * @return {@code non-null;} an appropriate instance
52 | */
53 | public CstMethodRef toMethodRef() {
54 | if (methodRef == null) {
55 | methodRef = new CstMethodRef(getDefiningClass(), getNat());
56 | }
57 |
58 | return methodRef;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/iface/StdField.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.iface;
18 |
19 | import com.android.dx.cf.attrib.AttConstantValue;
20 | import com.android.dx.rop.cst.CstNat;
21 | import com.android.dx.rop.cst.CstType;
22 | import com.android.dx.rop.cst.TypedConstant;
23 |
24 | /**
25 | * Standard implementation of {@link Field}, which directly stores
26 | * all the associated data.
27 | */
28 | public final class StdField extends StdMember implements Field {
29 | /**
30 | * Constructs an instance.
31 | *
32 | * @param definingClass {@code non-null;} the defining class
33 | * @param accessFlags access flags
34 | * @param nat {@code non-null;} member name and type (descriptor)
35 | * @param attributes {@code non-null;} list of associated attributes
36 | */
37 | public StdField(CstType definingClass, int accessFlags, CstNat nat,
38 | AttributeList attributes) {
39 | super(definingClass, accessFlags, nat, attributes);
40 | }
41 |
42 | /** {@inheritDoc} */
43 | @Override
44 | public TypedConstant getConstantValue() {
45 | AttributeList attribs = getAttributes();
46 | AttConstantValue cval = (AttConstantValue)
47 | attribs.findFirst(AttConstantValue.ATTRIBUTE_NAME);
48 |
49 | if (cval == null) {
50 | return null;
51 | }
52 |
53 | return cval.getConstantValue();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/com/android/dx/io/instructions/PackedSwitchPayloadDecodedInstruction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.io.instructions;
18 |
19 | /**
20 | * A decoded Dalvik instruction which contains the payload for
21 | * a {@code packed-switch} instruction.
22 | */
23 | public final class PackedSwitchPayloadDecodedInstruction
24 | extends DecodedInstruction {
25 | /** first key value */
26 | private final int firstKey;
27 |
28 | /**
29 | * array of target addresses. These are absolute, not relative,
30 | * addresses.
31 | */
32 | private final int[] targets;
33 |
34 | /**
35 | * Constructs an instance.
36 | */
37 | public PackedSwitchPayloadDecodedInstruction(InstructionCodec format,
38 | int opcode, int firstKey, int[] targets) {
39 | super(format, opcode, 0, null, 0, 0L);
40 |
41 | this.firstKey = firstKey;
42 | this.targets = targets;
43 | }
44 |
45 | /** {@inheritDoc} */
46 | @Override
47 | public int getRegisterCount() {
48 | return 0;
49 | }
50 |
51 | public int getFirstKey() {
52 | return firstKey;
53 | }
54 |
55 | public int[] getTargets() {
56 | return targets;
57 | }
58 |
59 | /** {@inheritDoc} */
60 | @Override
61 | public DecodedInstruction withIndex(int newIndex) {
62 | throw new UnsupportedOperationException("no index in instruction");
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/com/android/multidex/FolderPathElement.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multidex;
18 |
19 | import java.io.File;
20 | import java.io.FileInputStream;
21 | import java.io.FileNotFoundException;
22 | import java.io.InputStream;
23 | import java.util.ArrayList;
24 |
25 | /**
26 | * A folder element.
27 | */
28 | class FolderPathElement implements ClassPathElement {
29 |
30 | private final File baseFolder;
31 |
32 | public FolderPathElement(File baseFolder) {
33 | this.baseFolder = baseFolder;
34 | }
35 |
36 | @Override
37 | public InputStream open(String path) throws FileNotFoundException {
38 | return new FileInputStream(new File(baseFolder,
39 | path.replace(SEPARATOR_CHAR, File.separatorChar)));
40 | }
41 |
42 | @Override
43 | public void close() {
44 | }
45 |
46 | @Override
47 | public Iterable list() {
48 | ArrayList result = new ArrayList();
49 | collect(baseFolder, "", result);
50 | return result;
51 | }
52 |
53 | private void collect(File folder, String prefix, ArrayList result) {
54 | for (File file : folder.listFiles()) {
55 | if (file.isDirectory()) {
56 | collect(file, prefix + SEPARATOR_CHAR + file.getName(), result);
57 | } else {
58 | result.add(prefix + SEPARATOR_CHAR + file.getName());
59 | }
60 | }
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/com/android/dx/rop/cst/Zeroes.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.rop.cst;
18 |
19 | import com.android.dx.rop.type.Type;
20 |
21 | /**
22 | * Utility for turning types into zeroes.
23 | */
24 | public final class Zeroes {
25 | /**
26 | * This class is uninstantiable.
27 | */
28 | private Zeroes() {
29 | // This space intentionally left blank.
30 | }
31 |
32 | /**
33 | * Gets the "zero" (or {@code null}) value for the given type.
34 | *
35 | * @param type {@code non-null;} the type in question
36 | * @return {@code non-null;} its "zero" value
37 | */
38 | public static Constant zeroFor(Type type) {
39 | switch (type.getBasicType()) {
40 | case Type.BT_BOOLEAN: return CstBoolean.VALUE_FALSE;
41 | case Type.BT_BYTE: return CstByte.VALUE_0;
42 | case Type.BT_CHAR: return CstChar.VALUE_0;
43 | case Type.BT_DOUBLE: return CstDouble.VALUE_0;
44 | case Type.BT_FLOAT: return CstFloat.VALUE_0;
45 | case Type.BT_INT: return CstInteger.VALUE_0;
46 | case Type.BT_LONG: return CstLong.VALUE_0;
47 | case Type.BT_SHORT: return CstShort.VALUE_0;
48 | case Type.BT_OBJECT: return CstKnownNull.THE_ONE;
49 | default: {
50 | throw new UnsupportedOperationException("no zero for type: " +
51 | type.toHuman());
52 | }
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/com/android/dx/dex/file/FieldIdItem.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.dex.file;
18 |
19 | import com.android.dx.rop.cst.CstFieldRef;
20 |
21 | /**
22 | * Representation of a field reference inside a Dalvik file.
23 | */
24 | public final class FieldIdItem extends MemberIdItem {
25 | /**
26 | * Constructs an instance.
27 | *
28 | * @param field {@code non-null;} the constant for the field
29 | */
30 | public FieldIdItem(CstFieldRef field) {
31 | super(field);
32 | }
33 |
34 | /** {@inheritDoc} */
35 | @Override
36 | public ItemType itemType() {
37 | return ItemType.TYPE_FIELD_ID_ITEM;
38 | }
39 |
40 | /** {@inheritDoc} */
41 | @Override
42 | public void addContents(DexFile file) {
43 | super.addContents(file);
44 |
45 | TypeIdsSection typeIds = file.getTypeIds();
46 | typeIds.intern(getFieldRef().getType());
47 | }
48 |
49 | /**
50 | * Gets the field constant.
51 | *
52 | * @return {@code non-null;} the constant
53 | */
54 | public CstFieldRef getFieldRef() {
55 | return (CstFieldRef) getRef();
56 | }
57 |
58 | /** {@inheritDoc} */
59 | @Override
60 | protected int getTypoidIdx(DexFile file) {
61 | TypeIdsSection typeIds = file.getTypeIds();
62 | return typeIds.indexOf(getFieldRef().getType());
63 | }
64 |
65 | /** {@inheritDoc} */
66 | @Override
67 | protected String getTypoidName() {
68 | return "type_idx";
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/com/android/dx/dex/code/ZeroSizeInsn.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.dex.code;
18 |
19 | import com.android.dx.rop.code.RegisterSpecList;
20 | import com.android.dx.rop.code.SourcePosition;
21 | import com.android.dx.util.AnnotatedOutput;
22 |
23 | /**
24 | * Pseudo-instruction base class for zero-size (no code emitted)
25 | * instructions, which are generally used for tracking metainformation
26 | * about the code they are adjacent to.
27 | */
28 | public abstract class ZeroSizeInsn extends DalvInsn {
29 | /**
30 | * Constructs an instance. The output address of this instance is initially
31 | * unknown ({@code -1}).
32 | *
33 | * @param position {@code non-null;} source position
34 | */
35 | public ZeroSizeInsn(SourcePosition position) {
36 | super(Dops.SPECIAL_FORMAT, position, RegisterSpecList.EMPTY);
37 | }
38 |
39 | /** {@inheritDoc} */
40 | @Override
41 | public final int codeSize() {
42 | return 0;
43 | }
44 |
45 | /** {@inheritDoc} */
46 | @Override
47 | public final void writeTo(AnnotatedOutput out) {
48 | // Nothing to do here, for this class.
49 | }
50 |
51 | /** {@inheritDoc} */
52 | @Override
53 | public final DalvInsn withOpcode(Dop opcode) {
54 | throw new RuntimeException("unsupported");
55 | }
56 |
57 | /** {@inheritDoc} */
58 | @Override
59 | public DalvInsn withRegisterOffset(int delta) {
60 | return withRegisters(getRegisters().withOffset(delta));
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/com/android/dx/io/instructions/TwoRegisterDecodedInstruction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.io.instructions;
18 |
19 | import com.android.dx.io.IndexType;
20 |
21 | /**
22 | * A decoded Dalvik instruction which has two register arguments.
23 | */
24 | public final class TwoRegisterDecodedInstruction extends DecodedInstruction {
25 | /** register argument "A" */
26 | private final int a;
27 |
28 | /** register argument "B" */
29 | private final int b;
30 |
31 | /**
32 | * Constructs an instance.
33 | */
34 | public TwoRegisterDecodedInstruction(InstructionCodec format, int opcode,
35 | int index, IndexType indexType, int target, long literal,
36 | int a, int b) {
37 | super(format, opcode, index, indexType, target, literal);
38 |
39 | this.a = a;
40 | this.b = b;
41 | }
42 |
43 | /** {@inheritDoc} */
44 | @Override
45 | public int getRegisterCount() {
46 | return 2;
47 | }
48 |
49 | /** {@inheritDoc} */
50 | @Override
51 | public int getA() {
52 | return a;
53 | }
54 |
55 | /** {@inheritDoc} */
56 | @Override
57 | public int getB() {
58 | return b;
59 | }
60 |
61 | /** {@inheritDoc} */
62 | @Override
63 | public DecodedInstruction withIndex(int newIndex) {
64 | return new TwoRegisterDecodedInstruction(
65 | getFormat(), getOpcode(), newIndex, getIndexType(),
66 | getTarget(), getLiteral(), a, b);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/AttSourceDebugExtension.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | import com.android.dx.rop.cst.CstString;
20 |
21 | /**
22 | * Attribute class for standard {@code SourceDebugExtension} attributes.
23 | */
24 | public final class AttSourceDebugExtension extends BaseAttribute {
25 | /** {@code non-null;} attribute name for attributes of this type */
26 | public static final String ATTRIBUTE_NAME = "SourceDebugExtension";
27 |
28 | /** {@code non-null;} Contents of SMAP */
29 | private final CstString smapString;
30 |
31 | /**
32 | * Constructs an instance.
33 | *
34 | * @param smapString {@code non-null;} the SMAP data from the class file.
35 | */
36 | public AttSourceDebugExtension(CstString smapString) {
37 | super(ATTRIBUTE_NAME);
38 |
39 | if (smapString == null) {
40 | throw new NullPointerException("smapString == null");
41 | }
42 |
43 | this.smapString = smapString;
44 | }
45 |
46 | /** {@inheritDoc} */
47 | @Override
48 | public int byteLength() {
49 | // Add 6 for the standard attribute header: the attribute name
50 | // index (2 bytes) and the attribute length (4 bytes).
51 | return 6 + smapString.getUtf8Size();
52 | }
53 |
54 | /**
55 | * Gets the SMAP data of this instance.
56 | *
57 | * @return {@code non-null;} the SMAP data.
58 | */
59 | public CstString getSmapString() {
60 | return smapString;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/com/android/dx/dex/code/SimpleInsn.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.dex.code;
18 |
19 | import com.android.dx.rop.code.RegisterSpecList;
20 | import com.android.dx.rop.code.SourcePosition;
21 |
22 | /**
23 | * Instruction which has no extra info beyond the basics provided for in
24 | * the base class.
25 | */
26 | public final class SimpleInsn extends FixedSizeInsn {
27 | /**
28 | * Constructs an instance. The output address of this instance is initially
29 | * unknown ({@code -1}).
30 | *
31 | * @param opcode the opcode; one of the constants from {@link Dops}
32 | * @param position {@code non-null;} source position
33 | * @param registers {@code non-null;} register list, including a
34 | * result register if appropriate (that is, registers may be either
35 | * ins or outs)
36 | */
37 | public SimpleInsn(Dop opcode, SourcePosition position,
38 | RegisterSpecList registers) {
39 | super(opcode, position, registers);
40 | }
41 |
42 | /** {@inheritDoc} */
43 | @Override
44 | public DalvInsn withOpcode(Dop opcode) {
45 | return new SimpleInsn(opcode, getPosition(), getRegisters());
46 | }
47 |
48 | /** {@inheritDoc} */
49 | @Override
50 | public DalvInsn withRegisters(RegisterSpecList registers) {
51 | return new SimpleInsn(getOpcode(), getPosition(), registers);
52 | }
53 |
54 | /** {@inheritDoc} */
55 | @Override
56 | protected String argString() {
57 | return null;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/com/android/dx/io/instructions/RegisterRangeDecodedInstruction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.io.instructions;
18 |
19 | import com.android.dx.io.IndexType;
20 |
21 | /**
22 | * A decoded Dalvik instruction which has register range arguments (an
23 | * "A" start register and a register count).
24 | */
25 | public final class RegisterRangeDecodedInstruction extends DecodedInstruction {
26 | /** register argument "A" */
27 | private final int a;
28 |
29 | /** register count */
30 | private final int registerCount;
31 |
32 | /**
33 | * Constructs an instance.
34 | */
35 | public RegisterRangeDecodedInstruction(InstructionCodec format, int opcode,
36 | int index, IndexType indexType, int target, long literal,
37 | int a, int registerCount) {
38 | super(format, opcode, index, indexType, target, literal);
39 |
40 | this.a = a;
41 | this.registerCount = registerCount;
42 | }
43 |
44 | /** {@inheritDoc} */
45 | @Override
46 | public int getRegisterCount() {
47 | return registerCount;
48 | }
49 |
50 | /** {@inheritDoc} */
51 | @Override
52 | public int getA() {
53 | return a;
54 | }
55 |
56 | /** {@inheritDoc} */
57 | @Override
58 | public DecodedInstruction withIndex(int newIndex) {
59 | return new RegisterRangeDecodedInstruction(
60 | getFormat(), getOpcode(), newIndex, getIndexType(),
61 | getTarget(), getLiteral(), a, registerCount);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/com/android/dx/rop/cst/CstEnumRef.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.rop.cst;
18 |
19 | import com.android.dx.rop.type.Type;
20 |
21 | /**
22 | * Constant type to represent a reference to a particular constant
23 | * value of an enumerated type.
24 | */
25 | public final class CstEnumRef extends CstMemberRef {
26 | /** {@code null-ok;} the corresponding field ref, lazily initialized */
27 | private CstFieldRef fieldRef;
28 |
29 | /**
30 | * Constructs an instance.
31 | *
32 | * @param nat {@code non-null;} the name-and-type; the defining class is derived
33 | * from this
34 | */
35 | public CstEnumRef(CstNat nat) {
36 | super(new CstType(nat.getFieldType()), nat);
37 |
38 | fieldRef = null;
39 | }
40 |
41 | /** {@inheritDoc} */
42 | @Override
43 | public String typeName() {
44 | return "enum";
45 | }
46 |
47 | /**
48 | * {@inheritDoc}
49 | *
50 | * Note: This returns the enumerated type.
51 | */
52 | @Override
53 | public Type getType() {
54 | return getDefiningClass().getClassType();
55 | }
56 |
57 | /**
58 | * Get a {@link CstFieldRef} that corresponds with this instance.
59 | *
60 | * @return {@code non-null;} the corresponding field reference
61 | */
62 | public CstFieldRef getFieldRef() {
63 | if (fieldRef == null) {
64 | fieldRef = new CstFieldRef(getDefiningClass(), getNat());
65 | }
66 |
67 | return fieldRef;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/cst/ConstantTags.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.cst;
18 |
19 | /**
20 | * Tags for constant pool constants.
21 | */
22 | public interface ConstantTags {
23 | /** tag for a {@code CONSTANT_Utf8_info} */
24 | int CONSTANT_Utf8 = 1;
25 |
26 | /** tag for a {@code CONSTANT_Integer_info} */
27 | int CONSTANT_Integer = 3;
28 |
29 | /** tag for a {@code CONSTANT_Float_info} */
30 | int CONSTANT_Float = 4;
31 |
32 | /** tag for a {@code CONSTANT_Long_info} */
33 | int CONSTANT_Long = 5;
34 |
35 | /** tag for a {@code CONSTANT_Double_info} */
36 | int CONSTANT_Double = 6;
37 |
38 | /** tag for a {@code CONSTANT_Class_info} */
39 | int CONSTANT_Class = 7;
40 |
41 | /** tag for a {@code CONSTANT_String_info} */
42 | int CONSTANT_String = 8;
43 |
44 | /** tag for a {@code CONSTANT_Fieldref_info} */
45 | int CONSTANT_Fieldref = 9;
46 |
47 | /** tag for a {@code CONSTANT_Methodref_info} */
48 | int CONSTANT_Methodref = 10;
49 |
50 | /** tag for a {@code CONSTANT_InterfaceMethodref_info} */
51 | int CONSTANT_InterfaceMethodref = 11;
52 |
53 | /** tag for a {@code CONSTANT_NameAndType_info} */
54 | int CONSTANT_NameAndType = 12;
55 |
56 | /** tag for a {@code CONSTANT_MethodHandle} */
57 | int CONSTANT_MethodHandle = 15;
58 |
59 | /** tag for a {@code CONSTANT_MethodType} */
60 | int CONSTANT_MethodType = 16;
61 |
62 | /** tag for a {@code CONSTANT_InvokeDynamic} */
63 | int CONSTANT_InvokeDynamic = 18;
64 | }
65 |
--------------------------------------------------------------------------------
/src/com/android/dx/io/instructions/SparseSwitchPayloadDecodedInstruction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.io.instructions;
18 |
19 | /**
20 | * A decoded Dalvik instruction which contains the payload for
21 | * a {@code packed-switch} instruction.
22 | */
23 | public final class SparseSwitchPayloadDecodedInstruction
24 | extends DecodedInstruction {
25 | /** array of key values */
26 | private final int[] keys;
27 |
28 | /**
29 | * array of target addresses. These are absolute, not relative,
30 | * addresses.
31 | */
32 | private final int[] targets;
33 |
34 | /**
35 | * Constructs an instance.
36 | */
37 | public SparseSwitchPayloadDecodedInstruction(InstructionCodec format,
38 | int opcode, int[] keys, int[] targets) {
39 | super(format, opcode, 0, null, 0, 0L);
40 |
41 | if (keys.length != targets.length) {
42 | throw new IllegalArgumentException("keys/targets length mismatch");
43 | }
44 |
45 | this.keys = keys;
46 | this.targets = targets;
47 | }
48 |
49 | /** {@inheritDoc} */
50 | @Override
51 | public int getRegisterCount() {
52 | return 0;
53 | }
54 |
55 | public int[] getKeys() {
56 | return keys;
57 | }
58 |
59 | public int[] getTargets() {
60 | return targets;
61 | }
62 |
63 | /** {@inheritDoc} */
64 | @Override
65 | public DecodedInstruction withIndex(int newIndex) {
66 | throw new UnsupportedOperationException("no index in instruction");
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/com/android/dex/Annotation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dex;
18 |
19 | import static com.android.dex.EncodedValueReader.ENCODED_ANNOTATION;
20 |
21 | /**
22 | * An annotation.
23 | */
24 | public final class Annotation implements Comparable {
25 | private final Dex dex;
26 | private final byte visibility;
27 | private final EncodedValue encodedAnnotation;
28 |
29 | public Annotation(Dex dex, byte visibility, EncodedValue encodedAnnotation) {
30 | this.dex = dex;
31 | this.visibility = visibility;
32 | this.encodedAnnotation = encodedAnnotation;
33 | }
34 |
35 | public byte getVisibility() {
36 | return visibility;
37 | }
38 |
39 | public EncodedValueReader getReader() {
40 | return new EncodedValueReader(encodedAnnotation, ENCODED_ANNOTATION);
41 | }
42 |
43 | public int getTypeIndex() {
44 | EncodedValueReader reader = getReader();
45 | reader.readAnnotation();
46 | return reader.getAnnotationType();
47 | }
48 |
49 | public void writeTo(Dex.Section out) {
50 | out.writeByte(visibility);
51 | encodedAnnotation.writeTo(out);
52 | }
53 |
54 | @Override
55 | public int compareTo(Annotation other) {
56 | return encodedAnnotation.compareTo(other.encodedAnnotation);
57 | }
58 |
59 | @Override
60 | public String toString() {
61 | return dex == null
62 | ? visibility + " " + getTypeIndex()
63 | : visibility + " " + dex.typeNames().get(getTypeIndex());
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/com/android/dx/dex/file/MethodIdItem.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.dex.file;
18 |
19 | import com.android.dx.rop.cst.CstBaseMethodRef;
20 |
21 | /**
22 | * Representation of a method reference inside a Dalvik file.
23 | */
24 | public final class MethodIdItem extends MemberIdItem {
25 | /**
26 | * Constructs an instance.
27 | *
28 | * @param method {@code non-null;} the constant for the method
29 | */
30 | public MethodIdItem(CstBaseMethodRef method) {
31 | super(method);
32 | }
33 |
34 | /** {@inheritDoc} */
35 | @Override
36 | public ItemType itemType() {
37 | return ItemType.TYPE_METHOD_ID_ITEM;
38 | }
39 |
40 | /** {@inheritDoc} */
41 | @Override
42 | public void addContents(DexFile file) {
43 | super.addContents(file);
44 |
45 | ProtoIdsSection protoIds = file.getProtoIds();
46 | protoIds.intern(getMethodRef().getPrototype());
47 | }
48 |
49 | /**
50 | * Gets the method constant.
51 | *
52 | * @return {@code non-null;} the constant
53 | */
54 | public CstBaseMethodRef getMethodRef() {
55 | return (CstBaseMethodRef) getRef();
56 | }
57 |
58 | /** {@inheritDoc} */
59 | @Override
60 | protected int getTypoidIdx(DexFile file) {
61 | ProtoIdsSection protoIds = file.getProtoIds();
62 | return protoIds.indexOf(getMethodRef().getPrototype());
63 | }
64 |
65 | /** {@inheritDoc} */
66 | @Override
67 | protected String getTypoidName() {
68 | return "proto_idx";
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/iface/StdMethod.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.iface;
18 |
19 | import com.android.dx.rop.code.AccessFlags;
20 | import com.android.dx.rop.cst.CstNat;
21 | import com.android.dx.rop.cst.CstType;
22 | import com.android.dx.rop.type.Prototype;
23 |
24 | /**
25 | * Standard implementation of {@link Method}, which directly stores
26 | * all the associated data.
27 | */
28 | public final class StdMethod extends StdMember implements Method {
29 | /** {@code non-null;} the effective method descriptor */
30 | private final Prototype effectiveDescriptor;
31 |
32 | /**
33 | * Constructs an instance.
34 | *
35 | * @param definingClass {@code non-null;} the defining class
36 | * @param accessFlags access flags
37 | * @param nat {@code non-null;} member name and type (descriptor)
38 | * @param attributes {@code non-null;} list of associated attributes
39 | */
40 | public StdMethod(CstType definingClass, int accessFlags, CstNat nat,
41 | AttributeList attributes) {
42 | super(definingClass, accessFlags, nat, attributes);
43 |
44 | String descStr = getDescriptor().getString();
45 | effectiveDescriptor =
46 | Prototype.intern(descStr, definingClass.getClassType(),
47 | AccessFlags.isStatic(accessFlags),
48 | nat.isInstanceInit());
49 | }
50 |
51 | /** {@inheritDoc} */
52 | @Override
53 | public Prototype getEffectiveDescriptor() {
54 | return effectiveDescriptor;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/com/android/dx/io/instructions/CodeOutput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.io.instructions;
18 |
19 | /**
20 | * Output stream of code units, for writing out Dalvik bytecode.
21 | */
22 | public interface CodeOutput extends CodeCursor {
23 | /**
24 | * Writes a code unit.
25 | */
26 | public void write(short codeUnit);
27 |
28 | /**
29 | * Writes two code units.
30 | */
31 | public void write(short u0, short u1);
32 |
33 | /**
34 | * Writes three code units.
35 | */
36 | public void write(short u0, short u1, short u2);
37 |
38 | /**
39 | * Writes four code units.
40 | */
41 | public void write(short u0, short u1, short u2, short u3);
42 |
43 | /**
44 | * Writes five code units.
45 | */
46 | public void write(short u0, short u1, short u2, short u3, short u4);
47 |
48 | /**
49 | * Writes an {@code int}, little-endian.
50 | */
51 | public void writeInt(int value);
52 |
53 | /**
54 | * Writes a {@code long}, little-endian.
55 | */
56 | public void writeLong(long value);
57 |
58 | /**
59 | * Writes the contents of the given array.
60 | */
61 | public void write(byte[] data);
62 |
63 | /**
64 | * Writes the contents of the given array.
65 | */
66 | public void write(short[] data);
67 |
68 | /**
69 | * Writes the contents of the given array.
70 | */
71 | public void write(int[] data);
72 |
73 | /**
74 | * Writes the contents of the given array.
75 | */
76 | public void write(long[] data);
77 | }
78 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/AttInnerClasses.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | import com.android.dx.util.MutabilityException;
20 |
21 | /**
22 | * Attribute class for standard {@code InnerClasses} attributes.
23 | */
24 | public final class AttInnerClasses extends BaseAttribute {
25 | /** {@code non-null;} attribute name for attributes of this type */
26 | public static final String ATTRIBUTE_NAME = "InnerClasses";
27 |
28 | /** {@code non-null;} list of inner class entries */
29 | private final InnerClassList innerClasses;
30 |
31 | /**
32 | * Constructs an instance.
33 | *
34 | * @param innerClasses {@code non-null;} list of inner class entries
35 | */
36 | public AttInnerClasses(InnerClassList innerClasses) {
37 | super(ATTRIBUTE_NAME);
38 |
39 | try {
40 | if (innerClasses.isMutable()) {
41 | throw new MutabilityException("innerClasses.isMutable()");
42 | }
43 | } catch (NullPointerException ex) {
44 | // Translate the exception.
45 | throw new NullPointerException("innerClasses == null");
46 | }
47 |
48 | this.innerClasses = innerClasses;
49 | }
50 |
51 | /** {@inheritDoc} */
52 | @Override
53 | public int byteLength() {
54 | return 8 + innerClasses.size() * 8;
55 | }
56 |
57 | /**
58 | * Gets the list of "inner class" entries associated with this instance.
59 | *
60 | * @return {@code non-null;} the list
61 | */
62 | public InnerClassList getInnerClasses() {
63 | return innerClasses;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/com/android/dx/dex/file/TypeIdItem.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.dex.file;
18 |
19 | import com.android.dex.SizeOf;
20 | import com.android.dx.rop.cst.CstString;
21 | import com.android.dx.rop.cst.CstType;
22 | import com.android.dx.util.AnnotatedOutput;
23 | import com.android.dx.util.Hex;
24 |
25 | /**
26 | * Representation of a type reference inside a Dalvik file.
27 | */
28 | public final class TypeIdItem extends IdItem {
29 | /**
30 | * Constructs an instance.
31 | *
32 | * @param type {@code non-null;} the constant for the type
33 | */
34 | public TypeIdItem(CstType type) {
35 | super(type);
36 | }
37 |
38 | /** {@inheritDoc} */
39 | @Override
40 | public ItemType itemType() {
41 | return ItemType.TYPE_TYPE_ID_ITEM;
42 | }
43 |
44 | /** {@inheritDoc} */
45 | @Override
46 | public int writeSize() {
47 | return SizeOf.TYPE_ID_ITEM;
48 | }
49 |
50 | /** {@inheritDoc} */
51 | @Override
52 | public void addContents(DexFile file) {
53 | file.getStringIds().intern(getDefiningClass().getDescriptor());
54 | }
55 |
56 | /** {@inheritDoc} */
57 | @Override
58 | public void writeTo(DexFile file, AnnotatedOutput out) {
59 | CstType type = getDefiningClass();
60 | CstString descriptor = type.getDescriptor();
61 | int idx = file.getStringIds().indexOf(descriptor);
62 |
63 | if (out.annotates()) {
64 | out.annotate(0, indexString() + ' ' + descriptor.toHuman());
65 | out.annotate(4, " descriptor_idx: " + Hex.u4(idx));
66 | }
67 |
68 | out.writeInt(idx);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/AttBootstrapMethods.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.android.dx.cf.attrib;
17 |
18 | import com.android.dx.cf.code.BootstrapMethodsList;
19 |
20 | /**
21 | * Attribute class for standard {@code AttBootstrapMethods} attributes.
22 | */
23 | public class AttBootstrapMethods extends BaseAttribute {
24 | /** {@code non-null;} attribute name for attributes of this type */
25 | public static final String ATTRIBUTE_NAME = "BootstrapMethods";
26 |
27 | private static final int ATTRIBUTE_HEADER_BYTES = 8;
28 | private static final int BOOTSTRAP_METHOD_BYTES = 4;
29 | private static final int BOOTSTRAP_ARGUMENT_BYTES = 2;
30 |
31 | private final BootstrapMethodsList bootstrapMethods;
32 |
33 | private final int byteLength;
34 |
35 | public AttBootstrapMethods(BootstrapMethodsList bootstrapMethods) {
36 | super(ATTRIBUTE_NAME);
37 | this.bootstrapMethods = bootstrapMethods;
38 |
39 | int bytes = ATTRIBUTE_HEADER_BYTES + bootstrapMethods.size() * BOOTSTRAP_METHOD_BYTES;
40 | for (int i = 0; i < bootstrapMethods.size(); ++i) {
41 | int numberOfArguments = bootstrapMethods.get(i).getBootstrapMethodArguments().size();
42 | bytes += numberOfArguments * BOOTSTRAP_ARGUMENT_BYTES;
43 | }
44 | this.byteLength = bytes;
45 | }
46 |
47 | @Override
48 | public int byteLength() {
49 | return byteLength;
50 | }
51 |
52 | /**
53 | * Get the bootstrap methods present in attribute.
54 | * @return bootstrap methods list
55 | */
56 | public BootstrapMethodsList getBootstrapMethods() {
57 | return bootstrapMethods;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/AttLineNumberTable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | import com.android.dx.cf.code.LineNumberList;
20 | import com.android.dx.util.MutabilityException;
21 |
22 | /**
23 | * Attribute class for standard {@code LineNumberTable} attributes.
24 | */
25 | public final class AttLineNumberTable extends BaseAttribute {
26 | /** {@code non-null;} attribute name for attributes of this type */
27 | public static final String ATTRIBUTE_NAME = "LineNumberTable";
28 |
29 | /** {@code non-null;} list of line number entries */
30 | private final LineNumberList lineNumbers;
31 |
32 | /**
33 | * Constructs an instance.
34 | *
35 | * @param lineNumbers {@code non-null;} list of line number entries
36 | */
37 | public AttLineNumberTable(LineNumberList lineNumbers) {
38 | super(ATTRIBUTE_NAME);
39 |
40 | try {
41 | if (lineNumbers.isMutable()) {
42 | throw new MutabilityException("lineNumbers.isMutable()");
43 | }
44 | } catch (NullPointerException ex) {
45 | // Translate the exception.
46 | throw new NullPointerException("lineNumbers == null");
47 | }
48 |
49 | this.lineNumbers = lineNumbers;
50 | }
51 |
52 | /** {@inheritDoc} */
53 | @Override
54 | public int byteLength() {
55 | return 8 + 4 * lineNumbers.size();
56 | }
57 |
58 | /**
59 | * Gets the list of "line number" entries associated with this instance.
60 | *
61 | * @return {@code non-null;} the list
62 | */
63 | public LineNumberList getLineNumbers() {
64 | return lineNumbers;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/com/android/dx/dex/code/form/Form10x.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.dex.code.form;
18 |
19 | import com.android.dx.dex.code.DalvInsn;
20 | import com.android.dx.dex.code.InsnFormat;
21 | import com.android.dx.dex.code.SimpleInsn;
22 | import com.android.dx.util.AnnotatedOutput;
23 |
24 | /**
25 | * Instruction format {@code 10x}. See the instruction format spec
26 | * for details.
27 | */
28 | public final class Form10x extends InsnFormat {
29 | /** {@code non-null;} unique instance of this class */
30 | public static final InsnFormat THE_ONE = new Form10x();
31 |
32 | /**
33 | * Constructs an instance. This class is not publicly
34 | * instantiable. Use {@link #THE_ONE}.
35 | */
36 | private Form10x() {
37 | // This space intentionally left blank.
38 | }
39 |
40 | /** {@inheritDoc} */
41 | @Override
42 | public String insnArgString(DalvInsn insn) {
43 | // This format has no arguments.
44 | return "";
45 | }
46 |
47 | /** {@inheritDoc} */
48 | @Override
49 | public String insnCommentString(DalvInsn insn, boolean noteIndices) {
50 | // This format has no comment.
51 | return "";
52 | }
53 |
54 | /** {@inheritDoc} */
55 | @Override
56 | public int codeSize() {
57 | return 1;
58 | }
59 |
60 | /** {@inheritDoc} */
61 | @Override
62 | public boolean isCompatible(DalvInsn insn) {
63 | return (insn instanceof SimpleInsn) &&
64 | (insn.getRegisters().size() == 0);
65 | }
66 |
67 | /** {@inheritDoc} */
68 | @Override
69 | public void writeTo(AnnotatedOutput out, DalvInsn insn) {
70 | write(out, opcodeUnit(insn, 0));
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/AttAnnotationDefault.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | import com.android.dx.rop.cst.Constant;
20 |
21 | /**
22 | * Attribute class for {@code AnnotationDefault} attributes.
23 | */
24 | public final class AttAnnotationDefault extends BaseAttribute {
25 | /** {@code non-null;} attribute name for attributes of this type */
26 | public static final String ATTRIBUTE_NAME = "AnnotationDefault";
27 |
28 | /** {@code non-null;} the annotation default value */
29 | private final Constant value;
30 |
31 | /** {@code >= 0;} attribute data length in the original classfile (not
32 | * including the attribute header) */
33 | private final int byteLength;
34 |
35 | /**
36 | * Constructs an instance.
37 | *
38 | * @param value {@code non-null;} the annotation default value
39 | * @param byteLength {@code >= 0;} attribute data length in the original
40 | * classfile (not including the attribute header)
41 | */
42 | public AttAnnotationDefault(Constant value, int byteLength) {
43 | super(ATTRIBUTE_NAME);
44 |
45 | if (value == null) {
46 | throw new NullPointerException("value == null");
47 | }
48 |
49 | this.value = value;
50 | this.byteLength = byteLength;
51 | }
52 |
53 | /** {@inheritDoc} */
54 | @Override
55 | public int byteLength() {
56 | // Add six for the standard attribute header.
57 | return byteLength + 6;
58 | }
59 |
60 | /**
61 | * Gets the annotation default value.
62 | *
63 | * @return {@code non-null;} the value
64 | */
65 | public Constant getValue() {
66 | return value;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/BaseLocalVariables.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | import com.android.dx.cf.code.LocalVariableList;
20 | import com.android.dx.util.MutabilityException;
21 |
22 | /**
23 | * Base attribute class for standard {@code LocalVariableTable}
24 | * and {@code LocalVariableTypeTable} attributes.
25 | */
26 | public abstract class BaseLocalVariables extends BaseAttribute {
27 | /** {@code non-null;} list of local variable entries */
28 | private final LocalVariableList localVariables;
29 |
30 | /**
31 | * Constructs an instance.
32 | *
33 | * @param name {@code non-null;} attribute name
34 | * @param localVariables {@code non-null;} list of local variable entries
35 | */
36 | public BaseLocalVariables(String name,
37 | LocalVariableList localVariables) {
38 | super(name);
39 |
40 | try {
41 | if (localVariables.isMutable()) {
42 | throw new MutabilityException("localVariables.isMutable()");
43 | }
44 | } catch (NullPointerException ex) {
45 | // Translate the exception.
46 | throw new NullPointerException("localVariables == null");
47 | }
48 |
49 | this.localVariables = localVariables;
50 | }
51 |
52 | /** {@inheritDoc} */
53 | @Override
54 | public final int byteLength() {
55 | return 8 + localVariables.size() * 10;
56 | }
57 |
58 | /**
59 | * Gets the list of "local variable" entries associated with this instance.
60 | *
61 | * @return {@code non-null;} the list
62 | */
63 | public final LocalVariableList getLocalVariables() {
64 | return localVariables;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/com/android/dx/rop/cst/Constant.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.rop.cst;
18 |
19 | import com.android.dx.util.ToHuman;
20 |
21 | /**
22 | * Base class for constants of all sorts.
23 | */
24 | public abstract class Constant
25 | implements ToHuman, Comparable {
26 | /**
27 | * Returns {@code true} if this instance is a category-2 constant,
28 | * meaning it takes up two slots in the constant pool, or
29 | * {@code false} if this instance is category-1.
30 | *
31 | * @return {@code true} iff this instance is category-2
32 | */
33 | public abstract boolean isCategory2();
34 |
35 | /**
36 | * Returns the human name for the particular type of constant
37 | * this instance is.
38 | *
39 | * @return {@code non-null;} the name
40 | */
41 | public abstract String typeName();
42 |
43 | /**
44 | * {@inheritDoc}
45 | *
46 | * This compares in class-major and value-minor order.
47 | */
48 | @Override
49 | public final int compareTo(Constant other) {
50 | Class clazz = getClass();
51 | Class otherClazz = other.getClass();
52 |
53 | if (clazz != otherClazz) {
54 | return clazz.getName().compareTo(otherClazz.getName());
55 | }
56 |
57 | return compareTo0(other);
58 | }
59 |
60 | /**
61 | * Compare the values of this and another instance, which are guaranteed
62 | * to be of the same class. Subclasses must implement this.
63 | *
64 | * @param other {@code non-null;} the instance to compare to
65 | * @return {@code -1}, {@code 0}, or {@code 1}, as usual
66 | * for a comparison
67 | */
68 | protected abstract int compareTo0(Constant other);
69 | }
70 |
--------------------------------------------------------------------------------
/src/com/android/dx/io/instructions/ThreeRegisterDecodedInstruction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.io.instructions;
18 |
19 | import com.android.dx.io.IndexType;
20 |
21 | /**
22 | * A decoded Dalvik instruction which has three register arguments.
23 | */
24 | public final class ThreeRegisterDecodedInstruction extends DecodedInstruction {
25 | /** register argument "A" */
26 | private final int a;
27 |
28 | /** register argument "B" */
29 | private final int b;
30 |
31 | /** register argument "C" */
32 | private final int c;
33 |
34 | /**
35 | * Constructs an instance.
36 | */
37 | public ThreeRegisterDecodedInstruction(InstructionCodec format, int opcode,
38 | int index, IndexType indexType, int target, long literal,
39 | int a, int b, int c) {
40 | super(format, opcode, index, indexType, target, literal);
41 |
42 | this.a = a;
43 | this.b = b;
44 | this.c = c;
45 | }
46 |
47 | /** {@inheritDoc} */
48 | @Override
49 | public int getRegisterCount() {
50 | return 3;
51 | }
52 |
53 | /** {@inheritDoc} */
54 | @Override
55 | public int getA() {
56 | return a;
57 | }
58 |
59 | /** {@inheritDoc} */
60 | @Override
61 | public int getB() {
62 | return b;
63 | }
64 |
65 | /** {@inheritDoc} */
66 | @Override
67 | public int getC() {
68 | return c;
69 | }
70 |
71 | /** {@inheritDoc} */
72 | @Override
73 | public DecodedInstruction withIndex(int newIndex) {
74 | return new ThreeRegisterDecodedInstruction(
75 | getFormat(), getOpcode(), newIndex, getIndexType(),
76 | getTarget(), getLiteral(), a, b, c);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/code/ByteBlockList.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.code;
18 |
19 | import com.android.dx.util.Hex;
20 | import com.android.dx.util.LabeledList;
21 |
22 | /**
23 | * List of {@link ByteBlock} instances.
24 | */
25 | public final class ByteBlockList extends LabeledList {
26 |
27 | /**
28 | * Constructs an instance.
29 | *
30 | * @param size {@code >= 0;} the number of elements to be in the list
31 | */
32 | public ByteBlockList(int size) {
33 | super(size);
34 | }
35 |
36 | /**
37 | * Gets the indicated element. It is an error to call this with the
38 | * index for an element which was never set; if you do that, this
39 | * will throw {@code NullPointerException}.
40 | *
41 | * @param n {@code >= 0, < size();} which element
42 | * @return {@code non-null;} the indicated element
43 | */
44 | public ByteBlock get(int n) {
45 | return (ByteBlock) get0(n);
46 | }
47 |
48 | /**
49 | * Gets the block with the given label.
50 | *
51 | * @param label the label to look for
52 | * @return {@code non-null;} the block with the given label
53 | */
54 | public ByteBlock labelToBlock(int label) {
55 | int idx = indexOfLabel(label);
56 |
57 | if (idx < 0) {
58 | throw new IllegalArgumentException("no such label: "
59 | + Hex.u2(label));
60 | }
61 |
62 | return get(idx);
63 | }
64 |
65 | /**
66 | * Sets the element at the given index.
67 | *
68 | * @param n {@code >= 0, < size();} which element
69 | * @param bb {@code null-ok;} the value to store
70 | */
71 | public void set(int n, ByteBlock bb) {
72 | super.set(n, bb);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/com/android/dx/io/instructions/ShortArrayCodeInput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.io.instructions;
18 |
19 | import java.io.EOFException;
20 |
21 | /**
22 | * Implementation of {@code CodeInput} that reads from a {@code short[]}.
23 | */
24 | public final class ShortArrayCodeInput extends BaseCodeCursor
25 | implements CodeInput {
26 | /** source array to read from */
27 | private final short[] array;
28 |
29 | /**
30 | * Constructs an instance.
31 | */
32 | public ShortArrayCodeInput(short[] array) {
33 | if (array == null) {
34 | throw new NullPointerException("array == null");
35 | }
36 |
37 | this.array = array;
38 | }
39 |
40 | /** {@inheritDoc} */
41 | @Override
42 | public boolean hasMore() {
43 | return cursor() < array.length;
44 | }
45 |
46 | /** {@inheritDoc} */
47 | @Override
48 | public int read() throws EOFException {
49 | try {
50 | int value = array[cursor()];
51 | advance(1);
52 | return value & 0xffff;
53 | } catch (ArrayIndexOutOfBoundsException ex) {
54 | throw new EOFException();
55 | }
56 | }
57 |
58 | /** {@inheritDoc} */
59 | @Override
60 | public int readInt() throws EOFException {
61 | int short0 = read();
62 | int short1 = read();
63 |
64 | return short0 | (short1 << 16);
65 | }
66 |
67 | /** {@inheritDoc} */
68 | @Override
69 | public long readLong() throws EOFException {
70 | long short0 = read();
71 | long short1 = read();
72 | long short2 = read();
73 | long short3 = read();
74 |
75 | return short0 | (short1 << 16) | (short2 << 32) | (short3 << 48);
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/com/android/dex/ProtoId.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dex;
18 |
19 | import com.android.dex.util.Unsigned;
20 |
21 | public final class ProtoId implements Comparable {
22 | private final Dex dex;
23 | private final int shortyIndex;
24 | private final int returnTypeIndex;
25 | private final int parametersOffset;
26 |
27 | public ProtoId(Dex dex, int shortyIndex, int returnTypeIndex, int parametersOffset) {
28 | this.dex = dex;
29 | this.shortyIndex = shortyIndex;
30 | this.returnTypeIndex = returnTypeIndex;
31 | this.parametersOffset = parametersOffset;
32 | }
33 |
34 | @Override
35 | public int compareTo(ProtoId other) {
36 | if (returnTypeIndex != other.returnTypeIndex) {
37 | return Unsigned.compare(returnTypeIndex, other.returnTypeIndex);
38 | }
39 | return Unsigned.compare(parametersOffset, other.parametersOffset);
40 | }
41 |
42 | public int getShortyIndex() {
43 | return shortyIndex;
44 | }
45 |
46 | public int getReturnTypeIndex() {
47 | return returnTypeIndex;
48 | }
49 |
50 | public int getParametersOffset() {
51 | return parametersOffset;
52 | }
53 |
54 | public void writeTo(Dex.Section out) {
55 | out.writeInt(shortyIndex);
56 | out.writeInt(returnTypeIndex);
57 | out.writeInt(parametersOffset);
58 | }
59 |
60 | @Override
61 | public String toString() {
62 | if (dex == null) {
63 | return shortyIndex + " " + returnTypeIndex + " " + parametersOffset;
64 | }
65 |
66 | return dex.strings().get(shortyIndex)
67 | + ": " + dex.typeNames().get(returnTypeIndex)
68 | + " " + dex.readTypeList(parametersOffset);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/AttExceptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | import com.android.dx.rop.type.TypeList;
20 | import com.android.dx.util.MutabilityException;
21 |
22 | /**
23 | * Attribute class for standard {@code Exceptions} attributes.
24 | */
25 | public final class AttExceptions extends BaseAttribute {
26 | /** {@code non-null;} attribute name for attributes of this type */
27 | public static final String ATTRIBUTE_NAME = "Exceptions";
28 |
29 | /** {@code non-null;} list of exception classes */
30 | private final TypeList exceptions;
31 |
32 | /**
33 | * Constructs an instance.
34 | *
35 | * @param exceptions {@code non-null;} list of classes, presumed but not
36 | * verified to be subclasses of {@code Throwable}
37 | */
38 | public AttExceptions(TypeList exceptions) {
39 | super(ATTRIBUTE_NAME);
40 |
41 | try {
42 | if (exceptions.isMutable()) {
43 | throw new MutabilityException("exceptions.isMutable()");
44 | }
45 | } catch (NullPointerException ex) {
46 | // Translate the exception.
47 | throw new NullPointerException("exceptions == null");
48 | }
49 |
50 | this.exceptions = exceptions;
51 | }
52 |
53 | /** {@inheritDoc} */
54 | @Override
55 | public int byteLength() {
56 | return 8 + exceptions.size() * 2;
57 | }
58 |
59 | /**
60 | * Gets the list of classes associated with this instance. In
61 | * general, these classes are not pre-verified to be subclasses of
62 | * {@code Throwable}.
63 | *
64 | * @return {@code non-null;} the list of classes
65 | */
66 | public TypeList getExceptions() {
67 | return exceptions;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/com/android/dex/FieldId.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dex;
18 |
19 | import com.android.dex.util.Unsigned;
20 |
21 | public final class FieldId implements Comparable {
22 | private final Dex dex;
23 | private final int declaringClassIndex;
24 | private final int typeIndex;
25 | private final int nameIndex;
26 |
27 | public FieldId(Dex dex, int declaringClassIndex, int typeIndex, int nameIndex) {
28 | this.dex = dex;
29 | this.declaringClassIndex = declaringClassIndex;
30 | this.typeIndex = typeIndex;
31 | this.nameIndex = nameIndex;
32 | }
33 |
34 | public int getDeclaringClassIndex() {
35 | return declaringClassIndex;
36 | }
37 |
38 | public int getTypeIndex() {
39 | return typeIndex;
40 | }
41 |
42 | public int getNameIndex() {
43 | return nameIndex;
44 | }
45 |
46 | @Override
47 | public int compareTo(FieldId other) {
48 | if (declaringClassIndex != other.declaringClassIndex) {
49 | return Unsigned.compare(declaringClassIndex, other.declaringClassIndex);
50 | }
51 | if (nameIndex != other.nameIndex) {
52 | return Unsigned.compare(nameIndex, other.nameIndex);
53 | }
54 | return Unsigned.compare(typeIndex, other.typeIndex); // should always be 0
55 | }
56 |
57 | public void writeTo(Dex.Section out) {
58 | out.writeUnsignedShort(declaringClassIndex);
59 | out.writeUnsignedShort(typeIndex);
60 | out.writeInt(nameIndex);
61 | }
62 |
63 | @Override
64 | public String toString() {
65 | if (dex == null) {
66 | return declaringClassIndex + " " + typeIndex + " " + nameIndex;
67 | }
68 | return dex.typeNames().get(typeIndex) + "." + dex.strings().get(nameIndex);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/com/android/dx/rop/code/CstInsn.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.rop.code;
18 |
19 | import com.android.dx.rop.cst.Constant;
20 |
21 | /**
22 | * Instruction which contains an explicit reference to a constant.
23 | */
24 | public abstract class CstInsn
25 | extends Insn {
26 | /** {@code non-null;} the constant */
27 | private final Constant cst;
28 |
29 | /**
30 | * Constructs an instance.
31 | *
32 | * @param opcode {@code non-null;} the opcode
33 | * @param position {@code non-null;} source position
34 | * @param result {@code null-ok;} spec for the result, if any
35 | * @param sources {@code non-null;} specs for all the sources
36 | * @param cst {@code non-null;} constant
37 | */
38 | public CstInsn(Rop opcode, SourcePosition position, RegisterSpec result,
39 | RegisterSpecList sources, Constant cst) {
40 | super(opcode, position, result, sources);
41 |
42 | if (cst == null) {
43 | throw new NullPointerException("cst == null");
44 | }
45 |
46 | this.cst = cst;
47 | }
48 |
49 | /** {@inheritDoc} */
50 | @Override
51 | public String getInlineString() {
52 | return cst.toHuman();
53 | }
54 |
55 | /**
56 | * Gets the constant.
57 | *
58 | * @return {@code non-null;} the constant
59 | */
60 | public Constant getConstant() {
61 | return cst;
62 | }
63 |
64 | /** {@inheritDoc} */
65 | @Override
66 | public boolean contentEquals(Insn b) {
67 | /*
68 | * The cast (CstInsn)b below should always succeed since
69 | * Insn.contentEquals compares classes of this and b.
70 | */
71 | return super.contentEquals(b)
72 | && cst.equals(((CstInsn)b).getConstant());
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/com/android/dx/rop/cst/CstLiteral32.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.rop.cst;
18 |
19 | /**
20 | * Constants which are literal 32-bit values of some sort.
21 | */
22 | public abstract class CstLiteral32
23 | extends CstLiteralBits {
24 | /** the value as {@code int} bits */
25 | private final int bits;
26 |
27 | /**
28 | * Constructs an instance.
29 | *
30 | * @param bits the value as {@code int} bits
31 | */
32 | /*package*/ CstLiteral32(int bits) {
33 | this.bits = bits;
34 | }
35 |
36 | /** {@inheritDoc} */
37 | @Override
38 | public final boolean equals(Object other) {
39 | return (other != null) &&
40 | (getClass() == other.getClass()) &&
41 | bits == ((CstLiteral32) other).bits;
42 | }
43 |
44 | /** {@inheritDoc} */
45 | @Override
46 | public final int hashCode() {
47 | return bits;
48 | }
49 |
50 | /** {@inheritDoc} */
51 | @Override
52 | protected int compareTo0(Constant other) {
53 | int otherBits = ((CstLiteral32) other).bits;
54 |
55 | if (bits < otherBits) {
56 | return -1;
57 | } else if (bits > otherBits) {
58 | return 1;
59 | } else {
60 | return 0;
61 | }
62 | }
63 |
64 | /** {@inheritDoc} */
65 | @Override
66 | public final boolean isCategory2() {
67 | return false;
68 | }
69 |
70 | /** {@inheritDoc} */
71 | @Override
72 | public final boolean fitsInInt() {
73 | return true;
74 | }
75 |
76 | /** {@inheritDoc} */
77 | @Override
78 | public final int getIntBits() {
79 | return bits;
80 | }
81 |
82 | /** {@inheritDoc} */
83 | @Override
84 | public final long getLongBits() {
85 | return (long) bits;
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/com/android/dx/dex/code/OddSpacer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.dex.code;
18 |
19 | import com.android.dx.io.Opcodes;
20 | import com.android.dx.rop.code.RegisterSpecList;
21 | import com.android.dx.rop.code.SourcePosition;
22 | import com.android.dx.util.AnnotatedOutput;
23 |
24 | /**
25 | * Pseudo-instruction which either turns into a {@code nop} or
26 | * nothingness, in order to make the subsequent instruction have an
27 | * even address. This is used to align (subsequent) instructions that
28 | * require it.
29 | */
30 | public final class OddSpacer extends VariableSizeInsn {
31 | /**
32 | * Constructs an instance. The output address of this instance is initially
33 | * unknown ({@code -1}).
34 | *
35 | * @param position {@code non-null;} source position
36 | */
37 | public OddSpacer(SourcePosition position) {
38 | super(position, RegisterSpecList.EMPTY);
39 | }
40 |
41 | /** {@inheritDoc} */
42 | @Override
43 | public int codeSize() {
44 | return (getAddress() & 1);
45 | }
46 |
47 | /** {@inheritDoc} */
48 | @Override
49 | public void writeTo(AnnotatedOutput out) {
50 | if (codeSize() != 0) {
51 | out.writeShort(InsnFormat.codeUnit(Opcodes.NOP, 0));
52 | }
53 | }
54 |
55 | /** {@inheritDoc} */
56 | @Override
57 | public DalvInsn withRegisters(RegisterSpecList registers) {
58 | return new OddSpacer(getPosition());
59 | }
60 |
61 | /** {@inheritDoc} */
62 | @Override
63 | protected String argString() {
64 | return null;
65 | }
66 |
67 | /** {@inheritDoc} */
68 | @Override
69 | protected String listingString0(boolean noteIndices) {
70 | if (codeSize() == 0) {
71 | return null;
72 | }
73 |
74 | return "nop // spacer";
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/iface/Member.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.iface;
18 |
19 | import com.android.dx.rop.cst.CstNat;
20 | import com.android.dx.rop.cst.CstString;
21 | import com.android.dx.rop.cst.CstType;
22 |
23 | /**
24 | * Interface representing members of class files (that is, fields and methods).
25 | */
26 | public interface Member extends HasAttribute {
27 | /**
28 | * Get the defining class.
29 | *
30 | * @return {@code non-null;} the defining class
31 | */
32 | public CstType getDefiningClass();
33 |
34 | /**
35 | * Get the field {@code access_flags}.
36 | *
37 | * @return the access flags
38 | */
39 | public int getAccessFlags();
40 |
41 | /**
42 | * Get the field {@code name_index} of the member. This is
43 | * just a convenient shorthand for {@code getNat().getName()}.
44 | *
45 | * @return {@code non-null;} the name
46 | */
47 | public CstString getName();
48 |
49 | /**
50 | * Get the field {@code descriptor_index} of the member. This is
51 | * just a convenient shorthand for {@code getNat().getDescriptor()}.
52 | *
53 | * @return {@code non-null;} the descriptor
54 | */
55 | public CstString getDescriptor();
56 |
57 | /**
58 | * Get the name and type associated with this member. This is a
59 | * combination of the fields {@code name_index} and
60 | * {@code descriptor_index} in the original classfile, interpreted
61 | * via the constant pool.
62 | *
63 | * @return {@code non-null;} the name and type
64 | */
65 | public CstNat getNat();
66 |
67 | /**
68 | * Get the field {@code attributes} (along with
69 | * {@code attributes_count}).
70 | *
71 | * @return {@code non-null;} the constant pool
72 | */
73 | @Override
74 | public AttributeList getAttributes();
75 | }
76 |
--------------------------------------------------------------------------------
/src/com/android/dx/rop/cst/CstLiteral64.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.rop.cst;
18 |
19 | /**
20 | * Constants which are literal 64-bit values of some sort.
21 | */
22 | public abstract class CstLiteral64
23 | extends CstLiteralBits {
24 | /** the value as {@code long} bits */
25 | private final long bits;
26 |
27 | /**
28 | * Constructs an instance.
29 | *
30 | * @param bits the value as {@code long} bits
31 | */
32 | /*package*/ CstLiteral64(long bits) {
33 | this.bits = bits;
34 | }
35 |
36 | /** {@inheritDoc} */
37 | @Override
38 | public final boolean equals(Object other) {
39 | return (other != null) &&
40 | (getClass() == other.getClass()) &&
41 | bits == ((CstLiteral64) other).bits;
42 | }
43 |
44 | /** {@inheritDoc} */
45 | @Override
46 | public final int hashCode() {
47 | return (int) bits ^ (int) (bits >> 32);
48 | }
49 |
50 | /** {@inheritDoc} */
51 | @Override
52 | protected int compareTo0(Constant other) {
53 | long otherBits = ((CstLiteral64) other).bits;
54 |
55 | if (bits < otherBits) {
56 | return -1;
57 | } else if (bits > otherBits) {
58 | return 1;
59 | } else {
60 | return 0;
61 | }
62 | }
63 |
64 | /** {@inheritDoc} */
65 | @Override
66 | public final boolean isCategory2() {
67 | return true;
68 | }
69 |
70 | /** {@inheritDoc} */
71 | @Override
72 | public final boolean fitsInInt() {
73 | return (int) bits == bits;
74 | }
75 |
76 | /** {@inheritDoc} */
77 | @Override
78 | public final int getIntBits() {
79 | return (int) bits;
80 | }
81 |
82 | /** {@inheritDoc} */
83 | @Override
84 | public final long getLongBits() {
85 | return bits;
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/com/android/dx/rop/type/TypeList.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.rop.type;
18 |
19 | /**
20 | * List of {@link Type} instances (or of things that contain types).
21 | */
22 | public interface TypeList {
23 | /**
24 | * Returns whether this instance is mutable. Note that the
25 | * {@code TypeList} interface itself doesn't provide any
26 | * means of mutation, but that doesn't mean that there isn't an
27 | * extra-interface way of mutating an instance.
28 | *
29 | * @return {@code true} if this instance is mutable or
30 | * {@code false} if it is immutable
31 | */
32 | public boolean isMutable();
33 |
34 | /**
35 | * Gets the size of this list.
36 | *
37 | * @return {@code >= 0;} the size
38 | */
39 | public int size();
40 |
41 | /**
42 | * Gets the indicated element. It is an error to call this with the
43 | * index for an element which was never set; if you do that, this
44 | * will throw {@code NullPointerException}.
45 | *
46 | * @param n {@code >= 0, < size();} which element
47 | * @return {@code non-null;} the indicated element
48 | */
49 | public Type getType(int n);
50 |
51 | /**
52 | * Gets the number of 32-bit words required to hold instances of
53 | * all the elements of this list. This is a sum of the widths (categories)
54 | * of all the elements.
55 | *
56 | * @return {@code >= 0;} the required number of words
57 | */
58 | public int getWordCount();
59 |
60 | /**
61 | * Returns a new instance which is identical to this one, except that
62 | * the given item is appended to the end and it is guaranteed to be
63 | * immutable.
64 | *
65 | * @param type {@code non-null;} item to append
66 | * @return {@code non-null;} an appropriately-constructed instance
67 | */
68 | public TypeList withAddedType(Type type);
69 | }
70 |
--------------------------------------------------------------------------------
/src/com/android/dex/MethodId.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dex;
18 |
19 | import com.android.dex.util.Unsigned;
20 |
21 | public final class MethodId implements Comparable {
22 | private final Dex dex;
23 | private final int declaringClassIndex;
24 | private final int protoIndex;
25 | private final int nameIndex;
26 |
27 | public MethodId(Dex dex, int declaringClassIndex, int protoIndex, int nameIndex) {
28 | this.dex = dex;
29 | this.declaringClassIndex = declaringClassIndex;
30 | this.protoIndex = protoIndex;
31 | this.nameIndex = nameIndex;
32 | }
33 |
34 | public int getDeclaringClassIndex() {
35 | return declaringClassIndex;
36 | }
37 |
38 | public int getProtoIndex() {
39 | return protoIndex;
40 | }
41 |
42 | public int getNameIndex() {
43 | return nameIndex;
44 | }
45 |
46 | @Override
47 | public int compareTo(MethodId other) {
48 | if (declaringClassIndex != other.declaringClassIndex) {
49 | return Unsigned.compare(declaringClassIndex, other.declaringClassIndex);
50 | }
51 | if (nameIndex != other.nameIndex) {
52 | return Unsigned.compare(nameIndex, other.nameIndex);
53 | }
54 | return Unsigned.compare(protoIndex, other.protoIndex);
55 | }
56 |
57 | public void writeTo(Dex.Section out) {
58 | out.writeUnsignedShort(declaringClassIndex);
59 | out.writeUnsignedShort(protoIndex);
60 | out.writeInt(nameIndex);
61 | }
62 |
63 | @Override
64 | public String toString() {
65 | if (dex == null) {
66 | return declaringClassIndex + " " + protoIndex + " " + nameIndex;
67 | }
68 | return dex.typeNames().get(declaringClassIndex)
69 | + "." + dex.strings().get(nameIndex)
70 | + dex.readTypeList(dex.protoIds().get(protoIndex).getParametersOffset());
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/com/android/dx/dex/code/form/SpecialFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.dex.code.form;
18 |
19 | import com.android.dx.dex.code.DalvInsn;
20 | import com.android.dx.dex.code.InsnFormat;
21 | import com.android.dx.util.AnnotatedOutput;
22 |
23 | /**
24 | * Instruction format for nonstandard format instructions, which aren't
25 | * generally real instructions but do end up appearing in instruction
26 | * lists. Most of the overridden methods on this class end up throwing
27 | * exceptions, as code should know (implicitly or explicitly) to avoid
28 | * using this class. The one exception is {@link #isCompatible}, which
29 | * always returns {@code true}.
30 | */
31 | public final class SpecialFormat extends InsnFormat {
32 | /** {@code non-null;} unique instance of this class */
33 | public static final InsnFormat THE_ONE = new SpecialFormat();
34 |
35 | /**
36 | * Constructs an instance. This class is not publicly
37 | * instantiable. Use {@link #THE_ONE}.
38 | */
39 | private SpecialFormat() {
40 | // This space intentionally left blank.
41 | }
42 |
43 | /** {@inheritDoc} */
44 | @Override
45 | public String insnArgString(DalvInsn insn) {
46 | throw new RuntimeException("unsupported");
47 | }
48 |
49 | /** {@inheritDoc} */
50 | @Override
51 | public String insnCommentString(DalvInsn insn, boolean noteIndices) {
52 | throw new RuntimeException("unsupported");
53 | }
54 |
55 | /** {@inheritDoc} */
56 | @Override
57 | public int codeSize() {
58 | throw new RuntimeException("unsupported");
59 | }
60 |
61 | /** {@inheritDoc} */
62 | @Override
63 | public boolean isCompatible(DalvInsn insn) {
64 | return true;
65 | }
66 |
67 | /** {@inheritDoc} */
68 | @Override
69 | public void writeTo(AnnotatedOutput out, DalvInsn insn) {
70 | throw new RuntimeException("unsupported");
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | #*.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | parts/
18 | sdist/
19 | var/
20 | wheels/
21 | pip-wheel-metadata/
22 | share/python-wheels/
23 | *.egg-info/
24 | .installed.cfg
25 | *.egg
26 | MANIFEST
27 |
28 | # PyInstaller
29 | # Usually these files are written by a python script from a template
30 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
31 | *.manifest
32 | *.spec
33 |
34 | # Installer logs
35 | pip-log.txt
36 | pip-delete-this-directory.txt
37 |
38 | # Unit test / coverage reports
39 | htmlcov/
40 | .tox/
41 | .nox/
42 | .coverage
43 | .coverage.*
44 | .cache
45 | nosetests.xml
46 | coverage.xml
47 | *.cover
48 | *.py,cover
49 | .hypothesis/
50 | .pytest_cache/
51 |
52 | # Translations
53 | *.mo
54 | *.pot
55 |
56 | # Django stuff:
57 | *.log
58 | local_settings.py
59 | db.sqlite3
60 | db.sqlite3-journal
61 |
62 | # Flask stuff:
63 | instance/
64 | .webassets-cache
65 |
66 | # Scrapy stuff:
67 | .scrapy
68 |
69 | # Sphinx documentation
70 | docs/_build/
71 |
72 | # PyBuilder
73 | target/
74 |
75 | # Jupyter Notebook
76 | .ipynb_checkpoints
77 |
78 | # IPython
79 | profile_default/
80 | ipython_config.py
81 |
82 | # pyenv
83 | .python-version
84 |
85 | # pipenv
86 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
87 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
88 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
89 | # install all needed dependencies.
90 | #Pipfile.lock
91 |
92 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
93 | __pypackages__/
94 |
95 | # Celery stuff
96 | celerybeat-schedule
97 | celerybeat.pid
98 |
99 | # SageMath parsed files
100 | *.sage.py
101 |
102 | # Environments
103 | .env
104 | .venv
105 | .venvtest
106 | env/
107 | venv/
108 | ENV/
109 | env.bak/
110 | venv.bak/
111 |
112 | # Spyder project settings
113 | .spyderproject
114 | .spyproject
115 |
116 | # Rope project settings
117 | .ropeproject
118 |
119 | # mkdocs documentation
120 | /site
121 |
122 | # mypy
123 | .mypy_cache/
124 | .dmypy.json
125 | dmypy.json
126 |
127 | # Pyre type checker
128 | .pyre/
129 |
--------------------------------------------------------------------------------
/src/com/android/dx/dex/code/form/Form30t.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.dex.code.form;
18 |
19 | import com.android.dx.dex.code.DalvInsn;
20 | import com.android.dx.dex.code.InsnFormat;
21 | import com.android.dx.dex.code.TargetInsn;
22 | import com.android.dx.util.AnnotatedOutput;
23 |
24 | /**
25 | * Instruction format {@code 30t}. See the instruction format spec
26 | * for details.
27 | */
28 | public final class Form30t extends InsnFormat {
29 | /** {@code non-null;} unique instance of this class */
30 | public static final InsnFormat THE_ONE = new Form30t();
31 |
32 | /**
33 | * Constructs an instance. This class is not publicly
34 | * instantiable. Use {@link #THE_ONE}.
35 | */
36 | private Form30t() {
37 | // This space intentionally left blank.
38 | }
39 |
40 | /** {@inheritDoc} */
41 | @Override
42 | public String insnArgString(DalvInsn insn) {
43 | return branchString(insn);
44 | }
45 |
46 | /** {@inheritDoc} */
47 | @Override
48 | public String insnCommentString(DalvInsn insn, boolean noteIndices) {
49 | return branchComment(insn);
50 | }
51 |
52 | /** {@inheritDoc} */
53 | @Override
54 | public int codeSize() {
55 | return 3;
56 | }
57 |
58 | /** {@inheritDoc} */
59 | @Override
60 | public boolean isCompatible(DalvInsn insn) {
61 | if (!((insn instanceof TargetInsn) &&
62 | (insn.getRegisters().size() == 0))) {
63 | return false;
64 | }
65 |
66 | return true;
67 | }
68 |
69 | /** {@inheritDoc} */
70 | @Override
71 | public boolean branchFits(TargetInsn insn) {
72 | return true;
73 | }
74 |
75 | /** {@inheritDoc} */
76 | @Override
77 | public void writeTo(AnnotatedOutput out, DalvInsn insn) {
78 | int offset = ((TargetInsn) insn).getTargetOffset();
79 |
80 | write(out, opcodeUnit(insn, 0), offset);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/AttEnclosingMethod.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | import com.android.dx.rop.cst.CstNat;
20 | import com.android.dx.rop.cst.CstType;
21 |
22 | /**
23 | * Attribute class for standards-track {@code EnclosingMethod}
24 | * attributes.
25 | */
26 | public final class AttEnclosingMethod extends BaseAttribute {
27 | /** {@code non-null;} attribute name for attributes of this type */
28 | public static final String ATTRIBUTE_NAME = "EnclosingMethod";
29 |
30 | /** {@code non-null;} the innermost enclosing class */
31 | private final CstType type;
32 |
33 | /** {@code null-ok;} the name-and-type of the innermost enclosing method, if any */
34 | private final CstNat method;
35 |
36 | /**
37 | * Constructs an instance.
38 | *
39 | * @param type {@code non-null;} the innermost enclosing class
40 | * @param method {@code null-ok;} the name-and-type of the innermost enclosing
41 | * method, if any
42 | */
43 | public AttEnclosingMethod(CstType type, CstNat method) {
44 | super(ATTRIBUTE_NAME);
45 |
46 | if (type == null) {
47 | throw new NullPointerException("type == null");
48 | }
49 |
50 | this.type = type;
51 | this.method = method;
52 | }
53 |
54 | /** {@inheritDoc} */
55 | @Override
56 | public int byteLength() {
57 | return 10;
58 | }
59 |
60 | /**
61 | * Gets the innermost enclosing class.
62 | *
63 | * @return {@code non-null;} the innermost enclosing class
64 | */
65 | public CstType getEnclosingClass() {
66 | return type;
67 | }
68 |
69 | /**
70 | * Gets the name-and-type of the innermost enclosing method, if
71 | * any.
72 | *
73 | * @return {@code null-ok;} the name-and-type of the innermost enclosing
74 | * method, if any
75 | */
76 | public CstNat getMethod() {
77 | return method;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/com/android/dx/io/instructions/FourRegisterDecodedInstruction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.io.instructions;
18 |
19 | import com.android.dx.io.IndexType;
20 |
21 | /**
22 | * A decoded Dalvik instruction which has five register arguments.
23 | */
24 | public final class FourRegisterDecodedInstruction extends DecodedInstruction {
25 | /** register argument "A" */
26 | private final int a;
27 |
28 | /** register argument "B" */
29 | private final int b;
30 |
31 | /** register argument "C" */
32 | private final int c;
33 |
34 | /** register argument "D" */
35 | private final int d;
36 |
37 | /**
38 | * Constructs an instance.
39 | */
40 | public FourRegisterDecodedInstruction(InstructionCodec format, int opcode,
41 | int index, IndexType indexType, int target, long literal,
42 | int a, int b, int c, int d) {
43 | super(format, opcode, index, indexType, target, literal);
44 |
45 | this.a = a;
46 | this.b = b;
47 | this.c = c;
48 | this.d = d;
49 | }
50 |
51 | /** {@inheritDoc} */
52 | @Override
53 | public int getRegisterCount() {
54 | return 4;
55 | }
56 |
57 | /** {@inheritDoc} */
58 | @Override
59 | public int getA() {
60 | return a;
61 | }
62 |
63 | /** {@inheritDoc} */
64 | @Override
65 | public int getB() {
66 | return b;
67 | }
68 |
69 | /** {@inheritDoc} */
70 | @Override
71 | public int getC() {
72 | return c;
73 | }
74 |
75 | /** {@inheritDoc} */
76 | @Override
77 | public int getD() {
78 | return d;
79 | }
80 |
81 | /** {@inheritDoc} */
82 | @Override
83 | public DecodedInstruction withIndex(int newIndex) {
84 | return new FourRegisterDecodedInstruction(
85 | getFormat(), getOpcode(), newIndex, getIndexType(),
86 | getTarget(), getLiteral(), a, b, c, d);
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/com/android/dx/dex/file/MethodHandlesSection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.android.dx.dex.file;
17 |
18 | import com.android.dx.rop.cst.Constant;
19 | import com.android.dx.rop.cst.CstMethodHandle;
20 | import java.util.Collection;
21 | import java.util.TreeMap;
22 |
23 | public final class MethodHandlesSection extends UniformItemSection {
24 |
25 | private final TreeMap methodHandles = new TreeMap<>();
26 |
27 | public MethodHandlesSection(DexFile dexFile) {
28 | super("method_handles", dexFile, 8);
29 | }
30 |
31 | @Override
32 | public IndexedItem get(Constant cst) {
33 | if (cst == null) {
34 | throw new NullPointerException("cst == null");
35 | }
36 | throwIfNotPrepared();
37 |
38 | IndexedItem result = methodHandles.get((CstMethodHandle) cst);
39 | if (result == null) {
40 | throw new IllegalArgumentException("not found");
41 | }
42 | return result;
43 | }
44 |
45 | @Override
46 | protected void orderItems() {
47 | int index = 0;
48 | for (MethodHandleItem item : methodHandles.values()) {
49 | item.setIndex(index++);
50 | }
51 | }
52 |
53 | @Override
54 | public Collection extends Item> items() {
55 | return methodHandles.values();
56 | }
57 |
58 | public synchronized void intern(CstMethodHandle methodHandle) {
59 | if (methodHandle == null) {
60 | throw new NullPointerException("methodHandle == null");
61 | }
62 |
63 | throwIfPrepared();
64 |
65 | MethodHandleItem result = methodHandles.get(methodHandle);
66 | if (result == null) {
67 | result = new MethodHandleItem(methodHandle);
68 | methodHandles.put(methodHandle, result);
69 | }
70 | }
71 |
72 | int indexOf(CstMethodHandle cstMethodHandle) {
73 | return methodHandles.get(cstMethodHandle).getIndex();
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/com/android/dx/dex/file/IndexedItem.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.dex.file;
18 |
19 | /**
20 | * An item in a Dalvik file which is referenced by index.
21 | */
22 | public abstract class IndexedItem extends Item {
23 | /** {@code >= -1;} assigned index of the item, or {@code -1} if not
24 | * yet assigned */
25 | private int index;
26 |
27 | /**
28 | * Constructs an instance. The index is initially unassigned.
29 | */
30 | public IndexedItem() {
31 | index = -1;
32 | }
33 |
34 | /**
35 | * Gets whether or not this instance has been assigned an index.
36 | *
37 | * @return {@code true} iff this instance has been assigned an index
38 | */
39 | public final boolean hasIndex() {
40 | return (index >= 0);
41 | }
42 |
43 | /**
44 | * Gets the item index.
45 | *
46 | * @return {@code >= 0;} the index
47 | * @throws RuntimeException thrown if the item index is not yet assigned
48 | */
49 | public final int getIndex() {
50 | if (index < 0) {
51 | throw new RuntimeException("index not yet set");
52 | }
53 |
54 | return index;
55 | }
56 |
57 | /**
58 | * Sets the item index. This method may only ever be called once
59 | * per instance, and this will throw a {@code RuntimeException} if
60 | * called a second (or subsequent) time.
61 | *
62 | * @param index {@code >= 0;} the item index
63 | */
64 | public final void setIndex(int index) {
65 | if (this.index != -1) {
66 | throw new RuntimeException("index already set");
67 | }
68 |
69 | this.index = index;
70 | }
71 |
72 | /**
73 | * Gets the index of this item as a string, suitable for including in
74 | * annotations.
75 | *
76 | * @return {@code non-null;} the index string
77 | */
78 | public final String indexString() {
79 | return '[' + Integer.toHexString(index) + ']';
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/com/android/dx/cf/attrib/BaseAnnotations.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.cf.attrib;
18 |
19 | import com.android.dx.rop.annotation.Annotations;
20 | import com.android.dx.util.MutabilityException;
21 |
22 | /**
23 | * Base class for annotations attributes.
24 | */
25 | public abstract class BaseAnnotations extends BaseAttribute {
26 | /** {@code non-null;} list of annotations */
27 | private final Annotations annotations;
28 |
29 | /** {@code >= 0;} attribute data length in the original classfile (not
30 | * including the attribute header) */
31 | private final int byteLength;
32 |
33 | /**
34 | * Constructs an instance.
35 | *
36 | * @param attributeName {@code non-null;} the name of the attribute
37 | * @param annotations {@code non-null;} the list of annotations
38 | * @param byteLength {@code >= 0;} attribute data length in the original
39 | * classfile (not including the attribute header)
40 | */
41 | public BaseAnnotations(String attributeName, Annotations annotations,
42 | int byteLength) {
43 | super(attributeName);
44 |
45 | try {
46 | if (annotations.isMutable()) {
47 | throw new MutabilityException("annotations.isMutable()");
48 | }
49 | } catch (NullPointerException ex) {
50 | // Translate the exception.
51 | throw new NullPointerException("annotations == null");
52 | }
53 |
54 | this.annotations = annotations;
55 | this.byteLength = byteLength;
56 | }
57 |
58 | /** {@inheritDoc} */
59 | @Override
60 | public final int byteLength() {
61 | // Add six for the standard attribute header.
62 | return byteLength + 6;
63 | }
64 |
65 | /**
66 | * Gets the list of annotations associated with this instance.
67 | *
68 | * @return {@code non-null;} the list
69 | */
70 | public final Annotations getAnnotations() {
71 | return annotations;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/com/android/dx/dex/file/AnnotationSetRefItem.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.dex.file;
18 |
19 | import com.android.dx.util.AnnotatedOutput;
20 | import com.android.dx.util.Hex;
21 |
22 | /**
23 | * Indirect reference to an {@link AnnotationSetItem}.
24 | */
25 | public final class AnnotationSetRefItem extends OffsettedItem {
26 | /** the required alignment for instances of this class */
27 | private static final int ALIGNMENT = 4;
28 |
29 | /** write size of this class, in bytes */
30 | private static final int WRITE_SIZE = 4;
31 |
32 | /** {@code non-null;} the annotation set to refer to */
33 | private AnnotationSetItem annotations;
34 |
35 | /**
36 | * Constructs an instance.
37 | *
38 | * @param annotations {@code non-null;} the annotation set to refer to
39 | */
40 | public AnnotationSetRefItem(AnnotationSetItem annotations) {
41 | super(ALIGNMENT, WRITE_SIZE);
42 |
43 | if (annotations == null) {
44 | throw new NullPointerException("annotations == null");
45 | }
46 |
47 | this.annotations = annotations;
48 | }
49 |
50 | /** {@inheritDoc} */
51 | @Override
52 | public ItemType itemType() {
53 | return ItemType.TYPE_ANNOTATION_SET_REF_ITEM;
54 | }
55 |
56 | /** {@inheritDoc} */
57 | @Override
58 | public void addContents(DexFile file) {
59 | MixedItemSection wordData = file.getWordData();
60 |
61 | annotations = wordData.intern(annotations);
62 | }
63 |
64 | /** {@inheritDoc} */
65 | @Override
66 | public String toHuman() {
67 | return annotations.toHuman();
68 | }
69 |
70 | /** {@inheritDoc} */
71 | @Override
72 | protected void writeTo0(DexFile file, AnnotatedOutput out) {
73 | int annotationsOff = annotations.getAbsoluteOffset();
74 |
75 | if (out.annotates()) {
76 | out.annotate(4, " annotations_off: " + Hex.u4(annotationsOff));
77 | }
78 |
79 | out.writeInt(annotationsOff);
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/com/android/dx/rop/cst/CstLong.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.dx.rop.cst;
18 |
19 | import com.android.dx.rop.type.Type;
20 | import com.android.dx.util.Hex;
21 |
22 | /**
23 | * Constants of type {@code CONSTANT_Long_info}.
24 | */
25 | public final class CstLong
26 | extends CstLiteral64 {
27 | /** {@code non-null;} instance representing {@code 0} */
28 | public static final CstLong VALUE_0 = make(0);
29 |
30 | /** {@code non-null;} instance representing {@code 1} */
31 | public static final CstLong VALUE_1 = make(1);
32 |
33 | /**
34 | * Makes an instance for the given value. This may (but does not
35 | * necessarily) return an already-allocated instance.
36 | *
37 | * @param value the {@code long} value
38 | */
39 | public static CstLong make(long value) {
40 | /*
41 | * Note: Javadoc notwithstanding, this implementation always
42 | * allocates.
43 | */
44 | return new CstLong(value);
45 | }
46 |
47 | /**
48 | * Constructs an instance. This constructor is private; use {@link #make}.
49 | *
50 | * @param value the {@code long} value
51 | */
52 | private CstLong(long value) {
53 | super(value);
54 | }
55 |
56 | /** {@inheritDoc} */
57 | @Override
58 | public String toString() {
59 | long value = getLongBits();
60 | return "long{0x" + Hex.u8(value) + " / " + value + '}';
61 | }
62 |
63 | /** {@inheritDoc} */
64 | @Override
65 | public Type getType() {
66 | return Type.LONG;
67 | }
68 |
69 | /** {@inheritDoc} */
70 | @Override
71 | public String typeName() {
72 | return "long";
73 | }
74 |
75 | /** {@inheritDoc} */
76 | @Override
77 | public String toHuman() {
78 | return Long.toString(getLongBits());
79 | }
80 |
81 | /**
82 | * Gets the {@code long} value.
83 | *
84 | * @return the value
85 | */
86 | public long getValue() {
87 | return getLongBits();
88 | }
89 | }
90 |
--------------------------------------------------------------------------------