Example usage for org.objectweb.asm.commons InstructionAdapter astore

List of usage examples for org.objectweb.asm.commons InstructionAdapter astore

Introduction

In this page you can find the example usage for org.objectweb.asm.commons InstructionAdapter astore.

Prototype

public void astore(final Type type) 

Source Link

Usage

From source file:com.github.jasmo.obfuscate.ScrambleStrings.java

License:Open Source License

private void createStaticConstructor(ClassNode owner) throws UnsupportedEncodingException {
    MethodNode original = BytecodeHelper.getMethod(owner, "<clinit>", "()V");
    MethodVisitor mv = owner.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null);
    // generate instructions
    InstructionAdapter builder = new InstructionAdapter(mv);
    builder.iconst(stringList.size());/*  w  ww.j a v a 2s .co m*/
    builder.newarray(Type.getType(String.class));
    for (int i = 0; i < stringList.size(); i++) {
        builder.dup();
        builder.iconst(i);
        builder.aconst(Base64.getEncoder().encodeToString(stringList.get(i).getBytes("UTF-8")));
        builder.astore(InstructionAdapter.OBJECT_TYPE);
    }
    builder.putstatic(unscrambleClass.name, FIELD_NAME, "[Ljava/lang/String;");
    // merge with original if it exists
    if (original != null) {
        // original should already end with RETURN
        owner.methods.remove(original);
        original.instructions.accept(builder);
    } else {
        builder.areturn(Type.VOID_TYPE);
    }
}

From source file:com.google.devtools.build.android.resources.IntArrayFieldInitializer.java

License:Open Source License

@Override
public int writeCLInit(InstructionAdapter insts, String className) {
    insts.iconst(values.size());/*from   www . jav  a  2 s. co  m*/
    insts.newarray(Type.INT_TYPE);
    int curIndex = 0;
    for (Integer value : values) {
        insts.dup();
        insts.iconst(curIndex);
        insts.iconst(value);
        insts.astore(Type.INT_TYPE);
        ++curIndex;
    }
    insts.putstatic(className, fieldName, DESC);
    // Needs up to 4 stack slots for: the array ref for the putstatic, the dup of the array ref
    // for the store, the index, and the value to store.
    return 4;
}