--this script was intended to be private, where the fuck did you get it?
--well, I guess you're one of the guys whom I trust, don't fail me

dumpstart=0x0;
dumpend=0x0;
manual=true;

unhookarray={};

function UnhookArrayList()
	ClearUnhookList();
	local z=1;
	while true do
		if unhookarray[z]==nil then
			break;
		end;
		AddModuleToUnhookList(unhookarray[z]);
		z=z+1;
	end;
end;

function StartProcessInternal()
	UnhookArrayList();
	Start(false);
	unhook_inaction=true;
	AddBreak(jmp_to_oep+victim_base,3,0); EnableBreak(jmp_to_oep+victim_base);
	while true do
		Continue(true);
		if break_where==0xf40 then
			break;
		elseif break_where==0xf00 then
			WriteEx("Died while tracing to OEP",true,true,0x0000ff);
			return -1;
		end;
	end;
	unhook_inaction=false;
	return 0;
end;

function StartProcess()
	if StartProcessInternal()==-1 then
		return -1;
	end;
	SuspendAllOther();
	return 0;
end;

function MyDump(i)
	WriteLog(string.format("Dumping at 0x%08X",i));
	if manual==true then
		if CheckMemory(i)==1 or CheckMemory(i)==3 or ReadMemLarge(i,0x1000)==string.rep("\204",0x1000) then
			EIP=i;
			WriteLog(string.format("Probably CopyMem found at 0x%08X",i));
			local bContinue=GetProcAddress("ntdll.dll","ZwContinue");
			AddBreak(bContinue,1,0); EnableBreak(bContinue);
			while true do
				Continue(true);
				if break_where==bContinue then
					break;
				elseif break_where==0xf00 then
					return -1;
				end;
			end;
		end;
	end;
	return ReadMemLarge(i,0x1000);
end;

array={};
i=dumpstart;
while true do
	if StartProcess()==-1 then
		return -1;
	end;
	if dumpend==0 then
		if module_end==0 then
			dumpend=image_size;
		else
			dumpend=module_end;
		end;
		if cut_module~=0 and dumpend>cut_module then
			dumpend=cut_module;
		end;
	end;
	WriteLog("Ready to dump");

	while true do
		if i>=dumpend then
			break;
		end;
		array[(i-dumpstart)/0x1000]=MyDump(victim_base+i);
		if break_where==0xf00 then
			WriteEx(string.format("Died while dumping at 0x%08X",i),true,true,0x0000ff);
			break;
		end;
		i=i+0x1000;
	end;

	if i>=dumpend then
		break;
	end;
end;
Terminate();

if StartProcess()==-1 then
	return -1;
end;
for i=dumpend-0x1000,dumpstart,-0x1000 do
	WriteMemLarge(victim_base+i,array[(i-dumpstart)/0x1000],0x1000);
end;
Dump();
if cut_sections==true then
	ProcessResources();
	CutSections();
	ProcessExport();
	ProcessTLS();
end;
ProcessDelphiInit();
RestoreImportRelocs();
if cut_sections==true then
	SaveResources();
end;
ProcessOverlay();
SaveFile();
Terminate();