public void ParseStringAndWriteToAddress(String value, UIntPtr address, AVariableType variableType, Boolean hexadecimal = false) { var v = 0UL; var s = 0.0f; var d = 0.0; var x = UIntPtr.Zero; if (hexadecimal && (variableType == AVariableType.Single || variableType == AVariableType.Double)) { if (variableType == AVariableType.Single) { variableType = AVariableType.DWord; } else { variableType = AVariableType.QWord; } } if (variableType == AVariableType.ByteArray) { var b = new ATByteArray(); AStringUtils.ConvertStringToBytes(value, hexadecimal, b); for (var i = 0; i < b.Length; i++) { Proc.Memory.Write(UIntPtr.Add(address, i).ToIntPtr(), (Byte)b[i]); } } else { if (variableType == AVariableType.Single || variableType == AVariableType.Double) { d = UStringUtils.StringToDouble(value); s = UStringUtils.StringToFloat(value); } else { if (!(variableType == AVariableType.String || variableType == AVariableType.UnicodeString)) { if (hexadecimal) { value = "0x" + value; } v = AStringUtils.StrToQWordEx(value); // todo make custom work //if ((variableType == AVariableType.Custom) && (customtype != nil) & customtype.scriptusesfloat) //s = UStringUtils.StringToFloat(value); } } switch (variableType) { case AVariableType.Byte: Proc.Memory.Write(address.ToIntPtr(), (Byte)v); break; case AVariableType.Word: Proc.Memory.Write(address.ToIntPtr(), (UInt16)v); break; case AVariableType.DWord: Proc.Memory.Write(address.ToIntPtr(), (UInt32)v); break; case AVariableType.QWord: Proc.Memory.Write(address.ToIntPtr(), v); break; case AVariableType.Single: Proc.Memory.Write(address.ToIntPtr(), s); break; case AVariableType.Double: Proc.Memory.Write(address.ToIntPtr(), d); break; case AVariableType.String: Proc.Memory.Write(address.ToIntPtr(), value, Encoding.ASCII); break; case AVariableType.UnicodeString: Proc.Memory.Write(address.ToIntPtr(), value, Encoding.UTF8); break; case AVariableType.Custom: // todo make custom work //{ // if (customtype != nil) // { // getmem(ba, customtype.bytesize); // //try // if (readprocessmemory(processhandle, (pointer)(address), ba, customtype.bytesize, x)) // { // if (customtype.scriptusesfloat) // customtype.convertfloattodata(s, ba, address); // else // customtype.convertintegertodata(v, ba, address); // // writeprocessmemory(processhandle, (pointer)(address), ba, customtype.bytesize, x); // } // //finally // freememandnil(ba); // //end; // } //} break; } } }
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); }