public byte[] EntryToBuff(int Entry) { byte[] ret = new byte[0]; if (Entry < 0 || Entry >= Header.ExportCount) { return(ret); } exports ex = Export[Entry]; ret = new byte[ex.DataSize]; for (int i = 0; i < ex.DataSize; i++) { ret[i] = memory[ex.DataOffset + i]; } return(ret); }
public void CloneEntry(int entry) { byte[] buffdata; DialogResult r = MessageBox.Show("Clone with new data?","", MessageBoxButtons.YesNo); if (r == DialogResult.No) { buffdata = EntryToBuff(entry); } else { OpenFileDialog d = new OpenFileDialog(); d.Filter = "bin files (*.bin)|*.bin|all files|*.*"; if (d.ShowDialog() == DialogResult.OK) { FileStream f = new FileStream(d.FileName, FileMode.Open, FileAccess.Read); int size = (int)f.Length; buffdata = new byte[size]; int count; int sum = 0; while ((count = f.Read(buffdata, sum, size - sum)) > 0) sum += count; } else return; } int sizebefore = memsize; MemoryStream m = new MemoryStream(); m.Write(memory, 0, (int)Header.offinfo + 8); byte[] buff = BitConverter.GetBytes(Header.ExportCount + 1); m.Write(buff, 0, 4); buff = BitConverter.GetBytes(sizebefore); m.Write(buff, 0, 4); m.Write(memory, (int)Header.offinfo + 16,sizebefore - ((int)Header.offinfo + 16)); for (int i = 0; i < Export.Length; i++) { uint len = Export[i].end - Export[i].start; m.Write(memory, (int)Export[i].start, (int)len); } int pos =(int)m.Length; uint len2 = Export[entry].end - Export[entry].start; m.Write(memory, (int)Export[entry].start, 32); buff = BitConverter.GetBytes(buffdata.Length); m.Write(buff, 0, 4); buff = BitConverter.GetBytes(pos + (int)len2); m.Write(buff, 0, 4); m.Write(memory, (int)Export[entry].start + 40, (int)len2- 40); m.Write(buffdata, 0, buffdata.Length); Header.ExportCount++; Header.ExportOffset = (uint)sizebefore; exports ex = new exports(); ex.Class = Export[entry].Class; ex.DataOffset = (uint)pos + len2; ex.DataSize = (uint)buffdata.Length; ex.end = (uint)pos + len2; ex.Link = Export[entry].Link; ex.Name = Export[entry].Name; ex.off = Export[entry].off; ex.start = (uint)pos; exports[] t = new exports[Header.ExportCount]; for (int i = 0; i < Header.ExportCount - 1; i++) t[i] = Export[i]; t[Header.ExportCount - 1] = ex; Export = t; memory = m.ToArray(); TOCeditor tc = new TOCeditor(); if (!tc.UpdateFile(loadedFilename, (uint)memsize)) MessageBox.Show("Didn't found Entry"); }
public void CloneEntry(int entry) { byte[] buffdata; DialogResult r = MessageBox.Show("Clone with new data?", "", MessageBoxButtons.YesNo); if (r == DialogResult.No) { buffdata = EntryToBuff(entry); } else { OpenFileDialog d = new OpenFileDialog(); d.Filter = "bin files (*.bin)|*.bin|all files|*.*"; if (d.ShowDialog() == DialogResult.OK) { FileStream f = new FileStream(d.FileName, FileMode.Open, FileAccess.Read); int size = (int)f.Length; buffdata = new byte[size]; int count; int sum = 0; while ((count = f.Read(buffdata, sum, size - sum)) > 0) { sum += count; } } else { return; } } int sizebefore = memsize; MemoryStream m = new MemoryStream(); m.Write(memory, 0, (int)Header.offinfo + 8); byte[] buff = BitConverter.GetBytes(Header.ExportCount + 1); m.Write(buff, 0, 4); buff = BitConverter.GetBytes(sizebefore); m.Write(buff, 0, 4); m.Write(memory, (int)Header.offinfo + 16, sizebefore - ((int)Header.offinfo + 16)); for (int i = 0; i < Export.Length; i++) { uint len = Export[i].end - Export[i].start; m.Write(memory, (int)Export[i].start, (int)len); } int pos = (int)m.Length; uint len2 = Export[entry].end - Export[entry].start; m.Write(memory, (int)Export[entry].start, 32); buff = BitConverter.GetBytes(buffdata.Length); m.Write(buff, 0, 4); buff = BitConverter.GetBytes(pos + (int)len2); m.Write(buff, 0, 4); m.Write(memory, (int)Export[entry].start + 40, (int)len2 - 40); m.Write(buffdata, 0, buffdata.Length); Header.ExportCount++; Header.ExportOffset = (uint)sizebefore; exports ex = new exports(); ex.Class = Export[entry].Class; ex.DataOffset = (uint)pos + len2; ex.DataSize = (uint)buffdata.Length; ex.end = (uint)pos + len2; ex.Link = Export[entry].Link; ex.Name = Export[entry].Name; ex.off = Export[entry].off; ex.start = (uint)pos; exports[] t = new exports[Header.ExportCount]; for (int i = 0; i < Header.ExportCount - 1; i++) { t[i] = Export[i]; } t[Header.ExportCount - 1] = ex; Export = t; memory = m.ToArray(); TOCeditor tc = new TOCeditor(); if (!tc.UpdateFile(loadedFilename, (uint)memsize)) { MessageBox.Show("Didn't found Entry"); } }