mirror of
https://github.com/WerWolv/ImHex-Patterns.git
synced 2026-03-27 23:37:04 -05:00
includes/std: Moved stdlib to std folder, added all builtin functions
This commit is contained in:
@@ -36,7 +36,7 @@ Hex patterns, include patterns and magic files for the use with the ImHex Hex Ed
|
||||
|
||||
| Name | Path | Description |
|
||||
|------|------|-------------|
|
||||
| libstd | `includes/libstd/*` | Pattern Language Standard Libaray |
|
||||
| libstd | `includes/std/*` | Pattern Language Standard Libaray |
|
||||
| cstdint | `includes/cstdint.pat` | C integer types |
|
||||
|
||||
### Yara rules
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
using uint8_t = u8;
|
||||
using uint16_t = u16;
|
||||
using uint32_t = u32;
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace std::file {
|
||||
|
||||
using Handle = s32;
|
||||
|
||||
enum Mode : u8 {
|
||||
Read = 1,
|
||||
Write = 2,
|
||||
Create = 3
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace std::mem {
|
||||
|
||||
fn eof() {
|
||||
return $ >= std::mem::size();
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
namespace std::bit {
|
||||
|
||||
fn popcount(u128 x) {
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
namespace std {
|
||||
|
||||
using uint8_t = u8;
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
namespace std::ctype {
|
||||
|
||||
fn isdigit(char c) {
|
||||
49
includes/std/file.pat
Normal file
49
includes/std/file.pat
Normal file
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
namespace std::file {
|
||||
|
||||
using Handle = s32;
|
||||
|
||||
enum Mode : u8 {
|
||||
Read = 1,
|
||||
Write = 2,
|
||||
Create = 3
|
||||
};
|
||||
|
||||
|
||||
fn open(str path, Mode mode) {
|
||||
return builtin::std::file::open(path, mode);
|
||||
};
|
||||
|
||||
fn close(Handle handle) {
|
||||
builtin::std::file::close(handle);
|
||||
};
|
||||
|
||||
|
||||
fn read(Handle handle, u64 size) {
|
||||
return builtin::std::file::read(handle, size);
|
||||
};
|
||||
|
||||
fn write(Handle handle, str data) {
|
||||
return builtin::std::file::write(handle, data);
|
||||
};
|
||||
|
||||
|
||||
fn size(Handle handle) {
|
||||
return builtin::std::file::size(handle);
|
||||
};
|
||||
|
||||
fn resize(Handle handle, u64 size) {
|
||||
builtin::std::file::resize(handle, size);
|
||||
};
|
||||
|
||||
fn flush(Handle handle) {
|
||||
builtin::std::file::remove(handle);
|
||||
};
|
||||
|
||||
|
||||
fn remove(Handle handle) {
|
||||
builtin::std::file::remove(handle);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
namespace std::fxpt {
|
||||
|
||||
using fixed = s128;
|
||||
7
includes/std/http.pat
Normal file
7
includes/std/http.pat
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace std::http {
|
||||
|
||||
fn get(str url) {
|
||||
return builtin::std::http::get(url);
|
||||
};
|
||||
|
||||
}
|
||||
22
includes/std/io.pat
Normal file
22
includes/std/io.pat
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
namespace std {
|
||||
|
||||
fn print(str fmt, auto ... args) {
|
||||
builtin::std::print(fmt, args);
|
||||
};
|
||||
|
||||
fn format(str fmt, auto ... args) {
|
||||
return builtin::std::format(fmt, args);
|
||||
};
|
||||
|
||||
|
||||
fn error(str message) {
|
||||
builtin::std::error(message);
|
||||
};
|
||||
|
||||
fn warning(str message) {
|
||||
builtin::std::warning(message);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
namespace std::limits {
|
||||
|
||||
fn u8_min() {
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
namespace std::math {
|
||||
|
||||
fn min(auto a, auto b) {
|
||||
41
includes/std/mem.pat
Normal file
41
includes/std/mem.pat
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
namespace std::mem {
|
||||
|
||||
fn eof() {
|
||||
return $ >= std::mem::size();
|
||||
};
|
||||
|
||||
fn align_to(u128 alignment, u128 value) {
|
||||
u128 remainder = value % alignment;
|
||||
|
||||
return remainder != 0 ? value + (alignment - remainder) : value;
|
||||
};
|
||||
|
||||
|
||||
fn base_address() {
|
||||
return builtin::std::mem::base_address();
|
||||
};
|
||||
|
||||
fn size() {
|
||||
return builtin::std::mem::size();
|
||||
};
|
||||
|
||||
fn find_sequence(u128 occurrence_index, auto ... bytes) {
|
||||
return builtin::std::mem::find_sequence(occurrence_index, bytes);
|
||||
};
|
||||
|
||||
|
||||
fn read_unsigned(u128 address, u8 size) {
|
||||
return builtin::std::mem::read_unsigned(address, size);
|
||||
};
|
||||
|
||||
fn read_signed(u128 address, u8 size) {
|
||||
return builtin::std::mem::read_signed(address, size);
|
||||
};
|
||||
|
||||
fn read_string(u128 address, u8 size) {
|
||||
return builtin::std::mem::read_string(address, size);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
namespace std::ptr {
|
||||
|
||||
fn relative_to_pointer(u128 offset) {
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
namespace std {
|
||||
|
||||
using i8 = s8;
|
||||
@@ -1,5 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
namespace std::string {
|
||||
|
||||
fn length(str string) {
|
||||
return builtin::std::string::length(string);
|
||||
};
|
||||
|
||||
fn at(str string, u32 index) {
|
||||
return builtin::std::string::at(string, index);
|
||||
};
|
||||
|
||||
fn substr(str string, u32 pos, u32 count) {
|
||||
return builtin::std::string::substr(string, pos, count);
|
||||
};
|
||||
|
||||
|
||||
fn parse_int(str string, u8 base) {
|
||||
return builtin::std::string::parse_int(string, base);
|
||||
};
|
||||
|
||||
fn parse_float(str string) {
|
||||
return builtin::std::string::parse_float(string);
|
||||
};
|
||||
|
||||
|
||||
fn to_string(auto x) {
|
||||
return std::format("{}", x);
|
||||
};
|
||||
28
includes/std/sys.pat
Normal file
28
includes/std/sys.pat
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
|
||||
namespace std {
|
||||
|
||||
fn assert(bool condition, str message) {
|
||||
if (!condition) {
|
||||
std::error(std::format("assertion failed '{0}'", message));
|
||||
}
|
||||
};
|
||||
|
||||
fn assert_warn(bool condition, str message) {
|
||||
if (!condition) {
|
||||
std::warning(std::format("assertion failed '{0}'", message));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
fn env(str name) {
|
||||
return builtin::std::env(name);
|
||||
};
|
||||
|
||||
fn sizeof_pack(auto ... pack) {
|
||||
return builtin::std::sizeof_pack(pack);
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user