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

DOS Header magic not found #59

Open
programminglaboratorys opened this issue Oct 30, 2023 · 0 comments
Open

DOS Header magic not found #59

programminglaboratorys opened this issue Oct 30, 2023 · 0 comments

Comments

@programminglaboratorys
Copy link

programminglaboratorys commented Oct 30, 2023

Info:

C:\Users\ACER\Desktop\myproject\counter>python -V
Python 3.10.11

C:\Users\ACER\Desktop\myproject\counter>python -m pip show pdbparse
Name: pdbparse
Version: 1.5
Summary: Python parser for Microsoft PDB files
Home-page: https://github.com/moyix/pdbparse/
Author: Brendan Dolan-Gavitt
Author-email: [email protected]
License:
Location: c:\users\acer\appdata\roaming\python\python310\site-packages
Requires: construct, construct, pefile
Required-by:

C:\Users\ACER\Desktop\myproject\counter>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30152 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

python code:

#!/usr/bin/python
# coding: utf-8

import os
import sys
import pdbparse
from pdbparse.peinfo import *
from binascii import hexlify


def main(pepath):

    # Extract debug infos from PE.
    guid, pdb_filename = get_external_codeview(pepath)
    print("PE debug infos : %s, %s" % (pdb_filename, guid))

    # Extract corresponding PDB.
    pdbpath = os.path.join(os.path.dirname(pepath), pdb_filename)
    p = pdbparse.parse(pdbpath, fast_load = True)
    pdb = p.streams[pdbparse.PDB_STREAM_PDB]
    pdb.load()
    guidstr = (u'%08x%04x%04x%s%x' % (pdb.GUID.Data1, pdb.GUID.Data2, pdb.GUID.Data3, binascii.hexlify(
        pdb.GUID.Data4).decode('ascii'), pdb.Age)).upper()
    print("PDB Guid : %s" % (guidstr))

    if guid != guidstr:
        print(u'pdb not for this exe')
        sys.exit(-1)
    else:
        dbi = p.streams[pdbparse.PDB_STREAM_DBI]
        dbi.load()

        for (i, fns) in enumerate(dbi.modules):
            module_name = dbi.DBIExHeaders[i].objName.decode('ascii')
            print("[%d] DBI Module : %s" % (i, module_name))
            for fn in fns:
                print(u'\t%s' % fn)
            print(u'-')


if __name__ == u'__main__':
    pepath = sys.argv[1]
    print(pepath)
    main(pepath)

I used cl.exe /Zi /Fd "counter.pdb" "counter.cpp"
to build c++ pdb with this codde

// C++ Program to demonstrate
#include <iostream>
using namespace std;
int main_num = 0;

int add(int num) {
	main_num += num;
	return main_num;
}

int main()
{
	int numadder = 1;
	while (true) {
		printf("%d\r", add(numadder));
	}
	return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant