Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 830c052

Browse files
authored
Merge pull request #111 from google/soname-textrel-elf
fix bug #109
2 parents 9d314f8 + f135d82 commit 830c052

File tree

4 files changed

+77
-5
lines changed

4 files changed

+77
-5
lines changed

ClassySharkWS/src/com/google/classyshark/silverghost/translator/apk/ApkTranslator.java

+20-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,15 @@ public void apply() {
8282
elements.add(element);
8383
}
8484

85-
ELEMENT element = new ELEMENT("\nNative Libraries\n",
85+
ELEMENT element = new ELEMENT("\nDynamic Symbol Errors", TAG.DOCUMENT);
86+
elements.add(element);
87+
88+
for (String error : apkAnalysis.errors) {
89+
element = new ELEMENT("\n" + error, TAG.DOCUMENT);
90+
elements.add(element);
91+
}
92+
93+
element = new ELEMENT("\n\n\nNative Libraries\n",
8694
TAG.DOCUMENT);
8795

8896
elements.add(element);
@@ -103,12 +111,14 @@ public void apply() {
103111
List<String> nativeLibNames = extractLibNames(apkAnalysis.nativeLibs);
104112
for (String nativeLib : sortedNativeDependencies) {
105113
element = new ELEMENT(nativeLib + " " +
106-
PrivateNativeLibsInspector.check(nativeLib, nativeLibNames) + "\n", TAG.DOCUMENT);
114+
PrivateNativeLibsInspector.check(nativeLib, nativeLibNames) +
115+
"\n", TAG.DOCUMENT);
107116
elements.add(element);
108117
}
109-
}
110118

111119

120+
}
121+
112122
private static List<String> extractLibNames(List<String> nativeLibs) {
113123
// libs/x86/lib.so\n ==> libs.so
114124
LinkedList<String> result = new LinkedList<>();
@@ -191,6 +201,7 @@ private static class ApkAnalysis {
191201
public List<String> nativeLibs = new ArrayList<>();
192202
public TreeSet<DexData> dexes = new TreeSet<>();
193203
public TreeSet<String> nativeDependencies = new TreeSet<>();
204+
public List<String> errors = new LinkedList<>();
194205

195206
public String toString() {
196207
return dexes + "\n\n"
@@ -236,6 +247,12 @@ private static ApkAnalysis doInspect(File binaryArchiveFile) {
236247
result.nativeDependencies.add(dependency);
237248
}
238249

250+
DynamicSymbolsInspector dsi = new DynamicSymbolsInspector(dependenciesReader);
251+
252+
if (dsi.areErrors()) {
253+
result.errors.add(zipEntry.getName() + " " + dsi.getErrors());
254+
}
255+
239256
result.nativeLibs.add(zipEntry.getName() + "\n");
240257
}
241258
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2015 Google, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.classyshark.silverghost.translator.apk;
18+
19+
import java.io.IOException;
20+
import nl.lxtreme.binutils.elf.Elf;
21+
22+
public class DynamicSymbolsInspector {
23+
24+
private Elf elf;
25+
private String errors = "";
26+
private boolean areErrors = false;
27+
28+
public DynamicSymbolsInspector(Elf elf) {
29+
this.elf = elf;
30+
inspect();
31+
}
32+
33+
public boolean areErrors() {
34+
return areErrors;
35+
}
36+
37+
public String getErrors() {
38+
return this.errors;
39+
}
40+
41+
private void inspect() {
42+
try {
43+
if (!elf.isSoname()) {
44+
errors += " missing SONAME ";
45+
areErrors = true;
46+
}
47+
48+
if (elf.isTextRel()) {
49+
errors += " text relocations found ";
50+
areErrors = true;
51+
}
52+
} catch (IOException e) {
53+
e.printStackTrace();
54+
}
55+
}
56+
}

ClassySharkWS/src/com/google/classyshark/silverghost/translator/elf/ElfTranslator.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ public List<String> getDependencies() {
102102

103103
// TODO currently support only dexes, here is how to do for jar
104104
// TODO https://github.com/adamheinrich/native-utils/blob/master/NativeUtils.java
105-
public static File extractElf(String elfName,
106-
File apkFile) {
105+
public static File extractElf(String elfName, File apkFile) {
107106
File file = new File("classes.dex");
108107
ZipInputStream zipFile;
109108
try {

third_party/java-binutils.jar

-2.43 KB
Binary file not shown.

0 commit comments

Comments
 (0)