Browse Source

Added '/software/', new blog post

main
Seth Stubbs 6 months ago
parent
commit
5b7ea1d843
  1. 10
      config.toml
  2. 2
      content/_index.md
  3. 22
      content/pages/foxnet.md
  4. 28
      content/pages/lua-bytecode-parser.md
  5. 37
      content/pages/site-rewrite/index.md
  6. BIN
      content/pages/site-rewrite/pull.png
  7. BIN
      content/software/cosmo/REPL.png
  8. 63
      content/software/cosmo/index.md
  9. 88
      content/software/lua-pytecode/index.md
  10. 4
      layouts/_default/list.html
  11. 2
      layouts/index.html
  12. 1
      layouts/section/pages.html
  13. 1
      layouts/section/places.html
  14. 15
      layouts/section/software.html
  15. 20
      static/css/style.css

10
config.toml

@ -28,15 +28,19 @@ title = 'OpenPunk'
name = "Blog"
url = "/pages/"
weight = 2
[[menu.main]]
name = "Software"
url = "/software/"
weight = 3
[[menu.main]]
name = "Places"
url = "/places/"
weight = 3
weight = 4
[[menu.main]]
name = "Tags"
url = "/tags/"
weight = 4
weight = 5
[[menu.main]]
name = "Gitea"
url = "https://git.openpunk.com"
weight = 5
weight = 6

2
content/_index.md

