diff --git a/config.toml b/config.toml index 931a028..dd9f785 100644 --- a/config.toml +++ b/config.toml @@ -37,6 +37,7 @@ render_emoji = true bottom_footnotes = true github_alerts = true +# insert_anchor_links = "heading" [markdown.highlighting] light_theme = "github-light-high-contrast" diff --git a/content/blog/projects/generators.md b/content/blog/projects/generators.md index 07387a7..b1e6bdd 100644 --- a/content/blog/projects/generators.md +++ b/content/blog/projects/generators.md @@ -8,10 +8,70 @@ tags = ["java", "bytecode"] category = ["project"] +++ + +With the release of Java 24 came the official Class-File API giving a stable and (relatively) ergonomic interface for reading, modifying, and writing java classes/bytecode at runtime with no external dependencies. Seeing this I decided to play around with it and see what fun I could have. + + + +# Bytecode, Stack Machines, and Registers + +Java (and other JVM languages) are compiled to a set of [bytecode instructions](https://en.wikipedia.org/wiki/List_of_JVM_bytecode_instructions). +These instructions primarily operate on a stack (fifo) using 0-n operands from the top and pushing 0-1 values back onto the stack. + +An example would be the `iadd` instruction which pops two integers off the stack and pushes the sum of them. + +A more complex example would be something like `invokevirtual ` which calls a method on a class. +`methodref_index` is an index (in this case a 2 byte index) into the class files `constant_pool`[^1] + + +[^1]: https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-4.html#jvms-4.1 + +> [!NOTE] +> Highlights information that users should take into account, even when skimming. + +> [!TIP] +> Optional information to help a user be more successful. + +> [!IMPORTANT] +> Crucial information necessary for users to succeed. + +> [!WARNING] +> Critical content demanding immediate user attention due to potential risks. + +> [!CAUTION] +> Negative potential consequences of an action. + + +## Stack manipulation + +Sometimes it's + +## Registers + +# Stack Machine and Registers + +# Decompilation + +# Interlude, what's a stack map? + +# Tracking everything everywhere + +# Putting everything together + +# Injection + + Take a look at the [GitHub](https://github.com/ParkerTenBroeck/generators) + + + + + ```java,linenos -public static Future echo(@Cancellation("close") Socket socket) throws IOException { +public static Future echo( + @Cancellation("close") Socket socket +) throws IOException { try(socket){ var buffer = ByteBuffer.allocate(4096*2); while(true){ @@ -24,4 +84,17 @@ public static Future echo(@Cancellation("close") Socket socke } ``` -Java (and other languages which compile for the JVM) operate on a \ No newline at end of file + +```java,linenos +public static Gen primes() { + long number = 1; + Gen.yield(2L); + outer: while(true){ + number += 2; + for(long i=2; i <= Math.sqrt(number); i ++){ + if(number%i==0)continue outer; + } + Gen.yield(number); + } +} +``` \ No newline at end of file diff --git a/content/blog/projects/my_cpu.md b/content/blog/projects/my_cpu.md index 666e97c..bd0fc1a 100644 --- a/content/blog/projects/my_cpu.md +++ b/content/blog/projects/my_cpu.md @@ -60,37 +60,37 @@ Take a look at the [GitHub](https://github.com/ParkerTenBroeck/MyCPU_16bit) | No Operation | 00 | 30000 | 1044000 | 800000 | | | | | -| Bit | Function | -| --- | --- | -| 31 | NA | -| 30 | NA | -| 29 | NA | -| 28 | NA | -| 27 | NA | -| 26 | NA | -| 25 | NA | -| 24 | Instruction Register In | -| 23 | Micro Instruction Counter Reset | -| 22 | Conditional Instruction Type Select Bit 3 | -| 21 | Conditional Instruction Type Select Bit 2 | -| 20 | Conditional Instruction Type Select Bit 1 | -| 19 | Program Counter In | -| 18 | Program Counter Count | -| 17 | Program Counter Out | -| 16 | Update Memory Address Register | -| 15 | Memory In | -| 14 | Memory Out | -| 13 | Internal Screen Register In | -| 12 | Jump Register Out | -| 11 | Jump Register In | -| 10 | B Register Out | -| 9 | B Register In | -| 8 | A Register Out | -| 7 | A Register In | -| 6 | Y Register Out | -| 5 | Y Register In | -| 4 | X Register Out | -| 3 | X Register In | -| 2 | ALU mode select bit 3 | -| 1 | ALU mode select bit 2 | -| 0 | ALU mode select bit 1 | +| Bit | Function | +| -- | ------------------------------------------ | +| 31 | NA | +| 30 | NA | +| 29 | NA | +| 28 | NA | +| 27 | NA | +| 26 | NA | +| 25 | NA | +| 24 | Instruction Register In | +| 23 | Micro Instruction Counter Reset | +| 22 | Conditional Instruction Type Select Bit 3 | +| 21 | Conditional Instruction Type Select Bit 2 | +| 20 | Conditional Instruction Type Select Bit 1 | +| 19 | Program Counter In | +| 18 | Program Counter Count | +| 17 | Program Counter Out | +| 16 | Update Memory Address Register | +| 15 | Memory In | +| 14 | Memory Out | +| 13 | Internal Screen Register In | +| 12 | Jump Register Out | +| 11 | Jump Register In | +| 10 | B Register Out | +| 9 | B Register In | +| 8 | A Register Out | +| 7 | A Register In | +| 6 | Y Register Out | +| 5 | Y Register In | +| 4 | X Register Out | +| 3 | X Register In | +| 2 | ALU mode select bit 3 | +| 1 | ALU mode select bit 2 | +| 0 | ALU mode select bit 1 | diff --git a/sass/style.scss b/sass/style.scss index b9f85d3..853be11 100644 --- a/sass/style.scss +++ b/sass/style.scss @@ -172,3 +172,80 @@ th { } +.markdown-alert-note { + border-left: solid 3px var(--blue); + padding-left: 20px; + margin-left: 10px; + + ::before{ + content: "Note"; + display: block; + font-weight: bold; + color: var(--blue); + } +} + +.markdown-alert-note { + border-left: solid 3px var(--blue); + padding-left: 20px; + margin-left: 10px; + + ::before{ + content: "Note"; + display: block; + font-weight: bold; + color: var(--blue); + } +} + +.markdown-alert-tip { + border-left: solid 3px var(--green); + padding-left: 20px; + margin-left: 10px; + + ::before{ + content: "Tip"; + display: block; + font-weight: bold; + color: var(--green); + } +} + +.markdown-alert-important { + border-left: solid 3px var(--purple); + padding-left: 20px; + margin-left: 10px; + + ::before{ + content: "Important"; + display: block; + font-weight: bold; + color: var(--purple); + } +} + +.markdown-alert-warning { + border-left: solid 3px var(--yellow); + padding-left: 20px; + margin-left: 10px; + + ::before{ + content: "Warning"; + display: block; + font-weight: bold; + color: var(--yellow); + } +} + +.markdown-alert-caution { + border-left: solid 3px var(--red); + padding-left: 20px; + margin-left: 10px; + + ::before{ + content: "Caution"; + display: block; + font-weight: bold; + color: var(--red); + } +} \ No newline at end of file diff --git a/sass/theme.scss b/sass/theme.scss index 4345f40..d6a83ca 100644 --- a/sass/theme.scss +++ b/sass/theme.scss @@ -62,6 +62,12 @@ --primary: light-dark(#ffd979, #daa520); --text-highlight: color-mix(in srgb-linear, var(--primary) 50%, transparent); + + --blue: light-dark(#0969da, #1f6feb); + --green: light-dark(#1a7f37, #3fb950); + --purple: light-dark(#8250df, #ab7df8); + --yellow: light-dark(#9a6700, #d29922); + --red: light-dark(#d1242f, #f85149); } * {