Skip to content

Commit

Permalink
[DEX] Check EOF before reading
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Dec 5, 2024
1 parent 9f7b127 commit a46891a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/main/java/com/reandroid/dex/smali/SmaliParseException.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,22 @@ public static void expect(SmaliReader reader, SmaliDirective expect, boolean end
throw exception;
}
public static void expect(SmaliReader reader, char ch) throws IOException{
if(reader.readASCII() == ch){
if (reader.skipIfChar(ch)) {
return;
}
reader.skip(-1);
String message = "expecting '" + ch + "'";
SmaliParseException exception = new SmaliParseException(message, reader);
sanitizeStackTrace(exception);
throw exception;
}
public static char expect(SmaliReader reader, char ch1, char ch2) throws IOException{
char ch = reader.readASCII();
if(ch == ch1 || ch == ch2){
return ch;
public static char expect(SmaliReader reader, char ch1, char ch2) throws IOException {
if (!reader.finished()) {
char ch = reader.readASCII();
if (ch == ch1 || ch == ch2) {
return ch;
}
reader.skip(-1);
}
reader.skip(-1);
String message = "expecting '" + ch1 + "', or '" + ch2 + "'";
SmaliParseException exception = new SmaliParseException(message, reader);
sanitizeStackTrace(exception);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/reandroid/dex/smali/SmaliReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,14 @@ public boolean skipSpaces(){
}
return false;
}
public boolean skipIfChar(char c) {
int position = position();
if (!finished() && getASCII(position) == c) {
position(position + 1);
return true;
}
return false;
}
public void nextLine(){
int i = indexOf('\n');
if(i < 0){
Expand Down

0 comments on commit a46891a

Please sign in to comment.