EfuReader.java 9.8 KB

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