Skip to content
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

fix bug #330

Merged
merged 1 commit into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions dongtai-agent/src/main/java/io/dongtai/iast/agent/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ private static void doAttach(String pid, String agentArgs) {
}
}

private static boolean isLinux() {
return OS_NAME.indexOf("linux") >= 0;
private static boolean isArm() {
return System.getProperty("os.arch").contains("arm") || System.getProperty("os.arch").contains("aarch");
}

public static boolean isWindows() {
Expand All @@ -133,7 +133,10 @@ private static void extractJattach() throws IOException {
} else if (isMacOs()) {
JATTACH_FILE = System.getProperty("java.io.tmpdir")+ File.separator + "iast"+System.currentTimeMillis() + File.separator + "jattach-mac";
FileUtils.getResourceToFile("bin/jattach-mac", JATTACH_FILE);
} else {
} else if (isArm()){
JATTACH_FILE = System.getProperty("java.io.tmpdir")+ File.separator + "iast"+System.currentTimeMillis() + File.separator + "jattach-linux";
FileUtils.getResourceToFile("bin/jattach-arm", JATTACH_FILE);
}else {
JATTACH_FILE = System.getProperty("java.io.tmpdir")+ File.separator + "iast"+System.currentTimeMillis() + File.separator + "jattach-linux";
FileUtils.getResourceToFile("bin/jattach-linux", JATTACH_FILE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ public static void confReplace(String path) {
StringBuffer buf = new StringBuffer();
// 保存该行前面的内容
while ((temp = br.readLine()) != null) {
if (temp.contains("${HOSTNAME_AGENT_ID}")){
temp = temp.replace("${HOSTNAME_AGENT_ID}", AgentRegisterReport.getInternalHostName()+"-"+AgentRegisterReport.getAgentFlag().toString());
}else if (temp.contains("${HOSTNAME}")){
temp = temp.replace("${HOSTNAME}",AgentRegisterReport.getInternalHostName());
}else if (temp.contains("${AGENT_ID}")){
temp = temp.replace("${AGENT_ID}",AgentRegisterReport.getAgentFlag().toString());
}else if (temp.contains("${OPENAPI}")){
if (temp.contains("${HOSTNAME_AGENT_ID}")) {
temp = temp.replace("${HOSTNAME_AGENT_ID}", AgentRegisterReport.getInternalHostName() + "-" + AgentRegisterReport.getAgentFlag().toString());
} else if (temp.contains("${HOSTNAME}")) {
temp = temp.replace("${HOSTNAME}", AgentRegisterReport.getInternalHostName());
} else if (temp.contains("${AGENT_ID}")) {
temp = temp.replace("${AGENT_ID}", AgentRegisterReport.getAgentFlag().toString());
} else if (temp.contains("${OPENAPI}")) {
String logAddress = IastProperties.getInstance().getLogAddress();
if (null == logAddress){
if (null == logAddress) {
String s = IastProperties.getInstance().getBaseUrl();
try {
String openApiDomain = new URI(s).getHost();
Expand All @@ -70,17 +70,16 @@ public static void confReplace(String path) {
}
temp = temp.replace("${OPENAPI}", s);
}
}else {
} else {
temp = temp.replace("${OPENAPI}", logAddress);
}
}else if (temp.contains("${LOG_PORT}")){
} else if (temp.contains("${LOG_PORT}")) {
String logPort = IastProperties.getInstance().getLogPort();
if (null == logPort){
if (null == logPort) {
String s = IastProperties.getInstance().getBaseUrl();
try {
int openApiPort = new URI(s).getPort();
temp = temp.replace("${LOG_PORT}", openApiPort > 0 ? Integer.toString(openApiPort) :
("https".equalsIgnoreCase(new URI(s).getScheme()) ? "443" : "80"));
temp = temp.replace("${LOG_PORT}", openApiPort > 0 ? Integer.toString(openApiPort) : "80");
} catch (Exception e) {
s = s.substring(s.indexOf("://") + 3, s.indexOf("/openapi"));
if (s.contains(":")) {
Expand All @@ -90,11 +89,11 @@ public static void confReplace(String path) {
temp = temp.replace("${LOG_PORT}", "80");
}
}
}else {
} else {
temp = temp.replace("${LOG_PORT}", logPort);
}
}else if (temp.contains("${LOG_PATH}")){
temp = temp.replace("${LOG_PATH}", System.getProperty("java.io.tmpdir.dongtai")+File.separator+"dongtaiJavaAgentLogs"+File.separator+"dongtai_javaagent.log");
} else if (temp.contains("${LOG_PATH}")) {
temp = temp.replace("${LOG_PATH}", System.getProperty("java.io.tmpdir.dongtai") + File.separator + "dongtaiJavaAgentLogs" + File.separator + "dongtai_javaagent.log");
}
buf = buf.append(temp);
buf = buf.append(System.getProperty("line.separator"));
Expand Down
Binary file added dongtai-agent/src/main/resources/bin/jattach-arm
Binary file not shown.