Hallo 🙂
Inspiriert von diesem Beitrag fand ich es persönlich recht lustig mit Hello World! das ganze zu machen. Weil es das sonst am einfachst zu haltende Programm überhaupt ist ist es natürlich daraus genau das gegenteil zu machen :evil: .
Da ich nicht viel zeit hatte habe ich nur mal eine kleine implementierung gemacht die noch nicht wirklich schwer ist aber ich glaube ich lasse dort noch meine kreativität weiter aus. Bin mal gespannt ob auch andere spass an sowas finden, wo man doch sonst gerade so einfach wie möglich alles halten sollte.
static void Main(string[] args)
{
byte[] bc = new byte[] { 0x48 , 0x65, 0x6C, 0x6C, 0x6F, 0x00, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21 };
for (int i = 0; bc.Length > i; i++)
{
Console.Write(conhex(bc[i]));
}
Console.ReadLine();
}
static string conhex(byte b)
{
string result;
switch (b) { case 0x48: result = "H"; break;
case 0x57: result = "W"; break;
case 0x00: result = " "; break;
case 0x65: result = "e"; break;
case 0x6C: result = "l"; break;
case 0x6F: result = "o"; break;
case 0x72: result = "r"; break;
case 0x64: result = "d"; break;
case 0x21: result = "!"; break;
default: result = "0"; break; } return result;
}
Hallo
dann war mein Beitrag also doch nicht so schlecht. In C++ gibt es das aber schon etwas ähnliches: Evolution eines C++-Programmierers.
ich erstelle mal einen vb code wenns erlaubt ist
Public Class Form1
dim h as string
dim e as string
dim l as string
dim o as string
dim space as string
dim w as string
dim r as string
dim d as string
dim hw as string
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
for i as integer = 0 to 10
if i = 0 then
hw = hw & h
elseif i = 1 then
hw = hw & e
elseif i = 2 then
hw = hw & l
elseif i = 3 then
hw = hw & l
elseif i = 4 then
hw = hw & o
elseif i = 5 then
hw = hw & space
elseif i = 6 then
hw = hw & w
elseif i = 7 then
hw = hw & o
elseif i = 8 then
hw = hw & r
elseif i = 9 then
hw = hw & l
elseif i = 10 then
hw = hw & d
end if
next
msgbox(hw, MsgBoxStyle.Information + vbokonly, hw)
End Sub
End Class
das hier wäre dann c# code
public class Form1
{
string h;
string e;
string l;
string o;
string space;
string w;
string r;
string d;
string hw;
private void // ERROR: Handles clauses are not supported in C# Form1_Load(object sender, System.EventArgs e)
{
for (int i = 0; i <= 10; i++) {
if (i == 0) {
hw = hw + h;
}
else if (i == 1) {
hw = hw + e;
}
else if (i == 2) {
hw = hw + l;
}
else if (i == 3) {
hw = hw + l;
}
else if (i == 4) {
hw = hw + o;
}
else if (i == 5) {
hw = hw + space;
}
else if (i == 6) {
hw = hw + w;
}
else if (i == 7) {
hw = hw + o;
}
else if (i == 8) {
hw = hw + r;
}
else if (i == 9) {
hw = hw + l;
}
else if (i == 10) {
hw = hw + d;
}
}
Interaction.msgbox(hw, MsgBoxStyle.Information + Constants.vbokonly, hw);
}
}
MfG
ProGamer*Der Sinn Des Lebens Ist Es, Den Sinn Des Lebens Zu Finden!
*"Wenn Unrecht zu Recht wird dann wird Widerstand zur Pflicht."
*"Ignorance simplifies ANY problem."
*"Stoppt die Piraterie der Musikindustrie"
Ich kann zwar nicht viel mit vb direkt anfangen aber es sieht schon kurios aus ^^
[...] es sieht schon kurios aus ^^
Dennoch erkennt man auf den zweiten Blick was passiert. Interessanter wäre doch ein Programm wo man wirklich nicht sieht was es tut und ganz erstaunt ist, wenn man blötzlich "Hello World" liest. 🙂
Da will ich ja hinkommen ich überlege mir schon Sachen im Kopf und hoffe das es demnächst zur umsetzung kommt! 😉
Hallo Kaji, hallo zusammen
hier mal ein Ansatz, wie man das erreichen kann. Nicht unlösbar, aber einen Moment wird man schon überlegen müssen, um per Schreibtischtest herauszubekommen, was ausgegeben wird:
int i = 1;
for (int j = 0; j < 6; i <<= 1, ++j) if (j == 3) ++i;
Console.WriteLine ((char)i);
herbivore
Hallo herbivore,
an so einen ansatz hab ich auch schon gedacht. Mein erster Ansatz konvertiert ja auc schon bytes zu chars ..^^ Aber so mit rechnen ist das wesentlich schön/verkompliziert. Das nehme ich aufjedenfall mal mit rein! 🙂
Gruß Daniel
Hallo Kaji,
der Komplexität sind dabei keine Grenzen gesetzt. Hier eine noch etwas kompliziertere Version der Schleife:
for (int j = 0; i == 1 || ++j != i / 4; i <<= 1, ++j) if (j++ == 9) ++i;
herbivore
Hier mal ein Hello World verschlüsselt
using System.Text;
using System.Security.Cryptography;
using System.IO;
namespace ConsoleApplication2
{
class Program
{
public static byte[] Decrypt(byte[] cipherData, byte[] Key, byte[] IV)
{
using (MemoryStream ms = new MemoryStream())
{
Rijndael alg = Rijndael.Create();
alg.Key = Key;
alg.IV = IV;
using (CryptoStream cs = new CryptoStream(ms, alg.CreateDecryptor(), CryptoStreamMode.Write))
{
cs.Write(cipherData, 0, cipherData.Length);
}
return ms.ToArray();
}
}
public static byte[] Decrypt(byte[] cipherData, string Password)
{
PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password,
new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
return Decrypt(cipherData, pdb.GetBytes(32), pdb.GetBytes(16));
}
private const string KEY = "F354AB01CD1200ABBBAC";
private static byte[][] data = new byte[][]
{
new byte[] { 0xB8, 0x2, 0xBF, 0x9A, 0x60, 0xBB, 0x4E, 0x9, 0xAE, 0x18, 0xE3, 0x0, 0xE0, 0xD0, 0xD6, 0x1D },
new byte[] { 0xDA, 0x4, 0x1B, 0x2F, 0xAE, 0x41, 0xC3, 0x34, 0x75, 0x1B, 0xF3, 0xCF, 0xE1, 0x22, 0xC, 0x4D },
new byte[] { 0x93, 0xA7, 0xF1, 0xF4, 0x8F, 0xE7, 0xFB, 0xB4, 0x67, 0x83, 0x5F, 0xD3, 0x41, 0xD9, 0x24, 0x8B },
new byte[] { 0x5D, 0x72, 0x3A, 0x81, 0xD9, 0x34, 0x1C, 0x6C, 0xCB, 0x4E, 0x49, 0xD1, 0x7, 0xE3, 0x1D, 0xC4 },
new byte[] { 0x94, 0xAA, 0xD6, 0x9A, 0x0, 0xDD, 0xD9, 0xE1, 0x9E, 0x25, 0x25, 0x62, 0x5C, 0x7F, 0xC1, 0x24 },
new byte[] { 0x11, 0x35, 0x96, 0x2E, 0xC6, 0x92, 0x4D, 0x9B, 0xC4, 0x6, 0xAF, 0x25, 0xEB, 0x6F, 0x86, 0xDF },
new byte[] { 0xB9, 0x4E, 0x5E, 0x95, 0xDD, 0x10, 0x25, 0x61, 0x72, 0xB2, 0xB6, 0x9E, 0x13, 0xA0, 0xF4, 0xB8 },
new byte[] { 0x52, 0x4E, 0x7F, 0xC9, 0xCF, 0x7C, 0xD4, 0x71, 0xDE, 0xE, 0x94, 0xD1, 0xEB, 0x67, 0xEE, 0x93 }
};
private static int[] order = new int[] { 0, 1, 2, 2, 3, 4, 5, 3, 6, 2, 7 };
static void Main(string[] args)
{
for (int i = 0; i < order.Length; i++)
{
byte[] bytes = data[order[i]];
byte[] decryptedBytes = Decrypt(bytes, KEY);
Console.Write(System.Text.Encoding.Default.GetString(decryptedBytes));
}
Console.ReadKey();
}
}
}
"Jedes Ding hat drei Seiten, eine positive, eine negative und eine komische." (Karl Valentin)
string s = "I CAN SEE DEAD PEOPLE";
Console.Write((char)(s[0] & 0xAFFE));
Console.Write((char)(s[20] & 0xBEEF));
Console.Write((char)(s[19] & 0xCAFE));
Console.Write((char)(s[19] & 0xBEEF));
Console.Write((char)(s[17] & 0x006F));
Console.Write((char)(s[1] & 0xBAD));
Console.Write((char)(s[2] | 0x77));
Console.Write((char)(s[17] & 0x6f));
Console.Write((char)(s[6] & 0xC07A));
Console.Write((char)(s[19] & 0xCAFE));
Console.Write((char)(s[8] & 0x0EDE));
PLEASE DO ,1 <- #13
DO ,1 SUB #1 <- #584
DO ,1 SUB #2 <- #837
DO ,1 SUB #3 <- #1100
DO ,1 SUB #4 <- #1356
DO ,1 SUB #5 <- #1615
DO ,1 SUB #6 <- #1824
DO ,1 SUB #7 <- #2135
DO ,1 SUB #8 <- #2383
DO ,1 SUB #9 <- #2642
DO ,1 SUB #10 <- #2892
DO ,1 SUB #11 <- #3140
DO ,1 SUB #12 <- #3361
DO ,1 SUB #13 <- #266
PLEASE DO ,2 <- #1
PLEASE DO .5 <- #0
PLEASE DO .4 <- #1
PLEASE COME FROM (1)
DO .6 <- ",1 SUB .4"~#255
DO .6 <- !6~#15'$!6~#240'
DO .6 <- !6~#15'$!6~#240'
DO .6 <- !6~#15'$!6~#240'
DO .1 <- .5
DO .2 <- .6
PLEASE DO (1010) NEXT
DO .3 <- .3~#255
DO .5 <- .6
DO ,2 SUB #1 <- .3
PLEASE READ OUT ,2
(1) PLEASE DO .4 <- ",1 SUB .4"~#3840
PLEASE GIVE UP
Shift to the left, shift to the right!
Pop up, push down, byte, byte, byte!
YARRRRRR!
So und jetzt den ganzen Spaß noch mit im Speicher dynamisch generierter Assembly 🙂
//edit: Und zwar Generierung im Speicher mit System.Reflection.Emit, nicht das hier noch einer mit CodeDOM anfängt 🙂
`man könnte auch irgendeine text datei aus dem windoof ordner (eine zufällige) und diese dann nach einem bestimmten buhstaben durchsuchen wenn gefunden datei schliessen und nächste textdatei durchsuchen.
und das immer so weiter bis man "hello world" zusammen hat
natürlich darf die verschlüsselung nicht fehlen ^^
tut mir leid wenn ich das nicht code aber ich bin kein fan von streamwriter/reader 😁
MfG
ProGamer*Der Sinn Des Lebens Ist Es, Den Sinn Des Lebens Zu Finden!
*"Wenn Unrecht zu Recht wird dann wird Widerstand zur Pflicht."
*"Ignorance simplifies ANY problem."
*"Stoppt die Piraterie der Musikindustrie"
So und jetzt den ganzen Spaß noch mit im Speicher dynamisch generierter Assembly 🙂
Ich sehe das mal als Aufforderung 🙂
So schwer ist das aber gar nicht - der MSDN sei dank:
AssemblyBuilder builder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("MyAssembly"), AssemblyBuilderAccess.Run);
ModuleBuilder moduleBuilder = builder.DefineDynamicModule("TempModule");
TypeBuilder typeBuilder = moduleBuilder.DefineType("MyClass");
MethodBuilder methodBuilder = typeBuilder.DefineMethod("HelloWorld", MethodAttributes.Public | MethodAttributes.Static);
ILGenerator generator = methodBuilder.GetILGenerator();
generator.EmitWriteLine("Hello World");
generator.Emit(OpCodes.Ret);
Type t = typeBuilder.CreateType();
t.InvokeMember("HelloWorld", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Static, null, null, new object[] { });
Console.ReadLine();
hm,
generator.EmitWriteLine("Hello World");
ist auf alle Fälle noch ausbaufähig 🙂, ehrlich gesagt kannte ich den Befehl gar nicht. Ich hätte jetzt lauter einzelne Emits geschrieben. Die hohe Kunst ist es jetzt aber wie gesagt den Code von Khalid oben mit Reflection.Emit umzusetzen. Wenn das jetzt wieder jemand als Herausforderung betrachtet, dann viel Spaß dabei. Wenn man das hinkriegt ohne zwischedurch mal den Reflector oder den Disassembler anzuschmeißen, dann ist das schon verdammt gut. 🙂
am besten finde ich die Lolcode Implementierung
HAI
CAN HAS STDIO?
VISIBLE "HAI WORLD!"
KTHXBYE
using Skill
Bevor das hier gleich ausartet, sei noch Esoterische Programmiersprachen genannt
Es gibt 3 Arten von Menschen, die die bis 3 zählen können und die, die es nicht können...
Ich hab da auch etwas kleines gemacht:
using System;
using System.Collections.Generic;
class Hello
{
static void Main()
{
Dictionary<byte,char> d = new Dictionary<byte,char>();
d.Add(0, ' ');
d.Add(1, '_');
d.Add(2, '/');
d.Add(3, '\\');
d.Add(4, 'I');
d.Add(5, '-');
byte[][][] b = new byte[][][]{new byte[][]{
new byte[]{ 4,0,0,0,4,0,0,0,0,2,3,0,0,0,0,4,0,0,0,0,4,0,0,0,0,2,5,5,3 }
,new byte[]{ 4,1,1,1,4,0,0,0,2,1,1,3,0,0,0,4,0,0,0,0,4,0,0,0,0,4,0,0,4 }
,new byte[]{ 4,0,0,0,4,0,0,2,0,0,0,0,3,0,0,4,0,0,0,0,4,0,0,0,0,4,0,0,4 }
,new byte[]{ 4,0,0,0,4,0,2,0,0,0,0,0,0,3,0,4,1,1,1,0,4,1,1,1,0,3,1,1,2 }}
,new byte[][]{
new byte[]{ 3,0,0,0,0,0,2,0,0,0,0,0,2,0,4,5,5,5,0,4,0,0,0,0,5,5,5,0 }
,new byte[]{ 0,3,0,0,0,2,0,3,0,0,0,2,0,0,4,1,1,1,0,4,0,0,0,0,0,4,0,0 }
,new byte[]{ 0,0,3,0,2,0,0,0,3,0,2,0,0,0,4,0,0,0,0,4,0,0,0,0,0,4,0,0 }
,new byte[]{ 0,0,0,3,0,0,0,0,0,3,0,0,0,0,4,1,1,1,0,4,1,1,1,0,0,4,0,0 }}};
for (int z = 0; z < b.Length; z++)
{
for (int i = 0; i < b[z].Length; i++)
{
for (int y = 0; y < b[z][i].Length; y++)
{
Console.Write("{0}", d[b[z][i][y]]);
}
Console.WriteLine();
}
Console.WriteLine();
}
Console.ReadKey();
}
}
Noch eine Variante von mir, nicht allzu kompliziert, dafür schön unübersichtlich als Signatur Programm:
using System;using System.Collections.Generic;class H{static string z(List<char>c){
string r="";for(int x=0;x<(677%666);x++)r+=c[x];return r;}static void Main(){List<char>
b=new List<char>();int[]c={16968,3425,3180,13164,4207,6432,18263,12901,4460,19316,5921}
;for(int p=0;p<((110%88)/2);p++){b.Add((char)(c[p]%256));}Console.WriteLine(z(b));}}
Edit:
Eine Version die in die max. 300 Zeichen hier im Forum passt:
using System;class H{static string z(char[]c){string r="";for(int x=0;x<(677%666);x++)r+=c[
x];return r;}static void Main(){int[]c={798,218,229,592,232,274,813,585,229,842,275};char[]
b=new char[11];for(int p=0;p<((59%12));p++)b[p]=(char)(c[p]%121);Console.WriteLine(z(b));}}
Hi!
Ein klein bisschen komplizierter:
class m{static void Main(){int[]a,b,c;char[]d;int e;string f;goto j;i:f+=d[e];e++;if(e<0xB)goto i;System.Console.WriteLine(f);return;g:d[e]=(char)c[e];e++;if(e<0xB)goto g;f="";e=0;goto i;h:c[e]=(a[e]^b[e])%0x79;e++;if(e<0xB)goto h;d=new char[0xB];e=0;goto g;j:a=new int[]{0x0B4,0x07C,0x13B,0x065,0x0A6,0x10F,0x334,0x10A,0x3B4,0x2FE,0x385};b=new int[]{0x3AA,0x0A6,0x1DE,0x235,0x04E,0x01D,0x019,0x343,0x351,0x1B4,0x296};c=new int[0xB];e=0;goto h;}}
Gruß, Christian.
Hallo ihr beiden.
wäre doch schöner, wenn man ohne (int- oder char-)Array und überhaupt mit möglichst wenig Konstanten auskommt.
Außerdem warte ich noch auf eine Lösung mit CodeDOM. Oder sogar mit System.Reflection.Emit, wie onlinegurke das oben vorgeschlagen hat.
herbivore
[EDIT]Ich habe gerade gesehen, dass winSharp93 schon eine CodeDOM-Lösung gepostet hat, allerdings ist bei der trotz der höheren Komplexität leicht zu erkennen, was das Programm tut.[/EDIT]
Außerdem warte ich noch auf eine Lösung mit CodeDOM. Oder sogar mit System.Reflection.Emit, wie onlinegurke das oben vorgeschlagen hat.
Wie wär's stattdessen mit "etwas" Phoenix?
Phx.Targets.Architectures.Architecture x86Architecture = Phx.Targets.Architectures.X86.Architecture.New();
Phx.Targets.Runtimes.Runtime x86Runtime = Phx.Targets.Runtimes.Vccrt.Win32.X86.Runtime.New(x86Architecture);
Phx.GlobalData.RegisterTargetArchitecture(x86Architecture);
Phx.GlobalData.RegisterTargetRuntime(x86Runtime);
Phx.Targets.Architectures.Architecture msilArchitecture = Phx.Targets.Architectures.Msil.Architecture.New();
Phx.Targets.Runtimes.Runtime winMSILRuntime = Phx.Targets.Runtimes.Vccrt.Win.Msil.Runtime.New(msilArchitecture);
Phx.GlobalData.RegisterTargetArchitecture(msilArchitecture);
Phx.GlobalData.RegisterTargetRuntime(winMSILRuntime);
Phx.Initialize.BeginInitialization();
Phx.Initialize.EndInitialization("PHX|*|_PHX_", new string[] { });
Phx.Phases.PhaseConfiguration phaseConfiguration = Phx.Phases.PhaseConfiguration.New(Phx.GlobalData.GlobalLifetime, "phases");
Phx.Phases.Phase[] phases =
{
Phx.MirLowerPhase.New(phaseConfiguration),
Phx.Targets.Runtimes.CanonicalizePhase.New(phaseConfiguration),
Phx.Targets.Runtimes.LowerPhase.New(phaseConfiguration),
Phx.Targets.Runtimes.SwitchLowerPhase.New(phaseConfiguration),
Phx.StackAllocatePhase.New(phaseConfiguration),
Phx.Targets.Runtimes.FrameGenerationPhase.New(phaseConfiguration),
Phx.Graphs.BlockLayoutPhase.New(phaseConfiguration),
Phx.FlowOptimizer.Phase.New(phaseConfiguration),
};
foreach (Phx.Phases.Phase phase in phases)
phaseConfiguration.PhaseList.AppendPhase(phase);
Phx.GlobalData.GetFirstTargetRuntime().AddPhases(phaseConfiguration);
Phx.GlobalData.BuildPlugInPhases(phaseConfiguration);
PEModuleUnit moduleUnit = Phx.PEModuleUnit.Open(@"GenesisAssembly.exe");
moduleUnit.MetadataEmitter = Phx.Metadata.Emitter.New(moduleUnit.Lifetime, moduleUnit);
moduleUnit.OutputImagePath = "Test.dll";
foreach (Phx.FunctionUnit functionUnit in moduleUnit.GetEnumerableContributionUnit(Phx.ContributionUnitEnumerationKind.WritableFunctionUnit))
functionUnit.DisassembleToBeforeLayout();
Phx.Name classTypeName = Phx.Name.New(Phx.GlobalData.GlobalLifetime, "Class1");
TypeSymbol classTypeSymbol = Phx.Symbols.MsilTypeSymbol.New(moduleUnit.SymbolTable, classTypeName, 0);
AggregateType classType = Phx.Types.AggregateType.NewDynamicSize(moduleUnit.TypeTable, classTypeSymbol);
moduleUnit.AssemblyUnit.AssemblySymbol.InsertInLexicalScope(classTypeSymbol, classTypeName);
Phx.Types.FunctionTypeBuilder functionTypeBuilder = Phx.Types.FunctionTypeBuilder.New(moduleUnit.TypeTable);
functionTypeBuilder.CallingConventionKind = Phx.Types.CallingConventionKind.ClrCall;
functionTypeBuilder.AppendReturnParameter(moduleUnit.TypeTable.VoidType);
Phx.Types.FunctionType methodType = functionTypeBuilder.GetFunctionType();
Phx.Name functionName = Phx.Name.New(moduleUnit.Lifetime, "Main");
Phx.Symbols.FunctionSymbol functionSymbol = Phx.Symbols.FunctionSymbol.New(moduleUnit.SymbolTable, 0, functionName, methodType, Phx.Symbols.Visibility.GlobalDefinition);
functionSymbol.CreateParameterSymbols();
classType.AppendMethodSymbol(functionSymbol);
classType.TypeSymbol.InsertInLexicalScope(functionSymbol, functionName);
Phx.Name textName = Phx.Name.New(Phx.GlobalData.GlobalLifetime, ".text");
Phx.Symbols.SectionSymbol textSymbol = moduleUnit.SymbolTable.LookupByName(textName).AsSectionSymbol;
functionSymbol.AllocationBaseSectionSymbol = textSymbol;
functionSymbol.Access = Access.Public;
functionSymbol.MethodSpecifier |= MethodSpecifier.Virtual;
functionSymbol.MethodSpecifier |= Phx.Symbols.MethodSpecifier.Static;
functionSymbol.IsHideBySignature = true;
functionSymbol.FunctionUnit = Phx.FunctionUnit.New(functionSymbol, Phx.CodeGenerationMode.IJW, moduleUnit.TypeTable, moduleUnit.MsilRuntime.Architecture, moduleUnit.MsilRuntime, moduleUnit, 0);
moduleUnit.AppendChildUnit(functionSymbol.FunctionUnit);
Phx.Symbols.Table functionSymbolTable = Phx.Symbols.Table.New(functionSymbol.FunctionUnit, 64, false);
functionSymbolTable.AddMap(Phx.Symbols.NameMap.New(functionSymbolTable, 64));
Phx.Targets.Runtimes.Vccrt.Win.Msil.Runtime runtime = functionSymbol.FunctionUnit.Runtime as Phx.Targets.Runtimes.Vccrt.Win.Msil.Runtime;
runtime.TokenMap = Phx.Symbols.TokenMap.New(Phx.GlobalData.SymbolTable, 64);
functionSymbol.FunctionUnit.AllocateLifetime();
Phx.IR.Instruction startInstruction = functionSymbol.FunctionUnit.FirstInstruction;
Phx.IR.Instruction endInstruction = functionSymbol.FunctionUnit.LastInstruction;
Phx.Debug.Info.New(functionSymbol.FunctionUnit.Lifetime, functionSymbol.FunctionUnit);
functionSymbol.FunctionUnit.CurrentDebugTag = functionSymbol.FunctionUnit.DebugInfo.CreateTag(Phx.Name.New(functionSymbol.FunctionUnit.Lifetime, ""), 0, 0);
startInstruction.DebugTag = functionSymbol.FunctionUnit.CurrentDebugTag;
endInstruction.DebugTag = functionSymbol.FunctionUnit.CurrentDebugTag;
Phx.IR.LabelInstruction enterInstruction = Phx.IR.LabelInstruction.New(functionSymbol.FunctionUnit, Phx.Common.Opcode.EnterFunction, functionSymbol);
startInstruction.InsertAfter(enterInstruction);
startInstruction.AppendLabelSource(Phx.IR.LabelOperandKind.Technical, Phx.IR.LabelOperand.New(functionSymbol.FunctionUnit, enterInstruction));
Phx.IR.LabelInstruction exitInstruction = Phx.IR.LabelInstruction.New(functionSymbol.FunctionUnit, Phx.Common.Opcode.ExitFunction);
functionSymbol.FunctionUnit.LastInstruction.InsertBefore(exitInstruction);
string stringValue = "Hello World";
Phx.Types.Type stringType = moduleUnit.TypeTable.GetObjectPointerType(moduleUnit.TypeTable.SystemStringAggregateType);
Phx.Symbols.ConstantSymbol stringSymbol = Phx.Symbols.ConstantSymbol.New(moduleUnit.SymbolTable, 0, Phx.Name.New(functionSymbol.FunctionUnit.Lifetime, stringValue), functionSymbol.FunctionUnit.TypeTable.ObjectPointerSystemStringType, stringValue);
Phx.IR.Operand operand = Phx.IR.MemoryOperand.NewAddress(functionSymbol.FunctionUnit, stringType, stringSymbol, null, 0, Phx.Alignment.NaturalAlignment(stringType), functionSymbol.FunctionUnit.AliasInfo.NotAliasedMemoryTag);
Phx.IR.Instruction loadStringInstruction = Phx.IR.ValueInstruction.NewUnaryExpression(functionSymbol.FunctionUnit, Phx.Targets.Architectures.Msil.Opcode.ldstr, stringType, operand);
functionSymbol.FunctionUnit.LastInstruction.Previous.InsertBefore(loadStringInstruction);
Phx.Name assemblyName = Phx.Name.New(Phx.GlobalData.GlobalLifetime, "mscorlib");
Phx.Symbols.AssemblySymbol assemblyReferenceSymbol = moduleUnit.SymbolTable.NameMap.Lookup(assemblyName).AsAssemblySymbol;
Phx.Name name = Phx.Name.New(Phx.GlobalData.GlobalLifetime, "System.Console");
Phx.Symbols.MsilTypeSymbol typeSymbol = Phx.Symbols.MsilTypeSymbol.New(moduleUnit.SymbolTable, name, 0);
Phx.Types.AggregateType aggregateType = Phx.Types.AggregateType.NewDynamicSize(moduleUnit.TypeTable, typeSymbol);
aggregateType.IsDefinition = false;
assemblyReferenceSymbol.InsertInLexicalScope(typeSymbol, name);
functionTypeBuilder = Phx.Types.FunctionTypeBuilder.New(moduleUnit.TypeTable);
functionTypeBuilder.CallingConventionKind = Phx.Types.CallingConventionKind.ClrCall;
functionTypeBuilder.AppendReturnParameter(moduleUnit.TypeTable.VoidType);
functionTypeBuilder.AppendParameter(stringType);
Phx.Types.FunctionType functionType = functionTypeBuilder.GetFunctionType();
functionName = Phx.Name.New(Phx.GlobalData.GlobalLifetime, "WriteLine");
Phx.Symbols.FunctionSymbol target = Phx.Symbols.FunctionSymbol.New(moduleUnit.SymbolTable, 0, functionName, functionType, Phx.Symbols.Visibility.GlobalReference);
aggregateType.AsAggregateType.AppendMethodSymbol(target);
aggregateType.TypeSymbol.InsertInLexicalScope(target, functionName);
Phx.IR.CallInstruction callInstruction = Phx.IR.CallInstruction.New(functionSymbol.FunctionUnit, Phx.Common.Opcode.Call, target);
callInstruction.AppendSource(loadStringInstruction.DestinationOperand);
functionSymbol.FunctionUnit.LastInstruction.Previous.InsertBefore(callInstruction);
functionSymbol.FunctionUnit.FinishCreation();
Phx.Threading.Context context = Phx.Threading.Context.GetCurrent();
context.PushUnit(functionSymbol.FunctionUnit);
phaseConfiguration.PhaseList.DoPhaseList(functionSymbol.FunctionUnit);
Phx.Targets.Runtimes.Vccrt.Win.Msil.Frame frame = functionSymbol.FunctionUnit.Frame as Phx.Targets.Runtimes.Vccrt.Win.Msil.Frame;
frame.LocalVarSigTok = 0;
int byteOffset = 0;
foreach (Phx.Symbols.Symbol localSymbol in functionSymbol.FunctionUnit.SymbolTable.AllSymbols)
if (localSymbol.IsLocalVariableSymbol && localSymbol.AsLocalVariableSymbol.IsAuto)
localSymbol.Location.AsFrameLocation.ByteOffset = byteOffset++;
Phx.PE.Writer.UpdateEncodedIR(functionSymbol.FunctionUnit);
Phx.Metadata.SignatureEmitter.EncodeLocalSignature(functionSymbol.FunctionUnit);
functionSymbol.FunctionUnit.ReleaseLifetime();
moduleUnit.Close();
Wobei man aber beachten muss, dass man eine bereits existierende Assembly aus Grundlage braucht und auch keinen neuen Einstiegspunkt setzen kann... 😛
Beste Grüße,
dN!3L
Offtopic, weil T-SQL. Fällt aber wohl auch unter die Kategorie "nicht schön aber selten" 👅
DECLARE
@t VARCHAR(100) = 'Hallo Welt'
,@splt NVARCHAR(MAX),@unpvt NVARCHAR(MAX),@sql NVARCHAR(MAX);
WITH n (n, c) AS (
SELECT number, CONVERT(VARCHAR(10), number)
FROM master.dbo.spt_values
WHERE type = 'P' AND number > 0
)
SELECT
@splt = STUFF((
SELECT ',MAX(CASE WHEN n1 = ' + c + ' THEN SUBSTRING(@t, n1, 1) ELSE '''' END) c' + c + CHAR(10)
FROM n WHERE n <= LEN(@t) FOR XML PATH('')
),1,1,'')
,@unpvt = STUFF((
SELECT ',c' + c FROM n WHERE n <= LEN(@t)
FOR XML PATH('')
),1,1,'');
SELECT
@sql = N'WITH n (n1) AS (
SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 1))
FROM master.sys.all_columns c1 CROSS JOIN master.sys.all_columns c2
),
line AS (
SELECT ' + @splt + CHAR(10)
+ 'FROM n WHERE n1 <= LEN(@t)
)
SELECT chars
FROM line UNPIVOT (chars FOR c IN (' + @unpvt + ')) AS unpvt'
;
--PRINT @sql;
EXECUTE sp_executesql @sql, N'@t VARCHAR(100)', @t = @t;
Grüße
Flo
Blog: Things about Software Architecture, .NET development and SQL Server
Twitter
Google+
Je mehr ich weiß, desto mehr weiß ich was ich noch nicht weiß.
Is zwar nicht wirklich verschlüsselt, aber mal ganz interessant:
public class FinalisationCallback
{
public FinalisationCallback(System.Action a){this.a=a;}
Action a;
~FinalisationCallback() {a();}
public static void Main()
{
int x=0;
Action a=()=>Console.Write("Hallo, World!"[Interlocked.Increment(ref x)-1]);
for(int i=0;i<13;i++) GC.KeepAlive(new FinalisationCallback(a));
int reserved=0;
while(x!=13)
{
GC.KeepAlive(new byte[1024]);
reserved++;
Thread.Sleep(0);
}
Console.WriteLine();
Console.WriteLine(reserved+"KByte reserviert");
Console.ReadLine();
}
}
Hallo Floste,
beachte aber die Doku zu GC.KeepAlive:
Zitat von: GC.KeepAliveMethod
References the specified object, which makes it ineligible for garbage collection from the start of the current routine to the point where this method is called.
Die Aufrufe sind also wirkungslos!
Die Aufrufe sind also wirkungslos!
das ist auch so gewollt, dödel die methode ist nur dazu da, um optimierungen des jitters vorzubeugen. sonst merkt der am ende noch, dass ich die arrays eigendlich nur zun speicherzumüllen brauche und erstellt sie garned erst. sonst hat das keine funktion.
das ist auch so gewollt, dödel die methode ist nur dazu da, um optimierungen des jitters vorzubeugen.
Also würde es jede andere Methode auch tun.
Gib zu, das KeepAlive soll professioneller wirken 😁
GC.KeepAlive(new FinalisationCallback(a));
Da ist es aber IMHO wirklich wirkungslos.
Wo man tatsächlich einen Unterschied bemerkt ist Folgendes:
public class Program
{
public static void Main()
{
Timer timer = new Timer(Tick, null, 0, 1000);
//GC.KeepAlive(timer);
Console.ReadLine();
//GC.KeepAlive(timer);
}
private static void Tick(object state)
{
Console.WriteLine("Tick!");
GC.Collect();
}
}
Je nachdem, welches KeepAlive man nimmt, ist das Resultat anders.
Außerdem warte ich noch auf eine Lösung mit CodeDOM. Oder sogar mit System.Reflection.Emit, wie onlinegurke das oben vorgeschlagen hat.
Auch wenn es über ein Jahr her ist, hab ich mich gerade mit Reflection.Emit beschäftigt und da kam mir dieser Thread wieder in den Sinn. 😁
Also hier eine Verbindung von Verschlüsselung und Reflection.Emit:
Und ja, ich geb's zu: Ich habe nicht den ganzen IL-Code per Hand geschrieben, der Reflector hat geholfen. 😉
using System;
using System.Text;
using System.Reflection;
using System.Reflection.Emit;
namespace HelloWorldEmit
{
class Program
{
static void Main(string[] args)
{
try
{
AppDomain currentDomain = System.Threading.Thread.GetDomain();
AssemblyName assembly = new AssemblyName("hello");
AssemblyBuilder asmBuilder = currentDomain.DefineDynamicAssembly(assembly, AssemblyBuilderAccess.Run);
ModuleBuilder module = asmBuilder.DefineDynamicModule("hello", false);
TypeBuilder type = module.DefineType("hello", TypeAttributes.Public);
MethodBuilder decrypt = BuildDecrypt(type);
MethodBuilder getData = BuildGetData(type);
Type helloDecrypt = type.CreateType();
byte[] data = (byte[])helloDecrypt.InvokeMember("getData", BindingFlags.InvokeMethod, null, null, Type.EmptyTypes);
string retValue = (string)helloDecrypt.InvokeMember("decrypt", BindingFlags.InvokeMethod, null, null, new object[] { data, "Scavanger" });
Console.WriteLine(retValue);
}
catch (Exception ex)
{
Console.WriteLine("Error:\n" + ex.Message);
}
}
static MethodBuilder BuildDecrypt(TypeBuilder type)
{
MethodBuilder decrypt = type.DefineMethod("decrypt", System.Reflection.MethodAttributes.Public | System.Reflection.MethodAttributes.Static);
decrypt.SetParameters(typeof(Byte[]), typeof(String));
decrypt.SetReturnType(typeof(String));
ParameterBuilder encrypted = decrypt.DefineParameter(1, ParameterAttributes.None, "encrypted");
ParameterBuilder pass = decrypt.DefineParameter(2, ParameterAttributes.None, "pass");
ConstructorInfo memStreamCtor = typeof(System.IO.MemoryStream).GetConstructor(Type.EmptyTypes);
ConstructorInfo tdemCtor = typeof(System.Security.Cryptography.TripleDESCryptoServiceProvider).GetConstructor(Type.EmptyTypes);
ConstructorInfo CryptoStreamCtor = typeof(System.Security.Cryptography.CryptoStream).GetConstructor(new Type[] { typeof(System.IO.Stream), typeof(System.Security.Cryptography.ICryptoTransform), typeof(System.Security.Cryptography.CryptoStreamMode) });
MethodInfo encodingGetDefault = typeof(Encoding).GetMethod("get_Default", Type.EmptyTypes);
MethodInfo encodingGetBytes = typeof(Encoding).GetMethod("GetBytes", new Type[] { typeof(String) });
MethodInfo arrayCopy1 = typeof(Array).GetMethod("Copy", new Type[] { typeof(Array), typeof(Array), typeof(Int32) });
MethodInfo arrayCopy2 = typeof(Array).GetMethod("Copy", new Type[] { typeof(Array), typeof(Int32), typeof(Array), typeof(Int32), typeof(Int32) });
MethodInfo createDecryptor = typeof(System.Security.Cryptography.SymmetricAlgorithm).GetMethod("CreateDecryptor", new Type[] { typeof(Byte[]), typeof(Byte[]) });
MethodInfo streamWrite = typeof(System.IO.Stream).GetMethod("Write", new Type[] { typeof(Byte[]), typeof(Int32), typeof(Int32) });
MethodInfo cryptoStreamFlushFinalBlock = typeof(System.Security.Cryptography.CryptoStream).GetMethod("FlushFinalBlock", Type.EmptyTypes);
MethodInfo memStramToArray = typeof(System.IO.MemoryStream).GetMethod("ToArray", Type.EmptyTypes);
MethodInfo streamClose = typeof(System.IO.Stream).GetMethod("Close", Type.EmptyTypes);
MethodInfo encodingGetString = typeof(Encoding).GetMethod("GetString", new Type[] { typeof(Byte[]) });
ILGenerator ilGenerator = decrypt.GetILGenerator();
LocalBuilder key = ilGenerator.DeclareLocal(typeof(Byte[]));
LocalBuilder IV = ilGenerator.DeclareLocal(typeof(Byte[]));
LocalBuilder nameBytes = ilGenerator.DeclareLocal(typeof(Byte[]));
LocalBuilder tmpData = ilGenerator.DeclareLocal(typeof(Byte[]));
LocalBuilder i = ilGenerator.DeclareLocal(typeof(Int32));
LocalBuilder ms = ilGenerator.DeclareLocal(typeof(System.IO.MemoryStream));
LocalBuilder tdesProvider = ilGenerator.DeclareLocal(typeof(System.Security.Cryptography.TripleDESCryptoServiceProvider));
LocalBuilder cs = ilGenerator.DeclareLocal(typeof(System.Security.Cryptography.CryptoStream));
LocalBuilder retValue = ilGenerator.DeclareLocal(typeof(Byte[]));
Label loopBegin = ilGenerator.DefineLabel();
Label loopEnd = ilGenerator.DefineLabel();
ilGenerator.Emit(OpCodes.Ldc_I4_S, 24);
ilGenerator.Emit(OpCodes.Newarr, typeof(Byte));
ilGenerator.Emit(OpCodes.Stloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_8);
ilGenerator.Emit(OpCodes.Newarr, typeof(Byte));
ilGenerator.Emit(OpCodes.Stloc_1);
ilGenerator.Emit(OpCodes.Call, encodingGetDefault);
ilGenerator.Emit(OpCodes.Ldarg_1);
ilGenerator.Emit(OpCodes.Callvirt, encodingGetBytes);
ilGenerator.Emit(OpCodes.Stloc_2);
ilGenerator.Emit(OpCodes.Ldarg_0);
ilGenerator.Emit(OpCodes.Ldlen);
ilGenerator.Emit(OpCodes.Conv_I4);
ilGenerator.Emit(OpCodes.Newarr, typeof(Byte));
ilGenerator.Emit(OpCodes.Stloc_3);
ilGenerator.Emit(OpCodes.Ldc_I4_0);
ilGenerator.Emit(OpCodes.Stloc_S, 4);
ilGenerator.Emit(OpCodes.Br_S, loopEnd);
ilGenerator.MarkLabel(loopBegin);
ilGenerator.Emit(OpCodes.Ldloc_3);
ilGenerator.Emit(OpCodes.Ldloc_S, 4);
ilGenerator.Emit(OpCodes.Ldarg_0);
ilGenerator.Emit(OpCodes.Ldloc_S, 4);
ilGenerator.Emit(OpCodes.Ldelem_U1);
ilGenerator.Emit(OpCodes.Ldloc_2);
ilGenerator.Emit(OpCodes.Ldloc_S, 4);
ilGenerator.Emit(OpCodes.Ldloc_2);
ilGenerator.Emit(OpCodes.Ldlen);
ilGenerator.Emit(OpCodes.Conv_I4);
ilGenerator.Emit(OpCodes.Rem);
ilGenerator.Emit(OpCodes.Ldelem_U1);
ilGenerator.Emit(OpCodes.Xor);
ilGenerator.Emit(OpCodes.Conv_U1);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_S, 4);
ilGenerator.Emit(OpCodes.Ldc_I4_1);
ilGenerator.Emit(OpCodes.Add);
ilGenerator.Emit(OpCodes.Stloc_S, 4);
ilGenerator.MarkLabel(loopEnd);
ilGenerator.Emit(OpCodes.Ldloc_S, 4);
ilGenerator.Emit(OpCodes.Ldarg_0);
ilGenerator.Emit(OpCodes.Ldlen);
ilGenerator.Emit(OpCodes.Conv_I4);
ilGenerator.Emit(OpCodes.Blt_S, loopBegin);
ilGenerator.Emit(OpCodes.Ldloc_3);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 24);
ilGenerator.Emit(OpCodes.Call, arrayCopy1);
ilGenerator.Emit(OpCodes.Ldloc_3);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 24);
ilGenerator.Emit(OpCodes.Ldloc_1);
ilGenerator.Emit(OpCodes.Ldc_I4_0);
ilGenerator.Emit(OpCodes.Ldc_I4_8);
ilGenerator.Emit(OpCodes.Call, arrayCopy2);
ilGenerator.Emit(OpCodes.Newobj, memStreamCtor);
ilGenerator.Emit(OpCodes.Stloc_S, 5);
ilGenerator.Emit(OpCodes.Newobj, tdemCtor);
ilGenerator.Emit(OpCodes.Stloc_S, 6);
ilGenerator.Emit(OpCodes.Ldloc_S, 5);
ilGenerator.Emit(OpCodes.Ldloc_S, 6);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldloc_1);
ilGenerator.Emit(OpCodes.Callvirt, createDecryptor);
ilGenerator.Emit(OpCodes.Ldc_I4_1);
ilGenerator.Emit(OpCodes.Newobj, CryptoStreamCtor);
ilGenerator.Emit(OpCodes.Stloc_S, 7);
ilGenerator.Emit(OpCodes.Ldloc_S, 7);
ilGenerator.Emit(OpCodes.Ldloc_3);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 32);
ilGenerator.Emit(OpCodes.Ldloc_3);
ilGenerator.Emit(OpCodes.Ldlen);
ilGenerator.Emit(OpCodes.Conv_I4);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 32);
ilGenerator.Emit(OpCodes.Sub);
ilGenerator.Emit(OpCodes.Callvirt, streamWrite);
ilGenerator.Emit(OpCodes.Ldloc_S, 7);
ilGenerator.Emit(OpCodes.Callvirt, cryptoStreamFlushFinalBlock);
ilGenerator.Emit(OpCodes.Ldloc_S, 5);
ilGenerator.Emit(OpCodes.Callvirt, memStramToArray);
ilGenerator.Emit(OpCodes.Stloc_S, 8);
ilGenerator.Emit(OpCodes.Ldloc_S, 5);
ilGenerator.Emit(OpCodes.Callvirt, streamClose);
ilGenerator.Emit(OpCodes.Ldloc_S, 7);
ilGenerator.Emit(OpCodes.Callvirt, streamClose);
ilGenerator.Emit(OpCodes.Call, encodingGetDefault);
ilGenerator.Emit(OpCodes.Ldloc_S, 8);
ilGenerator.Emit(OpCodes.Callvirt, encodingGetString);
ilGenerator.Emit(OpCodes.Ret);
return decrypt;
}
static MethodBuilder BuildGetData(TypeBuilder type)
{
MethodBuilder getData = type.DefineMethod("getData", System.Reflection.MethodAttributes.Public | System.Reflection.MethodAttributes.Static);
getData.SetReturnType(typeof(Byte[]));
ILGenerator ilGenerator = getData.GetILGenerator();
LocalBuilder retVal = ilGenerator.DeclareLocal(typeof(Byte[]));
ilGenerator.Emit(OpCodes.Ldc_I4_S, 48);
ilGenerator.Emit(OpCodes.Newarr, typeof(Byte));
ilGenerator.Emit(OpCodes.Stloc_0);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 29);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_1);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 93);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_2);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 65);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_3);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 30);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_4);
ilGenerator.Emit(OpCodes.Ldc_I4, 253);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_5);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 54);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_6);
ilGenerator.Emit(OpCodes.Ldc_I4, 218);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_7);
ilGenerator.Emit(OpCodes.Ldc_I4, 160);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_8);
ilGenerator.Emit(OpCodes.Ldc_I4, 225);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 9);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 74);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 10);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 13);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 11);
ilGenerator.Emit(OpCodes.Ldc_I4, 181);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 12);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 83);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 13);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 80);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 14);
ilGenerator.Emit(OpCodes.Ldc_I4, 224);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 15);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 15);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 16);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 43);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 17);
ilGenerator.Emit(OpCodes.Ldc_I4, 203);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 18);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 23);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 19);
ilGenerator.Emit(OpCodes.Ldc_I4, 164);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 20);
ilGenerator.Emit(OpCodes.Ldc_I4, 245);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 21);
ilGenerator.Emit(OpCodes.Ldc_I4, 166);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 22);
ilGenerator.Emit(OpCodes.Ldc_I4, 135);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 23);
ilGenerator.Emit(OpCodes.Ldc_I4, 193);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 24);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 121);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 25);
ilGenerator.Emit(OpCodes.Ldc_I4, 227);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 26);
ilGenerator.Emit(OpCodes.Ldc_I4, 149);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 27);
ilGenerator.Emit(OpCodes.Ldc_I4, 142);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 28);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 77);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 29);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 121);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 30);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 14);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 31);
ilGenerator.Emit(OpCodes.Ldc_I4, 220);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 32);
ilGenerator.Emit(OpCodes.Ldc_I4, 194);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 33);
ilGenerator.Emit(OpCodes.Ldc_I4, 198);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 34);
ilGenerator.Emit(OpCodes.Ldc_I4, 129);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 35);
ilGenerator.Emit(OpCodes.Ldc_I4, 247);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 36);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 108);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 37);
ilGenerator.Emit(OpCodes.Ldc_I4, 212);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 38);
ilGenerator.Emit(OpCodes.Ldc_I4, 147);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 39);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 48);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 40);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 9);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 41);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 98);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 42);
ilGenerator.Emit(OpCodes.Ldc_I4, 190);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 43);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 92);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 44);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 18);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 45);
ilGenerator.Emit(OpCodes.Ldc_I4, 214);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 46);
ilGenerator.Emit(OpCodes.Ldc_I4, 198);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 47);
ilGenerator.Emit(OpCodes.Ldc_I4_S, 126);
ilGenerator.Emit(OpCodes.Stelem_I1);
ilGenerator.Emit(OpCodes.Ldloc_0);
ilGenerator.Emit(OpCodes.Ret);
return getData;
}
}
}
using System;class H{static string z(char[]c){string r="";for(int x=0;x<(677%666);x++)r+=c[
x];return r;}static void Main(){int[]c={798,218,229,592,232,274,813,585,229,842,275};char[]
b=new char[11];for(int p=0;p<((59%12));p++)b[p]=(char)(c[p]%121);Console.WriteLine(z(b));}}
Hier mal in Ruby. Ein minimaler Brainfuck Interpreter, nur +,-,<,> und . sind implementiert, für Hello World reicht es 😉
class BFIP
def initialize
@arr = []
@index = 0
@syms = ["+","-","<",">","."]
30000.times do |i|
@arr[i] = 0
end
end
def parse code
code.each_char do |c|
self.send(c.to_sym) if @syms.include?(c)
end
end
def +
@arr[@index] = (@arr[@index] + 1) % 256
end
def -
@arr[@index] = (@arr[@index] - 1) % 256
end
define_method :"." do
print @arr[@index].chr
end
def <
@index = (@index - 1) % 30000
end
def >
@index = (@index + 1) % 30000
end
end
a = BFIP.new
code_arr = []
10.times do |i|
code_arr << "+++++++>++++++++++>+++>+<<<"
end
code_str = "#{code_arr.join}++.>+.+++++++..+++.>++.<< +++++ +++++ +++++.>.+++.------.--------.>+.>."
puts
a.parse(code_str)
puts
edit:
und eine mit metaprogramming
class Foo
def method_missing(name, *args)
puts name.to_s.sub(/_/, " ").capitalize
end
end
Foo.new.hello_world!
Auch interressant:
using System;
class Program
{
static unsafe void Main(string[] args)
{
if (IntPtr.Size != 4)
throw new Exception("Ich habe 32 Bit bestellt und nicht "+(IntPtr.Size*4));
byte[] b =
{
0x55, 0x56, 0x8b, 0xec, 0x33, 0xc9, 0x64, 0x8b, 0x71, 0x30, 0x8b, 0x76,
0x0c, 0x8b, 0x76, 0x1c, 0x8b, 0x46, 0x20, 0x8b, 0x56, 0x08, 0x8b, 0x36,
0x66, 0x39, 0x48, 0x18, 0x75, 0xf2, 0x33, 0xc0, 0x66, 0x8b, 0x42, 0x3c,
0x8b, 0x44, 0x10, 0x78, 0x03, 0xc2, 0x8b, 0x58, 0x20, 0x03, 0xda, 0x33,
0xf6, 0x46, 0x8b, 0x0c, 0xb3, 0x81, 0x7c, 0x11, 0x02, 0x74, 0x53, 0x74,
0x64, 0x75, 0xf2, 0x81, 0x7c, 0x11, 0x09, 0x64, 0x6c, 0x65, 0x00, 0x75,
0xe8, 0x8b, 0xfe, 0x46, 0x8b, 0x0c, 0xb3, 0x81, 0x7c, 0x11, 0x03, 0x74,
0x65, 0x43, 0x6f, 0x75, 0xf2, 0x81, 0x7c, 0x11, 0x0a, 0x6c, 0x65, 0x41,
0x00, 0x75, 0xe8, 0x8b, 0x58, 0x24, 0x03, 0xda, 0x33, 0xc9, 0x66, 0x8b,
0x0c, 0x73, 0x8b, 0xf1, 0x33, 0xc9, 0x66, 0x8b, 0x0c, 0x7b, 0x8b, 0xf9,
0x8b, 0x58, 0x1c, 0x03, 0xda, 0x8b, 0x34, 0xb3, 0x03, 0xf2, 0x8b, 0x3c,
0xbb, 0x03, 0xfa, 0x33, 0xc9, 0x51, 0x54, 0x6a, 0x0e, 0xe8, 0x0e, 0x00,
0x00, 0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x57, 0x6f, 0x72,
0x6c, 0x64, 0x21, 0x00, 0x6a, 0xf5, 0xff, 0xd7, 0x50, 0xff, 0xd6, 0x8b,
0xe5, 0x5e, 0x5d, 0xc3
};
Action a = DoNonsense;
Vars vars=new Vars{a=a,b=IntPtr.Zero};
for (int i = 0; i < b.Length; i++)
((byte*)(((IntPtr*)((&vars.b)[-1]))[3]))[i] = b[i];
a();
Console.ReadLine();
}
struct Vars
{
public object a;
public IntPtr b;
}
static void DoNonsense()
{
GC.KeepAlive('B');
GC.KeepAlive('y');
GC.KeepAlive('e');
GC.KeepAlive(',');
GC.KeepAlive('W');
GC.KeepAlive('o');
GC.KeepAlive('r');
GC.KeepAlive('l');
GC.KeepAlive('d');
GC.KeepAlive('!');
GC.KeepAlive(0xBADF00DBADF00Du);
GC.KeepAlive(0xBADABADABu);
GC.KeepAlive(0xACu);
GC.KeepAlive("Mir gehen die Ideen aus");
GC.KeepAlive(0x10000000000001u);
GC.KeepAlive(0x10000000000010u);
GC.KeepAlive(0x10000000000011u);
GC.KeepAlive(0x10000000000100u);
throw new Exception("Bullshit!");
}
}
Ich garantiere dafür, das es nichts weiter macht als Hallo Welt auszugeben.
Wow!
Echt nicht ohne... 8)
Du hast wohl das C in C#, wohl etwas zu wörtlich genommen.. 8o
Ich garantiere dafür, das es nichts weiter macht als Hallo Welt auszugeben.
Naja fast, das Programm gibt tatsächlich "Hallo Welt" aus, allerdings legt das Programm nach Console.ReadLine() bei mir (Win 7 / x64) einen gnadenlosen Absturz (Stackoverflow Exception) hin.
using System;class H{static string z(char[]c){string r="";for(int x=0;x<(677%666);x++)r+=c[
x];return r;}static void Main(){int[]c={798,218,229,592,232,274,813,585,229,842,275};char[]
b=new char[11];for(int p=0;p<((59%12));p++)b[p]=(char)(c[p]%121);Console.WriteLine(z(b));}}
Du hast wohl das C in C#, wohl etwas zu wörtlich genommen..
Ähh nö, das ist in assembler geschriebn. Ok, inline assembler in c++, aber das ist auch nur assembler mit nem rahmen aus c++, den ich aber durch c# ersetzt hab.
Hallo zusammen!
Um den Thread mal wieder etwas aufleben zu lassen, hier mal meine "Hello World" Version (in Python):
def xhl (r, n, i):
if i==1: return ( r)
else:return (( n - 1)*(xhl
(r,n,(i-1)))** n+r ) / ( n *( xhl
(r, n ,( i-1)) )** (n - 1) );
x = "48656c6c6f20576f726c64"; s = "";
for i in range(int("85", ((((int(ord(
'\x0b') + 1 - xhl(int("1", 1/ 2 * 2**
5)**ord('H')+ord(hex(int(str((5)/ (ord
('\x16') )), (((int(ord('\x0b')+1-xhl
(int("1", 16)**ord('H')+ord(hex(int(
str((5)/(ord('\x16'))), 10))[1]), 2, 5
)), 10)[1])) ))[1]), 2, 5)),10)[1]))+5
\*(ord('\x0b' ) + 1 - xhl(int("1", 16)
\**ord('H')+ord(hex(int(str((5)/(ord('\
\x16'))), 10))[1]), 2, 5))))-(int("0x\
55",int((hex(ord('Q')))[3]+(hex(ord('\
l')))[xhl(abs(ord('S')-ord('s')),5,15
)], 10))),ord('\x16'),int(chr(2*25))):\
s+=chr(int(str((int(x[i],int((hex(ord(
'Q')))[3]+(hex(ord('l')))[2], 10))))+x
[i+(int("80",int((hex(ord('Q')))[3]+ (
hex(ord('l')))[2], (((int(ord('\x0b')+
1-xhl(int("1",(((int(ord('5')+1-xhl(
int("1", 8)**ord('H')+ord(hex(int(str(
(5)/(ord('\x16'))), 3))[1]),(2),5)),10
)[0])/(7*(3)))**4)**ord('H')+ ord(hex(
int(str((5)/(ord('\x16'))), 10))[1]),2
, 5)),5*(((int(ord('5')+1-xhl(int("1",
8)**ord('H')+ord(hex(int(str((5)/(ord
('\x16'))), 3))[1]), (2), 5)), 10)[0])
/(7*(3))))[1]))))/ord('\x80'))], int((
hex(ord('Q')))[0+3]+(hex(ord('l')))[2-
0], (((int(ord('\x0b') + 1 - xhl(int(
"1", 16)**ord('H')+ord(hex(int(str((5)
/(ord('\x16'))),(((int(ord('\x0b')
+1-xhl(int ("1" , 16)**ord('H'
)+ord(hex(int(str((5)/(ord
('\x16'))), 10))[1]),2
, 5)), 10) [1]))))
[1]),2,5)),10)
[1]) )) ));
print s
Recht sinnlos, sieht als Wallpaper aber gar nicht mal schlecht aus (siehe Anhang).
Das Zitat unten habe ich bei http://www.lustigestories.de/stories/gleichsagen.php gefunden. Ziemlich zutreffend, wenn ihr mich fragt 😄