peppy
peppy
CC#
Created by peppy on 1/1/2024 in #help
STJ: Prevent or reverse escaping of base64 string during deserialization
I am using STJ to decode a structure with a string member; the string contains an image in base64 format. Even with Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping set in the JsonSerializerOptions passed to the JsonSerializer.Deserialize call, the input is escaped:
input: (...) DPt+X/ (...)
output: (...) DPtu002BX/ (...)
input: (...) DPt+X/ (...)
output: (...) DPtu002BX/ (...)
Can I obtain the unmodified input in any way? Reading through the docs, I understand that STJ, in the name of safety, has a blacklist of things it will escape regardless of the user's preferences. It seems to me like I can't prevent it from doing it. I tried Regex.Unescape to reverse it, but it does not seem to work, possibly because of the missing backslash in front of u002B. How can I obtain the input exactly as given?
1 replies
CC#
Created by peppy on 6/15/2023 in #help
In a hooking/detouring scenario, "A callback was made on a garbage collected delegate of type (...)"
8 replies
CC#
Created by peppy on 6/5/2023 in #help
✅ ✅ Vararg P/Invoke (x86) throws BadImageFormatException (0x80131124 "Index not found")
67 replies
CC#
Created by peppy on 6/5/2023 in #help
Plugin attempts to load dependency again, despite it already being loaded?
7 replies
CC#
Created by peppy on 4/20/2023 in #help
❔ Default implementation of a `static abstract` base interface member in derived interface
I am trying to implement an idea I saw in MessagePack for C#:
public interface IMemoryPackable<T>
{
static abstract void Serialize<TBufferWriter>(ref MemoryPackWriter<TBufferWriter> writer, scoped ref T? value)
where TBufferWriter : IBufferWriter<byte>;
static abstract void Deserialize(ref MemoryPackReader reader, scoped ref T? value);
}
public interface IMemoryPackable<T>
{
static abstract void Serialize<TBufferWriter>(ref MemoryPackWriter<TBufferWriter> writer, scoped ref T? value)
where TBufferWriter : IBufferWriter<byte>;
static abstract void Deserialize(ref MemoryPackReader reader, scoped ref T? value);
}
where using static abstract surfaces the methods on the type itself, which I find very useful. I came up with this:
public interface IDispatchable<T>
{
public static abstract bool Initialize();
public static abstract bool Serialize(in ROS<T> src, in Span<byte> dest, out int bytesWritten);
public static abstract bool Deserialize(in ROS<byte> src, in Span<T> dest, int srcLen);
}
public interface IDispatchable<T>
{
public static abstract bool Initialize();
public static abstract bool Serialize(in ROS<T> src, in Span<byte> dest, out int bytesWritten);
public static abstract bool Deserialize(in ROS<byte> src, in Span<T> dest, int srcLen);
}
Now- if T were a struct, I can provide good default impls, so I declare a derived interface that constrains T:
public interface IBlockDispatchable<T> : IDispatchable<T> where T : struct { }
public interface IBlockDispatchable<T> : IDispatchable<T> where T : struct { }
Can this interface now declare a default implementation of the static abstract members of IDispatchable<T> such that implementing structs surface that default implementation? I know the derived interface can declare an explicit impl of the base interface method, but then the explicit impl is not available through the struct's type as I expect static abstract/virtual members to be. If this is not the correct way to approach this, I'm open to all suggestions on how I can provide specialized behavior to structs in this particular instance. Thank you!
8 replies
CC#
Created by peppy on 2/26/2023 in #help
❔ Why is typeof(T).FullName a ``string?``, but typeof(T).Name a ``string``
And in which instances is typeof(T).FullName potentially null? Is there a circumstance in which I can't rely on that field being available?
5 replies