public void Extract(AssemblyBox box) { Intelx86 ix86 = new Intelx86(box.TextSection.Data); // TODO Support file type detection ! Console.WriteLine("Disassembly of section .text:\n"); long address = box.TextSection.Virtual; Console.WriteLine("{0} <...>:", Hexa.ToString(address, 8, false).Substring(2)); for (; ; ) { x86Operator op = ix86.Next(); if (op == null) break; string amyMn = " " + Hexa.ToString(address).Substring(7) + ":\t"; for (var i = 0; i < Math.Min(op.Length, 7); ++i) amyMn += Hexa.ToString(ix86.Buffer[ix86.Offset + i], 2, false, false) + " "; for (var i = Math.Min(op.Length, 7); i < 7; ++i) amyMn += " "; amyMn += "\t"; amyMn += op.ATNTWriting; Console.WriteLine(amyMn); address += op.Length; int lg = op.Length, k = 7; while (lg > 7) { amyMn = " :\t"; for (var i = k; i < Math.Min(op.Length, k + 7); ++i) amyMn += Hexa.ToString(ix86.Buffer[ix86.Offset + i], 2, false, false) + " "; Console.WriteLine(amyMn); lg -= 7; k += 7; } } Console.WriteLine(); }
static void UTx86(string[] args) { string start = " 0:\t"; string objdump = @"C:\MinGW\bin\objdump"; string file = @"C:\Users\Aesgar\Downloads\exit.o"; // string objdump = @"D:\Programs\MinGW\bin\objdump"; // string file = @"D:/exit.o"; byte[] instr = new byte[15]; instr[0] = 1; long Tested = 0; long Failure = 0; for (; ; ) { if (instr[0] == 0x0f) instr[0]++; if (instr[0] == 0x66) instr[0] += 2; if (instr[0] == 0x82) instr[0]++; if (instr[0] == 0xc4) instr[0] += 2; if (instr[0] == 0xce) instr[0] += 2; if (instr[0] == 0xd2) instr[0] += 22; if (instr[0] == 0xe8) instr[0] += 8; // Disassemble using MingW try { using (BinaryWriter wr = new BinaryWriter(File.Open(file, FileMode.Open, FileAccess.ReadWrite))) { wr.BaseStream.Seek(0x104, SeekOrigin.Begin); wr.Write(instr); } } catch (Exception e) { } // Start Process string strCmdText; strCmdText = "-d " + file; ProcessStartInfo startInfo = new ProcessStartInfo(objdump, strCmdText); startInfo.RedirectStandardOutput = true; startInfo.UseShellExecute = false; Process p = Process.Start(startInfo); // Disassemble using Amy Intelx86 dn = new Intelx86(instr); x86Operator op = dn.Next(); string amyMn = start; for (var i = 0; i < Math.Min(op.Length, 7); ++i) amyMn += Hexa.ToString(instr[i], 2, false).Substring(2) + " "; for (var i = Math.Min(op.Length, 7); i < 7; ++i) amyMn += " "; amyMn += "\t"; amyMn += op.ATNTWriting; int lg = Math.Min(op.Length - 1, 1); if (instr[lg] == 0xff) while (lg >= 0 && instr[lg] == 0xff) instr[lg--] = 0; if (lg < 0) return; instr[lg]++; // Read // p.WaitForExit(); StreamReader rd = p.StandardOutput; string mingwMn = string.Empty; while (!mingwMn.StartsWith(start)) mingwMn = rd.ReadLine(); //Console.WriteLine(st); Tested++; if (mingwMn != amyMn) { Failure++; Console.WriteLine(mingwMn); } } }