Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add premake and rework into single executable #193

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/win-artifact-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: win-artifact-build

on:
push:
branches: [ build ]

jobs:
build-win64:

runs-on: windows-latest

steps:

- name: Install Cygwin
# You may pin to the exact commit or the version.
# uses: egor-tensin/setup-cygwin@4f96f9fecb8c952fa32ff791b0a77d93d5191bb4
uses: egor-tensin/setup-cygwin@v3
with:
platform: x64 # optional, default is x64
install-dir: c:\tools\cygwin # optional, default is C:\tools\cygwin
packages: gcc-core binutils make zip libssl-devel # optional

- name: Checkout with submodules
uses: actions/checkout@v3
with:
submodules: 'true'

- name: Compile
run: make

- name: Compile Windows-only tools and create a ZIP package
run: make zip

- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: win-build
path: ./*.zip
retention-days: 1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Debug
*.dSYM
*.log
.settings
build/**
src/ofs2rva
src/output
src/pedis
Expand Down
95 changes: 68 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,68 @@
LIBPE_DIR = lib/libpe
PEV_DIR = src
VERSION = 0.82
ZIPDIR = pev-$(VERSION)-win
ZIPFILE = $(ZIPDIR).zip

all:
%:
cd $(LIBPE_DIR) && $(MAKE) $@
cd $(PEV_DIR) && $(MAKE) $@

# Cygwin only
zip:
cd $(PEV_DIR)/windows && $(MAKE)
mkdir -p $(ZIPDIR)/plugins
cp src/build/plugins/*.dll $(ZIPDIR)/plugins/
echo -ne "plugins_dir=plugins\r\n" > $(ZIPDIR)/pev.conf
cp $(PEV_DIR)/userdb.txt $(ZIPDIR)
cp lib/libpe/libpe.dll $(ZIPDIR)/
cp /usr/bin/cygwin1.dll $(ZIPDIR)/
cp /usr/bin/cygcrypto-1*.dll $(ZIPDIR)/
cp /usr/bin/cygz.dll $(ZIPDIR)/
cp README.md $(ZIPDIR)/
cp $(PEV_DIR)/build/*.exe $(ZIPDIR)/
cp $(PEV_DIR)/windows/run.bat $(ZIPDIR)/
zip -r $(ZIPFILE) $(ZIPDIR)/*
rm -rf $(ZIPDIR)
# Alternative GNU Make workspace makefile autogenerated by Premake

ifndef config
config=debug
endif

ifndef verbose
SILENT = @
endif

ifeq ($(config),debug)
pe_config = debug
udis86_config = debug
readpe_config = debug

else ifeq ($(config),release)
pe_config = release
udis86_config = release
readpe_config = release

else
$(error "invalid configuration $(config)")
endif

PROJECTS := pe udis86 readpe

.PHONY: all clean help $(PROJECTS)

all: $(PROJECTS)

pe:
ifneq (,$(pe_config))
@echo "==== Building pe ($(pe_config)) ===="
@${MAKE} --no-print-directory -C lib/libpe -f Makefile config=$(pe_config)
endif

udis86:
ifneq (,$(udis86_config))
@echo "==== Building udis86 ($(udis86_config)) ===="
@${MAKE} --no-print-directory -C lib/libudis86/libudis86 -f Makefile config=$(udis86_config)
endif

readpe: pe udis86
ifneq (,$(readpe_config))
@echo "==== Building readpe ($(readpe_config)) ===="
@${MAKE} --no-print-directory -C src -f Makefile config=$(readpe_config)
endif

clean:
@${MAKE} --no-print-directory -C lib/libpe -f Makefile clean
@${MAKE} --no-print-directory -C lib/libudis86/libudis86 -f Makefile clean
@${MAKE} --no-print-directory -C src -f Makefile clean

help:
@echo "Usage: make [config=name] [target]"
@echo ""
@echo "CONFIGURATIONS:"
@echo " debug"
@echo " release"
@echo ""
@echo "TARGETS:"
@echo " all (default)"
@echo " clean"
@echo " pe"
@echo " udis86"
@echo " readpe"
@echo ""
@echo "For more information, see https://github.com/premake/premake-core/wiki"
13 changes: 12 additions & 1 deletion completion/bash/readpe
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/usr/bin/env bash
complete -F _longopt readpe

function _complete_readpe () {
echo $COMP_LINE
# local _comp=$COMP_LINE
# local _comp=$("${COMP_LINE[@]::${#COMP_LINE[@]}-1} --complete")
local _comp=$($COMP_LINE "--complete")
# printf "headers directories exports"
COMPREPLY=($_comp)
}

complete -F _complete_readpe readpe
complete -F _longopt pedis
complete -F _longopt pehash
complete -F _longopt peldd
Expand All @@ -9,3 +19,4 @@ complete -F _longopt pescan
complete -F _longopt pesec
complete -F _longopt pestr


35 changes: 18 additions & 17 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@

#define MAX_MSG 81
#define MAX_PATH 256
#define VERSION "0.82"

#ifndef VERSION
#define VERSION "1.0"
#endif

#define TOOLKIT "from pev " VERSION " <https://github.com/mentebinaria/readpe/> toolkit"
#define COPY \
"License GPLv2+: GNU GPL version 2 or later <https://www.gnu.org/licenses/gpl-2.0.txt>.\n" \
Expand All @@ -69,19 +73,16 @@
void *malloc_s(size_t size);
void *calloc_s(size_t nmemb, size_t size);

#define PEV_INITIALIZE(config) \
do { \
memset(config, 0, sizeof(*config)); \
pev_load_config(config); \
int ret = plugins_load_all(config); \
if (ret < 0) \
exit(EXIT_FAILURE); \
output_init(); /* Requires plugin for text output. */ \
} while (0)

