public NOP(ASMLine _prev) { if (_prev == null) { return; } Section = _prev.Section; _prev.Next = this; Previous = _prev; }
public RET(ASMLine _prev) { if (_prev == null) { return; } Section = _prev.Section; _prev.Next = this; Previous = _prev; Action = SolveAction.Finished; }
public CMP(ASMLine _prev, string[] split) { if (_prev == null) { return; } Section = _prev.Section; _prev.Next = this; Previous = _prev; R1 = split[1].Replace(",", ""); R2 = split[2]; }
public JUMP(ASMLine _prev, string[] split) { if (_prev == null) { return; } Section = _prev.Section; _prev.Next = this; Previous = _prev; Enum.TryParse(split[0], true, out Type); To = split[1] == "short" ? split[2] : split[1]; }
internal static bool TryParse(string ASMLine, ASMLine Current, out ASMLine Out) { Out = null; ASMLine = ASMLine.ToLower().Trim(); string[] split = null; if (ASMLine.Length < 1) { return(false); //empty line } if (ASMLine[0] == ';') { return(false); //comment line, end of section } //section headers if ((split = ASMLine.Split(':')).Length > 1 && Regex.IsMatch(split[0], "^[a-z_0-9]+$")) { return((Out = new SectionHeader(split[0])) != null); } split = SPR.Split(ASMLine); switch (split[0]) { case "nop": return((Out = new NOP(Current)) != null); case "movzx": return((Out = new MOVZX(Current, split)) != null); case "cmp": return((Out = new CMP(Current, split)) != null); case "jnb": case "jbe": case "jmp": return((Out = new JUMP(Current, split)) != null); case "retn": return((Out = new RET(Current)) != null); default: throw new NotImplementedException($"Unable to parse instruction {split[0]}"); } }
public MOVZX(ASMLine _prev, string[] split) { if (_prev == null) { return; } Section = _prev.Section; _prev.Next = this; Previous = _prev; Register = split[1].Replace(",", ""); BPOffset = Convert.ToInt32(split[2].Replace("[rbp+var_", "").Replace("]", ""), 16); BPOffset *= -1; #if DEBUG DebugVarName = split[2]; #endif }
static void Main(string[] args) { string[] lines = File.ReadAllLines(FName); ASM_Map = new Dictionary <string, ASMLine>(); ASMLine Current = null; foreach (string line in lines) { if (ASMLine.TryParse(line, Current, out ASMLine Next)) { if (Current == null || Current.Section != Next.Section) { if (!ASM_Map.ContainsKey(Next.Section)) { ASM_Map[Next.Section] = Next; } } Current = Next; } } char EDX = (char)0, EAX = (char)0; char[] Stack = new char[StackSize]; Random r = new Random(SEED); //flag{{ string IString = $"flag{{{new string(Enumerable.Repeat(__CHARSET__, BaseInSize - 6).Select(s => s[r.Next(s.Length)]).ToArray())}}}"; IString.CopyTo(0, Stack, 0, BaseInSize); Solve(ref Stack, ref EDX, ref EAX); Console.WriteLine("Finished!"); Console.ReadKey(false); }