feat: add static stage extraction and metadata detection

This commit is contained in:
bfloat16
2026-08-16 01:47:25 +08:00
parent b1d3699df3
commit 131ced6db5
17 changed files with 1840 additions and 49 deletions
+38
View File
@@ -6,6 +6,9 @@ use std::path::{Path, PathBuf};
use anyhow::{Context, Result, bail};
use senbei_android_elf::{RestoreOptions, RestoreReport, restore_libil2cpp};
use senbei_android_metadata::{DEFAULT_METHOD_TOKEN_SEED, Report as MetadataReport};
use senbei_android_stage2::{
DEFAULT_CIPHER_CONSTANT, DEFAULT_OUTER_SIZE, ExtractOptions, ExtractionReport, extract_stage2,
};
use serde::Serialize;
use tempfile::NamedTempFile;
@@ -30,6 +33,29 @@ pub struct RestoreMetadataJob {
pub report: Option<PathBuf>,
}
/// Filesystem arguments for pure-static Stage 1 and Stage 2 extraction.
#[derive(Debug, Clone)]
pub struct ExtractStage2Job {
pub input: PathBuf,
pub output_dir: PathBuf,
pub stage2_output: Option<PathBuf>,
pub outer_size: usize,
pub cipher_constant: u32,
}
impl ExtractStage2Job {
#[must_use]
pub fn new(input: PathBuf, output_dir: PathBuf) -> Self {
Self {
input,
output_dir,
stage2_output: None,
outer_size: DEFAULT_OUTER_SIZE,
cipher_constant: DEFAULT_CIPHER_CONSTANT,
}
}
}
impl RestoreMetadataJob {
#[must_use]
pub fn new(input: PathBuf, output: PathBuf) -> Self {
@@ -87,6 +113,18 @@ pub fn run_restore_metadata(job: &RestoreMetadataJob) -> Result<MetadataReport>
Ok(result)
}
/// Extract Stage 2 modules directly from one protected ELF.
pub fn run_extract_stage2(job: &ExtractStage2Job) -> Result<ExtractionReport> {
extract_stage2(&ExtractOptions {
input: job.input.clone(),
output_dir: job.output_dir.clone(),
stage2_output: job.stage2_output.clone(),
outer_size: job.outer_size,
cipher_constant: job.cipher_constant,
})
.context("extract protected Stage 1/Stage 2 payload")
}
fn refuse_in_place(input: &Path, output: &Path) -> Result<()> {
let input_absolute = absolute(input)?;
let output_absolute = absolute(output)?;