mirror of
https://github.com/revanced/Apktool.git
synced 2025-01-06 10:05:54 +01:00
[smali] add untracked 2b6 files
This commit is contained in:
parent
0e33e2d477
commit
792188b9fe
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder;
|
||||
|
||||
import org.jf.dexlib2.iface.debug.DebugItem;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class BuilderDebugItem implements DebugItem {
|
||||
@Nullable MethodLocation location;
|
||||
|
||||
public BuilderDebugItem(@Nonnull MethodLocation location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Override public int getCodeAddress() {
|
||||
if (location == null) {
|
||||
throw new IllegalStateException("Cannot get the address of a BuilderDebugItem that isn't associated with " +
|
||||
"a method.");
|
||||
}
|
||||
return location.getCodeAddress();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder;
|
||||
|
||||
import org.jf.dexlib2.base.BaseExceptionHandler;
|
||||
import org.jf.dexlib2.iface.ExceptionHandler;
|
||||
import org.jf.dexlib2.iface.reference.TypeReference;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
class BuilderExceptionHandler {
|
||||
static ExceptionHandler newExceptionHandler(@Nullable final TypeReference exceptionType,
|
||||
@Nonnull final Label handler) {
|
||||
if (exceptionType == null) {
|
||||
return newExceptionHandler(handler);
|
||||
}
|
||||
return new BaseExceptionHandler() {
|
||||
@Nullable @Override public String getExceptionType() {
|
||||
return exceptionType.getType();
|
||||
}
|
||||
|
||||
@Override public int getHandlerCodeAddress() {
|
||||
return handler.getCodeAddress();
|
||||
}
|
||||
|
||||
@Nullable @Override public TypeReference getExceptionTypeReference() {
|
||||
return exceptionType;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static ExceptionHandler newExceptionHandler(@Nonnull final Label handler) {
|
||||
return new BaseExceptionHandler() {
|
||||
@Nullable @Override public String getExceptionType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public int getHandlerCodeAddress() {
|
||||
return handler.getCodeAddress();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static ExceptionHandler newExceptionHandler(@Nullable final String exceptionType,
|
||||
@Nonnull final Label handler) {
|
||||
if (exceptionType == null) {
|
||||
return newExceptionHandler(handler);
|
||||
}
|
||||
return new BaseExceptionHandler() {
|
||||
@Nullable @Override public String getExceptionType() {
|
||||
return exceptionType;
|
||||
}
|
||||
|
||||
@Override public int getHandlerCodeAddress() {
|
||||
return handler.getCodeAddress();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.iface.instruction.Instruction;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class BuilderInstruction implements Instruction {
|
||||
@Nonnull protected final Opcode opcode;
|
||||
|
||||
@Nullable MethodLocation location;
|
||||
|
||||
protected BuilderInstruction(@Nonnull Opcode opcode) {
|
||||
Preconditions.checkFormat(opcode, getFormat());
|
||||
this.opcode = opcode;
|
||||
}
|
||||
|
||||
@Nonnull public Opcode getOpcode() {
|
||||
return opcode;
|
||||
}
|
||||
|
||||
public abstract Format getFormat();
|
||||
|
||||
public int getCodeUnits() {
|
||||
return getFormat().size / 2;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public MethodLocation getLocation() {
|
||||
if (location == null) {
|
||||
throw new IllegalStateException("Cannot get the location of an instruction that hasn't been added to a " +
|
||||
"method.");
|
||||
}
|
||||
return location;
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder;
|
||||
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.iface.instruction.OffsetInstruction;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public abstract class BuilderOffsetInstruction extends BuilderInstruction implements OffsetInstruction {
|
||||
@Nonnull
|
||||
protected final Label target;
|
||||
|
||||
public BuilderOffsetInstruction(@Nonnull Opcode opcode,
|
||||
@Nonnull Label target) {
|
||||
super(opcode);
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@Override public int getCodeOffset() {
|
||||
int codeOffset = internalGetCodeOffset();
|
||||
if ((this.getCodeUnits() == 1 && (codeOffset < Byte.MIN_VALUE || codeOffset > Byte.MAX_VALUE)) ||
|
||||
(this.getCodeUnits() == 2 && (codeOffset < Short.MIN_VALUE || codeOffset > Short.MAX_VALUE))) {
|
||||
throw new IllegalStateException("Target is out of range");
|
||||
}
|
||||
return codeOffset;
|
||||
}
|
||||
|
||||
|
||||
int internalGetCodeOffset() {
|
||||
return target.getCodeAddress() - this.getLocation().getCodeAddress();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Label getTarget() {
|
||||
return target;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder;
|
||||
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.iface.instruction.SwitchPayload;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class BuilderSwitchPayload extends BuilderInstruction implements SwitchPayload {
|
||||
@Nullable
|
||||
MethodLocation referrer;
|
||||
|
||||
protected BuilderSwitchPayload(@Nonnull Opcode opcode) {
|
||||
super(opcode);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public MethodLocation getReferrer() {
|
||||
if (referrer == null) {
|
||||
throw new IllegalStateException("The referrer has not been set yet");
|
||||
}
|
||||
return referrer;
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.jf.dexlib2.base.BaseTryBlock;
|
||||
import org.jf.dexlib2.iface.ExceptionHandler;
|
||||
import org.jf.dexlib2.iface.reference.TypeReference;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
class BuilderTryBlock extends BaseTryBlock<ExceptionHandler> {
|
||||
// We only ever have one exception handler per try block. They are later merged as needed in TryListBuilder
|
||||
@Nonnull public final ExceptionHandler exceptionHandler;
|
||||
@Nonnull public final Label start;
|
||||
// The end location is exclusive, it should point to the codeAddress of the instruction immediately after the last
|
||||
// covered instruction.
|
||||
@Nonnull public final Label end;
|
||||
|
||||
public BuilderTryBlock(@Nonnull Label start, @Nonnull Label end, @Nullable String exceptionType,
|
||||
@Nonnull Label handler) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.exceptionHandler = BuilderExceptionHandler.newExceptionHandler(exceptionType, handler);
|
||||
}
|
||||
|
||||
public BuilderTryBlock(@Nonnull Label start, @Nonnull Label end, @Nullable TypeReference exceptionType,
|
||||
@Nonnull Label handler) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.exceptionHandler = BuilderExceptionHandler.newExceptionHandler(exceptionType, handler);
|
||||
}
|
||||
|
||||
public BuilderTryBlock(@Nonnull Label start, @Nonnull Label end, @Nonnull Label handler) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.exceptionHandler = BuilderExceptionHandler.newExceptionHandler(handler);
|
||||
}
|
||||
|
||||
@Override public int getStartCodeAddress() {
|
||||
return start.getCodeAddress();
|
||||
}
|
||||
|
||||
@Override public int getCodeUnitCount() {
|
||||
return end.getCodeAddress() - start.getCodeAddress();
|
||||
}
|
||||
|
||||
@Nonnull @Override public List<? extends ExceptionHandler> getExceptionHandlers() {
|
||||
return ImmutableList.of(exceptionHandler);
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class Label {
|
||||
@Nullable MethodLocation location;
|
||||
|
||||
Label() {
|
||||
}
|
||||
|
||||
Label(MethodLocation location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public int getCodeAddress() {
|
||||
return getLocation().getCodeAddress();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public MethodLocation getLocation() {
|
||||
if (location == null) {
|
||||
throw new IllegalStateException("Cannot get the location of a label that hasn't been placed yet.");
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
public boolean isPlaced() {
|
||||
return location != null;
|
||||
}
|
||||
}
|
@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder;
|
||||
|
||||
import org.jf.dexlib2.iface.MethodImplementation;
|
||||
import org.jf.dexlib2.iface.reference.StringReference;
|
||||
import org.jf.dexlib2.iface.reference.TypeReference;
|
||||
import org.jf.dexlib2.writer.builder.BuilderStringReference;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MethodImplementationBuilder {
|
||||
// Contains all named labels - both placed and unplaced
|
||||
private final HashMap<String, Label> labels = new HashMap<String, Label>();
|
||||
|
||||
@Nonnull
|
||||
private final MutableMethodImplementation impl;
|
||||
|
||||
private MethodLocation currentLocation;
|
||||
|
||||
public MethodImplementationBuilder(int registerCount) {
|
||||
this.impl = new MutableMethodImplementation(registerCount);
|
||||
this.currentLocation = impl.instructionList.get(0);
|
||||
}
|
||||
|
||||
public MethodImplementation getMethodImplementation() {
|
||||
return impl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new named label at the current location.
|
||||
*
|
||||
* Any previous unplaced references to a label of this name will now refer to this label/location
|
||||
*
|
||||
* @param name The name of the label to add
|
||||
* @return A LabelRef representing the label
|
||||
*/
|
||||
@Nonnull
|
||||
public Label addLabel(@Nonnull String name) {
|
||||
Label label = labels.get(name);
|
||||
|
||||
if (label != null) {
|
||||
if (label.isPlaced()) {
|
||||
throw new IllegalArgumentException("There is already a label with that name.");
|
||||
} else {
|
||||
currentLocation.getLabels().add(label);
|
||||
}
|
||||
} else {
|
||||
label = currentLocation.addNewLabel();
|
||||
labels.put(name, label);
|
||||
}
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a reference to a label with the given name.
|
||||
*
|
||||
* If a label with that name has not been added yet, a new one is created, but is left
|
||||
* in an unplaced state. It is assumed that addLabel(name) will be called at a later
|
||||
* point to define the location of the label.
|
||||
*
|
||||
* @param name The name of the label to get
|
||||
* @return A LabelRef representing the label
|
||||
*/
|
||||
@Nonnull
|
||||
public Label getLabel(@Nonnull String name) {
|
||||
Label label = labels.get(name);
|
||||
if (label == null) {
|
||||
label = new Label();
|
||||
labels.put(name, label);
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
public void addCatch(@Nullable TypeReference type, @Nonnull Label from,
|
||||
@Nonnull Label to, @Nonnull Label handler) {
|
||||
impl.addCatch(type, from, to, handler);
|
||||
}
|
||||
|
||||
public void addCatch(@Nullable String type, @Nonnull Label from, @Nonnull Label to,
|
||||
@Nonnull Label handler) {
|
||||
impl.addCatch(type, from, to, handler);
|
||||
}
|
||||
|
||||
public void addCatch(@Nonnull Label from, @Nonnull Label to, @Nonnull Label handler) {
|
||||
impl.addCatch(from, to, handler);
|
||||
}
|
||||
|
||||
public void addLineNumber(int lineNumber) {
|
||||
currentLocation.addLineNumber(lineNumber);
|
||||
}
|
||||
|
||||
public void addStartLocal(int registerNumber, @Nullable StringReference name, @Nullable TypeReference type,
|
||||
@Nullable StringReference signature) {
|
||||
currentLocation.addStartLocal(registerNumber, name, type, signature);
|
||||
}
|
||||
|
||||
public void addEndLocal(int registerNumber) {
|
||||
currentLocation.addEndLocal(registerNumber);
|
||||
}
|
||||
|
||||
public void addRestartLocal(int registerNumber) {
|
||||
currentLocation.addRestartLocal(registerNumber);
|
||||
}
|
||||
|
||||
public void addPrologue() {
|
||||
currentLocation.addPrologue();
|
||||
}
|
||||
|
||||
public void addEpilogue() {
|
||||
currentLocation.addEpilogue();
|
||||
}
|
||||
|
||||
public void addSetSourceFile(@Nullable BuilderStringReference sourceFile) {
|
||||
currentLocation.addSetSourceFile(sourceFile);
|
||||
}
|
||||
|
||||
public void addInstruction(@Nullable BuilderInstruction instruction) {
|
||||
impl.addInstruction(instruction);
|
||||
currentLocation = impl.instructionList.get(impl.instructionList.size()-1);
|
||||
}
|
||||
}
|
@ -0,0 +1,213 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jf.dexlib2.builder.debug.*;
|
||||
import org.jf.dexlib2.iface.instruction.Instruction;
|
||||
import org.jf.dexlib2.iface.reference.StringReference;
|
||||
import org.jf.dexlib2.iface.reference.TypeReference;
|
||||
import org.jf.dexlib2.writer.builder.BuilderStringReference;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.AbstractSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class MethodLocation {
|
||||
@Nullable BuilderInstruction instruction;
|
||||
int codeAddress;
|
||||
int index;
|
||||
|
||||
private List<Label> labels = Lists.newArrayList();
|
||||
List<BuilderDebugItem> debugItems = Lists.newArrayList();
|
||||
|
||||
MethodLocation(@Nullable BuilderInstruction instruction, int codeAddress, int index) {
|
||||
this.instruction = instruction;
|
||||
this.codeAddress = codeAddress;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Instruction getInstruction() {
|
||||
return instruction;
|
||||
}
|
||||
|
||||
public int getCodeAddress() {
|
||||
return codeAddress;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
void mergeInto(@Nonnull MethodLocation other) {
|
||||
for (Label label: labels) {
|
||||
label.location = other;
|
||||
other.labels.add(label);
|
||||
}
|
||||
|
||||
// We need to keep the debug items in the same order. We add the other debug items to this list, then reassign
|
||||
// the list.
|
||||
for (BuilderDebugItem debugItem: debugItems) {
|
||||
debugItem.location = other;
|
||||
}
|
||||
debugItems.addAll(other.debugItems);
|
||||
other.debugItems = debugItems;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Set<Label> getLabels() {
|
||||
return new AbstractSet<Label>() {
|
||||
@Nonnull
|
||||
@Override public Iterator<Label> iterator() {
|
||||
final Iterator<Label> it = labels.iterator();
|
||||
|
||||
return new Iterator<Label>() {
|
||||
private @Nullable Label currentLabel = null;
|
||||
|
||||
@Override public boolean hasNext() {
|
||||
return it.hasNext();
|
||||
}
|
||||
|
||||
@Override public Label next() {
|
||||
currentLabel = it.next();
|
||||
return currentLabel;
|
||||
}
|
||||
|
||||
@Override public void remove() {
|
||||
if (currentLabel != null) {
|
||||
currentLabel.location = null;
|
||||
}
|
||||
it.remove();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override public int size() {
|
||||
return labels.size();
|
||||
}
|
||||
|
||||
@Override public boolean add(@Nonnull Label label) {
|
||||
if (label.isPlaced()) {
|
||||
throw new IllegalArgumentException("Cannot add a label that is already placed. You must remove " +
|
||||
"it from its current location first.");
|
||||
}
|
||||
label.location = MethodLocation.this;
|
||||
labels.add(label);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Label addNewLabel() {
|
||||
Label label = new Label(this);
|
||||
labels.add(label);
|
||||
return label;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Set<BuilderDebugItem> getDebugItems() {
|
||||
return new AbstractSet<BuilderDebugItem>() {
|
||||
@Nonnull
|
||||
@Override public Iterator<BuilderDebugItem> iterator() {
|
||||
final Iterator<BuilderDebugItem> it = debugItems.iterator();
|
||||
|
||||
return new Iterator<BuilderDebugItem>() {
|
||||
private @Nullable BuilderDebugItem currentDebugItem = null;
|
||||
|
||||
@Override public boolean hasNext() {
|
||||
return it.hasNext();
|
||||
}
|
||||
|
||||
@Override public BuilderDebugItem next() {
|
||||
currentDebugItem = it.next();
|
||||
return currentDebugItem;
|
||||
}
|
||||
|
||||
@Override public void remove() {
|
||||
if (currentDebugItem != null) {
|
||||
currentDebugItem.location = null;
|
||||
}
|
||||
it.remove();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override public int size() {
|
||||
return labels.size();
|
||||
}
|
||||
|
||||
@Override public boolean add(@Nonnull BuilderDebugItem debugItem) {
|
||||
if (debugItem.location != null) {
|
||||
throw new IllegalArgumentException("Cannot add a debug item that has already been added to a " +
|
||||
"method. You must remove it from its current location first.");
|
||||
}
|
||||
debugItem.location = MethodLocation.this;
|
||||
debugItems.add(debugItem);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void addLineNumber(int lineNumber) {
|
||||
debugItems.add(new BuilderLineNumber(this, lineNumber));
|
||||
}
|
||||
|
||||
public void addStartLocal(int registerNumber, @Nullable StringReference name, @Nullable TypeReference type,
|
||||
@Nullable StringReference signature) {
|
||||
debugItems.add(new BuilderStartLocal(this, registerNumber, name, type, signature));
|
||||
}
|
||||
|
||||
public void addEndLocal(int registerNumber) {
|
||||
debugItems.add(new BuilderEndLocal(this, registerNumber));
|
||||
}
|
||||
|
||||
public void addRestartLocal(int registerNumber) {
|
||||
debugItems.add(new BuilderRestartLocal(this, registerNumber));
|
||||
}
|
||||
|
||||
public void addPrologue() {
|
||||
debugItems.add(new BuilderPrologueEnd(this));
|
||||
}
|
||||
|
||||
public void addEpilogue() {
|
||||
debugItems.add(new BuilderEpilogueBegin(this));
|
||||
}
|
||||
|
||||
public void addSetSourceFile(@Nullable BuilderStringReference sourceFile) {
|
||||
debugItems.add(new BuilderSetSourceFile(this, sourceFile));
|
||||
}
|
||||
}
|
@ -0,0 +1,943 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jf.dexlib2.DebugItemType;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.debug.*;
|
||||
import org.jf.dexlib2.builder.instruction.*;
|
||||
import org.jf.dexlib2.iface.ExceptionHandler;
|
||||
import org.jf.dexlib2.iface.MethodImplementation;
|
||||
import org.jf.dexlib2.iface.TryBlock;
|
||||
import org.jf.dexlib2.iface.debug.*;
|
||||
import org.jf.dexlib2.iface.instruction.Instruction;
|
||||
import org.jf.dexlib2.iface.instruction.SwitchElement;
|
||||
import org.jf.dexlib2.iface.instruction.formats.*;
|
||||
import org.jf.dexlib2.iface.reference.TypeReference;
|
||||
import org.jf.util.ExceptionWithContext;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
|
||||
public class MutableMethodImplementation implements MethodImplementation {
|
||||
private final int registerCount;
|
||||
final ArrayList<MethodLocation> instructionList = Lists.newArrayList(new MethodLocation(null, 0, 0));
|
||||
private final ArrayList<BuilderTryBlock> tryBlocks = Lists.newArrayList();
|
||||
private boolean fixInstructions = true;
|
||||
|
||||
public MutableMethodImplementation(@Nonnull MethodImplementation methodImplementation) {
|
||||
this.registerCount = methodImplementation.getRegisterCount();
|
||||
|
||||
int codeAddress = 0;
|
||||
int index = 0;
|
||||
|
||||
for (Instruction instruction: methodImplementation.getInstructions()) {
|
||||
codeAddress += instruction.getCodeUnits();
|
||||
index++;
|
||||
|
||||
instructionList.add(new MethodLocation(null, codeAddress, index));
|
||||
}
|
||||
|
||||
final int[] codeAddressToIndex = new int[codeAddress+1];
|
||||
Arrays.fill(codeAddressToIndex, -1);
|
||||
|
||||
for (int i=0; i<instructionList.size(); i++) {
|
||||
codeAddressToIndex[instructionList.get(i).codeAddress] = i;
|
||||
}
|
||||
|
||||
List<Task> switchPayloadTasks = Lists.newArrayList();
|
||||
index = 0;
|
||||
for (final Instruction instruction: methodImplementation.getInstructions()) {
|
||||
final MethodLocation location = instructionList.get(index);
|
||||
final Opcode opcode = instruction.getOpcode();
|
||||
if (opcode == Opcode.PACKED_SWITCH_PAYLOAD || opcode == Opcode.SPARSE_SWITCH_PAYLOAD) {
|
||||
switchPayloadTasks.add(new Task() {
|
||||
@Override public void perform() {
|
||||
convertAndSetInstruction(location, codeAddressToIndex, instruction);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
convertAndSetInstruction(location, codeAddressToIndex, instruction);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
// the switch instructions must be converted last, so that any switch statements that refer to them have
|
||||
// created the referring labels that we look for
|
||||
for (Task switchPayloadTask: switchPayloadTasks) {
|
||||
switchPayloadTask.perform();
|
||||
}
|
||||
|
||||
for (DebugItem debugItem: methodImplementation.getDebugItems()) {
|
||||
int debugCodeAddress = debugItem.getCodeAddress();
|
||||
int locationIndex = mapCodeAddressToIndex(codeAddressToIndex, debugCodeAddress);
|
||||
MethodLocation debugLocation = instructionList.get(locationIndex);
|
||||
BuilderDebugItem builderDebugItem = convertDebugItem(debugLocation, debugItem);
|
||||
debugLocation.getDebugItems().add(builderDebugItem);
|
||||
builderDebugItem.location = debugLocation;
|
||||
}
|
||||
|
||||
for (TryBlock<? extends ExceptionHandler> tryBlock: methodImplementation.getTryBlocks()) {
|
||||
Label startLabel = newLabel(codeAddressToIndex, tryBlock.getStartCodeAddress());
|
||||
Label endLabel = newLabel(codeAddressToIndex, tryBlock.getStartCodeAddress() + tryBlock.getCodeUnitCount());
|
||||
|
||||
for (ExceptionHandler exceptionHandler: tryBlock.getExceptionHandlers()) {
|
||||
tryBlocks.add(new BuilderTryBlock(startLabel, endLabel,
|
||||
exceptionHandler.getExceptionTypeReference(),
|
||||
newLabel(codeAddressToIndex, exceptionHandler.getHandlerCodeAddress())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private interface Task {
|
||||
void perform();
|
||||
}
|
||||
|
||||
public MutableMethodImplementation(int registerCount) {
|
||||
this.registerCount = registerCount;
|
||||
}
|
||||
|
||||
@Override public int getRegisterCount() {
|
||||
return registerCount;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public List<Instruction> getInstructions() {
|
||||
if (fixInstructions) {
|
||||
fixInstructions();
|
||||
}
|
||||
|
||||
return new AbstractList<Instruction>() {
|
||||
@Override public Instruction get(int i) {
|
||||
if (i >= size()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
if (fixInstructions) {
|
||||
fixInstructions();
|
||||
}
|
||||
return instructionList.get(i).instruction;
|
||||
}
|
||||
|
||||
@Override public int size() {
|
||||
if (fixInstructions) {
|
||||
fixInstructions();
|
||||
}
|
||||
// don't include the last MethodLocation, which always has a null instruction
|
||||
return instructionList.size() - 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Nonnull @Override public List<? extends TryBlock<? extends ExceptionHandler>> getTryBlocks() {
|
||||
if (fixInstructions) {
|
||||
fixInstructions();
|
||||
}
|
||||
return Collections.unmodifiableList(tryBlocks);
|
||||
}
|
||||
|
||||
@Nonnull @Override public Iterable<? extends DebugItem> getDebugItems() {
|
||||
if (fixInstructions) {
|
||||
fixInstructions();
|
||||
}
|
||||
return Iterables.concat(
|
||||
Iterables.transform(instructionList, new Function<MethodLocation, Iterable<? extends DebugItem>>() {
|
||||
@Nullable @Override public Iterable<? extends DebugItem> apply(@Nullable MethodLocation input) {
|
||||
assert input != null;
|
||||
if (fixInstructions) {
|
||||
throw new IllegalStateException("This iterator was invalidated by a change to" +
|
||||
" this MutableMethodImplementation.");
|
||||
}
|
||||
return input.getDebugItems();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void addCatch(@Nullable TypeReference type, @Nonnull Label from,
|
||||
@Nonnull Label to, @Nonnull Label handler) {
|
||||
tryBlocks.add(new BuilderTryBlock(from, to, type, handler));
|
||||
}
|
||||
|
||||
public void addCatch(@Nullable String type, @Nonnull Label from, @Nonnull Label to,
|
||||
@Nonnull Label handler) {
|
||||
tryBlocks.add(new BuilderTryBlock(from, to, type, handler));
|
||||
}
|
||||
|
||||
public void addCatch(@Nonnull Label from, @Nonnull Label to, @Nonnull Label handler) {
|
||||
tryBlocks.add(new BuilderTryBlock(from, to, handler));
|
||||
}
|
||||
|
||||
public void addInstruction(int index, BuilderInstruction instruction) {
|
||||
// the end check here is intentially >= rather than >, because the list always includes an "empty"
|
||||
// (null instruction) MethodLocation at the end. To add an instruction to the end of the list, the user would
|
||||
// provide the index of this empty item, which would be size() - 1.
|
||||
if (index >= instructionList.size()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
if (index == instructionList.size() - 1) {
|
||||
addInstruction(instruction);
|
||||
return;
|
||||
}
|
||||
int codeAddress = instructionList.get(index).getCodeAddress();
|
||||
|
||||
instructionList.add(index, new MethodLocation(instruction, codeAddress, index));
|
||||
codeAddress += instruction.getCodeUnits();
|
||||
|
||||
for (int i=index+1; i<instructionList.size(); i++) {
|
||||
MethodLocation location = instructionList.get(i);
|
||||
location.index++;
|
||||
location.codeAddress = codeAddress;
|
||||
if (location.instruction != null) {
|
||||
codeAddress += location.instruction.getCodeUnits();
|
||||
} else {
|
||||
// only the last MethodLocation should have a null instruction
|
||||
assert i == instructionList.size()-1;
|
||||
}
|
||||
}
|
||||
|
||||
this.fixInstructions = true;
|
||||
}
|
||||
|
||||
public void addInstruction(@Nonnull BuilderInstruction instruction) {
|
||||
MethodLocation last = instructionList.get(instructionList.size()-1);
|
||||
last.instruction = instruction;
|
||||
instruction.location = last;
|
||||
|
||||
int nextCodeAddress = last.codeAddress + instruction.getCodeUnits();
|
||||
instructionList.add(new MethodLocation(null, nextCodeAddress, instructionList.size()));
|
||||
|
||||
this.fixInstructions = true;
|
||||
}
|
||||
|
||||
public void replaceInstruction(int index, @Nonnull BuilderInstruction replacementInstruction) {
|
||||
if (index >= instructionList.size() - 1) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
MethodLocation replaceLocation = instructionList.get(index);
|
||||
replacementInstruction.location = replaceLocation;
|
||||
BuilderInstruction old = replaceLocation.instruction;
|
||||
assert old != null;
|
||||
old.location = null;
|
||||
replaceLocation.instruction = replacementInstruction;
|
||||
|
||||
// TODO: factor out index/address fix up loop
|
||||
int codeAddress = replaceLocation.codeAddress + replaceLocation.instruction.getCodeUnits();
|
||||
for (int i=index+1; i<instructionList.size(); i++) {
|
||||
MethodLocation location = instructionList.get(i);
|
||||
location.codeAddress = codeAddress;
|
||||
|
||||
Instruction instruction = location.getInstruction();
|
||||
if (instruction != null) {
|
||||
codeAddress += instruction.getCodeUnits();
|
||||
} else {
|
||||
assert i == instructionList.size() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
this.fixInstructions = true;
|
||||
}
|
||||
|
||||
public void removeInstruction(int index) {
|
||||
if (index >= instructionList.size() - 1) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
MethodLocation toRemove = instructionList.get(index);
|
||||
toRemove.instruction = null;
|
||||
MethodLocation next = instructionList.get(index+1);
|
||||
toRemove.mergeInto(next);
|
||||
|
||||
instructionList.remove(index);
|
||||
int codeAddress = toRemove.codeAddress;
|
||||
for (int i=index; i<instructionList.size(); i++) {
|
||||
MethodLocation location = instructionList.get(i);
|
||||
location.index = i;
|
||||
location.codeAddress = codeAddress;
|
||||
|
||||
Instruction instruction = location.getInstruction();
|
||||
if (instruction != null) {
|
||||
codeAddress += instruction.getCodeUnits();
|
||||
} else {
|
||||
assert i == instructionList.size() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
this.fixInstructions = true;
|
||||
}
|
||||
|
||||
public void swapInstructions(int index1, int index2) {
|
||||
if (index1 >= instructionList.size() - 1 || index2 >= instructionList.size() - 1) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
MethodLocation first = instructionList.get(index1);
|
||||
MethodLocation second = instructionList.get(index2);
|
||||
|
||||
// only the last MethodLocation may have a null instruction
|
||||
assert first.instruction != null;
|
||||
assert second.instruction != null;
|
||||
|
||||
first.instruction.location = second;
|
||||
second.instruction.location = first;
|
||||
|
||||
{
|
||||
BuilderInstruction tmp = second.instruction;
|
||||
second.instruction = first.instruction;
|
||||
first.instruction = tmp;
|
||||
}
|
||||
|
||||
if (index2 < index1) {
|
||||
int tmp = index2;
|
||||
index2 = index1;
|
||||
index1 = tmp;
|
||||
}
|
||||
|
||||
int codeAddress = first.codeAddress + first.instruction.getCodeUnits();
|
||||
for (int i=index1+1; i<=index2; i++) {
|
||||
MethodLocation location = instructionList.get(i);
|
||||
location.codeAddress = codeAddress;
|
||||
|
||||
Instruction instruction = location.instruction;
|
||||
assert instruction != null;
|
||||
codeAddress += location.instruction.getCodeUnits();
|
||||
}
|
||||
|
||||
this.fixInstructions = true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private BuilderInstruction getFirstNonNop(int startIndex) {
|
||||
|
||||
for (int i=startIndex; i<instructionList.size()-1; i++) {
|
||||
BuilderInstruction instruction = instructionList.get(i).instruction;
|
||||
assert instruction != null;
|
||||
if (instruction.getOpcode() != Opcode.NOP) {
|
||||
return instruction;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void fixInstructions() {
|
||||
HashSet<MethodLocation> payloadLocations = Sets.newHashSet();
|
||||
|
||||
for (MethodLocation location: instructionList) {
|
||||
BuilderInstruction instruction = location.instruction;
|
||||
if (instruction != null) {
|
||||
switch (instruction.getOpcode()) {
|
||||
case SPARSE_SWITCH:
|
||||
case PACKED_SWITCH: {
|
||||
MethodLocation targetLocation =
|
||||
((BuilderOffsetInstruction)instruction).getTarget().getLocation();
|
||||
BuilderInstruction targetInstruction = targetLocation.instruction;
|
||||
if (targetInstruction == null) {
|
||||
throw new IllegalStateException(String.format("Switch instruction at address/index " +
|
||||
"0x%x/%d points to the end of the method.", location.codeAddress, location.index));
|
||||
}
|
||||
|
||||
if (targetInstruction.getOpcode() == Opcode.NOP) {
|
||||
targetInstruction = getFirstNonNop(targetLocation.index+1);
|
||||
}
|
||||
if (targetInstruction == null || !(targetInstruction instanceof BuilderSwitchPayload)) {
|
||||
throw new IllegalStateException(String.format("Switch instruction at address/index " +
|
||||
"0x%x/%d does not refer to a payload instruction.",
|
||||
location.codeAddress, location.index));
|
||||
}
|
||||
if ((instruction.opcode == Opcode.PACKED_SWITCH &&
|
||||
targetInstruction.getOpcode() != Opcode.PACKED_SWITCH_PAYLOAD) ||
|
||||
(instruction.opcode == Opcode.SPARSE_SWITCH &&
|
||||
targetInstruction.getOpcode() != Opcode.SPARSE_SWITCH_PAYLOAD)) {
|
||||
throw new IllegalStateException(String.format("Switch instruction at address/index " +
|
||||
"0x%x/%d refers to the wrong type of payload instruction.",
|
||||
location.codeAddress, location.index));
|
||||
}
|
||||
|
||||
if (!payloadLocations.add(targetLocation)) {
|
||||
throw new IllegalStateException("Multiple switch instructions refer to the same payload. " +
|
||||
"This is not currently supported. Please file a bug :)");
|
||||
}
|
||||
|
||||
((BuilderSwitchPayload)targetInstruction).referrer = location;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean madeChanges;
|
||||
do {
|
||||
madeChanges = false;
|
||||
|
||||
for (int index=0; index<instructionList.size(); index++) {
|
||||
MethodLocation location = instructionList.get(index);
|
||||
BuilderInstruction instruction = location.instruction;
|
||||
if (instruction != null) {
|
||||
switch (instruction.getOpcode()) {
|
||||
case GOTO: {
|
||||
int offset = ((BuilderOffsetInstruction)instruction).internalGetCodeOffset();
|
||||
if (offset < Byte.MIN_VALUE || offset > Byte.MAX_VALUE) {
|
||||
BuilderOffsetInstruction replacement;
|
||||
if (offset < Short.MIN_VALUE || offset > Short.MAX_VALUE) {
|
||||
replacement = new BuilderInstruction30t(Opcode.GOTO_32,
|
||||
((BuilderOffsetInstruction)instruction).getTarget());
|
||||
} else {
|
||||
replacement = new BuilderInstruction20t(Opcode.GOTO_16,
|
||||
((BuilderOffsetInstruction)instruction).getTarget());
|
||||
}
|
||||
replaceInstruction(location.index, replacement);
|
||||
madeChanges = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GOTO_16: {
|
||||
int offset = ((BuilderOffsetInstruction)instruction).internalGetCodeOffset();
|
||||
if (offset < Short.MIN_VALUE || offset > Short.MAX_VALUE) {
|
||||
BuilderOffsetInstruction replacement = new BuilderInstruction30t(Opcode.GOTO_32,
|
||||
((BuilderOffsetInstruction)instruction).getTarget());
|
||||
replaceInstruction(location.index, replacement);
|
||||
madeChanges = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SPARSE_SWITCH_PAYLOAD:
|
||||
case PACKED_SWITCH_PAYLOAD:
|
||||
case ARRAY_PAYLOAD: {
|
||||
if ((location.codeAddress & 0x01) != 0) {
|
||||
int previousIndex = location.index - 1;
|
||||
MethodLocation previousLocation = instructionList.get(previousIndex);
|
||||
Instruction previousInstruction = previousLocation.instruction;
|
||||
assert previousInstruction != null;
|
||||
if (previousInstruction.getOpcode() == Opcode.NOP) {
|
||||
removeInstruction(previousIndex);
|
||||
index--;
|
||||
} else {
|
||||
addInstruction(location.index, new BuilderInstruction10x(Opcode.NOP));
|
||||
index++;
|
||||
}
|
||||
madeChanges = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (madeChanges);
|
||||
|
||||
fixInstructions = false;
|
||||
}
|
||||
|
||||
private int mapCodeAddressToIndex(@Nonnull int[] codeAddressToIndex, int codeAddress) {
|
||||
int index;
|
||||
do {
|
||||
index = codeAddressToIndex[codeAddress];
|
||||
if (index < 0) {
|
||||
codeAddress--;
|
||||
} else {
|
||||
return index;
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private Label newLabel(@Nonnull int[] codeAddressToIndex, int codeAddress) {
|
||||
MethodLocation referent = instructionList.get(mapCodeAddressToIndex(codeAddressToIndex, codeAddress));
|
||||
return referent.addNewLabel();
|
||||
}
|
||||
|
||||
private static class SwitchPayloadReferenceLabel extends Label {
|
||||
@Nonnull public MethodLocation switchLocation;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Label newSwitchPayloadReferenceLabel(@Nonnull int[] codeAddressToIndex, int codeAddress) {
|
||||
MethodLocation referent = instructionList.get(mapCodeAddressToIndex(codeAddressToIndex, codeAddress));
|
||||
Label label = new SwitchPayloadReferenceLabel();
|
||||
referent.getLabels().add(label);
|
||||
return label;
|
||||
}
|
||||
|
||||
private void setInstruction(@Nonnull MethodLocation location, @Nonnull BuilderInstruction instruction) {
|
||||
location.instruction = instruction;
|
||||
instruction.location = location;
|
||||
}
|
||||
|
||||
private void convertAndSetInstruction(@Nonnull MethodLocation location, int[] codeAddressToIndex,
|
||||
@Nonnull Instruction instruction) {
|
||||
switch (instruction.getOpcode().format) {
|
||||
case Format10t:
|
||||
setInstruction(location, newBuilderInstruction10t(location.codeAddress, codeAddressToIndex,
|
||||
(Instruction10t)instruction));
|
||||
return;
|
||||
case Format10x:
|
||||
setInstruction(location, newBuilderInstruction10x((Instruction10x)instruction));
|
||||
return;
|
||||
case Format11n:
|
||||
setInstruction(location, newBuilderInstruction11n((Instruction11n)instruction));
|
||||
return;
|
||||
case Format11x:
|
||||
setInstruction(location, newBuilderInstruction11x((Instruction11x)instruction));
|
||||
return;
|
||||
case Format12x:
|
||||
setInstruction(location, newBuilderInstruction12x((Instruction12x)instruction));
|
||||
return;
|
||||
case Format20bc:
|
||||
setInstruction(location, newBuilderInstruction20bc((Instruction20bc)instruction));
|
||||
return;
|
||||
case Format20t:
|
||||
setInstruction(location, newBuilderInstruction20t(location.codeAddress, codeAddressToIndex,
|
||||
(Instruction20t)instruction));
|
||||
return;
|
||||
case Format21c:
|
||||
setInstruction(location, newBuilderInstruction21c((Instruction21c)instruction));
|
||||
return;
|
||||
case Format21ih:
|
||||
setInstruction(location, newBuilderInstruction21ih((Instruction21ih)instruction));
|
||||
return;
|
||||
case Format21lh:
|
||||
setInstruction(location, newBuilderInstruction10x((Instruction10x)instruction));
|
||||
return;
|
||||
case Format21s:
|
||||
setInstruction(location, newBuilderInstruction21s((Instruction21s)instruction));
|
||||
return;
|
||||
case Format21t:
|
||||
setInstruction(location, newBuilderInstruction21t(location.codeAddress, codeAddressToIndex,
|
||||
(Instruction21t)instruction));
|
||||
return;
|
||||
case Format22b:
|
||||
setInstruction(location, newBuilderInstruction22b((Instruction22b)instruction));
|
||||
return;
|
||||
case Format22c:
|
||||
setInstruction(location, newBuilderInstruction22c((Instruction22c)instruction));
|
||||
return;
|
||||
case Format22s:
|
||||
setInstruction(location, newBuilderInstruction22s((Instruction22s)instruction));
|
||||
return;
|
||||
case Format22t:
|
||||
setInstruction(location, newBuilderInstruction22t(location.codeAddress, codeAddressToIndex,
|
||||
(Instruction22t)instruction));
|
||||
return;
|
||||
case Format22x:
|
||||
setInstruction(location, newBuilderInstruction22x((Instruction22x)instruction));
|
||||
return;
|
||||
case Format23x:
|
||||
setInstruction(location, newBuilderInstruction23x((Instruction23x)instruction));
|
||||
return;
|
||||
case Format30t:
|
||||
setInstruction(location, newBuilderInstruction30t(location.codeAddress, codeAddressToIndex,
|
||||
(Instruction30t)instruction));
|
||||
return;
|
||||
case Format31c:
|
||||
setInstruction(location, newBuilderInstruction31c((Instruction31c)instruction));
|
||||
return;
|
||||
case Format31i:
|
||||
setInstruction(location, newBuilderInstruction31i((Instruction31i)instruction));
|
||||
return;
|
||||
case Format31t:
|
||||
setInstruction(location, newBuilderInstruction31t(location.codeAddress, codeAddressToIndex,
|
||||
(Instruction31t)instruction));
|
||||
return;
|
||||
case Format32x:
|
||||
setInstruction(location, newBuilderInstruction32x((Instruction32x)instruction));
|
||||
return;
|
||||
case Format35c:
|
||||
setInstruction(location, newBuilderInstruction35c((Instruction35c)instruction));
|
||||
return;
|
||||
case Format3rc:
|
||||
setInstruction(location, newBuilderInstruction3rc((Instruction3rc)instruction));
|
||||
return;
|
||||
case Format51l:
|
||||
setInstruction(location, newBuilderInstruction51l((Instruction51l)instruction));
|
||||
return;
|
||||
case PackedSwitchPayload:
|
||||
setInstruction(location,
|
||||
newBuilderPackedSwitchPayload(location, codeAddressToIndex, (PackedSwitchPayload)instruction));
|
||||
return;
|
||||
case SparseSwitchPayload:
|
||||
setInstruction(location,
|
||||
newBuilderSparseSwitchPayload(location, codeAddressToIndex, (SparseSwitchPayload)instruction));
|
||||
case ArrayPayload:
|
||||
setInstruction(location, newBuilderArrayPayload((ArrayPayload)instruction));
|
||||
default:
|
||||
throw new ExceptionWithContext("Instruction format %s not supported", instruction.getOpcode().format);
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction10t newBuilderInstruction10t(int codeAddress, int[] codeAddressToIndex,
|
||||
@Nonnull Instruction10t instruction) {
|
||||
return new BuilderInstruction10t(
|
||||
instruction.getOpcode(),
|
||||
newLabel(codeAddressToIndex, codeAddress + instruction.getCodeOffset()));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction10x newBuilderInstruction10x(@Nonnull Instruction10x instruction) {
|
||||
return new BuilderInstruction10x(
|
||||
instruction.getOpcode());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction11n newBuilderInstruction11n(@Nonnull Instruction11n instruction) {
|
||||
return new BuilderInstruction11n(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getNarrowLiteral());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction11x newBuilderInstruction11x(@Nonnull Instruction11x instruction) {
|
||||
return new BuilderInstruction11x(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction12x newBuilderInstruction12x(@Nonnull Instruction12x instruction) {
|
||||
return new BuilderInstruction12x(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getRegisterB());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction20bc newBuilderInstruction20bc(@Nonnull Instruction20bc instruction) {
|
||||
return new BuilderInstruction20bc(
|
||||
instruction.getOpcode(),
|
||||
instruction.getVerificationError(),
|
||||
instruction.getReference());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction20t newBuilderInstruction20t(int codeAddress, int[] codeAddressToIndex,
|
||||
@Nonnull Instruction20t instruction) {
|
||||
return new BuilderInstruction20t(
|
||||
instruction.getOpcode(),
|
||||
newLabel(codeAddressToIndex, codeAddress + instruction.getCodeOffset()));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction21c newBuilderInstruction21c(@Nonnull Instruction21c instruction) {
|
||||
return new BuilderInstruction21c(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getReference());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction21ih newBuilderInstruction21ih(@Nonnull Instruction21ih instruction) {
|
||||
return new BuilderInstruction21ih(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getHatLiteral());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction21lh newBuilderInstruction21lh(@Nonnull Instruction21lh instruction) {
|
||||
return new BuilderInstruction21lh(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getHatLiteral());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction21s newBuilderInstruction21s(@Nonnull Instruction21s instruction) {
|
||||
return new BuilderInstruction21s(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getNarrowLiteral());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction21t newBuilderInstruction21t(int codeAddress, int[] codeAddressToIndex,
|
||||
@Nonnull Instruction21t instruction) {
|
||||
return new BuilderInstruction21t(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
newLabel(codeAddressToIndex, codeAddress + instruction.getCodeOffset()));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction22b newBuilderInstruction22b(@Nonnull Instruction22b instruction) {
|
||||
return new BuilderInstruction22b(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getRegisterB(),
|
||||
instruction.getNarrowLiteral());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction22c newBuilderInstruction22c(@Nonnull Instruction22c instruction) {
|
||||
return new BuilderInstruction22c(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getRegisterB(),
|
||||
instruction.getReference());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction22s newBuilderInstruction22s(@Nonnull Instruction22s instruction) {
|
||||
return new BuilderInstruction22s(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getRegisterB(),
|
||||
instruction.getNarrowLiteral());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction22t newBuilderInstruction22t(int codeAddress, int[] codeAddressToIndex,
|
||||
@Nonnull Instruction22t instruction) {
|
||||
return new BuilderInstruction22t(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getRegisterB(),
|
||||
newLabel(codeAddressToIndex, codeAddress + instruction.getCodeOffset()));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction22x newBuilderInstruction22x(@Nonnull Instruction22x instruction) {
|
||||
return new BuilderInstruction22x(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getRegisterB());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction23x newBuilderInstruction23x(@Nonnull Instruction23x instruction) {
|
||||
return new BuilderInstruction23x(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getRegisterB(),
|
||||
instruction.getRegisterC());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction30t newBuilderInstruction30t(int codeAddress, int[] codeAddressToIndex,
|
||||
@Nonnull Instruction30t instruction) {
|
||||
return new BuilderInstruction30t(
|
||||
instruction.getOpcode(),
|
||||
newLabel(codeAddressToIndex, codeAddress + instruction.getCodeOffset()));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction31c newBuilderInstruction31c(@Nonnull Instruction31c instruction) {
|
||||
return new BuilderInstruction31c(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getReference());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction31i newBuilderInstruction31i(@Nonnull Instruction31i instruction) {
|
||||
return new BuilderInstruction31i(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getNarrowLiteral());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction31t newBuilderInstruction31t(int codeAddress, int[] codeAddressToIndex,
|
||||
@Nonnull Instruction31t instruction) {
|
||||
Label newLabel;
|
||||
if (instruction.getOpcode() != Opcode.FILL_ARRAY_DATA) {
|
||||
// if it's a sparse switch or packed switch
|
||||
newLabel = newSwitchPayloadReferenceLabel(codeAddressToIndex, codeAddress + instruction.getCodeOffset());
|
||||
} else {
|
||||
newLabel = newLabel(codeAddressToIndex, codeAddress + instruction.getCodeOffset());
|
||||
}
|
||||
return new BuilderInstruction31t(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
newLabel);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction32x newBuilderInstruction32x(@Nonnull Instruction32x instruction) {
|
||||
return new BuilderInstruction32x(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getRegisterB());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction35c newBuilderInstruction35c(@Nonnull Instruction35c instruction) {
|
||||
return new BuilderInstruction35c(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterCount(),
|
||||
instruction.getRegisterC(),
|
||||
instruction.getRegisterD(),
|
||||
instruction.getRegisterE(),
|
||||
instruction.getRegisterF(),
|
||||
instruction.getRegisterG(),
|
||||
instruction.getReference());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction3rc newBuilderInstruction3rc(@Nonnull Instruction3rc instruction) {
|
||||
return new BuilderInstruction3rc(
|
||||
instruction.getOpcode(),
|
||||
instruction.getStartRegister(),
|
||||
instruction.getRegisterCount(),
|
||||
instruction.getReference());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderInstruction51l newBuilderInstruction51l(@Nonnull Instruction51l instruction) {
|
||||
return new BuilderInstruction51l(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getWideLiteral());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private MethodLocation findSwitchForPayload(@Nonnull MethodLocation payloadLocation) {
|
||||
MethodLocation location = payloadLocation;
|
||||
MethodLocation switchLocation = null;
|
||||
do {
|
||||
for (Label label: location.getLabels()) {
|
||||
if (label instanceof SwitchPayloadReferenceLabel) {
|
||||
if (switchLocation != null) {
|
||||
throw new IllegalStateException("Multiple switch instructions refer to the same payload. " +
|
||||
"This is not currently supported. Please file a bug :)");
|
||||
}
|
||||
switchLocation = ((SwitchPayloadReferenceLabel)label).switchLocation;
|
||||
}
|
||||
}
|
||||
|
||||
// A switch instruction can refer to the payload instruction itself, or to a nop before the payload
|
||||
// instruction.
|
||||
// We need to search for all occurrences of a switch reference, so we can detect when multiple switch
|
||||
// statements refer to the same payload
|
||||
// TODO: confirm that it could refer to the first NOP in a series of NOPs preceding the payload
|
||||
if (location.index == 0) {
|
||||
return switchLocation;
|
||||
}
|
||||
location = instructionList.get(location.index - 1);
|
||||
if (location.instruction == null || location.instruction.getOpcode() != Opcode.NOP) {
|
||||
return switchLocation;
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderPackedSwitchPayload newBuilderPackedSwitchPayload(@Nonnull MethodLocation location,
|
||||
@Nonnull int[] codeAddressToIndex,
|
||||
@Nonnull PackedSwitchPayload instruction) {
|
||||
List<? extends SwitchElement> switchElements = instruction.getSwitchElements();
|
||||
if (switchElements.size() == 0) {
|
||||
return new BuilderPackedSwitchPayload(0, null);
|
||||
}
|
||||
|
||||
MethodLocation switchLocation = findSwitchForPayload(location);
|
||||
int baseAddress;
|
||||
if (switchLocation == null) {
|
||||
baseAddress = 0;
|
||||
} else {
|
||||
baseAddress = switchLocation.codeAddress;
|
||||
}
|
||||
|
||||
List<Label> labels = Lists.newArrayList();
|
||||
for (SwitchElement element: switchElements) {
|
||||
labels.add(newLabel(codeAddressToIndex, element.getOffset() - baseAddress));
|
||||
}
|
||||
|
||||
return new BuilderPackedSwitchPayload(switchElements.get(0).getKey(), labels);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderSparseSwitchPayload newBuilderSparseSwitchPayload(@Nonnull MethodLocation location,
|
||||
@Nonnull int[] codeAddressToIndex,
|
||||
@Nonnull SparseSwitchPayload instruction) {
|
||||
List<? extends SwitchElement> switchElements = instruction.getSwitchElements();
|
||||
if (switchElements.size() == 0) {
|
||||
return new BuilderSparseSwitchPayload(null);
|
||||
}
|
||||
|
||||
MethodLocation switchLocation = findSwitchForPayload(location);
|
||||
int baseAddress;
|
||||
if (switchLocation == null) {
|
||||
baseAddress = 0;
|
||||
} else {
|
||||
baseAddress = switchLocation.codeAddress;
|
||||
}
|
||||
|
||||
List<SwitchLabelElement> labelElements = Lists.newArrayList();
|
||||
for (SwitchElement element: switchElements) {
|
||||
labelElements.add(new SwitchLabelElement(element.getKey(),
|
||||
newLabel(codeAddressToIndex, element.getOffset() - baseAddress)));
|
||||
}
|
||||
|
||||
return new BuilderSparseSwitchPayload(labelElements);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderArrayPayload newBuilderArrayPayload(@Nonnull ArrayPayload instruction) {
|
||||
return new BuilderArrayPayload(instruction.getElementWidth(), instruction.getArrayElements());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BuilderDebugItem convertDebugItem(@Nonnull MethodLocation location, @Nonnull DebugItem debugItem) {
|
||||
switch (debugItem.getDebugItemType()) {
|
||||
case DebugItemType.START_LOCAL: {
|
||||
StartLocal startLocal = (StartLocal)debugItem;
|
||||
return new BuilderStartLocal(location, startLocal.getRegister(), startLocal.getNameReference(),
|
||||
startLocal.getTypeReference(), startLocal.getSignatureReference());
|
||||
}
|
||||
case DebugItemType.END_LOCAL: {
|
||||
EndLocal endLocal = (EndLocal)debugItem;
|
||||
return new BuilderEndLocal(location, endLocal.getRegister());
|
||||
}
|
||||
case DebugItemType.RESTART_LOCAL: {
|
||||
RestartLocal restartLocal = (RestartLocal)debugItem;
|
||||
return new BuilderRestartLocal(location, restartLocal.getRegister());
|
||||
}
|
||||
case DebugItemType.PROLOGUE_END:
|
||||
return new BuilderPrologueEnd(location);
|
||||
case DebugItemType.EPILOGUE_BEGIN:
|
||||
return new BuilderEpilogueBegin(location);
|
||||
case DebugItemType.LINE_NUMBER: {
|
||||
LineNumber lineNumber = (LineNumber)debugItem;
|
||||
return new BuilderLineNumber(location, lineNumber.getLineNumber());
|
||||
}
|
||||
case DebugItemType.SET_SOURCE_FILE: {
|
||||
SetSourceFile setSourceFile = (SetSourceFile)debugItem;
|
||||
return new BuilderSetSourceFile(location, setSourceFile.getSourceFileReference());
|
||||
}
|
||||
default:
|
||||
throw new ExceptionWithContext("Invalid debug item type: " + debugItem.getDebugItemType());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class SwitchLabelElement {
|
||||
public final int key;
|
||||
@Nonnull public final Label target;
|
||||
|
||||
public SwitchLabelElement(int key, @Nonnull Label target) {
|
||||
this.key = key;
|
||||
this.target = target;
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.debug;
|
||||
|
||||
import org.jf.dexlib2.DebugItemType;
|
||||
import org.jf.dexlib2.builder.BuilderDebugItem;
|
||||
import org.jf.dexlib2.builder.MethodLocation;
|
||||
import org.jf.dexlib2.iface.debug.EndLocal;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class BuilderEndLocal extends BuilderDebugItem implements EndLocal {
|
||||
private final int register;
|
||||
|
||||
public BuilderEndLocal(@Nonnull MethodLocation location,
|
||||
int register) {
|
||||
super(location);
|
||||
this.register = register;
|
||||
}
|
||||
|
||||
@Override public int getRegister() { return register; }
|
||||
@Nullable @Override public String getName() { return null; }
|
||||
@Nullable @Override public String getType() { return null; }
|
||||
@Nullable @Override public String getSignature() { return null; }
|
||||
|
||||
@Override public int getDebugItemType() { return DebugItemType.END_LOCAL; }
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.debug;
|
||||
|
||||
import org.jf.dexlib2.DebugItemType;
|
||||
import org.jf.dexlib2.builder.BuilderDebugItem;
|
||||
import org.jf.dexlib2.builder.MethodLocation;
|
||||
import org.jf.dexlib2.iface.debug.EpilogueBegin;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderEpilogueBegin extends BuilderDebugItem implements EpilogueBegin {
|
||||
public BuilderEpilogueBegin(@Nonnull MethodLocation location) {
|
||||
super(location);
|
||||
}
|
||||
|
||||
@Override public int getDebugItemType() { return DebugItemType.EPILOGUE_BEGIN; }
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.debug;
|
||||
|
||||
import org.jf.dexlib2.DebugItemType;
|
||||
import org.jf.dexlib2.builder.BuilderDebugItem;
|
||||
import org.jf.dexlib2.builder.MethodLocation;
|
||||
import org.jf.dexlib2.iface.debug.LineNumber;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderLineNumber extends BuilderDebugItem implements LineNumber {
|
||||
private final int lineNumber;
|
||||
|
||||
public BuilderLineNumber(@Nonnull MethodLocation location,
|
||||
int lineNumber) {
|
||||
super(location);
|
||||
this.lineNumber = lineNumber;
|
||||
}
|
||||
|
||||
@Override public int getLineNumber() { return lineNumber; }
|
||||
|
||||
@Override public int getDebugItemType() { return DebugItemType.LINE_NUMBER; }
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.debug;
|
||||
|
||||
import org.jf.dexlib2.DebugItemType;
|
||||
import org.jf.dexlib2.builder.BuilderDebugItem;
|
||||
import org.jf.dexlib2.builder.MethodLocation;
|
||||
import org.jf.dexlib2.iface.debug.PrologueEnd;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderPrologueEnd extends BuilderDebugItem implements PrologueEnd {
|
||||
public BuilderPrologueEnd(@Nonnull MethodLocation location) {
|
||||
super(location);
|
||||
}
|
||||
|
||||
@Override public int getDebugItemType() { return DebugItemType.PROLOGUE_END; }
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.debug;
|
||||
|
||||
import org.jf.dexlib2.DebugItemType;
|
||||
import org.jf.dexlib2.builder.BuilderDebugItem;
|
||||
import org.jf.dexlib2.builder.MethodLocation;
|
||||
import org.jf.dexlib2.iface.debug.RestartLocal;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class BuilderRestartLocal extends BuilderDebugItem implements RestartLocal {
|
||||
private final int register;
|
||||
|
||||
public BuilderRestartLocal(@Nonnull MethodLocation location,
|
||||
int register) {
|
||||
super(location);
|
||||
this.register = register;
|
||||
}
|
||||
|
||||
@Override public int getRegister() { return register; }
|
||||
@Nullable @Override public String getName() { return null; }
|
||||
@Nullable @Override public String getType() { return null; }
|
||||
@Nullable @Override public String getSignature() { return null; }
|
||||
|
||||
@Override public int getDebugItemType() { return DebugItemType.RESTART_LOCAL; }
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.debug;
|
||||
|
||||
import org.jf.dexlib2.DebugItemType;
|
||||
import org.jf.dexlib2.builder.BuilderDebugItem;
|
||||
import org.jf.dexlib2.builder.MethodLocation;
|
||||
import org.jf.dexlib2.iface.debug.SetSourceFile;
|
||||
import org.jf.dexlib2.iface.reference.StringReference;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class BuilderSetSourceFile extends BuilderDebugItem implements SetSourceFile {
|
||||
@Nullable
|
||||
private final StringReference sourceFile;
|
||||
|
||||
public BuilderSetSourceFile(@Nonnull MethodLocation location,
|
||||
@Nullable StringReference sourceFile) {
|
||||
super(location);
|
||||
this.sourceFile = sourceFile;
|
||||
}
|
||||
|
||||
@Override public int getDebugItemType() { return DebugItemType.SET_SOURCE_FILE; }
|
||||
|
||||
@Nullable @Override public String getSourceFile() {
|
||||
return sourceFile==null?null:sourceFile.getString();
|
||||
}
|
||||
|
||||
@Nullable @Override public StringReference getSourceFileReference() {
|
||||
return sourceFile;
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.debug;
|
||||
|
||||
import org.jf.dexlib2.DebugItemType;
|
||||
import org.jf.dexlib2.builder.BuilderDebugItem;
|
||||
import org.jf.dexlib2.builder.MethodLocation;
|
||||
import org.jf.dexlib2.iface.debug.StartLocal;
|
||||
import org.jf.dexlib2.iface.reference.StringReference;
|
||||
import org.jf.dexlib2.iface.reference.TypeReference;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class BuilderStartLocal extends BuilderDebugItem implements StartLocal {
|
||||
private final int register;
|
||||
@Nullable private final StringReference name;
|
||||
@Nullable private final TypeReference type;
|
||||
@Nullable private final StringReference signature;
|
||||
|
||||
public BuilderStartLocal(@Nonnull MethodLocation location,
|
||||
int register,
|
||||
@Nullable StringReference name,
|
||||
@Nullable TypeReference type,
|
||||
@Nullable StringReference signature) {
|
||||
super(location);
|
||||
this.register = register;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
@Override public int getRegister() { return register; }
|
||||
|
||||
@Nullable @Override public StringReference getNameReference() { return name; }
|
||||
@Nullable @Override public TypeReference getTypeReference() { return type; }
|
||||
@Nullable @Override public StringReference getSignatureReference() { return signature; }
|
||||
|
||||
@Nullable @Override public String getName() {
|
||||
return name==null?null:name.getString();
|
||||
}
|
||||
|
||||
@Nullable @Override public String getType() {
|
||||
return type==null?null:type.getType();
|
||||
}
|
||||
|
||||
@Nullable @Override public String getSignature() {
|
||||
return signature==null?null:signature.getString();
|
||||
}
|
||||
|
||||
@Override public int getDebugItemType() { return DebugItemType.START_LOCAL; }
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.ArrayPayload;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class BuilderArrayPayload extends BuilderInstruction implements ArrayPayload {
|
||||
public static final Opcode OPCODE = Opcode.ARRAY_PAYLOAD;
|
||||
|
||||
protected final int elementWidth;
|
||||
@Nonnull protected final List<Number> arrayElements;
|
||||
|
||||
public BuilderArrayPayload(int elementWidth,
|
||||
@Nullable List<Number> arrayElements) {
|
||||
super(OPCODE);
|
||||
this.elementWidth = elementWidth;
|
||||
this.arrayElements = arrayElements==null?ImmutableList.<Number>of():arrayElements;
|
||||
}
|
||||
|
||||
@Override public int getElementWidth() { return elementWidth; }
|
||||
@Nonnull @Override public List<Number> getArrayElements() { return arrayElements; }
|
||||
|
||||
@Override public int getCodeUnits() { return 4 + (elementWidth * arrayElements.size() + 1) / 2; }
|
||||
@Override public Format getFormat() { return OPCODE.format; }
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderOffsetInstruction;
|
||||
import org.jf.dexlib2.builder.Label;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction10t;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction10t extends BuilderOffsetInstruction implements Instruction10t {
|
||||
public static final Format FORMAT = Format.Format10t;
|
||||
|
||||
public BuilderInstruction10t(@Nonnull Opcode opcode,
|
||||
@Nonnull Label target) {
|
||||
super(opcode, target);
|
||||
}
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction10x;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction10x extends BuilderInstruction implements Instruction10x {
|
||||
public static final Format FORMAT = Format.Format10x;
|
||||
|
||||
public BuilderInstruction10x(@Nonnull Opcode opcode) {
|
||||
super(opcode);
|
||||
}
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction11n;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction11n extends BuilderInstruction implements Instruction11n {
|
||||
public static final Format FORMAT = Format.Format11n;
|
||||
|
||||
protected final int registerA;
|
||||
protected final int literal;
|
||||
|
||||
public BuilderInstruction11n(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
int literal) {
|
||||
super(opcode);
|
||||
this.registerA = Preconditions.checkNibbleRegister(registerA);
|
||||
this.literal = Preconditions.checkNibbleLiteral(literal);
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Override public int getNarrowLiteral() { return literal; }
|
||||
@Override public long getWideLiteral() { return literal; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction11x;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction11x extends BuilderInstruction implements Instruction11x {
|
||||
public static final Format FORMAT = Format.Format11x;
|
||||
|
||||
protected final int registerA;
|
||||
|
||||
public BuilderInstruction11x(@Nonnull Opcode opcode,
|
||||
int registerA) {
|
||||
super(opcode);
|
||||
this.registerA = Preconditions.checkByteRegister(registerA);
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction12x;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction12x extends BuilderInstruction implements Instruction12x {
|
||||
public static final Format FORMAT = Format.Format12x;
|
||||
|
||||
protected final int registerA;
|
||||
protected final int registerB;
|
||||
|
||||
public BuilderInstruction12x(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
int registerB) {
|
||||
super(opcode);
|
||||
this.registerA = Preconditions.checkNibbleRegister(registerA);
|
||||
this.registerB = Preconditions.checkNibbleRegister(registerB);
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Override public int getRegisterB() { return registerB; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction20bc;
|
||||
import org.jf.dexlib2.iface.reference.Reference;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction20bc extends BuilderInstruction implements Instruction20bc {
|
||||
public static final Format FORMAT = Format.Format20bc;
|
||||
|
||||
protected final int verificationError;
|
||||
@Nonnull protected final Reference reference;
|
||||
|
||||
public BuilderInstruction20bc(@Nonnull Opcode opcode,
|
||||
int verificationError,
|
||||
@Nonnull Reference reference) {
|
||||
super(opcode);
|
||||
this.verificationError = Preconditions.checkVerificationError(verificationError);
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
@Override public int getVerificationError() { return verificationError; }
|
||||
@Nonnull @Override public Reference getReference() { return reference; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderOffsetInstruction;
|
||||
import org.jf.dexlib2.builder.Label;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction20t;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction20t extends BuilderOffsetInstruction implements Instruction20t {
|
||||
public static final Format FORMAT = Format.Format20t;
|
||||
|
||||
public BuilderInstruction20t(@Nonnull Opcode opcode,
|
||||
@Nonnull Label target) {
|
||||
super(opcode, target);
|
||||
}
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction21c;
|
||||
import org.jf.dexlib2.iface.reference.Reference;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction21c extends BuilderInstruction implements Instruction21c {
|
||||
public static final Format FORMAT = Format.Format21c;
|
||||
|
||||
protected final int registerA;
|
||||
@Nonnull protected final Reference reference;
|
||||
|
||||
public BuilderInstruction21c(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
@Nonnull Reference reference) {
|
||||
super(opcode);
|
||||
this.registerA = Preconditions.checkByteRegister(registerA);
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Nonnull @Override public Reference getReference() { return reference; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction21ih;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction21ih extends BuilderInstruction implements Instruction21ih {
|
||||
public static final Format FORMAT = Format.Format21ih;
|
||||
|
||||
protected final int registerA;
|
||||
protected final int literal;
|
||||
|
||||
public BuilderInstruction21ih(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
int literal) {
|
||||
super(opcode);
|
||||
this.registerA = Preconditions.checkByteRegister(registerA);
|
||||
this.literal = Preconditions.checkIntegerHatLiteral(literal);
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Override public int getNarrowLiteral() { return literal; }
|
||||
@Override public long getWideLiteral() { return literal; }
|
||||
@Override public short getHatLiteral() { return (short)(literal >>> 16); }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction21lh;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction21lh extends BuilderInstruction implements Instruction21lh {
|
||||
public static final Format FORMAT = Format.Format21lh;
|
||||
|
||||
protected final int registerA;
|
||||
protected final long literal;
|
||||
|
||||
public BuilderInstruction21lh(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
long literal) {
|
||||
super(opcode);
|
||||
this.registerA = Preconditions.checkByteRegister(registerA);
|
||||
this.literal = Preconditions.checkLongHatLiteral(literal);
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Override public long getWideLiteral() { return literal; }
|
||||
@Override public short getHatLiteral() { return (short)(literal >>> 48); }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction21s;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction21s extends BuilderInstruction implements Instruction21s {
|
||||
public static final Format FORMAT = Format.Format21s;
|
||||
|
||||
protected final int registerA;
|
||||
protected final int literal;
|
||||
|
||||
public BuilderInstruction21s(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
int literal) {
|
||||
super(opcode);
|
||||
this.registerA = Preconditions.checkByteRegister(registerA);
|
||||
this.literal = Preconditions.checkShortLiteral(literal);
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Override public int getNarrowLiteral() { return literal; }
|
||||
@Override public long getWideLiteral() { return literal; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderOffsetInstruction;
|
||||
import org.jf.dexlib2.builder.Label;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction21t;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction21t extends BuilderOffsetInstruction implements Instruction21t {
|
||||
public static final Format FORMAT = Format.Format21t;
|
||||
|
||||
protected final int registerA;
|
||||
|
||||
public BuilderInstruction21t(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
@Nonnull Label target) {
|
||||
super(opcode, target);
|
||||
this.registerA = Preconditions.checkByteRegister(registerA);
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction22b;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction22b extends BuilderInstruction implements Instruction22b {
|
||||
public static final Format FORMAT = Format.Format22b;
|
||||
|
||||
protected final int registerA;
|
||||
protected final int registerB;
|
||||
protected final int literal;
|
||||
|
||||
public BuilderInstruction22b(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
int registerB,
|
||||
int literal) {
|
||||
super(opcode);
|
||||
this.registerA = Preconditions.checkByteRegister(registerA);
|
||||
this.registerB = Preconditions.checkByteRegister(registerB);
|
||||
this.literal = Preconditions.checkByteLiteral(literal);
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Override public int getRegisterB() { return registerB; }
|
||||
@Override public int getNarrowLiteral() { return literal; }
|
||||
@Override public long getWideLiteral() { return literal; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction22c;
|
||||
import org.jf.dexlib2.iface.reference.Reference;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction22c extends BuilderInstruction implements Instruction22c {
|
||||
public static final Format FORMAT = Format.Format22c;
|
||||
|
||||
protected final int registerA;
|
||||
protected final int registerB;
|
||||
@Nonnull protected final Reference reference;
|
||||
|
||||
public BuilderInstruction22c(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
int registerB,
|
||||
@Nonnull Reference reference) {
|
||||
super(opcode);
|
||||
this.registerA = Preconditions.checkNibbleRegister(registerA);
|
||||
this.registerB = Preconditions.checkNibbleRegister(registerB);
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Override public int getRegisterB() { return registerB; }
|
||||
@Nonnull @Override public Reference getReference() { return reference; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction22s;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction22s extends BuilderInstruction implements Instruction22s {
|
||||
public static final Format FORMAT = Format.Format22s;
|
||||
|
||||
protected final int registerA;
|
||||
protected final int registerB;
|
||||
protected final int literal;
|
||||
|
||||
public BuilderInstruction22s(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
int registerB,
|
||||
int literal) {
|
||||
super(opcode);
|
||||
this.registerA = Preconditions.checkNibbleRegister(registerA);
|
||||
this.registerB = Preconditions.checkNibbleRegister(registerB);
|
||||
this.literal = Preconditions.checkShortLiteral(literal);
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Override public int getRegisterB() { return registerB; }
|
||||
@Override public int getNarrowLiteral() { return literal; }
|
||||
@Override public long getWideLiteral() { return literal; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderOffsetInstruction;
|
||||
import org.jf.dexlib2.builder.Label;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction22t;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction22t extends BuilderOffsetInstruction implements Instruction22t {
|
||||
public static final Format FORMAT = Format.Format22t;
|
||||
|
||||
protected final int registerA;
|
||||
protected final int registerB;
|
||||
|
||||
public BuilderInstruction22t(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
int registerB,
|
||||
@Nonnull Label target) {
|
||||
super(opcode, target);
|
||||
this.registerA = Preconditions.checkNibbleRegister(registerA);
|
||||
this.registerB = Preconditions.checkNibbleRegister(registerB);
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Override public int getRegisterB() { return registerB; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction22x;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction22x extends BuilderInstruction implements Instruction22x {
|
||||
public static final Format FORMAT = Format.Format22x;
|
||||
|
||||
protected final int registerA;
|
||||
protected final int registerB;
|
||||
|
||||
public BuilderInstruction22x(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
int registerB) {
|
||||
super(opcode);
|
||||
this.registerA = Preconditions.checkByteRegister(registerA);
|
||||
this.registerB = Preconditions.checkShortRegister(registerB);
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Override public int getRegisterB() { return registerB; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction23x;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction23x extends BuilderInstruction implements Instruction23x {
|
||||
public static final Format FORMAT = Format.Format23x;
|
||||
|
||||
protected final int registerA;
|
||||
protected final int registerB;
|
||||
protected final int registerC;
|
||||
|
||||
public BuilderInstruction23x(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
int registerB,
|
||||
int registerC) {
|
||||
super(opcode);
|
||||
this.registerA = Preconditions.checkByteRegister(registerA);
|
||||
this.registerB = Preconditions.checkByteRegister(registerB);
|
||||
this.registerC = Preconditions.checkByteRegister(registerC);
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Override public int getRegisterB() { return registerB; }
|
||||
@Override public int getRegisterC() { return registerC; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderOffsetInstruction;
|
||||
import org.jf.dexlib2.builder.Label;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction30t;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction30t extends BuilderOffsetInstruction implements Instruction30t {
|
||||
public static final Format FORMAT = Format.Format30t;
|
||||
|
||||
public BuilderInstruction30t(@Nonnull Opcode opcode,
|
||||
@Nonnull Label target) {
|
||||
super(opcode, target);
|
||||
}
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
||||
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction31c;
|
||||
import org.jf.dexlib2.iface.reference.Reference;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction31c extends BuilderInstruction implements Instruction31c {
|
||||
public static final Format FORMAT = Format.Format31c;
|
||||
|
||||
protected final int registerA;
|
||||
@Nonnull protected final Reference reference;
|
||||
|
||||
public BuilderInstruction31c(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
@Nonnull Reference reference) {
|
||||
super(opcode);
|
||||
this.registerA = Preconditions.checkByteRegister(registerA);
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Nonnull @Override public Reference getReference() { return reference; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction31i;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction31i extends BuilderInstruction implements Instruction31i {
|
||||
public static final Format FORMAT = Format.Format31i;
|
||||
|
||||
protected final int registerA;
|
||||
protected final int literal;
|
||||
|
||||
public BuilderInstruction31i(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
int literal) {
|
||||
super(opcode);
|
||||
this.registerA = Preconditions.checkByteRegister(registerA);
|
||||
this.literal = literal;
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Override public int getNarrowLiteral() { return literal; }
|
||||
@Override public long getWideLiteral() { return literal; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderOffsetInstruction;
|
||||
import org.jf.dexlib2.builder.Label;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction31t;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction31t extends BuilderOffsetInstruction implements Instruction31t {
|
||||
public static final Format FORMAT = Format.Format31t;
|
||||
|
||||
protected final int registerA;
|
||||
|
||||
public BuilderInstruction31t(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
@Nonnull Label target) {
|
||||
super(opcode, target);
|
||||
this.registerA = Preconditions.checkByteRegister(registerA);
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
||||
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction32x;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction32x extends BuilderInstruction implements Instruction32x {
|
||||
public static final Format FORMAT = Format.Format32x;
|
||||
|
||||
protected final int registerA;
|
||||
protected final int registerB;
|
||||
|
||||
public BuilderInstruction32x(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
int registerB) {
|
||||
super(opcode);
|
||||
this.registerA = Preconditions.checkShortRegister(registerA);
|
||||
this.registerB = Preconditions.checkShortRegister(registerB);
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Override public int getRegisterB() { return registerB; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction35c;
|
||||
import org.jf.dexlib2.iface.reference.Reference;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction35c extends BuilderInstruction implements Instruction35c {
|
||||
public static final Format FORMAT = Format.Format35c;
|
||||
|
||||
protected final int registerCount;
|
||||
protected final int registerC;
|
||||
protected final int registerD;
|
||||
protected final int registerE;
|
||||
protected final int registerF;
|
||||
protected final int registerG;
|
||||
@Nonnull protected final Reference reference;
|
||||
|
||||
public BuilderInstruction35c(@Nonnull Opcode opcode,
|
||||
int registerCount,
|
||||
int registerC,
|
||||
int registerD,
|
||||
int registerE,
|
||||
int registerF,
|
||||
int registerG,
|
||||
@Nonnull Reference reference) {
|
||||
super(opcode);
|
||||
this.registerCount = Preconditions.check35cRegisterCount(registerCount);
|
||||
this.registerC = (registerCount>0) ? Preconditions.checkNibbleRegister(registerC) : 0;
|
||||
this.registerD = (registerCount>1) ? Preconditions.checkNibbleRegister(registerD) : 0;
|
||||
this.registerE = (registerCount>2) ? Preconditions.checkNibbleRegister(registerE) : 0;
|
||||
this.registerF = (registerCount>3) ? Preconditions.checkNibbleRegister(registerF) : 0;
|
||||
this.registerG = (registerCount>4) ? Preconditions.checkNibbleRegister(registerG) : 0;
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
@Override public int getRegisterCount() { return registerCount; }
|
||||
@Override public int getRegisterC() { return registerC; }
|
||||
@Override public int getRegisterD() { return registerD; }
|
||||
@Override public int getRegisterE() { return registerE; }
|
||||
@Override public int getRegisterF() { return registerF; }
|
||||
@Override public int getRegisterG() { return registerG; }
|
||||
@Nonnull @Override public Reference getReference() { return reference; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction3rc;
|
||||
import org.jf.dexlib2.iface.reference.Reference;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction3rc extends BuilderInstruction implements Instruction3rc {
|
||||
public static final Format FORMAT = Format.Format3rc;
|
||||
|
||||
protected final int startRegister;
|
||||
protected final int registerCount;
|
||||
|
||||
@Nonnull protected final Reference reference;
|
||||
|
||||
public BuilderInstruction3rc(@Nonnull Opcode opcode,
|
||||
int startRegister,
|
||||
int registerCount,
|
||||
@Nonnull Reference reference) {
|
||||
super(opcode);
|
||||
this.startRegister = Preconditions.checkShortRegister(startRegister);
|
||||
this.registerCount = Preconditions.checkRegisterRangeCount(registerCount);
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
@Override public int getStartRegister() { return startRegister; }
|
||||
@Override public int getRegisterCount() { return registerCount; }
|
||||
@Nonnull @Override public Reference getReference() { return reference; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
||||
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction51l;
|
||||
import org.jf.dexlib2.util.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderInstruction51l extends BuilderInstruction implements Instruction51l {
|
||||
public static final Format FORMAT = Format.Format51l;
|
||||
|
||||
protected final int registerA;
|
||||
protected final long literal;
|
||||
|
||||
public BuilderInstruction51l(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
long literal) {
|
||||
super(opcode);
|
||||
this.registerA = Preconditions.checkByteRegister(registerA);
|
||||
this.literal = literal;
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Override public long getWideLiteral() { return literal; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderSwitchPayload;
|
||||
import org.jf.dexlib2.builder.Label;
|
||||
import org.jf.dexlib2.builder.MethodLocation;
|
||||
import org.jf.dexlib2.iface.instruction.SwitchElement;
|
||||
import org.jf.dexlib2.iface.instruction.formats.PackedSwitchPayload;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class BuilderPackedSwitchPayload extends BuilderSwitchPayload implements PackedSwitchPayload {
|
||||
public static final Opcode OPCODE = Opcode.PACKED_SWITCH_PAYLOAD;
|
||||
|
||||
@Nonnull protected final List<? extends BuilderSwitchElement> switchElements;
|
||||
|
||||
public BuilderPackedSwitchPayload(final int startKey,
|
||||
@Nullable List<? extends Label> switchElements) {
|
||||
super(OPCODE);
|
||||
if (switchElements == null) {
|
||||
this.switchElements = ImmutableList.of();
|
||||
} else {
|
||||
this.switchElements = Lists.transform(switchElements, new Function<Label, BuilderSwitchElement>() {
|
||||
int key = startKey;
|
||||
@Nullable @Override public BuilderSwitchElement apply(@Nullable Label target) {
|
||||
assert target != null;
|
||||
return new BuilderSwitchElement(BuilderPackedSwitchPayload.this, key++, target);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull @Override public List<? extends SwitchElement> getSwitchElements() { return switchElements; }
|
||||
|
||||
@Override public int getCodeUnits() { return 4 + switchElements.size() * 2; }
|
||||
@Override public Format getFormat() { return OPCODE.format; }
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.BuilderSwitchPayload;
|
||||
import org.jf.dexlib2.builder.SwitchLabelElement;
|
||||
import org.jf.dexlib2.iface.instruction.SwitchElement;
|
||||
import org.jf.dexlib2.iface.instruction.formats.SparseSwitchPayload;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class BuilderSparseSwitchPayload extends BuilderSwitchPayload implements SparseSwitchPayload {
|
||||
public static final Opcode OPCODE = Opcode.SPARSE_SWITCH_PAYLOAD;
|
||||
|
||||
@Nonnull protected final List<? extends BuilderSwitchElement> switchElements;
|
||||
|
||||
public BuilderSparseSwitchPayload(@Nullable List<? extends SwitchLabelElement> switchElements) {
|
||||
super(OPCODE);
|
||||
if (switchElements == null) {
|
||||
this.switchElements = ImmutableList.of();
|
||||
} else {
|
||||
this.switchElements = Lists.transform(switchElements, new Function<SwitchLabelElement, BuilderSwitchElement>() {
|
||||
@Nullable @Override public BuilderSwitchElement apply(@Nullable SwitchLabelElement element) {
|
||||
assert element != null;
|
||||
return new BuilderSwitchElement(BuilderSparseSwitchPayload.this, element.key, element.target);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull @Override public List<? extends SwitchElement> getSwitchElements() { return switchElements; }
|
||||
|
||||
@Override public int getCodeUnits() { return 2 + switchElements.size() * 4; }
|
||||
@Override public Format getFormat() { return OPCODE.format; }
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package org.jf.dexlib2.builder.instruction;
|
||||
|
||||
import org.jf.dexlib2.builder.BuilderSwitchPayload;
|
||||
import org.jf.dexlib2.builder.Label;
|
||||
import org.jf.dexlib2.iface.instruction.SwitchElement;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BuilderSwitchElement implements SwitchElement {
|
||||
@Nonnull BuilderSwitchPayload parent;
|
||||
private final int key;
|
||||
@Nonnull private final Label target;
|
||||
|
||||
public BuilderSwitchElement(@Nonnull BuilderSwitchPayload parent,
|
||||
int key,
|
||||
@Nonnull Label target) {
|
||||
this.parent = parent;
|
||||
this.key = key;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@Override public int getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override public int getOffset() {
|
||||
return target.getCodeAddress() - parent.getReferrer().getCodeAddress();
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package org.jf.dexlib2.writer.io;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public abstract class DeferredOutputStream extends OutputStream {
|
||||
public abstract void writeTo(OutputStream output) throws IOException;
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package org.jf.dexlib2.writer.io;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface DeferredOutputStreamFactory {
|
||||
DeferredOutputStream makeDeferredOutputStream() throws IOException;
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package org.jf.dexlib2.writer.io;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public interface DexDataStore {
|
||||
@Nonnull OutputStream outputAt(int offset);
|
||||
@Nonnull InputStream readAt(int offset);
|
||||
void close() throws IOException;
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package org.jf.dexlib2.writer.io;
|
||||
|
||||
import org.jf.util.RandomAccessFileInputStream;
|
||||
import org.jf.util.RandomAccessFileOutputStream;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.*;
|
||||
|
||||
public class FileDataStore implements DexDataStore {
|
||||
private final RandomAccessFile raf;
|
||||
|
||||
public FileDataStore(@Nonnull File file) throws FileNotFoundException, IOException {
|
||||
this.raf = new RandomAccessFile(file, "rw");
|
||||
this.raf.setLength(0);
|
||||
}
|
||||
|
||||
@Nonnull @Override public OutputStream outputAt(int offset) {
|
||||
return new RandomAccessFileOutputStream(raf, offset);
|
||||
}
|
||||
|
||||
@Nonnull @Override public InputStream readAt(int offset) {
|
||||
return new RandomAccessFileInputStream(raf, offset);
|
||||
}
|
||||
|
||||
@Override public void close() throws IOException {
|
||||
raf.close();
|
||||
}
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package org.jf.dexlib2.writer.io;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* A deferred output stream that uses a file as its backing store, with a in-memory intermediate buffer.
|
||||
*/
|
||||
public class FileDeferredOutputStream extends DeferredOutputStream {
|
||||
private static final int DEFAULT_BUFFER_SIZE = 4 * 1024;
|
||||
|
||||
@Nonnull private final File backingFile;
|
||||
@Nonnull private final NakedBufferedOutputStream output;
|
||||
private int writtenBytes;
|
||||
|
||||
public FileDeferredOutputStream(@Nonnull File backingFile) throws FileNotFoundException {
|
||||
this(backingFile, DEFAULT_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
public FileDeferredOutputStream(@Nonnull File backingFile, int bufferSize) throws FileNotFoundException {
|
||||
this.backingFile = backingFile;
|
||||
output = new NakedBufferedOutputStream(new FileOutputStream(backingFile), bufferSize);
|
||||
}
|
||||
|
||||
@Override public void writeTo(@Nonnull OutputStream dest) throws IOException {
|
||||
byte[] outBuf = output.getBuffer();
|
||||
int count = output.getCount();
|
||||
output.resetBuffer();
|
||||
output.close();
|
||||
|
||||
// did we actually write something out to disk?
|
||||
if (count != writtenBytes) {
|
||||
InputStream fis = new FileInputStream(backingFile);
|
||||
ByteStreams.copy(fis, dest);
|
||||
backingFile.delete();
|
||||
}
|
||||
|
||||
dest.write(outBuf, 0, count);
|
||||
}
|
||||
|
||||
@Override public void write(int i) throws IOException {
|
||||
output.write(i);
|
||||
writtenBytes++;
|
||||
}
|
||||
|
||||
@Override public void write(byte[] bytes) throws IOException {
|
||||
output.write(bytes);
|
||||
writtenBytes += bytes.length;
|
||||
}
|
||||
|
||||
@Override public void write(byte[] bytes, int off, int len) throws IOException {
|
||||
output.write(bytes, off, len);
|
||||
writtenBytes += len;
|
||||
}
|
||||
|
||||
@Override public void flush() throws IOException {
|
||||
output.flush();
|
||||
}
|
||||
|
||||
@Override public void close() throws IOException {
|
||||
output.close();
|
||||
}
|
||||
|
||||
private static class NakedBufferedOutputStream extends BufferedOutputStream {
|
||||
public NakedBufferedOutputStream(OutputStream outputStream) {
|
||||
super(outputStream);
|
||||
}
|
||||
|
||||
public NakedBufferedOutputStream(OutputStream outputStream, int i) {
|
||||
super(outputStream, i);
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void resetBuffer() {
|
||||
count = 0;
|
||||
}
|
||||
|
||||
public byte[] getBuffer() {
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static DeferredOutputStreamFactory getFactory(@Nullable File containingDirectory) {
|
||||
return getFactory(containingDirectory, DEFAULT_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static DeferredOutputStreamFactory getFactory(@Nullable final File containingDirectory,
|
||||
final int bufferSize) {
|
||||
return new DeferredOutputStreamFactory() {
|
||||
@Override public DeferredOutputStream makeDeferredOutputStream() throws IOException {
|
||||
File tempFile = File.createTempFile("dexlibtmp", null, containingDirectory);
|
||||
return new FileDeferredOutputStream(tempFile, bufferSize);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
package org.jf.dexlib2.writer.io;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class MemoryDataStore implements DexDataStore {
|
||||
private byte[] buf;
|
||||
|
||||
public MemoryDataStore() {
|
||||
this(1024 * 1024);
|
||||
}
|
||||
|
||||
public MemoryDataStore(int initialCapacity) {
|
||||
buf = new byte[initialCapacity];
|
||||
}
|
||||
|
||||
public byte[] getData() {
|
||||
return buf;
|
||||
}
|
||||
|
||||
@Nonnull @Override public OutputStream outputAt(final int offset) {
|
||||
return new OutputStream() {
|
||||
private int position = offset;
|
||||
@Override public void write(int b) throws IOException {
|
||||
growBufferIfNeeded(position);
|
||||
buf[position++] = (byte)b;
|
||||
}
|
||||
|
||||
@Override public void write(byte[] b) throws IOException {
|
||||
growBufferIfNeeded(position + b.length);
|
||||
System.arraycopy(b, 0, buf, position, b.length);
|
||||
position += b.length;
|
||||
}
|
||||
|
||||
@Override public void write(byte[] b, int off, int len) throws IOException {
|
||||
growBufferIfNeeded(position + len);
|
||||
System.arraycopy(b, off, buf, position, len);
|
||||
position += len;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void growBufferIfNeeded(int index) {
|
||||
if (index < buf.length) {
|
||||
return;
|
||||
}
|
||||
buf = Arrays.copyOf(buf, (int)((index + 1) * 1.2));
|
||||
}
|
||||
|
||||
@Nonnull @Override public InputStream readAt(final int offset) {
|
||||
return new InputStream() {
|
||||
private int position = offset;
|
||||
|
||||
@Override public int read() throws IOException {
|
||||
if (position >= buf.length) {
|
||||
return -1;
|
||||
}
|
||||
return buf[position++];
|
||||
}
|
||||
|
||||
@Override public int read(byte[] b) throws IOException {
|
||||
int readLength = Math.min(b.length, buf.length - position);
|
||||
if (readLength <= 0) {
|
||||
if (position >= buf.length) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
System.arraycopy(buf, position, b, 0, readLength);
|
||||
position += readLength;
|
||||
return readLength;
|
||||
}
|
||||
|
||||
@Override public int read(byte[] b, int off, int len) throws IOException {
|
||||
int readLength = Math.min(len, buf.length - position);
|
||||
if (readLength <= 0) {
|
||||
if (position >= buf.length) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
System.arraycopy(buf, position, b, 0, readLength);
|
||||
position += readLength;
|
||||
return readLength;
|
||||
}
|
||||
|
||||
@Override public long skip(long n) throws IOException {
|
||||
int skipLength = (int)Math.min(n, buf.length - position);
|
||||
position += skipLength;
|
||||
return skipLength;
|
||||
}
|
||||
|
||||
@Override public int available() throws IOException {
|
||||
return buf.length - position;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override public void close() throws IOException {
|
||||
// no-op
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package org.jf.dexlib2.writer.io;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A deferred output stream that is stored in memory
|
||||
*/
|
||||
public class MemoryDeferredOutputStream extends DeferredOutputStream {
|
||||
private static final int DEFAULT_BUFFER_SIZE = 16 * 1024;
|
||||
|
||||
private final List<byte[]> buffers = Lists.newArrayList();
|
||||
private byte[] currentBuffer;
|
||||
private int currentPosition;
|
||||
|
||||
public MemoryDeferredOutputStream() {
|
||||
this(DEFAULT_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
public MemoryDeferredOutputStream(int bufferSize) {
|
||||
currentBuffer = new byte[bufferSize];
|
||||
}
|
||||
|
||||
@Override public void writeTo(OutputStream output) throws IOException {
|
||||
for (byte[] buffer: buffers) {
|
||||
output.write(buffer);
|
||||
}
|
||||
if (currentPosition > 0) {
|
||||
output.write(currentBuffer, 0, currentPosition);
|
||||
}
|
||||
buffers.clear();
|
||||
currentPosition = 0;
|
||||
}
|
||||
|
||||
@Override public void write(int i) throws IOException {
|
||||
if (remaining() == 0) {
|
||||
buffers.add(currentBuffer);
|
||||
currentBuffer = new byte[currentBuffer.length];
|
||||
currentPosition = 0;
|
||||
}
|
||||
currentBuffer[currentPosition++] = (byte)i;
|
||||
}
|
||||
|
||||
@Override public void write(byte[] bytes) throws IOException {
|
||||
write(bytes, 0, bytes.length);
|
||||
}
|
||||
|
||||
@Override public void write(byte[] bytes, int offset, int length) throws IOException {
|
||||
int remaining = remaining();
|
||||
int written = 0;
|
||||
while (length - written > 0) {
|
||||
int toWrite = Math.min(remaining, (length - written));
|
||||
System.arraycopy(bytes, offset + written, currentBuffer, currentPosition, toWrite);
|
||||
written += toWrite;
|
||||
currentPosition += toWrite;
|
||||
|
||||
remaining = remaining();
|
||||
if (remaining == 0) {
|
||||
buffers.add(currentBuffer);
|
||||
currentBuffer = new byte[currentBuffer.length];
|
||||
currentPosition = 0;
|
||||
remaining = currentBuffer.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int remaining() {
|
||||
return currentBuffer.length - currentPosition;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static DeferredOutputStreamFactory getFactory() {
|
||||
return getFactory(DEFAULT_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static DeferredOutputStreamFactory getFactory(final int bufferSize) {
|
||||
return new DeferredOutputStreamFactory() {
|
||||
@Override public DeferredOutputStream makeDeferredOutputStream() {
|
||||
return new MemoryDeferredOutputStream(bufferSize);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
package org.jf.dexlib2.builder;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import junit.framework.Assert;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.instruction.BuilderInstruction10t;
|
||||
import org.jf.dexlib2.builder.instruction.BuilderInstruction10x;
|
||||
import org.jf.dexlib2.builder.instruction.BuilderInstruction20t;
|
||||
import org.jf.dexlib2.iface.MethodImplementation;
|
||||
import org.jf.dexlib2.iface.instruction.Instruction;
|
||||
import org.jf.dexlib2.iface.instruction.OffsetInstruction;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FixGotoTest {
|
||||
@Test
|
||||
public void testFixGotoToGoto16() {
|
||||
MethodImplementationBuilder builder = new MethodImplementationBuilder(1);
|
||||
|
||||
Label gotoTarget = builder.getLabel("gotoTarget");
|
||||
builder.addInstruction(new BuilderInstruction10t(Opcode.GOTO, gotoTarget));
|
||||
|
||||
for (int i=0; i<500; i++) {
|
||||
builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
}
|
||||
|
||||
builder.addLabel("gotoTarget");
|
||||
builder.addInstruction(new BuilderInstruction10x(Opcode.RETURN_VOID));
|
||||
|
||||
MethodImplementation impl = builder.getMethodImplementation();
|
||||
|
||||
List<? extends Instruction> instructions = Lists.newArrayList(impl.getInstructions());
|
||||
Assert.assertEquals(502, instructions.size());
|
||||
|
||||
Assert.assertEquals(Opcode.GOTO_16, instructions.get(0).getOpcode());
|
||||
Assert.assertEquals(502, ((OffsetInstruction)instructions.get(0)).getCodeOffset());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFixGotoToGoto32() {
|
||||
MethodImplementationBuilder builder = new MethodImplementationBuilder(1);
|
||||
|
||||
Label gotoTarget = builder.getLabel("gotoTarget");
|
||||
builder.addInstruction(new BuilderInstruction10t(Opcode.GOTO, gotoTarget));
|
||||
|
||||
for (int i=0; i<70000; i++) {
|
||||
builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
}
|
||||
|
||||
builder.addLabel("gotoTarget");
|
||||
builder.addInstruction(new BuilderInstruction10x(Opcode.RETURN_VOID));
|
||||
|
||||
MethodImplementation impl = builder.getMethodImplementation();
|
||||
|
||||
List<? extends Instruction> instructions = Lists.newArrayList(impl.getInstructions());
|
||||
Assert.assertEquals(70002, instructions.size());
|
||||
|
||||
Assert.assertEquals(Opcode.GOTO_32, instructions.get(0).getOpcode());
|
||||
Assert.assertEquals(70003, ((OffsetInstruction)instructions.get(0)).getCodeOffset());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFixGoto16ToGoto32() {
|
||||
MethodImplementationBuilder builder = new MethodImplementationBuilder(1);
|
||||
|
||||
Label gotoTarget = builder.getLabel("gotoTarget");
|
||||
builder.addInstruction(new BuilderInstruction20t(Opcode.GOTO_16, gotoTarget));
|
||||
|
||||
for (int i=0; i<70000; i++) {
|
||||
builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
}
|
||||
|
||||
builder.addLabel("gotoTarget");
|
||||
builder.addInstruction(new BuilderInstruction10x(Opcode.RETURN_VOID));
|
||||
|
||||
MethodImplementation impl = builder.getMethodImplementation();
|
||||
|
||||
List<? extends Instruction> instructions = Lists.newArrayList(impl.getInstructions());
|
||||
Assert.assertEquals(70002, instructions.size());
|
||||
|
||||
Assert.assertEquals(Opcode.GOTO_32, instructions.get(0).getOpcode());
|
||||
Assert.assertEquals(70003, ((OffsetInstruction)instructions.get(0)).getCodeOffset());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFixGotoCascading() {
|
||||
MethodImplementationBuilder builder = new MethodImplementationBuilder(1);
|
||||
|
||||
Label goto16Target = builder.getLabel("goto16Target");
|
||||
builder.addInstruction(new BuilderInstruction20t(Opcode.GOTO_16, goto16Target));
|
||||
|
||||
for (int i=0; i<1000; i++) {
|
||||
builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
}
|
||||
|
||||
Label gotoTarget = builder.getLabel("gotoTarget");
|
||||
builder.addInstruction(new BuilderInstruction10t(Opcode.GOTO, gotoTarget));
|
||||
|
||||
for (int i=0; i<499; i++) {
|
||||
builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
}
|
||||
|
||||
builder.addLabel("gotoTarget");
|
||||
|
||||
for (int i=0; i<31265; i++) {
|
||||
builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
}
|
||||
|
||||
builder.addLabel("goto16Target");
|
||||
builder.addInstruction(new BuilderInstruction10x(Opcode.RETURN_VOID));
|
||||
|
||||
MethodImplementation impl = builder.getMethodImplementation();
|
||||
|
||||
List<? extends Instruction> instructions = Lists.newArrayList(impl.getInstructions());
|
||||
Assert.assertEquals(32767, instructions.size());
|
||||
|
||||
Assert.assertEquals(Opcode.GOTO_32, instructions.get(0).getOpcode());
|
||||
Assert.assertEquals(32769, ((OffsetInstruction)instructions.get(0)).getCodeOffset());
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import junit.framework.Assert;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.instruction.BuilderInstruction10t;
|
||||
import org.jf.dexlib2.builder.instruction.BuilderInstruction10x;
|
||||
import org.jf.dexlib2.iface.ExceptionHandler;
|
||||
import org.jf.dexlib2.iface.MethodImplementation;
|
||||
import org.jf.dexlib2.iface.TryBlock;
|
||||
import org.jf.dexlib2.iface.debug.DebugItem;
|
||||
import org.jf.dexlib2.iface.debug.LineNumber;
|
||||
import org.jf.dexlib2.iface.instruction.Instruction;
|
||||
import org.jf.dexlib2.iface.instruction.OffsetInstruction;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FixOffsetsTest {
|
||||
@Test
|
||||
public void testFixOffsets() {
|
||||
MethodImplementationBuilder builder = new MethodImplementationBuilder(1);
|
||||
|
||||
Label firstGotoTarget = builder.getLabel("firstGotoTarget");
|
||||
builder.addInstruction(new BuilderInstruction10t(Opcode.GOTO, firstGotoTarget));
|
||||
|
||||
builder.addLineNumber(1);
|
||||
|
||||
for (int i=0; i<250; i++) {
|
||||
builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
}
|
||||
|
||||
builder.addLabel("tryStart");
|
||||
|
||||
builder.addLineNumber(2);
|
||||
|
||||
for (int i=0; i<250; i++) {
|
||||
builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
}
|
||||
|
||||
builder.addLineNumber(3);
|
||||
|
||||
Label secondGotoTarget = builder.getLabel("secondGotoTarget");
|
||||
builder.addInstruction(new BuilderInstruction10t(Opcode.GOTO, secondGotoTarget));
|
||||
|
||||
|
||||
builder.addLineNumber(4);
|
||||
builder.addLabel("handler");
|
||||
|
||||
for (int i=0; i<500; i++) {
|
||||
builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
}
|
||||
|
||||
builder.addLineNumber(5);
|
||||
|
||||
builder.addLabel("tryEnd");
|
||||
|
||||
builder.addLabel("firstGotoTarget");
|
||||
builder.addLabel("secondGotoTarget");
|
||||
builder.addInstruction(new BuilderInstruction10x(Opcode.RETURN_VOID));
|
||||
|
||||
Label tryStart = builder.getLabel("tryStart");
|
||||
Label tryEnd = builder.getLabel("tryEnd");
|
||||
Label handler = builder.getLabel("handler");
|
||||
|
||||
builder.addCatch(tryStart, tryEnd, handler);
|
||||
|
||||
MethodImplementation impl = builder.getMethodImplementation();
|
||||
|
||||
List<? extends Instruction> instructions = Lists.newArrayList(impl.getInstructions());
|
||||
Assert.assertEquals(1003, instructions.size());
|
||||
|
||||
Assert.assertEquals(Opcode.GOTO_16, instructions.get(0).getOpcode());
|
||||
Assert.assertEquals(1004, ((OffsetInstruction)instructions.get(0)).getCodeOffset());
|
||||
|
||||
Assert.assertEquals(Opcode.GOTO_16, instructions.get(501).getOpcode());
|
||||
Assert.assertEquals(502, ((OffsetInstruction)instructions.get(501)).getCodeOffset());
|
||||
|
||||
List<? extends TryBlock<? extends ExceptionHandler>> exceptionHandlers = impl.getTryBlocks();
|
||||
|
||||
Assert.assertEquals(1, exceptionHandlers.size());
|
||||
Assert.assertEquals(252, exceptionHandlers.get(0).getStartCodeAddress());
|
||||
Assert.assertEquals(752, exceptionHandlers.get(0).getCodeUnitCount());
|
||||
|
||||
Assert.assertEquals(1, exceptionHandlers.get(0).getExceptionHandlers().size());
|
||||
|
||||
ExceptionHandler exceptionHandler = exceptionHandlers.get(0).getExceptionHandlers().get(0);
|
||||
Assert.assertEquals(504, exceptionHandler.getHandlerCodeAddress());
|
||||
|
||||
List<DebugItem> debugItems = Lists.newArrayList(impl.getDebugItems());
|
||||
|
||||
Assert.assertEquals(5, debugItems.size());
|
||||
|
||||
Assert.assertEquals(1, ((LineNumber)debugItems.get(0)).getLineNumber());
|
||||
Assert.assertEquals(2, debugItems.get(0).getCodeAddress());
|
||||
|
||||
Assert.assertEquals(2, ((LineNumber)debugItems.get(1)).getLineNumber());
|
||||
Assert.assertEquals(252, debugItems.get(1).getCodeAddress());
|
||||
|
||||
Assert.assertEquals(3, ((LineNumber)debugItems.get(2)).getLineNumber());
|
||||
Assert.assertEquals(502, debugItems.get(2).getCodeAddress());
|
||||
|
||||
Assert.assertEquals(4, ((LineNumber)debugItems.get(3)).getLineNumber());
|
||||
Assert.assertEquals(504, debugItems.get(3).getCodeAddress());
|
||||
|
||||
Assert.assertEquals(5, ((LineNumber)debugItems.get(4)).getLineNumber());
|
||||
Assert.assertEquals(1004, debugItems.get(4).getCodeAddress());
|
||||
}
|
||||
}
|
@ -0,0 +1,251 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.builder;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.builder.instruction.*;
|
||||
import org.jf.dexlib2.iface.instruction.Instruction;
|
||||
import org.jf.dexlib2.iface.instruction.OffsetInstruction;
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction31t;
|
||||
import org.jf.dexlib2.iface.instruction.formats.PackedSwitchPayload;
|
||||
import org.jf.dexlib2.iface.instruction.formats.SparseSwitchPayload;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PayloadAlignmentTest {
|
||||
|
||||
@Test
|
||||
public void testPayloadAlignmentRemoveNop() {
|
||||
MethodImplementationBuilder implBuilder = new MethodImplementationBuilder(10);
|
||||
|
||||
implBuilder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
implBuilder.addInstruction(new BuilderArrayPayload(4, null));
|
||||
|
||||
List<? extends Instruction> instructions =
|
||||
Lists.newArrayList(implBuilder.getMethodImplementation().getInstructions());
|
||||
|
||||
Assert.assertEquals(instructions.size(), 1);
|
||||
|
||||
Instruction instruction = instructions.get(0);
|
||||
|
||||
Assert.assertEquals(instruction.getOpcode(), Opcode.ARRAY_PAYLOAD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPayloadAlignmentAddNop() {
|
||||
MethodImplementationBuilder implBuilder = new MethodImplementationBuilder(10);
|
||||
|
||||
implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0));
|
||||
implBuilder.addInstruction(new BuilderArrayPayload(4, null));
|
||||
|
||||
List<? extends Instruction> instructions =
|
||||
Lists.newArrayList(implBuilder.getMethodImplementation().getInstructions());
|
||||
|
||||
Assert.assertEquals(instructions.size(), 3);
|
||||
|
||||
Instruction instruction = instructions.get(0);
|
||||
Assert.assertEquals(instruction.getOpcode(), Opcode.MOVE);
|
||||
|
||||
instruction = instructions.get(1);
|
||||
Assert.assertEquals(instruction.getOpcode(), Opcode.NOP);
|
||||
|
||||
instruction = instructions.get(2);
|
||||
Assert.assertEquals(instruction.getOpcode(), Opcode.ARRAY_PAYLOAD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPayloadAlignmentRemoveNopWithReferent() {
|
||||
MethodImplementationBuilder implBuilder = new MethodImplementationBuilder(10);
|
||||
|
||||
Label label = implBuilder.getLabel("array_payload");
|
||||
implBuilder.addInstruction(new BuilderInstruction31t(Opcode.FILL_ARRAY_DATA, 0, label));
|
||||
implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0));
|
||||
implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0));
|
||||
implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0));
|
||||
implBuilder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
implBuilder.addLabel("array_payload");
|
||||
implBuilder.addInstruction(new BuilderArrayPayload(4, null));
|
||||
|
||||
List<Instruction> instructions = Lists.newArrayList(implBuilder.getMethodImplementation().getInstructions());
|
||||
|
||||
checkInstructions(instructions,
|
||||
new Opcode[]{Opcode.FILL_ARRAY_DATA,
|
||||
Opcode.MOVE,
|
||||
Opcode.MOVE,
|
||||
Opcode.MOVE,
|
||||
Opcode.ARRAY_PAYLOAD});
|
||||
|
||||
Instruction31t referent = (Instruction31t)instructions.get(0);
|
||||
Assert.assertEquals(6, referent.getCodeOffset());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPayloadAlignmentAddNopWithReferent() {
|
||||
MethodImplementationBuilder implBuilder = new MethodImplementationBuilder(10);
|
||||
|
||||
Label label = implBuilder.getLabel("array_payload");
|
||||
implBuilder.addInstruction(new BuilderInstruction31t(Opcode.FILL_ARRAY_DATA, 0, label));
|
||||
implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0));
|
||||
implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0));
|
||||
implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0));
|
||||
implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0));
|
||||
implBuilder.addLabel("array_payload");
|
||||
implBuilder.addInstruction(new BuilderArrayPayload(4, null));
|
||||
|
||||
List<Instruction> instructions = Lists.newArrayList(implBuilder.getMethodImplementation().getInstructions());
|
||||
|
||||
checkInstructions(instructions,
|
||||
new Opcode[]{Opcode.FILL_ARRAY_DATA,
|
||||
Opcode.MOVE,
|
||||
Opcode.MOVE,
|
||||
Opcode.MOVE,
|
||||
Opcode.MOVE,
|
||||
Opcode.NOP,
|
||||
Opcode.ARRAY_PAYLOAD});
|
||||
|
||||
Instruction31t referent = (Instruction31t)instructions.get(0);
|
||||
Assert.assertEquals(8, referent.getCodeOffset());
|
||||
}
|
||||
|
||||
private static void checkInstructions(List<Instruction> instructions, Opcode[] expectedOpcodes) {
|
||||
Assert.assertEquals(expectedOpcodes.length, instructions.size());
|
||||
|
||||
for (int i=0; i<expectedOpcodes.length; i++) {
|
||||
Assert.assertEquals(instructions.get(i).getOpcode(), expectedOpcodes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackedSwitchAlignment() {
|
||||
MethodImplementationBuilder implBuilder = new MethodImplementationBuilder(10);
|
||||
|
||||
implBuilder.addLabel("switch_target_1");
|
||||
implBuilder.addInstruction(new BuilderInstruction10t(Opcode.GOTO, implBuilder.getLabel("goto_target")));
|
||||
|
||||
implBuilder.addLabel("switch_payload");
|
||||
implBuilder.addInstruction(new BuilderPackedSwitchPayload(0, Lists.newArrayList(
|
||||
implBuilder.getLabel("switch_target_1"),
|
||||
implBuilder.getLabel("switch_target_2"),
|
||||
implBuilder.getLabel("switch_target_3"))));
|
||||
|
||||
implBuilder.addLabel("goto_target");
|
||||
implBuilder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
implBuilder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
|
||||
implBuilder.addLabel("switch_target_2");
|
||||
implBuilder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
|
||||
implBuilder.addLabel("switch_target_3");
|
||||
implBuilder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
|
||||
implBuilder.addInstruction(new BuilderInstruction31t(Opcode.PACKED_SWITCH, 0,
|
||||
implBuilder.getLabel("switch_payload")));
|
||||
|
||||
List<Instruction> instructions = Lists.newArrayList(implBuilder.getMethodImplementation().getInstructions());
|
||||
|
||||
checkInstructions(instructions,
|
||||
new Opcode[]{Opcode.GOTO,
|
||||
Opcode.NOP,
|
||||
Opcode.PACKED_SWITCH_PAYLOAD,
|
||||
Opcode.NOP,
|
||||
Opcode.NOP,
|
||||
Opcode.NOP,
|
||||
Opcode.NOP,
|
||||
Opcode.PACKED_SWITCH});
|
||||
|
||||
OffsetInstruction gotoInstruction = (OffsetInstruction)instructions.get(0);
|
||||
Assert.assertEquals(12, gotoInstruction.getCodeOffset());
|
||||
|
||||
PackedSwitchPayload payload = (PackedSwitchPayload)instructions.get(2);
|
||||
Assert.assertEquals(3, payload.getSwitchElements().size());
|
||||
Assert.assertEquals(-16, payload.getSwitchElements().get(0).getOffset());
|
||||
Assert.assertEquals(-2, payload.getSwitchElements().get(1).getOffset());
|
||||
Assert.assertEquals(-1, payload.getSwitchElements().get(2).getOffset());
|
||||
|
||||
OffsetInstruction referent = (OffsetInstruction)instructions.get(7);
|
||||
Assert.assertEquals(-14, referent.getCodeOffset());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSparseSwitchAlignment() {
|
||||
MethodImplementationBuilder implBuilder = new MethodImplementationBuilder(10);
|
||||
|
||||
implBuilder.addLabel("switch_target_1");
|
||||
implBuilder.addInstruction(new BuilderInstruction10t(Opcode.GOTO, implBuilder.getLabel("goto_target")));
|
||||
|
||||
implBuilder.addLabel("switch_payload");
|
||||
implBuilder.addInstruction(new BuilderSparseSwitchPayload(Lists.newArrayList(
|
||||
new SwitchLabelElement(0, implBuilder.getLabel("switch_target_1")),
|
||||
new SwitchLabelElement(5, implBuilder.getLabel("switch_target_2")),
|
||||
new SwitchLabelElement(10, implBuilder.getLabel("switch_target_3")))));
|
||||
|
||||
implBuilder.addLabel("goto_target");
|
||||
implBuilder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
implBuilder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
|
||||
implBuilder.addLabel("switch_target_2");
|
||||
implBuilder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
|
||||
implBuilder.addLabel("switch_target_3");
|
||||
implBuilder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
|
||||
|
||||
implBuilder.addInstruction(new BuilderInstruction31t(Opcode.SPARSE_SWITCH, 0,
|
||||
implBuilder.getLabel("switch_payload")));
|
||||
|
||||
List<Instruction> instructions = Lists.newArrayList(implBuilder.getMethodImplementation().getInstructions());
|
||||
|
||||
checkInstructions(instructions,
|
||||
new Opcode[]{Opcode.GOTO,
|
||||
Opcode.NOP,
|
||||
Opcode.SPARSE_SWITCH_PAYLOAD,
|
||||
Opcode.NOP,
|
||||
Opcode.NOP,
|
||||
Opcode.NOP,
|
||||
Opcode.NOP,
|
||||
Opcode.SPARSE_SWITCH});
|
||||
|
||||
OffsetInstruction gotoInstruction = (OffsetInstruction)instructions.get(0);
|
||||
Assert.assertEquals(16, gotoInstruction.getCodeOffset());
|
||||
|
||||
SparseSwitchPayload payload = (SparseSwitchPayload)instructions.get(2);
|
||||
Assert.assertEquals(3, payload.getSwitchElements().size());
|
||||
Assert.assertEquals(-20, payload.getSwitchElements().get(0).getOffset());
|
||||
Assert.assertEquals(-2, payload.getSwitchElements().get(1).getOffset());
|
||||
Assert.assertEquals(-1, payload.getSwitchElements().get(2).getOffset());
|
||||
|
||||
OffsetInstruction referent = (OffsetInstruction)instructions.get(7);
|
||||
Assert.assertEquals(-18, referent.getCodeOffset());
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.util;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
public class RandomAccessFileInputStream extends InputStream {
|
||||
private int filePosition;
|
||||
@Nonnull private final RandomAccessFile raf;
|
||||
|
||||
public RandomAccessFileInputStream(@Nonnull RandomAccessFile raf, int filePosition) {
|
||||
this.filePosition = filePosition;
|
||||
this.raf = raf;
|
||||
}
|
||||
|
||||
@Override public int read() throws IOException {
|
||||
raf.seek(filePosition);
|
||||
filePosition++;
|
||||
return raf.read();
|
||||
}
|
||||
|
||||
@Override public int read(byte[] bytes) throws IOException {
|
||||
raf.seek(filePosition);
|
||||
int bytesRead = raf.read(bytes);
|
||||
filePosition += bytesRead;
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
@Override public int read(byte[] bytes, int offset, int length) throws IOException {
|
||||
raf.seek(filePosition);
|
||||
int bytesRead = raf.read(bytes, offset, length);
|
||||
filePosition += bytesRead;
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
@Override public long skip(long l) throws IOException {
|
||||
int skipBytes = Math.min((int)l, available());
|
||||
filePosition += skipBytes;
|
||||
return skipBytes;
|
||||
}
|
||||
|
||||
@Override public int available() throws IOException {
|
||||
return (int)raf.length() - filePosition;
|
||||
}
|
||||
|
||||
@Override public boolean markSupported() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2013, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.util;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ClassFileNameHandlerTest {
|
||||
@Test
|
||||
public void testShortedPathComponent() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i=0; i<300; i++) {
|
||||
sb.append((char)i);
|
||||
}
|
||||
|
||||
String result = ClassFileNameHandler.shortenPathComponent(sb.toString(), 255);
|
||||
|
||||
Assert.assertEquals(255, result.length());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user