8-bit CPU build

This material is based on the high quality build your own CPU guide by Ben Eater. Ben cites the SAP-1 CPU architecture as the design inspiration for the CPU, which originated from the book Digital Computer Electonics by Albert Paul Malvino. The SAP (Simple As Possible) computer has been designed for you, the beginner. Its purpose, to introduce the crucial ideas behind a CPUs operation without burying you in unnecessary detail. Architecture General Electonics Dirty power Resistors Capacitors Latch vs flip flop D flip flop The clock The registers Arithmetic and Logic Unit (ALU) Design Implementation Representing negative numbers - signing bit, 1’s and 2’s complement Ones complement Two complement Program Counter (PC) PC module problem 1: counter clearing PC module problem 2: dirty clock signal Output register Arduino Nano EEPROM programmer Binary to decimal 7-segment decoder Multiplexing four 7-segment displays with a single EEPROM Handy resources Architecture The SAP-1 defines a number of logical CPU modules which are capable of integrating to form a working CPU and ultimately computer. ...

July 12, 2020 · 19 min

Redux

Once you start working with React in anger, there is a tipping point to be aware of where: the complexity of data flows piles up the same data is being rendered in multiple places the number of state changes blow out Being able to tackle these problems in a single place is where Redux fits in. Contents Contents The Problem Option 1 lift the state Option 2 react context Option 3 Redux A chat with redux Container vs Presentation Components The Redux Principles Actions The Store Immutability Reducers React-Redux React-Redux Provider React-Redux Connect mapStateToProps mapDispatchToProps Redux Setup Async and APIs Mock API API Client Wrappers Redux Middleware Redux Async Libraries Thunks Conditional mapStateToProps Polish (the finer things) Spinner component Status API and feedback Server side validation Client side validation Optimistic deletes Testing Redux Connected Components Action Creators Thunks Reducers Store The Problem Imagine a fairly deep component hierarchy, starting with your top level App component. Deep down the tree, there are two child components that need to access a common piece of data (e.g. customer data). How should these components access the data they require? ...

April 29, 2020 · 21 min

Suckless programs

The suckless project values simplicity, clarity and frugality in software. Our philosophy is about keeping things simple, minimal and usable. We believe this should become the mainstream philosophy in the IT sector. As a user of most of their programs including the infamous dwm (a tiling window manager), dmenu (launcher), st (terminal emulator) and others tools, I can attest to benefits of using minimal and efficient software. Patching Programs are customised by patching the C source code. However, unlike typical open source projects, suckless source code is quite readable and hackable, a by-product of the philosophy. ...

April 8, 2020 · 3 min

Managing wifi on Arch

See archwiki: nmcli device wifi list sniff currently available wifi ssids in range nmcli connection show show active connection/s nmcli device wifi connect Jeneffer password S3CR3T connect to ssid nmcli device wifi connect Jeneffer password S3CR3T hidden yes connect to hidden ssid nmcli connection up uuid UUID reconnect a disconnected interface nmcli device list all interfaces and their state mcli device disconnect wlp3s0 disconnect an interface nmcli radio wifi off disable wifi radio

March 16, 2020 · 1 min

Exploiting Heap Allocators Technical Paper

An academic paper I authored in October 2019, as part of studying Modern Exploit Development at UNSW. Abstract Heap oriented exploits continue to be an ongoing threat, and have gained popularity post the stack smashing frenzy of the 90’s and early 00’s. Even so called safe languages (e.g. JavaScript, Java) remain vulnerable due to their underlying C/C++ implementations. Heap allocator designs and implementations, of which there are many, struggle to strike the balance between performance and security, performance often winning out to keep programs running as fast as possible. Two ingredients are needed for a successful heap exploit, the first a memory management error in the target program, and second an exploitable heap allocator implementation. Many countermeasures in mainstream allocators seen to date are often the result of knee-jerk reactions to exploits of the past, with patching occurring to existing designs. A large body of research exists around detecting, preventing or mitigating heap attacks. ...

