# HG changeset patch # User Michael Starzinger # Date 1301065710 -3600 # Node ID 68531618d3348d1124898d8ef6a07bfd65f99591 # Parent 6ea46c9287918b4fbf927d72a71024ba45cb6244 Adapted parser interface for FILL_ARRAY_DATA. * Interface changes have been proposed by Remi Forax. * dex/DexMethodVisitor.java (visitInstrFillArrayData): Specified further. * dex/Code.java: Adapted to new interface. * rewriter/DexRewriter.java: Likewise. * rewriter/FillArrayDataTest.java: New test case for FILL_ARRAY_DATA. diff -r 6ea46c928791 -r 68531618d334 src/main/java/org/icedrobot/daneel/dex/Code.java --- a/src/main/java/org/icedrobot/daneel/dex/Code.java Fri Mar 25 16:04:26 2011 +0100 +++ b/src/main/java/org/icedrobot/daneel/dex/Code.java Fri Mar 25 16:08:30 2011 +0100 @@ -428,9 +428,10 @@ label = getLabel(pos + i); if (!(label instanceof FillArrayDataLabel)) throw new DexParseException("Mistyped branch target."); - // XXX Use fill-array-data structure once the interface - // specifies how to do that. - v.visitInstrFillArrayData(op, b1, null); + FillArrayDataLabel fadl = (FillArrayDataLabel) label; + ByteBuffer data = fadl.data.duplicate().order(insns.order()); + v.visitInstrFillArrayData(op, b1, fadl.elementWidth, fadl.size, + data); break; case GOTO: @@ -1020,17 +1021,16 @@ * In-code data structure for fill-array-data instructions. */ private static class FillArrayDataLabel extends Label { - private final int elementWidth; - private final int size; - private final byte[] data; + final int elementWidth; + final int size; + final ByteBuffer data; public FillArrayDataLabel(ByteBuffer buffer) { if (buffer.getShort() != 0x0300) throw new DexParseException("Unidentified in-code data."); elementWidth = buffer.getShort(); size = buffer.getInt(); - data = new byte[size]; - buffer.get(data, 0, size); + data = (ByteBuffer) buffer.slice().limit(size * elementWidth); } public int length() { diff -r 6ea46c928791 -r 68531618d334 src/main/java/org/icedrobot/daneel/dex/DexMethodVisitor.java --- a/src/main/java/org/icedrobot/daneel/dex/DexMethodVisitor.java Fri Mar 25 16:04:26 2011 +0100 +++ b/src/main/java/org/icedrobot/daneel/dex/DexMethodVisitor.java Fri Mar 25 16:08:30 2011 +0100 @@ -36,6 +36,8 @@ */ package org.icedrobot.daneel.dex; +import java.nio.ByteBuffer; + /** * A visitor for methods contained in DEX files. */ @@ -362,9 +364,12 @@ * * @param opcode The opcode FILL_ARRAY_DATA. * @param vsrc The array register. - * @param arrayData XXX Specify me! + * @param elementWidth Width of one element in bytes. + * @param elementNumber Number of elements in the table. + * @param data The data as a buffer of bytes. */ - void visitInstrFillArrayData(Opcode opcode, int vsrc, Object arrayData); + void visitInstrFillArrayData(Opcode opcode, int vsrc, int elementWidth, + int elementNumber, ByteBuffer data); /** * Visits a try-catch block for the method's code. diff -r 6ea46c928791 -r 68531618d334 src/main/java/org/icedrobot/daneel/rewriter/DexRewriter.java --- a/src/main/java/org/icedrobot/daneel/rewriter/DexRewriter.java Fri Mar 25 16:04:26 2011 +0100 +++ b/src/main/java/org/icedrobot/daneel/rewriter/DexRewriter.java Fri Mar 25 16:08:30 2011 +0100 @@ -42,10 +42,10 @@ import static org.icedrobot.daneel.rewriter.Register.*; import static org.icedrobot.daneel.rewriter.Registers.*; +import java.nio.ByteBuffer; import java.util.Collections; import java.util.HashMap; import java.util.IdentityHashMap; -import java.util.Map; import java.util.Set; import org.icedrobot.daneel.dex.DexAnnotationVisitor; @@ -907,7 +907,7 @@ @Override public void visitInstrFillArrayData(Opcode opcode, int vsrc, - Object arrayData) { + int elementWidth, int elementNumber, ByteBuffer data) { fixStackAfterAMethodCallOrAnExceptionHandler(); vsrc = registerToSlot(vsrc); throw new UnsupportedOperationException("NYI " + opcode); diff -r 6ea46c928791 -r 68531618d334 src/test/java/org/icedrobot/daneel/rewriter/FillArrayDataTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/icedrobot/daneel/rewriter/FillArrayDataTest.java Fri Mar 25 16:08:30 2011 +0100 @@ -0,0 +1,62 @@ +/* + * Daneel - Dalvik to Java bytecode compiler + * Copyright (C) 2011 IcedRobot team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file is subject to the "Classpath" exception: + * + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce an + * executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. An + * independent module is a module which is not derived from or based on + * this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. + */ + +package org.icedrobot.daneel.rewriter; + +import static org.junit.Assert.assertArrayEquals; + +import org.icedrobot.daneel.DexifyingRunner; +import org.junit.Test; +import org.junit.runner.RunWith; + +@org.junit.Ignore("FILL_ARRAY_DATA not yet implemented") +@RunWith(DexifyingRunner.class) +public class FillArrayDataTest { + + @Test + public void testNewFilled() { + int[] array = DEXCode.newFilled(); + assertArrayEquals(new int[] { 7, 23, 42, 127, 128, 129 }, array); + } + + // Keep this class named "DEXCode" to push it through Daneel. + private static class DEXCode { + public static int[] newFilled() { + return new int[] { 7, 23, 42, 127, 128, 129 }; + } + }; +}