diff --git a/README.md b/README.md new file mode 100644 index 00000000..ca96dcc1 --- /dev/null +++ b/README.md @@ -0,0 +1,66 @@ +# Android-Disassembler +Disassemble .so (NDK, JNI) files on Android. Capstone-based disassembler application on android + +# Features +- Shows details of elf files. +- Disassembles the entire code sections. +- Has various export options of the disassembly. +- Highlights branch instructions. +- Has Instant analysis mode. + +# Usuage +1. Choose an elf file to analyze. +1. Go to details tab. +1. Press `Show details` button to see details. +1. Press `Save to file` button to save it. +1. Go to disassembly tab. +1. Press `disassemble` button. +1. Choose instant mode or persist mode. +1. To export the disassembly, press `Export` button and choose the option. + +# Analysis mode + - Instant mode +Fast and lightweight, but buggy. + - Persist mode +A bit lags, but OK + +# Export mode + - Classic +Pretty! + - Simple +Can be directly pasted as code! + - Json +It can be loaded again to analyze again(though reloading is not implemented yet - Sorry:( ) + +# Permissions + +Before using the app you need some steps: +**Granting permissions** + +![image](images/Screenshot_20180926-090152.png) +![image](images/Screenshot_20180926-090201.png) + +# ScreenShots +![image](images/Screenshot_20180926-090313.png?rw) +![image](images/Screenshot_20180926-090316.png) +![image](images/Screenshot_20180926-090327.png) +![image](images/Screenshot_20180926-090417.png) + + +# Build +I use [AIDE](https://play.google.com/store/apps/details?id=com.aide.ui) to build the project. + +As AIDE doesn't seem to support gradle&JNI mixed project you need to downliad some library projects. + +https://github.com/dandar3/android-support-v7-appcompat + +And [modified storagechooser-2.](https://github.com/KYHSGeekCode/storage-chooser-2-android-buildable-libtary-project) + +# Open Source + - This app used [Capstone](https://github.com/aquynh/capstone), and [Colorpickerview](https://github.com/danielnilsson9/color-picker-view). + +# What's new + - Changed to Android Studio structure. + +# TODO + - Optimization \ No newline at end of file diff --git a/app/libs/jna.jar b/app/libs/jna.jar new file mode 100644 index 00000000..6eb13fee Binary files /dev/null and b/app/libs/jna.jar differ diff --git a/app/src/github/danielnilsson9/colorpickerview/dialog/ColorPickerDialogFragment.java b/app/src/github/danielnilsson9/colorpickerview/dialog/ColorPickerDialogFragment.java new file mode 100644 index 00000000..55c8e302 --- /dev/null +++ b/app/src/github/danielnilsson9/colorpickerview/dialog/ColorPickerDialogFragment.java @@ -0,0 +1,187 @@ +/* + * Copyright (C) 2015 Daniel Nilsson + * + * 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 com.github.danielnilsson9.colorpickerview.dialog; + +//import com.github.danielnilsson9.colorpickerview.R; +import com.github.danielnilsson9.colorpickerview.view.ColorPanelView; +import com.github.danielnilsson9.colorpickerview.view.ColorPickerView; +import com.github.danielnilsson9.colorpickerview.view.ColorPickerView.OnColorChangedListener; +import android.app.Activity; +import android.app.Dialog; +import android.app.DialogFragment; +import android.content.DialogInterface; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.view.Window; +import android.widget.Button; +import android.widget.TextView; +import com.jourhyang.disasmarm.*; + +public class ColorPickerDialogFragment extends DialogFragment { + + public interface ColorPickerDialogListener { + public void onColorSelected(int dialogId, int color); + public void onDialogDismissed(int dialogId); + } + + + private int mDialogId = -1; + + private ColorPickerView mColorPicker; + private ColorPanelView mOldColorPanel; + private ColorPanelView mNewColorPanel; + private Button mOkButton; + + private ColorPickerDialogListener mListener; + + + public static ColorPickerDialogFragment newInstance(int dialogId, int initialColor) { + return newInstance(dialogId, null, null, initialColor, false); + } + + public static ColorPickerDialogFragment newInstance( + int dialogId, String title, String okButtonText, int initialColor, boolean showAlphaSlider) { + + ColorPickerDialogFragment frag = new ColorPickerDialogFragment(); + Bundle args = new Bundle(); + args.putInt("id", dialogId); + args.putString("title", title); + args.putString("ok_button", okButtonText); + args.putBoolean("alpha", showAlphaSlider); + args.putInt("init_color", initialColor); + + frag.setArguments(args); + + return frag; + } + + + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mDialogId = getArguments().getInt("id"); + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + + Log.d("color-picker-view", "onAttach()"); + + // Check for listener in parent activity + try { + mListener = (ColorPickerDialogListener) activity; + } + catch (ClassCastException e) { + e.printStackTrace(); + throw new ClassCastException("Parent activity must implement " + + "ColorPickerDialogListener to receive result."); + } + } + + + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + Dialog d = super.onCreateDialog(savedInstanceState); + + + d.requestWindowFeature(Window.FEATURE_NO_TITLE); + d.getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT); + + return d; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View v = inflater.inflate(R.layout.colorpickerview__dialog_color_picker, container); + + + TextView titleView = (TextView) v.findViewById(android.R.id.title); + + mColorPicker = (ColorPickerView) + v.findViewById(R.id.colorpickerview__color_picker_view); + mOldColorPanel = (ColorPanelView) + v.findViewById(R.id.colorpickerview__color_panel_old); + mNewColorPanel = (ColorPanelView) + v.findViewById(R.id.colorpickerview__color_panel_new); + mOkButton = (Button) v.findViewById(android.R.id.button1); + + + mColorPicker.setOnColorChangedListener(new OnColorChangedListener() { + + @Override + public void onColorChanged(int newColor) { + mNewColorPanel.setColor(newColor); + } + }); + + mOkButton.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + mListener.onColorSelected(mDialogId, mColorPicker.getColor()); + getDialog().dismiss(); + } + + }); + + + String title = getArguments().getString("title"); + + if(title != null) { + titleView.setText(title); + } + else { + titleView.setVisibility(View.GONE); + } + + + if(savedInstanceState == null) { + mColorPicker.setAlphaSliderVisible( + getArguments().getBoolean("alpha")); + + + String ok = getArguments().getString("ok_button"); + if(ok != null) { + mOkButton.setText(ok); + } + + int initColor = getArguments().getInt("init_color"); + + mOldColorPanel.setColor(initColor); + mColorPicker.setColor(initColor, true); + } + + + return v; + } + + + @Override + public void onDismiss(DialogInterface dialog) { + super.onDismiss(dialog); + mListener.onDialogDismissed(mDialogId); + } + +} diff --git a/app/src/github/danielnilsson9/colorpickerview/drawable/AlphaPatternDrawable.java b/app/src/github/danielnilsson9/colorpickerview/drawable/AlphaPatternDrawable.java new file mode 100644 index 00000000..f8050c73 --- /dev/null +++ b/app/src/github/danielnilsson9/colorpickerview/drawable/AlphaPatternDrawable.java @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2015 Daniel Nilsson + * + * 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 com.github.danielnilsson9.colorpickerview.drawable; + +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.ColorFilter; +import android.graphics.Paint; +import android.graphics.Rect; +import android.graphics.Bitmap.Config; +import android.graphics.drawable.Drawable; + +/** + * This drawable will draw a simple white and gray chessboard pattern. + * It's pattern you will often see as a background behind a + * partly transparent image in many applications. + * @author Daniel Nilsson + */ +public class AlphaPatternDrawable extends Drawable { + + private int mRectangleSize = 10; + + private Paint mPaint = new Paint(); + private Paint mPaintWhite = new Paint(); + private Paint mPaintGray = new Paint(); + + private int numRectanglesHorizontal; + private int numRectanglesVertical; + + /** + * Bitmap in which the pattern will be cached. + * This is so the pattern will not have to be recreated each time draw() gets called. + * Because recreating the pattern i rather expensive. I will only be recreated if the + * size changes. + */ + private Bitmap mBitmap; + + public AlphaPatternDrawable(int rectangleSize) { + mRectangleSize = rectangleSize; + mPaintWhite.setColor(0xffffffff); + mPaintGray.setColor(0xffcbcbcb); + } + + @Override + public void draw(Canvas canvas) { + if(mBitmap != null && !mBitmap.isRecycled()) { + canvas.drawBitmap(mBitmap, null, getBounds(), mPaint); + } + } + + @Override + public int getOpacity() { + return 0; + } + + @Override + public void setAlpha(int alpha) { + throw new UnsupportedOperationException("Alpha is not supported by this drawable."); + } + + @Override + public void setColorFilter(ColorFilter cf) { + throw new UnsupportedOperationException("ColorFilter is not supported by this drawable."); + } + + @Override + protected void onBoundsChange(Rect bounds) { + super.onBoundsChange(bounds); + + int height = bounds.height(); + int width = bounds.width(); + + numRectanglesHorizontal = (int) Math.ceil((width / mRectangleSize)); + numRectanglesVertical = (int) Math.ceil(height / mRectangleSize); + + generatePatternBitmap(); + + } + + /** + * This will generate a bitmap with the pattern + * as big as the rectangle we were allow to draw on. + * We do this to chache the bitmap so we don't need to + * recreate it each time draw() is called since it + * takes a few milliseconds. + */ + private void generatePatternBitmap(){ + + if(getBounds().width() <= 0 || getBounds().height() <= 0){ + return; + } + + mBitmap = Bitmap.createBitmap(getBounds().width(), getBounds().height(), Config.ARGB_8888); + Canvas canvas = new Canvas(mBitmap); + + Rect r = new Rect(); + boolean verticalStartWhite = true; + for (int i = 0; i <= numRectanglesVertical; i++) { + + boolean isWhite = verticalStartWhite; + for (int j = 0; j <= numRectanglesHorizontal; j++) { + + r.top = i * mRectangleSize; + r.left = j * mRectangleSize; + r.bottom = r.top + mRectangleSize; + r.right = r.left + mRectangleSize; + + canvas.drawRect(r, isWhite ? mPaintWhite : mPaintGray); + + isWhite = !isWhite; + } + + verticalStartWhite = !verticalStartWhite; + + } + + } + +} diff --git a/app/src/github/danielnilsson9/colorpickerview/preference/ColorPreference.java b/app/src/github/danielnilsson9/colorpickerview/preference/ColorPreference.java new file mode 100644 index 00000000..6eab84ba --- /dev/null +++ b/app/src/github/danielnilsson9/colorpickerview/preference/ColorPreference.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2015 Daniel Nilsson + * + * 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 com.github.danielnilsson9.colorpickerview.preference; + +//import com.github.danielnilsson9.colorpickerview.R; +import com.github.danielnilsson9.colorpickerview.view.ColorPanelView; +import android.content.Context; +import android.content.res.TypedArray; +import android.preference.Preference; +import android.util.AttributeSet; +import android.view.View; +import com.jourhyang.disasmarm.*; + +public class ColorPreference extends Preference { + + public interface OnShowDialogListener { + public void onShowColorPickerDialog(String title, int currentColor); + } + + private OnShowDialogListener mListener; + + private int mColor = 0xFF000000; + + + public ColorPreference(Context context, AttributeSet attrs) { + super(context, attrs); + init(attrs); + } + + public ColorPreference(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + init(attrs); + + } + + private void init(AttributeSet attrs) { + setPersistent(true); + + setWidgetLayoutResource(R.layout.colorpickerview__preference_preview_layout); + + setOnPreferenceClickListener(new OnPreferenceClickListener() { + + @Override + public boolean onPreferenceClick(Preference preference) { + + if(mListener != null) { + mListener.onShowColorPickerDialog((String) getTitle(), mColor); + return true; + } + else { + throw new IllegalArgumentException( + "You must first call setOnShowDialogListener() and " + + "handle showing the ColorPickerDialogFragment yourself."); + } + } + }); + } + + + /** + * Since the color picker dialog is now a DialogFragment + * this preference cannot take care of showing it without + * access to the fragment manager. Therefore I leave it up to + * you to actually show the dialog once the preference is clicked. + * + * Call saveValue() once you have a color to save. + * @param listener + */ + public void setOnShowDialogListener(OnShowDialogListener listener) { + mListener = listener; + } + + + @Override + protected void onBindView(View view) { + super.onBindView(view); + + ColorPanelView preview = (ColorPanelView) view.findViewById(R.id.colorpickerview__preference_preview_color_panel); + + if(preview != null) { + preview.setColor(mColor); + } + + } + + @Override + protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue) { + if(restorePersistedValue) { + mColor = getPersistedInt(0xFF000000); + //Log.d("mColorPicker", "Load saved color: " + mColor); + } + else { + mColor = (Integer)defaultValue; + persistInt(mColor); + } + } + + @Override + protected Object onGetDefaultValue(TypedArray a, int index) { + return a.getInteger(index, 0xFF000000); + } + + + public void saveValue(int color) { + mColor = color; + persistInt(mColor); + notifyChanged(); + } + +} diff --git a/app/src/github/danielnilsson9/colorpickerview/view/ColorPanelView.java b/app/src/github/danielnilsson9/colorpickerview/view/ColorPanelView.java new file mode 100644 index 00000000..cd3cbeac --- /dev/null +++ b/app/src/github/danielnilsson9/colorpickerview/view/ColorPanelView.java @@ -0,0 +1,219 @@ +/* + * Copyright (C) 2015 Daniel Nilsson + * + * 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 com.github.danielnilsson9.colorpickerview.view; + +//import com.github.danielnilsson9.colorpickerview.R; +import com.github.danielnilsson9.colorpickerview.drawable.AlphaPatternDrawable; +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Rect; +import android.os.Bundle; +import android.os.Parcelable; +import android.util.AttributeSet; +import android.util.TypedValue; +import android.view.View; +import com.jourhyang.disasmarm.*; + +/** + * This class draws a panel which which will be filled with a color which can be set. + * It can be used to show the currently selected color which you will get from + * the {@link ColorPickerView}. + * @author Daniel Nilsson + * + */ +public class ColorPanelView extends View{ + + /** + * The width in pixels of the border + * surrounding the color panel. + */ + private final static int BORDER_WIDTH_PX = 1; + + private final static int DEFAULT_BORDER_COLOR = 0xFF6E6E6E; + + private int mBorderColor = DEFAULT_BORDER_COLOR; + private int mColor = 0xff000000; + + private Paint mBorderPaint; + private Paint mColorPaint; + + private Rect mDrawingRect; + private Rect mColorRect; + + private AlphaPatternDrawable mAlphaPattern; + + + public ColorPanelView(Context context) { + this(context, null); + } + + public ColorPanelView(Context context, AttributeSet attrs){ + this(context, attrs, 0); + } + + public ColorPanelView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + + init(context, attrs); + } + + @Override + public Parcelable onSaveInstanceState() { + + Bundle state = new Bundle(); + state.putParcelable("instanceState", super.onSaveInstanceState()); + state.putInt("color", mColor); + + return state; + } + + @Override + public void onRestoreInstanceState(Parcelable state) { + + if (state instanceof Bundle) { + Bundle bundle = (Bundle) state; + mColor = bundle.getInt("color"); + state = bundle.getParcelable("instanceState"); + } + super.onRestoreInstanceState(state); + } + + + private void init(Context context, AttributeSet attrs){ + + TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.colorpickerview__ColorPickerView); + mBorderColor = a.getColor(R.styleable.colorpickerview__ColorPickerView_borderColor, 0xFF6E6E6E); + a.recycle(); + + applyThemeColors(context); + + mBorderPaint = new Paint(); + mColorPaint = new Paint(); + } + + private void applyThemeColors(Context c) { + // If no specific border color has been + // set we take the default secondary text color + // as border/slider color. Thus it will adopt + // to theme changes automatically. + + final TypedValue value = new TypedValue (); + TypedArray a = c.obtainStyledAttributes(value.data, new int[] { android.R.attr.textColorSecondary }); + + if(mBorderColor == DEFAULT_BORDER_COLOR) { + mBorderColor = a.getColor(0, DEFAULT_BORDER_COLOR); + } + + a.recycle(); + } + + + @Override + protected void onDraw(Canvas canvas) { + final Rect rect = mColorRect; + + if(BORDER_WIDTH_PX > 0){ + mBorderPaint.setColor(mBorderColor); + canvas.drawRect(mDrawingRect, mBorderPaint); + } + + if(mAlphaPattern != null){ + mAlphaPattern.draw(canvas); + } + + mColorPaint.setColor(mColor); + + canvas.drawRect(rect, mColorPaint); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + + int width = MeasureSpec.getSize(widthMeasureSpec); + int height = MeasureSpec.getSize(heightMeasureSpec); + + setMeasuredDimension(width, height); + } + + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); + + mDrawingRect = new Rect(); + mDrawingRect.left = getPaddingLeft(); + mDrawingRect.right = w - getPaddingRight(); + mDrawingRect.top = getPaddingTop(); + mDrawingRect.bottom = h - getPaddingBottom(); + + setUpColorRect(); + } + + private void setUpColorRect(){ + final Rect dRect = mDrawingRect; + + int left = dRect.left + BORDER_WIDTH_PX; + int top = dRect.top + BORDER_WIDTH_PX; + int bottom = dRect.bottom - BORDER_WIDTH_PX; + int right = dRect.right - BORDER_WIDTH_PX; + + mColorRect = new Rect(left,top, right, bottom); + + mAlphaPattern = new AlphaPatternDrawable(DrawingUtils.dpToPx(getContext(), 2)); + + mAlphaPattern.setBounds(Math.round(mColorRect.left), + Math.round(mColorRect.top), + Math.round(mColorRect.right), + Math.round(mColorRect.bottom)); + + } + + /** + * Set the color that should be shown by this view. + * @param color + */ + public void setColor(int color){ + mColor = color; + invalidate(); + } + + /** + * Get the color currently show by this view. + * @return + */ + public int getColor(){ + return mColor; + } + + /** + * Set the color of the border surrounding the panel. + * @param color + */ + public void setBorderColor(int color){ + mBorderColor = color; + invalidate(); + } + + /** + * Get the color of the border surrounding the panel. + */ + public int getBorderColor(){ + return mBorderColor; + } + +} diff --git a/app/src/github/danielnilsson9/colorpickerview/view/ColorPickerView.java b/app/src/github/danielnilsson9/colorpickerview/view/ColorPickerView.java new file mode 100644 index 00000000..0f0d9d0c --- /dev/null +++ b/app/src/github/danielnilsson9/colorpickerview/view/ColorPickerView.java @@ -0,0 +1,1088 @@ +/* + * Copyright (C) 2015 Daniel Nilsson + * + * 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. + * + * + * + + * Change Log: + * + * 1.1 + * - Fixed buggy measure and layout code. You can now make the view any size you want. + * - Optimization of the drawing using a bitmap cache, a lot faster! + * - Support for hardware acceleration for all but the problematic + * part of the view will still be software rendered but much faster! + * See comment in drawSatValPanel() for more info. + * - Support for declaring some variables in xml. + * + * 1.2 - 2015-05-08 + * - More bugs in onMeasure() have been fixed, should handle all cases properly now. + * - View automatically saves its state now. + * - Automatic border color depending on current theme. + * - Code cleanup, trackball support removed since they do not exist anymore. + * + * 1.3 - 2015-05-10 + * - Fixed hue bar selection did not align with what was shown in the sat/val panel. + * Fixed by replacing the linear gardient used before. Now drawing individual lines + * of different colors. This was expensive so we now use a bitmap cache for the hue + * panel too. + * - Replaced all RectF used in the layout process with Rect since the + * floating point values was causing layout issues (perfect alignment). + */ +package com.github.danielnilsson9.colorpickerview.view; + +//import com.github.danielnilsson9.colorpickerview.R; +import com.github.danielnilsson9.colorpickerview.drawable.AlphaPatternDrawable; +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Bitmap; +import android.graphics.Bitmap.Config; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.ComposeShader; +import android.graphics.LinearGradient; +import android.graphics.Paint; +import android.graphics.Paint.Align; +import android.graphics.Paint.Style; +import android.graphics.Point; +import android.graphics.PorterDuff; +import android.graphics.Rect; +import android.graphics.RectF; +import android.graphics.Shader; +import android.graphics.Shader.TileMode; +import android.os.Bundle; +import android.os.Parcelable; +import android.util.AttributeSet; +import android.util.Log; +import android.util.TypedValue; +import android.view.MotionEvent; +import android.view.View; +import com.jourhyang.disasmarm.*; + +/** + * Displays a color picker to the user and allow them + * to select a color. A slider for the alpha channel is + * also available. Enable it by setting + * setAlphaSliderVisible(boolean) to true. + * @author Daniel Nilsson + */ +public class ColorPickerView extends View{ + + public interface OnColorChangedListener{ + public void onColorChanged(int newColor); + } + + private final static int DEFAULT_BORDER_COLOR = 0xFF6E6E6E; + private final static int DEFAULT_SLIDER_COLOR = 0xFFBDBDBD; + + private final static int HUE_PANEL_WDITH_DP = 30; + private final static int ALPHA_PANEL_HEIGH_DP = 20; + private final static int PANEL_SPACING_DP = 10; + private final static int CIRCLE_TRACKER_RADIUS_DP = 5; + private final static int SLIDER_TRACKER_SIZE_DP = 4; + private final static int SLIDER_TRACKER_OFFSET_DP = 2; + + + /** + * The width in pixels of the border + * surrounding all color panels. + */ + private final static int BORDER_WIDTH_PX = 1; + + /** + * The width in px of the hue panel. + */ + private int mHuePanelWidthPx; + /** + * The height in px of the alpha panel + */ + private int mAlphaPanelHeightPx; + /** + * The distance in px between the different + * color panels. + */ + private int mPanelSpacingPx; + /** + * The radius in px of the color palette tracker circle. + */ + private int mCircleTrackerRadiusPx; + /** + * The px which the tracker of the hue or alpha panel + * will extend outside of its bounds. + */ + private int mSliderTrackerOffsetPx; + /** + * Height of slider tracker on hue panel, + * width of slider on alpha panel. + */ + private int mSliderTrackerSizePx; + + + private Paint mSatValPaint; + private Paint mSatValTrackerPaint; + + private Paint mAlphaPaint; + private Paint mAlphaTextPaint; + private Paint mHueAlphaTrackerPaint; + + private Paint mBorderPaint; + + private Shader mValShader; + private Shader mSatShader; + private Shader mAlphaShader; + + + /* + * We cache a bitmap of the sat/val panel which is expensive to draw each time. + * We can reuse it when the user is sliding the circle picker as long as the hue isn't changed. + */ + private BitmapCache mSatValBackgroundCache; + /* We cache the hue background to since its also very expensive now. */ + private BitmapCache mHueBackgroundCache; + + /* Current values */ + private int mAlpha = 0xff; + private float mHue = 360f; + private float mSat = 0f; + private float mVal = 0f; + + private boolean mShowAlphaPanel = false; + private String mAlphaSliderText = null; + private int mSliderTrackerColor = DEFAULT_SLIDER_COLOR; + private int mBorderColor = DEFAULT_BORDER_COLOR; + + + /** + * Minimum required padding. The offset from the + * edge we must have or else the finger tracker will + * get clipped when it's drawn outside of the view. + */ + private int mRequiredPadding; + + + /** + * The Rect in which we are allowed to draw. + * Trackers can extend outside slightly, + * due to the required padding we have set. + */ + private Rect mDrawingRect; + + private Rect mSatValRect; + private Rect mHueRect; + private Rect mAlphaRect; + + private Point mStartTouchPoint = null; + + private AlphaPatternDrawable mAlphaPattern; + private OnColorChangedListener mListener; + + + public ColorPickerView(Context context){ + this(context, null); + } + + public ColorPickerView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public ColorPickerView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + init(context, attrs); + } + + + + @Override + public Parcelable onSaveInstanceState() { + + Bundle state = new Bundle(); + state.putParcelable("instanceState", super.onSaveInstanceState()); + state.putInt("alpha", mAlpha); + state.putFloat("hue", mHue); + state.putFloat("sat", mSat); + state.putFloat("val", mVal); + state.putBoolean("show_alpha", mShowAlphaPanel); + state.putString("alpha_text", mAlphaSliderText); + + return state; + } + + @Override + public void onRestoreInstanceState(Parcelable state) { + + if (state instanceof Bundle) { + Bundle bundle = (Bundle) state; + + mAlpha = bundle.getInt("alpha"); + mHue = bundle.getFloat("hue"); + mSat = bundle.getFloat("sat"); + mVal = bundle.getFloat("val"); + mShowAlphaPanel = bundle.getBoolean("show_alpha"); + mAlphaSliderText = bundle.getString("alpha_text"); + + + state = bundle.getParcelable("instanceState"); + } + super.onRestoreInstanceState(state); + } + + + private void init(Context context, AttributeSet attrs) { + //Load those if set in xml resource file. + TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.colorpickerview__ColorPickerView); + mShowAlphaPanel = a.getBoolean(R.styleable.colorpickerview__ColorPickerView_alphaChannelVisible, false); + mAlphaSliderText = a.getString(R.styleable.colorpickerview__ColorPickerView_alphaChannelText); + mSliderTrackerColor = a.getColor(R.styleable.colorpickerview__ColorPickerView_sliderColor, 0xFFBDBDBD); + mBorderColor = a.getColor(R.styleable.colorpickerview__ColorPickerView_borderColor, 0xFF6E6E6E); + a.recycle(); + + applyThemeColors(context); + + + mHuePanelWidthPx = DrawingUtils.dpToPx(getContext(), HUE_PANEL_WDITH_DP); + mAlphaPanelHeightPx = DrawingUtils.dpToPx(getContext(), ALPHA_PANEL_HEIGH_DP); + mPanelSpacingPx = DrawingUtils.dpToPx(getContext(), PANEL_SPACING_DP); + mCircleTrackerRadiusPx = DrawingUtils.dpToPx(getContext(), CIRCLE_TRACKER_RADIUS_DP); + mSliderTrackerSizePx = DrawingUtils.dpToPx(getContext(), SLIDER_TRACKER_SIZE_DP); + mSliderTrackerOffsetPx = DrawingUtils.dpToPx(getContext(), SLIDER_TRACKER_OFFSET_DP); + + mRequiredPadding = getResources().getDimensionPixelSize(R.dimen.colorpickerview__required_padding); + + initPaintTools(); + + //Needed for receiving trackball motion events. + setFocusable(true); + setFocusableInTouchMode(true); + } + + private void applyThemeColors(Context c) { + // If no specific border/slider color has been + // set we take the default secondary text color + // as border/slider color. Thus it will adopt + // to theme changes automatically. + + final TypedValue value = new TypedValue (); + TypedArray a = c.obtainStyledAttributes(value.data, new int[] { android.R.attr.textColorSecondary }); + + if(mBorderColor == DEFAULT_BORDER_COLOR) { + mBorderColor = a.getColor(0, DEFAULT_BORDER_COLOR); + } + + if(mSliderTrackerColor == DEFAULT_SLIDER_COLOR) { + mSliderTrackerColor = a.getColor(0, DEFAULT_SLIDER_COLOR); + } + + a.recycle(); + } + + private void initPaintTools(){ + + mSatValPaint = new Paint(); + mSatValTrackerPaint = new Paint(); + mHueAlphaTrackerPaint = new Paint(); + mAlphaPaint = new Paint(); + mAlphaTextPaint = new Paint(); + mBorderPaint = new Paint(); + + + mSatValTrackerPaint.setStyle(Style.STROKE); + mSatValTrackerPaint.setStrokeWidth(DrawingUtils.dpToPx(getContext(), 2)); + mSatValTrackerPaint.setAntiAlias(true); + + mHueAlphaTrackerPaint.setColor(mSliderTrackerColor); + mHueAlphaTrackerPaint.setStyle(Style.STROKE); + mHueAlphaTrackerPaint.setStrokeWidth(DrawingUtils.dpToPx(getContext(), 2)); + mHueAlphaTrackerPaint.setAntiAlias(true); + + mAlphaTextPaint.setColor(0xff1c1c1c); + mAlphaTextPaint.setTextSize(DrawingUtils.dpToPx(getContext(), 14)); + mAlphaTextPaint.setAntiAlias(true); + mAlphaTextPaint.setTextAlign(Align.CENTER); + mAlphaTextPaint.setFakeBoldText(true); + + } + + + + @Override + protected void onDraw(Canvas canvas) { + if(mDrawingRect.width() <= 0 || mDrawingRect.height() <= 0) { + return; + } + + drawSatValPanel(canvas); + drawHuePanel(canvas); + drawAlphaPanel(canvas); + } + + private void drawSatValPanel(Canvas canvas){ + final Rect rect = mSatValRect; + + if(BORDER_WIDTH_PX > 0){ + mBorderPaint.setColor(mBorderColor); + canvas.drawRect(mDrawingRect.left, mDrawingRect.top, + rect.right + BORDER_WIDTH_PX, + rect.bottom + BORDER_WIDTH_PX, mBorderPaint); + } + + if(mValShader == null) { + //Black gradient has either not been created or the view has been resized. + mValShader = new LinearGradient( + rect.left, rect.top, rect.left, rect.bottom, + 0xffffffff, 0xff000000, TileMode.CLAMP); + } + + + //If the hue has changed we need to recreate the cache. + if(mSatValBackgroundCache == null || mSatValBackgroundCache.value != mHue) { + + if(mSatValBackgroundCache == null) { + mSatValBackgroundCache = new BitmapCache(); + } + + //We create our bitmap in the cache if it doesn't exist. + if(mSatValBackgroundCache.bitmap == null) { + mSatValBackgroundCache.bitmap = Bitmap + .createBitmap(rect.width(), rect.height(), Config.ARGB_8888); + } + + //We create the canvas once so we can draw on our bitmap and the hold on to it. + if(mSatValBackgroundCache.canvas == null) { + mSatValBackgroundCache.canvas = new Canvas(mSatValBackgroundCache.bitmap); + } + + int rgb = Color.HSVToColor(new float[]{mHue,1f,1f}); + + mSatShader = new LinearGradient( + rect.left, rect.top, rect.right, rect.top, + 0xffffffff, rgb, TileMode.CLAMP); + + ComposeShader mShader = new ComposeShader( + mValShader, mSatShader, PorterDuff.Mode.MULTIPLY); + mSatValPaint.setShader(mShader); + + // Finally we draw on our canvas, the result will be + // stored in our bitmap which is already in the cache. + // Since this is drawn on a canvas not rendered on + // screen it will automatically not be using the + // hardware acceleration. And this was the code that + // wasn't supported by hardware acceleration which mean + // there is no need to turn it of anymore. The rest of + // the view will still be hw accelerated. + mSatValBackgroundCache.canvas.drawRect(0, 0, + mSatValBackgroundCache.bitmap.getWidth(), + mSatValBackgroundCache.bitmap.getHeight(), + mSatValPaint); + + //We set the hue value in our cache to which hue it was drawn with, + //then we know that if it hasn't changed we can reuse our cached bitmap. + mSatValBackgroundCache.value = mHue; + + } + + // We draw our bitmap from the cached, if the hue has changed + // then it was just recreated otherwise the old one will be used. + canvas.drawBitmap(mSatValBackgroundCache.bitmap, null, rect, null); + + Point p = satValToPoint(mSat, mVal); + + mSatValTrackerPaint.setColor(0xff000000); + canvas.drawCircle(p.x, p.y, + mCircleTrackerRadiusPx - DrawingUtils.dpToPx(getContext(), 1), + mSatValTrackerPaint); + + mSatValTrackerPaint.setColor(0xffdddddd); + canvas.drawCircle(p.x, p.y, + mCircleTrackerRadiusPx, mSatValTrackerPaint); + + } + + private void drawHuePanel(Canvas canvas){ + final Rect rect = mHueRect; + + if(BORDER_WIDTH_PX > 0) { + mBorderPaint.setColor(mBorderColor); + + canvas.drawRect(rect.left - BORDER_WIDTH_PX, + rect.top - BORDER_WIDTH_PX, + rect.right + BORDER_WIDTH_PX, + rect.bottom + BORDER_WIDTH_PX, + mBorderPaint); + } + + + if(mHueBackgroundCache == null) { + mHueBackgroundCache = new BitmapCache(); + mHueBackgroundCache.bitmap = + Bitmap.createBitmap(rect.width(), rect.height(), Config.ARGB_8888); + mHueBackgroundCache.canvas = new Canvas(mHueBackgroundCache.bitmap); + + + int[] hueColors = new int[(int)(rect.height() + 0.5f)]; + + // Generate array of all colors, will be drawn as individual lines. + float h = 360f; + for(int i = 0; i < hueColors.length; i++) { + hueColors[i] = Color.HSVToColor(new float[]{h, 1f,1f}); + h -= 360f / hueColors.length; + } + + // Time to draw the hue color gradient, + // its drawn as individual lines which + // will be quite many when the resolution is high + // and/or the panel is large. + Paint linePaint = new Paint(); + linePaint.setStrokeWidth(0); + for(int i = 0; i < hueColors.length; i++) { + linePaint.setColor(hueColors[i]); + mHueBackgroundCache.canvas.drawLine(0, i, mHueBackgroundCache.bitmap.getWidth(), i, linePaint); + } + } + + + canvas.drawBitmap(mHueBackgroundCache.bitmap, null, rect, null); + + Point p = hueToPoint(mHue); + + RectF r = new RectF(); + r.left = rect.left - mSliderTrackerOffsetPx; + r.right = rect.right + mSliderTrackerOffsetPx; + r.top = p.y - (mSliderTrackerSizePx / 2); + r.bottom = p.y + (mSliderTrackerSizePx / 2); + + canvas.drawRoundRect(r, 2, 2, mHueAlphaTrackerPaint); + } + + private void drawAlphaPanel(Canvas canvas) { + /* + * Will be drawn with hw acceleration, very fast. + * Also the AlphaPatternDrawable is backed by a bitmap + * generated only once if the size does not change. + */ + + if(!mShowAlphaPanel || mAlphaRect == null || mAlphaPattern == null) return; + + final Rect rect = mAlphaRect; + + if(BORDER_WIDTH_PX > 0){ + mBorderPaint.setColor(mBorderColor); + canvas.drawRect(rect.left - BORDER_WIDTH_PX, + rect.top - BORDER_WIDTH_PX, + rect.right + BORDER_WIDTH_PX, + rect.bottom + BORDER_WIDTH_PX, + mBorderPaint); + } + + mAlphaPattern.draw(canvas); + + float[] hsv = new float[]{mHue,mSat,mVal}; + int color = Color.HSVToColor(hsv); + int acolor = Color.HSVToColor(0, hsv); + + mAlphaShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top, + color, acolor, TileMode.CLAMP); + + + mAlphaPaint.setShader(mAlphaShader); + + canvas.drawRect(rect, mAlphaPaint); + + if(mAlphaSliderText != null && !mAlphaSliderText.equals("")){ + canvas.drawText(mAlphaSliderText, rect.centerX(), + rect.centerY() + DrawingUtils.dpToPx(getContext(), 4), + mAlphaTextPaint); + } + + + Point p = alphaToPoint(mAlpha); + + RectF r = new RectF(); + r.left = p.x - (mSliderTrackerSizePx / 2); + r.right = p.x + (mSliderTrackerSizePx / 2); + r.top = rect.top - mSliderTrackerOffsetPx; + r.bottom = rect.bottom + mSliderTrackerOffsetPx; + + canvas.drawRoundRect(r, 2, 2, mHueAlphaTrackerPaint); + } + + + private Point hueToPoint(float hue){ + + final Rect rect = mHueRect; + final float height = rect.height(); + + Point p = new Point(); + + p.y = (int) (height - (hue * height / 360f) + rect.top); + p.x = (int) rect.left; + + return p; + } + + private Point satValToPoint(float sat, float val){ + + final Rect rect = mSatValRect; + final float height = rect.height(); + final float width = rect.width(); + + Point p = new Point(); + + p.x = (int) (sat * width + rect.left); + p.y = (int) ((1f - val) * height + rect.top); + + return p; + } + + private Point alphaToPoint(int alpha){ + + final Rect rect = mAlphaRect; + final float width = rect.width(); + + Point p = new Point(); + + p.x = (int) (width - (alpha * width / 0xff) + rect.left); + p.y = (int) rect.top; + + return p; + + } + + private float[] pointToSatVal(float x, float y){ + + final Rect rect = mSatValRect; + float[] result = new float[2]; + + float width = rect.width(); + float height = rect.height(); + + if (x < rect.left){ + x = 0f; + } + else if(x > rect.right){ + x = width; + } + else{ + x = x - rect.left; + } + + if (y < rect.top){ + y = 0f; + } + else if(y > rect.bottom){ + y = height; + } + else{ + y = y - rect.top; + } + + + result[0] = 1.f / width * x; + result[1] = 1.f - (1.f / height * y); + + return result; + } + + private float pointToHue(float y){ + + final Rect rect = mHueRect; + + float height = rect.height(); + + if (y < rect.top){ + y = 0f; + } + else if(y > rect.bottom){ + y = height; + } + else{ + y = y - rect.top; + } + + + float hue = 360f - (y * 360f / height); + Log.d("color-picker-view", "Hue: " + hue); + + return hue; + } + + private int pointToAlpha(int x){ + + final Rect rect = mAlphaRect; + final int width = (int) rect.width(); + + if(x < rect.left){ + x = 0; + } + else if(x > rect.right){ + x = width; + } + else{ + x = x - (int)rect.left; + } + + return 0xff - (x * 0xff / width); + + } + + + @SuppressLint("ClickableViewAccessibility") + @Override + public boolean onTouchEvent(MotionEvent event) { + boolean update = false; + + switch(event.getAction()){ + + case MotionEvent.ACTION_DOWN: + mStartTouchPoint = new Point((int)event.getX(), (int)event.getY()); + update = moveTrackersIfNeeded(event); + break; + case MotionEvent.ACTION_MOVE: + update = moveTrackersIfNeeded(event); + break; + case MotionEvent.ACTION_UP: + mStartTouchPoint = null; + update = moveTrackersIfNeeded(event); + break; + } + + if(update){ + if(mListener != null){ + mListener.onColorChanged(Color.HSVToColor(mAlpha, new float[]{mHue, mSat, mVal})); + } + invalidate(); + return true; + } + + return super.onTouchEvent(event); + } + + private boolean moveTrackersIfNeeded(MotionEvent event){ + if(mStartTouchPoint == null) { + return false; + } + + boolean update = false; + + int startX = mStartTouchPoint.x; + int startY = mStartTouchPoint.y; + + if(mHueRect.contains(startX, startY)){ + mHue = pointToHue(event.getY()); + + update = true; + } + else if(mSatValRect.contains(startX, startY)){ + float[] result = pointToSatVal(event.getX(), event.getY()); + + mSat = result[0]; + mVal = result[1]; + + update = true; + } + else if(mAlphaRect != null && mAlphaRect.contains(startX, startY)){ + mAlpha = pointToAlpha((int)event.getX()); + + update = true; + } + + return update; + } + + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + int finalWidth = 0; + int finalHeight = 0; + + int widthMode = MeasureSpec.getMode(widthMeasureSpec); + int heightMode = MeasureSpec.getMode(heightMeasureSpec); + + int widthAllowed = MeasureSpec.getSize(widthMeasureSpec) - getPaddingLeft() - getPaddingRight(); + int heightAllowed = MeasureSpec.getSize(heightMeasureSpec) - getPaddingBottom() - getPaddingTop(); + + + //Log.d("color-picker-view", "widthMode: " + modeToString(widthMode) + " heightMode: " + modeToString(heightMode) + " widthAllowed: " + widthAllowed + " heightAllowed: " + heightAllowed); + + if(widthMode == MeasureSpec.EXACTLY || heightMode == MeasureSpec.EXACTLY) { + //A exact value has been set in either direction, we need to stay within this size. + + if(widthMode == MeasureSpec.EXACTLY && heightMode != MeasureSpec.EXACTLY) { + //The with has been specified exactly, we need to adopt the height to fit. + int h = (int) (widthAllowed - mPanelSpacingPx - mHuePanelWidthPx); + + if(mShowAlphaPanel) { + h += mPanelSpacingPx + mAlphaPanelHeightPx; + } + + if(h > heightAllowed) { + //We can't fit the view in this container, set the size to whatever was allowed. + finalHeight = heightAllowed; + } + else { + finalHeight = h; + } + + finalWidth = widthAllowed; + + } + else if(heightMode == MeasureSpec.EXACTLY && widthMode != MeasureSpec.EXACTLY) { + //The height has been specified exactly, we need to stay within this height and adopt the width. + + int w = (int) (heightAllowed + mPanelSpacingPx + mHuePanelWidthPx); + + if(mShowAlphaPanel) { + w -= (mPanelSpacingPx + mAlphaPanelHeightPx); + } + + if(w > widthAllowed) { + //we can't fit within this container, set the size to whatever was allowed. + finalWidth = widthAllowed; + } + else { + finalWidth = w; + } + + finalHeight = heightAllowed; + + } + else { + //If we get here the dev has set the width and height to exact sizes. For example match_parent or 300dp. + //This will mean that the sat/val panel will not be square but it doesn't matter. It will work anyway. + //In all other senarios our goal is to make that panel square. + + //We set the sizes to exactly what we were told. + finalWidth = widthAllowed; + finalHeight = heightAllowed; + } + + } + else { + //If no exact size has been set we try to make our view as big as possible + //within the allowed space. + + //Calculate the needed width to layout using max allowed height. + int widthNeeded = (int) (heightAllowed + mPanelSpacingPx + mHuePanelWidthPx); + + //Calculate the needed height to layout using max allowed width. + int heightNeeded = (int) (widthAllowed - mPanelSpacingPx - mHuePanelWidthPx); + + if(mShowAlphaPanel) { + widthNeeded -= (mPanelSpacingPx + mAlphaPanelHeightPx); + heightNeeded += mPanelSpacingPx + mAlphaPanelHeightPx; + } + + boolean widthOk = false; + boolean heightOk = false; + + if(widthNeeded <= widthAllowed) { + widthOk = true; + } + + if(heightNeeded <= heightAllowed) { + heightOk = true; + } + + + //Log.d("color-picker-view", "Size - Allowed w: " + widthAllowed + " h: " + heightAllowed + " Needed w:" + widthNeeded + " h: " + heightNeeded); + + + if(widthOk && heightOk) { + finalWidth = widthAllowed; + finalHeight = heightNeeded; + } + else if(!heightOk && widthOk) { + finalHeight = heightAllowed; + finalWidth = widthNeeded; + } + else if(!widthOk && heightOk) { + finalHeight = heightNeeded; + finalWidth = widthAllowed; + } + else { + finalHeight = heightAllowed; + finalWidth = widthAllowed; + } + + } + + //Log.d("color-picker-view", "Final Size: " + finalWidth + "x" + finalHeight); + + setMeasuredDimension(finalWidth + getPaddingLeft() + getPaddingRight(), + finalHeight + getPaddingTop() + getPaddingBottom()); + } + + private int getPreferredWidth(){ + //Our preferred width and height is 200dp for the square sat / val rectangle. + int width = DrawingUtils.dpToPx(getContext(), 200); + + return (int) (width + mHuePanelWidthPx + mPanelSpacingPx); + } + + private int getPreferredHeight(){ + int height = DrawingUtils.dpToPx(getContext(), 200); + + if(mShowAlphaPanel){ + height += mPanelSpacingPx + mAlphaPanelHeightPx; + } + return height; + } + + @Override + public int getPaddingTop() { + return Math.max(super.getPaddingTop(), mRequiredPadding); + } + + @Override + public int getPaddingBottom() { + return Math.max(super.getPaddingBottom(), mRequiredPadding); + } + + @Override + public int getPaddingLeft() { + return Math.max(super.getPaddingLeft(), mRequiredPadding); + } + + @Override + public int getPaddingRight() { + return Math.max(super.getPaddingRight(), mRequiredPadding); + } + + + + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); + + mDrawingRect = new Rect(); + mDrawingRect.left = getPaddingLeft(); + mDrawingRect.right = w - getPaddingRight(); + mDrawingRect.top = getPaddingTop(); + mDrawingRect.bottom = h - getPaddingBottom(); + + //The need to be recreated because they depend on the size of the view. + mValShader = null; + mSatShader = null; + mAlphaShader = null;; + + // Clear those bitmap caches since the size may have changed. + mSatValBackgroundCache = null; + mHueBackgroundCache = null; + + //Log.d("color-picker-view", "Size: " + w + "x" + h); + + setUpSatValRect(); + setUpHueRect(); + setUpAlphaRect(); + } + + private void setUpSatValRect(){ + //Calculate the size for the big color rectangle. + final Rect dRect = mDrawingRect; + + int left = dRect.left + BORDER_WIDTH_PX; + int top = dRect.top + BORDER_WIDTH_PX; + int bottom = dRect.bottom - BORDER_WIDTH_PX; + int right = dRect.right - BORDER_WIDTH_PX - mPanelSpacingPx - mHuePanelWidthPx; + + + if(mShowAlphaPanel) { + bottom -= (mAlphaPanelHeightPx + mPanelSpacingPx); + } + + mSatValRect = new Rect(left,top, right, bottom); + } + + private void setUpHueRect(){ + //Calculate the size for the hue slider on the left. + final Rect dRect = mDrawingRect; + + int left = dRect.right - mHuePanelWidthPx + BORDER_WIDTH_PX; + int top = dRect.top + BORDER_WIDTH_PX; + int bottom = dRect.bottom - BORDER_WIDTH_PX - (mShowAlphaPanel ? (mPanelSpacingPx + mAlphaPanelHeightPx) : 0); + int right = dRect.right - BORDER_WIDTH_PX; + + mHueRect = new Rect(left, top, right, bottom); + } + + private void setUpAlphaRect(){ + + if(!mShowAlphaPanel) return; + + final Rect dRect = mDrawingRect; + + int left = dRect.left + BORDER_WIDTH_PX; + int top = dRect.bottom - mAlphaPanelHeightPx + BORDER_WIDTH_PX; + int bottom = dRect.bottom - BORDER_WIDTH_PX; + int right = dRect.right - BORDER_WIDTH_PX; + + mAlphaRect = new Rect(left, top, right, bottom); + + + mAlphaPattern = new AlphaPatternDrawable(DrawingUtils.dpToPx(getContext(), 5)); + mAlphaPattern.setBounds(Math.round(mAlphaRect.left), Math + .round(mAlphaRect.top), Math.round(mAlphaRect.right), Math + .round(mAlphaRect.bottom)); + } + + + /** + * Set a OnColorChangedListener to get notified when the color + * selected by the user has changed. + * @param listener + */ + public void setOnColorChangedListener(OnColorChangedListener listener){ + mListener = listener; + } + + /** + * Get the current color this view is showing. + * @return the current color. + */ + public int getColor(){ + return Color.HSVToColor(mAlpha, new float[]{mHue,mSat,mVal}); + } + + /** + * Set the color the view should show. + * @param color The color that should be selected. #argb + */ + public void setColor(int color){ + setColor(color, false); + } + + /** + * Set the color this view should show. + * @param color The color that should be selected. #argb + * @param callback If you want to get a callback to + * your OnColorChangedListener. + */ + public void setColor(int color, boolean callback){ + + int alpha = Color.alpha(color); + int red = Color.red(color); + int blue = Color.blue(color); + int green = Color.green(color); + + float[] hsv = new float[3]; + + Color.RGBToHSV(red, green, blue, hsv); + + mAlpha = alpha; + mHue = hsv[0]; + mSat = hsv[1]; + mVal = hsv[2]; + + if(callback && mListener != null){ + mListener.onColorChanged(Color.HSVToColor(mAlpha, new float[]{mHue, mSat, mVal})); + } + + invalidate(); + } + + /** + * Set if the user is allowed to adjust the alpha panel. Default is false. + * If it is set to false no alpha will be set. + * @param visible + */ + public void setAlphaSliderVisible(boolean visible){ + if(mShowAlphaPanel != visible){ + mShowAlphaPanel = visible; + + /* + * Force recreation. + */ + mValShader = null; + mSatShader = null; + mAlphaShader = null; + mHueBackgroundCache = null; + mSatValBackgroundCache = null; + + requestLayout(); + } + + } + + /** + * Set the color of the tracker slider on the hue and alpha panel. + * @param color + */ + public void setSliderTrackerColor(int color){ + mSliderTrackerColor = color; + mHueAlphaTrackerPaint.setColor(mSliderTrackerColor); + invalidate(); + } + + /** + * Get color of the tracker slider on the hue and alpha panel. + * @return + */ + public int getSliderTrackerColor(){ + return mSliderTrackerColor; + } + + /** + * Set the color of the border surrounding all panels. + * @param color + */ + public void setBorderColor(int color){ + mBorderColor = color; + invalidate(); + } + + /** + * Get the color of the border surrounding all panels. + */ + public int getBorderColor(){ + return mBorderColor; + } + + /** + * Set the text that should be shown in the + * alpha slider. Set to null to disable text. + * @param res string resource id. + */ + public void setAlphaSliderText(int res){ + String text = getContext().getString(res); + setAlphaSliderText(text); + } + + /** + * Set the text that should be shown in the + * alpha slider. Set to null to disable text. + * @param text Text that should be shown. + */ + public void setAlphaSliderText(String text){ + mAlphaSliderText = text; + invalidate(); + } + + /** + * Get the current value of the text + * that will be shown in the alpha + * slider. + * @return + */ + public String getAlphaSliderText(){ + return mAlphaSliderText; + } + + + private class BitmapCache { + public Canvas canvas; + public Bitmap bitmap; + public float value; + } + +} diff --git a/app/src/github/danielnilsson9/colorpickerview/view/DrawingUtils.java b/app/src/github/danielnilsson9/colorpickerview/view/DrawingUtils.java new file mode 100644 index 00000000..77b1081c --- /dev/null +++ b/app/src/github/danielnilsson9/colorpickerview/view/DrawingUtils.java @@ -0,0 +1,26 @@ +package com.github.danielnilsson9.colorpickerview.view; + +import android.content.Context; +import android.util.DisplayMetrics; +import android.util.TypedValue; + +public class DrawingUtils { + + public static int dpToPx(Context c, float dipValue) { + DisplayMetrics metrics = c.getResources().getDisplayMetrics(); + + float val = TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, dipValue, metrics); + + // Round + int res = (int)(val + 0.5); + + // Ensure at least 1 pixel if val was > 0 + if(res == 0 && val > 0) { + res = 1; + } + + return res; + } + +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 37f11960..5536a2d7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,11 @@ - + package="com.kyhsgeekcode.disassembler" + xmlns:tools="http://schemas.android.com/tools"> + + + + + + + diff --git a/app/src/main/assets/capstone b/app/src/main/assets/capstone new file mode 100644 index 00000000..b5be356b --- /dev/null +++ b/app/src/main/assets/capstone @@ -0,0 +1,31 @@ +This is the software license for Capstone disassembly framework. +Capstone has been designed & implemented by Nguyen Anh Quynh + +See http://www.capstone-engine.org for further information. + +Copyright (c) 2013, COSEINC. +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 the developer(s) 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 HOLDER 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. \ No newline at end of file diff --git a/app/src/main/assets/colorpicker b/app/src/main/assets/colorpicker new file mode 100644 index 00000000..e06d2081 --- /dev/null +++ b/app/src/main/assets/colorpicker @@ -0,0 +1,202 @@ +Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + 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. + diff --git a/app/src/main/java/capstone/.gitignore b/app/src/main/java/capstone/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/app/src/main/java/capstone/Arm.java b/app/src/main/java/capstone/Arm.java new file mode 100644 index 00000000..f8c7e0cf --- /dev/null +++ b/app/src/main/java/capstone/Arm.java @@ -0,0 +1,148 @@ +// Capstone Java binding +// By Nguyen Anh Quynh & Dang Hoang Vu, 2013 + +package capstone; + +import com.sun.jna.Structure; +import com.sun.jna.Union; + +import java.util.List; +import java.util.Arrays; + +import static capstone.Arm_const.*; + +public class Arm { + + public static class MemType extends Structure { + public int base; + public int index; + public int scale; + public int disp; + + @Override + public List getFieldOrder() { + return Arrays.asList("base", "index", "scale", "disp"); + } + } + + public static class OpValue extends Union { + public int reg; + public int imm; + public double fp; + public MemType mem; + public int setend; + + @Override + public List getFieldOrder() { + return Arrays.asList("reg", "imm", "fp", "mem", "setend"); + } + } + + public static class OpShift extends Structure { + public int type; + public int value; + + @Override + public List getFieldOrder() { + return Arrays.asList("type","value"); + } + } + + public static class Operand extends Structure { + public int vector_index; + public OpShift shift; + public int type; + public OpValue value; + public boolean subtracted; + + public void read() { + readField("vector_index"); + readField("type"); + if (type == ARM_OP_MEM) + value.setType(MemType.class); + if (type == ARM_OP_FP) + value.setType(Double.TYPE); + if (type == ARM_OP_PIMM || type == ARM_OP_IMM || type == ARM_OP_CIMM) + value.setType(Integer.TYPE); + if (type == ARM_OP_REG) + value.setType(Integer.TYPE); + if (type == ARM_OP_INVALID) + return; + readField("value"); + readField("shift"); + readField("subtracted"); + } + + @Override + public List getFieldOrder() { + return Arrays.asList("vector_index", "shift", "type", "value", "subtracted"); + } + } + + public static class UnionOpInfo extends Capstone.UnionOpInfo { + public boolean usermode; + public int vector_size; + public int vector_data; + public int cps_mode; + public int cps_flag; + public int cc; + public byte update_flags; + public byte writeback; + public byte mem_barrier; + public byte op_count; + + public Operand [] op; + + public UnionOpInfo() { + op = new Operand[36]; + } + + public void read() { + readField("usermode"); + readField("vector_size"); + readField("vector_data"); + readField("cps_mode"); + readField("cps_flag"); + readField("cc"); + readField("update_flags"); + readField("writeback"); + readField("mem_barrier"); + readField("op_count"); + op = new Operand[op_count]; + if (op_count != 0) + readField("op"); + } + + @Override + public List getFieldOrder() { + return Arrays.asList("usermode", "vector_size", "vector_data", + "cps_mode", "cps_flag", "cc", "update_flags", "writeback", "mem_barrier", "op_count", "op"); + } + } + + public static class OpInfo extends Capstone.OpInfo { + public boolean usermode; + public int vectorSize; + public int vectorData; + public int cpsMode; + public int cpsFlag; + public int cc; + public boolean updateFlags; + public boolean writeback; + public int memBarrier; + public Operand [] op = null; + + public OpInfo(UnionOpInfo op_info) { + usermode = op_info.usermode; + vectorSize = op_info.vector_size; + vectorData = op_info.vector_data; + cpsMode = op_info.cps_mode; + cpsFlag = op_info.cps_flag; + cc = op_info.cc; + updateFlags = (op_info.update_flags > 0); + writeback = (op_info.writeback > 0); + memBarrier = op_info.mem_barrier; + op = op_info.op; + } + } +} diff --git a/app/src/main/java/capstone/Arm64.java b/app/src/main/java/capstone/Arm64.java new file mode 100644 index 00000000..258e1b54 --- /dev/null +++ b/app/src/main/java/capstone/Arm64.java @@ -0,0 +1,127 @@ +// Capstone Java binding +// By Nguyen Anh Quynh & Dang Hoang Vu, 2013 + +package capstone; + +import com.sun.jna.Structure; +import com.sun.jna.Union; + +import java.util.List; +import java.util.Arrays; + +import static capstone.Arm64_const.*; + +public class Arm64 { + + public static class MemType extends Structure { + public int base; + public int index; + public int disp; + + @Override + public List getFieldOrder() { + return Arrays.asList("base", "index", "disp"); + } + } + + public static class OpValue extends Union { + public int reg; + public long imm; + public double fp; + public MemType mem; + public int pstate; + public int sys; + public int prefetch; + public int barrier; + + @Override + public List getFieldOrder() { + return Arrays.asList("reg", "imm", "fp", "mem", "pstate", "sys", "prefetch", "barrier"); + } + } + + public static class OpShift extends Structure { + public int type; + public int value; + + @Override + public List getFieldOrder() { + return Arrays.asList("type","value"); + } + } + + public static class Operand extends Structure { + public int vector_index; + public int vas; + public int vess; + public OpShift shift; + public int ext; + public int type; + public OpValue value; + + public void read() { + readField("type"); + if (type == ARM64_OP_MEM) + value.setType(MemType.class); + if (type == ARM64_OP_FP) + value.setType(Double.TYPE); + if (type == ARM64_OP_IMM || type == ARM64_OP_CIMM || type == ARM64_OP_REG || type == ARM64_OP_REG_MRS || type == ARM64_OP_REG_MSR || type == ARM64_OP_PSTATE || type == ARM64_OP_SYS || type == ARM64_OP_PREFETCH || type == ARM64_OP_BARRIER) + value.setType(Integer.TYPE); + if (type == ARM64_OP_INVALID) + return; + readField("value"); + readField("ext"); + readField("shift"); + readField("vess"); + readField("vas"); + readField("vector_index"); + } + + @Override + public List getFieldOrder() { + return Arrays.asList("vector_index", "vas", "vess", "shift", "ext", "type", "value"); + } + } + + public static class UnionOpInfo extends Capstone.UnionOpInfo { + public int cc; + public byte _update_flags; + public byte _writeback; + public byte op_count; + + public Operand [] op; + + public UnionOpInfo() { + op = new Operand[8]; + } + + public void read() { + readField("cc"); + readField("_update_flags"); + readField("_writeback"); + readField("op_count"); + op = new Operand[op_count]; + if (op_count != 0) + readField("op"); + } + + @Override + public List getFieldOrder() { + return Arrays.asList("cc", "_update_flags", "_writeback", "op_count", "op"); + } + } + + public static class OpInfo extends Capstone.OpInfo { + public int cc; + public boolean updateFlags; + public boolean writeback; + public Operand [] op = null; + + public OpInfo(UnionOpInfo op_info) { + cc = op_info.cc; + updateFlags = (op_info._update_flags > 0); + writeback = (op_info._writeback > 0); + op = op_info.op; + } + } +} diff --git a/app/src/main/java/capstone/Arm64_const.java b/app/src/main/java/capstone/Arm64_const.java new file mode 100644 index 00000000..1c281f70 --- /dev/null +++ b/app/src/main/java/capstone/Arm64_const.java @@ -0,0 +1,1047 @@ +// For Capstone Engine. AUTO-GENERATED FILE, DO NOT EDIT +package capstone; + +public class Arm64_const { + + // ARM64 shift type + + public static final int ARM64_SFT_INVALID = 0; + public static final int ARM64_SFT_LSL = 1; + public static final int ARM64_SFT_MSL = 2; + public static final int ARM64_SFT_LSR = 3; + public static final int ARM64_SFT_ASR = 4; + public static final int ARM64_SFT_ROR = 5; + + // ARM64 extender type + + public static final int ARM64_EXT_INVALID = 0; + public static final int ARM64_EXT_UXTB = 1; + public static final int ARM64_EXT_UXTH = 2; + public static final int ARM64_EXT_UXTW = 3; + public static final int ARM64_EXT_UXTX = 4; + public static final int ARM64_EXT_SXTB = 5; + public static final int ARM64_EXT_SXTH = 6; + public static final int ARM64_EXT_SXTW = 7; + public static final int ARM64_EXT_SXTX = 8; + + // ARM64 condition code + + public static final int ARM64_CC_INVALID = 0; + public static final int ARM64_CC_EQ = 1; + public static final int ARM64_CC_NE = 2; + public static final int ARM64_CC_HS = 3; + public static final int ARM64_CC_LO = 4; + public static final int ARM64_CC_MI = 5; + public static final int ARM64_CC_PL = 6; + public static final int ARM64_CC_VS = 7; + public static final int ARM64_CC_VC = 8; + public static final int ARM64_CC_HI = 9; + public static final int ARM64_CC_LS = 10; + public static final int ARM64_CC_GE = 11; + public static final int ARM64_CC_LT = 12; + public static final int ARM64_CC_GT = 13; + public static final int ARM64_CC_LE = 14; + public static final int ARM64_CC_AL = 15; + public static final int ARM64_CC_NV = 16; + + // System registers + + // System registers for MRS + + public static final int ARM64_SYSREG_INVALID = 0; + public static final int ARM64_SYSREG_MDCCSR_EL0 = 0x9808; + public static final int ARM64_SYSREG_DBGDTRRX_EL0 = 0x9828; + public static final int ARM64_SYSREG_MDRAR_EL1 = 0x8080; + public static final int ARM64_SYSREG_OSLSR_EL1 = 0x808c; + public static final int ARM64_SYSREG_DBGAUTHSTATUS_EL1 = 0x83f6; + public static final int ARM64_SYSREG_PMCEID0_EL0 = 0xdce6; + public static final int ARM64_SYSREG_PMCEID1_EL0 = 0xdce7; + public static final int ARM64_SYSREG_MIDR_EL1 = 0xc000; + public static final int ARM64_SYSREG_CCSIDR_EL1 = 0xc800; + public static final int ARM64_SYSREG_CLIDR_EL1 = 0xc801; + public static final int ARM64_SYSREG_CTR_EL0 = 0xd801; + public static final int ARM64_SYSREG_MPIDR_EL1 = 0xc005; + public static final int ARM64_SYSREG_REVIDR_EL1 = 0xc006; + public static final int ARM64_SYSREG_AIDR_EL1 = 0xc807; + public static final int ARM64_SYSREG_DCZID_EL0 = 0xd807; + public static final int ARM64_SYSREG_ID_PFR0_EL1 = 0xc008; + public static final int ARM64_SYSREG_ID_PFR1_EL1 = 0xc009; + public static final int ARM64_SYSREG_ID_DFR0_EL1 = 0xc00a; + public static final int ARM64_SYSREG_ID_AFR0_EL1 = 0xc00b; + public static final int ARM64_SYSREG_ID_MMFR0_EL1 = 0xc00c; + public static final int ARM64_SYSREG_ID_MMFR1_EL1 = 0xc00d; + public static final int ARM64_SYSREG_ID_MMFR2_EL1 = 0xc00e; + public static final int ARM64_SYSREG_ID_MMFR3_EL1 = 0xc00f; + public static final int ARM64_SYSREG_ID_ISAR0_EL1 = 0xc010; + public static final int ARM64_SYSREG_ID_ISAR1_EL1 = 0xc011; + public static final int ARM64_SYSREG_ID_ISAR2_EL1 = 0xc012; + public static final int ARM64_SYSREG_ID_ISAR3_EL1 = 0xc013; + public static final int ARM64_SYSREG_ID_ISAR4_EL1 = 0xc014; + public static final int ARM64_SYSREG_ID_ISAR5_EL1 = 0xc015; + public static final int ARM64_SYSREG_ID_A64PFR0_EL1 = 0xc020; + public static final int ARM64_SYSREG_ID_A64PFR1_EL1 = 0xc021; + public static final int ARM64_SYSREG_ID_A64DFR0_EL1 = 0xc028; + public static final int ARM64_SYSREG_ID_A64DFR1_EL1 = 0xc029; + public static final int ARM64_SYSREG_ID_A64AFR0_EL1 = 0xc02c; + public static final int ARM64_SYSREG_ID_A64AFR1_EL1 = 0xc02d; + public static final int ARM64_SYSREG_ID_A64ISAR0_EL1 = 0xc030; + public static final int ARM64_SYSREG_ID_A64ISAR1_EL1 = 0xc031; + public static final int ARM64_SYSREG_ID_A64MMFR0_EL1 = 0xc038; + public static final int ARM64_SYSREG_ID_A64MMFR1_EL1 = 0xc039; + public static final int ARM64_SYSREG_MVFR0_EL1 = 0xc018; + public static final int ARM64_SYSREG_MVFR1_EL1 = 0xc019; + public static final int ARM64_SYSREG_MVFR2_EL1 = 0xc01a; + public static final int ARM64_SYSREG_RVBAR_EL1 = 0xc601; + public static final int ARM64_SYSREG_RVBAR_EL2 = 0xe601; + public static final int ARM64_SYSREG_RVBAR_EL3 = 0xf601; + public static final int ARM64_SYSREG_ISR_EL1 = 0xc608; + public static final int ARM64_SYSREG_CNTPCT_EL0 = 0xdf01; + public static final int ARM64_SYSREG_CNTVCT_EL0 = 0xdf02; + public static final int ARM64_SYSREG_TRCSTATR = 0x8818; + public static final int ARM64_SYSREG_TRCIDR8 = 0x8806; + public static final int ARM64_SYSREG_TRCIDR9 = 0x880e; + public static final int ARM64_SYSREG_TRCIDR10 = 0x8816; + public static final int ARM64_SYSREG_TRCIDR11 = 0x881e; + public static final int ARM64_SYSREG_TRCIDR12 = 0x8826; + public static final int ARM64_SYSREG_TRCIDR13 = 0x882e; + public static final int ARM64_SYSREG_TRCIDR0 = 0x8847; + public static final int ARM64_SYSREG_TRCIDR1 = 0x884f; + public static final int ARM64_SYSREG_TRCIDR2 = 0x8857; + public static final int ARM64_SYSREG_TRCIDR3 = 0x885f; + public static final int ARM64_SYSREG_TRCIDR4 = 0x8867; + public static final int ARM64_SYSREG_TRCIDR5 = 0x886f; + public static final int ARM64_SYSREG_TRCIDR6 = 0x8877; + public static final int ARM64_SYSREG_TRCIDR7 = 0x887f; + public static final int ARM64_SYSREG_TRCOSLSR = 0x888c; + public static final int ARM64_SYSREG_TRCPDSR = 0x88ac; + public static final int ARM64_SYSREG_TRCDEVAFF0 = 0x8bd6; + public static final int ARM64_SYSREG_TRCDEVAFF1 = 0x8bde; + public static final int ARM64_SYSREG_TRCLSR = 0x8bee; + public static final int ARM64_SYSREG_TRCAUTHSTATUS = 0x8bf6; + public static final int ARM64_SYSREG_TRCDEVARCH = 0x8bfe; + public static final int ARM64_SYSREG_TRCDEVID = 0x8b97; + public static final int ARM64_SYSREG_TRCDEVTYPE = 0x8b9f; + public static final int ARM64_SYSREG_TRCPIDR4 = 0x8ba7; + public static final int ARM64_SYSREG_TRCPIDR5 = 0x8baf; + public static final int ARM64_SYSREG_TRCPIDR6 = 0x8bb7; + public static final int ARM64_SYSREG_TRCPIDR7 = 0x8bbf; + public static final int ARM64_SYSREG_TRCPIDR0 = 0x8bc7; + public static final int ARM64_SYSREG_TRCPIDR1 = 0x8bcf; + public static final int ARM64_SYSREG_TRCPIDR2 = 0x8bd7; + public static final int ARM64_SYSREG_TRCPIDR3 = 0x8bdf; + public static final int ARM64_SYSREG_TRCCIDR0 = 0x8be7; + public static final int ARM64_SYSREG_TRCCIDR1 = 0x8bef; + public static final int ARM64_SYSREG_TRCCIDR2 = 0x8bf7; + public static final int ARM64_SYSREG_TRCCIDR3 = 0x8bff; + public static final int ARM64_SYSREG_ICC_IAR1_EL1 = 0xc660; + public static final int ARM64_SYSREG_ICC_IAR0_EL1 = 0xc640; + public static final int ARM64_SYSREG_ICC_HPPIR1_EL1 = 0xc662; + public static final int ARM64_SYSREG_ICC_HPPIR0_EL1 = 0xc642; + public static final int ARM64_SYSREG_ICC_RPR_EL1 = 0xc65b; + public static final int ARM64_SYSREG_ICH_VTR_EL2 = 0xe659; + public static final int ARM64_SYSREG_ICH_EISR_EL2 = 0xe65b; + public static final int ARM64_SYSREG_ICH_ELSR_EL2 = 0xe65d; + + // System registers for MSR + public static final int ARM64_SYSREG_DBGDTRTX_EL0 = 0x9828; + public static final int ARM64_SYSREG_OSLAR_EL1 = 0x8084; + public static final int ARM64_SYSREG_PMSWINC_EL0 = 0xdce4; + public static final int ARM64_SYSREG_TRCOSLAR = 0x8884; + public static final int ARM64_SYSREG_TRCLAR = 0x8be6; + public static final int ARM64_SYSREG_ICC_EOIR1_EL1 = 0xc661; + public static final int ARM64_SYSREG_ICC_EOIR0_EL1 = 0xc641; + public static final int ARM64_SYSREG_ICC_DIR_EL1 = 0xc659; + public static final int ARM64_SYSREG_ICC_SGI1R_EL1 = 0xc65d; + public static final int ARM64_SYSREG_ICC_ASGI1R_EL1 = 0xc65e; + public static final int ARM64_SYSREG_ICC_SGI0R_EL1 = 0xc65f; + + // System PState Field (MSR instruction) + + public static final int ARM64_PSTATE_INVALID = 0; + public static final int ARM64_PSTATE_SPSEL = 0x05; + public static final int ARM64_PSTATE_DAIFSET = 0x1e; + public static final int ARM64_PSTATE_DAIFCLR = 0x1f; + + // Vector arrangement specifier (for FloatingPoint/Advanced SIMD insn) + + public static final int ARM64_VAS_INVALID = 0; + public static final int ARM64_VAS_8B = 1; + public static final int ARM64_VAS_16B = 2; + public static final int ARM64_VAS_4H = 3; + public static final int ARM64_VAS_8H = 4; + public static final int ARM64_VAS_2S = 5; + public static final int ARM64_VAS_4S = 6; + public static final int ARM64_VAS_1D = 7; + public static final int ARM64_VAS_2D = 8; + public static final int ARM64_VAS_1Q = 9; + + // Vector element size specifier + + public static final int ARM64_VESS_INVALID = 0; + public static final int ARM64_VESS_B = 1; + public static final int ARM64_VESS_H = 2; + public static final int ARM64_VESS_S = 3; + public static final int ARM64_VESS_D = 4; + + // Memory barrier operands + + public static final int ARM64_BARRIER_INVALID = 0; + public static final int ARM64_BARRIER_OSHLD = 0x1; + public static final int ARM64_BARRIER_OSHST = 0x2; + public static final int ARM64_BARRIER_OSH = 0x3; + public static final int ARM64_BARRIER_NSHLD = 0x5; + public static final int ARM64_BARRIER_NSHST = 0x6; + public static final int ARM64_BARRIER_NSH = 0x7; + public static final int ARM64_BARRIER_ISHLD = 0x9; + public static final int ARM64_BARRIER_ISHST = 0xa; + public static final int ARM64_BARRIER_ISH = 0xb; + public static final int ARM64_BARRIER_LD = 0xd; + public static final int ARM64_BARRIER_ST = 0xe; + public static final int ARM64_BARRIER_SY = 0xf; + + // Operand type for instruction's operands + + public static final int ARM64_OP_INVALID = 0; + public static final int ARM64_OP_REG = 1; + public static final int ARM64_OP_IMM = 2; + public static final int ARM64_OP_MEM = 3; + public static final int ARM64_OP_FP = 4; + public static final int ARM64_OP_CIMM = 64; + public static final int ARM64_OP_REG_MRS = 65; + public static final int ARM64_OP_REG_MSR = 66; + public static final int ARM64_OP_PSTATE = 67; + public static final int ARM64_OP_SYS = 68; + public static final int ARM64_OP_PREFETCH = 69; + public static final int ARM64_OP_BARRIER = 70; + + // TLBI operations + + public static final int ARM64_TLBI_INVALID = 0; + public static final int ARM64_TLBI_VMALLE1IS = 1; + public static final int ARM64_TLBI_VAE1IS = 2; + public static final int ARM64_TLBI_ASIDE1IS = 3; + public static final int ARM64_TLBI_VAAE1IS = 4; + public static final int ARM64_TLBI_VALE1IS = 5; + public static final int ARM64_TLBI_VAALE1IS = 6; + public static final int ARM64_TLBI_ALLE2IS = 7; + public static final int ARM64_TLBI_VAE2IS = 8; + public static final int ARM64_TLBI_ALLE1IS = 9; + public static final int ARM64_TLBI_VALE2IS = 10; + public static final int ARM64_TLBI_VMALLS12E1IS = 11; + public static final int ARM64_TLBI_ALLE3IS = 12; + public static final int ARM64_TLBI_VAE3IS = 13; + public static final int ARM64_TLBI_VALE3IS = 14; + public static final int ARM64_TLBI_IPAS2E1IS = 15; + public static final int ARM64_TLBI_IPAS2LE1IS = 16; + public static final int ARM64_TLBI_IPAS2E1 = 17; + public static final int ARM64_TLBI_IPAS2LE1 = 18; + public static final int ARM64_TLBI_VMALLE1 = 19; + public static final int ARM64_TLBI_VAE1 = 20; + public static final int ARM64_TLBI_ASIDE1 = 21; + public static final int ARM64_TLBI_VAAE1 = 22; + public static final int ARM64_TLBI_VALE1 = 23; + public static final int ARM64_TLBI_VAALE1 = 24; + public static final int ARM64_TLBI_ALLE2 = 25; + public static final int ARM64_TLBI_VAE2 = 26; + public static final int ARM64_TLBI_ALLE1 = 27; + public static final int ARM64_TLBI_VALE2 = 28; + public static final int ARM64_TLBI_VMALLS12E1 = 29; + public static final int ARM64_TLBI_ALLE3 = 30; + public static final int ARM64_TLBI_VAE3 = 31; + public static final int ARM64_TLBI_VALE3 = 32; + + // AT operations + public static final int ARM64_AT_S1E1R = 33; + public static final int ARM64_AT_S1E1W = 34; + public static final int ARM64_AT_S1E0R = 35; + public static final int ARM64_AT_S1E0W = 36; + public static final int ARM64_AT_S1E2R = 37; + public static final int ARM64_AT_S1E2W = 38; + public static final int ARM64_AT_S12E1R = 39; + public static final int ARM64_AT_S12E1W = 40; + public static final int ARM64_AT_S12E0R = 41; + public static final int ARM64_AT_S12E0W = 42; + public static final int ARM64_AT_S1E3R = 43; + public static final int ARM64_AT_S1E3W = 44; + + // DC operations + + public static final int ARM64_DC_INVALID = 0; + public static final int ARM64_DC_ZVA = 1; + public static final int ARM64_DC_IVAC = 2; + public static final int ARM64_DC_ISW = 3; + public static final int ARM64_DC_CVAC = 4; + public static final int ARM64_DC_CSW = 5; + public static final int ARM64_DC_CVAU = 6; + public static final int ARM64_DC_CIVAC = 7; + public static final int ARM64_DC_CISW = 8; + + // IC operations + + public static final int ARM64_IC_INVALID = 0; + public static final int ARM64_IC_IALLUIS = 1; + public static final int ARM64_IC_IALLU = 2; + public static final int ARM64_IC_IVAU = 3; + + // Prefetch operations (PRFM) + + public static final int ARM64_PRFM_INVALID = 0; + public static final int ARM64_PRFM_PLDL1KEEP = 0x00+1; + public static final int ARM64_PRFM_PLDL1STRM = 0x01+1; + public static final int ARM64_PRFM_PLDL2KEEP = 0x02+1; + public static final int ARM64_PRFM_PLDL2STRM = 0x03+1; + public static final int ARM64_PRFM_PLDL3KEEP = 0x04+1; + public static final int ARM64_PRFM_PLDL3STRM = 0x05+1; + public static final int ARM64_PRFM_PLIL1KEEP = 0x08+1; + public static final int ARM64_PRFM_PLIL1STRM = 0x09+1; + public static final int ARM64_PRFM_PLIL2KEEP = 0x0a+1; + public static final int ARM64_PRFM_PLIL2STRM = 0x0b+1; + public static final int ARM64_PRFM_PLIL3KEEP = 0x0c+1; + public static final int ARM64_PRFM_PLIL3STRM = 0x0d+1; + public static final int ARM64_PRFM_PSTL1KEEP = 0x10+1; + public static final int ARM64_PRFM_PSTL1STRM = 0x11+1; + public static final int ARM64_PRFM_PSTL2KEEP = 0x12+1; + public static final int ARM64_PRFM_PSTL2STRM = 0x13+1; + public static final int ARM64_PRFM_PSTL3KEEP = 0x14+1; + public static final int ARM64_PRFM_PSTL3STRM = 0x15+1; + + // ARM64 registers + + public static final int ARM64_REG_INVALID = 0; + public static final int ARM64_REG_X29 = 1; + public static final int ARM64_REG_X30 = 2; + public static final int ARM64_REG_NZCV = 3; + public static final int ARM64_REG_SP = 4; + public static final int ARM64_REG_WSP = 5; + public static final int ARM64_REG_WZR = 6; + public static final int ARM64_REG_XZR = 7; + public static final int ARM64_REG_B0 = 8; + public static final int ARM64_REG_B1 = 9; + public static final int ARM64_REG_B2 = 10; + public static final int ARM64_REG_B3 = 11; + public static final int ARM64_REG_B4 = 12; + public static final int ARM64_REG_B5 = 13; + public static final int ARM64_REG_B6 = 14; + public static final int ARM64_REG_B7 = 15; + public static final int ARM64_REG_B8 = 16; + public static final int ARM64_REG_B9 = 17; + public static final int ARM64_REG_B10 = 18; + public static final int ARM64_REG_B11 = 19; + public static final int ARM64_REG_B12 = 20; + public static final int ARM64_REG_B13 = 21; + public static final int ARM64_REG_B14 = 22; + public static final int ARM64_REG_B15 = 23; + public static final int ARM64_REG_B16 = 24; + public static final int ARM64_REG_B17 = 25; + public static final int ARM64_REG_B18 = 26; + public static final int ARM64_REG_B19 = 27; + public static final int ARM64_REG_B20 = 28; + public static final int ARM64_REG_B21 = 29; + public static final int ARM64_REG_B22 = 30; + public static final int ARM64_REG_B23 = 31; + public static final int ARM64_REG_B24 = 32; + public static final int ARM64_REG_B25 = 33; + public static final int ARM64_REG_B26 = 34; + public static final int ARM64_REG_B27 = 35; + public static final int ARM64_REG_B28 = 36; + public static final int ARM64_REG_B29 = 37; + public static final int ARM64_REG_B30 = 38; + public static final int ARM64_REG_B31 = 39; + public static final int ARM64_REG_D0 = 40; + public static final int ARM64_REG_D1 = 41; + public static final int ARM64_REG_D2 = 42; + public static final int ARM64_REG_D3 = 43; + public static final int ARM64_REG_D4 = 44; + public static final int ARM64_REG_D5 = 45; + public static final int ARM64_REG_D6 = 46; + public static final int ARM64_REG_D7 = 47; + public static final int ARM64_REG_D8 = 48; + public static final int ARM64_REG_D9 = 49; + public static final int ARM64_REG_D10 = 50; + public static final int ARM64_REG_D11 = 51; + public static final int ARM64_REG_D12 = 52; + public static final int ARM64_REG_D13 = 53; + public static final int ARM64_REG_D14 = 54; + public static final int ARM64_REG_D15 = 55; + public static final int ARM64_REG_D16 = 56; + public static final int ARM64_REG_D17 = 57; + public static final int ARM64_REG_D18 = 58; + public static final int ARM64_REG_D19 = 59; + public static final int ARM64_REG_D20 = 60; + public static final int ARM64_REG_D21 = 61; + public static final int ARM64_REG_D22 = 62; + public static final int ARM64_REG_D23 = 63; + public static final int ARM64_REG_D24 = 64; + public static final int ARM64_REG_D25 = 65; + public static final int ARM64_REG_D26 = 66; + public static final int ARM64_REG_D27 = 67; + public static final int ARM64_REG_D28 = 68; + public static final int ARM64_REG_D29 = 69; + public static final int ARM64_REG_D30 = 70; + public static final int ARM64_REG_D31 = 71; + public static final int ARM64_REG_H0 = 72; + public static final int ARM64_REG_H1 = 73; + public static final int ARM64_REG_H2 = 74; + public static final int ARM64_REG_H3 = 75; + public static final int ARM64_REG_H4 = 76; + public static final int ARM64_REG_H5 = 77; + public static final int ARM64_REG_H6 = 78; + public static final int ARM64_REG_H7 = 79; + public static final int ARM64_REG_H8 = 80; + public static final int ARM64_REG_H9 = 81; + public static final int ARM64_REG_H10 = 82; + public static final int ARM64_REG_H11 = 83; + public static final int ARM64_REG_H12 = 84; + public static final int ARM64_REG_H13 = 85; + public static final int ARM64_REG_H14 = 86; + public static final int ARM64_REG_H15 = 87; + public static final int ARM64_REG_H16 = 88; + public static final int ARM64_REG_H17 = 89; + public static final int ARM64_REG_H18 = 90; + public static final int ARM64_REG_H19 = 91; + public static final int ARM64_REG_H20 = 92; + public static final int ARM64_REG_H21 = 93; + public static final int ARM64_REG_H22 = 94; + public static final int ARM64_REG_H23 = 95; + public static final int ARM64_REG_H24 = 96; + public static final int ARM64_REG_H25 = 97; + public static final int ARM64_REG_H26 = 98; + public static final int ARM64_REG_H27 = 99; + public static final int ARM64_REG_H28 = 100; + public static final int ARM64_REG_H29 = 101; + public static final int ARM64_REG_H30 = 102; + public static final int ARM64_REG_H31 = 103; + public static final int ARM64_REG_Q0 = 104; + public static final int ARM64_REG_Q1 = 105; + public static final int ARM64_REG_Q2 = 106; + public static final int ARM64_REG_Q3 = 107; + public static final int ARM64_REG_Q4 = 108; + public static final int ARM64_REG_Q5 = 109; + public static final int ARM64_REG_Q6 = 110; + public static final int ARM64_REG_Q7 = 111; + public static final int ARM64_REG_Q8 = 112; + public static final int ARM64_REG_Q9 = 113; + public static final int ARM64_REG_Q10 = 114; + public static final int ARM64_REG_Q11 = 115; + public static final int ARM64_REG_Q12 = 116; + public static final int ARM64_REG_Q13 = 117; + public static final int ARM64_REG_Q14 = 118; + public static final int ARM64_REG_Q15 = 119; + public static final int ARM64_REG_Q16 = 120; + public static final int ARM64_REG_Q17 = 121; + public static final int ARM64_REG_Q18 = 122; + public static final int ARM64_REG_Q19 = 123; + public static final int ARM64_REG_Q20 = 124; + public static final int ARM64_REG_Q21 = 125; + public static final int ARM64_REG_Q22 = 126; + public static final int ARM64_REG_Q23 = 127; + public static final int ARM64_REG_Q24 = 128; + public static final int ARM64_REG_Q25 = 129; + public static final int ARM64_REG_Q26 = 130; + public static final int ARM64_REG_Q27 = 131; + public static final int ARM64_REG_Q28 = 132; + public static final int ARM64_REG_Q29 = 133; + public static final int ARM64_REG_Q30 = 134; + public static final int ARM64_REG_Q31 = 135; + public static final int ARM64_REG_S0 = 136; + public static final int ARM64_REG_S1 = 137; + public static final int ARM64_REG_S2 = 138; + public static final int ARM64_REG_S3 = 139; + public static final int ARM64_REG_S4 = 140; + public static final int ARM64_REG_S5 = 141; + public static final int ARM64_REG_S6 = 142; + public static final int ARM64_REG_S7 = 143; + public static final int ARM64_REG_S8 = 144; + public static final int ARM64_REG_S9 = 145; + public static final int ARM64_REG_S10 = 146; + public static final int ARM64_REG_S11 = 147; + public static final int ARM64_REG_S12 = 148; + public static final int ARM64_REG_S13 = 149; + public static final int ARM64_REG_S14 = 150; + public static final int ARM64_REG_S15 = 151; + public static final int ARM64_REG_S16 = 152; + public static final int ARM64_REG_S17 = 153; + public static final int ARM64_REG_S18 = 154; + public static final int ARM64_REG_S19 = 155; + public static final int ARM64_REG_S20 = 156; + public static final int ARM64_REG_S21 = 157; + public static final int ARM64_REG_S22 = 158; + public static final int ARM64_REG_S23 = 159; + public static final int ARM64_REG_S24 = 160; + public static final int ARM64_REG_S25 = 161; + public static final int ARM64_REG_S26 = 162; + public static final int ARM64_REG_S27 = 163; + public static final int ARM64_REG_S28 = 164; + public static final int ARM64_REG_S29 = 165; + public static final int ARM64_REG_S30 = 166; + public static final int ARM64_REG_S31 = 167; + public static final int ARM64_REG_W0 = 168; + public static final int ARM64_REG_W1 = 169; + public static final int ARM64_REG_W2 = 170; + public static final int ARM64_REG_W3 = 171; + public static final int ARM64_REG_W4 = 172; + public static final int ARM64_REG_W5 = 173; + public static final int ARM64_REG_W6 = 174; + public static final int ARM64_REG_W7 = 175; + public static final int ARM64_REG_W8 = 176; + public static final int ARM64_REG_W9 = 177; + public static final int ARM64_REG_W10 = 178; + public static final int ARM64_REG_W11 = 179; + public static final int ARM64_REG_W12 = 180; + public static final int ARM64_REG_W13 = 181; + public static final int ARM64_REG_W14 = 182; + public static final int ARM64_REG_W15 = 183; + public static final int ARM64_REG_W16 = 184; + public static final int ARM64_REG_W17 = 185; + public static final int ARM64_REG_W18 = 186; + public static final int ARM64_REG_W19 = 187; + public static final int ARM64_REG_W20 = 188; + public static final int ARM64_REG_W21 = 189; + public static final int ARM64_REG_W22 = 190; + public static final int ARM64_REG_W23 = 191; + public static final int ARM64_REG_W24 = 192; + public static final int ARM64_REG_W25 = 193; + public static final int ARM64_REG_W26 = 194; + public static final int ARM64_REG_W27 = 195; + public static final int ARM64_REG_W28 = 196; + public static final int ARM64_REG_W29 = 197; + public static final int ARM64_REG_W30 = 198; + public static final int ARM64_REG_X0 = 199; + public static final int ARM64_REG_X1 = 200; + public static final int ARM64_REG_X2 = 201; + public static final int ARM64_REG_X3 = 202; + public static final int ARM64_REG_X4 = 203; + public static final int ARM64_REG_X5 = 204; + public static final int ARM64_REG_X6 = 205; + public static final int ARM64_REG_X7 = 206; + public static final int ARM64_REG_X8 = 207; + public static final int ARM64_REG_X9 = 208; + public static final int ARM64_REG_X10 = 209; + public static final int ARM64_REG_X11 = 210; + public static final int ARM64_REG_X12 = 211; + public static final int ARM64_REG_X13 = 212; + public static final int ARM64_REG_X14 = 213; + public static final int ARM64_REG_X15 = 214; + public static final int ARM64_REG_X16 = 215; + public static final int ARM64_REG_X17 = 216; + public static final int ARM64_REG_X18 = 217; + public static final int ARM64_REG_X19 = 218; + public static final int ARM64_REG_X20 = 219; + public static final int ARM64_REG_X21 = 220; + public static final int ARM64_REG_X22 = 221; + public static final int ARM64_REG_X23 = 222; + public static final int ARM64_REG_X24 = 223; + public static final int ARM64_REG_X25 = 224; + public static final int ARM64_REG_X26 = 225; + public static final int ARM64_REG_X27 = 226; + public static final int ARM64_REG_X28 = 227; + public static final int ARM64_REG_V0 = 228; + public static final int ARM64_REG_V1 = 229; + public static final int ARM64_REG_V2 = 230; + public static final int ARM64_REG_V3 = 231; + public static final int ARM64_REG_V4 = 232; + public static final int ARM64_REG_V5 = 233; + public static final int ARM64_REG_V6 = 234; + public static final int ARM64_REG_V7 = 235; + public static final int ARM64_REG_V8 = 236; + public static final int ARM64_REG_V9 = 237; + public static final int ARM64_REG_V10 = 238; + public static final int ARM64_REG_V11 = 239; + public static final int ARM64_REG_V12 = 240; + public static final int ARM64_REG_V13 = 241; + public static final int ARM64_REG_V14 = 242; + public static final int ARM64_REG_V15 = 243; + public static final int ARM64_REG_V16 = 244; + public static final int ARM64_REG_V17 = 245; + public static final int ARM64_REG_V18 = 246; + public static final int ARM64_REG_V19 = 247; + public static final int ARM64_REG_V20 = 248; + public static final int ARM64_REG_V21 = 249; + public static final int ARM64_REG_V22 = 250; + public static final int ARM64_REG_V23 = 251; + public static final int ARM64_REG_V24 = 252; + public static final int ARM64_REG_V25 = 253; + public static final int ARM64_REG_V26 = 254; + public static final int ARM64_REG_V27 = 255; + public static final int ARM64_REG_V28 = 256; + public static final int ARM64_REG_V29 = 257; + public static final int ARM64_REG_V30 = 258; + public static final int ARM64_REG_V31 = 259; + public static final int ARM64_REG_ENDING = 260; + + // alias registers + public static final int ARM64_REG_IP0 = ARM64_REG_X16; + public static final int ARM64_REG_IP1 = ARM64_REG_X17; + public static final int ARM64_REG_FP = ARM64_REG_X29; + public static final int ARM64_REG_LR = ARM64_REG_X30; + + // ARM64 instruction + + public static final int ARM64_INS_INVALID = 0; + public static final int ARM64_INS_ABS = 1; + public static final int ARM64_INS_ADC = 2; + public static final int ARM64_INS_ADDHN = 3; + public static final int ARM64_INS_ADDHN2 = 4; + public static final int ARM64_INS_ADDP = 5; + public static final int ARM64_INS_ADD = 6; + public static final int ARM64_INS_ADDV = 7; + public static final int ARM64_INS_ADR = 8; + public static final int ARM64_INS_ADRP = 9; + public static final int ARM64_INS_AESD = 10; + public static final int ARM64_INS_AESE = 11; + public static final int ARM64_INS_AESIMC = 12; + public static final int ARM64_INS_AESMC = 13; + public static final int ARM64_INS_AND = 14; + public static final int ARM64_INS_ASR = 15; + public static final int ARM64_INS_B = 16; + public static final int ARM64_INS_BFM = 17; + public static final int ARM64_INS_BIC = 18; + public static final int ARM64_INS_BIF = 19; + public static final int ARM64_INS_BIT = 20; + public static final int ARM64_INS_BL = 21; + public static final int ARM64_INS_BLR = 22; + public static final int ARM64_INS_BR = 23; + public static final int ARM64_INS_BRK = 24; + public static final int ARM64_INS_BSL = 25; + public static final int ARM64_INS_CBNZ = 26; + public static final int ARM64_INS_CBZ = 27; + public static final int ARM64_INS_CCMN = 28; + public static final int ARM64_INS_CCMP = 29; + public static final int ARM64_INS_CLREX = 30; + public static final int ARM64_INS_CLS = 31; + public static final int ARM64_INS_CLZ = 32; + public static final int ARM64_INS_CMEQ = 33; + public static final int ARM64_INS_CMGE = 34; + public static final int ARM64_INS_CMGT = 35; + public static final int ARM64_INS_CMHI = 36; + public static final int ARM64_INS_CMHS = 37; + public static final int ARM64_INS_CMLE = 38; + public static final int ARM64_INS_CMLT = 39; + public static final int ARM64_INS_CMTST = 40; + public static final int ARM64_INS_CNT = 41; + public static final int ARM64_INS_MOV = 42; + public static final int ARM64_INS_CRC32B = 43; + public static final int ARM64_INS_CRC32CB = 44; + public static final int ARM64_INS_CRC32CH = 45; + public static final int ARM64_INS_CRC32CW = 46; + public static final int ARM64_INS_CRC32CX = 47; + public static final int ARM64_INS_CRC32H = 48; + public static final int ARM64_INS_CRC32W = 49; + public static final int ARM64_INS_CRC32X = 50; + public static final int ARM64_INS_CSEL = 51; + public static final int ARM64_INS_CSINC = 52; + public static final int ARM64_INS_CSINV = 53; + public static final int ARM64_INS_CSNEG = 54; + public static final int ARM64_INS_DCPS1 = 55; + public static final int ARM64_INS_DCPS2 = 56; + public static final int ARM64_INS_DCPS3 = 57; + public static final int ARM64_INS_DMB = 58; + public static final int ARM64_INS_DRPS = 59; + public static final int ARM64_INS_DSB = 60; + public static final int ARM64_INS_DUP = 61; + public static final int ARM64_INS_EON = 62; + public static final int ARM64_INS_EOR = 63; + public static final int ARM64_INS_ERET = 64; + public static final int ARM64_INS_EXTR = 65; + public static final int ARM64_INS_EXT = 66; + public static final int ARM64_INS_FABD = 67; + public static final int ARM64_INS_FABS = 68; + public static final int ARM64_INS_FACGE = 69; + public static final int ARM64_INS_FACGT = 70; + public static final int ARM64_INS_FADD = 71; + public static final int ARM64_INS_FADDP = 72; + public static final int ARM64_INS_FCCMP = 73; + public static final int ARM64_INS_FCCMPE = 74; + public static final int ARM64_INS_FCMEQ = 75; + public static final int ARM64_INS_FCMGE = 76; + public static final int ARM64_INS_FCMGT = 77; + public static final int ARM64_INS_FCMLE = 78; + public static final int ARM64_INS_FCMLT = 79; + public static final int ARM64_INS_FCMP = 80; + public static final int ARM64_INS_FCMPE = 81; + public static final int ARM64_INS_FCSEL = 82; + public static final int ARM64_INS_FCVTAS = 83; + public static final int ARM64_INS_FCVTAU = 84; + public static final int ARM64_INS_FCVT = 85; + public static final int ARM64_INS_FCVTL = 86; + public static final int ARM64_INS_FCVTL2 = 87; + public static final int ARM64_INS_FCVTMS = 88; + public static final int ARM64_INS_FCVTMU = 89; + public static final int ARM64_INS_FCVTNS = 90; + public static final int ARM64_INS_FCVTNU = 91; + public static final int ARM64_INS_FCVTN = 92; + public static final int ARM64_INS_FCVTN2 = 93; + public static final int ARM64_INS_FCVTPS = 94; + public static final int ARM64_INS_FCVTPU = 95; + public static final int ARM64_INS_FCVTXN = 96; + public static final int ARM64_INS_FCVTXN2 = 97; + public static final int ARM64_INS_FCVTZS = 98; + public static final int ARM64_INS_FCVTZU = 99; + public static final int ARM64_INS_FDIV = 100; + public static final int ARM64_INS_FMADD = 101; + public static final int ARM64_INS_FMAX = 102; + public static final int ARM64_INS_FMAXNM = 103; + public static final int ARM64_INS_FMAXNMP = 104; + public static final int ARM64_INS_FMAXNMV = 105; + public static final int ARM64_INS_FMAXP = 106; + public static final int ARM64_INS_FMAXV = 107; + public static final int ARM64_INS_FMIN = 108; + public static final int ARM64_INS_FMINNM = 109; + public static final int ARM64_INS_FMINNMP = 110; + public static final int ARM64_INS_FMINNMV = 111; + public static final int ARM64_INS_FMINP = 112; + public static final int ARM64_INS_FMINV = 113; + public static final int ARM64_INS_FMLA = 114; + public static final int ARM64_INS_FMLS = 115; + public static final int ARM64_INS_FMOV = 116; + public static final int ARM64_INS_FMSUB = 117; + public static final int ARM64_INS_FMUL = 118; + public static final int ARM64_INS_FMULX = 119; + public static final int ARM64_INS_FNEG = 120; + public static final int ARM64_INS_FNMADD = 121; + public static final int ARM64_INS_FNMSUB = 122; + public static final int ARM64_INS_FNMUL = 123; + public static final int ARM64_INS_FRECPE = 124; + public static final int ARM64_INS_FRECPS = 125; + public static final int ARM64_INS_FRECPX = 126; + public static final int ARM64_INS_FRINTA = 127; + public static final int ARM64_INS_FRINTI = 128; + public static final int ARM64_INS_FRINTM = 129; + public static final int ARM64_INS_FRINTN = 130; + public static final int ARM64_INS_FRINTP = 131; + public static final int ARM64_INS_FRINTX = 132; + public static final int ARM64_INS_FRINTZ = 133; + public static final int ARM64_INS_FRSQRTE = 134; + public static final int ARM64_INS_FRSQRTS = 135; + public static final int ARM64_INS_FSQRT = 136; + public static final int ARM64_INS_FSUB = 137; + public static final int ARM64_INS_HINT = 138; + public static final int ARM64_INS_HLT = 139; + public static final int ARM64_INS_HVC = 140; + public static final int ARM64_INS_INS = 141; + public static final int ARM64_INS_ISB = 142; + public static final int ARM64_INS_LD1 = 143; + public static final int ARM64_INS_LD1R = 144; + public static final int ARM64_INS_LD2R = 145; + public static final int ARM64_INS_LD2 = 146; + public static final int ARM64_INS_LD3R = 147; + public static final int ARM64_INS_LD3 = 148; + public static final int ARM64_INS_LD4 = 149; + public static final int ARM64_INS_LD4R = 150; + public static final int ARM64_INS_LDARB = 151; + public static final int ARM64_INS_LDARH = 152; + public static final int ARM64_INS_LDAR = 153; + public static final int ARM64_INS_LDAXP = 154; + public static final int ARM64_INS_LDAXRB = 155; + public static final int ARM64_INS_LDAXRH = 156; + public static final int ARM64_INS_LDAXR = 157; + public static final int ARM64_INS_LDNP = 158; + public static final int ARM64_INS_LDP = 159; + public static final int ARM64_INS_LDPSW = 160; + public static final int ARM64_INS_LDRB = 161; + public static final int ARM64_INS_LDR = 162; + public static final int ARM64_INS_LDRH = 163; + public static final int ARM64_INS_LDRSB = 164; + public static final int ARM64_INS_LDRSH = 165; + public static final int ARM64_INS_LDRSW = 166; + public static final int ARM64_INS_LDTRB = 167; + public static final int ARM64_INS_LDTRH = 168; + public static final int ARM64_INS_LDTRSB = 169; + public static final int ARM64_INS_LDTRSH = 170; + public static final int ARM64_INS_LDTRSW = 171; + public static final int ARM64_INS_LDTR = 172; + public static final int ARM64_INS_LDURB = 173; + public static final int ARM64_INS_LDUR = 174; + public static final int ARM64_INS_LDURH = 175; + public static final int ARM64_INS_LDURSB = 176; + public static final int ARM64_INS_LDURSH = 177; + public static final int ARM64_INS_LDURSW = 178; + public static final int ARM64_INS_LDXP = 179; + public static final int ARM64_INS_LDXRB = 180; + public static final int ARM64_INS_LDXRH = 181; + public static final int ARM64_INS_LDXR = 182; + public static final int ARM64_INS_LSL = 183; + public static final int ARM64_INS_LSR = 184; + public static final int ARM64_INS_MADD = 185; + public static final int ARM64_INS_MLA = 186; + public static final int ARM64_INS_MLS = 187; + public static final int ARM64_INS_MOVI = 188; + public static final int ARM64_INS_MOVK = 189; + public static final int ARM64_INS_MOVN = 190; + public static final int ARM64_INS_MOVZ = 191; + public static final int ARM64_INS_MRS = 192; + public static final int ARM64_INS_MSR = 193; + public static final int ARM64_INS_MSUB = 194; + public static final int ARM64_INS_MUL = 195; + public static final int ARM64_INS_MVNI = 196; + public static final int ARM64_INS_NEG = 197; + public static final int ARM64_INS_NOT = 198; + public static final int ARM64_INS_ORN = 199; + public static final int ARM64_INS_ORR = 200; + public static final int ARM64_INS_PMULL2 = 201; + public static final int ARM64_INS_PMULL = 202; + public static final int ARM64_INS_PMUL = 203; + public static final int ARM64_INS_PRFM = 204; + public static final int ARM64_INS_PRFUM = 205; + public static final int ARM64_INS_RADDHN = 206; + public static final int ARM64_INS_RADDHN2 = 207; + public static final int ARM64_INS_RBIT = 208; + public static final int ARM64_INS_RET = 209; + public static final int ARM64_INS_REV16 = 210; + public static final int ARM64_INS_REV32 = 211; + public static final int ARM64_INS_REV64 = 212; + public static final int ARM64_INS_REV = 213; + public static final int ARM64_INS_ROR = 214; + public static final int ARM64_INS_RSHRN2 = 215; + public static final int ARM64_INS_RSHRN = 216; + public static final int ARM64_INS_RSUBHN = 217; + public static final int ARM64_INS_RSUBHN2 = 218; + public static final int ARM64_INS_SABAL2 = 219; + public static final int ARM64_INS_SABAL = 220; + public static final int ARM64_INS_SABA = 221; + public static final int ARM64_INS_SABDL2 = 222; + public static final int ARM64_INS_SABDL = 223; + public static final int ARM64_INS_SABD = 224; + public static final int ARM64_INS_SADALP = 225; + public static final int ARM64_INS_SADDLP = 226; + public static final int ARM64_INS_SADDLV = 227; + public static final int ARM64_INS_SADDL2 = 228; + public static final int ARM64_INS_SADDL = 229; + public static final int ARM64_INS_SADDW2 = 230; + public static final int ARM64_INS_SADDW = 231; + public static final int ARM64_INS_SBC = 232; + public static final int ARM64_INS_SBFM = 233; + public static final int ARM64_INS_SCVTF = 234; + public static final int ARM64_INS_SDIV = 235; + public static final int ARM64_INS_SHA1C = 236; + public static final int ARM64_INS_SHA1H = 237; + public static final int ARM64_INS_SHA1M = 238; + public static final int ARM64_INS_SHA1P = 239; + public static final int ARM64_INS_SHA1SU0 = 240; + public static final int ARM64_INS_SHA1SU1 = 241; + public static final int ARM64_INS_SHA256H2 = 242; + public static final int ARM64_INS_SHA256H = 243; + public static final int ARM64_INS_SHA256SU0 = 244; + public static final int ARM64_INS_SHA256SU1 = 245; + public static final int ARM64_INS_SHADD = 246; + public static final int ARM64_INS_SHLL2 = 247; + public static final int ARM64_INS_SHLL = 248; + public static final int ARM64_INS_SHL = 249; + public static final int ARM64_INS_SHRN2 = 250; + public static final int ARM64_INS_SHRN = 251; + public static final int ARM64_INS_SHSUB = 252; + public static final int ARM64_INS_SLI = 253; + public static final int ARM64_INS_SMADDL = 254; + public static final int ARM64_INS_SMAXP = 255; + public static final int ARM64_INS_SMAXV = 256; + public static final int ARM64_INS_SMAX = 257; + public static final int ARM64_INS_SMC = 258; + public static final int ARM64_INS_SMINP = 259; + public static final int ARM64_INS_SMINV = 260; + public static final int ARM64_INS_SMIN = 261; + public static final int ARM64_INS_SMLAL2 = 262; + public static final int ARM64_INS_SMLAL = 263; + public static final int ARM64_INS_SMLSL2 = 264; + public static final int ARM64_INS_SMLSL = 265; + public static final int ARM64_INS_SMOV = 266; + public static final int ARM64_INS_SMSUBL = 267; + public static final int ARM64_INS_SMULH = 268; + public static final int ARM64_INS_SMULL2 = 269; + public static final int ARM64_INS_SMULL = 270; + public static final int ARM64_INS_SQABS = 271; + public static final int ARM64_INS_SQADD = 272; + public static final int ARM64_INS_SQDMLAL = 273; + public static final int ARM64_INS_SQDMLAL2 = 274; + public static final int ARM64_INS_SQDMLSL = 275; + public static final int ARM64_INS_SQDMLSL2 = 276; + public static final int ARM64_INS_SQDMULH = 277; + public static final int ARM64_INS_SQDMULL = 278; + public static final int ARM64_INS_SQDMULL2 = 279; + public static final int ARM64_INS_SQNEG = 280; + public static final int ARM64_INS_SQRDMULH = 281; + public static final int ARM64_INS_SQRSHL = 282; + public static final int ARM64_INS_SQRSHRN = 283; + public static final int ARM64_INS_SQRSHRN2 = 284; + public static final int ARM64_INS_SQRSHRUN = 285; + public static final int ARM64_INS_SQRSHRUN2 = 286; + public static final int ARM64_INS_SQSHLU = 287; + public static final int ARM64_INS_SQSHL = 288; + public static final int ARM64_INS_SQSHRN = 289; + public static final int ARM64_INS_SQSHRN2 = 290; + public static final int ARM64_INS_SQSHRUN = 291; + public static final int ARM64_INS_SQSHRUN2 = 292; + public static final int ARM64_INS_SQSUB = 293; + public static final int ARM64_INS_SQXTN2 = 294; + public static final int ARM64_INS_SQXTN = 295; + public static final int ARM64_INS_SQXTUN2 = 296; + public static final int ARM64_INS_SQXTUN = 297; + public static final int ARM64_INS_SRHADD = 298; + public static final int ARM64_INS_SRI = 299; + public static final int ARM64_INS_SRSHL = 300; + public static final int ARM64_INS_SRSHR = 301; + public static final int ARM64_INS_SRSRA = 302; + public static final int ARM64_INS_SSHLL2 = 303; + public static final int ARM64_INS_SSHLL = 304; + public static final int ARM64_INS_SSHL = 305; + public static final int ARM64_INS_SSHR = 306; + public static final int ARM64_INS_SSRA = 307; + public static final int ARM64_INS_SSUBL2 = 308; + public static final int ARM64_INS_SSUBL = 309; + public static final int ARM64_INS_SSUBW2 = 310; + public static final int ARM64_INS_SSUBW = 311; + public static final int ARM64_INS_ST1 = 312; + public static final int ARM64_INS_ST2 = 313; + public static final int ARM64_INS_ST3 = 314; + public static final int ARM64_INS_ST4 = 315; + public static final int ARM64_INS_STLRB = 316; + public static final int ARM64_INS_STLRH = 317; + public static final int ARM64_INS_STLR = 318; + public static final int ARM64_INS_STLXP = 319; + public static final int ARM64_INS_STLXRB = 320; + public static final int ARM64_INS_STLXRH = 321; + public static final int ARM64_INS_STLXR = 322; + public static final int ARM64_INS_STNP = 323; + public static final int ARM64_INS_STP = 324; + public static final int ARM64_INS_STRB = 325; + public static final int ARM64_INS_STR = 326; + public static final int ARM64_INS_STRH = 327; + public static final int ARM64_INS_STTRB = 328; + public static final int ARM64_INS_STTRH = 329; + public static final int ARM64_INS_STTR = 330; + public static final int ARM64_INS_STURB = 331; + public static final int ARM64_INS_STUR = 332; + public static final int ARM64_INS_STURH = 333; + public static final int ARM64_INS_STXP = 334; + public static final int ARM64_INS_STXRB = 335; + public static final int ARM64_INS_STXRH = 336; + public static final int ARM64_INS_STXR = 337; + public static final int ARM64_INS_SUBHN = 338; + public static final int ARM64_INS_SUBHN2 = 339; + public static final int ARM64_INS_SUB = 340; + public static final int ARM64_INS_SUQADD = 341; + public static final int ARM64_INS_SVC = 342; + public static final int ARM64_INS_SYSL = 343; + public static final int ARM64_INS_SYS = 344; + public static final int ARM64_INS_TBL = 345; + public static final int ARM64_INS_TBNZ = 346; + public static final int ARM64_INS_TBX = 347; + public static final int ARM64_INS_TBZ = 348; + public static final int ARM64_INS_TRN1 = 349; + public static final int ARM64_INS_TRN2 = 350; + public static final int ARM64_INS_UABAL2 = 351; + public static final int ARM64_INS_UABAL = 352; + public static final int ARM64_INS_UABA = 353; + public static final int ARM64_INS_UABDL2 = 354; + public static final int ARM64_INS_UABDL = 355; + public static final int ARM64_INS_UABD = 356; + public static final int ARM64_INS_UADALP = 357; + public static final int ARM64_INS_UADDLP = 358; + public static final int ARM64_INS_UADDLV = 359; + public static final int ARM64_INS_UADDL2 = 360; + public static final int ARM64_INS_UADDL = 361; + public static final int ARM64_INS_UADDW2 = 362; + public static final int ARM64_INS_UADDW = 363; + public static final int ARM64_INS_UBFM = 364; + public static final int ARM64_INS_UCVTF = 365; + public static final int ARM64_INS_UDIV = 366; + public static final int ARM64_INS_UHADD = 367; + public static final int ARM64_INS_UHSUB = 368; + public static final int ARM64_INS_UMADDL = 369; + public static final int ARM64_INS_UMAXP = 370; + public static final int ARM64_INS_UMAXV = 371; + public static final int ARM64_INS_UMAX = 372; + public static final int ARM64_INS_UMINP = 373; + public static final int ARM64_INS_UMINV = 374; + public static final int ARM64_INS_UMIN = 375; + public static final int ARM64_INS_UMLAL2 = 376; + public static final int ARM64_INS_UMLAL = 377; + public static final int ARM64_INS_UMLSL2 = 378; + public static final int ARM64_INS_UMLSL = 379; + public static final int ARM64_INS_UMOV = 380; + public static final int ARM64_INS_UMSUBL = 381; + public static final int ARM64_INS_UMULH = 382; + public static final int ARM64_INS_UMULL2 = 383; + public static final int ARM64_INS_UMULL = 384; + public static final int ARM64_INS_UQADD = 385; + public static final int ARM64_INS_UQRSHL = 386; + public static final int ARM64_INS_UQRSHRN = 387; + public static final int ARM64_INS_UQRSHRN2 = 388; + public static final int ARM64_INS_UQSHL = 389; + public static final int ARM64_INS_UQSHRN = 390; + public static final int ARM64_INS_UQSHRN2 = 391; + public static final int ARM64_INS_UQSUB = 392; + public static final int ARM64_INS_UQXTN2 = 393; + public static final int ARM64_INS_UQXTN = 394; + public static final int ARM64_INS_URECPE = 395; + public static final int ARM64_INS_URHADD = 396; + public static final int ARM64_INS_URSHL = 397; + public static final int ARM64_INS_URSHR = 398; + public static final int ARM64_INS_URSQRTE = 399; + public static final int ARM64_INS_URSRA = 400; + public static final int ARM64_INS_USHLL2 = 401; + public static final int ARM64_INS_USHLL = 402; + public static final int ARM64_INS_USHL = 403; + public static final int ARM64_INS_USHR = 404; + public static final int ARM64_INS_USQADD = 405; + public static final int ARM64_INS_USRA = 406; + public static final int ARM64_INS_USUBL2 = 407; + public static final int ARM64_INS_USUBL = 408; + public static final int ARM64_INS_USUBW2 = 409; + public static final int ARM64_INS_USUBW = 410; + public static final int ARM64_INS_UZP1 = 411; + public static final int ARM64_INS_UZP2 = 412; + public static final int ARM64_INS_XTN2 = 413; + public static final int ARM64_INS_XTN = 414; + public static final int ARM64_INS_ZIP1 = 415; + public static final int ARM64_INS_ZIP2 = 416; + public static final int ARM64_INS_MNEG = 417; + public static final int ARM64_INS_UMNEGL = 418; + public static final int ARM64_INS_SMNEGL = 419; + public static final int ARM64_INS_NOP = 420; + public static final int ARM64_INS_YIELD = 421; + public static final int ARM64_INS_WFE = 422; + public static final int ARM64_INS_WFI = 423; + public static final int ARM64_INS_SEV = 424; + public static final int ARM64_INS_SEVL = 425; + public static final int ARM64_INS_NGC = 426; + public static final int ARM64_INS_SBFIZ = 427; + public static final int ARM64_INS_UBFIZ = 428; + public static final int ARM64_INS_SBFX = 429; + public static final int ARM64_INS_UBFX = 430; + public static final int ARM64_INS_BFI = 431; + public static final int ARM64_INS_BFXIL = 432; + public static final int ARM64_INS_CMN = 433; + public static final int ARM64_INS_MVN = 434; + public static final int ARM64_INS_TST = 435; + public static final int ARM64_INS_CSET = 436; + public static final int ARM64_INS_CINC = 437; + public static final int ARM64_INS_CSETM = 438; + public static final int ARM64_INS_CINV = 439; + public static final int ARM64_INS_CNEG = 440; + public static final int ARM64_INS_SXTB = 441; + public static final int ARM64_INS_SXTH = 442; + public static final int ARM64_INS_SXTW = 443; + public static final int ARM64_INS_CMP = 444; + public static final int ARM64_INS_UXTB = 445; + public static final int ARM64_INS_UXTH = 446; + public static final int ARM64_INS_UXTW = 447; + public static final int ARM64_INS_IC = 448; + public static final int ARM64_INS_DC = 449; + public static final int ARM64_INS_AT = 450; + public static final int ARM64_INS_TLBI = 451; + public static final int ARM64_INS_ENDING = 452; + + // Group of ARM64 instructions + + public static final int ARM64_GRP_INVALID = 0; + + // Generic groups + public static final int ARM64_GRP_JUMP = 1; + + // Architecture-specific groups + public static final int ARM64_GRP_CRYPTO = 128; + public static final int ARM64_GRP_FPARMV8 = 129; + public static final int ARM64_GRP_NEON = 130; + public static final int ARM64_GRP_CRC = 131; + public static final int ARM64_GRP_ENDING = 132; +} \ No newline at end of file diff --git a/app/src/main/java/capstone/Arm_const.java b/app/src/main/java/capstone/Arm_const.java new file mode 100644 index 00000000..1574cb85 --- /dev/null +++ b/app/src/main/java/capstone/Arm_const.java @@ -0,0 +1,798 @@ +// For Capstone Engine. AUTO-GENERATED FILE, DO NOT EDIT +package capstone; + +import android.util.*; +import java.lang.reflect.*; + +public class Arm_const + { + + // ARM shift type + + public static final int ARM_SFT_INVALID = 0; + public static final int ARM_SFT_ASR = 1; + public static final int ARM_SFT_LSL = 2; + public static final int ARM_SFT_LSR = 3; + public static final int ARM_SFT_ROR = 4; + public static final int ARM_SFT_RRX = 5; + public static final int ARM_SFT_ASR_REG = 6; + public static final int ARM_SFT_LSL_REG = 7; + public static final int ARM_SFT_LSR_REG = 8; + public static final int ARM_SFT_ROR_REG = 9; + public static final int ARM_SFT_RRX_REG = 10; + + // ARM condition code + + public static final int ARM_CC_INVALID = 0; + public static final int ARM_CC_EQ = 1; + public static final int ARM_CC_NE = 2; + public static final int ARM_CC_HS = 3; + public static final int ARM_CC_LO = 4; + public static final int ARM_CC_MI = 5; + public static final int ARM_CC_PL = 6; + public static final int ARM_CC_VS = 7; + public static final int ARM_CC_VC = 8; + public static final int ARM_CC_HI = 9; + public static final int ARM_CC_LS = 10; + public static final int ARM_CC_GE = 11; + public static final int ARM_CC_LT = 12; + public static final int ARM_CC_GT = 13; + public static final int ARM_CC_LE = 14; + public static final int ARM_CC_AL = 15; + + public static String getCCName(int cc) + { + Class clazz=Arm_const.class; + Field[] fields=clazz.getFields(); + for(Field f:fields) + { + String s=f.getName(); + if(s.contains("ARM_CC_")) + try + { + if (((int)f.get(null))==cc) + { + return s.replace("ARM_CC_",""); + } + } + catch (IllegalAccessException e) + { + Log.e("arm","",e); + } + catch (IllegalArgumentException e) + {} + } + return ""; + } + // Special registers for MSR + + public static final int ARM_SYSREG_INVALID = 0; + public static final int ARM_SYSREG_SPSR_C = 1; + public static final int ARM_SYSREG_SPSR_X = 2; + public static final int ARM_SYSREG_SPSR_S = 4; + public static final int ARM_SYSREG_SPSR_F = 8; + public static final int ARM_SYSREG_CPSR_C = 16; + public static final int ARM_SYSREG_CPSR_X = 32; + public static final int ARM_SYSREG_CPSR_S = 64; + public static final int ARM_SYSREG_CPSR_F = 128; + public static final int ARM_SYSREG_APSR = 256; + public static final int ARM_SYSREG_APSR_G = 257; + public static final int ARM_SYSREG_APSR_NZCVQ = 258; + public static final int ARM_SYSREG_APSR_NZCVQG = 259; + public static final int ARM_SYSREG_IAPSR = 260; + public static final int ARM_SYSREG_IAPSR_G = 261; + public static final int ARM_SYSREG_IAPSR_NZCVQG = 262; + public static final int ARM_SYSREG_EAPSR = 263; + public static final int ARM_SYSREG_EAPSR_G = 264; + public static final int ARM_SYSREG_EAPSR_NZCVQG = 265; + public static final int ARM_SYSREG_XPSR = 266; + public static final int ARM_SYSREG_XPSR_G = 267; + public static final int ARM_SYSREG_XPSR_NZCVQG = 268; + public static final int ARM_SYSREG_IPSR = 269; + public static final int ARM_SYSREG_EPSR = 270; + public static final int ARM_SYSREG_IEPSR = 271; + public static final int ARM_SYSREG_MSP = 272; + public static final int ARM_SYSREG_PSP = 273; + public static final int ARM_SYSREG_PRIMASK = 274; + public static final int ARM_SYSREG_BASEPRI = 275; + public static final int ARM_SYSREG_BASEPRI_MAX = 276; + public static final int ARM_SYSREG_FAULTMASK = 277; + public static final int ARM_SYSREG_CONTROL = 278; + + // The memory barrier constants map directly to the 4-bit encoding of + + // the option field for Memory Barrier operations. + + public static final int ARM_MB_INVALID = 0; + public static final int ARM_MB_RESERVED_0 = 1; + public static final int ARM_MB_OSHLD = 2; + public static final int ARM_MB_OSHST = 3; + public static final int ARM_MB_OSH = 4; + public static final int ARM_MB_RESERVED_4 = 5; + public static final int ARM_MB_NSHLD = 6; + public static final int ARM_MB_NSHST = 7; + public static final int ARM_MB_NSH = 8; + public static final int ARM_MB_RESERVED_8 = 9; + public static final int ARM_MB_ISHLD = 10; + public static final int ARM_MB_ISHST = 11; + public static final int ARM_MB_ISH = 12; + public static final int ARM_MB_RESERVED_12 = 13; + public static final int ARM_MB_LD = 14; + public static final int ARM_MB_ST = 15; + public static final int ARM_MB_SY = 16; + + // Operand type for instruction's operands + + public static final int ARM_OP_INVALID = 0; + public static final int ARM_OP_REG = 1; + public static final int ARM_OP_IMM = 2; + public static final int ARM_OP_MEM = 3; + public static final int ARM_OP_FP = 4; + public static final int ARM_OP_CIMM = 64; + public static final int ARM_OP_PIMM = 65; + public static final int ARM_OP_SETEND = 66; + public static final int ARM_OP_SYSREG = 67; + + // Operand type for SETEND instruction + + public static final int ARM_SETEND_INVALID = 0; + public static final int ARM_SETEND_BE = 1; + public static final int ARM_SETEND_LE = 2; + + public static final int ARM_CPSMODE_INVALID = 0; + public static final int ARM_CPSMODE_IE = 2; + public static final int ARM_CPSMODE_ID = 3; + + // Operand type for SETEND instruction + + public static final int ARM_CPSFLAG_INVALID = 0; + public static final int ARM_CPSFLAG_F = 1; + public static final int ARM_CPSFLAG_I = 2; + public static final int ARM_CPSFLAG_A = 4; + public static final int ARM_CPSFLAG_NONE = 16; + + // Data type for elements of vector instructions. + + public static final int ARM_VECTORDATA_INVALID = 0; + public static final int ARM_VECTORDATA_I8 = 1; + public static final int ARM_VECTORDATA_I16 = 2; + public static final int ARM_VECTORDATA_I32 = 3; + public static final int ARM_VECTORDATA_I64 = 4; + public static final int ARM_VECTORDATA_S8 = 5; + public static final int ARM_VECTORDATA_S16 = 6; + public static final int ARM_VECTORDATA_S32 = 7; + public static final int ARM_VECTORDATA_S64 = 8; + public static final int ARM_VECTORDATA_U8 = 9; + public static final int ARM_VECTORDATA_U16 = 10; + public static final int ARM_VECTORDATA_U32 = 11; + public static final int ARM_VECTORDATA_U64 = 12; + public static final int ARM_VECTORDATA_P8 = 13; + public static final int ARM_VECTORDATA_F32 = 14; + public static final int ARM_VECTORDATA_F64 = 15; + public static final int ARM_VECTORDATA_F16F64 = 16; + public static final int ARM_VECTORDATA_F64F16 = 17; + public static final int ARM_VECTORDATA_F32F16 = 18; + public static final int ARM_VECTORDATA_F16F32 = 19; + public static final int ARM_VECTORDATA_F64F32 = 20; + public static final int ARM_VECTORDATA_F32F64 = 21; + public static final int ARM_VECTORDATA_S32F32 = 22; + public static final int ARM_VECTORDATA_U32F32 = 23; + public static final int ARM_VECTORDATA_F32S32 = 24; + public static final int ARM_VECTORDATA_F32U32 = 25; + public static final int ARM_VECTORDATA_F64S16 = 26; + public static final int ARM_VECTORDATA_F32S16 = 27; + public static final int ARM_VECTORDATA_F64S32 = 28; + public static final int ARM_VECTORDATA_S16F64 = 29; + public static final int ARM_VECTORDATA_S16F32 = 30; + public static final int ARM_VECTORDATA_S32F64 = 31; + public static final int ARM_VECTORDATA_U16F64 = 32; + public static final int ARM_VECTORDATA_U16F32 = 33; + public static final int ARM_VECTORDATA_U32F64 = 34; + public static final int ARM_VECTORDATA_F64U16 = 35; + public static final int ARM_VECTORDATA_F32U16 = 36; + public static final int ARM_VECTORDATA_F64U32 = 37; + + // ARM registers + + public static final int ARM_REG_INVALID = 0; + public static final int ARM_REG_APSR = 1; + public static final int ARM_REG_APSR_NZCV = 2; + public static final int ARM_REG_CPSR = 3; + public static final int ARM_REG_FPEXC = 4; + public static final int ARM_REG_FPINST = 5; + public static final int ARM_REG_FPSCR = 6; + public static final int ARM_REG_FPSCR_NZCV = 7; + public static final int ARM_REG_FPSID = 8; + public static final int ARM_REG_ITSTATE = 9; + public static final int ARM_REG_LR = 10; + public static final int ARM_REG_PC = 11; + public static final int ARM_REG_SP = 12; + public static final int ARM_REG_SPSR = 13; + public static final int ARM_REG_D0 = 14; + public static final int ARM_REG_D1 = 15; + public static final int ARM_REG_D2 = 16; + public static final int ARM_REG_D3 = 17; + public static final int ARM_REG_D4 = 18; + public static final int ARM_REG_D5 = 19; + public static final int ARM_REG_D6 = 20; + public static final int ARM_REG_D7 = 21; + public static final int ARM_REG_D8 = 22; + public static final int ARM_REG_D9 = 23; + public static final int ARM_REG_D10 = 24; + public static final int ARM_REG_D11 = 25; + public static final int ARM_REG_D12 = 26; + public static final int ARM_REG_D13 = 27; + public static final int ARM_REG_D14 = 28; + public static final int ARM_REG_D15 = 29; + public static final int ARM_REG_D16 = 30; + public static final int ARM_REG_D17 = 31; + public static final int ARM_REG_D18 = 32; + public static final int ARM_REG_D19 = 33; + public static final int ARM_REG_D20 = 34; + public static final int ARM_REG_D21 = 35; + public static final int ARM_REG_D22 = 36; + public static final int ARM_REG_D23 = 37; + public static final int ARM_REG_D24 = 38; + public static final int ARM_REG_D25 = 39; + public static final int ARM_REG_D26 = 40; + public static final int ARM_REG_D27 = 41; + public static final int ARM_REG_D28 = 42; + public static final int ARM_REG_D29 = 43; + public static final int ARM_REG_D30 = 44; + public static final int ARM_REG_D31 = 45; + public static final int ARM_REG_FPINST2 = 46; + public static final int ARM_REG_MVFR0 = 47; + public static final int ARM_REG_MVFR1 = 48; + public static final int ARM_REG_MVFR2 = 49; + public static final int ARM_REG_Q0 = 50; + public static final int ARM_REG_Q1 = 51; + public static final int ARM_REG_Q2 = 52; + public static final int ARM_REG_Q3 = 53; + public static final int ARM_REG_Q4 = 54; + public static final int ARM_REG_Q5 = 55; + public static final int ARM_REG_Q6 = 56; + public static final int ARM_REG_Q7 = 57; + public static final int ARM_REG_Q8 = 58; + public static final int ARM_REG_Q9 = 59; + public static final int ARM_REG_Q10 = 60; + public static final int ARM_REG_Q11 = 61; + public static final int ARM_REG_Q12 = 62; + public static final int ARM_REG_Q13 = 63; + public static final int ARM_REG_Q14 = 64; + public static final int ARM_REG_Q15 = 65; + public static final int ARM_REG_R0 = 66; + public static final int ARM_REG_R1 = 67; + public static final int ARM_REG_R2 = 68; + public static final int ARM_REG_R3 = 69; + public static final int ARM_REG_R4 = 70; + public static final int ARM_REG_R5 = 71; + public static final int ARM_REG_R6 = 72; + public static final int ARM_REG_R7 = 73; + public static final int ARM_REG_R8 = 74; + public static final int ARM_REG_R9 = 75; + public static final int ARM_REG_R10 = 76; + public static final int ARM_REG_R11 = 77; + public static final int ARM_REG_R12 = 78; + public static final int ARM_REG_S0 = 79; + public static final int ARM_REG_S1 = 80; + public static final int ARM_REG_S2 = 81; + public static final int ARM_REG_S3 = 82; + public static final int ARM_REG_S4 = 83; + public static final int ARM_REG_S5 = 84; + public static final int ARM_REG_S6 = 85; + public static final int ARM_REG_S7 = 86; + public static final int ARM_REG_S8 = 87; + public static final int ARM_REG_S9 = 88; + public static final int ARM_REG_S10 = 89; + public static final int ARM_REG_S11 = 90; + public static final int ARM_REG_S12 = 91; + public static final int ARM_REG_S13 = 92; + public static final int ARM_REG_S14 = 93; + public static final int ARM_REG_S15 = 94; + public static final int ARM_REG_S16 = 95; + public static final int ARM_REG_S17 = 96; + public static final int ARM_REG_S18 = 97; + public static final int ARM_REG_S19 = 98; + public static final int ARM_REG_S20 = 99; + public static final int ARM_REG_S21 = 100; + public static final int ARM_REG_S22 = 101; + public static final int ARM_REG_S23 = 102; + public static final int ARM_REG_S24 = 103; + public static final int ARM_REG_S25 = 104; + public static final int ARM_REG_S26 = 105; + public static final int ARM_REG_S27 = 106; + public static final int ARM_REG_S28 = 107; + public static final int ARM_REG_S29 = 108; + public static final int ARM_REG_S30 = 109; + public static final int ARM_REG_S31 = 110; + public static final int ARM_REG_ENDING = 111; + + // alias registers + public static final int ARM_REG_R13 = ARM_REG_SP; + public static final int ARM_REG_R14 = ARM_REG_LR; + public static final int ARM_REG_R15 = ARM_REG_PC; + public static final int ARM_REG_SB = ARM_REG_R9; + public static final int ARM_REG_SL = ARM_REG_R10; + public static final int ARM_REG_FP = ARM_REG_R11; + public static final int ARM_REG_IP = ARM_REG_R12; + + // ARM instruction + + public static final int ARM_INS_INVALID = 0; + public static final int ARM_INS_ADC = 1; + public static final int ARM_INS_ADD = 2; + public static final int ARM_INS_ADR = 3; + public static final int ARM_INS_AESD = 4; + public static final int ARM_INS_AESE = 5; + public static final int ARM_INS_AESIMC = 6; + public static final int ARM_INS_AESMC = 7; + public static final int ARM_INS_AND = 8; + public static final int ARM_INS_BFC = 9; + public static final int ARM_INS_BFI = 10; + public static final int ARM_INS_BIC = 11; + public static final int ARM_INS_BKPT = 12; + public static final int ARM_INS_BL = 13; + public static final int ARM_INS_BLX = 14; + public static final int ARM_INS_BX = 15; + public static final int ARM_INS_BXJ = 16; + public static final int ARM_INS_B = 17; + public static final int ARM_INS_CDP = 18; + public static final int ARM_INS_CDP2 = 19; + public static final int ARM_INS_CLREX = 20; + public static final int ARM_INS_CLZ = 21; + public static final int ARM_INS_CMN = 22; + public static final int ARM_INS_CMP = 23; + public static final int ARM_INS_CPS = 24; + public static final int ARM_INS_CRC32B = 25; + public static final int ARM_INS_CRC32CB = 26; + public static final int ARM_INS_CRC32CH = 27; + public static final int ARM_INS_CRC32CW = 28; + public static final int ARM_INS_CRC32H = 29; + public static final int ARM_INS_CRC32W = 30; + public static final int ARM_INS_DBG = 31; + public static final int ARM_INS_DMB = 32; + public static final int ARM_INS_DSB = 33; + public static final int ARM_INS_EOR = 34; + public static final int ARM_INS_VMOV = 35; + public static final int ARM_INS_FLDMDBX = 36; + public static final int ARM_INS_FLDMIAX = 37; + public static final int ARM_INS_VMRS = 38; + public static final int ARM_INS_FSTMDBX = 39; + public static final int ARM_INS_FSTMIAX = 40; + public static final int ARM_INS_HINT = 41; + public static final int ARM_INS_HLT = 42; + public static final int ARM_INS_ISB = 43; + public static final int ARM_INS_LDA = 44; + public static final int ARM_INS_LDAB = 45; + public static final int ARM_INS_LDAEX = 46; + public static final int ARM_INS_LDAEXB = 47; + public static final int ARM_INS_LDAEXD = 48; + public static final int ARM_INS_LDAEXH = 49; + public static final int ARM_INS_LDAH = 50; + public static final int ARM_INS_LDC2L = 51; + public static final int ARM_INS_LDC2 = 52; + public static final int ARM_INS_LDCL = 53; + public static final int ARM_INS_LDC = 54; + public static final int ARM_INS_LDMDA = 55; + public static final int ARM_INS_LDMDB = 56; + public static final int ARM_INS_LDM = 57; + public static final int ARM_INS_LDMIB = 58; + public static final int ARM_INS_LDRBT = 59; + public static final int ARM_INS_LDRB = 60; + public static final int ARM_INS_LDRD = 61; + public static final int ARM_INS_LDREX = 62; + public static final int ARM_INS_LDREXB = 63; + public static final int ARM_INS_LDREXD = 64; + public static final int ARM_INS_LDREXH = 65; + public static final int ARM_INS_LDRH = 66; + public static final int ARM_INS_LDRHT = 67; + public static final int ARM_INS_LDRSB = 68; + public static final int ARM_INS_LDRSBT = 69; + public static final int ARM_INS_LDRSH = 70; + public static final int ARM_INS_LDRSHT = 71; + public static final int ARM_INS_LDRT = 72; + public static final int ARM_INS_LDR = 73; + public static final int ARM_INS_MCR = 74; + public static final int ARM_INS_MCR2 = 75; + public static final int ARM_INS_MCRR = 76; + public static final int ARM_INS_MCRR2 = 77; + public static final int ARM_INS_MLA = 78; + public static final int ARM_INS_MLS = 79; + public static final int ARM_INS_MOV = 80; + public static final int ARM_INS_MOVT = 81; + public static final int ARM_INS_MOVW = 82; + public static final int ARM_INS_MRC = 83; + public static final int ARM_INS_MRC2 = 84; + public static final int ARM_INS_MRRC = 85; + public static final int ARM_INS_MRRC2 = 86; + public static final int ARM_INS_MRS = 87; + public static final int ARM_INS_MSR = 88; + public static final int ARM_INS_MUL = 89; + public static final int ARM_INS_MVN = 90; + public static final int ARM_INS_ORR = 91; + public static final int ARM_INS_PKHBT = 92; + public static final int ARM_INS_PKHTB = 93; + public static final int ARM_INS_PLDW = 94; + public static final int ARM_INS_PLD = 95; + public static final int ARM_INS_PLI = 96; + public static final int ARM_INS_QADD = 97; + public static final int ARM_INS_QADD16 = 98; + public static final int ARM_INS_QADD8 = 99; + public static final int ARM_INS_QASX = 100; + public static final int ARM_INS_QDADD = 101; + public static final int ARM_INS_QDSUB = 102; + public static final int ARM_INS_QSAX = 103; + public static final int ARM_INS_QSUB = 104; + public static final int ARM_INS_QSUB16 = 105; + public static final int ARM_INS_QSUB8 = 106; + public static final int ARM_INS_RBIT = 107; + public static final int ARM_INS_REV = 108; + public static final int ARM_INS_REV16 = 109; + public static final int ARM_INS_REVSH = 110; + public static final int ARM_INS_RFEDA = 111; + public static final int ARM_INS_RFEDB = 112; + public static final int ARM_INS_RFEIA = 113; + public static final int ARM_INS_RFEIB = 114; + public static final int ARM_INS_RSB = 115; + public static final int ARM_INS_RSC = 116; + public static final int ARM_INS_SADD16 = 117; + public static final int ARM_INS_SADD8 = 118; + public static final int ARM_INS_SASX = 119; + public static final int ARM_INS_SBC = 120; + public static final int ARM_INS_SBFX = 121; + public static final int ARM_INS_SDIV = 122; + public static final int ARM_INS_SEL = 123; + public static final int ARM_INS_SETEND = 124; + public static final int ARM_INS_SHA1C = 125; + public static final int ARM_INS_SHA1H = 126; + public static final int ARM_INS_SHA1M = 127; + public static final int ARM_INS_SHA1P = 128; + public static final int ARM_INS_SHA1SU0 = 129; + public static final int ARM_INS_SHA1SU1 = 130; + public static final int ARM_INS_SHA256H = 131; + public static final int ARM_INS_SHA256H2 = 132; + public static final int ARM_INS_SHA256SU0 = 133; + public static final int ARM_INS_SHA256SU1 = 134; + public static final int ARM_INS_SHADD16 = 135; + public static final int ARM_INS_SHADD8 = 136; + public static final int ARM_INS_SHASX = 137; + public static final int ARM_INS_SHSAX = 138; + public static final int ARM_INS_SHSUB16 = 139; + public static final int ARM_INS_SHSUB8 = 140; + public static final int ARM_INS_SMC = 141; + public static final int ARM_INS_SMLABB = 142; + public static final int ARM_INS_SMLABT = 143; + public static final int ARM_INS_SMLAD = 144; + public static final int ARM_INS_SMLADX = 145; + public static final int ARM_INS_SMLAL = 146; + public static final int ARM_INS_SMLALBB = 147; + public static final int ARM_INS_SMLALBT = 148; + public static final int ARM_INS_SMLALD = 149; + public static final int ARM_INS_SMLALDX = 150; + public static final int ARM_INS_SMLALTB = 151; + public static final int ARM_INS_SMLALTT = 152; + public static final int ARM_INS_SMLATB = 153; + public static final int ARM_INS_SMLATT = 154; + public static final int ARM_INS_SMLAWB = 155; + public static final int ARM_INS_SMLAWT = 156; + public static final int ARM_INS_SMLSD = 157; + public static final int ARM_INS_SMLSDX = 158; + public static final int ARM_INS_SMLSLD = 159; + public static final int ARM_INS_SMLSLDX = 160; + public static final int ARM_INS_SMMLA = 161; + public static final int ARM_INS_SMMLAR = 162; + public static final int ARM_INS_SMMLS = 163; + public static final int ARM_INS_SMMLSR = 164; + public static final int ARM_INS_SMMUL = 165; + public static final int ARM_INS_SMMULR = 166; + public static final int ARM_INS_SMUAD = 167; + public static final int ARM_INS_SMUADX = 168; + public static final int ARM_INS_SMULBB = 169; + public static final int ARM_INS_SMULBT = 170; + public static final int ARM_INS_SMULL = 171; + public static final int ARM_INS_SMULTB = 172; + public static final int ARM_INS_SMULTT = 173; + public static final int ARM_INS_SMULWB = 174; + public static final int ARM_INS_SMULWT = 175; + public static final int ARM_INS_SMUSD = 176; + public static final int ARM_INS_SMUSDX = 177; + public static final int ARM_INS_SRSDA = 178; + public static final int ARM_INS_SRSDB = 179; + public static final int ARM_INS_SRSIA = 180; + public static final int ARM_INS_SRSIB = 181; + public static final int ARM_INS_SSAT = 182; + public static final int ARM_INS_SSAT16 = 183; + public static final int ARM_INS_SSAX = 184; + public static final int ARM_INS_SSUB16 = 185; + public static final int ARM_INS_SSUB8 = 186; + public static final int ARM_INS_STC2L = 187; + public static final int ARM_INS_STC2 = 188; + public static final int ARM_INS_STCL = 189; + public static final int ARM_INS_STC = 190; + public static final int ARM_INS_STL = 191; + public static final int ARM_INS_STLB = 192; + public static final int ARM_INS_STLEX = 193; + public static final int ARM_INS_STLEXB = 194; + public static final int ARM_INS_STLEXD = 195; + public static final int ARM_INS_STLEXH = 196; + public static final int ARM_INS_STLH = 197; + public static final int ARM_INS_STMDA = 198; + public static final int ARM_INS_STMDB = 199; + public static final int ARM_INS_STM = 200; + public static final int ARM_INS_STMIB = 201; + public static final int ARM_INS_STRBT = 202; + public static final int ARM_INS_STRB = 203; + public static final int ARM_INS_STRD = 204; + public static final int ARM_INS_STREX = 205; + public static final int ARM_INS_STREXB = 206; + public static final int ARM_INS_STREXD = 207; + public static final int ARM_INS_STREXH = 208; + public static final int ARM_INS_STRH = 209; + public static final int ARM_INS_STRHT = 210; + public static final int ARM_INS_STRT = 211; + public static final int ARM_INS_STR = 212; + public static final int ARM_INS_SUB = 213; + public static final int ARM_INS_SVC = 214; + public static final int ARM_INS_SWP = 215; + public static final int ARM_INS_SWPB = 216; + public static final int ARM_INS_SXTAB = 217; + public static final int ARM_INS_SXTAB16 = 218; + public static final int ARM_INS_SXTAH = 219; + public static final int ARM_INS_SXTB = 220; + public static final int ARM_INS_SXTB16 = 221; + public static final int ARM_INS_SXTH = 222; + public static final int ARM_INS_TEQ = 223; + public static final int ARM_INS_TRAP = 224; + public static final int ARM_INS_TST = 225; + public static final int ARM_INS_UADD16 = 226; + public static final int ARM_INS_UADD8 = 227; + public static final int ARM_INS_UASX = 228; + public static final int ARM_INS_UBFX = 229; + public static final int ARM_INS_UDF = 230; + public static final int ARM_INS_UDIV = 231; + public static final int ARM_INS_UHADD16 = 232; + public static final int ARM_INS_UHADD8 = 233; + public static final int ARM_INS_UHASX = 234; + public static final int ARM_INS_UHSAX = 235; + public static final int ARM_INS_UHSUB16 = 236; + public static final int ARM_INS_UHSUB8 = 237; + public static final int ARM_INS_UMAAL = 238; + public static final int ARM_INS_UMLAL = 239; + public static final int ARM_INS_UMULL = 240; + public static final int ARM_INS_UQADD16 = 241; + public static final int ARM_INS_UQADD8 = 242; + public static final int ARM_INS_UQASX = 243; + public static final int ARM_INS_UQSAX = 244; + public static final int ARM_INS_UQSUB16 = 245; + public static final int ARM_INS_UQSUB8 = 246; + public static final int ARM_INS_USAD8 = 247; + public static final int ARM_INS_USADA8 = 248; + public static final int ARM_INS_USAT = 249; + public static final int ARM_INS_USAT16 = 250; + public static final int ARM_INS_USAX = 251; + public static final int ARM_INS_USUB16 = 252; + public static final int ARM_INS_USUB8 = 253; + public static final int ARM_INS_UXTAB = 254; + public static final int ARM_INS_UXTAB16 = 255; + public static final int ARM_INS_UXTAH = 256; + public static final int ARM_INS_UXTB = 257; + public static final int ARM_INS_UXTB16 = 258; + public static final int ARM_INS_UXTH = 259; + public static final int ARM_INS_VABAL = 260; + public static final int ARM_INS_VABA = 261; + public static final int ARM_INS_VABDL = 262; + public static final int ARM_INS_VABD = 263; + public static final int ARM_INS_VABS = 264; + public static final int ARM_INS_VACGE = 265; + public static final int ARM_INS_VACGT = 266; + public static final int ARM_INS_VADD = 267; + public static final int ARM_INS_VADDHN = 268; + public static final int ARM_INS_VADDL = 269; + public static final int ARM_INS_VADDW = 270; + public static final int ARM_INS_VAND = 271; + public static final int ARM_INS_VBIC = 272; + public static final int ARM_INS_VBIF = 273; + public static final int ARM_INS_VBIT = 274; + public static final int ARM_INS_VBSL = 275; + public static final int ARM_INS_VCEQ = 276; + public static final int ARM_INS_VCGE = 277; + public static final int ARM_INS_VCGT = 278; + public static final int ARM_INS_VCLE = 279; + public static final int ARM_INS_VCLS = 280; + public static final int ARM_INS_VCLT = 281; + public static final int ARM_INS_VCLZ = 282; + public static final int ARM_INS_VCMP = 283; + public static final int ARM_INS_VCMPE = 284; + public static final int ARM_INS_VCNT = 285; + public static final int ARM_INS_VCVTA = 286; + public static final int ARM_INS_VCVTB = 287; + public static final int ARM_INS_VCVT = 288; + public static final int ARM_INS_VCVTM = 289; + public static final int ARM_INS_VCVTN = 290; + public static final int ARM_INS_VCVTP = 291; + public static final int ARM_INS_VCVTT = 292; + public static final int ARM_INS_VDIV = 293; + public static final int ARM_INS_VDUP = 294; + public static final int ARM_INS_VEOR = 295; + public static final int ARM_INS_VEXT = 296; + public static final int ARM_INS_VFMA = 297; + public static final int ARM_INS_VFMS = 298; + public static final int ARM_INS_VFNMA = 299; + public static final int ARM_INS_VFNMS = 300; + public static final int ARM_INS_VHADD = 301; + public static final int ARM_INS_VHSUB = 302; + public static final int ARM_INS_VLD1 = 303; + public static final int ARM_INS_VLD2 = 304; + public static final int ARM_INS_VLD3 = 305; + public static final int ARM_INS_VLD4 = 306; + public static final int ARM_INS_VLDMDB = 307; + public static final int ARM_INS_VLDMIA = 308; + public static final int ARM_INS_VLDR = 309; + public static final int ARM_INS_VMAXNM = 310; + public static final int ARM_INS_VMAX = 311; + public static final int ARM_INS_VMINNM = 312; + public static final int ARM_INS_VMIN = 313; + public static final int ARM_INS_VMLA = 314; + public static final int ARM_INS_VMLAL = 315; + public static final int ARM_INS_VMLS = 316; + public static final int ARM_INS_VMLSL = 317; + public static final int ARM_INS_VMOVL = 318; + public static final int ARM_INS_VMOVN = 319; + public static final int ARM_INS_VMSR = 320; + public static final int ARM_INS_VMUL = 321; + public static final int ARM_INS_VMULL = 322; + public static final int ARM_INS_VMVN = 323; + public static final int ARM_INS_VNEG = 324; + public static final int ARM_INS_VNMLA = 325; + public static final int ARM_INS_VNMLS = 326; + public static final int ARM_INS_VNMUL = 327; + public static final int ARM_INS_VORN = 328; + public static final int ARM_INS_VORR = 329; + public static final int ARM_INS_VPADAL = 330; + public static final int ARM_INS_VPADDL = 331; + public static final int ARM_INS_VPADD = 332; + public static final int ARM_INS_VPMAX = 333; + public static final int ARM_INS_VPMIN = 334; + public static final int ARM_INS_VQABS = 335; + public static final int ARM_INS_VQADD = 336; + public static final int ARM_INS_VQDMLAL = 337; + public static final int ARM_INS_VQDMLSL = 338; + public static final int ARM_INS_VQDMULH = 339; + public static final int ARM_INS_VQDMULL = 340; + public static final int ARM_INS_VQMOVUN = 341; + public static final int ARM_INS_VQMOVN = 342; + public static final int ARM_INS_VQNEG = 343; + public static final int ARM_INS_VQRDMULH = 344; + public static final int ARM_INS_VQRSHL = 345; + public static final int ARM_INS_VQRSHRN = 346; + public static final int ARM_INS_VQRSHRUN = 347; + public static final int ARM_INS_VQSHL = 348; + public static final int ARM_INS_VQSHLU = 349; + public static final int ARM_INS_VQSHRN = 350; + public static final int ARM_INS_VQSHRUN = 351; + public static final int ARM_INS_VQSUB = 352; + public static final int ARM_INS_VRADDHN = 353; + public static final int ARM_INS_VRECPE = 354; + public static final int ARM_INS_VRECPS = 355; + public static final int ARM_INS_VREV16 = 356; + public static final int ARM_INS_VREV32 = 357; + public static final int ARM_INS_VREV64 = 358; + public static final int ARM_INS_VRHADD = 359; + public static final int ARM_INS_VRINTA = 360; + public static final int ARM_INS_VRINTM = 361; + public static final int ARM_INS_VRINTN = 362; + public static final int ARM_INS_VRINTP = 363; + public static final int ARM_INS_VRINTR = 364; + public static final int ARM_INS_VRINTX = 365; + public static final int ARM_INS_VRINTZ = 366; + public static final int ARM_INS_VRSHL = 367; + public static final int ARM_INS_VRSHRN = 368; + public static final int ARM_INS_VRSHR = 369; + public static final int ARM_INS_VRSQRTE = 370; + public static final int ARM_INS_VRSQRTS = 371; + public static final int ARM_INS_VRSRA = 372; + public static final int ARM_INS_VRSUBHN = 373; + public static final int ARM_INS_VSELEQ = 374; + public static final int ARM_INS_VSELGE = 375; + public static final int ARM_INS_VSELGT = 376; + public static final int ARM_INS_VSELVS = 377; + public static final int ARM_INS_VSHLL = 378; + public static final int ARM_INS_VSHL = 379; + public static final int ARM_INS_VSHRN = 380; + public static final int ARM_INS_VSHR = 381; + public static final int ARM_INS_VSLI = 382; + public static final int ARM_INS_VSQRT = 383; + public static final int ARM_INS_VSRA = 384; + public static final int ARM_INS_VSRI = 385; + public static final int ARM_INS_VST1 = 386; + public static final int ARM_INS_VST2 = 387; + public static final int ARM_INS_VST3 = 388; + public static final int ARM_INS_VST4 = 389; + public static final int ARM_INS_VSTMDB = 390; + public static final int ARM_INS_VSTMIA = 391; + public static final int ARM_INS_VSTR = 392; + public static final int ARM_INS_VSUB = 393; + public static final int ARM_INS_VSUBHN = 394; + public static final int ARM_INS_VSUBL = 395; + public static final int ARM_INS_VSUBW = 396; + public static final int ARM_INS_VSWP = 397; + public static final int ARM_INS_VTBL = 398; + public static final int ARM_INS_VTBX = 399; + public static final int ARM_INS_VCVTR = 400; + public static final int ARM_INS_VTRN = 401; + public static final int ARM_INS_VTST = 402; + public static final int ARM_INS_VUZP = 403; + public static final int ARM_INS_VZIP = 404; + public static final int ARM_INS_ADDW = 405; + public static final int ARM_INS_ASR = 406; + public static final int ARM_INS_DCPS1 = 407; + public static final int ARM_INS_DCPS2 = 408; + public static final int ARM_INS_DCPS3 = 409; + public static final int ARM_INS_IT = 410; + public static final int ARM_INS_LSL = 411; + public static final int ARM_INS_LSR = 412; + public static final int ARM_INS_ASRS = 413; + public static final int ARM_INS_LSRS = 414; + public static final int ARM_INS_ORN = 415; + public static final int ARM_INS_ROR = 416; + public static final int ARM_INS_RRX = 417; + public static final int ARM_INS_SUBS = 418; + public static final int ARM_INS_SUBW = 419; + public static final int ARM_INS_TBB = 420; + public static final int ARM_INS_TBH = 421; + public static final int ARM_INS_CBNZ = 422; + public static final int ARM_INS_CBZ = 423; + public static final int ARM_INS_MOVS = 424; + public static final int ARM_INS_POP = 425; + public static final int ARM_INS_PUSH = 426; + public static final int ARM_INS_NOP = 427; + public static final int ARM_INS_YIELD = 428; + public static final int ARM_INS_WFE = 429; + public static final int ARM_INS_WFI = 430; + public static final int ARM_INS_SEV = 431; + public static final int ARM_INS_SEVL = 432; + public static final int ARM_INS_VPUSH = 433; + public static final int ARM_INS_VPOP = 434; + public static final int ARM_INS_ENDING = 435; + + // Group of ARM instructions + + public static final int ARM_GRP_INVALID = 0; + + // Generic groups + public static final int ARM_GRP_JUMP = 1; + + // Architecture-specific groups + public static final int ARM_GRP_CRYPTO = 128; + public static final int ARM_GRP_DATABARRIER = 129; + public static final int ARM_GRP_DIVIDE = 130; + public static final int ARM_GRP_FPARMV8 = 131; + public static final int ARM_GRP_MULTPRO = 132; + public static final int ARM_GRP_NEON = 133; + public static final int ARM_GRP_T2EXTRACTPACK = 134; + public static final int ARM_GRP_THUMB2DSP = 135; + public static final int ARM_GRP_TRUSTZONE = 136; + public static final int ARM_GRP_V4T = 137; + public static final int ARM_GRP_V5T = 138; + public static final int ARM_GRP_V5TE = 139; + public static final int ARM_GRP_V6 = 140; + public static final int ARM_GRP_V6T2 = 141; + public static final int ARM_GRP_V7 = 142; + public static final int ARM_GRP_V8 = 143; + public static final int ARM_GRP_VFP2 = 144; + public static final int ARM_GRP_VFP3 = 145; + public static final int ARM_GRP_VFP4 = 146; + public static final int ARM_GRP_ARM = 147; + public static final int ARM_GRP_MCLASS = 148; + public static final int ARM_GRP_NOTMCLASS = 149; + public static final int ARM_GRP_THUMB = 150; + public static final int ARM_GRP_THUMB1ONLY = 151; + public static final int ARM_GRP_THUMB2 = 152; + public static final int ARM_GRP_PREV8 = 153; + public static final int ARM_GRP_FPVMLX = 154; + public static final int ARM_GRP_MULOPS = 155; + public static final int ARM_GRP_CRC = 156; + public static final int ARM_GRP_DPVFP = 157; + public static final int ARM_GRP_V6M = 158; + public static final int ARM_GRP_ENDING = 159; +} diff --git a/app/src/main/java/capstone/Capstone.java b/app/src/main/java/capstone/Capstone.java new file mode 100644 index 00000000..fe11ae82 --- /dev/null +++ b/app/src/main/java/capstone/Capstone.java @@ -0,0 +1,589 @@ +// Capstone Java binding +// By Nguyen Anh Quynh & Dang Hoang Vu, 2013 + +package capstone; + +import com.sun.jna.Library; +import com.sun.jna.Native; +import com.sun.jna.NativeLong; +import com.sun.jna.ptr.NativeLongByReference; +import com.sun.jna.Structure; +import com.sun.jna.Union; +import com.sun.jna.Pointer; +import com.sun.jna.ptr.PointerByReference; +import com.sun.jna.ptr.IntByReference; + +import java.util.List; +import java.util.Arrays; +import java.lang.RuntimeException; +import com.sun.jna.*; + +public class Capstone +{ + + protected static abstract class OpInfo + {}; + protected static abstract class UnionOpInfo extends Structure + {}; + + public static class UnionArch extends Union + { + public static class ByValue extends UnionArch implements Union.ByValue + {}; + + public Arm.UnionOpInfo arm; + public Arm64.UnionOpInfo arm64; + public X86.UnionOpInfo x86; + public Mips.UnionOpInfo mips; + public Ppc.UnionOpInfo ppc; + public Sparc.UnionOpInfo sparc; + public Systemz.UnionOpInfo sysz; + public Xcore.UnionOpInfo xcore; + } + + protected static class _cs_insn extends Structure + { + // instruction ID. + public int id; + // instruction address. + public long address; + // instruction size. + public short size; + // machine bytes of instruction. + public byte[] bytes; + // instruction mnemonic. NOTE: irrelevant for diet engine. + public byte[] mnemonic; + // instruction operands. NOTE: irrelevant for diet engine. + public byte[] op_str; + // detail information of instruction. + public _cs_detail.ByReference cs_detail; + + public _cs_insn() + { + bytes = new byte[16]; + mnemonic = new byte[32]; + op_str = new byte[160]; + java.util.Arrays.fill(mnemonic, (byte) 0); + java.util.Arrays.fill(op_str, (byte) 0); + } + + public _cs_insn(Pointer p) + { + this(); + useMemory(p); + read(); + } + + @Override + public List getFieldOrder() + { + return Arrays.asList("id", "address", "size", "bytes", "mnemonic", "op_str", "cs_detail"); + } + } + + protected static class _cs_detail extends Structure + { + public static class ByReference extends _cs_detail implements Structure.ByReference + {}; + + // list of all implicit registers being read. + public byte[] regs_read = new byte[12]; + public byte regs_read_count; + // list of all implicit registers being written. + public byte[] regs_write = new byte[20]; + public byte regs_write_count; + // list of semantic groups this instruction belongs to. + public byte[] groups = new byte[8]; + public byte groups_count; + + public UnionArch arch; + + @Override + public List getFieldOrder() + { + return Arrays.asList("regs_read", "regs_read_count", "regs_write", "regs_write_count", "groups", "groups_count", "arch"); + } + } + + public static class CsInsn + { + private NativeLong csh; + private CS cs; + private _cs_insn raw; + private int arch; + + // instruction ID. + public int id; + // instruction address. + public long address; + // instruction size. + public short size; + // instruction mnemonic. NOTE: irrelevant for diet engine. + public String mnemonic; + // instruction operands. NOTE: irrelevant for diet engine. + public String opStr; + // list of all implicit registers being read. + public byte[] regsRead; + // list of all implicit registers being written. + public byte[] regsWrite; + // list of semantic groups this instruction belongs to. + public byte[] groups; + public OpInfo operands; + + public CsInsn(_cs_insn insn, int _arch, NativeLong _csh, CS _cs, boolean diet) + { + id = insn.id; + address = insn.address; + size = insn.size; + + if (!diet) + { + int lm = 0; + while (insn.mnemonic[lm++] != 0); + int lo = 0; + while (insn.op_str[lo++] != 0); + mnemonic = new String(insn.mnemonic, 0, lm - 1); + opStr = new String(insn.op_str, 0, lo - 1); + } + + cs = _cs; + arch = _arch; + raw = insn; + csh = _csh; + + if (insn.cs_detail != null) + { + if (!diet) + { + regsRead = new byte[insn.cs_detail.regs_read_count]; + for (int i=0; i < regsRead.length; i++) + regsRead[i] = insn.cs_detail.regs_read[i]; + regsWrite = new byte[insn.cs_detail.regs_write_count]; + for (int i=0; i < regsWrite.length; i++) + regsWrite[i] = insn.cs_detail.regs_write[i]; + groups = new byte[insn.cs_detail.groups_count]; + for (int i=0; i < groups.length; i++) + groups[i] = insn.cs_detail.groups[i]; + } + + operands = getOptInfo(insn.cs_detail); + } + } + + private OpInfo getOptInfo(_cs_detail detail) + { + OpInfo op_info = null; + + switch (this.arch) + { + case CS_ARCH_ARM: + detail.arch.setType(Arm.UnionOpInfo.class); + detail.arch.read(); + op_info = new Arm.OpInfo((Arm.UnionOpInfo) detail.arch.arm); + break; + case CS_ARCH_ARM64: + detail.arch.setType(Arm64.UnionOpInfo.class); + detail.arch.read(); + op_info = new Arm64.OpInfo((Arm64.UnionOpInfo) detail.arch.arm64); + break; + case CS_ARCH_MIPS: + detail.arch.setType(Mips.UnionOpInfo.class); + detail.arch.read(); + op_info = new Mips.OpInfo((Mips.UnionOpInfo) detail.arch.mips); + break; + case CS_ARCH_X86: + detail.arch.setType(X86.UnionOpInfo.class); + detail.arch.read(); + op_info = new X86.OpInfo((X86.UnionOpInfo) detail.arch.x86); + break; + case CS_ARCH_SPARC: + detail.arch.setType(Sparc.UnionOpInfo.class); + detail.arch.read(); + op_info = new Sparc.OpInfo((Sparc.UnionOpInfo) detail.arch.sparc); + break; + case CS_ARCH_SYSZ: + detail.arch.setType(Systemz.UnionOpInfo.class); + detail.arch.read(); + op_info = new Systemz.OpInfo((Systemz.UnionOpInfo) detail.arch.sysz); + break; + case CS_ARCH_PPC: + detail.arch.setType(Ppc.UnionOpInfo.class); + detail.arch.read(); + op_info = new Ppc.OpInfo((Ppc.UnionOpInfo) detail.arch.ppc); + break; + case CS_ARCH_XCORE: + detail.arch.setType(Xcore.UnionOpInfo.class); + detail.arch.read(); + op_info = new Xcore.OpInfo((Xcore.UnionOpInfo) detail.arch.xcore); + break; + default: + } + + return op_info; + } + + public int opCount(int type) + { + return cs.cs_op_count(csh, raw.getPointer(), type); + } + + public int opIndex(int type, int index) + { + return cs.cs_op_index(csh, raw.getPointer(), type, index); + } + + public boolean regRead(int reg_id) + { + return cs.cs_reg_read(csh, raw.getPointer(), reg_id) != 0; + } + + public boolean regWrite(int reg_id) + { + return cs.cs_reg_write(csh, raw.getPointer(), reg_id) != 0; + } + + public int errno() + { + return cs.cs_errno(csh); + } + + public String regName(int reg_id) + { + return cs.cs_reg_name(csh, reg_id); + } + + public String insnName() + { + return cs.cs_insn_name(csh, id); + } + + public String groupName(int id) + { + return cs.cs_group_name(csh, id); + } + + public boolean group(int gid) + { + return cs.cs_insn_group(csh, raw.getPointer(), gid) != 0; + } + public byte[] bytes() + { + return raw.bytes; + } + @Override + protected void finalize() throws Throwable + { + // TODO: Implement this method + super.finalize(); + cs.cs_free(raw.getPointer(),new NativeLong(1)); + } + + } + + private CsInsn[] fromArrayRaw(_cs_insn[] arr_raw) + { + CsInsn[] arr = new CsInsn[arr_raw.length]; + + for (int i = 0; i < arr_raw.length; i++) + { + arr[i] = new CsInsn(arr_raw[i], this.arch, ns.csh, cs, this.diet); + } + + return arr; + } + + private interface CS extends Library + { + public int cs_open(int arch, int mode, NativeLongByReference handle); + public NativeLong cs_disasm(NativeLong handle, byte[] code, NativeLong code_len, + long addr, NativeLong count, PointerByReference insn); + public void cs_free(Pointer p, NativeLong count); + public int cs_close(NativeLongByReference handle); + public int cs_option(NativeLong handle, int option, NativeLong optionValue); + + public int cs_setup_mem(); + public NativeLong cs_disasm2(NativeLong handle, byte[] code, NativeLong code_offset,NativeLong code_len, + long addr, NativeLong count, PointerByReference insn); + + + public String cs_reg_name(NativeLong csh, int id); + public int cs_op_count(NativeLong csh, Pointer insn, int type); + public int cs_op_index(NativeLong csh, Pointer insn, int type, int index); + + public String cs_insn_name(NativeLong csh, int id); + public String cs_group_name(NativeLong csh, int id); + public byte cs_insn_group(NativeLong csh, Pointer insn, int id); + public byte cs_reg_read(NativeLong csh, Pointer insn, int id); + public byte cs_reg_write(NativeLong csh, Pointer insn, int id); + public int cs_errno(NativeLong csh); + public int cs_version(IntByReference major, IntByReference minor); + public boolean cs_support(int query); + } + + // Capstone API version + public static final int CS_API_MAJOR = 3; + public static final int CS_API_MINOR = 0; + + // architectures + public static final int CS_ARCH_ARM = 0; + public static final int CS_ARCH_ARM64 = 1; + public static final int CS_ARCH_MIPS = 2; + public static final int CS_ARCH_X86 = 3; + public static final int CS_ARCH_PPC = 4; + public static final int CS_ARCH_SPARC = 5; + public static final int CS_ARCH_SYSZ = 6; + public static final int CS_ARCH_XCORE = 7; + public static final int CS_ARCH_MAX = 8; + public static final int CS_ARCH_ALL = 0xFFFF; // query id for cs_support() + + // disasm mode + public static final int CS_MODE_LITTLE_ENDIAN = 0; // little-endian mode (default mode) + public static final int CS_MODE_ARM = 0; // 32-bit ARM + public static final int CS_MODE_16 = 1 << 1; // 16-bit mode for X86 + public static final int CS_MODE_32 = 1 << 2; // 32-bit mode for X86 + public static final int CS_MODE_64 = 1 << 3; // 64-bit mode for X86, PPC + public static final int CS_MODE_THUMB = 1 << 4; // ARM's Thumb mode, including Thumb-2 + public static final int CS_MODE_MCLASS = 1 << 5; // ARM's Cortex-M series + public static final int CS_MODE_V8 = 1 << 6; // ARMv8 A32 encodings for ARM + public static final int CS_MODE_MICRO = 1 << 4; // MicroMips mode (Mips arch) + public static final int CS_MODE_MIPS3 = 1 << 5; // Mips III ISA + public static final int CS_MODE_MIPS32R6 = 1 << 6; // Mips32r6 ISA + public static final int CS_MODE_MIPSGP64 = 1 << 7; // General Purpose Registers are 64-bit wide (MIPS arch) + public static final int CS_MODE_BIG_ENDIAN = 1 << 31; // big-endian mode + public static final int CS_MODE_V9 = 1 << 4; // SparcV9 mode (Sparc arch) + public static final int CS_MODE_MIPS32 = CS_MODE_32; // Mips32 ISA + public static final int CS_MODE_MIPS64 = CS_MODE_64; // Mips64 ISA + + // Capstone error + public static final int CS_ERR_OK = 0; + public static final int CS_ERR_MEM = 1; // Out-Of-Memory error + public static final int CS_ERR_ARCH = 2; // Unsupported architecture + public static final int CS_ERR_HANDLE = 3; // Invalid handle + public static final int CS_ERR_CSH = 4; // Invalid csh argument + public static final int CS_ERR_MODE = 5; // Invalid/unsupported mode + public static final int CS_ERR_OPTION = 6; // Invalid/unsupported option: cs_option() + public static final int CS_ERR_DETAIL = 7; // Invalid/unsupported option: cs_option() + public static final int CS_ERR_MEMSETUP = 8; + public static final int CS_ERR_VERSION = 9; //Unsupported version (bindings) + public static final int CS_ERR_DIET = 10; //Information irrelevant in diet engine + public static final int CS_ERR_SKIPDATA = 11; //Access irrelevant data for "data" instruction in SKIPDATA mode + public static final int CS_ERR_X86_ATT = 12; //X86 AT&T syntax is unsupported (opt-out at compile time) + public static final int CS_ERR_X86_INTEL = 13; //X86 Intel syntax is unsupported (opt-out at compile time) + + // Capstone option type + public static final int CS_OPT_SYNTAX = 1; // Intel X86 asm syntax (CS_ARCH_X86 arch) + public static final int CS_OPT_DETAIL = 2; // Break down instruction structure into details + public static final int CS_OPT_MODE = 3; // Change engine's mode at run-time + public static final int CS_OPT_INVALID = 0; // No option specified + public static final int CS_OPT_MEM=4; // User-defined dynamic memory related functions + public static final int CS_OPT_SKIPDATA=5;// Skip data when disassembling. Then engine is in SKIPDATA mode. + public static final int CS_OPT_SKIPDATA_SETUP=6; // Setup user-defined function for SKIPDATA option + + // Capstone option value + public static final int CS_OPT_OFF = 0; // Turn OFF an option - default option of CS_OPT_DETAIL + public static final int CS_OPT_SYNTAX_INTEL = 1; // Intel X86 asm syntax - default syntax on X86 (CS_OPT_SYNTAX, CS_ARCH_X86) + public static final int CS_OPT_SYNTAX_ATT = 2; // ATT asm syntax (CS_OPT_SYNTAX, CS_ARCH_X86) + public static final int CS_OPT_ON = 3; // Turn ON an option (CS_OPT_DETAIL) + public static final int CS_OPT_SYNTAX_NOREGNAME = 3; // PPC asm syntax: Prints register name with only number (CS_OPT_SYNTAX) + + // Common instruction operand types - to be consistent across all architectures. + public static final int CS_OP_INVALID = 0; + public static final int CS_OP_REG = 1; + public static final int CS_OP_IMM = 2; + public static final int CS_OP_MEM = 3; + public static final int CS_OP_FP = 4; + + // Common instruction groups - to be consistent across all architectures. + public static final int CS_GRP_INVALID = 0; // uninitialized/invalid group. + public static final int CS_GRP_JUMP = 1; // all jump instructions (conditional+direct+indirect jumps) + public static final int CS_GRP_CALL = 2; // all call instructions + public static final int CS_GRP_RET = 3; // all return instructions + public static final int CS_GRP_INT = 4; // all interrupt instructions (int+syscall) + public static final int CS_GRP_IRET = 5; // all interrupt return instructions + + // Query id for cs_support() + public static final int CS_SUPPORT_DIET = CS_ARCH_ALL + 1; // diet mode + public static final int CS_SUPPORT_X86_REDUCE = CS_ARCH_ALL + 2; // X86 reduce mode + + protected class NativeStruct + { + private NativeLong csh; + private NativeLongByReference handleRef; + } + protected class NativeOptmem + { + /*typedef struct cs_opt_mem { + cs_malloc_t malloc; + cs_calloc_t calloc; + cs_realloc_t realloc; + cs_free_t free; + cs_vsnprintf_t vsnprintf; + } cs_opt_mem;*/ + Function malloc; + Function calloc; + Function realloc; + Function free; + Function vsnprintf; + } + + private static final CsInsn[] EMPTY_INSN = new CsInsn[0]; + + protected NativeStruct ns; // for memory retention + private CS cs; + public int arch; + public int mode; + private int syntax; + private int detail; + private boolean diet; + + public Capstone(int arch, int mode) + { + cs = (CS)Native.loadLibrary("capstone", CS.class); + int err=0; + int version = cs.cs_version(null, null); + if (version != (CS_API_MAJOR << 8) + CS_API_MINOR) + { + throw new RuntimeException("Different API version between core & binding (CS_ERR_VERSION)"); + } + this.arch = arch; + this.mode = mode; + ns = new NativeStruct(); + ns.handleRef = new NativeLongByReference(); + //NativeOptmem nom=new NativeOptmem(); + //nom.calloc = Function.getFunction("c", "calloc"); + //err = cs.cs_option((NativeLong)null, CS_OPT_MEM,new NativeLongByReference().getNativeLong); + cs.cs_setup_mem(); + if ((err = cs.cs_open(arch, mode, ns.handleRef)) != CS_ERR_OK) + { + throw new RuntimeException("ERROR: Wrong arch or mode" + err); + } + ns.csh = ns.handleRef.getValue(); + this.detail = CS_OPT_OFF; + this.diet = cs.cs_support(CS_SUPPORT_DIET); + } + + // return combined API version + public int version() + { + return cs.cs_version(null, null); + } + + // set Assembly syntax + public void setSyntax(int syntax) + { + if (cs.cs_option(ns.csh, CS_OPT_SYNTAX, new NativeLong(syntax)) == CS_ERR_OK) + { + this.syntax = syntax; + } + else + { + throw new RuntimeException("ERROR: Failed to set assembly syntax"); + } + } + + // set detail option at run-time + public void setDetail(int opt) + { + if (cs.cs_option(ns.csh, CS_OPT_DETAIL, new NativeLong(opt)) == CS_ERR_OK) + { + this.detail = opt; + } + else + { + throw new RuntimeException("ERROR: Failed to set detail option"); + } + } + + // set mode option at run-time + public void setMode(int opt) + { + if (cs.cs_option(ns.csh, CS_OPT_MODE, new NativeLong(opt)) == CS_ERR_OK) + { + this.mode = opt; + } + else + { + throw new RuntimeException("ERROR: Failed to set mode option"); + } + } + + // destructor automatically caled at destroyed time. + protected void finalize() + { + // FIXME: crashed on Ubuntu 14.04 64bit, OpenJDK java 1.6.0_33 + // cs.cs_close(ns.handleRef); + } + + // destructor automatically caled at destroyed time. + public int close() + { + return cs.cs_close(ns.handleRef); + } + + /** + * Disassemble instructions from @code assumed to be located at @address, + * stop when encountering first broken instruction. + * + * @param code The source machine code bytes. + * @param address The address of the first machine code byte. + * @return the array of successfully disassembled instructions, empty if no instruction could be disassembled. + */ + public CsInsn[] disasm(byte[] code, long address) + { + return disasm(code, address, 0); + } + + /** + * Disassemble up to @count instructions from @code assumed to be located at @address, + * stop when encountering first broken instruction. + * + * @param code The source machine code bytes. + * @param address The address of the first machine code byte. + * @param count The maximum number of instructions to disassemble, 0 for no maximum. + * @return the array of successfully disassembled instructions, empty if no instruction could be disassembled. + */ + public CsInsn[] disasm(byte[] code, long address, long count) + { + PointerByReference insnRef = new PointerByReference(); + + NativeLong c = cs.cs_disasm(ns.csh, code, new NativeLong(code.length), address, new NativeLong(count), insnRef); + + if (0 == c.intValue()) + { + return EMPTY_INSN; + } + + Pointer p = insnRef.getValue(); + _cs_insn byref = new _cs_insn(p); + + CsInsn[] allInsn = fromArrayRaw((_cs_insn[]) byref.toArray(c.intValue())); + + // free allocated memory + // cs.cs_free(p, c); + // FIXME(danghvu): Can't free because memory is still inside CsInsn + + return allInsn; + } + public CsInsn[] disasm(byte[] code,long offset, long address, long count) + { + PointerByReference insnRef = new PointerByReference(); + + NativeLong c = cs.cs_disasm2(ns.csh, code,new NativeLong(offset), new NativeLong(code.length), address, new NativeLong(count), insnRef); + + if (0 == c.intValue()) + { + return EMPTY_INSN; + } + + Pointer p = insnRef.getValue(); + _cs_insn byref = new _cs_insn(p); + + CsInsn[] allInsn = fromArrayRaw((_cs_insn[]) byref.toArray(c.intValue())); + + // free allocated memory + // cs.cs_free(p, c); + // FIXME(danghvu): Can't free because memory is still inside CsInsn + + return allInsn; + } +} diff --git a/app/src/main/java/capstone/Mips.java b/app/src/main/java/capstone/Mips.java new file mode 100644 index 00000000..d2354891 --- /dev/null +++ b/app/src/main/java/capstone/Mips.java @@ -0,0 +1,88 @@ +// Capstone Java binding +// By Nguyen Anh Quynh & Dang Hoang Vu, 2013 + +package capstone; + +import com.sun.jna.Structure; +import com.sun.jna.Union; + +import java.util.List; +import java.util.Arrays; + +import static capstone.Mips_const.*; + +public class Mips { + + public static class MemType extends Structure { + public int base; + public long disp; + + @Override + public List getFieldOrder() { + return Arrays.asList("base", "disp"); + } + } + + public static class OpValue extends Union { + public int reg; + public long imm; + public MemType mem; + + @Override + public List getFieldOrder() { + return Arrays.asList("reg", "imm", "mem"); + } + } + + public static class Operand extends Structure { + public int type; + public OpValue value; + + public void read() { + super.read(); + if (type == MIPS_OP_MEM) + value.setType(MemType.class); + if (type == MIPS_OP_IMM) + value.setType(Long.TYPE); + if (type == MIPS_OP_REG) + value.setType(Integer.TYPE); + if (type == MIPS_OP_INVALID) + return; + readField("value"); + } + @Override + public List getFieldOrder() { + return Arrays.asList("type", "value"); + } + } + + public static class UnionOpInfo extends Capstone.UnionOpInfo { + public byte op_count; + public Operand [] op; + + public UnionOpInfo() { + op = new Operand[8]; + } + + public void read() { + readField("op_count"); + op = new Operand[op_count]; + if (op_count != 0) + readField("op"); + } + + @Override + public List getFieldOrder() { + return Arrays.asList("op_count", "op"); + } + } + + public static class OpInfo extends Capstone.OpInfo { + + public Operand [] op; + + public OpInfo(UnionOpInfo e) { + op = e.op; + } + } +} diff --git a/app/src/main/java/capstone/Mips_const.java b/app/src/main/java/capstone/Mips_const.java new file mode 100644 index 00000000..b44ba68f --- /dev/null +++ b/app/src/main/java/capstone/Mips_const.java @@ -0,0 +1,842 @@ +// For Capstone Engine. AUTO-GENERATED FILE, DO NOT EDIT +package capstone; + +public class Mips_const { + + // Operand type for instruction's operands + + public static final int MIPS_OP_INVALID = 0; + public static final int MIPS_OP_REG = 1; + public static final int MIPS_OP_IMM = 2; + public static final int MIPS_OP_MEM = 3; + + // MIPS registers + + public static final int MIPS_REG_INVALID = 0; + + // General purpose registers + public static final int MIPS_REG_0 = 1; + public static final int MIPS_REG_1 = 2; + public static final int MIPS_REG_2 = 3; + public static final int MIPS_REG_3 = 4; + public static final int MIPS_REG_4 = 5; + public static final int MIPS_REG_5 = 6; + public static final int MIPS_REG_6 = 7; + public static final int MIPS_REG_7 = 8; + public static final int MIPS_REG_8 = 9; + public static final int MIPS_REG_9 = 10; + public static final int MIPS_REG_10 = 11; + public static final int MIPS_REG_11 = 12; + public static final int MIPS_REG_12 = 13; + public static final int MIPS_REG_13 = 14; + public static final int MIPS_REG_14 = 15; + public static final int MIPS_REG_15 = 16; + public static final int MIPS_REG_16 = 17; + public static final int MIPS_REG_17 = 18; + public static final int MIPS_REG_18 = 19; + public static final int MIPS_REG_19 = 20; + public static final int MIPS_REG_20 = 21; + public static final int MIPS_REG_21 = 22; + public static final int MIPS_REG_22 = 23; + public static final int MIPS_REG_23 = 24; + public static final int MIPS_REG_24 = 25; + public static final int MIPS_REG_25 = 26; + public static final int MIPS_REG_26 = 27; + public static final int MIPS_REG_27 = 28; + public static final int MIPS_REG_28 = 29; + public static final int MIPS_REG_29 = 30; + public static final int MIPS_REG_30 = 31; + public static final int MIPS_REG_31 = 32; + + // DSP registers + public static final int MIPS_REG_DSPCCOND = 33; + public static final int MIPS_REG_DSPCARRY = 34; + public static final int MIPS_REG_DSPEFI = 35; + public static final int MIPS_REG_DSPOUTFLAG = 36; + public static final int MIPS_REG_DSPOUTFLAG16_19 = 37; + public static final int MIPS_REG_DSPOUTFLAG20 = 38; + public static final int MIPS_REG_DSPOUTFLAG21 = 39; + public static final int MIPS_REG_DSPOUTFLAG22 = 40; + public static final int MIPS_REG_DSPOUTFLAG23 = 41; + public static final int MIPS_REG_DSPPOS = 42; + public static final int MIPS_REG_DSPSCOUNT = 43; + + // ACC registers + public static final int MIPS_REG_AC0 = 44; + public static final int MIPS_REG_AC1 = 45; + public static final int MIPS_REG_AC2 = 46; + public static final int MIPS_REG_AC3 = 47; + + // COP registers + public static final int MIPS_REG_CC0 = 48; + public static final int MIPS_REG_CC1 = 49; + public static final int MIPS_REG_CC2 = 50; + public static final int MIPS_REG_CC3 = 51; + public static final int MIPS_REG_CC4 = 52; + public static final int MIPS_REG_CC5 = 53; + public static final int MIPS_REG_CC6 = 54; + public static final int MIPS_REG_CC7 = 55; + + // FPU registers + public static final int MIPS_REG_F0 = 56; + public static final int MIPS_REG_F1 = 57; + public static final int MIPS_REG_F2 = 58; + public static final int MIPS_REG_F3 = 59; + public static final int MIPS_REG_F4 = 60; + public static final int MIPS_REG_F5 = 61; + public static final int MIPS_REG_F6 = 62; + public static final int MIPS_REG_F7 = 63; + public static final int MIPS_REG_F8 = 64; + public static final int MIPS_REG_F9 = 65; + public static final int MIPS_REG_F10 = 66; + public static final int MIPS_REG_F11 = 67; + public static final int MIPS_REG_F12 = 68; + public static final int MIPS_REG_F13 = 69; + public static final int MIPS_REG_F14 = 70; + public static final int MIPS_REG_F15 = 71; + public static final int MIPS_REG_F16 = 72; + public static final int MIPS_REG_F17 = 73; + public static final int MIPS_REG_F18 = 74; + public static final int MIPS_REG_F19 = 75; + public static final int MIPS_REG_F20 = 76; + public static final int MIPS_REG_F21 = 77; + public static final int MIPS_REG_F22 = 78; + public static final int MIPS_REG_F23 = 79; + public static final int MIPS_REG_F24 = 80; + public static final int MIPS_REG_F25 = 81; + public static final int MIPS_REG_F26 = 82; + public static final int MIPS_REG_F27 = 83; + public static final int MIPS_REG_F28 = 84; + public static final int MIPS_REG_F29 = 85; + public static final int MIPS_REG_F30 = 86; + public static final int MIPS_REG_F31 = 87; + public static final int MIPS_REG_FCC0 = 88; + public static final int MIPS_REG_FCC1 = 89; + public static final int MIPS_REG_FCC2 = 90; + public static final int MIPS_REG_FCC3 = 91; + public static final int MIPS_REG_FCC4 = 92; + public static final int MIPS_REG_FCC5 = 93; + public static final int MIPS_REG_FCC6 = 94; + public static final int MIPS_REG_FCC7 = 95; + + // AFPR128 + public static final int MIPS_REG_W0 = 96; + public static final int MIPS_REG_W1 = 97; + public static final int MIPS_REG_W2 = 98; + public static final int MIPS_REG_W3 = 99; + public static final int MIPS_REG_W4 = 100; + public static final int MIPS_REG_W5 = 101; + public static final int MIPS_REG_W6 = 102; + public static final int MIPS_REG_W7 = 103; + public static final int MIPS_REG_W8 = 104; + public static final int MIPS_REG_W9 = 105; + public static final int MIPS_REG_W10 = 106; + public static final int MIPS_REG_W11 = 107; + public static final int MIPS_REG_W12 = 108; + public static final int MIPS_REG_W13 = 109; + public static final int MIPS_REG_W14 = 110; + public static final int MIPS_REG_W15 = 111; + public static final int MIPS_REG_W16 = 112; + public static final int MIPS_REG_W17 = 113; + public static final int MIPS_REG_W18 = 114; + public static final int MIPS_REG_W19 = 115; + public static final int MIPS_REG_W20 = 116; + public static final int MIPS_REG_W21 = 117; + public static final int MIPS_REG_W22 = 118; + public static final int MIPS_REG_W23 = 119; + public static final int MIPS_REG_W24 = 120; + public static final int MIPS_REG_W25 = 121; + public static final int MIPS_REG_W26 = 122; + public static final int MIPS_REG_W27 = 123; + public static final int MIPS_REG_W28 = 124; + public static final int MIPS_REG_W29 = 125; + public static final int MIPS_REG_W30 = 126; + public static final int MIPS_REG_W31 = 127; + public static final int MIPS_REG_HI = 128; + public static final int MIPS_REG_LO = 129; + public static final int MIPS_REG_P0 = 130; + public static final int MIPS_REG_P1 = 131; + public static final int MIPS_REG_P2 = 132; + public static final int MIPS_REG_MPL0 = 133; + public static final int MIPS_REG_MPL1 = 134; + public static final int MIPS_REG_MPL2 = 135; + public static final int MIPS_REG_ENDING = 136; + public static final int MIPS_REG_ZERO = MIPS_REG_0; + public static final int MIPS_REG_AT = MIPS_REG_1; + public static final int MIPS_REG_V0 = MIPS_REG_2; + public static final int MIPS_REG_V1 = MIPS_REG_3; + public static final int MIPS_REG_A0 = MIPS_REG_4; + public static final int MIPS_REG_A1 = MIPS_REG_5; + public static final int MIPS_REG_A2 = MIPS_REG_6; + public static final int MIPS_REG_A3 = MIPS_REG_7; + public static final int MIPS_REG_T0 = MIPS_REG_8; + public static final int MIPS_REG_T1 = MIPS_REG_9; + public static final int MIPS_REG_T2 = MIPS_REG_10; + public static final int MIPS_REG_T3 = MIPS_REG_11; + public static final int MIPS_REG_T4 = MIPS_REG_12; + public static final int MIPS_REG_T5 = MIPS_REG_13; + public static final int MIPS_REG_T6 = MIPS_REG_14; + public static final int MIPS_REG_T7 = MIPS_REG_15; + public static final int MIPS_REG_S0 = MIPS_REG_16; + public static final int MIPS_REG_S1 = MIPS_REG_17; + public static final int MIPS_REG_S2 = MIPS_REG_18; + public static final int MIPS_REG_S3 = MIPS_REG_19; + public static final int MIPS_REG_S4 = MIPS_REG_20; + public static final int MIPS_REG_S5 = MIPS_REG_21; + public static final int MIPS_REG_S6 = MIPS_REG_22; + public static final int MIPS_REG_S7 = MIPS_REG_23; + public static final int MIPS_REG_T8 = MIPS_REG_24; + public static final int MIPS_REG_T9 = MIPS_REG_25; + public static final int MIPS_REG_K0 = MIPS_REG_26; + public static final int MIPS_REG_K1 = MIPS_REG_27; + public static final int MIPS_REG_GP = MIPS_REG_28; + public static final int MIPS_REG_SP = MIPS_REG_29; + public static final int MIPS_REG_FP = MIPS_REG_30; + public static final int MIPS_REG_S8 = MIPS_REG_30; + public static final int MIPS_REG_RA = MIPS_REG_31; + public static final int MIPS_REG_HI0 = MIPS_REG_AC0; + public static final int MIPS_REG_HI1 = MIPS_REG_AC1; + public static final int MIPS_REG_HI2 = MIPS_REG_AC2; + public static final int MIPS_REG_HI3 = MIPS_REG_AC3; + public static final int MIPS_REG_LO0 = MIPS_REG_HI0; + public static final int MIPS_REG_LO1 = MIPS_REG_HI1; + public static final int MIPS_REG_LO2 = MIPS_REG_HI2; + public static final int MIPS_REG_LO3 = MIPS_REG_HI3; + + // MIPS instruction + + public static final int MIPS_INS_INVALID = 0; + public static final int MIPS_INS_ABSQ_S = 1; + public static final int MIPS_INS_ADD = 2; + public static final int MIPS_INS_ADDIUPC = 3; + public static final int MIPS_INS_ADDQH = 4; + public static final int MIPS_INS_ADDQH_R = 5; + public static final int MIPS_INS_ADDQ = 6; + public static final int MIPS_INS_ADDQ_S = 7; + public static final int MIPS_INS_ADDSC = 8; + public static final int MIPS_INS_ADDS_A = 9; + public static final int MIPS_INS_ADDS_S = 10; + public static final int MIPS_INS_ADDS_U = 11; + public static final int MIPS_INS_ADDUH = 12; + public static final int MIPS_INS_ADDUH_R = 13; + public static final int MIPS_INS_ADDU = 14; + public static final int MIPS_INS_ADDU_S = 15; + public static final int MIPS_INS_ADDVI = 16; + public static final int MIPS_INS_ADDV = 17; + public static final int MIPS_INS_ADDWC = 18; + public static final int MIPS_INS_ADD_A = 19; + public static final int MIPS_INS_ADDI = 20; + public static final int MIPS_INS_ADDIU = 21; + public static final int MIPS_INS_ALIGN = 22; + public static final int MIPS_INS_ALUIPC = 23; + public static final int MIPS_INS_AND = 24; + public static final int MIPS_INS_ANDI = 25; + public static final int MIPS_INS_APPEND = 26; + public static final int MIPS_INS_ASUB_S = 27; + public static final int MIPS_INS_ASUB_U = 28; + public static final int MIPS_INS_AUI = 29; + public static final int MIPS_INS_AUIPC = 30; + public static final int MIPS_INS_AVER_S = 31; + public static final int MIPS_INS_AVER_U = 32; + public static final int MIPS_INS_AVE_S = 33; + public static final int MIPS_INS_AVE_U = 34; + public static final int MIPS_INS_BADDU = 35; + public static final int MIPS_INS_BAL = 36; + public static final int MIPS_INS_BALC = 37; + public static final int MIPS_INS_BALIGN = 38; + public static final int MIPS_INS_BC = 39; + public static final int MIPS_INS_BC0F = 40; + public static final int MIPS_INS_BC0FL = 41; + public static final int MIPS_INS_BC0T = 42; + public static final int MIPS_INS_BC0TL = 43; + public static final int MIPS_INS_BC1EQZ = 44; + public static final int MIPS_INS_BC1F = 45; + public static final int MIPS_INS_BC1FL = 46; + public static final int MIPS_INS_BC1NEZ = 47; + public static final int MIPS_INS_BC1T = 48; + public static final int MIPS_INS_BC1TL = 49; + public static final int MIPS_INS_BC2EQZ = 50; + public static final int MIPS_INS_BC2F = 51; + public static final int MIPS_INS_BC2FL = 52; + public static final int MIPS_INS_BC2NEZ = 53; + public static final int MIPS_INS_BC2T = 54; + public static final int MIPS_INS_BC2TL = 55; + public static final int MIPS_INS_BC3F = 56; + public static final int MIPS_INS_BC3FL = 57; + public static final int MIPS_INS_BC3T = 58; + public static final int MIPS_INS_BC3TL = 59; + public static final int MIPS_INS_BCLRI = 60; + public static final int MIPS_INS_BCLR = 61; + public static final int MIPS_INS_BEQ = 62; + public static final int MIPS_INS_BEQC = 63; + public static final int MIPS_INS_BEQL = 64; + public static final int MIPS_INS_BEQZALC = 65; + public static final int MIPS_INS_BEQZC = 66; + public static final int MIPS_INS_BGEC = 67; + public static final int MIPS_INS_BGEUC = 68; + public static final int MIPS_INS_BGEZ = 69; + public static final int MIPS_INS_BGEZAL = 70; + public static final int MIPS_INS_BGEZALC = 71; + public static final int MIPS_INS_BGEZALL = 72; + public static final int MIPS_INS_BGEZALS = 73; + public static final int MIPS_INS_BGEZC = 74; + public static final int MIPS_INS_BGEZL = 75; + public static final int MIPS_INS_BGTZ = 76; + public static final int MIPS_INS_BGTZALC = 77; + public static final int MIPS_INS_BGTZC = 78; + public static final int MIPS_INS_BGTZL = 79; + public static final int MIPS_INS_BINSLI = 80; + public static final int MIPS_INS_BINSL = 81; + public static final int MIPS_INS_BINSRI = 82; + public static final int MIPS_INS_BINSR = 83; + public static final int MIPS_INS_BITREV = 84; + public static final int MIPS_INS_BITSWAP = 85; + public static final int MIPS_INS_BLEZ = 86; + public static final int MIPS_INS_BLEZALC = 87; + public static final int MIPS_INS_BLEZC = 88; + public static final int MIPS_INS_BLEZL = 89; + public static final int MIPS_INS_BLTC = 90; + public static final int MIPS_INS_BLTUC = 91; + public static final int MIPS_INS_BLTZ = 92; + public static final int MIPS_INS_BLTZAL = 93; + public static final int MIPS_INS_BLTZALC = 94; + public static final int MIPS_INS_BLTZALL = 95; + public static final int MIPS_INS_BLTZALS = 96; + public static final int MIPS_INS_BLTZC = 97; + public static final int MIPS_INS_BLTZL = 98; + public static final int MIPS_INS_BMNZI = 99; + public static final int MIPS_INS_BMNZ = 100; + public static final int MIPS_INS_BMZI = 101; + public static final int MIPS_INS_BMZ = 102; + public static final int MIPS_INS_BNE = 103; + public static final int MIPS_INS_BNEC = 104; + public static final int MIPS_INS_BNEGI = 105; + public static final int MIPS_INS_BNEG = 106; + public static final int MIPS_INS_BNEL = 107; + public static final int MIPS_INS_BNEZALC = 108; + public static final int MIPS_INS_BNEZC = 109; + public static final int MIPS_INS_BNVC = 110; + public static final int MIPS_INS_BNZ = 111; + public static final int MIPS_INS_BOVC = 112; + public static final int MIPS_INS_BPOSGE32 = 113; + public static final int MIPS_INS_BREAK = 114; + public static final int MIPS_INS_BSELI = 115; + public static final int MIPS_INS_BSEL = 116; + public static final int MIPS_INS_BSETI = 117; + public static final int MIPS_INS_BSET = 118; + public static final int MIPS_INS_BZ = 119; + public static final int MIPS_INS_BEQZ = 120; + public static final int MIPS_INS_B = 121; + public static final int MIPS_INS_BNEZ = 122; + public static final int MIPS_INS_BTEQZ = 123; + public static final int MIPS_INS_BTNEZ = 124; + public static final int MIPS_INS_CACHE = 125; + public static final int MIPS_INS_CEIL = 126; + public static final int MIPS_INS_CEQI = 127; + public static final int MIPS_INS_CEQ = 128; + public static final int MIPS_INS_CFC1 = 129; + public static final int MIPS_INS_CFCMSA = 130; + public static final int MIPS_INS_CINS = 131; + public static final int MIPS_INS_CINS32 = 132; + public static final int MIPS_INS_CLASS = 133; + public static final int MIPS_INS_CLEI_S = 134; + public static final int MIPS_INS_CLEI_U = 135; + public static final int MIPS_INS_CLE_S = 136; + public static final int MIPS_INS_CLE_U = 137; + public static final int MIPS_INS_CLO = 138; + public static final int MIPS_INS_CLTI_S = 139; + public static final int MIPS_INS_CLTI_U = 140; + public static final int MIPS_INS_CLT_S = 141; + public static final int MIPS_INS_CLT_U = 142; + public static final int MIPS_INS_CLZ = 143; + public static final int MIPS_INS_CMPGDU = 144; + public static final int MIPS_INS_CMPGU = 145; + public static final int MIPS_INS_CMPU = 146; + public static final int MIPS_INS_CMP = 147; + public static final int MIPS_INS_COPY_S = 148; + public static final int MIPS_INS_COPY_U = 149; + public static final int MIPS_INS_CTC1 = 150; + public static final int MIPS_INS_CTCMSA = 151; + public static final int MIPS_INS_CVT = 152; + public static final int MIPS_INS_C = 153; + public static final int MIPS_INS_CMPI = 154; + public static final int MIPS_INS_DADD = 155; + public static final int MIPS_INS_DADDI = 156; + public static final int MIPS_INS_DADDIU = 157; + public static final int MIPS_INS_DADDU = 158; + public static final int MIPS_INS_DAHI = 159; + public static final int MIPS_INS_DALIGN = 160; + public static final int MIPS_INS_DATI = 161; + public static final int MIPS_INS_DAUI = 162; + public static final int MIPS_INS_DBITSWAP = 163; + public static final int MIPS_INS_DCLO = 164; + public static final int MIPS_INS_DCLZ = 165; + public static final int MIPS_INS_DDIV = 166; + public static final int MIPS_INS_DDIVU = 167; + public static final int MIPS_INS_DERET = 168; + public static final int MIPS_INS_DEXT = 169; + public static final int MIPS_INS_DEXTM = 170; + public static final int MIPS_INS_DEXTU = 171; + public static final int MIPS_INS_DI = 172; + public static final int MIPS_INS_DINS = 173; + public static final int MIPS_INS_DINSM = 174; + public static final int MIPS_INS_DINSU = 175; + public static final int MIPS_INS_DIV = 176; + public static final int MIPS_INS_DIVU = 177; + public static final int MIPS_INS_DIV_S = 178; + public static final int MIPS_INS_DIV_U = 179; + public static final int MIPS_INS_DLSA = 180; + public static final int MIPS_INS_DMFC0 = 181; + public static final int MIPS_INS_DMFC1 = 182; + public static final int MIPS_INS_DMFC2 = 183; + public static final int MIPS_INS_DMOD = 184; + public static final int MIPS_INS_DMODU = 185; + public static final int MIPS_INS_DMTC0 = 186; + public static final int MIPS_INS_DMTC1 = 187; + public static final int MIPS_INS_DMTC2 = 188; + public static final int MIPS_INS_DMUH = 189; + public static final int MIPS_INS_DMUHU = 190; + public static final int MIPS_INS_DMUL = 191; + public static final int MIPS_INS_DMULT = 192; + public static final int MIPS_INS_DMULTU = 193; + public static final int MIPS_INS_DMULU = 194; + public static final int MIPS_INS_DOTP_S = 195; + public static final int MIPS_INS_DOTP_U = 196; + public static final int MIPS_INS_DPADD_S = 197; + public static final int MIPS_INS_DPADD_U = 198; + public static final int MIPS_INS_DPAQX_SA = 199; + public static final int MIPS_INS_DPAQX_S = 200; + public static final int MIPS_INS_DPAQ_SA = 201; + public static final int MIPS_INS_DPAQ_S = 202; + public static final int MIPS_INS_DPAU = 203; + public static final int MIPS_INS_DPAX = 204; + public static final int MIPS_INS_DPA = 205; + public static final int MIPS_INS_DPOP = 206; + public static final int MIPS_INS_DPSQX_SA = 207; + public static final int MIPS_INS_DPSQX_S = 208; + public static final int MIPS_INS_DPSQ_SA = 209; + public static final int MIPS_INS_DPSQ_S = 210; + public static final int MIPS_INS_DPSUB_S = 211; + public static final int MIPS_INS_DPSUB_U = 212; + public static final int MIPS_INS_DPSU = 213; + public static final int MIPS_INS_DPSX = 214; + public static final int MIPS_INS_DPS = 215; + public static final int MIPS_INS_DROTR = 216; + public static final int MIPS_INS_DROTR32 = 217; + public static final int MIPS_INS_DROTRV = 218; + public static final int MIPS_INS_DSBH = 219; + public static final int MIPS_INS_DSHD = 220; + public static final int MIPS_INS_DSLL = 221; + public static final int MIPS_INS_DSLL32 = 222; + public static final int MIPS_INS_DSLLV = 223; + public static final int MIPS_INS_DSRA = 224; + public static final int MIPS_INS_DSRA32 = 225; + public static final int MIPS_INS_DSRAV = 226; + public static final int MIPS_INS_DSRL = 227; + public static final int MIPS_INS_DSRL32 = 228; + public static final int MIPS_INS_DSRLV = 229; + public static final int MIPS_INS_DSUB = 230; + public static final int MIPS_INS_DSUBU = 231; + public static final int MIPS_INS_EHB = 232; + public static final int MIPS_INS_EI = 233; + public static final int MIPS_INS_ERET = 234; + public static final int MIPS_INS_EXT = 235; + public static final int MIPS_INS_EXTP = 236; + public static final int MIPS_INS_EXTPDP = 237; + public static final int MIPS_INS_EXTPDPV = 238; + public static final int MIPS_INS_EXTPV = 239; + public static final int MIPS_INS_EXTRV_RS = 240; + public static final int MIPS_INS_EXTRV_R = 241; + public static final int MIPS_INS_EXTRV_S = 242; + public static final int MIPS_INS_EXTRV = 243; + public static final int MIPS_INS_EXTR_RS = 244; + public static final int MIPS_INS_EXTR_R = 245; + public static final int MIPS_INS_EXTR_S = 246; + public static final int MIPS_INS_EXTR = 247; + public static final int MIPS_INS_EXTS = 248; + public static final int MIPS_INS_EXTS32 = 249; + public static final int MIPS_INS_ABS = 250; + public static final int MIPS_INS_FADD = 251; + public static final int MIPS_INS_FCAF = 252; + public static final int MIPS_INS_FCEQ = 253; + public static final int MIPS_INS_FCLASS = 254; + public static final int MIPS_INS_FCLE = 255; + public static final int MIPS_INS_FCLT = 256; + public static final int MIPS_INS_FCNE = 257; + public static final int MIPS_INS_FCOR = 258; + public static final int MIPS_INS_FCUEQ = 259; + public static final int MIPS_INS_FCULE = 260; + public static final int MIPS_INS_FCULT = 261; + public static final int MIPS_INS_FCUNE = 262; + public static final int MIPS_INS_FCUN = 263; + public static final int MIPS_INS_FDIV = 264; + public static final int MIPS_INS_FEXDO = 265; + public static final int MIPS_INS_FEXP2 = 266; + public static final int MIPS_INS_FEXUPL = 267; + public static final int MIPS_INS_FEXUPR = 268; + public static final int MIPS_INS_FFINT_S = 269; + public static final int MIPS_INS_FFINT_U = 270; + public static final int MIPS_INS_FFQL = 271; + public static final int MIPS_INS_FFQR = 272; + public static final int MIPS_INS_FILL = 273; + public static final int MIPS_INS_FLOG2 = 274; + public static final int MIPS_INS_FLOOR = 275; + public static final int MIPS_INS_FMADD = 276; + public static final int MIPS_INS_FMAX_A = 277; + public static final int MIPS_INS_FMAX = 278; + public static final int MIPS_INS_FMIN_A = 279; + public static final int MIPS_INS_FMIN = 280; + public static final int MIPS_INS_MOV = 281; + public static final int MIPS_INS_FMSUB = 282; + public static final int MIPS_INS_FMUL = 283; + public static final int MIPS_INS_MUL = 284; + public static final int MIPS_INS_NEG = 285; + public static final int MIPS_INS_FRCP = 286; + public static final int MIPS_INS_FRINT = 287; + public static final int MIPS_INS_FRSQRT = 288; + public static final int MIPS_INS_FSAF = 289; + public static final int MIPS_INS_FSEQ = 290; + public static final int MIPS_INS_FSLE = 291; + public static final int MIPS_INS_FSLT = 292; + public static final int MIPS_INS_FSNE = 293; + public static final int MIPS_INS_FSOR = 294; + public static final int MIPS_INS_FSQRT = 295; + public static final int MIPS_INS_SQRT = 296; + public static final int MIPS_INS_FSUB = 297; + public static final int MIPS_INS_SUB = 298; + public static final int MIPS_INS_FSUEQ = 299; + public static final int MIPS_INS_FSULE = 300; + public static final int MIPS_INS_FSULT = 301; + public static final int MIPS_INS_FSUNE = 302; + public static final int MIPS_INS_FSUN = 303; + public static final int MIPS_INS_FTINT_S = 304; + public static final int MIPS_INS_FTINT_U = 305; + public static final int MIPS_INS_FTQ = 306; + public static final int MIPS_INS_FTRUNC_S = 307; + public static final int MIPS_INS_FTRUNC_U = 308; + public static final int MIPS_INS_HADD_S = 309; + public static final int MIPS_INS_HADD_U = 310; + public static final int MIPS_INS_HSUB_S = 311; + public static final int MIPS_INS_HSUB_U = 312; + public static final int MIPS_INS_ILVEV = 313; + public static final int MIPS_INS_ILVL = 314; + public static final int MIPS_INS_ILVOD = 315; + public static final int MIPS_INS_ILVR = 316; + public static final int MIPS_INS_INS = 317; + public static final int MIPS_INS_INSERT = 318; + public static final int MIPS_INS_INSV = 319; + public static final int MIPS_INS_INSVE = 320; + public static final int MIPS_INS_J = 321; + public static final int MIPS_INS_JAL = 322; + public static final int MIPS_INS_JALR = 323; + public static final int MIPS_INS_JALRS = 324; + public static final int MIPS_INS_JALS = 325; + public static final int MIPS_INS_JALX = 326; + public static final int MIPS_INS_JIALC = 327; + public static final int MIPS_INS_JIC = 328; + public static final int MIPS_INS_JR = 329; + public static final int MIPS_INS_JRADDIUSP = 330; + public static final int MIPS_INS_JRC = 331; + public static final int MIPS_INS_JALRC = 332; + public static final int MIPS_INS_LB = 333; + public static final int MIPS_INS_LBUX = 334; + public static final int MIPS_INS_LBU = 335; + public static final int MIPS_INS_LD = 336; + public static final int MIPS_INS_LDC1 = 337; + public static final int MIPS_INS_LDC2 = 338; + public static final int MIPS_INS_LDC3 = 339; + public static final int MIPS_INS_LDI = 340; + public static final int MIPS_INS_LDL = 341; + public static final int MIPS_INS_LDPC = 342; + public static final int MIPS_INS_LDR = 343; + public static final int MIPS_INS_LDXC1 = 344; + public static final int MIPS_INS_LH = 345; + public static final int MIPS_INS_LHX = 346; + public static final int MIPS_INS_LHU = 347; + public static final int MIPS_INS_LL = 348; + public static final int MIPS_INS_LLD = 349; + public static final int MIPS_INS_LSA = 350; + public static final int MIPS_INS_LUXC1 = 351; + public static final int MIPS_INS_LUI = 352; + public static final int MIPS_INS_LW = 353; + public static final int MIPS_INS_LWC1 = 354; + public static final int MIPS_INS_LWC2 = 355; + public static final int MIPS_INS_LWC3 = 356; + public static final int MIPS_INS_LWL = 357; + public static final int MIPS_INS_LWPC = 358; + public static final int MIPS_INS_LWR = 359; + public static final int MIPS_INS_LWUPC = 360; + public static final int MIPS_INS_LWU = 361; + public static final int MIPS_INS_LWX = 362; + public static final int MIPS_INS_LWXC1 = 363; + public static final int MIPS_INS_LI = 364; + public static final int MIPS_INS_MADD = 365; + public static final int MIPS_INS_MADDF = 366; + public static final int MIPS_INS_MADDR_Q = 367; + public static final int MIPS_INS_MADDU = 368; + public static final int MIPS_INS_MADDV = 369; + public static final int MIPS_INS_MADD_Q = 370; + public static final int MIPS_INS_MAQ_SA = 371; + public static final int MIPS_INS_MAQ_S = 372; + public static final int MIPS_INS_MAXA = 373; + public static final int MIPS_INS_MAXI_S = 374; + public static final int MIPS_INS_MAXI_U = 375; + public static final int MIPS_INS_MAX_A = 376; + public static final int MIPS_INS_MAX = 377; + public static final int MIPS_INS_MAX_S = 378; + public static final int MIPS_INS_MAX_U = 379; + public static final int MIPS_INS_MFC0 = 380; + public static final int MIPS_INS_MFC1 = 381; + public static final int MIPS_INS_MFC2 = 382; + public static final int MIPS_INS_MFHC1 = 383; + public static final int MIPS_INS_MFHI = 384; + public static final int MIPS_INS_MFLO = 385; + public static final int MIPS_INS_MINA = 386; + public static final int MIPS_INS_MINI_S = 387; + public static final int MIPS_INS_MINI_U = 388; + public static final int MIPS_INS_MIN_A = 389; + public static final int MIPS_INS_MIN = 390; + public static final int MIPS_INS_MIN_S = 391; + public static final int MIPS_INS_MIN_U = 392; + public static final int MIPS_INS_MOD = 393; + public static final int MIPS_INS_MODSUB = 394; + public static final int MIPS_INS_MODU = 395; + public static final int MIPS_INS_MOD_S = 396; + public static final int MIPS_INS_MOD_U = 397; + public static final int MIPS_INS_MOVE = 398; + public static final int MIPS_INS_MOVF = 399; + public static final int MIPS_INS_MOVN = 400; + public static final int MIPS_INS_MOVT = 401; + public static final int MIPS_INS_MOVZ = 402; + public static final int MIPS_INS_MSUB = 403; + public static final int MIPS_INS_MSUBF = 404; + public static final int MIPS_INS_MSUBR_Q = 405; + public static final int MIPS_INS_MSUBU = 406; + public static final int MIPS_INS_MSUBV = 407; + public static final int MIPS_INS_MSUB_Q = 408; + public static final int MIPS_INS_MTC0 = 409; + public static final int MIPS_INS_MTC1 = 410; + public static final int MIPS_INS_MTC2 = 411; + public static final int MIPS_INS_MTHC1 = 412; + public static final int MIPS_INS_MTHI = 413; + public static final int MIPS_INS_MTHLIP = 414; + public static final int MIPS_INS_MTLO = 415; + public static final int MIPS_INS_MTM0 = 416; + public static final int MIPS_INS_MTM1 = 417; + public static final int MIPS_INS_MTM2 = 418; + public static final int MIPS_INS_MTP0 = 419; + public static final int MIPS_INS_MTP1 = 420; + public static final int MIPS_INS_MTP2 = 421; + public static final int MIPS_INS_MUH = 422; + public static final int MIPS_INS_MUHU = 423; + public static final int MIPS_INS_MULEQ_S = 424; + public static final int MIPS_INS_MULEU_S = 425; + public static final int MIPS_INS_MULQ_RS = 426; + public static final int MIPS_INS_MULQ_S = 427; + public static final int MIPS_INS_MULR_Q = 428; + public static final int MIPS_INS_MULSAQ_S = 429; + public static final int MIPS_INS_MULSA = 430; + public static final int MIPS_INS_MULT = 431; + public static final int MIPS_INS_MULTU = 432; + public static final int MIPS_INS_MULU = 433; + public static final int MIPS_INS_MULV = 434; + public static final int MIPS_INS_MUL_Q = 435; + public static final int MIPS_INS_MUL_S = 436; + public static final int MIPS_INS_NLOC = 437; + public static final int MIPS_INS_NLZC = 438; + public static final int MIPS_INS_NMADD = 439; + public static final int MIPS_INS_NMSUB = 440; + public static final int MIPS_INS_NOR = 441; + public static final int MIPS_INS_NORI = 442; + public static final int MIPS_INS_NOT = 443; + public static final int MIPS_INS_OR = 444; + public static final int MIPS_INS_ORI = 445; + public static final int MIPS_INS_PACKRL = 446; + public static final int MIPS_INS_PAUSE = 447; + public static final int MIPS_INS_PCKEV = 448; + public static final int MIPS_INS_PCKOD = 449; + public static final int MIPS_INS_PCNT = 450; + public static final int MIPS_INS_PICK = 451; + public static final int MIPS_INS_POP = 452; + public static final int MIPS_INS_PRECEQU = 453; + public static final int MIPS_INS_PRECEQ = 454; + public static final int MIPS_INS_PRECEU = 455; + public static final int MIPS_INS_PRECRQU_S = 456; + public static final int MIPS_INS_PRECRQ = 457; + public static final int MIPS_INS_PRECRQ_RS = 458; + public static final int MIPS_INS_PRECR = 459; + public static final int MIPS_INS_PRECR_SRA = 460; + public static final int MIPS_INS_PRECR_SRA_R = 461; + public static final int MIPS_INS_PREF = 462; + public static final int MIPS_INS_PREPEND = 463; + public static final int MIPS_INS_RADDU = 464; + public static final int MIPS_INS_RDDSP = 465; + public static final int MIPS_INS_RDHWR = 466; + public static final int MIPS_INS_REPLV = 467; + public static final int MIPS_INS_REPL = 468; + public static final int MIPS_INS_RINT = 469; + public static final int MIPS_INS_ROTR = 470; + public static final int MIPS_INS_ROTRV = 471; + public static final int MIPS_INS_ROUND = 472; + public static final int MIPS_INS_SAT_S = 473; + public static final int MIPS_INS_SAT_U = 474; + public static final int MIPS_INS_SB = 475; + public static final int MIPS_INS_SC = 476; + public static final int MIPS_INS_SCD = 477; + public static final int MIPS_INS_SD = 478; + public static final int MIPS_INS_SDBBP = 479; + public static final int MIPS_INS_SDC1 = 480; + public static final int MIPS_INS_SDC2 = 481; + public static final int MIPS_INS_SDC3 = 482; + public static final int MIPS_INS_SDL = 483; + public static final int MIPS_INS_SDR = 484; + public static final int MIPS_INS_SDXC1 = 485; + public static final int MIPS_INS_SEB = 486; + public static final int MIPS_INS_SEH = 487; + public static final int MIPS_INS_SELEQZ = 488; + public static final int MIPS_INS_SELNEZ = 489; + public static final int MIPS_INS_SEL = 490; + public static final int MIPS_INS_SEQ = 491; + public static final int MIPS_INS_SEQI = 492; + public static final int MIPS_INS_SH = 493; + public static final int MIPS_INS_SHF = 494; + public static final int MIPS_INS_SHILO = 495; + public static final int MIPS_INS_SHILOV = 496; + public static final int MIPS_INS_SHLLV = 497; + public static final int MIPS_INS_SHLLV_S = 498; + public static final int MIPS_INS_SHLL = 499; + public static final int MIPS_INS_SHLL_S = 500; + public static final int MIPS_INS_SHRAV = 501; + public static final int MIPS_INS_SHRAV_R = 502; + public static final int MIPS_INS_SHRA = 503; + public static final int MIPS_INS_SHRA_R = 504; + public static final int MIPS_INS_SHRLV = 505; + public static final int MIPS_INS_SHRL = 506; + public static final int MIPS_INS_SLDI = 507; + public static final int MIPS_INS_SLD = 508; + public static final int MIPS_INS_SLL = 509; + public static final int MIPS_INS_SLLI = 510; + public static final int MIPS_INS_SLLV = 511; + public static final int MIPS_INS_SLT = 512; + public static final int MIPS_INS_SLTI = 513; + public static final int MIPS_INS_SLTIU = 514; + public static final int MIPS_INS_SLTU = 515; + public static final int MIPS_INS_SNE = 516; + public static final int MIPS_INS_SNEI = 517; + public static final int MIPS_INS_SPLATI = 518; + public static final int MIPS_INS_SPLAT = 519; + public static final int MIPS_INS_SRA = 520; + public static final int MIPS_INS_SRAI = 521; + public static final int MIPS_INS_SRARI = 522; + public static final int MIPS_INS_SRAR = 523; + public static final int MIPS_INS_SRAV = 524; + public static final int MIPS_INS_SRL = 525; + public static final int MIPS_INS_SRLI = 526; + public static final int MIPS_INS_SRLRI = 527; + public static final int MIPS_INS_SRLR = 528; + public static final int MIPS_INS_SRLV = 529; + public static final int MIPS_INS_SSNOP = 530; + public static final int MIPS_INS_ST = 531; + public static final int MIPS_INS_SUBQH = 532; + public static final int MIPS_INS_SUBQH_R = 533; + public static final int MIPS_INS_SUBQ = 534; + public static final int MIPS_INS_SUBQ_S = 535; + public static final int MIPS_INS_SUBSUS_U = 536; + public static final int MIPS_INS_SUBSUU_S = 537; + public static final int MIPS_INS_SUBS_S = 538; + public static final int MIPS_INS_SUBS_U = 539; + public static final int MIPS_INS_SUBUH = 540; + public static final int MIPS_INS_SUBUH_R = 541; + public static final int MIPS_INS_SUBU = 542; + public static final int MIPS_INS_SUBU_S = 543; + public static final int MIPS_INS_SUBVI = 544; + public static final int MIPS_INS_SUBV = 545; + public static final int MIPS_INS_SUXC1 = 546; + public static final int MIPS_INS_SW = 547; + public static final int MIPS_INS_SWC1 = 548; + public static final int MIPS_INS_SWC2 = 549; + public static final int MIPS_INS_SWC3 = 550; + public static final int MIPS_INS_SWL = 551; + public static final int MIPS_INS_SWR = 552; + public static final int MIPS_INS_SWXC1 = 553; + public static final int MIPS_INS_SYNC = 554; + public static final int MIPS_INS_SYSCALL = 555; + public static final int MIPS_INS_TEQ = 556; + public static final int MIPS_INS_TEQI = 557; + public static final int MIPS_INS_TGE = 558; + public static final int MIPS_INS_TGEI = 559; + public static final int MIPS_INS_TGEIU = 560; + public static final int MIPS_INS_TGEU = 561; + public static final int MIPS_INS_TLBP = 562; + public static final int MIPS_INS_TLBR = 563; + public static final int MIPS_INS_TLBWI = 564; + public static final int MIPS_INS_TLBWR = 565; + public static final int MIPS_INS_TLT = 566; + public static final int MIPS_INS_TLTI = 567; + public static final int MIPS_INS_TLTIU = 568; + public static final int MIPS_INS_TLTU = 569; + public static final int MIPS_INS_TNE = 570; + public static final int MIPS_INS_TNEI = 571; + public static final int MIPS_INS_TRUNC = 572; + public static final int MIPS_INS_V3MULU = 573; + public static final int MIPS_INS_VMM0 = 574; + public static final int MIPS_INS_VMULU = 575; + public static final int MIPS_INS_VSHF = 576; + public static final int MIPS_INS_WAIT = 577; + public static final int MIPS_INS_WRDSP = 578; + public static final int MIPS_INS_WSBH = 579; + public static final int MIPS_INS_XOR = 580; + public static final int MIPS_INS_XORI = 581; + + // some alias instructions + public static final int MIPS_INS_NOP = 582; + public static final int MIPS_INS_NEGU = 583; + + // special instructions + public static final int MIPS_INS_JALR_HB = 584; + public static final int MIPS_INS_JR_HB = 585; + public static final int MIPS_INS_ENDING = 586; + + // Group of MIPS instructions + + public static final int MIPS_GRP_INVALID = 0; + + // Generic groups + public static final int MIPS_GRP_JUMP = 1; + + // Architecture-specific groups + public static final int MIPS_GRP_BITCOUNT = 128; + public static final int MIPS_GRP_DSP = 129; + public static final int MIPS_GRP_DSPR2 = 130; + public static final int MIPS_GRP_FPIDX = 131; + public static final int MIPS_GRP_MSA = 132; + public static final int MIPS_GRP_MIPS32R2 = 133; + public static final int MIPS_GRP_MIPS64 = 134; + public static final int MIPS_GRP_MIPS64R2 = 135; + public static final int MIPS_GRP_SEINREG = 136; + public static final int MIPS_GRP_STDENC = 137; + public static final int MIPS_GRP_SWAP = 138; + public static final int MIPS_GRP_MICROMIPS = 139; + public static final int MIPS_GRP_MIPS16MODE = 140; + public static final int MIPS_GRP_FP64BIT = 141; + public static final int MIPS_GRP_NONANSFPMATH = 142; + public static final int MIPS_GRP_NOTFP64BIT = 143; + public static final int MIPS_GRP_NOTINMICROMIPS = 144; + public static final int MIPS_GRP_NOTNACL = 145; + public static final int MIPS_GRP_NOTMIPS32R6 = 146; + public static final int MIPS_GRP_NOTMIPS64R6 = 147; + public static final int MIPS_GRP_CNMIPS = 148; + public static final int MIPS_GRP_MIPS32 = 149; + public static final int MIPS_GRP_MIPS32R6 = 150; + public static final int MIPS_GRP_MIPS64R6 = 151; + public static final int MIPS_GRP_MIPS2 = 152; + public static final int MIPS_GRP_MIPS3 = 153; + public static final int MIPS_GRP_MIPS3_32 = 154; + public static final int MIPS_GRP_MIPS3_32R2 = 155; + public static final int MIPS_GRP_MIPS4_32 = 156; + public static final int MIPS_GRP_MIPS4_32R2 = 157; + public static final int MIPS_GRP_MIPS5_32R2 = 158; + public static final int MIPS_GRP_GP32BIT = 159; + public static final int MIPS_GRP_GP64BIT = 160; + public static final int MIPS_GRP_ENDING = 161; +} \ No newline at end of file diff --git a/app/src/main/java/capstone/Ppc.java b/app/src/main/java/capstone/Ppc.java new file mode 100644 index 00000000..25eeb387 --- /dev/null +++ b/app/src/main/java/capstone/Ppc.java @@ -0,0 +1,109 @@ +// Capstone Java binding +// By Nguyen Anh Quynh & Dang Hoang Vu, 2013 + +package capstone; + +import com.sun.jna.Structure; +import com.sun.jna.Union; + +import java.util.List; +import java.util.Arrays; + +import static capstone.Ppc_const.*; + +public class Ppc { + + public static class MemType extends Structure { + public int base; + public int disp; + + @Override + public List getFieldOrder() { + return Arrays.asList("base", "disp"); + } + } + + public static class CrxType extends Structure { + public int scale; + public int reg; + public int cond; + + @Override + public List getFieldOrder() { + return Arrays.asList("scale", "reg", "cond"); + } + } + + public static class OpValue extends Union { + public int reg; + public int imm; + public MemType mem; + public CrxType crx; + } + + public static class Operand extends Structure { + public int type; + public OpValue value; + + public void read() { + readField("type"); + if (type == PPC_OP_MEM) + value.setType(MemType.class); + if (type == PPC_OP_CRX) + value.setType(CrxType.class); + if (type == PPC_OP_IMM || type == PPC_OP_REG) + value.setType(Integer.TYPE); + if (type == PPC_OP_INVALID) + return; + readField("value"); + } + + @Override + public List getFieldOrder() { + return Arrays.asList("type", "value"); + } + } + + public static class UnionOpInfo extends Capstone.UnionOpInfo { + public int bc; + public int bh; + public byte update_cr0; + public byte op_count; + + public Operand [] op; + + public UnionOpInfo() { + op = new Operand[8]; + } + + public void read() { + readField("bc"); + readField("bh"); + readField("update_cr0"); + readField("op_count"); + op = new Operand[op_count]; + if (op_count != 0) + readField("op"); + } + + @Override + public List getFieldOrder() { + return Arrays.asList("bc", "bh", "update_cr0", "op_count", "op"); + } + } + + public static class OpInfo extends Capstone.OpInfo { + public int bc; + public int bh; + public boolean updateCr0; + + public Operand [] op; + + public OpInfo(UnionOpInfo op_info) { + bc = op_info.bc; + bh = op_info.bh; + updateCr0 = (op_info.update_cr0 > 0); + op = op_info.op; + } + } +} diff --git a/app/src/main/java/capstone/Ppc_const.java b/app/src/main/java/capstone/Ppc_const.java new file mode 100644 index 00000000..8856c974 --- /dev/null +++ b/app/src/main/java/capstone/Ppc_const.java @@ -0,0 +1,1173 @@ +// For Capstone Engine. AUTO-GENERATED FILE, DO NOT EDIT +package capstone; + +public class Ppc_const { + + // PPC branch codes for some branch instructions + + public static final int PPC_BC_INVALID = 0; + public static final int PPC_BC_LT = (0<<5)|12; + public static final int PPC_BC_LE = (1<<5)|4; + public static final int PPC_BC_EQ = (2<<5)|12; + public static final int PPC_BC_GE = (0<<5)|4; + public static final int PPC_BC_GT = (1<<5)|12; + public static final int PPC_BC_NE = (2<<5)|4; + public static final int PPC_BC_UN = (3<<5)|12; + public static final int PPC_BC_NU = (3<<5)|4; + public static final int PPC_BC_SO = (4<<5)|12; + public static final int PPC_BC_NS = (4<<5)|4; + + // PPC branch hint for some branch instructions + + public static final int PPC_BH_INVALID = 0; + public static final int PPC_BH_PLUS = 1; + public static final int PPC_BH_MINUS = 2; + + // PPC registers + + public static final int PPC_REG_INVALID = 0; + public static final int PPC_REG_CARRY = 1; + public static final int PPC_REG_CC = 2; + public static final int PPC_REG_CR0 = 3; + public static final int PPC_REG_CR1 = 4; + public static final int PPC_REG_CR2 = 5; + public static final int PPC_REG_CR3 = 6; + public static final int PPC_REG_CR4 = 7; + public static final int PPC_REG_CR5 = 8; + public static final int PPC_REG_CR6 = 9; + public static final int PPC_REG_CR7 = 10; + public static final int PPC_REG_CTR = 11; + public static final int PPC_REG_F0 = 12; + public static final int PPC_REG_F1 = 13; + public static final int PPC_REG_F2 = 14; + public static final int PPC_REG_F3 = 15; + public static final int PPC_REG_F4 = 16; + public static final int PPC_REG_F5 = 17; + public static final int PPC_REG_F6 = 18; + public static final int PPC_REG_F7 = 19; + public static final int PPC_REG_F8 = 20; + public static final int PPC_REG_F9 = 21; + public static final int PPC_REG_F10 = 22; + public static final int PPC_REG_F11 = 23; + public static final int PPC_REG_F12 = 24; + public static final int PPC_REG_F13 = 25; + public static final int PPC_REG_F14 = 26; + public static final int PPC_REG_F15 = 27; + public static final int PPC_REG_F16 = 28; + public static final int PPC_REG_F17 = 29; + public static final int PPC_REG_F18 = 30; + public static final int PPC_REG_F19 = 31; + public static final int PPC_REG_F20 = 32; + public static final int PPC_REG_F21 = 33; + public static final int PPC_REG_F22 = 34; + public static final int PPC_REG_F23 = 35; + public static final int PPC_REG_F24 = 36; + public static final int PPC_REG_F25 = 37; + public static final int PPC_REG_F26 = 38; + public static final int PPC_REG_F27 = 39; + public static final int PPC_REG_F28 = 40; + public static final int PPC_REG_F29 = 41; + public static final int PPC_REG_F30 = 42; + public static final int PPC_REG_F31 = 43; + public static final int PPC_REG_LR = 44; + public static final int PPC_REG_R0 = 45; + public static final int PPC_REG_R1 = 46; + public static final int PPC_REG_R2 = 47; + public static final int PPC_REG_R3 = 48; + public static final int PPC_REG_R4 = 49; + public static final int PPC_REG_R5 = 50; + public static final int PPC_REG_R6 = 51; + public static final int PPC_REG_R7 = 52; + public static final int PPC_REG_R8 = 53; + public static final int PPC_REG_R9 = 54; + public static final int PPC_REG_R10 = 55; + public static final int PPC_REG_R11 = 56; + public static final int PPC_REG_R12 = 57; + public static final int PPC_REG_R13 = 58; + public static final int PPC_REG_R14 = 59; + public static final int PPC_REG_R15 = 60; + public static final int PPC_REG_R16 = 61; + public static final int PPC_REG_R17 = 62; + public static final int PPC_REG_R18 = 63; + public static final int PPC_REG_R19 = 64; + public static final int PPC_REG_R20 = 65; + public static final int PPC_REG_R21 = 66; + public static final int PPC_REG_R22 = 67; + public static final int PPC_REG_R23 = 68; + public static final int PPC_REG_R24 = 69; + public static final int PPC_REG_R25 = 70; + public static final int PPC_REG_R26 = 71; + public static final int PPC_REG_R27 = 72; + public static final int PPC_REG_R28 = 73; + public static final int PPC_REG_R29 = 74; + public static final int PPC_REG_R30 = 75; + public static final int PPC_REG_R31 = 76; + public static final int PPC_REG_V0 = 77; + public static final int PPC_REG_V1 = 78; + public static final int PPC_REG_V2 = 79; + public static final int PPC_REG_V3 = 80; + public static final int PPC_REG_V4 = 81; + public static final int PPC_REG_V5 = 82; + public static final int PPC_REG_V6 = 83; + public static final int PPC_REG_V7 = 84; + public static final int PPC_REG_V8 = 85; + public static final int PPC_REG_V9 = 86; + public static final int PPC_REG_V10 = 87; + public static final int PPC_REG_V11 = 88; + public static final int PPC_REG_V12 = 89; + public static final int PPC_REG_V13 = 90; + public static final int PPC_REG_V14 = 91; + public static final int PPC_REG_V15 = 92; + public static final int PPC_REG_V16 = 93; + public static final int PPC_REG_V17 = 94; + public static final int PPC_REG_V18 = 95; + public static final int PPC_REG_V19 = 96; + public static final int PPC_REG_V20 = 97; + public static final int PPC_REG_V21 = 98; + public static final int PPC_REG_V22 = 99; + public static final int PPC_REG_V23 = 100; + public static final int PPC_REG_V24 = 101; + public static final int PPC_REG_V25 = 102; + public static final int PPC_REG_V26 = 103; + public static final int PPC_REG_V27 = 104; + public static final int PPC_REG_V28 = 105; + public static final int PPC_REG_V29 = 106; + public static final int PPC_REG_V30 = 107; + public static final int PPC_REG_V31 = 108; + public static final int PPC_REG_VRSAVE = 109; + public static final int PPC_REG_VS0 = 110; + public static final int PPC_REG_VS1 = 111; + public static final int PPC_REG_VS2 = 112; + public static final int PPC_REG_VS3 = 113; + public static final int PPC_REG_VS4 = 114; + public static final int PPC_REG_VS5 = 115; + public static final int PPC_REG_VS6 = 116; + public static final int PPC_REG_VS7 = 117; + public static final int PPC_REG_VS8 = 118; + public static final int PPC_REG_VS9 = 119; + public static final int PPC_REG_VS10 = 120; + public static final int PPC_REG_VS11 = 121; + public static final int PPC_REG_VS12 = 122; + public static final int PPC_REG_VS13 = 123; + public static final int PPC_REG_VS14 = 124; + public static final int PPC_REG_VS15 = 125; + public static final int PPC_REG_VS16 = 126; + public static final int PPC_REG_VS17 = 127; + public static final int PPC_REG_VS18 = 128; + public static final int PPC_REG_VS19 = 129; + public static final int PPC_REG_VS20 = 130; + public static final int PPC_REG_VS21 = 131; + public static final int PPC_REG_VS22 = 132; + public static final int PPC_REG_VS23 = 133; + public static final int PPC_REG_VS24 = 134; + public static final int PPC_REG_VS25 = 135; + public static final int PPC_REG_VS26 = 136; + public static final int PPC_REG_VS27 = 137; + public static final int PPC_REG_VS28 = 138; + public static final int PPC_REG_VS29 = 139; + public static final int PPC_REG_VS30 = 140; + public static final int PPC_REG_VS31 = 141; + public static final int PPC_REG_VS32 = 142; + public static final int PPC_REG_VS33 = 143; + public static final int PPC_REG_VS34 = 144; + public static final int PPC_REG_VS35 = 145; + public static final int PPC_REG_VS36 = 146; + public static final int PPC_REG_VS37 = 147; + public static final int PPC_REG_VS38 = 148; + public static final int PPC_REG_VS39 = 149; + public static final int PPC_REG_VS40 = 150; + public static final int PPC_REG_VS41 = 151; + public static final int PPC_REG_VS42 = 152; + public static final int PPC_REG_VS43 = 153; + public static final int PPC_REG_VS44 = 154; + public static final int PPC_REG_VS45 = 155; + public static final int PPC_REG_VS46 = 156; + public static final int PPC_REG_VS47 = 157; + public static final int PPC_REG_VS48 = 158; + public static final int PPC_REG_VS49 = 159; + public static final int PPC_REG_VS50 = 160; + public static final int PPC_REG_VS51 = 161; + public static final int PPC_REG_VS52 = 162; + public static final int PPC_REG_VS53 = 163; + public static final int PPC_REG_VS54 = 164; + public static final int PPC_REG_VS55 = 165; + public static final int PPC_REG_VS56 = 166; + public static final int PPC_REG_VS57 = 167; + public static final int PPC_REG_VS58 = 168; + public static final int PPC_REG_VS59 = 169; + public static final int PPC_REG_VS60 = 170; + public static final int PPC_REG_VS61 = 171; + public static final int PPC_REG_VS62 = 172; + public static final int PPC_REG_VS63 = 173; + public static final int PPC_REG_RM = 174; + public static final int PPC_REG_CTR8 = 175; + public static final int PPC_REG_LR8 = 176; + public static final int PPC_REG_CR1EQ = 177; + public static final int PPC_REG_ENDING = 178; + + // Operand type for instruction's operands + + public static final int PPC_OP_INVALID = 0; + public static final int PPC_OP_REG = 1; + public static final int PPC_OP_IMM = 2; + public static final int PPC_OP_MEM = 3; + public static final int PPC_OP_CRX = 64; + + // PPC instruction + + public static final int PPC_INS_INVALID = 0; + public static final int PPC_INS_ADD = 1; + public static final int PPC_INS_ADDC = 2; + public static final int PPC_INS_ADDE = 3; + public static final int PPC_INS_ADDI = 4; + public static final int PPC_INS_ADDIC = 5; + public static final int PPC_INS_ADDIS = 6; + public static final int PPC_INS_ADDME = 7; + public static final int PPC_INS_ADDZE = 8; + public static final int PPC_INS_AND = 9; + public static final int PPC_INS_ANDC = 10; + public static final int PPC_INS_ANDIS = 11; + public static final int PPC_INS_ANDI = 12; + public static final int PPC_INS_B = 13; + public static final int PPC_INS_BA = 14; + public static final int PPC_INS_BC = 15; + public static final int PPC_INS_BCCTR = 16; + public static final int PPC_INS_BCCTRL = 17; + public static final int PPC_INS_BCL = 18; + public static final int PPC_INS_BCLR = 19; + public static final int PPC_INS_BCLRL = 20; + public static final int PPC_INS_BCTR = 21; + public static final int PPC_INS_BCTRL = 22; + public static final int PPC_INS_BDNZ = 23; + public static final int PPC_INS_BDNZA = 24; + public static final int PPC_INS_BDNZL = 25; + public static final int PPC_INS_BDNZLA = 26; + public static final int PPC_INS_BDNZLR = 27; + public static final int PPC_INS_BDNZLRL = 28; + public static final int PPC_INS_BDZ = 29; + public static final int PPC_INS_BDZA = 30; + public static final int PPC_INS_BDZL = 31; + public static final int PPC_INS_BDZLA = 32; + public static final int PPC_INS_BDZLR = 33; + public static final int PPC_INS_BDZLRL = 34; + public static final int PPC_INS_BL = 35; + public static final int PPC_INS_BLA = 36; + public static final int PPC_INS_BLR = 37; + public static final int PPC_INS_BLRL = 38; + public static final int PPC_INS_BRINC = 39; + public static final int PPC_INS_CMPD = 40; + public static final int PPC_INS_CMPDI = 41; + public static final int PPC_INS_CMPLD = 42; + public static final int PPC_INS_CMPLDI = 43; + public static final int PPC_INS_CMPLW = 44; + public static final int PPC_INS_CMPLWI = 45; + public static final int PPC_INS_CMPW = 46; + public static final int PPC_INS_CMPWI = 47; + public static final int PPC_INS_CNTLZD = 48; + public static final int PPC_INS_CNTLZW = 49; + public static final int PPC_INS_CREQV = 50; + public static final int PPC_INS_CRXOR = 51; + public static final int PPC_INS_CRAND = 52; + public static final int PPC_INS_CRANDC = 53; + public static final int PPC_INS_CRNAND = 54; + public static final int PPC_INS_CRNOR = 55; + public static final int PPC_INS_CROR = 56; + public static final int PPC_INS_CRORC = 57; + public static final int PPC_INS_DCBA = 58; + public static final int PPC_INS_DCBF = 59; + public static final int PPC_INS_DCBI = 60; + public static final int PPC_INS_DCBST = 61; + public static final int PPC_INS_DCBT = 62; + public static final int PPC_INS_DCBTST = 63; + public static final int PPC_INS_DCBZ = 64; + public static final int PPC_INS_DCBZL = 65; + public static final int PPC_INS_DCCCI = 66; + public static final int PPC_INS_DIVD = 67; + public static final int PPC_INS_DIVDU = 68; + public static final int PPC_INS_DIVW = 69; + public static final int PPC_INS_DIVWU = 70; + public static final int PPC_INS_DSS = 71; + public static final int PPC_INS_DSSALL = 72; + public static final int PPC_INS_DST = 73; + public static final int PPC_INS_DSTST = 74; + public static final int PPC_INS_DSTSTT = 75; + public static final int PPC_INS_DSTT = 76; + public static final int PPC_INS_EIEIO = 77; + public static final int PPC_INS_EQV = 78; + public static final int PPC_INS_EVABS = 79; + public static final int PPC_INS_EVADDIW = 80; + public static final int PPC_INS_EVADDSMIAAW = 81; + public static final int PPC_INS_EVADDSSIAAW = 82; + public static final int PPC_INS_EVADDUMIAAW = 83; + public static final int PPC_INS_EVADDUSIAAW = 84; + public static final int PPC_INS_EVADDW = 85; + public static final int PPC_INS_EVAND = 86; + public static final int PPC_INS_EVANDC = 87; + public static final int PPC_INS_EVCMPEQ = 88; + public static final int PPC_INS_EVCMPGTS = 89; + public static final int PPC_INS_EVCMPGTU = 90; + public static final int PPC_INS_EVCMPLTS = 91; + public static final int PPC_INS_EVCMPLTU = 92; + public static final int PPC_INS_EVCNTLSW = 93; + public static final int PPC_INS_EVCNTLZW = 94; + public static final int PPC_INS_EVDIVWS = 95; + public static final int PPC_INS_EVDIVWU = 96; + public static final int PPC_INS_EVEQV = 97; + public static final int PPC_INS_EVEXTSB = 98; + public static final int PPC_INS_EVEXTSH = 99; + public static final int PPC_INS_EVLDD = 100; + public static final int PPC_INS_EVLDDX = 101; + public static final int PPC_INS_EVLDH = 102; + public static final int PPC_INS_EVLDHX = 103; + public static final int PPC_INS_EVLDW = 104; + public static final int PPC_INS_EVLDWX = 105; + public static final int PPC_INS_EVLHHESPLAT = 106; + public static final int PPC_INS_EVLHHESPLATX = 107; + public static final int PPC_INS_EVLHHOSSPLAT = 108; + public static final int PPC_INS_EVLHHOSSPLATX = 109; + public static final int PPC_INS_EVLHHOUSPLAT = 110; + public static final int PPC_INS_EVLHHOUSPLATX = 111; + public static final int PPC_INS_EVLWHE = 112; + public static final int PPC_INS_EVLWHEX = 113; + public static final int PPC_INS_EVLWHOS = 114; + public static final int PPC_INS_EVLWHOSX = 115; + public static final int PPC_INS_EVLWHOU = 116; + public static final int PPC_INS_EVLWHOUX = 117; + public static final int PPC_INS_EVLWHSPLAT = 118; + public static final int PPC_INS_EVLWHSPLATX = 119; + public static final int PPC_INS_EVLWWSPLAT = 120; + public static final int PPC_INS_EVLWWSPLATX = 121; + public static final int PPC_INS_EVMERGEHI = 122; + public static final int PPC_INS_EVMERGEHILO = 123; + public static final int PPC_INS_EVMERGELO = 124; + public static final int PPC_INS_EVMERGELOHI = 125; + public static final int PPC_INS_EVMHEGSMFAA = 126; + public static final int PPC_INS_EVMHEGSMFAN = 127; + public static final int PPC_INS_EVMHEGSMIAA = 128; + public static final int PPC_INS_EVMHEGSMIAN = 129; + public static final int PPC_INS_EVMHEGUMIAA = 130; + public static final int PPC_INS_EVMHEGUMIAN = 131; + public static final int PPC_INS_EVMHESMF = 132; + public static final int PPC_INS_EVMHESMFA = 133; + public static final int PPC_INS_EVMHESMFAAW = 134; + public static final int PPC_INS_EVMHESMFANW = 135; + public static final int PPC_INS_EVMHESMI = 136; + public static final int PPC_INS_EVMHESMIA = 137; + public static final int PPC_INS_EVMHESMIAAW = 138; + public static final int PPC_INS_EVMHESMIANW = 139; + public static final int PPC_INS_EVMHESSF = 140; + public static final int PPC_INS_EVMHESSFA = 141; + public static final int PPC_INS_EVMHESSFAAW = 142; + public static final int PPC_INS_EVMHESSFANW = 143; + public static final int PPC_INS_EVMHESSIAAW = 144; + public static final int PPC_INS_EVMHESSIANW = 145; + public static final int PPC_INS_EVMHEUMI = 146; + public static final int PPC_INS_EVMHEUMIA = 147; + public static final int PPC_INS_EVMHEUMIAAW = 148; + public static final int PPC_INS_EVMHEUMIANW = 149; + public static final int PPC_INS_EVMHEUSIAAW = 150; + public static final int PPC_INS_EVMHEUSIANW = 151; + public static final int PPC_INS_EVMHOGSMFAA = 152; + public static final int PPC_INS_EVMHOGSMFAN = 153; + public static final int PPC_INS_EVMHOGSMIAA = 154; + public static final int PPC_INS_EVMHOGSMIAN = 155; + public static final int PPC_INS_EVMHOGUMIAA = 156; + public static final int PPC_INS_EVMHOGUMIAN = 157; + public static final int PPC_INS_EVMHOSMF = 158; + public static final int PPC_INS_EVMHOSMFA = 159; + public static final int PPC_INS_EVMHOSMFAAW = 160; + public static final int PPC_INS_EVMHOSMFANW = 161; + public static final int PPC_INS_EVMHOSMI = 162; + public static final int PPC_INS_EVMHOSMIA = 163; + public static final int PPC_INS_EVMHOSMIAAW = 164; + public static final int PPC_INS_EVMHOSMIANW = 165; + public static final int PPC_INS_EVMHOSSF = 166; + public static final int PPC_INS_EVMHOSSFA = 167; + public static final int PPC_INS_EVMHOSSFAAW = 168; + public static final int PPC_INS_EVMHOSSFANW = 169; + public static final int PPC_INS_EVMHOSSIAAW = 170; + public static final int PPC_INS_EVMHOSSIANW = 171; + public static final int PPC_INS_EVMHOUMI = 172; + public static final int PPC_INS_EVMHOUMIA = 173; + public static final int PPC_INS_EVMHOUMIAAW = 174; + public static final int PPC_INS_EVMHOUMIANW = 175; + public static final int PPC_INS_EVMHOUSIAAW = 176; + public static final int PPC_INS_EVMHOUSIANW = 177; + public static final int PPC_INS_EVMRA = 178; + public static final int PPC_INS_EVMWHSMF = 179; + public static final int PPC_INS_EVMWHSMFA = 180; + public static final int PPC_INS_EVMWHSMI = 181; + public static final int PPC_INS_EVMWHSMIA = 182; + public static final int PPC_INS_EVMWHSSF = 183; + public static final int PPC_INS_EVMWHSSFA = 184; + public static final int PPC_INS_EVMWHUMI = 185; + public static final int PPC_INS_EVMWHUMIA = 186; + public static final int PPC_INS_EVMWLSMIAAW = 187; + public static final int PPC_INS_EVMWLSMIANW = 188; + public static final int PPC_INS_EVMWLSSIAAW = 189; + public static final int PPC_INS_EVMWLSSIANW = 190; + public static final int PPC_INS_EVMWLUMI = 191; + public static final int PPC_INS_EVMWLUMIA = 192; + public static final int PPC_INS_EVMWLUMIAAW = 193; + public static final int PPC_INS_EVMWLUMIANW = 194; + public static final int PPC_INS_EVMWLUSIAAW = 195; + public static final int PPC_INS_EVMWLUSIANW = 196; + public static final int PPC_INS_EVMWSMF = 197; + public static final int PPC_INS_EVMWSMFA = 198; + public static final int PPC_INS_EVMWSMFAA = 199; + public static final int PPC_INS_EVMWSMFAN = 200; + public static final int PPC_INS_EVMWSMI = 201; + public static final int PPC_INS_EVMWSMIA = 202; + public static final int PPC_INS_EVMWSMIAA = 203; + public static final int PPC_INS_EVMWSMIAN = 204; + public static final int PPC_INS_EVMWSSF = 205; + public static final int PPC_INS_EVMWSSFA = 206; + public static final int PPC_INS_EVMWSSFAA = 207; + public static final int PPC_INS_EVMWSSFAN = 208; + public static final int PPC_INS_EVMWUMI = 209; + public static final int PPC_INS_EVMWUMIA = 210; + public static final int PPC_INS_EVMWUMIAA = 211; + public static final int PPC_INS_EVMWUMIAN = 212; + public static final int PPC_INS_EVNAND = 213; + public static final int PPC_INS_EVNEG = 214; + public static final int PPC_INS_EVNOR = 215; + public static final int PPC_INS_EVOR = 216; + public static final int PPC_INS_EVORC = 217; + public static final int PPC_INS_EVRLW = 218; + public static final int PPC_INS_EVRLWI = 219; + public static final int PPC_INS_EVRNDW = 220; + public static final int PPC_INS_EVSLW = 221; + public static final int PPC_INS_EVSLWI = 222; + public static final int PPC_INS_EVSPLATFI = 223; + public static final int PPC_INS_EVSPLATI = 224; + public static final int PPC_INS_EVSRWIS = 225; + public static final int PPC_INS_EVSRWIU = 226; + public static final int PPC_INS_EVSRWS = 227; + public static final int PPC_INS_EVSRWU = 228; + public static final int PPC_INS_EVSTDD = 229; + public static final int PPC_INS_EVSTDDX = 230; + public static final int PPC_INS_EVSTDH = 231; + public static final int PPC_INS_EVSTDHX = 232; + public static final int PPC_INS_EVSTDW = 233; + public static final int PPC_INS_EVSTDWX = 234; + public static final int PPC_INS_EVSTWHE = 235; + public static final int PPC_INS_EVSTWHEX = 236; + public static final int PPC_INS_EVSTWHO = 237; + public static final int PPC_INS_EVSTWHOX = 238; + public static final int PPC_INS_EVSTWWE = 239; + public static final int PPC_INS_EVSTWWEX = 240; + public static final int PPC_INS_EVSTWWO = 241; + public static final int PPC_INS_EVSTWWOX = 242; + public static final int PPC_INS_EVSUBFSMIAAW = 243; + public static final int PPC_INS_EVSUBFSSIAAW = 244; + public static final int PPC_INS_EVSUBFUMIAAW = 245; + public static final int PPC_INS_EVSUBFUSIAAW = 246; + public static final int PPC_INS_EVSUBFW = 247; + public static final int PPC_INS_EVSUBIFW = 248; + public static final int PPC_INS_EVXOR = 249; + public static final int PPC_INS_EXTSB = 250; + public static final int PPC_INS_EXTSH = 251; + public static final int PPC_INS_EXTSW = 252; + public static final int PPC_INS_FABS = 253; + public static final int PPC_INS_FADD = 254; + public static final int PPC_INS_FADDS = 255; + public static final int PPC_INS_FCFID = 256; + public static final int PPC_INS_FCFIDS = 257; + public static final int PPC_INS_FCFIDU = 258; + public static final int PPC_INS_FCFIDUS = 259; + public static final int PPC_INS_FCMPU = 260; + public static final int PPC_INS_FCPSGN = 261; + public static final int PPC_INS_FCTID = 262; + public static final int PPC_INS_FCTIDUZ = 263; + public static final int PPC_INS_FCTIDZ = 264; + public static final int PPC_INS_FCTIW = 265; + public static final int PPC_INS_FCTIWUZ = 266; + public static final int PPC_INS_FCTIWZ = 267; + public static final int PPC_INS_FDIV = 268; + public static final int PPC_INS_FDIVS = 269; + public static final int PPC_INS_FMADD = 270; + public static final int PPC_INS_FMADDS = 271; + public static final int PPC_INS_FMR = 272; + public static final int PPC_INS_FMSUB = 273; + public static final int PPC_INS_FMSUBS = 274; + public static final int PPC_INS_FMUL = 275; + public static final int PPC_INS_FMULS = 276; + public static final int PPC_INS_FNABS = 277; + public static final int PPC_INS_FNEG = 278; + public static final int PPC_INS_FNMADD = 279; + public static final int PPC_INS_FNMADDS = 280; + public static final int PPC_INS_FNMSUB = 281; + public static final int PPC_INS_FNMSUBS = 282; + public static final int PPC_INS_FRE = 283; + public static final int PPC_INS_FRES = 284; + public static final int PPC_INS_FRIM = 285; + public static final int PPC_INS_FRIN = 286; + public static final int PPC_INS_FRIP = 287; + public static final int PPC_INS_FRIZ = 288; + public static final int PPC_INS_FRSP = 289; + public static final int PPC_INS_FRSQRTE = 290; + public static final int PPC_INS_FRSQRTES = 291; + public static final int PPC_INS_FSEL = 292; + public static final int PPC_INS_FSQRT = 293; + public static final int PPC_INS_FSQRTS = 294; + public static final int PPC_INS_FSUB = 295; + public static final int PPC_INS_FSUBS = 296; + public static final int PPC_INS_ICBI = 297; + public static final int PPC_INS_ICCCI = 298; + public static final int PPC_INS_ISEL = 299; + public static final int PPC_INS_ISYNC = 300; + public static final int PPC_INS_LA = 301; + public static final int PPC_INS_LBZ = 302; + public static final int PPC_INS_LBZU = 303; + public static final int PPC_INS_LBZUX = 304; + public static final int PPC_INS_LBZX = 305; + public static final int PPC_INS_LD = 306; + public static final int PPC_INS_LDARX = 307; + public static final int PPC_INS_LDBRX = 308; + public static final int PPC_INS_LDU = 309; + public static final int PPC_INS_LDUX = 310; + public static final int PPC_INS_LDX = 311; + public static final int PPC_INS_LFD = 312; + public static final int PPC_INS_LFDU = 313; + public static final int PPC_INS_LFDUX = 314; + public static final int PPC_INS_LFDX = 315; + public static final int PPC_INS_LFIWAX = 316; + public static final int PPC_INS_LFIWZX = 317; + public static final int PPC_INS_LFS = 318; + public static final int PPC_INS_LFSU = 319; + public static final int PPC_INS_LFSUX = 320; + public static final int PPC_INS_LFSX = 321; + public static final int PPC_INS_LHA = 322; + public static final int PPC_INS_LHAU = 323; + public static final int PPC_INS_LHAUX = 324; + public static final int PPC_INS_LHAX = 325; + public static final int PPC_INS_LHBRX = 326; + public static final int PPC_INS_LHZ = 327; + public static final int PPC_INS_LHZU = 328; + public static final int PPC_INS_LHZUX = 329; + public static final int PPC_INS_LHZX = 330; + public static final int PPC_INS_LI = 331; + public static final int PPC_INS_LIS = 332; + public static final int PPC_INS_LMW = 333; + public static final int PPC_INS_LSWI = 334; + public static final int PPC_INS_LVEBX = 335; + public static final int PPC_INS_LVEHX = 336; + public static final int PPC_INS_LVEWX = 337; + public static final int PPC_INS_LVSL = 338; + public static final int PPC_INS_LVSR = 339; + public static final int PPC_INS_LVX = 340; + public static final int PPC_INS_LVXL = 341; + public static final int PPC_INS_LWA = 342; + public static final int PPC_INS_LWARX = 343; + public static final int PPC_INS_LWAUX = 344; + public static final int PPC_INS_LWAX = 345; + public static final int PPC_INS_LWBRX = 346; + public static final int PPC_INS_LWZ = 347; + public static final int PPC_INS_LWZU = 348; + public static final int PPC_INS_LWZUX = 349; + public static final int PPC_INS_LWZX = 350; + public static final int PPC_INS_LXSDX = 351; + public static final int PPC_INS_LXVD2X = 352; + public static final int PPC_INS_LXVDSX = 353; + public static final int PPC_INS_LXVW4X = 354; + public static final int PPC_INS_MBAR = 355; + public static final int PPC_INS_MCRF = 356; + public static final int PPC_INS_MFCR = 357; + public static final int PPC_INS_MFCTR = 358; + public static final int PPC_INS_MFDCR = 359; + public static final int PPC_INS_MFFS = 360; + public static final int PPC_INS_MFLR = 361; + public static final int PPC_INS_MFMSR = 362; + public static final int PPC_INS_MFOCRF = 363; + public static final int PPC_INS_MFSPR = 364; + public static final int PPC_INS_MFSR = 365; + public static final int PPC_INS_MFSRIN = 366; + public static final int PPC_INS_MFTB = 367; + public static final int PPC_INS_MFVSCR = 368; + public static final int PPC_INS_MSYNC = 369; + public static final int PPC_INS_MTCRF = 370; + public static final int PPC_INS_MTCTR = 371; + public static final int PPC_INS_MTDCR = 372; + public static final int PPC_INS_MTFSB0 = 373; + public static final int PPC_INS_MTFSB1 = 374; + public static final int PPC_INS_MTFSF = 375; + public static final int PPC_INS_MTLR = 376; + public static final int PPC_INS_MTMSR = 377; + public static final int PPC_INS_MTMSRD = 378; + public static final int PPC_INS_MTOCRF = 379; + public static final int PPC_INS_MTSPR = 380; + public static final int PPC_INS_MTSR = 381; + public static final int PPC_INS_MTSRIN = 382; + public static final int PPC_INS_MTVSCR = 383; + public static final int PPC_INS_MULHD = 384; + public static final int PPC_INS_MULHDU = 385; + public static final int PPC_INS_MULHW = 386; + public static final int PPC_INS_MULHWU = 387; + public static final int PPC_INS_MULLD = 388; + public static final int PPC_INS_MULLI = 389; + public static final int PPC_INS_MULLW = 390; + public static final int PPC_INS_NAND = 391; + public static final int PPC_INS_NEG = 392; + public static final int PPC_INS_NOP = 393; + public static final int PPC_INS_ORI = 394; + public static final int PPC_INS_NOR = 395; + public static final int PPC_INS_OR = 396; + public static final int PPC_INS_ORC = 397; + public static final int PPC_INS_ORIS = 398; + public static final int PPC_INS_POPCNTD = 399; + public static final int PPC_INS_POPCNTW = 400; + public static final int PPC_INS_RFCI = 401; + public static final int PPC_INS_RFDI = 402; + public static final int PPC_INS_RFI = 403; + public static final int PPC_INS_RFID = 404; + public static final int PPC_INS_RFMCI = 405; + public static final int PPC_INS_RLDCL = 406; + public static final int PPC_INS_RLDCR = 407; + public static final int PPC_INS_RLDIC = 408; + public static final int PPC_INS_RLDICL = 409; + public static final int PPC_INS_RLDICR = 410; + public static final int PPC_INS_RLDIMI = 411; + public static final int PPC_INS_RLWIMI = 412; + public static final int PPC_INS_RLWINM = 413; + public static final int PPC_INS_RLWNM = 414; + public static final int PPC_INS_SC = 415; + public static final int PPC_INS_SLBIA = 416; + public static final int PPC_INS_SLBIE = 417; + public static final int PPC_INS_SLBMFEE = 418; + public static final int PPC_INS_SLBMTE = 419; + public static final int PPC_INS_SLD = 420; + public static final int PPC_INS_SLW = 421; + public static final int PPC_INS_SRAD = 422; + public static final int PPC_INS_SRADI = 423; + public static final int PPC_INS_SRAW = 424; + public static final int PPC_INS_SRAWI = 425; + public static final int PPC_INS_SRD = 426; + public static final int PPC_INS_SRW = 427; + public static final int PPC_INS_STB = 428; + public static final int PPC_INS_STBU = 429; + public static final int PPC_INS_STBUX = 430; + public static final int PPC_INS_STBX = 431; + public static final int PPC_INS_STD = 432; + public static final int PPC_INS_STDBRX = 433; + public static final int PPC_INS_STDCX = 434; + public static final int PPC_INS_STDU = 435; + public static final int PPC_INS_STDUX = 436; + public static final int PPC_INS_STDX = 437; + public static final int PPC_INS_STFD = 438; + public static final int PPC_INS_STFDU = 439; + public static final int PPC_INS_STFDUX = 440; + public static final int PPC_INS_STFDX = 441; + public static final int PPC_INS_STFIWX = 442; + public static final int PPC_INS_STFS = 443; + public static final int PPC_INS_STFSU = 444; + public static final int PPC_INS_STFSUX = 445; + public static final int PPC_INS_STFSX = 446; + public static final int PPC_INS_STH = 447; + public static final int PPC_INS_STHBRX = 448; + public static final int PPC_INS_STHU = 449; + public static final int PPC_INS_STHUX = 450; + public static final int PPC_INS_STHX = 451; + public static final int PPC_INS_STMW = 452; + public static final int PPC_INS_STSWI = 453; + public static final int PPC_INS_STVEBX = 454; + public static final int PPC_INS_STVEHX = 455; + public static final int PPC_INS_STVEWX = 456; + public static final int PPC_INS_STVX = 457; + public static final int PPC_INS_STVXL = 458; + public static final int PPC_INS_STW = 459; + public static final int PPC_INS_STWBRX = 460; + public static final int PPC_INS_STWCX = 461; + public static final int PPC_INS_STWU = 462; + public static final int PPC_INS_STWUX = 463; + public static final int PPC_INS_STWX = 464; + public static final int PPC_INS_STXSDX = 465; + public static final int PPC_INS_STXVD2X = 466; + public static final int PPC_INS_STXVW4X = 467; + public static final int PPC_INS_SUBF = 468; + public static final int PPC_INS_SUBFC = 469; + public static final int PPC_INS_SUBFE = 470; + public static final int PPC_INS_SUBFIC = 471; + public static final int PPC_INS_SUBFME = 472; + public static final int PPC_INS_SUBFZE = 473; + public static final int PPC_INS_SYNC = 474; + public static final int PPC_INS_TD = 475; + public static final int PPC_INS_TDI = 476; + public static final int PPC_INS_TLBIA = 477; + public static final int PPC_INS_TLBIE = 478; + public static final int PPC_INS_TLBIEL = 479; + public static final int PPC_INS_TLBIVAX = 480; + public static final int PPC_INS_TLBLD = 481; + public static final int PPC_INS_TLBLI = 482; + public static final int PPC_INS_TLBRE = 483; + public static final int PPC_INS_TLBSX = 484; + public static final int PPC_INS_TLBSYNC = 485; + public static final int PPC_INS_TLBWE = 486; + public static final int PPC_INS_TRAP = 487; + public static final int PPC_INS_TW = 488; + public static final int PPC_INS_TWI = 489; + public static final int PPC_INS_VADDCUW = 490; + public static final int PPC_INS_VADDFP = 491; + public static final int PPC_INS_VADDSBS = 492; + public static final int PPC_INS_VADDSHS = 493; + public static final int PPC_INS_VADDSWS = 494; + public static final int PPC_INS_VADDUBM = 495; + public static final int PPC_INS_VADDUBS = 496; + public static final int PPC_INS_VADDUHM = 497; + public static final int PPC_INS_VADDUHS = 498; + public static final int PPC_INS_VADDUWM = 499; + public static final int PPC_INS_VADDUWS = 500; + public static final int PPC_INS_VAND = 501; + public static final int PPC_INS_VANDC = 502; + public static final int PPC_INS_VAVGSB = 503; + public static final int PPC_INS_VAVGSH = 504; + public static final int PPC_INS_VAVGSW = 505; + public static final int PPC_INS_VAVGUB = 506; + public static final int PPC_INS_VAVGUH = 507; + public static final int PPC_INS_VAVGUW = 508; + public static final int PPC_INS_VCFSX = 509; + public static final int PPC_INS_VCFUX = 510; + public static final int PPC_INS_VCMPBFP = 511; + public static final int PPC_INS_VCMPEQFP = 512; + public static final int PPC_INS_VCMPEQUB = 513; + public static final int PPC_INS_VCMPEQUH = 514; + public static final int PPC_INS_VCMPEQUW = 515; + public static final int PPC_INS_VCMPGEFP = 516; + public static final int PPC_INS_VCMPGTFP = 517; + public static final int PPC_INS_VCMPGTSB = 518; + public static final int PPC_INS_VCMPGTSH = 519; + public static final int PPC_INS_VCMPGTSW = 520; + public static final int PPC_INS_VCMPGTUB = 521; + public static final int PPC_INS_VCMPGTUH = 522; + public static final int PPC_INS_VCMPGTUW = 523; + public static final int PPC_INS_VCTSXS = 524; + public static final int PPC_INS_VCTUXS = 525; + public static final int PPC_INS_VEXPTEFP = 526; + public static final int PPC_INS_VLOGEFP = 527; + public static final int PPC_INS_VMADDFP = 528; + public static final int PPC_INS_VMAXFP = 529; + public static final int PPC_INS_VMAXSB = 530; + public static final int PPC_INS_VMAXSH = 531; + public static final int PPC_INS_VMAXSW = 532; + public static final int PPC_INS_VMAXUB = 533; + public static final int PPC_INS_VMAXUH = 534; + public static final int PPC_INS_VMAXUW = 535; + public static final int PPC_INS_VMHADDSHS = 536; + public static final int PPC_INS_VMHRADDSHS = 537; + public static final int PPC_INS_VMINFP = 538; + public static final int PPC_INS_VMINSB = 539; + public static final int PPC_INS_VMINSH = 540; + public static final int PPC_INS_VMINSW = 541; + public static final int PPC_INS_VMINUB = 542; + public static final int PPC_INS_VMINUH = 543; + public static final int PPC_INS_VMINUW = 544; + public static final int PPC_INS_VMLADDUHM = 545; + public static final int PPC_INS_VMRGHB = 546; + public static final int PPC_INS_VMRGHH = 547; + public static final int PPC_INS_VMRGHW = 548; + public static final int PPC_INS_VMRGLB = 549; + public static final int PPC_INS_VMRGLH = 550; + public static final int PPC_INS_VMRGLW = 551; + public static final int PPC_INS_VMSUMMBM = 552; + public static final int PPC_INS_VMSUMSHM = 553; + public static final int PPC_INS_VMSUMSHS = 554; + public static final int PPC_INS_VMSUMUBM = 555; + public static final int PPC_INS_VMSUMUHM = 556; + public static final int PPC_INS_VMSUMUHS = 557; + public static final int PPC_INS_VMULESB = 558; + public static final int PPC_INS_VMULESH = 559; + public static final int PPC_INS_VMULEUB = 560; + public static final int PPC_INS_VMULEUH = 561; + public static final int PPC_INS_VMULOSB = 562; + public static final int PPC_INS_VMULOSH = 563; + public static final int PPC_INS_VMULOUB = 564; + public static final int PPC_INS_VMULOUH = 565; + public static final int PPC_INS_VNMSUBFP = 566; + public static final int PPC_INS_VNOR = 567; + public static final int PPC_INS_VOR = 568; + public static final int PPC_INS_VPERM = 569; + public static final int PPC_INS_VPKPX = 570; + public static final int PPC_INS_VPKSHSS = 571; + public static final int PPC_INS_VPKSHUS = 572; + public static final int PPC_INS_VPKSWSS = 573; + public static final int PPC_INS_VPKSWUS = 574; + public static final int PPC_INS_VPKUHUM = 575; + public static final int PPC_INS_VPKUHUS = 576; + public static final int PPC_INS_VPKUWUM = 577; + public static final int PPC_INS_VPKUWUS = 578; + public static final int PPC_INS_VREFP = 579; + public static final int PPC_INS_VRFIM = 580; + public static final int PPC_INS_VRFIN = 581; + public static final int PPC_INS_VRFIP = 582; + public static final int PPC_INS_VRFIZ = 583; + public static final int PPC_INS_VRLB = 584; + public static final int PPC_INS_VRLH = 585; + public static final int PPC_INS_VRLW = 586; + public static final int PPC_INS_VRSQRTEFP = 587; + public static final int PPC_INS_VSEL = 588; + public static final int PPC_INS_VSL = 589; + public static final int PPC_INS_VSLB = 590; + public static final int PPC_INS_VSLDOI = 591; + public static final int PPC_INS_VSLH = 592; + public static final int PPC_INS_VSLO = 593; + public static final int PPC_INS_VSLW = 594; + public static final int PPC_INS_VSPLTB = 595; + public static final int PPC_INS_VSPLTH = 596; + public static final int PPC_INS_VSPLTISB = 597; + public static final int PPC_INS_VSPLTISH = 598; + public static final int PPC_INS_VSPLTISW = 599; + public static final int PPC_INS_VSPLTW = 600; + public static final int PPC_INS_VSR = 601; + public static final int PPC_INS_VSRAB = 602; + public static final int PPC_INS_VSRAH = 603; + public static final int PPC_INS_VSRAW = 604; + public static final int PPC_INS_VSRB = 605; + public static final int PPC_INS_VSRH = 606; + public static final int PPC_INS_VSRO = 607; + public static final int PPC_INS_VSRW = 608; + public static final int PPC_INS_VSUBCUW = 609; + public static final int PPC_INS_VSUBFP = 610; + public static final int PPC_INS_VSUBSBS = 611; + public static final int PPC_INS_VSUBSHS = 612; + public static final int PPC_INS_VSUBSWS = 613; + public static final int PPC_INS_VSUBUBM = 614; + public static final int PPC_INS_VSUBUBS = 615; + public static final int PPC_INS_VSUBUHM = 616; + public static final int PPC_INS_VSUBUHS = 617; + public static final int PPC_INS_VSUBUWM = 618; + public static final int PPC_INS_VSUBUWS = 619; + public static final int PPC_INS_VSUM2SWS = 620; + public static final int PPC_INS_VSUM4SBS = 621; + public static final int PPC_INS_VSUM4SHS = 622; + public static final int PPC_INS_VSUM4UBS = 623; + public static final int PPC_INS_VSUMSWS = 624; + public static final int PPC_INS_VUPKHPX = 625; + public static final int PPC_INS_VUPKHSB = 626; + public static final int PPC_INS_VUPKHSH = 627; + public static final int PPC_INS_VUPKLPX = 628; + public static final int PPC_INS_VUPKLSB = 629; + public static final int PPC_INS_VUPKLSH = 630; + public static final int PPC_INS_VXOR = 631; + public static final int PPC_INS_WAIT = 632; + public static final int PPC_INS_WRTEE = 633; + public static final int PPC_INS_WRTEEI = 634; + public static final int PPC_INS_XOR = 635; + public static final int PPC_INS_XORI = 636; + public static final int PPC_INS_XORIS = 637; + public static final int PPC_INS_XSABSDP = 638; + public static final int PPC_INS_XSADDDP = 639; + public static final int PPC_INS_XSCMPODP = 640; + public static final int PPC_INS_XSCMPUDP = 641; + public static final int PPC_INS_XSCPSGNDP = 642; + public static final int PPC_INS_XSCVDPSP = 643; + public static final int PPC_INS_XSCVDPSXDS = 644; + public static final int PPC_INS_XSCVDPSXWS = 645; + public static final int PPC_INS_XSCVDPUXDS = 646; + public static final int PPC_INS_XSCVDPUXWS = 647; + public static final int PPC_INS_XSCVSPDP = 648; + public static final int PPC_INS_XSCVSXDDP = 649; + public static final int PPC_INS_XSCVUXDDP = 650; + public static final int PPC_INS_XSDIVDP = 651; + public static final int PPC_INS_XSMADDADP = 652; + public static final int PPC_INS_XSMADDMDP = 653; + public static final int PPC_INS_XSMAXDP = 654; + public static final int PPC_INS_XSMINDP = 655; + public static final int PPC_INS_XSMSUBADP = 656; + public static final int PPC_INS_XSMSUBMDP = 657; + public static final int PPC_INS_XSMULDP = 658; + public static final int PPC_INS_XSNABSDP = 659; + public static final int PPC_INS_XSNEGDP = 660; + public static final int PPC_INS_XSNMADDADP = 661; + public static final int PPC_INS_XSNMADDMDP = 662; + public static final int PPC_INS_XSNMSUBADP = 663; + public static final int PPC_INS_XSNMSUBMDP = 664; + public static final int PPC_INS_XSRDPI = 665; + public static final int PPC_INS_XSRDPIC = 666; + public static final int PPC_INS_XSRDPIM = 667; + public static final int PPC_INS_XSRDPIP = 668; + public static final int PPC_INS_XSRDPIZ = 669; + public static final int PPC_INS_XSREDP = 670; + public static final int PPC_INS_XSRSQRTEDP = 671; + public static final int PPC_INS_XSSQRTDP = 672; + public static final int PPC_INS_XSSUBDP = 673; + public static final int PPC_INS_XSTDIVDP = 674; + public static final int PPC_INS_XSTSQRTDP = 675; + public static final int PPC_INS_XVABSDP = 676; + public static final int PPC_INS_XVABSSP = 677; + public static final int PPC_INS_XVADDDP = 678; + public static final int PPC_INS_XVADDSP = 679; + public static final int PPC_INS_XVCMPEQDP = 680; + public static final int PPC_INS_XVCMPEQSP = 681; + public static final int PPC_INS_XVCMPGEDP = 682; + public static final int PPC_INS_XVCMPGESP = 683; + public static final int PPC_INS_XVCMPGTDP = 684; + public static final int PPC_INS_XVCMPGTSP = 685; + public static final int PPC_INS_XVCPSGNDP = 686; + public static final int PPC_INS_XVCPSGNSP = 687; + public static final int PPC_INS_XVCVDPSP = 688; + public static final int PPC_INS_XVCVDPSXDS = 689; + public static final int PPC_INS_XVCVDPSXWS = 690; + public static final int PPC_INS_XVCVDPUXDS = 691; + public static final int PPC_INS_XVCVDPUXWS = 692; + public static final int PPC_INS_XVCVSPDP = 693; + public static final int PPC_INS_XVCVSPSXDS = 694; + public static final int PPC_INS_XVCVSPSXWS = 695; + public static final int PPC_INS_XVCVSPUXDS = 696; + public static final int PPC_INS_XVCVSPUXWS = 697; + public static final int PPC_INS_XVCVSXDDP = 698; + public static final int PPC_INS_XVCVSXDSP = 699; + public static final int PPC_INS_XVCVSXWDP = 700; + public static final int PPC_INS_XVCVSXWSP = 701; + public static final int PPC_INS_XVCVUXDDP = 702; + public static final int PPC_INS_XVCVUXDSP = 703; + public static final int PPC_INS_XVCVUXWDP = 704; + public static final int PPC_INS_XVCVUXWSP = 705; + public static final int PPC_INS_XVDIVDP = 706; + public static final int PPC_INS_XVDIVSP = 707; + public static final int PPC_INS_XVMADDADP = 708; + public static final int PPC_INS_XVMADDASP = 709; + public static final int PPC_INS_XVMADDMDP = 710; + public static final int PPC_INS_XVMADDMSP = 711; + public static final int PPC_INS_XVMAXDP = 712; + public static final int PPC_INS_XVMAXSP = 713; + public static final int PPC_INS_XVMINDP = 714; + public static final int PPC_INS_XVMINSP = 715; + public static final int PPC_INS_XVMSUBADP = 716; + public static final int PPC_INS_XVMSUBASP = 717; + public static final int PPC_INS_XVMSUBMDP = 718; + public static final int PPC_INS_XVMSUBMSP = 719; + public static final int PPC_INS_XVMULDP = 720; + public static final int PPC_INS_XVMULSP = 721; + public static final int PPC_INS_XVNABSDP = 722; + public static final int PPC_INS_XVNABSSP = 723; + public static final int PPC_INS_XVNEGDP = 724; + public static final int PPC_INS_XVNEGSP = 725; + public static final int PPC_INS_XVNMADDADP = 726; + public static final int PPC_INS_XVNMADDASP = 727; + public static final int PPC_INS_XVNMADDMDP = 728; + public static final int PPC_INS_XVNMADDMSP = 729; + public static final int PPC_INS_XVNMSUBADP = 730; + public static final int PPC_INS_XVNMSUBASP = 731; + public static final int PPC_INS_XVNMSUBMDP = 732; + public static final int PPC_INS_XVNMSUBMSP = 733; + public static final int PPC_INS_XVRDPI = 734; + public static final int PPC_INS_XVRDPIC = 735; + public static final int PPC_INS_XVRDPIM = 736; + public static final int PPC_INS_XVRDPIP = 737; + public static final int PPC_INS_XVRDPIZ = 738; + public static final int PPC_INS_XVREDP = 739; + public static final int PPC_INS_XVRESP = 740; + public static final int PPC_INS_XVRSPI = 741; + public static final int PPC_INS_XVRSPIC = 742; + public static final int PPC_INS_XVRSPIM = 743; + public static final int PPC_INS_XVRSPIP = 744; + public static final int PPC_INS_XVRSPIZ = 745; + public static final int PPC_INS_XVRSQRTEDP = 746; + public static final int PPC_INS_XVRSQRTESP = 747; + public static final int PPC_INS_XVSQRTDP = 748; + public static final int PPC_INS_XVSQRTSP = 749; + public static final int PPC_INS_XVSUBDP = 750; + public static final int PPC_INS_XVSUBSP = 751; + public static final int PPC_INS_XVTDIVDP = 752; + public static final int PPC_INS_XVTDIVSP = 753; + public static final int PPC_INS_XVTSQRTDP = 754; + public static final int PPC_INS_XVTSQRTSP = 755; + public static final int PPC_INS_XXLAND = 756; + public static final int PPC_INS_XXLANDC = 757; + public static final int PPC_INS_XXLNOR = 758; + public static final int PPC_INS_XXLOR = 759; + public static final int PPC_INS_XXLXOR = 760; + public static final int PPC_INS_XXMRGHW = 761; + public static final int PPC_INS_XXMRGLW = 762; + public static final int PPC_INS_XXPERMDI = 763; + public static final int PPC_INS_XXSEL = 764; + public static final int PPC_INS_XXSLDWI = 765; + public static final int PPC_INS_XXSPLTW = 766; + public static final int PPC_INS_BCA = 767; + public static final int PPC_INS_BCLA = 768; + public static final int PPC_INS_SLWI = 769; + public static final int PPC_INS_SRWI = 770; + public static final int PPC_INS_SLDI = 771; + public static final int PPC_INS_BTA = 772; + public static final int PPC_INS_CRSET = 773; + public static final int PPC_INS_CRNOT = 774; + public static final int PPC_INS_CRMOVE = 775; + public static final int PPC_INS_CRCLR = 776; + public static final int PPC_INS_MFBR0 = 777; + public static final int PPC_INS_MFBR1 = 778; + public static final int PPC_INS_MFBR2 = 779; + public static final int PPC_INS_MFBR3 = 780; + public static final int PPC_INS_MFBR4 = 781; + public static final int PPC_INS_MFBR5 = 782; + public static final int PPC_INS_MFBR6 = 783; + public static final int PPC_INS_MFBR7 = 784; + public static final int PPC_INS_MFXER = 785; + public static final int PPC_INS_MFRTCU = 786; + public static final int PPC_INS_MFRTCL = 787; + public static final int PPC_INS_MFDSCR = 788; + public static final int PPC_INS_MFDSISR = 789; + public static final int PPC_INS_MFDAR = 790; + public static final int PPC_INS_MFSRR2 = 791; + public static final int PPC_INS_MFSRR3 = 792; + public static final int PPC_INS_MFCFAR = 793; + public static final int PPC_INS_MFAMR = 794; + public static final int PPC_INS_MFPID = 795; + public static final int PPC_INS_MFTBLO = 796; + public static final int PPC_INS_MFTBHI = 797; + public static final int PPC_INS_MFDBATU = 798; + public static final int PPC_INS_MFDBATL = 799; + public static final int PPC_INS_MFIBATU = 800; + public static final int PPC_INS_MFIBATL = 801; + public static final int PPC_INS_MFDCCR = 802; + public static final int PPC_INS_MFICCR = 803; + public static final int PPC_INS_MFDEAR = 804; + public static final int PPC_INS_MFESR = 805; + public static final int PPC_INS_MFSPEFSCR = 806; + public static final int PPC_INS_MFTCR = 807; + public static final int PPC_INS_MFASR = 808; + public static final int PPC_INS_MFPVR = 809; + public static final int PPC_INS_MFTBU = 810; + public static final int PPC_INS_MTCR = 811; + public static final int PPC_INS_MTBR0 = 812; + public static final int PPC_INS_MTBR1 = 813; + public static final int PPC_INS_MTBR2 = 814; + public static final int PPC_INS_MTBR3 = 815; + public static final int PPC_INS_MTBR4 = 816; + public static final int PPC_INS_MTBR5 = 817; + public static final int PPC_INS_MTBR6 = 818; + public static final int PPC_INS_MTBR7 = 819; + public static final int PPC_INS_MTXER = 820; + public static final int PPC_INS_MTDSCR = 821; + public static final int PPC_INS_MTDSISR = 822; + public static final int PPC_INS_MTDAR = 823; + public static final int PPC_INS_MTSRR2 = 824; + public static final int PPC_INS_MTSRR3 = 825; + public static final int PPC_INS_MTCFAR = 826; + public static final int PPC_INS_MTAMR = 827; + public static final int PPC_INS_MTPID = 828; + public static final int PPC_INS_MTTBL = 829; + public static final int PPC_INS_MTTBU = 830; + public static final int PPC_INS_MTTBLO = 831; + public static final int PPC_INS_MTTBHI = 832; + public static final int PPC_INS_MTDBATU = 833; + public static final int PPC_INS_MTDBATL = 834; + public static final int PPC_INS_MTIBATU = 835; + public static final int PPC_INS_MTIBATL = 836; + public static final int PPC_INS_MTDCCR = 837; + public static final int PPC_INS_MTICCR = 838; + public static final int PPC_INS_MTDEAR = 839; + public static final int PPC_INS_MTESR = 840; + public static final int PPC_INS_MTSPEFSCR = 841; + public static final int PPC_INS_MTTCR = 842; + public static final int PPC_INS_NOT = 843; + public static final int PPC_INS_MR = 844; + public static final int PPC_INS_ROTLD = 845; + public static final int PPC_INS_ROTLDI = 846; + public static final int PPC_INS_CLRLDI = 847; + public static final int PPC_INS_ROTLWI = 848; + public static final int PPC_INS_CLRLWI = 849; + public static final int PPC_INS_ROTLW = 850; + public static final int PPC_INS_SUB = 851; + public static final int PPC_INS_SUBC = 852; + public static final int PPC_INS_LWSYNC = 853; + public static final int PPC_INS_PTESYNC = 854; + public static final int PPC_INS_TDLT = 855; + public static final int PPC_INS_TDEQ = 856; + public static final int PPC_INS_TDGT = 857; + public static final int PPC_INS_TDNE = 858; + public static final int PPC_INS_TDLLT = 859; + public static final int PPC_INS_TDLGT = 860; + public static final int PPC_INS_TDU = 861; + public static final int PPC_INS_TDLTI = 862; + public static final int PPC_INS_TDEQI = 863; + public static final int PPC_INS_TDGTI = 864; + public static final int PPC_INS_TDNEI = 865; + public static final int PPC_INS_TDLLTI = 866; + public static final int PPC_INS_TDLGTI = 867; + public static final int PPC_INS_TDUI = 868; + public static final int PPC_INS_TLBREHI = 869; + public static final int PPC_INS_TLBRELO = 870; + public static final int PPC_INS_TLBWEHI = 871; + public static final int PPC_INS_TLBWELO = 872; + public static final int PPC_INS_TWLT = 873; + public static final int PPC_INS_TWEQ = 874; + public static final int PPC_INS_TWGT = 875; + public static final int PPC_INS_TWNE = 876; + public static final int PPC_INS_TWLLT = 877; + public static final int PPC_INS_TWLGT = 878; + public static final int PPC_INS_TWU = 879; + public static final int PPC_INS_TWLTI = 880; + public static final int PPC_INS_TWEQI = 881; + public static final int PPC_INS_TWGTI = 882; + public static final int PPC_INS_TWNEI = 883; + public static final int PPC_INS_TWLLTI = 884; + public static final int PPC_INS_TWLGTI = 885; + public static final int PPC_INS_TWUI = 886; + public static final int PPC_INS_WAITRSV = 887; + public static final int PPC_INS_WAITIMPL = 888; + public static final int PPC_INS_XNOP = 889; + public static final int PPC_INS_XVMOVDP = 890; + public static final int PPC_INS_XVMOVSP = 891; + public static final int PPC_INS_XXSPLTD = 892; + public static final int PPC_INS_XXMRGHD = 893; + public static final int PPC_INS_XXMRGLD = 894; + public static final int PPC_INS_XXSWAPD = 895; + public static final int PPC_INS_BT = 896; + public static final int PPC_INS_BF = 897; + public static final int PPC_INS_BDNZT = 898; + public static final int PPC_INS_BDNZF = 899; + public static final int PPC_INS_BDZF = 900; + public static final int PPC_INS_BDZT = 901; + public static final int PPC_INS_BFA = 902; + public static final int PPC_INS_BDNZTA = 903; + public static final int PPC_INS_BDNZFA = 904; + public static final int PPC_INS_BDZTA = 905; + public static final int PPC_INS_BDZFA = 906; + public static final int PPC_INS_BTCTR = 907; + public static final int PPC_INS_BFCTR = 908; + public static final int PPC_INS_BTCTRL = 909; + public static final int PPC_INS_BFCTRL = 910; + public static final int PPC_INS_BTL = 911; + public static final int PPC_INS_BFL = 912; + public static final int PPC_INS_BDNZTL = 913; + public static final int PPC_INS_BDNZFL = 914; + public static final int PPC_INS_BDZTL = 915; + public static final int PPC_INS_BDZFL = 916; + public static final int PPC_INS_BTLA = 917; + public static final int PPC_INS_BFLA = 918; + public static final int PPC_INS_BDNZTLA = 919; + public static final int PPC_INS_BDNZFLA = 920; + public static final int PPC_INS_BDZTLA = 921; + public static final int PPC_INS_BDZFLA = 922; + public static final int PPC_INS_BTLR = 923; + public static final int PPC_INS_BFLR = 924; + public static final int PPC_INS_BDNZTLR = 925; + public static final int PPC_INS_BDZTLR = 926; + public static final int PPC_INS_BDZFLR = 927; + public static final int PPC_INS_BTLRL = 928; + public static final int PPC_INS_BFLRL = 929; + public static final int PPC_INS_BDNZTLRL = 930; + public static final int PPC_INS_BDNZFLRL = 931; + public static final int PPC_INS_BDZTLRL = 932; + public static final int PPC_INS_BDZFLRL = 933; + public static final int PPC_INS_ENDING = 934; + + // Group of PPC instructions + + public static final int PPC_GRP_INVALID = 0; + + // Generic groups + public static final int PPC_GRP_JUMP = 1; + + // Architecture-specific groups + public static final int PPC_GRP_ALTIVEC = 128; + public static final int PPC_GRP_MODE32 = 129; + public static final int PPC_GRP_MODE64 = 130; + public static final int PPC_GRP_BOOKE = 131; + public static final int PPC_GRP_NOTBOOKE = 132; + public static final int PPC_GRP_SPE = 133; + public static final int PPC_GRP_VSX = 134; + public static final int PPC_GRP_E500 = 135; + public static final int PPC_GRP_PPC4XX = 136; + public static final int PPC_GRP_PPC6XX = 137; + public static final int PPC_GRP_ENDING = 138; +} \ No newline at end of file diff --git a/app/src/main/java/capstone/Sparc.java b/app/src/main/java/capstone/Sparc.java new file mode 100644 index 00000000..9a8ca32d --- /dev/null +++ b/app/src/main/java/capstone/Sparc.java @@ -0,0 +1,92 @@ +// Capstone Java binding +// By Nguyen Anh Quynh & Dang Hoang Vu, 2013 + +package capstone; + +import com.sun.jna.Structure; +import com.sun.jna.Union; + +import java.util.List; +import java.util.Arrays; + +import static capstone.Sparc_const.*; + +public class Sparc { + + public static class MemType extends Structure { + public byte base; + public byte index; + public int disp; + + @Override + public List getFieldOrder() { + return Arrays.asList("base", "index", "disp"); + } + } + + public static class OpValue extends Union { + public int reg; + public int imm; + public MemType mem; + } + + public static class Operand extends Structure { + public int type; + public OpValue value; + + public void read() { + readField("type"); + if (type == SPARC_OP_MEM) + value.setType(MemType.class); + if (type == SPARC_OP_IMM || type == SPARC_OP_REG) + value.setType(Integer.TYPE); + if (type == SPARC_OP_INVALID) + return; + readField("value"); + } + + @Override + public List getFieldOrder() { + return Arrays.asList("type", "value"); + } + } + + public static class UnionOpInfo extends Capstone.UnionOpInfo { + public int cc; + public int hint; + public byte op_count; + + public Operand [] op; + + public UnionOpInfo() { + op = new Operand[4]; + } + + public void read() { + readField("cc"); + readField("hint"); + readField("op_count"); + op = new Operand[op_count]; + if (op_count != 0) + readField("op"); + } + + @Override + public List getFieldOrder() { + return Arrays.asList("cc", "hint", "op_count", "op"); + } + } + + public static class OpInfo extends Capstone.OpInfo { + public int cc; + public int hint; + + public Operand [] op; + + public OpInfo(UnionOpInfo op_info) { + cc = op_info.cc; + hint = op_info.hint; + op = op_info.op; + } + } +} diff --git a/app/src/main/java/capstone/Sparc_const.java b/app/src/main/java/capstone/Sparc_const.java new file mode 100644 index 00000000..564502b6 --- /dev/null +++ b/app/src/main/java/capstone/Sparc_const.java @@ -0,0 +1,453 @@ +// For Capstone Engine. AUTO-GENERATED FILE, DO NOT EDIT +package capstone; + +public class Sparc_const { + + // Enums corresponding to Sparc condition codes, both icc's and fcc's. + + public static final int SPARC_CC_INVALID = 0; + + // Integer condition codes + public static final int SPARC_CC_ICC_A = 8+256; + public static final int SPARC_CC_ICC_N = 0+256; + public static final int SPARC_CC_ICC_NE = 9+256; + public static final int SPARC_CC_ICC_E = 1+256; + public static final int SPARC_CC_ICC_G = 10+256; + public static final int SPARC_CC_ICC_LE = 2+256; + public static final int SPARC_CC_ICC_GE = 11+256; + public static final int SPARC_CC_ICC_L = 3+256; + public static final int SPARC_CC_ICC_GU = 12+256; + public static final int SPARC_CC_ICC_LEU = 4+256; + public static final int SPARC_CC_ICC_CC = 13+256; + public static final int SPARC_CC_ICC_CS = 5+256; + public static final int SPARC_CC_ICC_POS = 14+256; + public static final int SPARC_CC_ICC_NEG = 6+256; + public static final int SPARC_CC_ICC_VC = 15+256; + public static final int SPARC_CC_ICC_VS = 7+256; + + // Floating condition codes + public static final int SPARC_CC_FCC_A = 8+16+256; + public static final int SPARC_CC_FCC_N = 0+16+256; + public static final int SPARC_CC_FCC_U = 7+16+256; + public static final int SPARC_CC_FCC_G = 6+16+256; + public static final int SPARC_CC_FCC_UG = 5+16+256; + public static final int SPARC_CC_FCC_L = 4+16+256; + public static final int SPARC_CC_FCC_UL = 3+16+256; + public static final int SPARC_CC_FCC_LG = 2+16+256; + public static final int SPARC_CC_FCC_NE = 1+16+256; + public static final int SPARC_CC_FCC_E = 9+16+256; + public static final int SPARC_CC_FCC_UE = 10+16+256; + public static final int SPARC_CC_FCC_GE = 11+16+256; + public static final int SPARC_CC_FCC_UGE = 12+16+256; + public static final int SPARC_CC_FCC_LE = 13+16+256; + public static final int SPARC_CC_FCC_ULE = 14+16+256; + public static final int SPARC_CC_FCC_O = 15+16+256; + + // Branch hint + + public static final int SPARC_HINT_INVALID = 0; + public static final int SPARC_HINT_A = 1<<0; + public static final int SPARC_HINT_PT = 1<<1; + public static final int SPARC_HINT_PN = 1<<2; + + // Operand type for instruction's operands + + public static final int SPARC_OP_INVALID = 0; + public static final int SPARC_OP_REG = 1; + public static final int SPARC_OP_IMM = 2; + public static final int SPARC_OP_MEM = 3; + + // SPARC registers + + public static final int SPARC_REG_INVALID = 0; + public static final int SPARC_REG_F0 = 1; + public static final int SPARC_REG_F1 = 2; + public static final int SPARC_REG_F2 = 3; + public static final int SPARC_REG_F3 = 4; + public static final int SPARC_REG_F4 = 5; + public static final int SPARC_REG_F5 = 6; + public static final int SPARC_REG_F6 = 7; + public static final int SPARC_REG_F7 = 8; + public static final int SPARC_REG_F8 = 9; + public static final int SPARC_REG_F9 = 10; + public static final int SPARC_REG_F10 = 11; + public static final int SPARC_REG_F11 = 12; + public static final int SPARC_REG_F12 = 13; + public static final int SPARC_REG_F13 = 14; + public static final int SPARC_REG_F14 = 15; + public static final int SPARC_REG_F15 = 16; + public static final int SPARC_REG_F16 = 17; + public static final int SPARC_REG_F17 = 18; + public static final int SPARC_REG_F18 = 19; + public static final int SPARC_REG_F19 = 20; + public static final int SPARC_REG_F20 = 21; + public static final int SPARC_REG_F21 = 22; + public static final int SPARC_REG_F22 = 23; + public static final int SPARC_REG_F23 = 24; + public static final int SPARC_REG_F24 = 25; + public static final int SPARC_REG_F25 = 26; + public static final int SPARC_REG_F26 = 27; + public static final int SPARC_REG_F27 = 28; + public static final int SPARC_REG_F28 = 29; + public static final int SPARC_REG_F29 = 30; + public static final int SPARC_REG_F30 = 31; + public static final int SPARC_REG_F31 = 32; + public static final int SPARC_REG_F32 = 33; + public static final int SPARC_REG_F34 = 34; + public static final int SPARC_REG_F36 = 35; + public static final int SPARC_REG_F38 = 36; + public static final int SPARC_REG_F40 = 37; + public static final int SPARC_REG_F42 = 38; + public static final int SPARC_REG_F44 = 39; + public static final int SPARC_REG_F46 = 40; + public static final int SPARC_REG_F48 = 41; + public static final int SPARC_REG_F50 = 42; + public static final int SPARC_REG_F52 = 43; + public static final int SPARC_REG_F54 = 44; + public static final int SPARC_REG_F56 = 45; + public static final int SPARC_REG_F58 = 46; + public static final int SPARC_REG_F60 = 47; + public static final int SPARC_REG_F62 = 48; + public static final int SPARC_REG_FCC0 = 49; + public static final int SPARC_REG_FCC1 = 50; + public static final int SPARC_REG_FCC2 = 51; + public static final int SPARC_REG_FCC3 = 52; + public static final int SPARC_REG_FP = 53; + public static final int SPARC_REG_G0 = 54; + public static final int SPARC_REG_G1 = 55; + public static final int SPARC_REG_G2 = 56; + public static final int SPARC_REG_G3 = 57; + public static final int SPARC_REG_G4 = 58; + public static final int SPARC_REG_G5 = 59; + public static final int SPARC_REG_G6 = 60; + public static final int SPARC_REG_G7 = 61; + public static final int SPARC_REG_I0 = 62; + public static final int SPARC_REG_I1 = 63; + public static final int SPARC_REG_I2 = 64; + public static final int SPARC_REG_I3 = 65; + public static final int SPARC_REG_I4 = 66; + public static final int SPARC_REG_I5 = 67; + public static final int SPARC_REG_I7 = 68; + public static final int SPARC_REG_ICC = 69; + public static final int SPARC_REG_L0 = 70; + public static final int SPARC_REG_L1 = 71; + public static final int SPARC_REG_L2 = 72; + public static final int SPARC_REG_L3 = 73; + public static final int SPARC_REG_L4 = 74; + public static final int SPARC_REG_L5 = 75; + public static final int SPARC_REG_L6 = 76; + public static final int SPARC_REG_L7 = 77; + public static final int SPARC_REG_O0 = 78; + public static final int SPARC_REG_O1 = 79; + public static final int SPARC_REG_O2 = 80; + public static final int SPARC_REG_O3 = 81; + public static final int SPARC_REG_O4 = 82; + public static final int SPARC_REG_O5 = 83; + public static final int SPARC_REG_O7 = 84; + public static final int SPARC_REG_SP = 85; + public static final int SPARC_REG_Y = 86; + public static final int SPARC_REG_XCC = 87; + public static final int SPARC_REG_ENDING = 88; + public static final int SPARC_REG_O6 = SPARC_REG_SP; + public static final int SPARC_REG_I6 = SPARC_REG_FP; + + // SPARC instruction + + public static final int SPARC_INS_INVALID = 0; + public static final int SPARC_INS_ADDCC = 1; + public static final int SPARC_INS_ADDX = 2; + public static final int SPARC_INS_ADDXCC = 3; + public static final int SPARC_INS_ADDXC = 4; + public static final int SPARC_INS_ADDXCCC = 5; + public static final int SPARC_INS_ADD = 6; + public static final int SPARC_INS_ALIGNADDR = 7; + public static final int SPARC_INS_ALIGNADDRL = 8; + public static final int SPARC_INS_ANDCC = 9; + public static final int SPARC_INS_ANDNCC = 10; + public static final int SPARC_INS_ANDN = 11; + public static final int SPARC_INS_AND = 12; + public static final int SPARC_INS_ARRAY16 = 13; + public static final int SPARC_INS_ARRAY32 = 14; + public static final int SPARC_INS_ARRAY8 = 15; + public static final int SPARC_INS_B = 16; + public static final int SPARC_INS_JMP = 17; + public static final int SPARC_INS_BMASK = 18; + public static final int SPARC_INS_FB = 19; + public static final int SPARC_INS_BRGEZ = 20; + public static final int SPARC_INS_BRGZ = 21; + public static final int SPARC_INS_BRLEZ = 22; + public static final int SPARC_INS_BRLZ = 23; + public static final int SPARC_INS_BRNZ = 24; + public static final int SPARC_INS_BRZ = 25; + public static final int SPARC_INS_BSHUFFLE = 26; + public static final int SPARC_INS_CALL = 27; + public static final int SPARC_INS_CASX = 28; + public static final int SPARC_INS_CAS = 29; + public static final int SPARC_INS_CMASK16 = 30; + public static final int SPARC_INS_CMASK32 = 31; + public static final int SPARC_INS_CMASK8 = 32; + public static final int SPARC_INS_CMP = 33; + public static final int SPARC_INS_EDGE16 = 34; + public static final int SPARC_INS_EDGE16L = 35; + public static final int SPARC_INS_EDGE16LN = 36; + public static final int SPARC_INS_EDGE16N = 37; + public static final int SPARC_INS_EDGE32 = 38; + public static final int SPARC_INS_EDGE32L = 39; + public static final int SPARC_INS_EDGE32LN = 40; + public static final int SPARC_INS_EDGE32N = 41; + public static final int SPARC_INS_EDGE8 = 42; + public static final int SPARC_INS_EDGE8L = 43; + public static final int SPARC_INS_EDGE8LN = 44; + public static final int SPARC_INS_EDGE8N = 45; + public static final int SPARC_INS_FABSD = 46; + public static final int SPARC_INS_FABSQ = 47; + public static final int SPARC_INS_FABSS = 48; + public static final int SPARC_INS_FADDD = 49; + public static final int SPARC_INS_FADDQ = 50; + public static final int SPARC_INS_FADDS = 51; + public static final int SPARC_INS_FALIGNDATA = 52; + public static final int SPARC_INS_FAND = 53; + public static final int SPARC_INS_FANDNOT1 = 54; + public static final int SPARC_INS_FANDNOT1S = 55; + public static final int SPARC_INS_FANDNOT2 = 56; + public static final int SPARC_INS_FANDNOT2S = 57; + public static final int SPARC_INS_FANDS = 58; + public static final int SPARC_INS_FCHKSM16 = 59; + public static final int SPARC_INS_FCMPD = 60; + public static final int SPARC_INS_FCMPEQ16 = 61; + public static final int SPARC_INS_FCMPEQ32 = 62; + public static final int SPARC_INS_FCMPGT16 = 63; + public static final int SPARC_INS_FCMPGT32 = 64; + public static final int SPARC_INS_FCMPLE16 = 65; + public static final int SPARC_INS_FCMPLE32 = 66; + public static final int SPARC_INS_FCMPNE16 = 67; + public static final int SPARC_INS_FCMPNE32 = 68; + public static final int SPARC_INS_FCMPQ = 69; + public static final int SPARC_INS_FCMPS = 70; + public static final int SPARC_INS_FDIVD = 71; + public static final int SPARC_INS_FDIVQ = 72; + public static final int SPARC_INS_FDIVS = 73; + public static final int SPARC_INS_FDMULQ = 74; + public static final int SPARC_INS_FDTOI = 75; + public static final int SPARC_INS_FDTOQ = 76; + public static final int SPARC_INS_FDTOS = 77; + public static final int SPARC_INS_FDTOX = 78; + public static final int SPARC_INS_FEXPAND = 79; + public static final int SPARC_INS_FHADDD = 80; + public static final int SPARC_INS_FHADDS = 81; + public static final int SPARC_INS_FHSUBD = 82; + public static final int SPARC_INS_FHSUBS = 83; + public static final int SPARC_INS_FITOD = 84; + public static final int SPARC_INS_FITOQ = 85; + public static final int SPARC_INS_FITOS = 86; + public static final int SPARC_INS_FLCMPD = 87; + public static final int SPARC_INS_FLCMPS = 88; + public static final int SPARC_INS_FLUSHW = 89; + public static final int SPARC_INS_FMEAN16 = 90; + public static final int SPARC_INS_FMOVD = 91; + public static final int SPARC_INS_FMOVQ = 92; + public static final int SPARC_INS_FMOVRDGEZ = 93; + public static final int SPARC_INS_FMOVRQGEZ = 94; + public static final int SPARC_INS_FMOVRSGEZ = 95; + public static final int SPARC_INS_FMOVRDGZ = 96; + public static final int SPARC_INS_FMOVRQGZ = 97; + public static final int SPARC_INS_FMOVRSGZ = 98; + public static final int SPARC_INS_FMOVRDLEZ = 99; + public static final int SPARC_INS_FMOVRQLEZ = 100; + public static final int SPARC_INS_FMOVRSLEZ = 101; + public static final int SPARC_INS_FMOVRDLZ = 102; + public static final int SPARC_INS_FMOVRQLZ = 103; + public static final int SPARC_INS_FMOVRSLZ = 104; + public static final int SPARC_INS_FMOVRDNZ = 105; + public static final int SPARC_INS_FMOVRQNZ = 106; + public static final int SPARC_INS_FMOVRSNZ = 107; + public static final int SPARC_INS_FMOVRDZ = 108; + public static final int SPARC_INS_FMOVRQZ = 109; + public static final int SPARC_INS_FMOVRSZ = 110; + public static final int SPARC_INS_FMOVS = 111; + public static final int SPARC_INS_FMUL8SUX16 = 112; + public static final int SPARC_INS_FMUL8ULX16 = 113; + public static final int SPARC_INS_FMUL8X16 = 114; + public static final int SPARC_INS_FMUL8X16AL = 115; + public static final int SPARC_INS_FMUL8X16AU = 116; + public static final int SPARC_INS_FMULD = 117; + public static final int SPARC_INS_FMULD8SUX16 = 118; + public static final int SPARC_INS_FMULD8ULX16 = 119; + public static final int SPARC_INS_FMULQ = 120; + public static final int SPARC_INS_FMULS = 121; + public static final int SPARC_INS_FNADDD = 122; + public static final int SPARC_INS_FNADDS = 123; + public static final int SPARC_INS_FNAND = 124; + public static final int SPARC_INS_FNANDS = 125; + public static final int SPARC_INS_FNEGD = 126; + public static final int SPARC_INS_FNEGQ = 127; + public static final int SPARC_INS_FNEGS = 128; + public static final int SPARC_INS_FNHADDD = 129; + public static final int SPARC_INS_FNHADDS = 130; + public static final int SPARC_INS_FNOR = 131; + public static final int SPARC_INS_FNORS = 132; + public static final int SPARC_INS_FNOT1 = 133; + public static final int SPARC_INS_FNOT1S = 134; + public static final int SPARC_INS_FNOT2 = 135; + public static final int SPARC_INS_FNOT2S = 136; + public static final int SPARC_INS_FONE = 137; + public static final int SPARC_INS_FONES = 138; + public static final int SPARC_INS_FOR = 139; + public static final int SPARC_INS_FORNOT1 = 140; + public static final int SPARC_INS_FORNOT1S = 141; + public static final int SPARC_INS_FORNOT2 = 142; + public static final int SPARC_INS_FORNOT2S = 143; + public static final int SPARC_INS_FORS = 144; + public static final int SPARC_INS_FPACK16 = 145; + public static final int SPARC_INS_FPACK32 = 146; + public static final int SPARC_INS_FPACKFIX = 147; + public static final int SPARC_INS_FPADD16 = 148; + public static final int SPARC_INS_FPADD16S = 149; + public static final int SPARC_INS_FPADD32 = 150; + public static final int SPARC_INS_FPADD32S = 151; + public static final int SPARC_INS_FPADD64 = 152; + public static final int SPARC_INS_FPMERGE = 153; + public static final int SPARC_INS_FPSUB16 = 154; + public static final int SPARC_INS_FPSUB16S = 155; + public static final int SPARC_INS_FPSUB32 = 156; + public static final int SPARC_INS_FPSUB32S = 157; + public static final int SPARC_INS_FQTOD = 158; + public static final int SPARC_INS_FQTOI = 159; + public static final int SPARC_INS_FQTOS = 160; + public static final int SPARC_INS_FQTOX = 161; + public static final int SPARC_INS_FSLAS16 = 162; + public static final int SPARC_INS_FSLAS32 = 163; + public static final int SPARC_INS_FSLL16 = 164; + public static final int SPARC_INS_FSLL32 = 165; + public static final int SPARC_INS_FSMULD = 166; + public static final int SPARC_INS_FSQRTD = 167; + public static final int SPARC_INS_FSQRTQ = 168; + public static final int SPARC_INS_FSQRTS = 169; + public static final int SPARC_INS_FSRA16 = 170; + public static final int SPARC_INS_FSRA32 = 171; + public static final int SPARC_INS_FSRC1 = 172; + public static final int SPARC_INS_FSRC1S = 173; + public static final int SPARC_INS_FSRC2 = 174; + public static final int SPARC_INS_FSRC2S = 175; + public static final int SPARC_INS_FSRL16 = 176; + public static final int SPARC_INS_FSRL32 = 177; + public static final int SPARC_INS_FSTOD = 178; + public static final int SPARC_INS_FSTOI = 179; + public static final int SPARC_INS_FSTOQ = 180; + public static final int SPARC_INS_FSTOX = 181; + public static final int SPARC_INS_FSUBD = 182; + public static final int SPARC_INS_FSUBQ = 183; + public static final int SPARC_INS_FSUBS = 184; + public static final int SPARC_INS_FXNOR = 185; + public static final int SPARC_INS_FXNORS = 186; + public static final int SPARC_INS_FXOR = 187; + public static final int SPARC_INS_FXORS = 188; + public static final int SPARC_INS_FXTOD = 189; + public static final int SPARC_INS_FXTOQ = 190; + public static final int SPARC_INS_FXTOS = 191; + public static final int SPARC_INS_FZERO = 192; + public static final int SPARC_INS_FZEROS = 193; + public static final int SPARC_INS_JMPL = 194; + public static final int SPARC_INS_LDD = 195; + public static final int SPARC_INS_LD = 196; + public static final int SPARC_INS_LDQ = 197; + public static final int SPARC_INS_LDSB = 198; + public static final int SPARC_INS_LDSH = 199; + public static final int SPARC_INS_LDSW = 200; + public static final int SPARC_INS_LDUB = 201; + public static final int SPARC_INS_LDUH = 202; + public static final int SPARC_INS_LDX = 203; + public static final int SPARC_INS_LZCNT = 204; + public static final int SPARC_INS_MEMBAR = 205; + public static final int SPARC_INS_MOVDTOX = 206; + public static final int SPARC_INS_MOV = 207; + public static final int SPARC_INS_MOVRGEZ = 208; + public static final int SPARC_INS_MOVRGZ = 209; + public static final int SPARC_INS_MOVRLEZ = 210; + public static final int SPARC_INS_MOVRLZ = 211; + public static final int SPARC_INS_MOVRNZ = 212; + public static final int SPARC_INS_MOVRZ = 213; + public static final int SPARC_INS_MOVSTOSW = 214; + public static final int SPARC_INS_MOVSTOUW = 215; + public static final int SPARC_INS_MULX = 216; + public static final int SPARC_INS_NOP = 217; + public static final int SPARC_INS_ORCC = 218; + public static final int SPARC_INS_ORNCC = 219; + public static final int SPARC_INS_ORN = 220; + public static final int SPARC_INS_OR = 221; + public static final int SPARC_INS_PDIST = 222; + public static final int SPARC_INS_PDISTN = 223; + public static final int SPARC_INS_POPC = 224; + public static final int SPARC_INS_RD = 225; + public static final int SPARC_INS_RESTORE = 226; + public static final int SPARC_INS_RETT = 227; + public static final int SPARC_INS_SAVE = 228; + public static final int SPARC_INS_SDIVCC = 229; + public static final int SPARC_INS_SDIVX = 230; + public static final int SPARC_INS_SDIV = 231; + public static final int SPARC_INS_SETHI = 232; + public static final int SPARC_INS_SHUTDOWN = 233; + public static final int SPARC_INS_SIAM = 234; + public static final int SPARC_INS_SLLX = 235; + public static final int SPARC_INS_SLL = 236; + public static final int SPARC_INS_SMULCC = 237; + public static final int SPARC_INS_SMUL = 238; + public static final int SPARC_INS_SRAX = 239; + public static final int SPARC_INS_SRA = 240; + public static final int SPARC_INS_SRLX = 241; + public static final int SPARC_INS_SRL = 242; + public static final int SPARC_INS_STBAR = 243; + public static final int SPARC_INS_STB = 244; + public static final int SPARC_INS_STD = 245; + public static final int SPARC_INS_ST = 246; + public static final int SPARC_INS_STH = 247; + public static final int SPARC_INS_STQ = 248; + public static final int SPARC_INS_STX = 249; + public static final int SPARC_INS_SUBCC = 250; + public static final int SPARC_INS_SUBX = 251; + public static final int SPARC_INS_SUBXCC = 252; + public static final int SPARC_INS_SUB = 253; + public static final int SPARC_INS_SWAP = 254; + public static final int SPARC_INS_TADDCCTV = 255; + public static final int SPARC_INS_TADDCC = 256; + public static final int SPARC_INS_T = 257; + public static final int SPARC_INS_TSUBCCTV = 258; + public static final int SPARC_INS_TSUBCC = 259; + public static final int SPARC_INS_UDIVCC = 260; + public static final int SPARC_INS_UDIVX = 261; + public static final int SPARC_INS_UDIV = 262; + public static final int SPARC_INS_UMULCC = 263; + public static final int SPARC_INS_UMULXHI = 264; + public static final int SPARC_INS_UMUL = 265; + public static final int SPARC_INS_UNIMP = 266; + public static final int SPARC_INS_FCMPED = 267; + public static final int SPARC_INS_FCMPEQ = 268; + public static final int SPARC_INS_FCMPES = 269; + public static final int SPARC_INS_WR = 270; + public static final int SPARC_INS_XMULX = 271; + public static final int SPARC_INS_XMULXHI = 272; + public static final int SPARC_INS_XNORCC = 273; + public static final int SPARC_INS_XNOR = 274; + public static final int SPARC_INS_XORCC = 275; + public static final int SPARC_INS_XOR = 276; + public static final int SPARC_INS_RET = 277; + public static final int SPARC_INS_RETL = 278; + public static final int SPARC_INS_ENDING = 279; + + // Group of SPARC instructions + + public static final int SPARC_GRP_INVALID = 0; + + // Generic groups + public static final int SPARC_GRP_JUMP = 1; + + // Architecture-specific groups + public static final int SPARC_GRP_HARDQUAD = 128; + public static final int SPARC_GRP_V9 = 129; + public static final int SPARC_GRP_VIS = 130; + public static final int SPARC_GRP_VIS2 = 131; + public static final int SPARC_GRP_VIS3 = 132; + public static final int SPARC_GRP_32BIT = 133; + public static final int SPARC_GRP_64BIT = 134; + public static final int SPARC_GRP_ENDING = 135; +} \ No newline at end of file diff --git a/app/src/main/java/capstone/Systemz.java b/app/src/main/java/capstone/Systemz.java new file mode 100644 index 00000000..1bc5ed70 --- /dev/null +++ b/app/src/main/java/capstone/Systemz.java @@ -0,0 +1,91 @@ +// Capstone Java binding +// By Nguyen Anh Quynh & Dang Hoang Vu, 2013 + +package capstone; + +import com.sun.jna.Structure; +import com.sun.jna.Union; + +import java.util.List; +import java.util.Arrays; + +import static capstone.Sysz_const.*; + +public class Systemz { + + public static class MemType extends Structure { + public byte base; + public byte index; + public long length; + public long disp; + + @Override + public List getFieldOrder() { + return Arrays.asList("base", "index", "length", "disp"); + } + } + + public static class OpValue extends Union { + public int reg; + public long imm; + public MemType mem; + } + + public static class Operand extends Structure { + public int type; + public OpValue value; + + public void read() { + readField("type"); + if (type == SYSZ_OP_MEM) + value.setType(MemType.class); + if (type == SYSZ_OP_IMM) + value.setType(Long.TYPE); + if (type == SYSZ_OP_REG || type == SYSZ_OP_ACREG) + value.setType(Integer.TYPE); + if (type == SYSZ_OP_INVALID) + return; + readField("value"); + } + + @Override + public List getFieldOrder() { + return Arrays.asList("type", "value"); + } + } + + public static class UnionOpInfo extends Capstone.UnionOpInfo { + public int cc; + public byte op_count; + + public Operand [] op; + + public UnionOpInfo() { + op = new Operand[6]; + } + + public void read() { + readField("cc"); + readField("op_count"); + op = new Operand[op_count]; + if (op_count != 0) + readField("op"); + } + + @Override + public List getFieldOrder() { + return Arrays.asList("cc", "op_count", "op"); + } + } + + public static class OpInfo extends Capstone.OpInfo { + public int cc; + + public Operand [] op; + + public OpInfo(UnionOpInfo op_info) { + cc = op_info.cc; + op = op_info.op; + } + } +} diff --git a/app/src/main/java/capstone/Sysz_const.java b/app/src/main/java/capstone/Sysz_const.java new file mode 100644 index 00000000..d8ec9174 --- /dev/null +++ b/app/src/main/java/capstone/Sysz_const.java @@ -0,0 +1,771 @@ +// For Capstone Engine. AUTO-GENERATED FILE, DO NOT EDIT +package capstone; + +public class Sysz_const { + + // Enums corresponding to SystemZ condition codes + + public static final int SYSZ_CC_INVALID = 0; + public static final int SYSZ_CC_O = 1; + public static final int SYSZ_CC_H = 2; + public static final int SYSZ_CC_NLE = 3; + public static final int SYSZ_CC_L = 4; + public static final int SYSZ_CC_NHE = 5; + public static final int SYSZ_CC_LH = 6; + public static final int SYSZ_CC_NE = 7; + public static final int SYSZ_CC_E = 8; + public static final int SYSZ_CC_NLH = 9; + public static final int SYSZ_CC_HE = 10; + public static final int SYSZ_CC_NL = 11; + public static final int SYSZ_CC_LE = 12; + public static final int SYSZ_CC_NH = 13; + public static final int SYSZ_CC_NO = 14; + + // Operand type for instruction's operands + + public static final int SYSZ_OP_INVALID = 0; + public static final int SYSZ_OP_REG = 1; + public static final int SYSZ_OP_IMM = 2; + public static final int SYSZ_OP_MEM = 3; + public static final int SYSZ_OP_ACREG = 64; + + // SystemZ registers + + public static final int SYSZ_REG_INVALID = 0; + public static final int SYSZ_REG_0 = 1; + public static final int SYSZ_REG_1 = 2; + public static final int SYSZ_REG_2 = 3; + public static final int SYSZ_REG_3 = 4; + public static final int SYSZ_REG_4 = 5; + public static final int SYSZ_REG_5 = 6; + public static final int SYSZ_REG_6 = 7; + public static final int SYSZ_REG_7 = 8; + public static final int SYSZ_REG_8 = 9; + public static final int SYSZ_REG_9 = 10; + public static final int SYSZ_REG_10 = 11; + public static final int SYSZ_REG_11 = 12; + public static final int SYSZ_REG_12 = 13; + public static final int SYSZ_REG_13 = 14; + public static final int SYSZ_REG_14 = 15; + public static final int SYSZ_REG_15 = 16; + public static final int SYSZ_REG_CC = 17; + public static final int SYSZ_REG_F0 = 18; + public static final int SYSZ_REG_F1 = 19; + public static final int SYSZ_REG_F2 = 20; + public static final int SYSZ_REG_F3 = 21; + public static final int SYSZ_REG_F4 = 22; + public static final int SYSZ_REG_F5 = 23; + public static final int SYSZ_REG_F6 = 24; + public static final int SYSZ_REG_F7 = 25; + public static final int SYSZ_REG_F8 = 26; + public static final int SYSZ_REG_F9 = 27; + public static final int SYSZ_REG_F10 = 28; + public static final int SYSZ_REG_F11 = 29; + public static final int SYSZ_REG_F12 = 30; + public static final int SYSZ_REG_F13 = 31; + public static final int SYSZ_REG_F14 = 32; + public static final int SYSZ_REG_F15 = 33; + public static final int SYSZ_REG_R0L = 34; + public static final int SYSZ_REG_ENDING = 35; + + // SystemZ instruction + + public static final int SYSZ_INS_INVALID = 0; + public static final int SYSZ_INS_A = 1; + public static final int SYSZ_INS_ADB = 2; + public static final int SYSZ_INS_ADBR = 3; + public static final int SYSZ_INS_AEB = 4; + public static final int SYSZ_INS_AEBR = 5; + public static final int SYSZ_INS_AFI = 6; + public static final int SYSZ_INS_AG = 7; + public static final int SYSZ_INS_AGF = 8; + public static final int SYSZ_INS_AGFI = 9; + public static final int SYSZ_INS_AGFR = 10; + public static final int SYSZ_INS_AGHI = 11; + public static final int SYSZ_INS_AGHIK = 12; + public static final int SYSZ_INS_AGR = 13; + public static final int SYSZ_INS_AGRK = 14; + public static final int SYSZ_INS_AGSI = 15; + public static final int SYSZ_INS_AH = 16; + public static final int SYSZ_INS_AHI = 17; + public static final int SYSZ_INS_AHIK = 18; + public static final int SYSZ_INS_AHY = 19; + public static final int SYSZ_INS_AIH = 20; + public static final int SYSZ_INS_AL = 21; + public static final int SYSZ_INS_ALC = 22; + public static final int SYSZ_INS_ALCG = 23; + public static final int SYSZ_INS_ALCGR = 24; + public static final int SYSZ_INS_ALCR = 25; + public static final int SYSZ_INS_ALFI = 26; + public static final int SYSZ_INS_ALG = 27; + public static final int SYSZ_INS_ALGF = 28; + public static final int SYSZ_INS_ALGFI = 29; + public static final int SYSZ_INS_ALGFR = 30; + public static final int SYSZ_INS_ALGHSIK = 31; + public static final int SYSZ_INS_ALGR = 32; + public static final int SYSZ_INS_ALGRK = 33; + public static final int SYSZ_INS_ALHSIK = 34; + public static final int SYSZ_INS_ALR = 35; + public static final int SYSZ_INS_ALRK = 36; + public static final int SYSZ_INS_ALY = 37; + public static final int SYSZ_INS_AR = 38; + public static final int SYSZ_INS_ARK = 39; + public static final int SYSZ_INS_ASI = 40; + public static final int SYSZ_INS_AXBR = 41; + public static final int SYSZ_INS_AY = 42; + public static final int SYSZ_INS_BCR = 43; + public static final int SYSZ_INS_BRC = 44; + public static final int SYSZ_INS_BRCL = 45; + public static final int SYSZ_INS_CGIJ = 46; + public static final int SYSZ_INS_CGRJ = 47; + public static final int SYSZ_INS_CIJ = 48; + public static final int SYSZ_INS_CLGIJ = 49; + public static final int SYSZ_INS_CLGRJ = 50; + public static final int SYSZ_INS_CLIJ = 51; + public static final int SYSZ_INS_CLRJ = 52; + public static final int SYSZ_INS_CRJ = 53; + public static final int SYSZ_INS_BER = 54; + public static final int SYSZ_INS_JE = 55; + public static final int SYSZ_INS_JGE = 56; + public static final int SYSZ_INS_LOCE = 57; + public static final int SYSZ_INS_LOCGE = 58; + public static final int SYSZ_INS_LOCGRE = 59; + public static final int SYSZ_INS_LOCRE = 60; + public static final int SYSZ_INS_STOCE = 61; + public static final int SYSZ_INS_STOCGE = 62; + public static final int SYSZ_INS_BHR = 63; + public static final int SYSZ_INS_BHER = 64; + public static final int SYSZ_INS_JHE = 65; + public static final int SYSZ_INS_JGHE = 66; + public static final int SYSZ_INS_LOCHE = 67; + public static final int SYSZ_INS_LOCGHE = 68; + public static final int SYSZ_INS_LOCGRHE = 69; + public static final int SYSZ_INS_LOCRHE = 70; + public static final int SYSZ_INS_STOCHE = 71; + public static final int SYSZ_INS_STOCGHE = 72; + public static final int SYSZ_INS_JH = 73; + public static final int SYSZ_INS_JGH = 74; + public static final int SYSZ_INS_LOCH = 75; + public static final int SYSZ_INS_LOCGH = 76; + public static final int SYSZ_INS_LOCGRH = 77; + public static final int SYSZ_INS_LOCRH = 78; + public static final int SYSZ_INS_STOCH = 79; + public static final int SYSZ_INS_STOCGH = 80; + public static final int SYSZ_INS_CGIJNLH = 81; + public static final int SYSZ_INS_CGRJNLH = 82; + public static final int SYSZ_INS_CIJNLH = 83; + public static final int SYSZ_INS_CLGIJNLH = 84; + public static final int SYSZ_INS_CLGRJNLH = 85; + public static final int SYSZ_INS_CLIJNLH = 86; + public static final int SYSZ_INS_CLRJNLH = 87; + public static final int SYSZ_INS_CRJNLH = 88; + public static final int SYSZ_INS_CGIJE = 89; + public static final int SYSZ_INS_CGRJE = 90; + public static final int SYSZ_INS_CIJE = 91; + public static final int SYSZ_INS_CLGIJE = 92; + public static final int SYSZ_INS_CLGRJE = 93; + public static final int SYSZ_INS_CLIJE = 94; + public static final int SYSZ_INS_CLRJE = 95; + public static final int SYSZ_INS_CRJE = 96; + public static final int SYSZ_INS_CGIJNLE = 97; + public static final int SYSZ_INS_CGRJNLE = 98; + public static final int SYSZ_INS_CIJNLE = 99; + public static final int SYSZ_INS_CLGIJNLE = 100; + public static final int SYSZ_INS_CLGRJNLE = 101; + public static final int SYSZ_INS_CLIJNLE = 102; + public static final int SYSZ_INS_CLRJNLE = 103; + public static final int SYSZ_INS_CRJNLE = 104; + public static final int SYSZ_INS_CGIJH = 105; + public static final int SYSZ_INS_CGRJH = 106; + public static final int SYSZ_INS_CIJH = 107; + public static final int SYSZ_INS_CLGIJH = 108; + public static final int SYSZ_INS_CLGRJH = 109; + public static final int SYSZ_INS_CLIJH = 110; + public static final int SYSZ_INS_CLRJH = 111; + public static final int SYSZ_INS_CRJH = 112; + public static final int SYSZ_INS_CGIJNL = 113; + public static final int SYSZ_INS_CGRJNL = 114; + public static final int SYSZ_INS_CIJNL = 115; + public static final int SYSZ_INS_CLGIJNL = 116; + public static final int SYSZ_INS_CLGRJNL = 117; + public static final int SYSZ_INS_CLIJNL = 118; + public static final int SYSZ_INS_CLRJNL = 119; + public static final int SYSZ_INS_CRJNL = 120; + public static final int SYSZ_INS_CGIJHE = 121; + public static final int SYSZ_INS_CGRJHE = 122; + public static final int SYSZ_INS_CIJHE = 123; + public static final int SYSZ_INS_CLGIJHE = 124; + public static final int SYSZ_INS_CLGRJHE = 125; + public static final int SYSZ_INS_CLIJHE = 126; + public static final int SYSZ_INS_CLRJHE = 127; + public static final int SYSZ_INS_CRJHE = 128; + public static final int SYSZ_INS_CGIJNHE = 129; + public static final int SYSZ_INS_CGRJNHE = 130; + public static final int SYSZ_INS_CIJNHE = 131; + public static final int SYSZ_INS_CLGIJNHE = 132; + public static final int SYSZ_INS_CLGRJNHE = 133; + public static final int SYSZ_INS_CLIJNHE = 134; + public static final int SYSZ_INS_CLRJNHE = 135; + public static final int SYSZ_INS_CRJNHE = 136; + public static final int SYSZ_INS_CGIJL = 137; + public static final int SYSZ_INS_CGRJL = 138; + public static final int SYSZ_INS_CIJL = 139; + public static final int SYSZ_INS_CLGIJL = 140; + public static final int SYSZ_INS_CLGRJL = 141; + public static final int SYSZ_INS_CLIJL = 142; + public static final int SYSZ_INS_CLRJL = 143; + public static final int SYSZ_INS_CRJL = 144; + public static final int SYSZ_INS_CGIJNH = 145; + public static final int SYSZ_INS_CGRJNH = 146; + public static final int SYSZ_INS_CIJNH = 147; + public static final int SYSZ_INS_CLGIJNH = 148; + public static final int SYSZ_INS_CLGRJNH = 149; + public static final int SYSZ_INS_CLIJNH = 150; + public static final int SYSZ_INS_CLRJNH = 151; + public static final int SYSZ_INS_CRJNH = 152; + public static final int SYSZ_INS_CGIJLE = 153; + public static final int SYSZ_INS_CGRJLE = 154; + public static final int SYSZ_INS_CIJLE = 155; + public static final int SYSZ_INS_CLGIJLE = 156; + public static final int SYSZ_INS_CLGRJLE = 157; + public static final int SYSZ_INS_CLIJLE = 158; + public static final int SYSZ_INS_CLRJLE = 159; + public static final int SYSZ_INS_CRJLE = 160; + public static final int SYSZ_INS_CGIJNE = 161; + public static final int SYSZ_INS_CGRJNE = 162; + public static final int SYSZ_INS_CIJNE = 163; + public static final int SYSZ_INS_CLGIJNE = 164; + public static final int SYSZ_INS_CLGRJNE = 165; + public static final int SYSZ_INS_CLIJNE = 166; + public static final int SYSZ_INS_CLRJNE = 167; + public static final int SYSZ_INS_CRJNE = 168; + public static final int SYSZ_INS_CGIJLH = 169; + public static final int SYSZ_INS_CGRJLH = 170; + public static final int SYSZ_INS_CIJLH = 171; + public static final int SYSZ_INS_CLGIJLH = 172; + public static final int SYSZ_INS_CLGRJLH = 173; + public static final int SYSZ_INS_CLIJLH = 174; + public static final int SYSZ_INS_CLRJLH = 175; + public static final int SYSZ_INS_CRJLH = 176; + public static final int SYSZ_INS_BLR = 177; + public static final int SYSZ_INS_BLER = 178; + public static final int SYSZ_INS_JLE = 179; + public static final int SYSZ_INS_JGLE = 180; + public static final int SYSZ_INS_LOCLE = 181; + public static final int SYSZ_INS_LOCGLE = 182; + public static final int SYSZ_INS_LOCGRLE = 183; + public static final int SYSZ_INS_LOCRLE = 184; + public static final int SYSZ_INS_STOCLE = 185; + public static final int SYSZ_INS_STOCGLE = 186; + public static final int SYSZ_INS_BLHR = 187; + public static final int SYSZ_INS_JLH = 188; + public static final int SYSZ_INS_JGLH = 189; + public static final int SYSZ_INS_LOCLH = 190; + public static final int SYSZ_INS_LOCGLH = 191; + public static final int SYSZ_INS_LOCGRLH = 192; + public static final int SYSZ_INS_LOCRLH = 193; + public static final int SYSZ_INS_STOCLH = 194; + public static final int SYSZ_INS_STOCGLH = 195; + public static final int SYSZ_INS_JL = 196; + public static final int SYSZ_INS_JGL = 197; + public static final int SYSZ_INS_LOCL = 198; + public static final int SYSZ_INS_LOCGL = 199; + public static final int SYSZ_INS_LOCGRL = 200; + public static final int SYSZ_INS_LOCRL = 201; + public static final int SYSZ_INS_LOC = 202; + public static final int SYSZ_INS_LOCG = 203; + public static final int SYSZ_INS_LOCGR = 204; + public static final int SYSZ_INS_LOCR = 205; + public static final int SYSZ_INS_STOCL = 206; + public static final int SYSZ_INS_STOCGL = 207; + public static final int SYSZ_INS_BNER = 208; + public static final int SYSZ_INS_JNE = 209; + public static final int SYSZ_INS_JGNE = 210; + public static final int SYSZ_INS_LOCNE = 211; + public static final int SYSZ_INS_LOCGNE = 212; + public static final int SYSZ_INS_LOCGRNE = 213; + public static final int SYSZ_INS_LOCRNE = 214; + public static final int SYSZ_INS_STOCNE = 215; + public static final int SYSZ_INS_STOCGNE = 216; + public static final int SYSZ_INS_BNHR = 217; + public static final int SYSZ_INS_BNHER = 218; + public static final int SYSZ_INS_JNHE = 219; + public static final int SYSZ_INS_JGNHE = 220; + public static final int SYSZ_INS_LOCNHE = 221; + public static final int SYSZ_INS_LOCGNHE = 222; + public static final int SYSZ_INS_LOCGRNHE = 223; + public static final int SYSZ_INS_LOCRNHE = 224; + public static final int SYSZ_INS_STOCNHE = 225; + public static final int SYSZ_INS_STOCGNHE = 226; + public static final int SYSZ_INS_JNH = 227; + public static final int SYSZ_INS_JGNH = 228; + public static final int SYSZ_INS_LOCNH = 229; + public static final int SYSZ_INS_LOCGNH = 230; + public static final int SYSZ_INS_LOCGRNH = 231; + public static final int SYSZ_INS_LOCRNH = 232; + public static final int SYSZ_INS_STOCNH = 233; + public static final int SYSZ_INS_STOCGNH = 234; + public static final int SYSZ_INS_BNLR = 235; + public static final int SYSZ_INS_BNLER = 236; + public static final int SYSZ_INS_JNLE = 237; + public static final int SYSZ_INS_JGNLE = 238; + public static final int SYSZ_INS_LOCNLE = 239; + public static final int SYSZ_INS_LOCGNLE = 240; + public static final int SYSZ_INS_LOCGRNLE = 241; + public static final int SYSZ_INS_LOCRNLE = 242; + public static final int SYSZ_INS_STOCNLE = 243; + public static final int SYSZ_INS_STOCGNLE = 244; + public static final int SYSZ_INS_BNLHR = 245; + public static final int SYSZ_INS_JNLH = 246; + public static final int SYSZ_INS_JGNLH = 247; + public static final int SYSZ_INS_LOCNLH = 248; + public static final int SYSZ_INS_LOCGNLH = 249; + public static final int SYSZ_INS_LOCGRNLH = 250; + public static final int SYSZ_INS_LOCRNLH = 251; + public static final int SYSZ_INS_STOCNLH = 252; + public static final int SYSZ_INS_STOCGNLH = 253; + public static final int SYSZ_INS_JNL = 254; + public static final int SYSZ_INS_JGNL = 255; + public static final int SYSZ_INS_LOCNL = 256; + public static final int SYSZ_INS_LOCGNL = 257; + public static final int SYSZ_INS_LOCGRNL = 258; + public static final int SYSZ_INS_LOCRNL = 259; + public static final int SYSZ_INS_STOCNL = 260; + public static final int SYSZ_INS_STOCGNL = 261; + public static final int SYSZ_INS_BNOR = 262; + public static final int SYSZ_INS_JNO = 263; + public static final int SYSZ_INS_JGNO = 264; + public static final int SYSZ_INS_LOCNO = 265; + public static final int SYSZ_INS_LOCGNO = 266; + public static final int SYSZ_INS_LOCGRNO = 267; + public static final int SYSZ_INS_LOCRNO = 268; + public static final int SYSZ_INS_STOCNO = 269; + public static final int SYSZ_INS_STOCGNO = 270; + public static final int SYSZ_INS_BOR = 271; + public static final int SYSZ_INS_JO = 272; + public static final int SYSZ_INS_JGO = 273; + public static final int SYSZ_INS_LOCO = 274; + public static final int SYSZ_INS_LOCGO = 275; + public static final int SYSZ_INS_LOCGRO = 276; + public static final int SYSZ_INS_LOCRO = 277; + public static final int SYSZ_INS_STOCO = 278; + public static final int SYSZ_INS_STOCGO = 279; + public static final int SYSZ_INS_STOC = 280; + public static final int SYSZ_INS_STOCG = 281; + public static final int SYSZ_INS_BASR = 282; + public static final int SYSZ_INS_BR = 283; + public static final int SYSZ_INS_BRAS = 284; + public static final int SYSZ_INS_BRASL = 285; + public static final int SYSZ_INS_J = 286; + public static final int SYSZ_INS_JG = 287; + public static final int SYSZ_INS_BRCT = 288; + public static final int SYSZ_INS_BRCTG = 289; + public static final int SYSZ_INS_C = 290; + public static final int SYSZ_INS_CDB = 291; + public static final int SYSZ_INS_CDBR = 292; + public static final int SYSZ_INS_CDFBR = 293; + public static final int SYSZ_INS_CDGBR = 294; + public static final int SYSZ_INS_CDLFBR = 295; + public static final int SYSZ_INS_CDLGBR = 296; + public static final int SYSZ_INS_CEB = 297; + public static final int SYSZ_INS_CEBR = 298; + public static final int SYSZ_INS_CEFBR = 299; + public static final int SYSZ_INS_CEGBR = 300; + public static final int SYSZ_INS_CELFBR = 301; + public static final int SYSZ_INS_CELGBR = 302; + public static final int SYSZ_INS_CFDBR = 303; + public static final int SYSZ_INS_CFEBR = 304; + public static final int SYSZ_INS_CFI = 305; + public static final int SYSZ_INS_CFXBR = 306; + public static final int SYSZ_INS_CG = 307; + public static final int SYSZ_INS_CGDBR = 308; + public static final int SYSZ_INS_CGEBR = 309; + public static final int SYSZ_INS_CGF = 310; + public static final int SYSZ_INS_CGFI = 311; + public static final int SYSZ_INS_CGFR = 312; + public static final int SYSZ_INS_CGFRL = 313; + public static final int SYSZ_INS_CGH = 314; + public static final int SYSZ_INS_CGHI = 315; + public static final int SYSZ_INS_CGHRL = 316; + public static final int SYSZ_INS_CGHSI = 317; + public static final int SYSZ_INS_CGR = 318; + public static final int SYSZ_INS_CGRL = 319; + public static final int SYSZ_INS_CGXBR = 320; + public static final int SYSZ_INS_CH = 321; + public static final int SYSZ_INS_CHF = 322; + public static final int SYSZ_INS_CHHSI = 323; + public static final int SYSZ_INS_CHI = 324; + public static final int SYSZ_INS_CHRL = 325; + public static final int SYSZ_INS_CHSI = 326; + public static final int SYSZ_INS_CHY = 327; + public static final int SYSZ_INS_CIH = 328; + public static final int SYSZ_INS_CL = 329; + public static final int SYSZ_INS_CLC = 330; + public static final int SYSZ_INS_CLFDBR = 331; + public static final int SYSZ_INS_CLFEBR = 332; + public static final int SYSZ_INS_CLFHSI = 333; + public static final int SYSZ_INS_CLFI = 334; + public static final int SYSZ_INS_CLFXBR = 335; + public static final int SYSZ_INS_CLG = 336; + public static final int SYSZ_INS_CLGDBR = 337; + public static final int SYSZ_INS_CLGEBR = 338; + public static final int SYSZ_INS_CLGF = 339; + public static final int SYSZ_INS_CLGFI = 340; + public static final int SYSZ_INS_CLGFR = 341; + public static final int SYSZ_INS_CLGFRL = 342; + public static final int SYSZ_INS_CLGHRL = 343; + public static final int SYSZ_INS_CLGHSI = 344; + public static final int SYSZ_INS_CLGR = 345; + public static final int SYSZ_INS_CLGRL = 346; + public static final int SYSZ_INS_CLGXBR = 347; + public static final int SYSZ_INS_CLHF = 348; + public static final int SYSZ_INS_CLHHSI = 349; + public static final int SYSZ_INS_CLHRL = 350; + public static final int SYSZ_INS_CLI = 351; + public static final int SYSZ_INS_CLIH = 352; + public static final int SYSZ_INS_CLIY = 353; + public static final int SYSZ_INS_CLR = 354; + public static final int SYSZ_INS_CLRL = 355; + public static final int SYSZ_INS_CLST = 356; + public static final int SYSZ_INS_CLY = 357; + public static final int SYSZ_INS_CPSDR = 358; + public static final int SYSZ_INS_CR = 359; + public static final int SYSZ_INS_CRL = 360; + public static final int SYSZ_INS_CS = 361; + public static final int SYSZ_INS_CSG = 362; + public static final int SYSZ_INS_CSY = 363; + public static final int SYSZ_INS_CXBR = 364; + public static final int SYSZ_INS_CXFBR = 365; + public static final int SYSZ_INS_CXGBR = 366; + public static final int SYSZ_INS_CXLFBR = 367; + public static final int SYSZ_INS_CXLGBR = 368; + public static final int SYSZ_INS_CY = 369; + public static final int SYSZ_INS_DDB = 370; + public static final int SYSZ_INS_DDBR = 371; + public static final int SYSZ_INS_DEB = 372; + public static final int SYSZ_INS_DEBR = 373; + public static final int SYSZ_INS_DL = 374; + public static final int SYSZ_INS_DLG = 375; + public static final int SYSZ_INS_DLGR = 376; + public static final int SYSZ_INS_DLR = 377; + public static final int SYSZ_INS_DSG = 378; + public static final int SYSZ_INS_DSGF = 379; + public static final int SYSZ_INS_DSGFR = 380; + public static final int SYSZ_INS_DSGR = 381; + public static final int SYSZ_INS_DXBR = 382; + public static final int SYSZ_INS_EAR = 383; + public static final int SYSZ_INS_FIDBR = 384; + public static final int SYSZ_INS_FIDBRA = 385; + public static final int SYSZ_INS_FIEBR = 386; + public static final int SYSZ_INS_FIEBRA = 387; + public static final int SYSZ_INS_FIXBR = 388; + public static final int SYSZ_INS_FIXBRA = 389; + public static final int SYSZ_INS_FLOGR = 390; + public static final int SYSZ_INS_IC = 391; + public static final int SYSZ_INS_ICY = 392; + public static final int SYSZ_INS_IIHF = 393; + public static final int SYSZ_INS_IIHH = 394; + public static final int SYSZ_INS_IIHL = 395; + public static final int SYSZ_INS_IILF = 396; + public static final int SYSZ_INS_IILH = 397; + public static final int SYSZ_INS_IILL = 398; + public static final int SYSZ_INS_IPM = 399; + public static final int SYSZ_INS_L = 400; + public static final int SYSZ_INS_LA = 401; + public static final int SYSZ_INS_LAA = 402; + public static final int SYSZ_INS_LAAG = 403; + public static final int SYSZ_INS_LAAL = 404; + public static final int SYSZ_INS_LAALG = 405; + public static final int SYSZ_INS_LAN = 406; + public static final int SYSZ_INS_LANG = 407; + public static final int SYSZ_INS_LAO = 408; + public static final int SYSZ_INS_LAOG = 409; + public static final int SYSZ_INS_LARL = 410; + public static final int SYSZ_INS_LAX = 411; + public static final int SYSZ_INS_LAXG = 412; + public static final int SYSZ_INS_LAY = 413; + public static final int SYSZ_INS_LB = 414; + public static final int SYSZ_INS_LBH = 415; + public static final int SYSZ_INS_LBR = 416; + public static final int SYSZ_INS_LCDBR = 417; + public static final int SYSZ_INS_LCEBR = 418; + public static final int SYSZ_INS_LCGFR = 419; + public static final int SYSZ_INS_LCGR = 420; + public static final int SYSZ_INS_LCR = 421; + public static final int SYSZ_INS_LCXBR = 422; + public static final int SYSZ_INS_LD = 423; + public static final int SYSZ_INS_LDEB = 424; + public static final int SYSZ_INS_LDEBR = 425; + public static final int SYSZ_INS_LDGR = 426; + public static final int SYSZ_INS_LDR = 427; + public static final int SYSZ_INS_LDXBR = 428; + public static final int SYSZ_INS_LDXBRA = 429; + public static final int SYSZ_INS_LDY = 430; + public static final int SYSZ_INS_LE = 431; + public static final int SYSZ_INS_LEDBR = 432; + public static final int SYSZ_INS_LEDBRA = 433; + public static final int SYSZ_INS_LER = 434; + public static final int SYSZ_INS_LEXBR = 435; + public static final int SYSZ_INS_LEXBRA = 436; + public static final int SYSZ_INS_LEY = 437; + public static final int SYSZ_INS_LFH = 438; + public static final int SYSZ_INS_LG = 439; + public static final int SYSZ_INS_LGB = 440; + public static final int SYSZ_INS_LGBR = 441; + public static final int SYSZ_INS_LGDR = 442; + public static final int SYSZ_INS_LGF = 443; + public static final int SYSZ_INS_LGFI = 444; + public static final int SYSZ_INS_LGFR = 445; + public static final int SYSZ_INS_LGFRL = 446; + public static final int SYSZ_INS_LGH = 447; + public static final int SYSZ_INS_LGHI = 448; + public static final int SYSZ_INS_LGHR = 449; + public static final int SYSZ_INS_LGHRL = 450; + public static final int SYSZ_INS_LGR = 451; + public static final int SYSZ_INS_LGRL = 452; + public static final int SYSZ_INS_LH = 453; + public static final int SYSZ_INS_LHH = 454; + public static final int SYSZ_INS_LHI = 455; + public static final int SYSZ_INS_LHR = 456; + public static final int SYSZ_INS_LHRL = 457; + public static final int SYSZ_INS_LHY = 458; + public static final int SYSZ_INS_LLC = 459; + public static final int SYSZ_INS_LLCH = 460; + public static final int SYSZ_INS_LLCR = 461; + public static final int SYSZ_INS_LLGC = 462; + public static final int SYSZ_INS_LLGCR = 463; + public static final int SYSZ_INS_LLGF = 464; + public static final int SYSZ_INS_LLGFR = 465; + public static final int SYSZ_INS_LLGFRL = 466; + public static final int SYSZ_INS_LLGH = 467; + public static final int SYSZ_INS_LLGHR = 468; + public static final int SYSZ_INS_LLGHRL = 469; + public static final int SYSZ_INS_LLH = 470; + public static final int SYSZ_INS_LLHH = 471; + public static final int SYSZ_INS_LLHR = 472; + public static final int SYSZ_INS_LLHRL = 473; + public static final int SYSZ_INS_LLIHF = 474; + public static final int SYSZ_INS_LLIHH = 475; + public static final int SYSZ_INS_LLIHL = 476; + public static final int SYSZ_INS_LLILF = 477; + public static final int SYSZ_INS_LLILH = 478; + public static final int SYSZ_INS_LLILL = 479; + public static final int SYSZ_INS_LMG = 480; + public static final int SYSZ_INS_LNDBR = 481; + public static final int SYSZ_INS_LNEBR = 482; + public static final int SYSZ_INS_LNGFR = 483; + public static final int SYSZ_INS_LNGR = 484; + public static final int SYSZ_INS_LNR = 485; + public static final int SYSZ_INS_LNXBR = 486; + public static final int SYSZ_INS_LPDBR = 487; + public static final int SYSZ_INS_LPEBR = 488; + public static final int SYSZ_INS_LPGFR = 489; + public static final int SYSZ_INS_LPGR = 490; + public static final int SYSZ_INS_LPR = 491; + public static final int SYSZ_INS_LPXBR = 492; + public static final int SYSZ_INS_LR = 493; + public static final int SYSZ_INS_LRL = 494; + public static final int SYSZ_INS_LRV = 495; + public static final int SYSZ_INS_LRVG = 496; + public static final int SYSZ_INS_LRVGR = 497; + public static final int SYSZ_INS_LRVR = 498; + public static final int SYSZ_INS_LT = 499; + public static final int SYSZ_INS_LTDBR = 500; + public static final int SYSZ_INS_LTEBR = 501; + public static final int SYSZ_INS_LTG = 502; + public static final int SYSZ_INS_LTGF = 503; + public static final int SYSZ_INS_LTGFR = 504; + public static final int SYSZ_INS_LTGR = 505; + public static final int SYSZ_INS_LTR = 506; + public static final int SYSZ_INS_LTXBR = 507; + public static final int SYSZ_INS_LXDB = 508; + public static final int SYSZ_INS_LXDBR = 509; + public static final int SYSZ_INS_LXEB = 510; + public static final int SYSZ_INS_LXEBR = 511; + public static final int SYSZ_INS_LXR = 512; + public static final int SYSZ_INS_LY = 513; + public static final int SYSZ_INS_LZDR = 514; + public static final int SYSZ_INS_LZER = 515; + public static final int SYSZ_INS_LZXR = 516; + public static final int SYSZ_INS_MADB = 517; + public static final int SYSZ_INS_MADBR = 518; + public static final int SYSZ_INS_MAEB = 519; + public static final int SYSZ_INS_MAEBR = 520; + public static final int SYSZ_INS_MDB = 521; + public static final int SYSZ_INS_MDBR = 522; + public static final int SYSZ_INS_MDEB = 523; + public static final int SYSZ_INS_MDEBR = 524; + public static final int SYSZ_INS_MEEB = 525; + public static final int SYSZ_INS_MEEBR = 526; + public static final int SYSZ_INS_MGHI = 527; + public static final int SYSZ_INS_MH = 528; + public static final int SYSZ_INS_MHI = 529; + public static final int SYSZ_INS_MHY = 530; + public static final int SYSZ_INS_MLG = 531; + public static final int SYSZ_INS_MLGR = 532; + public static final int SYSZ_INS_MS = 533; + public static final int SYSZ_INS_MSDB = 534; + public static final int SYSZ_INS_MSDBR = 535; + public static final int SYSZ_INS_MSEB = 536; + public static final int SYSZ_INS_MSEBR = 537; + public static final int SYSZ_INS_MSFI = 538; + public static final int SYSZ_INS_MSG = 539; + public static final int SYSZ_INS_MSGF = 540; + public static final int SYSZ_INS_MSGFI = 541; + public static final int SYSZ_INS_MSGFR = 542; + public static final int SYSZ_INS_MSGR = 543; + public static final int SYSZ_INS_MSR = 544; + public static final int SYSZ_INS_MSY = 545; + public static final int SYSZ_INS_MVC = 546; + public static final int SYSZ_INS_MVGHI = 547; + public static final int SYSZ_INS_MVHHI = 548; + public static final int SYSZ_INS_MVHI = 549; + public static final int SYSZ_INS_MVI = 550; + public static final int SYSZ_INS_MVIY = 551; + public static final int SYSZ_INS_MVST = 552; + public static final int SYSZ_INS_MXBR = 553; + public static final int SYSZ_INS_MXDB = 554; + public static final int SYSZ_INS_MXDBR = 555; + public static final int SYSZ_INS_N = 556; + public static final int SYSZ_INS_NC = 557; + public static final int SYSZ_INS_NG = 558; + public static final int SYSZ_INS_NGR = 559; + public static final int SYSZ_INS_NGRK = 560; + public static final int SYSZ_INS_NI = 561; + public static final int SYSZ_INS_NIHF = 562; + public static final int SYSZ_INS_NIHH = 563; + public static final int SYSZ_INS_NIHL = 564; + public static final int SYSZ_INS_NILF = 565; + public static final int SYSZ_INS_NILH = 566; + public static final int SYSZ_INS_NILL = 567; + public static final int SYSZ_INS_NIY = 568; + public static final int SYSZ_INS_NR = 569; + public static final int SYSZ_INS_NRK = 570; + public static final int SYSZ_INS_NY = 571; + public static final int SYSZ_INS_O = 572; + public static final int SYSZ_INS_OC = 573; + public static final int SYSZ_INS_OG = 574; + public static final int SYSZ_INS_OGR = 575; + public static final int SYSZ_INS_OGRK = 576; + public static final int SYSZ_INS_OI = 577; + public static final int SYSZ_INS_OIHF = 578; + public static final int SYSZ_INS_OIHH = 579; + public static final int SYSZ_INS_OIHL = 580; + public static final int SYSZ_INS_OILF = 581; + public static final int SYSZ_INS_OILH = 582; + public static final int SYSZ_INS_OILL = 583; + public static final int SYSZ_INS_OIY = 584; + public static final int SYSZ_INS_OR = 585; + public static final int SYSZ_INS_ORK = 586; + public static final int SYSZ_INS_OY = 587; + public static final int SYSZ_INS_PFD = 588; + public static final int SYSZ_INS_PFDRL = 589; + public static final int SYSZ_INS_RISBG = 590; + public static final int SYSZ_INS_RISBHG = 591; + public static final int SYSZ_INS_RISBLG = 592; + public static final int SYSZ_INS_RLL = 593; + public static final int SYSZ_INS_RLLG = 594; + public static final int SYSZ_INS_RNSBG = 595; + public static final int SYSZ_INS_ROSBG = 596; + public static final int SYSZ_INS_RXSBG = 597; + public static final int SYSZ_INS_S = 598; + public static final int SYSZ_INS_SDB = 599; + public static final int SYSZ_INS_SDBR = 600; + public static final int SYSZ_INS_SEB = 601; + public static final int SYSZ_INS_SEBR = 602; + public static final int SYSZ_INS_SG = 603; + public static final int SYSZ_INS_SGF = 604; + public static final int SYSZ_INS_SGFR = 605; + public static final int SYSZ_INS_SGR = 606; + public static final int SYSZ_INS_SGRK = 607; + public static final int SYSZ_INS_SH = 608; + public static final int SYSZ_INS_SHY = 609; + public static final int SYSZ_INS_SL = 610; + public static final int SYSZ_INS_SLB = 611; + public static final int SYSZ_INS_SLBG = 612; + public static final int SYSZ_INS_SLBR = 613; + public static final int SYSZ_INS_SLFI = 614; + public static final int SYSZ_INS_SLG = 615; + public static final int SYSZ_INS_SLBGR = 616; + public static final int SYSZ_INS_SLGF = 617; + public static final int SYSZ_INS_SLGFI = 618; + public static final int SYSZ_INS_SLGFR = 619; + public static final int SYSZ_INS_SLGR = 620; + public static final int SYSZ_INS_SLGRK = 621; + public static final int SYSZ_INS_SLL = 622; + public static final int SYSZ_INS_SLLG = 623; + public static final int SYSZ_INS_SLLK = 624; + public static final int SYSZ_INS_SLR = 625; + public static final int SYSZ_INS_SLRK = 626; + public static final int SYSZ_INS_SLY = 627; + public static final int SYSZ_INS_SQDB = 628; + public static final int SYSZ_INS_SQDBR = 629; + public static final int SYSZ_INS_SQEB = 630; + public static final int SYSZ_INS_SQEBR = 631; + public static final int SYSZ_INS_SQXBR = 632; + public static final int SYSZ_INS_SR = 633; + public static final int SYSZ_INS_SRA = 634; + public static final int SYSZ_INS_SRAG = 635; + public static final int SYSZ_INS_SRAK = 636; + public static final int SYSZ_INS_SRK = 637; + public static final int SYSZ_INS_SRL = 638; + public static final int SYSZ_INS_SRLG = 639; + public static final int SYSZ_INS_SRLK = 640; + public static final int SYSZ_INS_SRST = 641; + public static final int SYSZ_INS_ST = 642; + public static final int SYSZ_INS_STC = 643; + public static final int SYSZ_INS_STCH = 644; + public static final int SYSZ_INS_STCY = 645; + public static final int SYSZ_INS_STD = 646; + public static final int SYSZ_INS_STDY = 647; + public static final int SYSZ_INS_STE = 648; + public static final int SYSZ_INS_STEY = 649; + public static final int SYSZ_INS_STFH = 650; + public static final int SYSZ_INS_STG = 651; + public static final int SYSZ_INS_STGRL = 652; + public static final int SYSZ_INS_STH = 653; + public static final int SYSZ_INS_STHH = 654; + public static final int SYSZ_INS_STHRL = 655; + public static final int SYSZ_INS_STHY = 656; + public static final int SYSZ_INS_STMG = 657; + public static final int SYSZ_INS_STRL = 658; + public static final int SYSZ_INS_STRV = 659; + public static final int SYSZ_INS_STRVG = 660; + public static final int SYSZ_INS_STY = 661; + public static final int SYSZ_INS_SXBR = 662; + public static final int SYSZ_INS_SY = 663; + public static final int SYSZ_INS_TM = 664; + public static final int SYSZ_INS_TMHH = 665; + public static final int SYSZ_INS_TMHL = 666; + public static final int SYSZ_INS_TMLH = 667; + public static final int SYSZ_INS_TMLL = 668; + public static final int SYSZ_INS_TMY = 669; + public static final int SYSZ_INS_X = 670; + public static final int SYSZ_INS_XC = 671; + public static final int SYSZ_INS_XG = 672; + public static final int SYSZ_INS_XGR = 673; + public static final int SYSZ_INS_XGRK = 674; + public static final int SYSZ_INS_XI = 675; + public static final int SYSZ_INS_XIHF = 676; + public static final int SYSZ_INS_XILF = 677; + public static final int SYSZ_INS_XIY = 678; + public static final int SYSZ_INS_XR = 679; + public static final int SYSZ_INS_XRK = 680; + public static final int SYSZ_INS_XY = 681; + public static final int SYSZ_INS_ENDING = 682; + + // Group of SystemZ instructions + + public static final int SYSZ_GRP_INVALID = 0; + + // Generic groups + public static final int SYSZ_GRP_JUMP = 1; + + // Architecture-specific groups + public static final int SYSZ_GRP_DISTINCTOPS = 128; + public static final int SYSZ_GRP_FPEXTENSION = 129; + public static final int SYSZ_GRP_HIGHWORD = 130; + public static final int SYSZ_GRP_INTERLOCKEDACCESS1 = 131; + public static final int SYSZ_GRP_LOADSTOREONCOND = 132; + public static final int SYSZ_GRP_ENDING = 133; +} \ No newline at end of file diff --git a/app/src/main/java/capstone/X86.java b/app/src/main/java/capstone/X86.java new file mode 100644 index 00000000..8f69ee1f --- /dev/null +++ b/app/src/main/java/capstone/X86.java @@ -0,0 +1,143 @@ +// Capstone Java binding +// By Nguyen Anh Quynh & Dang Hoang Vu, 2013 + +package capstone; + +import com.sun.jna.Structure; +import com.sun.jna.Union; + +import java.util.List; +import java.util.Arrays; + +import static capstone.X86_const.*; + +public class X86 { + + public static class MemType extends Structure { + public int segment; + public int base; + public int index; + public int scale; + public long disp; + + @Override + public List getFieldOrder() { + return Arrays.asList("segment", "base", "index", "scale", "disp"); + } + } + + public static class OpValue extends Union { + public int reg; + public long imm; + public double fp; + public MemType mem; + + @Override + public List getFieldOrder() { + return Arrays.asList("reg", "imm", "fp", "mem"); + } + } + + public static class Operand extends Structure { + public int type; + public OpValue value; + public byte size; + public int avx_bcast; + public boolean avx_zero_opmask; + + public void read() { + super.read(); + if (type == X86_OP_MEM) + value.setType(MemType.class); + if (type == X86_OP_FP) + value.setType(Double.TYPE); + if (type == X86_OP_IMM) + value.setType(Long.TYPE); + if (type == X86_OP_REG) + value.setType(Integer.TYPE); + if (type == X86_OP_INVALID) + return; + readField("value"); + } + + @Override + public List getFieldOrder() { + return Arrays.asList("type", "value", "size", "avx_bcast", "avx_zero_opmask"); + } + } + + public static class UnionOpInfo extends Capstone.UnionOpInfo { + public byte [] prefix; + public byte [] opcode; + public byte rex; + public byte addr_size; + public byte modrm; + public byte sib; + public int disp; + public int sib_index; + public byte sib_scale; + public int sib_base; + public int sse_cc; + public int avx_cc; + public byte avx_sae; + public int avx_rm; + + public byte op_count; + + public Operand [] op; + + public UnionOpInfo() { + op = new Operand[8]; + opcode = new byte[4]; + prefix = new byte[4]; + } + + @Override + public List getFieldOrder() { + return Arrays.asList("prefix", "opcode", "rex", "addr_size", + "modrm", "sib", "disp", "sib_index", "sib_scale", "sib_base", "sse_cc", "avx_cc", "avx_sae", "avx_rm", "op_count", "op"); + } + } + + public static class OpInfo extends Capstone.OpInfo { + public byte [] prefix; + public byte [] opcode; + public byte opSize; + public byte rex; + public byte addrSize; + public byte dispSize; + public byte immSize; + public byte modrm; + public byte sib; + public int disp; + public int sibIndex; + public byte sibScale; + public int sibBase; + public int sseCC; + public int avxCC; + public boolean avxSae; + public int avxRm; + + public Operand[] op; + + public OpInfo(UnionOpInfo e) { + prefix = e.prefix; + opcode = e.opcode; + rex = e.rex; + addrSize = e.addr_size; + modrm = e.modrm; + sib = e.sib; + disp = e.disp; + sibIndex = e.sib_index; + sibScale = e.sib_scale; + sibBase = e.sib_base; + sseCC = e.sse_cc; + avxCC = e.avx_cc; + avxSae = e.avx_sae > 0; + avxRm = e.avx_rm; + op = new Operand[e.op_count]; + for (int i=0; i Common instruction groups - to be consistent across all architectures. + byte[] groups; + byte groups_count; + /*typedef enum cs_group_type { + CS_GRP_INVALID = 0, // uninitialized/invalid group. + CS_GRP_JUMP, // all jump instructions (conditional+direct+indirect jumps) + CS_GRP_CALL, // all call instructions + CS_GRP_RET, // all return instructions + CS_GRP_INT, // all interrupt instructions (int+syscall) + CS_GRP_IRET, // all interrupt return instructions + } cs_group_type;*/ + public static final int CS_GRP_INVALID = 0, // uninitialized/invalid group. + CS_GRP_JUMP=1, // all jump instructions (conditional+direct+indirect jumps) + CS_GRP_CALL=2, // all call instructions + CS_GRP_RET=3, // all return instructions + CS_GRP_INT=4, // all interrupt instructions (int+syscall) + CS_GRP_IRET=5; // all interrupt return instructions + + + // Architecture-specific instruction info + //union { + /* cs_x86 x86; // X86 architecture, including 16-bit, 32-bit & 64-bit mode + cs_arm64 arm64; // ARM64 architecture (aka AArch64) + cs_arm arm; // ARM architecture (including Thumb/Thumb2) + cs_mips mips; // MIPS architecture + cs_ppc ppc; // PowerPC architecture + cs_sparc sparc; // Sparc architecture + cs_sysz sysz; // SystemZ architecture + cs_xcore xcore; // XCore architecture + //}; + */ + //} cs_detail; + //enum +} diff --git a/app/src/main/java/com/kyhsgeekcode/disassembler/ELFUtil.java b/app/src/main/java/com/kyhsgeekcode/disassembler/ELFUtil.java new file mode 100644 index 00000000..a6cf0c5b --- /dev/null +++ b/app/src/main/java/com/kyhsgeekcode/disassembler/ELFUtil.java @@ -0,0 +1,350 @@ +package com.kyhsgeekcode.disassembler; + +import android.util.*; +import java.io.*; +import java.util.*; +import nl.lxtreme.binutils.elf.*; +public class ELFUtil implements Closeable +{ + private String TAG="Disassembler elfutil"; + public long getCodeSectionVirtAddr() + { + return codeVirtualAddress; + } + public long getCodeSectionLimit() + { + // TODO: Implement this method + return codeLimit; + } + @Override + public void close() throws IOException + { + // TODO: Implement this method + elf.close(); + } + + Elf elf; + public long getEntryPoint() + { + return entryPoint; + } + public String toString() + { + return new StringBuilder(elf.toString()) + .append(Arrays.toString(symstrings)).append("\n").append(info).toString(); + } + public static int getWord(byte a, byte b, byte c, byte d) + { + return ((int)a << 24) & ((int)b << 16) & ((int)c << 8) & d; + } + /* + public ELFUtil(File file) throws Exception + { + long fsize=file.length(); + int index=0; + fileContents=new byte[(int)fsize]; + DataInputStream in = new DataInputStream(new FileInputStream(file.getPath())); + int len,counter=0; + byte[] b=new byte[1024]; + while ((len = in.read(b)) > 0) + { + for (int i = 0; i < len; i++) + { // byte[] 버퍼 내용 출력 + //System.out.format("%02X ", b[i]); + fileContents[index] = b[i]; + index++; + counter++; + } + } + + ParseData(); + } + public ELFUtil(byte[] bytes) throws Exception + { + fileContents=new byte[bytes.length]; + for(int s=0;s + * in this example -> cast it to make it usable */ + //vector* symbol_names = reinterpret_cast*>(symbol_names_vector); + + /* Iterate over all headers of the current shared lib + * (first call is for the executable itself) */ + //Elf elf=elfUtil.elf; + //elf.getSectionHeaderByType(SectionType.DYNAMIC); + /*for(SectionHeader sh:sections) + { + if(sh.type.equals(SectionType.DYNAMIC)) + { + //long dyn=sh.fileOffset; + ByteBuffer buf=elf.getSection(sh); + int entnum=(int)(sh.size/sh.entrySize); + symstrings=new String[entnum]; + for(int i=0;id_un.d_ptr; +// + /* The 2nd word is the number of symbols */ + // sym_cnt = hash[1]; + //int hashvalue=fileContents[(int)hash] + sym_cnt = (fileContents[(int)hash + 1] << 8 | fileContents[(int)hash]); + Log.v(TAG, "Hash=" + hash + "cnt=" + sym_cnt); + } + else if (tag.equals(DynamicEntry.Tag.STRTAB)) + { + strtab = de.getValue(); + Log.i(TAG, "strtab=" + strtab); + } + else if (tag.equals(DynamicEntry.Tag.SYMTAB)) + { + if (sym_cnt == 0 || strtab == 0) + { + continue; + } + long sym=de.getValue(); + Log.i(TAG, "sym=" + sym); + // int sym_index=0; + for (int sym_index=0;sym_index < sym_cnt;sym_index++) + { + String sym_name=new String(fileContents, (int)strtab + fileContents[(int)(sym + sym_index * 16)], 64); + byte[] bytes=sym_name.getBytes(); + //char[] chars=new char[sym_name.length()]; + //sym_name.getb(0,sym_name.length()-1,chars,0); + ArrayList arr=new ArrayList<>(); + for (int j=0;j < bytes.length;++j) + { + arr.add(new Byte(bytes[j])); + if (bytes[j] == 0) + { + break; + } + } + byte[] newbytes=new byte[arr.size()]; + for (int j=0;j < newbytes.length;++j) + { + newbytes[j] = arr.get(j); + } + sym_name = new String(newbytes); + //int symsymindexstname=fileContents[sym+sym_index]; + // sym_name = &strtab[sym[sym_index].st_name]; + /*try{ + sym_name=sym_name.split("\0")[0]; + }catch(Exception e){}*/ + sb.append(sym_name).append("\n"); + Log.v(TAG, "sym_nmae=" + sym_name); + } + break; + } + } + info = sb.toString(); + Log.i(TAG, "info=" + info); + } + Log.v(TAG,"Checking code section"); + for (SectionHeader sh:elf.sectionHeaders) + { + Log.v(TAG, "type=" + sh.type.toString() + "name=" + sh.getName()); + if (sh.type.equals(SectionType.PROGBITS)) + { + Log.v(TAG, "sh.type.equals Progbits"); + String name=sh.getName(); + if (name != null) + { + Log.i(TAG, "name nonnull:name=" + name); + if (name.equals(".text")) + { + codeOffset = sh.fileOffset; + codeLimit = codeOffset + sh.size; + codeVirtualAddress = sh.virtualAddress; + } + } + } + } + // for (size_t header_index = 0; header_index < info->dlpi_phnum; header_index++) + // { + + /* Further processing is only needed if the dynamic section is reached */ + // if (info->dlpi_phdr[header_index].p_type == PT_DYNAMIC) + // { + + /* Get a pointer to the first entry of the dynamic section. + * It's address is the shared lib's address + the virtual address */ + //dyn = (ElfW(Dyn)*)(info->dlpi_addr + info->dlpi_phdr[header_index].p_vaddr); + + /* Iterate over all entries of the dynamic section until the + * end of the symbol table is reached. This is indicated by + * an entry with d_tag == DT_NULL. + * + * Only the following entries need to be processed to find the + * symbol names: + * - DT_HASH -> second word of the hash is the number of symbols + * - DT_STRTAB -> pointer to the beginning of a string table that + * contains the symbol names + * - DT_SYMTAB -> pointer to the beginning of the symbols table + */ + // while(dyn->d_tag != DT_NULL) + // { + // if (dyn->d_tag == DT_HASH) + // { + // /* Get a pointer to the hash */ + // hash = (ElfW(Word*))dyn->d_un.d_ptr; +// + /* The 2nd word is the number of symbols */ + // sym_cnt = hash[1]; + + // } + // else if (dyn->d_tag == DT_STRTAB) + // { + // /* Get the pointer to the string table */ + // strtab = (char*)dyn->d_un.d_ptr; + //} + // else if (dyn->d_tag == DT_SYMTAB) + // { + /* Get the pointer to the first entry of the symbol table */ + //sym = (ElfW(Sym*))dyn->d_un.d_ptr; + + + /* Iterate over the symbol table */ + //for (ElfW(Word) sym_index = 0; sym_index < sym_cnt; sym_index++) + // { + /* get the name of the i-th symbol. + * This is located at the address of st_name + * relative to the beginning of the string table. */ + // sym_name = &strtab[sym[sym_index].st_name]; + + // symbol_names->push_back(string(sym_name)); + //} + //} + + /* move pointer to the next entry */ + //dyn++; + //} + //} + // } + + /* Returning something != 0 stops further iterations, + * since only the first entry, which is the executable itself, is needed + * 1 is returned after processing the first entry. + * + * If the symbols of all loaded dynamic libs shall be found, + * the return value has to be changed to 0. + */ + //return 1; + + //} + + //CodeBase= + //System.out.printf( "Entry point: 0x%x\n", header.entryPoint ); + } + String info=""; + public void ParseData() throws Exception + { + if (fileContents == null) + { + return; + } + if (fileContents.length < 54) + { + //return; + throw new Exception("Not a ELF HEADER"); + } + entryPoint = getWord((byte)0, (byte)0, (byte)0, (byte)0); + } + private long entryPoint; + private byte [] fileContents; + boolean bExecutable; + private long codeOffset=0L; + private long codeLimit=0L; + private long codeVirtualAddress=0L; + String[] symstrings; + +} diff --git a/app/src/main/java/com/kyhsgeekcode/disassembler/FileSelectorActivity.java b/app/src/main/java/com/kyhsgeekcode/disassembler/FileSelectorActivity.java new file mode 100644 index 00000000..009b68d3 --- /dev/null +++ b/app/src/main/java/com/kyhsgeekcode/disassembler/FileSelectorActivity.java @@ -0,0 +1,91 @@ +package com.kyhsgeekcode.disassembler; + + +import android.app.*; +import android.content.*; +import android.net.*; +import android.os.*; +import android.view.*; +import android.widget.*; +import java.io.*; +import java.util.*; +import android.util.*; + +public class FileSelectorActivity extends ListActivity { + private List item = (List) null; + private List path = (List) null; + private String root = "/"; + private TextView mPath; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState);; + setContentView(R.layout.fileaselactivity); + mPath = (TextView) findViewById(R.id.path); + getDir("/sdcard/"); + } + + private void getDir(String dirPath) { + mPath.setText("Location: " + dirPath); + item = new ArrayList(); + path = new ArrayList(); + File f = new File(dirPath); + File[] files = f.listFiles(); + if (!dirPath.equals(root)) { + item.add(root); + path.add(root); + item.add("../"); + path.add(f.getParent()); + } + if(files==null) + { + Log.e("Disassembler dirsel","listfile null"); + ArrayAdapter fileList = new ArrayAdapter(this, R.layout.row, item); + setListAdapter(fileList); + return; + } + for (int i = 0; i < files.length; i++) { + File file = files[i]; + path.add(file.getPath()); + if (file.isDirectory()) + item.add(file.getName() + "/"); + else + item.add(file.getName()); + } + ArrayAdapter fileList = new ArrayAdapter(this, R.layout.row, item); + setListAdapter(fileList); + } + + @Override + protected void onListItemClick(ListView l, View v, int position, long id) { + + final File file = new File(path.get(position)); + if (file.isDirectory()) { + if (file.canRead()) + getDir(path.get(position)); + else { + new AlertDialog.Builder(this) + .setIcon(R.drawable.ic_launcher) + .setTitle("[" + file.getName() + "] folder can't be read!") + .setPositiveButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + // TODO Auto-generated method stub + } + }).show(); + } + } else { + new AlertDialog.Builder(this) + .setIcon(R.drawable.ic_launcher) + .setTitle("[" + file.getName() + "]") + .setPositiveButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + // TODO Auto-generated method stub + Intent result = new Intent("com.jourhyang.disasmarm.RESULT_ACTION"); + result.putExtra("com.jourhyang.disasmarm.path",file.getAbsolutePath()); + setResult(Activity.RESULT_OK, result); + finish(); + } + }).show(); + } + } +} diff --git a/app/src/main/java/com/kyhsgeekcode/disassembler/ListViewAdapter.java b/app/src/main/java/com/kyhsgeekcode/disassembler/ListViewAdapter.java new file mode 100644 index 00000000..a0e82638 --- /dev/null +++ b/app/src/main/java/com/kyhsgeekcode/disassembler/ListViewAdapter.java @@ -0,0 +1,109 @@ +package com.kyhsgeekcode.disassembler; + + +import android.content.*; +import android.graphics.*; +import android.view.*; +import android.widget.*; +import java.util.*; + +public class ListViewAdapter extends BaseAdapter +{ + // Adapter에 추가된 데이터를 저장하기 위한 ArrayList + private ArrayList listViewItemList = new ArrayList() ; + + // ListViewAdapter의 생성자 + public ListViewAdapter() + { + + } + + // Adapter에 사용되는 데이터의 개수를 리턴. : 필수 구현 + @Override + public int getCount() + { + return listViewItemList.size() ; + } + + // position에 위치한 데이터를 화면에 출력하는데 사용될 View를 리턴. : 필수 구현 + @Override + public View getView(int position, View convertView, ViewGroup parent) + { + final int pos = position; + final Context context = parent.getContext(); + + // "listview_item" Layout을 inflate하여 convertView 참조 획득. + if (convertView == null) + { + LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + convertView = inflater.inflate(R.layout.listview_item, parent, false); + } + + // 화면에 표시될 View(Layout이 inflate된)으로부터 위젯에 대한 참조 획득 + TextView addrTextView = (TextView) convertView.findViewById(R.id.tvAddr) ; + TextView bytesTextView = (TextView) convertView.findViewById(R.id.tvBytes) ; + TextView commentTextView = (TextView) convertView.findViewById(R.id.tvComment) ; + TextView condTextView = (TextView) convertView.findViewById(R.id.tvCond) ; + TextView instTextView = (TextView) convertView.findViewById(R.id.tvInst) ; + TextView labelTextView = (TextView) convertView.findViewById(R.id.tvLabel) ; + TextView operandTextView = (TextView) convertView.findViewById(R.id.tvOperand) ; + //if (pos == 0) + //{ + // addrTextView.setTe + //} + //else + { + // Data Set(listViewItemList)에서 position에 위치한 데이터 참조 획득 + ListViewItem listViewItem = listViewItemList.get(position); + if(listViewItem.isBranch()){ + convertView.setBackgroundColor(0xFFFF00000); + }else{ + convertView.setBackgroundColor(Color.WHITE); + } + addrTextView.setText(listViewItem.getAddress()); + bytesTextView.setText(listViewItem.getBytes()); + commentTextView.setText(listViewItem.getComments()); + condTextView.setText(listViewItem.getCondition()); + instTextView.setText(listViewItem.getInstruction()); + labelTextView.setText(listViewItem.getLabel()); + operandTextView.setText(listViewItem.getOperands()); + // 아이템 내 각 위젯에 데이터 반영 + // iconImageView.setImageDrawable(listViewItem.getIcon()); + // titleTextView.setText(listViewItem.getTitle()); + // descTextView.setText(listViewItem.getDesc()); + } + return convertView; + } + + // 지정한 위치(position)에 있는 데이터와 관계된 아이템(row)의 ID를 리턴. : 필수 구현 + @Override + public long getItemId(int position) + { + return position ; + } + + // 지정한 위치(position)에 있는 데이터 리턴 : 필수 구현 + @Override + public Object getItem(int position) + { + return listViewItemList.get(position) ; + } + + // 아이템 데이터 추가를 위한 함수. 개발자가 원하는대로 작성 가능. + public void addItem(DisasmResult disasm) + { + ListViewItem item = new ListViewItem(disasm); + // item.setIcon(icon); + // item.setTitle(title); + // item.setDesc(desc); + listViewItemList.add(item); + //notifyDataSetChanged(); + } + // 아이템 데이터 추가를 위한 함수. 개발자가 원하는대로 작성 가능. + public void addItem(ListViewItem item) + { + listViewItemList.add(item); + //notifyDataSetChanged(); + } +} +//http://recipes4dev.tistory.com/m/43 diff --git a/app/src/main/java/com/kyhsgeekcode/disassembler/ListViewItem.java b/app/src/main/java/com/kyhsgeekcode/disassembler/ListViewItem.java new file mode 100644 index 00000000..21ba2549 --- /dev/null +++ b/app/src/main/java/com/kyhsgeekcode/disassembler/ListViewItem.java @@ -0,0 +1,155 @@ +package com.kyhsgeekcode.disassembler; +import capstone.*; + + +public class ListViewItem +{ + String address,bytes,label,instruction,operands,comments,condition; + DisasmResult disasmResult; + Capstone.CsInsn insn; + public ListViewItem(String address, String bytes, String label, String instruction, String operands, String comments, String condition) + { + this.address = address; + this.bytes = bytes; + this.label = label; + this.instruction = instruction; + this.operands = operands; + this.comments = comments; + this.condition = condition; + //this.disasmResult = disasmResult; + } + + public ListViewItem(DisasmResult disasmResult) + { + this.disasmResult = disasmResult; + this.address=Long.toHexString(disasmResult.address); + byte[] bytestmp=new byte[disasmResult.size]; + for(int i=0;i disasmResults=new ArrayList<>(); + + private TableLayout tlDisasmTable; + + private EditText etDetails; + //ViewPager vp; + TabHost tabHost; + FrameLayout frameLayout; + LinearLayout tab1,tab2; + + private EditText etFilename; + + private Button btSavDisasm; + + private Button btDisasm; + + private Button btShowDetails; + + private Button btSavDit; + + private NotificationManager mNotifyManager; + + private Notification.Builder mBuilder; + + boolean instantMode; + + private long instantEntry; + + Thread workerThread; + + private Capstone cs; + @Override + public void onClick(View p1) + { + Button btn=(Button)p1; + switch (btn.getId()) + { + case R.id.selFile: + showFileChooser(); + break; + case R.id.btnDisasm: + if (filecontent == null) + { + AlertSelFile(); + return; + } + final List ListItems = new ArrayList<>(); + ListItems.add("Instant mode"); + ListItems.add("Persist mode"); + // ListItems.add(""); + final CharSequence[] items = ListItems.toArray(new String[ ListItems.size()]); + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle("Disassemble as..."); + builder.setItems(items, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int pos) + { + //String selectedText = items[pos].toString(); + dialog.dismiss(); + if (pos == 0) + { + instantMode = true; + final List ListItems2 = new ArrayList<>(); + ListItems2.add("Entry point"); + ListItems2.add("Custom address"); + AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); + builder.setTitle("Start from..."); + builder.setItems(items, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog2, int pos) + { + if (pos == 0) + { + instantEntry = elfUtil.getEntryPoint(); + DisassembleInstant(); + } + else if (pos == 1) + { + final EditText edittext = new EditText(MainActivity.this); + + AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); + builder.setTitle("Start from..."); + builder.setMessage("Enter address to start analyzing."); + builder.setView(edittext); + builder.setPositiveButton("OK", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog3, int which) + { + instantEntry = parseAddress(edittext.getText().toString()); + DisassembleInstant(); + } + }); + builder.setNegativeButton("cancel", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog4, int which) + { + dialog4.dismiss(); + } + }); + dialog2.dismiss(); + builder.show(); + } + } + }); + builder.show(); + } + else if (pos == 1) + { + DisassembleFile(); + } + } + }); + builder.show(); + break; + case R.id.btnShowdetail: + if (elfUtil == null) + { + AlertSelFile(); + return; + } + ShowDetail(); + break; + case R.id.btnSaveDisasm: + SaveDisasm(); + break; + case R.id.btnSaveDetails: + SaveDetail(); + break; + default: + break; + } + + } + private long parseAddress(String toString) + { + // TODO: Implement this method + return Long.decode(toString); + } + + private void AlertSelFile() + { + Toast.makeText(this, "Please Select a file first.", 2).show(); + } + + private void SaveDisasm() + { + if (fpath == null || "".compareToIgnoreCase(fpath) == 0) + { + AlertSelFile(); + return; + } + final List ListItems = new ArrayList<>(); + ListItems.add("Classic(Addr bytes inst op comment)"); + ListItems.add("Simple(Addr: inst op; comment"); + ListItems.add("Json(Reloadable)"); + final CharSequence[] items = ListItems.toArray(new String[ ListItems.size()]); + + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle("Export as..."); + builder.setItems(items, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int pos) + { + //String selectedText = items[pos].toString(); + dialog.dismiss(); + final ProgressDialog dialog2= showProgressDialog("Saving..."); + SaveDisasmSub(pos); + dialog2.dismiss(); + } + }); + builder.show(); + } + + private void SaveDisasmSub(int mode) + { + Log.v(TAG, "Saving disassembly"); + File dir=new File("/sdcard/disasm/"); + File file=new File(dir, new File(fpath).getName() + "_" + new Date(System.currentTimeMillis()).toString() + ".disassembly.txt"); + dir.mkdirs(); + try + { + file.createNewFile(); + } + catch (IOException e) + { + Log.e(TAG, "", e); + Toast.makeText(this, "Something went wrong saving file", 3).show(); + } + //Editable et=etDetails.getText(); + try + { + FileOutputStream fos=new FileOutputStream(file); + try + { + StringBuilder sb=new StringBuilder(); + for (ListViewItem lvi:disasmResults) + { + switch (mode) + { + case 0: + sb.append(lvi.address); + sb.append("\t"); + sb.append(lvi.bytes); + sb.append("\t"); + sb.append(lvi.instruction); + sb.append(" "); + sb.append(lvi.operands); + sb.append("\t"); + sb.append(lvi.comments); + break; + case 1: + sb.append(lvi.address); + sb.append(":"); + sb.append(lvi.instruction); + sb.append(" "); + sb.append(lvi.operands); + sb.append(" ;"); + sb.append(lvi.comments); + break; + case 2: + sb.append(lvi.toString()); + } + sb.append(System.lineSeparator()); + } + fos.write(sb.toString().getBytes()); + } + catch (IOException e) + { + Log.e(TAG, "", e); + } + } + catch (FileNotFoundException e) + { + Log.e(TAG, "", e); + } + AlertSaveSuccess(file); + } + + private void SaveDetail() + { + if (fpath == null || "".compareToIgnoreCase(fpath) == 0) + { + AlertSelFile(); + return; + } + Log.v(TAG, "Saving details"); + File dir=new File("/sdcard/disasm/"); + File file=new File(dir, new File(fpath).getName() + "_" + new Date(System.currentTimeMillis()).toString() + ".details.txt"); + dir.mkdirs(); + try + { + file.createNewFile(); + } + catch (IOException e) + { + Log.e(TAG, "", e); + Toast.makeText(this, "Something went wrong saving file", 3).show(); + } + // TODO: Implement this method + //Editable et=etDetails.getText(); + try + { + FileOutputStream fos=new FileOutputStream(file); + try + { + fos.write(elfUtil.toString().getBytes()); + } + catch (IOException e) + { + Log.e(TAG, "", e); + } + } + catch (FileNotFoundException e) + { + Log.e(TAG, "", e); + } + + AlertSaveSuccess(file); + } + + private void AlertSaveSuccess(File file) + { + Toast.makeText(this, "Successfully saved to file: " + file.getPath(), 5).show(); + } + + private void ShowDetail() + { + etDetails.setText(elfUtil.toString()); + } + + private void DisassembleInstant() + { + long startaddress=instantEntry;//file offset + long index=startaddress; + long addr=elfUtil.getCodeSectionVirtAddr(); + long limit=startaddress + 400; + for (;;) + { + DisasmResult dar=new DisasmResult(filecontent, index, addr); + if (dar.size == 0) + { + dar.size = 4; + dar.mnemonic = "db"; + dar.bytes = new byte[]{filecontent[(int)index],filecontent[(int)index + 1],filecontent[(int)index + 2],filecontent[(int)index + 3]}; + dar.op_str = ""; + Log.e(TAG, "Dar.size==0, breaking?"); + //break; + } + final ListViewItem lvi=new ListViewItem(dar); + disasmResults.add(lvi); + adapter.addItem(lvi); + adapter.notifyDataSetChanged(); + Log.v(TAG, "i=" + index + "lvi=" + lvi.toString()); + if (index >= limit) + { + Log.i(TAG, "index is " + index + ", breaking"); + break; + } + Log.v(TAG, "dar.size is =" + dar.size); + Log.i(TAG, "" + index + " out of " + (limit - startaddress)); + /*if((limit-start)%320==0){ + mBuilder.setProgress((int)(limit-startaddress), (int)(index-start), false); + // Displays the progress bar for the first time. + mNotifyManager.notify(0, mBuilder.build()); + }*/ + index += dar.size; + addr += dar.size; + + } + } + + //TODO: DisassembleFile(long address, int amt); + private void DisassembleFile() + { + Toast.makeText(this, "started", 2).show(); + Log.v(TAG, "Strted disassm"); + + //final ProgressDialog dialog= showProgressDialog("Disassembling..."); + disasmResults.clear(); + mNotifyManager = + (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + mBuilder = new Notification.Builder(this); + mBuilder.setContentTitle("Disassembler") + .setContentText("Disassembling in progress") + .setSmallIcon(R.drawable.cell_shape) + .setOngoing(true) + .setProgress(100, 0, false); + workerThread = new Thread(new Runnable(){ + @Override + public void run() + { + long start=elfUtil.getCodeSectionOffset(); + long index=start; + long limit=elfUtil.getCodeSectionLimit(); + long addr=elfUtil.getCodeSectionVirtAddr(); + Log.v(TAG, "code section point :" + Long.toHexString(index)); + // getFunctionNames(); + HashMap xrefComments=new HashMap(); + for (;;) + { + Capstone.CsInsn[] insns=cs.disasm(filecontent,index,addr,1); + Capstone.CsInsn insn=insns[0]; + final ListViewItem lvi=new ListViewItem(insn/*filecontent, index, addr*/); + if (insn.size == 0) + { + insn.size = 4; + insn.mnemonic = "db"; + //insn.bytes = new byte[]{filecontent[(int)index],filecontent[(int)index + 1],filecontent[(int)index + 2],filecontent[(int)index + 3]}; + insn.opStr = ""; + Log.e(TAG, "Dar.size==0, breaking?"); + //break; + } + //final ListViewItem lvi=new ListViewItem(dar); + if(lvi.isBranch()) + { + //xrefComments.put(lvi.getTargetAddress(),lvi.address); + } + runOnUiThread(new Runnable(){ + @Override + public void run() + { + adapter.addItem(lvi); + adapter.notifyDataSetChanged(); + return ; + } + }); + //Log.v(TAG, "i=" + index + "lvi=" + lvi.toString()); + if (index >= limit) + { + Log.i(TAG, "index is " + index + ", breaking"); + break; + } + //Log.v(TAG, "dar.size is =" + dar.size); + Log.i(TAG, "" + index + " out of " + (limit - start)); + if ((index - start) % 320 == 0) + { + mBuilder.setProgress((int)(limit - start), (int)(index - start), false); + // Displays the progress bar for the first time. + mNotifyManager.notify(0, mBuilder.build()); + runOnUiThread(new Runnable(){ + @Override + public void run() + { + //adapter.notifyDataSetChanged(); + listview.requestLayout(); + } + }); + } + index += insn.size; + addr += insn.size; + //dialog.setProgress((int)((float)(index-start) * 100 / (float)(limit-start))); + //dialog.setTitle("Disassembling.."+(index-start)+" out of "+(limit-start)); + } + mNotifyManager.cancel(0); + final int len=disasmResults.size(); + //add xrefs + + + runOnUiThread(new Runnable(){ + @Override + public void run() + { + /*for (int i=0;i < len;++i) + { + final ListViewItem lvi=disasmResults.get(i); + adapter.addItem(lvi); + //AddOneRow(lvi); + }*/ + //adapter.notifyDataSetChanged(); + listview.requestLayout(); + tab2.invalidate(); + //dialog.dismiss(); + Toast.makeText(MainActivity.this, "done", 2).show(); + } + }); + Log.v(TAG, "disassembly done"); + } + }); + workerThread.start(); + } + View.OnClickListener rowClkListener= new OnClickListener() { + public void onClick(View view) + { + TableRow tablerow = (TableRow) view; + ListViewItem lvi= (ListViewItem) tablerow.getTag(); + //TextView sample = (TextView) tablerow.getChildAt(1); + tablerow.setBackgroundColor(Color.GREEN); + } + }; + private void AddOneRow(ListViewItem lvi) + { + TableRow tbrow = new TableRow(MainActivity.this); + TextView t1v = new TextView(MainActivity.this); + t1v.setText(lvi.getAddress()); + t1v.setTextColor(Color.BLACK); + t1v.setGravity(Gravity.CENTER); + t1v.setBackgroundResource(R.drawable.cell_shape); + tbrow.addView(t1v); + TextView t2v = new TextView(MainActivity.this); + t2v.setText(lvi.getLabel()); + t2v.setTextColor(Color.BLACK); + t2v.setGravity(Gravity.CENTER); + t2v.setBackgroundResource(R.drawable.cell_shape); + tbrow.addView(t2v); + TextView t3v = new TextView(MainActivity.this); + t3v.setText(lvi.getBytes()); + t3v.setTextColor(Color.BLACK); + t3v.setGravity(Gravity.CENTER); + t3v.setBackgroundResource(R.drawable.cell_shape); + tbrow.addView(t3v); + TextView t4v = new TextView(MainActivity.this); + t4v.setText(lvi.getInstruction()); + t4v.setTextColor(Color.BLACK); + t4v.setGravity(Gravity.CENTER); + t4v.setBackgroundResource(R.drawable.cell_shape); + tbrow.addView(t4v); + TextView t5v = new TextView(MainActivity.this); + t5v.setText(lvi.getCondition()); + t5v.setTextColor(Color.BLACK); + t5v.setGravity(Gravity.CENTER); + t5v.setBackgroundResource(R.drawable.cell_shape); + tbrow.addView(t5v); + TextView t6v = new TextView(MainActivity.this); + t6v.setText(lvi.getOperands()); + t6v.setTextColor(Color.BLACK); + t6v.setGravity(Gravity.CENTER); + t6v.setBackgroundResource(R.drawable.cell_shape); + tbrow.addView(t6v); + TextView t7v = new TextView(MainActivity.this); + t7v.setText(lvi.getComments()); + t7v.setTextColor(Color.BLACK); + t7v.setGravity(Gravity.CENTER); + t7v.setBackgroundResource(R.drawable.cell_shape); + tbrow.addView(t7v); + AdjustShow(t1v, t2v, t3v, t4v, t5v, t6v, t7v); + tbrow.invalidate(); + tbrow.setClickable(true); //allows you to select a specific row + tbrow.setOnClickListener(rowClkListener); + tbrow.setTag(lvi); + tlDisasmTable.addView(tbrow); + } + + private void getFunctionNames() + { + // TODO: Implement this me + return ; + } + public void AdjustShow(TextView t1v, TextView t2v, TextView t3v, TextView t4v, TextView t5v, TextView t6v, TextView t7v) + { + t1v.setVisibility(isShowAddress() ? View.VISIBLE: View.GONE); + t2v.setVisibility(isShowLabel() ? View.VISIBLE: View.GONE); + t3v.setVisibility(isShowBytes() ? View.VISIBLE: View.GONE); + t4v.setVisibility(isShowInstruction() ? View.VISIBLE: View.GONE); + t5v.setVisibility(isShowCondition() ? View.VISIBLE: View.GONE); + t6v.setVisibility(isShowOperands() ? View.VISIBLE: View.GONE); + t7v.setVisibility(isShowComment() ? View.VISIBLE: View.GONE); + } + + public static final int REQUEST_WRITE_STORAGE_REQUEST_CODE=1; + public static void requestAppPermissions(Activity a) { + if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + return; + } + if (hasReadPermissions(a) && hasWritePermissions(a)) { + Log.i(TAG,"Has permissions"); + return; + } + a.requestPermissions(new String[] { + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.WRITE_EXTERNAL_STORAGE + }, REQUEST_WRITE_STORAGE_REQUEST_CODE); // your request code + } + + public static boolean hasReadPermissions(Context c) { + return c.checkSelfPermission( Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; + } + + public static boolean hasWritePermissions(Context c) { + return c.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; + } + /** Called when the activity is first created. */ @Override - protected void onCreate(Bundle savedInstanceState) + public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + final Thread.UncaughtExceptionHandler ori=Thread.getDefaultUncaughtExceptionHandler(); + Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler(){ + @Override + public void uncaughtException(Thread p1, Throwable p2) + { + // TODO: Implement this method + final Intent emailIntent = new Intent( android.content.Intent.ACTION_SEND); + + emailIntent.setType("plain/text"); + + emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, + new String[] { "1641832e@fire.fundersclub.com" }); + + emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, + "Crash report"); + + emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, + Log.getStackTraceString(p2)); + + startActivity(Intent.createChooser(emailIntent, "Send crash report as an issue by email")); + ori.uncaughtException(p1,p2); + return ; + } + }); + + /* Create a TextView and set its content. + * the text is retrieved by calling a native + * function. + */ setContentView(R.layout.main); + etDetails = (EditText) findViewById(R.id.detailText); + Button selectFile=(Button) findViewById(R.id.selFile); + selectFile.setOnClickListener(this); + btShowDetails = (Button) findViewById(R.id.btnShowdetail); + btShowDetails.setOnClickListener(this); + btDisasm = (Button) findViewById(R.id.btnDisasm); + btDisasm.setOnClickListener(this); + btSavDisasm = (Button) findViewById(R.id.btnSaveDisasm); + btSavDisasm.setOnClickListener(this); + btSavDit = (Button) findViewById(R.id.btnSaveDetails); + btSavDit.setOnClickListener(this); + + etFilename = (EditText) findViewById(R.id.fileNameText); + etFilename.setFocusable(false); + etFilename.setEnabled(false); + + tabHost = (TabHost) findViewById(R.id.tabhost1); + tabHost.setup(); + TabHost.TabSpec tab0 = tabHost.newTabSpec("1").setContent(R.id.tab0).setIndicator("Overview"); + TabHost.TabSpec tab1 = tabHost.newTabSpec("2").setContent(R.id.tab1).setIndicator("Details"); + TabHost.TabSpec tab2 = tabHost.newTabSpec("3").setContent(R.id.tab2).setIndicator("Disassembly"); + tabHost.addTab(tab0); + tabHost.addTab(tab1); + tabHost.addTab(tab2); + this.tab1 = (LinearLayout) findViewById(R.id.tab1); + this.tab2 = (LinearLayout) findViewById(R.id.tab2); + try + { + cs = new Capstone(Capstone.CS_ARCH_ARM, Capstone.CS_MODE_ARM); + cs.setDetail(Capstone.CS_OPT_ON); + }catch(RuntimeException e) + { + Toast.makeText(this, "Failed to initialize the native engine: "+Log.getStackTraceString(e), 10).show(); + android.os.Process.killProcess(android.os.Process.getGidForName(null)); + } + if (cs==null) + { + Toast.makeText(this, "Failed to initialize the native engine", 3).show(); + android.os.Process.killProcess(android.os.Process.getGidForName(null)); + } + //tlDisasmTable = (TableLayout) findViewById(R.id.table_main); + // TableRow tbrow0 = new TableRow(MainActivity.this); + // CreateDisasmTopRow(tbrow0); + // tlDisasmTable.addView(tbrow0); + adapter = new ListViewAdapter(); + listview = (ListView) findViewById(R.id.listview); + listview.setAdapter(adapter); + listview.setOnItemClickListener(new AdapterView.OnItemClickListener(){ + @Override + public void onItemClick(AdapterView parent, View p2, int position, long id) + { + ListViewItem lvi=(ListViewItem) parent.getItemAtPosition(position); + if (lvi.isBranch()) + { + + } + // TODO: Implement this method + return; + } + }); + + requestAppPermissions(this); + // ViewGroup.LayoutParams lp= listview.getLayoutParams(); + //listview.setMinimumHeight(getScreenHeight()); + //listview.setLayoutParams(lp); + // elfUtil=null; + // filecontent=null; } + public static int getScreenHeight() + { + return Resources.getSystem().getDisplayMetrics().heightPixels; + } + private void CreateDisasmTopRow(TableRow tbrow0) + { + TextView tv0 = new TextView(MainActivity.this); + tv0.setText(" Address "); + tv0.setTextColor(Color.BLACK); + tbrow0.addView(tv0); + TextView tv1 = new TextView(MainActivity.this); + tv1.setText(" Label "); + tv1.setTextColor(Color.BLACK); + tbrow0.addView(tv1); + TextView tv2 = new TextView(MainActivity.this); + tv2.setText(" Bytes "); + tv2.setTextColor(Color.BLACK); + tbrow0.addView(tv2); + TextView tv3 = new TextView(MainActivity.this); + tv3.setText(" Inst "); + tv3.setTextColor(Color.BLACK); + tbrow0.addView(tv3); + TextView tv4 = new TextView(MainActivity.this); + tv4.setText(" Cond "); + tv4.setTextColor(Color.BLACK); + tbrow0.addView(tv4); + TextView tv5 = new TextView(MainActivity.this); + tv5.setText(" Operands "); + tv5.setTextColor(Color.BLACK); + tbrow0.addView(tv5); + TextView tv6 = new TextView(MainActivity.this); + tv6.setText(" Comment "); + tv6.setTextColor(Color.BLACK); + AdjustShow(tv0, tv1, tv2, tv3, tv4, tv5, tv6); + tbrow0.addView(tv6); + } + public void RefreshTable() + { + //tlDisasmTable.removeAllViews(); + //TableRow tbrow0 = new TableRow(MainActivity.this); + //CreateDisasmTopRow(tbrow0); + //tlDisasmTable.addView(tbrow0); + //for(int i=0;i 0 + && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + + // permission was granted, yay! Do the + // contacts-related task you need to do. + + } else { + + // permission denied, boo! Disable the + // functionality that depends on this permission. + } + return; + } + + // other 'case' lines to check for other + // permissions this app might request + } +} + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) + { + switch (requestCode) + { + /*case FILE_SELECT_CODE: + if (resultCode == RESULT_OK) + { + // Get the Uri of the selected file + Uri uri = data.getData(); + //File file=new File(uri.); + //URI -> real file path + try + { + String file_path; + if (new File(uri.getPath()).exists() == false) + { + file_path = RealPathUtils.getRealPathFromURI(this, uri); + } + else + { + file_path = uri.getPath(); + } + etFilename.setText(file_path); + fpath = file_path; //uri.getPath(); + File file=new File(file_path); + long fsize=file.length(); + int index=0; + filecontent = new byte[(int)fsize]; + DataInputStream in = new DataInputStream(new FileInputStream(fpath)); + int len,counter=0; + byte[] b=new byte[1024]; + while ((len = in.read(b)) > 0) + { + for (int i = 0; i < len; i++) + { // byte[] 버퍼 내용 출력 + //System.out.format("%02X ", b[i]); + filecontent[index] = b[i]; + index++; + counter++; + } + } + elfUtil = new ELFUtil(file, filecontent); + Toast.makeText(this, "success size=" + new Integer(index).toString(), 1).show(); + } + catch (Exception e) + { + Toast.makeText(this, Log.getStackTraceString(e), 30).show(); + Log.e(TAG, "Nooo", e); + } + } + break; + */ + case REQUEST_SELECT_FILE: + if (resultCode == Activity.RESULT_OK) + { + try + { + String path=data.getStringExtra("com.jourhyang.disasmarm.path"); + File file=new File(path); + etFilename.setText(file.getAbsolutePath()); + long fsize=file.length(); + int index=0; + filecontent = new byte[(int)fsize]; + DataInputStream in = new DataInputStream(new FileInputStream(file)); + int len,counter=0; + byte[] b=new byte[1024]; + while ((len = in.read(b)) > 0) + { + for (int i = 0; i < len; i++) + { // byte[] 버퍼 내용 출력 + //System.out.format("%02X ", b[i]); + filecontent[index] = b[i]; + index++; + counter++; + } + } + elfUtil = new ELFUtil(file, filecontent); + Toast.makeText(this, "success size=" + new Integer(index).toString(), 1).show(); + } + catch (IOException e) + { + Log.e(TAG,"",e); + Toast.makeText(this,Log.getStackTraceString(e),30).show(); + } + } + } + super.onActivityResult(requestCode, resultCode, data); + } + + private String getRealPathFromURI(Uri uri) + { + String filePath = ""; + filePath = uri.getPath(); + //경로에 /storage가 들어가면 real file path로 판단 + if (filePath.startsWith("/storage")) + return filePath; + String wholeID = DocumentsContract.getDocumentId(uri); + //wholeID는 파일명이 abc.zip이라면 /document/B5D7-1CE9:abc.zip와 같습니다. + // Split at colon, use second item in the array + String id = wholeID.split(":")[0]; + //Log.e(TAG, "id = " + id); + String[] column = { MediaStore.Files.FileColumns.DATA }; + //파일의 이름을 통해 where 조건식을 만듭니다. + String sel = MediaStore.Files.FileColumns.DATA + " LIKE '%" + id + "%'"; + //External storage에 있는 파일의 DB를 접근하는 방법 입니다. + Cursor cursor = getContentResolver().query(MediaStore.Files.getContentUri("external"), column, sel, null, null); + //SQL문으로 표현하면 아래와 같이 되겠죠???? + //SELECT _dtat FROM files WHERE _data LIKE '%selected file name%' + int columnIndex = cursor.getColumnIndex(column[0]); + if (cursor.moveToFirst()) + { + filePath = cursor.getString(columnIndex); + } + cursor.close(); + return filePath; + } + + /*ublic String Disassemble(EditText result) + { + //String s=disassemble(filecontent, elfUtil.getEntryPoint()); + String s; + byte [] b=Arrays.copyOfRange(filecontent, (int)elfUtil.getEntryPoint(), filecontent.length - 1); + s = new DisasmResult(b, 0).toString(); + return s; + } + */ + private ProgressDialog showProgressDialog(String s) + { + ProgressDialog dialog = new ProgressDialog(this); + dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); + dialog.setMessage(s); + dialog.setCancelable(false); + dialog.show(); + return dialog; + } + + private final static char[] hexArray = "0123456789ABCDEF".toCharArray(); + public static String bytesToHex(byte[] bytes) + { + char[] hexChars = new char[bytes.length * 2]; + for (int j = 0; j < bytes.length; j++) + { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + return new String(hexChars); + } + + public void setShowAddress(boolean showAddress) + { + this.showAddress = showAddress; + } + + public boolean isShowAddress() + { + return showAddress; + } + + public void setShowLabel(boolean showLabel) + { + this.showLabel = showLabel; + } + + public boolean isShowLabel() + { + return showLabel; + } + + public void setShowBytes(boolean showBytes) + { + this.showBytes = showBytes; + } + + public boolean isShowBytes() + { + return showBytes; + } + + public void setShowInstruction(boolean showInstruction) + { + this.showInstruction = showInstruction; + } + + public boolean isShowInstruction() + { + return showInstruction; + } + + public void setShowCondition(boolean showCondition) + { + this.showCondition = showCondition; + } + + public boolean isShowCondition() + { + return showCondition; + } + + public void setShowOperands(boolean showOperands) + { + this.showOperands = showOperands; + } + + public boolean isShowOperands() + { + return showOperands; + } + + public void setShowComment(boolean showComment) + { + this.showComment = showComment; + } + + public boolean isShowComment() + { + return showComment; + } + + /* A native method that is implemented by the + * 'hello-jni' native library, which is packaged + * with this application. + */ + // public native String disassemble(byte [] bytes, long entry); + //public native int Init(); + //public native void Finalize(); + + /* this is used to load the 'hello-jni' library on application + * startup. The library has already been unpacked into + * /data/data/com.example.hellojni/lib/libhello-jni.so at + * installation time by the package manager. + */ + + /* OnCreate() + vp = (ViewPager)findViewById(R.id.pager); + Button btn_first = (Button)findViewById(R.id.btn_first); + Button btn_second = (Button)findViewById(R.id.btn_second); + Button btn_third = (Button)findViewById(R.id.btn_third); + + vp.setAdapter(new pagerAdapter(getSupportFragmentManager())); + vp.setCurrentItem(0); + + btn_first.setOnClickListener(movePageListener); + btn_first.setTag(0); + btn_second.setOnClickListener(movePageListener); + btn_second.setTag(1); + btn_third.setOnClickListener(movePageListener); + btn_third.setTag(2);*/ + // Adapter 생성 + // adapter = new ListViewAdapter() ; + /* ListViewItem item=new ListViewItem(); + item.setAddress("address"); + item.setBytes("bytes"); + item.setComments("comments"); + item.setCondition("condition"); + item.setInstruction("inst"); + item.setLabel("label"); + item.setOperands("operands"); + adapter.addItem(item); + // 리스트뷰 참조 및 Adapter달기 + listview = (ListView) findViewById(R.id.lvDisassembly); + listview.setAdapter(adapter); + listview.setOnTouchListener(new ListView.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + int action = event.getAction(); + switch (action) { + case MotionEvent.ACTION_DOWN: + // Disallow ScrollView to intercept touch events. + v.getParent().requestDisallowInterceptTouchEvent(true); + break; + + case MotionEvent.ACTION_UP: + // Allow ScrollView to intercept touch events. + v.getParent().requestDisallowInterceptTouchEvent(false); + break; + } + + // Handle ListView touch events. + v.onTouchEvent(event); + return true; + }}); + // 위에서 생성한 listview에 클릭 이벤트 핸들러 정의. + listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View v, int position, long id) { + // get item + ListViewItem item = (ListViewItem) parent.getItemAtPosition(position) ; + + //String titleStr = item.getTitle() ; + //String descStr = item.getDesc() ; + //Drawable iconDrawable = item.getIcon() ; + + // TODO : use item data. + } + }) ;*/ + /* + PrintStackTrace to string + ByteArrayOutputStream out = new ByteArrayOutputStream(); + PrintStream pinrtStream = new PrintStream(out); + e.printStackTrace(pinrtStream); + String stackTraceString = out.toString(); // 찍은 값을 가져오고. + + */ + /* + public void onWindowFocusChanged(boolean hasFocus) { + // get content height + int contentHeight = listview.getChildAt(0).getHeight(); + contentHeight*=listview.getChildCount(); + // set listview height + LayoutParams lp = listview.getLayoutParams(); + lp.height = contentHeight; + listview.setLayoutParams(lp); + } + */ + + /* switch(id) { + case R.id.menu_login: + Toast.makeText(getApplicationContext(), "로그인 메뉴 클릭", + Toast.LENGTH_SHORT).show(); + return true; + case R.id.menu_logout: + Toast.makeText(getApplicationContext(), "로그아웃 메뉴 클릭", + Toast.LENGTH_SHORT).show(); + return true; + case R.id.menu_a: + Toast.makeText(getApplicationContext(), "다음", + Toast.LENGTH_SHORT).show(); + return true; + }*/ + /* + View.OnClickListener movePageListener = new View.OnClickListener() + { + @Override + public void onClick(View v) + { + int tag = (int) v.getTag(); + vp.setCurrentItem(tag); + } + }; + + private class pagerAdapter extends FragmentStatePagerAdapter + { + public pagerAdapter(android.support.v4.app.FragmentManager fm) + { + super(fm); + } + @Override + public android.support.v4.app.Fragment getItem(int position) + { + switch(position) + { + case 0: + return new OverviewFragment(); + case 1: + return new OverviewFragment(); + case 2: + return new OverviewFragment(); + default: + return null; + } + } + @Override + public int getCount() + { + return 3; + } + }*/ + //details.setText("file format not recognized."); + // String result=sample.getText().toString(); + //Toast toast = Toast.makeText(myActivity, result, Toast.LENGTH_LONG); + //toast.show(); } diff --git a/app/src/main/java/com/kyhsgeekcode/disassembler/OpenSourceActivity.java b/app/src/main/java/com/kyhsgeekcode/disassembler/OpenSourceActivity.java new file mode 100644 index 00000000..4ff5b7c1 --- /dev/null +++ b/app/src/main/java/com/kyhsgeekcode/disassembler/OpenSourceActivity.java @@ -0,0 +1,109 @@ +package com.kyhsgeekcode.disassembler; + +import android.app.*; +import android.content.*; +import android.os.*; +import android.preference.*; +import android.util.*; +import android.widget.*; +import java.io.*; +import android.view.*; +//https://stackoverflow.com/a/5712812/8614565 +//https://stackoverflow.com/a/16449611/8614565 +public class OpenSourceActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener, +AdapterView.OnItemClickListener +{ + @Override + public void onItemClick(AdapterView parent, View view,int pos, long id) + { + // TODO: Implement this method + Preference prf= getPreferenceScreen().getPreference(pos); + String key=prf.getKey(); + onSharedPreferenceChanged((SharedPreferences)null,key); + return ; + } + + SharedPreferences mPreferences; + private String TAG="Disassembler OSA"; + @Override + protected void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.pref_opensource); + //getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); + getListView().setOnItemClickListener(this); + Log.v(TAG,"OnCreate"); + // setOnPreferenceChange(findPreference("userName")); + //setOnPreferenceChange(findPreference("userNameOpen")); + // setOnPreferenceChange(findPreference("autoUpdate_ringtone")); + } + @SuppressWarnings("deprecation") + @Override + protected void onPause() + { + super.onPause(); + + //getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this); + } + + @SuppressWarnings("deprecation") + @Override + protected void onResume() + { + super.onResume(); + + //getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); + } + + + @SuppressWarnings("deprecation") + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + // //https://stackoverflow.com/a/16110044/8614565 + StringBuilder buf=new StringBuilder(); + Log.v(TAG,"on"); + try + { + Log.v(TAG,"key="+key); + InputStream notice=getAssets().open(key); + BufferedReader in= + new BufferedReader(new InputStreamReader(notice, "UTF-8")); + String str; + while ((str=in.readLine()) != null) { + buf.append(str); + } + in.close(); + } + catch (IOException e) + { + Log.e(TAG,"",e); + } + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(key); + builder.setMessage(buf.toString()); + builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) + { + //action on dialog close + } + }); + builder.show(); + return ; + } + //private void setOnPreferenceChange(Preference mPreference) + //{ + // mPreference.setOnPreferenceChangeListener(onPreferenceChangeListener); + +// onPreferenceChangeListener.onPreferenceChange( +// mPreference, +// PreferenceManager.getDefaultSharedPreferences( +// mPreference.getContext()).getString( +// mPreference.getKey(), "")); + //} +// public boolean onPreferenceClick(final Preference preference) +// { + +// +// } +} + diff --git a/app/src/main/java/com/kyhsgeekcode/disassembler/RadioGridGroup.java b/app/src/main/java/com/kyhsgeekcode/disassembler/RadioGridGroup.java new file mode 100644 index 00000000..d19c1af2 --- /dev/null +++ b/app/src/main/java/com/kyhsgeekcode/disassembler/RadioGridGroup.java @@ -0,0 +1,185 @@ +package com.kyhsgeekcode.disassembler; + + +import android.content.Context; +import android.os.Parcel; +import android.os.Parcelable; +//import android.support.annotation.IdRes; +import android.util.AttributeSet; +import android.view.View; +import android.widget.RadioButton; +import android.widget.TableLayout; +import android.widget.TableRow; + +//https://stackoverflow.com/a/33802142/8614565 +public class RadioGridGroup extends TableLayout implements View.OnClickListener { + + private static final String TAG = "ToggleButtonGroupTableLayout"; + private int checkedButtonID = -1; + + /** + * @param context + */ + public RadioGridGroup(Context context) { + super(context); + // TODO Auto-generated constructor stub + } + + /** + * @param context + * @param attrs + */ + public RadioGridGroup(Context context, AttributeSet attrs) { + super(context, attrs); + // TODO Auto-generated constructor stub + } + + @Override + public void onClick(View v) { + if (v instanceof RadioButton) { + int id = v.getId(); + check(id); + } + } + + private void setCheckedStateForView(int viewId, boolean checked) { + View checkedView = findViewById(viewId); + if (checkedView != null && checkedView instanceof RadioButton) { + ((RadioButton) checkedView).setChecked(checked); + } + } + + /* (non-Javadoc) + * @see android.widget.TableLayout#addView(android.view.View, int, android.view.ViewGroup.LayoutParams) + */ + @Override + public void addView(View child, int index, + android.view.ViewGroup.LayoutParams params) { + super.addView(child, index, params); + setChildrenOnClickListener((TableRow) child); + } + + + /* (non-Javadoc) + * @see android.widget.TableLayout#addView(android.view.View, android.view.ViewGroup.LayoutParams) + */ + @Override + public void addView(View child, android.view.ViewGroup.LayoutParams params) { + super.addView(child, params); + setChildrenOnClickListener((TableRow) child); + } + + + private void setChildrenOnClickListener(TableRow tr) { + final int c = tr.getChildCount(); + for (int i = 0; i < c; i++) { + final View v = tr.getChildAt(i); + if (v instanceof RadioButton) { + v.setOnClickListener(this); + } + } + } + + + /** + * @return the checked button Id + */ + public int getCheckedRadioButtonId() { + return checkedButtonID; + } + + + /** + * Check the id + * + * @param id + */ + public void check(/*@IdRes*/ int id) { + // don't even bother + if (id != -1 && (id == checkedButtonID)) { + return; + } + if (checkedButtonID != -1) { + setCheckedStateForView(checkedButtonID, false); + } + if (id != -1) { + setCheckedStateForView(id, true); + } + setCheckedId(id); + } + + /** + * set the checked button Id + * + * @param id + */ + private void setCheckedId(int id) { + this.checkedButtonID = id; + } + + public void clearCheck() { + check(-1); + } + + @Override + protected void onRestoreInstanceState(Parcelable state) { + if (!(state instanceof SavedState)) { + super.onRestoreInstanceState(state); + return; + } + + SavedState ss = (SavedState) state; + super.onRestoreInstanceState(ss.getSuperState()); + + this.checkedButtonID = ss.buttonId; + setCheckedStateForView(checkedButtonID, true); + } + + @Override + protected Parcelable onSaveInstanceState() { + Parcelable superState = super.onSaveInstanceState(); + SavedState savedState = new SavedState(superState); + savedState.buttonId = checkedButtonID; + return savedState; + } + + static class SavedState extends BaseSavedState { + int buttonId; + + /** + * Constructor used when reading from a parcel. Reads the state of the superclass. + * + * @param source + */ + public SavedState(Parcel source) { + super(source); + buttonId = source.readInt(); + } + + /** + * Constructor called by derived classes when creating their SavedState objects + * + * @param superState The state of the superclass of this view + */ + public SavedState(Parcelable superState) { + super(superState); + } + + @Override + public void writeToParcel(Parcel out, int flags) { + super.writeToParcel(out, flags); + out.writeInt(buttonId); + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + public SavedState createFromParcel(Parcel in) { + return new SavedState(in); + } + + public SavedState[] newArray(int size) { + return new SavedState[size]; + } + }; + } +} diff --git a/app/src/main/java/com/kyhsgeekcode/disassembler/RealPathUtils.java b/app/src/main/java/com/kyhsgeekcode/disassembler/RealPathUtils.java new file mode 100644 index 00000000..5563b997 --- /dev/null +++ b/app/src/main/java/com/kyhsgeekcode/disassembler/RealPathUtils.java @@ -0,0 +1,86 @@ +package com.kyhsgeekcode.disassembler; + + +import android.annotation.*; +import android.content.*; +import android.database.*; +import android.net.*; +import android.os.*; +import android.provider.*; +import android.util.*; +import java.io.*; + +public class RealPathUtils { + + @SuppressLint("NewApi") + public static String getRealPathFromURI_API19(Context context, Uri uri){ + String filePath = ""; + String wholeID = DocumentsContract.getDocumentId(uri); + + // Split at colon, use second item in the array + String id = wholeID.split(":")[1]; + + String[] column = { MediaStore.Images.Media.DATA }; + + // where id is equal to + String sel = MediaStore.Images.Media._ID + "=?"; + + Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, + column, sel, new String[]{ id }, null); + + int columnIndex = cursor.getColumnIndex(column[0]); + + if (cursor.moveToFirst()) { + filePath = cursor.getString(columnIndex); + } + cursor.close(); + return filePath; + } + + + @SuppressLint("NewApi") + public static String getRealPathFromURI_API11to18(Context context, Uri contentUri) { + String[] proj = { MediaStore.Images.Media.DATA }; + String result = null; + + CursorLoader cursorLoader = new CursorLoader( + context, + contentUri, proj, null, null, null); + Cursor cursor = cursorLoader.loadInBackground(); + + if(cursor != null){ + int column_index = + cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); + cursor.moveToFirst(); + result = cursor.getString(column_index); + } + return result; + } + + public static String getRealPathFromURI_BelowAPI11(Context context, Uri contentUri){ + String[] proj = { MediaStore.Images.Media.DATA }; + Cursor cursor = context.getContentResolver().query(contentUri, proj, null, null, null); + int column_index + = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); + cursor.moveToFirst(); + return cursor.getString(column_index); + } + public static String getRealPathFromURI(Context context,Uri contentUri) + { + String path = null; + if (Build.VERSION.SDK_INT < 11) + path = RealPathUtils.getRealPathFromURI_BelowAPI11(context, contentUri); + + // SDK >= 11 && SDK < 19 + else if (Build.VERSION.SDK_INT < 19) + path = RealPathUtils.getRealPathFromURI_API11to18(context, contentUri); + + // SDK > 19 (Android 4.4) + else + path = RealPathUtils.getRealPathFromURI_API19(context, contentUri); + //Log.d(TAG, "File Path: " + path); + // Get the file instance + //File file = new File(path); + return path; + } +} diff --git a/app/src/main/java/com/kyhsgeekcode/disassembler/SettingsActivity.java b/app/src/main/java/com/kyhsgeekcode/disassembler/SettingsActivity.java new file mode 100644 index 00000000..8747e999 --- /dev/null +++ b/app/src/main/java/com/kyhsgeekcode/disassembler/SettingsActivity.java @@ -0,0 +1,142 @@ +package com.kyhsgeekcode.disassembler; + + +import android.app.*; +import android.content.*; +import android.media.*; +import android.net.*; +import android.os.*; +import android.preference.*; +import android.text.*; +import android.util.*; +import java.io.*; + +public class SettingsActivity extends PreferenceActivity implements Preference.OnPreferenceClickListener +{ + private String TAG="Disassembler settings"; + + @Override + public boolean onPreferenceClick(Preference p1) + { + String key=p1.getKey(); + StringBuilder buf=new StringBuilder(); + Log.v(TAG,"on"); + try + { + Log.v(TAG,"key="+key); + InputStream notice=getAssets().open(key); + BufferedReader in= + new BufferedReader(new InputStreamReader(notice, "UTF-8")); + String str; + while ((str=in.readLine()) != null) { + buf.append(str); + } + in.close(); + } + catch (IOException e) + { + Log.e(TAG,"",e); + } + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(key); + builder.setMessage(buf.toString()); + builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) + { + //action on dialog close + } + }); + builder.show(); + return true ; + } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.pref_settings); + PreferenceScreen scrn=(PreferenceScreen) findPreference("openscrn"); + //scrn.setOnPreferenceClickListener(this); + int cnt=scrn.getPreferenceCount(); + for(int i=0;i= 0 ? listPreference.getEntries()[index] + : null); + + } else if (preference instanceof RingtonePreference) { + + /* + RingtonePreference�� ��� stringValue�� + * content://media/internal/audio/media�� ����̱� ������ + * RingtoneManager� ����Ͽ� Summary�� ����Ѵ� + * + * ����ϰ�� ""�̴� + */ + + if (TextUtils.isEmpty(stringValue)) { + // Empty values correspond to 'silent' (no ringtone). + preference.setSummary("������ �����"); + } else { + Ringtone ringtone = RingtoneManager.getRingtone( + preference.getContext(), Uri.parse(stringValue)); + + if (ringtone == null) { + // Clear the summary if there was a lookup error. + preference.setSummary(null); + + } else { + String name = ringtone + .getTitle(preference.getContext()); + preference.setSummary(name); + } + } + } + + return true; + } + + }; + + @Override + protected void onPause() + { + // TODO: Implement this method + super.onPause(); + //getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(onPreferenceChangeListener); + } + +} diff --git a/app/src/main/java/nl/lxtreme/binutils/ar/AR.java b/app/src/main/java/nl/lxtreme/binutils/ar/AR.java new file mode 100644 index 00000000..6f5839dc --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/ar/AR.java @@ -0,0 +1,404 @@ +/******************************************************************************* + * Copyright (c) 2011 - J.W. Janssen + * + * Copyright (c) 2000, 2008 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + * Abeer Bagul (Tensilica) - bug 102434 + * Anton Leherbauer (Wind River Systems) + * J.W. Janssen - Cleanup and some small API changes. + *******************************************************************************/ +package nl.lxtreme.binutils.ar; + + +import java.io.*; +import java.util.*; + + +/** + * Used for parsing standard ELF archive (ar) files. Each object within the + * archive is represented by an ARHeader class. Each of of these objects can + * then be turned into an Elf object for performing Elf class operations. + * + * @see AREntry + */ +public class AR +{ + // VARIABLES + + private final String path; + private RandomAccessFile efile; + private long stringTableOffset; + private Collection headers; + + // CONSTRUCTORS + + /** + * Creates a new AR object from the contents of the given file. + * + * @param aFile + * The AR archive file to process. + * @throws IllegalArgumentException + * in case the given file was null; + * @throws IOException + * if the given file is not a valid AR archive. + */ + public AR( final File aFile ) throws IOException + { + if ( aFile == null ) + { + throw new IllegalArgumentException( "Parameter File cannot be null!" ); + } + + this.path = aFile.getAbsolutePath(); + this.efile = new RandomAccessFile( aFile, "r" ); + + final byte[] hdrBytes = new byte[7]; + this.efile.readFully( hdrBytes ); + + if ( !AREntry.isARHeader( hdrBytes ) ) + { + this.efile.close(); + this.efile = null; + + throw new IOException( "Invalid AR archive! No header found." ); + } + + this.efile.readLine(); + } + + // METHODS + + /** + * Disposes all resources for this AR archive. + */ + public void dispose() + { + try + { + if ( this.efile != null ) + { + this.efile.close(); + this.efile = null; + } + } + catch ( final IOException exception ) + { + // Ignored... + } + } + + /** + * Extracts all files from this archive matching the given names. + * + * @param aOutputDir + * the output directory to extract the files to, cannot be + * null; + * @param aNames + * the names of the files to extract, if omitted all files will be + * extracted. + * @throws IllegalArgumentException + * in case the given output directory was null; + * @throws IOException + * in case of I/O problems. + */ + public void extractFiles( final File aOutputDir, final String... aNames ) throws IOException + { + if ( aOutputDir == null ) + { + throw new IllegalArgumentException( "Parameter OutputDir cannot be null!" ); + } + + for ( final AREntry header : getEntries() ) + { + String fileName = header.getFileName(); + if ( ( aNames != null ) && !stringInStrings( aNames, fileName ) ) + { + continue; + } + + this.efile.seek( header.getFileOffset() ); + + extractFile( header, new File( aOutputDir, fileName ) ); + } + } + + /** + * Returns the name of this archive. + * + * @return an archive name, never null. + */ + public String getArchiveName() + { + return this.path; + } + + /** + * Get an array of all the object file headers for this archive. + * + * @throws IOException + * Unable to process the archive file. + * @return An array of headers, one for each object within the archive. + * @see AREntry + */ + public Collection getEntries() throws IOException + { + if ( this.headers == null ) + { + this.headers = loadEntries(); + } + return Collections.unmodifiableCollection( this.headers ); + } + + /** + * Returns all names of the entries in this archive. + * + * @return a collection of entry names, never null. + * @throws IOException + * in case of I/O problems. + */ + public Collection getEntryNames() throws IOException + { + Collection entries = getEntries(); + + List result = new ArrayList( entries.size() ); + for ( AREntry entry : entries ) + { + result.add( entry.getFileName() ); + } + + return Collections.unmodifiableCollection( result ); + } + + /** + * Reads a file and writes the results to the given writer object. + * + * @param aWriter + * the writer to write the file contents to, cannot be + * null; + * @param aName + * the name of the file to read, cannot be null. + * @return true if the file was successfully read, + * false otherwise. + * @throws IllegalArgumentException + * in case either one of the given arguments was null; + * @throws IOException + * in case of I/O problems. + */ + public boolean readFile( final Writer aWriter, final String aName ) throws IOException + { + if ( aWriter == null ) + { + throw new IllegalArgumentException( "Parameter Writer cannot be null!" ); + } + if ( aName == null ) + { + throw new IllegalArgumentException( "Parameter Name cannot be null!" ); + } + + for ( final AREntry header : getEntries() ) + { + String name = header.getFileName(); + if ( aName.equals( name ) ) + { + this.efile.seek( header.getFileOffset() ); + + extractFile( header, aWriter ); + return true; + } + } + + return false; + } + + /** + * Look up the name stored in the archive's string table based on the offset + * given. Maintains efile file location. + * + * @param aOffset + * Offset into the string table for first character of the name. + * @throws IOException + * offset not in string table bounds. + */ + final String nameFromStringTable( final long aOffset ) throws IOException + { + if ( this.stringTableOffset < 0 ) + { + throw new IOException( "Invalid AR archive! No string table read yet?!" ); + } + + final StringBuilder name = new StringBuilder(); + + final long originalPos = this.efile.getFilePointer(); + + try + { + this.efile.seek( this.stringTableOffset + aOffset ); + + byte temp; + while ( ( temp = this.efile.readByte() ) != '\n' ) + { + name.append( ( char )temp ); + } + } + finally + { + this.efile.seek( originalPos ); + } + + return name.toString(); + } + + /** + * {@inheritDoc} + */ + @Override + protected void finalize() throws Throwable + { + try + { + dispose(); + } + finally + { + super.finalize(); + } + } + + /** + * Extracts the given entry and writes its data to a given file. + * + * @param aEntry + * the entry to extract; + * @param aFile + * the file to write the entry data to. + * @throws IOException + * in case of I/O problems. + */ + private void extractFile( final AREntry aEntry, final File aFile ) throws IOException + { + final FileWriter fw = new FileWriter( aFile ); + + try + { + extractFile( aEntry, fw ); + } + finally + { + try + { + fw.close(); + } + catch ( final IOException exception ) + { + // Ignore... + } + } + } + + /** + * Extracts the given entry and writes its data to a given file. + * + * @param aEntry + * the entry to extract; + * @param aWriter + * the {@link Writer} to write the entry data to. + * @throws IOException + * in case of I/O problems. + */ + private void extractFile( final AREntry aEntry, final Writer aWriter ) throws IOException + { + try + { + long bytesToRead = aEntry.getSize(); + + while ( bytesToRead > 0 ) + { + final int byteRead = this.efile.read(); + if ( ( byteRead < 0 ) && ( bytesToRead != 0 ) ) + { + throw new IOException( "Invalid AR archive! Premature end of archive?!" ); + } + + aWriter.write( byteRead ); + bytesToRead--; + } + } + finally + { + try + { + aWriter.flush(); + } + catch ( final IOException exception ) + { + // Ignore... + } + } + } + + /** + * Load the entries from the archive (if required). + * + * @return the read entries, never null. + */ + private Collection loadEntries() throws IOException + { + final List headers = new ArrayList(); + + // Check for EOF condition + while ( this.efile.getFilePointer() < this.efile.length() ) + { + final AREntry header = AREntry.create( this, this.efile ); + + if ( !header.isSpecial() ) + { + headers.add( header ); + } + + long pos = this.efile.getFilePointer(); + if ( header.isStringTableSection() ) + { + this.stringTableOffset = pos; + } + + // Compute the location of the next header in the archive. + pos += header.getSize(); + if ( ( pos % 2 ) != 0 ) + { + pos++; + } + + this.efile.seek( pos ); + } + + return headers; + } + + /** + * Searches for a given subject string in a given set of strings. + * + * @param aSet + * the set of strings to search; + * @param aSubject + * the subject to search for. + * @return true if the given subject was found in the given set, + * false otherwise. + */ + private boolean stringInStrings( final String[] aSet, final String aSubject ) + { + for ( final String element : aSet ) + { + if ( aSubject.equals( element ) ) + { + return true; + } + } + return false; + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/ar/AREntry.java b/app/src/main/java/nl/lxtreme/binutils/ar/AREntry.java new file mode 100644 index 00000000..454b7c40 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/ar/AREntry.java @@ -0,0 +1,366 @@ +/******************************************************************************* + * Copyright (c) 2011 - J.W. Janssen + * + * Copyright (c) 2000, 2008 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + * Abeer Bagul (Tensilica) - bug 102434 + * Anton Leherbauer (Wind River Systems) + * J.W. Janssen - Cleanup and some small API changes. + *******************************************************************************/ +package nl.lxtreme.binutils.ar; + + +import java.io.*; + + +/** + * The ARHeader class is used to store the per-object file + * archive headers. It can also create an Elf object for inspecting + * the object file data. + */ +public class AREntry +{ + // CONSTANTS + + private static final int NAME_IDX = 0; + private static final int NAME_LEN = 16; + private static final int MTIME_IDX = 16; + private static final int MTIME_LEN = 12; + private static final int UID_IDX = 28; + private static final int UID_LEN = 6; + private static final int GID_IDX = 34; + private static final int GID_LEN = 6; + private static final int MODE_IDX = 40; + private static final int MODE_LEN = 8; + private static final int SIZE_IDX = 48; + private static final int SIZE_LEN = 10; + private static final int MAGIC_IDX = 58; + @SuppressWarnings("unused") + private static final int MAGIC_LEN = 2; + private static final int HEADER_LEN = 60; + + // VARIABLES + + private String fileName; + private long fileOffset; + private long modificationTime; + private int uid; + private int gid; + private int mode; + private long size; + + // CONSTRUCTORS + + /** + * Creates a new archive header object. + */ + private AREntry() + { + super(); + } + + // METHODS + + /** + * Factory method to create a {@link AREntry} for the given {@link AR} + * archive. + * + * @param aArchive + * the archive to read the header for; + * @param aFile + * the file of the archive to read the header from. + * @return the newly read header, never null. + * @throws IOException + * in case of I/O problems. + */ + static AREntry create(final AR aArchive, final RandomAccessFile aFile) throws IOException + { + final AREntry result = new AREntry(); + + byte[] buf = new byte[HEADER_LEN]; + + // Read in the archive header data. Fixed sizes. + aFile.readFully(buf); + + // Save this location so we can create the Elf object later. + result.fileOffset = aFile.getFilePointer(); + + // Convert the raw bytes into strings and numbers. + result.fileName = new String(buf, NAME_IDX, NAME_LEN).trim(); + result.size = Long.parseLong(new String(buf, SIZE_IDX, SIZE_LEN).trim()); + + if (!result.isSpecial()) + { + result.modificationTime = Long.parseLong(new String(buf, MTIME_IDX, MTIME_LEN).trim()); + result.uid = Integer.parseInt(new String(buf, UID_IDX, UID_LEN).trim()); + result.gid = Integer.parseInt(new String(buf, GID_IDX, GID_LEN).trim()); + result.mode = Integer.parseInt(new String(buf, MODE_IDX, MODE_LEN).trim(), 8); + + if ((buf[MAGIC_IDX] != 0x60) && (buf[MAGIC_IDX + 1] != 0x0A)) + { + throw new IOException("Not a valid AR archive! No file header magic found."); + } + } + + // If the name is something like "#1/", then we're dealing with a BSD + // ar file. The is the actual file name length, and the file name + // itself is available directly after the header... + if (result.isBSDArExtendedFileName()) + { + try + { + final int fileNameLength = Integer.parseInt(result.fileName.substring(3)); + if (fileNameLength > 0) + { + buf = new byte[fileNameLength]; + aFile.readFully(buf); + + result.fileName = new String(buf).trim(); + } + } + catch (final NumberFormatException exception) + { + throw new IOException("Invalid AR archive! (BSD) Extended filename invalid?!"); + } + } + + // If the name is of the format "/", we're dealing with a GNU ar + // file and we should get name from the string table... + if (result.isGNUArExtendedFileName()) + { + try + { + final long offset = Long.parseLong(result.fileName.substring(1)); + result.fileName = aArchive.nameFromStringTable(offset); + } + catch (final NumberFormatException exception) + { + throw new IOException("Invalid AR archive! (GNU) Extended filename invalid?!"); + } + } + + // Strip the trailing / from the object name. + final int len = result.fileName.length(); + if ((len > 2) && (result.fileName.charAt(len - 1) == '/')) + { + result.fileName = result.fileName.substring(0, len - 1); + } + + return result; + } + + /** + * Determines whether the given byte array contains the global AR header, + * consisting of the string "!". + * + * @param aIdent + * the byte array with the possible AR header. + * @return true if the given byte array contains the AR header, + * false otherwise. + */ + static boolean isARHeader(final byte[] aIdent) + { + if ((aIdent.length < 7) + || (aIdent[0] != '!') + || (aIdent[1] != '<') + || (aIdent[2] != 'a') + || (aIdent[3] != 'r') + || (aIdent[4] != 'c') + || (aIdent[5] != 'h') + || (aIdent[6] != '>')) + { + return false; + } + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object aObject) + { + if (this == aObject) + { + return true; + } + if ((aObject == null) || (getClass() != aObject.getClass())) + { + return false; + } + + final AREntry other = (AREntry) aObject; + if (this.fileName == null) + { + if (other.fileName != null) + { + return false; + } + } + else if (!this.fileName.equals(other.fileName)) + { + return false; + } + if (this.fileOffset != other.fileOffset) + { + return false; + } + if (this.gid != other.gid) + { + return false; + } + if (this.mode != other.mode) + { + return false; + } + if (this.modificationTime != other.modificationTime) + { + return false; + } + if (this.size != other.size) + { + return false; + } + if (this.uid != other.uid) + { + return false; + } + return true; + } + + /** + * Returns UNIX file mode, containing the permissions of the file. + * + * @return the mode, should be interpreted as octal value. + */ + public int getFileMode() + { + return this.mode; + } + + /** + * Get the name of the object file + */ + public String getFileName() + { + return this.fileName; + } + + /** + * Returns the group ID of the file. + * + * @return the group ID, as integer value, >= 0. + */ + public int getGID() + { + return this.gid; + } + + /** + * Returns the timestamp of the file. + * + * @return the timestamp, as epoch time. + */ + public long getModificationTime() + { + return this.modificationTime; + } + + /** + * Get the size of the object file . + */ + public long getSize() + { + return this.size; + } + + /** + * Returns the user ID of the file. + * + * @return the user ID, as integer value, >= 0. + */ + public int getUID() + { + return this.uid; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + (int) (this.modificationTime ^ (this.modificationTime >>> 32)); + result = prime * result + ((this.fileName == null) ? 0 : this.fileName.hashCode()); + result = prime * result + (int) (this.fileOffset ^ (this.fileOffset >>> 32)); + result = prime * result + (int) (this.size ^ (this.size >>> 32)); + result = prime * result + this.gid; + result = prime * result + this.mode; + result = prime * result + this.uid; + return result; + } + + /** + * Returns whether this header represents a special file. + * + * @return true if this header represents a special file, + * false otherwise. + */ + public boolean isSpecial() + { + return this.fileName.charAt(0) == '/'; + } + + /** + * Returns whether this header represents the string table section. + * + * @return true if this header represents a string table section, + * false otherwise. + */ + public boolean isStringTableSection() + { + return this.fileName.equals("//"); + } + + /** + * Returns the file offset in the complete binary. + * + * @return a file offset (in bytes), >= 0. + */ + final long getFileOffset() + { + return this.fileOffset; + } + + /** + * Returns whether this header is created by BSD ar, and represents an + * extended filename. + * + * @return true if this header is an extended filename created by + * BSD ar, false otherwise. + */ + final boolean isBSDArExtendedFileName() + { + return this.fileName.matches("^#1/\\d+$"); + } + + /** + * Returns whether this header is created by GNU ar, and represents an + * extended filename. + * + * @return true if this header is an extended filename created by + * GNU ar, false otherwise. + */ + final boolean isGNUArExtendedFileName() + { + return this.fileName.matches("^/\\d+$"); + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/coff/Coff.java b/app/src/main/java/nl/lxtreme/binutils/coff/Coff.java new file mode 100644 index 00000000..87a61ed5 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/coff/Coff.java @@ -0,0 +1,239 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.coff; + + +import java.io.*; +import java.nio.*; +import java.nio.channels.*; +//import java.nio.file.*; + + +/** + * Represents a COFF file. + *

+ * This class is not thread-safe! + *

+ */ +public class Coff implements Closeable +{ + public final FileHeader fileHeader; + public final OptionalHeader optHeader; + public final SectionHeader[] sectionHeaders; + public final Symbol[] symbols; + + private FileChannel channel; + + public Coff( File file ) throws IOException + { + this((new RandomAccessFile(file.getAbsolutePath(), "r").getChannel()));/* FileChannel.open( file.toPath(), StandardOpenOption.READ */ + } + + public Coff( FileChannel channel ) throws IOException + { + this.channel = channel; + this.fileHeader = new FileHeader( channel ); + + ByteBuffer buf = ByteBuffer.allocate( Math.max( 40, fileHeader.optionalHeaderSize ) ); + buf.limit( fileHeader.optionalHeaderSize ); + buf.order( fileHeader.getByteOrder() ); + readFully( channel, buf, "Unable to read optional header!" ); + + this.optHeader = new OptionalHeader( buf ); + + buf.clear(); + buf.limit( 40 ); + + this.sectionHeaders = new SectionHeader[fileHeader.sectionCount]; + for ( int i = 0; i < sectionHeaders.length; i++ ) + { + readFully( channel, buf, "Unable to read section header #" + ( i + 1 ) ); + + sectionHeaders[i] = new SectionHeader( buf ); + } + + byte[] stringTable = new byte[0]; + + long stringPos = fileHeader.symbolFilePtr + ( fileHeader.symbolCount * 18 ); + if ( stringPos > 0 && stringPos < channel.size() ) + { + channel.position( stringPos ); + + buf.clear(); + buf.limit( 4 ); + readFully( channel, buf, "Unable to read string table size!" ); + + int size = buf.getInt(); + + ByteBuffer stringBuf = ByteBuffer.allocate( size ); + readFully( channel, stringBuf, "Unable to read string table!" ); + + stringTable = stringBuf.array(); + } + + buf.clear(); + buf.limit( 18 ); + + this.symbols = new Symbol[fileHeader.symbolCount]; + for ( int i = 0; i < symbols.length; i++ ) + { + readFully( channel, buf, "Unable to read symbol #" + ( i + 1 ) ); + + symbols[i] = new Symbol( buf, stringTable ); + } + } + + static void readFully( ReadableByteChannel ch, ByteBuffer buf, String errMsg ) throws IOException + { + buf.rewind(); + int read = ch.read( buf ); + if ( read != buf.limit() ) + { + throw new IOException( errMsg + " Read only " + read + " of " + buf.limit() + " bytes!" ); + } + buf.flip(); + } + + static String getZString( byte[] buf, int offset ) + { + int end = offset; + while ( end < buf.length && buf[end] != 0 ) + { + end++; + } + return new String( buf, offset, ( end - offset ) ); + } + + @Override + public void close() throws IOException + { + if ( channel != null ) + { + channel.close(); + channel = null; + } + } + + /** + * Returns the line number information for the given section. The section + * should represent a ".text" or other code section. + * + * @return an array of line number information, or an empty array if no such + * information is present. + */ + public LineNumber[] getLineNumbers( SectionHeader shdr ) throws IOException + { + if ( shdr == null ) + { + throw new IllegalArgumentException( "Header cannot be null!" ); + } + if ( channel == null ) + { + throw new IOException( "ELF file is already closed!" ); + } + if ( shdr.lineNumberOffset == 0 || shdr.lineNumberSize == 0 ) + { + // Nothing to do... + return new LineNumber[0]; + } + + ByteBuffer buf = ByteBuffer.allocate( 10 ); + buf.order( fileHeader.getByteOrder() ); + + channel.position( shdr.lineNumberOffset ); + + LineNumber[] result = new LineNumber[shdr.lineNumberSize]; + for ( int i = 0; i < result.length; i++ ) + { + readFully( channel, buf, "Unable to read line number information!" ); + + result[i] = new LineNumber( buf ); + } + + return result; + } + + /** + * Returns the relocation information for the given section. The section + * should represent a ".text" or other code section. + * + * @return an array of relocation information, or an empty array if no such + * information is present. + */ + public RelocationInfo[] getRelocationInfo( SectionHeader shdr ) throws IOException + { + if ( shdr == null ) + { + throw new IllegalArgumentException( "Header cannot be null!" ); + } + if ( channel == null ) + { + throw new IOException( "ELF file is already closed!" ); + } + if ( shdr.relocTableOffset == 0 || shdr.relocTableSize == 0 ) + { + // Nothing to do... + return new RelocationInfo[0]; + } + + ByteBuffer buf = ByteBuffer.allocate( 10 ); + buf.order( fileHeader.getByteOrder() ); + + channel.position( shdr.relocTableOffset ); + + RelocationInfo[] result = new RelocationInfo[shdr.relocTableSize]; + for ( int i = 0; i < result.length; i++ ) + { + readFully( channel, buf, "Unable to read relocation information!" ); + + result[i] = new RelocationInfo( buf ); + } + + return result; + } + + /** + * Returns the actual section data (= executable code + initialized data) for + * the given section header. + * + * @return a byte buffer from which the data can be read, never + * null. + */ + public ByteBuffer getSectionData( SectionHeader shdr ) throws IOException + { + if ( shdr == null ) + { + throw new IllegalArgumentException( "Header cannot be null!" ); + } + if ( channel == null ) + { + throw new IOException( "ELF file is already closed!" ); + } + + ByteBuffer buf = ByteBuffer.allocate( ( int )shdr.size ); + buf.order( fileHeader.getByteOrder() ); + + channel.position( shdr.dataOffset ); + readFully( channel, buf, "Unable to read section completely!" ); + + return buf; + } + + @Override + public String toString() + { + StringBuilder sb = new StringBuilder( "COFF " ); + sb.append( fileHeader ).append( "; " ); + sb.append( optHeader ).append( "\n" ); + for ( int i = 0; i < sectionHeaders.length; i++ ) + { + sb.append( "\t" ).append( sectionHeaders[i] ).append( "\n" ); + } + return sb.toString(); + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/coff/CoffMagic.java b/app/src/main/java/nl/lxtreme/binutils/coff/CoffMagic.java new file mode 100644 index 00000000..1917115a --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/coff/CoffMagic.java @@ -0,0 +1,49 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.coff; + + +/** + * Identifies the state of the image file. + */ +public enum CoffMagic +{ + /** */ + STMAGIC( 0401 ), + /** */ + OMAGIC( 0404 ), + /** */ + JMAGIC( 0407 ), + /** */ + DMAGIC( 0410 ), + /** Also PE32 */ + ZMAGIC( 0413 ), + /** */ + SHMAGIC( 0443 ), + /** PE32+ */ + PE32_PLUS( 01013 ); + + private final int no; + + private CoffMagic( int no ) + { + this.no = no; + } + + public static CoffMagic valueOf( int no ) + { + for ( CoffMagic entry : values() ) + { + if ( entry.no == no ) + { + return entry; + } + } + throw new IllegalArgumentException( "Invalid CoffMagic: 0" + Integer.toOctalString( no ) ); + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/coff/FileHeader.java b/app/src/main/java/nl/lxtreme/binutils/coff/FileHeader.java new file mode 100644 index 00000000..a6c0fe6b --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/coff/FileHeader.java @@ -0,0 +1,120 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.coff; + + +import static nl.lxtreme.binutils.coff.Coff.*; + +import java.io.*; +import java.nio.*; +import java.nio.channels.*; + + +/** + * Represents a COFF file header. + */ +public class FileHeader +{ + // relocation info stripped from file + public static final int F_RELFLG = 0x0001; + // file is executable (no unresolved external references) + public static final int F_EXEC = 0x0002; + // line numbers stripped from file + public static final int F_LNNO = 0x0004; + // local symbols stripped from file + public static final int F_LSYMS = 0x0008; + // Aggressively trim working set + public static final int F_AGGRESSIVE_WS_TRIM = 0x0010; + // App can handle >2GB addresses. + public static final int F_LARGE_ADDRESS_AWARE = 0x0020; + // Use of this flag is reserved for future use. + public static final int F_FILE_16BIT_MACHINE = 0x0040; + // file is 16-bit little-endian + public static final int F_AR16WR = 0x0080; + // file is 32-bit little-endian + public static final int F_AR32WR = 0x0100; + // file is 32-bit big-endian or debug information stripped. + public static final int F_AR32W = 0x0200; + // If image is on removable media, copy and run from swap file. + public static final int F_REMOVABLE_RUN_FROM_SWAP = 0x0400; + // rs/6000 aix: dynamically loadable w/imports & exports + public static final int F_DYNLOAD = 0x1000; + // rs/6000 aix: file is a shared object or PE format DLL. + public static final int F_SHROBJ = 0x2000; + // File should be run only on a UP machine. + public static final int F_UP_SYSTEM_ONLY = 0x4000; + // Big endian: MSB precedes LSB in memory. + public static final int F_AR32BE = 0x8000; + + public final MachineType machineType; + public final int sectionCount; + public final long timestamp; + public final long symbolFilePtr; + public final int symbolCount; + public final int optionalHeaderSize; + public final int flags; + + public FileHeader( FileChannel channel ) throws IOException + { + final ByteBuffer buf = ByteBuffer.allocate( 20 ); + + buf.order( ByteOrder.LITTLE_ENDIAN ); + readFully( channel, buf, "Unable to read file header!" ); + + machineType = MachineType.valueOf( buf.getShort() ); + sectionCount = buf.getShort(); + timestamp = buf.getInt(); + symbolFilePtr = buf.getInt(); + symbolCount = buf.getInt(); + optionalHeaderSize = buf.getShort(); + flags = buf.getShort(); + } + + /** + * @return true if the COFF file is stripped and has no symbols, + * false otherwise. + */ + public boolean isStripped() + { + return symbolFilePtr == 0 && symbolCount == 0; + } + + @Override + public String toString() + { + StringBuilder sb = new StringBuilder(); + sb.append( machineType ); + if ( timestamp != 0 ) + { + sb.append( "created at " ).append( timestamp ); + } + if ( isStripped() ) + { + sb.append( " (stripped)" ); + } + else + { + sb.append( " (" ).append( symbolCount ).append( " symbols)" ); + } + if ( flags != 0 ) + { + sb.append( " flags = 0x" ).append( Integer.toHexString( flags ) ); + } + return sb.toString(); + } + + public ByteOrder getByteOrder() + { + ByteOrder result = ByteOrder.LITTLE_ENDIAN; + if ( ( flags & F_AR32BE ) != 0 || ( flags & F_AR32W ) != 0 ) + { + result = ByteOrder.BIG_ENDIAN; + } + return result; + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/coff/LineNumber.java b/app/src/main/java/nl/lxtreme/binutils/coff/LineNumber.java new file mode 100644 index 00000000..1bc3cea6 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/coff/LineNumber.java @@ -0,0 +1,35 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.coff; + + +import java.io.*; +import java.nio.*; + + +public class LineNumber +{ + public final int lineNumber; + public final int type; + + public LineNumber( ByteBuffer buf ) throws IOException + { + type = buf.getInt(); + lineNumber = buf.getShort(); + } + + public boolean isSymbolIndex() + { + return lineNumber == 0; + } + + public boolean isVirtualAddress() + { + return lineNumber != 0; + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/coff/MachineType.java b/app/src/main/java/nl/lxtreme/binutils/coff/MachineType.java new file mode 100644 index 00000000..df632562 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/coff/MachineType.java @@ -0,0 +1,74 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.coff; + + +public enum MachineType +{ + /** */ + UNKNOWN( 0, "Unknown" ), + /** */ + ALPHA( 0x184, "Alpha AXP" ), + /** */ + ARM( 0x1c0, "ARM" ), + /** */ + ALPHA64( 0x284, "Alpha AXP-64" ), + /** */ + I386( 0x14c, "i386 compatible" ), + /** */ + IA64( 0x200, "Intel IA64" ), + /** */ + M68K( 0x268, "m68k" ), + /** */ + MIPS16( 0x266, "MIPS-16" ), + /** */ + MIPS_FPU( 0x366, "MIPS with FPU" ), + /** */ + MIPS_FPU16( 0x466, "MIPS-16 with FPU" ), + /** */ + POWERPC( 0x1f0, "PowerPC little-endian" ), + /** */ + R3000( 0x162, "MIPS R3000 little-endian" ), + /** */ + R4000( 0x166, "MIPS R4000 little-endian" ), + /** */ + R10000( 0x168, "MIPS R10000 little-endian" ), + /** */ + SH3( 0x1a2, "Hitachi SH3" ), + /** */ + SH4( 0x1a6, "Hitachi SH4" ), + /** */ + THUMB( 0x1c2, "ARM thumb" ); + + private final int no; + private final String desc; + + private MachineType( int no, String desc ) + { + this.no = no; + this.desc = desc; + } + + static MachineType valueOf( int value ) + { + for ( MachineType mt : values() ) + { + if ( mt.no == value ) + { + return mt; + } + } + throw new IllegalArgumentException( "Invalid machine type: " + value ); + } + + @Override + public String toString() + { + return desc; + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/coff/OptionalHeader.java b/app/src/main/java/nl/lxtreme/binutils/coff/OptionalHeader.java new file mode 100644 index 00000000..d66d67ce --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/coff/OptionalHeader.java @@ -0,0 +1,60 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.coff; + + +import java.io.*; +import java.nio.*; + + +/** + * Represents the a.out/optional header in a COFF file. + */ +public class OptionalHeader +{ + public final CoffMagic magic; + public final int versionStamp; + public final int textSize; + public final int initDataSize; + public final int uninitDataSize; + public final int entryPoint; + public final int textStart; + public final int dataStart; + + public OptionalHeader( ByteBuffer buf ) throws IOException + { + magic = CoffMagic.valueOf( buf.getShort() ); + versionStamp = buf.getShort(); + textSize = buf.getInt(); + initDataSize = buf.getInt(); + uninitDataSize = buf.getInt(); + entryPoint = buf.getInt(); + textStart = buf.getInt(); + if ( buf.hasRemaining() ) + { + dataStart = buf.getInt(); + } + else + { + dataStart = -1; + } + } + + @Override + public String toString() + { + StringBuilder sb = new StringBuilder(); + sb.append( magic ); + sb.append( ", entry point: 0x" ).append( Integer.toHexString( entryPoint ) ); + sb.append( ", code start: 0x" ).append( Integer.toHexString( textStart ) ); + sb.append( ", code size: " ).append( textSize ); + sb.append( ", data start: 0x" ).append( Integer.toHexString( dataStart ) ); + sb.append( ", data size: " ).append( initDataSize ).append( "+" ).append( uninitDataSize ); + return sb.toString(); + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/coff/RelocationInfo.java b/app/src/main/java/nl/lxtreme/binutils/coff/RelocationInfo.java new file mode 100644 index 00000000..d614cf4d --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/coff/RelocationInfo.java @@ -0,0 +1,37 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.coff; + + +import java.io.*; +import java.nio.*; + + +public class RelocationInfo +{ + public final int virtualAddress; + public final int symbolIndex; + public final int type; + + public RelocationInfo( ByteBuffer buf ) throws IOException + { + virtualAddress = buf.getInt(); + symbolIndex = buf.getInt(); + type = buf.getShort(); + } + + @Override + public String toString() + { + StringBuilder sb = new StringBuilder(); + sb.append( "virtualAddress = 0x" ).append( Integer.toHexString( virtualAddress ) ); + sb.append( ", symbolIndex = " ).append( symbolIndex ); + sb.append( ", type = " ).append( type ); + return sb.toString(); + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/coff/SectionHeader.java b/app/src/main/java/nl/lxtreme/binutils/coff/SectionHeader.java new file mode 100644 index 00000000..9f0803b6 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/coff/SectionHeader.java @@ -0,0 +1,77 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.coff; + + +import java.io.*; +import java.nio.*; + + +public class SectionHeader +{ + public static final int FLAG_REG = 0x00; // regular segment + public static final int FLAG_DSECT = 0x01; // dummy segment + public static final int FLAG_NOLOAD = 0x02; // no-load segment + public static final int FLAG_GROUP = 0x04; // group segment + public static final int FLAG_PAD = 0x08; // .pad segment + public static final int FLAG_COPY = 0x10; // copy section + public static final int FLAG_TEXT = 0x20; // .text segment (= executable code) + public static final int FLAG_DATA = 0x40; // .data segment (= initialized + // data) + public static final int FLAG_BSS = 0x80; // .bss segment (= uninitialized + // data) + public static final int FLAG_INFO = 0x200; // .comment section + public static final int FLAG_OVER = 0x400; // overlay section + public static final int FLAG_LIB = 0x800; // library section + + public final SectionType type; + public final int physicalAddress; + public final int virtualAddress; + public final int size; + public final int dataOffset; + public final int relocTableOffset; + public final int relocTableSize; + public final int lineNumberOffset; + public final int lineNumberSize; + public final int flags; + + public SectionHeader( ByteBuffer buf ) throws IOException + { + byte[] nameBytes = new byte[8]; + buf.get( nameBytes ); + + type = SectionType.valueOf( nameBytes ); + physicalAddress = buf.getInt(); + virtualAddress = buf.getInt(); + size = buf.getInt(); + dataOffset = buf.getInt(); + relocTableOffset = buf.getInt(); + lineNumberOffset = buf.getInt(); + relocTableSize = buf.getShort(); + lineNumberSize = buf.getShort(); + flags = buf.getInt(); + } + + @Override + public String toString() + { + StringBuilder sb = new StringBuilder(); + sb.append( type ); + sb.append( ", size = " ).append( size ); + if ( physicalAddress != virtualAddress ) + { + sb.append( ", address (p/v) = 0x" ).append( Integer.toHexString( physicalAddress ) ).append( "/0x" ).append( Integer.toHexString( virtualAddress ) ); + } + else + { + sb.append( ", address = 0x" ).append( Integer.toHexString( physicalAddress ) ); + } + sb.append( ", flags = " ).append( flags ); + return sb.toString(); + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/coff/SectionType.java b/app/src/main/java/nl/lxtreme/binutils/coff/SectionType.java new file mode 100644 index 00000000..cecb6737 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/coff/SectionType.java @@ -0,0 +1,53 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.coff; + + +/** + * Represents the name/type of a section in a COFF file. + */ +public class SectionType +{ + public final static SectionType TEXT = new SectionType( ".text" ); + public final static SectionType INIT = new SectionType( ".init" ); + public final static SectionType FINI = new SectionType( ".fini" ); + public final static SectionType RCONST = new SectionType( ".rconst" ); + public final static SectionType RDATA = new SectionType( ".rdata" ); + public final static SectionType DATA = new SectionType( ".data" ); + public final static SectionType BSS = new SectionType( ".bss" ); + public final static SectionType COMMENT = new SectionType( ".comment" ); + public final static SectionType LIB = new SectionType( ".lib" ); + + private static final SectionType[] VALUES = { TEXT, INIT, FINI, RCONST, RDATA, DATA, BSS, COMMENT, LIB }; + + private final String name; + + public SectionType( String name ) + { + this.name = name; + } + + public static SectionType valueOf( byte[] name ) + { + String _name = new String( name ); + for ( SectionType value : VALUES ) + { + if ( _name.equals( value.name ) ) + { + return value; + } + } + return new SectionType( _name ); + } + + @Override + public String toString() + { + return name; + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/coff/Symbol.java b/app/src/main/java/nl/lxtreme/binutils/coff/Symbol.java new file mode 100644 index 00000000..55ecb77e --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/coff/Symbol.java @@ -0,0 +1,83 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.coff; + + +import static nl.lxtreme.binutils.coff.Coff.*; +import java.io.*; +import java.nio.*; + + +public class Symbol +{ + public static final int DEBUG = 2; + public static final int ABSOLUTE = 1; + public static final int NONE = 0; + + public final String name; + public final int value; + public final int sectionNumber; + public final int type; + public final int storageClass; + public final int auxCount; + + public Symbol( ByteBuffer buf, byte[] stringTable ) throws IOException + { + byte[] nameBuf = new byte[8]; + buf.get( nameBuf ); + + if ( nameBuf[0] == 0 && nameBuf[1] == 0 && nameBuf[2] == 0 && nameBuf[3] == 0 ) + { + // Long name (> 8 characters)... + int offset = ( ( ( nameBuf[7] & 0xff ) << 24 ) | ( ( nameBuf[6] & 0xff ) << 16 ) | ( ( nameBuf[5] & 0xff ) << 8 ) + | ( nameBuf[4] & 0xff ) ) - 4; + if ( offset > 0 && offset < stringTable.length ) + { + name = getZString( stringTable, offset ); + } + else + { + name = ""; + } + } + else + { + name = new String( nameBuf ); + } + + value = buf.getInt(); + sectionNumber = buf.getShort(); + type = buf.getShort(); + storageClass = buf.get(); + auxCount = buf.getInt(); + } + + public boolean isAbsoluteSymbol() + { + return sectionNumber == ABSOLUTE; + } + + public boolean isDebugSymbol() + { + return sectionNumber == DEBUG; + } + + public boolean isExternal() + { + return sectionNumber == NONE; + } + + @Override + public String toString() + { + StringBuilder sb = new StringBuilder(); + sb.append( name ); + sb.append( ", value = 0x" ).append( Integer.toHexString( value ) ); + return sb.toString(); + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/elf/AbiType.java b/app/src/main/java/nl/lxtreme/binutils/elf/AbiType.java new file mode 100644 index 00000000..263019e4 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/elf/AbiType.java @@ -0,0 +1,50 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.elf; + +/** + * Represent the various types of ABIs that exist (extracted from "elf.h" file from libc6-dev package). + */ +public enum AbiType { + SYSV(0, "UNIX System V ABI"), + HPUX(1, "HP-UX"), + NETBSD(2, "NetBSD."), + GNU(3, "Object uses GNU ELF extensions."), + SOLARIS(6, "Sun Solaris."), + AIX(7, "IBM AIX."), + IRIX(8, "SGI Irix."), + FREEBSD(9, "FreeBSD."), + TRU64(10, "Compaq TRU64 UNIX."), + MODESTO(11, "Novell Modesto."), + OPENBSD(12, "OpenBSD."), + ARM_AEABI(64, "ARM EABI"), + ARM(97, "ARM"), + STANDALONE(255, "Standalone (embedded) application"); + + private final int no; + private final String desc; + + private AbiType(int no, String desc) { + this.no = no; + this.desc = desc; + } + + static AbiType valueOf(int value) { + for (AbiType at : values()) { + if (at.no == value) { + return at; + } + } + throw new IllegalArgumentException("Invalid ABI type: " + value); + } + + @Override + public String toString() { + return desc; + } +} \ No newline at end of file diff --git a/app/src/main/java/nl/lxtreme/binutils/elf/DynamicEntry.java b/app/src/main/java/nl/lxtreme/binutils/elf/DynamicEntry.java new file mode 100644 index 00000000..c2d2f476 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/elf/DynamicEntry.java @@ -0,0 +1,203 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.elf; + +/** + * Represents an entry in the dynamic table. + */ +public class DynamicEntry { + + public static class Tag { + public static final Tag NULL = new Tag(0, "Marks end of dynamic section"); + public static final Tag NEEDED = new Tag(1, "Name of needed library", true /* strTableOffset */); + public static final Tag PLTRELSZ = new Tag(2, "Size in bytes of PLT relocs"); + public static final Tag PLTGOT = new Tag(3, "Processor defined value"); + public static final Tag HASH = new Tag(4, "Address of symbol hash table"); + public static final Tag STRTAB = new Tag(5, "Address of string table"); + public static final Tag SYMTAB = new Tag(6, "Address of symbol table"); + public static final Tag RELA = new Tag(7, "Address of Rela relocs"); + public static final Tag RELASZ = new Tag(8, "Total size of Rela relocs"); + public static final Tag RELAENT = new Tag(9, "Size of one Rela reloc"); + public static final Tag STRSZ = new Tag(10, "Size of string table"); + public static final Tag SYMENT = new Tag(11, "Size of one symbol table entry"); + public static final Tag INIT = new Tag(12, "Address of init function"); + public static final Tag FINI = new Tag(13, "Address of termination function"); + public static final Tag SONAME = new Tag(14, "Name of shared object", true /* strTableOffset */); + public static final Tag RPATH = new Tag(15, "Library search path (deprecated)", true /* strTableOffset */); + public static final Tag SYMBOLIC = new Tag(16, "Start symbol search here"); + public static final Tag REL = new Tag(17, "Address of Rel relocs"); + public static final Tag RELSZ = new Tag(18, "Total size of Rel relocs"); + public static final Tag RELENT = new Tag(19, "Size of one Rel reloc"); + public static final Tag PLTREL = new Tag(20, "Type of reloc in PLT"); + public static final Tag DEBUG = new Tag(21, "For debugging; unspecified"); + public static final Tag TEXTREL = new Tag(22, "Reloc might modify .text"); + public static final Tag JMPREL = new Tag(23, "Address of PLT relocs"); + public static final Tag BIND_NOW = new Tag(24, "Process relocations of object"); + public static final Tag INIT_ARRAY = new Tag(25, "Array with addresses of init fct"); + public static final Tag FINI_ARRAY = new Tag(26, "Array with addresses of fini fct"); + public static final Tag INIT_ARRAYSZ = new Tag(27, "Size in bytes of DT_INIT_ARRAY"); + public static final Tag FINI_ARRAYSZ = new Tag(28, "Size in bytes of DT_FINI_ARRAY"); + public static final Tag RUNPATH = new Tag(29, "Library search path"); + public static final Tag FLAGS = new Tag(30, "Flags for the object being loaded"); + public static final Tag ENCODING = new Tag(32, "Start of encoded range"); + public static final Tag PREINIT_ARRAY = new Tag(32, "Array with addresses of preinit fct"); + public static final Tag PREINIT_ARRAYSZ = new Tag(33, "size in bytes of DT_PREINIT_ARRAY"); + + public static final Tag GNU_PRELINKED = new Tag(0x6ffffdf5, "Prelinking timestamp"); + public static final Tag GNU_CONFLICTSZ = new Tag(0x6ffffdf6, "Size of conflict section"); + public static final Tag GNU_LIBLISTSZ = new Tag(0x6ffffdf7, "Size of library list"); + public static final Tag CHECKSUM = new Tag(0x6ffffdf8, "CHECKSUM"); + public static final Tag PLTPADSZ = new Tag(0x6ffffdf9, "DT_PLTPADSZ"); + public static final Tag MOVEENT = new Tag(0x6ffffdfa, "DT_MOVEENT"); + public static final Tag MOVESZ = new Tag(0x6ffffdfb, "DT_MOVESZ"); + public static final Tag FEATURE_1 = new Tag(0x6ffffdfc, "DT_FEATURE_1"); + public static final Tag POSFLAG_1 = new Tag(0x6ffffdfd, "DT_POSFLAG_1"); + public static final Tag SYMINSZ = new Tag(0x6ffffdfe, "DT_SYMINSZ"); + + public static final Tag GNU_HASH = new Tag(0x6ffffef5, "GNU-style hash table"); + public static final Tag TLSDESC_PLT = new Tag(0x6ffffef6, "DT_TLSDESC_PLT"); + public static final Tag TLSDESC_GOT = new Tag(0x6ffffef7, "DT_TLSDESC_GOT"); + public static final Tag GNU_CONFLICT = new Tag(0x6ffffef8, "Start of conflict section"); + public static final Tag GNU_LIBLIST = new Tag(0x6ffffef9, "Library list"); + public static final Tag CONFIG = new Tag(0x6ffffefa, "Configuration information"); + public static final Tag DEPAUDIT = new Tag(0x6ffffefb, "Dependency auditing"); + public static final Tag AUDIT = new Tag(0x6ffffefc, "Object auditing."); + public static final Tag PLTPAD = new Tag(0x6ffffefd, "PLT padding"); + public static final Tag MOVETAB = new Tag(0x6ffffefe, "Move table"); + public static final Tag SYMINFO = new Tag(0x6ffffeff, "Syminfo table"); + + public static final Tag VERSYM = new Tag(0x6ffffff0, "DT_VERSYM"); + public static final Tag RELACOUNT = new Tag(0x6ffffff9, "DT_RELACOUNT"); + public static final Tag RELCOUNT = new Tag(0x6ffffffa, "DT_RELCOUNT"); + public static final Tag FLAGS_1 = new Tag(0x6ffffffb, "State flags"); + public static final Tag VERDEF = new Tag(0x6ffffffc, "Address of version definition table"); + public static final Tag VERDEFNUM = new Tag(0x6ffffffd, "Number of version definitions"); + public static final Tag VERNEED = new Tag(0x6ffffffe, "Address of table with needed versions"); + public static final Tag VERNEEDNUM = new Tag(0x6fffffff, "Number of needed versions"); + + private static final Tag[] VALUES = + { NULL, NEEDED, PLTRELSZ, PLTGOT, HASH, STRTAB, SYMTAB, RELA, RELASZ, RELAENT, STRSZ, SYMENT, INIT, FINI, + SONAME, RPATH, SYMBOLIC, REL, RELSZ, RELENT, PLTREL, DEBUG, TEXTREL, JMPREL, BIND_NOW, INIT_ARRAY, + FINI_ARRAY, INIT_ARRAYSZ, FINI_ARRAYSZ, RUNPATH, FLAGS, ENCODING, PREINIT_ARRAY, PREINIT_ARRAYSZ, + GNU_PRELINKED, GNU_CONFLICTSZ, GNU_LIBLISTSZ, CHECKSUM, PLTPADSZ, MOVEENT, MOVESZ, FEATURE_1, POSFLAG_1, + SYMINSZ, GNU_HASH, TLSDESC_PLT, TLSDESC_GOT, GNU_CONFLICT, GNU_LIBLIST, CONFIG, DEPAUDIT, AUDIT, PLTPAD, + MOVETAB, SYMINFO, VERSYM, RELACOUNT, RELCOUNT, FLAGS_1, VERDEF, VERDEFNUM, VERNEED, VERNEEDNUM }; + + private static final int DT_LOOS = 0x6000000d; + private static final int DT_HIOS = 0x6fffffff; + private static final int DT_LOPROC = 0x70000000; + private static final int DT_HIPROC = 0x7fffffff; + + public static Tag valueOf(int value) { + for (Tag t : VALUES) { + if (t.no == value) { + return t; + } + } + if (value >= DT_LOOS && value <= DT_HIOS) { + return new Tag(value, "OS-specific tag"); + } else if (value >= DT_LOPROC && value <= DT_HIPROC) { + return new Tag(value, "Processor-specific tag"); + } else { + throw new IllegalArgumentException("Invalid/unknown tag: " + Integer.toHexString(value)); + } + } + + private final int no; + private final String desc; + private final boolean strTableOffset; + + private Tag(int no, String desc) { + this(no, desc, false); + } + + private Tag(int no, String desc, boolean strTableOffset) { + this.no = no; + this.desc = desc; + this.strTableOffset = strTableOffset; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + + Tag other = (Tag) obj; + return (no == other.no); + } + + @Override + public int hashCode() { + return 37 + no; + } + + public String name() { + return desc; + } + + public int ordinal() { + return no; + } + + @Override + public String toString() { + return desc; + } + } + + private final Tag tag; + private final long value; + + public DynamicEntry(Tag tag, long value) { + this.tag = tag; + this.value = value; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + + DynamicEntry other = (DynamicEntry) obj; + return (tag == other.tag) && (value == other.value); + } + + public Tag getTag() { + return tag; + } + + public long getValue() { + return value; + } + + public boolean isStringOffset() { + return tag.strTableOffset; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + tag.hashCode(); + result = prime * result + (int) (value ^ (value >>> 32)); + return result; + } + + @Override + public String toString() { + return String.format("%s[%x]", tag, value); + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/elf/Elf.java b/app/src/main/java/nl/lxtreme/binutils/elf/Elf.java new file mode 100644 index 00000000..b58ab4a3 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/elf/Elf.java @@ -0,0 +1,498 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.elf; + + +import android.util.*; +import java.io.*; +import java.nio.*; +import java.nio.channels.*; +import java.util.*; +import nl.lxtreme.binutils.elf.DynamicEntry.*; + + +/** + * Represents an ELF object file. + *

+ * This class is not thread-safe! + *

+ */ +public class Elf implements Closeable +{ + static int expectByteInRange( int in, int lowInclusive, int highInclusive, String errMsg ) throws IOException + { + if ( in < lowInclusive || in > highInclusive ) + { + throw new IOException( errMsg ); + } + return in; + } + + static String getZString( byte[] buf, long offset ) + { + return getZString( buf, ( int )( offset & 0xFFFFFFFF ) ); + } + + static String getZString( byte[] buf, int offset ) + { + int end = offset; + while ( end < buf.length && buf[end] != 0 ) + { + end++; + } + return new String( buf, offset, ( end - offset ) ); + } + + static boolean isBitSet( int flags, int mask ) + { + return ( flags & mask ) == mask; + } + + static boolean isBitSet( long flags, long mask ) + { + return ( flags & mask ) == mask; + } + + static void readFully( ReadableByteChannel ch, ByteBuffer buf, String errMsg ) throws IOException + { + buf.rewind(); + int read = ch.read( buf ); + if ( read != buf.limit() ) + { + throw new IOException( errMsg + " Read only " + read + " of " + buf.limit() + " bytes!" ); + } + buf.flip(); + } + + public final Header header; + public final ProgramHeader[] programHeaders; + public final SectionHeader[] sectionHeaders; + public final DynamicEntry[] dynamicTable; + + // locally managed. + private FileChannel channel; + + public Elf( File file ) throws IOException + { + this((new RandomAccessFile(file.getAbsolutePath(), "r").getChannel()));/* FileChannel.open( file.toPath(), StandardOpenOption.READ */ + /* FileChannel.open( file.toPath(), StandardOpenOption.READ*/ + } + + public Elf( FileChannel channel ) throws IOException + { + this.channel = channel; + this.header = new Header( channel ); + + // Read the last part of the ELF header and interpret the various headers... + ByteBuffer buf = ByteBuffer.allocate( 65536 ); + buf.order( header.elfByteOrder ); + buf.limit( 10 ); + + readFully( channel, buf, "Unable to read entry information!" ); + + int programHeaderEntrySize = buf.getShort(); + int programHeaderEntryCount = buf.getShort(); + int sectionHeaderEntrySize = buf.getShort(); + int sectionHeaderEntryCount = buf.getShort(); + int sectionNameTableIndex = buf.getShort(); + + // Should not be necessary unless we've not read the entire header... + channel.position( header.programHeaderOffset ); + + // Prepare for reading the program headers... + buf.limit( programHeaderEntrySize ); + + this.programHeaders = new ProgramHeader[programHeaderEntryCount]; + for ( int i = 0; i < programHeaderEntryCount; i++ ) + { + readFully( channel, buf, "Unable to read program header entry #" + i ); + + this.programHeaders[i] = new ProgramHeader( header.elfClass, buf ); + } + + // Should not be necessary unless we've not read the entire header... + channel.position( header.sectionHeaderOffset ); + + // Prepare for reading the section headers... + buf.limit( sectionHeaderEntrySize ); + + this.sectionHeaders = new SectionHeader[sectionHeaderEntryCount - 1]; + for ( int i = 0; i < sectionHeaderEntryCount; i++ ) + { + readFully( channel, buf, "Unable to read section header entry #" + i ); + + SectionHeader sHdr = new SectionHeader( header.elfClass, buf ); + if ( i == 0 ) + { + // Should always be a SHT_NONE entry... + if ( sHdr.type != SectionType.NULL ) + { + throw new IOException( "Invalid section found! First section should always be of type SHT_NULL!" ); + } + } + else + { + this.sectionHeaders[i - 1] = sHdr; + } + } + + if ( sectionNameTableIndex != 0 ) + { + // There's a section name string table present... + SectionHeader shdr = this.sectionHeaders[sectionNameTableIndex - 1]; + + buf = getSection( shdr ); + if ( buf == null ) + { + throw new IOException( "Unable to get section name table!" ); + } + + for ( SectionHeader hdr : sectionHeaders ) + { + hdr.setName( buf ); + } + } + + ProgramHeader phdr = getProgramHeaderByType( SegmentType.DYNAMIC ); + if ( phdr != null ) + { + List entries = new ArrayList<>(); + + buf = getSegment( phdr ); + if ( buf == null ) + { + throw new IOException( "Unable to get dynamic segment!" ); + } + + // Walk through the entries... + final boolean is32bit = header.is32bit(); + while ( buf.remaining() > 0 ) + { + long tagValue = is32bit ? buf.getInt() : buf.getLong(); + long value = is32bit ? buf.getInt() : buf.getLong(); + if ( tagValue == 0 ) + { + break; + } + Tag tag = Tag.valueOf( ( int )tagValue ); + + entries.add( new DynamicEntry( tag, value ) ); + } + + dynamicTable = entries.toArray( new DynamicEntry[entries.size()] ); + } + else + { + dynamicTable = null; + } + } + + public Elf( String name ) throws IOException + { + this( new File( name ) ); + } + + @Override + public void close() throws IOException + { + if ( channel != null ) + { + channel.close(); + channel = null; + } + } + + protected StringBuilder dumpDynamicEntry( StringBuilder sb, DynamicEntry entry, byte[] stringTable ) + { + sb.append( entry.getTag() ); + sb.append( " => " ); + if ( entry.isStringOffset() ) + { + sb.append( getZString( stringTable, entry.getValue() ) ); + } + else + { + sb.append( "0x" ).append( Long.toHexString( entry.getValue() ) ); + } + return sb; + } + + protected StringBuilder dumpProgramHeader( StringBuilder sb, ProgramHeader phdr ) + { + sb.append( phdr.type ); + sb.append( ", offset: 0x" ).append( Long.toHexString( phdr.offset ) ); + sb.append( ", vaddr: 0x" ).append( Long.toHexString( phdr.virtualAddress ) ); + sb.append( ", paddr: 0x" ).append( Long.toHexString( phdr.physicalAddress ) ); + sb.append( ", align: 0x" ).append( Long.toHexString( phdr.segmentAlignment ) ); + sb.append( ", file size: 0x" ).append( Long.toHexString( phdr.segmentFileSize ) ); + sb.append( ", memory size: 0x" ).append( Long.toHexString( phdr.segmentMemorySize ) ); + sb.append( ", flags: " ); + if ( isBitSet( phdr.flags, 0x04 ) ) + { + sb.append( "r" ); + } + else + { + sb.append( "-" ); + } + if ( isBitSet( phdr.flags, 0x02 ) ) + { + sb.append( "w" ); + } + else + { + sb.append( "-" ); + } + if ( isBitSet( phdr.flags, 0x01 ) ) + { + sb.append( "x" ); + } + else + { + sb.append( "-" ); + } + return sb; + } + + protected StringBuilder dumpSectionHeader( StringBuilder sb, SectionHeader shdr ) + { + String name = shdr.getName(); + if ( name != null ) + { + sb.append( name ); + sb.append("\t"); + sb.append( shdr.type ); + } + else + { + sb.append( shdr.type ); + } + sb.append( ", size: 0x" ).append( Long.toHexString( shdr.size ) ); + sb.append( ", vaddr: 0x" ).append( Long.toHexString( shdr.virtualAddress ) ); + sb.append( ", foffs: 0x" ).append( Long.toHexString( shdr.fileOffset ) ); + sb.append( ", align: 0x" ).append( Long.toHexString( shdr.sectionAlignment ) ); + if ( shdr.link != 0 ) + { + sb.append( ", link: 0x" ).append( Long.toHexString( shdr.link ) ); + } + if ( shdr.info != 0 ) + { + sb.append( ", info: 0x" ).append( Long.toHexString( shdr.info ) ); + } + if ( shdr.entrySize != 0 ) + { + sb.append( ", entrySize: 0x" ).append( Long.toHexString( shdr.entrySize ) ); + } + return sb; + } + + protected byte[] getDynamicStringTable() throws IOException + { + SectionHeader dynStrHdr = getSectionHeaderByType( SectionType.STRTAB ); + if ( dynStrHdr == null ) + { + throw new IOException( "Unable to get string table for dynamic section!" ); + } + + ByteBuffer dynStr = getSection( dynStrHdr ); + if ( dynStr == null ) + { + throw new IOException( "Unable to get string table for dynamic section!" ); + } + + return dynStr.array(); + } + + /** + * Returns the first program header with the given type. + * + * @return the first program header with the given type, or null + * if no such segment exists in this ELF object. + */ + public ProgramHeader getProgramHeaderByType( SegmentType type ) + { + if ( type == null ) + { + throw new IllegalArgumentException( "Type cannot be null!" ); + } + for ( ProgramHeader hdr : programHeaders ) + { + if ( type.equals( hdr.type ) ) + { + return hdr; + } + } + return null; + } + + /** + * Convenience method for determining which interpreter should be used for + * this ELF object. + * + * @return the name of the interpreter, or null if no interpreter + * could be determined. + */ + public String getProgramInterpreter() throws IOException + { + ProgramHeader phdr = getProgramHeaderByType( SegmentType.INTERP ); + if ( phdr == null ) + { + return null; + } + + ByteBuffer buf = getSegment( phdr ); + if ( buf == null ) + { + throw new IOException( "Unable to get program interpreter segment?!" ); + } + + return new String( buf.array(), 0, buf.remaining() ); + } + + /** + * Returns the actual section data based on the information from the given + * header. + * + * @return a byte buffer from which the section data can be read, never + * null. + */ + public ByteBuffer getSection( SectionHeader shdr ) throws IOException + { + if ( shdr == null ) + { + throw new IllegalArgumentException( "Header cannot be null!" ); + } + if ( channel == null ) + { + throw new IOException( "ELF file is already closed!" ); + } + + ByteBuffer buf = ByteBuffer.allocate( ( int )shdr.size ); + buf.order( header.elfByteOrder ); + + channel.position( shdr.fileOffset ); + readFully( channel, buf, "Unable to read section completely!" ); + + return buf; + } + + /** + * Returns the first section header with the given type. + * + * @return the first section header with the given type, or null + * if no such section exists in this ELF object. + */ + public SectionHeader getSectionHeaderByType( SectionType type ) + { + if ( type == null ) + { + throw new IllegalArgumentException( "Type cannot be null!" ); + } + for ( SectionHeader hdr : sectionHeaders ) + { + if ( type.equals( hdr.type ) ) + { + return hdr; + } + } + return null; + } + + /** + * Returns the actual segment data based on the information from the given + * header. + * + * @return a {@link ByteBuffer} from which the segment data can be read, never + * null. + */ + public ByteBuffer getSegment( final ProgramHeader phdr ) throws IOException + { + if ( phdr == null ) + { + throw new IllegalArgumentException( "Header cannot be null!" ); + } + if ( channel == null ) + { + throw new IOException( "ELF file is already closed!" ); + } + + ByteBuffer buf = ByteBuffer.allocate( ( int )phdr.segmentFileSize ); + buf.order( header.elfByteOrder ); + + channel.position( phdr.offset ); + readFully( channel, buf, "Unable to read segment completely!" ); + + return buf; + } + + public List getSharedDependencies() throws IOException + { + byte[] array = getDynamicStringTable(); + + List result = new ArrayList<>(); + for ( DynamicEntry entry : dynamicTable ) + { + if ( Tag.NEEDED.equals( entry.getTag() ) ) + { + result.add( getZString( array, ( int )entry.getValue() ) ); + } + } + + return result; + } + + @Override + public String toString() + { + try + { + StringBuilder sb = new StringBuilder(); + sb.append( header ).append( '\n' ); + sb.append( "Program header:\n" ); + for ( int i = 0; i < programHeaders.length; i++ ) + { + sb.append( '\t' ); + dumpProgramHeader( sb, programHeaders[i] ); + sb.append( '\n' ); + } + + byte[] strTable = getDynamicStringTable(); + + sb.append( "Dynamic table:\n" ); + if(dynamicTable!=null) + for ( DynamicEntry entry : dynamicTable ) + { + sb.append( '\t' ); + dumpDynamicEntry( sb, entry, strTable ); + sb.append( '\n' ); + } + + sb.append( "Sections:\n" ); + for ( int i = 0; i < sectionHeaders.length; i++ ) + { + SectionHeader shdr = sectionHeaders[i]; + if ( !SectionType.STRTAB.equals( shdr.type ) ) + { + sb.append( '\t' ); + dumpSectionHeader( sb, sectionHeaders[i] ); + sb.append( '\n' ); + } + } + return sb.toString(); + } + catch ( IOException exception ) + { + throw new RuntimeException( "Unable to get dynamic string table!" ); + } + catch(NullPointerException npe) + { + Log.e("Disassembler elf","",npe); + } + return ""; + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/elf/ElfClass.java b/app/src/main/java/nl/lxtreme/binutils/elf/ElfClass.java new file mode 100644 index 00000000..47241533 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/elf/ElfClass.java @@ -0,0 +1,15 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.elf; + +/** + * Denotes the class of an ELF object, whether it is using 32- or 64-bits offsets. + */ +public enum ElfClass { + CLASS_32, CLASS_64; +} \ No newline at end of file diff --git a/app/src/main/java/nl/lxtreme/binutils/elf/Flags.java b/app/src/main/java/nl/lxtreme/binutils/elf/Flags.java new file mode 100644 index 00000000..8394b8e7 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/elf/Flags.java @@ -0,0 +1,127 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.elf; + +/** + * Contains logic for interpreting the flags (e_flags) field in a ELF-header. + */ +public interface Flags { + /* Motorola 68k specific definitions. */ + int EF_CPU32 = 0x00810000; + + /* SUN SPARC specific definitions. */ + int EF_SPARCV9_MM = 3; + int EF_SPARCV9_TSO = 0; + int EF_SPARCV9_PSO = 1; + int EF_SPARCV9_RMO = 2; + int EF_SPARC_LEDATA = 0x800000; /* little endian data */ + int EF_SPARC_32PLUS = 0x000100; /* generic V8+ features */ + int EF_SPARC_SUN_US1 = 0x000200; /* Sun UltraSPARC1 extensions */ + int EF_SPARC_HAL_R1 = 0x000400; /* HAL R1 extensions */ + int EF_SPARC_SUN_US3 = 0x000800; /* Sun UltraSPARCIII extensions */ + + /* MIPS R3000 specific definitions. */ + int EF_MIPS_NOREORDER = 1; /* A .noreorder directive was used. */ + int EF_MIPS_PIC = 2; /* Contains PIC code. */ + int EF_MIPS_CPIC = 4; /* Uses PIC calling sequence. */ + int EF_MIPS_XGOT = 8; + int EF_MIPS_64BIT_WHIRL = 16; + int EF_MIPS_ABI2 = 32; + int EF_MIPS_ABI_ON32 = 64; + int EF_MIPS_NAN2008 = 1024; /* Uses IEEE 754-2008 NaN encoding. */ + int EF_MIPS_ARCH_1 = 0x00000000; /* -mips1 code. */ + int EF_MIPS_ARCH_2 = 0x10000000; /* -mips2 code. */ + int EF_MIPS_ARCH_3 = 0x20000000; /* -mips3 code. */ + int EF_MIPS_ARCH_4 = 0x30000000; /* -mips4 code. */ + int EF_MIPS_ARCH_5 = 0x40000000; /* -mips5 code. */ + int EF_MIPS_ARCH_32 = 0x50000000; /* MIPS32 code. */ + int EF_MIPS_ARCH_64 = 0x60000000; /* MIPS64 code. */ + int EF_MIPS_ARCH_32R2 = 0x70000000; /* MIPS32r2 code. */ + int EF_MIPS_ARCH_64R2 = 0x80000000; /* MIPS64r2 code. */ + + /* HPPA specific definitions. */ + int EF_PARISC_TRAPNIL = 0x00010000; /* Trap nil pointer dereference. */ + int EF_PARISC_EXT = 0x00020000; /* Program uses arch. extensions. */ + int EF_PARISC_LSB = 0x00040000; /* Program expects little endian. */ + int EF_PARISC_WIDE = 0x00080000; /* Program expects wide mode. */ + int EF_PARISC_NO_KABP = 0x00100000; /* No kernel assisted branch prediction. */ + int EF_PARISC_LAZYSWAP = 0x00400000; /* Allow lazy swapping. */ + int EF_PARISC_ARCH_1_0 = 0x020b; /* PA-RISC 1.0 big-endian. */ + int EF_PARISC_ARCH_1_1 = 0x0210; /* PA-RISC 1.1 big-endian. */ + int EF_PARISC_ARCH_2_0 = 0x0214; /* PA-RISC 2.0 big-endian. */ + + /* Alpha specific definitions. */ + int EF_ALPHA_32BIT = 1; /* All addresses must be < 2GB. */ + int EF_ALPHA_CANRELAX = 2; /* Relocations for relaxing exist. */ + + /* PowerPC specific declarations */ + int EF_PPC_EMB = 0x80000000; /* PowerPC embedded flag */ + int EF_PPC_RELOCATABLE = 0x00010000; /* PowerPC -mrelocatable flag */ + int EF_PPC_RELOCATABLE_LIB = 0x00008000; /* PowerPC -mrelocatable-lib */ + + /* ARM specific declarations */ + int EF_ARM_RELEXEC = 0x01; + int EF_ARM_HASENTRY = 0x02; + int EF_ARM_INTERWORK = 0x04; + int EF_ARM_APCS_26 = 0x08; + int EF_ARM_APCS_FLOAT = 0x10; + int EF_ARM_PIC = 0x20; + int EF_ARM_ALIGN8 = 0x40; /* 8-bit structure alignment is in use */ + int EF_ARM_NEW_ABI = 0x80; + int EF_ARM_OLD_ABI = 0x100; + int EF_ARM_SOFT_FLOAT = 0x200; + int EF_ARM_VFP_FLOAT = 0x400; + int EF_ARM_MAVERICK_FLOAT = 0x800; + /* Other constants defined in the ARM ELF spec. version B-01. */ + /* NB. These conflict with values defined above. */ + int EF_ARM_SYMSARESORTED = 0x04; + int EF_ARM_DYNSYMSUSESEGIDX = 0x08; + int EF_ARM_MAPSYMSFIRST = 0x10; + /* Constants defined in AAELF. */ + int EF_ARM_BE8 = 0x00800000; + int EF_ARM_LE8 = 0x00400000; + + int EF_ARM_EABI_UNKNOWN = 0x00000000; + int EF_ARM_EABI_VER1 = 0x01000000; + int EF_ARM_EABI_VER2 = 0x02000000; + int EF_ARM_EABI_VER3 = 0x03000000; + int EF_ARM_EABI_VER4 = 0x04000000; + int EF_ARM_EABI_VER5 = 0x05000000; + + /* IA-64 specific declarations. */ + int EF_IA_64_MASKOS = 0x0000000f; /* os-specific flags */ + int EF_IA_64_ABI64 = 0x00000010; /* 64-bit ABI */ + int EF_IA_64_ARCH = 0xff000000; /* arch. version mask */ + + /* SH specific declarations */ + int EF_SH_MACH_MASK = 0x1f; + int EF_SH_UNKNOWN = 0x0; + int EF_SH1 = 0x1; + int EF_SH2 = 0x2; + int EF_SH3 = 0x3; + int EF_SH_DSP = 0x4; + int EF_SH3_DSP = 0x5; + int EF_SH4AL_DSP = 0x6; + int EF_SH3E = 0x8; + int EF_SH4 = 0x9; + int EF_SH2E = 0xb; + int EF_SH4A = 0xc; + int EF_SH2A = 0xd; + int EF_SH4_NOFPU = 0x10; + int EF_SH4A_NOFPU = 0x11; + int EF_SH4_NOMMU_NOFPU = 0x12; + int EF_SH2A_NOFPU = 0x13; + int EF_SH3_NOMMU = 0x14; + int EF_SH2A_SH4_NOFPU = 0x15; + int EF_SH2A_SH3_NOFPU = 0x16; + int EF_SH2A_SH4 = 0x17; + int EF_SH2A_SH3E = 0x18; + + /* S/390 specific definitions. */ + int EF_S390_HIGH_GPRS = 0x00000001; /* High GPRs kernel facility needed. */ +} diff --git a/app/src/main/java/nl/lxtreme/binutils/elf/Header.java b/app/src/main/java/nl/lxtreme/binutils/elf/Header.java new file mode 100644 index 00000000..171f9f5d --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/elf/Header.java @@ -0,0 +1,255 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.elf; + + +import static nl.lxtreme.binutils.elf.Elf.*; +import static nl.lxtreme.binutils.elf.Flags.*; + +import java.io.*; +import java.nio.*; +import java.nio.channels.*; + + +/** + * Represents an ELF header. + */ +public class Header +{ + private static final int EI_NIDENT = 16; + + public final ElfClass elfClass; + public final ByteOrder elfByteOrder; + public final AbiType abiType; + public final int abiVersion; + public final ObjectFileType elfType; + public final MachineType machineType; + public final int elfVersion; + public final long entryPoint; + public final int flags; + public final long programHeaderOffset; + public final long sectionHeaderOffset; + + public Header( ReadableByteChannel channel ) throws IOException + { + final ByteBuffer buf = ByteBuffer.allocate( 128 ); + + buf.clear(); + buf.limit( EI_NIDENT ); + readFully( channel, buf, "Excepted a valid ELF header!" ); + + byte[] eIdent = buf.array(); + // Verify whether it is has the correct file ID... + if ( eIdent[0] != 0x7f || eIdent[1] != 'E' || eIdent[2] != 'L' || eIdent[3] != 'F' ) + { + throw new IOException( "Unknown file format! Expected valid ELF header (EI_MAG0..3)!" ); + } + + int eClass = expectByteInRange( eIdent[4], 1, 2, "Invalid ELF file! Invalid ELF class (EI_CLASS)!" ); + elfClass = ElfClass.values()[eClass - 1]; + + int byteOrder = expectByteInRange( eIdent[5], 1, 2, "Invalid ELF file! Unknown byte order (EI_DATA)!" ); + elfByteOrder = byteOrder == 1 ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN; + + expectByteInRange( eIdent[6], 1, 1, "Invalid ELF file! Unknown file version (EI_VERSION)!" ); + + abiType = AbiType.valueOf( eIdent[7] ); + abiVersion = eIdent[8]; + + buf.clear(); + buf.limit( 8 ); + buf.order( elfByteOrder ); + + readFully( channel, buf, "Failed to read ELF type, machine and version!" ); + + elfType = ObjectFileType.valueOf( buf.getShort() ); + machineType = MachineType.valueOf( buf.getShort() ); + elfVersion = buf.getInt(); + + buf.clear(); + switch ( elfClass ) + { + case CLASS_32: + buf.limit( 12 ); + readFully( channel, buf, "Failed to read ELF entry point and offsets!" ); + entryPoint = buf.getInt() & 0xFFFFFFFFL; + programHeaderOffset = buf.getInt() & 0xFFFFFFFFL; + sectionHeaderOffset = buf.getInt() & 0xFFFFFFFFL; + break; + case CLASS_64: + buf.limit( 24 ); + readFully( channel, buf, "Failed to read ELF entry point and offsets!" ); + entryPoint = buf.getLong(); + programHeaderOffset = buf.getLong(); + sectionHeaderOffset = buf.getLong(); + break; + default: + throw new IOException( "Unhandled ELF-class!" ); + } + + buf.clear(); + buf.limit( 6 ); + readFully( channel, buf, "Failed to read ELF flags and size information!" ); + + flags = buf.getInt(); + + int headerSize = buf.getShort(); + // TODO this might not always be true? According to the GABI/ELF spec it + // should... + if ( programHeaderOffset != 0 && headerSize != programHeaderOffset ) + { + throw new IOException( "Header size and program header do not match?!" ); + } + } + + public boolean is32bit() + { + return elfClass == ElfClass.CLASS_32; + } + + public boolean is64bit() + { + return elfClass == ElfClass.CLASS_64; + } + + public boolean isBigEndian() + { + return elfByteOrder == ByteOrder.BIG_ENDIAN; + } + + public boolean isLittleEndian() + { + return elfByteOrder == ByteOrder.LITTLE_ENDIAN; + } + + @Override + public String toString() + { + StringBuilder sb = new StringBuilder( "ELF " ); + switch ( elfClass ) + { + case CLASS_32: + sb.append( "32" ); + break; + case CLASS_64: + sb.append( "64" ); + break; + } + sb.append( "-bit " ); + if ( isLittleEndian() ) + { + sb.append( "LSB " ); + } + else + { + sb.append( "MSB " ); + } + sb.append( elfType ).append( ", " ).append( machineType ); + switch ( machineType ) + { + case ARM: + if ( ( flags & EF_ARM_EABI_VER5 ) == EF_ARM_EABI_VER5 ) + { + sb.append( " EABIv5" ); + } + else if ( ( flags & EF_ARM_EABI_VER4 ) == EF_ARM_EABI_VER4 ) + { + sb.append( " EABIv4" ); + } + else if ( ( flags & EF_ARM_EABI_VER3 ) == EF_ARM_EABI_VER3 ) + { + sb.append( " EABIv3" ); + } + else if ( ( flags & EF_ARM_EABI_VER2 ) == EF_ARM_EABI_VER2 ) + { + sb.append( " EABIv2" ); + } + else if ( ( flags & EF_ARM_EABI_VER1 ) == EF_ARM_EABI_VER1 ) + { + sb.append( " EABIv1" ); + } + else if ( ( flags & EF_ARM_EABI_UNKNOWN ) == EF_ARM_EABI_UNKNOWN ) + { + sb.append( " unknown EABI" ); + } + break; + default: + break; + } + sb.append( " version " ); + sb.append( elfVersion ).append( " (" ).append( abiType ).append( ")\n" ); + sb.append( "Using entry point = 0x" ).append( Long.toHexString( entryPoint ) ); + switch ( machineType ) + { + case ARM: + if ( isBitSet( flags, EF_ARM_RELEXEC ) ) + { + sb.append( ", relocatable executable" ); + } + if ( isBitSet( flags, EF_ARM_HASENTRY ) ) + { + sb.append( ", has entry point" ); + } + if ( isBitSet( flags, EF_ARM_INTERWORK ) ) + { + sb.append( ", interworking enabled" ); + } + if ( isBitSet( flags, EF_ARM_APCS_26 ) ) + { + sb.append( ", APCS-26" ); + } + else + { + sb.append( ", APCS-32" ); + } + if ( isBitSet( flags, EF_ARM_APCS_FLOAT ) ) + { + sb.append( ", using float registers" ); + } + else + { + sb.append( ", using integer registers" ); + } + if ( isBitSet( flags, EF_ARM_PIC ) ) + { + sb.append( ", position independent" ); + } + if ( isBitSet( flags, EF_ARM_ALIGN8 ) ) + { + sb.append( ", 8-bit structure alignment" ); + } + if ( isBitSet( flags, EF_ARM_NEW_ABI ) ) + { + sb.append( ", new ABI" ); + } + if ( isBitSet( flags, EF_ARM_OLD_ABI ) ) + { + sb.append( ", old ABI" ); + } + if ( isBitSet( flags, EF_ARM_SOFT_FLOAT ) ) + { + sb.append( ", using software FP" ); + } + if ( isBitSet( flags, EF_ARM_VFP_FLOAT ) ) + { + sb.append( ", using VFP FP" ); + } + if ( isBitSet( flags, EF_ARM_MAVERICK_FLOAT ) ) + { + sb.append( ", using maverick FP" ); + } + break; + default: + if ( flags != 0 ) + { + sb.append( "0x" ).append( Integer.toHexString( flags ) ); + } + } + return sb.toString(); + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/elf/MachineType.java b/app/src/main/java/nl/lxtreme/binutils/elf/MachineType.java new file mode 100644 index 00000000..b151b480 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/elf/MachineType.java @@ -0,0 +1,117 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.elf; + +/** + * Represents the various known machine types (extracted from "elf.h" file from libc6-dev package). + */ +public enum MachineType { + NONE(0, "No machine"), + M32(1, "AT&T WE 32100"), + SPARC(2, "SUN SPARC"), + i386(3, "Intel 80386"), + m68K(4, "Motorola m68k family"), + m88K(5, "Motorola m88k family"), + i860(7, "Intel 80860"), + MIPS(8, "MIPS R3000 big-endian"), + S370(9, "IBM System/370"), + MIPS_RS3_LE(10, "MIPS R3000 little-endian"), + + PARISC(15, "HPPA"), + VPP500(17, "Fujitsu VPP500"), + SPARC32PLUS(18, "Sun's \"v8plus\""), + i960(19, "Intel 80960"), + PPC(20, "PowerPC"), + PPC64(21, "PowerPC 64-bit"), + S390(22, "IBM S390"), + + V800(36, "NEC V800 series"), + FR20(37, "Fujitsu FR20"), + RH32(38, "TRW RH-32"), + RCE(39, "Motorola RCE"), + ARM(40, "ARM"), + FAKE_ALPHA(41, "Digital Alpha"), + SH(42, "Hitachi SH"), + SPARCV9(43, "SPARC v9 64-bit"), + TRICORE(44, "Siemens Tricore"), + ARC(45, "Argonaut RISC Core"), + H8_300(46, "Hitachi H8/300"), + H8_300H(47, "Hitachi H8/300H"), + H8S(48, "Hitachi H8S"), + H8_500(49, "Hitachi H8/500"), + IA_64(50, "Intel Merced"), + MIPS_X(51, "Stanford MIPS-X"), + COLDFIRE(52, "Motorola Coldfire"), + m68HC12(53, "Motorola M68HC12"), + MMA(54, "Fujitsu MMA Multimedia Accelerator"), + PCP(55, "Siemens PCP"), + NCPU(56, "Sony nCPU embeeded RISC"), + NDR1(57, "Denso NDR1 microprocessor"), + STARCORE(58, "Motorola Start*Core processor"), + ME16(59, "Toyota ME16 processor"), + ST100(60, "STMicroelectronic ST100 processor"), + TINYJ(61, "Advanced Logic Corp. Tinyj emb.fam"), + x86_64(62, "x86-64"), + PDSP(63, "Sony DSP Processor"), + + FX66(66, "Siemens FX66 microcontroller"), + ST9PLUS(67, "STMicroelectronics ST9+ 8/16 mc"), + ST7(68, "STmicroelectronics ST7 8 bit mc"), + m68HC16(69, "Motorola MC68HC16 microcontroller"), + m68HC11(70, "Motorola MC68HC11 microcontroller"), + m68HC08(71, "Motorola MC68HC08 microcontroller"), + m68HC05(72, "Motorola MC68HC05 microcontroller"), + SVX(73, "Silicon Graphics SVx"), + ST19(74, "STMicroelectronics ST19 8 bit mc"), + VAX(75, "Digital VAX"), + CRIS(76, "Axis Communications 32-bit embedded processor"), + JAVELIN(77, "Infineon Technologies 32-bit embedded processor"), + FIREPATH(78, "Element 14 64-bit DSP Processor"), + ZSP(79, "LSI Logic 16-bit DSP Processor"), + MMIX(80, "Donald Knuth's educational 64-bit processor"), + HUANY(81, "Harvard University machine-independent object files"), + PRISM(82, "SiTera Prism"), + AVR(83, "Atmel AVR 8-bit microcontroller"), + FR30(84, "Fujitsu FR30"), + D10V(85, "Mitsubishi D10V"), + D30V(86, "Mitsubishi D30V"), + V850(87, "NEC v850"), + M32R(88, "Mitsubishi M32R"), + MN10300(89, "Matsushita MN10300"), + MN10200(90, "Matsushita MN10200"), + PJ(91, "picoJava"), + OPENRISC(92, "OpenRISC 32-bit embedded processor"), + ARC_A5(93, "ARC Cores Tangent-A5"), + XTENSA(94, "Tensilica Xtensa Architecture"), + AARCH64(183, "ARM AARCH64"), + TILEPRO(188, "Tilera TILEPro"), + MICROBLAZE(189, "Xilinx MicroBlaze"), + TILEGX(191, "Tilera TILE-Gx"); + + private final int no; + private final String desc; + + private MachineType(int no, String desc) { + this.no = no; + this.desc = desc; + } + + static MachineType valueOf(int value) { + for (MachineType mt : values()) { + if (mt.no == value) { + return mt; + } + } + throw new IllegalArgumentException("Invalid machine type: " + value); + } + + @Override + public String toString() { + return desc; + } +} \ No newline at end of file diff --git a/app/src/main/java/nl/lxtreme/binutils/elf/ObjectFileType.java b/app/src/main/java/nl/lxtreme/binutils/elf/ObjectFileType.java new file mode 100644 index 00000000..e6a27513 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/elf/ObjectFileType.java @@ -0,0 +1,76 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.elf; + +public final class ObjectFileType { + public static final ObjectFileType NONE = new ObjectFileType(0, "no file type"); + public static final ObjectFileType REL = new ObjectFileType(1, "relocatable"); + public static final ObjectFileType EXEC = new ObjectFileType(2, "executable"); + public static final ObjectFileType DYN = new ObjectFileType(3, "shared object"); + public static final ObjectFileType CORE = new ObjectFileType(4, "core file"); + + private static final ObjectFileType[] VALUES = { NONE, REL, EXEC, DYN, CORE }; + + private static final int ET_LOOS = 0xfe00; + private static final int ET_HIOS = 0xfeff; + private static final int ET_LOPROC = 0xff00; + private static final int ET_HIPROC = 0xffff; + + public static ObjectFileType valueOf(int value) { + for (ObjectFileType oft : VALUES) { + if (oft.type == value) { + return oft; + } + } + if (value >= ET_LOOS && value <= ET_HIOS) { + return new ObjectFileType(value, "OS-specific object file"); + } else if (value >= ET_LOPROC && value <= ET_HIPROC) { + return new ObjectFileType(value, "Processor-specific object file"); + } else { + throw new IllegalArgumentException("Unknown object file type!"); + } + } + + private final int type; + private final String desc; + + private ObjectFileType(int type, String desc) { + this.type = type; + this.desc = desc; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + ObjectFileType other = (ObjectFileType) obj; + return (type == other.type); + } + + @Override + public int hashCode() { + return 37 + type; + } + + public String name() { + return desc; + } + + public int ordinal() { + return this.type; + } + + @Override + public String toString() { + return desc; + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/elf/ProgramHeader.java b/app/src/main/java/nl/lxtreme/binutils/elf/ProgramHeader.java new file mode 100644 index 00000000..f0666fa7 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/elf/ProgramHeader.java @@ -0,0 +1,52 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.elf; + +import java.io.*; +import java.nio.*; + +/** + * Represents information about the various segments in an ELF object. + */ +public class ProgramHeader { + public final SegmentType type; + public final long flags; + public final long offset; + public final long virtualAddress; + public final long physicalAddress; + public final long segmentFileSize; + public final long segmentMemorySize; + public final long segmentAlignment; + + public ProgramHeader(ElfClass elfClass, ByteBuffer buf) throws IOException { + switch (elfClass) { + case CLASS_32: + type = SegmentType.valueOf(buf.getInt() & 0xFFFFFFFF); + offset = buf.getInt() & 0xFFFFFFFFL; + virtualAddress = buf.getInt() & 0xFFFFFFFFL; + physicalAddress = buf.getInt() & 0xFFFFFFFFL; + segmentFileSize = buf.getInt() & 0xFFFFFFFFL; + segmentMemorySize = buf.getInt() & 0xFFFFFFFFL; + flags = buf.getInt() & 0xFFFFFFFFL; + segmentAlignment = buf.getInt() & 0xFFFFFFFFL; + break; + case CLASS_64: + type = SegmentType.valueOf(buf.getInt() & 0xFFFFFFFF); + flags = buf.getInt() & 0xFFFFFFFFL; + offset = buf.getLong(); + virtualAddress = buf.getLong(); + physicalAddress = buf.getLong(); + segmentFileSize = buf.getLong(); + segmentMemorySize = buf.getLong(); + segmentAlignment = buf.getLong(); + break; + default: + throw new IOException("Unhandled ELF-class!"); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/nl/lxtreme/binutils/elf/SectionHeader.java b/app/src/main/java/nl/lxtreme/binutils/elf/SectionHeader.java new file mode 100644 index 00000000..0beb9fa3 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/elf/SectionHeader.java @@ -0,0 +1,78 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.elf; + +import java.io.*; +import java.nio.*; + +/** + * Represents information about the various sections in an ELF object. + */ +public class SectionHeader { + private final int nameOffset; + private String name; + + public final SectionType type; + public final long flags; + public final long virtualAddress; + public final long fileOffset; + public final long size; + public final int link; + public final int info; + public final long sectionAlignment; + public final long entrySize; + + public SectionHeader(ElfClass elfClass, ByteBuffer buf) throws IOException { + nameOffset = buf.getInt(); + type = SectionType.valueOf(buf.getInt()); + + if (elfClass == ElfClass.CLASS_32) { + flags = buf.getInt() & 0xFFFFFFFFL; + virtualAddress = buf.getInt() & 0xFFFFFFFFL; + fileOffset = buf.getInt() & 0xFFFFFFFFL; + size = buf.getInt() & 0xFFFFFFFFL; + } else if (elfClass == ElfClass.CLASS_64) { + flags = buf.getLong(); + virtualAddress = buf.getLong(); + fileOffset = buf.getLong(); + size = buf.getLong(); + } else { + throw new IOException("Unhandled ELF-class!"); + } + + link = buf.getInt(); + info = buf.getInt(); + + if (elfClass == ElfClass.CLASS_32) { + sectionAlignment = buf.getInt() & 0xFFFFFFFFL; + entrySize = buf.getInt() & 0xFFFFFFFFL; + } else if (elfClass == ElfClass.CLASS_64) { + sectionAlignment = buf.getLong(); + entrySize = buf.getLong(); + } else { + throw new IOException("Unhandled ELF-class!"); + } + } + + public String getName() { + return name; + } + + void setName(ByteBuffer buf) { + if (nameOffset > 0) { + byte[] array = buf.array(); + + int end = nameOffset; + while (end < array.length && array[end] != 0) { + end++; + } + + name = new String(array, nameOffset, end - nameOffset); + } + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/elf/SectionType.java b/app/src/main/java/nl/lxtreme/binutils/elf/SectionType.java new file mode 100644 index 00000000..7e001539 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/elf/SectionType.java @@ -0,0 +1,106 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.elf; + +/** + * Represents a type of section used in an ELF object. + */ +public class SectionType { + public static final SectionType NULL = new SectionType(0, "Section header table entry unused"); + public static final SectionType PROGBITS = new SectionType(1, "Program data"); + public static final SectionType SYMTAB = new SectionType(2, "Symbol table"); + public static final SectionType STRTAB = new SectionType(3, "String table"); + public static final SectionType RELA = new SectionType(4, "Relocation entries with addends"); + public static final SectionType HASH = new SectionType(5, "Symbol hash table"); + public static final SectionType DYNAMIC = new SectionType(6, "Dynamic linking information"); + public static final SectionType NOTE = new SectionType(7, "Notes"); + public static final SectionType NOBITS = new SectionType(8, "Program space with no data (bss)"); + public static final SectionType REL = new SectionType(9, "Relocation entries, no addends"); + public static final SectionType SHLIB = new SectionType(10, "Reserved"); + public static final SectionType DYNSYM = new SectionType(11, "Thread-local storage segment"); + public static final SectionType INIT_ARRAY = new SectionType(14, "Array of constructors"); + public static final SectionType FINI_ARRAY = new SectionType(15, "Array of destructors"); + public static final SectionType PREINIT_ARRAY = new SectionType(16, "Array of pre-constructors"); + public static final SectionType GROUP = new SectionType(17, "Section group"); + public static final SectionType SYMTAB_SHNDX = new SectionType(18, "Extended section indeces"); + public static final SectionType GNU_ATTRIBUTES = new SectionType(0x6ffffff5, "GNU object attributes"); + public static final SectionType GNU_HASH = new SectionType(0x6ffffff6, "GNU-style hash table"); + public static final SectionType GNU_LIBLIST = new SectionType(0x6ffffff7, "GNU Prelink library list"); + public static final SectionType CHECKSUM = new SectionType(0x6ffffff8, "Checksum for DSO content"); + public static final SectionType SUNW_MOVE = new SectionType(0x6ffffffa, "SUNW_MOVE"); + public static final SectionType SUNW_COMDAT = new SectionType(0x6ffffffb, "SUNW_COMDAT"); + public static final SectionType SUNW_SYMINFO = new SectionType(0x6ffffffc, "SUNW_SYMINFO"); + public static final SectionType GNU_VERDEF = new SectionType(0x6ffffffd, "GNU version definition section"); + public static final SectionType GNU_VERNEED = new SectionType(0x6ffffffe, "GNU version needs section"); + public static final SectionType GNU_VERSYM = new SectionType(0x6fffffff, "GNU version symbol table"); + + private static final SectionType[] VALUES = { NULL, PROGBITS, SYMTAB, STRTAB, RELA, HASH, DYNAMIC, NOTE, NOBITS, + REL, SHLIB, DYNSYM, INIT_ARRAY, FINI_ARRAY, PREINIT_ARRAY, GROUP, SYMTAB_SHNDX, GNU_ATTRIBUTES, GNU_HASH, + GNU_LIBLIST, CHECKSUM, SUNW_MOVE, SUNW_COMDAT, SUNW_SYMINFO, GNU_VERDEF, GNU_VERNEED, GNU_VERSYM }; + + private static final int SHT_LOOS = 0x60000000; + private static final int SHT_HIOS = 0x6fffffff; + private static final int SHT_LOPROC = 0x70000000; + private static final int SHT_HIPROC = 0x7fffffff; + private static final int SHT_LOUSER = 0x70000000; + private static final int SHT_HIUSER = 0x7fffffff; + + public static SectionType valueOf(int value) { + for (SectionType st : VALUES) { + if (st.no == value) { + return st; + } + } + if (value >= SHT_LOOS && value <= SHT_HIOS) { + return new SectionType(value, "OS-specific segment"); + } else if (value >= SHT_LOPROC && value <= SHT_HIPROC) { + return new SectionType(value, "Processor-specific segment"); + } else if (value >= SHT_LOUSER && value <= SHT_HIUSER) { + return new SectionType(value, "User-specific segment"); + } + throw new IllegalArgumentException("Invalid segment type!"); + } + + private final int no; + private final String desc; + + private SectionType(int no, String desc) { + this.no = no; + this.desc = desc; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + SectionType other = (SectionType) obj; + return (no == other.no); + } + + @Override + public int hashCode() { + return 37 + no; + } + + public String name() { + return desc; + } + + public int ordinal() { + return no; + } + + @Override + public String toString() { + return desc; + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/elf/SegmentType.java b/app/src/main/java/nl/lxtreme/binutils/elf/SegmentType.java new file mode 100644 index 00000000..b76ba308 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/elf/SegmentType.java @@ -0,0 +1,70 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2016 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.elf; + +/** + * Represents a type of segment used in an ELF object. + */ +public class SegmentType { + public static final SegmentType NULL = new SegmentType(0, "Program header table entry unused"); + public static final SegmentType LOAD = new SegmentType(1, "Loadable program segment"); + public static final SegmentType DYNAMIC = new SegmentType(2, "Dynamic linking information"); + public static final SegmentType INTERP = new SegmentType(3, "Program interpreter"); + public static final SegmentType NOTE = new SegmentType(4, "Auxiliary information"); + public static final SegmentType SHLIB = new SegmentType(5, "Reserved"); + public static final SegmentType PHDR = new SegmentType(6, "Entry for header table itself"); + public static final SegmentType TLS = new SegmentType(7, "Thread-local storage segment"); + public static final SegmentType GNU_EH_FRAME = new SegmentType(0x6474e550, "GCC .eh_frame_hdr segment"); + public static final SegmentType GNU_STACK = new SegmentType(0x6474e551, "Stack executability"); + public static final SegmentType GNU_RELRO = new SegmentType(0x6474e552, "Read-only after relocation"); + public static final SegmentType SUNWBSS = new SegmentType(0x6ffffffa, "Sun Specific segment"); + public static final SegmentType SUNWSTACK = new SegmentType(0x6ffffffb, "Sun Stack segment"); + + public static final SegmentType[] VALUES = + { NULL, LOAD, DYNAMIC, INTERP, NOTE, SHLIB, PHDR, TLS, GNU_EH_FRAME, GNU_STACK, GNU_RELRO, SUNWBSS, SUNWSTACK }; + + private static final int PT_LOOS = 0x60000000; + private static final int PT_HIOS = 0x6fffffff; + private static final int PT_LOPROC = 0x70000000; + private static final int PT_HIPROC = 0x7fffffff; + + private final int no; + private final String desc; + + private SegmentType(int no, String desc) { + this.no = no; + this.desc = desc; + } + + public static SegmentType valueOf(int value) { + for (SegmentType st : VALUES) { + if (st.no == value) { + return st; + } + } + if (value >= PT_LOOS && value <= PT_HIOS) { + return new SegmentType(value, "OS-specific segment"); + } else if (value >= PT_LOPROC && value <= PT_HIPROC) { + return new SegmentType(value, "Processor-specific segment"); + } + throw new IllegalArgumentException("Invalid segment type!"); + } + + public int ordinal() { + return no; + } + + public String name() { + return desc; + } + + @Override + public String toString() { + return desc; + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/hex/AbstractReader.java b/app/src/main/java/nl/lxtreme/binutils/hex/AbstractReader.java new file mode 100644 index 00000000..f0a80ba0 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/hex/AbstractReader.java @@ -0,0 +1,173 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2017 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.hex; + + +import java.io.*; +import java.nio.*; + +import nl.lxtreme.binutils.hex.util.*; + + +/** + * Base implementation for interpreting hex-based data files. + */ +public abstract class AbstractReader +{ + // VARIABLES + + protected final Reader reader; + + // CONSTRUCTORS + + /** + * Creates a new AbstractReader instance. + */ + public AbstractReader( Reader aReader ) + { + this.reader = ( aReader instanceof BufferedReader ) ? ( BufferedReader )aReader : new BufferedReader( aReader ); + } + + // METHODS + + /** + * Closes this instruction stream. + * + * @throws IOException + * in case of stream I/O problems. + */ + public void close() throws IOException + { + this.reader.close(); + } + + /** + * @return the current address location, or -1 if no address is + * known. + * @throws IOException + * in case of I/O problems. + */ + public abstract long getAddress() throws IOException; + + /** + * Reads a single byte from the underlying stream. + * + * @return the next byte, can be -1 in case an end-of-stream was + * encountered. + * @throws IOException + * in case of stream I/O problems; + */ + public abstract int readByte() throws IOException; + + /** + * Reads a long word (4 bytes) from the underlying stream. + * + * @return the next long word, can be -1 in case an end-of-stream + * was encountered. + * @throws IOException + * in case of stream I/O problems; + */ + public int readLongWord() throws IOException + { + final byte[] data = readBytes( 4 ); + if ( data == null ) + { + return -1; + } + + return ( int )ByteOrderUtils.decode( getByteOrder(), data ); + } + + /** + * Reads a word (2 bytes) from the underlying stream. + * + * @return the next word, can be -1 in case an end-of-stream was + * encountered. + * @throws IOException + * in case of stream I/O problems; + */ + public int readWord() throws IOException + { + final byte[] data = readBytes( 2 ); + if ( data == null ) + { + return -1; + } + + return ( int )ByteOrderUtils.decode( ByteOrder.LITTLE_ENDIAN, data ); + } + + /** + * Returns the byte order in which this data provider reads its data. + * + * @return a byte order, never null. + */ + protected abstract ByteOrder getByteOrder(); + + /** + * Convenience method to read a number of bytes. + * + * @param aCount + * the number of bytes to read, should be > 0. + * @return a byte array with the read bytes, can be null in case + * an EOF was found. + * @throws IOException + * in case of I/O problems; + * @throws IllegalArgumentException + * in case the given count was <= 0. + */ + protected final byte[] readBytes( final int aCount ) throws IOException, IllegalArgumentException + { + if ( aCount <= 0 ) + { + throw new IllegalArgumentException( "Count cannot be less or equal to zero!" ); + } + + final byte[] result = new byte[aCount]; + for ( int i = 0; i < aCount; i++ ) + { + int readByte = readByte(); + if ( readByte == -1 ) + { + return null; + } + result[i] = ( byte )readByte; + } + + return result; + } + + protected final char[] readChars( final int aCount ) throws IOException, IllegalArgumentException + { + if ( aCount <= 0 ) + { + throw new IllegalArgumentException( "Invalid count!" ); + } + final char[] buf = new char[aCount]; + if ( this.reader.read( buf ) != aCount ) + { + throw new IOException( "Unexpected end of stream!" ); + } + return buf; + } + + /** + * Skips until the end-of-line is found. + */ + protected final int readSingleByte() throws IOException + { + int ch; + do + { + ch = this.reader.read(); + } + while ( ( ch != -1 ) && Character.isWhitespace( ch ) ); + return ch; + } + +} diff --git a/app/src/main/java/nl/lxtreme/binutils/hex/IntelHexReader.java b/app/src/main/java/nl/lxtreme/binutils/hex/IntelHexReader.java new file mode 100644 index 00000000..1e8b0ec7 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/hex/IntelHexReader.java @@ -0,0 +1,240 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2017 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.hex; + + +import java.io.*; +import java.nio.*; + +import nl.lxtreme.binutils.hex.util.*; + + +/** + * Provides a data provider based on a Intel-HEX file. + *

+ * A file in the Intel hex-format is a text file containing hexadecimal encoded + * data, organised in so-called records: a text line in the following format: + *

+ * + *
+ *     :<datacount><address><recordtype><data><checksum>
+ * 
+ *

+ * In which is: + *

+ *
    + *
  • ':', the identifying character of the record;
  • + *
  • datacount, the hex-encoded byte representing the number of data + * bytes in the record;
  • + *
  • address, the hex-encoded 2-byte address;
  • + *
  • recordtype, hex-encoded byte representing the record type: + *
      + *
    • '00': data record (like the Motorola record type "S1");
    • + *
    • '01': termination record (like the Motorola record type "S9");
    • + *
    • '02': segment base address record, the first word of data of this record + * used as Segment Base Address of the addresses of the next data records; + * actual addresses are calculated as: start address := (SegmentBaseAddress*16) + * + record start address;
    • + *
    • '04': unknown record-type, the first word of data of this record is + * interpreted by Binex as Segment Address, the most significant word of the + * addresses of the next data records; actual addresses are calculated as: start + * address := (SegmentAddress*65536) + record start address;
    • + *
    + *
  • + *
  • data, the hex-encoded data bytes (maximum 255);
  • + *
  • checksum, the two's complement of the sum of all bytes in the + * record after the identifying character.
  • + *
+ *

+ * Files with only 00, and 01 records are called to be in Intel "Intellec" 8/MDS + * format. The Intel MCS86 (Intellec 86) format adds the 02 type records to + * that. + *

+ */ +public class IntelHexReader extends AbstractReader +{ + // CONSTANTS + + private static final char PREAMBLE = ':'; + + private static final int DATA_TYPE = 0; + private static final int TERMINATION_TYPE = 1; + private static final int EXTENDED_SEGMENT_ADDRESS_TYPE = 2; + private static final int START_SEGMENT_ADDRESS_TYPE = 3; + private static final int EXTENDED_LINEAR_ADDRESS_TYPE = 4; + private static final int START_LINEAR_ADDRESS_TYPE = 5; + + // VARIABLES + + private final Checksummer checksum; + + private Integer segmentBaseAddress; + private Integer linearAddress; + private Integer address; + private Integer dataLength; + + // CONSTRUCTORS + + /** + * Creates a new IntelHexDataProvider instance. + * + * @param aReader + * the reader to use. + */ + public IntelHexReader( final Reader aReader ) + { + super( aReader ); + + this.checksum = Checksum.TWOS_COMPLEMENT.instance(); + } + + // METHODS + + @Override + public long getAddress() throws IOException + { + if ( this.address == null ) + { + throw new IOException( "Unexpected call to getAddress!" ); + } + return this.address.longValue(); + } + + @Override + public int readByte() throws IOException + { + int ch; + + do + { + ch = readSingleByte(); + if ( ch == -1 ) + { + // End-of-file reached; return immediately! + return -1; + } + + if ( PREAMBLE == ch ) + { + // New record started... + startNewDataRecord(); + } + else if ( this.dataLength != null ) + { + final int secondHexDigit = this.reader.read(); + if ( secondHexDigit == -1 ) + { + throw new IOException( "Unexpected end-of-stream!" ); + } + + final char[] buf = { ( char )ch, ( char )secondHexDigit }; + + final byte dataByte = HexUtils.parseHexByte( buf ); + if ( this.dataLength == 0 ) + { + // All data-bytes returned? If so, verify the CRC we've just read... + final byte calculatedCRC = this.checksum.getResult(); + if ( dataByte != calculatedCRC ) + { + throw new IOException( "CRC Error! Expected: 0x" + Integer.toHexString( dataByte ) + "; got: 0x" + + Integer.toHexString( calculatedCRC ) ); + } + } + else + { + // Decrease the number of hex-bytes we've got to read... + this.checksum.add( ( byte )dataByte ); + + this.dataLength--; + this.address++; + + return ( dataByte & 0xFF ); + } + } + } + while ( ch != -1 ); + + // We should never come here; it means that we've found a situation that + // isn't covered by our loop above... + throw new IOException( "Invalid Intel HEX-file!" ); + } + + @Override + protected ByteOrder getByteOrder() + { + return ByteOrder.LITTLE_ENDIAN; + } + + /** + * Starts a new data record, calculates the initial address, and checks what + * kind of data the record contains. + * + * @throws IOException + * in case of I/O problems. + */ + private void startNewDataRecord() throws IOException + { + // First byte is the length of the data record... + this.dataLength = ( int )HexUtils.readHexByte( this.reader ); + + // When a segment base address is previously set, calculate the actual + // address by OR-ing this base-address with the address of the record... + this.address = HexUtils.readHexWord( this.reader ); + if ( ( this.segmentBaseAddress != null ) && ( this.segmentBaseAddress > 0 ) ) + { + this.address = this.segmentBaseAddress | this.address; + } + else if ( ( this.linearAddress != null ) && ( this.linearAddress > 0 ) ) + { + this.address = ( this.linearAddress << 16 ) | this.address; + } + + final int recordType = HexUtils.readHexByte( this.reader ); + + // Calculate the first part of the record CRC; which is defined as the + // ones-complement of all (non-CRC) items in the record... + this.checksum.reset(); + this.checksum.add( this.dataLength.byteValue() ); + this.checksum.add( ( byte )recordType ); + this.checksum.addWord( this.address ); + + if ( DATA_TYPE == recordType ) + { + // Ok, found first data item... Adjust address with a single byte in + // order to obtain a valid first address... + this.address--; + } + else if ( EXTENDED_SEGMENT_ADDRESS_TYPE == recordType ) + { + this.segmentBaseAddress = HexUtils.readHexWord( this.reader ); + + this.checksum.addWord( this.segmentBaseAddress ); + + // Ignore the rest of the data; but calculate the CRC... + this.dataLength = 0; + } + else if ( EXTENDED_LINEAR_ADDRESS_TYPE == recordType ) + { + this.linearAddress = HexUtils.readHexWord( this.reader ); + + this.checksum.addWord( this.linearAddress ); + + // Ignore the rest of the data; but calculate the CRC... + this.dataLength = 0; + } + else if ( TERMINATION_TYPE == recordType ) + { + // Ignore the rest of the data; but calculate the CRC... + this.dataLength = 0; + } + else if ( ( START_LINEAR_ADDRESS_TYPE != recordType ) && ( START_SEGMENT_ADDRESS_TYPE != recordType ) ) + { + throw new IOException( "Unknown Intel record type: " + recordType ); + } + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/hex/SRecordReader.java b/app/src/main/java/nl/lxtreme/binutils/hex/SRecordReader.java new file mode 100644 index 00000000..bca10483 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/hex/SRecordReader.java @@ -0,0 +1,275 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2017 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.hex; + + +import java.io.*; +import java.nio.*; + +import nl.lxtreme.binutils.hex.util.*; + + +/** + * Provides a data provider based on a Motorola SRecord file. + * + *
+ *      S<recordtype><recordlength><address><data><checksum>
+ * 
+ *

+ * In which is: + *

+ *
    + *
  • 'S', the identifying character of the record (therefore called + * S-record);
  • + *
  • recordtype, a character specifying the type of the record: + *
      + *
    • '0': header record with 2 bytes address (value 0); contains usually not + * much interesting data, e.g. with the hex encoded text "HEADER";
    • + *
    • '1', '2', '3': data record with 2, 3, respectively 4-byte address that + * represents the absolute starting address of the first data byte of the + * record;
    • + *
    • '5': data record count record with a 2-byte address that represents the + * preceding number of data records; this record contains no data bytes;
    • + *
    • '7', '8', '9': termination record with a 4, 3, respectively 2-byte + * address that represents the Entry Point in the terminated data block, so e.g. + * the initial value of the program counter of a processor.
    • + *
    + *
  • + *
  • recordlength, the hex-encoded byte representing the number of + * address, data, and checksum bytes;
  • + *
  • address, the hex-encoded 2, 3, or 4-byte address, depending on the + * record type;
  • + *
  • data, the hex-encoded data bytes (usually not more than 64 per + * record, maximum 255);
  • + *
  • checksum, the one's complement of the sum of all bytes in the + * record after the recordtype.
  • + *
+ *

+ * Files with only S0, S1 and S9 records are also called to be in Motorola + * Exorcisor format. If also S2 and S8 records appear, the format is also called + * Motorola Exormax. + *

+ */ +public class SRecordReader extends AbstractReader +{ + // CONSTANTS + + private static final char PREAMBLE = 'S'; + + // VARIABLES + + private final Checksummer checksum; + + private Integer address; + private Integer dataLength; + private boolean inDataRecord; + + // CONSTRUCTORS + + /** + * Creates a new SRecordDataProvider instance. + * + * @param aReader + */ + public SRecordReader( final Reader aReader ) + { + super( aReader ); + + this.checksum = Checksum.ONES_COMPLEMENT.instance(); + } + + // METHODS + + @Override + public long getAddress() throws IOException + { + if ( this.address == null ) + { + throw new IOException( "Unexpected call to getAddress!" ); + } + return this.address; + } + + @Override + public int readByte() throws IOException + { + int ch; + + do + { + ch = readSingleByte(); + if ( ch == -1 ) + { + // End-of-file reached; return immediately! + return -1; + } + + if ( PREAMBLE == ch ) + { + // New record started... + this.inDataRecord = isDataRecord( startNewRecord() ); + } + else if ( this.dataLength != null ) + { + final int secondHexDigit = this.reader.read(); + if ( secondHexDigit == -1 ) + { + throw new IOException( "Unexpected end-of-stream!" ); + } + final char[] buf = { ( char )ch, ( char )secondHexDigit }; + + final byte dataByte = HexUtils.parseHexByte( buf ); + if ( this.dataLength == 0 ) + { + // All data-bytes returned? If so, verify the CRC we've just read... + final byte calculatedCRC = this.checksum.getResult(); + if ( dataByte != calculatedCRC ) + { + throw new IOException( "CRC Error! Expected: " + dataByte + "; got: " + calculatedCRC ); + } + } + else + { + // Decrease the number of hex-bytes we've got to read... + this.checksum.add( ( byte )dataByte ); + + this.dataLength--; + this.address++; + + if ( this.inDataRecord ) + { + return ( dataByte & 0xFF ); + } + } + } + } + while ( ch != -1 ); + + // We should never come here; it means that we've found a situation that + // isn't covered by our loop above... + throw new IOException( "Invalid Intel HEX-file!" ); + } + + /** + * @see nl.lxtreme.cpemu.util.data.impl.AbstractDataProvider#getByteOrder() + */ + @Override + protected ByteOrder getByteOrder() + { + return ByteOrder.BIG_ENDIAN; + } + + /** + * Returns the address length in number of bytes of a given SRecord-type. + * + * @param aType + * the SRecord-type to return the address length for. + * @return the address length as number of bytes. + */ + private int getAddressLength( final int aType ) + { + int result = 2; + if ( ( aType == 2 ) || ( aType == 8 ) ) + { + result = 3; + } + else if ( ( aType == 3 ) || ( aType == 7 ) ) + { + result = 4; + } + + return result; + } + + /** + * @param aType + * the integer (srecord-)type; + * @return true if the given (srecord-)type is a data record, + * otherwise false. + */ + private boolean isDataRecord( final int aType ) + { + return ( aType == 1 ) || ( aType == 2 ) || ( aType == 3 ); + } + + /** + * @param aType + * the integer (srecord-)type; + * @return true if the given (srecord-)type is a header record, + * otherwise false. + */ + private boolean isHeaderRecord( final int aType ) + { + return ( aType == 0 ); + } + + /** + * Returns whether the given (srecord-)type is valid or not. + * + * @param aType + * the integer (srecord-)type; + * @return true if the given (srecord-)type is valid, otherwise + * false. + */ + private boolean isValidType( final int aType ) + { + // (S0, S1, S2, S3, S5, S7, S8, or S9) + return ( ( aType == 0 ) || ( aType == 1 ) || ( aType == 2 ) || ( aType == 3 ) || ( aType == 5 ) || ( aType == 7 ) + || ( aType == 8 ) || ( aType == 9 ) ); + } + + private int startNewRecord() throws IOException + { + // First byte is the length of the data record... + final int type = this.reader.read() - '0'; + if ( !isValidType( type ) ) + { + throw new IOException( "Unknown type: " + type ); + } + + // recordLength is representing the number of address, data, and checksum + // bytes; + final int recordLength = HexUtils.readHexByte( this.reader ); + + final int addressLength = getAddressLength( type ); + this.address = HexUtils.readHexNumber( this.reader, addressLength ); + + // Calculate the first part of the record CRC; which is defined as the + // ones-complement of all (non-CRC) items in the record... + // record length + this.checksum.reset(); + this.checksum.add( ( byte )recordLength ); + // address length + this.checksum.addWord( ( this.address >> 16 ) & 0xFFFF ); + this.checksum.addWord( this.address & 0xFFFF ); + + // The real data length... + this.dataLength = recordLength - addressLength - 1; + + if ( this.dataLength > 0 ) + { + // Make sure NO data is only for records that should have NO data... + if ( !isDataRecord( type ) && !isHeaderRecord( type ) ) + { + throw new IOException( "Data found while record-type should not have data!" ); + } + + this.address--; + } + else if ( this.dataLength == 0 ) + { + // Make sure NO data is only for records that should have NO data... + if ( isDataRecord( type ) || isHeaderRecord( type ) ) + { + throw new IOException( "No data found while record-type should have data!" ); + } + } + + return type; + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/hex/util/ByteOrderUtils.java b/app/src/main/java/nl/lxtreme/binutils/hex/util/ByteOrderUtils.java new file mode 100644 index 00000000..ab5d9e74 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/hex/util/ByteOrderUtils.java @@ -0,0 +1,138 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2017 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.hex.util; + + +import java.nio.*; + + +/** + * In computing, endianness is the byte (and sometimes bit) ordering used to + * represent some kind of data. Typical cases are the order in which integer + * values are stored as bytes in computer memory (relative to a given memory + * addressing scheme) and the transmission order over a network or other medium. + * When specifically talking about bytes, endianness is also referred to simply + * as byte order. + */ +public class ByteOrderUtils +{ + // CONSTRUCTORS + + private ByteOrderUtils() + { + // NO-op + } + + // METHODS + + /** + * Creates a (16-bit) word value with the correct byte order. + * + * @param aMSB + * the most significant byte; + * @param aLSB + * the least significant byte. + * @return the 16-bit combination of both given bytes in the order of + * endianness. + */ + public static int createWord( final ByteOrder aByteOrder, final int aMSB, final int aLSB ) + { + if ( aByteOrder == ByteOrder.BIG_ENDIAN ) + { + return ( ( aMSB << 8 ) & 0xFF00 ) | ( aLSB & 0x00FF ); + } + + return ( ( aLSB << 8 ) & 0xFF00 ) | ( aMSB & 0x00FF ); + } + + /** + * Creates a (16-bit) word value with the correct byte order. + * + * @param aMSB + * the most significant byte; + * @param aLSB + * the least significant byte. + * @return the 16-bit combination of both given bytes in the order of + * endianness. + */ + public static int createWord( final int aMSB, final int aLSB ) + { + return createWord( ByteOrder.nativeOrder(), aMSB, aLSB ); + } + + /** + * Convenience method to create a single value using the given byte values in + * a given byte order. + * + * @param aExpectedByteOrder + * the expected byte order; + * @param aBytes + * the bytes to decode into a single value, their order depends! + * @return the word in the expected byte order. + */ + public static long decode( final ByteOrder aExpectedByteOrder, final byte... aBytes ) + { + final int byteCount = aBytes.length; + final int lastByteIdx = byteCount - 1; + + long result = 0L; + + if ( aExpectedByteOrder == ByteOrder.BIG_ENDIAN ) + { + for ( int i = 0; i < byteCount; i++ ) + { + result <<= 8; + result |= ( aBytes[i] & 0xFF ); + } + } + else if ( aExpectedByteOrder == ByteOrder.LITTLE_ENDIAN ) + { + for ( int i = lastByteIdx; i >= 0; i-- ) + { + result <<= 8; + result |= ( aBytes[i] & 0xFF ); + } + } + + return result; + } + + /** + * Switches the order of bytes of the given (16-bit) word value. + *

+ * In effect, this method casts a little-endian value to a big-endian value + * and the other way around. + *

+ * + * @param aValue + * the (16-bit) word value to switch the byte order for. + * @return the given value with the MSB & LSB switched. + */ + public static int swap16( final int aValue ) + { + return ( ( ( aValue & 0x00ff ) << 8 ) | ( ( aValue & 0xff00 ) >> 8 ) ); + } + + /** + * Switches the order of bytes of the given (32-bit) long word value. + *

+ * In effect, this method casts a little-endian value to a big-endian value + * and the other way around. + *

+ * + * @param aValue + * the (32-bit) long word value to switch the byte order for. + * @return the given value with the MSB & LSB switched. + */ + public static int swap32( final int aValue ) + { + return ( ( aValue & 0x000000FF ) << 24 ) | ( ( aValue & 0x0000FF00 ) << 8 ) // + | ( ( aValue & 0xFF000000 ) >>> 24 ) | ( ( aValue & 0x00FF0000 ) >>> 8 ); + } + +} diff --git a/app/src/main/java/nl/lxtreme/binutils/hex/util/Checksum.java b/app/src/main/java/nl/lxtreme/binutils/hex/util/Checksum.java new file mode 100644 index 00000000..d979b59d --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/hex/util/Checksum.java @@ -0,0 +1,104 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2017 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.hex.util; + + +/** + * Provides two checksum algorithms commonly used in many HEX-files. + */ +public enum Checksum +{ + /** */ + ONES_COMPLEMENT + { + @Override + public Checksummer instance( byte seed ) + { + return new BaseChecksummer( seed ) + { + @Override + public byte getResult() + { + return ( byte )( ~this.sum ); + } + }; + } + }, + /** */ + TWOS_COMPLEMENT + { + @Override + public Checksummer instance( byte seed ) + { + return new BaseChecksummer( seed ) + { + @Override + public byte getResult() + { + return ( byte )( ~this.sum + 1 ); + } + }; + } + }; + + // METHODS + + /** + * @return a new instance, cannot be null. + */ + public final Checksummer instance() + { + return instance( ( byte )0 ); + } + + /** + * @param seed + * the initial value to use for the checksum calculation. + * @return a new instance, cannot be null. + */ + public abstract Checksummer instance( byte seed ); + + /** + * Base implementation of a {@link Checksummer} shared by the various specific + * implementations. + */ + static abstract class BaseChecksummer implements Checksummer + { + protected byte sum; + + public BaseChecksummer( byte seed ) + { + this.sum = seed; + } + + @Override + public final Checksummer add( byte... aValues ) + { + for ( byte value : aValues ) + { + this.sum += value; + } + return this; + } + + @Override + public final Checksummer addWord( int value ) + { + add( ( byte )( ( value >> 8 ) & 0xFF ) ); + add( ( byte )( value & 0xFF ) ); + return this; + } + + @Override + public final Checksummer reset() + { + this.sum = 0; + return this; + } + } +} diff --git a/app/src/main/java/nl/lxtreme/binutils/hex/util/Checksummer.java b/app/src/main/java/nl/lxtreme/binutils/hex/util/Checksummer.java new file mode 100644 index 00000000..b96a8376 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/hex/util/Checksummer.java @@ -0,0 +1,51 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2017 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.hex.util; + + +public interface Checksummer +{ + + /** + * Adds a given value to the checksum. + * + * @param values + * the byte values to add to this checksum. + * @return this checksummer instance, for chaining purposes. + */ + Checksummer add( byte... values ); + + /** + * Adds a given word (16-bit) value to the checksum. + *

+ * This method is a convenience method for calling:

+   *   add((byte)(value >> 8));
+   *   add((byte)(value & 0xFF));
+   * 
+ * + * @param value + * the word value to add to this checksum. + * @return this checksummer instance, for chaining purposes. + */ + Checksummer addWord( int value ); + + /** + * Returns the resulting checksum of all previously added values. + * + * @return the resulting checksum value. + */ + byte getResult(); + + /** + * Prepares this instance for a new checksum. + * + * @return this checksummer instance, for chaining purposes. + */ + Checksummer reset(); + +} diff --git a/app/src/main/java/nl/lxtreme/binutils/hex/util/HexUtils.java b/app/src/main/java/nl/lxtreme/binutils/hex/util/HexUtils.java new file mode 100644 index 00000000..d7f26f57 --- /dev/null +++ b/app/src/main/java/nl/lxtreme/binutils/hex/util/HexUtils.java @@ -0,0 +1,130 @@ +/* + * BinUtils - access various binary formats from Java + * + * (C) Copyright 2017 - JaWi - j.w.janssen@lxtreme.nl + * + * Licensed under Apache License v2. + */ +package nl.lxtreme.binutils.hex.util; + + +import java.io.*; + + +/** + * Provides some convenience utilities to work with strings of hex digits. + */ +public final class HexUtils +{ + // CONSTRUCTORS + + /** + * Creates a new HexUtils instance. + */ + private HexUtils() + { + // NO-op + } + + // METHODS + + /** + * Parses the hex-byte in the given character sequence at the given offset. + * + * @param aInput + * the characters to parse as hex-bytes. + * @return a byte value. + * @throws IllegalArgumentException + * in case the given char sequence was null, in case + * the given input did not yield a hex-byte, or the requested offset + * is outside the boundaries of the given char sequence. + */ + public static byte parseHexByte( char[] aInput ) throws IllegalArgumentException + { + if ( aInput == null ) + { + throw new IllegalArgumentException( "Input cannot be null!" ); + } + if ( aInput.length < 2 ) + { + throw new IllegalArgumentException( "Input should be at least two characters!" ); + } + return ( byte )( ( parseHex( aInput[0] ) << 4 ) | ( parseHex( aInput[1] ) ) ); + } + + /** + * Reads two characters from the given reader and parses them as a single + * hex-value byte. + * + * @param aReader + * @return + * @throws IllegalArgumentException + * @throws IOException + */ + public static byte readHexByte( Reader aReader ) throws IllegalArgumentException, IOException + { + return ( byte )readHexNumber( aReader, 1 ); + } + + /** + * Reads a number of characters from the given reader and parses them as a + * hex-value. + * + * @param aReader + * the reader to read the data from; + * @param aByteCount + * the number of bytes to read (= 2 * amount of actual characters + * read). + * @return the parsed number. + * @throws IllegalArgumentException + * in case the given reader was null or the given byte + * count was <= 0. + * @throws IOException + * in case of I/O problems. + */ + public static int readHexNumber( Reader aReader, int aByteCount ) throws IllegalArgumentException, IOException + { + if ( aReader == null ) + { + throw new IllegalArgumentException( "Input cannot be null!" ); + } + if ( aByteCount <= 0 ) + { + throw new IllegalArgumentException( "Byte count cannot be less or equal to zero!" ); + } + + int result = 0; + int nibbleCount = 2 * aByteCount; + while ( nibbleCount-- > 0 ) + { + int hexdigit = parseHex( aReader.read() ); + result = ( result << 4 ) | hexdigit; + } + + return result; + } + + /** + * Reads four characters from the given reader and parses them as a single + * hex-value word. + * + * @param aReader + * @return + * @throws IllegalArgumentException + * @throws IOException + */ + public static int readHexWord( Reader aReader ) throws IllegalArgumentException, IOException + { + return ( readHexNumber( aReader, 2 ) & 0xFFFF ); + } + + private static int parseHex( int c ) + { + int v = Character.digit( c, 16 ); + if ( v < 0 ) + { + throw new IllegalArgumentException( "Unexpected character: " + c ); + } + return v; + } +} diff --git a/app/src/main/jniLibs/armeabi-v7a/libcapstone.so b/app/src/main/jniLibs/armeabi-v7a/libcapstone.so new file mode 100644 index 00000000..f590e370 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libcapstone.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libjnidispatch.so b/app/src/main/jniLibs/armeabi-v7a/libjnidispatch.so new file mode 100644 index 00000000..79e1fbae Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libjnidispatch.so differ diff --git a/app/src/main/jniLibs/x86/libcapstone.so b/app/src/main/jniLibs/x86/libcapstone.so new file mode 100644 index 00000000..217768bd Binary files /dev/null and b/app/src/main/jniLibs/x86/libcapstone.so differ diff --git a/app/src/main/jniLibs/x86/libjnidispatch.so b/app/src/main/jniLibs/x86/libjnidispatch.so new file mode 100644 index 00000000..4045c86b Binary files /dev/null and b/app/src/main/jniLibs/x86/libjnidispatch.so differ diff --git a/app/src/main/res/drawable-hdpi/cell_shape.xml b/app/src/main/res/drawable-hdpi/cell_shape.xml new file mode 100644 index 00000000..e1cefa0e --- /dev/null +++ b/app/src/main/res/drawable-hdpi/cell_shape.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/app/src/main/res/drawable/colorpickerview__btn_background.xml b/app/src/main/res/drawable/colorpickerview__btn_background.xml new file mode 100644 index 00000000..f90c1881 --- /dev/null +++ b/app/src/main/res/drawable/colorpickerview__btn_background.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/colorpickerview__btn_background_pressed.xml b/app/src/main/res/drawable/colorpickerview__btn_background_pressed.xml new file mode 100644 index 00000000..a765a26b --- /dev/null +++ b/app/src/main/res/drawable/colorpickerview__btn_background_pressed.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_colorpicker_dialog.xml b/app/src/main/res/layout/activity_colorpicker_dialog.xml new file mode 100644 index 00000000..c77bf8fe --- /dev/null +++ b/app/src/main/res/layout/activity_colorpicker_dialog.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +