Skip to content

Commit 9b9cfb7

Browse files
committed
🐛 Fix #56, fix rootpicker bug, remove redundant
1 parent e1bf2ae commit 9b9cfb7

File tree

4 files changed

+43
-62
lines changed

4 files changed

+43
-62
lines changed

app/src/main/java/com/kyhsgeekcode/disassembler/AbstractFile.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
//represents a raw file and interface
44

5+
import android.util.Log;
6+
57
import java.io.Closeable;
68
import java.io.File;
79
import java.io.FileInputStream;
@@ -56,6 +58,7 @@ public static AbstractFile createInstance(String tag) throws IOException {
5658
return new ELFUtil(file, content);
5759
} catch (Exception e) {
5860
//not an elf file. try PE parser
61+
Log.d(TAG, "Fail elfutil", e);
5962
try {
6063
return new PEFile(file, content);
6164
} catch (NotThisFormatException f) {

app/src/main/java/com/kyhsgeekcode/disassembler/ELFUtil.java

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public void ParseData() throws Exception
3939
boolean bExecutable;
4040
private String TAG = "Disassembler elfutil";
4141

42-
4342
public ELFUtil(File file, byte[] filec) throws IOException {
4443
elf = new Elf(file);
4544
setPath(file.getPath());
@@ -59,10 +58,12 @@ public void close() throws IOException {
5958
@Override
6059
public String toString() {
6160
StringBuilder sb = new StringBuilder(super.toString());
61+
sb.append(System.lineSeparator());
6262
importSymbols = getImportSymbols();
6363
for (PLT plt : importSymbols) {
6464
sb.append(plt).append(System.lineSeparator());
6565
}
66+
6667
sb.append(elf.toString())
6768
//.append(Arrays.toString(symstrings))
6869
.append("\n").append(info);
@@ -93,14 +94,12 @@ public void AfterConstructor() throws IOException {
9394
machineType = elf.header.machineType;
9495
Header header = elf.header;
9596
//assertNotNull( header );
96-
9797
if (header.entryPoint == 0) {
9898
//Log.i(TAG, "file " + file.getName() + "doesnt have entry point. currently set to 0x30");
9999
//entryPoint = 0;
100100
} else {
101101
entryPoint = header.entryPoint;
102102
}
103-
104103
//Analyze ExportAddressTable(DynSym)
105104
if (elf.dynamicTable != null) {
106105
StringBuilder sb = new StringBuilder();
@@ -120,7 +119,6 @@ public void AfterConstructor() throws IOException {
120119
{
121120
dynsymbuffer = elf.getSection(elf.getSectionHeaderByType(SectionType.DYNSYM));
122121
ElfClass elfClass=elf.header.elfClass;
123-
124122
if (elfClass.equals(ElfClass.CLASS_32))
125123
{
126124
while (dynsymbuffer.hasRemaining())
@@ -183,12 +181,10 @@ public void AfterConstructor() throws IOException {
183181
Log.e(TAG, "", e);
184182
}*/
185183
sb.append(System.lineSeparator()).append("syms;").append(System.lineSeparator());
186-
187184
if (symbols == null)
188185
symbols = new ArrayList<>();
189186
//if (dynsyms != null)
190187
//symbols.addAll(dynsyms);//I hope this statement be no longer needed in the future, as they may contain duplicates
191-
192188
// //First, Analyze Symbol table
193189
// ParseSymtab(sb, strtable);
194190
// // Second, Analyze Rela table
@@ -208,20 +204,15 @@ public int compare(Symbol p1, Symbol p2) {
208204
return 0;
209205
}
210206
});
211-
212-
for(Symbol sym: symbols) {
207+
for (Symbol sym : symbols) {
213208
sb.append(sym.toString());
214209
}
215210
/*https://docs.oracle.com/cd/E19683-01/816-1386/6m7qcoblj/index.html#chapter6-35166
216211
Symbol Values
217212
Symbol table entries for different object file types have slightly different interpretations for the st_value member.
218-
219213
In relocatable files, st_value holds alignment constraints for a symbol whose section index is SHN_COMMON.
220-
221214
In relocatable files, st_value holds a section offset for a defined symbol. st_value is an offset from the beginning of the section that st_shndx identifies.
222-
223215
In executable and shared object files, st_value holds a virtual address. To make these files' symbols more useful for the runtime linker, the section offset (file interpretation) gives way to a virtual address (memory interpretation) for which the section number is irrelevant.
224-
225216
Although the symbol table values have similar meanings for different object files, the data allow efficient access by the appropriate programs.
226217
*/
227218
/*https://github.com/torvalds/linux/blob/master/include/uapi/linux/elf.h
@@ -231,7 +222,6 @@ public int compare(Symbol p1, Symbol p2) {
231222
typedef __u32 Elf32_Off;
232223
typedef __s32 Elf32_Sword;
233224
typedef __u32 Elf32_Word;
234-
235225
/* 64-bit ELF base types.
236226
typedef __u64 Elf64_Addr;
237227
typedef __u16 Elf64_Half;
@@ -241,7 +231,6 @@ public int compare(Symbol p1, Symbol p2) {
241231
typedef __u32 Elf64_Word;
242232
typedef __u64 Elf64_Xword;
243233
typedef __s64 Elf64_Sxword;
244-
245234
*/
246235
/*https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-79797/index.html
247236
typedef struct {
@@ -252,7 +241,6 @@ public int compare(Symbol p1, Symbol p2) {
252241
unsigned char st_other;
253242
Elf32_Half st_shndx;
254243
} Elf32_Sym; size 16
255-
256244
typedef struct {
257245
Elf64_Word st_name;
258246
unsigned char st_info;
@@ -262,23 +250,19 @@ public int compare(Symbol p1, Symbol p2) {
262250
Elf64_Xword st_size;
263251
} Elf64_Sym; size 24
264252
The elements of this structure are:
265-
266253
st_name
267254
An index into the object file's symbol string table, which holds the character representations of the symbol names.
268255
If the value is nonzero, it represents a string table index that gives the symbol name.
269256
Otherwise, the symbol table entry has no name.
270-
271257
st_value
272258
The value of the associated symbol. Depending on the context, this can be an absolute value, an address, and so forth. See "Symbol Values".
273-
274259
st_size
275260
Many symbols have associated sizes. For example, a data object's size is the number of bytes contained in the object. This member holds 0 if the symbol has no size or an unknown size.
276-
277261
*/
278-
ByteBuffer relBuf = elf.getSection(elf.getSectionHeaderByType(SectionType.REL));
279-
ElfClass elfClass = elf.header.elfClass;
280-
if (elfClass.equals(ElfClass.CLASS_32)) {
281-
while (relBuf.remaining() > 0) {
262+
// ByteBuffer relBuf = elf.getSection(elf.getSectionHeaderByType(SectionType.REL));
263+
// ElfClass elfClass = elf.header.elfClass;
264+
// if (elfClass.equals(ElfClass.CLASS_32)) {
265+
// while (relBuf.remaining() > 0) {
282266
/*t y p e d e f s t r u c t {
283267
E l f 3 2 _ A d d r r _ o f f s e t ;
284268
E l f 3 2 _ W o r d r _ i n f o ;
@@ -288,17 +272,15 @@ public int compare(Symbol p1, Symbol p2) {
288272
E l f 3 2 _ W o r d r _ i n f o ;
289273
E l f 3 2 _ S w o r d r _ a d d e n d ;
290274
} E l f 3 2 _ R e l a;
291-
292275
# d e f i n e E L F 3 2 _ R _ S Y M ( i ) ( ( i ) > > 8 )
293276
# d e f i n e E L F 3 2 _ R _ T Y P E ( i ) ( ( u n s i g n e d c h a r ) ( i ) )
294277
# d e f i n e E L F 3 2 _ R _ I N F O ( s , t ) ( ( ( s ) < < 8 ) + ( u n s i g n e d c h a r ) ( t ) )
295278
*/
296-
int offset = relBuf.getInt();
297-
int info = relBuf.getInt();
298-
int symidx = info >> 8;
299-
int type = info & 0x7F;
300-
301-
Log.v(TAG, "offset=" + Integer.toHexString(offset) + "symidx=" + symidx + "&type=" + type + "&info=" + info);
279+
// int offset = relBuf.getInt();
280+
// int info = relBuf.getInt();
281+
// int symidx = info >> 8;
282+
// int type = info & 0x7F;
283+
// Log.v(TAG, "offset=" + Integer.toHexString(offset) + "symidx=" + symidx + "&type=" + type + "&info=" + info);
302284
/*
303285
Intel
304286
Name Value Field Calculation
@@ -316,7 +298,6 @@ public int compare(Symbol p1, Symbol p2) {
316298
10 word32 GOT + A - P
317299
_ __________________________________________________
318300
Tool Interface Standards (TIS) Portable Formats Specification, Version 1.1
319-
320301
ARM
321302
Code Name Type Class
322303
0 R_ARM_NONE Static Operation Miscellaneous
@@ -363,7 +344,6 @@ Tool Interface Standards (TIS) Portable Formats Specification, Version 1.1
363344
41 R_ARM_TARGET2 Static Miscellaneous
364345
42 R_ARM_PREL31 Static Data ((S + A) | T) – P
365346
ARM IHI 0044F Copyright © 2003-2009, 2012, 2014-2015 ARM Limited. All rights reserved. Page 26 of 48
366-
367347
Table 4-18, Dynamic relocations
368348
Code Relocation Comment
369349
17 (S ≠ 0) R_ARM_TLS_DTPMOD32 Resolves to the module number of the module defining the specified TLS symbol, S. (S = 0) Resolves to the module number of the current module (ie. the module containing this relocation).
@@ -377,12 +357,12 @@ Tool Interface Standards (TIS) Portable Formats Specification, Version 1.1
377357
23 R_ARM_RELATIVE (S ≠ 0) B(S) resolves to the difference between the address at which the segment defining the symbol S was loaded and the address at which it was linked. l
378358
(S = 0) B(S) resolves to the difference between the address at which the segment being relocated was loaded and the address at which it was linked
379359
*/
380-
}
381-
}
360+
// }
361+
// }
382362
//Now prepare IAT(PLT/GOT)
383363
//get .got
384-
for (SectionHeader hdr : sections) {
385-
if (".plt".equalsIgnoreCase(hdr.getName())) {
364+
// for (SectionHeader hdr : sections) {
365+
// if (".plt".equalsIgnoreCase(hdr.getName())) {
386366
//plt is code
387367
// 000173ec __android_log_print@plt:
388368
// 173ec: e28fc600 add ip, pc, #0, 12 ; ip!=pc?
@@ -393,13 +373,11 @@ Tool Interface Standards (TIS) Portable Formats Specification, Version 1.1
393373
// 173fc: e28cca11 add ip, ip, #69632
394374
// 17400: e5bcf9ec ldr pc, [ip, #2540]!
395375
// ...
396-
ByteBuffer buf = elf.getSection(hdr);
397-
398-
}
399-
}
400-
dynsymbuffer = elf.getSection(elf.getSectionHeaderByType(SectionType.PROGBITS));
376+
// ByteBuffer buf = elf.getSection(hdr);
377+
// }
378+
// }
379+
// dynsymbuffer = elf.getSection(elf.getSectionHeaderByType(SectionType.PROGBITS));
401380
// importSymbols=ParsePLT(path);
402-
403381
info = sb.toString();
404382
//Log.i(TAG, "info=" + info);
405383
}
@@ -420,11 +398,11 @@ Tool Interface Standards (TIS) Portable Formats Specification, Version 1.1
420398
}
421399
}
422400
}
401+
423402
//private long codeOffset=0L;
424403
//private long codeLimit=0L;
425404
//private long codeVirtualAddress=0L;
426405
//String[] symstrings;
427-
428406
private void ParseRela(ArrayList<Rela> relas) throws IOException {
429407
SectionHeader relaSec = elf.getSectionHeaderByType(SectionType.RELA);
430408
if (relaSec != null) {
@@ -520,7 +498,6 @@ public void addSymbol(Symbol symbol) {
520498
symbols.add(symbol);
521499
}
522500
}
523-
524501
// public static int getWord(byte a, byte b, byte c, byte d)
525502
// {
526503
// return ((int)a << 24) & ((int)b << 16) & ((int)c << 8) & d;
@@ -544,7 +521,6 @@ public ELFUtil(File file) throws Exception
544521
counter++;
545522
}
546523
}
547-
548524
ParseData();
549525
}
550526
public ELFUtil(byte[] bytes) throws Exception

app/src/main/java/com/kyhsgeekcode/disassembler/MainActivity.kt

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,23 +1868,25 @@ class MainActivity : AppCompatActivity(), View.OnClickListener, OnProjectOpenLis
18681868
object Utils {
18691869
@JvmStatic
18701870
@Throws(IOException::class)
1871-
fun getBytes(`is`: InputStream): ByteArray {
1872-
var len: Int
1873-
var size = 1024
1874-
var buf: ByteArray
1875-
if (`is` is ByteArrayInputStream) {
1876-
size = `is`.available()
1877-
buf = ByteArray(size)
1878-
len = `is`.read(buf, 0, size)
1879-
} else {
1880-
val bos = ByteArrayOutputStream()
1881-
buf = ByteArray(size)
1882-
while (`is`.read(buf, 0, size).also { len = it } != -1) bos.write(buf, 0, len)
1883-
buf = bos.toByteArray()
1884-
}
1885-
`is`.close()
1886-
return buf
1871+
fun getBytes(inputStream: InputStream): ByteArray {
1872+
return inputStream.use{ it.readBytes()}
18871873
}
1874+
// var len: Int
1875+
// var size = 1024
1876+
// var buf: ByteArray
1877+
// if (inputStream is ByteArrayInputStream) {
1878+
// size = inputStream.available()
1879+
// buf = ByteArray(size)
1880+
// len = inputStream.read(buf, 0, size)
1881+
// } else {
1882+
// val bos = ByteArrayOutputStream()
1883+
// buf = ByteArray(size)
1884+
// while (inputStream.read(buf, 0, size).also { len = it } != -1) bos.write(buf, 0, len)
1885+
// buf = bos.toByteArray()
1886+
// }
1887+
// inputStream.close()
1888+
// return buf
1889+
// }
18881890
}
18891891

18901892
// internal inner class SaveDBAsync : AsyncTask<DatabaseHelper?, Int?, Void?>() {

app/src/main/java/com/kyhsgeekcode/rootpicker/FileSelectorActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void onCreate(Bundle savedInstanceState) {
8585
fos.close();
8686
lspath = dest.getAbsolutePath();
8787
try {
88-
ProcessBuilder builder = new ProcessBuilder("su");
88+
ProcessBuilder builder = new ProcessBuilder("sh");
8989
builder.redirectErrorStream(true);
9090
java.lang.Process shProcess = builder.start();
9191
DataOutputStream os = new DataOutputStream(shProcess.getOutputStream());

0 commit comments

Comments
 (0)