@ -12,7 +12,7 @@ socialList:
## Welcome!
Welcome to my tomb of software! I'm CPunch, I [write software](https://github.com/CPunch) (for you!) and [reverse engineer](/tags/reverse-engineering) things. I enjoy being curious, playing the piano and [exploring](/places).
Welcome to my tomb of software! I'm CPunch, I [write software](/software) (for you!) and [reverse engineer](/tags/reverse-engineering) things. I enjoy being curious, playing the piano and [exploring](/places).
Some all-encompassing highlights:
- [git.openpunk.com](https://git.openpunk.com) - my self-hosted Gitea instance, most of my projects are mirrored here.

22
content/pages/foxnet.md

@ -1,22 +0,0 @@
---
title: "FoxNet: "
date: 2021-09-02
author: CPunch
tags: ["C++", "networking"]
repo: "https://github.com/CPunch/FoxNet"
draft: true
---
Recently I've been trying to find a lightweight networking library for another project. I had looked at several other libraries (RakNet namely) and wasn't impressed. RakNet hasn't been maintained in over 7 years and also included lots of features that weren't needed and unnecessarily made the library FAT. Such as specific reserved packets for consoles like the XBOX and a built-in team balancer. It's pretty obvious that RakNet was geared towards gaming-related applications. After seeing the state of things, I thought it'd be easier to write a minimal networking library that had just the very basics of features and left the rest to be extensible by the user.
## Enter: FoxNet
After spending about a month of trying different styles and ways of making the protocol extensible by the user, I finally landed on something that seems to have the best of both worlds. Let's walk through an example.
First things first, lets clone the repo and setup our CMake environment
```bash
mkdir FoxNetExample && cd FoxNetExample && git clone https://github.com/CPunch/FoxNet.git
```
```CMakeList

28
content/pages/lua-bytecode-parser.md

@ -16,7 +16,6 @@ So recently I've been getting back into Lua, my first scripting language. I've a
- Protos (The functions)
- and even Debug information and line info
Now I know what you're thinking "Who cares! Why would I need to know this!" Well, being able to parse bytecode can enable us to do many things! To name a few:
- We could easily edit pre-compiled Lua Scripts embedded in a game.
- Read Lua Bytecode disassembly.
@ -126,31 +125,26 @@ In lua Bytecode, datatypes are stored as the following:
Now, let's write some code to read the datatypes before parsing the function chunk. We'll need to be able to get the binary of bytes for the instructions, to do that I'll be using python's 'bin' function which turns any number into base 2, aka BInary. However we'll still need it to be 32 bits long, so any missing bits I'll just add a tracing 0. That'll look like this:
```python
# at [p]osition to k
def get_bits(num, p, k):
# at [p]osition, with [s]ize of bits
def get_bits(num, p, s):
# convert number into binary first
binary = bin(num)
# remove first two characters
binary = binary[2:]
# fill in missing bits
for i in range(32 - len(binary)):
binary = '0' + binary
end = len(binary) - p + 1
start = len(binary) - k + 1
start = len(binary) - (p+s)
end = len(binary) - p
# extract k bit sub-string
kBitSubStr = binary[start : end]
kBitSubStr = binary[start : end]
# convert extracted sub-string into decimal again
return (int(kBitSubStr,2))
return (int(kBitSubStr,2))
```
This method lets us parse the binary of an instruction, and extract the specific bits we want, then convert them back into base 10. Pretty cool :)
@ -310,15 +304,15 @@ Here's the code equivalent:
instruction['OPCODE'] = opcode
instruction['TYPE'] = tp
instruction['A'] = get_bits(data, 7, 14)
instruction['A'] = get_bits(data, 6, 8)
if instruction['TYPE'] == "ABC":
instruction['B'] = get_bits(data, 24, 32)
instruction['C'] = get_bits(data, 15, 23)
instruction['B'] = get_bits(data, 23, 9)
instruction['C'] = get_bits(data, 14, 9)
elif instruction['TYPE'] == "ABx":
instruction['Bx'] = get_bits(data, 15, 32)
instruction['Bx'] = get_bits(data, 14, 18)
elif instruction['TYPE'] == "AsBx":
instruction['sBx'] = get_bits(data, 15, 32) - 131071
instruction['sBx'] = get_bits(data, 14, 18) - 131071
chunk['INSTRUCTIONS'][i] = instruction

37
content/pages/site-rewrite/index.md

@ -0,0 +1,37 @@
---
title: "Site Rewrite: From theme to lean"
date: 2021-12-02
author: CPunch
tags: ["hugo"]
draft: false
---
I recently rewrote my Hugo site. I'd be lying if I said this was a spur-of-the-moment thing. The thing that really kicked me into finally starting from scratch was [this recent PR](https://github.com/XXIIVV/webring/pull/643) where I submitted my site to XXIIVV's webring. It was closed rather quickly, with the site ultimately being rejected from the webring. Neauoire's reasoning was simply put, it read:
{{< img pull.png "900x q100 jpg" "It's nice to see a PR from you, but your website in its current state does not qualify for the webring. There are no projects documented on-site(besides the site-builder itself), also using such a standard Hugo template goes against the hand-crafted requirement of the webring. Sorry, feel free to open another one when the site is further down the line" >}}
This didn't come as a surprise, in fact after I had submitted my PR I was reviewing other closed PRs and saw that my site somewhat fit-in with the rejected sites. While I had made several modifications to the theme it was still fairly generic and 'template-y.' The theme in question was this [lovely theme by adityatelange](https://github.com/adityatelange/hugo-PaperMod). There was nothing inherently wrong with the theme, but it didn't quite fit my needs any more.
## The woes of using a theme
There were many, *many* features of that theme I didn't have a use for or just completely disagreed with. For example, the theme had integration for google analytics. My site has never and will never use such an analytics tool, instead relying on nginx log parsers like [GoAccess](https://goaccess.io). All of these unused features were just that, unused. This made my site full of features I didn't even know I had. My site should only have things that I explicitly enable and added.
Another thing about using a Hugo theme is it doesn't force you to *learn* Hugo. Immediately after starting the rewrite I had learned more in 20 minutes from reading the docs and writing my own layouts than I had in the year I spent modifying that theme. Being forced to really *know* your tooling is always a plus.
## The rewrite and some nice-to-haves
After deciding to get rid of my Hugo theme, I was forced to learn a lot more about Hugo than I had before. Writing my own [shortcodes](https://git.openpunk.com/OpenPunk/openpunk/src/branch/main/layouts/shortcodes), [section parsers](https://git.openpunk.com/OpenPunk/openpunk/src/branch/main/layouts/section), and of course the actual rendered HTML and CSS.
[One such shortcode](https://git.openpunk.com/OpenPunk/openpunk/src/branch/main/layouts/shortcodes/img.html) enables me to compress images into a more friendly format for your web browser automagically. This made sharing photos (and ultimately [/places/](/places)) a lot more intuitive and friendly for my servers bandwidth and yours! Having to compress my images manually is such a chore, but Hugo and this shortcode makes it as easy as adding
```md
{{</* img image.png "q70 jpg" "alt-text" */>}}
```
This even lets me selectively compress images, ignoring images I'd like to keep raw.
Another main point was the lack of JavaScript. Not to say JS is inherently bad, but this keeps compatibility with some more privacy-focused web browsers like the Tor Browser. Speaking of Tor, my Tor mirror link is no longer hidden behind some obscure blog post, instead its in plain view as a clickable link in the site's footer.
## Addressing the PR
My immediate decision was made to rewrite my site from scratch, ditching the Hugo theme. I had debated writing my own static site generator but I did this a couple weeks before finals so I scrapped that almost immediately since I wanted to get this done rather quickly. Another note of importance was the lack of on-site project documentation. So, I've created a new section called ['Software'](/software). This section is pretty lackluster right now, however eventually I plan to document *most* of my projects here. This also might force me to finish some projects so that they're in a nice presentable state.

BIN
content/pages/site-rewrite/pull.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
content/software/cosmo/REPL.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

63
content/software/cosmo/index.md

@ -0,0 +1,63 @@
---
title: "Cosmo"
author: CPunch
date: 2020-10-28
tags: ["C", "scripting-lang", "cosmo"]
repo: "https://git.openpunk.com/CPunch/Cosmo"
---
Cosmo is an eccentric scripting language, taking inspiration from [Lua](https://www.lua.org/), Cosmo is easily extensible through the use of 'Proto-objects,' which describe the behavior of Objects. For example the following is a simple Vector Proto which describes behavior for a Vector-like object.
```lua
proto Vector
function __init(self)
self.vector = []
self.x = 0
end
function __index(self, key)
return self.vector[key]
end
function push(self, val)
self.vector[self.x++] = val
end
function pop(self)
return self.vector[--self.x]
end
end
var vector = Vector()
for (var i = 0; i < 4; i++) do
vector:push(i)
end
for (var i = 0; i < 4; i++) do
print(vector:pop() .. " : " .. vector[i])
end
```
Output:
```
3 : 0
2 : 1
1 : 2
0 : 3
```
Usage:
```sh
$ cosmo script.cosmo
```
or a REPL can be opened by providing no arguments.
{{< img REPL.png "720x q100 jpg" "" >}}
Full documentation on language features can be found [here](https://git.openpunk.com/CPunch/Cosmo/src/branch/main/docs)

88
content/software/lua-pytecode/index.md

@ -0,0 +1,88 @@
---
title: "LuaPytecode"
author: CPunch
date: 2019-09-15
tags: ["lua", "python"]
repo: "https://github.com/CPunch/LuaPytecode"
---
A Lua5.1 cross-platform bytecode deserializer. This module pulls int and size_t sizes from the chunk header, meaning it should be able to deserialize lua bytecode dumps from most platforms, regardless of the host machine.
For details on the Lua5.1 bytecode format, I read [this PDF](https://archive.org/download/a-no-frills-intro-to-lua-5.1-vm-instructions/a-no-frills-intro-to-lua-5.1-vm-instructions_archive.torrent) as well as read the [lundump.c](https://www.lua.org/source/5.1/lundump.c.html) source file from the Lua5.1 source.
```lua
total = 1
function setTotal()
for i=1,10 do
total=total*i
end
end
setTotal()
print(total)
```
Compile our example script with
```sh
$ luac -o example.luac -- example.lua
```
Now disassemble it
```python
import luac
lc = luac.LuaUndump()
chunk = lc.loadFile("example.luac")
lc.print_dissassembly()
```
```
==== [[example.lua's constants]] ====
0: [STRING] total
1: [NUMBER] 1.0
2: [STRING] setTotal
3: [STRING] print
==== [[example.lua's dissassembly]] ====
[ 0] LOADK : 0 1
[ 1] SETGLOBAL : 0 0
[ 2] CLOSURE : 0 0
[ 3] SETGLOBAL : 0 2
[ 4] GETGLOBAL : 0 2
[ 5] CALL : 0 1 1
[ 6] GETGLOBAL : 0 3
[ 7] GETGLOBAL : 1 0
[ 8] CALL : 0 2 1
[ 9] RETURN : 0 1 0
==== [[example.lua's protos]] ====
==== [['s constants]] ====
0: [NUMBER] 1.0
1: [NUMBER] 10.0
2: [STRING] total
==== [['s dissassembly]] ====
[ 0] LOADK : 0 0
[ 1] LOADK : 1 1
[ 2] LOADK : 2 0
[ 3] FORPREP : 0 3
[ 4] GETGLOBAL : 4 2
[ 5] MUL : 4 4 3
[ 6] SETGLOBAL : 4 2
[ 7] FORLOOP : 0 -4
[ 8] RETURN : 0 1 0
==== [['s protos]] ====
```

4
layouts/_default/list.html

@ -4,9 +4,7 @@
<h1>{{ .Title }}</h1>
<ul>
{{ range .Pages.ByPublishDate.Reverse }}
<li>
<a href="{{ .RelPermalink }}">{{ .Title }}</a>
</li>
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
{{ end }}
</ul>
</div>

2
layouts/index.html

@ -9,6 +9,6 @@
{{- partial "social_list.html" $.Params.socialList -}}
</header>
</article>
<div class="post-content main">{{ .Content }}</div>
<div class="post-content">{{ .Content }}</div>
{{ end }}

1
layouts/section/pages.html

@ -1,6 +1,7 @@
{{ define "main" }}
<div class="main">
<h1>Blog</h1>
{{ range .Pages.ByPublishDate.Reverse }}
<p>
<a href="{{ .RelPermalink }}">{{- if not .Date.IsZero -}}

1
layouts/section/places.html

@ -1,6 +1,7 @@
{{ define "main" }}
<div class="main">
<h1>Places</h1>
{{ range .Pages.ByPublishDate.Reverse }}
<p>
<a href="{{ .RelPermalink }}">{{- if not .Date.IsZero -}}

15
layouts/section/software.html

@ -0,0 +1,15 @@
{{ define "main" }}
<div class="main">
<h1>Software</h1>
{{ range .Pages.ByPublishDate.Reverse }}
<p>
<a href="{{ .RelPermalink }}">{{- if not .Date.IsZero -}}
{{- (slice (.Date.Format (default "January 2, 2006" .Site.Params.DateFormat))) }}
{{- end -}}<br>- {{ .Title }}</a>
</p>
{{ end }}
<br>
</div>
{{ end }}

20
static/css/style.css

@ -31,8 +31,6 @@ body {
a {
color: var(--primary);
text-decoration: none;
padding-top: 2px;
padding-bottom: 2px;
padding-left: 5px;
padding-right: 5px;
}
@ -108,6 +106,11 @@ h1, h2, h3, h4, h5, h6 {
display: inline-flex;
}
.social-list a {
padding-top: 2px;
padding-bottom: 2px;
}
.social-list a:not(:last-of-type) {
margin-inline-end: 12px;
}
@ -149,8 +152,7 @@ h1, h2, h3, h4, h5, h6 {
}
.post-content pre {
margin: 32px;
border-radius: var(--radius);
border-radius: 5px;
background-color: var(--code-bg) !important;
}
@ -158,7 +160,7 @@ h1, h2, h3, h4, h5, h6 {
display: block;
margin: auto 0;
padding: 10px;
border-radius: 2px;
border-radius: 5px;
overflow-x: auto;
background-color: var(--code-bg) !important;
}
@ -168,7 +170,7 @@ h1, h2, h3, h4, h5, h6 {
}
.post-content a {
box-shadow: 0 1px 0 var(--secondary);
border-bottom: 1px solid var(--secondary);
}
.post-content img {
@ -201,16 +203,18 @@ h1, h2, h3, h4, h5, h6 {
content: "#";
color: var(--secondary);
position: relative;
left: -1.2rem;
left: -1rem;
font-weight: bold;
padding-left: 1rem;
}
.post-content h1::before {
content: "#";
color: var(--secondary);
position: relative;
left: -1.2rem;
left: -1rem;
font-weight: bold;
padding-left: 1rem;
}
.post-tags li {

Loading…
Cancel
Save