Commit f390f2e6 authored by Julian Kranz's avatar Julian Kranz

X86 Pretty Printer

...

- Bug fixes
...
parent 11bf49b0
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
// Copyright (c) 2012 Axel Simon. All rights reserved. // Copyright (c) 2012 Axel Simon. All rights reserved.
// //
#include <stdint.h>
#include <strings.h> #include <strings.h>
#include "Segment.h" #include "Segment.h"
#include <sys/mman.h> #include <sys/mman.h>
......
...@@ -5,9 +5,72 @@ ...@@ -5,9 +5,72 @@
* Author: jucs * Author: jucs
*/ */
#include <stdlib.h> #include <stdint.h>
#include <stdio.h> #include <iostream>
#include <fstream>
#include "Segment.h"
#include "RReil.h"
#include <vector>
#include <fcntl.h>
int main(void) { int main(int argc, const char * argv[]) {
printf(":-)\n"); char *file_name = "/bin/echo";
SegmentSet segments;
// Read in what code/data segments there are and store them in
// uint32_t cmd_buf[header.sizeofcmds/sizeof(uint32_t)];
// char* cp = (char*) &cmd_buf;
// f.read(cp, header.sizeofcmds);
// uint32_t ncmds = header.ncmds;
// while ((cp-(char*) &cmd_buf)<header.sizeofcmds && ncmds--) {
// struct load_command* lc = (struct load_command*) cp;
// switch (lc->cmd) {
// case LC_SEGMENT_64: {
// struct segment_command_64* cmd = (struct segment_command_64*) cp;
// char name[17];
// name[16]=0;
// memcpy(&name[0], &cmd->segname[0], 16);
// std::cout << "found " << &name[0] << " segment" << std::endl;
// uint32_t nsect = cmd->nsects;
// struct section_64* sect = (struct section_64*) (cp+sizeof(struct segment_command_64));
// for (int i=0; i<nsect; i++, sect++) {
// sect->sectname[15]=0;
// Segment* s = new Segment(&(sect->sectname[0]), sect->addr, sect->size, sect->offset);
// segments.addSegment(s);
// }
// }
// }
// cp = cp+lc->cmdsize;
// }
Segment* s = new Segment("text", 0x401170, 0xbd, 0x1170);
segments.addSegment(s);
// f.close();
int fd = open(file_name, O_RDONLY);
if (fd== -1) return 1;
bool res = segments.map(fd);
if (!res) {
std::cout << "Cannot map segment sections." << std::endl;
return 1;
}
//std::cout << segments;
Segment* text = segments.findByName("text");
if (text==NULL) {
std::cout << "Segment containing code not found." << std::endl;
return 1;
}
std::cout << segments << std::endl;
uint64_t start = text->getBase();
char* limit;
char* addr = segments.resolve(start, &limit);
//std::cout << "first byte of text segment is " << std::hex << start << ": " << std::hex << (uint8_t) (*addr) << std::dec << std::endl;
RReilBB* b = translate(addr,limit);
if (b!=NULL) std::cout << "basic block:" << std::endl << *b << std::endl;
return 0;
} }
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#define __RT_HEAP_SIZE (4*1024*1024) #define __RT_HEAP_SIZE (8*1024*1024)
#define __CHECK_HEAP(n) /* TODO: check for heap-overflow */ #define __CHECK_HEAP(n) /* TODO: check for heap-overflow */
#define __ALLOC1() --hp /* TODO: check for heap-overflow */ #define __ALLOC1() --hp /* TODO: check for heap-overflow */
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
all: cmusl-cli all: cmusl-cli
ccmp: ccmp:
gcc -O2 -Wall -static -I. -I../.. -I../../resources/xed/xed2-intel64/include -L../../resources/xed/xed2-intel64/lib -Wfatal-errors cmp.c ../../dis.c pretty.c -lbfd -liberty -ldl -lz -lxed -DRELAXEDFATAL -o cmp clang -O2 -Wall -static -I. -I../.. -I../../resources/xed/xed2-intel64/include -L../../resources/xed/xed2-intel64/lib -Wfatal-errors cmp.c ../../dis.c pretty.c -lbfd -liberty -ldl -lz -lxed -DRELAXEDFATAL -o cmp
cxedcmp: cxedcmp:
gcc -O2 -Wall -Wfatal-errors -static -I. -I../.. -I../../resources/xed/xed2-intel64/include -L../../resources/xed/xed2-intel64/lib xed-cmp.c pretty.c ../../dis.c -lbfd -liberty -ldl -lz -lxed -DRELAXEDFATAL -o xed-cmp clang -O2 -Wall -Wfatal-errors -static -I. -I../.. -I../../resources/xed/xed2-intel64/include -L../../resources/xed/xed2-intel64/lib xed-cmp.c pretty.c ../../dis.c -lbfd -liberty -ldl -lz -lxed -DRELAXEDFATAL -o xed-cmp
ccli: ccli:
gcc -pipe -O2 -Wall -static -I. -I../.. -Wfatal-errors cli.c pretty.c ../../dis.c -DRELAXEDFATAL -o cli clang -pipe -O2 -Wall -static -I. -I../.. -Wfatal-errors cli.c pretty.c ../../dis.c -DRELAXEDFATAL -o cli
cmusl-cli: cmusl-cli:
/usr/musl/bin/musl-gcc -pipe -O3 -Wall -static -I. -I../.. -Wfatal-errors cli.c pretty.c ../../dis.c -DRELAXEDFATAL -o musl-cli /usr/musl/bin/musl-gcc -pipe -O3 -Wall -static -I. -I../.. -Wfatal-errors cli.c pretty.c ../../dis.c -DRELAXEDFATAL -o musl-cli
...@@ -17,4 +17,4 @@ cmusl-cli-println: ...@@ -17,4 +17,4 @@ cmusl-cli-println:
/usr/musl/bin/musl-gcc -pipe -O3 -Wall -static -I. -I../.. -Wfatal-errors cli-println.c ../../dis.c -DRELAXEDFATAL -o musl-cli-println /usr/musl/bin/musl-gcc -pipe -O3 -Wall -static -I. -I../.. -Wfatal-errors cli-println.c ../../dis.c -DRELAXEDFATAL -o musl-cli-println
ccli-println: ccli-println:
gcc -O2 -Wall -static -I. -I../.. -Wfatal-errors cli-println.c ../../dis.c -DRELAXEDFATAL -o cli-println clang -O2 -Wall -static -I. -I../.. -Wfatal-errors cli-println.c ../../dis.c -DRELAXEDFATAL -o cli-println
This diff is collapsed.
...@@ -667,6 +667,11 @@ end ...@@ -667,6 +667,11 @@ end
val sem-lddqu x = sem-lddqu-vlddqu 128 x; val sem-lddqu x = sem-lddqu-vlddqu 128 x;
val sem-vlddqu x = sem-lddqu-vlddqu 256 x; val sem-vlddqu x = sem-lddqu-vlddqu 256 x;
val sem-lds x = do
return void
end
val sem-lea x = do val sem-lea x = do
opnd-sz <- sizeof1 x.opnd1; opnd-sz <- sizeof1 x.opnd1;
dst <- write opnd-sz x.opnd1; dst <- write opnd-sz x.opnd1;
......
...@@ -978,7 +978,7 @@ val semantics insn = ...@@ -978,7 +978,7 @@ val semantics insn =
| LAR x: sem-undef-arity2 x | LAR x: sem-undef-arity2 x
| LDDQU x: sem-lddqu x | LDDQU x: sem-lddqu x
| LDMXCSR x: sem-undef-arity1 x | LDMXCSR x: sem-undef-arity1 x
| LDS x: sem-undef-arity2 x | LDS x: sem-lds x
| LEA x: sem-lea x | LEA x: sem-lea x
| LEAVE x: sem-undef-arity0 x | LEAVE x: sem-undef-arity0 x
| LES x: sem-undef-arity2 x | LES x: sem-undef-arity2 x
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment