GP-43 Clang review fixes/changes

This commit is contained in:
ghizard
2020-09-03 11:11:40 -04:00
parent 627ddc2e63
commit bb48b7433f
3 changed files with 54 additions and 35 deletions
@@ -901,7 +901,6 @@ public class PeLoader extends AbstractPeDebugLoader {
offsetChoice = CompilerEnum.Clang;
}
else if (dh.e_lfanew() < 0x80) {
// 0x78 checked for Clang above, but 0x7c fits here too
offsetChoice = CompilerEnum.Unknown;
}
else {
@@ -985,7 +984,7 @@ public class PeLoader extends AbstractPeDebugLoader {
}
// Check for AddressOfStart and PointerToSymbol
if (errStringChoice == CompilerEnum.GCC_VS && asmChoice == CompilerEnum.GCC_VS &&
if (errStringChoice == CompilerEnum.GCC_VS && asmChoice == CompilerEnum.GCC_VS_Clang &&
dh.e_lfanew() == 0x80) {
// Trying to determine if we have gcc or old VS
@@ -511,39 +511,6 @@ public class RttiModelTest extends AbstractRttiTest {
}
@Test
public void testInvalidRtti4_64NotVSOrClang() throws Exception {
ProgramBuilder builder = build64BitX86NonVS();
ProgramDB program = builder.getProgram();
setupRtti4_32(builder, 0x101001340L, 0, 0, 0, "0x00005364", "0x0000137c");
Address address = builder.addr(0x101001340L);
Rtti4Model model = new Rtti4Model(program, address, defaultValidationOptions);
try {
model.validate();
}
catch (InvalidDataTypeException e) {
assertEquals(
"RTTICompleteObjectLocator data type model is only valid for Visual Studio windows PE.",
e.getMessage());
}
}
@Test
public void testInvalidRtti4_64Clang() throws Exception {
ProgramBuilder builder = build64BitX86Clang();
ProgramDB program = builder.getProgram();
setupRtti4_32(builder, 0x101001340L, 0, 0, 0, "0x00005364", "0x0000137c");
Address address = builder.addr(0x101001340L);
Rtti4Model model = new Rtti4Model(program, address, defaultValidationOptions);
try {
model.validate();
}
catch (InvalidDataTypeException e) {
assertEquals("TypeDescriptor data type is not properly aligned at 101005364.",
e.getMessage());
}
}
@Test
public void testValidRtti4Model_64NoFollowFlow() throws Exception {
@@ -0,0 +1,53 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.app.plugin.prototype.MicrosoftCodeAnalyzerPlugin;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import ghidra.app.cmd.data.AbstractCreateDataTypeModelTest;
import ghidra.program.database.ProgramBuilder;
import ghidra.program.database.ProgramDB;
public class PEUtilTest extends AbstractCreateDataTypeModelTest {
@Test
public void testIsVisualStudioOrClangPeGivenVisualStudioPe() throws Exception {
ProgramBuilder builder = build64BitX86();
ProgramDB program = builder.getProgram();
boolean result = PEUtil.isVisualStudioOrClangPe(program);
assertTrue(result);
}
@Test
public void testIsVisualStudioOrClangPeGivenClangPe() throws Exception {
ProgramBuilder builder = build64BitX86Clang();
ProgramDB program = builder.getProgram();
boolean result = PEUtil.isVisualStudioOrClangPe(program);
assertTrue(result);
}
@Test
public void testIsVisualStudioOrClangPeGivenNotVisualStudioOrClangPe() throws Exception {
ProgramBuilder builder = build64BitX86NonVS();
ProgramDB program = builder.getProgram();
boolean result = PEUtil.isVisualStudioOrClangPe(program);
assertFalse(result);
}
}