Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 8eb5e30028725f46f84875269b048cd4aea63eba @SirCmpwn committed Jan 4, 2013
@@ -0,0 +1,36 @@
+# IRC-BF
+
+An IRC bot written in brainfuck.
+
+## Usage
+
+I've included a simple brainfuck interpreter that uses a TCP connection for input and output.
+
+You can probably run this through a regular old brainfuck interpreter and do some crazy shit to wire it
+up to a TCP connection, but I didn't feel like it. You can probably make something work with socat.
+
+You can use the custom bf interpreter like this:
+
+ netfuck hostname:port path/to/code.bf
+
+For example, to connect the bot to freenode, use this:
+
+ netfuck irc.freenode.net:6667 irc-bot.bf
+
+Then, to get it into your favorite channel, use this from IRC:
+
+ /msg bfbot join #channelname
+
+## Included Programs
+
+A couple of simple C# programs are included.
+
+* bf.exe: A simple brainfuck interpreter.
+* netfuck.exe: A brainfuck interpreter that uses TCP for input/output.
+* asciitodec.exe: Converts an ASCII string to decimal to make my life easier
+
+## Status
+
+Current capabilities of the bot:
+
+* Connect to IRC. Ignore all responses from the server. Time out and die.
Binary file not shown.
BIN bf.exe
Binary file not shown.
@@ -0,0 +1,88 @@
+Brainfuck IRC bot
+* Comments use ; in place of periods or commas as punctuation
+* Meant to operate on 8 bit unsigned memory
+* Expects a good amount of memory; I use 0x10000 bytes; smaller is probably fine
+* Expects stdin to block until data is available
+* If you use netfuck; it'd be useful to know that debug mode outputs every character read from the remote to the console
+
+Send NICK and USER
+
+"NICK bfbot\r\nUSER bfbot a a :bfbot\r\n" (78 73 67 75 32 98 102 98 111 116 13 10 85 83 69 82 32 98 102 98 111 116 32 97 32 58 98 102 98 111 116)
+ ++++++++++
+ [
+ N > +++++++
+ I > +++++++
+ C > ++++++
+ K > +++++++
+ > +++
+ b > +++++++++
+ f > ++++++++++
+ b > +++++++++
+ o > +++++++++++
+ t > +++++++++++
+ \r > +
+ \n > +
+ U > ++++++++
+ S > ++++++++
+ E > ++++++
+ R > ++++++++
+ > +++
+ b > +++++++++
+ f > ++++++++++
+ b > +++++++++
+ o > +++++++++++
+ t > +++++++++++
+ > +++
+ a > +++++++++
+ > +++
+ a > +++++++++
+ > +++
+ : > +++++
+ b > +++++++++
+ f > ++++++++++
+ b > +++++++++
+ o > +++++++++++
+ t > +++++++++++
+ \r > +
+ \n > +
+ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<-
+ ]
+ "NICK bfbot\r\nUSER bfbot a a :bfbot\r\n" (78 73 67 75 32 98 102 98 111 116 13 10 85 83 69 82 32 98 102 98 111 116 32 97 32 58 98 102 98 111 116)
+ N > ++++++++ .
+ I > +++ .
+ C > +++++++ .
+ K > +++++ .
+ > ++ .
+ b > ++++++++ .
+ f > ++ .
+ b > ++++++++ .
+ o > + .
+ t > ++++++ .
+ \r > +++ .
+ \n > .
+ U > +++++ .
+ S > +++ .
+ E > +++++++++ .
+ R > ++ .
+ > ++ .
+ b > +++++++++ .
+ f > ++ .
+ b > ++++++++ .
+ o > + .
+ t > ++++++ .
+ > ++ .
+ a > +++++++ .
+ > ++ .
+ a > +++++++ .
+ > ++ .
+ : > ++++++++ .
+ b > ++++++++ .
+ f > ++ .
+ b > ++++++++ .
+ o > + .
+ t > ++++++ .
+ \r > +++ .
+ \n > .
+ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< end of "NICK bfbot\r\nUSER bfbot a :bfbot\r\n"
+
++[,]
@@ -0,0 +1 @@
+++++++++++[>+++++++>+++++++>++++++>+++++++>+++>+++++++++>++++++++++>+++++++++>+++++++++++>+++++++++++>+>+>++++++++>++++++++>++++++>++++++++>+++>+++++++++>++++++++++>+++++++++>+++++++++++>+++++++++++>+++>+++++++++>+++>+++++++++>+++>+++++>+++++++++>++++++++++>+++++++++>+++++++++++>+++++++++++>+>+<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<-]>++++++++.>+++.>+++++++.>+++++.>++.>++++++++.>++.>++++++++.>+.>++++++.>+++.>.>+++++.>+++.>+++++++++.>++.>++.>+++++++++.>++.>++++++++.>+.>++++++.>++.>+++++++.>++.>+++++++.>++.>++++++++.>++++++++.>++.>++++++++.>+.>++++++.>+++.>.<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+[,]
Binary file not shown.
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<configuration>
+ <startup>
+
+ <supportedRuntime version="v2.0.50727"/></startup>
+</configuration>
@@ -0,0 +1,107 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.IO;
+using System.Net.Sockets;
+
+namespace netfuck
+{
+ internal class Program
+ {
+ private static void Main(string[] args)
+ {
+ bool debug = args.Length == 3;
+ if (args.Length < 2 || args.Length > 3)
+ {
+ Console.WriteLine("Usage: netfuck hostname:address /path/to/file.bf [--debug]");
+ return;
+ }
+ var code = args[1];
+ if (File.Exists(code))
+ code = File.ReadAllText(code);
+ // Establish connection
+ var endpoint = ParseEndPoint(args[0]);
+ var client = new TcpClient();
+ client.Connect(endpoint);
+ var stream = client.GetStream();
+ // Interpret code
+ var memory = new byte[ushort.MaxValue + 1];
+ ushort pointer = 0;
+ int codeIndex = 0;
+ while (codeIndex < code.Length)
+ {
+ switch (code[codeIndex++])
+ {
+ case '>':
+ pointer++;
+ break;
+ case '<':
+ pointer--;
+ break;
+ case '+':
+ memory[pointer]++;
+ break;
+ case '-':
+ memory[pointer]--;
+ break;
+ case '.':
+ stream.WriteByte(memory[pointer]);
+ break;
+ case ',':
+ while (client.Available == 0) ;
+ memory[pointer] = (byte)stream.ReadByte();
+ if (debug) Console.Write(Encoding.ASCII.GetString(new[] { memory[pointer] }));
+ break;
+ case '[':
+ if (memory[pointer] == 0)
+ {
+ codeIndex = code.IndexOf(']', codeIndex);
+ if (codeIndex == -1)
+ {
+ Console.WriteLine("Error: Hanging '['");
+ return;
+ }
+ }
+ break;
+ case ']':
+ if (memory[pointer] != 0)
+ {
+ codeIndex = code.Remove(codeIndex).LastIndexOf('[');
+ if (codeIndex == -1)
+ {
+ Console.WriteLine("Error: Hanging ']'");
+ return;
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ private static IPEndPoint ParseEndPoint(string arg)
+ {
+ IPAddress address;
+ int port;
+ if (arg.Contains(':'))
+ {
+ // Both IP and port are specified
+ var parts = arg.Split(':');
+ if (!IPAddress.TryParse(parts[0], out address))
+ address = Resolve(parts[0]);
+ return new IPEndPoint(address, int.Parse(parts[1]));
+ }
+ if (IPAddress.TryParse(arg, out address))
+ return new IPEndPoint(address, 6667);
+ if (int.TryParse(arg, out port))
+ return new IPEndPoint(IPAddress.Loopback, port);
+ return new IPEndPoint(Resolve(arg), 6667);
+ }
+
+ private static IPAddress Resolve(string arg)
+ {
+ return Dns.GetHostEntry(arg).AddressList.FirstOrDefault();
+ }
+ }
+}
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("netfuck")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("netfuck")]
+[assembly: AssemblyCopyright("Copyright © 2013")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("d253352a-8bfc-4c1d-b806-c322a7db01b2")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{33B62F46-CAD2-4F30-9124-E2E4A5072286}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>netfuck</RootNamespace>
+ <AssemblyName>netfuck</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <TargetFrameworkProfile>
+ </TargetFrameworkProfile>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
21 test.bf
@@ -0,0 +1,21 @@
++++++ +++++ initialize counter (cell #0) to 10
+[ use loop to set the next four cells to 70/100/30/10
+ > +++++ ++ add 7 to cell #1
+ > +++++ +++++ add 10 to cell #2
+ > +++ add 3 to cell #3
+ > + add 1 to cell #4
+ <<<< - decrement counter (cell #0)
+]
+> ++ . print 'H'
+> + . print 'e'
++++++ ++ . print 'l'
+. print 'l'
++++ . print 'o'
+> ++ . print ' '
+<< +++++ +++++ +++++ . print 'W'
+> . print 'o'
++++ . print 'r'
+----- - . print 'l'
+----- --- . print 'd'
+> + . print '!'
+> . print '\n'

0 comments on commit 8eb5e30

Please sign in to comment.