Skip to content

Instantly share code, notes, and snippets.

@TheGreatSageEqualToHeaven
Created March 12, 2025 12:53
Show Gist options
  • Save TheGreatSageEqualToHeaven/e242aee39f9ca91a2c19cb23b5eb1b90 to your computer and use it in GitHub Desktop.
Save TheGreatSageEqualToHeaven/e242aee39f9ca91a2c19cb23b5eb1b90 to your computer and use it in GitHub Desktop.
Oracle client in C#
using System.Net;
using System.Text;
using Newtonsoft.Json;
public class OracleClient
{
public enum OracleRenamingType
{
NONE,
UNIQUE,
UNIQUE_VALUE_BASED
}
public class OracleOptions
{
[JsonProperty("renamingType")]
public OracleRenamingType? RenamingType { get; set; }
[JsonProperty("removeDotZero")]
public bool? RemoveDotZero { get; set; }
[JsonProperty("removeFunctionEntryNote")]
public bool? RemoveFunctionEntryNote { get; set; }
[JsonProperty("swapConstantPosition")]
public bool? SwapConstantPosition { get; set; }
[JsonProperty("inlineWhileConditions")]
public bool? InlineWhileConditions { get; set; }
[JsonProperty("showFunctionLineDefined")]
public bool? ShowFunctionLineDefined { get; set; }
[JsonProperty("removeUselessNumericForStep")]
public bool? RemoveUselessNumericForStep { get; set; }
[JsonProperty("removeUselessReturnInFunction")]
public bool? RemoveUselessReturnInFunction { get; set; }
[JsonProperty("sugarRecursiveLocalFunctions")]
public bool? SugarRecursiveLocalFunctions { get; set; }
[JsonProperty("sugarLocalFunctions")]
public bool? SugarLocalFunctions { get; set; }
[JsonProperty("sugarGlobalFunctions")]
public bool? SugarGlobalFunctions { get; set; }
[JsonProperty("sugarGenericFor")]
public bool? SugarGenericFor { get; set; }
[JsonProperty("showFunctionDebugName")]
public bool? ShowFunctionDebugName { get; set; }
[JsonProperty("upvalueComment")]
public bool? UpvalueComment { get; set; }
}
private static readonly HttpClient HttpClient = new();
public static string Decompile(string key, byte[] bytecode)
{
var base64Script = Convert.ToBase64String(bytecode);
var options = new OracleOptions();
var requestBody = new
{
script = base64Script,
decompilerOptions = options
};
var jsonBody = JsonConvert.SerializeObject(requestBody, new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
});
var request = new HttpRequestMessage(HttpMethod.Post, $"https://oracle.mshq.dev/decompile?key={key}")
{
Content = new StringContent(jsonBody, Encoding.UTF8, "application/json")
};
try
{
var response = HttpClient.SendAsync(request).Result;
var responseBody = response.Content.ReadAsStringAsync().Result;
return response.StatusCode switch
{
HttpStatusCode.OK => responseBody,
_ => throw new Exception($"Failed to decompile: {response.StatusCode}")
};
}
catch
{
throw new Exception("Failed to decompile");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment