public void processFile(List <byte> rawData) { int currentOffset = 0; int currentOpcodeSize; int whileSec = 0; // Read header Header = rawData.GetRange(headerOffset, headerSize); currentOffset += headerSize; // Opcodes while (currentOffset < rawData.Count) { //Console.WriteLine("DEBUG >>> Reading opcode at offset: " + currentOffset + "/" + rawData.Count); // Prevent infinite loop if (whileSec >= 10000) { break; } // Read the opcode's size and then store it currentOpcodeSize = OpcodeItem.entrySize + OpcodeItem.paramSize * DataAccess.readUShort(rawData, currentOffset + OpcodeItem.paramCountOffset, OpcodeItem.paramCountSize);; Opcodes.Add(new OpcodeItem(rawData.GetRange(currentOffset, currentOpcodeSize))); currentOffset += currentOpcodeSize; whileSec++; } }
protected override void AddOpcodes() { Opcodes.Add(new Opcode("NOP", 0x0, (z80) => { return(TStates.Count(4)); })); }
public void RefreshPackets() { ListView.BeginUpdate(); MaplePacket previous = ListView.SelectedIndices.Count > 0 ? FilteredPackets[ListView.SelectedIndices[0]] : null; Opcodes.Clear(); ListView.Clear(); MainForm.DataForm.ClearHexBox(); MainForm.StructureForm.Tree.Nodes.Clear(); MainForm.PropertyForm.Properties.SelectedObject = null; if (!mViewOutboundMenu.Checked && !mViewInboundMenu.Checked) { return; } int previousIndex = -1; foreach (MaplePacket packet in mPackets) { if (packet.Outbound && !mViewOutboundMenu.Checked) { continue; } if (!packet.Outbound && !mViewInboundMenu.Checked) { continue; } if (!Opcodes.Exists(op => op.Outbound == packet.Outbound && op.Header == packet.Opcode)) { Opcodes.Add(new Opcode(packet.Outbound, packet.Opcode)); } Definition definition = Config.Instance.GetDefinition(packet); if (definition != null && !mViewIgnoredMenu.Checked && definition.Ignore) { continue; } int index = ListView.AddPacket(packet); if (packet == previous) { previousIndex = index; } } MainForm.SearchForm.RefreshOpcodes(true); ListView.EndUpdate(); // This should be called after EndUpdate so VirtualListSize is set properly if (previous != null && previousIndex >= 0) { ListView.Items[previousIndex].Selected = true; ListView.Items[previousIndex].EnsureVisible(); } }
protected override void AddOpcodes() { Opcodes.Add(new Opcode("EI", 0xFB, (z80) => { z80.InteruptsEnabled = true; return(TStates.Count(4)); })); }
public void Add_should_return_x_plus_y() { // Arrange var opcode = Opcodes.Add(); // Act var output = ArithmeticLogicUnit.Do(opcode, new Byte2(27), new Byte2(45)); // Assert output.ToInt16().Should().Be(72); }
protected override void AddOpcodes() { Opcodes.Add(new Opcode("IND", 0xED, 0xAA, (z80) => { var value = z80.Ports.GetByte(z80.C.Value); z80.Memory.Set(z80.HL.Value, value); z80.HL.Value--; z80.B.Value--; z80.F.Zero = z80.B.Value.IsZero(); return(TStates.Count(16)); })); }
protected override void AddOpcodes() { Opcodes.Add(new Opcode("LDI", 0xED, 0xA0, (z80) => { var value = z80.Memory.Get(z80.HL.Value); z80.Memory.Set(z80.DE.Value, value); z80.DE.Value++; z80.HL.Value++; z80.BC.Value--; z80.F.ParityOrOverflow = !z80.BC.Value.IsZero(); return(TStates.Count(16)); })); }
public void Increment(string opcodeName, bool hasStack) { if (hasStack) { StackCount++; } Count++; OpcodeStats opcodeStats; if (!Opcodes.TryGetValue(opcodeName, out opcodeStats)) { opcodeStats = new OpcodeStats(opcodeName); Opcodes.Add(opcodeName, opcodeStats); } opcodeStats.Increment(hasStack); }
protected override void AddOpcodes() { Opcodes.Add(new Opcode("HALT", 0x76, z80 => { var nop = new NOP().Opcodes.First(); while (true) { // excute nop nop.Execute(z80); //check if reset has been received //check if interupt has been received break; } return(TStates.Count(0)); })); }
protected override void AddOpcodes() { Opcodes.Add(new Opcode("EXX", 0xD9, (z80) => { var bc = z80.BC.Value; var de = z80.DE.Value; var hl = z80.HL.Value; z80.BC.Value = z80.BC_.Value; z80.DE.Value = z80.DE_.Value; z80.HL.Value = z80.HL_.Value; z80.BC_.Value = bc; z80.DE_.Value = de; z80.HL_.Value = hl; return(TStates.Count(4)); })); }
public Opcode(string name, List <BitField> bitFields, List <ParameterBitField> appearance) { // Check that all items within both BitField arrays are valid int invalidCount = appearance.Count(x => bitFields.Count(y => y.GetType() == x.GetType()) == 0); if (invalidCount > 0) { throw new Exception( $"All items within the appearance list must also be within the bitFields list.\r\n" + $"Failed [{invalidCount}/{appearance.Count}]"); } // Matrix.Fit(); todo Name = name; BitFields = bitFields; Appearance = appearance; Opcodes.Add(this); }
protected override void AddOpcodes() { Opcodes.Add(new Opcode("DJNZ e", 0x10, (z80) => { z80.B.Value--; if (z80.B.Value.IsZero()) { var offset = z80.Memory.Get(z80.PC.Value); var pc = z80.PC.Value + (sbyte)offset; z80.PC.Value = (ushort)pc; return(TStates.Count(8)); } else { //increment PC to skip the offset z80.PC.Increment(); return(TStates.Count(13)); } })); }
protected override void AddOpcodes() { Opcodes.Add(new Opcode("LDDR", 0xED, 0xB8, (z80) => { var value = z80.Memory.Get(z80.HL); z80.Memory.Set(z80.DE, value); z80.DE.Decrement(); z80.HL.Decrement(); z80.BC.Decrement(); if (z80.BC.IsNotZero) { z80.PC.Decrement(); z80.PC.Decrement(); return(TStates.Count(21)); } return(TStates.Count(16)); })); }
protected override void AddOpcodes() { Opcodes.Add(new Opcode("LDIR", 0xED, 0xB0, (z80) => { var value = z80.Memory.Get(z80.HL.Value); z80.Memory.Set(z80.DE.Value, value); z80.DE.Value++; z80.HL.Value++; z80.BC.Value--; if (z80.BC.Value.IsZero()) { return(TStates.Count(16)); } else { z80.PC.Value--; z80.PC.Value--; return(TStates.Count(21)); } })); }
private void AddPacket(MaplePacket packet, bool buffered = true, bool forceAdd = false) { mPackets.Add(packet); Definition definition = Config.Instance.GetDefinition(Build, Locale, packet.Outbound, packet.Opcode); if (!Opcodes.Exists(op => op.Outbound == packet.Outbound && op.Header == packet.Opcode)) { Opcodes.Add(new Opcode(packet.Outbound, packet.Opcode)); } if (!forceAdd) { if (definition != null && !mViewIgnoredMenu.Checked && definition.Ignore) { return; } if (packet.Outbound && !mViewOutboundMenu.Checked) { return; } if (!packet.Outbound && !mViewInboundMenu.Checked) { return; } } if (buffered) { bufferedPackets.Add(packet); } else { ListView.AddPacket(packet); } }
private Results ProcessPacket(byte[] bytes, bool isOutbound, DateTime timestamp) { if (mTerminated) { return(Results.Terminated); } if (Build == 0) { var packet = new ByteReader(bytes); packet.Read <ushort>(); // rawSeq int length = packet.ReadInt(); if (bytes.Length - 6 < length) { logger.Debug($"Connection on port {mLocalEndpoint} did not have a MapleStory2 Handshake"); return(Results.CloseMe); } ushort opcode = packet.Read <ushort>(); if (opcode != 0x01) { // RequestVersion logger.Debug($"Connection on port {mLocalEndpoint} did not have a valid MapleStory2 Connection Header"); return(Results.CloseMe); } uint version = packet.Read <uint>(); uint siv = packet.Read <uint>(); uint riv = packet.Read <uint>(); uint blockIV = packet.Read <uint>(); byte type = packet.ReadByte(); Build = version; Locale = MapleLocale.UNKNOWN; outDecryptor = new MapleCipher.Decryptor(Build, siv, blockIV); inDecryptor = new MapleCipher.Decryptor(Build, riv, blockIV); inDecryptor.Decrypt(bytes); // Advance the IV // Generate HandShake packet Definition definition = Config.Instance.GetDefinition(Build, Locale, false, opcode); if (definition == null) { definition = new Definition { Outbound = false, Opcode = opcode, Name = "RequestVersion", }; SaveDefinition(Locale, Build, definition); } ArraySegment <byte> segment = new ArraySegment <byte>(packet.Buffer); var maplePacket = new MaplePacket(timestamp, isOutbound, Build, opcode, segment); // Add to list of not exist (TODO: SortedSet?) if (!Opcodes.Exists(op => op.Outbound == maplePacket.Outbound && op.Header == maplePacket.Opcode)) { // Should be false, but w/e Opcodes.Add(new Opcode(maplePacket.Outbound, maplePacket.Opcode)); } AddPacket(maplePacket, false, true); logger.Info($"[CONNECTION] {mRemoteEndpoint} <-> {mLocalEndpoint}: MapleStory2 V{Build}"); return(Results.Show); } try { MapleCipher.Decryptor decryptor = isOutbound ? outDecryptor : inDecryptor; ByteReader packet = decryptor.Decrypt(bytes); // It's possible to get an empty packet, just ignore it. // Decryption is still necessary to advance sequence number. if (packet.Available == 0) { return(Results.Continue); } ushort opcode = packet.Peek <ushort>(); ArraySegment <byte> segment = new ArraySegment <byte>(packet.Buffer, 2, packet.Length - 2); var maplePacket = new MaplePacket(timestamp, isOutbound, Build, opcode, segment); AddPacket(maplePacket); return(Results.Continue); } catch (ArgumentException ex) { logger.Fatal(ex, "Exception while processing packets"); return(Results.CloseMe); } }