Update tools/armpe_tester.

This commit is contained in:
Markus F.X.J. Oberhumer 2009-02-12 03:33:14 +01:00
parent d117e442a4
commit be57adaee7
3 changed files with 59 additions and 49 deletions

View File

@ -45,7 +45,7 @@ stub/**.*-stamp
stub/tmp*/* stub/tmp*/*
stub/**/tmp*/* stub/**/tmp*/*
stub/tools/armpe/armpe_tester stub/tools/armpe/armpe_tester{,.exe,.out}
stub/tools/sstrip/amd64-linux-sstrip stub/tools/sstrip/amd64-linux-sstrip
stub/tools/sstrip/i386-linux-sstrip stub/tools/sstrip/i386-linux-sstrip

View File

@ -1,29 +1,35 @@
# Makefile for armpe_tester # Makefile for armpe_tester
MAKEFLAGS += -rR MAKEFLAGS += -rR
SHELL = /bin/sh .SUFFIXES:
.SECONDEXPANSION:
.NOTPARALLEL:
export LC_ALL = C
export SHELL = /bin/sh
# update path for our special stub build tools # update $PATH for our special stub build tools
ifneq ($(wildcard $(HOME)/local/bin/bin-upx),) ifneq ($(wildcard $(HOME)/local/bin/bin-upx/.),)
export PATH := $(HOME)/local/bin/bin-upx:$(PATH) export PATH := $(HOME)/local/bin/bin-upx:$(PATH)
endif endif
ifneq ($(wildcard $(HOME)/bin/bin-upx/.),)
ifneq ($(wildcard $(HOME)/bin/bin-upx),)
export PATH := $(HOME)/bin/bin-upx:$(PATH) export PATH := $(HOME)/bin/bin-upx:$(PATH)
endif endif
CFLAGS_W = -Wall -W -Wcast-align -Wcast-qual -Wwrite-strings
all: armpe_tester wtest.exe
armpe_tester: armpe_tester.c all: armpe_tester.out
arm-9tdmi-linux-gnu-gcc -Wl,--section-start,.interp=0x1000 -g -Wall -W -o $@ $< #all: armpe_tester.exe
wtest.exe: armpe_tester.c armpe_tester.out: armpe_tester.c $(MAKEFILE_LIST)
arm-wince-pe-gcc -Wl,--image-base,0x400000 -s -Wall -W -o $@ $< arm-linux-gcc-4.1.0 -Wl,--section-start,.interp=0x1000 -g $(CFLAGS_W) -o $@ $<
armpe_tester.exe: armpe_tester.c $(MAKEFILE_LIST)
arm-wince-pe-gcc -Wl,--image-base,0x400000 -s $(CFLAGS_W) -o $@ $<
mostlyclean clean distclean maintainer-clean: mostlyclean clean distclean maintainer-clean:
rm -f *.d *.o *.obj rm -f *.d *.o *.obj
rm -f armpe_tester wtest.exe rm -f armpe_tester.exe armpe_tester.out
.PHONY: all mostlyclean clean distclean maintainer-clean .PHONY: all mostlyclean clean distclean maintainer-clean

View File

@ -32,38 +32,46 @@
// arm-9tdmi-linux-gnu-gcc -Wl,--section-start,.interp=0x1000 // arm-9tdmi-linux-gnu-gcc -Wl,--section-start,.interp=0x1000
// arm-wince-pe-gcc -Wl,--image-base,0x400000 // arm-wince-pe-gcc -Wl,--image-base,0x400000
#include <stddef.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <string.h>
#include <stdarg.h>
#ifdef i386 #ifdef __i386__
# define UPX_MMAP_ADDRESS 0x20000000 # define UPX_MMAP_ADDRESS 0x20000000
#else #else
# define UPX_MMAP_ADDRESS 0x10000 # define UPX_MMAP_ADDRESS 0x10000
#endif #endif
#ifdef linux #ifdef __linux__
# include <sys/mman.h> # include <sys/mman.h>
#else #else
void *VirtualAlloc(void *address, unsigned size, unsigned type, unsigned protect); void *VirtualAlloc(void *address, unsigned size, unsigned type, unsigned protect);
# define MEM_COMMIT 0x1000 # define MEM_COMMIT 0x1000
# define PAGE_EXECUTE_READWRITE 0x0040 # define PAGE_EXECUTE_READWRITE 0x0040
#endif #endif
typedef unsigned short LE16; typedef size_t acc_uintptr_t;
typedef unsigned long LE32; typedef unsigned short LE16;
#define __attribute_packed typedef unsigned int LE32;
#define get_le32(p) (* (const unsigned *) (p))
#define set_le32(p,v) (* (unsigned *) (p) = (v))
#define get_le16(p) (* (const unsigned short *) (p))
struct ddirs_t #if !defined(__packed_struct)
{ # define __packed_struct(s) struct s {
# define __packed_struct_end() };
#endif
__packed_struct(ddirs_t)
LE32 vaddr; LE32 vaddr;
LE32 size; LE32 size;
} __packed_struct_end()
__attribute_packed;
struct pe_header_t
{ __packed_struct(pe_header_t)
// 0x0 // 0x0
char _[4]; char _[4];
LE16 cpu; LE16 cpu;
@ -97,13 +105,12 @@ struct pe_header_t
char _____[20]; char _____[20];
// 0x74 // 0x74
LE32 ddirsentries; LE32 ddirsentries;
//
struct ddirs_t ddirs[16]; struct ddirs_t ddirs[16];
} __packed_struct_end()
__attribute_packed;
struct pe_section_t
{ __packed_struct(pe_section_t)
char name[8]; char name[8];
LE32 vsize; LE32 vsize;
LE32 vaddr; LE32 vaddr;
@ -111,12 +118,10 @@ struct pe_section_t
LE32 rawdataptr; LE32 rawdataptr;
char _[12]; char _[12];
LE32 flags; LE32 flags;
} __packed_struct_end()
__attribute_packed;
struct exe_header_t __packed_struct(exe_header_t)
{
LE16 mz; LE16 mz;
LE16 m512; LE16 m512;
LE16 p512; LE16 p512;
@ -124,8 +129,8 @@ struct exe_header_t
LE16 relocoffs; LE16 relocoffs;
char __[34]; char __[34];
LE32 nexepos; LE32 nexepos;
} __packed_struct_end()
__attribute_packed;
enum { enum {
PEDIR_EXPORT = 0, PEDIR_EXPORT = 0,
@ -145,9 +150,6 @@ enum {
PEDIR_COMRT = 14 PEDIR_COMRT = 14
}; };
#define get_le32(p) (*(unsigned *) (p))
#define set_le32(p, v) (*(unsigned *) (p) = (v))
#define get_le16(p) (*(unsigned short *) (p))
static struct pe_header_t ih; static struct pe_header_t ih;
static struct pe_section_t isections[4]; static struct pe_section_t isections[4];
@ -213,7 +215,7 @@ static int load(const char *file)
static int read(void) static int read(void)
{ {
unsigned ic; unsigned ic;
#ifdef linux #ifdef __linux__
vaddr = mmap((void *) UPX_MMAP_ADDRESS, ih.imagesize, vaddr = mmap((void *) UPX_MMAP_ADDRESS, ih.imagesize,
PROT_WRITE | PROT_READ | PROT_EXEC, PROT_WRITE | PROT_READ | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
@ -237,7 +239,7 @@ static int read(void)
static void dump(char n) static void dump(char n)
{ {
char buf[100]; char buf[100];
#ifdef linux #ifdef __linux__
snprintf(buf, sizeof(buf), "/tmp/a.dump%c", n); snprintf(buf, sizeof(buf), "/tmp/a.dump%c", n);
#else #else
snprintf(buf, sizeof(buf), "/a.dump%c", n); snprintf(buf, sizeof(buf), "/a.dump%c", n);
@ -247,7 +249,7 @@ static void dump(char n)
fclose(f2); fclose(f2);
} }
static int loadlibraryw(unsigned short *name) static int loadlibraryw(const unsigned short *name)
{ {
return name[0] + name[1] * 0x100 + name[2] * 0x10000; return name[0] + name[1] * 0x100 + name[2] * 0x10000;
} }
@ -315,7 +317,7 @@ static void dump2(int c)
static void call(void) static void call(void)
{ {
#ifndef i386 #ifndef __i386__
void (*entry)(void (*)(int), unsigned) = vaddr + ih.entry; void (*entry)(void (*)(int), unsigned) = vaddr + ih.entry;
entry(dump2, 1); entry(dump2, 1);
dump('z'); dump('z');
@ -346,10 +348,12 @@ static int main2(int argc, char **argv)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
out = stdout; out = stdout;
#ifndef linux #ifndef __linux__
out = fopen("/wtest.log", "wt"); out = fopen("/wtest.log", "wt");
#endif #endif
int ret = main2(argc, argv); int ret = main2(argc, argv);
fclose(out); fclose(out);
return ret; return ret;
} }
/* vim:set ts=4 sw=4 et: */