public UIntPtr GetAddressFromName(String name, Boolean waitForSymbols) { var result = GetAddressFromName(name, waitForSymbols, out var x); if (x) { throw new Exception(UStringUtils.Sprintf("Failure determining what %s means", name)); } return(result); }
public void SetUserDefinedSymbolAllocSize(String name, UInt32 size, UIntPtr preferredAddress) { const String PREV_DEC = "The symbol named %s was previously declared with a size of %s instead of %s." + " all scripts that use this memory must give the same size. " + "Adjust the size, or delete the old alloc from the userdefined symbol list"; if (size == 0) { throw new Exception("Please provide a bigger size"); } UIntPtr p; int i; for (i = 0; i < UserDefinedSymbols.Length; i++) { if (!UserDefinedSymbols[i].IsMatch(name)) { continue; //it exists, check first } if (UserDefinedSymbols[i].AllocSize > 0 && UserDefinedSymbols[i].ProcessId == Process.Native.Id) { if (size != UserDefinedSymbols[i].AllocSize) { throw new Exception(UStringUtils.Sprintf(PREV_DEC, UserDefinedSymbols[i].Name, UserDefinedSymbols[i].AllocSize, size)); } } if (UserDefinedSymbols[i].ProcessId != Process.Native.Id) { if (preferredAddress != UIntPtr.Zero) { p = AMemoryHelper.Allocate(Process.Handle, preferredAddress.ToIntPtr(), (int)size).ToUIntPtr(); } else { p = AMemoryHelper.Allocate(Process.Handle, (int)size).ToUIntPtr(); } if (p == UIntPtr.Zero) { throw new Exception("Error allocating memory"); } UserDefinedSymbols[i].Address = p; UserDefinedSymbols[i].AddressString = AStringUtils.IntToHex(p, 8); UserDefinedSymbols[i].AllocSize = size; UserDefinedSymbols[i].ProcessId = Process.Native.Id; } return; // Redefined the symbol and exit; } //Still here, symbol Not exists, let's define a new one. if (preferredAddress != UIntPtr.Zero) { p = AMemoryHelper.Allocate(Process.Handle, preferredAddress.ToIntPtr(), (int)size).ToUIntPtr(); } else { p = AMemoryHelper.Allocate(Process.Handle, (int)size).ToUIntPtr(); } if (p == UIntPtr.Zero) { throw new Exception("Error allocating memory"); } AddUserDefinedSymbol(AStringUtils.IntToHex(p, 8), name); UserDefinedSymbols[i].AllocSize = size; UserDefinedSymbols[i].ProcessId = Process.Native.Id; }
public String DataToString(UBytePtr buf, int size, AVariableType varType, Boolean clean = false) { String result; switch (varType) { case AVariableType.Byte: { if (clean) { result = AStringUtils.IntToHex(buf[0], 2); } else { result = "(byte)" + AStringUtils.IntToHex(buf[0], 2) + '(' + buf[0] + ')'; } break; } case AVariableType.Word: { if (clean) { result = AStringUtils.IntToHex(buf.ReadUInt16(), 4); } else { result = "(word)" + AStringUtils.IntToHex(buf.ReadUInt16(), 4) + '(' + buf.ReadUInt16() + ')'; } break; } case AVariableType.DWord: { if (clean) { result = AStringUtils.IntToHex(buf.ReadUInt32(), 8); } else { result = "(dword)" + AStringUtils.IntToHex(buf.ReadUInt32(), 8) + '(' + buf.ReadUInt32() + ')'; } break; } case AVariableType.QWord: { if (clean) { result = AStringUtils.IntToHex(buf.ReadUInt64(), 16); } else { result = "(qword)" + AStringUtils.IntToHex(buf.ReadUInt64(), 16) + '(' + buf.ReadUInt64() + ')'; } break; } case AVariableType.Single: { if (clean) { result = UStringUtils.Sprintf("%.2f", buf.ReadFloat()); } else { result = "(float)" + UStringUtils.Sprintf("%.2f", buf.ReadFloat()); } break; } case AVariableType.Double: { if (clean) { result = UStringUtils.Sprintf("%.2f", buf.ReadDouble()); } else { result = "(double)" + UStringUtils.Sprintf("%.2f", buf.ReadDouble()); } break; } case AVariableType.String: { using (var p = new UBytePtr(size + 1)) { AArrayUtils.CopyMemory(p, buf, size); p[size] = 0; result = UBitConverter.UnpackSingle("z1", 0, p.ToByteArray()); } break; } case AVariableType.UnicodeString: { using (var p = new UBytePtr(size + 2)) { AArrayUtils.CopyMemory(p, buf, size); p[size] = 0; p[size + 1] = 0; result = UBitConverter.UnpackSingle("z7", 0, p.ToByteArray()); } break; } case AVariableType.Pointer: { UIntPtr a; if (Proc.IsX64) { a = (UIntPtr)buf.ReadUInt64(); } else { a = (UIntPtr)buf.ReadUInt32(); } if (clean) { result = ""; } else { result = "(pointer)"; } result += SymbolHandler.GetNameFromAddress(a, true, true, false); break; } default: { result = "(...)"; for (var i = 0; i <= Math.Min(size, 8) - 1; i++) { result = result + AStringUtils.IntToHex(buf[i], 2) + ' '; } break; } } return(result); }