Skip to content

Commit

Permalink
v 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixaill committed Mar 7, 2021
1 parent 3c93e3e commit 2d84f49
Show file tree
Hide file tree
Showing 56 changed files with 9,233 additions and 5,652 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
build/
~build/
cmake-build-*/

.idea/
.vscode/

*.pyc
*.pyc
33 changes: 20 additions & 13 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

Tool for PDB generation from IDA Pro database

Supports IDA >= 7.0
Supports:
* IDA >= 7.4

## TODO

* Linux support
* GHIDRA support
* Function arguments support

## How to get

Expand All @@ -13,31 +20,37 @@ Supports IDA >= 7.0

## How to install

* copy content of `fakepdb.zip` to `<IDA_directory>/plugins`
* IDA
* copy content of `fakepdb.zip/ida` to `<IDA_directory>/plugins`

## How to use

There are several features in this plugin:

### 1. PDB file generation
* Open target executable in IDA >= 7.0
### PDB file generation
* Open target executable in IDA
* `Edit` -> `FakePDB` -> `Generate .PDB file` (or `Ctrl`+`Shift`+`4`)
* get PDB file from the IDA database directory

The PDB can optionally include symbols for function labels: use `Generate .PDB file (with function labels)` (or `Ctrl`+`Shift`+`5`).

### 2. IDA database export to .json
### LIB file generation
* Open target executable in IDA
* `Edit` -> `FakePDB` -> `Generate .LIB file`
* get LIB file from the IDA database directory

### IDA database export to .json
* Open target executable in IDA >= 7.0
* `Edit` -> `FakePDB` -> `Dump info to .json` (or `Ctrl`+`Shift`+`1`)
* it will generate `filename.json` near the `.idb` file

### 3. Binary signature search
### Binary signature search
* Open target executable in IDA >= 7.0
* Set cursor on start of the target function
* `Edit` -> `FakePDB` -> `Find signature` (or `Ctrl`+`Shift`+`2`)
* signature will be displayed in IDA console

### 4. Function names import from `.json` file
### Function names import from `.json` file
* Open target executable in IDA >= 7.0
* `Edit` -> `FakePDB` -> `Import offset from .json` (or `Ctrl`+`Shift`+`3`)

Expand All @@ -56,12 +69,6 @@ where:
* `YYYY`: offset from the begining of the section in decimal numbers
* 0x0124567AF: IDA effective address

## TODO

* GHIDRA support
* Linux support
* Function arguments support


## Thanks

Expand Down
98 changes: 65 additions & 33 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,44 +1,75 @@
#
# Config
#

$build_llvm = $true

#
# Set environment
#

Push-Location $PSScriptRoot
$root = (Get-Location).Path -replace "\\","/"

#https://stackoverflow.com/a/64744522
Push-Location "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools"
cmd /c "VsDevCmd.bat -arch=amd64 -host_arch=amd64&set " |
ForEach-Object {
if ($_ -match "=") {
$v = $_.split("="); set-item -force -path "ENV:\$($v[0])" -value "$($v[1])"
}
}
Pop-Location

#
# Build LLVM
#

git clone --depth=1 https://github.com/llvm/llvm-project "./~build/llvm_git" -q

