EfuReader.java 9.7 KB

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