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

Support for extracting certificates from digitally signed binaries #42

Merged
merged 28 commits into from
Jan 22, 2013
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7bbfdf0
small fix to is_pe so that it will work after seeking elsewhere in th…
Nov 8, 2012
46a8153
libpe: Fix possible memory leaks.
jweyrich Nov 8, 2012
bbe12bd
libpe: Introduce new function pe_get_data_directory.
jweyrich Nov 8, 2012
fcfe946
libpe: Add very basic support for the security directory.
jweyrich Nov 8, 2012
f8ace9e
libpe: Fix indentation and line-breaks.
jweyrich Nov 8, 2012
8f185fe
libpe: Fix missing cert types.
jweyrich Nov 9, 2012
7f270cf
Merge pull request #40 from logan-m-lamb/is_peFix
merces Nov 9, 2012
1d0ae4b
libpe: Ops, fix off-by-1 error.
jweyrich Nov 9, 2012
f54eb30
do not exit readpe if export directory is not found
merces Nov 14, 2012
a001008
Merge branch 'master' of https://github.com/merces/pev into win_certi…
jweyrich Nov 19, 2012
e9accc4
README now contains instructions on how to build in Mac OS X.
jweyrich Dec 29, 2012
8fa06d3
Parse certificates from digitally signed PE's.
jweyrich Dec 29, 2012
1d00753
Fix sign conversion warning.
jweyrich Dec 29, 2012
878d90b
Fix missing static specifier for a couple of functions.
jweyrich Dec 30, 2012
6005050
pesec: Support new CLI parameters --certoutform and --certout.
jweyrich Dec 31, 2012
5decd89
Cosmetic change. Fix style of pointer return and arguments.
jweyrich Dec 31, 2012
70c5021
Fix missing static specifiers.
jweyrich Dec 31, 2012
94e73b7
Remove unused code.
jweyrich Dec 31, 2012
b68490e
Remove more unused code.
jweyrich Dec 31, 2012
6703266
pesec: Only print certificates when --certout is informed.
jweyrich Jan 2, 2013
8a2a85f
pesec: Show all signers and whether certificate signature is valid.
jweyrich Jan 2, 2013
9158bf6
Remove and ignore src/output.
jweyrich Jan 10, 2013
71014bf
Quoting pecoff_v8.docx: "Entries in the section table are numbered st…
jweyrich Jan 10, 2013
faddf52
Merge pull request #41 from marcelomf/master
merces Jan 21, 2013
e58ee84
Add rule to compile peres.
jweyrich Jan 22, 2013
fbe4561
peres: Fix warnings.
jweyrich Jan 22, 2013
a294452
Merge branch 'master' into merge_peres_pesec
jweyrich Jan 22, 2013
5d0fa30
peres: Add constness to string literal.
jweyrich Jan 22, 2013
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
Prev Previous commit
Next Next commit
libpe: Fix possible memory leaks.
  • Loading branch information
jweyrich committed Nov 8, 2012
commit 46a81534b8839c44724b0bbb7046424b920bd816
29 changes: 19 additions & 10 deletions lib/libpe/pe.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ bool pe_get_sections(PE_FILE *pe)

bool pe_get_directories(PE_FILE *pe)
{
IMAGE_DATA_DIRECTORY **dirs;

if (!pe)
return false;

Expand All @@ -230,19 +228,27 @@ bool pe_get_directories(PE_FILE *pe)
if (pe->num_directories > 32)
return false;

dirs = xmalloc(sizeof(IMAGE_DATA_DIRECTORY *) * pe->num_directories);
const size_t directories_size = sizeof(IMAGE_DATA_DIRECTORY *) * pe->num_directories;

pe->directories_ptr = xmalloc(directories_size);
if (!pe->directories_ptr)
return false;

// Zero out the entire block, otherwise if one allocation fails for dirs[i],
// pe_deinit() will try to free wild pointers. This of course does not take
// into consideration that an allocation failure will make the process die.
memset(pe->directories_ptr, 0, directories_size);

for (unsigned int i=0; i < pe->num_directories; i++)
{
dirs[i] = xmalloc(sizeof(IMAGE_DATA_DIRECTORY));
if (!fread(dirs[i], sizeof(IMAGE_DATA_DIRECTORY), 1, pe->handle))
pe->directories_ptr[i] = xmalloc(sizeof(IMAGE_DATA_DIRECTORY));
if (!fread(pe->directories_ptr[i], sizeof(IMAGE_DATA_DIRECTORY), 1, pe->handle))
return false;
}

pe->addr_sections = ftell(pe->handle);
pe->directories_ptr = dirs;

if (!pe->addr_sections || !pe->directories_ptr)
if (!pe->addr_sections)
return false;

return true;
Expand All @@ -269,7 +275,11 @@ bool pe_get_optional(PE_FILE *pe)
if (fseek(pe->handle, pe->addr_optional, SEEK_SET))
return false;

header = xmalloc(sizeof(IMAGE_OPTIONAL_HEADER));
pe->optional_ptr = xmalloc(sizeof(IMAGE_OPTIONAL_HEADER));
if (!pe->optional_ptr)
return false;

header = pe->optional_ptr;

switch (pe->architecture)
{
Expand Down Expand Up @@ -298,10 +308,9 @@ bool pe_get_optional(PE_FILE *pe)
return false;
}

pe->optional_ptr = header;
pe->addr_directories = ftell(pe->handle);

if (!pe->optional_ptr || !pe->addr_directories)
if (!pe->addr_directories)
return false;

return true;
Expand Down