cmake "./~build/llvm_git/llvm" -B"./~build/llvm_build" `
-DCMAKE_BUILD_TYPE="Release" `
-DCMAKE_INSTALL_PREFIX="./~build/llvm_install" `
-DLLVM_BUILD_LLVM_C_DYLIB=OFF `
-DLLVM_BUILD_RUNTIME=OFF `
-DLLVM_BUILD_RUNTIMES=OFF `
-DLLVM_BUILD_TOOLS=OFF `
-DLLVM_BUILD_UTILS=OFF `
-DLLVM_ENABLE_BACKTRACES=OFF `
-DLLVM_ENABLE_BINDINGS=OFF `
-DLLVM_ENABLE_CRASH_OVERRIDES=OFF `
-DLLVM_ENABLE_OCAMLDOC=OFF `
-DLLVM_ENABLE_PDB=ON `
-DLLVM_INCLUDE_BENCHMARKS=OFF `
-DLLVM_INCLUDE_DOCS=OFF `
-DLLVM_INCLUDE_EXAMPLES=OFF `
-DLLVM_INCLUDE_GO_TESTS=OFF `
-DLLVM_INCLUDE_RUNTIMES=OFF `
-DLLVM_INCLUDE_TESTS=OFF `
-DLLVM_INCLUDE_TOOLS=OFF `
-DLLVM_INCLUDE_UTILS=OFF `
-DLLVM_TARGETS_TO_BUILD=""

cmake --build "./~build/llvm_build" --config Release --target INSTALL
if($true -eq $build_llvm){
git clone --depth=1 https://github.com/llvm/llvm-project "./~build/llvm_git"

cmake "./~build/llvm_git/llvm" `
-B"./~build/llvm_build" `
-GNinja `
-DCMAKE_BUILD_TYPE="Release" `
-DCMAKE_INSTALL_PREFIX="./~build/llvm_install" `
-DLLVM_BUILD_LLVM_C_DYLIB=OFF `
-DLLVM_BUILD_RUNTIME=OFF `
-DLLVM_BUILD_RUNTIMES=OFF `
-DLLVM_BUILD_TOOLS=OFF `
-DLLVM_BUILD_UTILS=OFF `
-DLLVM_ENABLE_BACKTRACES=OFF `
-DLLVM_ENABLE_BINDINGS=OFF `
-DLLVM_ENABLE_CRASH_OVERRIDES=OFF `
-DLLVM_ENABLE_OCAMLDOC=OFF `
-DLLVM_ENABLE_PDB=ON `
-DLLVM_INCLUDE_BENCHMARKS=OFF `
-DLLVM_INCLUDE_DOCS=OFF `
-DLLVM_INCLUDE_EXAMPLES=OFF `
-DLLVM_INCLUDE_GO_TESTS=OFF `
-DLLVM_INCLUDE_RUNTIMES=OFF `
-DLLVM_INCLUDE_TESTS=OFF `
-DLLVM_INCLUDE_TOOLS=OFF `
-DLLVM_INCLUDE_UTILS=OFF `
-DLLVM_TARGETS_TO_BUILD=""

cmake --build "./~build/llvm_build"
cmake --install "./~build/llvm_build"
}

#
# Build PDBGen
#

