⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 autoassembler.pas.svn-base

📁 这是一段游戏修改工具的源代码.ring3功能由dephi开发,驱动是C开发.希望对大家有帮助
💻 SVN-BASE
📖 第 1 页 / 共 4 页
字号:
              if not fileexists(s1) then
                raise exception.Create(s1+' could not be found');


              include:=tstringlist.Create;
              try
                include.LoadFromFile(s1);
                for j:=i+1 to (i+1)+(include.Count-1) do
                  code.Insert(j,include[j-(i+1)]);
              finally
                include.Free;
              end;

              setlength(assemblerlines,length(assemblerlines)-1);
              continue;
            end
            else raise exception.Create('Wrong syntax. Include(filename.cea)');
          end;

          if uppercase(copy(currentline,1,13))='CREATETHREAD(' then
          begin
            //load a binary file into memory , this one already executes BEFORE the 2nd pass to get addressnames correct
            a:=pos('(',currentline);
            b:=pos(')',currentline);
            if (a>0) and (b>0) then
            begin
              s1:=copy(currentline,a+1,b-a-1);
            
              setlength(createthread,length(createthread)+1);
              createthread[length(createthread)-1]:=s1;

              setlength(assemblerlines,length(assemblerlines)-1);
              continue;
            end else raise exception.Create('Wrong syntax. CreateThread(address)');          
          end;

          if uppercase(copy(currentline,1,12))='LOADLIBRARY(' then
          begin
            //load a library into memory , this one already executes BEFORE the 2nd pass to get addressnames correct
            a:=pos('(',currentline);
            b:=pos(')',currentline);

            if (a>0) and (b>0) then
            begin
              s1:=copy(currentline,a+1,b-a-1);

              if pos(':',s1)=0 then
              begin
                s2:=extractfilename(s1);

                if fileexists(cheatenginedir+s2) then s1:=cheatenginedir+s2 else
                  if fileexists(getcurrentdir+'\'+s2) then s1:=getcurrentdir+'\'+s2 else
                    if fileexists(cheatenginedir+s1) then s1:=cheatenginedir+s1;

                //else just hope it's in the dll searchpath
              end; //else direct file path

              try
                InjectDll(s1,'');
                symhandler.reinitialize;
                symhandler.waitforsymbolsloaded;
              except
                raise exception.create(s1+' could not be injected');
              end;

              setlength(assemblerlines,length(assemblerlines)-1);
              continue;
            end else raise exception.Create('Wrong syntax. LoadLibrary(filename)');
          end;

          if uppercase(copy(currentline,1,8))='READMEM(' then
          begin
            //read memory and place it here (readmem(address,size) )
            a:=pos('(',currentline);
            b:=pos(',',currentline);
            c:=pos(')',currentline);
            if (a>0) and (b>0) and (c>0) then
            begin
              s1:=copy(currentline,a+1,b-a-1);
              s2:=copy(currentline,b+1,c-b-1);

              //read memory and replace with lines of DB xx xx xx xx xx xx xx xx
              try
                x:=symhandler.getAddressFromName(s1);
              except
                raise exception.Create('Invalid address for ReadMem');
              end;

              try
                a:=strtoint(s2);
              except
                raise exception.Create('Invalid size for ReadMem');
              end;

              if a=0 then
                raise exception.Create('Invalid size for ReadMem');


              getmem(bytebuf,a);
              try
                if (not ReadProcessMemory(processhandle, pointer(x),bytebuf,a,x)) or (x<a) then
                  raise exception.Create('The memory at '+s1+' could not be fully read');

                //still here so everything ok
                setlength(assemblerlines,length(assemblerlines)-1);

                s1:='db';

                for j:=0 to a-1 do
                begin
                  s1:=s1+' '+inttohex(bytebuf[j],2);
                  if (j mod 16)=15 then
                  begin
                    setlength(assemblerlines,length(assemblerlines)+1);
                    assemblerlines[length(assemblerlines)-1]:=s1;

                    s1:='db';
                  end;
                end;

                if length(s1)>2 then
                begin
                  setlength(assemblerlines,length(assemblerlines)+1);
                  assemblerlines[length(assemblerlines)-1]:=s1;
                end;

              finally
                freemem(bytebuf);
              end;



            end else raise exception.Create('Wrong syntax. ReadMem(address,size)');

            continue;
          end;

          if uppercase(copy(currentline,1,11))='LOADBINARY(' then
          begin
            //load a binary file into memory
            a:=pos('(',currentline);
            b:=pos(',',currentline);
            c:=pos(')',currentline);
            if (a>0) and (b>0) and (c>0) then
            begin
              s1:=copy(currentline,a+1,b-a-1);
              s2:=copy(currentline,b+1,c-b-1);

              if not fileexists(s2) then raise exception.Create('The file '+s2+' does not exist');

              setlength(loadbinary,length(loadbinary)+1);
              loadbinary[length(loadbinary)-1].address:=s1;
              loadbinary[length(loadbinary)-1].filename:=s2;

              setlength(assemblerlines,length(assemblerlines)-1);
              continue;
            end else raise exception.Create('Wrong syntax. LoadBinary(address,filename)');
          end;

          if uppercase(copy(currentline,1,15))='REGISTERSYMBOL(' then
          begin
            //add this symbol to the register symbollist
            a:=pos('(',currentline);
            b:=pos(')',currentline);

            if (a>0) and (b>0) then
            begin
              s1:=copy(currentline,a+1,b-a-1);

              setlength(addsymbollist,length(addsymbollist)+1);
              addsymbollist[length(addsymbollist)-1]:=s1;
            end
            else raise exception.Create('Syntax error');

            setlength(assemblerlines,length(assemblerlines)-1);
            continue;
          end;

          if uppercase(copy(currentline,1,17))='UNREGISTERSYMBOL(' then
          begin
            //add this symbol to the register symbollist
            a:=pos('(',currentline);
            b:=pos(')',currentline);

            if (a>0) and (b>0) then
            begin
              s1:=copy(currentline,a+1,b-a-1);

              setlength(deletesymbollist,length(deletesymbollist)+1);
              deletesymbollist[length(deletesymbollist)-1]:=s1;
            end
            else raise exception.Create('Syntax error');

            setlength(assemblerlines,length(assemblerlines)-1);
            continue;
          end;

          //define
          if uppercase(copy(currentline,1,7))='DEFINE(' then
          begin
            //syntax: alloc(x,size)    x=variable name size=bytes
            //allocate memory
            a:=pos('(',currentline);
            b:=pos(',',currentline);
            c:=pos(')',currentline);
            if (a>0) and (b>0) and (c>0) then
            begin
              s1:=copy(currentline,a+1,b-a-1);
              s2:=copy(currentline,b+1,c-b-1);

              for j:=0 to length(defines)-1 do
                if uppercase(defines[j].name)=uppercase(s1) then
                  raise exception.Create('Define '+s1+' already defined');

              setlength(defines,length(defines)+1);
              defines[length(defines)-1].name:=s1;
              defines[length(defines)-1].whatever:=s2;

              setlength(assemblerlines,length(assemblerlines)-1);   //don't bother with this in the 2nd pass
              continue;          
            end else raise exception.Create('Wrong syntax. DEFINE(name,whatever)');
          end;


          if uppercase(copy(currentline,1,11))='FULLACCESS(' then
          begin
            a:=pos('(',currentline);
            b:=pos(',',currentline);
            c:=pos(')',currentline);

            if (a>0) and (b>0) and (c>0) then
            begin
              s1:=copy(currentline,a+1,b-a-1);
              s2:=copy(currentline,b+1,c-b-1);

              setlength(fullaccess,length(fullaccess)+1);
              fullaccess[length(fullaccess)-1].address:=symhandler.getAddressFromName(s1);
              fullaccess[length(fullaccess)-1].size:=strtoint(s2);
            end else raise exception.Create('Syntax error. FullAccess(address,size)');

            setlength(assemblerlines,length(assemblerlines)-1);
            continue;
          end;


          if uppercase(copy(currentline,1,6))='LABEL(' then
          begin
            //syntax: label(x)  x=name of the label
            //later on in the code there has to be a line with "labelname:"
            a:=pos('(',currentline);
            b:=pos(')',currentline);

            if (a>0) and (b>0) then
            begin
              s1:=copy(currentline,a+1,b-a-1);


              val('$'+s1,j,a);
              if a=0 then raise exception.Create(s1+' is not a valid identifier');

              varsize:=length(s1);

              while (j<length(labels)) and (length(labels[j].labelname)>varsize) do
              begin
                if labels[j].labelname=s1 then
                  raise exception.Create(s1+' is being redeclared');
                inc(j);
              end;

              j:=length(labels);//quickfix
              l:=j;


              //check for the line "labelname:"
              ok1:=false;
              for j:=0 to code.Count-1 do
                if trim(code[j])=s1+':' then
                begin
                  if ok1 then raise exception.Create('label '+s1+' is being defined more than once');
                  ok1:=true;
                end;

              if not ok1 then raise exception.Create('label '+s1+' is not defined in the script');


              //still here so ok
              //insert it
              setlength(labels,length(labels)+1);
              for k:=length(labels)-1 downto j+1 do
                labels[k]:=labels[k-1];


              labels[l].labelname:=s1;
              labels[l].defined:=false;
              setlength(assemblerlines,length(assemblerlines)-1);
              setlength(labels[l].references,0);
              setlength(labels[l].references2,0);

              continue;
            end else raise exception.Create('Syntax Error');
          end;

          if (uppercase(copy(currentline,1,8))='DEALLOC(') then
          begin
            if (ceallocarray<>nil) then//memory dealloc=possible
            begin

              //syntax: dealloc(x)  x=name of region to deallocate
              //later on in the code there has to be a line with "labelname:"
              a:=pos('(',currentline);
              b:=pos(')',currentline);

              if (a>0) and (b>0) then
              begin
                s1:=copy(currentline,a+1,b-a-1);

                //find s1 in the ceallocarray
                for j:=0 to length(ceallocarray)-1 do
                begin
                  if uppercase(ceallocarray[j].varname)=uppercase(s1) then
                  begin
                    setlength(dealloc,length(dealloc)+1);
                    dealloc[length(dealloc)-1]:=ceallocarray[j].address;
                  end;
                end;
              end;
            end;
            setlength(assemblerlines,length(assemblerlines)-1);
            continue;
          end;

          //memory alloc
          if uppercase(copy(currentline,1,6))='ALLOC(' then
          begin
            //syntax: alloc(x,size)    x=variable name size=bytes
            //allocate memory
            a:=pos('(',currentline);
            b:=pos(',',currentline);
            c:=pos(')',currentline);

            if (a>0) and (b>0) and (c>0) then
            begin
              s1:=copy(currentline,a+1,b-a-1);
              s2:=copy(currentline,b+1,c-b-1);

              val('$'+s1,j,a);
              if a=0 then raise exception.Create(s1+' is not a valid identifier');

              varsize:=length(s1);

              //check for duplicate identifiers
              j:=0;
              while (j<length(allocs)) and (length(allocs[j].varname)>varsize) do
              begin
                if allocs[j].varname=s1 then
                  raise exception.Create('The identifier '+s1+' has already been declared');

                inc(j);
              end;

              j:=length(allocs);//quickfix

              setlength(allocs,length(allocs)+1);

              //longest varnames first so the rename of a shorter matching var wont override the longer one
              //move up the other allocs so I can inser this element (A linked list might have been better)
              for k:=length(allocs)-1 downto j+1 do
                allocs[k]:=allocs[k-1];

              allocs[j].varname:=s1;
              allocs[j].size:=StrToInt(s2);

              setlength(assemblerlines,length(assemblerlines)-1);   //don't bother with this in the 2nd pass
              continue;
            end else raise exception.Create('Wrong syntax. ALLOC(identifier,sizeinbytes)');
          end;

          //replace identifiers with values so the assemble error check doesnt crash on that
          for j:=0 to length(allocs)-1 do
            currentline:=replacetoken(currentline,allocs[j].varname,'00000000');

          for j:=0 to length(defines)-1 do
            currentline:=replacetoken(currentline,defines[j].name,defines[j].whatever);


          {$ifndef net}
          //memory kalloc
          if uppercase(copy(currentline,1,7))='KALLOC(' then
          begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -