code stringlengths 40 729k | docstring stringlengths 22 46.3k | func_name stringlengths 1 97 | language stringclasses 1
value | repo stringlengths 6 48 | path stringlengths 8 176 | url stringlengths 47 228 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
pub fn validate_author(name: &str) -> anyhow::Result<()> {
let mut s = Scanner::new(name);
s.eat_until(|c| c == '<');
if s.eat_if('<') {
let contact = s.eat_until('>');
if let Some(handle) = contact.strip_prefix('@') {
validate_github_handle(handle).context("GitHub handle is inv... | Validates the format of an author field. It can contain a name and, in angle
brackets, one of a URL, email or GitHub handle. | validate_author | rust | typst/packages | bundler/src/author.rs | https://github.com/typst/packages/blob/master/bundler/src/author.rs | Apache-2.0 |
fn is_legal_in_url(c: char) -> bool {
c.is_ascii_alphanumeric() || "-_.~:/?#[]@!$&'()*+,;=".contains(c)
} | Whether a character is legal in a URL. | is_legal_in_url | rust | typst/packages | bundler/src/author.rs | https://github.com/typst/packages/blob/master/bundler/src/author.rs | Apache-2.0 |
pub fn validate_category(category: &str) -> anyhow::Result<()> {
match category {
// Functional categories.
"components" => {}
"visualization" => {}
"model" => {}
"layout" => {}
"text" => {}
"languages" => {}
"scripting" => {}
"integration" => ... | Validate that this is a Typst universe category. | validate_category | rust | typst/packages | bundler/src/categories.rs | https://github.com/typst/packages/blob/master/bundler/src/categories.rs | Apache-2.0 |
pub fn validate_discipline(discipline: &str) -> anyhow::Result<()> {
match discipline {
"agriculture" => {}
"anthropology" => {}
"archaeology" => {}
"architecture" => {}
"biology" => {}
"business" => {}
"chemistry" => {}
"communication" => {}
"... | Validate that this is a Typst universe discipline. | validate_discipline | rust | typst/packages | bundler/src/disciplines.rs | https://github.com/typst/packages/blob/master/bundler/src/disciplines.rs | Apache-2.0 |
fn parse_manifest(path: &Path, namespace: &str) -> anyhow::Result<PackageManifest> {
let src = fs::read_to_string(path.join("typst.toml"))?;
let manifest: PackageManifest = toml::from_str(&src)?;
let expected = format!(
"packages/{namespace}/{}/{}",
manifest.package.name, manifest.package.v... | Read and validate the package's manifest. | parse_manifest | rust | typst/packages | bundler/src/main.rs | https://github.com/typst/packages/blob/master/bundler/src/main.rs | Apache-2.0 |
fn read_readme(dir_path: &Path) -> anyhow::Result<String> {
fs::read_to_string(dir_path.join("README.md")).context("failed to read README.md")
} | Return the README file as a string. | read_readme | rust | typst/packages | bundler/src/main.rs | https://github.com/typst/packages/blob/master/bundler/src/main.rs | Apache-2.0 |
fn validate_archive(buf: &[u8]) -> anyhow::Result<()> {
let decompressed = flate2::read::GzDecoder::new(io::Cursor::new(&buf));
let mut tar = tar::Archive::new(decompressed);
for entry in tar.entries()? {
let _ = entry?;
}
Ok(())
} | Ensures that the archive can be decompressed and read. | validate_archive | rust | typst/packages | bundler/src/main.rs | https://github.com/typst/packages/blob/master/bundler/src/main.rs | Apache-2.0 |
fn write_archive(info: &PackageInfo, buf: &[u8], namespace_dir: &Path) -> anyhow::Result<()> {
let path = namespace_dir.join(format!("{}-{}.tar.gz", info.name, info.version));
fs::write(path, buf)?;
Ok(())
} | Write a compressed archive to the output directory. | write_archive | rust | typst/packages | bundler/src/main.rs | https://github.com/typst/packages/blob/master/bundler/src/main.rs | Apache-2.0 |
fn process_thumbnail(
path: &Path,
manifest: &PackageManifest,
template: &TemplateInfo,
namespace_dir: &Path,
) -> anyhow::Result<()> {
let original_path = path.join(template.thumbnail.as_str());
let thumb_dir = namespace_dir.join(THUMBS_DIR);
let filename = format!("{}-{}", manifest.package... | Process the thumbnail image for a package and write it to the `dist`
directory in large and small version. | process_thumbnail | rust | typst/packages | bundler/src/main.rs | https://github.com/typst/packages/blob/master/bundler/src/main.rs | Apache-2.0 |
fn validate_typst_file(path: &Path, name: &str) -> anyhow::Result<()> {
if !path.exists() {
bail!("{name} is missing");
}
if path.extension().is_none_or(|ext| ext != "typ") {
bail!("{name} must have a .typ extension");
}
fs::read_to_string(path).context("failed to read {name} file"... | Check that a Typst file exists, its name ends in `.typ`, and that it is valid
UTF-8. | validate_typst_file | rust | typst/packages | bundler/src/main.rs | https://github.com/typst/packages/blob/master/bundler/src/main.rs | Apache-2.0 |
fn is_ident(string: &str) -> bool {
let mut chars = string.chars();
chars
.next()
.is_some_and(|c| is_id_start(c) && chars.all(is_id_continue))
} | Whether a string is a valid Typst identifier. | is_ident | rust | typst/packages | bundler/src/main.rs | https://github.com/typst/packages/blob/master/bundler/src/main.rs | Apache-2.0 |
fn is_id_start(c: char) -> bool {
is_xid_start(c) || c == '_'
} | Whether a character can start an identifier. | is_id_start | rust | typst/packages | bundler/src/main.rs | https://github.com/typst/packages/blob/master/bundler/src/main.rs | Apache-2.0 |
fn is_id_continue(c: char) -> bool {
is_xid_continue(c) || c == '_' || c == '-'
} | Whether a character can continue an identifier. | is_id_continue | rust | typst/packages | bundler/src/main.rs | https://github.com/typst/packages/blob/master/bundler/src/main.rs | Apache-2.0 |
pub fn new(r2api: &mut R2Api, btor: Solver, blank: bool) -> Memory {
let segments = r2api.get_segments().unwrap();
let mut segs = Vec::with_capacity(64);
for seg in segments {
segs.push(MemorySegment {
name: seg.name,
addr: seg.vaddr,
... | Create a new Memory struct to hold memory values for symbolic execution | new | rust | aemmitt-ns/radius2 | radius/src/memory.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/memory.rs | MIT |
pub fn alloc(&mut self, length: &Value) -> u64 {
let len = length.as_u64().unwrap();
// aligning makes some runs take much longer wtaf
let len = len + if len % ALIGN != 0 { ALIGN - len % ALIGN } else { 0 };
let addr = self.heap.alloc(len);
//let canary = self.heap_canary.clone()... | Allocate memory `length` bytes long. Returns the address of the allocation. | alloc | rust | aemmitt-ns/radius2 | radius/src/memory.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/memory.rs | MIT |
pub fn read_value(&mut self, addr: u64, length: usize) -> Value {
if length <= 32 {
let mut data: [Value; 32] = Default::default();
self.read(addr, length, &mut data[..length]);
self.pack(&data[..length])
} else {
let mut data = vec![Value::Concrete(0, 0);... | read a Value of `length` bytes from memory at `addr` | read_value | rust | aemmitt-ns/radius2 | radius/src/memory.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/memory.rs | MIT |
pub fn write_value(&mut self, addr: u64, value: &Value, length: usize) {
if length <= 32 {
let mut data: [Value; 32] = Default::default();
self.unpack(value, length, &mut data[..length]);
self.write(addr, &mut data[..length])
} else {
let mut data = vec![V... | write a Value of `length` bytes to memory at `addr` | write_value | rust | aemmitt-ns/radius2 | radius/src/memory.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/memory.rs | MIT |
pub fn read(&mut self, addr: u64, length: usize, data: &mut [Value]) {
if length == 0 || data.len() == 0 {
return;
}
let make_sym = self.blank && !self.check_permission(addr, length as u64, 'i');
let size = READ_CACHE as u64;
let mask = -1i64 as u64 ^ (size - 1);
... | read `length` bytes from memory at `addr` into `data` | read | rust | aemmitt-ns/radius2 | radius/src/memory.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/memory.rs | MIT |
pub fn write(&mut self, addr: u64, data: &mut [Value]) {
let length = data.len();
let size = READ_CACHE as u64;
let mask = -1i64 as u64 ^ (size - 1);
let not_mask = size - 1;
let chunks = (((addr & not_mask) + length as u64) / size) + 1;
let mut index = 0;
for co... | write `length` bytes to memory at `addr` from `data` | write | rust | aemmitt-ns/radius2 | radius/src/memory.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/memory.rs | MIT |
pub fn pack(&self, data: &[Value]) -> Value {
let new_data = data;
let length = new_data.len();
let mut taint = 0;
if self.endian == Endian::Big {
let mut new_data = data.to_owned();
new_data.reverse();
}
// if length > 64 bits use sym to cheat
... | Pack the bytes in `data` into a Value according to the endianness of the target | pack | rust | aemmitt-ns/radius2 | radius/src/memory.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/memory.rs | MIT |
pub fn unpack(&self, value: &Value, length: usize, data: &mut [Value]) {
//let mut data: Vec<Value> = Vec::with_capacity(length);
if length == 0 {
return;
}
match value {
Value::Concrete(val, t) => {
for count in 0..length {
//... | Unpack the Value into `length` bytes and store them in the `data` ref | unpack | rust | aemmitt-ns/radius2 | radius/src/memory.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/memory.rs | MIT |
pub fn print_instr(&self, state: &mut State, instr: &Instruction) {
if let Some(sim) = self.sims.get(&instr.offset) {
println!(
"\n0x{:08x} ( {} {} )\n",
instr.offset,
"simulated", sim.symbol.blue()
);
} else if !self.color {
... | print instruction if debug output is enabled | print_instr | rust | aemmitt-ns/radius2 | radius/src/processor.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/processor.rs | MIT |
pub fn optimize(&mut self, state: &mut State, prev_pc: u64, curr_instr: &InstructionEntry) {
let prev_instr = &self.instructions[&prev_pc];
if !prev_instr
.tokens
.contains(&Word::Operator(Operations::WeakEqual))
|| !curr_instr
.tokens
... | removes words that weak set flag values that are never read, and words that are NOPs
really need to refactor this mess but every time i try it gets slower | optimize | rust | aemmitt-ns/radius2 | radius/src/processor.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/processor.rs | MIT |
pub fn step(&mut self, state: &mut State) -> Vec<State> {
self.steps += 1;
state.visit();
let pc_allocs = 32;
let pc_value = state.registers.get_pc();
if let Some(pc_val) = pc_value.as_u64() {
self.execute_instruction(state, pc_val);
} else {
pan... | Take single step with the state provided | step | rust | aemmitt-ns/radius2 | radius/src/processor.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/processor.rs | MIT |
pub fn run(&mut self, state: State, mode: RunMode) -> Vec<State> {
// use binary heap as priority queue to prioritize states
// that have the lowest number of visits for the current PC
let mut states = BinaryHeap::new();
let mut results = vec![];
states.push(Rc::new(state));
... | run the state until completion based on mode | run | rust | aemmitt-ns/radius2 | radius/src/processor.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/processor.rs | MIT |
pub fn new<T: AsRef<str>>(filename: T) -> Self {
// no radius options and no r2 errors by default
Radius::new_with_options(Some(filename), &[])
} | Create a new Radius instance for the provided binary
## Arguments
* `filename` - path to the target binary
## Example
```
use radius2::radius::Radius;
let mut radius = Radius::new("/bin/sh");
``` | new | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn new_with_options<T: AsRef<str>>(filename: Option<T>, options: &[RadiusOption]) -> Self {
let mut argv = vec!["-2"];
let mut eval_max = 256;
let mut paths = vec![];
for o in options {
if let RadiusOption::R2Argument(arg) = o {
argv.push(*arg);
... | Create a new Radius instance for the provided binary with a vec of `RadiusOption`
## Arguments
* `filename` - path to the target binary
* `options` - array of options to configure radius2
## Example
```
use radius2::radius::{Radius, RadiusOption};
let options = [RadiusOption::Optimize(false), RadiusOption::Sims(false... | new_with_options | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn call_state(&mut self, addr: u64) -> State {
self.r2api.seek(addr);
self.r2api.init_vm();
let mut state = self.init_state();
state.memory.add_stack();
state.memory.add_heap();
state.memory.add_std_streams();
state
} | Initialized state at the provided function address with an initialized stack
(if applicable)
## Arguments
* `addr` - the address of the function
## Example
```
use radius2::radius::Radius;
let mut radius = Radius::new("/bin/sh");
let mut state = radius.call_state(0x004006fd);
``` | call_state | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn callsym_state<T: AsRef<str>>(&mut self, sym: T) -> State {
let addr = self.get_address(sym).unwrap_or_default();
self.call_state(addr)
} | Initialized state at the provided function name with an initialized stack
equivalent to `call_state(get_address(sym))`
## Arguments
* `sym` - the name of the function
## Example
```
use radius2::Radius;
let mut radius = Radius::new("/bin/sh");
let mut state = radius.callsym_state("printf");
``` | callsym_state | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn debug_state(&mut self, addr: u64, args: &[String]) -> State {
// set cache to false to set breakpoint
self.r2api.set_option("io.cache", "false").unwrap();
self.r2api.init_debug(addr, args);
self.init_state()
} | Initialize state from a debugger breakpoint
the program will block until bp is hit | debug_state | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn frida_state(&mut self, addr: u64) -> State {
self.r2api.seek(addr);
let mut state = self.init_state();
self.processor.fetch_instruction(&mut state, addr); // cache real instrs
let context = self.r2api.init_frida(addr).unwrap();
for reg in context.keys() {
if s... | Initialize state from a frida hook
the program will block until the hook is hit | frida_state | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn entry_state(&mut self) -> State {
// get the entrypoint
let entrypoints = self.r2api.get_entrypoints().unwrap_or_default();
if !entrypoints.is_empty() {
self.r2api.seek(entrypoints[0].vaddr);
}
self.r2api.init_vm();
let mut state = self.init_state();
... | Initialized state at the program entry point (the first if multiple).
## Example
```
use radius2::Radius;
let mut radius = Radius::new("/bin/sh");
let mut state = radius.entry_state();
``` | entry_state | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn set_argv_env(&mut self, state: &mut State, args: &[Value], env: &[Value]) {
// we write args to both regs and stack
// i think this is ok
let sp = state.registers.get_with_alias("SP");
let ptrlen = (state.memory.bits / 8) as usize;
let argc = Value::Concrete(args.len() as ... | Set argv and env with arrays of values | set_argv_env | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn blank_state(&mut self) -> State {
State::new(
&mut self.r2api,
self.eval_max,
self.debug,
true,
self.check,
self.strict,
)
} | A "blank" state with uninitialized values set to be symbolic | blank_state | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn blank_call_state(&mut self, addr: u64) -> State {
self.r2api.seek(addr);
self.r2api.init_vm();
let mut state = self.blank_state();
let sp = self.r2api.get_register_value("SP").unwrap();
state
.registers
.set_with_alias("PC", Value::Concrete(addr, 0)... | A blank state except for PC and SP | blank_call_state | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn hook(&mut self, addr: u64, hook_callback: HookMethod) {
self.processor
.hooks
.entry(addr)
.or_insert(vec![])
.push(hook_callback);
} | Hook an address with a callback that is passed the `State`.
The return value of the callback specifies whether the hooked instruction should be executed or skipped
## Arguments
* `addr` - the address to hook
* `hook_callback` - the function to call once the address is reached
## Example
```
use radius2::{Radius, Sta... | hook | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn esil_hook(&mut self, addr: u64, esil: &str) {
self.processor
.esil_hooks
.entry(addr)
.or_insert(vec![])
.push(esil.to_owned());
} | Hook an address with an esil expression. The instruction
at the address is skipped if the last value on the stack is nonzero
## Arguments
* `addr` - the address to hook
* `esil` - the ESIL expression to evaluate | esil_hook | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn hook_symbol(&mut self, sym: &str, hook_callback: HookMethod) {
let addr = self.get_address(sym).unwrap();
self.hook(addr, hook_callback);
} | Hook a symbol with a callback that is passed each state that reaches it | hook_symbol | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn trap(&mut self, trap_num: u64, sim: SimMethod) {
self.processor.traps.insert(trap_num, sim);
} | Register a trap to call the provided `SimMethod` | trap | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn simulate(&mut self, addr: u64, sim: Sim) {
self.processor.sims.insert(addr, sim);
} | Register a `SimMethod` for the provided function address
## Arguments
* `addr` - address of the function to simulate (usually the PLT address)
* `sim` - Sim struct containing the function name, implementation, and arg count
## Example
```
use radius2::{Radius, State, Sim, Value, vc};
let mut radius = Radius::new("/bi... | simulate | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn assign_sim(&mut self, addr: u64, name: &str) {
// TODO: get_sims should return a HashMap idk why it doesnt
get_sims()
.into_iter()
.find(|s| s.symbol == name)
.map(|s| self.simulate(addr, s));
} | assign an existing sim to an address (for static binaries) | assign_sim | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn avoid(&mut self, addrs: &[u64]) {
for addr in addrs {
self.processor.avoidpoints.insert(*addr);
}
} | Add addresses that will be avoided during execution. Any
`State` that reaches these addresses will be marked inactive
## Arguments
* `addrs` - slice of addresses to avoid during execution | avoid | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn get_steps(&self) -> u64 {
self.processor.steps
+ self
.processors
.lock()
.unwrap()
.iter()
.map(|p| p.steps)
.sum::<u64>()
} | Get total number of steps from all processors | get_steps | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn call_function(&mut self, sym: &str, state: State, args: Vec<Value>) -> Option<State> {
let addr = self.r2api.get_address(sym).unwrap_or_default();
self.call_address(addr, state, args)
} | Execute function and return the resulting state | call_function | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn call_address(&mut self, addr: u64, mut state: State, args: Vec<Value>) -> Option<State> {
state.set_args(args);
state.registers.set_pc(vc(addr));
let mut states = self.run_all(state);
let count = states.len();
if !states.is_empty() {
let mut end = states.remo... | Execute function at address and return the resulting state
if there are multiple result states, merge them all | call_address | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn run_until(&mut self, state: State, target: u64, avoid: &[u64]) -> Option<State> {
self.breakpoint(target);
self.avoid(avoid);
self.processor.run(state, RunMode::Single).pop()
} | Simple way to execute until a given target address while avoiding a vec of other addrs
## Arguments
* `state` - the program state to begin running from
* `target` - the goal address where execution should stop and return the result state
* `avoid` - slice of addresses to avoid, states that reach them will be marked in... | run_until | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn run_all(&mut self, state: State) -> Vec<State> {
self.processor.run(state, RunMode::Multiple)
} | Execute until every state has reached an end and return active states | run_all | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn run(&mut self, state: State, _threads: usize) -> Option<State> {
// we are gonna scrap threads for now cuz theyre currently useless.
self.processor.run(state, RunMode::Single).pop()
} | Main run method, start or continue a symbolic execution
## Arguments
* `state` - the program state to begin executing from
* `threads` - number of threads (currently unused)
## Example
```
use radius2::Radius;
let mut radius = Radius::new("/bin/ls");
let state = radius.entry_state();
let new_state = radius.run(state,... | run | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn write_string(&mut self, address: u64, string: &str) {
self.r2api
.write(address, string.chars().map(|c| c as u8).collect::<Vec<_>>())
} | Write string to binary / real memory | write_string | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn set_option(&mut self, key: &str, value: &str) {
self.r2api.set_option(key, value).unwrap();
} | Set radare2 option, equivalent to "e `key`=`value`" | set_option | rust | aemmitt-ns/radius2 | radius/src/radius.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/radius.rs | MIT |
pub fn new(
r2api: &mut R2Api,
eval_max: usize,
debug: bool,
blank: bool,
check: bool,
strict: bool,
) -> Self {
let esil_state = EsilState {
mode: ExecMode::Uncon,
prev_pc: Value::Concrete(0, 0),
previous: Value::Concrete(0... | Create a new state, should generally not be called directly | new | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn duplicate(&mut self) -> Self {
let solver = self.solver.duplicate();
let mut registers = self.registers.clone();
registers.solver = solver.clone();
registers.values = registers
.values
.iter()
.map(|r| solver.translate_value(r))
.co... | duplicate state is different from clone as it creates
a duplicate solver instead of another reference to the old one | duplicate | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn memory_alloc(&mut self, length: &Value) -> Value {
if DO_EVENT_HOOKS && self.has_event_hooks {
let event = if length.is_symbolic() {
Event::SymbolicAlloc(EventTrigger::Before)
} else {
Event::Alloc(EventTrigger::Before)
};
se... | Allocate a block of memory `length` bytes in size | memory_alloc | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn memory_free(&mut self, addr: &Value) -> Value {
if DO_EVENT_HOOKS && self.has_event_hooks {
let event = if addr.is_symbolic() {
Event::SymbolicFree(EventTrigger::Before)
} else {
Event::Free(EventTrigger::Before)
};
self.do_h... | Free a block of memory at `addr` | memory_free | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn memory_search(
&mut self,
addr: &Value,
needle: &Value,
length: &Value,
reverse: bool,
) -> Value {
if DO_EVENT_HOOKS && self.has_event_hooks {
let event = if addr.is_symbolic() || length.is_symbolic() {
Event::SymbolicSearch(EventTr... | Search for `needle` at the address `addr` for a maximum of `length` bytes
Returns a `Value` containing the **address** of the needle, not index | memory_search | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn memory_compare(&mut self, dst: &Value, src: &Value, length: &Value) -> Value {
if DO_EVENT_HOOKS && self.has_event_hooks {
let event = if dst.is_symbolic() || src.is_symbolic() || length.is_symbolic() {
Event::SymbolicCompare(EventTrigger::Before)
} else {
... | Compare memory at `dst` and `src` address up to `length` bytes.
This is akin to memcmp but will handle symbolic addrs and length | memory_compare | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn memory_strlen(&mut self, addr: &Value, length: &Value) -> Value {
if DO_EVENT_HOOKS && self.has_event_hooks {
let event = if addr.is_symbolic() || length.is_symbolic() {
Event::SymbolicStrlen(EventTrigger::Before)
} else {
Event::StringLength(EventT... | Get the length of the null terminated string at `addr` | memory_strlen | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn memory_move(&mut self, dst: &Value, src: &Value, length: &Value) {
if DO_EVENT_HOOKS && self.has_event_hooks {
let event = if dst.is_symbolic() || src.is_symbolic() || length.is_symbolic() {
Event::SymbolicMove(EventTrigger::Before)
} else {
Event::... | Move `length` bytes from `src` to `dst` | memory_move | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn memory_read_string(&mut self, address: u64, length: usize) -> String {
self.memory.read_string(address, length, &mut self.solver)
} | Read a string from `address` up to `length` bytes long | memory_read_string | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn unpack(&self, data: &Value, length: usize) -> Vec<Value> {
let mut values = vec![Value::Concrete(0, 0); length];
self.memory.unpack(data, length, &mut values);
values
} | unpack `Value` into vector of bytes | unpack | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn apply(&mut self) {
let mut inds = Vec::with_capacity(256);
for reg in &self.registers.indexes {
if !inds.contains(®.value_index) {
inds.push(reg.value_index);
let rval = self.registers.values[reg.value_index].to_owned();
let r = self.... | Apply this state to the radare2 instance. This writes all the values
in the states memory back to the memory in r2 as well as the register
values, evaluating any symbolic expressions. | apply | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn constrain_with_state(&mut self, state: &Self) {
self.solver = state.solver.clone();
} | Use the constraints from the provided state. This is
useful for constraining the data in some initial
state with the assertions of some desired final state | constrain_with_state | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn bv(&self, s: &str, n: u32) -> BitVec {
self.solver.bv(s, n)
} | Create a bitvector from this states solver | bv | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn bvv(&self, v: u64, n: u32) -> BitVec {
self.solver.bvv(v, n)
} | Create a bitvector value from this states solver | bvv | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn concrete_value(&self, v: u64, n: u32) -> Value {
let mask = if n < 64 { (1 << n) - 1 } else { -1i64 as u64 };
Value::Concrete(v & mask, 0)
} | Create a `Value::Concrete` from a value `v` and bit width `n` | concrete_value | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn symbolic_value(&self, s: &str, n: u32) -> Value {
Value::Symbolic(self.bv(s, n), 0)
} | Create a `Value::Symbolic` from a name `s` and bit width `n` | symbolic_value | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn tainted_concrete_value(&mut self, t: &str, v: u64, n: u32) -> Value {
let mask = if n < 64 { (1 << n) - 1 } else { -1i64 as u64 };
let taint = self.get_tainted_identifier(t);
Value::Concrete(v & mask, taint)
} | Create a tainted `Value::Concrete` from a value `v` and bit width `n` | tainted_concrete_value | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn tainted_symbolic_value(&mut self, t: &str, s: &str, n: u32) -> Value {
let taint = self.get_tainted_identifier(t);
Value::Symbolic(self.bv(s, n), taint)
} | Create a tainted `Value::Symbolic` from a name `s` and bit width `n` | tainted_symbolic_value | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn get_tainted_identifier(&mut self, t: &str) -> u64 {
if let Some(taint) = self.taints.get(t) {
*taint
} else {
let index = self.taints.len();
if index < 64 {
let new_taint = 1 << index as u64;
self.taints.insert(t.to_owned(), new_... | Get the numeric identifier for the given taint name | get_tainted_identifier | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn is_tainted_with(&mut self, value: &Value, taint: &str) -> bool {
(value.get_taint() & self.get_tainted_identifier(taint)) != 0
} | Check if the `value` is tainted with the given `taint` | is_tainted_with | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn constrain_bytes_bv(&mut self, bv: &BitVec, pattern: &str) {
if &pattern[..1] != "[" {
for (i, c) in pattern.chars().enumerate() {
self.assert_bv(
&bv.slice(8 * (i as u32 + 1) - 1, 8 * i as u32)
._eq(&self.bvv(c as u64, 8)),
... | Constrain bytes of bitvector to be an exact string eg. "ABC"
or use "\[...\]" to match a simple pattern eg. "\[XYZa-z0-9\]" | constrain_bytes_bv | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn constrain_fd(&mut self, fd: usize, content: &str) {
let fbytes = self.dump_file(fd);
let fbv = self.pack(&fbytes);
self.constrain_bytes(&fbv, content);
} | Constrain bytes of file with file descriptor `fd` and pattern | constrain_fd | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn constrain_file(&mut self, path: &str, content: &str) {
if let Some(fd) = self.filesystem.getfd(path) {
self.constrain_fd(fd, content);
}
} | Constrain bytes of file at `path` with pattern | constrain_file | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn is_sat(&mut self) -> bool {
if self.solver.is_sat() {
true
} else {
self.status = StateStatus::Unsat;
false
}
} | Check if this state is satisfiable and mark the state `Unsat` if not | is_sat | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn set_status(&mut self, status: StateStatus) {
self.status = status;
} | Set status of state (active, inactive, merge, unsat...) | set_status | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn set_crash(&mut self, addr: u64, perm: char) {
self.set_status(StateStatus::Crash(addr, perm));
} | Convenience method to mark state crashed | set_crash | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn get_args(&mut self) -> Vec<Value> {
let pc = self.registers.get_pc().as_u64().unwrap();
let cc = self.r2api.get_cc(pc).unwrap_or_default();
let mut args = Vec::with_capacity(16);
if !cc.args.is_empty() {
for arg in &cc.args {
args.push(self.registers.g... | Get the argument values for the current function | get_args | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn get_ret(&mut self) -> Value {
let pc = self.registers.get_pc().as_u64().unwrap();
let cc = self.r2api.get_cc(pc).unwrap_or_default();
self.registers.get(&cc.ret)
} | get the return value from the right register | get_ret | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn set_args(&mut self, mut values: Vec<Value>) {
let pc = self.registers.get_pc().as_u64().unwrap();
let cc = self.r2api.get_cc(pc).unwrap_or_default();
if !cc.args.is_empty() {
for arg in &cc.args {
if !values.is_empty() {
self.registers.set_... | Set the argument values for the current function | set_args | rust | aemmitt-ns/radius2 | radius/src/state.rs | https://github.com/aemmitt-ns/radius2/blob/master/radius/src/state.rs | MIT |
pub fn fluctuate_from_pattern(config_delay: Option<u32>, event_handle: Option<HANDLE>, pattern: [u8;2]) -> Result<(), String>
{
fluctuate_core(true, config_delay, event_handle, 0, Some(pattern))
} | Encrypt the whole PE. Use this function in order to specify a two bytes pattern that the library will look for to retrieve the module's base address. These two bytes replace
the classic MZ PE magic bytes, allowing you to remove PE headers to hide the pressence of the binary.
- config_delay: Number of seconds that the... | fluctuate_from_pattern | rust | Kudaes/Shelter | src/lib.rs | https://github.com/Kudaes/Shelter/blob/master/src/lib.rs | Apache-2.0 |
pub fn fluctuate_from_address(config_delay: Option<u32>, event_handle: Option<HANDLE>, base_adress: usize) -> Result<(), String>
{
fluctuate_core(true, config_delay, event_handle, base_adress, None)
} | Encrypt the whole PE. Use this function in order to specify the base_address of the current PE, preventing the library from searching the MZ pattern.
- config_delay: Number of seconds that the program will sleep for. If it is left to None, the timeout will be infinite.
For that option to work correctly, a valid event... | fluctuate_from_address | rust | Kudaes/Shelter | src/lib.rs | https://github.com/Kudaes/Shelter/blob/master/src/lib.rs | Apache-2.0 |
pub fn fluctuate(config_encryptall: bool, config_delay: Option<u32>, event_handle: Option<HANDLE>) -> Result<(), String>
{
fluctuate_core(config_encryptall, config_delay, event_handle, 0, None)
} | Encrypt either the current memory region or the whole PE.
- config_encryptall: Encrypt all sections from the PE or just the current memory region where the main program resides.
Keep in mind that, to be able to encrypt all sections, PE's magic bytes shouldn't be stripped.
For more information check out the implementati... | fluctuate | rust | Kudaes/Shelter | src/lib.rs | https://github.com/Kudaes/Shelter/blob/master/src/lib.rs | Apache-2.0 |
fn get_pe_metadata (module_ptr: *const u8) -> Result<PeMetadata,String> {
let mut pe_metadata= PeMetadata::default();
unsafe {
let e_lfanew = *((module_ptr as u64 + 0x3C) as *const u32);
pe_metadata.image_file_header = *((module_ptr as u64 + e_lfanew as u64 + 0x4) as *mut ImageFileHeader)... | Retrieves PE headers information from the module base address.
It will return either a dinvoke_rs::data::PeMetada struct containing the PE
metadata or a String with a descriptive error message.
# Examples
```
use std::fs;
let file_content = fs::read("c:\\windows\\system32\\ntdll.dll").expect("[x] Error opening the ... | get_pe_metadata | rust | Kudaes/Shelter | src/lib.rs | https://github.com/Kudaes/Shelter/blob/master/src/lib.rs | Apache-2.0 |
async fn interaction_handler<F>(
req: Request<Incoming>,
f: impl Fn(Box<CommandData>) -> F,
) -> anyhow::Result<Response<Full<Bytes>>>
where
F: Future<Output = anyhow::Result<InteractionResponse>>,
{
// Check that the method used is a POST, all other methods are not allowed.
if req.method() != Metho... | Main request handler which will handle checking the signature.
Responses are made by giving a function that takes a Interaction and returns
a InteractionResponse or a error. | interaction_handler | rust | twilight-rs/twilight | examples/model-webhook-slash.rs | https://github.com/twilight-rs/twilight/blob/master/examples/model-webhook-slash.rs | ISC |
async fn handler(data: Box<CommandData>) -> anyhow::Result<InteractionResponse> {
match data.name.as_ref() {
"vroom" => vroom(data).await,
"debug" => debug(data).await,
_ => debug(data).await,
}
} | Interaction handler that matches on the name of the interaction that
have been dispatched from Discord. | handler | rust | twilight-rs/twilight | examples/model-webhook-slash.rs | https://github.com/twilight-rs/twilight/blob/master/examples/model-webhook-slash.rs | ISC |
async fn debug(data: Box<CommandData>) -> anyhow::Result<InteractionResponse> {
Ok(InteractionResponse {
kind: InteractionResponseType::ChannelMessageWithSource,
data: Some(InteractionResponseData {
content: Some(format!("```rust\n{data:?}\n```")),
..Default::default()
... | Example of a handler that returns the formatted version of the interaction. | debug | rust | twilight-rs/twilight | examples/model-webhook-slash.rs | https://github.com/twilight-rs/twilight/blob/master/examples/model-webhook-slash.rs | ISC |
async fn vroom(_: Box<CommandData>) -> anyhow::Result<InteractionResponse> {
Ok(InteractionResponse {
kind: InteractionResponseType::ChannelMessageWithSource,
data: Some(InteractionResponseData {
content: Some("Vroom vroom".to_owned()),
..Default::default()
}),
})... | Example of interaction that responds with a message saying "Vroom vroom". | vroom | rust | twilight-rs/twilight | examples/model-webhook-slash.rs | https://github.com/twilight-rs/twilight/blob/master/examples/model-webhook-slash.rs | ISC |
pub const fn new() -> Self {
Self(Config::new(), PhantomData)
} | Creates a builder to configure and construct an [`InMemoryCache`]. | new | rust | twilight-rs/twilight | twilight-cache-inmemory/src/builder.rs | https://github.com/twilight-rs/twilight/blob/master/twilight-cache-inmemory/src/builder.rs | ISC |
pub const fn resource_types(mut self, resource_types: ResourceType) -> Self {
self.0.resource_types = resource_types;
self
} | Sets the list of resource types for the cache to handle.
Defaults to all types. | resource_types | rust | twilight-rs/twilight | twilight-cache-inmemory/src/builder.rs | https://github.com/twilight-rs/twilight/blob/master/twilight-cache-inmemory/src/builder.rs | ISC |
pub const fn message_cache_size(mut self, message_cache_size: usize) -> Self {
self.0.message_cache_size = message_cache_size;
self
} | Sets the number of messages to cache per channel.
Defaults to 100. | message_cache_size | rust | twilight-rs/twilight | twilight-cache-inmemory/src/builder.rs | https://github.com/twilight-rs/twilight/blob/master/twilight-cache-inmemory/src/builder.rs | ISC |
pub const fn new() -> Self {
Self {
resource_types: ResourceType::all(),
message_cache_size: 100,
}
} | Create a new default configuration.
Refer to individual getters for their defaults. | new | rust | twilight-rs/twilight | twilight-cache-inmemory/src/config.rs | https://github.com/twilight-rs/twilight/blob/master/twilight-cache-inmemory/src/config.rs | ISC |
pub fn message_cache_size_mut(&mut self) -> &mut usize {
&mut self.message_cache_size
} | Returns a mutable reference to the message cache size. | message_cache_size_mut | rust | twilight-rs/twilight | twilight-cache-inmemory/src/config.rs | https://github.com/twilight-rs/twilight/blob/master/twilight-cache-inmemory/src/config.rs | ISC |
pub fn resource_types_mut(&mut self) -> &mut ResourceType {
&mut self.resource_types
} | Returns a mutable reference to the resource types enabled. | resource_types_mut | rust | twilight-rs/twilight | twilight-cache-inmemory/src/config.rs | https://github.com/twilight-rs/twilight/blob/master/twilight-cache-inmemory/src/config.rs | ISC |
pub fn members(
&self,
) -> ResourceIter<'a, (Id<GuildMarker>, Id<UserMarker>), CacheModels::Member> {
ResourceIter::new(self.0.members.iter())
} | Create an iterator over the members across all guilds in the cache. | members | rust | twilight-rs/twilight | twilight-cache-inmemory/src/iter.rs | https://github.com/twilight-rs/twilight/blob/master/twilight-cache-inmemory/src/iter.rs | ISC |
pub fn presences(
&self,
) -> ResourceIter<'a, (Id<GuildMarker>, Id<UserMarker>), CacheModels::Presence> {
ResourceIter::new(self.0.presences.iter())
} | Create an iterator over the presences in the cache. | presences | rust | twilight-rs/twilight | twilight-cache-inmemory/src/iter.rs | https://github.com/twilight-rs/twilight/blob/master/twilight-cache-inmemory/src/iter.rs | ISC |
pub fn stage_instances(
&self,
) -> ResourceIter<'a, Id<StageMarker>, GuildResource<CacheModels::StageInstance>> {
ResourceIter::new(self.0.stage_instances.iter())
} | Create an iterator over the stage instances in the cache. | stage_instances | rust | twilight-rs/twilight | twilight-cache-inmemory/src/iter.rs | https://github.com/twilight-rs/twilight/blob/master/twilight-cache-inmemory/src/iter.rs | ISC |
pub fn stickers(
&self,
) -> ResourceIter<'a, Id<StickerMarker>, GuildResource<CacheModels::Sticker>> {
ResourceIter::new(self.0.stickers.iter())
} | Create an iterator over the stickers in the cache. | stickers | rust | twilight-rs/twilight | twilight-cache-inmemory/src/iter.rs | https://github.com/twilight-rs/twilight/blob/master/twilight-cache-inmemory/src/iter.rs | ISC |
pub fn voice_states(
&self,
) -> ResourceIter<'a, (Id<GuildMarker>, Id<UserMarker>), CacheModels::VoiceState> {
ResourceIter::new(self.0.voice_states.iter())
} | Create an iterator over the voice states in the cache. | voice_states | rust | twilight-rs/twilight | twilight-cache-inmemory/src/iter.rs | https://github.com/twilight-rs/twilight/blob/master/twilight-cache-inmemory/src/iter.rs | ISC |
pub fn channel_messages(
&self,
channel_id: Id<ChannelMarker>,
) -> Option<Reference<'_, Id<ChannelMarker>, VecDeque<Id<MessageMarker>>>> {
self.channel_messages.get(&channel_id).map(Reference::new)
} | Gets the set of messages in a channel.
This requires the [`DIRECT_MESSAGES`] or [`GUILD_MESSAGES`] intents.
[`DIRECT_MESSAGES`]: ::twilight_model::gateway::Intents::DIRECT_MESSAGES
[`GUILD_MESSAGES`]: ::twilight_model::gateway::Intents::GUILD_MESSAGES | channel_messages | rust | twilight-rs/twilight | twilight-cache-inmemory/src/lib.rs | https://github.com/twilight-rs/twilight/blob/master/twilight-cache-inmemory/src/lib.rs | ISC |
pub fn emoji(
&self,
emoji_id: Id<EmojiMarker>,
) -> Option<Reference<'_, Id<EmojiMarker>, GuildResource<CacheModels::Emoji>>> {
self.emojis.get(&emoji_id).map(Reference::new)
} | Gets an emoji by ID.
This requires the [`GUILD_EMOJIS_AND_STICKERS`] intent.
[`GUILD_EMOJIS_AND_STICKERS`]: ::twilight_model::gateway::Intents::GUILD_EMOJIS_AND_STICKERS | emoji | rust | twilight-rs/twilight | twilight-cache-inmemory/src/lib.rs | https://github.com/twilight-rs/twilight/blob/master/twilight-cache-inmemory/src/lib.rs | ISC |
End of preview. Expand in Data Studio
Rust CodeSearch Dataset (Shuu12121/rust-treesitter-dedupe-filtered-datasetsV2)
Dataset Description
This dataset contains Rust functions and methods paired with their documentation comments, extracted from open-source Rust repositories on GitHub. It is formatted similarly to the CodeSearchNet challenge dataset.
Each entry includes:
code: The source code of a rust function or method.docstring: The docstring or Javadoc associated with the function/method.func_name: The name of the function/method.language: The programming language (always "rust").repo: The GitHub repository from which the code was sourced (e.g., "owner/repo").path: The file path within the repository where the function/method is located.url: A direct URL to the function/method's source file on GitHub (approximated to master/main branch).license: The SPDX identifier of the license governing the source repository (e.g., "MIT", "Apache-2.0"). Additional metrics if available (from Lizard tool):ccn: Cyclomatic Complexity Number.params: Number of parameters of the function/method.nloc: Non-commenting lines of code.token_count: Number of tokens in the function/method.
Dataset Structure
The dataset is divided into the following splits:
train: 381,521 examplesvalidation: 6,333 examplestest: 8,868 examples
Data Collection
The data was collected by:
- Identifying popular and relevant Rust repositories on GitHub.
- Cloning these repositories.
- Parsing Rust files (
.rs) using tree-sitter to extract functions/methods and their docstrings/Javadoc. - Filtering functions/methods based on code length and presence of a non-empty docstring/Javadoc.
- Using the
lizardtool to calculate code metrics (CCN, NLOC, params). - Storing the extracted data in JSONL format, including repository and license information.
- Splitting the data by repository to ensure no data leakage between train, validation, and test sets.
Intended Use
This dataset can be used for tasks such as:
- Training and evaluating models for code search (natural language to code).
- Code summarization / docstring generation (code to natural language).
- Studies on Rust code practices and documentation habits.
Licensing
The code examples within this dataset are sourced from repositories with permissive licenses (typically MIT, Apache-2.0, BSD).
Each sample includes its original license information in the license field.
The dataset compilation itself is provided under a permissive license (e.g., MIT or CC-BY-SA-4.0),
but users should respect the original licenses of the underlying code.
Example Usage
from datasets import load_dataset
# Load the dataset
dataset = load_dataset("Shuu12121/rust-treesitter-dedupe-filtered-datasetsV2")
# Access a split (e.g., train)
train_data = dataset["train"]
# Print the first example
print(train_data[0])
- Downloads last month
- 14