#define PEV_FINALIZE(config) \
do { \
output_term(); \
plugins_unload_all(); \
pev_cleanup_config(config); \
} while (0)
static inline void PEV_INITIALIZE(pev_config_t *config) {
memset(config, 0, sizeof(*config));
pev_load_config(config);
plugins_load_all(config);
output_init(); /* Requires plugin for text output. */
}

static inline void PEV_FINALIZE(pev_config_t *config) {
output_term();
plugins_unload_all();
pev_cleanup_config(config);
}

40 changes: 40 additions & 0 deletions include/peldd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* vim: set ts=4 sw=4 noet: */
/*
readpe - the PE file analyzer toolkit

Copyright (C) 2023 readpe authors

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

In addition, as a special exception, the copyright holders give
permission to link the code of portions of this program with the
OpenSSL library under certain conditions as described in each
individual source file, and distribute linked combinations
including the two.

You must obey the GNU General Public License in all respects
for all of the code used other than OpenSSL. If you modify
file(s) with this exception, you may extend this exception to your
version of the file(s), but you are not obligated to do so. If you
do not wish to do so, delete this exception statement from your
version. If you delete this exception statement from all source
files in the program, then also delete it here.
*/

#pragma once

#include <libpe/pe.h>

void print_dependencies(pe_ctx_t *ctx);

48 changes: 48 additions & 0 deletions include/peres.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* vim: set ts=4 sw=4 noet: */
/*
readpe - the PE file analyzer toolkit

Copyright (C) 2023 readpe authors

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

In addition, as a special exception, the copyright holders give
permission to link the code of portions of this program with the
OpenSSL library under certain conditions as described in each
individual source file, and distribute linked combinations
including the two.

You must obey the GNU General Public License in all respects
for all of the code used other than OpenSSL. If you modify
file(s) with this exception, you may extend this exception to your
version of the file(s), but you are not obligated to do so. If you
do not wish to do so, delete this exception statement from your
version. If you delete this exception statement from all source
files in the program, then also delete it here.
*/

#pragma once

#include <libpe/context.h>
#include <libpe/pe.h>
#include <libpe/resources.h>
#include <libpe/types_resources.h>
#include <libpe/utlist.h>

void peres_show_nodes(pe_ctx_t *ctx, const pe_resource_node_t *node);
void peres_show_stats(const pe_resource_node_t *node);
void peres_show_list(pe_ctx_t *ctx, const pe_resource_node_t *node);
void peres_save_all_resources(pe_ctx_t *ctx, const pe_resource_node_t *node, bool namedExtract);
void peres_show_version(pe_ctx_t *ctx, const pe_resource_node_t *node);

55 changes: 55 additions & 0 deletions include/pesec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* vim: set ts=4 sw=4 noet: */
/*
readpe - the PE file analyzer toolkit

Copyright (C) 2023 readpe authors

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

In addition, as a special exception, the copyright holders give
permission to link the code of portions of this program with the
OpenSSL library under certain conditions as described in each
individual source file, and distribute linked combinations
including the two.

You must obey the GNU General Public License in all respects
for all of the code used other than OpenSSL. If you modify
file(s) with this exception, you may extend this exception to your
version of the file(s), but you are not obligated to do so. If you
do not wish to do so, delete this exception statement from your
version. If you delete this exception statement from all source
files in the program, then also delete it here.
*/

#pragma once

#include "common.h"
#include <libpe/pe.h>
#include <openssl/pem.h>

typedef enum {
CERT_FORMAT_TEXT = 1,
CERT_FORMAT_PEM = 2,
CERT_FORMAT_DER = 3
} cert_format_e;

typedef struct {
cert_format_e certoutform;
BIO *certout;
} certificate_settings;

bool stack_cookies(pe_ctx_t *ctx);
void print_securities(pe_ctx_t *ctx);
void parse_certificates(const certificate_settings *options, pe_ctx_t *ctx);

Loading