Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ no-compiler-lsp = { path = "./crates/lsp" }

clap = { version = "4.5.16", features = ["derive"] }
tokio = { version = "1.40.0", features = ["full"] }
thiserror = "1.0.64"

# The profile that 'cargo dist' will build with
[profile.dist]
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# ⚙️ No-Compiler
Are you tired of having read all the Intel Developer manuals and not being able to use the information correctly?
Are you proficient in binary but cannot show your skills beyond Assembly?
Do you want to code with no restrictions directly in machine code?
No problem my friend, the no-compiler is here!
No compiler is a revolutionary and complex tool that **doesn't** compile bits from any text file to any file format you want (Since **all** digital information is made out of bits)
Are you tired of having read all the Intel Developer manuals and not being able to use the information correctly?
Are you proficient in binary but cannot show your skills beyond Assembly?
Do you want to code with no restrictions directly in machine code?
No problem my friend, the no-compiler is here!
No compiler is a revolutionary and complex tool that **doesn't** compile bits from any text file to any file format you want (Since **all** digital information is made out of bits)

## 💫 Features
- Compile binary code
Expand All @@ -23,14 +23,14 @@ Download from [releases](https://github.com/gg0074x/no-compiler/releases)

## 🗒️ Usage

Run the command `noc -h` once installed to receive help about the arguments and options.
You must specify an input file containing 0s or 1s characters to represent your binary code and then you can compile it by using `noc ./path/to/file`
You can decompile other files by using the decomp flag like this: `noc ./path/to/file --decomp`
Run the command `noc -h` once installed to receive help about the arguments and options.
You must specify an input file containing 0s or 1s characters to represent your binary code and then you can compile it by using `noc ./path/to/file`
You can decompile other files by using the decomp flag like this: `noc ./path/to/file --decomp`

You can use the option `-o` to provide a name for the output file and `-f` to specify the file extension you want the output file to have.
You can use the option `-o` to provide a name for the output file and `-f` to specify the file extension you want the output file to have.

Any characters that are not 0s or 1s will be recognized as comments.
Decompilation can take a while since its reading every single 0 or 1 from the file.
Any characters that are not 0s or 1s will be recognized as comments.
Decompilation can take a while since its reading every single 0 or 1 from the file.

```sh
Usage: noc [OPTIONS] <FILE PATH>...
Expand Down
7 changes: 2 additions & 5 deletions crates/lsp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::io::Read;

use tower_lsp::jsonrpc::Result;
use tower_lsp::lsp_types::*;
use tower_lsp::{LanguageServer, LspService, Server};
Expand All @@ -20,8 +18,7 @@ impl LanguageServer for Backend {
..Default::default()
}),
..ServerCapabilities::default()
},
..Default::default()
}
})
}

Expand Down Expand Up @@ -65,7 +62,7 @@ pub async fn run() {
tracing_subscriber::fmt().init();

let (stdin, stdout) = (tokio::io::stdin(), tokio::io::stdout());

let (service, socket) = LspService::new(|_| Backend);

Server::new(stdin, stdout, socket).serve(service).await;
}
162 changes: 162 additions & 0 deletions src/actions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
use std::{env::current_dir, fs::{read, read_to_string, File}, io::{Error as IoError, Write}, num::TryFromIntError, path::PathBuf};
use thiserror::Error;
use crate::structures::{bits::Bits, byte::{Byte, ByteCreationError}};

#[derive(Debug, Error)]
pub enum CompilerError {
#[error("Error geting current path: {0:#}")]
CurrentPath(IoError),

#[error("Path is not a file")]
StemRetrieval,

#[error("Error reading file: {0:#}")]
FileRead(IoError),

#[error("Error creating output file: {0:#}")]
OutputCreation(IoError),

#[error("Error writing output file: {0:#}")]
WriteOutput(IoError),

#[error("{0:#}")]
MakeBytes(#[from] MakeBytesError),

#[error("No paths specified")]
NoInput
}

pub fn compile(paths: &[PathBuf], format: &str) -> Result<(), CompilerError> {
if paths.is_empty() {
return Err(CompilerError::NoInput);
}

let curr_dir = current_dir()
.map_err(CompilerError::CurrentPath)?;

for path in paths {
let mut file = curr_dir
.clone();

let file_name = path
.file_stem()
.ok_or(CompilerError::StemRetrieval)?;

let code = read_to_string(path)
.map_err(CompilerError::FileRead)?;

file.push(file_name);
file.set_extension(format);

let mut file = File::create(file)
.map_err(CompilerError::OutputCreation)?;

file
.write(&make_bytes(&code)?)
.map_err(CompilerError::WriteOutput)?;
}

Ok(())
}

pub fn decompile(paths: &[PathBuf], format: &str) -> Result<(), CompilerError> {
if paths.is_empty() {
return Err(CompilerError::NoInput);
}

let curr_dir = current_dir()
.map_err(CompilerError::CurrentPath)?;

for path in paths {
let mut file = curr_dir
.clone();

let file_name = path
.file_stem()
.ok_or(CompilerError::StemRetrieval)?;

let code = read(path)
.map_err(CompilerError::FileRead)?;

file.push(file_name);
file.set_extension(format);

let mut file = File::create(file)
.map_err(CompilerError::OutputCreation)?;

let mut decompiled = Vec::new();

for b in code {
for c in format!("{b:08b}").chars() {
decompiled.push(c as u8);
}

decompiled.push(b' ');
}

file
.write(&decompiled)
.map_err(CompilerError::WriteOutput)?;
}

Ok(())
}

#[derive(Debug, Error)]
pub enum MakeBytesError {
#[error("{0:#}")]
ByteCreation(#[from] ByteCreationError),

#[error("{0:#}")]
Cast(#[from] TryFromIntError),

#[error("Error converting value to digit")]
Conversion
}

fn make_bytes(code: &str) -> Result<Vec<u8>, MakeBytesError> {
let chars: Vec<char> = code
.chars()
.collect();

let mut buff: [u8; 8] = [0; 8];
let mut buff_index = 0;

let mut bytes = Vec::new();

for c in 0..=code.len() {
if buff_index == 8 {
bytes.push(
Byte::from_bits(
&Bits::from_iter(buff)
)?
.value()
.to_owned()
);

buff_index = 0;

} else {
if chars.get(c).is_none() {
return Ok(bytes);
}

let chars = chars
.get(c)
.unwrap();

match chars {
'1' | '0' => {
buff[buff_index] = u8::try_from(
chars
.to_digit(10)
.ok_or(MakeBytesError::Conversion)?
)?;
}
_ => {}
}
}
}

Ok(bytes)
}
12 changes: 7 additions & 5 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ pub struct Args {

#[derive(Debug, Subcommand)]
pub enum Commands {
/// Subcommand to compile
/// Compile files into actual binary.
#[clap(alias = "build")]
Compile {
/// Input files to compile
/// Input files to compile.
#[arg(value_name = "FILE PATH", index = 1)]
files: Vec<PathBuf>,
},
/// Subcommand to decompile

/// Decompile files into readable binary.
#[clap(alias = "decomp")]
Decompile {
/// Input files to decompile
/// Input files to decompile.
#[arg(value_name = "FILE PATH", index = 1)]
files: Vec<PathBuf>,
},
/// Run LSP in stdio mode

/// Start a LSP within the program STDIO.
Lsp,
}
24 changes: 0 additions & 24 deletions src/bandb/bits.rs

This file was deleted.

33 changes: 0 additions & 33 deletions src/bandb/byte.rs

This file was deleted.

Loading
Loading