cmake "./src_pdbgen/" -B"./~build/pdbgen_build" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_INSTALL_PREFIX="./~build/pdbgen_install" -DCMAKE_PREFIX_PATH="$root/~build/llvm_install"
cmake --build "./~build/pdbgen_build" --config Release --target INSTALL
cmake "./src_cpp/" `
-B"./~build/fakepdb_build" `
-GNinja `
-DCMAKE_BUILD_TYPE="Release" `
-DCMAKE_INSTALL_PREFIX="./~build/fakepdb_install" `
-DCMAKE_PREFIX_PATH="$root/~build/llvm_install"

cmake --build "./~build/fakepdb_build"
cmake --install "./~build/fakepdb_build"

#
# Sign
Expand Down Expand Up @@ -66,18 +97,19 @@ function Sign-Folder($Folder, $Filters = @("*.exe", "*.dll"), $TimestampServer =

if(Sign-IsAvailable){
Write-Output "Signing files"
Sign-Folder -Folder "./~build/pdbgen_install/bin/"
Sign-Folder -Folder "./~build/fakepdb_install/bin/"
Write-Output ""
}

#
# Copy files
#

New-Item -Path "./~build/deploy" -ItemType Directory -ErrorAction SilentlyContinue
Copy-Item -Path "./src_ida/*" -Destination "./~build/deploy/" -Recurse
New-Item -Path "./~build/deploy/fakepdb/win32/" -ItemType Directory -ErrorAction SilentlyContinue
Copy-Item -Path "./~build/pdbgen_install/bin/*.exe" -Destination "./~build/deploy/fakepdb/win32/" -Recurse
New-Item -Path "./~build/deploy/ida" -ItemType Directory -ErrorAction SilentlyContinue
Copy-Item -Path "./src_plugins/ida/*" -Destination "./~build/deploy/ida/" -Recurse

New-Item -Path "./~build/deploy/ida/fakepdb/win32/" -ItemType Directory -ErrorAction SilentlyContinue
Copy-Item -Path "./~build/fakepdb_install/bin/*.exe" -Destination "./~build/deploy/ida/fakepdb/win32/" -Recurse

#
# Pack files
Expand Down
94 changes: 94 additions & 0 deletions src_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#
# Copyright 2019-2021 Mikhail Paulyshka
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# Global project settings
#

cmake_minimum_required(VERSION 3.16)
project(FakePDB)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

#
# Packages
#
find_package(LLVM REQUIRED CONFIG)

#
# Compiler settings
#

if (MSVC)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
add_compile_definitions(_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)
add_compile_definitions(__STDC_WANT_SECURE_LIB__=1)

add_compile_options(/Wall)
add_compile_options(/wd4061 /wd4100 /wd4146 /wd4242 /wd4244 /wd4245 /wd4266 /wd4267 /wd4324 /wd4365 /wd4458 /wd4459 /wd4514 /wd4582 /wd4583 /wd4623 /wd4624 /wd4625 /wd4626 /wd4702 /wd4710 /wd4711 /wd4774 /wd4800 /wd4820 /wd5026 /wd5027 /wd5045)
else()
add_compile_options(-Wall -Wextra)
endif()

#
# fakepdb executable
#

add_executable(fakepdb)
target_sources(fakepdb PRIVATE
src/main.cpp

include/coff/lib_creator.h
src/coff/lib_creator.cpp

include/commands/command_coff_createlib.h
include/commands/command_interface.h
include/commands/command_pdb_generate.h
include/commands/command_pe_exports.h
include/commands/command_pe_guidage.h
include/commands/command_pe_timestamp.h

include/common/guid.h
include/common/hex.h

include/data/db.h
include/data/export.h
include/data/function.h
include/data/general.h
include/data/label.h
include/data/name.h
include/data/root.h
include/data/segment.h
src/data/db.cpp

include/pdb/pdb_creator.h
src/pdb/pdb_creator.cpp

include/pe/pe_file.h
src/pe/pe_file.cpp
)

target_include_directories(fakepdb PUBLIC ${LLVM_INCLUDE_DIRS})
target_include_directories(fakepdb PUBLIC "include")
target_include_directories(fakepdb PUBLIC ".")

llvm_map_components_to_libnames(llvm_libs core support DebugInfoPDB)
target_link_libraries(fakepdb ${llvm_libs})

install(
TARGETS fakepdb
RUNTIME DESTINATION bin
)
14 changes: 14 additions & 0 deletions src_cpp/include/coff/lib_creator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

//stdlib
#include <filesystem>

//fakepdb
#include "data/db.h"

namespace FakePDB::COFF {
class LibCreator {
public:
bool Create(Data::DB &db, std::filesystem::path& path);
};
}
58 changes: 58 additions & 0 deletions src_cpp/include/commands/command_coff_createlib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//stdlib
#include <filesystem>
#include <fstream>
#include <iostream>

//nlohmann
#include "nlohmann/json.hpp"

//FakePDB
#include "commands/command_interface.h"
#include "coff/lib_creator.h"

namespace FakePDB::Commands {
class CommandCoffCreatelib : public CommandInterface {
public:
~CommandCoffCreatelib() = default;

int32_t GetArgsMin() override {
return 2;
};

int32_t GetArgsMax() override {
return 2;
};

std::string GetCommandName() override {
return "coff_createlib";
}

std::vector<std::string> GetCommandUsage() override {
return { "<json_filepath> [lib_path]" };
}

std::string GetCommandDescription() override {
return "creates .lib file from .json";
}

int Run(int argc, char* argv[]) override {
std::filesystem::path path_json = argv[2];
std::filesystem::path path_lib = argv[3];

if (!std::filesystem::exists(path_json)) {
std::cerr << "json file does not exists";
return 1;
}

Data::DB db(path_json);

COFF::LibCreator libCreator;
if(!libCreator.Create(db, path_lib)) {
std::cerr << "failed to create lib";
return 2;
}

return 0;
}
};
}
Loading

0 comments on commit 2d84f49

Please sign in to comment.