private static string getmacaddress() { if (!File.Exists(variables.filename1)) { return("nomac"); } byte[] smc_config; bool big_block = false; bool corona = false; int block_offset; smc_config = Nand.Nand.getsmcconfig(variables.filename1, ref big_block, ref corona); if (big_block) { if (corona) { block_offset = 0; } else { block_offset = 0x60000; } } else { block_offset = 0xC000; } string mac = Regex.Replace(Oper.ByteArrayToString(Oper.returnportion(smc_config, 0x220 + block_offset, 5)), @"(.{2})(.{2})(.{2})(.{2})(.{2})", @"$1-$2-$3-$4-$5"); return(mac); }
string getmacaddress() { if (!File.Exists(variables.filename1)) { return("nomac"); } byte[] smc_config; int block_offset; smc_config = Nand.Nand.getsmcconfig(variables.filename1, out block_offset); string mac = Regex.Replace(Oper.ByteArrayToString(Oper.returnportion(smc_config, 0x220 + block_offset, 6)), @"(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})", @"$1-$2-$3-$4-$5-$6"); return(mac); }
private void parsehex() { try { byte[] file = File.ReadAllBytes(variables.filename1); if (file[0] != 0x3A) { Console.WriteLine("Bad file"); return; } byte[] length = new byte[2]; byte[] address = new byte[4]; byte[] record = new byte[2]; byte[] line, write; int i = 0, len = 0, add = 0, rec = 0; while (!variables.escapeloop) { length = Oper.returnportion(file, i + 1, 2); address = Oper.returnportion(file, i + 3, 4); record = Oper.returnportion(file, i + 7, 2); len = Convert.ToInt32((ASCIIEncoding.ASCII.GetString(length)), 16); rec = Convert.ToInt32((ASCIIEncoding.ASCII.GetString(record)), 16); add = Convert.ToInt32((ASCIIEncoding.ASCII.GetString(address)), 16); line = Oper.returnportion(file, i + 9, len * 2); write = Oper.StringToByteArray(ASCIIEncoding.ASCII.GetString(line)); Console.WriteLine("len: 0x{0:X}", len); Console.WriteLine("rec: 0x{0:X}", rec); Console.WriteLine("add: 0x{0:X}", add); //Console.WriteLine(ByteArrayToString(write)); Console.WriteLine(""); if ((add >= 0x800) && (add < 0x6000) && (rec == 0)) { Console.WriteLine(Oper.ByteArrayToString(write)); Console.WriteLine(""); } if (rec == 0x01) { break; } i = i + 2 + 4 + 2 + len + len + 2 + 2 + 1; if (file[i] != 0x3A) { break; } } Console.WriteLine("Done"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } variables.escapeloop = false; }
private static bool verify(ref ProgressBar pb) { try { string filename = variables.filename1; FileInfo fl = new FileInfo(filename); int filesize = (int)fl.Length; byte[] file = File.ReadAllBytes(filename); if (file[0] != 0x3A) { Console.WriteLine("Bad file"); return(false); } byte[] length = new byte[2]; byte[] address = new byte[4]; byte[] record = new byte[2]; byte[] line, write, offset; int i = 0, len = 0, add = 0, rec = 0; while (!variables.escapeloop) { length = Oper.returnportion(file, i + 1, 2); address = Oper.returnportion(file, i + 3, 4); record = Oper.returnportion(file, i + 7, 2); len = Convert.ToInt32((ASCIIEncoding.ASCII.GetString(length)), 16); rec = Convert.ToInt32((ASCIIEncoding.ASCII.GetString(record)), 16); add = Convert.ToInt32((ASCIIEncoding.ASCII.GetString(address)), 16); offset = Oper.StringToByteArray(ASCIIEncoding.ASCII.GetString(address)); Array.Reverse(offset); line = Oper.returnportion(file, i + 9, len * 2); write = Oper.StringToByteArray(ASCIIEncoding.ASCII.GetString(line)); if ((add >= 0x800) && (add < 0x6000) && (rec == 0)) { byte[] send = new byte[0x3F]; send[1] = 0x5; send[6] = 0x10; Buffer.BlockCopy(offset, 0, send, 3, 2); pb.Value = ((i * pb.Maximum) / filesize); re = new HidReport(0x3F, new HidDeviceData(send, HidDeviceData.ReadStatus.Success)); byte[] returnb = null; if (!_selectedDevice.WriteReport(re, 5000)) { Console.Write("X"); } else { re = _selectedDevice.ReadReport(5000); returnb = re.Data; } if (!Oper.ByteArrayCompare(Oper.returnportion(returnb, 6, write.Length), write)) { //if (comboBox1.Text == "2") Console.WriteLine("Data: {0:X}", ByteArrayToString(datab)); if (variables.debugme) { Console.WriteLine("Return: {0:X}", Oper.ByteArrayToString(returnb)); } if (variables.debugme) { Console.WriteLine("Data: {0:X}", Oper.ByteArrayToString(Oper.returnportion(returnb, 6, 0x10))); } if (variables.debugme) { Console.WriteLine("File: {0:X}", Oper.ByteArrayToString(write)); } Console.Write("x"); } else if (i % 8 == 0) { Console.Write("."); } Thread.Sleep(0x5); } if (rec == 0x01) { break; } i = i + 2 + 4 + 2 + len + len + 2 + 2 + 1; if (file[i] != 0x3A) { break; } } variables.escapeloop = false; return(true); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(false); } }
private static bool write(ref ProgressBar pb) { try { string filename = variables.filename1; FileInfo fl = new FileInfo(filename); bool rty = false; int reTRY = 0; int filesize = (int)fl.Length; byte[] file = File.ReadAllBytes(filename); if (file[0] != 0x3A) { Console.WriteLine("Bad file"); return(false); } byte[] length = new byte[2]; byte[] address = new byte[4]; byte[] record = new byte[2]; byte[] line, write, offset; int i = 0, len = 0, add = 0, rec = 0; while (!variables.escapeloop) { length = Oper.returnportion(file, i + 1, 2); address = Oper.returnportion(file, i + 3, 4); record = Oper.returnportion(file, i + 7, 2); len = Convert.ToInt32((ASCIIEncoding.ASCII.GetString(length)), 16); rec = Convert.ToInt32((ASCIIEncoding.ASCII.GetString(record)), 16); add = Convert.ToInt32((ASCIIEncoding.ASCII.GetString(address)), 16); offset = Oper.StringToByteArray(ASCIIEncoding.ASCII.GetString(address)); Array.Reverse(offset); line = Oper.returnportion(file, i + 9, len * 2); write = Oper.StringToByteArray(ASCIIEncoding.ASCII.GetString(line)); if ((add >= 0x800) && (add < 0x6000) && (rec == 0)) { byte[] send = new byte[0x3F]; send[1] = 0x1; send[6] = 0x10; Buffer.BlockCopy(offset, 0, send, 3, 2); Buffer.BlockCopy(write, 0, send, 0x7, write.Length); pb.Value = ((i * pb.Maximum) / filesize); re = new HidReport(0x3F, new HidDeviceData(send, HidDeviceData.ReadStatus.Success)); if (!_selectedDevice.WriteReport(re, 5000)) { Console.Write("x"); reTRY++; if (variables.debugme) { Console.WriteLine(" Retry: " + reTRY); } if (variables.debugme) { Console.WriteLine(" Command: {0:X}", Oper.ByteArrayToString(send)); } if (variables.debugme) { Console.WriteLine(" Data: {0:X}", Oper.ByteArrayToString(write)); } if (variables.debugme) { Console.WriteLine(" Offset: {0:X}", Oper.ByteArrayToString(offset)); } rty = true; } else if (i % 8 == 0) { Console.Write("."); rty = false; reTRY = 0; //i = i + 2 + 4 + 2 + len + len + 2 + 2 + 1; } Thread.Sleep(0x7); } if (rec == 0x01) { break; } if (!rty) { i = i + 2 + 4 + 2 + len + len + 2 + 2 + 1; } if (reTRY >= 0x0A) { return(false); } if (file[i] != 0x3A) { break; } } return(true); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(false); } finally { variables.escapeloop = false; } }
void unpack_base_image_ecc(ref byte[] image, ref ProgressBar pb, ref eccs dt) { byte[] data; if (Nand.Nand.hasecc(image)) { hasecc = true; Console.WriteLine("Spare Data found, will remove."); Nand.Nand.unecc(ref image, ref pb); Console.WriteLine("Removed"); } else { hasecc = false; Console.WriteLine("Spare data NOT found"); } try { byte[] block_offset = new byte[4], smc_len = new byte[4], smc_start = new byte[4]; //block_offset = Nand.returnportion(image, 0x8, 4); Buffer.BlockCopy(image, 0x8, block_offset, 0, 4); //smc_len = Nand.returnportion(image, 0x78, 4); Buffer.BlockCopy(image, 0x78, smc_len, 0, 4); //smc_start = Nand.returnportion(image, 0x7C, 4); Buffer.BlockCopy(image, 0x7C, smc_start, 0, 4); dt.SMC = new byte[Convert.ToInt32(Oper.ByteArrayToString(smc_len), 16)]; //SMC = Nand.returnportion(image, Convert.ToInt32(Nand.ByteArrayToString(smc_start), 16), Convert.ToInt32(Nand.ByteArrayToString(smc_len), 16)); Buffer.BlockCopy(image, Convert.ToInt32(Oper.ByteArrayToString(smc_start), 16), dt.SMC, 0, Convert.ToInt32(Oper.ByteArrayToString(smc_len), 16)); if (variables.extractfiles) { Oper.savefile(dt.SMC, "output\\SMC_en.bin"); } #region keyvault dt.Keyvault = new byte[0x4000]; Buffer.BlockCopy(image, 0x4000, dt.Keyvault, 0, 0x4000); //Keyvault = Nand.returnportion(image, 0x4000, 0x4000); if (variables.extractfiles) { Oper.savefile(dt.Keyvault, "output\\KV_en.bin"); } #endregion #region blocks int block = 0, block_size, id; byte block_id; int block_build; byte[] block_build_b = new byte[2], block_size_b = new byte[4]; int block_offset_b = Convert.ToInt32(Oper.ByteArrayToString(block_offset), 16); int semi = 0; for (block = 0; block < 30; block++) { block_id = image[block_offset_b + 1]; //block_build_b = Nand.returnportion(image, block_offset_b + 2, 2); Buffer.BlockCopy(image, block_offset_b + 2, block_build_b, 0, 2); //block_size_b = Nand.returnportion(image, block_offset_b + 12, 4); Buffer.BlockCopy(image, block_offset_b + 12, block_size_b, 0, 4); block_size = Convert.ToInt32(Oper.ByteArrayToString(block_size_b), 16); block_build = Convert.ToInt32(Oper.ByteArrayToString(block_build_b), 16); block_size += 0xF; block_size &= ~0xF; id = block_id & 0xF; if (variables.debugme) { Console.WriteLine("Found {0}BL (build {1}) at {2}", id, block_build, Convert.ToString(block_offset_b, 16)); } data = null; try { data = new byte[block_size]; //data = Nand.returnportion(image, block_offset_b, block_size); Buffer.BlockCopy(image, block_offset_b, data, 0, block_size); } catch (Exception ex) { if (variables.debugme) { Console.WriteLine(ex.ToString()); } } if (id == 2) { if (semi == 0) { if (block_build == 6751) { Console.WriteLine("A donor version will be used with this CB"); long csize = 0; dt.CB_A = Oper.openfile(Path.Combine(variables.pathforit, "common/CB/cb_6750.bin"), ref csize, 0); if (dt.CB_A == null) { Console.WriteLine("CB_A 6750 file is missing!!!"); } donor = true; } else if (block_build == 5771) { if (variables.debugme) { Console.WriteLine("This CB version can be for a Falcon or an Opus"); } dt.CB_A = data; } else { dt.CB_A = data; } semi = 1; } else if (semi == 1) { dt.CB_B = data; semi = 0; } } else if (id == 4) { dt.CD = data; } else if (id == 5) { dt.CE = data; } block_offset_b += block_size; if (id == 5) { break; } } #endregion } catch (Exception ex) { if (variables.debugme) { Console.WriteLine(ex.ToString()); } } }