-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04d768a
commit 01b13aa
Showing
36 changed files
with
1,187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
plugins { | ||
id 'com.android.application' | ||
} | ||
|
||
android { | ||
namespace 'com.mastergames.elfreader' | ||
compileSdk 33 | ||
|
||
defaultConfig { | ||
applicationId "com.mastergames.elfreader" | ||
minSdk 21 | ||
targetSdk 33 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.appcompat:appcompat:1.6.1' | ||
implementation 'com.google.android.material:material:1.8.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.5' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/com/mastergames/elfreader/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.mastergames.elfreader; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); | ||
assertEquals("com.mastergames.elfreader", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" | ||
tools:ignore="ScopedStorage" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.ELFReader" | ||
tools:targetApi="31"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
189 changes: 189 additions & 0 deletions
189
app/src/main/java/com/mastergames/elfreader/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
package com.mastergames.elfreader; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.core.app.ActivityCompat; | ||
import androidx.core.content.ContextCompat; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.content.pm.PackageManager; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import org.w3c.dom.Text; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
private EditText directoryOfFile; | ||
private Button readFile; | ||
private TextView archiveIsElf; | ||
private TextView architectureElf; | ||
private TextView elfEndian; | ||
private TextView elfABI; | ||
private TextView elfVersion; | ||
private TextView typeIsElfVersionABI; | ||
private TextView typeIsElf; | ||
private TextView typeIsElfPad; | ||
private Button clearOutputs; | ||
|
||
@SuppressLint("MissingInflatedId") | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
directoryOfFile = findViewById(R.id.directoryoffile); | ||
readFile = findViewById(R.id.button_readfile); | ||
archiveIsElf = findViewById(R.id.isELForNot); | ||
architectureElf = findViewById(R.id.archictureiself); | ||
elfEndian = findViewById(R.id.elfEndian); | ||
elfABI = findViewById(R.id.elfAbi); | ||
elfVersion = findViewById(R.id.elfVersion); | ||
typeIsElf = findViewById(R.id.typeiself); | ||
clearOutputs = findViewById(R.id.clearoutput); | ||
|
||
readFile.setOnClickListener(new View.OnClickListener() { | ||
@SuppressLint("SetTextI18n") | ||
@Override | ||
public void onClick(View v) { | ||
try { | ||
// Open the .so file and create a FileInputStream | ||
String fileDirectory = directoryOfFile.getText().toString(); | ||
File file = new File(fileDirectory); | ||
FileInputStream fis = new FileInputStream(file); | ||
|
||
// Reading the first 52 bytes to get the ELF header | ||
byte[] header = new byte[52]; | ||
fis.read(header); | ||
|
||
// Get the ELF identifier | ||
String magic = new String(header, 0, 4); | ||
if (!magic.equals("\u007fELF")) { | ||
archiveIsElf.setText("EI_MAG : " + "Unknown"); | ||
} else { | ||
archiveIsElf.setText("EI_MAG : " + "0x7fELF (ELF)"); | ||
} | ||
|
||
// Get elf class (32-bit or 64-bit) | ||
int elfClass = header[4]; | ||
if (elfClass == 1) { | ||
architectureElf.setText("EI_CLASS : " + "ELFCLASS32 (32-bit)"); | ||
} else if (elfClass == 2) { | ||
architectureElf.setText("EI_CLASS : " + "ELFCLASS64 (64-bit)"); | ||
} else { | ||
architectureElf.setText("EI_CLASS : " + "ELFCLASSNONE (This class is invalid)"); | ||
} | ||
|
||
// Get data encoding | ||
int dataEncoding = header[5]; | ||
if (dataEncoding == 1) { | ||
elfEndian.setText("EI_DATA : " + "ELFDATA2LSB (Little-endian)"); | ||
} else if (dataEncoding == 2) { | ||
elfEndian.setText("EI_DATA : " + "ELFDATA2MSB (Big-endian)"); | ||
} else { | ||
elfEndian.setText("EI_DATA : " + "ELFDATANONE (Unknown data format)"); | ||
} | ||
|
||
// Get the ELF version | ||
int version = header[6]; | ||
if (version == 1) { | ||
elfVersion.setText("EI_VERSION : " + "EV_CURRENT (Current version)"); | ||
} else { | ||
elfVersion.setText("EI_VERSION : " + "EV_NONE (Invalid version)"); | ||
} | ||
|
||
// Get the value of the EI_OSABI | ||
byte osAbi = header[7]; | ||
String osAbiStr; | ||
switch (osAbi) { | ||
case 0: | ||
osAbiStr = "ELFOSABI_NONE/ELFOSABI_SYSV (UNIX System V ABI)"; | ||
break; | ||
case 1: | ||
osAbiStr = "ELFOSABI_HPUX (HP-UX ABI)"; | ||
break; | ||
case 2: | ||
osAbiStr = "ELFOSABI_NETBSD (NetBSD ABI)"; | ||
break; | ||
case 3: | ||
osAbiStr = "ELFOSABI_LINUX (Linux ABI)"; | ||
break; | ||
case 6: | ||
osAbiStr = "ELFOSABI_SOLARIS (Solaris ABI)"; | ||
break; | ||
case 8: | ||
osAbiStr = "ELFOSABI_IRIX (IRIX ABI)"; | ||
break; | ||
case 9: | ||
osAbiStr = "ELFOSABI_FREEBSD (FreeBSD ABI)"; | ||
break; | ||
case 10: | ||
osAbiStr = "ELFOSABI_TRU64 (TRU64 UNIX ABI)"; | ||
break; | ||
case 97: | ||
osAbiStr = "ELFOSABI_ARM (ARM architecture ABI)"; | ||
break; | ||
case (byte) 255: | ||
osAbiStr = "ELFOSABI_STANDALONE (Stand-alone (embedded) ABI)"; | ||
break; | ||
default: | ||
osAbiStr = "Unknown"; | ||
break; | ||
} | ||
elfABI.setText("EI_OSABI : " + osAbiStr); | ||
|
||
// Get ELF file type | ||
int type = header[16] + (header[17] << 8); | ||
String typeStr = ""; | ||
switch (type) { | ||
case 1: | ||
typeStr = "ET_REL (A Relocatable file)"; | ||
break; | ||
case 2: | ||
typeStr = "ET_EXEC (An Executable file)"; | ||
break; | ||
case 3: | ||
typeStr = "ET_DYN (A Shared object file)"; | ||
break; | ||
case 4: | ||
typeStr = "ET_CORE (A Core file)"; | ||
break; | ||
default: | ||
typeStr = "ET_NONE (An unknown type)"; | ||
break; | ||
} | ||
typeIsElf.setText("ET : " + typeStr); | ||
|
||
// Close FileInputStream | ||
fis.close(); | ||
} catch (FileNotFoundException e) { | ||
Toast.makeText(getApplicationContext(), "The file does not exist", Toast.LENGTH_LONG).show(); | ||
} catch (IOException e) { | ||
Toast.makeText(getApplicationContext(), "Failed to read the file", Toast.LENGTH_LONG).show(); | ||
} | ||
} | ||
}); | ||
|
||
clearOutputs.setOnClickListener(new View.OnClickListener() { | ||
@SuppressLint("SetTextI18n") | ||
@Override | ||
public void onClick(View v) { | ||
archiveIsElf.setText("EI_MAG : "); | ||
architectureElf.setText("EI_CLASS : "); | ||
elfEndian.setText("EI_DATA : "); | ||
elfVersion.setText("EI_VERSION : "); | ||
elfABI.setText("EI_OSABI : "); | ||
typeIsElf.setText("ET : "); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:aapt="http://schemas.android.com/aapt" | ||
android:width="108dp" | ||
android:height="108dp" | ||
android:viewportWidth="108" | ||
android:viewportHeight="108"> | ||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z"> | ||
<aapt:attr name="android:fillColor"> | ||
<gradient | ||
android:endX="85.84757" | ||
android:endY="92.4963" | ||
android:startX="42.9492" | ||
android:startY="49.59793" | ||
android:type="linear"> | ||
<item | ||
android:color="#44000000" | ||
android:offset="0.0" /> | ||
<item | ||
android:color="#00000000" | ||
android:offset="1.0" /> | ||
</gradient> | ||
</aapt:attr> | ||
</path> | ||
<path | ||
android:fillColor="#FFFFFF" | ||
android:fillType="nonZero" | ||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z" | ||
android:strokeWidth="1" | ||
android:strokeColor="#00000000" /> | ||
</vector> |
Oops, something went wrong.