patchFile.write("7\n");  l = lcs2(original.debugInfoItems, update.debugInfoItems, typeIndexMap, stringIndexMap); it = l.listIterator(l.size()); c = it.previous(); long[] debugInfoIndexMap = new long[10000]; fileIndex = 0; mapIndex = 0; while (true) { int val = c.type; int nx = c.type; int count = 0; while (nx == val) { if (nx == 0) { debugInfoIndexMap[mapIndex++] = fileIndex++; } else if (nx == 1) { dataFile.write(c.data); ++fileIndex; } else if (nx == 2) { debugInfoIndexMap[mapIndex++] = -1; }  ++count;  if (!it.hasPrevious()) break;  c = it.previous(); nx = c.type; }  patchFile.write(((Integer)val).toString() + " " + ((Integer)count).toString() + "\n");  if (!it.hasPrevious()) { if(nx != val) { if (nx == 0) { debugInfoIndexMap[mapIndex++] = fileIndex++; } else if (nx == 1) { dataFile.write(c.data); ++fileIndex; } else if (nx == 2) { debugInfoIndexMap[mapIndex++] = -1; } patchFile.write(((Integer)nx).toString() + " " + "1\n"); } break; } }
	public static void main(String[] args) {		DexOriginalFile original = new DexOriginalFile();		DexOriginalFile update = new DexOriginalFile();		original.setDumpOff();		update.setDumpOff();		RandomAccessFile raf = null;		try {			raf = new RandomAccessFile("testfiles/connect2.dex", "r");		} catch (FileNotFoundException e) {			e.printStackTrace();		}		original.setRandomAccessFile(raf);		original.parse();		try {			raf = new RandomAccessFile("testfiles/connect3.dex", "r");		} catch (FileNotFoundException e) {			e.printStackTrace();		}		update.setRandomAccessFile(raf);		update.parse();				GeneratedFile patchFile = new GeneratedFile("out/connect.patch");		GeneratedFile dataFile = new GeneratedFile("out/data.patch");		patchFile.write(((Long)update.getStringDataItemOffset()).toString() +"\n");		patchFile.write(((Long)update.getTypeListOffset()).toString() +"\n");				String[] data1 = { "a", "b", "c", "d", "e", "f", "g" };		String[] data2 = { "a", "f", "b", "c", "e", "f", "g", "s" };		List<PCommand> l = lcs2(original.stringData, update.stringData);		//List<PCommand> l = lcs2(data1, data2);				// string_data_item		ListIterator<PCommand> it = l.listIterator(l.size());		PCommand c = it.previous();		long[] stringIndexMap = new long[10000];		int fileIndex = 0;		int mapIndex = 0;		while (true) {			int val = c.type;			int nx = c.type;			int count = 0;			while (nx == val) {				if (nx == 0) {					stringIndexMap[mapIndex++] = fileIndex++;				} else if (nx == 1) {					dataFile.write(c.data);					dataFile.write("\n");					++fileIndex;				} else if (nx == 2) {					stringIndexMap[mapIndex++] = -1;				}				++count;								if (!it.hasPrevious())					break;								c = it.previous();				nx = c.type;			}						patchFile.write(((Integer)val).toString() + " " + ((Integer)count).toString() + "\n");						if (!it.hasPrevious()) {				if(nx != val) {					if (nx == 0) {						stringIndexMap[mapIndex++] = fileIndex++;					} else if (nx == 1) {						dataFile.write(c.data);						dataFile.write("\n");						++fileIndex;					} else if (nx == 2) {						stringIndexMap[mapIndex++] = -1;					}					patchFile.write(((Integer)nx).toString() + " " + "1\n");				}				break;			}		}				patchFile.write("4\n");				// type_id		l = lcs2(original.typeIds, update.typeIds, original.stringData, update.stringData);		it = l.listIterator(l.size());		c = it.previous();		long[] typeIndexMap = new long[10000];		fileIndex = 0;		mapIndex = 0;		while (true) {			int val = c.type;			int nx = c.type;			int count = 0;			while (nx == val) {				if (nx == 0) {					typeIndexMap[mapIndex++] = fileIndex++;				} else if (nx == 1) {					dataFile.write(((Integer)c.index).toString());					dataFile.write("\n");					++fileIndex;				} else if (nx == 2) {					typeIndexMap[mapIndex++] = -1;				}								++count;								if (!it.hasPrevious())					break;								c = it.previous();				nx = c.type;			}						patchFile.write(((Integer)val).toString() + " " + ((Integer)count).toString() + "\n");						if (!it.hasPrevious()) {				if(nx != val) {					if (nx == 0) {						typeIndexMap[mapIndex++] = fileIndex++;					} else if (nx == 1) {						dataFile.write(((Integer)c.index).toString());						dataFile.write("\n");						++fileIndex;					} else if (nx == 2) {						typeIndexMap[mapIndex++] = -1;					}					patchFile.write(((Integer)nx).toString() + " " + "1\n");				}				break;			}		}				patchFile.write("5\n");				// field_id_item		l = lcs2(original.fieldIds, update.fieldIds, original.typeIds, update.typeIds, original.stringData, update.stringData);		it = l.listIterator(l.size());		c = it.previous();		while (true) {			int val = c.type;			int nx = c.type;			int count = 0;			while (nx == val) {				if(nx == 1) {					dataFile.write(c.data);				}								++count;								if (!it.hasPrevious())					break;								c = it.previous();				nx = c.type;			}						patchFile.write(((Integer)val).toString() + " " + ((Integer)count).toString() + "\n");						if (!it.hasPrevious()) {				if(nx != val) {					if(nx == 1) {						dataFile.write(c.data);					}					patchFile.write(((Integer)nx).toString() + " " + "1\n");				}				break;			}		}				patchFile.write("6\n");				// type_list		l = lcs2(original.typeLists, update.typeLists, original.typeIds, update.typeIds, original.stringData, update.stringData);		it = l.listIterator(l.size());		c = it.previous();		long[] typeListIndexMap = new long[10000];		fileIndex = 0;		mapIndex = 0;		while (true) {			int val = c.type;			int nx = c.type;			int count = 0;			while (nx == val) {				if(nx == 0) {					typeListIndexMap[mapIndex++] = fileIndex++;				} else if(nx == 1) {					dataFile.write(c.data);					++fileIndex;				} else if(nx == 2) {					typeListIndexMap[mapIndex++] = -1;				}								++count;								if (!it.hasPrevious())					break;								c = it.previous();				nx = c.type;			}						patchFile.write(((Integer)val).toString() + " " + ((Integer)count).toString() + "\n");						if (!it.hasPrevious()) {				if(nx != val) {					if(nx == 0) {						typeListIndexMap[mapIndex++] = fileIndex++;					} else if(nx == 1) {						dataFile.write(c.data);						++fileIndex;					} else if(nx == 2) {						typeListIndexMap[mapIndex++] = -1;					}					patchFile.write(((Integer)nx).toString() + " " + "1\n");				}				break;			}		}				patchFile.write("7\n");		// proto_id		l = lcs2(original.protoIds, update.protoIds, typeListIndexMap, typeIndexMap, stringIndexMap);		it = l.listIterator(l.size());		c = it.previous();		long[] protoIndexMap = new long[10000];		fileIndex = 0;		mapIndex = 0;		while (true) {			int val = c.type;			int nx = c.type;			int count = 0;			while (nx == val) {				if (nx == 0) {					protoIndexMap[mapIndex++] = fileIndex++;				} else if (nx == 1) {					dataFile.write(c.data);					++fileIndex;				} else if (nx == 2) {					protoIndexMap[mapIndex++] = -1;				}								++count;								if (!it.hasPrevious())					break;								c = it.previous();				nx = c.type;			}						patchFile.write(((Integer)val).toString() + " " + ((Integer)count).toString() + "\n");						if (!it.hasPrevious()) {				if(nx != val) {					if (nx == 0) {						protoIndexMap[mapIndex++] = fileIndex++;					} else if (nx == 1) {						dataFile.write(c.data);						++fileIndex;					} else if (nx == 2) {						protoIndexMap[mapIndex++] = -1;					}					patchFile.write(((Integer)nx).toString() + " " + "1\n");				}				break;			}		}				patchFile.write("7\n");		// method_id		l = lcs2(original.methodIds, update.methodIds, typeIndexMap, protoIndexMap, stringIndexMap);		it = l.listIterator(l.size());		c = it.previous();		long[] methodIndexMap = new long[10000];		fileIndex = 0;		mapIndex = 0;		while (true) {			int val = c.type;			int nx = c.type;			int count = 0;			while (nx == val) {				if (nx == 0) {					methodIndexMap[mapIndex++] = fileIndex++;				} else if (nx == 1) {					dataFile.write(c.data);					++fileIndex;				} else if (nx == 2) {					methodIndexMap[mapIndex++] = -1;				}								++count;								if (!it.hasPrevious())					break;								c = it.previous();				nx = c.type;			}						patchFile.write(((Integer)val).toString() + " " + ((Integer)count).toString() + "\n");						if (!it.hasPrevious()) {				if(nx != val) {					if (nx == 0) {						methodIndexMap[mapIndex++] = fileIndex++;					} else if (nx == 1) {						dataFile.write(c.data);						++fileIndex;					} else if (nx == 2) {						methodIndexMap[mapIndex++] = -1;					}					patchFile.write(((Integer)nx).toString() + " " + "1\n");				}				break;			}		}				System.out.print("done");	}