mirror of
https://github.com/Noratrieb/coldsquare.git
synced 2026-01-16 09:25:08 +01:00
Merge remote-tracking branch 'origin/master'
# Conflicts: # crates/file-info/src/ui.rs
This commit is contained in:
commit
a1620476d8
8 changed files with 105 additions and 63 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -2,6 +2,10 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "class-struct"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "file-info"
|
name = "file-info"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
|
||||||
8
crates/class-struct/Cargo.toml
Normal file
8
crates/class-struct/Cargo.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "class-struct"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
23
crates/class-struct/src/lib.rs
Normal file
23
crates/class-struct/src/lib.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
struct MethodSignature {
|
||||||
|
args: Vec<Type>,
|
||||||
|
return_t: Type,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A Java type, found in signatures
|
||||||
|
enum Type {
|
||||||
|
/// V
|
||||||
|
Void,
|
||||||
|
/// B
|
||||||
|
Boolean,
|
||||||
|
Byte,
|
||||||
|
Short,
|
||||||
|
Int,
|
||||||
|
Long,
|
||||||
|
Float,
|
||||||
|
Double,
|
||||||
|
Object,
|
||||||
|
/// [
|
||||||
|
Array(Box<Type>),
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use file_parser::ClassFile;
|
use file_parser::{ClassFile, ParseErr};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
|
|
@ -17,11 +17,11 @@ pub fn display_class<W: Write>(mut w: W, class: &ClassFile) -> Result<(), Box<dy
|
||||||
w,
|
w,
|
||||||
"class {} extends {}{} {{",
|
"class {} extends {}{} {{",
|
||||||
&class.this_class.get(cp).name_index.get(cp),
|
&class.this_class.get(cp).name_index.get(cp),
|
||||||
match class.super_class.maybe_get(cp) {
|
match class.super_class.get(cp) {
|
||||||
None => "<none>",
|
None => "<none>",
|
||||||
Some(class) => &class.name_index.get(cp),
|
Some(class) => &class.name_index.get(cp),
|
||||||
},
|
}
|
||||||
if class.interfaces.len() == 0 {
|
if class.interfaces.is_empty() {
|
||||||
"".to_string()
|
"".to_string()
|
||||||
} else {
|
} else {
|
||||||
format!(
|
format!(
|
||||||
|
|
@ -31,8 +31,10 @@ pub fn display_class<W: Write>(mut w: W, class: &ClassFile) -> Result<(), Box<dy
|
||||||
.interfaces
|
.interfaces
|
||||||
.iter()
|
.iter()
|
||||||
.map(|i| i.get(cp))
|
.map(|i| i.get(cp))
|
||||||
|
.collect::<Result<Vec<_>, ParseErr>>()?
|
||||||
|
.iter()
|
||||||
.map(|i| i.name_index.get(cp))
|
.map(|i| i.name_index.get(cp))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Result<Vec<_>, ParseErr>>()?
|
||||||
.join(",")
|
.join(",")
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
@ -40,7 +42,7 @@ pub fn display_class<W: Write>(mut w: W, class: &ClassFile) -> Result<(), Box<dy
|
||||||
|
|
||||||
writeln!(w, " Attributes:")?;
|
writeln!(w, " Attributes:")?;
|
||||||
for attr in &class.attributes {
|
for attr in &class.attributes {
|
||||||
writeln!(w, " {}", &attr.attribute_name_index.get(cp))?;
|
writeln!(w, " {}", &attr.attribute_name_index.get(cp)?)?;
|
||||||
}
|
}
|
||||||
writeln!(w)?;
|
writeln!(w)?;
|
||||||
|
|
||||||
|
|
@ -49,8 +51,8 @@ pub fn display_class<W: Write>(mut w: W, class: &ClassFile) -> Result<(), Box<dy
|
||||||
writeln!(
|
writeln!(
|
||||||
w,
|
w,
|
||||||
" {} {}",
|
" {} {}",
|
||||||
&field.descriptor_index.get(cp),
|
&field.descriptor_index.get(cp)?,
|
||||||
&field.name_index.get(cp)
|
&field.name_index.get(cp)?
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
writeln!(w)?;
|
writeln!(w)?;
|
||||||
|
|
@ -60,8 +62,8 @@ pub fn display_class<W: Write>(mut w: W, class: &ClassFile) -> Result<(), Box<dy
|
||||||
writeln!(
|
writeln!(
|
||||||
w,
|
w,
|
||||||
" {} {}",
|
" {} {}",
|
||||||
&method.descriptor_index.get(cp),
|
&method.descriptor_index.get(cp)?,
|
||||||
&method.name_index.get(cp),
|
&method.name_index.get(cp)?,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ impl<'a> Data<'a> {
|
||||||
fn u1(&mut self) -> Result<u1> {
|
fn u1(&mut self) -> Result<u1> {
|
||||||
let item = self.data.get(self.pointer).cloned();
|
let item = self.data.get(self.pointer).cloned();
|
||||||
self.pointer += 1;
|
self.pointer += 1;
|
||||||
item.ok_or(ParseErr("No u1 left".to_string()))
|
item.ok_or_else(|| ParseErr("No u1 left".to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn u2(&mut self) -> Result<u2> {
|
fn u2(&mut self) -> Result<u2> {
|
||||||
|
|
@ -60,7 +60,7 @@ impl<'a> Data<'a> {
|
||||||
self.data
|
self.data
|
||||||
.get(self.pointer - 1)
|
.get(self.pointer - 1)
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or(ParseErr("Last u1 not found".to_string()))
|
.ok_or_else(|| ParseErr("Last u1 not found".to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn last_u2(&self) -> Result<u2> {
|
fn last_u2(&self) -> Result<u2> {
|
||||||
|
|
@ -68,7 +68,7 @@ impl<'a> Data<'a> {
|
||||||
.data
|
.data
|
||||||
.get(self.pointer - 2)
|
.get(self.pointer - 2)
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or(ParseErr("Last u2 not found".to_string()))?;
|
.ok_or_else(|| ParseErr("Last u2 not found".to_string()))?;
|
||||||
Ok(((last2u1 as u2) << 8) | self.last_u1()? as u2)
|
Ok(((last2u1 as u2) << 8) | self.last_u1()? as u2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,12 +77,12 @@ impl<'a> Data<'a> {
|
||||||
.data
|
.data
|
||||||
.get(self.pointer - 3)
|
.get(self.pointer - 3)
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or(ParseErr("Last 2 u1 in last u4 not found".to_string()))?;
|
.ok_or_else(|| ParseErr("Last 2 u1 in last u4 not found".to_string()))?;
|
||||||
let last3u1 = self
|
let last3u1 = self
|
||||||
.data
|
.data
|
||||||
.get(self.pointer - 4)
|
.get(self.pointer - 4)
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or(ParseErr("Last 3 u1 in last u4 not found".to_string()))?;
|
.ok_or_else(|| ParseErr("Last 3 u1 in last u4 not found".to_string()))?;
|
||||||
Ok(((last3u1 as u4) << 24) | ((last2u1 as u4) << 16) | self.last_u2()? as u4)
|
Ok(((last3u1 as u4) << 24) | ((last2u1 as u4) << 16) | self.last_u2()? as u4)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -262,7 +262,7 @@ impl Parse for CpInfo {
|
||||||
name_and_type_index: data.cp(cp)?,
|
name_and_type_index: data.cp(cp)?,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
_ => Err(ParseErr(format!("Invalid CPInfo tag: {}", tag)))?,
|
_ => return Err(ParseErr(format!("Invalid CPInfo tag: {}", tag))),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -346,10 +346,12 @@ impl Parse for StackMapFrame {
|
||||||
locals: parse_vec(data.u2()?, data, cp)?,
|
locals: parse_vec(data.u2()?, data, cp)?,
|
||||||
stack: parse_vec(data.u2()?, data, cp)?,
|
stack: parse_vec(data.u2()?, data, cp)?,
|
||||||
},
|
},
|
||||||
_ => Err(ParseErr(format!(
|
_ => {
|
||||||
"Invalid StackMapFrame type: {}",
|
return Err(ParseErr(format!(
|
||||||
frame_type
|
"Invalid StackMapFrame type: {}",
|
||||||
)))?,
|
frame_type
|
||||||
|
)))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -373,10 +375,12 @@ impl Parse for VerificationTypeInfo {
|
||||||
tag,
|
tag,
|
||||||
offset: data.u2()?,
|
offset: data.u2()?,
|
||||||
},
|
},
|
||||||
_ => Err(ParseErr(format!(
|
_ => {
|
||||||
"Invalid VerificationTypeInfo tag: {}",
|
return Err(ParseErr(format!(
|
||||||
tag
|
"Invalid VerificationTypeInfo tag: {}",
|
||||||
)))?,
|
tag
|
||||||
|
)))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -461,10 +465,12 @@ impl Parse for AnnotationElementValueValue {
|
||||||
'[' => Self::ArrayValue {
|
'[' => Self::ArrayValue {
|
||||||
values: parse_vec(data.u2()?, data, cp)?,
|
values: parse_vec(data.u2()?, data, cp)?,
|
||||||
},
|
},
|
||||||
_ => Err(ParseErr(format!(
|
_ => {
|
||||||
"Invalid AnnotationElementValueValue tag: {}",
|
return Err(ParseErr(format!(
|
||||||
tag
|
"Invalid AnnotationElementValueValue tag: {}",
|
||||||
)))?,
|
tag
|
||||||
|
)))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -551,7 +557,7 @@ impl AttributeInfo {
|
||||||
_ => return Err(ParseErr("Constant Pool index out of Bounds".to_string())),
|
_ => return Err(ParseErr("Constant Pool index out of Bounds".to_string())),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut data = Data::new(&content);
|
let mut data = Data::new(content);
|
||||||
self.resolve_attribute_inner(index, len, info, &mut data, pool)
|
self.resolve_attribute_inner(index, len, info, &mut data, pool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -467,29 +467,29 @@ pub enum ClassAccessFlag {
|
||||||
#[repr(u16)]
|
#[repr(u16)]
|
||||||
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
|
||||||
pub enum MethodAccessFlag {
|
pub enum MethodAccessFlag {
|
||||||
// Declared public; may be accessed from outside its package.
|
/// Declared public; may be accessed from outside its package.
|
||||||
PUBLIC = 0x0001,
|
PUBLIC = 0x0001,
|
||||||
// Declared private; accessible only within the defining class.
|
/// Declared private; accessible only within the defining class.
|
||||||
PRIVATE = 0x0002,
|
PRIVATE = 0x0002,
|
||||||
// Declared protected; may be accessed within subclasses.
|
/// Declared protected; may be accessed within subclasses.
|
||||||
PROTECTED = 0x0004,
|
PROTECTED = 0x0004,
|
||||||
// Declared static.
|
/// Declared static.
|
||||||
STATIC = 0x0008,
|
STATIC = 0x0008,
|
||||||
// Declared final; must not be overridden.
|
/// Declared final; must not be overridden.
|
||||||
FINAL = 0x0010,
|
FINAL = 0x0010,
|
||||||
// Declared synchronized; invocation is wrapped by a monitor use.
|
/// Declared synchronized; invocation is wrapped by a monitor use.
|
||||||
SYNCHRONIZED = 0x0020,
|
SYNCHRONIZED = 0x0020,
|
||||||
// A bridge method, generated by the compiler.
|
/// A bridge method, generated by the compiler.
|
||||||
BRIDGE = 0x0040,
|
BRIDGE = 0x0040,
|
||||||
// Declared with variable number of arguments.
|
/// Declared with variable number of arguments.
|
||||||
VARARGS = 0x0080,
|
VARARGS = 0x0080,
|
||||||
// Declared native; implemented in a language other than Java.
|
/// Declared native; implemented in a language other than Java.
|
||||||
NATIVE = 0x0100,
|
NATIVE = 0x0100,
|
||||||
// Declared abstract; no implementation is provided.
|
/// Declared abstract; no implementation is provided.
|
||||||
ABSTRACT = 0x0400,
|
ABSTRACT = 0x0400,
|
||||||
// Declared strictfp; floating-point mode is FP-strict.
|
/// Declared strictfp; floating-point mode is FP-strict.
|
||||||
STRICT = 0x0800,
|
STRICT = 0x0800,
|
||||||
// Declared synthetic; not present in the source code.
|
// /Declared synthetic; not present in the source code.
|
||||||
SYNTHETIC = 0x1000,
|
SYNTHETIC = 0x1000,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -497,23 +497,23 @@ pub enum MethodAccessFlag {
|
||||||
#[repr(u16)]
|
#[repr(u16)]
|
||||||
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
|
||||||
pub enum InnerClassAccessFlags {
|
pub enum InnerClassAccessFlags {
|
||||||
/// Marked or implicitly public in source.
|
/// Marked or implicitly public in source.
|
||||||
PUBLIC = 0x0001,
|
PUBLIC = 0x0001,
|
||||||
/// Marked private in source.
|
/// Marked private in source.
|
||||||
PRIVATE = 0x0002,
|
PRIVATE = 0x0002,
|
||||||
/// Marked protected in source.
|
/// Marked protected in source.
|
||||||
PROTECTED = 0x0004,
|
PROTECTED = 0x0004,
|
||||||
/// Marked or implicitly static in source.
|
/// Marked or implicitly static in source.
|
||||||
STATIC = 0x0008,
|
STATIC = 0x0008,
|
||||||
/// Marked final in source.
|
/// Marked final in source.
|
||||||
FINAL = 0x0010,
|
FINAL = 0x0010,
|
||||||
/// Was an interface in source.
|
/// Was an interface in source.
|
||||||
INTERFACE = 0x0200,
|
INTERFACE = 0x0200,
|
||||||
/// Marked or implicitly abstract in source.
|
/// Marked or implicitly abstract in source.
|
||||||
ABSTRACT = 0x0400,
|
ABSTRACT = 0x0400,
|
||||||
/// Declared synthetic; not present in the source code.
|
/// Declared synthetic; not present in the source code.
|
||||||
SYNTHETIC = 0x1000,
|
SYNTHETIC = 0x1000,
|
||||||
/// Declared as an annotation type.
|
/// Declared as an annotation type.
|
||||||
ANNOTATION = 0x2000,
|
ANNOTATION = 0x2000,
|
||||||
/// Declared as an enum type.
|
/// Declared as an enum type.
|
||||||
ENUM = 0x4000,
|
ENUM = 0x4000,
|
||||||
|
|
@ -523,22 +523,22 @@ pub enum InnerClassAccessFlags {
|
||||||
#[repr(u16)]
|
#[repr(u16)]
|
||||||
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
|
||||||
pub enum FieldAccessFlags {
|
pub enum FieldAccessFlags {
|
||||||
/// Declared public; may be accessed from outside its package.
|
/// Declared public; may be accessed from outside its package.
|
||||||
PUBLIC = 0x0001,
|
PUBLIC = 0x0001,
|
||||||
/// Declared private; usable only within the defining class.
|
/// Declared private; usable only within the defining class.
|
||||||
PRIVATE = 0x0002,
|
PRIVATE = 0x0002,
|
||||||
/// Declared protected; may be accessed within subclasses.
|
/// Declared protected; may be accessed within subclasses.
|
||||||
PROTECTED = 0x0004,
|
PROTECTED = 0x0004,
|
||||||
/// Declared static.
|
/// Declared static.
|
||||||
STATIC = 0x0008,
|
STATIC = 0x0008,
|
||||||
/// Declared final; never directly assigned to after object construction (JLS §17.5).
|
/// Declared final; never directly assigned to after object construction (JLS §17.5).
|
||||||
FINAL = 0x0010,
|
FINAL = 0x0010,
|
||||||
/// Declared volatile; cannot be cached.
|
/// Declared volatile; cannot be cached.
|
||||||
VOLATILE = 0x0040,
|
VOLATILE = 0x0040,
|
||||||
/// Declared transient; not written or read by a persistent object manager.
|
/// Declared transient; not written or read by a persistent object manager.
|
||||||
TRANSIENT = 0x0080,
|
TRANSIENT = 0x0080,
|
||||||
/// Declared synthetic; not present in the source code.
|
/// Declared synthetic; not present in the source code.
|
||||||
SYNTHETIC = 0x1000,
|
SYNTHETIC = 0x1000,
|
||||||
/// Declared as an element of an enum.
|
/// Declared as an element of an enum.
|
||||||
ENUM = 0x4000,
|
ENUM = 0x4000,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,8 @@ impl OperandStack {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn swap(&mut self) {
|
pub fn swap(&mut self) {
|
||||||
let tmp = self.arr[(self.sp - 1) as usize];
|
self.arr
|
||||||
self.arr[(self.sp - 1) as usize] = self.arr[(self.sp - 2) as usize];
|
.swap((self.sp - 2) as usize, (self.sp - 2) as usize);
|
||||||
self.arr[(self.sp - 2) as usize] = tmp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env bash
|
#!/bin/bash
|
||||||
|
|
||||||
cd crates/file-info
|
cd crates/file-info
|
||||||
cargo run ../../"$1"
|
cargo run ../../"$1"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue