Merge remote-tracking branch 'origin/ghidra1_Emulator'

Conflicts:
	gradle/root/eclipse.gradle
This commit is contained in:
ghidra1
2019-07-12 16:14:17 -04:00
257 changed files with 32702 additions and 232 deletions
+6
View File
@@ -63,3 +63,9 @@ Release
.project
.classpath
.settings/
# Ignore XTEXT generated dirs/files
*/*/*/*/xtend-gen
*/*/*/*/src-gen
*/*/*/*/model/generated
*/*/*/*/test-bin
+2
View File
@@ -1,3 +1,5 @@
apply from: file("../gpl.gradle").getCanonicalPath()
if (findProject(':Generic') != null) {
apply from: "$rootProject.projectDir/gradle/nativeProject.gradle"
apply from: "$rootProject.projectDir/gradle/distributableGPLModule.gradle"
+1
View File
@@ -4,3 +4,4 @@
Module.manifest||Public Domain||||END|
build.gradle||Public Domain||||END|
data/cabextract-1.6.tar.gz||GPL 3||||END|
settings.gradle||Public Domain||||END|
View File
+3 -2
View File
@@ -1,13 +1,13 @@
apply from: file("../gpl.gradle").getCanonicalPath()
if (findProject(':Generic') != null) {
apply from: "$rootProject.projectDir/gradle/javaProject.gradle"
apply from: "$rootProject.projectDir/gradle/distributableGPLModule.gradle"
rootProject.assembleDistribution {
doLast {
// eliminate standard module lib directory
def assemblePath = destinationDir.path + "/" + getZipPath(this.project)
println "DELETE: ${assemblePath}/lib"
delete assemblePath + "/lib"
}
}
@@ -28,6 +28,7 @@ eclipse.project.name = 'GPL DMG'
*
*********************************************************************************/
sourceSets {
dmg {
java {
srcDir 'src/dmg/java'
+1
View File
@@ -16,3 +16,4 @@ data/os/win64/llio_amd64.dll||GPL 3||||END|
data/os/win64/llio_i386.dll||GPL 3||||END|
data/os/win64/llio_ia64.dll||GPL 3||||END|
data/server_memory.cfg||Public Domain||||END|
settings.gradle||Public Domain||||END|
View File
+1
View File
@@ -1,3 +1,4 @@
apply from: file("../gpl.gradle").getCanonicalPath()
if (findProject(':Generic') != null) {
apply from: "$rootProject.projectDir/gradle/nativeProject.gradle"
+1
View File
@@ -6,4 +6,5 @@
##MODULE IP: Public Domain
Module.manifest||Public Domain||||END|
build.gradle||Public Domain||||END|
settings.gradle||Public Domain||||END|
src/demangler_gnu/README.txt||Public Domain||||END|
View File
View File
+20
View File
@@ -0,0 +1,20 @@
The GnuDisassembler extension module must be built using gradle prior to its' use within Ghidra.
This module provides the ability to leverage the binutils disassembler capabilities
for various processors as a means of verifying Sleigh disassembler output syntax.
To build this extension for Linux or Mac OS X:
1. If building for an installation of Ghidra, copy the appropriate source distribution of
binutils into this module's root directory. If building within a git clone of the full
Ghidra source, copy binutils source distribution file into the ghidra.bin/GPL/GnuDisassembler
directory.
The supported version and archive format is identified within the build.gradle file.
If a different binutils distribution is used the build.gradle and/or buildGdis.gradle
may require modification.
2. Run gradle from the module's root directory (see top of build.gradle file for
specific instructions).
This resulting gdis executable will be located in build/os/<platform>.
+81
View File
@@ -0,0 +1,81 @@
// If extension module does not reside within the Ghidra GPL directory, the Ghidra installation directory
// must be specified either by setting the GHIDRA_INSTALL_DIR environment variable or Gradle
// project property:
//
// > export GHIDRA_INSTALL_DIR=<Absolute path to Ghidra>
// > gradle build
//
// or
//
// > gradle -PGHIDRA_INSTALL_DIR=<Absolute path to Ghidra> build
//
// In addition, the appropriate binutils source distribution archive must be placed
// within this module's directory (see below for binutils version and archive file naming.
//
// Gradle should be invoked from the directory of the extension module to build. Please see the
// application.gradle.version property in <GHIDRA_INSTALL_DIR>/Ghidra/application.properties
// for the correction version of Gradle to use for the Ghidra installation you specify.
//
// Build Prerequisite:
// The appropriate binutils source distribution archive (see version and naming below) must be
// obtained and placed appropriately prior to building the gdis executable. If working with
// a full source distribution of Ghidra the binutils archive should be placed within the module's
// shadow directory located within ghidra.bin (ghidra.bin/GPL/GnuDisassembler/). If building within
// an unpacked distribution of Ghidra it should be placed directly within the module
// directory once the extension has been installed/unpacked by Ghidra. The binutils referenced
// by the script below may be downloaded from the following URL:
//
// https://ftp.gnu.org/pub/gnu/binutils/binutils-2.29.1.tar.bz2
//
ext.binutils = "binutils-2.29.1"
ext.binutilsDistro = "${binutils}.tar.bz2"
ext.ghidraInstallDir = null;
if (file("../gpl.gradle").exists()) {
// Module is located within the Ghidra GPL directory
ext.ghidraInstallDir = file("../..").getCanonicalPath()
ext.binutilsLocation = file("${ghidraInstallDir}/../ghidra.bin/GPL/${name}").getCanonicalPath()
apply from: file("../gpl.gradle").getCanonicalPath()
}
else {
// various module placements for Ghidra installations
ext.binutilsLocation = projectDir
if (file("../../../GPL/gpl.gradle").exists()) {
// Handle GPL extension install within Ghidra Extensions directory
ext.ghidraInstallDir = file("../../..").getCanonicalPath()
}
else {
// Handle extension install outside of Ghidra installation - must specify Ghidra install path
if (System.env.GHIDRA_INSTALL_DIR) {
ext.ghidraInstallDir = System.env.GHIDRA_INSTALL_DIR
}
else if (project.hasProperty("GHIDRA_INSTALL_DIR")) {
ext.ghidraInstallDir = project.getProperty("GHIDRA_INSTALL_DIR")
}
}
if (ghidraInstallDir) {
if (ghidraInstallDir.replace("\\","/").endsWith("/")) {
ext.ghidraInstallDir = ghidraInstallDir.substring(0, ghidraInstallDir.length()-1)
}
println "Building with Ghidra installation at $ghidraInstallDir"
apply from: new File(ghidraInstallDir).getCanonicalPath() + "/GPL/gpl.gradle"
}
else {
throw new GradleException("GHIDRA_INSTALL_DIR is not defined!")
}
}
if (findProject(':Generic') != null) {
// Handle integrated Ghidra build - do not build gdis native
apply from: "$rootProject.projectDir/gradle/distributableGPLExtension.gradle"
delete file("build/os"); // remove any prior build of gdis
}
else {
apply from: "${ghidraInstallDir}/GPL/nativeBuildProperties.gradle"
apply from: "buildGdis.gradle"
}
apply plugin: 'eclipse'
eclipse.project.name = 'Xtra GPL GnuDisassembler'
+169
View File
@@ -0,0 +1,169 @@
/*******************************************************************************************
* build.gradle file that applies this script must define two properties
* 1) binutilsLocation - the folder where the original binutils.zip lives
* 2) binutilsPrebuiltPath - the folder where the custom prebuilt binutils lives or will be built to
*******************************************************************************************/
defaultTasks 'assemble'
ext.supportedPlatforms = ['osx64', 'linux64']
ext.binutilsResource = new File("${binutilsLocation}/${binutils}.tar.bz2")
def binutilsUnpackDir = file("${project.buildDir}/${binutils}/")
/******************************************************************************************
*
* For each supported platform build the following tasks:
* buildBinutils_<platform> builds binutils for the platform
* packageBinutilsDev_<platform> creates the built bundle of stuf we need to build gdis
* unpackBinutilsPrebuilt_<platform> unpacks the built bundle to be used to build gdis
*
******************************************************************************************/
model {
platforms {
linux64 {
architecture 'x86_64'
operatingSystem 'linux'
}
osx64 {
architecture 'x86_64'
operatingSystem 'osx'
}
}
components {
gdis(NativeExecutableSpec) {
// NOTE: Windows build requires Mingw and is very very slow and touchy
supportedPlatforms.each { targetPlatform it}
sources {
c {
source {
srcDir "src/gdis/c"
include "disasm_1.c"
}
}
}
binaries {
all {
def binutilsArtifactsDir = file("build/binutils/${targetPlatform.name}")
if ((toolChain in Gcc) || (toolChain in Clang)) {
cCompiler.args "-I${binutilsArtifactsDir}/include", "-I${binutilsArtifactsDir}/bfd"
linker.args "-L${binutilsArtifactsDir}/lib", "-lopcodes", "-lbfd", "-liberty", "-lz", "-ldl"
}
}
}
}
}
tasks.compileGdisOsx64ExecutableGdisC {
dependsOn 'copyBinutilsArtifcats_osx64'
}
tasks.compileGdisLinux64ExecutableGdisC {
dependsOn 'copyBinutilsArtifcats_linux64'
}
}
// change gdis linker output directory to build/os/<platform>
gradle.taskGraph.whenReady {
def p = this.project
p.tasks.withType(LinkExecutable).each { t ->
File f = t.linkedFile.getAsFile().get()
String filename = f.getName()
NativePlatform platform = t.targetPlatform.get()
String osName = platform.getName()
t.linkedFile = p.file("build/os/${osName}/$filename")
}
}
/*******************************************************************************************
* Task to unpack the standard binutils zip file
*******************************************************************************************/
task binutilsUnpack {
description "Unpack binutils (for building gdis)"
group "Native Build Dependencies"
outputs.file { binutilsUnpackDir }
onlyIf { !binutilsUnpackDir.exists() }
doFirst {
if (!binutilsResource.exists()) {
throw new GradleException("${binutilsResource.getCanonicalPath()} not found")
}
}
doLast {
copy {
from tarTree(resources.bzip2("${binutilsResource}"))
into file("build")
}
}
}
supportedPlatforms.each { platform ->
def buildName = "buildBinutils_${platform}"
def postBuildName = "copyBinutilsArtifcats_${platform}"
def configDir = file("build/config/${platform}")
def artifactsDir = file("build/binutils/${platform}")
task(buildName) {
description "Configure and make binutils for $platform (for building gdis)"
group "Native Prebuild Dependencies"
onlyIf { !configDir.exists() }
dependsOn binutilsUnpack
inputs.dir binutilsUnpackDir
outputs.dir configDir
doLast {
File binutilsDir = binutilsUnpackDir
delete configDir
println "Configuring binutils - config directory: $configDir"
println "${binutilsDir}/configure --prefix=\"${configDir}\" --enable-targets=all --with-zlib=no --disable-nls --disable-werror"
configDir.mkdirs();
exec {
workingDir configDir
commandLine "${binutilsDir}/configure", "--prefix=${configDir}", "--enable-targets=all", "--with-zlib=no", "--disable-nls", "--disable-werror"
}
println "Building binutils - config directory: $configDir"
exec {
commandLine "make", "-C", "${configDir}", "all"
}
}
}
task(postBuildName, type: Copy) {
description "Copy binutil artifcacts for $platform (for building gdis)"
group "Native Prebuild Dependencies"
dependsOn buildName
destinationDir = artifactsDir
into("/include") {
from("${binutilsUnpackDir}/include")
include "**/*.h"
}
into("/bfd") {
from "${configDir}/bfd"
include "**/*.h"
}
into("/lib") {
from "${configDir}/bfd/libbfd.a"
from "${configDir}/libiberty/libiberty.a"
from "${configDir}/opcodes/libopcodes.a"
}
}
}
@@ -0,0 +1,13 @@
##VERSION: 2.0
##MODULE IP: GPL 2
##MODULE IP: Public Domain
.project||GHIDRA||||END|
Module.manifest||Public Domain||||END|
README.txt||Public Domain||||END|
build.gradle||Public Domain||||END|
buildGdis.gradle||Public Domain||||END|
data/arm_test1.s||Public Domain||||END|
data/big.elf||Public Domain||||END|
data/little.elf||Public Domain||||END|
extension.properties||Public Domain||||END|
settings.gradle||Public Domain||||END|
+7
View File
@@ -0,0 +1,7 @@
.text
__start:
lw $t0, #4
li $t1, #0
add $t2, $t0, $t1
done
Binary file not shown.
Binary file not shown.
+6
View File
@@ -0,0 +1,6 @@
name=GnuDisassembler
description=GNU Disassembler. Extension is delivered unbuilt. See module README.txt for build instructions.
author=Ghidra Team
createdOn=6/18/2019
version=@extversion@
gpl=true
View File
+457
View File
@@ -0,0 +1,457 @@
/* ###
* IP: Public Domain
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "bfd.h"
#include "dis-asm.h"
// #include "bucomm.h" // for set_default_bfd_target()
#include "gdis.h"
#define MAX_ASCII_CHAR_BYTE_STRING 256
void listSupportedArchMachTargets(void)
{
const char** targetList;
const char** archList;
int i, j;
targetList = bfd_target_list();
if(targetList != NULL){
for(i=0, j=0; targetList[i] !=0; i++){
printf("Supported Target: %s\n", targetList[i]);
}
}
printf("\ndone with targetList.\n");
archList = bfd_arch_list();
if(archList != NULL){
for(i=0, j=0; archList[i] !=0; i++){
printf("Supported Arch: %s\n", archList[i]);
}
}
printf("\ndone with archList.\n");
}
/* sprintf to a "stream". */
int objdump_sprintf (SFILE *f, const char *format, ...)
{
int i;
size_t n;
va_list args;
va_start (args, format);
n = vsnprintf (f->buffer + f->pos, BUFF_SIZE, format, args);
strncat(disassembled_buffer, f->buffer, n);
va_end (args);
return n;
}
void configureDisassembleInfo(bfd* abfd,
disassemble_info* info,
enum bfd_architecture arch,
unsigned long mach,
enum bfd_endian end)
{
memset(sfile.buffer, 0x00, BUFF_SIZE);
INIT_DISASSEMBLE_INFO(*info, stdout, objdump_sprintf);
info->arch = (enum bfd_architecture) arch;
info->mach = mach;
info->flavour = bfd_get_flavour(abfd);
info->endian = end;
info->stream = (FILE*)&sfile; // set up our "buffer stream"
info->display_endian = BFD_ENDIAN_LITTLE;
/* Allow the target to customize the info structure. */
disassemble_init_for_target(info);
}
disassembler_ftype configureBfd(bfd* abfd,
enum bfd_architecture arch,
unsigned long mach,
enum bfd_endian endian,
disassemble_info* DI,
disassembler_ftype* disassemble_fn)
{
struct bfd_target *xvec;
abfd->flags |= EXEC_P;
// set up xvec byteorder.
xvec = (struct bfd_target *) malloc (sizeof (struct bfd_target));
memset(xvec, 0x00, sizeof (struct bfd_target));
memcpy (xvec, abfd->xvec, sizeof (struct bfd_target));
xvec->byteorder = endian;
abfd->xvec = xvec;
configureDisassembleInfo(abfd, DI, arch, mach, endian);
if(endian == BFD_ENDIAN_BIG){
bfd_big_endian(abfd);
DI->display_endian = DI->endian = BFD_ENDIAN_BIG;
}
else{
bfd_little_endian(abfd);
DI->display_endian = DI->endian = BFD_ENDIAN_LITTLE;
}
/*
bfd_error_type err = bfd_get_error();
printf("bfd_error_msg: %s.\n", bfd_errmsg(err));
*/
/* Use libopcodes to locate a suitable disassembler. */
*disassemble_fn = NULL;
*disassemble_fn = disassembler (arch, endian == BFD_ENDIAN_BIG, mach, abfd);
if (!*disassemble_fn){
printf("can't disassemble for arch 0x%08X, mach 0x%08lX\n", arch, mach);
exit(1);
}
return *disassemble_fn;
}
int disassemble_buffer( disassembler_ftype disassemble_fn,
disassemble_info *info,
int* offset,
PDIS_INFO pDisInfo)
{
int i, j, size = 0;
int len = 0;
while ( *offset < info->buffer_length ) {
/* call the libopcodes disassembler */
memset(pDisInfo->disassemblyString, 0x00, MAX_DIS_STRING);
/* set the insn_info_valid bit to 0, as explained in BFD's
* include/dis-asm.h. The bit will then be set to tell us
* whether the decoder supports "extra" information about the
* instruction.
*/
info->insn_info_valid = 0;
size = (*disassemble_fn)(info->buffer_vma + *offset, info);
/* -- analyze disassembled instruction here -- */
/* -- print any symbol names as labels here -- */
/* save off corresponding hex bytes */
for ( j= 0,i = 0; i < 8; i++, j+=3) {
if ( i < size ){
sprintf(&(pDisInfo->bytesBufferAscii[j]), "%02X ", info->buffer[*offset + i]);
pDisInfo->bytesBufferBin[i] = info->buffer[*offset + i];
}
}
/* add the augmented information to our disassembly info struct */
pDisInfo->count = size;
pDisInfo->insn_info_valid = info->insn_info_valid;
pDisInfo->branch_delay_insns = info->branch_delay_insns;
pDisInfo->data_size = info->data_size;
pDisInfo->insn_type = info->insn_type;
pDisInfo->target = info->target;
pDisInfo->target2 = info->target2;
strcat(&(pDisInfo->disassemblyString[0]), disassembled_buffer);
memset(disassembled_buffer, 0x00, BUFF_SIZE);
if(size != 0){
*offset += size; /* advance position in buffer */
goto END;
}
}
END:
return size;
}
void processBuffer(unsigned char* buff,
int buff_len,
bfd_vma buff_vma,
disassembler_ftype disassemble_fn,
struct disassemble_info* DI)
{
int bytesConsumed = -1;
int offset = 0;
int numDisassemblies = 0;
int i;
DI->buffer = buff; /* buffer of bytes to disassemble */
DI->buffer_length = buff_len; /* size of buffer */
DI->buffer_vma = buff_vma; /* base RVA of buffer */
memset(disassemblyInfoBuffer, 0x00, sizeof(DIS_INFO)*MAX_NUM_ENTRIES);
while((buff_len - offset) > 0 && bytesConsumed != 0 && numDisassemblies < MAX_NUM_ENTRIES){
bytesConsumed = disassemble_buffer( disassemble_fn, DI, &offset, &(disassemblyInfoBuffer[numDisassemblies++]));
}
for (i = 0; i < numDisassemblies; i++) {
printf("%s\nInfo: %d,%d,%d,%d,%d\n", disassemblyInfoBuffer[i].disassemblyString,
disassemblyInfoBuffer[i].count,
disassemblyInfoBuffer[i].insn_info_valid,
disassemblyInfoBuffer[i].branch_delay_insns,
disassemblyInfoBuffer[i].data_size,
disassemblyInfoBuffer[i].insn_type);
}
}
int main(int argc, char* argv[]){
struct disassemble_info DI;
enum bfd_architecture arch;
struct bfd_arch_info ai;
unsigned long mach;
enum bfd_endian endian;
unsigned int end;
bfd_vma offset;
disassembler_ftype disassemble_fn;
char *target = default_target;
bfd *bfdfile;
unsigned long a,m;
char* byteString;
char elf_file_location[MAX_ELF_FILE_PATH_LEN];
char arch_str[256];
char mach_str[256];
if ( argc < 8) {
fprintf(stderr, "Usage: %s target-str, arch, mach, disassembly base-addr (for rel offsets instrs), full-path to Little and Big Elfs, big/little ascii-byte-string up to %d chars\n", argv[0], MAX_ASCII_CHAR_BYTE_STRING);
listSupportedArchMachTargets();
const char** archList = bfd_arch_list();
const bfd_arch_info_type* ait;
while(*archList != NULL){
printf("checking against architecture: %s.\n", *archList);
ait = NULL;
ait = bfd_scan_arch(*archList);
if(ait != NULL){
printf("archname: %s arch: 0x%08X, mach: 0x%08lX.\n", ait->arch_name, ait->arch, ait->mach);
}
archList++;
}
return(1);
}
end = 0x00000000;
endian = (enum bfd_endian) 0x00;
mach = 0x00000000;
arch = (enum bfd_architecture) 0x00;
offset = 0x00000000;
sscanf(argv[2], "%128s", arch_str);
sscanf(argv[3], "%18lX", &mach);
sscanf(argv[4], "%10X", &end);
sscanf(argv[5], "%18lX", &offset);
// if arch starts with 0x, then parse a number
// else lookup the string in the table to get the arch, ignore the mach
if (arch_str[0] == '0' && arch_str[1] == 'x') {
sscanf(arch_str, "%10X", &arch);
} else {
const char** archList = bfd_arch_list();
const bfd_arch_info_type* ait;
while(*archList != NULL){
ait = bfd_scan_arch(*archList);
if(strcmp(arch_str, *archList)== 0){
arch = ait->arch;
mach = ait->mach;
break;
}
ait = NULL;
archList++;
}
if (ait == NULL) {
printf("Couldn't find arch %s\n", arch_str);
return(-1);
}
}
endian = (enum bfd_endian) end;
/* open a correct type of file to fill in most of the required data. */
// printf("Arch is: 0x%08X, Machine is: 0x%08lX Endian is: 0x%02X.\n", arch, mach, endian);
memset(elf_file_location, 0x00, MAX_ELF_FILE_PATH_LEN);
strncpy(elf_file_location, argv[6], MAX_ELF_FILE_PATH_LEN-sizeof(LITTLE_ELF_FILE)-2); // actual file name and nulls
// arg[7] is either a hex string or the string "stdin", which
// triggers reading line by line from stdin.
byteString = argv[7];
int stdin_mode = 2; // use CLI
if (strcmp(byteString, "stdin") == 0) {
stdin_mode = 1; // use STDIN
}
unsigned char byteBuffer[BYTE_BUFFER_SIZE];
char byteStringBuffer[(BYTE_BUFFER_SIZE*2)];
char addressStringBuffer[128];
if (endian == BFD_ENDIAN_BIG){
strcat(elf_file_location, BIG_ELF_FILE);
}
else {
strcat(elf_file_location, LITTLE_ELF_FILE);
}
while (stdin_mode) {
// convert user input AsciiHex to Binary data for processing
char tmp[3];
unsigned int byteValue;
tmp[0] = tmp[1] = tmp[2] = 0x00;
if (stdin_mode == 1) { // use stdin
// read in the address
if (fgets(addressStringBuffer, sizeof(addressStringBuffer), stdin)) {
//fprintf(stderr, "read: %s\n", addressStringBuffer);
//char *p = strchr(addressStringBuffer, '\n');
//if (p) {
// *p = '\0';
//}
sscanf(addressStringBuffer, "%18lX", &offset);
}
//getchar();
// read in the ASCII hex string from stdin
if (fgets(byteStringBuffer, sizeof(byteStringBuffer), stdin)) {
//fprintf(stderr, "read: %s\n", byteStringBuffer);
// remove trailing newline
char *p = strchr(byteStringBuffer, '\n');
if (p) {
*p = '\0';
}
//if (strcmp(byteStringBuffer, "EOF") == 0) {
//return 0; // terminate on EOF string
//}
} else {
fprintf(stderr, "exiting, no ASCII hex found\n");
return 0; // finished! #TODO
}
} else {
if(strlen(byteString) > BYTE_BUFFER_SIZE*2) {
fprintf(stderr, "Max ascii string size is %d you provided: %lu chars. Exiting.\n", BYTE_BUFFER_SIZE*2,
strlen(byteString));
exit(-1);
}
strncpy(byteStringBuffer, byteString, BYTE_BUFFER_SIZE*2);
stdin_mode = 0; // break out of the while loop
}
int size = strlen(byteStringBuffer);
if((size % 2) != 0){
fprintf(stderr, "need even-number of ascii chars for byte-stream: (offset: %08lx, %s, %ld)\n", offset, byteStringBuffer, strlen(byteStringBuffer));
exit(-1);
}
memset(byteBuffer, 0x00, BYTE_BUFFER_SIZE);
//
// TODO:
// check to make sure chars are only valid HEX.
//
int i, j;
for(i=j=0; (i < size) && (j < BYTE_BUFFER_SIZE); i+=2, j++){
tmp[0] = byteStringBuffer[i];
tmp[1] = byteStringBuffer[i+1];
tmp[2] = 0;
sscanf(tmp, "%02X", &byteValue);
byteBuffer[j] = (unsigned char)byteValue;
}
/*
for(j=0; j < BYTE_BUFFER_SIZE; j++){
printf("0x%02X ", byteBuffer[j]);
}
*/
bfd_init( );
target = argv[1];
bfd_set_default_target(target);
// printf("Debug: BFD sample file: %s\n", elf_file_location);
// printf("Debug: LITTLE: %s\n", LITTLE_ELF_FILE);
// printf("Debug: BIG: %s\n", BIG_ELF_FILE);
if(endian == BFD_ENDIAN_BIG){
bfdfile = bfd_openr(elf_file_location, target );
if ( ! bfdfile ) {
printf("Error opening BIG ELF file: %s\n", elf_file_location);
bfd_perror( "Error on bfdfile" );
return(3);
}
}
else{
bfdfile = bfd_openr(elf_file_location, target );
if ( ! bfdfile ) {
printf("Error opening LITTLE ELF file: %s\n", elf_file_location);
// bfdfile = bfd_openr(elf_file_location, target );
bfd_perror( "Error on bfdfile" );
return(3);
}
}
memset((void*) &DI, 0x00, sizeof(struct disassemble_info));
disassemble_fn = NULL;
// important set up!
//---------------------------------------
ai.arch = arch;
ai.mach = mach;
bfd_set_arch_info(bfdfile, &ai);
//---------------------------------------
/*
bfd_error_type err = bfd_get_error();
printf("bfd_error_msg: %s.\n", bfd_errmsg(err));
*/
configureBfd(bfdfile, arch, mach, endian, &DI, &disassemble_fn);
/*
err = bfd_get_error();
printf("bfd_error_msg: %s.\n", bfd_errmsg(err));
*/
if (disassemble_fn == NULL){
fprintf(stderr, "Error: disassemble_fn is NULL. Nothing I can do.\n");
exit(1);
}
else{
/*
printf("the disassemble_fn func pointer is: 0x%08X.\n", disassemble_fn);
printf("We can try to disassemble for this arch/mach. calling disassemble_init_for_target().\n");
*/
disassemble_init_for_target(&DI);
// go diassemble the buffer and build up the result in a accumulator string buffer.
processBuffer(byteBuffer, size >> 1, offset, disassemble_fn, &DI); //
}
free((void*)bfdfile->xvec);
bfd_close(bfdfile);
printf("EOF\n");
fflush(stdout);
} // while loop on lines of stdin
return 0;
}
+94
View File
@@ -0,0 +1,94 @@
/* ###
* IP: Public Domain
*/
#ifndef _GDIS_H_
#define _GDIS_H_
#define BYTE_BUFFER_SIZE 128
#define LITTLE_ELF_FILE "little.elf" // built for intel x64
#define BIG_ELF_FILE "big.elf"
#define BUFF_SIZE 128
#define MAX_DIS_STRING 128
#define MAX_BYTES_STRING 64
#define MAX_BYTES 64
#define MAX_NUM_ENTRIES 64
#define MAX_ELF_FILE_PATH_LEN 512
typedef struct _DIS_INFO_{
char disassemblyString[MAX_DIS_STRING];
char bytesBufferAscii[MAX_BYTES_STRING];
unsigned char bytesBufferBin[MAX_BYTES];
int count; /* Number of bytes consumed */
char insn_info_valid; /* Branch info has been set. */
char branch_delay_insns; /* How many sequential insn's will run before
a branch takes effect. (0 = normal) */
char data_size; /* Size of data reference in insn, in bytes */
enum dis_insn_type insn_type; /* Type of instruction */
bfd_vma target; /* Target address of branch or dref, if known;
zero if unknown. */
bfd_vma target2; /* Second target address for dref2 */
} DIS_INFO, *PDIS_INFO;
static DIS_INFO disassemblyInfoBuffer[MAX_NUM_ENTRIES];
char mnemonic[32] = {0}, src[32] = {0}, dest[32] = {0}, arg[32] = {0};
char disassembled_buffer[BUFF_SIZE];
/* Pseudo FILE object for strings. */
typedef struct
{
// char *buffer;
char buffer[BUFF_SIZE];
size_t pos;
size_t alloc;
} SFILE;
static SFILE sfile;
static char *default_target = NULL; /* Default at runtime. */
// ------------------------------------------------------------------------
void listSupportedArchMachTargets(void);
int objdump_sprintf (SFILE *f, const char *format, ...);
void configureDisassembleInfo(bfd* abfd,
disassemble_info* info,
enum bfd_architecture arch,
unsigned long mach,
enum bfd_endian end);
disassembler_ftype configureBfd(bfd* abfd,
enum bfd_architecture arch,
unsigned long mach,
enum bfd_endian endian,
disassemble_info* DI,
disassembler_ftype* disassemble_fn);
int disassemble_buffer( disassembler_ftype disassemble_fn,
disassemble_info *info,
int* offset,
PDIS_INFO pDisInfo);
void processBuffer(unsigned char* buff,
int buff_len,
bfd_vma buff_vma,
disassembler_ftype disassemble_fn,
struct disassemble_info* DI);
#endif
+1 -2
View File
@@ -1,5 +1,4 @@
##VERSION: 2.0
##MODULE IP: Public Domain
build.gradle||Public Domain||||END|
gpl.gradle||Public Domain||||END|
nativeBuildProperties.gradle||Public Domain||||END|
settings.gradle||Public Domain||||END|
+10 -5
View File
@@ -1,11 +1,13 @@
project.ext.BIN_REPO = file("${projectDir}/../../ghidra.bin").absolutePath
// BIN_REPO only useable in full Ghidra source configuration
project.ext.BIN_REPO = file("../../../ghidra.bin").absolutePath
project.ext.set("OS_NAMES", ["osx64", "win32", "win64", "linux64"])
/*********************************************************************************
* Returns the local platform name.
*********************************************************************************/
String getCurrentPlatformName() {
ext.getCurrentPlatformName = {
String osName = System.getProperty("os.name")
String archName = System.getProperty("os.arch")
@@ -37,10 +39,13 @@ String getCurrentPlatformName() {
* Helper method that returns a file that is the same relative location in the bin repo
* as the given project is in its repo.
******************************************************************************************/
File getProjectLocationInBinRepo(Project p) {
String relativePath = getGhidraRelativePath(p)
ext.getProjectLocationInBinRepo = {
String relativePath = getGhidraRelativePath(this.project)
println("RELATIVE: $relativePath")
File binRepoRootProject = new File("${BIN_REPO}")
if (!binRepoRootProject.isDirectory()) {
throw new GradleException("Task requires Ghidra source and ghidra.bin")
}
return new File(binRepoRootProject, relativePath)
}
/****************************************************************************************
-4
View File
@@ -1,4 +0,0 @@
include "DemanglerGnu"
include "DMG"
include "CabExtract"
@@ -0,0 +1,9 @@
apply from: "$rootProject.projectDir/gradle/distributableGhidraExtension.gradle"
apply from: "$rootProject.projectDir/gradle/javaProject.gradle"
apply from: "$rootProject.projectDir/gradle/javaTestProject.gradle"
apply plugin: 'eclipse'
eclipse.project.name = 'Xtra SleighDevTools'
dependencies {
compile project(':Base')
}
@@ -0,0 +1,34 @@
##VERSION: 2.0
.classpath||GHIDRA||||END|
.project||GHIDRA||||END|
Module.manifest||GHIDRA||||END|
build.gradle||GHIDRA||||END|
data/ExtensionPoint.manifest||GHIDRA||||END|
data/LanguageMap.txt||GHIDRA||||END|
extension.properties||GHIDRA||||END|
pcodetest/.gitignore||GHIDRA||||END|
pcodetest/README.txt||GHIDRA||||END|
pcodetest/build||GHIDRA||||END|
pcodetest/build.py||GHIDRA||||END|
pcodetest/c_src/BIOPS.test||GHIDRA||||END|
pcodetest/c_src/BIOPS2.test||GHIDRA||||END|
pcodetest/c_src/BIOPS_DOUBLE.test||GHIDRA||||END|
pcodetest/c_src/BIOPS_FLOAT.test||GHIDRA||||END|
pcodetest/c_src/BIOPS_LONGLONG.test||GHIDRA||||END|
pcodetest/c_src/BitManipulation.test||GHIDRA||||END|
pcodetest/c_src/DecisionMaking.test||GHIDRA||||END|
pcodetest/c_src/GlobalVariables.test||GHIDRA||||END|
pcodetest/c_src/IterativeProcessingDoWhile.test||GHIDRA||||END|
pcodetest/c_src/IterativeProcessingFor.test||GHIDRA||||END|
pcodetest/c_src/IterativeProcessingWhile.test||GHIDRA||||END|
pcodetest/c_src/ParameterPassing1.test||GHIDRA||||END|
pcodetest/c_src/ParameterPassing2.test||GHIDRA||||END|
pcodetest/c_src/ParameterPassing3.test||GHIDRA||||END|
pcodetest/c_src/PointerManipulation.test||GHIDRA||||END|
pcodetest/c_src/StructUnionManipulation.test||GHIDRA||||END|
pcodetest/c_src/misc.test||GHIDRA||||END|
pcodetest/c_src/msp430x.ld||GHIDRA||||END|
pcodetest/defaults.py||GHIDRA||||END|
pcodetest/pcode_defs.py||GHIDRA||||END|
pcodetest/pcodetest.py||GHIDRA||||END|
pcodetest/tpp.py||GHIDRA||||END|
@@ -0,0 +1 @@
ExternalDisassembler
@@ -0,0 +1,13 @@
// Format: LanguageID#CustomGDISExecutable
//
// Mapping of LanguageNameFromGhidra to external (gdis) architecture names is no longer done here.
// This functionality has been moved to each language's ldefs file.
// External names are mapped via 'external_name' tags in language definitions.
// The CustomGDISExecutable is found via a call to Application.getOSFile(), which will search in
// the platform-specific OS directory within all modules.
//
// Lines starting with "//" are not parsed.
//
// '*' can be used to wild-card parts of the languageID
//
@@ -0,0 +1,5 @@
name=SleighDevTools
description=Sleigh language development tools including external disassembler capabilities. The GnuDisassembler extension may be also be required as a disassembly provider.
author=Ghidra Team
createdOn=6/18/2019
version=@extversion@
@@ -0,0 +1,320 @@
/* ###
* 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.
*/
// Compare Sliegh disassembly with external disassembly results
import java.util.HashMap;
import java.util.List;
import ghidra.app.script.GhidraScript;
import ghidra.app.util.PseudoDisassembler;
import ghidra.app.util.PseudoInstruction;
import ghidra.app.util.disassemble.GNUExternalDisassembler;
import ghidra.program.disassemble.Disassembler;
import ghidra.program.model.address.*;
import ghidra.program.model.lang.Register;
import ghidra.program.model.lang.UnknownInstructionException;
import ghidra.program.model.listing.BookmarkType;
import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.scalar.Scalar;
import ghidra.util.exception.CancelledException;
public class CompareSleighExternal extends GhidraScript {
@Override
public void run() throws Exception {
if (currentProgram == null) {
return;
}
AddressSetView set = currentSelection;
if (set == null || set.isEmpty()) {
set = currentProgram.getMemory().getLoadedAndInitializedAddressSet();
}
putEquivalent("xzr", "x31"); // Think they messed up and allowed x31, there is no x31
putEquivalent("wzr", "w31"); // Think they messed up and allowed w31, there is no w31
putEquivalent("r12", "ip");
int completed = 0;
monitor.initialize(set.getNumAddresses());
AddressIterator addresses = set.getAddresses(true);
PseudoDisassembler pseudoDisassembler = new PseudoDisassembler(currentProgram);
GNUExternalDisassembler dis = new GNUExternalDisassembler();
long align = currentProgram.getLanguage().getInstructionAlignment();
while (addresses.hasNext()) {
monitor.checkCanceled();
Address addr = addresses.next();
completed++;
// only on valid boundaries
if ((addr.getOffset() % align) != 0) {
continue;
}
clearBad(addr);
monitor.setProgress(completed);
CodeUnit cu = currentProgram.getListing().getCodeUnitAt(addr);
if (cu == null) {
continue;
}
String str = dis.getDisassembly(cu);
str = str.toLowerCase();
PseudoInstruction pinst = null;
try {
pinst = pseudoDisassembler.disassemble(addr);
} catch (UnknownInstructionException e) {
// didn't get an instruction, did external not get one?
if (str.startsWith(".inst") && str.endsWith("undefined")) {
continue;
}
markErrorBad(addr,"Unimplemented Instruction", str);
continue;
}
// didn't get an instruction, did external not get one?
if (pinst == null && str.startsWith(".inst") && str.endsWith("undefined")) {
continue;
}
if (pinst == null) {
markErrorBad(addr,"Unimplemented Instruction", str);
continue;
}
// collapse both instruction to strings, compare removing whitespace, and to-lower
String pStr = pinst.toString().toLowerCase().replaceAll("\\s","");
String eStr = str.toLowerCase().replaceAll("\\s", "");
// simple equivalence
if (pStr.equals(eStr)) {
continue;
}
String mnemonic = pinst.getMnemonicString().toLowerCase();
if (!str.startsWith(mnemonic)) {
markBad(addr,"Mnemonic Disagreement", str + " != " + mnemonic);
continue;
}
int start = str.indexOf(" ");
for (int opIndex = 0; opIndex < pinst.getNumOperands(); opIndex++) {
// try to parse the operand string from the instruction
int sepEnd = str.indexOf(",", start);
String extOp = getExtOpStr(str, start, sepEnd);
start = sepEnd + 1;
String valStr = null;
// TODO: could remove all characters, making sure none are left!
int loc = 0;
boolean subRegList = false;
List<Object> opObjList = pinst.getDefaultOperandRepresentationList(opIndex);
for (Object object : opObjList) {
if (object instanceof Character) {
Character ch = (Character) object;
ch = Character.toLowerCase(ch);
loc = extOp.indexOf(ch);
if (loc != -1) {
extOp = extOp.substring(0,loc) + extOp.substring(loc+1);
continue;
}
if (ch.equals(',')) {
if (subRegList) {
continue;
}
// gotta move into next string, must be embedded comma
sepEnd = str.indexOf(",", start);
extOp = getExtOpStr(str, start, sepEnd);
start = sepEnd + 1;
continue;
}
if (ch.equals(' ')) {
continue;
}
markBad(addr,"Missing String Markup", ch.toString());
break;
}
if (object instanceof Scalar) {
// find the scalar, hex or decimal
Scalar scalar = (Scalar) object;
valStr = scalar.toString(16, false, false, "0x", "");
loc = extOp.indexOf(valStr);
if (loc != -1) {
extOp = extOp.substring(0,loc) + extOp.substring(loc+valStr.length());
continue;
}
valStr = scalar.toString(16, true, false, "0x", "");
loc = extOp.indexOf(valStr);
if (loc != -1) {
extOp = extOp.substring(0,loc) + extOp.substring(loc+valStr.length());
continue;
}
valStr = scalar.toString(10, false, true, "", "");
loc = extOp.indexOf(valStr);
if (loc != -1) {
extOp = extOp.substring(0,loc) + extOp.substring(loc+valStr.length());
continue;
}
valStr = scalar.toString(10, false, false, "", "");
loc = extOp.indexOf(valStr);
if (loc != -1) {
extOp = extOp.substring(0,loc) + extOp.substring(loc+valStr.length());
continue;
}
valStr = scalar.toString(16, false, false, "", "");
loc = extOp.indexOf(valStr);
if (loc != -1) {
extOp = extOp.substring(0,loc) + extOp.substring(loc+valStr.length());
continue;
}
valStr = scalar.toString(16, true, false, "", "");
loc = extOp.indexOf(valStr);
if (loc != -1) {
extOp = extOp.substring(0,loc) + extOp.substring(loc+valStr.length());
continue;
}
markBad(addr,"Missing Scalar", valStr);
break;
}
if (object instanceof Register) {
Register reg = (Register) object;
loc = extOp.indexOf(reg.getName().toLowerCase());
if (loc != -1) {
// check for '-' first
if (extOp.charAt(0) == '-') {
extOp = extOp.substring(1);
loc = 0;
subRegList = false;
}
extOp = extOp.substring(0,loc) + extOp.substring(loc+reg.getName().length());
if (extOp.length() > 0 && extOp.charAt(0) == '-') {
subRegList = true;
}
continue;
}
// check for equivalent register
String equivReg = regGetEquivalent(reg.getName());
if (equivReg != null) {
loc = extOp.indexOf(equivReg);
if (loc != -1) {
extOp = extOp.substring(0,loc) + extOp.substring(loc+equivReg.length());
continue;
}
}
loc = extOp.indexOf('-'); // could be a register list, assume we will find beginning and end register
if (loc != -1) {
continue;
}
markBad(addr,"Missing Register", reg.toString());
break;
}
if (object instanceof Address) {
Address dest = (Address) object;
valStr = dest.toString(false,true);
valStr = "0x" + valStr;
loc = extOp.indexOf(valStr);
if (loc != -1) {
extOp = extOp.substring(0,loc) + extOp.substring(loc+valStr.length());
continue;
}
valStr = dest.toString(false,false);
valStr = "0x" + valStr;
loc = extOp.indexOf(valStr);
if (loc != -1) {
extOp = extOp.substring(0,loc) + extOp.substring(loc+valStr.length());
continue;
}
valStr = dest.toString(false,true);
loc = extOp.indexOf(valStr);
if (loc != -1) {
extOp = extOp.substring(0,loc) + extOp.substring(loc+valStr.length());
continue;
}
valStr = dest.toString(false,false);
loc = extOp.indexOf(valStr);
if (loc != -1) {
extOp = extOp.substring(0,loc) + extOp.substring(loc+valStr.length());
continue;
}
markBad(addr,"Missing Address", dest.toString());
}
}
extOp = extOp.trim();
if (extOp.length() > 0 && !extOp.startsWith(";") && !extOp.startsWith("//") && !extOp.equals("#") && !extOp.matches("[0x]+")) {
markBad(addr,"Missing characters", extOp);
}
}
}
}
HashMap<String, String> equivRegisters = new HashMap<String, String>();
private String regGetEquivalent(String name) {
return equivRegisters.get(name);
}
private void putEquivalent(String name, String equiv) {
equivRegisters.put(name, equiv);
}
private String getExtOpStr(String str, int start, int sepEnd) {
String opS = null;
if (start == -1) {
return "";
}
if (sepEnd == -1) {
opS = str.substring(start);
} else {
opS = str.substring(start, sepEnd);
}
String extOp = opS.trim();
return extOp;
}
private void markBad(Address addr, String type, String error) {
currentProgram.getBookmarkManager().setBookmark(addr, BookmarkType.WARNING,
type,
error);
}
private void markErrorBad(Address addr, String type, String error) {
currentProgram.getBookmarkManager().setBookmark(addr, BookmarkType.ERROR,
Disassembler.ERROR_BOOKMARK_CATEGORY,
error);
}
private void clearBad(Address addr) {
AddressSet set = new AddressSet(addr);
try {
currentProgram.getBookmarkManager().removeBookmarks(set, BookmarkType.WARNING, monitor);
currentProgram.getBookmarkManager().removeBookmarks(set, BookmarkType.ERROR, monitor);
} catch (CancelledException e) {
// do nothing
}
}
}
@@ -0,0 +1,79 @@
/* ###
* 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.
*/
import ghidra.app.script.GhidraScript;
import ghidra.app.util.disassemble.GNUExternalDisassembler;
import ghidra.app.util.disassemble.GnuDisassembledInstruction;
import ghidra.program.model.address.Address;
import java.util.List;
public class GNUDisassembleBlockScript extends GhidraScript {
@Override
protected void run() throws Exception {
if (currentProgram == null || currentAddress == null) {
return;
}
GNUExternalDisassembler dis = new GNUExternalDisassembler();
Address addr = currentAddress.getNewAddress(currentAddress.getOffset() & -32); // block aligned address
List<GnuDisassembledInstruction> results = dis.getBlockDisassembly(currentProgram, addr, 5);
if (results == null) {
println("Block Disassembly Failed!");
return;
}
int maxByteLen = 0;
for (GnuDisassembledInstruction result : results) {
maxByteLen = Math.max(maxByteLen, result.getNumberOfBytesInInstruction());
}
StringBuilder sb = new StringBuilder();
for (GnuDisassembledInstruction result : results) {
sb.append(addr.toString());
sb.append(' ');
int cnt = 0;
byte[] bytes = new byte[result.getNumberOfBytesInInstruction()];
currentProgram.getMemory().getBytes(addr, bytes);
for (byte b : bytes) {
if (b >= 0 && b < 0x10) {
sb.append('0');
}
sb.append(Integer.toHexString(b & 0xff));
sb.append(' ');
++cnt;
}
if (cnt < maxByteLen) {
int pad = (maxByteLen - cnt) * 3;
for (int i = 0; i < pad; i++) {
sb.append(' ');
}
}
sb.append(result.getInstruction());
sb.append("\n");
addr = addr.add(bytes.length);
}
if (sb.length() != 0) {
println("Block Disassembly:\n" + sb.toString());
}
}
}
@@ -0,0 +1 @@
*.pyc
@@ -0,0 +1,31 @@
OVERVIEW
--------
The executable 'build' file in this directory is a python script for
building pcode test binaries. Each pcode test binary is built using
an associated toolchain.
The list of available pcode test binaries is in the file pcode_defs.py.
Each entry in this file indicates the required toolchain, and additional
options needed to build the pcode test.
The defaults.py script should be modified to suit your environment
reflecting the installation location of your toolchains, build artifacts, etc.
USAGE
-----
To see a list of available options, run the build script without
arguments.
./build
It is possible to build everything from scratch with this command:
./build --pcodetest-all
Typically, pcode test binaries are built individually per processor,
such as:
./build --pcodetest MIPS16
+91
View File
@@ -0,0 +1,91 @@
#!/usr/bin/python
import os
import sys
import argparse
import traceback
import json
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
from build import *
from pcodetest import *
# set default properties first, then update values from the command
# line before they are instantiated.
execfile('defaults.py')
parser = argparse.ArgumentParser(description='''Build pcodetests.
One and only one of the following options must be given:
[--pcodetest, --pcodetest-all, --pcodetest-list]''',
epilog='(*) default properties for pcodetest instances',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# all-applicable arguments
parser.add_argument('-f', '--force', action='store_true', help='force a build')
parser.add_argument('-v', '--verbose', action='store_true', help='verbose output where available ')
parser.add_argument('--toolchain-root', default=PCodeTest.defaults.toolchain_root, help='directory where toolchain directories can be found (*)')
parser.add_argument('--build-root', default=PCodeTest.defaults.build_root, help='temporary directory to hold build files (*)')
parser.add_argument('--gcc-version', default=PCodeTest.defaults.gcc_version, help='default version of gcc (*)')
# required alternates
required_group = parser.add_mutually_exclusive_group(required=True)
required_group.add_argument('--pcodetest', help='the pcode test to build')
required_group.add_argument('--pcodetest-all', action='store_true', help='build all pcode tests')
required_group.add_argument('--pcodetest-list', action='store_true', help='list available pcode tests')
# pcodetest arguments
pcodetest_group = parser.add_argument_group('pcodetest', 'pcodetest options')
pcodetest_group.add_argument('--no-publish', action='store_true', help='do not publish pcode test binaries to pcode test root')
pcodetest_group.add_argument('--pcodetest-root', default=PCodeTest.defaults.pcodetest_root, help='location to publish pcode tests binaries (*)')
pcodetest_group.add_argument('--pcodetest-src', default=PCodeTest.defaults.pcodetest_src, help='location of pcode test .c and .h source files (*)')
pcodetest_group.add_argument('--skip-files', nargs='+', default=PCodeTest.defaults.skip_files, help='default .c files to remove from the pcode test image (*)')
pcodetest_group.add_argument('--strip-symbols', action='store_true', help='strip symbols from image')
pcodetest_group.add_argument('--add-ccflags', default='', help='additional flags to pass to compiler (must be quoted)')
pcodetest_group.add_argument('--add-info', action='store_true', help='add data to binary with information about types and symbols')
pcodetest_group.add_argument('--build-exe', action='store_true', help='build a guest executable binary (exe)')
pcodetest_group.add_argument('--variants', default=json.dumps(PCodeTest.defaults.variants, sort_keys=True, separators=(',',':')), type=json.loads, help='build the (optimization) variants, encoded as a json dict')
sys.argv.pop(0)
args = parser.parse_args(sys.argv)
PCodeTest.defaults.skip_files = args.skip_files
PCodeTest.defaults.pcodetest_root = args.pcodetest_root
PCodeTest.defaults.pcodetest_src = args.pcodetest_src
PCodeTest.defaults.strip_symbols = args.strip_symbols
PCodeTest.defaults.add_ccflags = args.add_ccflags
PCodeTest.defaults.add_info = args.add_info
PCodeTest.defaults.build_exe = args.build_exe
PCodeTest.defaults.variants = args.variants
PCodeTest.defaults.verbose = args.verbose
PCodeTest.defaults.force = args.force
PCodeTest.defaults.no_publish = args.no_publish
# load the known pcodetests
execfile('pcode_defs.py')
cwd = os.getcwd()
if args.pcodetest_list:
PCodeTest.print_all()
elif args.pcodetest_all:
for n,pct in sorted(PCodeTest.list.iteritems(), key=lambda x: x[0].lower()):
if pct.config.build_all:
try: PCodeTestBuild.factory(pct).main()
except Exception as e:
print 'unhandled exception while building %s' % n
traceback.print_exc(file=sys.stdout)
os.chdir(cwd)
elif args.pcodetest:
if args.pcodetest in PCodeTest.list:
PCodeTest = PCodeTest.list[args.pcodetest]
PCodeTestBuild.factory(PCodeTest).main()
else:
print 'the pcode test %s is not in the list' % args.pcodetest
else:
parser.print_help()
@@ -0,0 +1,291 @@
import os
import shutil
import subprocess
import sys
import pwd
import grp
import re
class BuildUtil(object):
def __init__(self):
self.log = False
self.name = False
self.num_errors = 0
self.num_warnings = 0
def run(self, cmd, stdout=False, stderr=False, verbose=True):
if isinstance(cmd, basestring):
if stdout and stderr:
cmd += ' 1>%s 2>%s' % (stdout, stderr)
elif stdout and not stderr:
cmd += ' 1>%s 2>&1' % (stdout)
elif not stdout and stderr:
cmd += ' 2>%s' % (stderr)
if verbose: self.log_info(cmd)
os.system(cmd)
else:
str = ' '.join(cmd);
if stdout:
f = file(stdout, 'w+')
str += ' 1>%s 2>&1' % (stdout)
else:
f = subprocess.PIPE
if verbose: self.log_info(str)
try:
sp = subprocess.Popen(cmd, stdout=f, stderr=subprocess.PIPE)
except OSError as e:
self.log_err(cmd)
self.log_err(e)
return 0,e.message#raise
if stdout: f.close()
out, err = sp.communicate()
# print 'run returned %d bytes stdout and %d bytes stderr' % (len(out) if out else 0, len(err) if err else 0)
return out, err
def isdir(self, dname):
return os.path.isdir(dname)
def getcwd(self):
return os.getcwd()
def basename(self, fname):
return os.path.basename(fname)
def dirname(self, fname):
return os.path.dirname(fname)
def getmtime(self, fname):
return os.path.getmtime(fname)
def isfile(self, fname):
return os.path.isfile(fname)
def getenv(self, var, dflt):
return os.getenv(var, dflt)
def pw_name(self, fname):
return pwd.getpwuid(os.stat(fname).st_uid).pw_name
def gr_name(self, fname):
return grp.getgrgid(os.stat(fname).st_gid).gr_name
def isatty(self):
return os.isatty(sys.stdin.fileno())
def is_readable_file(self, fname):
if not self.isfile(fname):
self.log_warn('%s does not exist' % fname)
return False
if os.stat(fname).st_size == 0:
self.log_warn('%s is empty' % fname)
return False
if os.access(fname, os.R_OK) == 0:
self.log_warn('%s is not readable' % fname)
return False
return True
def is_executable_file(self, fname):
if not self.is_readable_file(fname): return False
if os.access(fname, os.X_OK) == 0:
self.log_warn('%s is not executable' % fname)
return False
return True
# export a file to a directory
def export_file(self, fname, dname,):
try:
if not os.path.isdir(dname):
self.makedirs(dname)
if os.path.isfile(fname):
self.copy(fname, dname, verbose=True)
elif os.path.isdir(fname):
self.copy(fname, dname, dir=True, verbose=True)
except IOError as e:
self.log_err('Error occurred exporting %s to %s' % (fname, dname))
self.log_err("Unexpected error: %s" % str(e))
def rmtree(self, dir, verbose=True):
if verbose: self.log_info('rm -r %s' % dir)
shutil.rmtree(dir)
def makedirs(self, dir, verbose=True):
if verbose: self.log_info('mkdir -p %s' % dir)
try: os.makedirs(dir)
except: pass
# copy a file to a directory
def copy(self, fname, dname, verbose=True, dir=False):
if not dir:
if verbose: self.log_info('cp -av %s %s' % (fname, dname))
shutil.copy(fname, dname)
else:
if verbose: self.log_info('cp -avr %s %s' % (fname, dname))
if os.path.exists(dname):
shutil.rmtree(dname)
shutil.copytree(fname, dname)
def chdir(self, dir, verbose=True):
if verbose: self.log_info('cd %s' % dir)
os.chdir(dir)
def remove(self, fname, verbose=True):
if verbose: self.log_info('rm -f %s' % fname)
try: os.remove(fname)
except: pass
def environment(self, var, val, verbose=True):
if verbose: self.log_info('%s=%s' % (var, val))
os.environ[var] = val
def unlink(self, targ, verbose=True):
if verbose: self.log_info('unlink %s' % targ)
os.unlink(targ)
def symlink(self, src, targ, verbose=True):
if verbose: self.log_info('ln -s %s %s' % (src, targ))
if os.path.islink(targ):
os.unlink(targ)
os.symlink(src, targ)
def build_dir(self, root, kind, what):
return root + "/" + re.sub(r'[^a-zA-Z0-9_-]+', '_', 'build-%s-%s' % (kind, what))
def log_prefix(self, kind, what):
return kind.upper() + ' ' + what
def open_log(self, root, kind, what, chdir=False):
build_dir = self.build_dir(root, kind, what)
# Get the name of the log file
logFile = '%s/log.txt' % build_dir
self.log_info('%s LOGFILE %s' % (self.log_prefix(kind, what), logFile))
try: self.rmtree(build_dir, verbose=False)
except: pass
self.makedirs(build_dir, verbose=False)
self.log_open(logFile)
if chdir: self.chdir(build_dir)
def log_open(self, name):
if self.log: self.log_close()
self.log = open(name, 'w')
self.name = name
def log_close(self):
if self.log:
if self.num_errors > 0:
print '# ERROR: There were errors, see %s' % self.name
elif self.num_warnings > 0:
print '# WARNING: There were warnings, see %s' % self.name
self.log.close()
self.log = False
self.name = False
self.num_errors = 0
self.num_warnings = 0
def log_pr(self, what):
if self.log:
self.log.write(what + '\n')
self.log.flush()
else:
print what
sys.stdout.flush()
def log_err(self, what):
self.log_pr('# ERROR: ' + what)
self.num_errors += 1
def log_warn(self, what):
self.log_pr('# WARNING: ' + what)
self.num_warnings += 1
def log_info(self, what):
self.log_pr('# INFO: ' + what)
# create a file with size, type, and symbol info
# the function is here because it is useful and has no dependencies
def mkinfo(self, fname):
ifdefs = { 'i8':'HAS_LONGLONG', 'u8':'HAS_LONGLONG', 'f4':'HAS_FLOAT', 'f8':'HAS_DOUBLE' }
sizes = [
'char', 'signed char', 'unsigned char',
'short', 'signed short', 'unsigned short',
'int', 'signed int', 'unsigned int',
'long', 'signed long', 'unsigned long',
'long long', 'signed long long', 'unsigned long long',
'float', 'double', 'float', 'long double',
'i1', 'i2', 'i4', 'u1', 'u2', 'u4', 'i8', 'u8', 'f4', 'f8']
syms = [
'__AVR32__', '__AVR_ARCH__', 'dsPIC30', '__GNUC__', '__has_feature', 'INT4_IS_LONG',
'__INT64_TYPE__', '__INT8_TYPE__', '__llvm__', '_M_ARM_FP', '__MSP430__', '_MSV_VER',
'__SDCC', '__SIZEOF_DOUBLE__', '__SIZEOF_FLOAT__', '__SIZEOF_SIZE_T__', '__TI_COMPILER_VERSION__',
'__INT8_TYPE__', '__INT16_TYPE__', '__INT32_TYPE__', '__INT64_TYPE__', '__UINT8_TYPE__',
'__UINT16_TYPE__', '__UINT32_TYPE__', '__UINT64_TYPE__', 'HAS_FLOAT', 'HAS_DOUBLE',
'HAS_LONGLONG', 'HAS_FLOAT_OVERRIDE', 'HAS_DOUBLE_OVERRIDE', 'HAS_LONGLONG_OVERRIDE']
typedefs = { 'i1':1, 'i2':2, 'i4':4, 'u1':1, 'u2':2, 'u4':4, 'i8':8, 'u8':8, 'f4':4, 'f8':8 }
f = open(fname, 'w')
f.write('#include "types.h"\n\n')
i = 0
for s in sizes:
i += 1
d = 'INFO sizeof(%s) = ' % s
x = list(d)
x = "', '".join(x)
x = "'%s', '0'+sizeof(%s), '\\n'" % (x, s)
l = 'char size_info_%d[] = {%s};\n' % (i, x)
if s in ifdefs: f.write('#ifdef %s\n' % ifdefs[s])
f.write(l)
if s in ifdefs: f.write('#endif\n')
for s in typedefs:
if s in ifdefs: f.write('#ifdef %s\n' % ifdefs[s])
f.write('_Static_assert(sizeof(%s) == %d, "INFO %s should have size %d, is not correct\\n");\n' % (s, typedefs[s], s, typedefs[s]))
if s in ifdefs: f.write('#endif\n')
for s in syms:
i += 1
f.write('#ifdef %s\n' % s)
f.write('char sym_info_%d[] = "INFO %s is defined\\n\";\n' % (i, s))
f.write('#else\n')
f.write('char sym_info_%d[] = "INFO %s is not defined\\n\";\n' % (i, s))
f.write('#endif\n')
f.close()
class Config(object):
def __init__(self, *obj):
for o in obj:
if isinstance(o, dict): self.__dict__.update(o)
else: self.__dict__.update(o.__dict__)
def format(self, val):
if isinstance(val, basestring) and '%' in val:
return val % self.__dict__
elif isinstance(val, dict):
return dict(map(lambda (k,v): (k,self.format(v)), val.iteritems()))
else: return val
def __getattr__(self, attr):
return ''
def expand(self):
for k,v in self.__dict__.iteritems():
self.__dict__[k] = self.format(v)
def dump(self):
ret = ''
for k,v in sorted(self.__dict__.iteritems()):
if isinstance(v, basestring): vv = "'" + v + "'"
else: vv = str(v)
ret += ' '.ljust(10) + k.ljust(20) + vv + '\n'
return ret
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,197 @@
#include "pcode_test.h"
#ifdef HAS_DOUBLE
TEST biopEqf8f8_Main()
{
extern f8 biopEqf8f8(f8 lhs, f8 rhs);
f8 lhs = 2;
f8 rhs = 1;
f8 retVal;
retVal = biopEqf8f8(lhs, rhs);
ASSERTF8(retVal, 0);
ASSERTF8(biopEqf8f8(PI_SHORT, PI_SHORT), 1.0);
ASSERTF8(biopEqf8f8(PI_SHORT, 2*PI_SHORT), 0.0);
ASSERTF8(biopEqf8f8(2*PI_SHORT, PI_SHORT), 0.0);
}
#endif
#ifdef HAS_DOUBLE
TEST biopNef8f8_Main()
{
extern f8 biopNef8f8(f8 lhs, f8 rhs);
f8 lhs = 2;
f8 rhs = 1;
f8 retVal;
retVal = biopNef8f8(lhs, rhs);
ASSERTF8(retVal, 1);
ASSERTF8(biopNef8f8(PI_SHORT, PI_SHORT), 0.0);
ASSERTF8(biopNef8f8(PI_SHORT, 2*PI_SHORT), 1.0);
ASSERTF8(biopNef8f8(2*PI_SHORT, PI_SHORT), 1.0);
}
#endif
#ifdef HAS_DOUBLE
TEST biopLogicOrf8f8_Main()
{
extern f8 biopLogicOrf8f8(f8 lhs, f8 rhs);
f8 lhs = 2;
f8 rhs = 1;
f8 retVal;
retVal = biopLogicOrf8f8(lhs, rhs);
ASSERTF8(retVal, 1);
ASSERTF8(biopLogicOrf8f8(PI_SHORT, PI_SHORT), 1);
ASSERTF8(biopLogicOrf8f8(PI_SHORT, 0), 1);
}
#endif
#ifdef HAS_DOUBLE
TEST biopLogicAndf8f8_Main()
{
extern f8 biopLogicAndf8f8(f8 lhs, f8 rhs);
f8 lhs = 2;
f8 rhs = 1;
f8 retVal;
retVal = biopLogicAndf8f8(lhs, rhs);
ASSERTF8(retVal, 1);
ASSERTF8(biopLogicAndf8f8(PI_SHORT, PI_SHORT), 1);
ASSERTF8(biopLogicAndf8f8(PI_SHORT, 0), 0.0);
}
#endif
#ifdef HAS_DOUBLE
TEST unopNotf8_Main()
{
extern f8 unopNotf8(f8 lhs);
f8 lhs = 2;
f8 retVal;
retVal = unopNotf8(lhs);
ASSERTF8(retVal, 0);
ASSERTF8(unopNotf8(PI_SHORT), 0);
}
#endif
#ifdef HAS_DOUBLE
TEST unopNegativef8_Main()
{
extern f8 unopNegativef8(f8 lhs);
f8 lhs = 2;
f8 retVal;
retVal = unopNegativef8(lhs);
ASSERTF8(retVal, -2);
ASSERTF8(unopNegativef8(PI_SHORT), -3.14);
}
#endif
#ifdef HAS_DOUBLE
TEST unopPlusf8_Main()
{
extern f8 unopPlusf8(f8 lhs);
f8 lhs = 2;
f8 retVal;
retVal = unopPlusf8(lhs);
ASSERTF8(retVal, 2);
ASSERTF8(unopPlusf8(PI_SHORT), PI_SHORT);
}
#endif
#ifdef HAS_DOUBLE
TEST biopMultf8f8_Main()
{
extern f8 biopMultf8f8(f8 lhs, f8 rhs);
f8 lhs = 2;
f8 rhs = 1;
f8 retVal;
retVal = biopMultf8f8(lhs, rhs);
ASSERTF8(retVal, 2);
ASSERTF8(biopMultf8f8(PI_SHORT, PI_SHORT), 9.8596);
}
#endif
#ifdef HAS_DOUBLE
TEST biopSubf8f8_Main()
{
extern f8 biopSubf8f8(f8 lhs, f8 rhs);
f8 lhs = 2;
f8 rhs = 1;
f8 retVal;
retVal = biopSubf8f8(lhs, rhs);
ASSERTF8(retVal, 1);
ASSERTF8(biopSubf8f8(PI_SHORT, PI_SHORT), 0.0);
}
#endif
#ifdef HAS_DOUBLE
TEST biopAddf8f8_Main()
{
extern f8 biopAddf8f8(f8 lhs, f8 rhs);
f8 lhs = 2;
f8 rhs = 1;
f8 retVal;
retVal = biopAddf8f8(lhs, rhs);
ASSERTF8(retVal, 3);
ASSERTF8(biopAddf8f8(PI_SHORT, PI_SHORT), 6.28);
}
#endif
#ifdef HAS_DOUBLE
TEST biopGtf8f8_Main()
{
extern f8 biopGtf8f8(f8 lhs, f8 rhs);
f8 lhs = 2;
f8 rhs = 1;
f8 retVal;
retVal = biopGtf8f8(lhs, rhs);
ASSERTF8(retVal, 1);
ASSERTF8(biopGtf8f8(PI_SHORT, PI_SHORT), 0.0);
ASSERTF8(biopGtf8f8(PI_SHORT, 2*PI_SHORT), 0.0);
ASSERTF8(biopGtf8f8(2*PI_SHORT, PI_SHORT), 1.0);
}
#endif
#ifdef HAS_DOUBLE
TEST biopGef8f8_Main()
{
extern f8 biopGef8f8(f8 lhs, f8 rhs);
f8 lhs = 2;
f8 rhs = 1;
f8 retVal;
retVal = biopGef8f8(lhs, rhs);
ASSERTF8(retVal, 1);
ASSERTF8(biopGef8f8(PI_SHORT, PI_SHORT), 1.0);
ASSERTF8(biopGef8f8(PI_SHORT, 2*PI_SHORT), 0.0);
ASSERTF8(biopGef8f8(2*PI_SHORT, PI_SHORT), 1.0);
}
#endif
#ifdef HAS_DOUBLE
TEST biopLtf8f8_Main()
{
extern f8 biopLtf8f8(f8 lhs, f8 rhs);
f8 lhs = 2;
f8 rhs = 1;
f8 retVal;
retVal = biopLtf8f8(lhs, rhs);
ASSERTF8(retVal, 0);
ASSERTF8(biopLtf8f8(PI_SHORT, PI_SHORT), 0.0);
ASSERTF8(biopLtf8f8(PI_SHORT, 2*PI_SHORT), 1.0);
ASSERTF8(biopLtf8f8(2*PI_SHORT, PI_SHORT), 0.0);
}
#endif
#ifdef HAS_DOUBLE
TEST biopLef8f8_Main()
{
extern f8 biopLef8f8(f8 lhs, f8 rhs);
f8 lhs = 2;
f8 rhs = 1;
f8 retVal;
retVal = biopLef8f8(lhs, rhs);
ASSERTF8(retVal, 0);
ASSERTF8(biopLef8f8(PI_SHORT, PI_SHORT), 1.0);
ASSERTF8(biopLef8f8(PI_SHORT, 2*PI_SHORT), 1.0);
ASSERTF8(biopLef8f8(2*PI_SHORT, PI_SHORT), 0.0);
}
#endif
MAIN BIOPS_DOUBLE_main() { }
@@ -0,0 +1,131 @@
/* ###
* 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.
*/
#include "pcode_test.h"
#ifdef HAS_DOUBLE
f8 biopEqf8f8(f8 lhs, f8 rhs)
{
f8 z;
z = lhs == rhs;
return z;
}
f8 biopNef8f8(f8 lhs, f8 rhs)
{
f8 z;
z = lhs != rhs;
return z;
}
f8 biopLogicOrf8f8(f8 lhs, f8 rhs)
{
f8 z;
z = lhs || rhs;
return z;
}
f8 biopLogicAndf8f8(f8 lhs, f8 rhs)
{
f8 z;
z = lhs && rhs;
return z;
}
f8 unopNotf8(f8 lhs)
{
f8 z;
z = !lhs;
return z;
}
f8 unopNegativef8(f8 lhs)
{
f8 z;
z = -lhs;
return z;
}
f8 unopPlusf8(f8 lhs)
{
f8 z;
z = +lhs;
return z;
}
f8 biopMultf8f8(f8 lhs, f8 rhs)
{
f8 z;
z = lhs * rhs;
return z;
}
f8 biopSubf8f8(f8 lhs, f8 rhs)
{
f8 z;
z = lhs - rhs;
return z;
}
f8 biopAddf8f8(f8 lhs, f8 rhs)
{
f8 z;
z = lhs + rhs;
return z;
}
f8 biopGtf8f8(f8 lhs, f8 rhs)
{
f8 z;
z = lhs > rhs;
return z;
}
f8 biopGef8f8(f8 lhs, f8 rhs)
{
f8 z;
z = lhs >= rhs;
return z;
}
f8 biopLtf8f8(f8 lhs, f8 rhs)
{
f8 z;
z = lhs < rhs;
return z;
}
f8 biopLef8f8(f8 lhs, f8 rhs)
{
f8 z;
z = lhs <= rhs;
return z;
}
#endif /* #ifdef HAS_DOUBLE */
@@ -0,0 +1,169 @@
#include "pcode_test.h"
#ifdef HAS_FLOAT
TEST biopCmpf4f4_Main()
{
extern f4 biopCmpf4f4(f4 lhs, f4 rhs);
ASSERTF4(biopCmpf4f4(0x1, 0x1), 21);
ASSERTF4(biopCmpf4f4(0x1, 0x2), 21);
ASSERTF4(biopCmpf4f4(0x2, 0x1), 22);
ASSERTF4(biopCmpf4f4(-0x1, -0x1), 21);
ASSERTF4(biopCmpf4f4(-0x1, -0x2), 21);
ASSERTF4(biopCmpf4f4(-0x2, -0x1), 24);
}
#endif
#ifdef HAS_DOUBLE
TEST biopCmpf8f8_Main()
{
extern f8 biopCmpf8f8(f8 lhs, f8 rhs);
ASSERTF8(biopCmpf8f8(0x1, 0x1), 21);
ASSERTF8(biopCmpf8f8(0x1, 0x2), 21);
ASSERTF8(biopCmpf8f8(0x2, 0x1), 22);
ASSERTF8(biopCmpf8f8(-0x1, -0x1), 21);
ASSERTF8(biopCmpf8f8(-0x1, -0x2), 21);
ASSERTF8(biopCmpf8f8(-0x2, -0x1), 24);
}
#endif
#ifdef HAS_FLOAT
TEST biopLtf4f4_Main()
{
extern f4 biopLtf4f4(f4 lhs, f4 rhs);
f4 lhs = 2;
f4 rhs = 1;
f4 retVal;
ASSERTF4(biopLtf4f4(lhs, rhs), 0);
}
#endif
#ifdef HAS_FLOAT
TEST biopLef4f4_Main()
{
extern f4 biopLef4f4(f4 lhs, f4 rhs);
ASSERTF4(biopLef4f4(2, 1), 0);
ASSERTF4(biopLef4f4(PI_SHORT, 2*PI_SHORT), 1.0);
ASSERTF4(biopLef4f4(PI_SHORT, PI_SHORT), 1.0);
ASSERTF4(biopLef4f4(2*PI_SHORT, PI_SHORT), 0.0);
}
#endif
#ifdef HAS_FLOAT
TEST biopEqf4f4_Main()
{
extern f4 biopEqf4f4(f4 lhs, f4 rhs);
ASSERTF4(biopEqf4f4(2, 1), 0);
ASSERTF4(biopEqf4f4(PI_SHORT, PI_SHORT), 1.0);
ASSERTF4(biopEqf4f4(PI_SHORT, 2*PI_SHORT), 0.0);
ASSERTF4(biopEqf4f4(2*PI_SHORT, PI_SHORT), 0.0);
}
#endif
#ifdef HAS_FLOAT
TEST biopNef4f4_Main()
{
extern f4 biopNef4f4(f4 lhs, f4 rhs);
ASSERTF4(biopNef4f4(2, 1), 1);
ASSERTF4(biopNef4f4(PI_SHORT, PI_SHORT), 0.0);
ASSERTF4(biopNef4f4(PI_SHORT, 2*PI_SHORT), 1.0);
ASSERTF4(biopNef4f4(2*PI_SHORT, PI_SHORT), 1.0);
}
#endif
#ifdef HAS_FLOAT
TEST biopLogicOrf4f4_Main()
{
extern f4 biopLogicOrf4f4(f4 lhs, f4 rhs);
ASSERTF4(biopLogicOrf4f4(2, 1), 1);
ASSERTF4(biopLogicOrf4f4(PI_SHORT, PI_SHORT), 1);
ASSERTF4(biopLogicOrf4f4(PI_SHORT, 0), 1);
}
#endif
#ifdef HAS_FLOAT
TEST biopLogicAndf4f4_Main()
{
extern f4 biopLogicAndf4f4(f4 lhs, f4 rhs);
ASSERTF4(biopLogicAndf4f4(2, 1), 1);
ASSERTF4(biopLogicAndf4f4(PI_SHORT, PI_SHORT), 1);
ASSERTF4(biopLogicAndf4f4(PI_SHORT, 0), 0.0);
}
#endif
#ifdef HAS_FLOAT
TEST unopNotf4_Main()
{
extern f4 unopNotf4(f4 lhs);
ASSERTF4(unopNotf4(2), 0);
ASSERTF4(unopNotf4(PI_SHORT), 0);
}
#endif
#ifdef HAS_FLOAT
TEST unopNegativef4_Main()
{
extern f4 unopNegativef4(f4 lhs);
ASSERTF4(unopNegativef4(2), -2);
ASSERTF4(unopNegativef4(PI_SHORT), -3.14);
}
#endif
#ifdef HAS_FLOAT
TEST unopPlusf4_Main()
{
extern f4 unopPlusf4(f4 lhs);
ASSERTF4(unopPlusf4(2), 2);
ASSERTF4(unopPlusf4(PI_SHORT), PI_SHORT);
}
#endif
#ifdef HAS_FLOAT
TEST biopMultf4f4_Main()
{
extern f4 biopMultf4f4(f4 lhs, f4 rhs);
ASSERTF4(biopMultf4f4(2, 1), 2);
ASSERTF4(biopMultf4f4(PI_SHORT, PI_SHORT), 9.859601);
}
#endif
#ifdef HAS_FLOAT
TEST biopSubf4f4_Main()
{
extern f4 biopSubf4f4(f4 lhs, f4 rhs);
ASSERTF4(biopSubf4f4(2, 1), 1);
ASSERTF4(biopSubf4f4(PI_SHORT, PI_SHORT), 0.0);
}
#endif
#ifdef HAS_FLOAT
TEST biopAddf4f4_Main()
{
extern f4 biopAddf4f4(f4 lhs, f4 rhs);
ASSERTF4(biopAddf4f4(2, 1), 3);
ASSERTF4(biopAddf4f4(PI_SHORT, PI_SHORT), 6.280000);
}
#endif
#ifdef HAS_FLOAT
TEST biopGtf4f4_Main()
{
extern f4 biopGtf4f4(f4 lhs, f4 rhs);
ASSERTF4(biopGtf4f4(2, 1), 1);
ASSERTF4(biopGtf4f4(PI_SHORT, PI_SHORT), 0.0);
ASSERTF4(biopGtf4f4(PI_SHORT, 2*PI_SHORT), 0.0);
ASSERTF4(biopGtf4f4(2*PI_SHORT, PI_SHORT), 1.0);
}
#endif
#ifdef HAS_FLOAT
TEST biopGef4f4_Main()
{
extern f4 biopGef4f4(f4 lhs, f4 rhs);
ASSERTF4(biopGef4f4(2, 1), 1);
ASSERTF4(biopGef4f4(PI_SHORT, PI_SHORT), 1.0);
ASSERTF4(biopGef4f4(PI_SHORT, 2*PI_SHORT), 0.0);
ASSERTF4(biopGef4f4(2*PI_SHORT, PI_SHORT), 1.0);
}
#endif
MAIN BIOPS_FLOAT_main() { }
@@ -0,0 +1,157 @@
/* ###
* 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.
*/
#include "pcode_test.h"
#ifdef HAS_FLOAT
f4 biopCmpf4f4(f4 lhs, f4 rhs)
{
if (lhs < 0)
lhs += 2;
if (lhs > 0)
lhs += 4;
if (lhs == 0)
lhs += 8;
if (lhs != rhs)
lhs += 16;
return lhs;
}
f8 biopCmpf8f8(f8 lhs, f8 rhs)
{
if (lhs < 0)
lhs += 2;
if (lhs > 0)
lhs += 4;
if (lhs == 0)
lhs += 8;
if (lhs != rhs)
lhs += 16;
return lhs;
}
f4 biopLtf4f4(f4 lhs, f4 rhs)
{
f4 z;
z = lhs < rhs;
return z;
}
f4 biopLef4f4(f4 lhs, f4 rhs)
{
f4 z;
z = lhs <= rhs;
return z;
}
f4 biopEqf4f4(f4 lhs, f4 rhs)
{
f4 z;
z = lhs == rhs;
return z;
}
f4 biopNef4f4(f4 lhs, f4 rhs)
{
f4 z;
z = lhs != rhs;
return z;
}
f4 biopLogicOrf4f4(f4 lhs, f4 rhs)
{
f4 z;
z = lhs || rhs;
return z;
}
f4 biopLogicAndf4f4(f4 lhs, f4 rhs)
{
f4 z;
z = lhs && rhs;
return z;
}
f4 unopNotf4(f4 lhs)
{
f4 z;
z = !lhs;
return z;
}
f4 unopNegativef4(f4 lhs)
{
f4 z;
z = -lhs;
return z;
}
f4 unopPlusf4(f4 lhs)
{
f4 z;
z = +lhs;
return z;
}
f4 biopMultf4f4(f4 lhs, f4 rhs)
{
f4 z;
z = lhs * rhs;
return z;
}
f4 biopSubf4f4(f4 lhs, f4 rhs)
{
f4 z;
z = lhs - rhs;
return z;
}
f4 biopAddf4f4(f4 lhs, f4 rhs)
{
f4 z;
z = lhs + rhs;
return z;
}
f4 biopGtf4f4(f4 lhs, f4 rhs)
{
f4 z;
z = lhs > rhs;
return z;
}
f4 biopGef4f4(f4 lhs, f4 rhs)
{
f4 z;
z = lhs >= rhs;
return z;
}
#endif /* #ifdef HAS_FLOAT */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,403 @@
/* ###
* 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.
*/
#include "pcode_test.h"
#ifdef HAS_LONGLONG
i8 pcode_i8_complexLogic(i8 a, i8 b, i8 c, i8 d, i8 e, i8 f)
{
i8 ret = 0;
if (a > b && b > c || d < e && f < e) {
ret += 1;
}
if (a != b || a != c && d != e || f != e) {
ret += 2;
}
if (a && b && c || d && e && f) {
ret += 4;
}
if (a || b || c && d || e || f) {
ret += 8;
}
return ret;
}
u8 pcode_u8_complexLogic(u8 a, u8 b, u8 c, u8 d, u8 e, u8 f)
{
u8 ret = 0;
if (a > b && b > c || d < e && f < e) {
ret += 1;
}
if (a != b || a != c && d != e || f != e) {
ret += 2;
}
if (a && b && c || d && e && f) {
ret += 4;
}
if (a || b || c && d || e || f) {
ret += 8;
}
return ret;
}
i8 biopCmpi8i8(i8 lhs, i8 rhs)
{
if (lhs < 0)
lhs += 2;
if (lhs > 0)
lhs += 4;
if (lhs == 0)
lhs += 8;
if (lhs != rhs)
lhs += 16;
return lhs;
}
u8 biopCmpu8u8(u8 lhs, u8 rhs)
{
if (lhs < rhs)
lhs += 2;
if (lhs > rhs)
lhs += 4;
if (lhs == 0)
lhs += 8;
if (lhs != rhs)
lhs += 16;
return lhs;
}
i8 biopNei8i8(i8 lhs, i8 rhs)
{
i8 z;
z = lhs != rhs;
return z;
}
u8 biopAndu8u8(u8 lhs, u8 rhs)
{
u8 z;
z = lhs & rhs;
return z;
}
i8 biopAndi8i8(i8 lhs, i8 rhs)
{
i8 z;
z = lhs & rhs;
return z;
}
u8 biopOru8u8(u8 lhs, u8 rhs)
{
u8 z;
z = lhs | rhs;
return z;
}
u8 biopXOru8u8(u8 lhs, u8 rhs)
{
u8 z;
z = lhs ^ rhs;
return z;
}
i8 biopOri8i8(i8 lhs, i8 rhs)
{
i8 z;
z = lhs | rhs;
return z;
}
u8 biopLogicOru8u8(u8 lhs, u8 rhs)
{
u8 z;
z = lhs || rhs;
return z;
}
i8 biopXOri8i8(i8 lhs, i8 rhs)
{
i8 z;
z = lhs ^ rhs;
return z;
}
i8 biopRemainderi8i8(i8 lhs, i8 rhs)
{
i8 z;
z = lhs % rhs;
return z;
}
i8 biopLogicOri8i8(i8 lhs, i8 rhs)
{
i8 z;
z = lhs || rhs;
return z;
}
u8 biopLogicAndu8u8(u8 lhs, u8 rhs)
{
u8 z;
z = lhs && rhs;
return z;
}
i8 biopDividi8i8(i8 lhs, i8 rhs)
{
i8 z;
z = lhs / rhs;
return z;
}
u8 biopDividu8u8(u8 lhs, u8 rhs)
{
u8 z;
z = lhs / rhs;
return z;
}
i8 biopLogicAndi8i8(i8 lhs, i8 rhs)
{
i8 z;
z = lhs && rhs;
return z;
}
u8 unopNotu8(u8 lhs)
{
u8 z;
z = !lhs;
return z;
}
i8 unopNoti8(i8 lhs)
{
i8 z;
z = !lhs;
return z;
}
u8 unopPlusu8(u8 lhs)
{
u8 z;
z = +lhs;
return z;
}
i8 unopNegativei8(i8 lhs)
{
i8 z;
z = -lhs;
return z;
}
i8 unopPlusi8(i8 lhs)
{
i8 z;
z = +lhs;
return z;
}
u8 biopMultu8u8(u8 lhs, u8 rhs)
{
u8 z;
z = lhs * rhs;
return z;
}
i8 biopMulti8i8(i8 lhs, i8 rhs)
{
i8 z;
z = lhs * rhs;
return z;
}
u8 biopSubu8u8(u8 lhs, u8 rhs)
{
u8 z;
z = lhs - rhs;
return z;
}
i8 biopSubi8i8(i8 lhs, i8 rhs)
{
i8 z;
z = lhs - rhs;
return z;
}
u8 biopAddu8u8(u8 lhs, u8 rhs)
{
u8 z;
z = lhs + rhs;
return z;
}
u8 biopShtLftu8u8(u8 lhs, u8 rhs)
{
u8 z;
z = lhs << rhs;
return z;
}
i8 biopAddi8i8(i8 lhs, i8 rhs)
{
i8 z;
z = lhs + rhs;
return z;
}
u8 biopShtRhtu8u8(u8 lhs, u8 rhs)
{
u8 z;
z = lhs >> rhs;
return z;
}
i8 biopShtLfti8i8(i8 lhs, i8 rhs)
{
i8 z;
z = lhs << rhs;
return z;
}
i8 biopShtRhti8i8(i8 lhs, i8 rhs)
{
i8 z;
z = lhs >> rhs;
return z;
}
u8 biopGtu8u8(u8 lhs, u8 rhs)
{
u8 z;
z = lhs > rhs;
return z;
}
i8 biopGti8i8(i8 lhs, i8 rhs)
{
i8 z;
z = lhs > rhs;
return z;
}
u8 biopGeu8u8(u8 lhs, u8 rhs)
{
u8 z;
z = lhs >= rhs;
return z;
}
i8 biopGei8i8(i8 lhs, i8 rhs)
{
i8 z;
z = lhs >= rhs;
return z;
}
u8 biopLtu8u8(u8 lhs, u8 rhs)
{
u8 z;
z = lhs < rhs;
return z;
}
u8 biopLeu8u8(u8 lhs, u8 rhs)
{
u8 z;
z = lhs <= rhs;
return z;
}
i8 biopLti8i8(i8 lhs, i8 rhs)
{
i8 z;
z = lhs < rhs;
return z;
}
u8 biopEqu8u8(u8 lhs, u8 rhs)
{
u8 z;
z = lhs == rhs;
return z;
}
i8 biopLei8i8(i8 lhs, i8 rhs)
{
i8 z;
z = lhs <= rhs;
return z;
}
i8 biopEqi8i8(i8 lhs, i8 rhs)
{
i8 z;
z = lhs == rhs;
return z;
}
u8 biopNeu8u8(u8 lhs, u8 rhs)
{
u8 z;
z = lhs != rhs;
return z;
}
#endif /* #ifdef HAS_LONGLONG */
@@ -0,0 +1,356 @@
#include "pcode_test.h"
#ifdef HAS_LONGLONG
TEST pcode_BM1_GetBitLongLong_Main()
{
extern i8 pcode_BM1_GetBitLongLong(i8 arg, u4 bit);
ASSERTI8(pcode_BM1_GetBitLongLong(0xFF, 1), 2);
ASSERTI8(pcode_BM1_GetBitLongLong(I8_MAX, 8), 256);
ASSERTI8(pcode_BM1_GetBitLongLong(I8_MAX, 16), 65536);
ASSERTI8(pcode_BM1_GetBitLongLong(I8_MAX, 32), 4294967296LL);
ASSERTI8(pcode_BM1_GetBitLongLong(I8_MAX, 63), 0);
ASSERTI8(pcode_BM1_GetBitLongLong(0x0, 1), 0);
}
#endif
TEST pcode_BM2_GetBitInt_Main()
{
extern i4 pcode_BM2_GetBitInt(i4 arg, u4 bit);
ASSERTI4(pcode_BM2_GetBitInt(0xFF, 1), 2);
ASSERTI4(pcode_BM2_GetBitInt(0, 1), 0);
ASSERTI4(pcode_BM2_GetBitInt(I4_MAX, 8), 256);
ASSERTI4(pcode_BM2_GetBitInt(I4_MAX, 16), 65536);
ASSERTI4(pcode_BM2_GetBitInt(I4_MAX, 24), 16777216);
ASSERTI4(pcode_BM2_GetBitInt(I4_MAX, 31), 0);
}
TEST pcode_BM3_GetBitShort_Main()
{
extern i2 pcode_BM3_GetBitShort(i2 arg, u4 bit);
ASSERTI2(pcode_BM3_GetBitShort(0xFD, 1), 0);
ASSERTI2(pcode_BM3_GetBitShort(0x02, 1), 2);
ASSERTI2(pcode_BM3_GetBitShort(I2_MAX, 8), 256);
ASSERTI2(pcode_BM3_GetBitShort(I2_MAX, 14), 16384);
ASSERTI2(pcode_BM3_GetBitShort(I2_MAX, 15), 0);
}
TEST pcode_BM4_GetBitChar_Main()
{
extern i1 pcode_BM4_GetBitChar(i1 arg, u4 bit);
ASSERTI1(pcode_BM4_GetBitChar(0xFD, 1), 0);
ASSERTI1(pcode_BM4_GetBitChar(0x02, 1), 2);
ASSERTI1(pcode_BM4_GetBitChar(0xFF, 7), -128);
ASSERTI1(pcode_BM4_GetBitChar(0x7F, 7), 0);
ASSERTI1(pcode_BM4_GetBitChar(0, 1), 0);
}
#ifdef HAS_LONGLONG
TEST pcode_BM5_GetBitUnsignedLongLong_Main()
{
extern u8 pcode_BM5_GetBitUnsignedLongLong(u8 arg, u8 bit);
ASSERTU8(pcode_BM5_GetBitUnsignedLongLong(0x02, 1), 2);
ASSERTU8(pcode_BM5_GetBitUnsignedLongLong(0xFFFFFFFFFFFFFFFDULL, 1), 0);
ASSERTU8(pcode_BM5_GetBitUnsignedLongLong(U8_MAX, 8), 256);
ASSERTU8(pcode_BM5_GetBitUnsignedLongLong(U8_MAX, 16), 65536);
ASSERTU8(pcode_BM5_GetBitUnsignedLongLong(U8_MAX, 24), 16777216ULL);
ASSERTU8(pcode_BM5_GetBitUnsignedLongLong(U8_MAX, 32), 4294967296ULL);
}
#endif
TEST pcode_BM6_GetBitUnsignedInt_Main()
{
extern u4 pcode_BM6_GetBitUnsignedInt(u4 arg, u4 bit);
ASSERTU4(pcode_BM6_GetBitUnsignedInt(0x02, 1), 2);
ASSERTU4(pcode_BM6_GetBitUnsignedInt(0xFD, 1), 0);
ASSERTU4(pcode_BM6_GetBitUnsignedInt(U4_MAX, 8), 256);
ASSERTU4(pcode_BM6_GetBitUnsignedInt(U4_MAX, 16), 65536);
ASSERTU4(pcode_BM6_GetBitUnsignedInt(U4_MAX, 24), 16777216);
ASSERTU4(pcode_BM6_GetBitUnsignedInt(U4_MAX, 31), 2147483648);
}
TEST pcode_BM7_GetBitUnsignedShort_Main()
{
extern u2 pcode_BM7_GetBitUnsignedShort(u2 arg, u4 bit);
ASSERTU2(pcode_BM7_GetBitUnsignedShort(0xFF, 1), 2);
ASSERTU2(pcode_BM7_GetBitUnsignedShort(0, 1), 0);
ASSERTU2(pcode_BM7_GetBitUnsignedShort(U2_MAX, 8), 256);
ASSERTU2(pcode_BM7_GetBitUnsignedShort(U2_MAX, 16), 0);
}
TEST pcode_BM8_GetBitUnsignedChar_Main()
{
extern u1 pcode_BM8_GetBitUnsignedChar(u1 arg, u4 bit);
ASSERTU1(pcode_BM8_GetBitUnsignedChar(0xFF, 1), 2);
ASSERTU1(pcode_BM8_GetBitUnsignedChar(0, 1), 0);
ASSERTU1(pcode_BM8_GetBitUnsignedChar(U1_MAX, 4), 16);
ASSERTU1(pcode_BM8_GetBitUnsignedChar(U1_MAX, 8), 0);
}
#ifdef HAS_LONGLONG
TEST pcode_BM9_SetBitLongLong_Main()
{
extern i8 pcode_BM9_SetBitLongLong(i8 arg, u4 bit);
ASSERTI8(pcode_BM9_SetBitLongLong(0xFF, 1), 255);
ASSERTI8(pcode_BM9_SetBitLongLong(0, 1), 2);
ASSERTI8(pcode_BM9_SetBitLongLong(I8_MAX, 8), I8_MAX);
ASSERTI8(pcode_BM9_SetBitLongLong(I8_MAX, 16), I8_MAX);
ASSERTI8(pcode_BM9_SetBitLongLong(I8_MAX, 24), I8_MAX);
ASSERTI8(pcode_BM9_SetBitLongLong(I8_MAX, 32), I8_MAX);
ASSERTI8(pcode_BM9_SetBitLongLong(I8_MAX, 0), I8_MAX);
ASSERTI8(pcode_BM9_SetBitLongLong(4, 8), 260);
}
#endif
TEST pcode_BM10_SetBitInt_Main()
{
extern i4 pcode_BM10_SetBitInt(i4 arg, u4 bit);
ASSERTI4(pcode_BM10_SetBitInt(0xFF, 1), 255);
ASSERTI4(pcode_BM10_SetBitInt(0, 1), 2);
ASSERTI4(pcode_BM10_SetBitInt(I4_MAX, 31), -1);
ASSERTI4(pcode_BM10_SetBitInt(I4_MAX, I4_MIN), I4_MAX);
ASSERTI4(pcode_BM10_SetBitInt(4, 8), 260);
}
TEST pcode_BM11_SetBitShort_Main()
{
extern i2 pcode_BM11_SetBitShort(i2 arg, i2 bit);
ASSERTI2(pcode_BM11_SetBitShort(0xFF, 1), 255);
ASSERTI2(pcode_BM11_SetBitShort(0, 1), 2);
ASSERTI2(pcode_BM11_SetBitShort(I2_MAX, 8), 32767);
ASSERTI2(pcode_BM11_SetBitShort(I2_MAX, 15), -1);
}
TEST pcode_BM12_SetBitChar_Main()
{
extern i1 pcode_BM12_SetBitChar(i1 arg, u1 bit);
ASSERTI1(pcode_BM12_SetBitChar(0xFF, 1), -1);
ASSERTI1(pcode_BM12_SetBitChar(0, 1), 2);
ASSERTI1(pcode_BM12_SetBitChar(I1_MAX, 8), 127);
}
#ifdef HAS_LONGLONG
TEST pcode_BM12_SetBitUnsignedLongLong_Main()
{
extern u8 pcode_BM12_SetBitUnsignedLongLong(u8 arg, u8 bit);
ASSERTU8(pcode_BM12_SetBitUnsignedLongLong(0xFF, 1), 255);
ASSERTU8(pcode_BM12_SetBitUnsignedLongLong(0, 1), 2);
ASSERTU8(pcode_BM12_SetBitUnsignedLongLong(0, 8), 256);
ASSERTU8(pcode_BM12_SetBitUnsignedLongLong(0, 16), 65536);
ASSERTU8(pcode_BM12_SetBitUnsignedLongLong(0, 24), 16777216ULL);
ASSERTU8(pcode_BM12_SetBitUnsignedLongLong(0, 31), 2147483648ULL);
ASSERTU8(pcode_BM12_SetBitUnsignedLongLong(0, 32), 4294967296ULL);
ASSERTU8(pcode_BM12_SetBitUnsignedLongLong(U8_MAX, 8), U8_MAX);
ASSERTU8(pcode_BM12_SetBitUnsignedLongLong(U8_MAX, 16), U8_MAX);
ASSERTU8(pcode_BM12_SetBitUnsignedLongLong(U8_MAX, 24), U8_MAX);
ASSERTU8(pcode_BM12_SetBitUnsignedLongLong(U8_MAX, 32), U8_MAX);
}
#endif
#ifdef HAS_LONGLONG
TEST pcode_BM13_SetLowBitUnsignedLongLong_Main()
{
extern u8 pcode_BM13_SetLowBitUnsignedLongLong(u8 arg, u8 bit);
ASSERTU8(pcode_BM13_SetLowBitUnsignedLongLong(0xFF, 1), 255);
ASSERTU8(pcode_BM13_SetLowBitUnsignedLongLong(0, 1), 2);
ASSERTU8(pcode_BM13_SetLowBitUnsignedLongLong(0, 8), 256);
ASSERTU8(pcode_BM13_SetLowBitUnsignedLongLong(0, 16), 65536);
ASSERTU8(pcode_BM13_SetLowBitUnsignedLongLong(0, 24), 16777216ULL);
ASSERTU8(pcode_BM13_SetLowBitUnsignedLongLong(0, 31), 2147483648ULL); // ensure no sign extension occurs
}
#endif
TEST pcode_BM14_SetBitUnsignedInt_Main()
{
extern u4 pcode_BM14_SetBitUnsignedInt(u4 arg, u4 bit);
ASSERTU4(pcode_BM14_SetBitUnsignedInt(0xFF, 1), 255);
ASSERTU4(pcode_BM14_SetBitUnsignedInt(0, 1), 2);
ASSERTU4(pcode_BM14_SetBitUnsignedInt(0, 8), 256);
ASSERTU4(pcode_BM14_SetBitUnsignedInt(0, 16), 65536);
ASSERTU4(pcode_BM14_SetBitUnsignedInt(0, 24), 16777216);
ASSERTU4(pcode_BM14_SetBitUnsignedInt(0, 31), 2147483648);
}
TEST pcode_BM15_SetBitUnsignedShort_Main()
{
extern u2 pcode_BM15_SetBitUnsignedShort(u2 arg, u4 bit);
ASSERTU2(pcode_BM15_SetBitUnsignedShort(0xFF, 1), 255);
ASSERTU2(pcode_BM15_SetBitUnsignedShort(0, 1), 2);
ASSERTU2(pcode_BM15_SetBitUnsignedShort(0, 8), 256);
ASSERTU2(pcode_BM15_SetBitUnsignedShort(0, 15), 32768);
}
TEST pcode_BM16_SetBitUnsignedChar_Main()
{
extern u1 pcode_BM16_SetBitUnsignedChar(u1 arg, u1 bit);
ASSERTU1(pcode_BM16_SetBitUnsignedChar(0xFF, 1), 255);
ASSERTU1(pcode_BM16_SetBitUnsignedChar(0, 1), 2);
ASSERTU1(pcode_BM16_SetBitUnsignedChar(4, 1), 6);
}
#ifdef HAS_LONGLONG
TEST pcode_BM17_ClearBitLongLong_Main()
{
extern i8 pcode_BM17_ClearBitLongLong(i8 arg, i8 bit);
ASSERTI8(pcode_BM17_ClearBitLongLong(0xFF, 1), 253);
ASSERTI8(pcode_BM17_ClearBitLongLong(0, 1), 0);
ASSERTI8(pcode_BM17_ClearBitLongLong(I8_MAX, 8), 9223372036854775551LL);
ASSERTI8(pcode_BM17_ClearBitLongLong(I8_MAX, 16), 9223372036854710271LL);
ASSERTI8(pcode_BM17_ClearBitLongLong(I8_MAX, 24), 9223372036837998591LL);
ASSERTI8(pcode_BM17_ClearBitLongLong(I8_MAX, 32), 9223372032559808511LL);
}
#endif
TEST pcode_BM18_ClearBitInt_Main()
{
extern i4 pcode_BM18_ClearBitInt(i4 arg, i4 bit);
ASSERTI4(pcode_BM18_ClearBitInt(0xFF, 1), 253);
ASSERTI4(pcode_BM18_ClearBitInt(0, 1), 0);
ASSERTI4(pcode_BM18_ClearBitInt(I4_MAX, 8), 2147483391);
ASSERTI4(pcode_BM18_ClearBitInt(I4_MAX, 16), 2147418111);
ASSERTI4(pcode_BM18_ClearBitInt(I4_MAX, 31), 2147483647);
}
TEST pcode_BM19_ClearBitShort_Main()
{
extern i2 pcode_BM19_ClearBitShort(i2 arg, i2 bit);
ASSERTI2(pcode_BM19_ClearBitShort(0xFF, 1), 253);
ASSERTI2(pcode_BM19_ClearBitShort(0, 1), 0);
ASSERTI2(pcode_BM19_ClearBitShort(I2_MAX, 8), 32511);
ASSERTI2(pcode_BM19_ClearBitShort(I2_MAX, 15), 32767);
}
TEST pcode_BM20_ClearBitChar_Main()
{
extern i1 pcode_BM20_ClearBitChar(i1 arg, u1 bit);
ASSERTI1(pcode_BM20_ClearBitChar(0xFF, 1), -3);
ASSERTI1(pcode_BM20_ClearBitChar(0, 1), 0);
ASSERTI1(pcode_BM20_ClearBitChar(I1_MAX, 4), 111);
ASSERTI1(pcode_BM20_ClearBitChar(I1_MAX, 8), 127);
}
#ifdef HAS_LONGLONG
TEST pcode_BM21_ClearBitUnsignedLongLong_Main()
{
extern u8 pcode_BM21_ClearBitUnsignedLongLong(u8 arg, u8 bit);
ASSERTU8(pcode_BM21_ClearBitUnsignedLongLong(0xFF, 1), 253);
ASSERTU8(pcode_BM21_ClearBitUnsignedLongLong(0, 1), 0);
ASSERTU8(pcode_BM21_ClearBitUnsignedLongLong(U8_MAX, 8), 18446744073709551359ULL);
ASSERTU8(pcode_BM21_ClearBitUnsignedLongLong(U8_MAX, 16), 18446744073709486079ULL);
ASSERTU8(pcode_BM21_ClearBitUnsignedLongLong(U8_MAX, 32), 18446744069414584319ULL);
ASSERTU8(pcode_BM21_ClearBitUnsignedLongLong(U8_MAX, 63), 9223372036854775807ULL);
}
#endif
TEST pcode_BM22_ClearBitUnsignedInt_Main()
{
extern u4 pcode_BM22_ClearBitUnsignedInt(u4 arg, u4 bit);
ASSERTU4(pcode_BM22_ClearBitUnsignedInt(0xFF, 1), 253);
ASSERTU4(pcode_BM22_ClearBitUnsignedInt(0, 1), 0);
ASSERTU4(pcode_BM22_ClearBitUnsignedInt(U4_MAX, 8), -257);
ASSERTU4(pcode_BM22_ClearBitUnsignedInt(U4_MAX, 16), -65537);
ASSERTU4(pcode_BM22_ClearBitUnsignedInt(U4_MAX, 24), -16777217);
ASSERTU4(pcode_BM22_ClearBitUnsignedInt(U4_MAX, 31), 2147483647);
}
TEST pcode_BM23_ClearBitUnsignedShort_Main()
{
extern u2 pcode_BM23_ClearBitUnsignedShort(u2 arg, u2 bit);
ASSERTU2(pcode_BM23_ClearBitUnsignedShort(0xFF, 1), 253);
ASSERTU2(pcode_BM23_ClearBitUnsignedShort(0, 1), 0);
ASSERTU2(pcode_BM23_ClearBitUnsignedShort(U2_MAX, 8), 65279);
ASSERTU2(pcode_BM23_ClearBitUnsignedShort(U2_MAX, 15), 32767);
}
TEST pcode_BM24_ClearBitUnsignedChar_Main()
{
extern u1 pcode_BM24_ClearBitUnsignedChar(u1 arg, u1 bit);
ASSERTU1(pcode_BM24_ClearBitUnsignedChar(0xFF, 1), 253);
ASSERTU1(pcode_BM24_ClearBitUnsignedChar(0, 1), 0);
ASSERTU1(pcode_BM24_ClearBitUnsignedChar(U1_MAX, 4), 239);
ASSERTU1(pcode_BM24_ClearBitUnsignedChar(U1_MAX, 8), 255);
}
#ifdef HAS_LONGLONG
TEST pcode_BM25_ToggleBitLongLong_Main()
{
extern i8 pcode_BM25_ToggleBitLongLong(i8 arg, u4 bit);
ASSERTI8(pcode_BM25_ToggleBitLongLong(0xFF, 1), 253);
ASSERTI8(pcode_BM25_ToggleBitLongLong(0, 1), 2);
ASSERTI8(pcode_BM25_ToggleBitLongLong(I8_MAX, 8), 9223372036854775551LL);
ASSERTI8(pcode_BM25_ToggleBitLongLong(I8_MAX, 16), 9223372036854710271LL);
ASSERTI8(pcode_BM25_ToggleBitLongLong(I8_MAX, 32), 9223372032559808511LL);
ASSERTI8(pcode_BM25_ToggleBitLongLong(I8_MAX, 63), -1LL);
}
#endif
TEST pcode_BM26_ToggleBitInt_Main()
{
extern i4 pcode_BM26_ToggleBitInt(i4 arg, i4 bit);
ASSERTI4(pcode_BM26_ToggleBitInt(0xFF, 1), 253);
ASSERTI4(pcode_BM26_ToggleBitInt(0, 1), 2);
ASSERTI4(pcode_BM26_ToggleBitInt(I4_MAX, 8), 2147483391);
ASSERTI4(pcode_BM26_ToggleBitInt(I4_MAX, 16), 2147418111);
ASSERTI4(pcode_BM26_ToggleBitInt(I4_MAX, 24), 2130706431);
ASSERTI4(pcode_BM26_ToggleBitInt(I4_MAX, 31), -1);
}
TEST pcode_BM27_ToggleBitShort_Main()
{
extern i2 pcode_BM27_ToggleBitShort(i2 arg, i2 bit);
ASSERTI2(pcode_BM27_ToggleBitShort(0xFF, 1), 253);
ASSERTI2(pcode_BM27_ToggleBitShort(0, 1), 2);
ASSERTI2(pcode_BM27_ToggleBitShort(I2_MAX, 8), 32511);
ASSERTI2(pcode_BM27_ToggleBitShort(I2_MAX, 15), -1);
}
TEST pcode_BM28_ToggleBitChar_Main()
{
extern i1 pcode_BM28_ToggleBitChar(i1 arg, u4 bit);
ASSERTI1(pcode_BM28_ToggleBitChar(0xFF, 1), -3);
ASSERTI1(pcode_BM28_ToggleBitChar(0, 1), 2);
ASSERTI1(pcode_BM28_ToggleBitChar(I1_MAX, 4), 111);
ASSERTI1(pcode_BM28_ToggleBitChar(I1_MAX, 8), 127);
}
#ifdef HAS_LONGLONG
TEST pcode_BM29_ToggleBitUnsignedLongLong_Main()
{
extern u8 pcode_BM29_ToggleBitUnsignedLongLong(u8 arg, u4 bit);
ASSERTU8(pcode_BM29_ToggleBitUnsignedLongLong(0xFF, 1), 253);
ASSERTU8(pcode_BM29_ToggleBitUnsignedLongLong(0, 1), 2);
ASSERTU8(pcode_BM29_ToggleBitUnsignedLongLong(U8_MAX, 8), 18446744073709551359ULL);
ASSERTU8(pcode_BM29_ToggleBitUnsignedLongLong(U8_MAX, 16), 18446744073709486079ULL);
ASSERTU8(pcode_BM29_ToggleBitUnsignedLongLong(U8_MAX, 32), 18446744069414584319ULL);
ASSERTU8(pcode_BM29_ToggleBitUnsignedLongLong(U8_MAX, 63), 9223372036854775807ULL);
}
#endif
TEST pcode_BM30_ToggleBitUnsignedInt_Main()
{
extern u4 pcode_BM30_ToggleBitUnsignedInt(u4 arg, u4 bit);
ASSERTU4(pcode_BM30_ToggleBitUnsignedInt(0xFF, 1), 253);
ASSERTU4(pcode_BM30_ToggleBitUnsignedInt(0, 1), 2);
ASSERTU4(pcode_BM30_ToggleBitUnsignedInt(U4_MAX, 8), 4294967039);
ASSERTU4(pcode_BM30_ToggleBitUnsignedInt(U4_MAX, 16), 4294901759);
ASSERTU4(pcode_BM30_ToggleBitUnsignedInt(U4_MAX, 31), 2147483647);
}
TEST pcode_BM31_ToggleBitUnsignedShort_Main()
{
extern u2 pcode_BM31_ToggleBitUnsignedShort(u2 arg, u4 bit);
ASSERTU2(pcode_BM31_ToggleBitUnsignedShort(0xFF, 1), 253);
ASSERTU2(pcode_BM31_ToggleBitUnsignedShort(0, 1), 2);
ASSERTU2(pcode_BM31_ToggleBitUnsignedShort(U2_MAX, 8), 65279);
ASSERTU2(pcode_BM31_ToggleBitUnsignedShort(U2_MAX, 15), 32767);
}
TEST pcode_BM32_ToggleBitUnsignedChar_Main()
{
extern u1 pcode_BM32_ToggleBitUnsignedChar(u1 arg, u1 bit);
ASSERTU1(pcode_BM32_ToggleBitUnsignedChar(0xFF, 1), 253);
ASSERTU1(pcode_BM32_ToggleBitUnsignedChar(0, 1), 2);
ASSERTU1(pcode_BM32_ToggleBitUnsignedChar(U1_MAX, 4), 239);
ASSERTU1(pcode_BM32_ToggleBitUnsignedChar(U1_MAX, 7), 127);
}
MAIN BitManipulation_main() { }
@@ -0,0 +1,204 @@
/* ###
* 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.
*/
#include "pcode_test.h"
#define GET_BIT(typ, arg, bit) (arg & (((typ)1) << bit))
#define SET_BIT(typ, arg, bit) (arg | (((typ)1) << bit))
#define CLR_BIT(typ, arg, bit) (arg & (~(((typ)1) << bit)))
#define TGL_BIT(typ, arg, bit) (arg ^ (((typ)1) << bit))
#ifdef HAS_LONGLONG
i8 pcode_BM1_GetBitLongLong(i8 arg, u4 bit)
{
return GET_BIT(i8, arg, bit);
}
#endif /* #ifdef HAS_LONGLONG */
i4 pcode_BM2_GetBitInt(i4 arg, u4 bit)
{
return GET_BIT(i4, arg, bit);
}
i2 pcode_BM3_GetBitShort(i2 arg, u4 bit)
{
return GET_BIT(i2, arg, bit);
}
i1 pcode_BM4_GetBitChar(i1 arg, u4 bit)
{
return GET_BIT(i1, arg, bit);
}
#ifdef HAS_LONGLONG
u8 pcode_BM5_GetBitUnsignedLongLong(u8 arg, u8 bit)
{
return GET_BIT(u8, arg, bit);
}
#endif /* #ifdef HAS_LONGLONG */
u4 pcode_BM6_GetBitUnsignedInt(u4 arg, u4 bit)
{
return GET_BIT(u4, arg, bit);
}
u2 pcode_BM7_GetBitUnsignedShort(u2 arg, u4 bit)
{
return GET_BIT(u2, arg, bit);
}
u1 pcode_BM8_GetBitUnsignedChar(u1 arg, u4 bit)
{
return GET_BIT(u1, arg, bit);
}
#ifdef HAS_LONGLONG
i8 pcode_BM9_SetBitLongLong(i8 arg, u4 bit)
{
return SET_BIT(i8, arg, bit);
}
#endif /* #ifdef HAS_LONGLONG */
i4 pcode_BM10_SetBitInt(i4 arg, u4 bit)
{
return SET_BIT(i4, arg, bit);
}
i2 pcode_BM11_SetBitShort(i2 arg, i2 bit)
{
return SET_BIT(i2, arg, bit);
}
i1 pcode_BM12_SetBitChar(i1 arg, u1 bit)
{
return SET_BIT(i1, arg, bit);
}
#ifdef HAS_LONGLONG
u8 pcode_BM12_SetBitUnsignedLongLong(u8 arg, u8 bit)
{
return SET_BIT(u8, arg, bit);
}
#endif /* #ifdef HAS_LONGLONG */
#ifdef HAS_LONGLONG
u8 pcode_BM13_SetLowBitUnsignedLongLong(u8 arg, u8 bit)
{
return SET_BIT(u8, arg, bit);
}
#endif /* #ifdef HAS_LONGLONG */
u4 pcode_BM14_SetBitUnsignedInt(u4 arg, u4 bit)
{
return SET_BIT(u4, arg, bit);
}
u2 pcode_BM15_SetBitUnsignedShort(u2 arg, u4 bit)
{
return SET_BIT(u2, arg, bit);
}
u1 pcode_BM16_SetBitUnsignedChar(u1 arg, u1 bit)
{
return SET_BIT(u1, arg, bit);
}
#ifdef HAS_LONGLONG
i8 pcode_BM17_ClearBitLongLong(i8 arg, i8 bit)
{
return CLR_BIT(i8, arg, bit);
}
#endif /* #ifdef HAS_LONGLONG */
i4 pcode_BM18_ClearBitInt(i4 arg, i4 bit)
{
return CLR_BIT(i4, arg, bit);
}
i2 pcode_BM19_ClearBitShort(i2 arg, i2 bit)
{
return CLR_BIT(i2, arg, bit);
}
i1 pcode_BM20_ClearBitChar(i1 arg, u1 bit)
{
return CLR_BIT(i1, arg, bit);
}
#ifdef HAS_LONGLONG
u8 pcode_BM21_ClearBitUnsignedLongLong(u8 arg, u8 bit)
{
return CLR_BIT(u8, arg, bit);
}
#endif /* #ifdef HAS_LONGLONG */
u4 pcode_BM22_ClearBitUnsignedInt(u4 arg, u4 bit)
{
return CLR_BIT(u4, arg, bit);
}
u2 pcode_BM23_ClearBitUnsignedShort(u2 arg, u2 bit)
{
return CLR_BIT(u2, arg, bit);
}
u1 pcode_BM24_ClearBitUnsignedChar(u1 arg, u1 bit)
{
return CLR_BIT(u1, arg, bit);
}
#ifdef HAS_LONGLONG
i8 pcode_BM25_ToggleBitLongLong(i8 arg, u4 bit)
{
return TGL_BIT(i8, arg, bit);
}
#endif /* #ifdef HAS_LONGLONG */
i4 pcode_BM26_ToggleBitInt(i4 arg, i4 bit)
{
return TGL_BIT(i4, arg, bit);
}
i2 pcode_BM27_ToggleBitShort(i2 arg, i2 bit)
{
return TGL_BIT(i2, arg, bit);
}
i1 pcode_BM28_ToggleBitChar(i1 arg, u4 bit)
{
return TGL_BIT(i1, arg, bit);
}
#ifdef HAS_LONGLONG
u8 pcode_BM29_ToggleBitUnsignedLongLong(u8 arg, u4 bit)
{
return TGL_BIT(u8, arg, bit);
}
#endif /* #ifdef HAS_LONGLONG */
u4 pcode_BM30_ToggleBitUnsignedInt(u4 arg, u4 bit)
{
return TGL_BIT(u4, arg, bit);
}
u2 pcode_BM31_ToggleBitUnsignedShort(u2 arg, u4 bit)
{
return TGL_BIT(u2, arg, bit);
}
u1 pcode_BM32_ToggleBitUnsignedChar(u1 arg, u1 bit)
{
return TGL_BIT(u1, arg, bit);
}
@@ -0,0 +1,82 @@
#include "pcode_test.h"
TEST pcode_DM1_IfElse_Main()
{
extern i4 pcode_DM1_IfElse(i4 arg1);
ASSERTI4(pcode_DM1_IfElse(0), 0);
ASSERTI4(pcode_DM1_IfElse(0x42), 1);
}
TEST pcode_DM2_IfElseIfElse_Main()
{
extern i4 pcode_DM2_IfElseIfElse(i4 arg1);
ASSERTI4(pcode_DM2_IfElseIfElse(0), 0);
ASSERTI4(pcode_DM2_IfElseIfElse(0x42), 1);
ASSERTI4(pcode_DM2_IfElseIfElse(0x69), 2);
}
TEST pcode_DM3_SmallSwitch_Main()
{
extern i4 pcode_DM3_SmallSwitch(i4 arg1);
i4 ret = pcode_DM3_SmallSwitch(0);
ASSERTI4(pcode_DM3_SmallSwitch(0), 0);
ASSERTI4(pcode_DM3_SmallSwitch(0x42), 1);
ASSERTI4(pcode_DM3_SmallSwitch(0x69), 2);
}
TEST pcode_DM4_MediumSwitch_Main()
{
extern i4 pcode_DM4_MediumSwitch(i4 arg1);
ASSERTI4(pcode_DM4_MediumSwitch(0x42), 1);
ASSERTI4(pcode_DM4_MediumSwitch(0x69), 2);
ASSERTI4(pcode_DM4_MediumSwitch(0x101), 3);
ASSERTI4(pcode_DM4_MediumSwitch(-1), 0);
}
TEST pcode_DM5_EQ_TernaryOperator_Main()
{
extern i4 pcode_DM5_EQ_TernaryOperator(i4 arg1);
ASSERTI4(pcode_DM5_EQ_TernaryOperator(0x42), 0);
ASSERTI4(pcode_DM5_EQ_TernaryOperator(0x69), 1);
}
TEST pcode_DM6_NE_TernaryOperator_Main()
{
extern i4 pcode_DM6_NE_TernaryOperator(i4 arg1);
ASSERTI4(pcode_DM6_NE_TernaryOperator(0x42), 1);
ASSERTI4(pcode_DM6_NE_TernaryOperator(0x69), 0);
}
TEST pcode_DM7_LT_TernaryOperator_Main()
{
extern i4 pcode_DM7_LT_TernaryOperator(i4 arg1);
ASSERTI4(pcode_DM7_LT_TernaryOperator(0x42), 1);
ASSERTI4(pcode_DM7_LT_TernaryOperator(0x69), 0);
ASSERTI4(pcode_DM7_LT_TernaryOperator(0x72), 0);
}
TEST pcode_DM8_GT_TernaryOperator_Main()
{
extern i4 pcode_DM8_GT_TernaryOperator(i4 arg1);
ASSERTI4(pcode_DM8_GT_TernaryOperator(0x42), 0);
ASSERTI4(pcode_DM8_GT_TernaryOperator(0x69), 0);
ASSERTI4(pcode_DM8_GT_TernaryOperator(0x82), 1);
}
TEST pcode_DM9_LE_TernaryOperator_Main()
{
extern i4 pcode_DM9_LE_TernaryOperator(i4 arg1);
ASSERTI4(pcode_DM9_LE_TernaryOperator(0x42), 1);
ASSERTI4(pcode_DM9_LE_TernaryOperator(0x69), 1);
ASSERTI4(pcode_DM9_LE_TernaryOperator(0x72), 0);
}
TEST pcode_DM10_GE_TernaryOperator_Main()
{
extern i4 pcode_DM10_GE_TernaryOperator(i4 arg1);
ASSERTI4(pcode_DM10_GE_TernaryOperator(0x42), 0);
ASSERTI4(pcode_DM10_GE_TernaryOperator(0x69), 1);
ASSERTI4(pcode_DM10_GE_TernaryOperator(0x72), 1);
}
MAIN DecisionMaking_main() { }

Some files were not shown because too many files have changed in this diff Show More