Here are the examples of the csharp api System.IO.TextWriter.Write(string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1807 Examples
19
View Source File : Logger.cs
License : MIT License
Project Creator : 0x0ade
License : MIT License
Project Creator : 0x0ade
public static void Log(LogLevel level, string tag, string str) {
if (level < Level)
return;
TextWriter w = Writer;
w.Write("(");
w.Write(DateTime.Now);
w.Write(LogCelesteNetTag ? ") [CelesteNet] [" : ") [");
w.Write(level.ToString());
w.Write("] [");
w.Write(tag);
w.Write("] ");
w.WriteLine(str);
}
19
View Source File : Program.cs
License : zlib License
Project Creator : 0x0ade
License : zlib License
Project Creator : 0x0ade
public static void Main(string[] args) {
XnaToFnaUtil xtf = new XnaToFnaUtil();
Console.WriteLine($"XnaToFna {XnaToFnaUtil.Version}");
Console.WriteLine($"using MonoMod {MonoModder.Version}");
bool showHelp = false;
bool showVersion = false;
bool relinkOnly = false;
OptionSet options = new OptionSet {
{ "h|help", "Show this message and exit.", v => showHelp = v != null },
{ "v|version", "Show the version and exit.", v => showVersion = v != null },
{ "profile=", "Choose between multiple base profiles:\ndefault, minimal, forms", v => {
switch (v.ToLowerInvariant()) {
case "default":
xtf.HookCompat = true;
xtf.HookHacks = true;
xtf.HookEntryPoint = false;
xtf.HookLocks = false;
xtf.FixOldMonoXML = false;
xtf.HookBinaryFormatter = true;
xtf.HookReflection = true;
break;
case "minimal":
xtf.HookCompat = false;
xtf.HookHacks = false;
xtf.HookEntryPoint = false;
xtf.HookLocks = false;
xtf.FixOldMonoXML = false;
xtf.HookBinaryFormatter = false;
xtf.HookReflection = false;
break;
case "forms":
xtf.HookCompat = true;
xtf.HookHacks = false;
xtf.HookEntryPoint = true;
xtf.HookLocks = false;
xtf.FixOldMonoXML = false;
xtf.HookBinaryFormatter = false;
xtf.HookReflection = false;
break;
}
} },
{ "relinkonly=", "Only read and write the replacedemblies listed.", (bool v) => relinkOnly = v },
{ "hook-compat=", "Toggle Forms and P/Invoke compatibility hooks.", (bool v) => xtf.HookCompat = v },
{ "hook-hacks=", "Toggle some hack hooks, f.e.\nXNATOFNA_DISPLAY_FULLSCREEN", (bool v) => xtf.HookEntryPoint = v },
{ "hook-locks=", "Toggle if locks should be \"destroyed\" or not.", (bool v) => xtf.HookLocks = v },
{ "hook-oldmonoxml=", "Toggle basic XML serialization fixes.\nPlease try updating mono first!", (bool v) => xtf.FixOldMonoXML = v },
{ "hook-binaryformatter=", "Toggle BinaryFormatter-related fixes.", (bool v) => xtf.HookBinaryFormatter = v },
{ "hook-reflection=", "Toggle reflection-related fixes.", (bool v) => xtf.HookBinaryFormatter = v },
{ "hook-patharg=", "Hook the given method to receive fixed paths.\nCan be used multiple times.", v => xtf.FixPathsFor.Add(v) },
{ "ilplatform=", "Choose the target IL platform:\nkeep, x86, x64, anycpu, x86pref", v => xtf.PreferredPlatform = ParseEnum(v, ILPlatform.Keep) },
{ "mixeddeps=", "Choose the action performed to mixed dependencies:\nkeep, stub, remove", v => xtf.MixedDeps = ParseEnum(v, MixedDepAction.Keep) },
{ "removepublickeytoken=", "Remove the public key token of a dependency.\nCan be used multiple times.", v => xtf.DestroyPublicKeyTokens.Add(v) },
};
void WriteHelp(TextWriter writer) {
writer.WriteLine("Usage: <mono> XnaToFna.exe [options] <--> FileOrDir <FileOrDir> <...>");
options.WriteOptionDescriptions(writer);
}
List<string> extra;
try {
extra = options.Parse(args);
} catch (OptionException e) {
Console.Error.Write("Command parse error: ");
Console.Error.WriteLine(e.Message);
Console.Error.WriteLine();
WriteHelp(Console.Error);
return;
}
if (showVersion) {
return;
}
if (showHelp) {
WriteHelp(Console.Out);
return;
}
foreach (string arg in extra)
xtf.ScanPath(arg);
if (!relinkOnly && !Debugger.IsAttached) // Otherwise catches XnaToFna.vshost.exe
xtf.ScanPath(Directory.GetCurrentDirectory());
xtf.OrderModules();
xtf.RelinkAll();
xtf.Log("[Main] Done!");
if (Debugger.IsAttached) // Keep window open when running in IDE
Console.ReadKey();
}
19
View Source File : Disassembler.cs
License : MIT License
Project Creator : 0xd4d
License : MIT License
Project Creator : 0xd4d
public void Disreplacedemble(Formatter formatter, TextWriter output, DisasmInfo method) {
formatterOutput.writer = output;
targets.Clear();
sortedTargets.Clear();
bool uppercaseHex = formatter.Options.UppercaseHex;
output.Write(commentPrefix);
output.WriteLine("================================================================================");
output.Write(commentPrefix);
output.WriteLine(method.MethodFullName);
uint codeSize = 0;
foreach (var info in method.Code)
codeSize += (uint)info.Code.Length;
var codeSizeHexText = codeSize.ToString(uppercaseHex ? "X" : "x");
output.WriteLine($"{commentPrefix}{codeSize} (0x{codeSizeHexText}) bytes");
var instrCount = method.Instructions.Count;
var instrCountHexText = instrCount.ToString(uppercaseHex ? "X" : "x");
output.WriteLine($"{commentPrefix}{instrCount} (0x{instrCountHexText}) instructions");
void Add(ulong address, TargetKind kind) {
if (!targets.TryGetValue(address, out var addrInfo))
targets[address] = new AddressInfo(kind);
else if (addrInfo.Kind < kind)
addrInfo.Kind = kind;
}
if (method.Instructions.Count > 0)
Add(method.Instructions[0].IP, TargetKind.Unknown);
foreach (ref var instr in method.Instructions) {
switch (instr.FlowControl) {
case FlowControl.Next:
case FlowControl.Interrupt:
break;
case FlowControl.UnconditionalBranch:
Add(instr.NextIP, TargetKind.Unknown);
if (instr.Op0Kind == OpKind.NearBranch16 || instr.Op0Kind == OpKind.NearBranch32 || instr.Op0Kind == OpKind.NearBranch64)
Add(instr.NearBranchTarget, TargetKind.Branch);
break;
case FlowControl.ConditionalBranch:
case FlowControl.XbeginXabortXend:
if (instr.Op0Kind == OpKind.NearBranch16 || instr.Op0Kind == OpKind.NearBranch32 || instr.Op0Kind == OpKind.NearBranch64)
Add(instr.NearBranchTarget, TargetKind.Branch);
break;
case FlowControl.Call:
if (instr.Op0Kind == OpKind.NearBranch16 || instr.Op0Kind == OpKind.NearBranch32 || instr.Op0Kind == OpKind.NearBranch64)
Add(instr.NearBranchTarget, TargetKind.Call);
break;
case FlowControl.IndirectBranch:
Add(instr.NextIP, TargetKind.Unknown);
// Unknown target
break;
case FlowControl.IndirectCall:
// Unknown target
break;
case FlowControl.Return:
case FlowControl.Exception:
Add(instr.NextIP, TargetKind.Unknown);
break;
default:
Debug.Fail($"Unknown flow control: {instr.FlowControl}");
break;
}
var baseReg = instr.MemoryBase;
if (baseReg == Register.RIP || baseReg == Register.EIP) {
int opCount = instr.OpCount;
for (int i = 0; i < opCount; i++) {
if (instr.GetOpKind(i) == OpKind.Memory) {
if (method.Contains(instr.IPRelativeMemoryAddress))
Add(instr.IPRelativeMemoryAddress, TargetKind.Branch);
break;
}
}
}
else if (instr.MemoryDisplSize >= 2) {
ulong displ;
switch (instr.MemoryDisplSize) {
case 2:
case 4: displ = instr.MemoryDisplacement; break;
case 8: displ = (ulong)(int)instr.MemoryDisplacement; break;
default:
Debug.Fail($"Unknown mem displ size: {instr.MemoryDisplSize}");
goto case 8;
}
if (method.Contains(displ))
Add(displ, TargetKind.Branch);
}
}
foreach (var map in method.ILMap) {
if (targets.TryGetValue(map.nativeStartAddress, out var info)) {
if (info.Kind < TargetKind.BlockStart && info.Kind != TargetKind.Unknown)
info.Kind = TargetKind.BlockStart;
}
else
targets.Add(map.nativeStartAddress, info = new AddressInfo(TargetKind.Unknown));
if (info.ILOffset < 0)
info.ILOffset = map.ilOffset;
}
int labelIndex = 0, methodIndex = 0;
string GetLabel(int index) => LABEL_PREFIX + index.ToString();
string GetFunc(int index) => FUNC_PREFIX + index.ToString();
foreach (var kv in targets) {
if (method.Contains(kv.Key))
sortedTargets.Add(kv);
}
sortedTargets.Sort((a, b) => a.Key.CompareTo(b.Key));
foreach (var kv in sortedTargets) {
var address = kv.Key;
var info = kv.Value;
switch (info.Kind) {
case TargetKind.Unknown:
info.Name = null;
break;
case TargetKind.Data:
info.Name = GetLabel(labelIndex++);
break;
case TargetKind.BlockStart:
case TargetKind.Branch:
info.Name = GetLabel(labelIndex++);
break;
case TargetKind.Call:
info.Name = GetFunc(methodIndex++);
break;
default:
throw new InvalidOperationException();
}
}
foreach (ref var instr in method.Instructions) {
ulong ip = instr.IP;
if (targets.TryGetValue(ip, out var lblInfo)) {
output.WriteLine();
if (!(lblInfo.Name is null)) {
output.Write(lblInfo.Name);
output.Write(':');
output.WriteLine();
}
if (lblInfo.ILOffset >= 0) {
if (ShowSourceCode) {
foreach (var info in sourceCodeProvider.GetStatementLines(method, lblInfo.ILOffset)) {
output.Write(commentPrefix);
var line = info.Line;
int column = commentPrefix.Length;
WriteWithTabs(output, line, 0, line.Length, '\0', ref column);
output.WriteLine();
if (info.Partial) {
output.Write(commentPrefix);
column = commentPrefix.Length;
WriteWithTabs(output, line, 0, info.Span.Start, ' ', ref column);
output.WriteLine(new string('^', info.Span.Length));
}
}
}
}
}
if (ShowAddresses) {
var address = FormatAddress(bitness, ip, uppercaseHex);
output.Write(address);
output.Write(" ");
}
else
output.Write(formatter.Options.TabSize > 0 ? "\t\t" : " ");
if (ShowHexBytes) {
if (!method.TryGetCode(ip, out var nativeCode))
throw new InvalidOperationException();
var codeBytes = nativeCode.Code;
int index = (int)(ip - nativeCode.IP);
int instrLen = instr.Length;
for (int i = 0; i < instrLen; i++) {
byte b = codeBytes[index + i];
output.Write(b.ToString(uppercaseHex ? "X2" : "x2"));
}
int missingBytes = HEXBYTES_COLUMN_BYTE_LENGTH - instrLen;
for (int i = 0; i < missingBytes; i++)
output.Write(" ");
output.Write(" ");
}
formatter.Format(instr, formatterOutput);
output.WriteLine();
}
}
19
View Source File : JsonWriter.cs
License : MIT License
Project Creator : 404Lcc
License : MIT License
Project Creator : 404Lcc
private void PutString (string str)
{
Put (String.Empty);
writer.Write ('"');
int n = str.Length;
for (int i = 0; i < n; i++) {
switch (str[i]) {
case '\n':
writer.Write ("\\n");
continue;
case '\r':
writer.Write ("\\r");
continue;
case '\t':
writer.Write ("\\t");
continue;
case '"':
case '\\':
writer.Write ('\\');
writer.Write (str[i]);
continue;
case '\f':
writer.Write ("\\f");
continue;
case '\b':
writer.Write ("\\b");
continue;
}
if ((int) str[i] >= 32 && (int) str[i] <= 126) {
writer.Write (str[i]);
continue;
}
// Default, turn into a \uXXXX sequence
IntToHex ((int) str[i], hex_seq);
writer.Write ("\\u");
writer.Write (hex_seq);
}
writer.Write ('"');
}
19
View Source File : JsonFile.cs
License : Apache License 2.0
Project Creator : 42skillz
License : Apache License 2.0
Project Creator : 42skillz
public static void WriteToJsonFile<T>(string filePath, T objectToWrite, bool append = false) where T : new()
{
TextWriter writer = null;
try
{
var contentsToWriteToFile = JsonConvert.SerializeObject(objectToWrite);
writer = new StreamWriter(filePath, append);
writer.Write(contentsToWriteToFile);
}
finally
{
writer?.Close();
}
}
19
View Source File : JsonWriter.cs
License : MIT License
Project Creator : 404Lcc
License : MIT License
Project Creator : 404Lcc
private void Put (string str)
{
if (pretty_print && ! context.ExpectingValue)
for (int i = 0; i < indentation; i++)
writer.Write (' ');
writer.Write (str);
}
19
View Source File : JsonWriter.cs
License : MIT License
Project Creator : 404Lcc
License : MIT License
Project Creator : 404Lcc
public void Write (double number)
{
DoValidation (Condition.Value);
PutNewline ();
string str = Convert.ToString (number, number_format);
Put (str);
if (str.IndexOf ('.') == -1 &&
str.IndexOf ('E') == -1)
writer.Write (".0");
context.ExpectingValue = false;
}
19
View Source File : JsonWriter.cs
License : MIT License
Project Creator : 404Lcc
License : MIT License
Project Creator : 404Lcc
public void WritePropertyName (string property_name)
{
DoValidation (Condition.Property);
PutNewline ();
PutString (property_name);
if (pretty_print) {
if (property_name.Length > context.Padding)
context.Padding = property_name.Length;
for (int i = context.Padding - property_name.Length;
i >= 0; i--)
writer.Write (' ');
writer.Write (": ");
} else
writer.Write (':');
context.ExpectingValue = true;
}
19
View Source File : ITextSource.cs
License : MIT License
Project Creator : Abdesol
License : MIT License
Project Creator : Abdesol
public void WriteTextTo(TextWriter writer)
{
writer.Write(text);
}
19
View Source File : ITextSource.cs
License : MIT License
Project Creator : Abdesol
License : MIT License
Project Creator : Abdesol
public void WriteTextTo(TextWriter writer, int offset, int length)
{
writer.Write(text.Substring(offset, length));
}
19
View Source File : HtmlOptions.cs
License : MIT License
Project Creator : Abdesol
License : MIT License
Project Creator : Abdesol
public virtual void WriteStyleAttributeForColor(TextWriter writer, HighlightingColor color)
{
if (writer == null)
throw new ArgumentNullException("writer");
if (color == null)
throw new ArgumentNullException("color");
writer.Write(" style=\"");
WebUtility.HtmlEncode(color.ToCss(), writer);
writer.Write('"');
}
19
View Source File : HtmlRichTextWriter.cs
License : MIT License
Project Creator : Abdesol
License : MIT License
Project Creator : Abdesol
void FlushSpace(bool nextIsWhitespace)
{
if (hreplacedpace) {
if (spaceNeedsEscaping || nextIsWhitespace)
htmlWriter.Write(" ");
else
htmlWriter.Write(' ');
hreplacedpace = false;
spaceNeedsEscaping = true;
}
}
19
View Source File : HtmlRichTextWriter.cs
License : MIT License
Project Creator : Abdesol
License : MIT License
Project Creator : Abdesol
void WriteChar(char c)
{
bool isWhitespace = char.IsWhiteSpace(c);
FlushSpace(isWhitespace);
switch (c) {
case ' ':
if (spaceNeedsEscaping)
htmlWriter.Write(" ");
else
hreplacedpace = true;
break;
case '\t':
for (int i = 0; i < options.TabSize; i++) {
htmlWriter.Write(" ");
}
break;
case '\r':
break; // ignore; we'll write the <br/> with the following \n
case '\n':
htmlWriter.Write("<br/>");
needIndentation = true;
break;
default:
WebUtility.HtmlEncode(c.ToString(), htmlWriter);
break;
}
// If we just handled a space by setting hreplacedpace = true,
// we mustn't set spaceNeedsEscaping as doing so would affect our own space,
// not just the following spaces.
if (c != ' ') {
// Following spaces must be escaped if c was a newline/tab;
// and they don't need escaping if c was a normal character.
spaceNeedsEscaping = isWhitespace;
}
}
19
View Source File : HtmlRichTextWriter.cs
License : MIT License
Project Creator : Abdesol
License : MIT License
Project Creator : Abdesol
public override void EndSpan()
{
htmlWriter.Write(endTagStack.Pop());
}
19
View Source File : HtmlRichTextWriter.cs
License : MIT License
Project Creator : Abdesol
License : MIT License
Project Creator : Abdesol
public override void BeginSpan(HighlightingColor highlightingColor)
{
WriteIndentationAndSpace();
if (options.ColorNeedsSpanForStyling(highlightingColor)) {
htmlWriter.Write("<span");
options.WriteStyleAttributeForColor(htmlWriter, highlightingColor);
htmlWriter.Write('>');
endTagStack.Push("</span>");
} else {
endTagStack.Push(null);
}
}
19
View Source File : HtmlRichTextWriter.cs
License : MIT License
Project Creator : Abdesol
License : MIT License
Project Creator : Abdesol
public override void BeginHyperlinkSpan(Uri uri)
{
WriteIndentationAndSpace();
string link = WebUtility.HtmlEncode(uri.ToString());
htmlWriter.Write("<a href=\"" + link + "\">");
endTagStack.Push("</a>");
}
19
View Source File : PlainRichTextWriter.cs
License : MIT License
Project Creator : Abdesol
License : MIT License
Project Creator : Abdesol
void WriteIndentation()
{
for (int i = 0; i < indentationLevel; i++) {
textWriter.Write(indentationString);
}
}
19
View Source File : Ecoji.cs
License : MIT License
Project Creator : abock
License : MIT License
Project Creator : abock
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void WriteRune(this TextWriter writer, int rune)
=> writer.Write(char.ConvertFromUtf32(rune));
19
View Source File : Extensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public static string BuildPacketString(this byte[] bytes, int startPosition = 0, int bytesToOutput = 9999)
{
TextWriter tw = new StringWriter();
byte[] buffer = bytes;
int column = 0;
int row = 0;
int columns = 16;
tw.Write(" x ");
for (int i = 0; i < columns; i++)
{
tw.Write(i.ToString().PadLeft(3));
}
tw.WriteLine(" |Text");
tw.Write(" 0 ");
string asciiLine = "";
for (int i = startPosition; i < startPosition+bytesToOutput; i++)
{
if (i >= buffer.Length) {
break;
}
if (column >= columns)
{
row++;
column = 0;
tw.WriteLine(" |" + asciiLine);
asciiLine = "";
tw.Write((row * columns).ToString().PadLeft(4));
tw.Write(" ");
}
tw.Write(buffer[i].ToString("X2").PadLeft(3));
if (Char.IsControl((char)buffer[i]))
asciiLine += " ";
else
asciiLine += (char)buffer[i];
column++;
}
tw.Write("".PadLeft((columns - column) * 3));
tw.WriteLine(" |" + asciiLine);
return tw.ToString();
}
19
View Source File : LiquidExtensions.cs
License : MIT License
Project Creator : Adoxio
License : MIT License
Project Creator : Adoxio
public static void RenderLiquid(this HtmlHelper html, string source, string sourceIdentifier, TextWriter output, IDictionary<string, object> variables = null)
{
if (string.IsNullOrEmpty(source))
{
return;
}
if (!html.BooleanSetting("Liquid/Enabled").GetValueOrDefault(true))
{
output.Write(source);
return;
}
var environment = html.GetLiquidEnvironment();
var localVariables = Hash.FromDictionary(environment.Globals);
if (variables != null)
{
localVariables.Merge(variables);
}
// Save a reference to this HtmlHelper to the liquid context so that any child "Donut Drops" can
// also access the same custom ViewBag information like "ViewSupportsDonuts".
var registers = Hash.FromDictionary(environment.Registers);
registers["htmlHelper"] = html;
var context = new Context(new List<Hash> { localVariables }, new Hash(), registers, false);
InternalRenderLiquid(source, sourceIdentifier, output, context);
}
19
View Source File : Formatter.cs
License : MIT License
Project Creator : adrianoc
License : MIT License
Project Creator : adrianoc
private static void WriteVariables(TextWriter writer, MethodBody body)
{
var variables = body.Variables;
writer.Write('\t');
writer.Write(".locals {0}(", body.InitLocals ? "init " : string.Empty);
for (var i = 0; i < variables.Count; i++)
{
if (i > 0)
{
writer.Write(", ");
}
var variable = variables[i];
writer.Write("{0} {1}", variable.VariableType, variable);
}
writer.WriteLine(")");
}
19
View Source File : Formatter.cs
License : MIT License
Project Creator : adrianoc
License : MIT License
Project Creator : adrianoc
private static void WriteInstruction(TextWriter writer, Instruction instruction)
{
writer.Write(FormatLabel(instruction.Offset));
writer.Write(": ");
writer.Write(instruction.OpCode.Name);
if (null != instruction.Operand)
{
writer.Write(' ');
WriteOperand(writer, instruction.Operand);
}
}
19
View Source File : Formatter.cs
License : MIT License
Project Creator : adrianoc
License : MIT License
Project Creator : adrianoc
private static void WriteOperand(TextWriter writer, object operand)
{
if (null == operand)
{
throw new ArgumentNullException("operand");
}
var target = operand as Instruction;
if (null != target)
{
writer.Write(FormatLabel(target.Offset));
return;
}
var targets = operand as Instruction[];
if (null != targets)
{
WriteLabelList(writer, targets);
return;
}
var s = operand as string;
if (null != s)
{
writer.Write("\"" + s + "\"");
return;
}
var parameter = operand as ParameterDefinition;
if (parameter != null)
{
writer.Write(ToInvariantCultureString(parameter.Sequence));
return;
}
s = ToInvariantCultureString(operand);
writer.Write(s);
}
19
View Source File : Formatter.cs
License : MIT License
Project Creator : adrianoc
License : MIT License
Project Creator : adrianoc
private static void WriteLabelList(TextWriter writer, Instruction[] instructions)
{
writer.Write("(");
for (var i = 0; i < instructions.Length; i++)
{
if (i != 0)
{
writer.Write(", ");
}
writer.Write(FormatLabel(instructions[i].Offset));
}
writer.Write(")");
}
19
View Source File : Formatter.cs
License : MIT License
Project Creator : adrianoc
License : MIT License
Project Creator : adrianoc
private static void WriteExceptionHandlers(TextWriter writer, MethodBody body)
{
if (!body.HasExceptionHandlers)
{
return;
}
foreach (var handler in body.ExceptionHandlers)
{
writer.Write("\t");
writer.WriteLine(".try {0} to {1} {2} handler {3} to {4}",
FormatLabel(handler.TryStart),
FormatLabel(handler.TryEnd),
FormatHandlerType(handler),
FormatLabel(handler.HandlerStart),
FormatLabel(handler.HandlerEnd));
}
}
19
View Source File : ConvertEditLinksFilter.cs
License : Apache License 2.0
Project Creator : advanced-cms
License : Apache License 2.0
Project Creator : advanced-cms
public void Flush(bool rewriteText)
{
var bufferedText = stringBuilder.ToString();
if (rewriteText && textRewriteFunction != null)
{
bufferedText = textRewriteFunction.Invoke(bufferedText);
}
InnerTextWriter.Write(bufferedText);
InnerTextWriter.Flush();
}
19
View Source File : Tester.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
static void TestFrame(string replacedle, ZeroOperatorStateType state, params byte[][] frames)
{
Console.Error.Write(replacedle);
Console.ForegroundColor = ConsoleColor.Red;
TestFrameInner(replacedle, state, frames);
Console.Error.WriteLine();
Console.Error.WriteLine("**----**");
Console.ResetColor();
}
19
View Source File : Tester.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
static void TestFrameInner(string replacedle, ZeroOperatorStateType state, byte[][] frames)
{
using (var socket = ZSocket.CreateClientSocket(address, ZSocketType.DEALER))
{
socket.SetOption(ZSocketOption.RCVTIMEO, 30000);
if (!socket.SendTo(frames))
{
Console.Error.Write(" : Send Error");
return;
}
var result = socket.Receive();
if (!result.InteractiveSuccess)
Console.Error.WriteLine(" : Receive Error");
if (result.State == state)
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write($"(success) : {state}");
}
else
Console.Error.Write($"(bad) : {result.State}");
}
}
19
View Source File : JsonParser.cs
License : MIT License
Project Creator : agens-no
License : MIT License
Project Creator : agens-no
public void WriteToStream(TextWriter tw)
{
tw.Write(WriteToString());
}
19
View Source File : DecompileFullOutput.cs
License : GNU General Public License v3.0
Project Creator : ahmed605
License : GNU General Public License v3.0
Project Creator : ahmed605
public void Process(File file, TextWriter writer)
{
var decoder = new Decoder(file);
var program = new ScriptProgram(decoder);
var replacedyzer = new ControlFlowreplacedyzer(program);
replacedyzer.replacedyze();
var stackreplacedyzer = new StackUsereplacedyzer(program);
stackreplacedyzer.replacedyze();
foreach (Function function in program.Functions)
{
var sb = new StringBuilder();
for (int i = 0; i < function.ParameterCount; i++)
{
if (i != 0)
{
sb.Append(", ");
}
sb.Append("var");
sb.Append(i);
}
writer.WriteLine(string.Format("{0} {1}({2})", function.ReturnCount > 0 ? "function" : "void",
function.Name, sb));
writer.WriteLine("{");
if (function.VariableCount > 2)
{
writer.Write(" auto ");
for (int i = 2; i < function.VariableCount; i++)
{
if (i != 2)
{
writer.Write(", ");
}
writer.Write("var" + (i + function.ParameterCount));
}
writer.WriteLine(";");
}
if (function.TemporaryCount > 0)
{
writer.Write(" auto ");
for (int i = 0; i < function.TemporaryCount; i++)
{
if (i != 0)
{
writer.Write(", ");
}
writer.Write("temp" + i);
}
writer.WriteLine(";");
}
if (function.TemporaryCount > 0 || function.VariableCount > 2)
{
writer.WriteLine();
}
ProcessCodePath(writer, function.MainCodePath, " ");
writer.WriteLine("}");
writer.WriteLine();
}
}
19
View Source File : DecompileScruffOutput.cs
License : GNU General Public License v3.0
Project Creator : ahmed605
License : GNU General Public License v3.0
Project Creator : ahmed605
private void WriteInstruction(TextWriter writer, HLInstruction instruction, string indent)
{
//writer.Write(string.Format("{0}{1:x}: ", indent, instruction.Instruction.Offset));
if (instruction.BranchFunction != null)
{
writer.Write(indent);
writer.WriteLine(string.Format(".call {0}", instruction.BranchFunction.Name));
}
else if (instruction.ExitFunction)
{
Function parentFunction = instruction.ParentCodePath.ParentFunction;
if (instruction.ExitFunction && instruction == parentFunction.MainCodePath.EndInstruction)
{
// Don't write the default return unless we're somewhere in the middle!
}
else
{
writer.Write(indent);
writer.WriteLine(".return");
}
}
else if (instruction.Instruction is InstructionNative)
{
writer.Write(indent);
writer.WriteLine(string.Format(".native {1} // in={2}, out={3}", instruction.Instruction.OpCode,
instruction.Instruction.Operands[2], instruction.Instruction.Operands[0],
instruction.Instruction.Operands[1]));
}
else if (instruction.UnconditionalBranch || instruction.Instruction.OpCode == OpCode.Jump)
{
//writer.WriteLine();
}
else
{
writer.Write(indent);
writer.WriteLine(string.Format("{0}", instruction.Instruction.GetInstructionText()));
}
}
19
View Source File : DecompileFullOutput.cs
License : GNU General Public License v3.0
Project Creator : ahmed605
License : GNU General Public License v3.0
Project Creator : ahmed605
private void ProcessCodePath(TextWriter writer, CodePath path, string indent)
{
HLInstruction instruction = path.GetFirstInstruction();
while (instruction != null)
{
Annotate(writer, indent, instruction);
if (instruction.UnconditionalBranch)
{
// Not used
}
else if (instruction.IsConditionalBranch)
{
if (_nextIfIsAnElseIf)
{
writer.Write(string.Format("{0}else if", indent));
_nextIfIsAnElseIf = false;
}
else
{
writer.Write(string.Format("{0}if", indent));
}
writer.WriteLine(string.Format(" ({0})", instruction.ProcessedStackValue));
writer.WriteLine(indent + "{");
ProcessCodePath(writer, instruction.BranchCodesPaths[instruction.DefaultConditional],
indent + " ");
writer.WriteLine(indent + "}");
if (instruction.BranchCodesPaths.ContainsKey(!instruction.DefaultConditional))
{
CodePath elsePath = instruction.BranchCodesPaths[!instruction.DefaultConditional];
if (elsePath.StartInstruction != null)
{
if (IsCodePathAnIfPath(elsePath))
{
_nextIfIsAnElseIf = true;
ProcessCodePath(writer, elsePath, indent);
}
else
{
writer.WriteLine(indent + "else");
writer.WriteLine(indent + "{");
ProcessCodePath(writer, elsePath, indent + " ");
writer.WriteLine(indent + "}");
}
}
}
}
else if (instruction.IsSwitchBranch)
{
// Do switch cases ever fall through?? I'm replaceduming they don't here!
writer.WriteLine(indent + string.Format("switch ({0})", instruction.ProcessedStackValue));
writer.WriteLine(indent + "{");
// Keep track of code paths are have already outputted to keep
// track of offsets that lead to the same codepath
var swDonePaths = new List<CodePath>();
foreach (var item in instruction.BranchCodesPaths)
{
if (swDonePaths.Contains(item.Value))
{
continue;
}
foreach (var item2 in instruction.BranchCodesPaths)
{
// O(n^2) loop here, there's probably a better way to optimize it
if (item2.Value == item.Value)
{
if (item2.Key.GetType() == typeof (int))
{
writer.WriteLine(string.Format("{0} case {1}:", indent, LiteralFormatter.FormatInteger((int)item2.Key)));
}
else
{
writer.WriteLine(string.Format("{0} default:", indent));
}
}
}
writer.WriteLine(indent + " {");
ProcessCodePath(writer, item.Value, indent + " ");
if (item.Value.EndInstruction == null || !item.Value.EndInstruction.ExitFunction)
{
writer.WriteLine(indent + " break;");
}
writer.WriteLine(indent + " }");
swDonePaths.Add(item.Value);
}
writer.WriteLine(indent + "}");
}
else if (instruction.LoopCodePath != null)
{
// First of a loop instruction (hopefully, someday, this will be extracted out by the Programreplacedyzer)
// Can we ever break out of a loop? I replacedume we can't here!
while (!instruction.IsConditionalBranch)
{
instruction = instruction.NextInstruction;
Annotate(writer, indent, instruction);
}
writer.WriteLine(indent + string.Format("while ({0})", instruction.ProcessedStackValue));
writer.WriteLine(indent + "{");
ProcessCodePath(writer, instruction.BranchCodesPaths[true], indent + " ");
writer.WriteLine(indent + "}");
}
else
{
WriteInstruction(writer, instruction, indent);
}
instruction = instruction.NextInstruction;
}
}
19
View Source File : DecompileCFOutput.cs
License : GNU General Public License v3.0
Project Creator : ahmed605
License : GNU General Public License v3.0
Project Creator : ahmed605
private void WriteInstruction(TextWriter writer, HLInstruction instruction, string indent)
{
writer.Write(string.Format("{0}{1:x}: ", indent, instruction.Instruction.Offset));
if (instruction.BranchFunction != null)
{
writer.WriteLine(string.Format("{0}()", instruction.BranchFunction.Name));
}
else if (instruction.ExitFunction)
{
writer.WriteLine("return");
}
else if (instruction.Instruction is InstructionNative)
{
writer.WriteLine(string.Format("{0}(in={1}, out={2})", instruction.Instruction.Operands[2],
instruction.Instruction.Operands[0], instruction.Instruction.Operands[1]));
}
else
{
writer.WriteLine(string.Format("{0}", instruction.Instruction.GetInstructionText()));
}
}
19
View Source File : DateTimeUtils.cs
License : MIT License
Project Creator : akaskela
License : MIT License
Project Creator : akaskela
internal static void WriteDateTimeString(TextWriter writer, DateTime value, DateFormatHandling format, string formatString, CultureInfo culture)
{
if (string.IsNullOrEmpty(formatString))
{
char[] chars = new char[64];
int pos = WriteDateTimeString(chars, 0, value, null, value.Kind, format);
writer.Write(chars, 0, pos);
}
else
{
writer.Write(value.ToString(formatString, culture));
}
}
19
View Source File : DateTimeUtils.cs
License : MIT License
Project Creator : akaskela
License : MIT License
Project Creator : akaskela
internal static void WriteDateTimeOffsetString(TextWriter writer, DateTimeOffset value, DateFormatHandling format, string formatString, CultureInfo culture)
{
if (string.IsNullOrEmpty(formatString))
{
char[] chars = new char[64];
int pos = WriteDateTimeString(chars, 0, (format == DateFormatHandling.IsoDateFormat) ? value.DateTime : value.UtcDateTime, value.Offset, DateTimeKind.Local, format);
writer.Write(chars, 0, pos);
}
else
{
writer.Write(value.ToString(formatString, culture));
}
}
19
View Source File : JavaScriptUtils.cs
License : MIT License
Project Creator : akaskela
License : MIT License
Project Creator : akaskela
public static void WriteEscapedJavaScriptString(TextWriter writer, string s, char delimiter, bool appendDelimiters,
bool[] charEscapeFlags, StringEscapeHandling stringEscapeHandling, IArrayPool<char> bufferPool, ref char[] writeBuffer)
{
// leading delimiter
if (appendDelimiters)
{
writer.Write(delimiter);
}
if (s != null)
{
int lastWritePosition = 0;
for (int i = 0; i < s.Length; i++)
{
var c = s[i];
if (c < charEscapeFlags.Length && !charEscapeFlags[c])
{
continue;
}
string escapedValue;
switch (c)
{
case '\t':
escapedValue = @"\t";
break;
case '\n':
escapedValue = @"\n";
break;
case '\r':
escapedValue = @"\r";
break;
case '\f':
escapedValue = @"\f";
break;
case '\b':
escapedValue = @"\b";
break;
case '\\':
escapedValue = @"\\";
break;
case '\u0085': // Next Line
escapedValue = @"\u0085";
break;
case '\u2028': // Line Separator
escapedValue = @"\u2028";
break;
case '\u2029': // Paragraph Separator
escapedValue = @"\u2029";
break;
default:
if (c < charEscapeFlags.Length || stringEscapeHandling == StringEscapeHandling.EscapeNonAscii)
{
if (c == '\'' && stringEscapeHandling != StringEscapeHandling.EscapeHtml)
{
escapedValue = @"\'";
}
else if (c == '"' && stringEscapeHandling != StringEscapeHandling.EscapeHtml)
{
escapedValue = @"\""";
}
else
{
if (writeBuffer == null || writeBuffer.Length < UnicodeTextLength)
{
writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, UnicodeTextLength, writeBuffer);
}
StringUtils.ToCharAsUnicode(c, writeBuffer);
// slightly hacky but it saves multiple conditions in if test
escapedValue = EscapedUnicodeText;
}
}
else
{
escapedValue = null;
}
break;
}
if (escapedValue == null)
{
continue;
}
bool isEscapedUnicodeText = string.Equals(escapedValue, EscapedUnicodeText);
if (i > lastWritePosition)
{
int length = i - lastWritePosition + ((isEscapedUnicodeText) ? UnicodeTextLength : 0);
int start = (isEscapedUnicodeText) ? UnicodeTextLength : 0;
if (writeBuffer == null || writeBuffer.Length < length)
{
char[] newBuffer = BufferUtils.RentBuffer(bufferPool, length);
// the unicode text is already in the buffer
// copy it over when creating new buffer
if (isEscapedUnicodeText)
{
Array.Copy(writeBuffer, newBuffer, UnicodeTextLength);
}
BufferUtils.ReturnBuffer(bufferPool, writeBuffer);
writeBuffer = newBuffer;
}
s.CopyTo(lastWritePosition, writeBuffer, start, length - start);
// write unchanged chars before writing escaped text
writer.Write(writeBuffer, start, length - start);
}
lastWritePosition = i + 1;
if (!isEscapedUnicodeText)
{
writer.Write(escapedValue);
}
else
{
writer.Write(writeBuffer, 0, UnicodeTextLength);
}
}
if (lastWritePosition == 0)
{
// no escaped text, write entire string
writer.Write(s);
}
else
{
int length = s.Length - lastWritePosition;
if (writeBuffer == null || writeBuffer.Length < length)
{
writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, length, writeBuffer);
}
s.CopyTo(lastWritePosition, writeBuffer, 0, length);
// write remaining text
writer.Write(writeBuffer, 0, length);
}
}
// trailing delimiter
if (appendDelimiters)
{
writer.Write(delimiter);
}
}
19
View Source File : JsonTextWriter.cs
License : MIT License
Project Creator : akaskela
License : MIT License
Project Creator : akaskela
public override void WriteStartConstructor(string name)
{
InternalWriteStart(JsonToken.StartConstructor, JsonContainerType.Constructor);
_writer.Write("new ");
_writer.Write(name);
_writer.Write('(');
}
19
View Source File : JsonTextWriter.cs
License : MIT License
Project Creator : akaskela
License : MIT License
Project Creator : akaskela
public override void WritePropertyName(string name, bool escape)
{
InternalWritePropertyName(name);
if (escape)
{
WriteEscapedString(name, _quoteName);
}
else
{
if (_quoteName)
{
_writer.Write(_quoteChar);
}
_writer.Write(name);
if (_quoteName)
{
_writer.Write(_quoteChar);
}
}
_writer.Write(':');
}
19
View Source File : JsonTextWriter.cs
License : MIT License
Project Creator : akaskela
License : MIT License
Project Creator : akaskela
private void WriteValueInternal(string value, JsonToken token)
{
_writer.Write(value);
}
19
View Source File : JsonTextWriter.cs
License : MIT License
Project Creator : akaskela
License : MIT License
Project Creator : akaskela
public override void WriteRaw(string json)
{
InternalWriteRaw();
_writer.Write(json);
}
19
View Source File : JsonTextWriter.cs
License : MIT License
Project Creator : akaskela
License : MIT License
Project Creator : akaskela
public override void WriteValue(DateTime value)
{
InternalWriteValue(JsonToken.Date);
value = DateTimeUtils.EnsureDateTime(value, DateTimeZoneHandling);
if (string.IsNullOrEmpty(DateFormatString))
{
EnsureWriteBuffer();
int pos = 0;
_writeBuffer[pos++] = _quoteChar;
pos = DateTimeUtils.WriteDateTimeString(_writeBuffer, pos, value, null, value.Kind, DateFormatHandling);
_writeBuffer[pos++] = _quoteChar;
_writer.Write(_writeBuffer, 0, pos);
}
else
{
_writer.Write(_quoteChar);
_writer.Write(value.ToString(DateFormatString, Culture));
_writer.Write(_quoteChar);
}
}
19
View Source File : JsonTextWriter.cs
License : MIT License
Project Creator : akaskela
License : MIT License
Project Creator : akaskela
public override void WriteValue(DateTimeOffset value)
{
InternalWriteValue(JsonToken.Date);
if (string.IsNullOrEmpty(DateFormatString))
{
EnsureWriteBuffer();
int pos = 0;
_writeBuffer[pos++] = _quoteChar;
pos = DateTimeUtils.WriteDateTimeString(_writeBuffer, pos, (DateFormatHandling == DateFormatHandling.IsoDateFormat) ? value.DateTime : value.UtcDateTime, value.Offset, DateTimeKind.Local, DateFormatHandling);
_writeBuffer[pos++] = _quoteChar;
_writer.Write(_writeBuffer, 0, pos);
}
else
{
_writer.Write(_quoteChar);
_writer.Write(value.ToString(DateFormatString, Culture));
_writer.Write(_quoteChar);
}
}
19
View Source File : JsonTextWriter.cs
License : MIT License
Project Creator : akaskela
License : MIT License
Project Creator : akaskela
public override void WriteValue(Guid value)
{
InternalWriteValue(JsonToken.String);
string text = null;
#if !(DOTNET || PORTABLE40 || PORTABLE)
text = value.ToString("D", CultureInfo.InvariantCulture);
#else
text = value.ToString("D");
#endif
_writer.Write(_quoteChar);
_writer.Write(text);
_writer.Write(_quoteChar);
}
19
View Source File : JsonTextWriter.cs
License : MIT License
Project Creator : akaskela
License : MIT License
Project Creator : akaskela
public override void WriteValue(TimeSpan value)
{
InternalWriteValue(JsonToken.String);
string text;
#if (NET35 || NET20)
text = value.ToString();
#else
text = value.ToString(null, CultureInfo.InvariantCulture);
#endif
_writer.Write(_quoteChar);
_writer.Write(text);
_writer.Write(_quoteChar);
}
19
View Source File : JsonTextWriter.cs
License : MIT License
Project Creator : akaskela
License : MIT License
Project Creator : akaskela
public override void WriteComment(string text)
{
InternalWriteComment();
_writer.Write("/*");
_writer.Write(text);
_writer.Write("*/");
}
19
View Source File : JsonTextWriter.cs
License : MIT License
Project Creator : akaskela
License : MIT License
Project Creator : akaskela
public override void WriteWhitespace(string ws)
{
InternalWriteWhitespace(ws);
_writer.Write(ws);
}
19
View Source File : AboutDialog.xaml.cs
License : GNU Affero General Public License v3.0
Project Creator : akshinmustafayev
License : GNU Affero General Public License v3.0
Project Creator : akshinmustafayev
private static void ConvertTo(HtmlNode node, TextWriter outText)
{
string html;
switch (node.NodeType)
{
case HtmlNodeType.Comment:
// don't output comments
break;
case HtmlNodeType.Doreplacedent:
ConvertContentTo(node, outText);
break;
case HtmlNodeType.Text:
// script and style must not be output
string parentName = node.ParentNode.Name;
if ((parentName == "script") || (parentName == "style"))
break;
// get text
html = ((HtmlTextNode)node).Text;
// is it in fact a special closing node output as text?
if (HtmlNode.IsOverlappedClosingElement(html))
break;
// check the text is meaningful and not a bunch of whitespaces
if (html.Trim().Length > 0)
{
outText.Write(HtmlEnreplacedy.DeEnreplacedize(html));
}
break;
case HtmlNodeType.Element:
switch (node.Name)
{
case "p":
// treat paragraphs as crlf
outText.Write("\r\n");
break;
case "br":
outText.Write("\r\n");
break;
}
if (node.HasChildNodes)
{
ConvertContentTo(node, outText);
}
break;
}
}
19
View Source File : Block.cs
License : MIT License
Project Creator : alexanderdna
License : MIT License
Project Creator : alexanderdna
public void PrepareForPowHash(TextWriter writer)
{
HexUtils.AppendHexFromInt(writer, Index);
HexUtils.AppendHexFromLong(writer, Timestamp);
writer.Write(MerkleHash);
writer.Write(PreviousBlockHash);
writer.Flush();
}
19
View Source File : HexUtils.cs
License : MIT License
Project Creator : alexanderdna
License : MIT License
Project Creator : alexanderdna
public static void AppendHexFromByteArray(TextWriter writer, ReadOnlySpan<byte> data, int index, int length)
{
if (index < 0 || index >= data.Length)
throw new ArgumentOutOfRangeException(nameof(index));
if (length < 0 || (index + length) > data.Length)
throw new ArgumentOutOfRangeException(nameof(length));
for (int i = index, c = index + length; i < c; ++i)
{
writer.Write(hexMap16[data[i]]);
}
}
19
View Source File : SourceFileGenerator.cs
License : GNU General Public License v3.0
Project Creator : alexgracianoarj
License : GNU General Public License v3.0
Project Creator : alexgracianoarj
protected void WriteFileContent(TextWriter writer)
{
if (codeBuilder == null)
codeBuilder = new StringBuilder(DefaultBuilderCapacity);
else
codeBuilder.Length = 0;
WriteFileContent();
writer.Write(codeBuilder.ToString());
}
See More Examples