/// <summary> /// Connects to a device and creates lsl streams. /// </summary> private void Initialize() { try { //connect to currently selected device string serial = cbDevices.SelectedItem.ToString(); string streamName; if (tbStreamName.Text.Length <= 0 || tbStreamName.Text == null) { streamName = serial; tbStreamName.Text = streamName; } else { streamName = tbStreamName.Text; } Thread connectionThread = new Thread(() => ConnectionThread_DoWork(serial, streamName)); connectionThread.Start(); } catch (DeviceException ex) { _device = null; UpdateUIElements(DeviceStates.NotConnected); ShowErrorBox(ex.Message); } catch (Exception ex) { _device = null; UpdateUIElements(DeviceStates.NotConnected); ShowErrorBox(String.Format("Could not open device. {0}", ex.Message)); } }
/// <summary> /// Connects to a Unicorn. /// </summary> /// <param name="serial">The serial of the device to connect.</param> private void ConnectionThread_DoWork(string serial, IPAddress ip, int port) { try { UpdateUIElements(DeviceStates.Connecting); //Open device _device = new Unicorn(serial); //Initialize upd socket _socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); _endPoint = new IPEndPoint(ip, port); _socket.Connect(_endPoint); UpdateUIElements(DeviceStates.Connected); } catch (DeviceException ex) { _device = null; UpdateUIElements(DeviceStates.NotConnected); ShowErrorBox(ex.Message); } catch (Exception ex) { _device = null; UpdateUIElements(DeviceStates.NotConnected); ShowErrorBox(String.Format("Could not open device. {0}", ex.Message)); } }
//recording the ride at dynamoDB public async Task recordRide(string orderId, string userName, Unicorn unicorn) { //loading the designated table for the ride - dynamodb document model Table orders = Table.LoadTable(ddb, "Orders"); //can use in attributeValue in here also Document order = new Document(); order["OrderId"] = orderId; order["User"] = userName; order["Unicorn"] = JsonConvert.SerializeObject(unicorn); order["UnicornName"] = unicorn.Name; order["RequestTime"] = DateTime.Now.ToString(); //putting items in the table await orders.PutItemAsync(order); ////attributeValue method //var client = new AmazonDynamoDBClient(); //var request = new PutItemRequest //{ // TableName = "Orders", // Item = new Dictionary<string, AttributeValue> { // { "OrderId", new AttributeValue { S = orderId } }, // { "User", new AttributeValue { S = userName } }, // { "Unicorn", new AttributeValue { S = JsonConvert.SerializeObject(unicorn)} }, // { "UnicornName", new AttributeValue { S = unicorn.name } }, // { "RequestTime", new AttributeValue { S = DateTime.Now.ToString() } } // } //}; //await client.PutItemAsync(request); }
public static void RunTest(Byte[] code, UInt64 address) { var u = new Unicorn(Common.UC_ARCH_X86, Common.UC_MODE_32); Console.WriteLine("Unicorn version: {0}", u.Version()); // map 2MB of memory for this emulation Utils.CheckError(u.MemMap(address, new UIntPtr(2 * 1024 * 1024), Common.UC_PROT_ALL)); // write machine code to be emulated to memory Utils.CheckError(u.MemWrite(address, code)); // initialize machine registers Utils.CheckError(u.RegWrite(X86.UC_X86_REG_ESP, Utils.Int64ToBytes(address + 0x200000))); // tracing all instructions by having @begin > @end Utils.CheckError(u.AddCodeHook(CodeHookCallback, null, 1, 0).Item1); // handle interrupt ourself Utils.CheckError(u.AddInterruptHook(InterruptHookCallback, null).Item1); // handle SYSCALL Utils.CheckError(u.AddSyscallHook(SyscallHookCallback, null).Item1); Console.WriteLine(">>> Start tracing linux code"); // emulate machine code in infinite time u.EmuStart(address, address + (UInt64)code.Length, 0u, new UIntPtr(0)); Console.WriteLine(">>> Emulation Done!"); }
private static void OutHookCallback(Unicorn u, Int32 port, Int32 size, Int32 value, Object userData) { var eip = u.RegRead(X86.UC_X86_REG_EIP); Console.WriteLine("[!] Writing to port 0x{0}, size: {1}, value: 0x{2}, address: 0x{3}", port.ToString("X"), size.ToString("X"), value.ToString("X"), eip.ToString("X")); // confirm that value is indeed the value of AL/ AX / EAX var v = 0L; var regName = String.Empty; switch (size) { case 1: // read 1 byte in AL v = u.RegRead(X86.UC_X86_REG_AL); regName = "AL"; break; case 2: // read 2 byte in AX v = u.RegRead(X86.UC_X86_REG_AX); regName = "AX"; break; case 4: // read 4 byte in EAX v = u.RegRead(X86.UC_X86_REG_EAX); regName = "EAX"; break; } Console.WriteLine("[!] Register {0}: {1}", regName, v.ToString("X")); }
void Start() { if (useRecordedFile) { csvP = new TestCSVParser("Assets/TestFiles/" + testFileName); } else { unicornDevice = new Unicorn("UN-2019.02.86"); print(unicornDevice.GetDeviceInformation().DeviceVersion); FrameLength = 1; uint numberOfAcquiredChannels = unicornDevice.GetNumberOfAcquiredChannels(); print(numberOfAcquiredChannels); receiveBuffer = new byte[FrameLength * sizeof(float) * numberOfAcquiredChannels]; receiveBufferHandle = GCHandle.Alloc(receiveBuffer, GCHandleType.Pinned); unicornDevice.StartAcquisition(false); } ps = GetComponent <ParticleSystem>(); for (int i = 0; i < 8; i++) { arrays.Add(new float[60]); } }
private static void CodeHookCallback( CapstoneDisassembler <X86Instruction, X86Register, X86InstructionGroup, X86InstructionDetail> disassembler, Unicorn u, Int64 addr, Int32 size, Object userData) { Console.Write("[+] 0x{0}: ", addr.ToString("X")); var eipBuffer = new Byte[4]; u.RegRead(X86.UC_X86_REG_EIP, eipBuffer); var effectiveSize = Math.Min(16, size); var tmp = new Byte[effectiveSize]; u.MemRead(addr, tmp); var sb = new StringBuilder(); foreach (var t in tmp) { sb.AppendFormat("{0} ", (0xFF & t).ToString("X")); } Console.Write("{0,-20}", sb); Console.WriteLine(Utils.Disassemble(disassembler, tmp)); }
/// <summary> /// Connects to a Unicorn. /// </summary> /// <param name="serial">The serial of the device to connect.</param> private void ConnectionThread_DoWork(string serial, string streamName) { try { UpdateUIElements(DeviceStates.Connecting); //Open device _device = new Unicorn(serial); //Initialize lsl _lslInfo = new liblsl.StreamInfo(streamName, "Data", (int)_device.GetNumberOfAcquiredChannels(), Unicorn.SamplingRate, liblsl.channel_format_t.cf_float32, serial); _lslOutlet = new liblsl.StreamOutlet(_lslInfo); UpdateUIElements(DeviceStates.Connected); } catch (DeviceException ex) { _device = null; UpdateUIElements(DeviceStates.NotConnected); ShowErrorBox(ex.Message); } catch (Exception ex) { _device = null; UpdateUIElements(DeviceStates.NotConnected); ShowErrorBox(String.Format("Could not open device. {0}", ex.Message)); } }
public void DeleteResponse() { List <Todo> oldTodos = new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL)) .GetModelAsync <List <Todo> >().Result; Assert.IsTrue(oldTodos != null && oldTodos.Count > 0); int oldCount = oldTodos.Count; Todo first = oldTodos.FirstOrDefault(); HttpResponseMessage result = new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL)) .DeleteResponseAsync(first.Id).Result; Assert.IsTrue(result.IsSuccessStatusCode); List <Todo> newTodos = new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL)) .GetModelAsync <List <Todo> >().Result; Assert.IsTrue(newTodos != null && newTodos.Count > 0); int newCount = newTodos.Count; Assert.IsTrue(newCount < oldCount); }
public Unicorn(int x, int y, int scale) { this.x = this.x; this.y = this.y; this.scale = (this.scale / 10); this.image = Unicorn.getImage(); }
public virtual Balloon Update(Unicorn unicorn) { float distance = Vector2.Distance(unicorn.GetCenterPos(), Position + new Vector2(width / 2, height / 2)); if (Math.Abs(distance) < 96) { ExitPortal exit = GameManager.getInstance().exit; if (isActive && exit != null) { exit.IncreasePhase(); } if (isActive) { popAudio.Play(); } isActive = false; Destroy(); return(this); } return(null); }
public void toggleSource() { if (useRecordedFile) // switch from recorded file to live capture { clearBufferArrays(); toggleButton.GetComponentInChildren <Text>().text = "Live capture active"; print("switched to live capture"); useRecordedFile = false; initUnicorn(); acquisitionRunning = true; } else // switch from live capture to recorded file { toggleButton.GetComponentInChildren <Text>().text = "Recorded file active"; print("switched to test file"); useRecordedFile = true; initTestFileParser(); try { unicornDevice.StopAcquisition(); } catch (Exception e) { print(e.Message); } unicornDevice.Dispose(); unicornDevice = null; acquisitionRunning = false; } }
public void UnicornsShouldBeUnicorns() { IBattleable unicorn = new Unicorn(); Assert.AreEqual(unicorn.Type, CharacterTypes.Unicorn); Assert.IsTrue(unicorn is Unicorn); }
private static Int32 InHookCallback(Unicorn u, Int32 port, Int32 size, Object userData) { var eip = u.RegRead(X86.UC_X86_REG_EIP); Console.WriteLine("[!] Reading from port 0x{0}, size: {1}, address: 0x{2}", port.ToString("X"), size.ToString("X"), eip.ToString("X")); var res = 0; switch (size) { case 1: // read 1 byte to AL res = 0xf1; break; case 2: // read 2 byte to AX res = 0xf2; break; case 4: // read 4 byte to EAX res = 0xf4; break; } Console.WriteLine("[!] Return value: {0}", res.ToString("X")); return(res); }
private static void Main(string[] args) { using (var unicorn = new Unicorn(UcArch.UC_ARCH_ARM64, UcMode.UC_MODE_ARM)) { const ulong address = 0x1000; const ulong memSize = 0x1000; var codeBytes = new byte[] { 0x01, 0x06, 0xa0, 0xd2, 0x41, 0x10, 0x18, 0xd5, 0xdf, 0x3f, 0x03, 0xd5 }; unicorn.HookCode((uc, address1, size, data) => { Console.WriteLine("Code.."); }); unicorn.MemMap(address, memSize); unicorn.MemWrite(address, codeBytes); unicorn.RegWrite(UcArm64Reg.UC_ARM64_REG_SP, address + memSize); unicorn.EmuStart(address, address + (ulong)codeBytes.Length); } }
/// <summary> /// Add a unicorn to the DB /// </summary> public Unicorn AddUnicorn(Unicorn unicorn) { var result = Context.Unicorns.Add(unicorn); Context.SaveChanges(); return(result); }
public RideResponse(string orderId, Unicorn unicorn, string unicornName, string eta, string rider) { OrderId = orderId; Unicorn = unicorn; UnicornName = unicornName; Eta = eta; Rider = rider; }
private static void InterruptHookCallback(Unicorn u, Int32 intNumber, Object userData) { // only handle Linux syscall if (intNumber != 0x80) { return; } var eaxBuffer = new Byte[4]; var eipBuffer = new Byte[4]; u.RegRead(X86.UC_X86_REG_EAX, eaxBuffer); u.RegRead(X86.UC_X86_REG_EIP, eipBuffer); var eax = Utils.ToInt(eaxBuffer); var eip = Utils.ToInt(eipBuffer); switch (eax) { default: Console.WriteLine("[!] Interrupt 0x{0} num {1}, EAX=0x{2}", eip.ToString("X"), intNumber.ToString("X"), eax.ToString("X")); break; case 1: // sys_exit Console.WriteLine("[!] Interrupt 0x{0} num {1}, SYS_EXIT", eip.ToString("X"), intNumber.ToString("X")); u.EmuStop(); break; case 4: // sys_write // ECX = buffer address var ecxBuffer = new Byte[4]; // EDX = buffer size var edxBuffer = new Byte[4]; u.RegRead(X86.UC_X86_REG_ECX, ecxBuffer); u.RegRead(X86.UC_X86_REG_EDX, edxBuffer); var ecx = Utils.ToInt(ecxBuffer); var edx = Utils.ToInt(edxBuffer); // read the buffer in var size = Math.Min(256, edx); var buffer = new Byte[size]; u.MemRead(ecx, buffer); var content = Encoding.Default.GetString(buffer); Console.WriteLine( "[!] Interrupt 0x{0}: num {1}, SYS_WRITE. buffer = 0x{2}, size = , content = '{3}'", eip.ToString("X"), ecx.ToString("X"), edx.ToString("X"), content); break; } }
public void DragonShouldBeatUnicorn() { IBattleable dragon = new Dragon(); IBattleable unicorn = new Unicorn(); bool result = dragon.Battle(unicorn); Assert.IsTrue(result); }
/// <inheritdoc/> public async Task <int?> FindUnicornUpdateAsync(Guid id, Unicorn unicorn) { if (!this.unicornRepository.UnicornExists(id)) { return(null); } return(await this.unicornRepository.UpdateUnicornAsync(unicorn)); }
public void TRexShouldNotBeatUnicorn() { IBattleable trex = new TRex(); IBattleable unicorn = new Unicorn(); bool result = trex.Battle(unicorn); Assert.IsFalse(result); }
public void UnicornShouldBeatWearwolf() { IBattleable unicorn = new Unicorn(); IBattleable wearwolf = new Wearwolf(); bool result = unicorn.Battle(wearwolf); Assert.IsTrue(result); }
public void GetResponse() { using (HttpResponseMessage responseMessage = new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL)) .GetResponseAsync().Result) { Assert.IsTrue(responseMessage.IsSuccessStatusCode); } }
public void UnicornShouldBeatTRex() { IBattleable unicorn = new Unicorn(); IBattleable trex = new TRex(); bool result = unicorn.Battle(trex); Assert.IsTrue(result); }
private void Start() { Unicorn starter = new Unicorn(); starter.name = "Baby starter"; starter.description = "A useless little unicorn to get you started"; starter.thisRace = Unicorn.Race.Baby; cards.Add(starter); }
/// <summary> /// Determines available device serials and writes them to the available devices box. /// </summary> private void GetAvailableDevices() { List <string> devices = new List <string>(Unicorn.GetAvailableDevices(true)); if (devices.Count > 0 && cbDevices != null) { cbDevices.DataSource = devices; } }
public void UnicornShouldNotBeatDragon() { IBattleable unicorn = new Unicorn(); IBattleable dragon = new Dragon(); bool result = unicorn.Battle(dragon); Assert.IsFalse(result); }
public void WearwolfShouldNotBeatUnicorn() { IBattleable wearwolf = new Wearwolf(); IBattleable unicorn = new Unicorn(); bool result = wearwolf.Battle(unicorn); Assert.IsFalse(result); }
public void UnicornShouldNotBeatUnicorn() { IBattleable unicornOne = new Unicorn(); IBattleable unicornTwo = new Unicorn(); bool result = unicornOne.Battle(unicornTwo); Assert.IsFalse(result); }
public static void Play() { var unicorn = new Unicorn() { Name = "Pony", Color = "Blue" }; // unicorn impl Deconstruct //_ means discard var(n, c1, _) = unicorn; Console.WriteLine($"{n},{c1}"); //unicorn impl IEnumerable foreach (var s in unicorn) { Console.WriteLine(s); } //unicorn impl IEquatable Console.WriteLine(unicorn == null); //unicorn impl ICloneable var c = new Unicorn(unicorn); //unicorn impl IComparable c.Name = "YiJiang"; Console.WriteLine(c.CompareTo(unicorn) > 0 ? "bigger" : "smaller"); //unicorn has partial impl unicorn.Barking(); //interface mixed in with unicorn (c# 8.0) if (unicorn is Runner runable) { //Run impl in interface def runable.Run(5); } // unicorn.Stop(); //unicorn impl this[int i] Console.WriteLine(unicorn[5]); //pass many params in unicorn.AnyParams(1, 2, 3, "aaa", "bbb"); //unicorn impl implicit byte[] //NOTE Very Ambiguity,DONT USE OFTEN! Only use it on mathematically purpose byte[] b = unicorn; //unicorn impl explicit(byte[]) Unicorn bb = (Unicorn)b; //unicorn impl op+ Console.WriteLine(unicorn + c); }
// END CUT HERE // BEGIN CUT HERE public static void Main() { try { Unicorn ___test = new Unicorn(); ___test.run_test(-1); } catch(Exception e) { //Console.WriteLine(e.StackTrace); Console.WriteLine(e.ToString()); } }
public override Balloon Update(Unicorn unicorn) { if (!activatedOnce && !isActive) { activatedOnce = true; ActivateAll(); } return(base.Update(unicorn)); }
public void Finalization_IsNondeterministic() { Unicorn unicon = new Unicorn(); Assert.AreEqual<int>( 1, Unicorn.PendingFinalizations); unicon.Close(); Assert.IsFalse(unicon.HasLotsOfData); }
public void Finalization_IDisposable() { Unicorn unicorn; using (unicorn = new Unicorn()) { Assert.AreEqual<int>( 1, Unicorn.PendingFinalizations); } Assert.IsFalse(unicorn.HasLotsOfData); }
private static void RunTest(Byte[] code, Int64 address) { try { using (var u = new Unicorn(Common.UC_ARCH_X86, Common.UC_MODE_32)) using(var disassembler = CapstoneDisassembler.CreateX86Disassembler(DisassembleMode.Bit32)) { Console.WriteLine("Unicorn version: {0}", u.Version()); // map 2MB of memory for this emulation u.MemMap(address, 2 * 1024 * 1024, Common.UC_PROT_ALL); // write machine code to be emulated to memory u.MemWrite(address, code); // initialize machine registers u.RegWrite(X86.UC_X86_REG_ESP, Utils.Int64ToBytes(address + 0x200000)); var regv = new Byte[4]; u.RegRead(X86.UC_X86_REG_ESP, regv); // tracing all instructions by having @begin > @end u.AddCodeHook((uc, addr, size, userData) => CodeHookCallback(disassembler, uc, addr, size, userData), 1, 0); // handle interrupt ourself u.AddInterruptHook(InterruptHookCallback); // handle SYSCALL u.AddSyscallHook(SyscallHookCallback); Console.WriteLine(">>> Start tracing code"); // emulate machine code in infinite time u.EmuStart(address, address + code.Length, 0u, 0u); Console.WriteLine(">>> Emulation Done!"); } } catch (UnicornEngineException ex) { Console.Error.WriteLine("Emulation FAILED! " + ex.Message); } }
private static void RunTest(Byte[] code, Int64 address, Int32 mode) { using (var u = new Unicorn(Common.UC_ARCH_X86, mode)) using (var disassembler = CapstoneDisassembler.CreateX86Disassembler(DisassembleMode.Bit32)) { Console.WriteLine("Unicorn version: {0}", u.Version()); // map 2MB of memory for this emulation u.MemMap(address, 2 * 1024 * 1024, Common.UC_PROT_ALL); // initialize machine registers u.RegWrite(X86.UC_X86_REG_EAX, 0x1234); u.RegWrite(X86.UC_X86_REG_ECX, 0x1234); u.RegWrite(X86.UC_X86_REG_EDX, 0x7890); // write machine code to be emulated to memory u.MemWrite(address, code); // initialize machine registers u.RegWrite(X86.UC_X86_REG_ESP, Utils.Int64ToBytes(address + 0x200000)); // handle IN & OUT instruction u.AddInHook(InHookCallback); u.AddOutHook(OutHookCallback); // tracing all instructions by having @begin > @end u.AddCodeHook((uc, addr, size, userData) => CodeHookCallback(disassembler, uc, addr, size, userData), 1, 0); // handle interrupt ourself u.AddInterruptHook(InterruptHookCallback); // handle SYSCALL u.AddSyscallHook(SyscallHookCallback); // intercept invalid memory events u.AddEventMemHook(MemMapHookCallback, Common.UC_HOOK_MEM_READ_UNMAPPED | Common.UC_HOOK_MEM_WRITE_UNMAPPED); Console.WriteLine(">>> Start tracing code"); // emulate machine code in infinite time u.EmuStart(address, address + code.Length, 0u, 0u); // print registers var ecx = u.RegRead(X86.UC_X86_REG_ECX); var edx = u.RegRead(X86.UC_X86_REG_EDX); var eax = u.RegRead(X86.UC_X86_REG_EAX); Console.WriteLine("[!] EAX = {0}", eax.ToString("X")); Console.WriteLine("[!] ECX = {0}", ecx.ToString("X")); Console.WriteLine("[!] EDX = {0}", edx.ToString("X")); Console.WriteLine(">>> Emulation Done!"); } }
private static void CodeHookCallback(Unicorn u, UInt64 addr, Int32 size, Object userData) { Console.Write("Tracing >>> 0x{0} ", addr.ToString("X")); var eipBuffer = new Byte[4]; Utils.CheckError(u.RegRead(X86.UC_X86_REG_EIP, eipBuffer)); var effectiveSize = Math.Min(16, size); var tmp = new Byte[effectiveSize]; Utils.CheckError(u.MemRead(addr, tmp)); foreach (var t in tmp) { Console.Write("{0} ", (0xFF & t).ToString("X")); } Console.WriteLine(); }
public static void Main(string[] args) { Speaker speak = null; Informator info = null; Creature unicorn = new Unicorn("Saint", 100, 60); Console.WriteLine(); Creature dragon = new Dragon("Fire", 200, 50); Console.WriteLine(); Dragon special = new Dragon("Morroh", 200, 80, "black dragon", "Rise!"); Console.WriteLine(); Manticore manticore = new Manticore(); Console.WriteLine(); Creature phoenix = new Phoenix("Taurus", 100, 60); Console.WriteLine(); Phoenix derek = new Phoenix("Derek", 120, 70); derek.Age = 55; Console.WriteLine(); Gargoyle howley = new Gargoyle("Howley", 100, 60); Console.WriteLine(); Unicorn trevor = new Unicorn("Trevor", 100, 60); Console.WriteLine(); Pegasus rash = new Pegasus("Rash", 120, 70); Console.WriteLine(); ArrayList creatures = new ArrayList(); creatures.Add(unicorn); creatures.Add(derek); creatures.Add(special); creatures.Add(howley); creatures.Add(dragon); creatures.Add(phoenix); creatures.Add(trevor); creatures.Add(rash); foreach(Creature c in creatures) { react += c.React; speak += c.Say; info += c.Print; } info(); Console.WriteLine(); speak(); Console.WriteLine(); Console.WriteLine(); try { trevor.Fight(manticore); Console.WriteLine("{0}: {1}", manticore.Name, manticore.Health); trevor.Enchant(dragon); trevor.Fight(null); } catch(AttackingMonsterException e) { Console.WriteLine("{0}: {1}", e.GetType(), e.Message); } Console.WriteLine(); try { rash.Fight(howley); Console.WriteLine("{0}: {1}", howley.Name, howley.Health); Console.WriteLine(); rash.Fight(special); } catch(AttackingMonsterException e) { Console.WriteLine("{0}: {1}", e.GetType(), e.Message); } try { rash.Fight(null); } catch(AttackingMonsterException e) { Console.WriteLine("{0}: {1}", e.GetType(), e.Message); } Console.WriteLine(); Console.WriteLine(); Console.WriteLine("I summon you, Satan!"); Demon satan = Demon.Summon("Satan!"); satan.Print(); Console.WriteLine(); satan.Say(); Console.WriteLine(); satan.ApocalypsisEvent += new EventHandler<ApocalypsisEventArgs>(ReactionOfAnimals); satan.CarryChaos(); satan.ApocalypsisEvent -= new EventHandler<ApocalypsisEventArgs>(ReactionOfAnimals); Console.WriteLine(); Console.WriteLine("Damage from earthquake:"); Console.WriteLine("{0}: {1}", unicorn.Name, unicorn.Health); Console.WriteLine("{0}: {1}", derek.Name, derek.Health); Console.WriteLine("{0}: {1}", phoenix.Name, phoenix.Health); Console.WriteLine("{0}: {1}", trevor.Name, trevor.Health); Console.WriteLine("{0}: {1}", rash.Name, rash.Health); Console.WriteLine(); manticore.Poison(trevor); manticore.Fight(rash); Console.WriteLine("{0}: {1}", rash.Name, rash.Health); Console.ReadKey(); }
private static void SyscallHookCallback(Unicorn u, Object userData) { var eaxBuffer = new Byte[4]; Utils.CheckError(u.RegRead(X86.UC_X86_REG_EAX, eaxBuffer)); var eax = Utils.ToInt(eaxBuffer); Console.WriteLine("Syscall >>> EAX = 0x{0}", eax.ToString("X")); u.EmuStop(); }
private static void InterruptHookCallback(Unicorn u, Int32 intNumber, Object userData) { // only handle Linux syscall if (intNumber != 0x80) { return; } var eaxBuffer = new Byte[4]; var eipBuffer = new Byte[4]; Utils.CheckError(u.RegRead(X86.UC_X86_REG_EAX, eaxBuffer)); Utils.CheckError(u.RegRead(X86.UC_X86_REG_EIP, eipBuffer)); var eax = Utils.ToInt(eaxBuffer); var eip = Utils.ToInt(eipBuffer); switch (eax) { default: Console.WriteLine("Interrupt >>> 0x{0} num {1}, EAX=0x{2}", eip.ToString("X"), intNumber.ToString("X"), eax.ToString("X")); break; case 1: // sys_exit Console.WriteLine("Interrupt >>> 0x{0} num {1}, SYS_EXIT", eip.ToString("X"), intNumber.ToString("X")); u.EmuStop(); break; case 4: // sys_write // ECX = buffer address var ecxBuffer = new Byte[4]; // EDX = buffer size var edxBuffer = new Byte[4]; Utils.CheckError(u.RegRead(X86.UC_X86_REG_ECX, ecxBuffer)); Utils.CheckError(u.RegRead(X86.UC_X86_REG_EDX, edxBuffer)); var ecx = Utils.ToInt(ecxBuffer); var edx = Utils.ToInt(edxBuffer); // read the buffer in var size = Math.Min(256, edx); var buffer = new Byte[size]; Utils.CheckError(u.MemRead(ecx, buffer)); var content = Encoding.Default.GetString(buffer); Console.WriteLine( "Interrupt >>> 0x{0}: num {1}, SYS_WRITE. buffer = 0x{2}, size = , content = '{3}'", eip.ToString("X"), ecx.ToString("X"), edx.ToString("X"), content); break; } }
private static Int32 InHookCallback(Unicorn u, Int32 port, Int32 size, Object userData) { var eip = u.RegRead(X86.UC_X86_REG_EIP); Console.WriteLine("[!] Reading from port 0x{0}, size: {1}, address: 0x{2}", port.ToString("X"), size.ToString("X"), eip.ToString("X")); var res = 0; switch (size) { case 1: // read 1 byte to AL res = 0xf1; break; case 2: // read 2 byte to AX res = 0xf2; break; case 4: // read 4 byte to EAX res = 0xf4; break; } Console.WriteLine("[!] Return value: {0}", res.ToString("X")); return res; }
private static Boolean MemMapHookCallback(Unicorn u, Int32 eventType, Int64 address, Int32 size, Int64 value, Object userData) { if (eventType == Common.UC_MEM_WRITE_UNMAPPED) { Console.WriteLine("[!] Missing memory is being WRITE at 0x{0}, data size = {1}, data value = 0x{2}. Map memory.", address.ToString("X"), size.ToString("X"), value.ToString("X")); u.MemMap(0xaaaa0000, 2 * 1024 * 1024, Common.UC_PROT_ALL); return true; } else { return false; } }
private static void CodeHookCallback( CapstoneDisassembler<X86Instruction, X86Register, X86InstructionGroup, X86InstructionDetail> disassembler, Unicorn u, Int64 addr, Int32 size, Object userData) { Console.Write("[+] 0x{0}: ", addr.ToString("X")); var eipBuffer = new Byte[4]; u.RegRead(X86.UC_X86_REG_EIP, eipBuffer); var effectiveSize = Math.Min(16, size); var tmp = new Byte[effectiveSize]; u.MemRead(addr, tmp); var sb = new StringBuilder(); foreach (var t in tmp) { sb.AppendFormat("{0} ", (0xFF & t).ToString("X")); } Console.Write("{0,-20}", sb); Console.WriteLine(Utils.Disassemble(disassembler, tmp)); }