EfuReader.java 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. package epson.maintain;
  2. import android.support.media.ExifInterface;
  3. import androidx.annotation.NonNull;
  4. import androidx.annotation.Nullable;
  5. import java.io.BufferedOutputStream;
  6. import java.io.ByteArrayOutputStream;
  7. import java.io.Closeable;
  8. import java.io.File;
  9. import java.io.FileNotFoundException;
  10. import java.io.IOException;
  11. import java.io.RandomAccessFile;
  12. import java.nio.charset.Charset;
  13. import java.util.Arrays;
  14. import java.util.HashMap;
  15. import java.util.regex.Matcher;
  16. import java.util.regex.Pattern;
  17. import org.apache.commons.lang.CharEncoding;
  18. public class EfuReader {
  19. /* JADX WARNING: Removed duplicated region for block: B:35:0x005d */
  20. /* JADX WARNING: Removed duplicated region for block: B:37:0x0062 A[SYNTHETIC, Splitter:B:37:0x0062] */
  21. /* Code decompiled incorrectly, please refer to instructions dump. */
  22. public static void unzipOnlyOneEntry(@android.support.annotation.NonNull java.lang.String r3, @android.support.annotation.NonNull java.lang.String r4) throws java.io.IOException {
  23. throw new UnsupportedOperationException("Method not decompiled: epson.maintain.EfuReader.unzipOnlyOneEntry(java.lang.String, java.lang.String):void");
  24. }
  25. /* JADX WARNING: Removed duplicated region for block: B:22:0x0031 */
  26. /* Code decompiled incorrectly, please refer to instructions dump. */
  27. public void writeOnlyOneFirmwareData(java.io.File r3, java.io.File r4) throws java.io.IOException {
  28. throw new UnsupportedOperationException("Method not decompiled: epson.maintain.EfuReader.writeOnlyOneFirmwareData(java.io.File, java.io.File):void");
  29. }
  30. private boolean checkHeaderData(@NonNull RcxFileReader rcxFileReader) {
  31. String sectionAData = rcxFileReader.getSectionAData("1");
  32. if ((!ExifInterface.GPS_MEASUREMENT_2D.equals(sectionAData) && !ExifInterface.GPS_MEASUREMENT_3D.equals(sectionAData)) || !"11".equals(rcxFileReader.getSectionAData(ExifInterface.GPS_MEASUREMENT_2D))) {
  33. return false;
  34. }
  35. String sectionAData2 = rcxFileReader.getSectionAData("16");
  36. if (sectionAData2 == null || !RcxFileReader.PATTERN_KOMMA.matcher(sectionAData2).lookingAt()) {
  37. return true;
  38. }
  39. return false;
  40. }
  41. static class RcxFileReader implements Closeable {
  42. private static final Pattern COMMENT_PATTERN = Pattern.compile("^#.*");
  43. private static final Pattern PATTERN_KEY_AND_VALUE = Pattern.compile("(\\d+)=\"(.*)\"");
  44. static final Pattern PATTERN_KOMMA = Pattern.compile(PreferencesConstants.COOKIE_DELIMITER);
  45. private static final Pattern PATTERN_SECTION_SEPARATOR = Pattern.compile("\\[([A-Z]+)\\]", 2);
  46. private static final byte[] RCX_HEADER_ID = "RCX\r\nSEIKO EPSON EpsonNet Form\r\n".getBytes(Charset.forName(CharEncoding.US_ASCII));
  47. /* renamed from: is */
  48. private RandomAccessFile f333is = null;
  49. private long mHeaderEndPosition = -1;
  50. private final HashMap<String, String> mSectionAKeyAndValue = new HashMap<>();
  51. RcxFileReader(File file) throws FileNotFoundException {
  52. f333is = new RandomAccessFile(file, "r");
  53. }
  54. public static boolean checkHeaderId(File file) {
  55. return !Arrays.equals(RCX_HEADER_ID, getFileByte(file, RCX_HEADER_ID.length));
  56. }
  57. /* JADX WARNING: Removed duplicated region for block: B:20:0x0021 A[SYNTHETIC, Splitter:B:20:0x0021] */
  58. /* JADX WARNING: Removed duplicated region for block: B:27:0x0028 A[SYNTHETIC, Splitter:B:27:0x0028] */
  59. /* Code decompiled incorrectly, please refer to instructions dump. */
  60. private static byte[] getFileByte(java.io.File r5, int r6) {
  61. throw new UnsupportedOperationException("Method not decompiled: epson.maintain.EfuReader.RcxFileReader.getFileByte(java.io.File, int):byte[]");
  62. }
  63. @Nullable
  64. public String getSectionAData(String str) {
  65. return mSectionAKeyAndValue.get(str);
  66. }
  67. /* access modifiers changed from: private */
  68. /* JADX WARNING: Code restructure failed: missing block: B:20:0x0048, code lost:
  69. return false;
  70. */
  71. /* JADX WARNING: Exception block dominator not found, dom blocks: [] */
  72. /* Code decompiled incorrectly, please refer to instructions dump. */
  73. public boolean readHeader() {
  74. throw new UnsupportedOperationException("Method not decompiled: epson.maintain.EfuReader.RcxFileReader.readHeader():boolean");
  75. }
  76. @VisibleForTesting
  77. static boolean isCommentLine(@NonNull String str) {
  78. return COMMENT_PATTERN.matcher(str).matches();
  79. }
  80. @Nullable
  81. @VisibleForTesting
  82. static String isSectionSeparator(@NonNull String str) {
  83. Matcher matcher = PATTERN_SECTION_SEPARATOR.matcher(str);
  84. if (!matcher.lookingAt()) {
  85. return null;
  86. }
  87. return matcher.group(1).toUpperCase();
  88. }
  89. @Nullable
  90. @VisibleForTesting
  91. static String[] isKeyAndValueData(@NonNull String str) {
  92. Matcher matcher = PATTERN_KEY_AND_VALUE.matcher(str);
  93. if (!matcher.lookingAt()) {
  94. return null;
  95. }
  96. return new String[]{matcher.group(1).toLowerCase(), matcher.group(2)};
  97. }
  98. @Nullable
  99. private String getNextLine(@NonNull RandomAccessFile randomAccessFile) throws IOException {
  100. ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  101. boolean z = false;
  102. while (true) {
  103. int read = randomAccessFile.read();
  104. if (read != -1) {
  105. switch (z) {
  106. case false:
  107. if (read == 13) {
  108. z = true;
  109. break;
  110. } else if (read != 12 || byteArrayOutputStream.size() != 0) {
  111. byteArrayOutputStream.write(read);
  112. break;
  113. } else {
  114. return null;
  115. }
  116. case true:
  117. if (read == 10) {
  118. return byteArrayOutputStream.toString(CharEncoding.US_ASCII);
  119. }
  120. throw new IOException();
  121. }
  122. } else {
  123. throw new IOException("file data ends");
  124. }
  125. }
  126. }
  127. public void close() {
  128. RandomAccessFile randomAccessFile = f333is;
  129. if (randomAccessFile != null) {
  130. try {
  131. randomAccessFile.close();
  132. f333is = null;
  133. } catch (IOException unused) {
  134. }
  135. }
  136. }
  137. public void writeOnlyOneFirmwareData(File file) throws IOException {
  138. writeRemainingData(this.f333is, mHeaderEndPosition, file);
  139. }
  140. /* JADX WARNING: Removed duplicated region for block: B:23:0x0034 A[Catch:{ all -> 0x002b }] */
  141. /* JADX WARNING: Removed duplicated region for block: B:26:0x003a A[SYNTHETIC, Splitter:B:26:0x003a] */
  142. @android.support.annotation.VisibleForTesting
  143. /* Code decompiled incorrectly, please refer to instructions dump. */
  144. static void writeRemainingData(@android.support.annotation.NonNull java.io.RandomAccessFile r3, long r4, @android.support.annotation.NonNull java.io.File r6) throws java.io.IOException {
  145. throw new UnsupportedOperationException("Method not decompiled: epson.maintain.EfuReader.RcxFileReader.writeRemainingData(java.io.RandomAccessFile, long, java.io.File):void");
  146. }
  147. static boolean searchDataAndWriteRemaining(@android.support.annotation.NonNull java.io.RandomAccessFile r4, long r5, @android.support.annotation.NonNull byte[] r7, @android.support.annotation.NonNull java.io.File r8) {
  148. throw new UnsupportedOperationException("Method not decompiled: epson.maintain.EfuReader.RcxFileReader.searchDataAndWriteRemaining(java.io.RandomAccessFile, long, byte[], java.io.File):boolean");
  149. }
  150. static void writeRemainingData(RandomAccessFile randomAccessFile, BufferedOutputStream bufferedOutputStream) throws IOException {
  151. byte[] bArr = new byte[4096];
  152. while (true) {
  153. int read = randomAccessFile.read(bArr);
  154. if (read != -1) {
  155. try {
  156. bufferedOutputStream.write(bArr, 0, read);
  157. } catch (IOException e) {
  158. throw new WriteException(e);
  159. }
  160. } else {
  161. return;
  162. }
  163. }
  164. }
  165. static void seekDataPosition(RandomAccessFile randomAccessFile, long j, byte[] bArr) throws IOException {
  166. randomAccessFile.seek(j);
  167. long j2 = 0;
  168. int i = 0;
  169. while (true) {
  170. int read = randomAccessFile.read();
  171. if (read == -1) {
  172. throw new IOException("data not found");
  173. } else if (i == 0) {
  174. if (read == bArr[0]) {
  175. j2 = randomAccessFile.getFilePointer();
  176. i++;
  177. }
  178. } else if (read == bArr[i]) {
  179. i++;
  180. if (i >= bArr.length) {
  181. randomAccessFile.seek(j2 - 1);
  182. return;
  183. }
  184. } else {
  185. randomAccessFile.seek(j2);
  186. i = 0;
  187. }
  188. }
  189. }
  190. }
  191. public static class WriteException extends IOException {
  192. public WriteException(Throwable th) {
  193. super(th);
  194. }
  195. public WriteException() {
  196. }
  197. }
  198. }