Skip to content

Commit

Permalink
Merge pull request #330 from Nizernizer/main
Browse files Browse the repository at this point in the history
fix bug
  • Loading branch information
Nizernizer authored Jun 21, 2022
2 parents 833f978 + 3010435 commit 01ae872
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
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.

0 comments on commit 01ae872

Please sign in to comment.