Новичок
Профиль
Группа: Участник
Сообщений: 9
Регистрация: 8.7.2008
Репутация: нет Всего: нет
|
Здравствуйте. При компиляции dll, сталкнулся с ошибкой LNK2019, использование поиска не дало резльтата. Ошибка: Код | Error 1 error LNK2001: unresolved external symbol "extern "C" unsigned long __cdecl bims_Assemble(char *,unsigned char *,int,int)" (?bims_Assemble@@$$J0YAKPADPAEHH@Z) bims.obj BimsCommander
|
Листинг небольшой, поэтому выкладываю: bims.h Код | #pragma once
#define BIMS_OK 0 #define BIMS_WORKING 1 #define BIMS_ERROR 2
#define DEFAULT_MEMORY_SIZE 0x1000 #define DEFAULT_PASS_LIMIT 100
#define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <stdio.h> #include "AssemblyInfo.cpp" #using <mscorlib.dll>
using namespace System; using namespace System::Text; using namespace System::Runtime::InteropServices; using namespace System::Collections::Generic;
namespace Bims { public ref class BimsCommander { public: BimsCommander(); BimsCommander(IntPtr hProcess);
~BimsCommander();
void AddLine(String ^ szLine); void AddLine(String ^ szFormatString, ... array<Object ^> ^ args); void Add(String ^ szLine); void Add(String ^ szFormatString, ... array<Object ^> ^ args); void InsertLine(String ^ szLine, int nIndex); void Insert(String ^ szLine, int nIndex); void Clear();
array<Byte> ^ Assemble();
bool Inject(IntPtr hProcess, DWORD dwAddress); bool Inject(DWORD dwAddress);
DWORD InjectAndExecute(IntPtr hProcess, DWORD dwAddress, DWORD dwParameter); DWORD InjectAndExecute(IntPtr hProcess, DWORD dwAddress); DWORD InjectAndExecute(DWORD dwAddress);
IntPtr InjectAndExecuteEx(IntPtr hProcess, DWORD dwAddress, DWORD dwParameter); IntPtr InjectAndExecuteEx(IntPtr hProcess, DWORD dwAddress); IntPtr InjectAndExecuteEx(DWORD dwAddress);
IntPtr GetProcessHandle() { return m_hProcess; } void SetProcessHandle(IntPtr Value) { m_hProcess = Value; }
int GetMemorySize() { return m_MemorySize; } void SetMemorySize(int Value) { m_MemorySize = Value; }
int GetPassLimit() { return m_PassLimit; } void SetPassLimit(int Value) { m_PassLimit = Value; }
static array<Byte> ^ Assemble(String ^ szSource); static array<Byte> ^ Assemble(String ^ szSource, int nMemorySize); static array<Byte> ^ Assemble(String ^ szSource, int nMemorySize, int nPassLimit);
private: StringBuilder ^ m_AssemblyString; List<IntPtr> ^ m_ThreadHandles;
IntPtr m_hProcess; int m_MemorySize; int m_PassLimit; }; }
|
bims.cpp Код | #include "bims.h"
#pragma region UNMANAGED #pragma unmanaged
typedef struct _c_BimsLineHeader { char * file_path; DWORD line_number; union { DWORD file_offset; DWORD macro_offset_line; }; _c_BimsLineHeader * macro_line; } _C_BIMS_LINE_HEADER;
typedef struct _c_BimsState { int condition; union { int error_code; DWORD output_length; }; union { BYTE * output_data; _c_BimsLineHeader * error_data; }; } _C_BIMS_STATE;
extern "C" DWORD bims_Assemble(char * szSource, BYTE * lpMemory, int nSize, int nPassesLimit);
BYTE * _c_bims_memorybuf;
DWORD _c_BimsAssemble(char * szSource, DWORD nMemorySize, DWORD nPassesLimit) { DWORD dwBimsReturn; if (strlen(szSource) == 0) return NULL;
if (nPassesLimit == 0) nPassesLimit = DEFAULT_PASS_LIMIT;
if (nMemorySize == 0) nMemorySize = DEFAULT_MEMORY_SIZE;
if (_c_bims_memorybuf) delete[] _c_bims_memorybuf;
_c_bims_memorybuf = new BYTE[nMemorySize];
dwBimsReturn = bims_Assemble(szSource, _c_bims_memorybuf, nMemorySize, nPassesLimit);
return dwBimsReturn; } #pragma endregion
#pragma managed
namespace Bims { BimsCommander::BimsCommander() { m_AssemblyString = gcnew StringBuilder("use32\n"); m_ThreadHandles = gcnew List<IntPtr>();
m_MemorySize = DEFAULT_MEMORY_SIZE; m_PassLimit = DEFAULT_PASS_LIMIT; }
BimsCommander::BimsCommander(IntPtr hProcess) { m_hProcess = hProcess;
m_AssemblyString = gcnew StringBuilder("use32\n"); m_ThreadHandles = gcnew List<IntPtr>();
m_MemorySize = DEFAULT_MEMORY_SIZE; m_PassLimit = DEFAULT_PASS_LIMIT; }
BimsCommander::~BimsCommander() { for (int i = 0; i < m_ThreadHandles->Count; i++) CloseHandle((HANDLE)(m_ThreadHandles[i].ToInt32())); m_ThreadHandles->Clear(); }
void BimsCommander::AddLine(String ^ szLine) { m_AssemblyString->Append(szLine + "\n"); }
void BimsCommander::AddLine(String ^ szFormatString, ... array<Object ^> ^ args) { m_AssemblyString->AppendFormat(szFormatString + "\n", args); }
void BimsCommander::Add(String ^ szLine) { m_AssemblyString->Append(szLine); }
void BimsCommander::Add(String ^ szFormatString, ... array<Object ^> ^ args) { m_AssemblyString->AppendFormat(szFormatString, args); }
void BimsCommander::InsertLine(String ^ szLine, int nIndex) { m_AssemblyString->Insert(nIndex, szLine + "\n"); }
void BimsCommander::Insert(String ^ szLine, int nIndex) { m_AssemblyString->Insert(nIndex, szLine); }
array<Byte> ^ BimsCommander::Assemble() { return BimsCommander::Assemble(m_AssemblyString->ToString(), m_MemorySize, m_PassLimit); }
void BimsCommander::Clear() { m_AssemblyString = gcnew StringBuilder("use32\n"); }
bool BimsCommander::Inject(IntPtr hProcess, DWORD dwAddress) { if (hProcess == IntPtr::Zero) return false;
if (m_AssemblyString->ToString()->Contains("use64") || m_AssemblyString->ToString()->Contains("use16")) m_AssemblyString->Replace("use32\n", "");
if (!m_AssemblyString->ToString()->Contains("org ")) m_AssemblyString->Insert(0, String::Format("org 0x{0:X08}\n", dwAddress));
IntPtr lpSource = IntPtr::Zero;
try { lpSource = Marshal::StringToHGlobalAnsi(m_AssemblyString->ToString()); _c_BimsAssemble((char *)lpSource.ToPointer(), m_MemorySize, m_PassLimit); } catch (Exception ^ ex) { Console::WriteLine(ex->Message); return false; } finally { if (lpSource != IntPtr::Zero) Marshal::FreeHGlobal(lpSource); }
_C_BIMS_STATE * bims_state = reinterpret_cast<_C_BIMS_STATE *>(_c_bims_memorybuf); if (bims_state->condition != BIMS_OK) throw gcnew Exception(String::Format("Assembly failed! Error code: {0}; Error Line: {1}", bims_state->error_code, bims_state->error_data->line_number)); return WriteProcessMemory((HANDLE)hProcess, (void *)dwAddress, bims_state->output_data, bims_state->output_length, NULL); }
bool BimsCommander::Inject(DWORD dwAddress) { return this->Inject(m_hProcess, dwAddress); }
DWORD BimsCommander::InjectAndExecute(IntPtr hProcess, DWORD dwAddress, DWORD dwParameter) { if (hProcess == IntPtr::Zero) throw gcnew ArgumentNullException("hProcess");
if (dwAddress == NULL) throw gcnew ArgumentNullException("dwAddress");
HANDLE hThread; DWORD dwExitCode = 0;
if (!this->Inject(hProcess, dwAddress)) throw gcnew Exception("Injection failed for some reason.");
hThread = CreateRemoteThread((HANDLE)(hProcess.ToInt32()), NULL, 0, (LPTHREAD_START_ROUTINE)dwAddress, (void *)dwParameter, 0, NULL); if (hThread == NULL) throw gcnew Exception("Remote thread failed.");
try { if (WaitForSingleObject(hThread, 10000) == WAIT_OBJECT_0) if (!GetExitCodeThread(hThread, &dwExitCode)) throw gcnew Exception("Could not get thread exit code."); } finally { CloseHandle(hThread); } return dwExitCode; }
DWORD BimsCommander::InjectAndExecute(IntPtr hProcess, DWORD dwAddress) { return this->InjectAndExecute(hProcess, dwAddress, NULL); }
DWORD BimsCommander::InjectAndExecute(DWORD dwAddress) { return this->InjectAndExecute(m_hProcess, dwAddress, NULL); }
IntPtr BimsCommander::InjectAndExecuteEx(IntPtr hProcess, DWORD dwAddress, DWORD dwParameter) { HANDLE hThread;
this->Inject(hProcess, dwAddress);
hThread = CreateRemoteThread((HANDLE)(hProcess.ToInt32()), NULL, 0, (LPTHREAD_START_ROUTINE)dwAddress, (void *)dwParameter, 0, NULL); m_ThreadHandles->Add((IntPtr)hThread); return (IntPtr)hThread; }
IntPtr BimsCommander::InjectAndExecuteEx(IntPtr hProcess, DWORD dwAddress) { return this->InjectAndExecuteEx(hProcess, dwAddress, NULL); }
IntPtr BimsCommander::InjectAndExecuteEx(DWORD dwAddress) { return this->InjectAndExecuteEx(m_hProcess, dwAddress, NULL); }
#pragma region Static Methods array<Byte> ^ BimsCommander::Assemble(String ^ szSource) { return BimsCommander::Assemble(szSource, DEFAULT_MEMORY_SIZE, DEFAULT_PASS_LIMIT); }
array<Byte> ^ BimsCommander::Assemble(String ^ szSource, int nMemorySize) { return BimsCommander::Assemble(szSource, nMemorySize, DEFAULT_PASS_LIMIT); }
array<Byte> ^ BimsCommander::Assemble(String ^ szSource, int nMemorySize, int nPassLimit) { array<Byte> ^ bBytecode; DWORD dwAssembleRet; _C_BIMS_STATE *bims_state; IntPtr lpSource;
lpSource = Marshal::StringToHGlobalAnsi(szSource);
dwAssembleRet = _c_BimsAssemble((char *)lpSource.ToPointer(), nMemorySize, nPassLimit); bims_state = reinterpret_cast<_C_BIMS_STATE *>(_c_bims_memorybuf); Marshal::FreeHGlobal(lpSource);
if (bims_state->condition == BIMS_OK) { bBytecode = gcnew array<Byte>(bims_state->output_length); Marshal::Copy((IntPtr)(bims_state->output_data), bBytecode, 0, bims_state->output_length); } else { throw gcnew Exception(String::Format("Assembly failed! Error code: {0}; Error Line: {1}", bims_state->error_code, bims_state->error_data->line_number)); } return bBytecode; } #pragma endregion }
|
Содержимое bims.vcproj Код | <?xml version="1.0" encoding="windows-1251"?> <VisualStudioProject ProjectType="Visual C++" Version="9,00" Name="BimsCommander" ProjectGUID="{AD9E3605-4B01-4436-B423-C3E74EF0784C}" RootNamespace="bims" Keyword="ManagedCProj" TargetFrameworkVersion="196613" > <Platforms> <Platform Name="Win32" /> </Platforms> <ToolFiles> </ToolFiles> <Configurations> <Configuration Name="Debug|Win32" OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" ConfigurationType="2" CharacterSet="1" ManagedExtensions="1" > <Tool Name="VCPreBuildEventTool" /> <Tool Name="VCCustomBuildTool" /> <Tool Name="VCXMLDataGeneratorTool" /> <Tool Name="VCWebServiceProxyGeneratorTool" /> <Tool Name="VCMIDLTool" /> <Tool Name="VCCLCompilerTool" Optimization="0" PreprocessorDefinitions="WIN32;_DEBUG" RuntimeLibrary="2" UsePrecompiledHeader="0" WarningLevel="3" DebugInformationFormat="3" /> <Tool Name="VCManagedResourceCompilerTool" /> <Tool Name="VCResourceCompilerTool" /> <Tool Name="VCPreLinkEventTool" /> <Tool Name="VCLinkerTool" AdditionalDependencies="$(NoInherit)" LinkIncremental="2" GenerateDebugInformation="true" AssemblyDebug="2" TargetMachine="1" /> <Tool Name="VCALinkTool" /> <Tool Name="VCManifestTool" /> <Tool Name="VCXDCMakeTool" /> <Tool Name="VCBscMakeTool" /> <Tool Name="VCFxCopTool" /> <Tool Name="VCAppVerifierTool" /> <Tool Name="VCPostBuildEventTool" /> </Configuration> <Configuration Name="Release|Win32" OutputDirectory="bin\$(ConfigurationName)" IntermediateDirectory="bin\$(ConfigurationName)" ConfigurationType="2" CharacterSet="1" ManagedExtensions="1" WholeProgramOptimization="1" > <Tool Name="VCPreBuildEventTool" /> <Tool Name="VCCustomBuildTool" /> <Tool Name="VCXMLDataGeneratorTool" /> <Tool Name="VCWebServiceProxyGeneratorTool" /> <Tool Name="VCMIDLTool" /> <Tool Name="VCCLCompilerTool" PreprocessorDefinitions="WIN32;NDEBUG" RuntimeLibrary="2" UsePrecompiledHeader="0" WarningLevel="3" DebugInformationFormat="3" /> <Tool Name="VCManagedResourceCompilerTool" /> <Tool Name="VCResourceCompilerTool" /> <Tool Name="VCPreLinkEventTool" /> <Tool Name="VCLinkerTool" AdditionalDependencies="$(NOINHERIT)" LinkIncremental="1" IgnoreEmbeddedIDL="false" GenerateDebugInformation="true" SubSystem="1" TargetMachine="1" /> <Tool Name="VCALinkTool" /> <Tool Name="VCManifestTool" /> <Tool Name="VCXDCMakeTool" /> <Tool Name="VCBscMakeTool" /> <Tool Name="VCFxCopTool" /> <Tool Name="VCAppVerifierTool" /> <Tool Name="VCPostBuildEventTool" /> </Configuration> </Configurations> <References> <AssemblyReference RelativePath="System.dll" AssemblyName="System, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" MinFrameworkVersion="131072" /> <AssemblyReference RelativePath="System.Data.dll" AssemblyName="System.Data, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86" MinFrameworkVersion="131072" /> <AssemblyReference RelativePath="System.XML.dll" AssemblyName="System.Xml, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" MinFrameworkVersion="131072" /> </References> <Files> <Filter Name="Source Files" Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > <File RelativePath=".\AssemblyInfo.cpp" > </File> <File RelativePath=".\bims.cpp" > </File> </Filter> <Filter Name="Header Files" Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > <File RelativePath=".\bims.h" > </File> </Filter> </Files> <Globals> </Globals> </VisualStudioProject>
|
|