コード例 #1
0
ファイル: ApplyDlg.cpp プロジェクト: boogie1337/IDAplugins
BOOL Main_Apply_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
	HWND hList = GetDlgItem(hwnd,IDC_LIST_SEGMEN);

	CheckedListBox_SetFlatStyleChecks(hList, TRUE);
	
	

	char szFilePath[256 * 2] = {0};
	strncpy(szFilePath, database_idb, 256);
	char *lpTmpBuf = strrchr(szFilePath, '\\') + 1;
	if(lpTmpBuf == (char*)1)
	{
		return FALSE;
	}
	*lpTmpBuf = 0;
	get_root_filename(lpTmpBuf, 256);
	HANDLE hFile=CreateFile(szFilePath, GENERIC_WRITE | GENERIC_READ, 0, 
		NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);   //获得文件句柄
	if(hFile == INVALID_HANDLE_VALUE)
	{
		msg("Apply Path:%s\n", szFilePath);
		msg("失败!目标%s文件不存在 或 文件无法打开    ErrorCode:%d\n", szFilePath, GetLastError());
		MoveWindowCenter(g_hwndMain, hwnd);
		return FALSE;
	}
	CloseHandle(hFile);
	int i;
	segment_t *curseg;
	int seg_qty = get_segm_qty();
	netnode n("$ Apply SegMen");
	if(BADNODE == (nodeidx_t)n)
	{
		netnode n("$ Apply SegMen", 0, true);
		for(i=0 ; i < seg_qty; i++)
		{
			BOOL bStats = FALSE;
			char segname[0x100] = {0};
			curseg = getnseg(i);
			get_true_segm_name(curseg, segname, 255);
			ListBox_InsertString(hList, -1, segname);
			bStats = !IsFilterTable(segname);
			if(bStats)
			{
				msg("segname:%s, type:%d\n", segname, curseg->type);
				bStats = curseg->type == SEG_CODE;
			}
			if(get_fileregion_offset(curseg->startEA) > 0)
			{
				CheckedListBox_SetCheckState(hList, i, bStats);
				n.altset(i, bStats);
			}

		}
		n.altset(CHECK_BACKFILE_INDEX, 1);
		CheckDlgButton( hwnd,IDC_APPLY_CHECK_BACK,   BST_CHECKED   );
	}
	else
	{
		for(i=0 ; i < seg_qty; i++)
		{
			char segname[0x100] = {0};
			curseg = getnseg(i);
			get_true_segm_name(curseg, segname, 255);
			ListBox_InsertString(hList, -1, segname);
			if(get_fileregion_offset(curseg->startEA) > 0)
			{
				CheckedListBox_SetCheckState(hList, i, n.altval(i));
			}
		}
		if(n.altval(CHECK_BACKFILE_INDEX))
		{
			CheckDlgButton( hwnd, IDC_APPLY_CHECK_BACK,  BST_CHECKED  );
		}
	}
	
	MoveWindowCenter(g_hwndMain, hwnd);
	return FALSE;
}
コード例 #2
0
ファイル: ApplyDlg.cpp プロジェクト: boogie1337/IDAplugins
void  Apply_patches(HWND hwnd)
{
	HWND hList = GetDlgItem(hwnd,IDC_LIST_SEGMEN);
	netnode n("$ Apply SegMen");
	char szFilePath[256 * 2] = {0};
	strncpy(szFilePath, database_idb, 256);
	char *lpTmpBuf = strrchr(szFilePath, '\\') + 1;
	if(lpTmpBuf == (char*)1)
	{
		return;
	}
	*lpTmpBuf = 0;
	get_root_filename(lpTmpBuf, 256);
	msg("=============================\n");
	msg("Apply Path:%s\n", szFilePath);
	if(IsDlgButtonChecked(hwnd, IDC_APPLY_CHECK_BACK))
	{
		char szBackPath[300] = {0};
		sprintf(szBackPath, "%s.back", szFilePath);
		msg("BackFile Path:%s.back\n", szFilePath);
		CopyFile(szFilePath, szBackPath, FALSE);
		n.altset(CHECK_BACKFILE_INDEX, 1);
	}
	else
	{
		n.altset(CHECK_BACKFILE_INDEX, 0);
	}
	HANDLE hFile=CreateFile(szFilePath, GENERIC_WRITE | GENERIC_READ, 0, 
		NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);   //获得文件句柄
	HANDLE hMapping=CreateFileMapping(hFile,NULL,PAGE_READWRITE,0,0,NULL);  //创建内存映射对象
	if(INVALID_HANDLE_VALUE == hMapping)
	{
		msg("CreateFileMapping :%08X ErrorCode:%d\n", hMapping, GetLastError());
		return ;
	}
	unsigned char* pvFile=(unsigned char*)MapViewOfFile(hMapping,FILE_MAP_ALL_ACCESS,0,0,0); //创建视图 就是映射文件到内存;

	int i;
	segment_t *curseg;
	int seg_qty = get_segm_qty();
	for(i=0 ; i < seg_qty; i++)
	{
		char segname[0x100] = {0};
		curseg = getnseg(i);
		get_true_segm_name(curseg, segname, 255);
		int offset = get_fileregion_offset(curseg->startEA);
		int nSize = curseg->endEA - curseg->startEA;
		int nSelectStat = CheckedListBox_GetCheckState(hList, i);
		n.altset(i, nSelectStat);
		if(offset > 0 && nSelectStat)
		{
			//msg("offset:%X  segname:%s EA:%08X, nSize: %X\n", offset, segname, curseg->startEA, nSize);
			unsigned char *lpMem = (unsigned char*)malloc(nSize + 1);
			memset(lpMem, 0, nSize + 1);
			//if(get_many_bytes(curseg->startEA, lpMem, nSize))
			if(segReadBuf(curseg->startEA, lpMem, nSize))
			{
				msg("Apply SegMenName: %s\n", segname);
				SegWriteFile(pvFile, lpMem, nSize, offset);
			}
			//msg("lpMem:%X\n", lpMem);
			free(lpMem);
		}

		//	msg("Name:%s, StartEA:%08X, Offset:%08X, EndEA:%08X\n", segname, curseg->startEA, offset, curseg->endEA);


	}
	CloseHandle(hMapping);
	//	msg("CloseHandle(hMapping)\n");
	if(0 == UnmapViewOfFile(pvFile) )
	{
		msg("文件同步失败! ErrorCode:%d\n", GetLastError());
	}
	else
	{
		msg("文件同步成功!\n");
		msg("=============================\n");
	}
	//	msg("UnmapViewOfFile(pvFile);\n");
	CloseHandle(hFile);
	
	return;
}
コード例 #3
0
ファイル: Apply.cpp プロジェクト: Artorios/IDAplugins-1
void  Apply_patches()
{
	char szFilePath[256 * 2] = {0};
	strncpy(szFilePath, database_idb, 256);
	char *lpTmpBuf = strrchr(szFilePath, '\\') + 1;
	if(lpTmpBuf == (char*)1)
	{
		return;
	}
	*lpTmpBuf = 0;
	get_root_filename(lpTmpBuf, 256);
	msg("Apply Path:%s\n", szFilePath);
	HANDLE hFile=CreateFile(szFilePath, GENERIC_WRITE | GENERIC_READ, 0, 
		NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);   //获得文件句柄
	if(hFile == INVALID_HANDLE_VALUE)
	{
		msg("失败!目标%s文件不存在 或 文件无法打开    ErrorCode:%d\n", szFilePath, GetLastError());
		return;
	}
	HANDLE hMapping=CreateFileMapping(hFile,NULL,PAGE_READWRITE,0,0,NULL);  //创建内存映射对象
	if(INVALID_HANDLE_VALUE == hMapping)
	{
		msg("CreateFileMapping :%08X ErrorCode:%d\n", hMapping, GetLastError());
	}
	unsigned char* pvFile=(unsigned char*)MapViewOfFile(hMapping,FILE_MAP_ALL_ACCESS,0,0,0); //创建视图 就是映射文件到内存;

	int i;
	segment_t *curseg;
	int seg_qty = get_segm_qty();
	for(i=0 ; i < seg_qty; i++)
	{
		char segname[0x100] = {0};
		curseg = getnseg(i);
		get_true_segm_name(curseg, segname, 255);
		int offset = get_fileregion_offset(curseg->startEA);
		int nSize = curseg->endEA - curseg->startEA;
		if(offset > 0 && !IsFilterTable(segname))
		{
			//msg("offset:%X  segname:%s EA:%08X, nSize: %X\n", offset, segname, curseg->startEA, nSize);
			unsigned char *lpMem = (unsigned char*)malloc(nSize + 1);
			memset(lpMem, 0, nSize + 1);
			//if(get_many_bytes(curseg->startEA, lpMem, nSize))
			if(segReadBuf(curseg->startEA, lpMem, nSize))
			{
				SegWriteFile(pvFile, lpMem, nSize, offset);
			}
			//msg("lpMem:%X\n", lpMem);
			free(lpMem);
		}

		//	msg("Name:%s, StartEA:%08X, Offset:%08X, EndEA:%08X\n", segname, curseg->startEA, offset, curseg->endEA);


	}
	CloseHandle(hMapping);
//	msg("CloseHandle(hMapping)\n");
	UnmapViewOfFile(pvFile);
//	msg("UnmapViewOfFile(pvFile);\n");
	CloseHandle(hFile);
	msg("文件同步成功!\n");
	return;
}