Skip to content

Commit 26f06cd

Browse files
committed
Fix
1 parent 6ae7cff commit 26f06cd

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

translator/src/main/java/com/mcal/elfeditor/Elf.java

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class Elf implements Closeable {
6363
public static final String SHN_TEXT = ".text";
6464
public static final String SHN_DYNAMIC = ".dynamic";
6565
public static final String SHN_SHSTRTAB = ".shstrtab";
66-
final static char ElfMagic[] = {0x7f, 'E', 'L', 'F', '\0'};
66+
final static char[] ElfMagic = {0x7f, 'E', 'L', 'F', '\0'};
6767
final static int EI_CLASS = 4; // File class
6868
final static int EI_DATA = 5; // Data encoding
6969
final static int EI_NIDENT = 16;
@@ -109,19 +109,19 @@ public class Elf implements Closeable {
109109
Elf_Sym[] mHashSymbols;
110110
byte[] mDynStringTable;
111111
byte[] mDynHashTable;
112-
private LEDataInputStream mReader;
113-
private byte[] mStringTable;
114-
private byte mRoDataStringTable[];
112+
private final LEDataInputStream mReader;
113+
private final byte[] mStringTable;
114+
private byte[] mRoDataStringTable;
115115
private int num_buckets;
116116
// semantics.
117117
private int num_chains;
118118
// These could probably be memoized.
119-
private int buckets[];
120-
private int chains[];
119+
private int[] buckets;
120+
private int[] chains;
121121
private boolean error; // 解析时是否有错误
122122

123123
public Elf(ByteArrayInputStream bis) throws IOException, UnknownFormatConversionException {
124-
dy_items = new ArrayList<ItemHelper>();
124+
dy_items = new ArrayList<>();
125125
final LEDataInputStream r = mReader = new LEDataInputStream(bis);
126126
r.readFully(e_ident);
127127
if (!checkMagic()) {
@@ -311,7 +311,7 @@ public static boolean isElf(File f) {
311311
public static byte[] readFile(File file) throws FileNotFoundException, IOException {
312312
ByteArrayOutputStream bos = new ByteArrayOutputStream();
313313
InputStream is = new FileInputStream(file);
314-
byte buffer[] = new byte[2048];
314+
byte[] buffer = new byte[2048];
315315
int count;
316316
while ((count = is.read(buffer)) != -1) {
317317
bos.write(buffer, 0, count);
@@ -361,13 +361,15 @@ private String fillString(String string, int length) {
361361
*/
362362
public int find(String str) {
363363
long hash = ELFHash(str);
364-
for (int i = buckets[(int) (hash % num_buckets)]; i != 0; i = chains[i]) {
365-
Elf_Sym ds = mDynamicSymbols[i];
366-
String string = getDynString(ds.st_name);
367-
System.out.println(string);
368-
if (string.equals(str)) {
369-
//Logger.write("str=" + str + " " + "pos=" + i + "\n");
370-
return i;
364+
if(num_buckets != 0) {
365+
for (int i = buckets[(int) (hash % num_buckets)]; i != 0; i = chains[i]) {
366+
Elf_Sym ds = mDynamicSymbols[i];
367+
String string = getDynString(ds.st_name);
368+
System.out.println(string);
369+
if (string.equals(str)) {
370+
//Logger.write("str=" + str + " " + "pos=" + i + "\n");
371+
return i;
372+
}
371373
}
372374
}
373375
return -1;
@@ -577,11 +579,11 @@ public long ELFHash(String strUri) {
577579
/**
578580
* 写入符号表hash
579581
*/
580-
private final void writeDynHash(List<ItemHelper> items, LEDataOutputStream lmOut) throws IOException {
582+
private void writeDynHash(List<ItemHelper> items, LEDataOutputStream lmOut) throws IOException {
581583
lmOut.writeInt(num_buckets);
582584
lmOut.writeInt(num_chains);
583-
int buckets_t[] = new int[num_buckets];
584-
int chains_t[] = new int[num_chains];
585+
int[] buckets_t = new int[num_buckets];
586+
int[] chains_t = new int[num_chains];
585587

586588
for (ItemHelper item : items) {
587589
//没有符号索引,说明该字符串不是符号表中的
@@ -611,7 +613,7 @@ private final void writeDynHash(List<ItemHelper> items, LEDataOutputStream lmOut
611613
*
612614
* @return 写入的实际大小
613615
***/
614-
private final long writeDynString(List<ItemHelper> items, LEDataOutputStream lmOut) throws IOException {
616+
private long writeDynString(List<ItemHelper> items, LEDataOutputStream lmOut) throws IOException {
615617

616618
long offset = 0;
617619
long len = 0;
@@ -621,7 +623,7 @@ private final long writeDynString(List<ItemHelper> items, LEDataOutputStream lmO
621623
continue;
622624
// String new_string = item.newVal;
623625
lmOut.writeByte((byte) '\0');
624-
byte data[] = old_string.getBytes();
626+
byte[] data = old_string.getBytes();
625627
offset += data.length; // 切勿调换顺序
626628

627629
if (item.newVal != null) {
@@ -695,7 +697,7 @@ private void writeExtra(long offset1, long offset2, LEDataOutputStream lmOut) th
695697
int buf_len = 2048;
696698
long remaining = len;
697699
mReader.seek(offset1);
698-
byte buffer[] = new byte[buf_len];
700+
byte[] buffer = new byte[buf_len];
699701
while (remaining != 0) {
700702
if (buf_len <= remaining) {
701703
mReader.readFully(buffer);
@@ -729,7 +731,7 @@ public void sortStrData(List<String> source, List<String> target, List<ItemHelpe
729731
}
730732
}
731733

732-
public void writeRodataBytes() throws UnsupportedEncodingException {
734+
public void writeRodataBytes() {
733735
for (ItemHelper item : ro_items) {
734736
if (item.newVal != null && !item.newVal.equals("")) {
735737
byte[] s_data = item.data;

translator/src/main/java/com/mcal/elfeditor/io/LEDataInputStream.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public byte readByte() throws IOException {
114114
*
115115
* @throws IOException
116116
*/
117-
public void readFully(byte ba[]) throws IOException {
117+
public void readFully(byte[] ba) throws IOException {
118118
dis.readFully(ba, 0, ba.length);
119119
}
120120

@@ -123,7 +123,7 @@ public void readFully(byte ba[]) throws IOException {
123123
*
124124
* @throws IOException
125125
*/
126-
public void readFully(byte ba[], int off, int len) throws IOException {
126+
public void readFully(byte[] ba, int off, int len) throws IOException {
127127
dis.readFully(ba, off, len);
128128
}
129129

translator/src/main/java/com/mcal/elfeditor/io/LEDataOutputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private void writeIntArray(int[] buf, int s, int end) throws IOException {
164164
/**
165165
* 写入一个64位的long型数据
166166
*
167-
* @param i
167+
* @param l
168168
* @throws IOException
169169
*/
170170
public void writeLong(long l) throws IOException {

0 commit comments

Comments
 (0)