Skip to content

Commit

Permalink
Fix go binary initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
mooncat-greenpy committed Jan 30, 2022
1 parent f9701d8 commit 958e339
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
9 changes: 5 additions & 4 deletions src/main/java/golanganalyzerextension/FunctionModifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public class FunctionModifier extends GolangBinary {
public FunctionModifier(Program program, TaskMonitor monitor, MessageLog log, boolean rename_option, boolean param_option, boolean comment_option, boolean extended_option, boolean debugmode) {
super(program, monitor, log, debugmode);

if(this.gopclntab_base==null) {
return;
}

this.rename_option=rename_option;
this.param_option=param_option;
this.comment_option=comment_option;
Expand All @@ -44,9 +48,6 @@ public FunctionModifier(Program program, TaskMonitor monitor, MessageLog log, bo
return;
}

if(!init_gopclntab()) {
return;
}
if(!init_file_name_list()) {
return;
}
Expand All @@ -58,7 +59,7 @@ public FunctionModifier(Program program, TaskMonitor monitor, MessageLog log, bo
init_hardcode_functions();
}

ok=true;
this.ok=true;
}

boolean init_file_name_list() {
Expand Down
27 changes: 12 additions & 15 deletions src/main/java/golanganalyzerextension/GolangBinary.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public GolangBinary(Program program, TaskMonitor monitor, MessageLog log, boolea
this.memory=program.getMemory();
this.ok=false;
this.debugmode=debugmode;

if(!init_go_version()) {
append_message("Failed to init go version");
}
if(!init_gopclntab()) {
append_message("Failed to init gopclntab");
}
}

public GolangBinary(GolangBinary obj) {
Expand Down Expand Up @@ -323,14 +330,12 @@ Address get_gopclntab() {
return tmp_gopclntab_base;
}

boolean init_gopclntab(Address addr) {
if(gopclntab_base!=null) {
boolean init_gopclntab() {
if(this.gopclntab_base!=null) {
return true;
}
if(addr==null) {
addr=get_gopclntab();
}
this.gopclntab_base=addr;

this.gopclntab_base=get_gopclntab();
if(this.gopclntab_base==null) {
append_message("Failed to get gopclntab");
return false;
Expand All @@ -350,23 +355,16 @@ boolean init_gopclntab(Address addr) {
return true;
}

boolean init_gopclntab() {
return init_gopclntab(get_gopclntab());
}

boolean init_go_version()
{
if(go_version.length()>0) {
return true;
}
go_version="";
// cmd/go/internal/version/version.go
// "\xff Go buildinf:"
byte build_info_magic[]= {(byte)0xff,(byte)0x20,(byte)0x47,(byte)0x6f,(byte)0x20,(byte)0x62,(byte)0x75,(byte)0x69,(byte)0x6c,(byte)0x64,(byte)0x69,(byte)0x6e,(byte)0x66,(byte)0x3a};
Address base_addr=null;
base_addr=memory.findBytes(base_addr, build_info_magic, new byte[] {(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff}, true, monitor);
if(base_addr==null) {
append_message("Failed to find \"\\xff Go buildinf:\"");
go_version="go0.0.0";
return false;
}

Expand Down Expand Up @@ -399,7 +397,6 @@ else if(go_version_mod.length()>=33 && go_version_mod.charAt(go_version_mod.leng
}

int compare_go_version(String cmp_go_version) {
init_go_version();
String cmp1=cmp_go_version.substring(2);
String cmp2=go_version.length()>2?go_version.substring(2):"0.0.0";
String[] sp_cmp1=cmp1.split("\\.");
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/golanganalyzerextension/StructureManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,15 @@ public StructureManager(Program program, TaskMonitor monitor, MessageLog log, bo
return;
}

this.datatype_manager=program.getDataTypeManager();
hardcode_datatype_map=new HashMap<String, DataType>();
name_to_type_map=new HashMap<String, Long>();
basic_type_info_map=new HashMap<Long, BasicTypeInfo>();

if(!init_gopclntab()) {
append_message("Failed to init gopclntab");
if(this.gopclntab_base==null) {
return;
}

this.datatype_manager=program.getDataTypeManager();
this.hardcode_datatype_map=new HashMap<String, DataType>();
this.name_to_type_map=new HashMap<String, Long>();
this.basic_type_info_map=new HashMap<Long, BasicTypeInfo>();

if(!init_basig_golang_hardcode_datatype()) {
return;
}
Expand All @@ -314,7 +313,7 @@ public StructureManager(Program program, TaskMonitor monitor, MessageLog log, bo
return;
}

ok=true;
this.ok=true;
return;
}

Expand Down

0 comments on commit 958e339

Please sign in to comment.