Advertisement
LoofahJoeBiden

Untitled

Feb 26th, 2025
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 6.93 KB | Cybersecurity | 0 0
  1. /// Just a random js snipet
  2. class p extends i{type;size;constructor(t,o){super();this.type=t;this.size=o}mangle(){return"A"+this.size.toString()+"_"+this.type.mangle()}toString(){return this.type.toString()+"["+this.size.toString()+"]"}}class c extends i{name;constructor(t){super();this.name=t}mangle(){return R[this.name]}toString(){return this.name}}class g extends i{type;constructor(t){super();this.type=t}mangle(){return"K"+this.type.mangle()}toString(){return"const "+this.type.toString()}}class l extends i{name;constructor(t){super();this.name=t}mangle(){return"U"+this.name.length.toString()+this.name}toString(){return this.name}}class b extends i{parameters;returnType;constructor(t,o){super();this.parameters=t;this.returnType=o}mangle(){let t="F";if(this.parameters.length===0)t+="v";else for(let o of this.parameters)t+=o.mangle();return t+="_"+this.returnType.mangle()+"E",t}toString(){let t=this.parameters.map((o)=>o.toString()).join(", ");return this.returnType.toString()+" ("+t+")"}}class m extends i{to;constructor(t){super();this.to=t}mangle(){return"R"+this.to.mangle()}toString(){return this.to.toString()+"&"}}class u extends i{to;constructor(t){super();this.to=t}mangle(){return"P"+this.to.mangle()}toString(){return this.to.toString()+"*"}}class x extends i{namespaces;base;constructor(t,o){super();this.namespaces=t;this.base=o}mangle(){let t="N";for(let o of this.namespaces)t+=o.length.toString()+o;return t+=this.base.length.toString()+this.base,t+="E",t}toString(){return this.namespaces.join("::")+"::"+this.base}}class S extends i{to;constructor(t){super();this.to=t}mangle(){return"O"+this.to.mangle()}toString(){return this.to.toString()+"&&"}}class f extends i{base;args;constructor(t,o){super();this.base=t;this.args=o}mangle(){return this.base.mangle()+"I"+this.args.map((t)=>t.mangle()).join("")+"E"}toString(){return this.base.toString()+"<"+this.args.map((t)=>t.toString()).join(", ")+">"}}class i{}var R={void:"v",int:"i",double:"d",char:"c",float:"f",bool:"b"},C={v:"void",i:"int",d:"double",c:"char",f:"float",b:"bool"};class d{input;pos=0;constructor(t){this.input=t}peek(){return this.input[this.pos]}consume(t=1){let o=this.input.substr(this.pos,t);return this.pos+=t,o}eof(){return this.pos>=this.input.length}readNumber(){let t="";while(!this.eof()&&/[0-9]/.test(this.peek()))t+=this.consume();if(t==="")throw new Error("Expected number at position "+this.pos);return t}parseType(){if(this.eof())throw new Error("Unexpected end of input.");let t=this.consume(1),o;switch(t){case"K":o=new g(this.parseType());break;case"P":o=new u(this.parseType());break;case"R":o=new m(this.parseType());break;case"O":o=new S(this.parseType());break;case"A":{let r=this.readNumber();if(this.consume(1)!=="_")throw new Error("Expected '_' in array encoding.");o=new p(this.parseType(),parseInt(r,10));break}case"F":{let r=[];if(this.peek()==="v")this.consume();else while(this.peek()!=="_")r.push(this.parseType());if(this.consume(1)!=="_")throw new Error("Expected '_' in function type encoding.");let n=this.parseType();if(this.consume(1)!=="E")throw new Error("Expected 'E' at end of function type encoding.");o=new b(r,n);break}case"U":{let r=this.readNumber(),n=parseInt(r,10),s=this.consume(n);o=new l(s);break}default:if(C[t])o=new c(C[t]);else throw new Error("Unknown type code: "+t)}if(!this.eof()&&this.peek()==="I"){this.consume();let r=[];while(this.peek()!=="E")r.push(this.parseType());this.consume(1),o=new f(o,r)}return o}}class v{functionName;parameters;returnType;namespaces;constructor(t,o,r,n){this.functionName=t;this.parameters=o;this.returnType=r;this.namespaces=n}mangle(){let t="";if(this.namespaces)for(let o of this.namespaces)t+=o.length.toString()+o;t+=this.functionName.length.toString()+this.functionName;for(let{type:o}of this.parameters)t+=o.mangle();return t}toString(){let t="";if(this.namespaces)t+=this.namespaces.join("::")+"::";if(t+=this.functionName,t+="("+this.parameters.map((o)=>{let r=o.name?` ${o.name}`:"";return o.type.toString()+r}).join(", ")+")",this.returnType)t=`${this.returnType.toString()} ${t}`;return t}}class T{input;pos=0;constructor(t){this.input=t}skipWhitespace(){while(!this.eof()&&/\s/.test(this.peek()))this.consume()}peek(){return this.input[this.pos]}consume(t=1){let o=this.input.substr(this.pos,t);return this.pos+=t,o}eof(){return this.pos>=this.input.length}parseIdentifier(){this.skipWhitespace();let t="";while(!this.eof()&&/[a-zA-Z0-9_]/.test(this.peek()))t+=this.consume();if(t==="")throw new Error("Expected identifier at position "+this.pos);return t}parseQualifiedIdentifierParts(){this.skipWhitespace();let t=[];t.push(this.parseIdentifier());while(!this.eof()&&this.input.substr(this.pos,2)==="::")this.consume(2),t.push(this.parseIdentifier());return t}parseTemplateArguments(){if(this.skipWhitespace(),this.peek()!=="<")return[];this.consume();let t=[];while(!0){this.skipWhitespace();let o=this._parseType();if(t.push(o),this.skipWhitespace(),this.peek()===","){this.consume();continue}else if(this.peek()===">"){this.consume();break}else throw new Error("Expected ',' or '>' in template argument list at position "+this.pos)}return t}parseTypeToken(){return this._parseType()}_parseType(){this.skipWhitespace();let t=!1;if(this.input.substr(this.pos,5)==="const")this.consume(5),t=!0,this.skipWhitespace();let o=this.parseQualifiedIdentifierParts(),r;if(o.length===1){let n=o[0];if(["void","int","double","char","float","bool"].includes(n))r=new c(n);else r=new l(n)}else{let n=o.slice(0,o.length-1),s=o[o.length-1];r=new x(n,s)}if(this.skipWhitespace(),!this.eof()&&this.peek()==="<"){let n=this.parseTemplateArguments();r=new f(r,n)}while(!this.eof())if(this.skipWhitespace(),this.peek()==="*")this.consume(),r=new u(r);else break;if(t)r=new g(r);return r}parseParameterList(){this.skipWhitespace();let t=[];if(this.peek()===")")return t;while(!0){let o=this._parseType(),r;if(this.skipWhitespace(),/[a-zA-Z_][a-zA-Z0-9_]*/.test(this.peek()))r=this.parseIdentifier();if(t.push({type:o,name:r}),this.skipWhitespace(),this.peek()===","){this.consume(),this.skipWhitespace();continue}else break}return t}parseSignature(){this.skipWhitespace();let t=this.input.indexOf("(");if(t===-1)throw new Error("Expected '(' in function signature");let o=this.input.slice(0,t).trim(),r=void 0,n="",s=o.split(/\s+/).filter((h)=>h.length>0);if(s.length>1){n=s[s.length-1];let h=s.slice(0,s.length-1).join(" ");r=new T(h).parseTypeToken()}else n=s[0];let e=n.split("::").map((h)=>h.trim()).filter(Boolean),j=e.pop(),z=e.length>0?e:void 0;if(this.pos=t,this.consume()!=="(")throw new Error("Expected '(' after function name");let _=this.parseParameterList();if(this.skipWhitespace(),this.consume()!==")")throw new Error("Expected ')' after parameter list");return new v(j,_,r,z)}}export{C as codeToBasicType,R as basicTypeToCode,f as TemplateType,T as SignatureParser,S as RvalueReferenceType,x as QualifiedType,u as PointerType,m as LvalueReferenceType,b as FunctionType,v as FunctionSignature,d as DemangleParser,l as CustomType,g as ConstType,i as CType,c as BasicType,p as ArrayType};
  3.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement