Je suis nouveau sur Android et j'ai un projet qui contient une .so
fichier. Dans un .java
cette librairie est utilisée et je veux la lire. .so
fichier.
Réponse
Trop de publicités?
Jitendra
Points
52
Oui, vous pouvez le lire en utilisant ReadElf.java. https://Android.googlesource.com/platform/cts/+/17fcb6c/libs/deviceutil/src/Android/cts/util/ReadElf.java .
Le code ci-dessous lit le fichier .SO et détermine le type d'architecture.
Code complet- https://github.com/robust12/ArchFinderBLStack.git
public class MainActivity extends AppCompatActivity {
private final String TAG = "MainActivity";
private final String ARMV7ABI = "armeabi-v7a";
private final String X86 = "x86";
private final String MIPS = "mips";
private final String X86_64 = "x86_64";
private final String ARM64_V8 = "arm64-v8a";
private final String ARMABI = "armeabi";
private String result = "";
private File[] libFilesArray;
private int request_code = 1;
HashMap<Integer, String> typeMap;
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textViewId);
typeMap = new HashMap<>();
initializeMap();
readFilesFromStorage();
textView.setText(result);
textView.setMovementMethod(new ScrollingMovementMethod());
}
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
private void readFilesFromStorage() throws NullPointerException {
String filePath = Environment.getExternalStorageDirectory() + "/test-input/";
File readSOFILE = new File(filePath);
if(!readSOFILE.exists()) {
result = getString(R.string.path_not_exist);
return;
}
libFilesArray = readSOFILE.listFiles();
if(libFilesArray == null) {
result = getString(R.string.error);
return;
}
findAbiType();
}
private void findAbiType() {
int count = libFilesArray.length;
int soCount = 0;
result = "";
Log.e(TAG, "Count is " + count);
for (int i = 0; i < count; i++) {
try {
if (libFilesArray[i].isFile()) {
int type = ReadElf.read(libFilesArray[i]).getType();
if (type == 3) {
soCount++;
int archCode = ReadElf.e_machine;
result += libFilesArray[i].getName() + " - " + typeMap.get(archCode) + "\n\n";
Log.e(TAG, "Code is " + archCode);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
if(soCount != 0) {
result += "Total Libs Count: " + soCount + "\n\n";
} else{
result = getString(R.string.incorrect_type_libs);
}
}
private void initializeMap() {
typeMap.put(40, ARMV7ABI);
typeMap.put(3, X86);
typeMap.put(8, MIPS);
typeMap.put(62, X86_64);
typeMap.put(183, ARM64_V8);
typeMap.put(164, ARMABI);
}
}
- Réponses précédentes
- Plus de réponses