Skip to content

Commit 91fc1c1

Browse files
Fix
1 parent 2a6be3b commit 91fc1c1

File tree

6 files changed

+104
-14
lines changed

6 files changed

+104
-14
lines changed

src/main/java/golanganalyzerextension/FunctionModifier.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,25 @@ private boolean init_functions() {
173173
long func_entry_value;
174174
long func_end_value;
175175
try {
176-
func_addr_value=go_bin.get_address_value(func_list_base, i*(is_go118?4:pointer_size)*2, is_go118?4:pointer_size);
176+
int functab_field_size=is_go118?4:pointer_size;
177+
func_addr_value=go_bin.get_address_value(func_list_base, i*functab_field_size*2, functab_field_size);
177178
if(is_go118) {
178179
func_addr_value+=go_bin.get_address_value(pcheader_base, 8+pointer_size*2, pointer_size);
179180
}
180-
func_info_offset=go_bin.get_address_value(func_list_base, i*(is_go118?4:pointer_size)*2+(is_go118?4:pointer_size), is_go118?4:pointer_size);
181+
func_info_offset=go_bin.get_address_value(func_list_base, i*functab_field_size*2+functab_field_size, functab_field_size);
181182

182183
if(is_go116) {
183184
func_info_addr=go_bin.get_address(func_list_base, func_info_offset);
184185
}else {
185186
func_info_addr=go_bin.get_address(pcheader_base, func_info_offset);
186187
}
187188

188-
func_entry_value=go_bin.get_address_value(func_info_addr, is_go118?4:pointer_size);
189-
func_end_value=go_bin.get_address_value(func_list_base, i*(is_go118?4:pointer_size)*2+(is_go118?4:pointer_size)*2, is_go118?4:pointer_size);
189+
func_entry_value=go_bin.get_address_value(func_info_addr, functab_field_size);
190+
func_end_value=go_bin.get_address_value(func_list_base, i*functab_field_size*2+functab_field_size*2, functab_field_size);
190191
if(is_go118) {
191-
func_entry_value+=go_bin.get_address_value(pcheader_base, 8+pointer_size*2, pointer_size);
192-
func_end_value+=go_bin.get_address_value(pcheader_base, 8+pointer_size*2, pointer_size);
192+
long text=go_bin.get_address_value(pcheader_base, 8+pointer_size*2, pointer_size);
193+
func_entry_value+=text;
194+
func_end_value+=text;
193195
}
194196
} catch (BinaryAccessException e) {
195197
Logger.append_message(String.format("Failed to init func: pcheader_addr=%s, func_list_base=%s, i=%d, message=%s", pcheader_base, func_list_base, i, e.getMessage()));

src/main/java/golanganalyzerextension/function/GolangFunction.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,9 @@ private List<PcFile> get_pc_to_file_name_list(int target_pc_offset) {
590590
Address file_name_addr;
591591
try {
592592
int cu_offset=(int)go_bin.get_address_value(info_addr, (is_go118?4:pointer_size)+4*7, 4);
593+
if(cu_offset==0xffffffff) {
594+
return pcfile_list;
595+
}
593596
Address cutab_base;
594597
if(is_go118) {
595598
cutab_base=go_bin.get_address(pcheader_base, go_bin.get_address_value(pcheader_base, 8+pointer_size*4, pointer_size));

src/main/java/golanganalyzerextension/gobinary/GolangBinary.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,7 @@ public String read_string(Address addr, int size) throws BinaryAccessException,
385385
byte[] bytes=new byte[size];
386386
memory.getBytes(addr, bytes, 0, size);
387387
String str=new String(bytes);
388-
int tmp_len=str.length();
389388
str=str.replaceAll("[^\\x09\\x0a\\x0d\\x20-\\x7e]", "");
390-
if(str.length()!=tmp_len) {
391-
// Logger.append_message(String.format("Invalid char: %x %x %s", addr.getOffset(), size, str));
392-
}
393389
return str;
394390
} catch (MemoryAccessException e) {
395391
throw new BinaryAccessException(String.format("Get string: addr=%s, size=%d, message=%s", addr, size, e.getMessage()));
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package golanganalyzerextension.gobinary;
2+
3+
import ghidra.program.model.data.AbstractSignedIntegerDataType;
4+
import ghidra.program.model.data.DataOrganization;
5+
import ghidra.program.model.data.DataTypeManager;
6+
7+
public class Integer4DataType extends AbstractSignedIntegerDataType {
8+
9+
/** A statically defined Integer4DataType instance.*/
10+
public final static Integer4DataType dataType = new Integer4DataType();
11+
12+
public Integer4DataType() {
13+
this(null);
14+
}
15+
16+
public Integer4DataType(DataTypeManager dtm) {
17+
super("int4", dtm);
18+
}
19+
20+
@Override
21+
public String getDescription() {
22+
return "Signed 4-Byte Integer";
23+
}
24+
25+
@Override
26+
public int getLength() {
27+
return 4;
28+
}
29+
30+
@Override
31+
public UnsignedInteger4DataType getOppositeSignednessDataType() {
32+
return UnsignedInteger4DataType.dataType.clone(getDataTypeManager());
33+
}
34+
35+
@Override
36+
public Integer4DataType clone(DataTypeManager dtm) {
37+
if (dtm == getDataTypeManager()) {
38+
return this;
39+
}
40+
return new Integer4DataType(dtm);
41+
}
42+
43+
@Override
44+
public String getCTypeDeclaration(DataOrganization dataOrganization) {
45+
return getCTypeDeclaration(this, true, dataOrganization, false);
46+
}
47+
}

src/main/java/golanganalyzerextension/gobinary/PcHeader.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static int to_integer(GO_VERSION go_version) {
6262
public PcHeader(GolangBinary go_bin) throws InvalidBinaryStructureException {
6363
this.go_bin=go_bin;
6464

65-
this.addr=search_by_magic();
65+
this.addr=search_by_magic_all_ver();
6666
}
6767

6868
public PcHeader(GolangBinary go_bin, Address target_addr, GO_VERSION go_version, boolean little_endian) throws InvalidBinaryStructureException {
@@ -91,7 +91,7 @@ public boolean is_little_endian() {
9191
return little_endian;
9292
}
9393

94-
private Address search_by_magic() {
94+
private Address search_by_magic_all_ver() {
9595
Address result_addr=null;
9696
if(result_addr==null) {
9797
result_addr=search_by_magic(null, GO_VERSION.GO_12, true);
@@ -177,8 +177,9 @@ private Address search_by_magic(Address target_addr, GO_VERSION target_go_versio
177177
}else {
178178
func_list_base=go_bin.get_address(tmp_addr, 8+pointer_size);
179179
}
180-
long func_addr_value=go_bin.get_address_value(func_list_base, 0, is_go118?4:pointer_size);
181-
long func_info_offset=go_bin.get_address_value(func_list_base, is_go118?4:pointer_size, is_go118?4:pointer_size);
180+
int functab_field_size=is_go118?4:pointer_size;
181+
long func_addr_value=go_bin.get_address_value(func_list_base, 0, functab_field_size);
182+
long func_info_offset=go_bin.get_address_value(func_list_base, functab_field_size, functab_field_size);
182183
long func_entry_value;
183184
if(is_go118) {
184185
func_entry_value=go_bin.get_address_value(func_list_base, func_info_offset, 4);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package golanganalyzerextension.gobinary;
2+
3+
import ghidra.program.model.data.AbstractUnsignedIntegerDataType;
4+
import ghidra.program.model.data.DataTypeManager;
5+
6+
public class UnsignedInteger4DataType extends AbstractUnsignedIntegerDataType {
7+
8+
/** A statically defined UnsignedInteger4DataType instance.*/
9+
public final static UnsignedInteger4DataType dataType = new UnsignedInteger4DataType();
10+
11+
public UnsignedInteger4DataType() {
12+
this(null);
13+
}
14+
15+
public UnsignedInteger4DataType(DataTypeManager dtm) {
16+
super("uint4", dtm);
17+
}
18+
19+
@Override
20+
public String getDescription() {
21+
return "Unsigned 4-Byte Integer";
22+
}
23+
24+
@Override
25+
public int getLength() {
26+
return 4;
27+
}
28+
29+
@Override
30+
public Integer4DataType getOppositeSignednessDataType() {
31+
return Integer4DataType.dataType.clone(getDataTypeManager());
32+
}
33+
34+
@Override
35+
public UnsignedInteger4DataType clone(DataTypeManager dtm) {
36+
if (dtm == getDataTypeManager()) {
37+
return this;
38+
}
39+
return new UnsignedInteger4DataType(dtm);
40+
}
41+
}

0 commit comments

Comments
 (0)