October 19, 2019 · 39 min

The Go Programming Lang

GOPATH Run, build and install Dependencies Formatting Documentation Structuring a source tree The lang Variables Control structures (if, switch and for) if switch for I/O fmt CLI Args Flags Basic Data Types Type conversion Strings Unicode String literals Numbers Integers Bitwise operations Floating point Constants Pointers Functions Grouped parameters types Variadic functions Multiple return values Named return values Recursion Deferred functional calls Functions as values Function literals (anonymous functions) Passing functions to functions Closures Error Handling Error handling strategies Propagate to caller Retry Log and continue Log and exit pkg/errors Panic and Recover Packages and Libraries Package aliases Imported unused packages for side effects Inspecting a package API Advanced Data Types Arrays Slices Extending slices Creating a slice with make Byte slices Maps Creating maps CRUD (create retrieve update delete) operations with maps Named types (user defined types) Function named type Type aliases Struct Struct embedding Field tags Struct methods Receiver Method Sets Interfaces Interface internals WARNING - dont assign nil variables to interfaces Type assertion Type switches Cool cool cool stdlib Tools Make Vim setup Libraries Data Middleware Web Effective Go is a howto on writing idiomatic Go. ...

October 5, 2019 · 30 min

Technical Analysis of ImageTragick (CVE-2016-3714)

ImageMagick is a widely deployed, general purpose image processing library written in C. Over the past few years hundreds of security related issues have been identified. This paper considers one such instance of a remote code execution vulnerability discovered in 2016 under CVE-2016-3714. Introduction ImageMagick is a widely deployed, general purpose image processing library written in C, most commonly used to resize, transcode or annotate user supplied images on the web. Originally developed in 1987 and open sourced in 1990, with a large ecosystem of bindings for most programming languages, has established an enormous user base over the last 3 decades. ...

September 27, 2019 · 25 min

ROP (return oriented programming) chains

An evolution on basic stack smashing, return oriented programming (or ROP) was first presented by Solar Designer in 1997, as an innovative solution to crafting a complete program by daisy chaining up instructions that already exist within the address space of the program. Because existing legitimate executable instructions are chained together, is an effective way of bypassing non-executable stack (DEP) and code signing mitigations employed by most modern OS’s. An attacker gains control of the IP by overflowing the stack (i.e. buffer overflow or stack smash), to hijack program control flow and then executes carefully chosen machine instruction sequences that are already present programs address space. The individual pieces are known as gadgets. Each gadget typically ends in a return (RET) instruction. Chained together, these gadgets allow an attacker to perform arbitrary operations. ...

September 7, 2019 · 13 min

Stack Canaries

A popular buffer overflow prevention technique employed by some programs. Used to detect a stack buffer overflow before execution of malicious code can occur, by placing a small integer, the value of which is randomly chosen at program start, in memory just before the stack return pointer. Most buffer overflows overwrite memory from lower to higher memory addresses, so in order to overwrite the return pointer, the canary value must also be overwritten. This value is checked to make sure it has not changed before a routine uses the return pointer on the stack. This technique can greatly increase the difficulty of exploiting a stack buffer overflow because it forces the attacker to gain control of the instruction pointer by corrupting other important variables on the stack. ...

August 20, 2019 · 3 min

Smashing the Stack

What’s a buffer overflow, and they can be exploited. Cover some prerequistite knowledge of (Intel x86) assembly and how a Von-Neumann machine works is needed. Attacking the stack is only one category of control flow attack, there are many others including heap allocators, race conditions, root exploits, ELF, networking, viruses, etc. The end game is to gain control of the instruction pointer (IP), and as a result contol flow of the program. But to set the scene, need to understand how this is even possible in the first place. All general purpose binary computers are bound by the laws of the turing machine, and its implementation architecture, the Von-Neumann design. ...

August 4, 2019 · 12 min