ghidra-master/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/oat/quickmethod/OatQuickMethodHeaderFactory.java
/* ###
 * IP: GHIDRA
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ghidra.file.formats.android.oat.quickmethod;

import java.io.IOException;

import ghidra.app.util.bin.BinaryReader;
import ghidra.file.formats.android.oat.OatConstants;

public final class OatQuickMethodHeaderFactory {

	public final static int getOatQuickMethodHeaderSize(String oatVersion) throws IOException {
		switch (oatVersion) {
			case OatConstants.OAT_VERSION_039:
				return 12 + QuickMethodFrameInfo.SIZE;
			case OatConstants.OAT_VERSION_045:
			case OatConstants.OAT_VERSION_051:
			case OatConstants.OAT_VERSION_064:
				return 16 + QuickMethodFrameInfo.SIZE;
			case OatConstants.OAT_VERSION_079:
			case OatConstants.OAT_VERSION_088:
				return 8 + QuickMethodFrameInfo.SIZE;
			case OatConstants.OAT_VERSION_124:
			case OatConstants.OAT_VERSION_131:
			case OatConstants.OAT_VERSION_126:
			case OatConstants.OAT_VERSION_138:
				return 12 + QuickMethodFrameInfo.SIZE;
			case OatConstants.OAT_VERSION_170:
			case OatConstants.OAT_VERSION_183:
				return 8;
			case OatConstants.OAT_VERSION_195:
			case OatConstants.OAT_VERSION_199:
			case OatConstants.OAT_VERSION_220:
			case OatConstants.OAT_VERSION_223:
			case OatConstants.OAT_VERSION_225:
				return 4;
		}
		throw new IOException("OatQuickMethodHeader unsupported OAT version: " + oatVersion);
	}

	public final static OatQuickMethodHeader getOatQuickMethodHeader(BinaryReader reader,
			String oatVersion) throws IOException {
		switch (oatVersion ) {
			case OatConstants.OAT_VERSION_039:
				return new OatQuickMethodHeader_Lollipop(reader);
			case OatConstants.OAT_VERSION_045:
			case OatConstants.OAT_VERSION_051:
			case OatConstants.OAT_VERSION_064:
				return new OatQuickMethodHeader_LollipopMR1(reader);
			case OatConstants.OAT_VERSION_079:
			case OatConstants.OAT_VERSION_088:
				return new OatQuickMethodHeader_Nougat(reader);
			case OatConstants.OAT_VERSION_124:
			case OatConstants.OAT_VERSION_131:
			case OatConstants.OAT_VERSION_126:
			case OatConstants.OAT_VERSION_138:
				return new OatQuickMethodHeader_Oreo(reader);
			case OatConstants.OAT_VERSION_170:
			case OatConstants.OAT_VERSION_183:
				return new OatQuickMethodHeader_Q_R(reader);
			case OatConstants.OAT_VERSION_195:
			case OatConstants.OAT_VERSION_199:
			case OatConstants.OAT_VERSION_220:
			case OatConstants.OAT_VERSION_223:
			case OatConstants.OAT_VERSION_225:
				return new OatQuickMethodHeader_S_T(reader);
		}
		throw new IOException("OatQuickMethodHeader unsupported OAT version: " + oatVersion);
	}
}
