-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Librasp modify guoyj #634
Open
cnguoyj-leminis
wants to merge
2
commits into
main
Choose a base branch
from
librasp-modify-guoyj
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Librasp modify guoyj #634
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
use anyhow::{anyhow, Result}; | ||
use anyhow::{anyhow, Result, Result as AnyhowResult}; | ||
|
||
use log::*; | ||
use regex::Regex; | ||
use std::process::Command; | ||
use std::fs; | ||
use std::path::Path; | ||
use std::path::PathBuf; | ||
use std::time::Duration; | ||
use crate::async_command::run_async_process; | ||
use crate::process::ProcessInfo; | ||
use crate::runtime::{ProbeCopy, ProbeState, ProbeStateInspect}; | ||
use crate::settings::{self, RASP_VERSION}; | ||
use lazy_static::lazy_static; | ||
use fs_extra::file::{copy as file_copy, remove as file_remove, CopyOptions as FileCopyOptions}; | ||
|
||
lazy_static! { | ||
static ref RASP_JAVA_CHECKSUMSTR: String = { | ||
|
@@ -53,6 +56,127 @@ impl ProbeCopy for JVMProbe { | |
} | ||
} | ||
|
||
pub struct JVMProbeNativeLib {} | ||
|
||
impl ProbeCopy for JVMProbeNativeLib { | ||
#[cfg(all(target_os = "linux"))] | ||
fn names() -> (Vec<String>, Vec<String>) { | ||
( | ||
[ | ||
settings::RASP_JAVA_NETTY_EPOLL_SO(), | ||
] | ||
.to_vec(), | ||
[].to_vec(), | ||
) | ||
} | ||
|
||
#[cfg(all(target_os = "macos"))] | ||
fn names() -> (Vec<String>, Vec<String>) { | ||
( | ||
[ | ||
settings::RASP_JAVA_NETTY_KQUEUQ_SO_MAC(), | ||
settings::RASP_JAVA_NETTY_DNS_SO_MAC(), | ||
] | ||
.to_vec(), | ||
[].to_vec(), | ||
) | ||
} | ||
} | ||
|
||
pub fn parse_java_library_path(input: &str) -> Result<Vec<PathBuf>, anyhow::Error> { | ||
let xinput = input.replace("\\:", ":"); | ||
let paths: Vec<&str> = xinput.split(":").collect(); | ||
let mut result = Vec::with_capacity(paths.len()); | ||
|
||
for path in paths { | ||
let path_buf = { | ||
let path_str = path.to_string(); | ||
PathBuf::from(path_str) | ||
}; | ||
if path_buf.exists() { | ||
result.push(path_buf); | ||
} else { | ||
// Ignore non-existent paths | ||
continue; | ||
} | ||
} | ||
|
||
Ok(result) | ||
} | ||
|
||
fn copy_file_probe(from:String,to:String) -> AnyhowResult<()> { | ||
let options = FileCopyOptions::new(); | ||
return match file_copy(from.clone(), to.clone(), &options) { | ||
Ok(_) => Ok(()), | ||
Err(e) => { | ||
warn!("can not copy: {}", e); | ||
Err(anyhow!( | ||
"copy failed: from {} to {}: {}", | ||
from, | ||
to, | ||
e | ||
)) | ||
} | ||
} | ||
} | ||
|
||
fn get_last_filename(path: &str) -> Option<String> { | ||
Path::new(path) | ||
.file_name() | ||
.and_then(|name| name.to_str()) | ||
.map(|name| name.to_string()) | ||
} | ||
|
||
pub fn copy_probe_nativelib(pid:i32,dst_root:String) -> AnyhowResult<()> { | ||
let _ = jcmd(pid, " VM.system_properties").and_then(|output| { | ||
let output_str = String::from_utf8_lossy(&output); | ||
let lines: Vec<&str> = output_str.split("\n").collect(); | ||
let java_library_path_line = lines.iter().find(|line| line.starts_with("java.library.path=")); | ||
if let Some(line) = java_library_path_line { | ||
let path = line.trim_start_matches("java.library.path="); | ||
match parse_java_library_path(path) { | ||
Ok(parsed_paths) => { | ||
println!("Java library paths:{:?}",parsed_paths); | ||
for from in JVMProbeNativeLib::names().0.iter() { | ||
let src_path = from.clone(); | ||
if let Some(soname) = get_last_filename(&src_path) { | ||
let mut bIsExist = false; | ||
println!("Last filename: {}", soname); | ||
for path in parsed_paths.clone() { | ||
let mut path_str = format!("{}{}",dst_root,path.display()); | ||
let path_buf: PathBuf = path_str.into(); | ||
println!(" {} exist", path_buf.display()); | ||
if path_buf.join(&soname).exists() { | ||
println!("{} exist",soname); | ||
bIsExist = true; | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果后面依赖库修改了版本,这里会依旧使用旧的so库?是否会有兼容性问题呢? |
||
} | ||
} | ||
|
||
if !bIsExist { | ||
let path = parsed_paths[0].clone(); | ||
|
||
let dst_path = format!("{}{}/{}",dst_root,path.display(),soname); | ||
println!("copy {} to {}",src_path,dst_path); | ||
copy_file_probe(src_path,dst_path); | ||
} | ||
} | ||
} | ||
} | ||
Err(e) => { | ||
info!("parse java library path failed: {}", e); | ||
} | ||
} | ||
|
||
Ok(0) | ||
} else { | ||
Err(anyhow::anyhow!("java.library.path not found in output")) | ||
} | ||
}); | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn java_attach(pid: i32) -> Result<bool> { | ||
let java_attach = settings::RASP_JAVA_JATTACH_BIN(); | ||
let agent = settings::RASP_JAVA_AGENT_BIN(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些打印改成跟原先的日志一致吧,可以重定向到rasp.log