220
\$\begingroup\$

Try to write some code in your language and make it not satisfying our criteria of being a programming language any more.

A language satisfies our criteria (simplified version for this challenge) of being a programming language if:

  • It can read user input representing tuples of positive integers in some way.
  • It can output at least two different possible results depending on the input.
  • It can take two positive integers and add them (and the result can affect the output).
  • It can take a positive integer and decide whether it is a prime (and the result can affect the output).
  • For the purpose of this challenge, any kind of output that isn't an allowed output method for a normal challenge is ignored. So it doesn't matter whether the program can also play a piece of music, or posting via HTTP, etc.
  • Update: You can also choose one or some of the allowed output methods, and ignore all the others. But you must use the same definition everywhere in the following criteria. And if your program can disable more than one output methods — that worths more upvotes.

Examples like making it not able to output, or disabling all the loop constructs so it won't be able to do primality test and making sure the user cannot re-enable them.

You should leave a place for inserting new code. By default, it is at the end of your code. If we consider putting the source code in that place in your answer and running the full code as a complete program the interpreter of a new language, that language should not satisfy the criteria.

But the inserted code must be executed in such a way like a language satisfying the criteria:

  • The inserted code must be grammatically the same as something (say it's a code block in the following criteria) that generally do satisfy the criteria, from the perspective of whoever wants to write a syntax highlighter. So it cannot be in a string, comment, etc.
  • The inserted code must be actually executed, in a way it is supposed to satisfy the criteria. So it cannot be in an unused function or sizeof in C, you cannot just execute only a non-functional part in the code, and you cannot put it after an infinite loop, etc.
  • You can't limit the number of possible grammatically correct programs generated this way. If there is already something like a length limit in the language you are using, it shouldn't satisfy the criteria even if this limit is removed.
  • You can't modify or "use up" the content of input / output, but you can prevent them from being accessed.
  • These criteria usually only applies to languages without explicit I/O:
    • Your code should redirect the user input (that contains informations of arbitrary length) to the inserted code, if a code block isn't usually able to get the user input directly / explicitly in the language you are using.
    • Your code should print the returned value of the inserted code, if a code block isn't usually able to output things directly / explicitly in the language you are using.
    • In case you print the returned value, and it is typed in the language you are using, the returned type should be able to have 2 different practically possible values. For example, you cannot use the type struct {} or struct {private:int x;} in C++.

This is popularity-contest. The highest voted valid answer (so nobody spotted an error or all errors are fixed) wins.

Clarifications

  • You shouldn't modify the code in the text form, but can change the syntax before the code is interpreted or compiled.
  • You can do other things while the code is running. But the reason that it doesn't satisfy the criteria should be within the inserted code itself. It can error because of the interference of another thread, but not just be killed by another thread.
  • All the specs basically means it should be grammatically likely satisfying the criteria if all the built-ins were not changed but not actually do. It's fine if you find any non-grammatical workarounds, such as passing the parameters to the code block correctly, but make them not able to be used in some way.
  • Again, the inserted code must be actually executed. Code after an infinite loop or crashing is considered "not actually executed", thus not valid. Those answers might be interesting, but there are already some other infinite loop or crashing questions on this site, and you may find a more appropriate one to answer. If not, consider asking a new question. Examples of those questions are:

Leaderboard

var QUESTION_ID=61115/*,OVERRIDE_USER=8478*/;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,/*getComments()*/(more_answers?getAnswers():process())}})}/*function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}*/function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),score:s.score,language:a[1],lang:jQuery('<div>').html(a[1]).text(),link:s.share_link})}),e.sort(function(e,s){var r=e.score,a=s.score;return a-r});var s={},r=1,a=null,n=1;e.forEach(function(e){e.score!=a&&(n=r),a=e.score,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",e.n=n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.score).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text())/*,s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}*/});var t=e/*[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o])*/;t.sort(function(e,s){return (e.lang.toUpperCase()>s.lang.toUpperCase())-(e.lang.toUpperCase()<s.lang.toUpperCase())||(e.lang>s.lang)-(e.lang<s.lang)});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{PLACE}}",o.n).replace("{{LANGUAGE}}",o.language).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.score).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<(?:h\d|(?!.*<h\d>)p)>\s*((?:[^,;(\s]| +[^-,;(\s])+)(?=(?: *(?:[,;(]| -).*?)?\s*<\/(h\d|p)>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;float:left}table{width:250px}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/all.css?v=7509797c03ea"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Score</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Sorted by Language</h2> <table class="language-list"> <thead> <tr><td></td><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{PLACE}}</td><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

\$\endgroup\$
44
  • \$\begingroup\$ Am I allowed to change the code before executing it? Also, can I run other code whilst I am running the code given? \$\endgroup\$
    – Blue
    Oct 18, 2015 at 12:30
  • 26
    \$\begingroup\$ This could have made a really great cops and robbers challenge I think. \$\endgroup\$
    – DankMemes
    Oct 18, 2015 at 23:07
  • 6
    \$\begingroup\$ @DankMemes Agreed. As it stands, it's much too vague, and most answers would be invalidated by finding a workaround. CnR with this premise would be delightful. \$\endgroup\$
    – user45941
    Oct 18, 2015 at 23:54
  • 3
    \$\begingroup\$ So then it seems to be saying that in languages with explicit IO it's permissible to do completely boring things like reading and discarding the contents of stdin. It sets up a completely unfair playing field where some languages require you to carefully handle the IO for the inserted code, and other languages allow you to trash it and deny IO to the inserted code. \$\endgroup\$ Oct 19, 2015 at 12:28
  • 6
    \$\begingroup\$ Are we allowed to use a language that's already unusable to begin with? (JavaScript for example) \$\endgroup\$
    – 12Me21
    Oct 17, 2017 at 14:23

89 Answers 89

1 2
3
3
\$\begingroup\$

[min]mod

[].UNWRAP.SET[].IF.SET[].SET.SET

Try it step by step!

Set all the built-in instructions to empty stacks (noops), making all instructions based on those instructions noops as well, since they only execute noops in different orders :)

\$\endgroup\$
2
\$\begingroup\$

Enema

:OQ::!Q:

Code can come any place after this.

This language is similar to Emmental in that it is capable of redefining itself. Essentially, what we're doing here is redefining O (which normally is for output) to do nothing (thus making the language no longer have a transformational model) and then redefine ! (which can be used to reset a word to its default behavior) to do nothing as well.

\$\endgroup\$
2
\$\begingroup\$

O

N:+:-:/:*:@:\:[:]:1:2:3:4:5:6:7:8:9:0:{:}:<:>:=:#:%:^:?:d:w:o:p::;

This reassigns mostly everything to a null codeblock, making any code that contains these characters do nothing.

You could add every ASCII character to make sure they can't do anything, but this kills all arithmetic, stack manipulation, codeblock creation, array creation, pushing numbers to the stack, comparing numbers, control flow, outputting, and assigning variables.

\$\endgroup\$
2
\$\begingroup\$

Mouse-2002

$ ~your code here

In Mouse, $ denotes the end of the program, thus, anything after it will be evaluated and "run" but won't actually do anything. No online interpreter available, unfortunately, but here is a fixed-so-it-compiles-in-gcc version of the interpreter written in C.

\$\endgroup\$
3
  • \$\begingroup\$ Too bad it ain't ): \$\endgroup\$
    – cat
    Dec 9, 2015 at 1:22
  • \$\begingroup\$ Invalid because the code after it wasn't actually executed. \$\endgroup\$ Feb 22, 2016 at 21:19
  • \$\begingroup\$ @ppperry did you read past the first clause of the first sentence? \$\endgroup\$
    – cat
    Feb 22, 2016 at 21:22
2
\$\begingroup\$

J, online interpreter

f =: f
f 3

This calls f with f with f with... etc. Here's what the page looks like:

crash 1

Successive attempts at entering things in yields, well, nothing:

this

Tested on Firefox.

\$\endgroup\$
2
  • \$\begingroup\$ Hmm this only seem to break for me on the online interpreter using Firefox. The interpreter seems to be usable afterwards in Chrome, and jconsole handles the error completely differently locally. Might be worth noting. \$\endgroup\$
    – Sp3000
    May 23, 2016 at 8:05
  • \$\begingroup\$ @Sp3000 Huh, interesting. Consider it noted. \$\endgroup\$ May 23, 2016 at 15:51
2
\$\begingroup\$

Lua

local write = io.write
local type = type
local pairs = pairs
local setmetatable = setmetatable
local function destroy(g,t)
    t = t or {}
    setmetatable(g, {__index = function() return write end,__newindex = function() return false end})
    for k,v in pairs(g) do
        if(type(v)=="table")then
            local has = false
            for k2, v2 in pairs(t) do
                if v2 == v then
                    has = true
                    break
                end
            end
            if not has then
                t[#t+1]=v
                destroy(v,t)
            end
        elseif(type(v)=="function")then
            g[k] = write
        end
    end
end
destroy(_G)
type = write
pairs = write
setmetatable = nil

A fun one, makes all functions, including string and table constructors, into the io.write function. It doesn't necessarily prevent the language from doing things it was already doing, but it does cripple it from this point onwards. I chose io.write because I thought it interesting to see if I could make trying to run literally anything print. It didn't work so well.

\$\endgroup\$
2
\$\begingroup\$

Bash

exec &> /dev/null

Any code that comes after can execute whatever it wants, but its output is cast into the void of /dev/null.

\$\endgroup\$
7
  • \$\begingroup\$ File I/O still works though. \$\endgroup\$
    – eush77
    May 14, 2017 at 18:02
  • \$\begingroup\$ @eush77 True! However, the challenge stated that we could cover only a subset of the allowed output methods. \$\endgroup\$
    – Chris
    May 15, 2017 at 8:51
  • \$\begingroup\$ Right, I missed that. \$\endgroup\$
    – eush77
    May 15, 2017 at 9:16
  • 1
    \$\begingroup\$ Too bad exec &> /dev/tty easily reverses that :) \$\endgroup\$
    – eush77
    May 15, 2017 at 9:23
  • \$\begingroup\$ @eush77 True... If you really wanted to break it, you would do exec &> /dev/null < /dev/zero. But I'm pretty sure that breaks the rules. \$\endgroup\$
    – Chris
    May 15, 2017 at 20:03
2
\$\begingroup\$

Forth (gforth), 8 bytes

0 >ORDER

Everything you type in after that except an empty line will result in Invalid memory address.

I stumbled upon this by accident just now, I don't know precisely how it works but I guess >ORDER adds a new dictionary to search in for words or something. And it can't read from address 0, the address we told it to search for first, so it throws an error.

Forth (RCOS), 10 bytes

0 LATEST !

Tells the Forth that no words have been defined (latest word is the null pointer). Thus, you can only input numbers, everything else results in an Unknown token error.

Forth (RCOS), 18 bytes

219 ' INTERPRET C!

Writes byte 0xDB (65C02's STP instruction which halts the processor) to the start of the INTERPRET word. Now, everytime that word is called, the processor is halted. What INTERPRET normally does, it takes an area of memory (most likely the line buffer) and executes the words in there in order. It gets called when you press enter to execute the current line. So, with our new behavior, everytime you press enter (aka call INTERPRET) it halts the computer.

Looks like there's many ways to break my RCOS, but what do you expect, it's written in assembly

\$\endgroup\$
2
\$\begingroup\$

S.I.L.O.S, 1 byte

0

Try it online!

Yes, in SILOS, your code can be made completely useless by editing the first line. With this, you can not store any variavbles (or take any input). Essentially it allocates 0 bytes of memory for the first line.

\$\endgroup\$
2
\$\begingroup\$

JS, 11B

delete this

works with IE>8 and Edge (non-strict mode), with only workaround is exiting then reentering console to redefine them.

\$\endgroup\$
2
\$\begingroup\$

Staq

{ '}{{}}

which redefines the noop to push entered number to stack. Then { to }.

\$\endgroup\$
2
\$\begingroup\$

Crystal, 44 bytes

fun main(a : Int32,b : UInt8**) : Int32 0end

Try it online!

Works by overwriting the main function, so that rather than actually running code, it simply returns. Code can be inserted at any point after that, and it will simply be ignored.

\$\endgroup\$
2
\$\begingroup\$

JavaScript (Node.js), 23 bytes

for(y in this)this[y]=0

Try it online!

This script works almost universally unlike other JS examples here. I think I could probably shorten this using regex matching.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Doesn't really work with V8 in browsers unfortunately \$\endgroup\$ Dec 1, 2020 at 20:01
2
\$\begingroup\$

Spice

A couple of ways:

1. ALS

;@
ALS LOD OUT;
ALS ADD SWI;
ALS SUB BRK;
ALS MUL NUL;

New code goes at the end.

Explanation

The first character of a spice program defines the delimiter, in this case ; which is usually followed by all variable definitions before @ denotes the beginning of operations on those variables.

ALS allows aliasing operations to other names, so here we overwrite some builtin operations with other. Because OUT, SWI, BRK and NUL are the only operations that don't require a variable as at least one argument, by aliasing them to pre-existing operations we make it impossible to invoke them, as aliases are resolved first.

2. Poorly defined delimiter

 @

(Note leading space)

Explanation

We define the delimiter as a space, making invoking any operation cause a runtime exception in the interpreter: this is the equivalent of writing code similar to:

;var1;@
ADD;1;2;var

which is nonsensical in Spice.

\$\endgroup\$
2
\$\begingroup\$

JavaScript (browser)

It's hard to test this since it breaks everything. Not sure if this is complete but it's easy to keep adding clear(somebuiltin) to remove more properties

const clear = (obj) => {
  for (const prop in obj) obj[prop] = undefined
}
window.addEventListener("error", () => {})
clear(window);
clear(document);
clear(console);

// code here
console.log(Number(prompt("a")) + Number(prompt("b")))
\$\endgroup\$
2
  • \$\begingroup\$ Only clear(window) should be enough, document and console are both properties of window \$\endgroup\$
    – mousetail
    Dec 28, 2022 at 18:57
  • \$\begingroup\$ Yeah that seems like it would be like that intuitively @mousetail. I remember finding some workaround while I was testing but I'm going to double check \$\endgroup\$
    – noodle man
    Dec 28, 2022 at 22:43
1
\$\begingroup\$

Befunge 98

 v
v>"PAMI"4("zqzCzOz=z.z,z)zozszM"akMn
>

Redefines the , and . instructions to NOPS to prevent out the standard way, then redifines the = instruction to prevent execution oif an arbirtrary program, then redefines the o instruction to prevent file output and the q instruction to prevent output by exit code, then redefines the C,O,M,and ) instructions to prevent you from undoing its definitions. Insert your code after the > on the third line.

\$\endgroup\$
1
\$\begingroup\$

Factor

Factor is a concatenative stack-based language, where all operators are words which are defined with :. Here, we kill the builtin print functions by defining them as nothing, and then redfine the macro redefiniton operator.

: stream-write ( -- ) ;
: write ( -- ) ;
: print ( -- ) ;
: . ( -- ) ;
: : ( -- ) ;

! your code here
\$\endgroup\$
1
\$\begingroup\$

DUP

[]⇒.[]⇒;[]⇒"[]⇒,[]⇒`[]⇒'[]⇒⇒ { your code here }

Redefine the print operators, the string allocation operators, and the input operators all to noop, and then define the definition operator as a noop.

\$\endgroup\$
1
\$\begingroup\$

Staq, 20 bytes

{` }{' }{: }{; }{{}}

Redefines all I/0 instructions as NOPs

Standard Staq instructions:

: output the topmost stack value to the console as a number
; output the topmost stack value to the console as a character
' push entered number on stack
` push value of entered character on stack
{ begin function definition
} end function definition

{` }                   define ` as NOP 
    {' }               define ' as NOP
        {: }           define : as NOP
            {; }       define ; as NOP
                {{}}   define { as }

This way, no more functions can be defined, which would be necessary to reset the instructions to their original state. In Staq, all predefined instructions can be reset to their original state by putting them between curly braces without a space. For example, : could be reset by writing {:}. But that’s not possible anymore because the opening { is defined as }, which would result in a useless set of instructions: }:}, which in turn (due to the redefinition of :) means } }.

So, anything that gets executed after this block runs as normal, but is useless because there is neither input nor output possible anymore, and no way to define functions to restore that ability.

\$\endgroup\$
1
  • \$\begingroup\$ No need to count the bytes, this is popularity contest, not code-golf. \$\endgroup\$
    – user75200
    Oct 29, 2017 at 16:50
1
\$\begingroup\$

Python 3 REPL

def f():
    import gc
    obs = gc.get_objects()
    for ob in obs:
       if isinstance(ob, dict) and ob is not locals() and ob is not __builtins__.__dict__ and ob is not globals():
           ob.clear()
f()
#What can you do now!
\$\endgroup\$
1
  • \$\begingroup\$ @mbomb007 It works, but only in a REPL. tio.run/nexus/… \$\endgroup\$
    – Dennis
    May 5, 2017 at 16:43
1
\$\begingroup\$

Japt

$Japt=undefined$

Test it online!

\$\endgroup\$
4
  • \$\begingroup\$ Can you replace it with $Japt=0 for savings? \$\endgroup\$ Jul 10, 2017 at 21:41
  • \$\begingroup\$ Won't the embedded JavaScript still be run? \$\endgroup\$ Aug 22, 2017 at 20:08
  • \$\begingroup\$ @Oliver Yes, but there's no closing $, meaning that I can continue to add Javascript after the assignment. \$\endgroup\$ Aug 23, 2017 at 4:58
  • \$\begingroup\$ [][1] instead of undefined? :P \$\endgroup\$
    – ASCII-only
    Apr 1, 2019 at 10:40
1
\$\begingroup\$

ForceLang

undef def
undef gui
undef io
undef if
undef goto
undef gotoex
undef require
undef undef

Your code goes after.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ I'm pretty sure this doesn't actually do anything, since all undef does is remove a definition created using the def command and doesn't actually change the value of any variables (or in this case constants.) \$\endgroup\$ Apr 2, 2019 at 1:25
1
\$\begingroup\$

JS (updated, compatible with IE11)

console.error=eval=0

Defines console.error to be eval which is redefined to be 0, which is no function but a number.

Output isn't directly possible.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ alert is a valid output method for PPCG challenges by default. \$\endgroup\$
    – hyper-neutrino
    Oct 21, 2017 at 17:12
  • \$\begingroup\$ But IE evals thus you can't alert your string. If you delete eval then try deleting console.error, you get The tab contains a modified eval function. It's possible the command program diagnostic windows won't work correctly, which is done by console.error. \$\endgroup\$
    – user75200
    Oct 29, 2017 at 16:51
1
\$\begingroup\$

Staq, elaborated more

{: }{; }{' }{" }{` }{{}}
{: }                    redefine : to NOP
    {; }                redefine ; to NOP
        {' }            redefine ' to NOP
            {" }        redefine " to NOP
                {` }    redefine ` to NOP
                    {{}}redefine { to }

If we didn't use {{}}, {:} can be used for restoring predefined characters.

\$\endgroup\$
1
\$\begingroup\$

C (gcc), 136 bytes

#include <stdlib.h>
#include <signal.h>
__attribute__((constructor))
void enable_io()
{
    // Make it clear that we are ready for IO
    raise(SIGPOLL);
}

Try it online!

Place it after any C file using libc (or LD_PRELOAD it for dynamically linked programs 😉)

#include <stdio.h>
int main()
{
    puts("hello");
}

(note that the program did not output this, it is the shell):

$ ./a.out
I/O possible

The __attribute__((constructor)) is a feature that allows GCC to inject functions before main() runs, and we exit the program before main() by raising a signal saying that I/O is possible, making I/O impossible.

exit(0) works as well, but this is funnier.

\$\endgroup\$
0
\$\begingroup\$

Java

Building upon https://codegolf.stackexchange.com/a/61124/40787's input I saw that there is just too much boilerplate and reflection.

You can insert the code after the comment.

Edit

Saw this wasn't a strict code-golf, so prettied it a bit

import static java.lang.Thread.*;

import java.io.*;
import java.lang.reflect.Proxy;

import sun.misc.*;

public class Jail {

    public static void main(String[] a) {
        //user code here :D
        //Remember, do not do anything funky!
    }

    static {
        // From the original Java submission
        System.setOut(new PrintStream(new ByteArrayOutputStream()));
        System.setErr(new PrintStream(new ByteArrayOutputStream()));
        System.setIn(new ByteArrayInputStream(new byte[0]));

        // Block all access
        SharedSecrets.setJavaIOAccess(b(JavaIOAccess.class));
        SharedSecrets.setJavaLangAccess(b(JavaLangAccess.class));
        SharedSecrets.setJavaSecurityAccess(b(JavaSecurityAccess.class));

        //prevent throw new Error(output to show)
        setDefaultUncaughtExceptionHandler(b(UncaughtExceptionHandler.class));

        // Seal the deal
        System.setSecurityManager(new SecurityManager());
    }

    static <T> T b(Class<T> t) {
        return (T) Proxy.newProxyInstance(null, new Class[]{t}, (p, m, a) -> null);
    }
}

Original

import static java.lang.Thread.*;
import java.io.*;
import java.lang.reflect.*;
import sun.misc.*;

class X {

    static SharedSecrets s;

    public static void main(String[] a) throws IOException {
        // From the original Java submission
        a=null;
        System.setOut(new PrintStream(new ByteArrayOutputStream()));
        System.setErr(new PrintStream(new ByteArrayOutputStream()));
        System.setIn(new ByteArrayInputStream(new byte[0]));

        // Block all access
        s.setJavaIOAccess(b(JavaIOAccess.class));
        s.setJavaLangAccess(b(JavaLangAccess.class));
        s.setJavaSecurityAccess(b(JavaSecurityAccess.class));

        //prevent throw new Error(output to show)
        setDefaultUncaughtExceptionHandler(b(UncaughtExceptionHandler.class));

        // Seal the deal
        System.setSecurityManager(new SecurityManager());

        //user code here :D
        //Remember, do not do anything funky!

    }

    static <T> T b(Class t) {
        return (T) Proxy.newProxyInstance(null, new Class[]{t}, (p, m, a) -> {
            throw null;
        });
    }
}

If you write normal language syntax, it still works (mostly). Also, opening files or trying to reset the streams is frowned upon. Just wanted to get some lower number Java submissions.

\$\endgroup\$
0
\$\begingroup\$

Groovy

java.lang.Class.metaClass = Integer.metaClass
Integer.metaClass.plus = { Integer n ->     return 'a' }
Integer.metaClass.minus = { Integer n ->     return 's' }
Integer.metaClass.multiply = { Integer n ->     return 'd' }
Integer.metaClass.div = { Integer n ->     return 'f' }

I tried (without success) to overwrite the print commands, so I redefined the Object instead :) ​

\$\endgroup\$
0
\$\begingroup\$

Javascript

for(let q in this)delete this[q];

which deletes each property of this.

Or,

eval=0;

assigning 0 to eval, thus any input raises this:

The tab contains a modified eval function. It's possible, the command program diagnostic windows don't work correctly.

thus being irreversible by even restarting developer tools!

\$\endgroup\$
2
  • \$\begingroup\$ only works in IE>10. \$\endgroup\$
    – user75200
    Oct 29, 2017 at 16:48
  • \$\begingroup\$ eval=0 doesn't seem to work. \$\endgroup\$
    – emanresu A
    Apr 5, 2021 at 0:55
0
\$\begingroup\$

Python 3.11

import sys
sys.stdout.close()
sys.stderr.close()
def hook(a,b):
   raise RuntimeError()
sys.addaudithook(hook)
for key in list(sys.modules):
    del sys.modules[key]
del sys
del hook

Should prevent any kind of IO. Even suppresses any error messages. No modules can be imported. No files can be opened. Also disables use of eval and exec.

However, just by itself this code runs with no errors and exits with status 0.

\$\endgroup\$
1 2
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.