var processName = process.argv[2]; var script="'use strict'; "; [ './views/js/frida/romdata.js', './views/js/frida/romlib.js', './views/js/frida/rompackets.js', './views/js/frida/rom.js' ].forEach(function(elem){ script+=fs.readFileSync(elem, 'utf8'); }); frida.attach(processName).then(function (session) { return session.createScript(script); }).then(function (script) { script.load().then(function () { console.log("script loaded"); }); }).catch(function (err) { console.error(err); });
struct PG_Move_CtoL_PlayerMoveObject { GamePGCommandEnum Command; int GItemID; RolePosStruct Pos; ClientMoveTypeENUM Type; float vX; float vY; float vZ; int AttachObjID; PG_Move_CtoL_PlayerMoveObject() { Command = EM_PG_Move_CtoL_PlayerMoveObject; } };
var Move_CtoL_PlayerMoveObject = new MakeStruct(Memory, memalloc, { command: {type: 'int', value: 24}, gitemid: {type: 'int', value: 2045}, x: {type: 'float', value: 1000.0}, y: {type: 'float', value: 1000.0}, z: {type: 'float', value: 1000.0}, dir: {type: 'float', value: 154}, type: {type: 'int', value: 0}, vX: {type: 'float', value: 0.0}, vY: {type: 'float', value: 0.0}, vZ: {type: 'float', value: 0.0}, attachObjID: {type: 'int', value: 0} });
Interceptor.attach(ptr("0x6694E0"), { onEnter: function(args) { var dataptr = ptr(args[2]); var val = Memory.readU32(dataptr); } }
void SendToLocal( int Size , void* Data ){ int *dataptr=(int*)Data; int val = dataptr[0]; }
function toString(buf, length) { var binary=new Uint8Array(buf); var result=new Uint8Array(length); for(var i=0; i<result.length; i++) result[i]=binary[i]; //console.log(length, result); return String.fromCharCode.apply(null, result); } function fromString(str, length) { var buf = new ArrayBuffer(length); // 2 bytes for each char var bufView = new Uint8Array(buf); for (var i=0, strLen=length; i<strLen; i++) { if(i<str.length) bufView[i] = str.charCodeAt(i); else bufView[i] = 0; } return buf; } var MakeStruct = function(Memory, ptr, options){ var _this=this; _this.offset = 0; _this.struct={}; _this.types={ byte: function(name, size){ _this.struct[name] = { type: 'byte', value: Memory.readS8(ptr.add(_this.offset)), size: 1, offset: _this.offset }; _this.offset+=1; }, short: function(name, size){ _this.struct[name] = { type: 'short', value: Memory.readS16(ptr.add(_this.offset)), size: 2, offset: _this.offset }; _this.offset+=2; }, int: function(name, size){ _this.struct[name] = { type: 'int', value: Memory.readS32(ptr.add(_this.offset)), size: 4, offset: _this.offset }; _this.offset+=4; }, float: function(name, size){ _this.struct[name] = { type: 'float', value: Memory.readFloat(ptr.add(_this.offset)), size: 4, offset: _this.offset }; _this.offset+=4; }, string: function(name, size, typesize){ //console.log(size, typesize); var mem=Memory.readByteArray(ptr.add(_this.offset), typesize); _this.struct[name] = { type: 'string', value: toString(mem, size), size: typesize, offset: _this.offset }; _this.offset+=typesize; }, bytes: function(name, size){ var mem=Memory.readByteArray(ptr.add(_this.offset), size); _this.struct[name] = { type: 'bytes', value: mem, size: size, offset: _this.offset }; _this.offset+=size; } }; _this.update = function(){ for(var key in _this.struct){ if(_this.struct.hasOwnProperty(key)){ var item=_this.struct[key]; switch(item.type){ case 'byte': Memory.writeS8(ptr.add(item.offset), item.value); break; case 'short': Memory.writeS16(ptr.add(item.offset), item.value); break; case 'int': Memory.writeS32(ptr.add(item.offset), item.value); break; case 'float': Memory.writeFloat(ptr.add(item.offset), item.value); break; case 'bytes': Memory.writeByteArray(ptr.add(item.offset), item.value); break; case 'string': Memory.writeByteArray(ptr.add(item.offset), fromString(item.value, item.size)); break; } } } } _this.sizeof = function(){ var s=0; for(var key in _this.struct){ if(_this.struct.hasOwnProperty(key) && _this.struct[key].size){ s+=_this.struct[key].size*1; } } return s; } _this.print = function(){ for(var key in _this.struct){ if(_this.struct.hasOwnProperty(key) && _this.struct[key].size){ console.log(key, _this.struct[key].value); } } console.log(''); } _this.struct['update']=_this.update; _this.struct['sizeof']=_this.sizeof; _this.struct['print']=_this.print; _this.struct['ptr']=ptr; for(var key in options){ if(options.hasOwnProperty(key)){ var elem=options[key]; _this.types[elem.type](key, typeof elem.size==="number" || typeof elem.size==="undefined"?elem.size:_this.struct[elem.size].value, elem.typesize); if(elem.value) _this.struct[key].value=elem.value; } } return _this.struct; };
Interceptor.attach(ptr("0x60CCC0"), { onEnter: function(args) { var dataptr = ptr(args[1]); var val = Memory.readS16(dataptr); var packetname=GamePGCommandEnum.enumName(val); if(packetname=="EM_PG_Move_CtoL_PlayerMoveObject"){ var Move_CtoL_PlayerMoveObject = new MakeStruct(Memory, dataptr, { command: {type: 'int'}, gitemid: {type: 'int'}, x: {type: 'float'}, y: {type: 'float'}, z: {type: 'float'}, dir: {type: 'float'}, type: {type: 'int'}, vX: {type: 'float'}, vY: {type: 'float'}, vZ: {type: 'float'}, attachObjID: {type: 'int'} }); Move_CtoL_PlayerMoveObject.x.value+=100; Move_CtoL_PlayerMoveObject.update(); Move_CtoL_PlayerMoveObject.print(); } } });
var _sendToLocal=new NativeFunction(ptr("0x60CCC0"), 'void', ['int', 'pointer']); var _setpos=new NativeFunction(ptr("0x79AE70"), 'void', ['pointer']); function _Send(obj){ _sendToLocal(obj.sizeof(),obj.ptr); } class Structs{ _gmcommand(ptr){ var memalloc = ptr||Memory.alloc(4096); var v = ""; var Talk_CtoL_GMCommand = new MakeStruct(Memory, memalloc, { command: {type: 'int', value: 154}, gitemid: {type: 'int', value: 0}, contentsize: {type: 'int', value: v.length}, content: {type: 'string', typesize: 512, size: 'contentsize', value: v}, }); return Talk_CtoL_GMCommand; } _moveTest(ptr){ var memalloc = ptr||Memory.alloc(4096); var Move_CtoL_PlayerMoveObject = new MakeStruct(Memory, memalloc, { command: {type: 'int', value: 24}, gitemid: {type: 'int', value: 2045}, x: {type: 'float', value: 1000.0}, y: {type: 'float', value: 1000.0}, z: {type: 'float', value: 1000.0}, dir: {type: 'float', value: 154}, type: {type: 'int', value: 0}, vX: {type: 'float', value: 0.0}, vY: {type: 'float', value: 0.0}, vZ: {type: 'float', value: 0.0}, attachObjID: {type: 'int', value: 0} }); return Move_CtoL_PlayerMoveObject; } }; function _call(name, args, ptr){ var struct = new Structs(); var s=struct[name](ptr); for(var i in args){ s[i].value=args[i]; } s.update(); _Send(s); }
var cmd="give 0x31194"; _call('_gmcommand', { contentsize: cmd.length, content: cmd });
var memalloc = Memory.alloc(128); var q=-4050.7; setInterval(function(){ Memory.writeUtf8String(memalloc, q+++", 244.5, -8251.9"); _setpos(memalloc); }, 100);
Source: https://habr.com/ru/post/268997/
All Articles