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

代码貌似有误 #5

Open
let-me-look-look-and-see-see opened this issue Apr 17, 2022 · 1 comment
Open

代码貌似有误 #5

let-me-look-look-and-see-see opened this issue Apr 17, 2022 · 1 comment

Comments

@let-me-look-look-and-see-see
Copy link

let-me-look-look-and-see-see commented Apr 17, 2022

一、“2015.3.24-按序号按名字导出函数地址”这节的GetFunctionAddr.cpp的GetRVAFunctionAddrByName函数的74行的if (!ord_in_name_table) 这里有误,因为有可能是i==0也就是函数名字表的第一个就是你要找的name。所以应该再加一个布尔类型的变量,如:bool got_it = false;

改成61到74行改成:
int ord_in_name_table = 0;
bool got_it = false;
for (DWORD i = 0; i < pExportDirectory->NumberOfNames; i++)
{
DWORD t_NameAddr_FOA = 0;
RVA_TO_FOA(pFileBuffer, pDosHeader, pNTHeader, pSectionHeader,
arr_name[i], &t_NameAddr_FOA);

	if (!strcmp((char*)((DWORD)pFileBuffer + t_NameAddr_FOA), name))
	{
		ord_in_name_table = i;
		got_it = true;
		break;
	}
}
if (!got_it)  // 如果一直没有找到
	EXIT_ERROR("there is no function with this name!");

二、"2015.3.25-打印重定位表中的信息/PrintRelocationTable.cpp"的第52行的
t_pAddr = (PDWORD)((DWORD)pRelocationTable + 8);
改成
t_pAddr = (PWORD)((DWORD)pRelocationTable + 8); 因为每个项是两字节的!

三、“2015.3.26(2)-移动重定位表到新增节中/MoveRelocationTable.cpp”的
<1>第126行的
pNewSectionHeader->VirtualAddress = t_LastSectionHeader->VirtualAddress + t_LastSectionHeader->SizeOfRawData;
应该改成
pNewSectionHeader->VirtualAddress = t_LastSectionHeader->VirtualAddress + MAX(t_LastSectionHeader->SizeOfRawData,t_LastSectionHeader->VirtualSize);
其中MAX函数可以定义成函数:
DWORD MAX(DWORD x, DWORD y){
return x>y?x:y;
}
也可以在head.h头文件中定义成宏:
#define MAX(x,y) ( x>y?x:y)
因为拉伸后(PE loader),VirtualSize可能比SizeOfRawData还大!未初始化的空间可能很多(变量声明了但未初始化,也就是所谓的单等号赋值)

<2> 63-64行
PDWORD t_pAddr = NULL;
t_pAddr = (PDWORD)((DWORD)pForeBaseRelocation + 8);
同二改成
PWORD t_pAddr = NULL;
t_pAddr = (PWORD)((DWORD)pForeBaseRelocation + 8);因为每个项是两字节的!

<3> 59行
int num_of_addr = (pForeBaseRelocation->SizeOfBlock - 8) / 2;
应该把num_of_addr定义在while(1)上面,避免重复定义
即:
1)在while(1)上面写int num_of_addr = 0;
2)while(1)里面
int num_of_addr = (pForeBaseRelocation->SizeOfBlock - 8) / 2;
改为
num_of_addr = (pForeBaseRelocation->SizeOfBlock - 8) / 2; ==>去掉int

<4>82行
memset(pAfterBaseRelocation, 0, 8); // 在最后补上8个0
改成
memset(pAfterBaseRelocation, 0, 2); // 在最后补上8个一字节的0
==> VirtualAddress和SizeOfBlock各占4个字节嘛!全零为结束标记!
因为void * __cdecl memset(void , int, size_t);
第二个参数是int,本身就会占据4个字节,4
2=8个字节!完事!

<5>25行
MoveRelocationTable(pFileBuffer, pDosHeader, pNTHeader, pSectionHeader, file_size + 0x100);
你把文件增大了0x2000个字节,然后再空出0x100个字节的空间,才开始黏贴重定位表数据
为什么?空出来的那0x100个字节用来干嘛?我觉得不用空出来吧,直接黏贴重定位表的数据就好了呀!

还有112行
realloc(pFileBuffer, file_size + size_of_new_section * 2);
为什么是size_of_new_section * 2,一个size_of_new_section 空间不够吗?

四、2015.3.27-打印导入表中的信息/PrintImportTable.cpp的
<1> export_ 都应该换成import_ ==> 见名知意
<2>36行的
printf("%s", (PCHAR)(DWORD)pFileBuffer + name_FOA);
改成
printf("%s", (PCHAR)((DWORD)pFileBuffer + name_FOA)); ==> 少了个括号意思不一样!

@smallzhong
Copy link
Owner

谢谢修改,,时间太久了我也不太记得这些代码的细节了,就不在仓库里面改了😵,您有空的话可以提个PR

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

2 participants