I've searched all around for name to call this, but i can't find any....
Its in a .java file sent to me by a friend(He Thought i would decode it straightaway), without knowing i'm also a noob of this....
This is the String data i want to decode without compiling the Java file.
String[] descriptorData = {
"\n0com/google/javascript/jscomp/function_" +
"info.proto\022\006jscomp\"\277\002\n\026FunctionInformati" +
"onMap\0223\n\005entry\030\001 \003(\n2$.jscomp.FunctionIn" +
"formationMap.Entry\0225\n\006module\030e \003(\n2%.jsc" +
"omp.FunctionInformationMap.Module\032\207\001\n\005En" +
"try\022\n\n\002id\030\002 \002(\005\022\023\n\013source_name\030\003 \002(\t\022\023\n\013" +
"line_number\030\004 \002(\005\022\023\n\013module_name\030\005 \002(\t\022\014" +
"\n\004size\030\006 \002(\005\022\014\n\004name\030\007 \002(\t\022\027\n\017compiled_s" +
"ource\030\010 \002(\t\032/\n\006Module\022\014\n\004name\030f \002(\t\022\027\n\017c" +
"ompiled_source\030g \002(\tB \n\034com.google.javas","cript.jscompP\001"
What you see there is if I'm not mistaken a piece of auto generated code that describes
message FunctionInformationMap {
repeated group Entry = 1 {
required int32 id = 2;
required string source_name = 3;
required int32 line_number = 4;
required string module_name = 5;
required int32 size = 6;
required string name = 7;
required string compiled_source = 8;
}
}
It's here
https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/function_info.proto
and the generated code here can be found for example here
https://code.google.com/p/closure-compiler/source/browse/gen/com/google/javascript/jscomp/FunctionInfo.java?name=v20140407
Ps: I just googled "com/google/javascript/jscomp/function_info.proto" but you can actually reverse the process. Hints here for example https://www.sysdream.com/reverse-engineering-protobuf-apps
I Simply solved this by using the System.Out.PrintIn to print out the string data to a TXT file...
That's It..
Thanks...
Related
I have written a SNMP listener in Java using the TNM4J library which uses the SNMP4J library.
The listener is able to read received traps, except for traps that appear to be indexed in a table.
The listener is listening to traps from an Ericsson object, which means I am using the ERICSSON-ALARM-MIB and the MIB imports it needs. The trap I am receiving is the eriAlarmActiveManagedObject with OID .1.3.6.1.4.1.193.183.4.1.3.5.1.5, but I also tested it locally with the other traps in the table and the same error occurs
If one looks at https://mibs.observium.org/mib/ERICSSON-ALARM-MIB/ :
All the traps that are from a table like this can not be read by the listener.
It gives an index out of bound exception from a extractIndexes method in MibbleIndexExtractor.java in the TNM4J library.
#Override
public IndexDescriptor[] extractIndexes(String instanceOid) {
String oid = symbol.getValue().toString();
String suboid = instanceOid.substring(oid.length() + 1);
int[] components = oidToArray(suboid);
int offset = 0;
IndexDescriptor[] descriptors = new IndexDescriptor[indexes.length];
for (int i = 0; i < indexes.length; i++) {
SnmpIndex index = indexes[i];
MibValueSymbol indexSymbol = symbol.getMib().getSymbolByOid(index.getValue().toString());
MibType indexType = ((SnmpObjectType) indexSymbol.getType()).getSyntax();
int length = fixedLength(indexType);
boolean implied = length != -1 || index.isImplied();
if (length == -1) {
length = variableLength(indexType, components, offset, index.isImplied());
}
int[] encoded = new int[length];
System.arraycopy(components, offset, encoded, 0, length);
descriptors[i] = new MibbleIndexDescriptor(indexSymbol, encoded, implied);
offset += length;
}
return descriptors;
}
I have debugged it and this happens because the oid String and instanceOid String are identical which of course causes an exception where the suboid String is being created.
However on all other traps it never calls this extractIndexes method, but just works finely and prints out the trap and oid name correctly.
Any suggestion on how to fix this issue?
After being in contact with the developer of TNM4J he made some fixes to his library.
After that the Ericsson oids was being correctly translated. There was a few missing translations from oids, which was because of the loading order of the MIBs.
Re-adjusting these made it work.
For anyone interested the troubleshooting process with the developer can view it here:
https://github.com/soulwing/tnm4j/issues/9
i have just this code:
import java.util.Calendar;
public class Contigencia
{
public String Contigencia(){
int ano = Calendar.getInstance().get(Calendar.YEAR);
int mes = Calendar.getInstance().get(Calendar.MONTH);
int dia = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
mes = mes + 1;
String Contigencia;
int anoC, mesC, diaC;
diaC = 200 - dia;
mesC = mes*3;
anoC = 9999 - ano;
Contigencia = ("" + diaC + mesC + "0" + anoC);
return Contigencia;
}
}
And I want to create a executable file, for when I execute the file, show me the String Contigencia, like in this return.
BlueJ allows you to create executable JARs.
In other words: you can package a Java application into a single JAR, which you can later "launch" using some wrapper script. See here for a video tutorial on how to do that.
Creating a real binary executable is something completely different; and not something that BlueJ is capable of doing.
You can look into launch4j for the later.
So when an error occurred during runtime, the log always show a link to the specific error and you can click on it to be taken there directly.
I'm looking to exploit this function for my own use (since finding where the log is generated across multiple files can be a pain). Of course you can just put the source in the log key but if I'm able to link it just the way Android Studio / Intellij IDEAS does it with the error output, that would be MASSIVELY helpful. Thanks.
The following code will be a work-around to print the logged function name and line number (in Java):
private static String _FUNC_() {
int STACK_LEVEL = 2;
StackTraceElement traceElement = ((new Exception()).getStackTrace())[STACK_LEVEL];
StringBuilder sb = new StringBuilder();
sb.append("<");
String className = traceElement.getClassName();
className = className.substring(className.lastIndexOf(".") + 1);
sb.append(className);
sb.append(":");
sb.append(traceElement.getMethodName());
sb.append(":");
sb.append(traceElement.getLineNumber());
sb.append("> ");
return sb.toString();
}
Been stumped on this for a while and pulling what is left of my hair out.
Sending non-nested Protobufs from Python to Java and Java to Python without
an issue with WebSockets. My problem is sending a nested version over a WebSocket. I believe my issue is on
the Python encoding side.
Your guidance is appreciated.
.proto file
message Response {
// Reflect back to caller
required string service_name = 1;
// Reflect back to caller
required string method_name = 2;
// Who is responding
required string client_id = 3;
// Status Code
required StatusCd status_cd = 4;
// RPC response proto
optional bytes response_proto = 5;
// Was callback invoked
optional bool callback = 6 [default = false];
// Error, if any
optional string error = 7;
//optional string response_desc = 6;
}
message HeartbeatResult {
required string service = 1;
required string timestamp = 2;
required float status_cd = 3;
required string status_summary = 4;
}
A Heartbeat result is supposed to get sent in the reponse_proto field
of the Response Protobuf. I am able to do this in Java to Java but Python
to Java is not working.
I've included two variations of the python code. Neither of which works.
def GetHeartbeat(self):
print "GetHeartbeat called"
import time
ts = time.time()
import datetime
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
heartbeatResult = rpc_pb2.HeartbeatResult()
heartbeatResult.service = "ALERT_SERVICE"
heartbeatResult.timestamp = st
heartbeatResult.status_cd = rpc_pb2.OK
heartbeatResult.status_summary = "OK"
response = rpc_pb2.Response()
response.service_name = ""
response.method_name = "SendHeartbeatResult"
response.client_id = "ALERT_SERVICE"
response.status_cd = rpc_pb2.OK
response.response_proto = str(heartbeatResult).encode('utf-8')
self.sendMessage(response.SerializeToString())
print "GetHeartbeat finished"
def GetHeartbeat2(self):
print "GetHeartbeat called"
import time
ts = time.time()
import datetime
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
heartbeatResult = rpc_pb2.HeartbeatResult()
heartbeatResult.service = "ALERT_SERVICE"
heartbeatResult.timestamp = st
heartbeatResult.status_cd = rpc_pb2.OK
heartbeatResult.status_summary = "OK"
response = rpc_pb2.Response()
response.service_name = ""
response.method_name = "SendHeartbeatResult"
response.client_id = "ALERT_SERVICE"
response.status_cd = rpc_pb2.OK
response.response_proto = heartbeatResult.SerializeToString()
self.sendMessage(response.SerializeToString())
print "GetHeartbeat finished"
Errors on the Java server side are:
(GetHeartbeat) Protocol message end-group tag did not match expected tag
and
(GetHeartbeat2)
Message: [org.java_websocket.exceptions.InvalidDataException: java.nio.charset.MalformedInputException: Input length = 1
at org.java_websocket.util.Charsetfunctions.stringUtf8(Charsetfunctions.java:80)
at org.java_websocket.WebSocketImpl.deliverMessage(WebSocketImpl.java:561)
at org.java_websocket.WebSocketImpl.decodeFrames(WebSocketImpl.java:328)
at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:149)
at org.java_websocket.server.WebSocketServer$WebSocketWorker.run(WebSocketServer.java:593)
Caused by: java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException(CoderResult.java:277)
at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:798)
at org.java_websocket.util.Charsetfunctions.stringUtf8(Charsetfunctions.java:77)
Solution
Also posted this question on protobuf group
Credit to Christopher Head and Ilia Mirkin for providing input on the google group
https://groups.google.com/forum/#!topic/protobuf/Cp7zWiWok9I
response.response_proto = base64.b64encode(heartbeatResult.SerializeToString())
self.sendMessage(response.SerializeToString())
FYI, Ilia also suggested base64 encoding the entire message but this seems to be working at the moment.
I am currently calculating values to fill a database of 15 milion records. The first 7 mill went just fin,e however now my update query starts giving problems :
Now & then a random letter changes into some jibberish.
In java I generate the query doing :
String updateSql = "UPDATE VanNaar SET time = CASE ID ";
for (int i = 0; i < routes.size(); i++) {
updateSql += " WHEN " + routes.get(i).ID + " THEN " + routes.get(i).driveTime;
}
updateSql += " END, ";
updateSql += " distance = CASE ID ";
for (int i = 0; i < routes.size(); i++) {
updateSql += " WHEN " + routes.get(i).ID + " THEN " + routes.get(i).distance;
}
updateSql += " END WHERE id IN (";
for (int i = 0; i < routes.size(); i++) {
updateSql += routes.get(i).ID + ",";
}
updateSql = updateSql.substring(0, updateSql.length() - 1);
updateSql += ");";
Which works just fine, as mentioned before. Here is what Java trows at me now:
...MySQL server version for the right syntax to use near '×HEN 8284022 THEN 999.999 WHEN 8284023 THEN 3791.0 WHEN 8284024 THEN 378...
Or
...MySQL server version for the right syntax to use near 'WÈEN 7468574 THEN 2273.0 WHEN 7468575 THEN 2410.0 WHEN 7468576 THEN 2472.0 W' at line 1
Notice the weirdisch Ã^ or Ã- , a final exmpale, mind you the bold tekst:
...MySQL server version for the right syntax to use near **'Â** WHEN 7228125 THEN 48590.0 WHEN 7228126 THEN 47910.0 WHEN 7228127 THEN...
...
Update:
It seems to be getting worse..:
Unknown column '9°22331' in 'where clause'
I'm no Java expert but shouldn't you be using a StringBuilder in the first place? Possibly even use a prepared statement? You could buld the prepared statement with a stringbuilder but instead of
updateSql += " WHEN " + routes.get(i).ID + " THEN " + routes.get(i).driveTime;
everywhere you'd do something like
myStrngBldr.append(" WHEN ? THEN ?");
or
myStrngBldr.append(" WHEN #foo1 THEN #foo2");
if named parameters are supported (don't know) and later add the actual parameters:
myPrepdStmt = myConn.prepareStatement(myStrngBldr.toString());
myPrepdStmt.setInt(1, routes.get(i).ID);
myPrepdStmt.setFloat(2, routes.get(i).driveTime);
...
myPrepdStmt.executeUpdate();
This page should help you.
What is actually causing the 'strange malformed strings': I don't know. My best guess would be the you'd have to use something like .ToString() on all those ID's and other non-string values since you're concatenating a string. Maybe, somehow, the values are interpreted as charcodes (because they're not explicitly casted as string) and thus causing weird characters.
Another guess would be: are you actually building 15 million queries in-memory before sending them to the database? Or does each query get sent to the DB seperately? Maybe the fact that you're trying to store a huge-ass string in-memory causes some problems (although it shouldn't cause the problem you're describing here).
You might want to consider replacing the gigantic update with two CASE selectors and one IN with individual UPDATE statements for each row. I know that the problem is not caused by this, but it is probably a cleaner and more efficient solution. If your DB connector supports multiple statements per execution, you could do something like the following:
int batchSize = 0;
StringBuilder sb = new StringBuilder();
for (Route r: routes) {
sb.append("UPDATE VanNaar SET")
.append(" time = '").append(r.driveTime).append("',")
.append(" distance = '").append(r.distance).append("'")
.append(" WHERE ID = '").append(r.ID).append("'; ");
if (++batchSize == BATCH_SIZE) {
connector.exec(sb.toString());
sb = new StringBuilder();
batchSize = 0;
}
}
if (sb.length() > 0) {
connector.exec(sb.toString());
}
This will let StringBuilder take care of transforming whatever the underlying value type is into a String. If driveTime, distance, or ID are already strings, then you will have to escape them properly using the appropriate JDBC methods.
You'd probably be better off using prepared statements for this sort of thing as suggested by #RobIII since they would take care of the SQL injection problems automatically.